* [PATCH v2] arm64: topology: add source check in arch_cpu_idle_enter()
@ 2026-08-10 10:20 seanwang1
2026-08-10 11:37 ` Greg Kroah-Hartman
2026-08-10 15:04 ` Sumit Gupta
0 siblings, 2 replies; 3+ messages in thread
From: seanwang1 @ 2026-08-10 10:20 UTC (permalink / raw)
To: Catalin Marinas, Will Deacon, Sudeep Holla, Greg Kroah-Hartman,
rafael, Danilo Krummrich
Cc: Lifeng Zheng, Beata Michalska, Xuewen Yan, Geert Uytterhoeven,
Sumit Gupta, Yunhui Cui, linux-arm-kernel, linux-kernel,
driver-core, seanwang1
arch_cpu_idle_enter() directly calls amu_scale_freq_tick() to update
arch_freq_scale when a CPU enters idle. This bypasses the sft_data
pointer check that topology_clear_scale_freq_source() relies on.
As a result, even after calling topology_clear_scale_freq_source()
with SCALE_FREQ_SOURCE_ARCH to disable AMU-based frequency scaling,
the arch_freq_scale value can still be modified by AMU counters when
the CPU goes idle through the arch_cpu_idle_enter() path.
Add topology_scale_freq_source() helper to check whether a specific
frequency scaling source is currently registered for a CPU. Use it
in arch_cpu_idle_enter() to verify that AMU is the active source
before calling amu_scale_freq_tick().
This ensures that topology_clear_scale_freq_source() properly
disables AMU updates in both the tick path (already handled by
topology_scale_freq_tick()) and the idle path.
Co-developed-by: Xuewen Yan <xuewen.yan@unisoc.com>
Signed-off-by: Sean Wang <seanwang1@lenovo.com>
Signed-off-by: Xuewen Yan <xuewen.yan@unisoc.com>
---
arch/arm64/kernel/topology.c | 3 +++
drivers/base/arch_topology.c | 14 ++++++++++++++
include/linux/arch_topology.h | 1 +
3 files changed, 18 insertions(+)
diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c
index b32f13358fbb..cae5da68d5ec 100644
--- a/arch/arm64/kernel/topology.c
+++ b/arch/arm64/kernel/topology.c
@@ -173,6 +173,9 @@ void arch_cpu_idle_enter(void)
if (!amu_fie_cpu_supported(cpu))
return;
+ if (!topology_scale_freq_source(SCALE_FREQ_SOURCE_ARCH, cpu))
+ return;
+
/* Kick in AMU update but only if one has not happened already */
if (housekeeping_cpu(cpu, HK_TYPE_TICK) &&
time_is_before_jiffies(per_cpu(cpu_amu_samples.last_scale_update, cpu)))
diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c
index 8c5e47c28d9a..dfc2574a5588 100644
--- a/drivers/base/arch_topology.c
+++ b/drivers/base/arch_topology.c
@@ -127,6 +127,20 @@ void topology_clear_scale_freq_source(enum scale_freq_source source,
}
EXPORT_SYMBOL_GPL(topology_clear_scale_freq_source);
+bool topology_scale_freq_source(enum scale_freq_source source, unsigned int cpu)
+{
+ struct scale_freq_data *sfd;
+ bool ret;
+
+ rcu_read_lock_sched();
+ sfd = rcu_dereference_sched(*per_cpu_ptr(&sft_data, cpu));
+ ret = (sfd && sfd->source == source);
+ rcu_read_unlock_sched();
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(topology_scale_freq_source);
+
void topology_scale_freq_tick(void)
{
struct scale_freq_data *sfd = rcu_dereference_sched(*this_cpu_ptr(&sft_data));
diff --git a/include/linux/arch_topology.h b/include/linux/arch_topology.h
index ebd7f8935f96..803382f599a2 100644
--- a/include/linux/arch_topology.h
+++ b/include/linux/arch_topology.h
@@ -48,6 +48,7 @@ struct scale_freq_data {
void topology_scale_freq_tick(void);
void topology_set_scale_freq_source(struct scale_freq_data *data, const struct cpumask *cpus);
void topology_clear_scale_freq_source(enum scale_freq_source source, const struct cpumask *cpus);
+bool topology_scale_freq_source(enum scale_freq_source source, unsigned int cpu);
DECLARE_PER_CPU(unsigned long, hw_pressure);
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] arm64: topology: add source check in arch_cpu_idle_enter()
2026-08-10 10:20 [PATCH v2] arm64: topology: add source check in arch_cpu_idle_enter() seanwang1
@ 2026-08-10 11:37 ` Greg Kroah-Hartman
2026-08-10 15:04 ` Sumit Gupta
1 sibling, 0 replies; 3+ messages in thread
From: Greg Kroah-Hartman @ 2026-08-10 11:37 UTC (permalink / raw)
To: seanwang1
Cc: Catalin Marinas, Will Deacon, Sudeep Holla, rafael,
Danilo Krummrich, Lifeng Zheng, Beata Michalska, Xuewen Yan,
Geert Uytterhoeven, Sumit Gupta, Yunhui Cui, linux-arm-kernel,
linux-kernel, driver-core
On Mon, Aug 10, 2026 at 06:20:06PM +0800, seanwang1 wrote:
> arch_cpu_idle_enter() directly calls amu_scale_freq_tick() to update
> arch_freq_scale when a CPU enters idle. This bypasses the sft_data
> pointer check that topology_clear_scale_freq_source() relies on.
>
> As a result, even after calling topology_clear_scale_freq_source()
> with SCALE_FREQ_SOURCE_ARCH to disable AMU-based frequency scaling,
> the arch_freq_scale value can still be modified by AMU counters when
> the CPU goes idle through the arch_cpu_idle_enter() path.
>
> Add topology_scale_freq_source() helper to check whether a specific
> frequency scaling source is currently registered for a CPU. Use it
> in arch_cpu_idle_enter() to verify that AMU is the active source
> before calling amu_scale_freq_tick().
>
> This ensures that topology_clear_scale_freq_source() properly
> disables AMU updates in both the tick path (already handled by
> topology_scale_freq_tick()) and the idle path.
>
> Co-developed-by: Xuewen Yan <xuewen.yan@unisoc.com>
> Signed-off-by: Sean Wang <seanwang1@lenovo.com>
> Signed-off-by: Xuewen Yan <xuewen.yan@unisoc.com>
> ---
The From: line does not match your signed-off-by name :(
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] arm64: topology: add source check in arch_cpu_idle_enter()
2026-08-10 10:20 [PATCH v2] arm64: topology: add source check in arch_cpu_idle_enter() seanwang1
2026-08-10 11:37 ` Greg Kroah-Hartman
@ 2026-08-10 15:04 ` Sumit Gupta
1 sibling, 0 replies; 3+ messages in thread
From: Sumit Gupta @ 2026-08-10 15:04 UTC (permalink / raw)
To: seanwang1, Catalin Marinas, Will Deacon, Sudeep Holla,
Greg Kroah-Hartman, rafael, Danilo Krummrich
Cc: Lifeng Zheng, Beata Michalska, Xuewen Yan, Geert Uytterhoeven,
Yunhui Cui, linux-arm-kernel, linux-kernel, driver-core
On 10/08/26 15:50, seanwang1 wrote:
> External email: Use caution opening links or attachments
>
>
> arch_cpu_idle_enter() directly calls amu_scale_freq_tick() to update
> arch_freq_scale when a CPU enters idle. This bypasses the sft_data
> pointer check that topology_clear_scale_freq_source() relies on.
>
> As a result, even after calling topology_clear_scale_freq_source()
> with SCALE_FREQ_SOURCE_ARCH to disable AMU-based frequency scaling,
> the arch_freq_scale value can still be modified by AMU counters when
> the CPU goes idle through the arch_cpu_idle_enter() path.
>
> Add topology_scale_freq_source() helper to check whether a specific
> frequency scaling source is currently registered for a CPU. Use it
> in arch_cpu_idle_enter() to verify that AMU is the active source
> before calling amu_scale_freq_tick().
>
> This ensures that topology_clear_scale_freq_source() properly
> disables AMU updates in both the tick path (already handled by
> topology_scale_freq_tick()) and the idle path.
>
> Co-developed-by: Xuewen Yan <xuewen.yan@unisoc.com>
> Signed-off-by: Sean Wang <seanwang1@lenovo.com>
> Signed-off-by: Xuewen Yan <xuewen.yan@unisoc.com>
> ---
> arch/arm64/kernel/topology.c | 3 +++
> drivers/base/arch_topology.c | 14 ++++++++++++++
> include/linux/arch_topology.h | 1 +
> 3 files changed, 18 insertions(+)
>
> diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c
> index b32f13358fbb..cae5da68d5ec 100644
> --- a/arch/arm64/kernel/topology.c
> +++ b/arch/arm64/kernel/topology.c
> @@ -173,6 +173,9 @@ void arch_cpu_idle_enter(void)
> if (!amu_fie_cpu_supported(cpu))
> return;
>
> + if (!topology_scale_freq_source(SCALE_FREQ_SOURCE_ARCH, cpu))
> + return;
> +
> /* Kick in AMU update but only if one has not happened already */
> if (housekeeping_cpu(cpu, HK_TYPE_TICK) &&
> time_is_before_jiffies(per_cpu(cpu_amu_samples.last_scale_update, cpu)))
How about moving it into the condition below, so we only take the RCU
read side when an update is due rather than on every idle entry?
if (housekeeping_cpu(cpu, HK_TYPE_TICK) &&
time_is_before_jiffies(per_cpu(cpu_amu_samples.last_scale_update, cpu)) &&
topology_scale_freq_source(SCALE_FREQ_SOURCE_ARCH, cpu))
amu_scale_freq_tick();
> diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c
> index 8c5e47c28d9a..dfc2574a5588 100644
> --- a/drivers/base/arch_topology.c
> +++ b/drivers/base/arch_topology.c
> @@ -127,6 +127,20 @@ void topology_clear_scale_freq_source(enum scale_freq_source source,
> }
> EXPORT_SYMBOL_GPL(topology_clear_scale_freq_source);
>
> +bool topology_scale_freq_source(enum scale_freq_source source, unsigned int cpu)
%s/topology_scale_freq_source/topology_is_scale_freq_source/ ?
> +{
> + struct scale_freq_data *sfd;
> + bool ret;
> +
> + rcu_read_lock_sched();
> + sfd = rcu_dereference_sched(*per_cpu_ptr(&sft_data, cpu));
> + ret = (sfd && sfd->source == source);
> + rcu_read_unlock_sched();
> +
> + return ret;
> +}
> +EXPORT_SYMBOL_GPL(topology_scale_freq_source);
> +
Do we need to export it?
Thanks,
Sumit
....
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-08-10 15:05 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-10 10:20 [PATCH v2] arm64: topology: add source check in arch_cpu_idle_enter() seanwang1
2026-08-10 11:37 ` Greg Kroah-Hartman
2026-08-10 15:04 ` Sumit Gupta
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox