The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] arm64: topology: fix arch_cpu_idle_enter()
@ 2026-08-07 13:52 seanwang1
  2026-08-10  2:08 ` Xuewen Yan
  2026-08-10  6:26 ` Beata Michalska
  0 siblings, 2 replies; 4+ messages in thread
From: seanwang1 @ 2026-08-07 13:52 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon
  Cc: linux-arm-kernel, linux-kernel, Beata Michalska, Lifeng Zheng,
	Greg Kroah-Hartman, Geert Uytterhoeven, Sumit Gupta, Yunhui Cui,
	seanwang1, Xuewen Yan

arch_cpu_idle_enter() directly calls amu_scale_freq_tick() to update
arch_freq_scale when CPU enters idle state. 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.

Fix by replacing the direct amu_scale_freq_tick() call with
topology_scale_freq_tick(), which is the generic interface for updating
frequency scale and properly respects the sft_data pointer state.

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 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c
index b32f13358fbb..f617ef5c9903 100644
--- a/arch/arm64/kernel/topology.c
+++ b/arch/arm64/kernel/topology.c
@@ -176,7 +176,7 @@ void arch_cpu_idle_enter(void)
 	/* 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)))
-		amu_scale_freq_tick();
+		topology_scale_freq_tick();
 }
 
 #define AMU_SAMPLE_EXP_MS	20
-- 
2.25.1


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

* Re: [PATCH] arm64: topology: fix arch_cpu_idle_enter()
  2026-08-07 13:52 [PATCH] arm64: topology: fix arch_cpu_idle_enter() seanwang1
@ 2026-08-10  2:08 ` Xuewen Yan
  2026-08-10  6:26 ` Beata Michalska
  1 sibling, 0 replies; 4+ messages in thread
From: Xuewen Yan @ 2026-08-10  2:08 UTC (permalink / raw)
  To: seanwang1
  Cc: Catalin Marinas, Will Deacon, linux-arm-kernel, linux-kernel,
	Beata Michalska, Lifeng Zheng, Greg Kroah-Hartman,
	Geert Uytterhoeven, Sumit Gupta, Yunhui Cui, Xuewen Yan

Hi sean,

On Fri, Aug 7, 2026 at 10:07 PM seanwang1 <seanwang1@lenovo.com> wrote:
>
> arch_cpu_idle_enter() directly calls amu_scale_freq_tick() to update
> arch_freq_scale when CPU enters idle state. 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.
>
> Fix by replacing the direct amu_scale_freq_tick() call with
> topology_scale_freq_tick(), which is the generic interface for updating
> frequency scale and properly respects the sft_data pointer state.
>
> 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 | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c
> index b32f13358fbb..f617ef5c9903 100644
> --- a/arch/arm64/kernel/topology.c
> +++ b/arch/arm64/kernel/topology.c
> @@ -176,7 +176,7 @@ void arch_cpu_idle_enter(void)
>         /* 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)))
> -               amu_scale_freq_tick();
> +               topology_scale_freq_tick();

Need we add rcu_lock/unlock?

>  }
>
>  #define AMU_SAMPLE_EXP_MS      20
> --
> 2.25.1
>
>

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

* Re: [PATCH] arm64: topology: fix arch_cpu_idle_enter()
  2026-08-07 13:52 [PATCH] arm64: topology: fix arch_cpu_idle_enter() seanwang1
  2026-08-10  2:08 ` Xuewen Yan
@ 2026-08-10  6:26 ` Beata Michalska
  2026-08-10  8:02   ` Sean Wang1
  1 sibling, 1 reply; 4+ messages in thread
From: Beata Michalska @ 2026-08-10  6:26 UTC (permalink / raw)
  To: seanwang1
  Cc: Catalin Marinas, Will Deacon, linux-arm-kernel, linux-kernel,
	Lifeng Zheng, Greg Kroah-Hartman, Geert Uytterhoeven, Sumit Gupta,
	Yunhui Cui, Xuewen Yan

On Fri, Aug 07, 2026 at 09:52:16PM +0800, seanwang1 wrote:
> arch_cpu_idle_enter() directly calls amu_scale_freq_tick() to update
> arch_freq_scale when CPU enters idle state. 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.
> 
> Fix by replacing the direct amu_scale_freq_tick() call with
> topology_scale_freq_tick(), which is the generic interface for updating
> frequency scale and properly respects the sft_data pointer state.
> 
> 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 | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c
> index b32f13358fbb..f617ef5c9903 100644
> --- a/arch/arm64/kernel/topology.c
> +++ b/arch/arm64/kernel/topology.c
> @@ -176,7 +176,7 @@ void arch_cpu_idle_enter(void)
>  	/* 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)))
> -		amu_scale_freq_tick();
> +		topology_scale_freq_tick();
>  }
That actually changes semantics here. This path is strictly AMU-oriented and
topology_scale_freq_tick is a dispatcher that does not really care about the
actual source of the scale info. So it would be best if this could verify
whether AMUs are the current source and call a tick only then, bailing out
otherwise.

---
BR
Beata
>  
>  #define AMU_SAMPLE_EXP_MS	20
> -- 
> 2.25.1
> 

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

* Re: Re: [PATCH] arm64: topology: fix arch_cpu_idle_enter()
  2026-08-10  6:26 ` Beata Michalska
@ 2026-08-10  8:02   ` Sean Wang1
  0 siblings, 0 replies; 4+ messages in thread
From: Sean Wang1 @ 2026-08-10  8:02 UTC (permalink / raw)
  To: Beata Michalska
  Cc: Catalin Marinas, Will Deacon,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, Lifeng Zheng, Greg Kroah-Hartman,
	Geert Uytterhoeven, Sumit Gupta, Yunhui Cui, Xuewen Yan

On Mon, Aug 10, 2026 at 02:26PM, Beata Michalska wrote:
>
> That actually changes semantics here. This path is strictly AMU-oriented and
> topology_scale_freq_tick is a dispatcher that does not really care about the
> actual source of the scale info. So it would be best if this could verify whether
> AMUs are the current source and call a tick only then, bailing out otherwise.

You're right. Using topology_scale_freq_tick() here would incorrectly invoke a non-AMU source's callback if one has been registered after AMU was cleared.

I'll add a helper topology_scale_freq_source() to check whether AMU is the current source.

I will send v2 with this approach.

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

end of thread, other threads:[~2026-08-10  8:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-07 13:52 [PATCH] arm64: topology: fix arch_cpu_idle_enter() seanwang1
2026-08-10  2:08 ` Xuewen Yan
2026-08-10  6:26 ` Beata Michalska
2026-08-10  8:02   ` Sean Wang1

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox