LKML Archive on lore.kernel.org
 help / Atom feed
* [PATCH 0/2] cpufreq: Allow light-weight tear down on CPU offline
@ 2019-02-11  8:41 Viresh Kumar
  2019-02-11  8:41 ` [PATCH 1/2] cpufreq: Allow light-weight tear down on CPU offline operation Viresh Kumar
  2019-02-11  8:41 ` [PATCH 2/2] cpufreq: dt: Implement light_weight_exit() callback Viresh Kumar
  0 siblings, 2 replies; 5+ messages in thread
From: Viresh Kumar @ 2019-02-11  8:41 UTC (permalink / raw)
  To: Rafael Wysocki
  Cc: Viresh Kumar, linux-pm, Vincent Guittot, Sudeep Holla,
	Marek Szyprowski, linux-kernel

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(-)

-- 
2.20.1.321.g9e740568ce00


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] cpufreq: Allow light-weight tear down on CPU offline operation
  2019-02-11  8:41 [PATCH 0/2] cpufreq: Allow light-weight tear down on CPU offline Viresh Kumar
@ 2019-02-11  8:41 ` Viresh Kumar
  2019-02-11 10:51   ` Rafael J. Wysocki
  2019-02-11  8:41 ` [PATCH 2/2] cpufreq: dt: Implement light_weight_exit() callback Viresh Kumar
  1 sibling, 1 reply; 5+ messages in thread
From: Viresh Kumar @ 2019-02-11  8:41 UTC (permalink / raw)
  To: Rafael Wysocki
  Cc: Viresh Kumar, linux-pm, Vincent Guittot, Sudeep Holla,
	Marek Szyprowski, linux-kernel

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.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/cpufreq/cpufreq.c | 16 +++++++++++-----
 include/linux/cpufreq.h   |  1 +
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 96a69c67a545..215a8bfc78bb 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -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);
+	}
 }
 
 /**
diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
index 9db074ecbbd7..36ce31516041 100644
--- a/include/linux/cpufreq.h
+++ b/include/linux/cpufreq.h
@@ -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);
-- 
2.20.1.321.g9e740568ce00


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/2] cpufreq: dt: Implement light_weight_exit() callback
  2019-02-11  8:41 [PATCH 0/2] cpufreq: Allow light-weight tear down on CPU offline Viresh Kumar
  2019-02-11  8:41 ` [PATCH 1/2] cpufreq: Allow light-weight tear down on CPU offline operation Viresh Kumar
@ 2019-02-11  8:41 ` Viresh Kumar
  1 sibling, 0 replies; 5+ messages in thread
From: Viresh Kumar @ 2019-02-11  8:41 UTC (permalink / raw)
  To: Rafael Wysocki
  Cc: Viresh Kumar, linux-pm, Vincent Guittot, Sudeep Holla,
	Marek Szyprowski, linux-kernel

Implement the light-weight tear down helper to reduce the amount of work
to do on CPU offline/online operation.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/cpufreq/cpufreq-dt.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c
index 7ba392911cd0..69309a8121f0 100644
--- a/drivers/cpufreq/cpufreq-dt.c
+++ b/drivers/cpufreq/cpufreq-dt.c
@@ -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,
-- 
2.20.1.321.g9e740568ce00


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] cpufreq: Allow light-weight tear down on CPU offline operation
  2019-02-11  8:41 ` [PATCH 1/2] cpufreq: Allow light-weight tear down on CPU offline operation Viresh Kumar
@ 2019-02-11 10:51   ` Rafael J. Wysocki
  2019-02-11 10:56     ` Rafael J. Wysocki
  0 siblings, 1 reply; 5+ messages in thread
From: Rafael J. Wysocki @ 2019-02-11 10:51 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Rafael Wysocki, Linux PM, Vincent Guittot, Sudeep Holla,
	Marek Szyprowski, Linux Kernel Mailing List

On Mon, Feb 11, 2019 at 9:41 AM Viresh Kumar <viresh.kumar@linaro.org> wrote:
>
> 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.
>
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> ---
>  drivers/cpufreq/cpufreq.c | 16 +++++++++++-----
>  include/linux/cpufreq.h   |  1 +
>  2 files changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index 96a69c67a545..215a8bfc78bb 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -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);
> +       }
>  }
>
>  /**
> diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
> index 9db074ecbbd7..36ce31516041 100644
> --- a/include/linux/cpufreq.h
> +++ b/include/linux/cpufreq.h
> @@ -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"?

>         int             (*exit)(struct cpufreq_policy *policy);
>         void            (*stop_cpu)(struct cpufreq_policy *policy);
>         int             (*suspend)(struct cpufreq_policy *policy);
> --

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] cpufreq: Allow light-weight tear down on CPU offline operation
  2019-02-11 10:51   ` Rafael J. Wysocki
@ 2019-02-11 10:56     ` Rafael J. Wysocki
  0 siblings, 0 replies; 5+ messages in thread
From: Rafael J. Wysocki @ 2019-02-11 10:56 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Rafael Wysocki, Linux PM, Vincent Guittot, Sudeep Holla,
	Marek Szyprowski, Linux Kernel Mailing List

On Mon, Feb 11, 2019 at 11:51 AM Rafael J. Wysocki <rafael@kernel.org> wrote:
>
> On Mon, Feb 11, 2019 at 9:41 AM Viresh Kumar <viresh.kumar@linaro.org> wrote:
> >
> > 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.
> >
> > Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> > ---

[cut]

> > diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
> > index 9db074ecbbd7..36ce31516041 100644
> > --- a/include/linux/cpufreq.h
> > +++ b/include/linux/cpufreq.h
> > @@ -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"?
>
> >         int             (*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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, back to index

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-11  8:41 [PATCH 0/2] cpufreq: Allow light-weight tear down on CPU offline Viresh Kumar
2019-02-11  8:41 ` [PATCH 1/2] cpufreq: Allow light-weight tear down on CPU offline operation Viresh Kumar
2019-02-11 10:51   ` Rafael J. Wysocki
2019-02-11 10:56     ` Rafael J. Wysocki
2019-02-11  8:41 ` [PATCH 2/2] cpufreq: dt: Implement light_weight_exit() callback Viresh Kumar

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git
	git clone --mirror https://lore.kernel.org/lkml/7 lkml/git/7.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lore.kernel.org/lkml \
		linux-kernel@vger.kernel.org linux-kernel@archiver.kernel.org
	public-inbox-index lkml


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/ public-inbox