Skip to content

Commit 973207a

Browse files
committed
cpufreq: intel_pstate: Rearrange max frequency updates handling code
Rename __intel_pstate_update_max_freq() to intel_pstate_update_max_freq() and move the cpufreq policy reference counting and locking into it (and implement the locking with the recently introduced cpufreq policy "write" locking guard). No intentional functional impact. Signed-off-by: Rafael J. Wysocki <[email protected]> Reviewed-by: Mario Limonciello <[email protected]> Acked-by: Srinivas Pandruvada <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent 6fec833 commit 973207a

File tree

1 file changed

+17
-35
lines changed

1 file changed

+17
-35
lines changed

drivers/cpufreq/intel_pstate.c

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,54 +1353,41 @@ static void intel_pstate_update_policies(void)
13531353
cpufreq_update_policy(cpu);
13541354
}
13551355

1356-
static void __intel_pstate_update_max_freq(struct cpudata *cpudata,
1357-
struct cpufreq_policy *policy)
1356+
static bool intel_pstate_update_max_freq(struct cpudata *cpudata)
13581357
{
1358+
struct cpufreq_policy *policy __free(put_cpufreq_policy);
1359+
1360+
policy = cpufreq_cpu_get(cpudata->cpu);
1361+
if (!policy)
1362+
return false;
1363+
1364+
guard(cpufreq_policy_write)(policy);
1365+
13591366
if (hwp_active)
13601367
intel_pstate_get_hwp_cap(cpudata);
13611368

13621369
policy->cpuinfo.max_freq = READ_ONCE(global.no_turbo) ?
13631370
cpudata->pstate.max_freq : cpudata->pstate.turbo_freq;
13641371

13651372
refresh_frequency_limits(policy);
1373+
1374+
return true;
13661375
}
13671376

13681377
static void intel_pstate_update_limits(unsigned int cpu)
13691378
{
1370-
struct cpufreq_policy *policy = cpufreq_cpu_acquire(cpu);
1371-
struct cpudata *cpudata;
1372-
1373-
if (!policy)
1374-
return;
1375-
1376-
cpudata = all_cpu_data[cpu];
1377-
1378-
__intel_pstate_update_max_freq(cpudata, policy);
1379-
1380-
/* Prevent the driver from being unregistered now. */
1381-
mutex_lock(&intel_pstate_driver_lock);
1379+
struct cpudata *cpudata = all_cpu_data[cpu];
13821380

1383-
cpufreq_cpu_release(policy);
1384-
1385-
hybrid_update_capacity(cpudata);
1386-
1387-
mutex_unlock(&intel_pstate_driver_lock);
1381+
if (intel_pstate_update_max_freq(cpudata))
1382+
hybrid_update_capacity(cpudata);
13881383
}
13891384

13901385
static void intel_pstate_update_limits_for_all(void)
13911386
{
13921387
int cpu;
13931388

1394-
for_each_possible_cpu(cpu) {
1395-
struct cpufreq_policy *policy = cpufreq_cpu_acquire(cpu);
1396-
1397-
if (!policy)
1398-
continue;
1399-
1400-
__intel_pstate_update_max_freq(all_cpu_data[cpu], policy);
1401-
1402-
cpufreq_cpu_release(policy);
1403-
}
1389+
for_each_possible_cpu(cpu)
1390+
intel_pstate_update_max_freq(all_cpu_data[cpu]);
14041391

14051392
mutex_lock(&hybrid_capacity_lock);
14061393

@@ -1840,13 +1827,8 @@ static void intel_pstate_notify_work(struct work_struct *work)
18401827
{
18411828
struct cpudata *cpudata =
18421829
container_of(to_delayed_work(work), struct cpudata, hwp_notify_work);
1843-
struct cpufreq_policy *policy = cpufreq_cpu_acquire(cpudata->cpu);
1844-
1845-
if (policy) {
1846-
__intel_pstate_update_max_freq(cpudata, policy);
1847-
1848-
cpufreq_cpu_release(policy);
18491830

1831+
if (intel_pstate_update_max_freq(cpudata)) {
18501832
/*
18511833
* The driver will not be unregistered while this function is
18521834
* running, so update the capacity without acquiring the driver

0 commit comments

Comments
 (0)