cpufreq: Allow light-weight tear down on CPU offline
Viresh Kumar
maintainercover cpufreq: Allow light-weight tear down on CPU offline
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 patcset takes the same idea a step ahead to allow drivers to do light weight tear-down during CPU offline operation and updates the cpufreq-dt driver to implement the new helper.
Viresh Kumar (2):
cpufreq: Allow light-weight tear down on CPU offline operation
cpufreq: dt: Implement light_weight_exit() callback
drivers/cpufreq/cpufreq-dt.c | 19 +++++++++++++++++++ drivers/cpufreq/cpufreq.c | 16 +++++++++++----- include/linux/cpufreq.h | 1 + 3 files changed, 31 insertions(+), 5 deletions(-)
Signature · 1 line
2.20.1.321.g9e740568ce00
Viresh Kumar
maintainerPATCH 1/2 cpufreq: Allow light-weight tear down on CPU offline operation
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 during CPU offline operation.
A new callback is introduced, light_weight_exit(), which gets called when all the CPUs of a policy are removed/offlined and the existing exit() callback gets called when the policy gets freed.
--- drivers/cpufreq/cpufreq.c | 16 +++++++++++----- include/linux/cpufreq.h | 1 + 2 files changed, 12 insertions(+), 5 deletions(-)
drivers/cpufreq/cpufreq.c +11 -5
@@ -1421,11 +1421,12 @@ static int cpufreq_offline(unsigned int cpu)cpufreq_exit_governor (policy);/* -* Perform the ->exit() even during light-weight tear-down, -* since this is a core component, and is essential for the -* subsequent light-weight ->init() to succeed. +* Perform the ->light_weight_exit() during light-weight tear-down, as +* that allows fast recovery when the CPU comes back. */ -if (cpufreq_driver->exit) { +if (cpufreq_driver->light_weight_exit) { + cpufreq_driver->light_weight_exit (policy); + }else if (cpufreq_driver->exit) { cpufreq_driver->exit (policy); policy->freq_table =NULL ; }
@@ -1454,8 +1455,13 @@ static void cpufreq_remove_dev(struct device *dev, struct subsys_interface *sif)cpumask_clear_cpu (cpu, policy->real_cpus);remove_cpu_dev_symlink (policy, dev); -if (cpumask_empty (policy->real_cpus)) +if (cpumask_empty (policy->real_cpus)) { +/* We did light-weight exit earlier, do full tear down now */ +if (cpufreq_driver->light_weight_exit) + cpufreq_driver->exit (policy); +cpufreq_policy_free (policy); + } }/**
include/linux/cpufreq.h +1 -0
@@ -325,6 +325,7 @@ struct cpufreq_driver {/* optional */ int (*bios_limit)(int cpu,unsigned int *limit); +int (*light_weight_exit)(struct cpufreq_policy *policy);int (*exit)(struct cpufreq_policy *policy);void (*stop_cpu)(struct cpufreq_policy *policy);int (*suspend)(struct cpufreq_policy *policy);
Signature · 1 line
2.20.1.321.g9e740568ce00
Rafael J. Wysocki
maintainerRe: [PATCH 1/2] cpufreq: Allow light-weight tear down on CPU offline operation
Quoted 62 lines · Viresh Kumar
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 during CPU offline operation.
A new callback is introduced,
light_weight_exit(), which gets called when all the CPUs of a policy are removed/offlined and the existingexit()callback gets called when the policy gets freed.Signed-off-by Viresh Kumar <[email protected]>--- drivers/cpufreq/cpufreq.c | 16 +++++++++++----- include/linux/cpufreq.h | 1 + 2 files changed, 12 insertions(+), 5 deletions(-)drivers/cpufreq/cpufreq.c +11
-5@@ -1421,11 +1421,12 @@ static int cpufreq_offline(unsigned int cpu)cpufreq_exit_governor (policy);/* -* Perform the ->exit() even during light-weight tear-down, -* since this is a core component, and is essential for the -* subsequent light-weight ->init() to succeed. +* Perform the ->light_weight_exit() during light-weight tear-down, as +* that allows fast recovery when the CPU comes back. */ -if (cpufreq_driver->exit) { +if (cpufreq_driver->light_weight_exit) { + cpufreq_driver->light_weight_exit (policy); + }else if (cpufreq_driver->exit) { cpufreq_driver->exit (policy); policy->freq_table =NULL ; }@@ -1454,8 +1455,13 @@ static void cpufreq_remove_dev(struct device *dev, struct subsys_interface *sif)cpumask_clear_cpu (cpu, policy->real_cpus);remove_cpu_dev_symlink (policy, dev); -if (cpumask_empty (policy->real_cpus)) +if (cpumask_empty (policy->real_cpus)) { +/* We did light-weight exit earlier, do full tear down now */ +if (cpufreq_driver->light_weight_exit) + cpufreq_driver->exit (policy); +cpufreq_policy_free (policy); + } }/** include/linux/cpufreq.h +0
-0
include/linux/cpufreq.h struct cpufreq_driver { · line 328
Quoted 4 lines
include/linux/cpufreq.h +1
-0@@ -325,6 +325,7 @@ struct cpufreq_driver {/* optional */ int (*bios_limit)(int cpu,unsigned int *limit); +int (*light_weight_exit)(struct cpufreq_policy *policy);
Can you call it "offline"?
Quoted 4 lines
include/linux/cpufreq.h +0
-1int (*exit)(struct cpufreq_policy *policy);void (*stop_cpu)(struct cpufreq_policy *policy);int (*suspend)(struct cpufreq_policy *policy); --
Rafael J. Wysocki
maintainerRe: [PATCH 1/2] cpufreq: Allow light-weight tear down on CPU offline operation
Quoted 19 lines · Rafael J. Wysocki
Quoted 17 lines · Viresh Kumar
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 during CPU offline operation.
A new callback is introduced,
light_weight_exit(), which gets called when all the CPUs of a policy are removed/offlined and the existingexit()callback gets called when the policy gets freed.Signed-off-by Viresh Kumar <[email protected]>---
[cut]
Quoted 8 lines
Quoted 8 lines
include/linux/cpufreq.h +0
-0@@ -325,6 +325,7 @@ struct cpufreq_driver {/* optional */ int (*bios_limit)(int cpu,unsigned int *limit);
Quoted 8 lines
include/linux/cpufreq.h struct cpufreq_driver { · line 328
Quoted 1 line
include/linux/cpufreq.h +1
-0+int (*light_weight_exit)(struct cpufreq_policy *policy);Can you call it "offline"?
Quoted 4 lines
include/linux/cpufreq.h +0
-1int (*exit)(struct cpufreq_policy *policy);void (*stop_cpu)(struct cpufreq_policy *policy);int (*suspend)(struct cpufreq_policy *policy); --
Also, I would prefer a corresponding "online" callback to be there too for symmetry and I'd prefer the core to decide to call "online" instead of "init" for the light-weight case instead of ->init() itself having to figure out the context.
Viresh Kumar
maintainerPATCH 2/2 cpufreq: dt: Implement light_weight_exit() callback
In reply to Viresh KumarImplement the light-weight tear down helper to reduce the amount of work to do on CPU offline/online operation.
--- drivers/cpufreq/cpufreq-dt.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
drivers/cpufreq/cpufreq-dt.c +19 -0
@@ -160,6 +160,15 @@ static int cpufreq_init(struct cpufreq_policy *policy)const char *name;int ret; +/* +* We did light-weight shutdown earlier, nothing else to initialize here +* apart from policy->cpus. +*/ +if (policy->driver_data) { +cpumask_copy (policy->cpus, policy->related_cpus); +return 0 ; + } + cpu_dev =get_cpu_device (policy->cpu);if (!cpu_dev) {pr_err ("failed to get cpu%d device\n" , policy->cpu);
@@ -295,6 +304,15 @@ static int cpufreq_init(struct cpufreq_policy *policy)return ret; } +static int cpufreq_light_weight_exit (struct cpufreq_policy *policy) +{ +/* +* Preserve policy->driver_data and don't free resources on light-weight +* tear down. +*/ +return 0 ; +} +static int cpufreq_exit (struct cpufreq_policy *policy) {struct private_data *priv = policy->driver_data;
@@ -319,6 +337,7 @@ static struct cpufreq_driver dt_cpufreq_driver = { .get = cpufreq_generic_get, .init = cpufreq_init, .exit = cpufreq_exit, + .light_weight_exit = cpufreq_light_weight_exit, .name = "cpufreq-dt", .attr = cpufreq_dt_attr, .suspend = cpufreq_generic_suspend,
Signature · 1 line
2.20.1.321.g9e740568ce00