From: Byungchul Park <byungchul.park@lge.com>
To: peterz@infradead.org, mingo@kernel.org
Cc: linux-kernel@vger.kernel.org, npiggin@suse.de,
sergey.senozhatsky@gmail.com, gregkh@linuxfoundation.org,
minchan@kernel.org
Subject: [PATCH 2/5] lockdep: Apply bitlock to bit_spin_lock
Date: Mon, 20 Jun 2016 13:55:12 +0900 [thread overview]
Message-ID: <1466398515-1005-3-git-send-email-byungchul.park@lge.com> (raw)
In-Reply-To: <1466398515-1005-1-git-send-email-byungchul.park@lge.com>
Currently, bit_spin_lock does not use lockdep_map at all. Of course,
the lock correctness validator is not supported for bit_spin_lock.
This patch makes bit_spin_lock possible to use the validator using
CONFIG_BITLOCK_ALLOC.
Signed-off-by: Byungchul Park <byungchul.park@lge.com>
---
include/linux/bit_spinlock.h | 57 +++++++++++++++++++++++++++++++++++++++-----
1 file changed, 51 insertions(+), 6 deletions(-)
diff --git a/include/linux/bit_spinlock.h b/include/linux/bit_spinlock.h
index 3b5bafc..3f8b013 100644
--- a/include/linux/bit_spinlock.h
+++ b/include/linux/bit_spinlock.h
@@ -6,13 +6,43 @@
#include <linux/atomic.h>
#include <linux/bug.h>
+#ifdef CONFIG_BITLOCK_ALLOC
+#include <linux/bitlock.h>
+#define bit_spin_init(b, a) \
+do { \
+ static struct lock_class_key __key; \
+ bitlock_init(b, a, #b "@" #a, &__key); \
+} while (0)
+
+static inline void bit_spin_free(int bitnum, unsigned long *addr)
+{
+ bitlock_free(bitnum, addr);
+}
+
+static inline void bit_spin_acquire(int bitnum, unsigned long *addr, int try)
+{
+ struct lockdep_map *map = bitlock_get_map(bitnum, addr, BIT_ACQUIRE);
+ if (map)
+ spin_acquire(map, 0, try, _RET_IP_);
+}
+
+static inline void bit_spin_release(int bitnum, unsigned long *addr)
+{
+ struct lockdep_map *map = bitlock_get_map(bitnum, addr, BIT_RELEASE);
+ if (map)
+ spin_release(map, 0, _RET_IP_);
+}
+#else
+static inline void bit_spin_init(int bitnum, unsigned long *addr) {}
+static inline void bit_spin_free(int bitnum, unsigned long *addr) {}
+static inline void bit_spin_acquire(int bitnum, unsigned long *addr, int try) {}
+static inline void bit_spin_release(int bitnum, unsigned long *addr) {}
+#endif
+
/*
- * bit-based spin_lock()
- *
- * Don't use this unless you really need to: spin_lock() and spin_unlock()
- * are significantly faster.
+ * bit-based spin_lock() without lock acquiring
*/
-static inline void bit_spin_lock(int bitnum, unsigned long *addr)
+static inline void do_raw_bit_spin_lock(int bitnum, unsigned long *addr)
{
/*
* Assuming the lock is uncontended, this never enters
@@ -21,7 +51,6 @@ static inline void bit_spin_lock(int bitnum, unsigned long *addr)
* 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();
@@ -35,6 +64,19 @@ static inline void bit_spin_lock(int bitnum, unsigned long *addr)
}
/*
+ * bit-based spin_lock()
+ *
+ * Don't use this unless you really need to: spin_lock() and spin_unlock()
+ * are significantly faster.
+ */
+static inline void bit_spin_lock(int bitnum, unsigned long *addr)
+{
+ preempt_disable();
+ bit_spin_acquire(bitnum, addr, 0);
+ do_raw_bit_spin_lock(bitnum, addr);
+}
+
+/*
* Return true if it was acquired
*/
static inline int bit_spin_trylock(int bitnum, unsigned long *addr)
@@ -46,6 +88,7 @@ static inline int bit_spin_trylock(int bitnum, unsigned long *addr)
return 0;
}
#endif
+ bit_spin_acquire(bitnum, addr, 1);
__acquire(bitlock);
return 1;
}
@@ -55,6 +98,7 @@ static inline int bit_spin_trylock(int bitnum, unsigned long *addr)
*/
static inline void bit_spin_unlock(int bitnum, unsigned long *addr)
{
+ bit_spin_release(bitnum, addr);
#ifdef CONFIG_DEBUG_SPINLOCK
BUG_ON(!test_bit(bitnum, addr));
#endif
@@ -72,6 +116,7 @@ static inline void bit_spin_unlock(int bitnum, unsigned long *addr)
*/
static inline void __bit_spin_unlock(int bitnum, unsigned long *addr)
{
+ bit_spin_release(bitnum, addr);
#ifdef CONFIG_DEBUG_SPINLOCK
BUG_ON(!test_bit(bitnum, addr));
#endif
--
1.9.1
next prev parent reply other threads:[~2016-06-20 5:12 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-20 4:55 [PATCH 0/5] Implement bitlock map allocator Byungchul Park
2016-06-20 4:55 ` [PATCH 1/5] lockdep: " Byungchul Park
2016-06-30 12:59 ` Peter Zijlstra
2016-07-01 0:24 ` Byungchul Park
2016-07-01 7:53 ` Peter Zijlstra
2016-07-04 7:29 ` Byungchul Park
2016-07-07 10:22 ` Byungchul Park
2016-07-13 20:17 ` Peter Zijlstra
2016-07-18 1:46 ` Byungchul Park
2016-06-20 4:55 ` Byungchul Park [this message]
2016-06-20 4:55 ` [PATCH 3/5] lockdep: Apply bit_spin_lock lockdep to zram Byungchul Park
2016-06-20 15:36 ` Sergey Senozhatsky
2016-06-21 1:05 ` Byungchul Park
2016-06-20 4:55 ` [PATCH 4/5] fs/buffer.c: Remove trailing white space Byungchul Park
2016-06-20 4:55 ` [PATCH 5/5] lockdep: Apply bit_spin_lock lockdep to BH_Uptodate_Lock Byungchul Park
2016-06-29 12:45 ` [PATCH 0/5] Implement bitlock map allocator Byungchul Park
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1466398515-1005-3-git-send-email-byungchul.park@lge.com \
--to=byungchul.park@lge.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=minchan@kernel.org \
--cc=mingo@kernel.org \
--cc=npiggin@suse.de \
--cc=peterz@infradead.org \
--cc=sergey.senozhatsky@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).