Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1655638
| From | Waiman Long <longman@redhat.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH v5 7/9] locking/rwsem: Make rwsem_spin_on_owner() return a tri-state value |
| Date | 2017-06-01 19:50 +0200 |
| Message-ID | <tNCoq-5EC-41@gated-at.bofh.it> (permalink) |
| References | <tNCop-5EC-1@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
This patch modifies rwsem_spin_on_owner() to return a tri-state value
to better reflect the state of lock holder which enables us to make a
better decision of what to do next.
Signed-off-by: Waiman Long <longman@redhat.com>
---
kernel/locking/rwsem-xadd.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/kernel/locking/rwsem-xadd.c b/kernel/locking/rwsem-xadd.c
index f82ce29..7d030a2 100644
--- a/kernel/locking/rwsem-xadd.c
+++ b/kernel/locking/rwsem-xadd.c
@@ -341,9 +341,13 @@ static inline bool rwsem_can_spin_on_owner(struct rw_semaphore *sem)
}
/*
- * Return true only if we can still spin on the owner field of the rwsem.
+ * Return the folowing three values depending on the lock owner state.
+ * 1 when owner has changed and no reader is detected yet.
+ * 0 when owner has change and/or owner is a reader.
+ * -1 when optimistic spinning has to stop because either the owner stops
+ * running or its timeslice has been used up.
*/
-static noinline bool rwsem_spin_on_owner(struct rw_semaphore *sem)
+static noinline int rwsem_spin_on_owner(struct rw_semaphore *sem)
{
struct task_struct *owner = READ_ONCE(sem->owner);
@@ -367,7 +371,7 @@ static noinline bool rwsem_spin_on_owner(struct rw_semaphore *sem)
if (!owner->on_cpu || need_resched() ||
vcpu_is_preempted(task_cpu(owner))) {
rcu_read_unlock();
- return false;
+ return -1;
}
cpu_relax();
@@ -378,7 +382,7 @@ static noinline bool rwsem_spin_on_owner(struct rw_semaphore *sem)
* If there is a new owner or the owner is not set, we continue
* spinning.
*/
- return !rwsem_owner_is_reader(READ_ONCE(sem->owner));
+ return rwsem_owner_is_reader(READ_ONCE(sem->owner)) ? 0 : 1;
}
static bool rwsem_optimistic_spin(struct rw_semaphore *sem,
@@ -399,7 +403,7 @@ static bool rwsem_optimistic_spin(struct rw_semaphore *sem,
* 2) readers own the lock as we can't determine if they are
* actively running or not.
*/
- while (rwsem_spin_on_owner(sem)) {
+ while (rwsem_spin_on_owner(sem) > 0) {
/*
* Try to acquire the lock
*/
--
1.8.3.1
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH v5 0/9] locking/rwsem: Enable reader optimistic spinning Waiman Long <longman@redhat.com> - 2017-06-01 19:50 +0200 [PATCH v5 4/9] locking/rwsem: Change RWSEM_WAITING_BIAS for better disambiguation Waiman Long <longman@redhat.com> - 2017-06-01 19:50 +0200 [PATCH v5 6/9] locking/rwsem: Use bit in owner to stop spinning Waiman Long <longman@redhat.com> - 2017-06-01 19:50 +0200 [PATCH v5 9/9] locking/rwsem: Enable reader lock stealing Waiman Long <longman@redhat.com> - 2017-06-01 19:50 +0200 [PATCH v5 3/9] locking/rwsem: Move common rwsem macros to asm-generic/rwsem_types.h Waiman Long <longman@redhat.com> - 2017-06-01 19:50 +0200 [PATCH v5 8/9] locking/rwsem: Enable count-based spinning on reader Waiman Long <longman@redhat.com> - 2017-06-01 19:50 +0200 [PATCH v5 2/9] locking/rwsem: Stop active read lock ASAP Waiman Long <longman@redhat.com> - 2017-06-01 19:50 +0200 [PATCH v5 1/9] locking/rwsem: relocate rwsem_down_read_failed() Waiman Long <longman@redhat.com> - 2017-06-01 19:50 +0200 [PATCH v5 7/9] locking/rwsem: Make rwsem_spin_on_owner() return a tri-state value Waiman Long <longman@redhat.com> - 2017-06-01 19:50 +0200 [PATCH v5 5/9] locking/rwsem: Enable readers spinning on writer Waiman Long <longman@redhat.com> - 2017-06-01 19:50 +0200
csiph-web