From: Waiman Long <longman@redhat.com>
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>,
Boqun Feng <boqun.feng@gmail.com>
Cc: linux-kernel@vger.kernel.org, Waiman Long <longman@redhat.com>
Subject: [PATCH v2 4/8] locking/rwsem: Simplify rwsem_writer_wake()
Date: Mon, 27 Mar 2023 16:24:09 -0400 [thread overview]
Message-ID: <20230327202413.1955856-5-longman@redhat.com> (raw)
In-Reply-To: <20230327202413.1955856-1-longman@redhat.com>
From: Peter Zijlstra <peterz@infradead.org>
Since @waiter := rwsem_first_waiter() simplify things.
Suggested-by: Waiman Long <longman@redhat.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
kernel/locking/rwsem.c | 21 ++++-----------------
1 file changed, 4 insertions(+), 17 deletions(-)
diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c
index 0cc0aa566a6b..225e86326ea4 100644
--- a/kernel/locking/rwsem.c
+++ b/kernel/locking/rwsem.c
@@ -426,26 +426,12 @@ rwsem_waiter_wake(struct rwsem_waiter *waiter, struct wake_q_head *wake_q)
static inline bool rwsem_try_write_lock(struct rw_semaphore *sem,
struct rwsem_waiter *waiter)
{
-
- struct rwsem_waiter *first = rwsem_first_waiter(sem);
long count, new;
lockdep_assert_held(&sem->wait_lock);
count = atomic_long_read(&sem->count);
do {
- bool has_handoff = !!(count & RWSEM_FLAG_HANDOFF);
-
- if (has_handoff) {
- /*
- * Honor handoff bit and yield only when the first
- * waiter is the one that set it. Otherwisee, we
- * still try to acquire the rwsem.
- */
- if (first->handoff_set && (waiter != first))
- return false;
- }
-
new = count;
if (count & RWSEM_LOCK_MASK) {
@@ -454,8 +440,9 @@ static inline bool rwsem_try_write_lock(struct rw_semaphore *sem,
* if it is an RT task or wait in the wait queue
* for too long.
*/
- if (has_handoff || (!rt_task(waiter->task) &&
- !time_after(jiffies, waiter->timeout)))
+ if ((count & RWSEM_FLAG_HANDOFF) ||
+ (!rt_task(waiter->task) &&
+ !time_after(jiffies, waiter->timeout)))
return false;
new |= RWSEM_FLAG_HANDOFF;
@@ -474,7 +461,7 @@ static inline bool rwsem_try_write_lock(struct rw_semaphore *sem,
* set here to enable optimistic spinning in slowpath loop.
*/
if (new & RWSEM_FLAG_HANDOFF) {
- first->handoff_set = true;
+ waiter->handoff_set = true;
lockevent_inc(rwsem_wlock_handoff);
return false;
}
--
2.31.1
next prev parent reply other threads:[~2023-03-27 20:26 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-27 20:24 [PATCH v2 0/8] locking/rwsem: Rework writer wakeup and handoff Waiman Long
2023-03-27 20:24 ` [PATCH v2 1/8] locking/rwsem: Minor code refactoring in rwsem_mark_wake() Waiman Long
2023-03-27 20:24 ` [PATCH v2 2/8] locking/rwsem: Enforce queueing when HANDOFF Waiman Long
2023-03-27 20:24 ` [PATCH v2 3/8] locking/rwsem: Rework writer wakeup Waiman Long
2023-03-27 20:24 ` Waiman Long [this message]
2023-03-27 20:24 ` [PATCH v2 5/8] locking/rwsem: Split out rwsem_reader_wake() Waiman Long
2023-03-27 20:24 ` [PATCH v2 6/8] locking/rwsem: Unify wait loop Waiman Long
2023-03-27 20:24 ` [PATCH v2 7/8] locking/rwsem: Use the force Waiman Long
2023-03-27 20:24 ` [PATCH v2 8/8] locking/rwsem: Restore old write lock slow path behavior Waiman Long
2023-03-28 14:02 ` Peter Zijlstra
2023-03-29 3:45 ` Waiman Long
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=20230327202413.1955856-5-longman@redhat.com \
--to=longman@redhat.com \
--cc=boqun.feng@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.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