Skip to content

Commit 3a95717

Browse files
committed
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 <[email protected]> Reviewed-by: Francisco Jerez <[email protected]>
1 parent 80e3036 commit 3a95717

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

drivers/cpufreq/intel_pstate.c

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -649,28 +649,18 @@ static int intel_pstate_set_energy_pref_index(struct cpudata *cpu_data,
649649
if (!pref_index)
650650
epp = cpu_data->epp_default;
651651

652-
mutex_lock(&intel_pstate_limits_lock);
653-
654652
if (boot_cpu_has(X86_FEATURE_HWP_EPP)) {
655653
u64 value;
656654

657655
ret = rdmsrl_on_cpu(cpu_data->cpu, MSR_HWP_REQUEST, &value);
658656
if (ret)
659-
goto return_pref;
657+
return ret;
660658

661659
value &= ~GENMASK_ULL(31, 24);
662660

663-
if (use_raw) {
664-
if (raw_epp > 255) {
665-
ret = -EINVAL;
666-
goto return_pref;
667-
}
668-
value |= (u64)raw_epp << 24;
669-
ret = wrmsrl_on_cpu(cpu_data->cpu, MSR_HWP_REQUEST, value);
670-
goto return_pref;
671-
}
672-
673-
if (epp == -EINVAL)
661+
if (use_raw)
662+
epp = raw_epp;
663+
else if (epp == -EINVAL)
674664
epp = epp_values[pref_index - 1];
675665

676666
value |= (u64)epp << 24;
@@ -680,8 +670,6 @@ static int intel_pstate_set_energy_pref_index(struct cpudata *cpu_data,
680670
epp = (pref_index - 1) << 2;
681671
ret = intel_pstate_set_epb(cpu_data->cpu, epp);
682672
}
683-
return_pref:
684-
mutex_unlock(&intel_pstate_limits_lock);
685673

686674
return ret;
687675
}
@@ -708,8 +696,8 @@ static ssize_t store_energy_performance_preference(
708696
struct cpudata *cpu_data = all_cpu_data[policy->cpu];
709697
char str_preference[21];
710698
bool raw = false;
699+
ssize_t ret;
711700
u32 epp = 0;
712-
int ret;
713701

714702
ret = sscanf(buf, "%20s", str_preference);
715703
if (ret != 1)
@@ -724,14 +712,21 @@ static ssize_t store_energy_performance_preference(
724712
if (ret)
725713
return ret;
726714

715+
if (epp > 255)
716+
return -EINVAL;
717+
727718
raw = true;
728719
}
729720

721+
mutex_lock(&intel_pstate_limits_lock);
722+
730723
ret = intel_pstate_set_energy_pref_index(cpu_data, ret, raw, epp);
731-
if (ret)
732-
return ret;
724+
if (!ret)
725+
ret = count;
733726

734-
return count;
727+
mutex_unlock(&intel_pstate_limits_lock);
728+
729+
return ret;
735730
}
736731

737732
static ssize_t show_energy_performance_preference(

0 commit comments

Comments
 (0)