From: Peter Zijlstra <peterz@infradead.org>
To: longman@redhat.com, mingo@redhat.com, will@kernel.org
Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, boqun.feng@gmail.com
Subject: [PATCH 6/6] locking/rwsem: Use the force
Date: Thu, 23 Feb 2023 13:26:48 +0100 [thread overview]
Message-ID: <20230223123319.667433408@infradead.org> (raw)
In-Reply-To: 20230223122642.491637862@infradead.org
Now that the writer adjustment is done from the wakeup side and
HANDOFF guarantees spinning/stealing is disabled, use the combined
guarantee it ignore spurious READER_BIAS and directly claim the lock.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
kernel/locking/lock_events_list.h | 1 +
kernel/locking/rwsem.c | 21 +++++++++++++++++++++
2 files changed, 22 insertions(+)
--- a/kernel/locking/lock_events_list.h
+++ b/kernel/locking/lock_events_list.h
@@ -67,3 +67,4 @@ LOCK_EVENT(rwsem_rlock_handoff) /* # of
LOCK_EVENT(rwsem_wlock) /* # of write locks acquired */
LOCK_EVENT(rwsem_wlock_fail) /* # of failed write lock acquisitions */
LOCK_EVENT(rwsem_wlock_handoff) /* # of write lock handoffs */
+LOCK_EVENT(rwsem_wlock_ehandoff) /* # of write lock early handoffs */
--- a/kernel/locking/rwsem.c
+++ b/kernel/locking/rwsem.c
@@ -433,6 +433,26 @@ static void rwsem_writer_wake(struct rw_
lockdep_assert_held(&sem->wait_lock);
count = atomic_long_read(&sem->count);
+
+ /*
+ * Since rwsem_mark_wake() is only called (with WAKE_ANY) when
+ * the lock is unlocked, and the HANDOFF bit guarantees that
+ * all spinning / stealing is disabled, it is posssible to
+ * unconditionally claim the lock -- any READER_BIAS will be
+ * temporary.
+ */
+ if (count & RWSEM_FLAG_HANDOFF) {
+ unsigned long adjustment = RWSEM_WRITER_LOCKED - RWSEM_FLAG_HANDOFF;
+
+ if (list_is_singular(&sem->wait_list))
+ adjustment -= RWSEM_FLAG_WAITERS;
+
+ atomic_long_set(&sem->owner, (long)waiter->task);
+ atomic_long_add(adjustment, &sem->count);
+ lockevent_inc(rwsem_wlock_ehandoff);
+ goto success;
+ }
+
do {
bool has_handoff = !!(count & RWSEM_FLAG_HANDOFF);
@@ -479,6 +499,7 @@ static void rwsem_writer_wake(struct rw_
return;
}
+success:
/*
* Have rwsem_writer_wake() fully imply rwsem_del_waiter() on
* success.
next prev parent reply other threads:[~2023-02-23 12:35 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-23 12:26 [PATCH 0/6] locking/rwsem: Rework writer wakeup and handoff Peter Zijlstra
2023-02-23 12:26 ` [PATCH 1/6] locking/rwsem: Minor code refactoring in rwsem_mark_wake() Peter Zijlstra
2023-02-23 12:26 ` [PATCH 2/6] locking/rwsem: Enforce queueing when HANDOFF Peter Zijlstra
2023-02-23 12:26 ` [PATCH 3/6] locking/rwsem: Rework writer wakeup Peter Zijlstra
2023-02-23 21:38 ` Waiman Long
2023-02-26 11:58 ` Peter Zijlstra
2023-02-26 12:00 ` Peter Zijlstra
2023-02-26 21:31 ` Waiman Long
2023-02-26 11:59 ` Peter Zijlstra
2023-02-26 15:04 ` Peter Zijlstra
2023-02-26 16:51 ` Peter Zijlstra
2023-02-27 0:22 ` Waiman Long
2023-02-27 10:31 ` Peter Zijlstra
2023-02-27 20:16 ` Waiman Long
2023-03-20 8:12 ` Peter Zijlstra
2023-03-20 17:36 ` Waiman Long
2023-02-23 12:26 ` [PATCH 4/6] locking/rwsem: Split out rwsem_reader_wake() Peter Zijlstra
2023-02-23 12:26 ` [PATCH 5/6] locking/rwsem: Unify wait loop Peter Zijlstra
2023-02-23 19:31 ` Boqun Feng
2023-02-24 1:33 ` Boqun Feng
2023-02-26 12:01 ` Peter Zijlstra
2023-02-26 18:22 ` Boqun Feng
2023-02-23 22:45 ` Waiman Long
2023-02-26 16:15 ` Peter Zijlstra
2023-02-23 12:26 ` Peter Zijlstra [this message]
2023-02-24 1:19 ` [PATCH 0/6] locking/rwsem: Rework writer wakeup and handoff Waiman Long
2023-02-24 11:55 ` Jiri Wiesner
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=20230223123319.667433408@infradead.org \
--to=peterz@infradead.org \
--cc=boqun.feng@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mingo@redhat.com \
--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).