2023-01-16 00:30:48

by Vincent Wang

[permalink] [raw]
Subject: [PATCH] cpufreq: Send CPUFREQ_CREATE_POLICY notification after the perf domain creation.

From: Vincent Wang <[email protected]>

We found the following issue during kernel boot on android phone:

[ 1.325272][ T1] cpu cpu0: EM: created perf domain
[ 1.329317][ T1] cpu cpu4: EM: created perf domain
[ 1.337597][ T76] pd_init: no EM found for CPU7
[ 1.350849][ T1] cpu cpu7: EM: created perf domain

pd init for cluster2 is executed in a kworker thread and
is earlier than the perf domain creation for cluster2.

pd_init() is called from the cpufreq notification of
CPUFREQ_CREATE_POLICY in cpufreq_online(), which is earlier
than that cpufreq_driver->register_em() is called.

To avoid this issue, cpufreq notification should be sent after
the perf domain creation.

Signed-off-by: Vincent Wang <[email protected]>
---
drivers/cpufreq/cpufreq.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 7e56a42750ea..af8836069398 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -1430,9 +1430,6 @@ static int cpufreq_online(unsigned int cpu)
policy->max_freq_req = NULL;
goto out_destroy_policy;
}
-
- blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
- CPUFREQ_CREATE_POLICY, policy);
}

if (cpufreq_driver->get && has_target()) {
@@ -1506,6 +1503,9 @@ static int cpufreq_online(unsigned int cpu)
*/
if (cpufreq_driver->register_em)
cpufreq_driver->register_em(policy);
+
+ blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
+ CPUFREQ_CREATE_POLICY, policy);
}

ret = cpufreq_init_policy(policy);
--
2.25.1


2023-01-16 04:44:56

by Viresh Kumar

[permalink] [raw]
Subject: Re: [PATCH] cpufreq: Send CPUFREQ_CREATE_POLICY notification after the perf domain creation.

+Lukasz,

Any inputs ?

On 16-01-23, 07:52, Vincent Wang wrote:
> From: Vincent Wang <[email protected]>
>
> We found the following issue during kernel boot on android phone:
>
> [ 1.325272][ T1] cpu cpu0: EM: created perf domain
> [ 1.329317][ T1] cpu cpu4: EM: created perf domain
> [ 1.337597][ T76] pd_init: no EM found for CPU7
> [ 1.350849][ T1] cpu cpu7: EM: created perf domain
>
> pd init for cluster2 is executed in a kworker thread and
> is earlier than the perf domain creation for cluster2.
>
> pd_init() is called from the cpufreq notification of
> CPUFREQ_CREATE_POLICY in cpufreq_online(), which is earlier
> than that cpufreq_driver->register_em() is called.
>
> To avoid this issue, cpufreq notification should be sent after
> the perf domain creation.
>
> Signed-off-by: Vincent Wang <[email protected]>
> ---
> drivers/cpufreq/cpufreq.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index 7e56a42750ea..af8836069398 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -1430,9 +1430,6 @@ static int cpufreq_online(unsigned int cpu)
> policy->max_freq_req = NULL;
> goto out_destroy_policy;
> }
> -
> - blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
> - CPUFREQ_CREATE_POLICY, policy);
> }
>
> if (cpufreq_driver->get && has_target()) {
> @@ -1506,6 +1503,9 @@ static int cpufreq_online(unsigned int cpu)
> */
> if (cpufreq_driver->register_em)
> cpufreq_driver->register_em(policy);
> +
> + blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
> + CPUFREQ_CREATE_POLICY, policy);
> }
>
> ret = cpufreq_init_policy(policy);
> --
> 2.25.1

--
viresh

2023-01-17 13:50:51

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH] cpufreq: Send CPUFREQ_CREATE_POLICY notification after the perf domain creation.

On Mon, Jan 16, 2023 at 12:52 AM Vincent Wang <[email protected]> wrote:
>
> From: Vincent Wang <[email protected]>
>
> We found the following issue during kernel boot on android phone:
>
> [ 1.325272][ T1] cpu cpu0: EM: created perf domain
> [ 1.329317][ T1] cpu cpu4: EM: created perf domain
> [ 1.337597][ T76] pd_init: no EM found for CPU7
> [ 1.350849][ T1] cpu cpu7: EM: created perf domain
>
> pd init for cluster2 is executed in a kworker thread and
> is earlier than the perf domain creation for cluster2.
>
> pd_init() is called from the cpufreq notification of
> CPUFREQ_CREATE_POLICY in cpufreq_online(), which is earlier
> than that cpufreq_driver->register_em() is called.
>
> To avoid this issue, cpufreq notification should be sent after
> the perf domain creation.
>
> Signed-off-by: Vincent Wang <[email protected]>
> ---
> drivers/cpufreq/cpufreq.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index 7e56a42750ea..af8836069398 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -1430,9 +1430,6 @@ static int cpufreq_online(unsigned int cpu)
> policy->max_freq_req = NULL;
> goto out_destroy_policy;
> }
> -
> - blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
> - CPUFREQ_CREATE_POLICY, policy);
> }

AFAICS, in some cases, this may cause cpufreq_online() to send
CPUFREQ_REMOVE_POLICY without sending CPUFREQ_CREATE_POLICY which is
generally confusing to its callers.

I'm wondering if you can reorder the EM registration before the
initialization of frequency QoS for the policy?

>
> if (cpufreq_driver->get && has_target()) {
> @@ -1506,6 +1503,9 @@ static int cpufreq_online(unsigned int cpu)
> */
> if (cpufreq_driver->register_em)
> cpufreq_driver->register_em(policy);
> +
> + blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
> + CPUFREQ_CREATE_POLICY, policy);
> }
>
> ret = cpufreq_init_policy(policy);
> --