Skip to content

Commit 3000ce3

Browse files
committed
cpufreq: Use per-policy frequency QoS
Replace the CPU device PM QoS used for the management of min and max frequency constraints in cpufreq (and its users) with per-policy frequency QoS to avoid problems with cpufreq policies covering more then one CPU. Namely, a cpufreq driver is registered with the subsys interface which calls cpufreq_add_dev() for each CPU, starting from CPU0, so currently the PM QoS notifiers are added to the first CPU in the policy (i.e. CPU0 in the majority of cases). In turn, when the cpufreq driver is unregistered, the subsys interface doing that calls cpufreq_remove_dev() for each CPU, starting from CPU0, and the PM QoS notifiers are only removed when cpufreq_remove_dev() is called for the last CPU in the policy, say CPUx, which as a rule is not CPU0 if the policy covers more than one CPU. Then, the PM QoS notifiers cannot be removed, because CPUx does not have them, and they are still there in the device PM QoS notifiers list of CPU0, which prevents new PM QoS notifiers from being registered for CPU0 on the next attempt to register the cpufreq driver. The same issue occurs when the first CPU in the policy goes offline before unregistering the driver. After this change it does not matter which CPU is the policy CPU at the driver registration time and whether or not it is online all the time, because the frequency QoS is per policy and not per CPU. Fixes: 67d874c ("cpufreq: Register notifiers with the PM QoS framework") Reported-by: Dmitry Osipenko <digetx@gmail.com> Tested-by: Dmitry Osipenko <digetx@gmail.com> Reported-by: Sudeep Holla <sudeep.holla@arm.com> Tested-by: Sudeep Holla <sudeep.holla@arm.com> Diagnosed-by: Viresh Kumar <viresh.kumar@linaro.org> Link: https://lore.kernel.org/linux-pm/5ad2624194baa2f53acc1f1e627eb7684c577a19.1562210705.git.viresh.kumar@linaro.org/T/#md2d89e95906b8c91c15f582146173dce2e86e99f Link: https://lore.kernel.org/linux-pm/20191017094612.6tbkwoq4harsjcqv@vireshk-i7/T/#m30d48cc23b9a80467fbaa16e30f90b3828a5a29b Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
1 parent 77751a4 commit 3000ce3

10 files changed

Lines changed: 114 additions & 114 deletions

File tree

‎drivers/acpi/processor_driver.c‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,14 +290,13 @@ static int acpi_processor_notifier(struct notifier_block *nb,
290290
unsigned long event, void *data)
291291
{
292292
struct cpufreq_policy *policy = data;
293-
int cpu = policy->cpu;
294293

295294
if (event == CPUFREQ_CREATE_POLICY) {
296-
acpi_thermal_cpufreq_init(cpu);
297-
acpi_processor_ppc_init(cpu);
295+
acpi_thermal_cpufreq_init(policy);
296+
acpi_processor_ppc_init(policy);
298297
} else if (event == CPUFREQ_REMOVE_POLICY) {
299-
acpi_processor_ppc_exit(cpu);
300-
acpi_thermal_cpufreq_exit(cpu);
298+
acpi_processor_ppc_exit(policy);
299+
acpi_thermal_cpufreq_exit(policy);
301300
}
302301

303302
return 0;

‎drivers/acpi/processor_perflib.c‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ static int acpi_processor_get_platform_limit(struct acpi_processor *pr)
8181
pr->performance_platform_limit = (int)ppc;
8282

8383
if (ppc >= pr->performance->state_count ||
84-
unlikely(!dev_pm_qos_request_active(&pr->perflib_req)))
84+
unlikely(!freq_qos_request_active(&pr->perflib_req)))
8585
return 0;
8686

87-
ret = dev_pm_qos_update_request(&pr->perflib_req,
87+
ret = freq_qos_update_request(&pr->perflib_req,
8888
pr->performance->states[ppc].core_frequency * 1000);
8989
if (ret < 0) {
9090
pr_warn("Failed to update perflib freq constraint: CPU%d (%d)\n",
@@ -157,28 +157,28 @@ void acpi_processor_ignore_ppc_init(void)
157157
ignore_ppc = 0;
158158
}
159159

160-
void acpi_processor_ppc_init(int cpu)
160+
void acpi_processor_ppc_init(struct cpufreq_policy *policy)
161161
{
162+
int cpu = policy->cpu;
162163
struct acpi_processor *pr = per_cpu(processors, cpu);
163164
int ret;
164165

165166
if (!pr)
166167
return;
167168

168-
ret = dev_pm_qos_add_request(get_cpu_device(cpu),
169-
&pr->perflib_req, DEV_PM_QOS_MAX_FREQUENCY,
170-
INT_MAX);
169+
ret = freq_qos_add_request(&policy->constraints, &pr->perflib_req,
170+
FREQ_QOS_MAX, INT_MAX);
171171
if (ret < 0)
172172
pr_err("Failed to add freq constraint for CPU%d (%d)\n", cpu,
173173
ret);
174174
}
175175

176-
void acpi_processor_ppc_exit(int cpu)
176+
void acpi_processor_ppc_exit(struct cpufreq_policy *policy)
177177
{
178-
struct acpi_processor *pr = per_cpu(processors, cpu);
178+
struct acpi_processor *pr = per_cpu(processors, policy->cpu);
179179

180180
if (pr)
181-
dev_pm_qos_remove_request(&pr->perflib_req);
181+
freq_qos_remove_request(&pr->perflib_req);
182182
}
183183

184184
static int acpi_processor_get_performance_control(struct acpi_processor *pr)

‎drivers/acpi/processor_thermal.c‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ static int cpufreq_set_cur_state(unsigned int cpu, int state)
105105

106106
pr = per_cpu(processors, i);
107107

108-
if (unlikely(!dev_pm_qos_request_active(&pr->thermal_req)))
108+
if (unlikely(!freq_qos_request_active(&pr->thermal_req)))
109109
continue;
110110

111111
policy = cpufreq_cpu_get(i);
@@ -116,7 +116,7 @@ static int cpufreq_set_cur_state(unsigned int cpu, int state)
116116

117117
cpufreq_cpu_put(policy);
118118

119-
ret = dev_pm_qos_update_request(&pr->thermal_req, max_freq);
119+
ret = freq_qos_update_request(&pr->thermal_req, max_freq);
120120
if (ret < 0) {
121121
pr_warn("Failed to update thermal freq constraint: CPU%d (%d)\n",
122122
pr->id, ret);
@@ -125,28 +125,28 @@ static int cpufreq_set_cur_state(unsigned int cpu, int state)
125125
return 0;
126126
}
127127

128-
void acpi_thermal_cpufreq_init(int cpu)
128+
void acpi_thermal_cpufreq_init(struct cpufreq_policy *policy)
129129
{
130+
int cpu = policy->cpu;
130131
struct acpi_processor *pr = per_cpu(processors, cpu);
131132
int ret;
132133

133134
if (!pr)
134135
return;
135136

136-
ret = dev_pm_qos_add_request(get_cpu_device(cpu),
137-
&pr->thermal_req, DEV_PM_QOS_MAX_FREQUENCY,
138-
INT_MAX);
137+
ret = freq_qos_add_request(&policy->constraints, &pr->thermal_req,
138+
FREQ_QOS_MAX, INT_MAX);
139139
if (ret < 0)
140140
pr_err("Failed to add freq constraint for CPU%d (%d)\n", cpu,
141141
ret);
142142
}
143143

144-
void acpi_thermal_cpufreq_exit(int cpu)
144+
void acpi_thermal_cpufreq_exit(struct cpufreq_policy *policy)
145145
{
146-
struct acpi_processor *pr = per_cpu(processors, cpu);
146+
struct acpi_processor *pr = per_cpu(processors, policy->cpu);
147147

148148
if (pr)
149-
dev_pm_qos_remove_request(&pr->thermal_req);
149+
freq_qos_remove_request(&pr->thermal_req);
150150
}
151151
#else /* ! CONFIG_CPU_FREQ */
152152
static int cpufreq_get_max_state(unsigned int cpu)

‎drivers/cpufreq/cpufreq.c‎

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ static ssize_t store_##file_name \
720720
if (ret != 1) \
721721
return -EINVAL; \
722722
\
723-
ret = dev_pm_qos_update_request(policy->object##_freq_req, val);\
723+
ret = freq_qos_update_request(policy->object##_freq_req, val);\
724724
return ret >= 0 ? count : ret; \
725725
}
726726

@@ -1202,19 +1202,21 @@ static struct cpufreq_policy *cpufreq_policy_alloc(unsigned int cpu)
12021202
goto err_free_real_cpus;
12031203
}
12041204

1205+
freq_constraints_init(&policy->constraints);
1206+
12051207
policy->nb_min.notifier_call = cpufreq_notifier_min;
12061208
policy->nb_max.notifier_call = cpufreq_notifier_max;
12071209

1208-
ret = dev_pm_qos_add_notifier(dev, &policy->nb_min,
1209-
DEV_PM_QOS_MIN_FREQUENCY);
1210+
ret = freq_qos_add_notifier(&policy->constraints, FREQ_QOS_MIN,
1211+
&policy->nb_min);
12101212
if (ret) {
12111213
dev_err(dev, "Failed to register MIN QoS notifier: %d (%*pbl)\n",
12121214
ret, cpumask_pr_args(policy->cpus));
12131215
goto err_kobj_remove;
12141216
}
12151217

1216-
ret = dev_pm_qos_add_notifier(dev, &policy->nb_max,
1217-
DEV_PM_QOS_MAX_FREQUENCY);
1218+
ret = freq_qos_add_notifier(&policy->constraints, FREQ_QOS_MAX,
1219+
&policy->nb_max);
12181220
if (ret) {
12191221
dev_err(dev, "Failed to register MAX QoS notifier: %d (%*pbl)\n",
12201222
ret, cpumask_pr_args(policy->cpus));
@@ -1232,8 +1234,8 @@ static struct cpufreq_policy *cpufreq_policy_alloc(unsigned int cpu)
12321234
return policy;
12331235

12341236
err_min_qos_notifier:
1235-
dev_pm_qos_remove_notifier(dev, &policy->nb_min,
1236-
DEV_PM_QOS_MIN_FREQUENCY);
1237+
freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MIN,
1238+
&policy->nb_min);
12371239
err_kobj_remove:
12381240
cpufreq_policy_put_kobj(policy);
12391241
err_free_real_cpus:
@@ -1250,7 +1252,6 @@ static struct cpufreq_policy *cpufreq_policy_alloc(unsigned int cpu)
12501252

12511253
static void cpufreq_policy_free(struct cpufreq_policy *policy)
12521254
{
1253-
struct device *dev = get_cpu_device(policy->cpu);
12541255
unsigned long flags;
12551256
int cpu;
12561257

@@ -1262,10 +1263,10 @@ static void cpufreq_policy_free(struct cpufreq_policy *policy)
12621263
per_cpu(cpufreq_cpu_data, cpu) = NULL;
12631264
write_unlock_irqrestore(&cpufreq_driver_lock, flags);
12641265

1265-
dev_pm_qos_remove_notifier(dev, &policy->nb_max,
1266-
DEV_PM_QOS_MAX_FREQUENCY);
1267-
dev_pm_qos_remove_notifier(dev, &policy->nb_min,
1268-
DEV_PM_QOS_MIN_FREQUENCY);
1266+
freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MAX,
1267+
&policy->nb_max);
1268+
freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MIN,
1269+
&policy->nb_min);
12691270

12701271
if (policy->max_freq_req) {
12711272
/*
@@ -1274,10 +1275,10 @@ static void cpufreq_policy_free(struct cpufreq_policy *policy)
12741275
*/
12751276
blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
12761277
CPUFREQ_REMOVE_POLICY, policy);
1277-
dev_pm_qos_remove_request(policy->max_freq_req);
1278+
freq_qos_remove_request(policy->max_freq_req);
12781279
}
12791280

1280-
dev_pm_qos_remove_request(policy->min_freq_req);
1281+
freq_qos_remove_request(policy->min_freq_req);
12811282
kfree(policy->min_freq_req);
12821283

12831284
cpufreq_policy_put_kobj(policy);
@@ -1357,8 +1358,6 @@ static int cpufreq_online(unsigned int cpu)
13571358
cpumask_and(policy->cpus, policy->cpus, cpu_online_mask);
13581359

13591360
if (new_policy) {
1360-
struct device *dev = get_cpu_device(cpu);
1361-
13621361
for_each_cpu(j, policy->related_cpus) {
13631362
per_cpu(cpufreq_cpu_data, j) = policy;
13641363
add_cpu_dev_symlink(policy, j);
@@ -1369,36 +1368,31 @@ static int cpufreq_online(unsigned int cpu)
13691368
if (!policy->min_freq_req)
13701369
goto out_destroy_policy;
13711370

1372-
ret = dev_pm_qos_add_request(dev, policy->min_freq_req,
1373-
DEV_PM_QOS_MIN_FREQUENCY,
1374-
policy->min);
1371+
ret = freq_qos_add_request(&policy->constraints,
1372+
policy->min_freq_req, FREQ_QOS_MIN,
1373+
policy->min);
13751374
if (ret < 0) {
13761375
/*
1377-
* So we don't call dev_pm_qos_remove_request() for an
1376+
* So we don't call freq_qos_remove_request() for an
13781377
* uninitialized request.
13791378
*/
13801379
kfree(policy->min_freq_req);
13811380
policy->min_freq_req = NULL;
1382-
1383-
dev_err(dev, "Failed to add min-freq constraint (%d)\n",
1384-
ret);
13851381
goto out_destroy_policy;
13861382
}
13871383

13881384
/*
13891385
* This must be initialized right here to avoid calling
1390-
* dev_pm_qos_remove_request() on uninitialized request in case
1386+
* freq_qos_remove_request() on uninitialized request in case
13911387
* of errors.
13921388
*/
13931389
policy->max_freq_req = policy->min_freq_req + 1;
13941390

1395-
ret = dev_pm_qos_add_request(dev, policy->max_freq_req,
1396-
DEV_PM_QOS_MAX_FREQUENCY,
1397-
policy->max);
1391+
ret = freq_qos_add_request(&policy->constraints,
1392+
policy->max_freq_req, FREQ_QOS_MAX,
1393+
policy->max);
13981394
if (ret < 0) {
13991395
policy->max_freq_req = NULL;
1400-
dev_err(dev, "Failed to add max-freq constraint (%d)\n",
1401-
ret);
14021396
goto out_destroy_policy;
14031397
}
14041398

@@ -2374,7 +2368,6 @@ int cpufreq_set_policy(struct cpufreq_policy *policy,
23742368
struct cpufreq_policy *new_policy)
23752369
{
23762370
struct cpufreq_governor *old_gov;
2377-
struct device *cpu_dev = get_cpu_device(policy->cpu);
23782371
int ret;
23792372

23802373
pr_debug("setting new policy for CPU %u: %u - %u kHz\n",
@@ -2386,8 +2379,8 @@ int cpufreq_set_policy(struct cpufreq_policy *policy,
23862379
* PM QoS framework collects all the requests from users and provide us
23872380
* the final aggregated value here.
23882381
*/
2389-
new_policy->min = dev_pm_qos_read_value(cpu_dev, DEV_PM_QOS_MIN_FREQUENCY);
2390-
new_policy->max = dev_pm_qos_read_value(cpu_dev, DEV_PM_QOS_MAX_FREQUENCY);
2382+
new_policy->min = freq_qos_read_value(&policy->constraints, FREQ_QOS_MIN);
2383+
new_policy->max = freq_qos_read_value(&policy->constraints, FREQ_QOS_MAX);
23912384

23922385
/* verify the cpu speed can be set within this limit */
23932386
ret = cpufreq_driver->verify(new_policy);
@@ -2518,7 +2511,7 @@ static int cpufreq_boost_set_sw(int state)
25182511
break;
25192512
}
25202513

2521-
ret = dev_pm_qos_update_request(policy->max_freq_req, policy->max);
2514+
ret = freq_qos_update_request(policy->max_freq_req, policy->max);
25222515
if (ret < 0)
25232516
break;
25242517
}

‎drivers/cpufreq/intel_pstate.c‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,10 +1088,10 @@ static ssize_t store_no_turbo(struct kobject *a, struct kobj_attribute *b,
10881088

10891089
static struct cpufreq_driver intel_pstate;
10901090

1091-
static void update_qos_request(enum dev_pm_qos_req_type type)
1091+
static void update_qos_request(enum freq_qos_req_type type)
10921092
{
10931093
int max_state, turbo_max, freq, i, perf_pct;
1094-
struct dev_pm_qos_request *req;
1094+
struct freq_qos_request *req;
10951095
struct cpufreq_policy *policy;
10961096

10971097
for_each_possible_cpu(i) {
@@ -1112,7 +1112,7 @@ static void update_qos_request(enum dev_pm_qos_req_type type)
11121112
else
11131113
turbo_max = cpu->pstate.turbo_pstate;
11141114

1115-
if (type == DEV_PM_QOS_MIN_FREQUENCY) {
1115+
if (type == FREQ_QOS_MIN) {
11161116
perf_pct = global.min_perf_pct;
11171117
} else {
11181118
req++;
@@ -1122,7 +1122,7 @@ static void update_qos_request(enum dev_pm_qos_req_type type)
11221122
freq = DIV_ROUND_UP(turbo_max * perf_pct, 100);
11231123
freq *= cpu->pstate.scaling;
11241124

1125-
if (dev_pm_qos_update_request(req, freq) < 0)
1125+
if (freq_qos_update_request(req, freq) < 0)
11261126
pr_warn("Failed to update freq constraint: CPU%d\n", i);
11271127
}
11281128
}
@@ -1153,7 +1153,7 @@ static ssize_t store_max_perf_pct(struct kobject *a, struct kobj_attribute *b,
11531153
if (intel_pstate_driver == &intel_pstate)
11541154
intel_pstate_update_policies();
11551155
else
1156-
update_qos_request(DEV_PM_QOS_MAX_FREQUENCY);
1156+
update_qos_request(FREQ_QOS_MAX);
11571157

11581158
mutex_unlock(&intel_pstate_driver_lock);
11591159

@@ -1187,7 +1187,7 @@ static ssize_t store_min_perf_pct(struct kobject *a, struct kobj_attribute *b,
11871187
if (intel_pstate_driver == &intel_pstate)
11881188
intel_pstate_update_policies();
11891189
else
1190-
update_qos_request(DEV_PM_QOS_MIN_FREQUENCY);
1190+
update_qos_request(FREQ_QOS_MIN);
11911191

11921192
mutex_unlock(&intel_pstate_driver_lock);
11931193

@@ -2381,7 +2381,7 @@ static unsigned int intel_cpufreq_fast_switch(struct cpufreq_policy *policy,
23812381
static int intel_cpufreq_cpu_init(struct cpufreq_policy *policy)
23822382
{
23832383
int max_state, turbo_max, min_freq, max_freq, ret;
2384-
struct dev_pm_qos_request *req;
2384+
struct freq_qos_request *req;
23852385
struct cpudata *cpu;
23862386
struct device *dev;
23872387

@@ -2416,15 +2416,15 @@ static int intel_cpufreq_cpu_init(struct cpufreq_policy *policy)
24162416
max_freq = DIV_ROUND_UP(turbo_max * global.max_perf_pct, 100);
24172417
max_freq *= cpu->pstate.scaling;
24182418

2419-
ret = dev_pm_qos_add_request(dev, req, DEV_PM_QOS_MIN_FREQUENCY,
2420-
min_freq);
2419+
ret = freq_qos_add_request(&policy->constraints, req, FREQ_QOS_MIN,
2420+
min_freq);
24212421
if (ret < 0) {
24222422
dev_err(dev, "Failed to add min-freq constraint (%d)\n", ret);
24232423
goto free_req;
24242424
}
24252425

2426-
ret = dev_pm_qos_add_request(dev, req + 1, DEV_PM_QOS_MAX_FREQUENCY,
2427-
max_freq);
2426+
ret = freq_qos_add_request(&policy->constraints, req + 1, FREQ_QOS_MAX,
2427+
max_freq);
24282428
if (ret < 0) {
24292429
dev_err(dev, "Failed to add max-freq constraint (%d)\n", ret);
24302430
goto remove_min_req;
@@ -2435,7 +2435,7 @@ static int intel_cpufreq_cpu_init(struct cpufreq_policy *policy)
24352435
return 0;
24362436

24372437
remove_min_req:
2438-
dev_pm_qos_remove_request(req);
2438+
freq_qos_remove_request(req);
24392439
free_req:
24402440
kfree(req);
24412441
pstate_exit:
@@ -2446,12 +2446,12 @@ static int intel_cpufreq_cpu_init(struct cpufreq_policy *policy)
24462446

24472447
static int intel_cpufreq_cpu_exit(struct cpufreq_policy *policy)
24482448
{
2449-
struct dev_pm_qos_request *req;
2449+
struct freq_qos_request *req;
24502450

24512451
req = policy->driver_data;
24522452

2453-
dev_pm_qos_remove_request(req + 1);
2454-
dev_pm_qos_remove_request(req);
2453+
freq_qos_remove_request(req + 1);
2454+
freq_qos_remove_request(req);
24552455
kfree(req);
24562456

24572457
return intel_pstate_cpu_exit(policy);

0 commit comments

Comments
 (0)