All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ankur Arora <ankur.a.arora@oracle.com>
To: "Okanovic, Haris" <harisokn@amazon.com>
Cc: "ankur.a.arora@oracle.com" <ankur.a.arora@oracle.com>,
	"joao.m.martins@oracle.com" <joao.m.martins@oracle.com>,
	"xueshuai@linux.alibaba.com" <xueshuai@linux.alibaba.com>,
	"david.laight.linux@gmail.com" <david.laight.linux@gmail.com>,
	"boris.ostrovsky@oracle.com" <boris.ostrovsky@oracle.com>,
	"memxor@gmail.com" <memxor@gmail.com>,
	"ashok.bhat@arm.com" <ashok.bhat@arm.com>,
	"zhenglifeng1@huawei.com" <zhenglifeng1@huawei.com>,
	"konrad.wilk@oracle.com" <konrad.wilk@oracle.com>,
	"cl@gentwo.org" <cl@gentwo.org>,
	"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"catalin.marinas@arm.com" <catalin.marinas@arm.com>,
	"ast@kernel.org" <ast@kernel.org>,
	"rdunlap@infradead.org" <rdunlap@infradead.org>,
	"daniel.lezcano@linaro.org" <daniel.lezcano@linaro.org>,
	"arnd@arndb.de" <arnd@arndb.de>,
	"linux-arch@vger.kernel.org" <linux-arch@vger.kernel.org>,
	"will@kernel.org" <will@kernel.org>,
	"mark.rutland@arm.com" <mark.rutland@arm.com>,
	"peterz@infradead.org" <peterz@infradead.org>,
	"bpf@vger.kernel.org" <bpf@vger.kernel.org>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"rafael@kernel.org" <rafael@kernel.org>,
	"linux-pm@vger.kernel.org" <linux-pm@vger.kernel.org>
Subject: Re: [PATCH v11 12/14] cpuidle/poll_state: Wait for need-resched via tif_need_resched_relaxed_wait()
Date: Mon, 20 Apr 2026 10:50:08 -0700	[thread overview]
Message-ID: <87mryxh67j.fsf@oracle.com> (raw)
In-Reply-To: <a374b23f8b03f850a874d46bc78411fb99483ca2.camel@amazon.com>


Okanovic, Haris <harisokn@amazon.com> writes:

> On Wed, 2026-04-08 at 17:55 +0530, Ankur Arora wrote:
>> CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
>>
>>
>>
>> The inner loop in poll_idle() polls over the thread_info flags,
>> waiting to see if the thread has TIF_NEED_RESCHED set. The loop
>> exits once the condition is met, or if the poll time limit has
>> been exceeded.
>>
>> To minimize the number of instructions executed in each iteration,
>> the time check is rate-limited. In addition, each loop iteration
>> executes cpu_relax() which on certain platforms provides a hint to
>> the pipeline that the loop busy-waits, allowing the processor to
>> reduce power consumption.
>>
>> Switch over to tif_need_resched_relaxed_wait() instead, since that
>> provides exactly that.
>>
>> However, since we want to minimize power consumption in idle, building
>> of cpuidle/poll_state.c continues to depend on CONFIG_ARCH_HAS_CPU_RELAX
>> as that serves as an indicator that the platform supports an optimized
>> version of tif_need_resched_relaxed_wait() (via
>> smp_cond_load_acquire_timeout()).
>>
>> Cc: Rafael J. Wysocki <rafael@kernel.org>
>> Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
>> Cc: linux-pm@vger.kernel.org
>> Suggested-by: Rafael J. Wysocki <rafael@kernel.org>
>> Acked-by: Rafael J. Wysocki (Intel) <rafael@kernel.org>
>> Signed-off-by: Ankur Arora <ankur.a.arora@oracle.com>
>> ---
>>  drivers/cpuidle/poll_state.c | 21 +--------------------
>>  1 file changed, 1 insertion(+), 20 deletions(-)
>>
>> diff --git a/drivers/cpuidle/poll_state.c b/drivers/cpuidle/poll_state.c
>> index c7524e4c522a..7443b3e971ba 100644
>> --- a/drivers/cpuidle/poll_state.c
>> +++ b/drivers/cpuidle/poll_state.c
>> @@ -6,41 +6,22 @@
>>  #include <linux/cpuidle.h>
>>  #include <linux/export.h>
>>  #include <linux/irqflags.h>
>> -#include <linux/sched.h>
>> -#include <linux/sched/clock.h>
>>  #include <linux/sched/idle.h>
>>  #include <linux/sprintf.h>
>>  #include <linux/types.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();
>> -
>>         dev->poll_time_limit = false;
>>
>>         raw_local_irq_enable();
>>         if (!current_set_polling_and_test()) {
>> -               unsigned int loop_count = 0;
>>                 u64 limit;
>>
>>                 limit = cpuidle_poll_time(drv, dev);
>>
>> -               while (!need_resched()) {
>> -                       cpu_relax();
>> -                       if (loop_count++ < POLL_IDLE_RELAX_COUNT)
>> -                               continue;
>> -
>> -                       loop_count = 0;
>> -                       if (local_clock_noinstr() - time_start > limit) {
>> -                               dev->poll_time_limit = true;
>> -                               break;
>> -                       }
>> -               }
>> +               dev->poll_time_limit = !tif_need_resched_relaxed_wait(limit);
>>         }
>>         raw_local_irq_disable();
>>
>> --
>> 2.31.1
>>
>
> Hi Ankur,
>
> Tested atop latest mainline d60bc1401 with the rest of your haltpoll
> changes from separate thread:
> ~10% improvement in `perf sched bench pipe` micro and ~4-6% throughput
> improvements in mysql,
> postgresql, cassandra, and memcached in under-loaded configurations.
> Tested on AWS Graviton3 and
> Graviton4, ARM Neoverse V1 and V2 cores respectively.
>
> I hope this series can merge soon. It's been stuck in review for more
> than 2 years.
>
> Tested-by: Haris Okanovic <harisokn@amazon.com>

Thanks Haris. Yeah, I don't think there are any open issues left on
this.

--
ankur

  reply	other threads:[~2026-04-20 17:50 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-08 12:25 [PATCH v11 00/14] barrier: Add smp_cond_load_{relaxed,acquire}_timeout() Ankur Arora
2026-04-08 12:25 ` [PATCH v11 01/14] asm-generic: barrier: Add smp_cond_load_relaxed_timeout() Ankur Arora
2026-05-06  7:30   ` Ankur Arora
2026-05-06  8:58     ` David Laight
2026-05-06 20:54       ` Ankur Arora
2026-05-07  9:57         ` David Laight
2026-05-08  6:31           ` Ankur Arora
2026-05-08  8:32             ` David Laight
2026-04-08 12:25 ` [PATCH v11 02/14] arm64: barrier: Support smp_cond_load_relaxed_timeout() Ankur Arora
2026-04-08 12:25 ` [PATCH v11 03/14] arm64/delay: move some constants out to a separate header Ankur Arora
2026-04-08 12:25 ` [PATCH v11 04/14] arm64: support WFET in smp_cond_load_relaxed_timeout() Ankur Arora
2026-04-08 12:25 ` [PATCH v11 05/14] arm64: rqspinlock: Remove private copy of smp_cond_load_acquire_timewait() Ankur Arora
2026-04-08 12:25 ` [PATCH v11 06/14] asm-generic: barrier: Add smp_cond_load_acquire_timeout() Ankur Arora
2026-04-08 12:25 ` [PATCH v11 07/14] atomic: Add atomic_cond_read_*_timeout() Ankur Arora
2026-04-08 12:25 ` [PATCH v11 08/14] locking/atomic: scripts: build atomic_long_cond_read_*_timeout() Ankur Arora
2026-04-08 12:25 ` [PATCH v11 09/14] bpf/rqspinlock: switch check_timeout() to a clock interface Ankur Arora
2026-04-08 12:25 ` [PATCH v11 10/14] bpf/rqspinlock: Use smp_cond_load_acquire_timeout() Ankur Arora
2026-04-08 12:25 ` [PATCH v11 11/14] sched: add need-resched timed wait interface Ankur Arora
2026-04-08 12:25 ` [PATCH v11 12/14] cpuidle/poll_state: Wait for need-resched via tif_need_resched_relaxed_wait() Ankur Arora
2026-04-20 16:57   ` Okanovic, Haris
2026-04-20 17:50     ` Ankur Arora [this message]
2026-04-21  7:15       ` Catalin Marinas
2026-04-20 22:12     ` Christoph Lameter (Ampere)
2026-04-08 12:25 ` [PATCH v11 13/14] kunit: enable testing smp_cond_load_relaxed_timeout() Ankur Arora
2026-04-08 12:25 ` [PATCH v11 14/14] kunit: add tests for smp_cond_load_relaxed_timeout() Ankur Arora
2026-04-23 17:16 ` [PATCH v11 00/14] barrier: Add smp_cond_load_{relaxed,acquire}_timeout() Andrew Morton
2026-04-23 19:29   ` Ankur Arora
2026-04-24 14:16     ` [PATCH v11 00/14] barrier: Add smp_cond_load_{relaxed, acquire}_timeout() Okanovic, Haris
2026-04-24 14:10   ` Okanovic, Haris
2026-04-24 14:28 ` [PATCH v11 00/14] barrier: Add smp_cond_load_{relaxed,acquire}_timeout() Andrew Morton
2026-04-24 18:10   ` Ankur Arora

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87mryxh67j.fsf@oracle.com \
    --to=ankur.a.arora@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=ashok.bhat@arm.com \
    --cc=ast@kernel.org \
    --cc=boris.ostrovsky@oracle.com \
    --cc=bpf@vger.kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=cl@gentwo.org \
    --cc=daniel.lezcano@linaro.org \
    --cc=david.laight.linux@gmail.com \
    --cc=harisokn@amazon.com \
    --cc=joao.m.martins@oracle.com \
    --cc=konrad.wilk@oracle.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=memxor@gmail.com \
    --cc=peterz@infradead.org \
    --cc=rafael@kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=will@kernel.org \
    --cc=xueshuai@linux.alibaba.com \
    --cc=zhenglifeng1@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.