History

cpufreq: Allow light-weight tear down and bring up of CPUs

The cpufreq core doesn't remove the cpufreq policy anymore on CPU offline operation, rather that happens when the CPU device gets unregistered from the kernel. This allows faster recovery when the CPU comes back online. This is also very useful during system wide suspend/resume where we offline all non-boot CPUs during suspend and then bring them back on resume. This commit takes the same idea a step ahead to allow drivers to do light weight tear-down and bring-up during CPU offline and online operations. A new set of callbacks is introduced, online/offline(). online() gets called when the first CPU of an inactive policy is brought up and offline() gets called when all the CPUs of a policy are offlined. The existing init/exit() callback get called on policy creation/destruction. They also get called instead of online/offline() callbacks if the online/offline() callbacks aren't provided. This also moves around some code to get executed only for the new-policy case going forward.

Viresh Kumar committed 7 years ago

Commit 91a12e91 parent 97956072 files · +40 −20Browse files

Unified · Split

2 files
  1. drivers/cpufreq/cpufreq.c +38 −20
  2. include/linux/cpufreq.h +2 −0
drivers/cpufreq/cpufreq.c+38−20
@@ -1201,28 +1201,39 @@ static int cpufreq_online(unsigned int cpu) · 1200 unmodified lines
1201 return -ENOMEM;1201 return -ENOMEM;
1202 }1202 }
1203 1203
1204 cpumask_copy(policy->cpus, cpumask_of(cpu));1204 if (!new_policy && cpufreq_driver->online) {
1205 ret = cpufreq_driver->online(policy);
1206 if (ret) {
1207 pr_debug("%s: %d: initialization failed\n", __func__,
1208 __LINE__);
1209 goto out_exit_policy;
1210 }
1205 1211
1206 /* call driver. From then on the cpufreq must be able1212 /* Recover policy->cpus using related_cpus */
1207 * to accept all calls to ->verify and ->setpolicy for this CPU1213 cpumask_copy(policy->cpus, policy->related_cpus);
1208 */1214 } else {
1209 ret = cpufreq_driver->init(policy);1215 cpumask_copy(policy->cpus, cpumask_of(cpu));
1210 if (ret) {
1211 pr_debug("initialization failed\n");
1212 goto out_free_policy;
1213 }
1214 1216
1215 ret = cpufreq_table_validate_and_sort(policy);1217 /*
1216 if (ret)1218 * Call driver. From then on the cpufreq must be able
1217 goto out_exit_policy;1219 * to accept all calls to ->verify and ->setpolicy for this CPU.
1220 */
1221 ret = cpufreq_driver->init(policy);
1222 if (ret) {
1223 pr_debug("%s: %d: initialization failed\n", __func__,
1224 __LINE__);
1225 goto out_free_policy;
1226 }
1218 1227
1219 down_write(&policy->rwsem);1228 ret = cpufreq_table_validate_and_sort(policy);
1229 if (ret)
1230 goto out_exit_policy;
1220 1231
1221 if (new_policy) {
1222 /* related_cpus should at least include policy->cpus. */1232 /* related_cpus should at least include policy->cpus. */
1223 cpumask_copy(policy->related_cpus, policy->cpus);1233 cpumask_copy(policy->related_cpus, policy->cpus);
1224 }1234 }
1225 1235
1236 down_write(&policy->rwsem);
1226 /*1237 /*
1227 * affected cpus must always be the one, which are online. We aren't1238 * affected cpus must always be the one, which are online. We aren't
1228 * managing offline cpus here.1239 * managing offline cpus here.
@@ -1421,11 +1432,12 @@ static int cpufreq_offline(unsigned int cpu) · 192 unmodified lines
1421 cpufreq_exit_governor(policy);1432 cpufreq_exit_governor(policy);
1422 1433
1423 /*1434 /*
1424 * Perform the ->exit() even during light-weight tear-down,1435 * Perform the ->offline() during light-weight tear-down, as
1425 * since this is a core component, and is essential for the1436 * that allows fast recovery when the CPU comes back.
1426 * subsequent light-weight ->init() to succeed.
1427 */1437 */
1428 if (cpufreq_driver->exit) {1438 if (cpufreq_driver->offline) {
1439 cpufreq_driver->offline(policy);
1440 } else if (cpufreq_driver->exit) {
1429 cpufreq_driver->exit(policy);1441 cpufreq_driver->exit(policy);
1430 policy->freq_table = NULL;1442 policy->freq_table = NULL;
1431 }1443 }
@@ -1454,8 +1466,13 @@ static void cpufreq_remove_dev(struct device *dev, struct subsys_interface *sif) · 22 unmodified lines
1454 cpumask_clear_cpu(cpu, policy->real_cpus);1466 cpumask_clear_cpu(cpu, policy->real_cpus);
1455 remove_cpu_dev_symlink(policy, dev);1467 remove_cpu_dev_symlink(policy, dev);
1456 1468
1457 if (cpumask_empty(policy->real_cpus))1469 if (cpumask_empty(policy->real_cpus)) {
1470 /* We did light-weight exit earlier, do full tear down now */
1471 if (cpufreq_driver->offline)
1472 cpufreq_driver->exit(policy);
1473
1458 cpufreq_policy_free(policy);1474 cpufreq_policy_free(policy);
1475 }
1459}1476}
1460 1477
1461/**1478/**
@@ -2488,7 +2505,8 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data) · 1026 unmodified lines
2488 driver_data->target) ||2505 driver_data->target) ||
2489 (driver_data->setpolicy && (driver_data->target_index ||2506 (driver_data->setpolicy && (driver_data->target_index ||
2490 driver_data->target)) ||2507 driver_data->target)) ||
2491 (!!driver_data->get_intermediate != !!driver_data->target_intermediate))2508 (!!driver_data->get_intermediate != !!driver_data->target_intermediate) ||
2509 (!driver_data->online != !driver_data->offline))
2492 return -EINVAL;2510 return -EINVAL;
2493 2511
2494 pr_debug("trying to register driver %s\n", driver_data->name);2512 pr_debug("trying to register driver %s\n", driver_data->name);
include/linux/cpufreq.h+2−0
@@ -325,6 +325,8 @@ struct cpufreq_driver { · 324 unmodified lines
325 /* optional */325 /* optional */
326 int (*bios_limit)(int cpu, unsigned int *limit);326 int (*bios_limit)(int cpu, unsigned int *limit);
327 327
328 int (*online)(struct cpufreq_policy *policy);
329 int (*offline)(struct cpufreq_policy *policy);
328 int (*exit)(struct cpufreq_policy *policy);330 int (*exit)(struct cpufreq_policy *policy);
329 void (*stop_cpu)(struct cpufreq_policy *policy);331 void (*stop_cpu)(struct cpufreq_policy *policy);
330 int (*suspend)(struct cpufreq_policy *policy);332 int (*suspend)(struct cpufreq_policy *policy);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t