linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] bit_spinlock: introduce smp_cond_load_relaxed
@ 2018-10-13  6:47 Gao Xiang
  2018-10-13  7:04 ` Greg Kroah-Hartman
  2018-10-30  6:04 ` [PATCH v2] " Gao Xiang
  0 siblings, 2 replies; 19+ messages in thread
From: Gao Xiang @ 2018-10-13  6:47 UTC (permalink / raw)
  To: Philippe Ombredanne, Kate Stewart, Thomas Gleixner, Greg Kroah-Hartman
  Cc: linux-kernel, Miao Xie, Chao Yu, Gao Xiang

It is better to use smp_cond_load_relaxed instead
of busy waiting for bit_spinlock.

Signed-off-by: Gao Xiang <hsiangkao@aol.com>
---
 include/linux/bit_spinlock.h | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/include/linux/bit_spinlock.h b/include/linux/bit_spinlock.h
index bbc4730..713efc4 100644
--- a/include/linux/bit_spinlock.h
+++ b/include/linux/bit_spinlock.h
@@ -15,22 +15,17 @@
  */
 static inline void bit_spin_lock(int bitnum, unsigned long *addr)
 {
-	/*
-	 * Assuming the lock is uncontended, this never enters
-	 * the body of the outer loop. If it is contended, then
-	 * within the inner loop a non-atomic test is used to
-	 * busywait with less bus contention for a good time to
-	 * attempt to acquire the lock bit.
-	 */
-	preempt_disable();
 #if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
-	while (unlikely(test_and_set_bit_lock(bitnum, addr))) {
-		preempt_enable();
-		do {
-			cpu_relax();
-		} while (test_bit(bitnum, addr));
+	while (1) {
+		smp_cond_load_relaxed(&addr[BIT_WORD(bitnum)],
+				      !(VAL >> (bitnum & (BITS_PER_LONG-1))));
 		preempt_disable();
+		if (!test_and_set_bit_lock(bitnum, addr))
+			break;
+		preempt_enable();
 	}
+#else
+	preempt_disable();
 #endif
 	__acquire(bitlock);
 }
-- 
2.7.4


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

end of thread, other threads:[~2018-11-06 12:43 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-13  6:47 [RFC PATCH] bit_spinlock: introduce smp_cond_load_relaxed Gao Xiang
2018-10-13  7:04 ` Greg Kroah-Hartman
2018-10-13  7:22   ` Gao Xiang
2018-10-13  7:30     ` Greg Kroah-Hartman
2018-10-13  7:44       ` Gao Xiang
2018-10-13  7:30     ` Gao Xiang
2018-10-30  6:04 ` [PATCH v2] " Gao Xiang
2018-10-30  5:52   ` Gao Xiang
2018-11-05 17:11     ` Gao Xiang
2018-11-05 22:49   ` Will Deacon
2018-11-06  1:45     ` Gao Xiang
2018-11-06  9:06     ` Peter Zijlstra
2018-11-06 10:22       ` Gao Xiang
2018-11-06 11:00         ` Peter Zijlstra
2018-11-06 11:36           ` Gao Xiang
2018-11-06 12:27             ` Peter Zijlstra
2018-11-06 12:33               ` Gao Xiang
2018-11-06 12:38                 ` Gao Xiang
2018-11-06 12:43                 ` Peter Zijlstra

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