* [PATCH v3 0/3] arm64: topology: Setup AMU FIE for online CPUs only
@ 2025-08-05 9:33 Lifeng Zheng
2025-08-05 9:33 ` [PATCH v3 1/3] arm64: topology: Set scale freq source only for the CPUs that have not been set before Lifeng Zheng
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: Lifeng Zheng @ 2025-08-05 9:33 UTC (permalink / raw)
To: catalin.marinas, will, rafael, viresh.kumar, beata.michalska,
sudeep.holla
Cc: linux-arm-kernel, linux-pm, linux-kernel, linuxarm,
jonathan.cameron, vincent.guittot, yangyicong, zhanjie9,
lihuisong, yubowen8, linhongye, zhenglifeng1
Solve a problem that causes CPUs Setup AMU FIE failed in a corner case,
even though they're eligible.
Changelog:
v3:
- add a patch to optimize amu_fie_setup()
- add a patch to add a function to get cpufreq policy without checking if
the CPU is online
- discard the reuse of amu_fie_setup() in cpuhp_topology_online() and keep
all the new logic in cpuhp_topology_online()
- test only the CPU which is going online in cpuhp_topology_online()
- when the freq_counters_valid() check fails, not only clear the scale
freq source but also clear all the related CPUs from amu_fie_cpus mask
- add some comments
v2:
- keep init_amu_fie_notifier for setting up AMU FIE when the cpufreq
policy is being created
- set up AMU FIE only for online CPUs instead of related_cpus in
init_amu_fie_callback()
- check and set all the online CPUs in the same policy when hotplug one
- clear scale freq source for all the online CPUs in the same policy to
avoid using different source of the freq scale
---
Discussions of previous version:
v1: https://lore.kernel.org/all/20250607094533.416368-1-zhenglifeng1@huawei.com/
v2: https://lore.kernel.org/all/20250725102813.1404322-1-zhenglifeng1@huawei.com/
Lifeng Zheng (3):
arm64: topology: Set scale freq source only for the CPUs that have not
been set before
cpufreq: Add a new function to get cpufreq policy without checking if
the CPU is online
arm64: topology: Setup AMU FIE for online CPUs only
arch/arm64/kernel/topology.c | 56 ++++++++++++++++++++++++++++++++++--
drivers/cpufreq/cpufreq.c | 11 +++++++
include/linux/cpufreq.h | 1 +
3 files changed, 65 insertions(+), 3 deletions(-)
--
2.33.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v3 1/3] arm64: topology: Set scale freq source only for the CPUs that have not been set before
2025-08-05 9:33 [PATCH v3 0/3] arm64: topology: Setup AMU FIE for online CPUs only Lifeng Zheng
@ 2025-08-05 9:33 ` Lifeng Zheng
2025-08-05 9:33 ` [PATCH v3 2/3] cpufreq: Add a new function to get cpufreq policy without checking if the CPU is online Lifeng Zheng
2025-08-05 9:33 ` [PATCH v3 3/3] arm64: topology: Setup AMU FIE for online CPUs only Lifeng Zheng
2 siblings, 0 replies; 11+ messages in thread
From: Lifeng Zheng @ 2025-08-05 9:33 UTC (permalink / raw)
To: catalin.marinas, will, rafael, viresh.kumar, beata.michalska,
sudeep.holla
Cc: linux-arm-kernel, linux-pm, linux-kernel, linuxarm,
jonathan.cameron, vincent.guittot, yangyicong, zhanjie9,
lihuisong, yubowen8, linhongye, zhenglifeng1
The scale freq source of the CPUs in 'amu_fie_cpus' mask are already set to
AMU tick before, so in amu_fie_setup(), only the CPUs in the 'cpus' mask
should be set.
Signed-off-by: Lifeng Zheng <zhenglifeng1@huawei.com>
---
arch/arm64/kernel/topology.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c
index 5d07ee85bdae..9317a618bb87 100644
--- a/arch/arm64/kernel/topology.c
+++ b/arch/arm64/kernel/topology.c
@@ -373,7 +373,7 @@ static void amu_fie_setup(const struct cpumask *cpus)
cpumask_or(amu_fie_cpus, amu_fie_cpus, cpus);
- topology_set_scale_freq_source(&amu_sfd, amu_fie_cpus);
+ topology_set_scale_freq_source(&amu_sfd, cpus);
pr_debug("CPUs[%*pbl]: counters will be used for FIE.",
cpumask_pr_args(cpus));
--
2.33.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v3 2/3] cpufreq: Add a new function to get cpufreq policy without checking if the CPU is online
2025-08-05 9:33 [PATCH v3 0/3] arm64: topology: Setup AMU FIE for online CPUs only Lifeng Zheng
2025-08-05 9:33 ` [PATCH v3 1/3] arm64: topology: Set scale freq source only for the CPUs that have not been set before Lifeng Zheng
@ 2025-08-05 9:33 ` Lifeng Zheng
2025-08-05 12:57 ` Rafael J. Wysocki
2025-08-05 9:33 ` [PATCH v3 3/3] arm64: topology: Setup AMU FIE for online CPUs only Lifeng Zheng
2 siblings, 1 reply; 11+ messages in thread
From: Lifeng Zheng @ 2025-08-05 9:33 UTC (permalink / raw)
To: catalin.marinas, will, rafael, viresh.kumar, beata.michalska,
sudeep.holla
Cc: linux-arm-kernel, linux-pm, linux-kernel, linuxarm,
jonathan.cameron, vincent.guittot, yangyicong, zhanjie9,
lihuisong, yubowen8, linhongye, zhenglifeng1
cpufreq_cpu_get_raw() gets cpufreq policy only if the CPU is in
policy->cpus mask, which means the CPU is already online. But in some
cases, the policy is needed before the CPU is added to cpus mask. Add a
function to get the policy in these cases.
Signed-off-by: Lifeng Zheng <zhenglifeng1@huawei.com>
---
drivers/cpufreq/cpufreq.c | 11 +++++++++++
include/linux/cpufreq.h | 1 +
2 files changed, 12 insertions(+)
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index fc7eace8b65b..2de76a072893 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -198,6 +198,17 @@ struct cpufreq_policy *cpufreq_cpu_get_raw(unsigned int cpu)
}
EXPORT_SYMBOL_GPL(cpufreq_cpu_get_raw);
+struct cpufreq_policy *cpufreq_cpu_get_raw_no_check(unsigned int cpu)
+{
+ struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu);
+
+ if (policy)
+ return policy;
+
+ return NULL;
+}
+EXPORT_SYMBOL_GPL(cpufreq_cpu_get_raw_no_check);
+
unsigned int cpufreq_generic_get(unsigned int cpu)
{
struct cpufreq_policy *policy = cpufreq_cpu_get_raw(cpu);
diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
index 95f3807c8c55..02ad8173dc10 100644
--- a/include/linux/cpufreq.h
+++ b/include/linux/cpufreq.h
@@ -205,6 +205,7 @@ struct cpufreq_freqs {
#ifdef CONFIG_CPU_FREQ
struct cpufreq_policy *cpufreq_cpu_get_raw(unsigned int cpu);
+struct cpufreq_policy *cpufreq_cpu_get_raw_no_check(unsigned int cpu);
struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu);
void cpufreq_cpu_put(struct cpufreq_policy *policy);
#else
--
2.33.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v3 3/3] arm64: topology: Setup AMU FIE for online CPUs only
2025-08-05 9:33 [PATCH v3 0/3] arm64: topology: Setup AMU FIE for online CPUs only Lifeng Zheng
2025-08-05 9:33 ` [PATCH v3 1/3] arm64: topology: Set scale freq source only for the CPUs that have not been set before Lifeng Zheng
2025-08-05 9:33 ` [PATCH v3 2/3] cpufreq: Add a new function to get cpufreq policy without checking if the CPU is online Lifeng Zheng
@ 2025-08-05 9:33 ` Lifeng Zheng
2025-08-06 9:55 ` Beata Michalska
` (2 more replies)
2 siblings, 3 replies; 11+ messages in thread
From: Lifeng Zheng @ 2025-08-05 9:33 UTC (permalink / raw)
To: catalin.marinas, will, rafael, viresh.kumar, beata.michalska,
sudeep.holla
Cc: linux-arm-kernel, linux-pm, linux-kernel, linuxarm,
jonathan.cameron, vincent.guittot, yangyicong, zhanjie9,
lihuisong, yubowen8, linhongye, zhenglifeng1
When boot with maxcpu=1 restrict, and LPI(Low Power Idle States) is on,
only CPU0 will go online. The support AMU flag of CPU0 will be set but the
flags of other CPUs will not. This will cause AMU FIE set up fail for CPU0
when it shares a cpufreq policy with other CPU(s). After that, when other
CPUs are finally online and the support AMU flags of them are set, they'll
never have a chance to set up AMU FIE, even though they're eligible.
To solve this problem, the process of setting up AMU FIE needs to be
modified as follows:
1. Set up AMU FIE only for the online CPUs.
2. Try to set up AMU FIE each time a CPU goes online and do the
freq_counters_valid() check. If this check fails, clear scale freq source
of all the CPUs related to the same policy, in case they use different
source of the freq scale.
Signed-off-by: Lifeng Zheng <zhenglifeng1@huawei.com>
---
arch/arm64/kernel/topology.c | 54 ++++++++++++++++++++++++++++++++++--
1 file changed, 52 insertions(+), 2 deletions(-)
diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c
index 9317a618bb87..b68621b3c071 100644
--- a/arch/arm64/kernel/topology.c
+++ b/arch/arm64/kernel/topology.c
@@ -385,7 +385,7 @@ static int init_amu_fie_callback(struct notifier_block *nb, unsigned long val,
struct cpufreq_policy *policy = data;
if (val == CPUFREQ_CREATE_POLICY)
- amu_fie_setup(policy->related_cpus);
+ amu_fie_setup(policy->cpus);
/*
* We don't need to handle CPUFREQ_REMOVE_POLICY event as the AMU
@@ -404,10 +404,60 @@ static struct notifier_block init_amu_fie_notifier = {
.notifier_call = init_amu_fie_callback,
};
+static int cpuhp_topology_online(unsigned int cpu)
+{
+ struct cpufreq_policy *policy = cpufreq_cpu_get_raw_no_check(cpu);
+
+ /*
+ * If the online CPUs are not all AMU FIE CPUs or the new one is already
+ * an AMU FIE one, no need to set it.
+ */
+ if (!policy || !cpumask_available(amu_fie_cpus) ||
+ !cpumask_subset(policy->cpus, amu_fie_cpus) ||
+ cpumask_test_cpu(cpu, amu_fie_cpus))
+ return 0;
+
+ /*
+ * If the new online CPU cannot pass this check, all the CPUs related to
+ * the same policy should be clear from amu_fie_cpus mask, otherwise they
+ * may use different source of the freq scale.
+ */
+ if (!freq_counters_valid(cpu)) {
+ topology_clear_scale_freq_source(SCALE_FREQ_SOURCE_ARCH,
+ policy->related_cpus);
+ cpumask_andnot(amu_fie_cpus, amu_fie_cpus, policy->related_cpus);
+ return 0;
+ }
+
+ cpumask_set_cpu(cpu, amu_fie_cpus);
+
+ topology_set_scale_freq_source(&amu_sfd, cpumask_of(cpu));
+
+ pr_debug("CPU[%u]: counter will be used for FIE.", cpu);
+
+ return 0;
+}
+
static int __init init_amu_fie(void)
{
- return cpufreq_register_notifier(&init_amu_fie_notifier,
+ int ret;
+
+ ret = cpufreq_register_notifier(&init_amu_fie_notifier,
CPUFREQ_POLICY_NOTIFIER);
+ if (ret)
+ return ret;
+
+ ret = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN,
+ "arm64/topology:online",
+ cpuhp_topology_online,
+ NULL);
+ if (ret < 0) {
+ cpufreq_unregister_notifier(&init_amu_fie_notifier,
+ CPUFREQ_POLICY_NOTIFIER);
+ return ret;
+ }
+
+ return 0;
}
core_initcall(init_amu_fie);
--
2.33.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v3 2/3] cpufreq: Add a new function to get cpufreq policy without checking if the CPU is online
2025-08-05 9:33 ` [PATCH v3 2/3] cpufreq: Add a new function to get cpufreq policy without checking if the CPU is online Lifeng Zheng
@ 2025-08-05 12:57 ` Rafael J. Wysocki
2025-08-05 13:32 ` zhenglifeng (A)
0 siblings, 1 reply; 11+ messages in thread
From: Rafael J. Wysocki @ 2025-08-05 12:57 UTC (permalink / raw)
To: Lifeng Zheng
Cc: catalin.marinas, will, rafael, viresh.kumar, beata.michalska,
sudeep.holla, linux-arm-kernel, linux-pm, linux-kernel, linuxarm,
jonathan.cameron, vincent.guittot, yangyicong, zhanjie9,
lihuisong, yubowen8, linhongye
On Tue, Aug 5, 2025 at 11:34 AM Lifeng Zheng <zhenglifeng1@huawei.com> wrote:
>
> cpufreq_cpu_get_raw() gets cpufreq policy only if the CPU is in
> policy->cpus mask, which means the CPU is already online. But in some
> cases, the policy is needed before the CPU is added to cpus mask. Add a
> function to get the policy in these cases.
>
> Signed-off-by: Lifeng Zheng <zhenglifeng1@huawei.com>
> ---
> drivers/cpufreq/cpufreq.c | 11 +++++++++++
> include/linux/cpufreq.h | 1 +
> 2 files changed, 12 insertions(+)
>
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index fc7eace8b65b..2de76a072893 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -198,6 +198,17 @@ struct cpufreq_policy *cpufreq_cpu_get_raw(unsigned int cpu)
> }
> EXPORT_SYMBOL_GPL(cpufreq_cpu_get_raw);
>
> +struct cpufreq_policy *cpufreq_cpu_get_raw_no_check(unsigned int cpu)
This is not a particularly nice name. Maybe call it cpufreq_cpu_policy()?
> +{
> + struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu);
> +
> + if (policy)
> + return policy;
> +
> + return NULL;
This could just be a one-liner with this statement in the function body:
return per_cpu(cpufreq_cpu_data, cpu);
Can't it?
In which case it can be called in all places reading cpufreq_cpu_data
for a given CPU.
> +}
> +EXPORT_SYMBOL_GPL(cpufreq_cpu_get_raw_no_check);
> +
> unsigned int cpufreq_generic_get(unsigned int cpu)
> {
> struct cpufreq_policy *policy = cpufreq_cpu_get_raw(cpu);
> diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
> index 95f3807c8c55..02ad8173dc10 100644
> --- a/include/linux/cpufreq.h
> +++ b/include/linux/cpufreq.h
> @@ -205,6 +205,7 @@ struct cpufreq_freqs {
>
> #ifdef CONFIG_CPU_FREQ
> struct cpufreq_policy *cpufreq_cpu_get_raw(unsigned int cpu);
> +struct cpufreq_policy *cpufreq_cpu_get_raw_no_check(unsigned int cpu);
> struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu);
> void cpufreq_cpu_put(struct cpufreq_policy *policy);
> #else
> --
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3 2/3] cpufreq: Add a new function to get cpufreq policy without checking if the CPU is online
2025-08-05 12:57 ` Rafael J. Wysocki
@ 2025-08-05 13:32 ` zhenglifeng (A)
0 siblings, 0 replies; 11+ messages in thread
From: zhenglifeng (A) @ 2025-08-05 13:32 UTC (permalink / raw)
To: Rafael J. Wysocki
Cc: catalin.marinas, will, viresh.kumar, beata.michalska,
sudeep.holla, linux-arm-kernel, linux-pm, linux-kernel, linuxarm,
jonathan.cameron, vincent.guittot, yangyicong, zhanjie9,
lihuisong, yubowen8, linhongye
On 2025/8/5 20:57, Rafael J. Wysocki wrote:
> On Tue, Aug 5, 2025 at 11:34 AM Lifeng Zheng <zhenglifeng1@huawei.com> wrote:
>>
>> cpufreq_cpu_get_raw() gets cpufreq policy only if the CPU is in
>> policy->cpus mask, which means the CPU is already online. But in some
>> cases, the policy is needed before the CPU is added to cpus mask. Add a
>> function to get the policy in these cases.
>>
>> Signed-off-by: Lifeng Zheng <zhenglifeng1@huawei.com>
>> ---
>> drivers/cpufreq/cpufreq.c | 11 +++++++++++
>> include/linux/cpufreq.h | 1 +
>> 2 files changed, 12 insertions(+)
>>
>> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
>> index fc7eace8b65b..2de76a072893 100644
>> --- a/drivers/cpufreq/cpufreq.c
>> +++ b/drivers/cpufreq/cpufreq.c
>> @@ -198,6 +198,17 @@ struct cpufreq_policy *cpufreq_cpu_get_raw(unsigned int cpu)
>> }
>> EXPORT_SYMBOL_GPL(cpufreq_cpu_get_raw);
>>
>> +struct cpufreq_policy *cpufreq_cpu_get_raw_no_check(unsigned int cpu)
>
> This is not a particularly nice name. Maybe call it cpufreq_cpu_policy()?
Thanks for giving a better one.
>
>> +{
>> + struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu);
>> +
>> + if (policy)
>> + return policy;
>> +
>> + return NULL;
>
> This could just be a one-liner with this statement in the function body:
>
> return per_cpu(cpufreq_cpu_data, cpu);
>
> Can't it?
>
> In which case it can be called in all places reading cpufreq_cpu_data
> for a given CPU.
Yes, it can be done in one line. Thanks.
>
>> +}
>> +EXPORT_SYMBOL_GPL(cpufreq_cpu_get_raw_no_check);
>> +
>> unsigned int cpufreq_generic_get(unsigned int cpu)
>> {
>> struct cpufreq_policy *policy = cpufreq_cpu_get_raw(cpu);
>> diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
>> index 95f3807c8c55..02ad8173dc10 100644
>> --- a/include/linux/cpufreq.h
>> +++ b/include/linux/cpufreq.h
>> @@ -205,6 +205,7 @@ struct cpufreq_freqs {
>>
>> #ifdef CONFIG_CPU_FREQ
>> struct cpufreq_policy *cpufreq_cpu_get_raw(unsigned int cpu);
>> +struct cpufreq_policy *cpufreq_cpu_get_raw_no_check(unsigned int cpu);
>> struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu);
>> void cpufreq_cpu_put(struct cpufreq_policy *policy);
>> #else
>> --
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3 3/3] arm64: topology: Setup AMU FIE for online CPUs only
2025-08-05 9:33 ` [PATCH v3 3/3] arm64: topology: Setup AMU FIE for online CPUs only Lifeng Zheng
@ 2025-08-06 9:55 ` Beata Michalska
2025-08-13 10:17 ` zhenglifeng (A)
2025-08-06 13:45 ` kernel test robot
2025-08-06 13:45 ` kernel test robot
2 siblings, 1 reply; 11+ messages in thread
From: Beata Michalska @ 2025-08-06 9:55 UTC (permalink / raw)
To: Lifeng Zheng
Cc: catalin.marinas, will, rafael, viresh.kumar, sudeep.holla,
linux-arm-kernel, linux-pm, linux-kernel, linuxarm,
jonathan.cameron, vincent.guittot, yangyicong, zhanjie9,
lihuisong, yubowen8, linhongye
On Tue, Aug 05, 2025 at 05:33:30PM +0800, Lifeng Zheng wrote:
> When boot with maxcpu=1 restrict, and LPI(Low Power Idle States) is on,
> only CPU0 will go online. The support AMU flag of CPU0 will be set but the
> flags of other CPUs will not. This will cause AMU FIE set up fail for CPU0
> when it shares a cpufreq policy with other CPU(s). After that, when other
> CPUs are finally online and the support AMU flags of them are set, they'll
> never have a chance to set up AMU FIE, even though they're eligible.
>
> To solve this problem, the process of setting up AMU FIE needs to be
> modified as follows:
>
> 1. Set up AMU FIE only for the online CPUs.
>
> 2. Try to set up AMU FIE each time a CPU goes online and do the
> freq_counters_valid() check. If this check fails, clear scale freq source
> of all the CPUs related to the same policy, in case they use different
> source of the freq scale.
>
> Signed-off-by: Lifeng Zheng <zhenglifeng1@huawei.com>
> ---
> arch/arm64/kernel/topology.c | 54 ++++++++++++++++++++++++++++++++++--
> 1 file changed, 52 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c
> index 9317a618bb87..b68621b3c071 100644
> --- a/arch/arm64/kernel/topology.c
> +++ b/arch/arm64/kernel/topology.c
> @@ -385,7 +385,7 @@ static int init_amu_fie_callback(struct notifier_block *nb, unsigned long val,
> struct cpufreq_policy *policy = data;
>
> if (val == CPUFREQ_CREATE_POLICY)
> - amu_fie_setup(policy->related_cpus);
> + amu_fie_setup(policy->cpus);
I think my previous comment still stands.
This will indeed set the AMU FIE support for online cpus.
Still, on each frequency change, arch_set_freq_scale will be called with
`related_cpus`, and that mask will be used to verify support for AMU counters,
and it will report there is none as 'related_cpus' won't be a subset of
`scale_freq_counters_mask`. As a consequence, new scale will be set, as seen by
the cpufreq. Now this will be corrected on next tick but it might cause
disruptions. So this change should also be applied to cpufreq - if feasible, or
at least be proven not to be an issue. Unless I am missing smth.
>
> /*
> * We don't need to handle CPUFREQ_REMOVE_POLICY event as the AMU
> @@ -404,10 +404,60 @@ static struct notifier_block init_amu_fie_notifier = {
> .notifier_call = init_amu_fie_callback,
> };
>
> +static int cpuhp_topology_online(unsigned int cpu)
> +{
> + struct cpufreq_policy *policy = cpufreq_cpu_get_raw_no_check(cpu);
> +
> + /*
> + * If the online CPUs are not all AMU FIE CPUs or the new one is already
> + * an AMU FIE one, no need to set it.
> + */
> + if (!policy || !cpumask_available(amu_fie_cpus) ||
> + !cpumask_subset(policy->cpus, amu_fie_cpus) ||
> + cpumask_test_cpu(cpu, amu_fie_cpus))
> + return 0;
This is getting rather cumbersome as the CPU that is coming online might belong
to a policy that is yet to be created. Both AMU FIE support, as well as cpufreq,
rely on dynamic hp state so, in theory, we cannot be certain that the cpufreq
callback will be fired first (although that seems to be the case).
If that does not happen, the policy will not exist, and as such given CPU
will not use AMUs for FIE. The problem might be hypothetical but it at least
deservers a comment I think.
Second problem is cpumask_available use: this might be the very fist CPU that
might potentially rely on AMUs for frequency invariance so that mask may not be
available yet. That does not mean AMUs setup should be skipped. Not just yet,
at least. Again more hypothetical.
BTW, there should be `amu_fie_cpu_supported'.
> +
> + /*
> + * If the new online CPU cannot pass this check, all the CPUs related to
> + * the same policy should be clear from amu_fie_cpus mask, otherwise they
> + * may use different source of the freq scale.
> + */
> + if (!freq_counters_valid(cpu)) {
> + topology_clear_scale_freq_source(SCALE_FREQ_SOURCE_ARCH,
> + policy->related_cpus);
> + cpumask_andnot(amu_fie_cpus, amu_fie_cpus, policy->related_cpus);
I think it might deserve a warning as this probably should not happen.
---
BR
Beata
> + return 0;
> + }
> +
> + cpumask_set_cpu(cpu, amu_fie_cpus);
> +
> + topology_set_scale_freq_source(&amu_sfd, cpumask_of(cpu));
> +
> + pr_debug("CPU[%u]: counter will be used for FIE.", cpu);
> +
> + return 0;
> +}
> +
> static int __init init_amu_fie(void)
> {
> - return cpufreq_register_notifier(&init_amu_fie_notifier,
> + int ret;
> +
> + ret = cpufreq_register_notifier(&init_amu_fie_notifier,
> CPUFREQ_POLICY_NOTIFIER);
> + if (ret)
> + return ret;
> +
> + ret = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN,
> + "arm64/topology:online",
> + cpuhp_topology_online,
> + NULL);
> + if (ret < 0) {
> + cpufreq_unregister_notifier(&init_amu_fie_notifier,
> + CPUFREQ_POLICY_NOTIFIER);
> + return ret;
> + }
> +
> + return 0;
> }
> core_initcall(init_amu_fie);
>
> --
> 2.33.0
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3 3/3] arm64: topology: Setup AMU FIE for online CPUs only
2025-08-05 9:33 ` [PATCH v3 3/3] arm64: topology: Setup AMU FIE for online CPUs only Lifeng Zheng
2025-08-06 9:55 ` Beata Michalska
@ 2025-08-06 13:45 ` kernel test robot
2025-08-06 13:45 ` kernel test robot
2 siblings, 0 replies; 11+ messages in thread
From: kernel test robot @ 2025-08-06 13:45 UTC (permalink / raw)
To: Lifeng Zheng, catalin.marinas, will, rafael, viresh.kumar,
beata.michalska, sudeep.holla
Cc: llvm, oe-kbuild-all, linux-arm-kernel, linux-pm, linux-kernel,
linuxarm, jonathan.cameron, vincent.guittot, yangyicong, zhanjie9,
lihuisong, yubowen8, linhongye, zhenglifeng1
Hi Lifeng,
kernel test robot noticed the following build errors:
[auto build test ERROR on arm64/for-next/core]
[also build test ERROR on rafael-pm/linux-next rafael-pm/bleeding-edge arm/for-next arm/fixes kvmarm/next soc/for-next linus/master v6.16 next-20250806]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Lifeng-Zheng/arm64-topology-Set-scale-freq-source-only-for-the-CPUs-that-have-not-been-set-before/20250806-101537
base: https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-next/core
patch link: https://lore.kernel.org/r/20250805093330.3715444-4-zhenglifeng1%40huawei.com
patch subject: [PATCH v3 3/3] arm64: topology: Setup AMU FIE for online CPUs only
config: arm64-randconfig-002-20250806 (https://download.01.org/0day-ci/archive/20250806/202508062127.qvRnTPvH-lkp@intel.com/config)
compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project 7b8dea265e72c3037b6b1e54d5ab51b7e14f328b)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250806/202508062127.qvRnTPvH-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202508062127.qvRnTPvH-lkp@intel.com/
All errors (new ones prefixed by >>):
>> arch/arm64/kernel/topology.c:409:34: error: call to undeclared function 'cpufreq_cpu_get_raw_no_check'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
409 | struct cpufreq_policy *policy = cpufreq_cpu_get_raw_no_check(cpu);
| ^
arch/arm64/kernel/topology.c:409:34: note: did you mean 'cpufreq_cpu_get_raw'?
include/linux/cpufreq.h:212:38: note: 'cpufreq_cpu_get_raw' declared here
212 | static inline struct cpufreq_policy *cpufreq_cpu_get_raw(unsigned int cpu)
| ^
>> arch/arm64/kernel/topology.c:409:25: error: incompatible integer to pointer conversion initializing 'struct cpufreq_policy *' with an expression of type 'int' [-Wint-conversion]
409 | struct cpufreq_policy *policy = cpufreq_cpu_get_raw_no_check(cpu);
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 errors generated.
vim +/cpufreq_cpu_get_raw_no_check +409 arch/arm64/kernel/topology.c
406
407 static int cpuhp_topology_online(unsigned int cpu)
408 {
> 409 struct cpufreq_policy *policy = cpufreq_cpu_get_raw_no_check(cpu);
410
411 /*
412 * If the online CPUs are not all AMU FIE CPUs or the new one is already
413 * an AMU FIE one, no need to set it.
414 */
415 if (!policy || !cpumask_available(amu_fie_cpus) ||
416 !cpumask_subset(policy->cpus, amu_fie_cpus) ||
417 cpumask_test_cpu(cpu, amu_fie_cpus))
418 return 0;
419
420 /*
421 * If the new online CPU cannot pass this check, all the CPUs related to
422 * the same policy should be clear from amu_fie_cpus mask, otherwise they
423 * may use different source of the freq scale.
424 */
425 if (!freq_counters_valid(cpu)) {
426 topology_clear_scale_freq_source(SCALE_FREQ_SOURCE_ARCH,
427 policy->related_cpus);
428 cpumask_andnot(amu_fie_cpus, amu_fie_cpus, policy->related_cpus);
429 return 0;
430 }
431
432 cpumask_set_cpu(cpu, amu_fie_cpus);
433
434 topology_set_scale_freq_source(&amu_sfd, cpumask_of(cpu));
435
436 pr_debug("CPU[%u]: counter will be used for FIE.", cpu);
437
438 return 0;
439 }
440
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3 3/3] arm64: topology: Setup AMU FIE for online CPUs only
2025-08-05 9:33 ` [PATCH v3 3/3] arm64: topology: Setup AMU FIE for online CPUs only Lifeng Zheng
2025-08-06 9:55 ` Beata Michalska
2025-08-06 13:45 ` kernel test robot
@ 2025-08-06 13:45 ` kernel test robot
2 siblings, 0 replies; 11+ messages in thread
From: kernel test robot @ 2025-08-06 13:45 UTC (permalink / raw)
To: Lifeng Zheng, catalin.marinas, will, rafael, viresh.kumar,
beata.michalska, sudeep.holla
Cc: oe-kbuild-all, linux-arm-kernel, linux-pm, linux-kernel, linuxarm,
jonathan.cameron, vincent.guittot, yangyicong, zhanjie9,
lihuisong, yubowen8, linhongye, zhenglifeng1
Hi Lifeng,
kernel test robot noticed the following build warnings:
[auto build test WARNING on arm64/for-next/core]
[also build test WARNING on rafael-pm/linux-next rafael-pm/bleeding-edge arm/for-next arm/fixes kvmarm/next soc/for-next linus/master v6.16 next-20250806]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Lifeng-Zheng/arm64-topology-Set-scale-freq-source-only-for-the-CPUs-that-have-not-been-set-before/20250806-101537
base: https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-next/core
patch link: https://lore.kernel.org/r/20250805093330.3715444-4-zhenglifeng1%40huawei.com
patch subject: [PATCH v3 3/3] arm64: topology: Setup AMU FIE for online CPUs only
config: arm64-randconfig-003-20250806 (https://download.01.org/0day-ci/archive/20250806/202508062150.aKsrWjHB-lkp@intel.com/config)
compiler: aarch64-linux-gcc (GCC) 9.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250806/202508062150.aKsrWjHB-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202508062150.aKsrWjHB-lkp@intel.com/
All warnings (new ones prefixed by >>):
arch/arm64/kernel/topology.c: In function 'cpuhp_topology_online':
arch/arm64/kernel/topology.c:409:34: error: implicit declaration of function 'cpufreq_cpu_get_raw_no_check'; did you mean 'cpufreq_cpu_get_raw'? [-Werror=implicit-function-declaration]
409 | struct cpufreq_policy *policy = cpufreq_cpu_get_raw_no_check(cpu);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
| cpufreq_cpu_get_raw
>> arch/arm64/kernel/topology.c:409:34: warning: initialization of 'struct cpufreq_policy *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
cc1: some warnings being treated as errors
vim +409 arch/arm64/kernel/topology.c
406
407 static int cpuhp_topology_online(unsigned int cpu)
408 {
> 409 struct cpufreq_policy *policy = cpufreq_cpu_get_raw_no_check(cpu);
410
411 /*
412 * If the online CPUs are not all AMU FIE CPUs or the new one is already
413 * an AMU FIE one, no need to set it.
414 */
415 if (!policy || !cpumask_available(amu_fie_cpus) ||
416 !cpumask_subset(policy->cpus, amu_fie_cpus) ||
417 cpumask_test_cpu(cpu, amu_fie_cpus))
418 return 0;
419
420 /*
421 * If the new online CPU cannot pass this check, all the CPUs related to
422 * the same policy should be clear from amu_fie_cpus mask, otherwise they
423 * may use different source of the freq scale.
424 */
425 if (!freq_counters_valid(cpu)) {
426 topology_clear_scale_freq_source(SCALE_FREQ_SOURCE_ARCH,
427 policy->related_cpus);
428 cpumask_andnot(amu_fie_cpus, amu_fie_cpus, policy->related_cpus);
429 return 0;
430 }
431
432 cpumask_set_cpu(cpu, amu_fie_cpus);
433
434 topology_set_scale_freq_source(&amu_sfd, cpumask_of(cpu));
435
436 pr_debug("CPU[%u]: counter will be used for FIE.", cpu);
437
438 return 0;
439 }
440
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3 3/3] arm64: topology: Setup AMU FIE for online CPUs only
2025-08-06 9:55 ` Beata Michalska
@ 2025-08-13 10:17 ` zhenglifeng (A)
2025-08-13 11:08 ` Beata Michalska
0 siblings, 1 reply; 11+ messages in thread
From: zhenglifeng (A) @ 2025-08-13 10:17 UTC (permalink / raw)
To: Beata Michalska
Cc: catalin.marinas, will, rafael, viresh.kumar, sudeep.holla,
linux-arm-kernel, linux-pm, linux-kernel, linuxarm,
jonathan.cameron, vincent.guittot, yangyicong, zhanjie9,
lihuisong, yubowen8, linhongye
On 2025/8/6 17:55, Beata Michalska wrote:
> On Tue, Aug 05, 2025 at 05:33:30PM +0800, Lifeng Zheng wrote:
>> When boot with maxcpu=1 restrict, and LPI(Low Power Idle States) is on,
>> only CPU0 will go online. The support AMU flag of CPU0 will be set but the
>> flags of other CPUs will not. This will cause AMU FIE set up fail for CPU0
>> when it shares a cpufreq policy with other CPU(s). After that, when other
>> CPUs are finally online and the support AMU flags of them are set, they'll
>> never have a chance to set up AMU FIE, even though they're eligible.
>>
>> To solve this problem, the process of setting up AMU FIE needs to be
>> modified as follows:
>>
>> 1. Set up AMU FIE only for the online CPUs.
>>
>> 2. Try to set up AMU FIE each time a CPU goes online and do the
>> freq_counters_valid() check. If this check fails, clear scale freq source
>> of all the CPUs related to the same policy, in case they use different
>> source of the freq scale.
>>
>> Signed-off-by: Lifeng Zheng <zhenglifeng1@huawei.com>
>> ---
>> arch/arm64/kernel/topology.c | 54 ++++++++++++++++++++++++++++++++++--
>> 1 file changed, 52 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c
>> index 9317a618bb87..b68621b3c071 100644
>> --- a/arch/arm64/kernel/topology.c
>> +++ b/arch/arm64/kernel/topology.c
>> @@ -385,7 +385,7 @@ static int init_amu_fie_callback(struct notifier_block *nb, unsigned long val,
>> struct cpufreq_policy *policy = data;
>>
>> if (val == CPUFREQ_CREATE_POLICY)
>> - amu_fie_setup(policy->related_cpus);
>> + amu_fie_setup(policy->cpus);
> I think my previous comment still stands.
> This will indeed set the AMU FIE support for online cpus.
> Still, on each frequency change, arch_set_freq_scale will be called with
> `related_cpus`, and that mask will be used to verify support for AMU counters,
> and it will report there is none as 'related_cpus' won't be a subset of
> `scale_freq_counters_mask`. As a consequence, new scale will be set, as seen by
> the cpufreq. Now this will be corrected on next tick but it might cause
> disruptions. So this change should also be applied to cpufreq - if feasible, or
> at least be proven not to be an issue. Unless I am missing smth.
I know what you mean now. Yes, I think you are right, this change should
also be applied to cpufreq too. Thanks!
>>
>> /*
>> * We don't need to handle CPUFREQ_REMOVE_POLICY event as the AMU
>> @@ -404,10 +404,60 @@ static struct notifier_block init_amu_fie_notifier = {
>> .notifier_call = init_amu_fie_callback,
>> };
>>
>> +static int cpuhp_topology_online(unsigned int cpu)
>> +{
>> + struct cpufreq_policy *policy = cpufreq_cpu_get_raw_no_check(cpu);
>> +
>> + /*
>> + * If the online CPUs are not all AMU FIE CPUs or the new one is already
>> + * an AMU FIE one, no need to set it.
>> + */
>> + if (!policy || !cpumask_available(amu_fie_cpus) ||
>> + !cpumask_subset(policy->cpus, amu_fie_cpus) ||
>> + cpumask_test_cpu(cpu, amu_fie_cpus))
>> + return 0;
> This is getting rather cumbersome as the CPU that is coming online might belong
> to a policy that is yet to be created. Both AMU FIE support, as well as cpufreq,
> rely on dynamic hp state so, in theory, we cannot be certain that the cpufreq
> callback will be fired first (although that seems to be the case).
> If that does not happen, the policy will not exist, and as such given CPU
> will not use AMUs for FIE. The problem might be hypothetical but it at least
> deservers a comment I think.
Actually, this callback will always be fired before the cpufreq one,
because init_amu_fie() is called before any cpufreq driver init func (It
has to be, otherwise the init_amu_fie_notifier cannot be registered before
it is needed.). And the callback that is setup first will be called first
when online if rely on dynamic hp state. So in your hypothetical scenario,
yes, the policy will not exist and this funcion will do nothing. But that's
OK because the notifier callback will do what should be done when the
policy is being created.
> Second problem is cpumask_available use: this might be the very fist CPU that
> might potentially rely on AMUs for frequency invariance so that mask may not be
> available yet. That does not mean AMUs setup should be skipped. Not just yet,
> at least. Again more hypothetical.
Same, things will be done in the notifier callback when the policy is being
created.
> BTW, there should be `amu_fie_cpu_supported'.
Sorry, I can't see why it is needed. Could you explained further?
>> +
>> + /*
>> + * If the new online CPU cannot pass this check, all the CPUs related to
>> + * the same policy should be clear from amu_fie_cpus mask, otherwise they
>> + * may use different source of the freq scale.
>> + */
>> + if (!freq_counters_valid(cpu)) {
>> + topology_clear_scale_freq_source(SCALE_FREQ_SOURCE_ARCH,
>> + policy->related_cpus);
>> + cpumask_andnot(amu_fie_cpus, amu_fie_cpus, policy->related_cpus);
> I think it might deserve a warning as this probably should not happen.
Yes, makes sense. Thanks!
>
> ---
> BR
> Beata
>> + return 0;
>> + }
>> +
>> + cpumask_set_cpu(cpu, amu_fie_cpus);
>> +
>> + topology_set_scale_freq_source(&amu_sfd, cpumask_of(cpu));
>> +
>> + pr_debug("CPU[%u]: counter will be used for FIE.", cpu);
>> +
>> + return 0;
>> +}
>> +
>> static int __init init_amu_fie(void)
>> {
>> - return cpufreq_register_notifier(&init_amu_fie_notifier,
>> + int ret;
>> +
>> + ret = cpufreq_register_notifier(&init_amu_fie_notifier,
>> CPUFREQ_POLICY_NOTIFIER);
>> + if (ret)
>> + return ret;
>> +
>> + ret = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN,
>> + "arm64/topology:online",
>> + cpuhp_topology_online,
>> + NULL);
>> + if (ret < 0) {
>> + cpufreq_unregister_notifier(&init_amu_fie_notifier,
>> + CPUFREQ_POLICY_NOTIFIER);
>> + return ret;
>> + }
>> +
>> + return 0;
>> }
>> core_initcall(init_amu_fie);
>>
>> --
>> 2.33.0
>>
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3 3/3] arm64: topology: Setup AMU FIE for online CPUs only
2025-08-13 10:17 ` zhenglifeng (A)
@ 2025-08-13 11:08 ` Beata Michalska
0 siblings, 0 replies; 11+ messages in thread
From: Beata Michalska @ 2025-08-13 11:08 UTC (permalink / raw)
To: zhenglifeng (A)
Cc: catalin.marinas, will, rafael, viresh.kumar, sudeep.holla,
linux-arm-kernel, linux-pm, linux-kernel, linuxarm,
jonathan.cameron, vincent.guittot, yangyicong, zhanjie9,
lihuisong, yubowen8, linhongye
On Wed, Aug 13, 2025 at 06:17:54PM +0800, zhenglifeng (A) wrote:
> On 2025/8/6 17:55, Beata Michalska wrote:
>
> > On Tue, Aug 05, 2025 at 05:33:30PM +0800, Lifeng Zheng wrote:
> >> When boot with maxcpu=1 restrict, and LPI(Low Power Idle States) is on,
> >> only CPU0 will go online. The support AMU flag of CPU0 will be set but the
> >> flags of other CPUs will not. This will cause AMU FIE set up fail for CPU0
> >> when it shares a cpufreq policy with other CPU(s). After that, when other
> >> CPUs are finally online and the support AMU flags of them are set, they'll
> >> never have a chance to set up AMU FIE, even though they're eligible.
> >>
> >> To solve this problem, the process of setting up AMU FIE needs to be
> >> modified as follows:
> >>
> >> 1. Set up AMU FIE only for the online CPUs.
> >>
> >> 2. Try to set up AMU FIE each time a CPU goes online and do the
> >> freq_counters_valid() check. If this check fails, clear scale freq source
> >> of all the CPUs related to the same policy, in case they use different
> >> source of the freq scale.
> >>
> >> Signed-off-by: Lifeng Zheng <zhenglifeng1@huawei.com>
> >> ---
> >> arch/arm64/kernel/topology.c | 54 ++++++++++++++++++++++++++++++++++--
> >> 1 file changed, 52 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c
> >> index 9317a618bb87..b68621b3c071 100644
> >> --- a/arch/arm64/kernel/topology.c
> >> +++ b/arch/arm64/kernel/topology.c
> >> @@ -385,7 +385,7 @@ static int init_amu_fie_callback(struct notifier_block *nb, unsigned long val,
> >> struct cpufreq_policy *policy = data;
> >>
> >> if (val == CPUFREQ_CREATE_POLICY)
> >> - amu_fie_setup(policy->related_cpus);
> >> + amu_fie_setup(policy->cpus);
> > I think my previous comment still stands.
> > This will indeed set the AMU FIE support for online cpus.
> > Still, on each frequency change, arch_set_freq_scale will be called with
> > `related_cpus`, and that mask will be used to verify support for AMU counters,
> > and it will report there is none as 'related_cpus' won't be a subset of
> > `scale_freq_counters_mask`. As a consequence, new scale will be set, as seen by
> > the cpufreq. Now this will be corrected on next tick but it might cause
> > disruptions. So this change should also be applied to cpufreq - if feasible, or
> > at least be proven not to be an issue. Unless I am missing smth.
>
> I know what you mean now. Yes, I think you are right, this change should
> also be applied to cpufreq too. Thanks!
>
> >>
> >> /*
> >> * We don't need to handle CPUFREQ_REMOVE_POLICY event as the AMU
> >> @@ -404,10 +404,60 @@ static struct notifier_block init_amu_fie_notifier = {
> >> .notifier_call = init_amu_fie_callback,
> >> };
> >>
> >> +static int cpuhp_topology_online(unsigned int cpu)
> >> +{
> >> + struct cpufreq_policy *policy = cpufreq_cpu_get_raw_no_check(cpu);
> >> +
> >> + /*
> >> + * If the online CPUs are not all AMU FIE CPUs or the new one is already
> >> + * an AMU FIE one, no need to set it.
> >> + */
> >> + if (!policy || !cpumask_available(amu_fie_cpus) ||
> >> + !cpumask_subset(policy->cpus, amu_fie_cpus) ||
> >> + cpumask_test_cpu(cpu, amu_fie_cpus))
> >> + return 0;
> > This is getting rather cumbersome as the CPU that is coming online might belong
> > to a policy that is yet to be created. Both AMU FIE support, as well as cpufreq,
> > rely on dynamic hp state so, in theory, we cannot be certain that the cpufreq
> > callback will be fired first (although that seems to be the case).
> > If that does not happen, the policy will not exist, and as such given CPU
> > will not use AMUs for FIE. The problem might be hypothetical but it at least
> > deservers a comment I think.
>
> Actually, this callback will always be fired before the cpufreq one,
> because init_amu_fie() is called before any cpufreq driver init func (It
> has to be, otherwise the init_amu_fie_notifier cannot be registered before
> it is needed.). And the callback that is setup first will be called first
> when online if rely on dynamic hp state. So in your hypothetical scenario,
> yes, the policy will not exist and this funcion will do nothing. But that's
> OK because the notifier callback will do what should be done when the
> policy is being created.
>
You are right, I definitely drifted away too much with this one.
> > Second problem is cpumask_available use: this might be the very fist CPU that
> > might potentially rely on AMUs for frequency invariance so that mask may not be
> > available yet. That does not mean AMUs setup should be skipped. Not just yet,
> > at least. Again more hypothetical.
>
> Same, things will be done in the notifier callback when the policy is being
> created.
>
> > BTW, there should be `amu_fie_cpu_supported'.
>
> Sorry, I can't see why it is needed. Could you explained further?
It covers the 'cpumask_available' and `cpumask_test_cpu` so I was thinking
your condition could look like:
if (!policy || amu_fie_cpu_supported(cpu) ||
!cpumask_subset(policy->cpus, amu_fie_cpus)
return 0
but that one will not cover all cases so feel free to ignore me.
---
BR
Beata
>
> >> +
> >> + /*
> >> + * If the new online CPU cannot pass this check, all the CPUs related to
> >> + * the same policy should be clear from amu_fie_cpus mask, otherwise they
> >> + * may use different source of the freq scale.
> >> + */
> >> + if (!freq_counters_valid(cpu)) {
> >> + topology_clear_scale_freq_source(SCALE_FREQ_SOURCE_ARCH,
> >> + policy->related_cpus);
> >> + cpumask_andnot(amu_fie_cpus, amu_fie_cpus, policy->related_cpus);
> > I think it might deserve a warning as this probably should not happen.
>
> Yes, makes sense. Thanks!
>
> >
> > ---
> > BR
> > Beata
> >> + return 0;
> >> + }
> >> +
> >> + cpumask_set_cpu(cpu, amu_fie_cpus);
> >> +
> >> + topology_set_scale_freq_source(&amu_sfd, cpumask_of(cpu));
> >> +
> >> + pr_debug("CPU[%u]: counter will be used for FIE.", cpu);
> >> +
> >> + return 0;
> >> +}
> >> +
> >> static int __init init_amu_fie(void)
> >> {
> >> - return cpufreq_register_notifier(&init_amu_fie_notifier,
> >> + int ret;
> >> +
> >> + ret = cpufreq_register_notifier(&init_amu_fie_notifier,
> >> CPUFREQ_POLICY_NOTIFIER);
> >> + if (ret)
> >> + return ret;
> >> +
> >> + ret = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN,
> >> + "arm64/topology:online",
> >> + cpuhp_topology_online,
> >> + NULL);
> >> + if (ret < 0) {
> >> + cpufreq_unregister_notifier(&init_amu_fie_notifier,
> >> + CPUFREQ_POLICY_NOTIFIER);
> >> + return ret;
> >> + }
> >> +
> >> + return 0;
> >> }
> >> core_initcall(init_amu_fie);
> >>
> >> --
> >> 2.33.0
> >>
> >
>
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2025-08-13 11:08 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-05 9:33 [PATCH v3 0/3] arm64: topology: Setup AMU FIE for online CPUs only Lifeng Zheng
2025-08-05 9:33 ` [PATCH v3 1/3] arm64: topology: Set scale freq source only for the CPUs that have not been set before Lifeng Zheng
2025-08-05 9:33 ` [PATCH v3 2/3] cpufreq: Add a new function to get cpufreq policy without checking if the CPU is online Lifeng Zheng
2025-08-05 12:57 ` Rafael J. Wysocki
2025-08-05 13:32 ` zhenglifeng (A)
2025-08-05 9:33 ` [PATCH v3 3/3] arm64: topology: Setup AMU FIE for online CPUs only Lifeng Zheng
2025-08-06 9:55 ` Beata Michalska
2025-08-13 10:17 ` zhenglifeng (A)
2025-08-13 11:08 ` Beata Michalska
2025-08-06 13:45 ` kernel test robot
2025-08-06 13:45 ` kernel test robot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).