linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] locking/rwsem: fix comments about reader optimistic lock stealing conditions
@ 2021-09-27 16:38 Yanfei Xu
  2021-09-27 16:38 ` [PATCH 2/2] locking/rwsem: add preempt_disable/enable for spin region Yanfei Xu
  0 siblings, 1 reply; 2+ messages in thread
From: Yanfei Xu @ 2021-09-27 16:38 UTC (permalink / raw)
  To: peterz, mingo, will, longman, boqun.feng; +Cc: linux-kernel

After the commit 617f3ef95177 ("locking/rwsem: Remove reader
optimistic spinning"), reader doesn't support optimistic spinning
anymore, there is no need meet the condition which OSQ is empty.

BTW, add an unlikely() for the max reader wakeup check.

Signed-off-by: Yanfei Xu <yanfei.xu@windriver.com>
---
 kernel/locking/rwsem.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c
index 000e8d5a2884..2907f9d8e4a6 100644
--- a/kernel/locking/rwsem.c
+++ b/kernel/locking/rwsem.c
@@ -56,7 +56,6 @@
  *
  * A fast path reader optimistic lock stealing is supported when the rwsem
  * is previously owned by a writer and the following conditions are met:
- *  - OSQ is empty
  *  - rwsem is not currently writer owned
  *  - the handoff isn't set.
  */
@@ -485,7 +484,7 @@ static void rwsem_mark_wake(struct rw_semaphore *sem,
 		/*
 		 * Limit # of readers that can be woken up per wakeup call.
 		 */
-		if (woken >= MAX_READERS_WAKEUP)
+		if (unlikely(woken >= MAX_READERS_WAKEUP))
 			break;
 	}
 
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH 2/2] locking/rwsem: add preempt_disable/enable for spin region
  2021-09-27 16:38 [PATCH 1/2] locking/rwsem: fix comments about reader optimistic lock stealing conditions Yanfei Xu
@ 2021-09-27 16:38 ` Yanfei Xu
  0 siblings, 0 replies; 2+ messages in thread
From: Yanfei Xu @ 2021-09-27 16:38 UTC (permalink / raw)
  To: peterz, mingo, will, longman, boqun.feng; +Cc: linux-kernel

The rwsem_optimistic_spin() invokes the rwsem_spin_on_owner() with
preemption disabled, but rwsem_down_write_slowpath() doesn't. Because
the spin region should not be preempted, add preempt_disable/enable()
in rwsem_spin_on_owner().

Signed-off-by: Yanfei Xu <yanfei.xu@windriver.com>
---
 kernel/locking/rwsem.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c
index 2907f9d8e4a6..db3a6a06a9c8 100644
--- a/kernel/locking/rwsem.c
+++ b/kernel/locking/rwsem.c
@@ -674,6 +674,7 @@ rwsem_spin_on_owner(struct rw_semaphore *sem)
 	if (state != OWNER_WRITER)
 		return state;
 
+	preempt_disable();
 	rcu_read_lock();
 	for (;;) {
 		/*
@@ -704,6 +705,7 @@ rwsem_spin_on_owner(struct rw_semaphore *sem)
 		cpu_relax();
 	}
 	rcu_read_unlock();
+	preempt_enable();
 
 	return state;
 }
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-09-27 16:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-27 16:38 [PATCH 1/2] locking/rwsem: fix comments about reader optimistic lock stealing conditions Yanfei Xu
2021-09-27 16:38 ` [PATCH 2/2] locking/rwsem: add preempt_disable/enable for spin region Yanfei Xu

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).