From: Waiman Long <longman@redhat.com>
To: Arnd Bergmann <arnd@kernel.org>, Arnd Bergmann <arnd@arndb.de>,
Matthew Wilcox <willy@infradead.org>,
Ingo Molnar <mingo@kernel.org>,
"Peter Zijlstra (Intel)" <peterz@infradead.org>,
Will Deacon <will@kernel.org>
Cc: Will Deacon <will.deacon@arm.com>,
Thomas Gleixner <tglx@linutronix.de>,
Nicholas Piggin <npiggin@gmail.com>,
Michael Ellerman <mpe@ellerman.id.au>,
Herbert Xu <herbert@gondor.apana.org.au>,
linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] qspinlock: use signed temporaries for cmpxchg
Date: Mon, 26 Oct 2020 14:03:06 -0400 [thread overview]
Message-ID: <022365e9-f7fe-5589-7867-d2ad2d33cfa3@redhat.com> (raw)
In-Reply-To: <20201026165807.3724647-1-arnd@kernel.org>
On 10/26/20 12:57 PM, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> When building with W=2, the build log is flooded with
>
> include/asm-generic/qrwlock.h:65:56: warning: pointer targets in passing argument 2 of 'atomic_try_cmpxchg_acquire' differ in signedness [-Wpointer-sign]
> include/asm-generic/qrwlock.h:92:53: warning: pointer targets in passing argument 2 of 'atomic_try_cmpxchg_acquire' differ in signedness [-Wpointer-sign]
> include/asm-generic/qspinlock.h:68:55: warning: pointer targets in passing argument 2 of 'atomic_try_cmpxchg_acquire' differ in signedness [-Wpointer-sign]
> include/asm-generic/qspinlock.h:82:52: warning: pointer targets in passing argument 2 of 'atomic_try_cmpxchg_acquire' differ in signedness [-Wpointer-sign]
>
> The atomics are built on top of signed integers, but the caller
> doesn't actually care. Just use signed types as well.
>
> Fixes: 27df89689e25 ("locking/spinlocks: Remove an instruction from spin and write locks")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> include/asm-generic/qrwlock.h | 8 ++++----
> include/asm-generic/qspinlock.h | 4 ++--
> 2 files changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/include/asm-generic/qrwlock.h b/include/asm-generic/qrwlock.h
> index 3aefde23dcea..84ce841ce735 100644
> --- a/include/asm-generic/qrwlock.h
> +++ b/include/asm-generic/qrwlock.h
> @@ -37,7 +37,7 @@ extern void queued_write_lock_slowpath(struct qrwlock *lock);
> */
> static inline int queued_read_trylock(struct qrwlock *lock)
> {
> - u32 cnts;
> + int cnts;
>
> cnts = atomic_read(&lock->cnts);
> if (likely(!(cnts & _QW_WMASK))) {
> @@ -56,7 +56,7 @@ static inline int queued_read_trylock(struct qrwlock *lock)
> */
> static inline int queued_write_trylock(struct qrwlock *lock)
> {
> - u32 cnts;
> + int cnts;
>
> cnts = atomic_read(&lock->cnts);
> if (unlikely(cnts))
> @@ -71,7 +71,7 @@ static inline int queued_write_trylock(struct qrwlock *lock)
> */
> static inline void queued_read_lock(struct qrwlock *lock)
> {
> - u32 cnts;
> + int cnts;
>
> cnts = atomic_add_return_acquire(_QR_BIAS, &lock->cnts);
> if (likely(!(cnts & _QW_WMASK)))
> @@ -87,7 +87,7 @@ static inline void queued_read_lock(struct qrwlock *lock)
> */
> static inline void queued_write_lock(struct qrwlock *lock)
> {
> - u32 cnts = 0;
> + int cnts = 0;
> /* Optimize for the unfair lock case where the fair flag is 0. */
> if (likely(atomic_try_cmpxchg_acquire(&lock->cnts, &cnts, _QW_LOCKED)))
> return;
> diff --git a/include/asm-generic/qspinlock.h b/include/asm-generic/qspinlock.h
> index 4fe7fd0fe834..d74b13825501 100644
> --- a/include/asm-generic/qspinlock.h
> +++ b/include/asm-generic/qspinlock.h
> @@ -60,7 +60,7 @@ static __always_inline int queued_spin_is_contended(struct qspinlock *lock)
> */
> static __always_inline int queued_spin_trylock(struct qspinlock *lock)
> {
> - u32 val = atomic_read(&lock->val);
> + int val = atomic_read(&lock->val);
>
> if (unlikely(val))
> return 0;
> @@ -77,7 +77,7 @@ extern void queued_spin_lock_slowpath(struct qspinlock *lock, u32 val);
> */
> static __always_inline void queued_spin_lock(struct qspinlock *lock)
> {
> - u32 val = 0;
> + int val = 0;
>
> if (likely(atomic_try_cmpxchg_acquire(&lock->val, &val, _Q_LOCKED_VAL)))
> return;
Yes, it shouldn't really matter if the value is defined as int or u32.
However, the only caveat that I see is queued_spin_lock_slowpath() is
expecting a u32 argument. Maybe you should cast it back to (u32) when
calling it.
Cheers,
Longman
next prev parent reply other threads:[~2020-10-26 18:04 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-26 16:57 Arnd Bergmann
2020-10-26 17:10 ` Peter Zijlstra
2020-10-26 18:03 ` Waiman Long [this message]
2020-10-27 7:47 ` Peter Zijlstra
2020-10-27 8:33 ` Arnd Bergmann
2020-10-27 10:32 ` Peter Zijlstra
2020-10-27 13:38 ` David Laight
2020-10-27 16:22 ` Arnd Bergmann
2020-10-27 17:34 ` Peter Zijlstra
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=022365e9-f7fe-5589-7867-d2ad2d33cfa3@redhat.com \
--to=longman@redhat.com \
--cc=arnd@arndb.de \
--cc=arnd@kernel.org \
--cc=herbert@gondor.apana.org.au \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=mpe@ellerman.id.au \
--cc=npiggin@gmail.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=will.deacon@arm.com \
--cc=will@kernel.org \
--cc=willy@infradead.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
all inboxes | Powered by JetHome®