diff options
author | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2020-07-27 17:15:43 +0200 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2020-07-30 18:19:52 +0200 |
commit | 3a9571760665817a269eb8f74749cbc231e7af45 (patch) | |
tree | a700f0dc52e355010ab9d7f5adf4396f9541c8a9 /drivers/cpufreq/intel_pstate.c | |
parent | 80e30368669e0387d9778b15bd1b985074725a2e (diff) |
cpufreq: intel_pstate: Rearrange the storing of new EPP values
Move the locking away from intel_pstate_set_energy_pref_index()
into its only caller and drop the (now redundant) return_pref label
from it.
Also move the "raw" EPP value check into the caller of that function,
so as to do it before acquiring the mutex, and reduce code duplication
related to the "raw" EPP values processing somewhat.
No intentional functional impact.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Francisco Jerez <currojerez@riseup.net>
Diffstat (limited to 'drivers/cpufreq/intel_pstate.c')
-rw-r--r-- | drivers/cpufreq/intel_pstate.c | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c index 8f1f01ca9b8e..c55f6e35a1e3 100644 --- a/drivers/cpufreq/intel_pstate.c +++ b/drivers/cpufreq/intel_pstate.c @@ -649,28 +649,18 @@ static int intel_pstate_set_energy_pref_index(struct cpudata *cpu_data, if (!pref_index) epp = cpu_data->epp_default; - mutex_lock(&intel_pstate_limits_lock); - if (boot_cpu_has(X86_FEATURE_HWP_EPP)) { u64 value; ret = rdmsrl_on_cpu(cpu_data->cpu, MSR_HWP_REQUEST, &value); if (ret) - goto return_pref; + return ret; value &= ~GENMASK_ULL(31, 24); - if (use_raw) { - if (raw_epp > 255) { - ret = -EINVAL; - goto return_pref; - } - value |= (u64)raw_epp << 24; - ret = wrmsrl_on_cpu(cpu_data->cpu, MSR_HWP_REQUEST, value); - goto return_pref; - } - - if (epp == -EINVAL) + if (use_raw) + epp = raw_epp; + else if (epp == -EINVAL) epp = epp_values[pref_index - 1]; value |= (u64)epp << 24; @@ -680,8 +670,6 @@ static int intel_pstate_set_energy_pref_index(struct cpudata *cpu_data, epp = (pref_index - 1) << 2; ret = intel_pstate_set_epb(cpu_data->cpu, epp); } -return_pref: - mutex_unlock(&intel_pstate_limits_lock); return ret; } @@ -708,8 +696,8 @@ static ssize_t store_energy_performance_preference( struct cpudata *cpu_data = all_cpu_data[policy->cpu]; char str_preference[21]; bool raw = false; + ssize_t ret; u32 epp = 0; - int ret; ret = sscanf(buf, "%20s", str_preference); if (ret != 1) @@ -724,14 +712,21 @@ static ssize_t store_energy_performance_preference( if (ret) return ret; + if (epp > 255) + return -EINVAL; + raw = true; } + mutex_lock(&intel_pstate_limits_lock); + ret = intel_pstate_set_energy_pref_index(cpu_data, ret, raw, epp); - if (ret) - return ret; + if (!ret) + ret = count; - return count; + mutex_unlock(&intel_pstate_limits_lock); + + return ret; } static ssize_t show_energy_performance_preference( |