Skip to content

Commit a240c4a

Browse files
committed
cpufreq: intel_pstate: Do not reinit performance limits in ->setpolicy
If the current P-state selection algorithm is set to "performance" in intel_pstate_set_policy(), the limits may be initialized from scratch, but only if no_turbo is not set and the maximum frequency allowed for the given CPU (i.e. the policy object representing it) is at least equal to the max frequency supported by the CPU. In all of the other cases, the limits will not be updated. For example, the following can happen: # cat intel_pstate/status active # echo performance > cpufreq/policy0/scaling_governor # cat intel_pstate/min_perf_pct 100 # echo 94 > intel_pstate/min_perf_pct # cat intel_pstate/min_perf_pct 100 # cat cpufreq/policy0/scaling_max_freq 3100000 echo 3000000 > cpufreq/policy0/scaling_max_freq # cat intel_pstate/min_perf_pct 94 # echo 95 > intel_pstate/min_perf_pct # cat intel_pstate/min_perf_pct 95 That is confusing for two reasons. First, the initial attempt to change min_perf_pct to 94 seems to have no effect, even though setting the global limits should always work. Second, after changing scaling_max_freq for policy0 the global min_perf_pct attribute shows 94, even though it should have not been affected by that operation in principle. Moreover, the final attempt to change min_perf_pct to 95 worked as expected, because scaling_max_freq for the only policy with scaling_governor equal to "performance" was different from the maximum at that time. To make all that confusion go away, modify intel_pstate_set_policy() so that it doesn't reinitialize the limits at all. At the same time, change intel_pstate_set_performance_limits() to set min_sysfs_pct to 100 in the "performance" limits set so that switching the P-state selection algorithm to "performance" causes intel_pstate/min_perf_pct in sysfs to go to 100 (or whatever value min_sysfs_pct in the "performance" limits is set to later). That requires per-CPU limits to be initialized explicitly rather than by copying the global limits to avoid setting min_sysfs_pct in the per-CPU limits to 100. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent d74b199 commit a240c4a

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

drivers/cpufreq/intel_pstate.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ static void intel_pstate_set_performance_limits(struct perf_limits *limits)
382382
intel_pstate_init_limits(limits);
383383
limits->min_perf_pct = 100;
384384
limits->min_perf = int_ext_tofp(1);
385+
limits->min_sysfs_pct = 100;
385386
}
386387

387388
static DEFINE_MUTEX(intel_pstate_driver_lock);
@@ -2146,16 +2147,11 @@ static int intel_pstate_set_policy(struct cpufreq_policy *policy)
21462147
mutex_lock(&intel_pstate_limits_lock);
21472148

21482149
if (policy->policy == CPUFREQ_POLICY_PERFORMANCE) {
2150+
pr_debug("set performance\n");
21492151
if (!perf_limits) {
21502152
limits = &performance_limits;
21512153
perf_limits = limits;
21522154
}
2153-
if (policy->max >= policy->cpuinfo.max_freq &&
2154-
!limits->no_turbo) {
2155-
pr_debug("set performance\n");
2156-
intel_pstate_set_performance_limits(perf_limits);
2157-
goto out;
2158-
}
21592155
} else {
21602156
pr_debug("set powersave\n");
21612157
if (!perf_limits) {
@@ -2166,7 +2162,7 @@ static int intel_pstate_set_policy(struct cpufreq_policy *policy)
21662162
}
21672163

21682164
intel_pstate_update_perf_limits(policy, perf_limits);
2169-
out:
2165+
21702166
if (cpu->policy == CPUFREQ_POLICY_PERFORMANCE) {
21712167
/*
21722168
* NOHZ_FULL CPUs need this as the governor callback may not
@@ -2257,13 +2253,8 @@ static int __intel_pstate_cpu_init(struct cpufreq_policy *policy)
22572253

22582254
cpu = all_cpu_data[policy->cpu];
22592255

2260-
/*
2261-
* We need sane value in the cpu->perf_limits, so inherit from global
2262-
* perf_limits limits, which are seeded with values based on the
2263-
* CONFIG_CPU_FREQ_DEFAULT_GOV_*, during boot up.
2264-
*/
22652256
if (per_cpu_limits)
2266-
memcpy(cpu->perf_limits, limits, sizeof(struct perf_limits));
2257+
intel_pstate_init_limits(cpu->perf_limits);
22672258

22682259
policy->min = cpu->pstate.min_pstate * cpu->pstate.scaling;
22692260
policy->max = cpu->pstate.turbo_pstate * cpu->pstate.scaling;

0 commit comments

Comments
 (0)