From: Ankur Arora <ankur.a.arora@oracle.com>
To: "Tomohiro Misono (Fujitsu)" <misono.tomohiro@fujitsu.com>
Cc: 'Ankur Arora' <ankur.a.arora@oracle.com>,
"linux-pm@vger.kernel.org" <linux-pm@vger.kernel.org>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"catalin.marinas@arm.com" <catalin.marinas@arm.com>,
"will@kernel.org" <will@kernel.org>,
"tglx@linutronix.de" <tglx@linutronix.de>,
"mingo@redhat.com" <mingo@redhat.com>,
"bp@alien8.de" <bp@alien8.de>,
"dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>,
"x86@kernel.org" <x86@kernel.org>,
"hpa@zytor.com" <hpa@zytor.com>,
"pbonzini@redhat.com" <pbonzini@redhat.com>,
"wanpengli@tencent.com" <wanpengli@tencent.com>,
"vkuznets@redhat.com" <vkuznets@redhat.com>,
"rafael@kernel.org" <rafael@kernel.org>,
"daniel.lezcano@linaro.org" <daniel.lezcano@linaro.org>,
"peterz@infradead.org" <peterz@infradead.org>,
"arnd@arndb.de" <arnd@arndb.de>,
"lenb@kernel.org" <lenb@kernel.org>,
"mark.rutland@arm.com" <mark.rutland@arm.com>,
"harisokn@amazon.com" <harisokn@amazon.com>,
"mtosatti@redhat.com" <mtosatti@redhat.com>,
"sudeep.holla@arm.com" <sudeep.holla@arm.com>,
"cl@gentwo.org" <cl@gentwo.org>,
"joao.m.martins@oracle.com" <joao.m.martins@oracle.com>,
"boris.ostrovsky@oracle.com" <boris.ostrovsky@oracle.com>,
"konrad.wilk@oracle.com" <konrad.wilk@oracle.com>
Subject: Re: [PATCH v6 01/10] cpuidle/poll_state: poll via smp_cond_load_relaxed()
Date: Mon, 12 Aug 2024 15:36:20 -0700 [thread overview]
Message-ID: <8734n9s717.fsf@oracle.com> (raw)
In-Reply-To: <TY3PR01MB11148449A97A47AF875036994E5BA2@TY3PR01MB11148.jpnprd01.prod.outlook.com>
Tomohiro Misono (Fujitsu) <misono.tomohiro@fujitsu.com> writes:
>> Subject: [PATCH v6 01/10] cpuidle/poll_state: poll via smp_cond_load_relaxed()
>>
>> From: Mihai Carabas <mihai.carabas@oracle.com>
>>
>> The inner loop in poll_idle() polls up to POLL_IDLE_RELAX_COUNT times,
>> checking to see if the thread has the TIF_NEED_RESCHED bit 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 each iteration, the
>> time check is done only infrequently (once every POLL_IDLE_RELAX_COUNT
>> iterations). In addition, each loop iteration executes cpu_relax()
>> which on certain platforms provides a hint to the pipeline that the
>> loop is busy-waiting, thus allowing the processor to reduce power
>> consumption.
>>
>> However, cpu_relax() is defined optimally only on x86. On arm64, for
>> instance, it is implemented as a YIELD which only serves a hint to the
>> CPU that it prioritize a different hardware thread if one is available.
>> arm64, however, does expose a more optimal polling mechanism via
>> smp_cond_load_relaxed() which uses LDXR, WFE to wait until a store
>> to a specified region.
>>
>> So restructure the loop, folding both checks in smp_cond_load_relaxed().
>> Also, move the time check to the head of the loop allowing it to exit
>> straight-away once TIF_NEED_RESCHED is set.
>>
>> Suggested-by: Peter Zijlstra <peterz@infradead.org>
>> Signed-off-by: Mihai Carabas <mihai.carabas@oracle.com>
>> Signed-off-by: Ankur Arora <ankur.a.arora@oracle.com>
>> ---
>> drivers/cpuidle/poll_state.c | 10 +++++-----
>> 1 file changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/cpuidle/poll_state.c b/drivers/cpuidle/poll_state.c
>> index 9b6d90a72601..532e4ed19e0f 100644
>> --- a/drivers/cpuidle/poll_state.c
>> +++ b/drivers/cpuidle/poll_state.c
>> @@ -21,21 +21,21 @@ static int __cpuidle poll_idle(struct cpuidle_device *dev,
>>
>> raw_local_irq_enable();
>> if (!current_set_polling_and_test()) {
>> - unsigned int loop_count = 0;
>> + unsigned int loop_count;
>> 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;
>> }
>> +
>> + smp_cond_load_relaxed(¤t_thread_info()->flags,
>> + VAL & _TIF_NEED_RESCHED ||
>> + loop_count++ >= POLL_IDLE_RELAX_COUNT);
>> }
>> }
>> raw_local_irq_disable();
>> --
>> 2.43.5
>
> Reviewed-by: Misono Tomohiro <misono.tomohiro@fujitsu.com>
Thanks!
--
ankur
next prev parent reply other threads:[~2024-08-12 22:37 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-26 20:13 [PATCH v6 00/10] Enable haltpoll on arm64 Ankur Arora
2024-07-26 20:13 ` [PATCH v6 01/10] cpuidle/poll_state: poll via smp_cond_load_relaxed() Ankur Arora
2024-08-05 23:07 ` Christoph Lameter (Ampere)
2024-08-12 22:35 ` Ankur Arora
2024-08-09 5:54 ` Tomohiro Misono (Fujitsu)
2024-08-12 22:36 ` Ankur Arora [this message]
2024-07-26 20:13 ` [PATCH v6 02/10] cpuidle: rename ARCH_HAS_CPU_RELAX to ARCH_HAS_OPTIMIZED_POLL Ankur Arora
2024-08-05 23:09 ` Christoph Lameter (Ampere)
2024-07-26 20:21 ` [PATCH v6 03/10] Kconfig: move ARCH_HAS_OPTIMIZED_POLL to arch/Kconfig Ankur Arora
2024-07-26 20:21 ` [PATCH v6 04/10] cpuidle-haltpoll: define arch_haltpoll_want() Ankur Arora
2024-07-26 20:21 ` [PATCH v6 05/10] governors/haltpoll: drop kvm_para_available() check Ankur Arora
2024-07-26 20:21 ` [PATCH v6 06/10] cpuidle-haltpoll: condition on ARCH_CPUIDLE_HALTPOLL Ankur Arora
2024-07-26 20:21 ` [PATCH v6 07/10] arm64: define TIF_POLLING_NRFLAG Ankur Arora
2024-08-05 23:13 ` Christoph Lameter (Ampere)
2024-08-12 22:35 ` Ankur Arora
2024-07-26 20:21 ` [PATCH v6 08/10] arm64: idle: export arch_cpu_idle Ankur Arora
2024-07-26 20:21 ` [PATCH v6 09/10] arm64: support cpuidle-haltpoll Ankur Arora
2024-07-29 17:20 ` Okanovic, Haris
2024-07-29 18:02 ` Ankur Arora
2024-08-13 15:26 ` Okanovic, Haris
2024-08-13 18:56 ` Ankur Arora
2024-08-13 21:14 ` Okanovic, Haris
2024-08-06 1:37 ` maobibo
2024-08-12 22:48 ` Ankur Arora
2024-08-13 0:54 ` maobibo
2024-08-09 6:08 ` Tomohiro Misono (Fujitsu)
2024-07-26 20:21 ` [PATCH v6 10/10] cpuidle/poll_state: limit POLL_IDLE_RELAX_COUNT on arm64 Ankur Arora
2024-08-09 6:02 ` [PATCH v6 00/10] Enable haltpoll " Tomohiro Misono (Fujitsu)
2024-08-12 22:43 ` 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=8734n9s717.fsf@oracle.com \
--to=ankur.a.arora@oracle.com \
--cc=arnd@arndb.de \
--cc=boris.ostrovsky@oracle.com \
--cc=bp@alien8.de \
--cc=catalin.marinas@arm.com \
--cc=cl@gentwo.org \
--cc=daniel.lezcano@linaro.org \
--cc=dave.hansen@linux.intel.com \
--cc=harisokn@amazon.com \
--cc=hpa@zytor.com \
--cc=joao.m.martins@oracle.com \
--cc=konrad.wilk@oracle.com \
--cc=kvm@vger.kernel.org \
--cc=lenb@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=mingo@redhat.com \
--cc=misono.tomohiro@fujitsu.com \
--cc=mtosatti@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=rafael@kernel.org \
--cc=sudeep.holla@arm.com \
--cc=tglx@linutronix.de \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.com \
--cc=will@kernel.org \
--cc=x86@kernel.org \
/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.