2021-06-16 06:41:55

by Viresh Kumar

[permalink] [raw]
Subject: [PATCH V2 0/3] cpufreq: Migrate away from ->stop_cpu() callback

Hi Rafael,

Sending these separately from CPPC stuff to avoid unnecessary confusion and
independent merging of these patches. These should get in nevertheless.

commit 367dc4aa932b ("cpufreq: Add stop CPU callback to cpufreq_driver
interface") added the stop_cpu() callback to allow the drivers to do
clean up before the CPU is completely down and its state can't be
modified.

At that time the CPU hotplug framework used to call the cpufreq core's
registered notifier for different events like CPU_DOWN_PREPARE and
CPU_POST_DEAD. The stop_cpu() callback was called during the
CPU_DOWN_PREPARE event.

This is no longer the case, cpuhp_cpufreq_offline() is called only once
by the CPU hotplug core now and we don't really need two separate
callbacks for cpufreq drivers, i.e. stop_cpu() and exit(), as everything
can be done from the exit() callback itself.

Migrate to using the exit() callback instead of stop_cpu().

The stop_cpu() callback isn't removed from core as it will be reused in
a different way in a separate patchset.

--
Viresh

Viresh Kumar (3):
cpufreq: cppc: Migrate to ->exit() callback instead of ->stop_cpu()
cpufreq: intel_pstate: Migrate to ->exit() callback instead of
->stop_cpu()
cpufreq: powerenv: Migrate to ->exit() callback instead of
->stop_cpu()

drivers/cpufreq/cppc_cpufreq.c | 46 ++++++++++++++++---------------
drivers/cpufreq/intel_pstate.c | 9 +-----
drivers/cpufreq/powernv-cpufreq.c | 23 ++++++----------
3 files changed, 34 insertions(+), 44 deletions(-)

--
2.31.1.272.g89b43f80a514


2021-06-16 06:42:04

by Viresh Kumar

[permalink] [raw]
Subject: [PATCH V2 2/3] cpufreq: intel_pstate: Migrate to ->exit() callback instead of ->stop_cpu()

commit 367dc4aa932b ("cpufreq: Add stop CPU callback to cpufreq_driver
interface") added the stop_cpu() callback to allow the drivers to do
clean up before the CPU is completely down and its state can't be
modified.

At that time the CPU hotplug framework used to call the cpufreq core's
registered notifier for different events like CPU_DOWN_PREPARE and
CPU_POST_DEAD. The stop_cpu() callback was called during the
CPU_DOWN_PREPARE event.

This is no longer the case, cpuhp_cpufreq_offline() is called only once
by the CPU hotplug core now and we don't really need two separate
callbacks for cpufreq drivers, i.e. stop_cpu() and exit(), as everything
can be done from the exit() callback itself.

Migrate to using the exit() callback instead of stop_cpu().

Cc: Dirk Brandewie <[email protected]>
Signed-off-by: Viresh Kumar <[email protected]>
---
drivers/cpufreq/intel_pstate.c | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index 0e69dffd5a76..37ad42926904 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -2374,17 +2374,11 @@ static int intel_pstate_cpu_online(struct cpufreq_policy *policy)
return 0;
}

-static void intel_pstate_stop_cpu(struct cpufreq_policy *policy)
-{
- pr_debug("CPU %d stopping\n", policy->cpu);
-
- intel_pstate_clear_update_util_hook(policy->cpu);
-}
-
static int intel_pstate_cpu_exit(struct cpufreq_policy *policy)
{
pr_debug("CPU %d exiting\n", policy->cpu);

+ intel_pstate_clear_update_util_hook(policy->cpu);
policy->fast_switch_possible = false;

return 0;
@@ -2451,7 +2445,6 @@ static struct cpufreq_driver intel_pstate = {
.resume = intel_pstate_resume,
.init = intel_pstate_cpu_init,
.exit = intel_pstate_cpu_exit,
- .stop_cpu = intel_pstate_stop_cpu,
.offline = intel_pstate_cpu_offline,
.online = intel_pstate_cpu_online,
.update_limits = intel_pstate_update_limits,
--
2.31.1.272.g89b43f80a514

2021-06-16 06:42:40

by Viresh Kumar

[permalink] [raw]
Subject: [PATCH V2 3/3] cpufreq: powerenv: Migrate to ->exit() callback instead of ->stop_cpu()

commit 367dc4aa932b ("cpufreq: Add stop CPU callback to cpufreq_driver
interface") added the stop_cpu() callback to allow the drivers to do
clean up before the CPU is completely down and its state can't be
modified.

At that time the CPU hotplug framework used to call the cpufreq core's
registered notifier for different events like CPU_DOWN_PREPARE and
CPU_POST_DEAD. The stop_cpu() callback was called during the
CPU_DOWN_PREPARE event.

This is no longer the case, cpuhp_cpufreq_offline() is called only once
by the CPU hotplug core now and we don't really need two separate
callbacks for cpufreq drivers, i.e. stop_cpu() and exit(), as everything
can be done from the exit() callback itself.

Migrate to using the exit() callback instead of stop_cpu().

Signed-off-by: Viresh Kumar <[email protected]>
---
drivers/cpufreq/powernv-cpufreq.c | 23 +++++++++--------------
1 file changed, 9 insertions(+), 14 deletions(-)

diff --git a/drivers/cpufreq/powernv-cpufreq.c b/drivers/cpufreq/powernv-cpufreq.c
index e439b43c19eb..005600cef273 100644
--- a/drivers/cpufreq/powernv-cpufreq.c
+++ b/drivers/cpufreq/powernv-cpufreq.c
@@ -875,7 +875,15 @@ static int powernv_cpufreq_cpu_init(struct cpufreq_policy *policy)

static int powernv_cpufreq_cpu_exit(struct cpufreq_policy *policy)
{
- /* timer is deleted in cpufreq_cpu_stop() */
+ struct powernv_smp_call_data freq_data;
+ struct global_pstate_info *gpstates = policy->driver_data;
+
+ freq_data.pstate_id = idx_to_pstate(powernv_pstate_info.min);
+ freq_data.gpstate_id = idx_to_pstate(powernv_pstate_info.min);
+ smp_call_function_single(policy->cpu, set_pstate, &freq_data, 1);
+ if (gpstates)
+ del_timer_sync(&gpstates->timer);
+
kfree(policy->driver_data);

return 0;
@@ -1007,18 +1015,6 @@ static struct notifier_block powernv_cpufreq_opal_nb = {
.priority = 0,
};

-static void powernv_cpufreq_stop_cpu(struct cpufreq_policy *policy)
-{
- struct powernv_smp_call_data freq_data;
- struct global_pstate_info *gpstates = policy->driver_data;
-
- freq_data.pstate_id = idx_to_pstate(powernv_pstate_info.min);
- freq_data.gpstate_id = idx_to_pstate(powernv_pstate_info.min);
- smp_call_function_single(policy->cpu, set_pstate, &freq_data, 1);
- if (gpstates)
- del_timer_sync(&gpstates->timer);
-}
-
static unsigned int powernv_fast_switch(struct cpufreq_policy *policy,
unsigned int target_freq)
{
@@ -1042,7 +1038,6 @@ static struct cpufreq_driver powernv_cpufreq_driver = {
.target_index = powernv_cpufreq_target_index,
.fast_switch = powernv_fast_switch,
.get = powernv_cpufreq_get,
- .stop_cpu = powernv_cpufreq_stop_cpu,
.attr = powernv_cpu_freq_attr,
};

--
2.31.1.272.g89b43f80a514

2021-06-16 06:42:54

by Viresh Kumar

[permalink] [raw]
Subject: [PATCH V2 1/3] cpufreq: cppc: Migrate to ->exit() callback instead of ->stop_cpu()

commit 367dc4aa932b ("cpufreq: Add stop CPU callback to cpufreq_driver
interface") added the stop_cpu() callback to allow the drivers to do
clean up before the CPU is completely down and its state can't be
modified.

At that time the CPU hotplug framework used to call the cpufreq core's
registered notifier for different events like CPU_DOWN_PREPARE and
CPU_POST_DEAD. The stop_cpu() callback was called during the
CPU_DOWN_PREPARE event.

This is no longer the case, cpuhp_cpufreq_offline() is called only once
by the CPU hotplug core now and we don't really need two separate
callbacks for cpufreq drivers, i.e. stop_cpu() and exit(), as everything
can be done from the exit() callback itself.

Migrate to using the exit() callback instead of stop_cpu().

Signed-off-by: Viresh Kumar <[email protected]>
---
drivers/cpufreq/cppc_cpufreq.c | 46 ++++++++++++++++++----------------
1 file changed, 24 insertions(+), 22 deletions(-)

diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c
index 2f769b1630c5..be4f62e2c5f1 100644
--- a/drivers/cpufreq/cppc_cpufreq.c
+++ b/drivers/cpufreq/cppc_cpufreq.c
@@ -182,27 +182,6 @@ static int cppc_verify_policy(struct cpufreq_policy_data *policy)
return 0;
}

-static void cppc_cpufreq_stop_cpu(struct cpufreq_policy *policy)
-{
- struct cppc_cpudata *cpu_data = policy->driver_data;
- struct cppc_perf_caps *caps = &cpu_data->perf_caps;
- unsigned int cpu = policy->cpu;
- int ret;
-
- cpu_data->perf_ctrls.desired_perf = caps->lowest_perf;
-
- ret = cppc_set_perf(cpu, &cpu_data->perf_ctrls);
- if (ret)
- pr_debug("Err setting perf value:%d on CPU:%d. ret:%d\n",
- caps->lowest_perf, cpu, ret);
-
- /* Remove CPU node from list and free driver data for policy */
- free_cpumask_var(cpu_data->shared_cpu_map);
- list_del(&cpu_data->node);
- kfree(policy->driver_data);
- policy->driver_data = NULL;
-}
-
/*
* The PCC subspace describes the rate at which platform can accept commands
* on the shared PCC channel (including READs which do not count towards freq
@@ -352,6 +331,29 @@ static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy)
return ret;
}

+static int cppc_cpufreq_cpu_exit(struct cpufreq_policy *policy)
+{
+ struct cppc_cpudata *cpu_data = policy->driver_data;
+ struct cppc_perf_caps *caps = &cpu_data->perf_caps;
+ unsigned int cpu = policy->cpu;
+ int ret;
+
+ cpu_data->perf_ctrls.desired_perf = caps->lowest_perf;
+
+ ret = cppc_set_perf(cpu, &cpu_data->perf_ctrls);
+ if (ret)
+ pr_debug("Err setting perf value:%d on CPU:%d. ret:%d\n",
+ caps->lowest_perf, cpu, ret);
+
+ /* Remove CPU node from list and free driver data for policy */
+ free_cpumask_var(cpu_data->shared_cpu_map);
+ list_del(&cpu_data->node);
+ kfree(policy->driver_data);
+ policy->driver_data = NULL;
+
+ return 0;
+}
+
static inline u64 get_delta(u64 t1, u64 t0)
{
if (t1 > t0 || t0 > ~(u32)0)
@@ -451,7 +453,7 @@ static struct cpufreq_driver cppc_cpufreq_driver = {
.target = cppc_cpufreq_set_target,
.get = cppc_cpufreq_get_rate,
.init = cppc_cpufreq_cpu_init,
- .stop_cpu = cppc_cpufreq_stop_cpu,
+ .exit = cppc_cpufreq_cpu_exit,
.set_boost = cppc_cpufreq_set_boost,
.attr = cppc_cpufreq_attr,
.name = "cppc_cpufreq",
--
2.31.1.272.g89b43f80a514

2021-06-17 16:07:13

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH V2 2/3] cpufreq: intel_pstate: Migrate to ->exit() callback instead of ->stop_cpu()

On Wed, Jun 16, 2021 at 8:41 AM Viresh Kumar <[email protected]> wrote:
>
> commit 367dc4aa932b ("cpufreq: Add stop CPU callback to cpufreq_driver
> interface") added the stop_cpu() callback to allow the drivers to do
> clean up before the CPU is completely down and its state can't be
> modified.
>
> At that time the CPU hotplug framework used to call the cpufreq core's
> registered notifier for different events like CPU_DOWN_PREPARE and
> CPU_POST_DEAD. The stop_cpu() callback was called during the
> CPU_DOWN_PREPARE event.
>
> This is no longer the case, cpuhp_cpufreq_offline() is called only once
> by the CPU hotplug core now and we don't really need two separate
> callbacks for cpufreq drivers, i.e. stop_cpu() and exit(), as everything
> can be done from the exit() callback itself.
>
> Migrate to using the exit() callback instead of stop_cpu().
>
> Cc: Dirk Brandewie <[email protected]>
> Signed-off-by: Viresh Kumar <[email protected]>
> ---
> drivers/cpufreq/intel_pstate.c | 9 +--------
> 1 file changed, 1 insertion(+), 8 deletions(-)
>
> diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
> index 0e69dffd5a76..37ad42926904 100644
> --- a/drivers/cpufreq/intel_pstate.c
> +++ b/drivers/cpufreq/intel_pstate.c
> @@ -2374,17 +2374,11 @@ static int intel_pstate_cpu_online(struct cpufreq_policy *policy)
> return 0;
> }
>
> -static void intel_pstate_stop_cpu(struct cpufreq_policy *policy)
> -{
> - pr_debug("CPU %d stopping\n", policy->cpu);
> -
> - intel_pstate_clear_update_util_hook(policy->cpu);
> -}
> -
> static int intel_pstate_cpu_exit(struct cpufreq_policy *policy)
> {
> pr_debug("CPU %d exiting\n", policy->cpu);
>
> + intel_pstate_clear_update_util_hook(policy->cpu);

This addresses the ->exit case, but it doesn't address the ->offline
case AFAICS.

> policy->fast_switch_possible = false;
>
> return 0;
> @@ -2451,7 +2445,6 @@ static struct cpufreq_driver intel_pstate = {
> .resume = intel_pstate_resume,
> .init = intel_pstate_cpu_init,
> .exit = intel_pstate_cpu_exit,
> - .stop_cpu = intel_pstate_stop_cpu,
> .offline = intel_pstate_cpu_offline,
> .online = intel_pstate_cpu_online,
> .update_limits = intel_pstate_update_limits,
> --

2021-06-18 07:06:51

by Viresh Kumar

[permalink] [raw]
Subject: [PATCH V3 2/3] cpufreq: intel_pstate: Migrate away from ->stop_cpu() callback

commit 367dc4aa932b ("cpufreq: Add stop CPU callback to cpufreq_driver
interface") added the stop_cpu() callback to allow the drivers to do
clean up before the CPU is completely down and its state can't be
modified.

At that time the CPU hotplug framework used to call the cpufreq core's
registered notifier for different events like CPU_DOWN_PREPARE and
CPU_POST_DEAD. The stop_cpu() callback was called during the
CPU_DOWN_PREPARE event.

This is no longer the case, cpuhp_cpufreq_offline() is called only once
by the CPU hotplug core now and we don't really need to separately
call stop_cpu() for cpufreq drivers.

Migrate to using the exit() and offline() callbacks instead of
stop_cpu().

We need to clear util hook from both the callbacks, exit() and
offline(), since it is possible that only exit() gets called sometimes
(specially on errors) or both get called at other times.
intel_pstate_clear_update_util_hook() anyway have enough protection in
place if it gets called a second time and will return early then.

Cc: Dirk Brandewie <[email protected]>
Signed-off-by: Viresh Kumar <[email protected]>
---
V2->V3:
- Update intel_pstate_cpu_offline() as well.
- Improved commit log.

drivers/cpufreq/intel_pstate.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index 0e69dffd5a76..8f8a2d9d7daa 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -2335,6 +2335,8 @@ static int intel_pstate_cpu_offline(struct cpufreq_policy *policy)

pr_debug("CPU %d going offline\n", cpu->cpu);

+ intel_pstate_clear_update_util_hook(policy->cpu);
+
if (cpu->suspended)
return 0;

@@ -2374,17 +2376,12 @@ static int intel_pstate_cpu_online(struct cpufreq_policy *policy)
return 0;
}

-static void intel_pstate_stop_cpu(struct cpufreq_policy *policy)
-{
- pr_debug("CPU %d stopping\n", policy->cpu);
-
- intel_pstate_clear_update_util_hook(policy->cpu);
-}
-
static int intel_pstate_cpu_exit(struct cpufreq_policy *policy)
{
pr_debug("CPU %d exiting\n", policy->cpu);

+ intel_pstate_clear_update_util_hook(policy->cpu);
+
policy->fast_switch_possible = false;

return 0;
@@ -2451,7 +2448,6 @@ static struct cpufreq_driver intel_pstate = {
.resume = intel_pstate_resume,
.init = intel_pstate_cpu_init,
.exit = intel_pstate_cpu_exit,
- .stop_cpu = intel_pstate_stop_cpu,
.offline = intel_pstate_cpu_offline,
.online = intel_pstate_cpu_online,
.update_limits = intel_pstate_update_limits,
--
2.31.1.272.g89b43f80a514

2021-06-18 16:04:29

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH V3 2/3] cpufreq: intel_pstate: Migrate away from ->stop_cpu() callback

On Fri, Jun 18, 2021 at 5:22 AM Viresh Kumar <[email protected]> wrote:
>
> commit 367dc4aa932b ("cpufreq: Add stop CPU callback to cpufreq_driver
> interface") added the stop_cpu() callback to allow the drivers to do
> clean up before the CPU is completely down and its state can't be
> modified.
>
> At that time the CPU hotplug framework used to call the cpufreq core's
> registered notifier for different events like CPU_DOWN_PREPARE and
> CPU_POST_DEAD. The stop_cpu() callback was called during the
> CPU_DOWN_PREPARE event.
>
> This is no longer the case, cpuhp_cpufreq_offline() is called only once
> by the CPU hotplug core now and we don't really need to separately
> call stop_cpu() for cpufreq drivers.
>
> Migrate to using the exit() and offline() callbacks instead of
> stop_cpu().
>
> We need to clear util hook from both the callbacks, exit() and
> offline(), since it is possible that only exit() gets called sometimes
> (specially on errors) or both get called at other times.
> intel_pstate_clear_update_util_hook() anyway have enough protection in
> place if it gets called a second time and will return early then.
>
> Cc: Dirk Brandewie <[email protected]>
> Signed-off-by: Viresh Kumar <[email protected]>
> ---
> V2->V3:
> - Update intel_pstate_cpu_offline() as well.
> - Improved commit log.
>
> drivers/cpufreq/intel_pstate.c | 12 ++++--------
> 1 file changed, 4 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
> index 0e69dffd5a76..8f8a2d9d7daa 100644
> --- a/drivers/cpufreq/intel_pstate.c
> +++ b/drivers/cpufreq/intel_pstate.c
> @@ -2335,6 +2335,8 @@ static int intel_pstate_cpu_offline(struct cpufreq_policy *policy)
>
> pr_debug("CPU %d going offline\n", cpu->cpu);
>
> + intel_pstate_clear_update_util_hook(policy->cpu);
> +
> if (cpu->suspended)
> return 0;
>
> @@ -2374,17 +2376,12 @@ static int intel_pstate_cpu_online(struct cpufreq_policy *policy)
> return 0;
> }
>
> -static void intel_pstate_stop_cpu(struct cpufreq_policy *policy)
> -{
> - pr_debug("CPU %d stopping\n", policy->cpu);
> -
> - intel_pstate_clear_update_util_hook(policy->cpu);
> -}
> -
> static int intel_pstate_cpu_exit(struct cpufreq_policy *policy)
> {
> pr_debug("CPU %d exiting\n", policy->cpu);
>
> + intel_pstate_clear_update_util_hook(policy->cpu);

This change is not needed now, because ->offline always runs before
->exit if present.

> +
> policy->fast_switch_possible = false;
>
> return 0;
> @@ -2451,7 +2448,6 @@ static struct cpufreq_driver intel_pstate = {
> .resume = intel_pstate_resume,
> .init = intel_pstate_cpu_init,
> .exit = intel_pstate_cpu_exit,
> - .stop_cpu = intel_pstate_stop_cpu,
> .offline = intel_pstate_cpu_offline,
> .online = intel_pstate_cpu_online,
> .update_limits = intel_pstate_update_limits,
> --
> 2.31.1.272.g89b43f80a514
>

2021-06-21 03:12:13

by Viresh Kumar

[permalink] [raw]
Subject: Re: [PATCH V3 2/3] cpufreq: intel_pstate: Migrate away from ->stop_cpu() callback

On 18-06-21, 14:00, Rafael J. Wysocki wrote:
> On Fri, Jun 18, 2021 at 5:22 AM Viresh Kumar <[email protected]> wrote:
> >
> > commit 367dc4aa932b ("cpufreq: Add stop CPU callback to cpufreq_driver
> > interface") added the stop_cpu() callback to allow the drivers to do
> > clean up before the CPU is completely down and its state can't be
> > modified.
> >
> > At that time the CPU hotplug framework used to call the cpufreq core's
> > registered notifier for different events like CPU_DOWN_PREPARE and
> > CPU_POST_DEAD. The stop_cpu() callback was called during the
> > CPU_DOWN_PREPARE event.
> >
> > This is no longer the case, cpuhp_cpufreq_offline() is called only once
> > by the CPU hotplug core now and we don't really need to separately
> > call stop_cpu() for cpufreq drivers.
> >
> > Migrate to using the exit() and offline() callbacks instead of
> > stop_cpu().
> >
> > We need to clear util hook from both the callbacks, exit() and
> > offline(), since it is possible that only exit() gets called sometimes
> > (specially on errors) or both get called at other times.
> > intel_pstate_clear_update_util_hook() anyway have enough protection in
> > place if it gets called a second time and will return early then.
> >
> > Cc: Dirk Brandewie <[email protected]>
> > Signed-off-by: Viresh Kumar <[email protected]>
> > ---
> > V2->V3:
> > - Update intel_pstate_cpu_offline() as well.
> > - Improved commit log.
> >
> > drivers/cpufreq/intel_pstate.c | 12 ++++--------
> > 1 file changed, 4 insertions(+), 8 deletions(-)
> >
> > diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
> > index 0e69dffd5a76..8f8a2d9d7daa 100644
> > --- a/drivers/cpufreq/intel_pstate.c
> > +++ b/drivers/cpufreq/intel_pstate.c
> > @@ -2335,6 +2335,8 @@ static int intel_pstate_cpu_offline(struct cpufreq_policy *policy)
> >
> > pr_debug("CPU %d going offline\n", cpu->cpu);
> >
> > + intel_pstate_clear_update_util_hook(policy->cpu);
> > +
> > if (cpu->suspended)
> > return 0;
> >
> > @@ -2374,17 +2376,12 @@ static int intel_pstate_cpu_online(struct cpufreq_policy *policy)
> > return 0;
> > }
> >
> > -static void intel_pstate_stop_cpu(struct cpufreq_policy *policy)
> > -{
> > - pr_debug("CPU %d stopping\n", policy->cpu);
> > -
> > - intel_pstate_clear_update_util_hook(policy->cpu);
> > -}
> > -
> > static int intel_pstate_cpu_exit(struct cpufreq_policy *policy)
> > {
> > pr_debug("CPU %d exiting\n", policy->cpu);
> >
> > + intel_pstate_clear_update_util_hook(policy->cpu);
>
> This change is not needed now, because ->offline always runs before
> ->exit if present.

Not necessarily, we don't call ->offline() for many error paths in
cpufreq_online(). offline() only comes into play after driver is registered
properly once.

--
viresh

2021-06-21 14:20:20

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH V3 2/3] cpufreq: intel_pstate: Migrate away from ->stop_cpu() callback

On Mon, Jun 21, 2021 at 5:09 AM Viresh Kumar <[email protected]> wrote:
>
> On 18-06-21, 14:00, Rafael J. Wysocki wrote:
> > On Fri, Jun 18, 2021 at 5:22 AM Viresh Kumar <[email protected]> wrote:
> > >
> > > commit 367dc4aa932b ("cpufreq: Add stop CPU callback to cpufreq_driver
> > > interface") added the stop_cpu() callback to allow the drivers to do
> > > clean up before the CPU is completely down and its state can't be
> > > modified.
> > >
> > > At that time the CPU hotplug framework used to call the cpufreq core's
> > > registered notifier for different events like CPU_DOWN_PREPARE and
> > > CPU_POST_DEAD. The stop_cpu() callback was called during the
> > > CPU_DOWN_PREPARE event.
> > >
> > > This is no longer the case, cpuhp_cpufreq_offline() is called only once
> > > by the CPU hotplug core now and we don't really need to separately
> > > call stop_cpu() for cpufreq drivers.
> > >
> > > Migrate to using the exit() and offline() callbacks instead of
> > > stop_cpu().
> > >
> > > We need to clear util hook from both the callbacks, exit() and
> > > offline(), since it is possible that only exit() gets called sometimes
> > > (specially on errors) or both get called at other times.
> > > intel_pstate_clear_update_util_hook() anyway have enough protection in
> > > place if it gets called a second time and will return early then.
> > >
> > > Cc: Dirk Brandewie <[email protected]>
> > > Signed-off-by: Viresh Kumar <[email protected]>
> > > ---
> > > V2->V3:
> > > - Update intel_pstate_cpu_offline() as well.
> > > - Improved commit log.
> > >
> > > drivers/cpufreq/intel_pstate.c | 12 ++++--------
> > > 1 file changed, 4 insertions(+), 8 deletions(-)
> > >
> > > diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
> > > index 0e69dffd5a76..8f8a2d9d7daa 100644
> > > --- a/drivers/cpufreq/intel_pstate.c
> > > +++ b/drivers/cpufreq/intel_pstate.c
> > > @@ -2335,6 +2335,8 @@ static int intel_pstate_cpu_offline(struct cpufreq_policy *policy)
> > >
> > > pr_debug("CPU %d going offline\n", cpu->cpu);
> > >
> > > + intel_pstate_clear_update_util_hook(policy->cpu);
> > > +
> > > if (cpu->suspended)
> > > return 0;
> > >
> > > @@ -2374,17 +2376,12 @@ static int intel_pstate_cpu_online(struct cpufreq_policy *policy)
> > > return 0;
> > > }
> > >
> > > -static void intel_pstate_stop_cpu(struct cpufreq_policy *policy)
> > > -{
> > > - pr_debug("CPU %d stopping\n", policy->cpu);
> > > -
> > > - intel_pstate_clear_update_util_hook(policy->cpu);
> > > -}
> > > -
> > > static int intel_pstate_cpu_exit(struct cpufreq_policy *policy)
> > > {
> > > pr_debug("CPU %d exiting\n", policy->cpu);
> > >
> > > + intel_pstate_clear_update_util_hook(policy->cpu);
> >
> > This change is not needed now, because ->offline always runs before
> > ->exit if present.
>
> Not necessarily, we don't call ->offline() for many error paths in
> cpufreq_online().

I guess you mean the error paths in cpufreq_offline()?

IMO this is confusing/broken, because ->offline should always be
called after ->online has returned success.

> offline() only comes into play after driver is registered properly once.

The relevant intel_pstate case is a ->setpolicy driver where
->setpolicy or ->online, if successful, need to be followed by
->offline.

If ->setpolicy is successful in the cpufreq_online() path, the entire
cpufreq_online() is successful and the error paths in question are not
executed.

So the change I was talking about is not needed AFAICS.

2021-06-21 14:28:08

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH V3 2/3] cpufreq: intel_pstate: Migrate away from ->stop_cpu() callback

On Mon, Jun 21, 2021 at 4:17 PM Rafael J. Wysocki <[email protected]> wrote:
>
> On Mon, Jun 21, 2021 at 5:09 AM Viresh Kumar <[email protected]> wrote:
> >
> > On 18-06-21, 14:00, Rafael J. Wysocki wrote:
> > > On Fri, Jun 18, 2021 at 5:22 AM Viresh Kumar <[email protected]> wrote:
> > > >
> > > > commit 367dc4aa932b ("cpufreq: Add stop CPU callback to cpufreq_driver
> > > > interface") added the stop_cpu() callback to allow the drivers to do
> > > > clean up before the CPU is completely down and its state can't be
> > > > modified.
> > > >
> > > > At that time the CPU hotplug framework used to call the cpufreq core's
> > > > registered notifier for different events like CPU_DOWN_PREPARE and
> > > > CPU_POST_DEAD. The stop_cpu() callback was called during the
> > > > CPU_DOWN_PREPARE event.
> > > >
> > > > This is no longer the case, cpuhp_cpufreq_offline() is called only once
> > > > by the CPU hotplug core now and we don't really need to separately
> > > > call stop_cpu() for cpufreq drivers.
> > > >
> > > > Migrate to using the exit() and offline() callbacks instead of
> > > > stop_cpu().
> > > >
> > > > We need to clear util hook from both the callbacks, exit() and
> > > > offline(), since it is possible that only exit() gets called sometimes
> > > > (specially on errors) or both get called at other times.
> > > > intel_pstate_clear_update_util_hook() anyway have enough protection in
> > > > place if it gets called a second time and will return early then.
> > > >
> > > > Cc: Dirk Brandewie <[email protected]>
> > > > Signed-off-by: Viresh Kumar <[email protected]>
> > > > ---
> > > > V2->V3:
> > > > - Update intel_pstate_cpu_offline() as well.
> > > > - Improved commit log.
> > > >
> > > > drivers/cpufreq/intel_pstate.c | 12 ++++--------
> > > > 1 file changed, 4 insertions(+), 8 deletions(-)
> > > >
> > > > diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
> > > > index 0e69dffd5a76..8f8a2d9d7daa 100644
> > > > --- a/drivers/cpufreq/intel_pstate.c
> > > > +++ b/drivers/cpufreq/intel_pstate.c
> > > > @@ -2335,6 +2335,8 @@ static int intel_pstate_cpu_offline(struct cpufreq_policy *policy)
> > > >
> > > > pr_debug("CPU %d going offline\n", cpu->cpu);
> > > >
> > > > + intel_pstate_clear_update_util_hook(policy->cpu);
> > > > +
> > > > if (cpu->suspended)
> > > > return 0;
> > > >
> > > > @@ -2374,17 +2376,12 @@ static int intel_pstate_cpu_online(struct cpufreq_policy *policy)
> > > > return 0;
> > > > }
> > > >
> > > > -static void intel_pstate_stop_cpu(struct cpufreq_policy *policy)
> > > > -{
> > > > - pr_debug("CPU %d stopping\n", policy->cpu);
> > > > -
> > > > - intel_pstate_clear_update_util_hook(policy->cpu);
> > > > -}
> > > > -
> > > > static int intel_pstate_cpu_exit(struct cpufreq_policy *policy)
> > > > {
> > > > pr_debug("CPU %d exiting\n", policy->cpu);
> > > >
> > > > + intel_pstate_clear_update_util_hook(policy->cpu);
> > >
> > > This change is not needed now, because ->offline always runs before
> > > ->exit if present.
> >
> > Not necessarily, we don't call ->offline() for many error paths in
> > cpufreq_online().
>
> I guess you mean the error paths in cpufreq_offline()?

s/offline/online/

> IMO this is confusing/broken, because ->offline should always be
> called after ->online has returned success.
>
> > offline() only comes into play after driver is registered properly once.
>
> The relevant intel_pstate case is a ->setpolicy driver where
> ->setpolicy or ->online, if successful, need to be followed by
> ->offline.
>
> If ->setpolicy is successful in the cpufreq_online() path, the entire
> cpufreq_online() is successful and the error paths in question are not
> executed.
>
> So the change I was talking about is not needed AFAICS.

2021-06-21 17:16:47

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH V3 2/3] cpufreq: intel_pstate: Migrate away from ->stop_cpu() callback

On Mon, Jun 21, 2021 at 4:26 PM Rafael J. Wysocki <[email protected]> wrote:
>
> On Mon, Jun 21, 2021 at 4:17 PM Rafael J. Wysocki <[email protected]> wrote:
> >
> > On Mon, Jun 21, 2021 at 5:09 AM Viresh Kumar <[email protected]> wrote:
> > >
> > > On 18-06-21, 14:00, Rafael J. Wysocki wrote:
> > > > On Fri, Jun 18, 2021 at 5:22 AM Viresh Kumar <[email protected]> wrote:
> > > > >
> > > > > commit 367dc4aa932b ("cpufreq: Add stop CPU callback to cpufreq_driver
> > > > > interface") added the stop_cpu() callback to allow the drivers to do
> > > > > clean up before the CPU is completely down and its state can't be
> > > > > modified.
> > > > >
> > > > > At that time the CPU hotplug framework used to call the cpufreq core's
> > > > > registered notifier for different events like CPU_DOWN_PREPARE and
> > > > > CPU_POST_DEAD. The stop_cpu() callback was called during the
> > > > > CPU_DOWN_PREPARE event.
> > > > >
> > > > > This is no longer the case, cpuhp_cpufreq_offline() is called only once
> > > > > by the CPU hotplug core now and we don't really need to separately
> > > > > call stop_cpu() for cpufreq drivers.
> > > > >
> > > > > Migrate to using the exit() and offline() callbacks instead of
> > > > > stop_cpu().
> > > > >
> > > > > We need to clear util hook from both the callbacks, exit() and
> > > > > offline(), since it is possible that only exit() gets called sometimes
> > > > > (specially on errors) or both get called at other times.
> > > > > intel_pstate_clear_update_util_hook() anyway have enough protection in
> > > > > place if it gets called a second time and will return early then.
> > > > >
> > > > > Cc: Dirk Brandewie <[email protected]>
> > > > > Signed-off-by: Viresh Kumar <[email protected]>
> > > > > ---
> > > > > V2->V3:
> > > > > - Update intel_pstate_cpu_offline() as well.
> > > > > - Improved commit log.
> > > > >
> > > > > drivers/cpufreq/intel_pstate.c | 12 ++++--------
> > > > > 1 file changed, 4 insertions(+), 8 deletions(-)
> > > > >
> > > > > diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
> > > > > index 0e69dffd5a76..8f8a2d9d7daa 100644
> > > > > --- a/drivers/cpufreq/intel_pstate.c
> > > > > +++ b/drivers/cpufreq/intel_pstate.c
> > > > > @@ -2335,6 +2335,8 @@ static int intel_pstate_cpu_offline(struct cpufreq_policy *policy)
> > > > >
> > > > > pr_debug("CPU %d going offline\n", cpu->cpu);
> > > > >
> > > > > + intel_pstate_clear_update_util_hook(policy->cpu);
> > > > > +
> > > > > if (cpu->suspended)
> > > > > return 0;
> > > > >
> > > > > @@ -2374,17 +2376,12 @@ static int intel_pstate_cpu_online(struct cpufreq_policy *policy)
> > > > > return 0;
> > > > > }
> > > > >
> > > > > -static void intel_pstate_stop_cpu(struct cpufreq_policy *policy)
> > > > > -{
> > > > > - pr_debug("CPU %d stopping\n", policy->cpu);
> > > > > -
> > > > > - intel_pstate_clear_update_util_hook(policy->cpu);
> > > > > -}
> > > > > -
> > > > > static int intel_pstate_cpu_exit(struct cpufreq_policy *policy)
> > > > > {
> > > > > pr_debug("CPU %d exiting\n", policy->cpu);
> > > > >
> > > > > + intel_pstate_clear_update_util_hook(policy->cpu);
> > > >
> > > > This change is not needed now, because ->offline always runs before
> > > > ->exit if present.
> > >
> > > Not necessarily, we don't call ->offline() for many error paths in
> > > cpufreq_online().
> >
> > I guess you mean the error paths in cpufreq_offline()?
>
> s/offline/online/
>
> > IMO this is confusing/broken, because ->offline should always be
> > called after ->online has returned success.
> >
> > > offline() only comes into play after driver is registered properly once.
> >
> > The relevant intel_pstate case is a ->setpolicy driver where
> > ->setpolicy or ->online, if successful, need to be followed by
> > ->offline.
> >
> > If ->setpolicy is successful in the cpufreq_online() path, the entire
> > cpufreq_online() is successful and the error paths in question are not
> > executed.
> >
> > So the change I was talking about is not needed AFAICS.

Regardless of all of the above, the ->online, ->offline and ->exit
callback routines are used by intel_pstate both in the active mode and
the passive mode, so some more work is needed to migrate it away from
using ->stop_cpu.