[PATCH v4 0/5] barrier: Add smp_cond_load_*_timewait()
Ankur Arora
ankur.a.arora at oracle.com
Tue Sep 2 15:46:52 PDT 2025
Catalin Marinas <catalin.marinas at arm.com> writes:
> On Fri, Aug 29, 2025 at 01:07:30AM -0700, Ankur Arora wrote:
>> Ankur Arora (5):
>> asm-generic: barrier: Add smp_cond_load_relaxed_timewait()
>> arm64: barrier: Add smp_cond_load_relaxed_timewait()
>> arm64: rqspinlock: Remove private copy of
>> smp_cond_load_acquire_timewait
>> asm-generic: barrier: Add smp_cond_load_acquire_timewait()
>> rqspinlock: use smp_cond_load_acquire_timewait()
>
> Can you have a go at poll_idle() to see how it would look like using
> this API? It doesn't necessarily mean we have to merge them all at once
> but it gives us a better idea of the suitability of the interface.
So, I've been testing with some version of the following:
diff --git a/drivers/cpuidle/poll_state.c b/drivers/cpuidle/poll_state.c
index 9b6d90a72601..361879396d0c 100644
--- a/drivers/cpuidle/poll_state.c
+++ b/drivers/cpuidle/poll_state.c
@@ -8,35 +8,25 @@
#include <linux/sched/clock.h>
#include <linux/sched/idle.h>
-#define POLL_IDLE_RELAX_COUNT 200
-
static int __cpuidle poll_idle(struct cpuidle_device *dev,
struct cpuidle_driver *drv, int index)
{
- u64 time_start;
-
- time_start = local_clock_noinstr();
+ unsigned long flags;
dev->poll_time_limit = false;
raw_local_irq_enable();
if (!current_set_polling_and_test()) {
- unsigned int loop_count = 0;
- u64 limit;
+ u64 limit, time_end;
limit = cpuidle_poll_time(drv, dev);
+ time_end = local_clock_noinstr() + limit;
- while (!need_resched()) {
- cpu_relax();
- if (loop_count++ < POLL_IDLE_RELAX_COUNT)
- continue;
+ flags = smp_cond_load_relaxed_timewait(¤t_thread_info()->flags,
+ VAL & _TIF_NEED_RESCHED,
+ (local_clock_noinstr() >= time_end));
- loop_count = 0;
- if (local_clock_noinstr() - time_start > limit) {
- dev->poll_time_limit = true;
- break;
- }
- }
+ dev->poll_time_limit = (local_clock_noinstr() >= time_end);
}
raw_local_irq_disable();
With that, poll_idle() is:
static int __cpuidle poll_idle(struct cpuidle_device *dev,
struct cpuidle_driver *drv, int index)
{
unsigned long flags;
dev->poll_time_limit = false;
raw_local_irq_enable();
if (!current_set_polling_and_test()) {
u64 limit, time_end;
limit = cpuidle_poll_time(drv, dev);
time_end = local_clock_noinstr() + limit;
flags = smp_cond_load_relaxed_timewait(¤t_thread_info()->flags,
VAL & _TIF_NEED_RESCHED,
(local_clock_noinstr() >= time_end));
dev->poll_time_limit = (local_clock_noinstr() >= time_end);
}
raw_local_irq_disable();
current_clr_polling();
return index;
}
--
ankur
More information about the linux-arm-kernel
mailing list