X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=lib%2Flibrte_power%2Fpower_acpi_cpufreq.c;h=583815a07e9fe75c0053d2551206232895f91f42;hb=ec0b862d5e52db12932c3125d06081307aea6af4;hp=bce933e9203906dc3f86b1b4c77decafe211993a;hpb=d69dc8476dcb1a517505b8b505494c8c5e3cc881;p=dpdk.git diff --git a/lib/librte_power/power_acpi_cpufreq.c b/lib/librte_power/power_acpi_cpufreq.c index bce933e920..583815a07e 100644 --- a/lib/librte_power/power_acpi_cpufreq.c +++ b/lib/librte_power/power_acpi_cpufreq.c @@ -12,8 +12,10 @@ #include #include -#include #include +#include +#include +#include #include "power_acpi_cpufreq.h" #include "power_common.h" @@ -28,7 +30,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) @@ -57,6 +59,7 @@ "/sys/devices/system/cpu/cpu%u/cpufreq/scaling_available_frequencies" #define POWER_SYSFILE_SETSPEED \ "/sys/devices/system/cpu/cpu%u/cpufreq/scaling_setspeed" +#define POWER_ACPI_DRIVER "acpi-cpufreq" /* * MSR related @@ -107,7 +110,7 @@ set_freq_internal(struct rte_power_info *pi, uint32_t idx) if (idx == pi->curr_idx) return 0; - POWER_DEBUG_TRACE("Freqency[%u] %u to be set for lcore %u\n", + POWER_DEBUG_TRACE("Frequency[%u] %u to be set for lcore %u\n", idx, pi->freqs[idx], pi->lcore_id); if (fseek(pi->f, 0, SEEK_SET) < 0) { RTE_LOG(ERR, POWER, "Fail to set file position indicator to 0 " @@ -147,6 +150,8 @@ power_set_governor_userspace(struct rte_power_info *pi) s = fgets(buf, sizeof(buf), f); FOPS_OR_NULL_GOTO(s, out); + /* Strip off terminating '\n' */ + strtok(buf, "\n"); /* Check if current governor is userspace */ if (strncmp(buf, POWER_GOVERNOR_USERSPACE, @@ -157,7 +162,7 @@ power_set_governor_userspace(struct rte_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 'userspace' to the governor */ val = fseek(f, 0, SEEK_SET); @@ -166,6 +171,10 @@ power_set_governor_userspace(struct rte_power_info *pi) val = fputs(POWER_GOVERNOR_USERSPACE, f); FOPS_OR_ERR_GOTO(val, out); + /* We need to flush to see if the fputs succeeds */ + val = fflush(f); + FOPS_OR_ERR_GOTO(val, out); + ret = 0; RTE_LOG(INFO, POWER, "Power management governor of lcore %u has been " "set to user space successfully\n", pi->lcore_id); @@ -281,6 +290,12 @@ out: return -1; } +int +power_acpi_cpufreq_check_supported(void) +{ + return cpufreq_check_scaling_driver(POWER_ACPI_DRIVER); +} + int power_acpi_cpufreq_init(unsigned int lcore_id) { @@ -436,8 +451,13 @@ power_acpi_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t num) { struct rte_power_info *pi; - if (lcore_id >= RTE_MAX_LCORE || !freqs) { - RTE_LOG(ERR, POWER, "Invalid input parameter\n"); + if (lcore_id >= RTE_MAX_LCORE) { + RTE_LOG(ERR, POWER, "Invalid lcore ID\n"); + return 0; + } + + if (freqs == NULL) { + RTE_LOG(ERR, POWER, "NULL buffer supplied\n"); return 0; } @@ -502,7 +522,8 @@ power_acpi_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. */ @@ -623,3 +644,24 @@ power_acpi_disable_turbo(unsigned int lcore_id) return 0; } + +int power_acpi_get_capabilities(unsigned int lcore_id, + struct rte_power_core_capabilities *caps) +{ + struct rte_power_info *pi; + + if (lcore_id >= RTE_MAX_LCORE) { + RTE_LOG(ERR, POWER, "Invalid lcore ID\n"); + return -1; + } + if (caps == NULL) { + RTE_LOG(ERR, POWER, "Invalid argument\n"); + return -1; + } + + pi = &lcore_power_info[lcore_id]; + caps->capabilities = 0; + caps->turbo = !!(pi->turbo_available); + + return 0; +}