From: Peter Zijlstra <peterz@infradead.org>
To: linux-kernel@vger.kernel.org, will.deacon@arm.com
Cc: waiman.long@hpe.com, mingo@redhat.com,
paulmck@linux.vnet.ibm.com, boqun.feng@gmail.com,
torvalds@linux-foundation.org, dave@stgolabs.net,
peterz@infradead.org
Subject: [RFC][PATCH 2/3] locking/qrwlock: Use smp_cond_load_acquire()
Date: Mon, 04 Apr 2016 14:22:52 +0200 [thread overview]
Message-ID: <20160404123633.423468902@infradead.org> (raw)
In-Reply-To: <20160404122250.340636238@infradead.org>
[-- Attachment #1: peterz-locking-qrwlock-smp_cond_load_acquire.patch --]
[-- Type: text/plain, Size: 1640 bytes --]
Use smp_cond_load_acquire() to make better use of the hardware
assisted 'spin' wait on arm64.
Arguably the second hunk is the more horrid abuse possible, but
avoids having to use cmpwait (see next patch) directly. Also, this
makes 'clever' (ab)use of the cond+rmb acquire to omit the acquire
from cmpxchg().
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
kernel/locking/qrwlock.c | 18 ++++--------------
1 file changed, 4 insertions(+), 14 deletions(-)
--- a/kernel/locking/qrwlock.c
+++ b/kernel/locking/qrwlock.c
@@ -53,10 +53,7 @@ struct __qrwlock {
static __always_inline void
rspin_until_writer_unlock(struct qrwlock *lock, u32 cnts)
{
- while ((cnts & _QW_WMASK) == _QW_LOCKED) {
- cpu_relax_lowlatency();
- cnts = atomic_read_acquire(&lock->cnts);
- }
+ smp_cond_load_acquire(&lock->cnts.counter, (VAL & _QW_WMASK) != _QW_LOCKED);
}
/**
@@ -109,8 +106,6 @@ EXPORT_SYMBOL(queued_read_lock_slowpath)
*/
void queued_write_lock_slowpath(struct qrwlock *lock)
{
- u32 cnts;
-
/* Put the writer into the wait queue */
arch_spin_lock(&lock->wait_lock);
@@ -134,15 +129,10 @@ void queued_write_lock_slowpath(struct q
}
/* When no more readers, set the locked flag */
- for (;;) {
- cnts = atomic_read(&lock->cnts);
- if ((cnts == _QW_WAITING) &&
- (atomic_cmpxchg_acquire(&lock->cnts, _QW_WAITING,
- _QW_LOCKED) == _QW_WAITING))
- break;
+ smp_cond_load_acquire(&lock->cnts.counter,
+ (VAL == _QW_WAITING) &&
+ atomic_cmpxchg_relaxed(&lock->cnts, _QW_WAITING, _QW_LOCKED) == _QW_WAITING);
- cpu_relax_lowlatency();
- }
unlock:
arch_spin_unlock(&lock->wait_lock);
}
next prev parent reply other threads:[~2016-04-04 12:37 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-04 12:22 [RFC][PATCH 0/3] smp_cond_load_acquire + cmpwait Peter Zijlstra
2016-04-04 12:22 ` [RFC][PATCH 1/3] locking: Replace smp_cond_acquire with smp_cond_load_acquire Peter Zijlstra
2016-04-04 18:20 ` Waiman Long
2016-04-04 12:22 ` Peter Zijlstra [this message]
2016-04-12 4:58 ` [RFC][PATCH 2/3] locking/qrwlock: Use smp_cond_load_acquire() Davidlohr Bueso
2016-04-12 16:45 ` Waiman Long
2016-04-04 12:22 ` [RFC][PATCH 3/3] locking,arm64: Introduce cmpwait() Peter Zijlstra
2016-04-04 13:12 ` Peter Zijlstra
2016-04-12 16:59 ` Will Deacon
2016-04-13 12:52 ` Peter Zijlstra
2016-04-26 16:33 ` Will Deacon
2016-04-26 17:15 ` Will Deacon
2016-04-26 20:25 ` Peter Zijlstra
2016-04-22 16:08 ` Boqun Feng
2016-04-22 16:53 ` Will Deacon
2016-04-23 4:02 ` Boqun Feng
2016-04-23 2:37 ` Peter Zijlstra
2016-04-23 3:40 ` Boqun Feng
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=20160404123633.423468902@infradead.org \
--to=peterz@infradead.org \
--cc=boqun.feng@gmail.com \
--cc=dave@stgolabs.net \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=paulmck@linux.vnet.ibm.com \
--cc=torvalds@linux-foundation.org \
--cc=waiman.long@hpe.com \
--cc=will.deacon@arm.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 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®