linux-riscv.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: "'guoren@kernel.org'" <guoren@kernel.org>,
	"palmer@rivosinc.com" <palmer@rivosinc.com>,
	"arnd@arndb.de" <arnd@arndb.de>,
	"mingo@redhat.com" <mingo@redhat.com>,
	"will@kernel.org" <will@kernel.org>,
	"longman@redhat.com" <longman@redhat.com>,
	"boqun.feng@gmail.com" <boqun.feng@gmail.com>
Cc: "linux-riscv@lists.infradead.org"
	<linux-riscv@lists.infradead.org>,
	"linux-arch@vger.kernel.org" <linux-arch@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Guo Ren <guoren@linux.alibaba.com>,
	Peter Zijlstra <peterz@infradead.org>
Subject: RE: [PATCH V7 1/5] asm-generic: ticket-lock: Remove unnecessary atomic_read
Date: Wed, 29 Jun 2022 08:27:19 +0000	[thread overview]
Message-ID: <8eaf85d4e4d9401ea187366de12e7269@AcuMS.aculab.com> (raw)
In-Reply-To: <20220628081707.1997728-2-guoren@kernel.org>

From: guoren@kernel.org
> Sent: 28 June 2022 09:17
> 
> From: Guo Ren <guoren@linux.alibaba.com>
> 
> Remove unnecessary atomic_read in arch_spin_value_unlocked(lock),
> because the value has been in lock. This patch could prevent
> arch_spin_value_unlocked contend spin_lock data again.

I'm confused (as usual).
Isn't atomic_read() pretty much free?

..
> diff --git a/include/asm-generic/spinlock.h b/include/asm-generic/spinlock.h
> index fdfebcb050f4..f1e4fa100f5a 100644
> --- a/include/asm-generic/spinlock.h
> +++ b/include/asm-generic/spinlock.h
> @@ -84,7 +84,9 @@ static __always_inline int arch_spin_is_contended(arch_spinlock_t *lock)
> 
>  static __always_inline int arch_spin_value_unlocked(arch_spinlock_t lock)
>  {
> -	return !arch_spin_is_locked(&lock);
> +	u32 val = lock.counter;
> +
> +	return ((val >> 16) == (val & 0xffff));

That almost certainly needs a READ_ONCE().

The result is also inherently stale.
So the uses must be pretty limited.

	David

>  }
> 
>  #include <asm/qrwlock.h>
> --
> 2.36.1

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


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

  parent reply	other threads:[~2022-06-29  8:27 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-28  8:17 [PATCH V7 0/5] riscv: Add qspinlock support with combo style guoren
2022-06-28  8:17 ` [PATCH V7 1/5] asm-generic: ticket-lock: Remove unnecessary atomic_read guoren
2022-06-28 18:05   ` Waiman Long
2022-06-29  2:12     ` Guo Ren
2022-06-29  8:27   ` David Laight [this message]
2022-07-01 15:18     ` Guo Ren
2022-07-04  9:52   ` Peter Zijlstra
2022-07-04 11:10     ` Guo Ren
2022-06-28  8:17 ` [PATCH V7 2/5] asm-generic: ticket-lock: Use the same struct definitions with qspinlock guoren
2022-06-28  8:17 ` [PATCH V7 3/5] asm-generic: ticket-lock: Move into ticket_spinlock.h guoren
2022-06-28  8:17 ` [PATCH V7 4/5] asm-generic: spinlock: Add combo spinlock (ticket & queued) guoren
2022-06-28 18:13   ` Waiman Long
2022-06-29  1:17     ` Guo Ren
2022-06-29  1:34       ` Waiman Long
2022-06-29  2:29         ` Guo Ren
2022-06-29  7:08         ` Arnd Bergmann
2022-06-29  8:24           ` Guo Ren
2022-06-29  8:29             ` Arnd Bergmann
2022-07-01 12:18               ` Guo Ren
2022-06-29 12:53           ` Waiman Long
2022-07-04  9:57   ` Peter Zijlstra
2022-07-04 13:13     ` Guo Ren
2022-07-04 13:45       ` Peter Zijlstra
2022-06-28  8:17 ` [PATCH V7 5/5] riscv: Add qspinlock support guoren

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=8eaf85d4e4d9401ea187366de12e7269@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=arnd@arndb.de \
    --cc=boqun.feng@gmail.com \
    --cc=guoren@kernel.org \
    --cc=guoren@linux.alibaba.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=longman@redhat.com \
    --cc=mingo@redhat.com \
    --cc=palmer@rivosinc.com \
    --cc=peterz@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).