* [PATCH] cpuidle: powerpc: avoid double clear when breaking snooze
@ 2026-03-10 15:28 Shrikanth Hegde
2026-03-11 5:12 ` Mukesh Kumar Chaurasiya
0 siblings, 1 reply; 2+ messages in thread
From: Shrikanth Hegde @ 2026-03-10 15:28 UTC (permalink / raw)
To: linuxppc-dev, maddy
Cc: sshegde, chleroy, nysal, mkchauras, rafael, daniel.lezcano,
christian.loehle
snooze_loop is done often in any system which has fair bit of
idle time. So it qualifies for even micro-optimizations.
When breaking the snooze due to timeout, TIF_POLLING_NRFLAG is cleared
twice. Clearing the bit invokes atomics. Avoid double clear and thereby
avoid one atomic write.
dev->poll_time_limit indicates whether the loop was broken due to
timeout. Use that instead of defining a new variable.
Signed-off-by: Shrikanth Hegde <sshegde@linux.ibm.com>
---
drivers/cpuidle/cpuidle-powernv.c | 5 ++++-
drivers/cpuidle/cpuidle-pseries.c | 5 ++++-
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/cpuidle/cpuidle-powernv.c b/drivers/cpuidle/cpuidle-powernv.c
index 9ebedd972df0..b89e7111e7b8 100644
--- a/drivers/cpuidle/cpuidle-powernv.c
+++ b/drivers/cpuidle/cpuidle-powernv.c
@@ -95,7 +95,10 @@ static int snooze_loop(struct cpuidle_device *dev,
HMT_medium();
ppc64_runlatch_on();
- clear_thread_flag(TIF_POLLING_NRFLAG);
+
+ /* Avoid double clear when breaking */
+ if (!dev->poll_time_limit)
+ clear_thread_flag(TIF_POLLING_NRFLAG);
local_irq_disable();
diff --git a/drivers/cpuidle/cpuidle-pseries.c b/drivers/cpuidle/cpuidle-pseries.c
index f68c65f1d023..864dd5d6e627 100644
--- a/drivers/cpuidle/cpuidle-pseries.c
+++ b/drivers/cpuidle/cpuidle-pseries.c
@@ -64,7 +64,10 @@ int snooze_loop(struct cpuidle_device *dev, struct cpuidle_driver *drv,
}
HMT_medium();
- clear_thread_flag(TIF_POLLING_NRFLAG);
+
+ /* Avoid double clear when breaking */
+ if (!dev->poll_time_limit)
+ clear_thread_flag(TIF_POLLING_NRFLAG);
raw_local_irq_disable();
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] cpuidle: powerpc: avoid double clear when breaking snooze
2026-03-10 15:28 [PATCH] cpuidle: powerpc: avoid double clear when breaking snooze Shrikanth Hegde
@ 2026-03-11 5:12 ` Mukesh Kumar Chaurasiya
0 siblings, 0 replies; 2+ messages in thread
From: Mukesh Kumar Chaurasiya @ 2026-03-11 5:12 UTC (permalink / raw)
To: Shrikanth Hegde
Cc: linuxppc-dev, maddy, chleroy, nysal, mkchauras, rafael,
daniel.lezcano, christian.loehle
On Tue, Mar 10, 2026 at 08:58:11PM +0530, Shrikanth Hegde wrote:
> snooze_loop is done often in any system which has fair bit of
> idle time. So it qualifies for even micro-optimizations.
>
> When breaking the snooze due to timeout, TIF_POLLING_NRFLAG is cleared
> twice. Clearing the bit invokes atomics. Avoid double clear and thereby
> avoid one atomic write.
>
> dev->poll_time_limit indicates whether the loop was broken due to
> timeout. Use that instead of defining a new variable.
>
> Signed-off-by: Shrikanth Hegde <sshegde@linux.ibm.com>
> ---
> drivers/cpuidle/cpuidle-powernv.c | 5 ++++-
> drivers/cpuidle/cpuidle-pseries.c | 5 ++++-
> 2 files changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/cpuidle/cpuidle-powernv.c b/drivers/cpuidle/cpuidle-powernv.c
> index 9ebedd972df0..b89e7111e7b8 100644
> --- a/drivers/cpuidle/cpuidle-powernv.c
> +++ b/drivers/cpuidle/cpuidle-powernv.c
> @@ -95,7 +95,10 @@ static int snooze_loop(struct cpuidle_device *dev,
>
> HMT_medium();
> ppc64_runlatch_on();
> - clear_thread_flag(TIF_POLLING_NRFLAG);
> +
> + /* Avoid double clear when breaking */
> + if (!dev->poll_time_limit)
> + clear_thread_flag(TIF_POLLING_NRFLAG);
>
> local_irq_disable();
>
> diff --git a/drivers/cpuidle/cpuidle-pseries.c b/drivers/cpuidle/cpuidle-pseries.c
> index f68c65f1d023..864dd5d6e627 100644
> --- a/drivers/cpuidle/cpuidle-pseries.c
> +++ b/drivers/cpuidle/cpuidle-pseries.c
> @@ -64,7 +64,10 @@ int snooze_loop(struct cpuidle_device *dev, struct cpuidle_driver *drv,
> }
>
> HMT_medium();
> - clear_thread_flag(TIF_POLLING_NRFLAG);
> +
> + /* Avoid double clear when breaking */
> + if (!dev->poll_time_limit)
> + clear_thread_flag(TIF_POLLING_NRFLAG);
>
> raw_local_irq_disable();
>
> --
> 2.43.0
>
>
LGTM
Reviewed-by: Mukesh Kumar Chaurasiya (IBM) <mkchauras@gmail.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-03-11 5:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-10 15:28 [PATCH] cpuidle: powerpc: avoid double clear when breaking snooze Shrikanth Hegde
2026-03-11 5:12 ` Mukesh Kumar Chaurasiya
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox