Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1400408 > unrolled thread
| Started by | Waiman Long <Waiman.Long@hpe.com> |
|---|---|
| First post | 2016-05-13 01:00 +0200 |
| Last post | 2016-05-17 19:40 +0200 |
| Articles | 2 — 2 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH v3 3/4] locking/rwsem: Improve reader wakeup code Waiman Long <Waiman.Long@hpe.com> - 2016-05-13 01:00 +0200
Re: [PATCH v3 3/4] locking/rwsem: Improve reader wakeup code Peter Hurley <peter@hurleysoftware.com> - 2016-05-17 19:40 +0200
| From | Waiman Long <Waiman.Long@hpe.com> |
|---|---|
| Date | 2016-05-13 01:00 +0200 |
| Subject | [PATCH v3 3/4] locking/rwsem: Improve reader wakeup code |
| Message-ID | <ry7Kh-7bF-13@gated-at.bofh.it> |
In __rwsem_do_wake(), the reader wakeup code will assume a writer
has stolen the lock if the active reader/writer count is not 0.
However, this is not as reliable an indicator as the original
"< RWSEM_WAITING_BIAS" check. If another reader is present, the code
will still break out and exit even if the writer is gone. This patch
changes it to check the same "< RWSEM_WAITING_BIAS" condition to
reduce the chance of false positive.
Signed-off-by: Waiman Long <Waiman.Long@hpe.com>
---
kernel/locking/rwsem-xadd.c | 11 ++++++++---
1 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/kernel/locking/rwsem-xadd.c b/kernel/locking/rwsem-xadd.c
index 22f7d58..6c08ad9 100644
--- a/kernel/locking/rwsem-xadd.c
+++ b/kernel/locking/rwsem-xadd.c
@@ -148,9 +148,14 @@ __rwsem_do_wake(struct rw_semaphore *sem, enum rwsem_wake_type wake_type)
try_reader_grant:
oldcount = rwsem_atomic_update(adjustment, sem) - adjustment;
if (unlikely(oldcount < RWSEM_WAITING_BIAS)) {
- /* A writer stole the lock. Undo our reader grant. */
- if (rwsem_atomic_update(-adjustment, sem) &
- RWSEM_ACTIVE_MASK)
+ /*
+ * If the count is still less than RWSEM_WAITING_BIAS
+ * after removing the adjustment, it is assumed that
+ * a writer has stolen the lock. We have to undo our
+ * reader grant.
+ */
+ if (rwsem_atomic_update(-adjustment, sem)
+ < RWSEM_WAITING_BIAS)
goto out;
/* Last active locker left. Retry waking readers. */
goto try_reader_grant;
--
1.7.1
[toc] | [next] | [standalone]
| From | Peter Hurley <peter@hurleysoftware.com> |
|---|---|
| Date | 2016-05-17 19:40 +0200 |
| Message-ID | <rzR8l-7vF-3@gated-at.bofh.it> |
| In reply to | #1400408 |
On 05/12/2016 03:56 PM, Waiman Long wrote: > In __rwsem_do_wake(), the reader wakeup code will assume a writer > has stolen the lock if the active reader/writer count is not 0. > However, this is not as reliable an indicator as the original > "< RWSEM_WAITING_BIAS" check. If another reader is present, the code > will still break out and exit even if the writer is gone. This patch > changes it to check the same "< RWSEM_WAITING_BIAS" condition to > reduce the chance of false positive. Nice. Reviewed-by: Peter Hurley <peter@hurleysoftware.com>
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web