From: Peter Zijlstra <peterz@infradead.org>
To: Waiman Long <longman@redhat.com>
Cc: mingo@redhat.com, will@kernel.org, linux-kernel@vger.kernel.org,
boqun.feng@gmail.com
Subject: Re: [PATCH 5/6] locking/rwsem: Unify wait loop
Date: Sun, 26 Feb 2023 17:15:27 +0100 [thread overview]
Message-ID: <Y/uFn4WwZ8R3Dh4S@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <0be586e4-8c08-63ff-a78d-ffb5ae37adc3@redhat.com>
On Thu, Feb 23, 2023 at 05:45:56PM -0500, Waiman Long wrote:
> Unfortunately, lockevent_inc() doesn't work with waiter_type() like that as
> the compilation will fail if CONFIG_LOCK_EVENT_COUNTS is enabled. Could you
> include the attached patch in your series and make the following changes?
Yeah, robot told me; fixed it like so:
--- a/kernel/locking/rwsem.c
+++ b/kernel/locking/rwsem.c
@@ -995,13 +995,16 @@ static inline void rwsem_cond_wake_waite
rwsem_mark_wake(sem, wake_type, wake_q);
}
-#define waiter_type(_waiter, _r, _w) \
- ((_waiter)->type == RWSEM_WAITING_FOR_READ ? (_r) : (_w))
+#define lockevent_rw_inc(rd, evr, evw) do { \
+ lockevent_cond_inc(evr, (rd)); \
+ lockevent_cond_inc(evw, !(rd)); \
+} while (0)
static __always_inline struct rw_semaphore *
-rwsem_waiter_wait(struct rw_semaphore *sem, struct rwsem_waiter *waiter, int state)
+rwsem_waiter_wait(struct rw_semaphore *sem, struct rwsem_waiter *waiter,
+ int state, bool reader)
{
- trace_contention_begin(sem, waiter_type(waiter, LCB_F_READ, LCB_F_WRITE));
+ trace_contention_begin(sem, reader ? LCB_F_READ : LCB_F_WRITE);
/* wait to be given the lock */
for (;;) {
@@ -1019,18 +1022,19 @@ rwsem_waiter_wait(struct rw_semaphore *s
break;
}
schedule_preempt_disabled();
- lockevent_inc(waiter_type(waiter, rwsem_sleep_reader, rwsem_sleep_writer));
+ lockevent_rw_inc(reader, rwsem_sleep_reader, rwsem_sleep_writer);
}
__set_current_state(TASK_RUNNING);
- lockevent_inc(waiter_type(waiter, rwsem_rlock, rwsem_wlock));
+
+ lockevent_rw_inc(reader, rwsem_rlock, rwsem_wlock);
trace_contention_end(sem, 0);
return sem;
out_nolock:
rwsem_del_wake_waiter(sem, waiter);
__set_current_state(TASK_RUNNING);
- lockevent_inc(waiter_type(waiter, rwsem_rlock_fail, rwsem_wlock_fail));
+ lockevent_rw_inc(reader, rwem_rlock_fail, rwsem_wlock_fail);
trace_contention_end(sem, -EINTR);
return ERR_PTR(-EINTR);
}
@@ -1112,7 +1116,7 @@ rwsem_down_read_slowpath(struct rw_semap
if (!wake_q_empty(&wake_q))
wake_up_q(&wake_q);
- return rwsem_waiter_wait(sem, &waiter, state);
+ return rwsem_waiter_wait(sem, &waiter, state, true);
}
/*
@@ -1162,7 +1166,7 @@ rwsem_down_write_slowpath(struct rw_sema
}
raw_spin_unlock_irq(&sem->wait_lock);
- return rwsem_waiter_wait(sem, &waiter, state);
+ return rwsem_waiter_wait(sem, &waiter, state, false);
}
/*
next prev parent reply other threads:[~2023-02-26 16:15 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 [this message]
2023-02-23 12:26 ` [PATCH 6/6] locking/rwsem: Use the force Peter Zijlstra
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=Y/uFn4WwZ8R3Dh4S@hirez.programming.kicks-ass.net \
--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).