All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marc Zyngier <maz@kernel.org>
To: Catalin Marinas <catalin.marinas@arm.com>
Cc: kernel-team@android.com, kvm@vger.kernel.org,
	Joey Gouly <joey.gouly@arm.com>, Will Deacon <will@kernel.org>,
	kvmarm@lists.cs.columbia.edu,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v2 10/10] arm64: Use WFxT for __delay() when possible
Date: Wed, 20 Apr 2022 19:35:49 +0100	[thread overview]
Message-ID: <87levza9h6.wl-maz@kernel.org> (raw)
In-Reply-To: <YmBGYLpaJJ3OZMQV@arm.com>

On Wed, 20 Apr 2022 18:44:00 +0100,
Catalin Marinas <catalin.marinas@arm.com> wrote:
> 
> On Tue, Apr 19, 2022 at 07:27:55PM +0100, Marc Zyngier wrote:
> > Marginally optimise __delay() by using a WFIT/WFET sequence.
> > It probably is a win if no interrupt fires during the delay.
> > 
> > Signed-off-by: Marc Zyngier <maz@kernel.org>
> > ---
> >  arch/arm64/lib/delay.c | 12 +++++++++++-
> >  1 file changed, 11 insertions(+), 1 deletion(-)
> > 
> > diff --git a/arch/arm64/lib/delay.c b/arch/arm64/lib/delay.c
> > index 1688af0a4c97..5b7890139bc2 100644
> > --- a/arch/arm64/lib/delay.c
> > +++ b/arch/arm64/lib/delay.c
> > @@ -27,7 +27,17 @@ void __delay(unsigned long cycles)
> >  {
> >  	cycles_t start = get_cycles();
> >  
> > -	if (arch_timer_evtstrm_available()) {
> > +	if (cpus_have_const_cap(ARM64_HAS_WFXT)) {
> > +		u64 end = start + cycles;
> > +
> > +		/*
> > +		 * Start with WFIT. If an interrupt makes us resume
> > +		 * early, use a WFET loop to complete the delay.
> > +		 */
> > +		wfit(end);
> > +		while ((get_cycles() - start) < cycles)
> > +			wfet(end);
> 
> Do you use WFET here as a pending interrupt would cause WFIT to complete
> immediately?

Yes, that's the idea. Even if a pending interrupt is not immediately
present, it could come halfway through, shortening the delay, and
making WFIT useless until the interrupt is acknowledged.

I would have loved for WFIT to return a status indicating whether the
wakeup was for a pending interrupt or for another reason (such as
reaching the timeout), but apparently it was too much to ask... Maybe
in ARMv11!  ;-)

> 
> > +	} else 	if (arch_timer_evtstrm_available()) {
> 
> Nit: two spaces between else and if ;).

I'll make sure to fix this! ;-)

> 
> Acked-by: Catalin Marinas <catalin.marinas@arm.com>
> 

Thanks,

	M.

-- 
Without deviation from the norm, progress is not possible.
_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

WARNING: multiple messages have this Message-ID (diff)
From: Marc Zyngier <maz@kernel.org>
To: Catalin Marinas <catalin.marinas@arm.com>
Cc: linux-arm-kernel@lists.infradead.org,
	kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org,
	Will Deacon <will@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	James Morse <james.morse@arm.com>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	Alexandru Elisei <alexandru.elisei@arm.com>,
	Joey Gouly <joey.gouly@arm.com>,
	kernel-team@android.com
Subject: Re: [PATCH v2 10/10] arm64: Use WFxT for __delay() when possible
Date: Wed, 20 Apr 2022 19:35:49 +0100	[thread overview]
Message-ID: <87levza9h6.wl-maz@kernel.org> (raw)
In-Reply-To: <YmBGYLpaJJ3OZMQV@arm.com>

On Wed, 20 Apr 2022 18:44:00 +0100,
Catalin Marinas <catalin.marinas@arm.com> wrote:
> 
> On Tue, Apr 19, 2022 at 07:27:55PM +0100, Marc Zyngier wrote:
> > Marginally optimise __delay() by using a WFIT/WFET sequence.
> > It probably is a win if no interrupt fires during the delay.
> > 
> > Signed-off-by: Marc Zyngier <maz@kernel.org>
> > ---
> >  arch/arm64/lib/delay.c | 12 +++++++++++-
> >  1 file changed, 11 insertions(+), 1 deletion(-)
> > 
> > diff --git a/arch/arm64/lib/delay.c b/arch/arm64/lib/delay.c
> > index 1688af0a4c97..5b7890139bc2 100644
> > --- a/arch/arm64/lib/delay.c
> > +++ b/arch/arm64/lib/delay.c
> > @@ -27,7 +27,17 @@ void __delay(unsigned long cycles)
> >  {
> >  	cycles_t start = get_cycles();
> >  
> > -	if (arch_timer_evtstrm_available()) {
> > +	if (cpus_have_const_cap(ARM64_HAS_WFXT)) {
> > +		u64 end = start + cycles;
> > +
> > +		/*
> > +		 * Start with WFIT. If an interrupt makes us resume
> > +		 * early, use a WFET loop to complete the delay.
> > +		 */
> > +		wfit(end);
> > +		while ((get_cycles() - start) < cycles)
> > +			wfet(end);
> 
> Do you use WFET here as a pending interrupt would cause WFIT to complete
> immediately?

Yes, that's the idea. Even if a pending interrupt is not immediately
present, it could come halfway through, shortening the delay, and
making WFIT useless until the interrupt is acknowledged.

I would have loved for WFIT to return a status indicating whether the
wakeup was for a pending interrupt or for another reason (such as
reaching the timeout), but apparently it was too much to ask... Maybe
in ARMv11!  ;-)

> 
> > +	} else 	if (arch_timer_evtstrm_available()) {
> 
> Nit: two spaces between else and if ;).

I'll make sure to fix this! ;-)

> 
> Acked-by: Catalin Marinas <catalin.marinas@arm.com>
> 

Thanks,

	M.

-- 
Without deviation from the norm, progress is not possible.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

WARNING: multiple messages have this Message-ID (diff)
From: Marc Zyngier <maz@kernel.org>
To: Catalin Marinas <catalin.marinas@arm.com>
Cc: linux-arm-kernel@lists.infradead.org,
	kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org,
	Will Deacon <will@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	James Morse <james.morse@arm.com>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	Alexandru Elisei <alexandru.elisei@arm.com>,
	Joey Gouly <joey.gouly@arm.com>,
	kernel-team@android.com
Subject: Re: [PATCH v2 10/10] arm64: Use WFxT for __delay() when possible
Date: Wed, 20 Apr 2022 19:35:49 +0100	[thread overview]
Message-ID: <87levza9h6.wl-maz@kernel.org> (raw)
In-Reply-To: <YmBGYLpaJJ3OZMQV@arm.com>

On Wed, 20 Apr 2022 18:44:00 +0100,
Catalin Marinas <catalin.marinas@arm.com> wrote:
> 
> On Tue, Apr 19, 2022 at 07:27:55PM +0100, Marc Zyngier wrote:
> > Marginally optimise __delay() by using a WFIT/WFET sequence.
> > It probably is a win if no interrupt fires during the delay.
> > 
> > Signed-off-by: Marc Zyngier <maz@kernel.org>
> > ---
> >  arch/arm64/lib/delay.c | 12 +++++++++++-
> >  1 file changed, 11 insertions(+), 1 deletion(-)
> > 
> > diff --git a/arch/arm64/lib/delay.c b/arch/arm64/lib/delay.c
> > index 1688af0a4c97..5b7890139bc2 100644
> > --- a/arch/arm64/lib/delay.c
> > +++ b/arch/arm64/lib/delay.c
> > @@ -27,7 +27,17 @@ void __delay(unsigned long cycles)
> >  {
> >  	cycles_t start = get_cycles();
> >  
> > -	if (arch_timer_evtstrm_available()) {
> > +	if (cpus_have_const_cap(ARM64_HAS_WFXT)) {
> > +		u64 end = start + cycles;
> > +
> > +		/*
> > +		 * Start with WFIT. If an interrupt makes us resume
> > +		 * early, use a WFET loop to complete the delay.
> > +		 */
> > +		wfit(end);
> > +		while ((get_cycles() - start) < cycles)
> > +			wfet(end);
> 
> Do you use WFET here as a pending interrupt would cause WFIT to complete
> immediately?

Yes, that's the idea. Even if a pending interrupt is not immediately
present, it could come halfway through, shortening the delay, and
making WFIT useless until the interrupt is acknowledged.

I would have loved for WFIT to return a status indicating whether the
wakeup was for a pending interrupt or for another reason (such as
reaching the timeout), but apparently it was too much to ask... Maybe
in ARMv11!  ;-)

> 
> > +	} else 	if (arch_timer_evtstrm_available()) {
> 
> Nit: two spaces between else and if ;).

I'll make sure to fix this! ;-)

> 
> Acked-by: Catalin Marinas <catalin.marinas@arm.com>
> 

Thanks,

	M.

-- 
Without deviation from the norm, progress is not possible.

  reply	other threads:[~2022-04-20 18:36 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-19 18:27 [PATCH v2 00/10] arm64: Add initial support for FEAT_WFxT Marc Zyngier
2022-04-19 18:27 ` Marc Zyngier
2022-04-19 18:27 ` Marc Zyngier
2022-04-19 18:27 ` [PATCH v2 01/10] arm64: Expand ESR_ELx_WFx_ISS_TI to match its ARMv8.7 definition Marc Zyngier
2022-04-19 18:27   ` Marc Zyngier
2022-04-19 18:27   ` Marc Zyngier
2022-04-20 17:24   ` Catalin Marinas
2022-04-20 17:24     ` Catalin Marinas
2022-04-20 17:24     ` Catalin Marinas
2022-04-19 18:27 ` [PATCH v2 02/10] arm64: Add RV and RN fields for ESR_ELx_WFx_ISS Marc Zyngier
2022-04-19 18:27   ` Marc Zyngier
2022-04-19 18:27   ` Marc Zyngier
2022-04-20 17:25   ` Catalin Marinas
2022-04-20 17:25     ` Catalin Marinas
2022-04-20 17:25     ` Catalin Marinas
2022-04-19 18:27 ` [PATCH v2 03/10] KVM: arm64: Simplify kvm_cpu_has_pending_timer() Marc Zyngier
2022-04-19 18:27   ` Marc Zyngier
2022-04-19 18:27   ` Marc Zyngier
2022-04-19 18:27 ` [PATCH v2 04/10] KVM: arm64: Introduce kvm_counter_compute_delta() helper Marc Zyngier
2022-04-19 18:27   ` Marc Zyngier
2022-04-19 18:27   ` Marc Zyngier
2022-04-19 18:27 ` [PATCH v2 05/10] KVM: arm64: Handle blocking WFIT instruction Marc Zyngier
2022-04-19 18:27   ` Marc Zyngier
2022-04-19 18:27   ` Marc Zyngier
2022-04-19 18:27 ` [PATCH v2 06/10] KVM: arm64: Offer early resume for non-blocking WFxT instructions Marc Zyngier
2022-04-19 18:27   ` Marc Zyngier
2022-04-19 18:27   ` Marc Zyngier
2022-04-19 18:27 ` [PATCH v2 07/10] KVM: arm64: Expose the WFXT feature to guests Marc Zyngier
2022-04-19 18:27   ` Marc Zyngier
2022-04-19 18:27   ` Marc Zyngier
2022-04-20 17:46   ` Catalin Marinas
2022-04-20 17:46     ` Catalin Marinas
2022-04-20 17:46     ` Catalin Marinas
2022-04-19 18:27 ` [PATCH v2 08/10] arm64: Add HWCAP advertising FEAT_WFXT Marc Zyngier
2022-04-19 18:27   ` Marc Zyngier
2022-04-19 18:27   ` Marc Zyngier
2022-04-20 17:27   ` Catalin Marinas
2022-04-20 17:27     ` Catalin Marinas
2022-04-20 17:27     ` Catalin Marinas
2022-04-20 18:39     ` Marc Zyngier
2022-04-20 18:39       ` Marc Zyngier
2022-04-20 18:39       ` Marc Zyngier
2022-04-19 18:27 ` [PATCH v2 09/10] arm64: Add wfet()/wfit() helpers Marc Zyngier
2022-04-19 18:27   ` Marc Zyngier
2022-04-19 18:27   ` Marc Zyngier
2022-04-20 17:28   ` Catalin Marinas
2022-04-20 17:28     ` Catalin Marinas
2022-04-20 17:28     ` Catalin Marinas
2022-04-19 18:27 ` [PATCH v2 10/10] arm64: Use WFxT for __delay() when possible Marc Zyngier
2022-04-19 18:27   ` Marc Zyngier
2022-04-19 18:27   ` Marc Zyngier
2022-04-20 17:44   ` Catalin Marinas
2022-04-20 17:44     ` Catalin Marinas
2022-04-20 17:44     ` Catalin Marinas
2022-04-20 18:35     ` Marc Zyngier [this message]
2022-04-20 18:35       ` Marc Zyngier
2022-04-20 18:35       ` Marc Zyngier
2022-04-20 17:24 ` [PATCH v2 00/10] arm64: Add initial support for FEAT_WFxT Catalin Marinas
2022-04-20 17:24   ` Catalin Marinas
2022-04-20 17:24   ` Catalin Marinas
2022-04-20 18:50   ` Marc Zyngier
2022-04-20 18:50     ` Marc Zyngier
2022-04-20 18:50     ` Marc Zyngier

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=87levza9h6.wl-maz@kernel.org \
    --to=maz@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=joey.gouly@arm.com \
    --cc=kernel-team@android.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=will@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.