[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20181030060441.16107-1-gaoxiang25@huawei.com>
Date: Tue, 30 Oct 2018 14:04:41 +0800
From: Gao Xiang <gaoxiang25@...wei.com>
To: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
CC: Philippe Ombredanne <pombredanne@...b.com>,
Kate Stewart <kstewart@...uxfoundation.org>,
Thomas Gleixner <tglx@...utronix.de>,
"Will Deacon" <will.deacon@....com>,
<linux-kernel@...r.kernel.org>, Miao Xie <miaoxie@...wei.com>,
Chao Yu <chao@...nel.org>, Gao Xiang <gaoxiang25@...wei.com>
Subject: [PATCH v2] bit_spinlock: introduce smp_cond_load_relaxed
It is better to use wrapped smp_cond_load_relaxed
instead of open-coded busy waiting for bit_spinlock.
Signed-off-by: Gao Xiang <gaoxiang25@...wei.com>
---
change log v2:
- fix the incorrect expression !(VAL >> (bitnum & (BITS_PER_LONG-1)))
- the test result is described in the following reply.
Thanks,
Gao Xiang
include/linux/bit_spinlock.h | 23 ++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)
diff --git a/include/linux/bit_spinlock.h b/include/linux/bit_spinlock.h
index bbc4730a6505..d5f922b5ffd9 100644
--- a/include/linux/bit_spinlock.h
+++ b/include/linux/bit_spinlock.h
@@ -15,22 +15,19 @@
*/
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));
+ const unsigned int bitshift = bitnum & (BITS_PER_LONG - 1);
+
+ while (1) {
+ smp_cond_load_relaxed(&addr[BIT_WORD(bitnum)],
+ !((VAL >> bitshift) & 1));
preempt_disable();
+ if (!test_and_set_bit_lock(bitnum, addr))
+ break;
+ preempt_enable();
}
+#else
+ preempt_disable();
#endif
__acquire(bitlock);
}
--
2.17.1
Powered by blists - more mailing lists