Skip to content

Commit eaff6b6

Browse files
committed
cpufreq: Pass policy pointer to ->update_limits()
Since cpufreq_update_limits() obtains a cpufreq policy pointer for the given CPU and reference counts the corresponding policy object, it may as well pass the policy pointer to the cpufreq driver's ->update_limits() callback which allows that callback to avoid invoking cpufreq_cpu_get() for the same CPU. Accordingly, redefine ->update_limits() to take a policy pointer instead of a CPU number and update both drivers implementing it, intel_pstate and amd-pstate, as needed. Signed-off-by: Rafael J. Wysocki <[email protected]> Acked-by: Viresh Kumar <[email protected]> Reviewed-by: Mario Limonciello <[email protected]> Acked-by: Srinivas Pandruvada <[email protected]> Acked-by: Sudeep Holla <[email protected]> Tested-by: Sudeep Holla <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent 684e185 commit eaff6b6

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

drivers/cpufreq/amd-pstate.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -821,19 +821,16 @@ static void amd_pstate_init_prefcore(struct amd_cpudata *cpudata)
821821
schedule_work(&sched_prefcore_work);
822822
}
823823

824-
static void amd_pstate_update_limits(unsigned int cpu)
824+
static void amd_pstate_update_limits(struct cpufreq_policy *policy)
825825
{
826-
struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(cpu);
827826
struct amd_cpudata *cpudata;
828827
u32 prev_high = 0, cur_high = 0;
829828
bool highest_perf_changed = false;
829+
unsigned int cpu = policy->cpu;
830830

831831
if (!amd_pstate_prefcore)
832832
return;
833833

834-
if (!policy)
835-
return;
836-
837834
if (amd_get_highest_perf(cpu, &cur_high))
838835
return;
839836

drivers/cpufreq/cpufreq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2769,7 +2769,7 @@ void cpufreq_update_limits(unsigned int cpu)
27692769
return;
27702770

27712771
if (cpufreq_driver->update_limits)
2772-
cpufreq_driver->update_limits(cpu);
2772+
cpufreq_driver->update_limits(policy);
27732773
else
27742774
cpufreq_policy_refresh(policy);
27752775
}

drivers/cpufreq/intel_pstate.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,14 +1353,9 @@ static void intel_pstate_update_policies(void)
13531353
cpufreq_update_policy(cpu);
13541354
}
13551355

1356-
static bool intel_pstate_update_max_freq(struct cpudata *cpudata)
1356+
static void __intel_pstate_update_max_freq(struct cpufreq_policy *policy,
1357+
struct cpudata *cpudata)
13571358
{
1358-
struct cpufreq_policy *policy __free(put_cpufreq_policy);
1359-
1360-
policy = cpufreq_cpu_get(cpudata->cpu);
1361-
if (!policy)
1362-
return false;
1363-
13641359
guard(cpufreq_policy_write)(policy);
13651360

13661361
if (hwp_active)
@@ -1370,16 +1365,28 @@ static bool intel_pstate_update_max_freq(struct cpudata *cpudata)
13701365
cpudata->pstate.max_freq : cpudata->pstate.turbo_freq;
13711366

13721367
refresh_frequency_limits(policy);
1368+
}
1369+
1370+
static bool intel_pstate_update_max_freq(struct cpudata *cpudata)
1371+
{
1372+
struct cpufreq_policy *policy __free(put_cpufreq_policy);
1373+
1374+
policy = cpufreq_cpu_get(cpudata->cpu);
1375+
if (!policy)
1376+
return false;
1377+
1378+
__intel_pstate_update_max_freq(policy, cpudata);
13731379

13741380
return true;
13751381
}
13761382

1377-
static void intel_pstate_update_limits(unsigned int cpu)
1383+
static void intel_pstate_update_limits(struct cpufreq_policy *policy)
13781384
{
1379-
struct cpudata *cpudata = all_cpu_data[cpu];
1385+
struct cpudata *cpudata = all_cpu_data[policy->cpu];
13801386

1381-
if (intel_pstate_update_max_freq(cpudata))
1382-
hybrid_update_capacity(cpudata);
1387+
__intel_pstate_update_max_freq(policy, cpudata);
1388+
1389+
hybrid_update_capacity(cpudata);
13831390
}
13841391

13851392
static void intel_pstate_update_limits_for_all(void)

include/linux/cpufreq.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ struct cpufreq_driver {
399399
unsigned int (*get)(unsigned int cpu);
400400

401401
/* Called to update policy limits on firmware notifications. */
402-
void (*update_limits)(unsigned int cpu);
402+
void (*update_limits)(struct cpufreq_policy *policy);
403403

404404
/* optional */
405405
int (*bios_limit)(int cpu, unsigned int *limit);

0 commit comments

Comments
 (0)