test mbuf attach
[dpdk.git] / lib / librte_power / power_pstate_cpufreq.c
index 61ff8db..2526441 100644 (file)
 #include <errno.h>
 #include <inttypes.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"
@@ -31,7 +33,7 @@
 
 #define FOPEN_OR_ERR_RET(f, retval) do { \
                if ((f) == NULL) { \
-                       RTE_LOG(ERR, POWER, "File not openned\n"); \
+                       RTE_LOG(ERR, POWER, "File not opened\n"); \
                        return retval; \
                } \
 } while (0)
@@ -69,6 +71,7 @@
                "/sys/devices/system/cpu/cpu%u/cpufreq/cpuinfo_min_freq"
 #define POWER_SYSFILE_BASE_FREQ  \
                "/sys/devices/system/cpu/cpu%u/cpufreq/base_frequency"
+#define POWER_PSTATE_DRIVER "intel_pstate"
 #define POWER_MSR_PATH  "/dev/cpu/%u/msr"
 
 /*
@@ -157,6 +160,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);
@@ -198,8 +202,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;
 
@@ -218,7 +224,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
@@ -280,7 +288,7 @@ set_freq_internal(struct pstate_power_info *pi, uint32_t idx)
                        return -1;
                }
 
-               POWER_DEBUG_TRACE("Freqency '%u' to be set for lcore %u\n",
+               POWER_DEBUG_TRACE("Frequency '%u' to be set for lcore %u\n",
                                  target_freq, pi->lcore_id);
 
                fflush(pi->f_cur_min);
@@ -303,7 +311,7 @@ set_freq_internal(struct pstate_power_info *pi, uint32_t idx)
                        return -1;
                }
 
-               POWER_DEBUG_TRACE("Freqency '%u' to be set for lcore %u\n",
+               POWER_DEBUG_TRACE("Frequency '%u' to be set for lcore %u\n",
                                  target_freq, pi->lcore_id);
 
                fflush(pi->f_cur_max);
@@ -349,7 +357,7 @@ power_set_governor_performance(struct pstate_power_info *pi)
                goto out;
        }
        /* Save the original governor */
-       snprintf(pi->governor_ori, sizeof(pi->governor_ori), "%s", buf);
+       strlcpy(pi->governor_ori, buf, sizeof(pi->governor_ori));
 
        /* Write 'performance' to the governor */
        val = fseek(f, 0, SEEK_SET);
@@ -524,6 +532,12 @@ out:
        return ret;
 }
 
+int
+power_pstate_cpufreq_check_supported(void)
+{
+       return cpufreq_check_scaling_driver(POWER_PSTATE_DRIVER);
+}
+
 int
 power_pstate_cpufreq_init(unsigned int lcore_id)
 {
@@ -689,7 +703,8 @@ power_pstate_cpufreq_freq_up(unsigned int lcore_id)
        }
 
        pi = &lcore_power_info[lcore_id];
-       if (pi->curr_idx == 0)
+       if (pi->curr_idx == 0 ||
+           (pi->curr_idx == 1 && pi->turbo_available && !pi->turbo_enable))
                return 0;
 
        /* Frequencies in the array are from high to low. */
@@ -809,6 +824,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;
 }