All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] locking/rwsem: Reinit wake_q after use
@ 2017-01-22  2:33 Waiman Long
  2017-01-22 10:14 ` [tip:locking/core] " tip-bot for Waiman Long
  0 siblings, 1 reply; 5+ messages in thread
From: Waiman Long @ 2017-01-22  2:33 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra; +Cc: linux-kernel, Davidlohr Bueso, Waiman Long

In __rwsem_down_write_failed_common(), the same wake_q variable name
is defined twice, with the inner wake_q hiding the one in outer scope.
We can either use different names for the two wake_q's. Even better,
we can use the same wake_q twice, if necessary. To enable the latter
change, we need to define a new helper function wake_q_init() to
enable reinitalization of wake_q after use.

Signed-off-by: Waiman Long <longman@redhat.com>
---
 include/linux/sched.h       | 6 ++++++
 kernel/locking/rwsem-xadd.c | 7 +++++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index 8a9bbb6..3640bde 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1019,6 +1019,12 @@ struct wake_q_head {
 #define DEFINE_WAKE_Q(name)				\
 	struct wake_q_head name = { WAKE_Q_TAIL, &name.first }
 
+static inline void wake_q_init(struct wake_q_head *head)
+{
+	head->first = WAKE_Q_TAIL;
+	head->lastp = &head->first;
+}
+
 extern void wake_q_add(struct wake_q_head *head,
 		       struct task_struct *task);
 extern void wake_up_q(struct wake_q_head *head);
diff --git a/kernel/locking/rwsem-xadd.c b/kernel/locking/rwsem-xadd.c
index a3a381a..2ad8d8d 100644
--- a/kernel/locking/rwsem-xadd.c
+++ b/kernel/locking/rwsem-xadd.c
@@ -502,8 +502,6 @@ static inline bool rwsem_has_spinner(struct rw_semaphore *sem)
 		 * wake any read locks that were queued ahead of us.
 		 */
 		if (count > RWSEM_WAITING_BIAS) {
-			DEFINE_WAKE_Q(wake_q);
-
 			__rwsem_mark_wake(sem, RWSEM_WAKE_READERS, &wake_q);
 			/*
 			 * The wakeup is normally called _after_ the wait_lock
@@ -513,6 +511,11 @@ static inline bool rwsem_has_spinner(struct rw_semaphore *sem)
 			 * for attempting rwsem_try_write_lock().
 			 */
 			wake_up_q(&wake_q);
+
+			/*
+			 * Reinitialize wake_q after use.
+			 */
+			wake_q_init(&wake_q);
 		}
 
 	} else
-- 
1.8.3.1

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

end of thread, other threads:[~2017-02-01 10:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-22  2:33 [PATCH] locking/rwsem: Reinit wake_q after use Waiman Long
2017-01-22 10:14 ` [tip:locking/core] " tip-bot for Waiman Long
2017-01-29 15:15   ` [PATCH -tip] sched/wake_q: Clarify queue reinit Davidlohr Bueso
2017-01-29 16:22     ` Waiman Long
2017-02-01 10:08     ` [tip:locking/core] sched/wake_q: Clarify queue reinit comment tip-bot for Davidlohr Bueso

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.