net/virtio: improve perf via one-way barrier on avail flag
[dpdk.git] / lib / librte_power / power_pstate_cpufreq.c
index 336c138..ecbcb3a 100644 (file)
 #include <errno.h>
 #include <inttypes.h>
 
-#include <rte_string_fns.h>
-#include <rte_memcpy.h>
 #include <rte_atomic.h>
+#include <rte_memcpy.h>
+#include <rte_memory.h>
+#include <rte_string_fns.h>
 
 #include "power_pstate_cpufreq.h"
 #include "power_common.h"
@@ -158,6 +159,7 @@ power_init_for_setting_freq(struct pstate_power_info *pi)
        char *s_base;
        uint32_t base_ratio = 0;
        uint64_t max_non_turbo = 0;
+       int  ret_val = 0;
 
        snprintf(fullpath_min, sizeof(fullpath_min), POWER_SYSFILE_MIN_FREQ,
                        pi->lcore_id);
@@ -199,8 +201,10 @@ power_init_for_setting_freq(struct pstate_power_info *pi)
 
        /* Add MSR read to detect turbo status */
 
-       if (power_rdmsr(PLATFORM_INFO, &max_non_turbo, pi->lcore_id) < 0)
-               return -1;
+       if (power_rdmsr(PLATFORM_INFO, &max_non_turbo, pi->lcore_id) < 0) {
+               ret_val = -1;
+               goto out;
+       }
 
        max_non_turbo = (max_non_turbo&NON_TURBO_MASK)>>NON_TURBO_OFFSET;
 
@@ -219,7 +223,9 @@ power_init_for_setting_freq(struct pstate_power_info *pi)
        pi->core_base_freq = base_ratio * BUS_FREQ;
 
 out:
-       return 0;
+       if (f_base != NULL)
+               fclose(f_base);
+       return ret_val;
 }
 
 static int
@@ -810,6 +816,15 @@ power_pstate_disable_turbo(unsigned int lcore_id)
 
        pi->turbo_enable = 0;
 
+       if (pi->turbo_available && pi->curr_idx <= 1) {
+               /* Try to set freq to max by default coming out of turbo */
+               if (power_pstate_cpufreq_freq_max(lcore_id) < 0) {
+                       RTE_LOG(ERR, POWER,
+                               "Failed to set frequency of lcore %u to max\n",
+                               lcore_id);
+                       return -1;
+               }
+       }
 
        return 0;
 }