mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sasha Levin <sasha.levin@oracle.com>
To: linux-kernel@vger.kernel.org
Cc: peterz@infradead.org, mingo@redhat.com,
	Sasha Levin <sasha.levin@oracle.com>
Subject: [RFC 3/4] locking/rwsem: additional lock information when dumping locks
Date: Mon, 12 Jan 2015 09:57:10 -0500	[thread overview]
Message-ID: <1421074631-18831-3-git-send-email-sasha.levin@oracle.com> (raw)
In-Reply-To: <1421074631-18831-1-git-send-email-sasha.levin@oracle.com>

Show the counter and the owner of the lock when dumping held locks in the
system.

This is useful to figure out who really holds a lock and how many waiters
it has.

Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
---
 include/linux/lockdep.h         |    2 +-
 include/linux/rwsem.h           |    3 ++-
 kernel/locking/lockdep.c        |    5 +++++
 kernel/locking/rwsem-spinlock.c |    7 ++++++-
 kernel/locking/rwsem-xadd.c     |    2 +-
 kernel/locking/rwsem.c          |   15 +++++++++++++++
 6 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
index cab929b..4527f99 100644
--- a/include/linux/lockdep.h
+++ b/include/linux/lockdep.h
@@ -143,7 +143,7 @@ struct lock_class_stats lock_stats(struct lock_class *class);
 void clear_lock_stats(struct lock_class *class);
 #endif
 
-enum LOCK_TYPE { LOCKTYPE_NONE, LOCKTYPE_MUTEX, };
+enum LOCK_TYPE { LOCKTYPE_NONE, LOCKTYPE_MUTEX, LOCKTYPE_RWSEM, };
 
 /*
  * Map the lock object (the lock instance) to the lock-class object.
diff --git a/include/linux/rwsem.h b/include/linux/rwsem.h
index 8f498cd..68732af 100644
--- a/include/linux/rwsem.h
+++ b/include/linux/rwsem.h
@@ -60,7 +60,8 @@ static inline int rwsem_is_locked(struct rw_semaphore *sem)
 /* Common initializer macros and functions */
 
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
-# define __RWSEM_DEP_MAP_INIT(lockname) , .dep_map = { .name = #lockname }
+extern void rwsem_print_debug(const struct rw_semaphore *sem);
+# define __RWSEM_DEP_MAP_INIT(lockname) , .dep_map = { .name = #lockname, .type = LOCKTYPE_RWSEM }
 #else
 # define __RWSEM_DEP_MAP_INIT(lockname)
 #endif
diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index 07c337d..e75f83b 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -511,6 +511,7 @@ void get_usage_chars(struct lock_class *class, char usage[LOCK_USAGE_CHARS])
 static void get_lock_info(enum LOCK_TYPE t, struct lockdep_map *map)
 {
 	struct mutex *mtx;
+	struct rw_semaphore *rw;
 
 	switch (t) {
 	case LOCKTYPE_NONE: break;
@@ -518,6 +519,10 @@ static void get_lock_info(enum LOCK_TYPE t, struct lockdep_map *map)
 		mtx = container_of(map, struct mutex, dep_map);
 		mutex_print_debug(mtx);
 		break;
+	case LOCKTYPE_RWSEM:
+		rw = container_of(map, struct rw_semaphore, dep_map);
+		rwsem_print_debug(rw);
+		break;
 	}
 }
 
diff --git a/kernel/locking/rwsem-spinlock.c b/kernel/locking/rwsem-spinlock.c
index 2c93571..b07029e 100644
--- a/kernel/locking/rwsem-spinlock.c
+++ b/kernel/locking/rwsem-spinlock.c
@@ -44,7 +44,7 @@ void __init_rwsem(struct rw_semaphore *sem, const char *name,
 	 * Make sure we are not reinitializing a held semaphore:
 	 */
 	debug_check_no_locks_freed((void *)sem, sizeof(*sem));
-	lockdep_init_map(&sem->dep_map, name, key, 0);
+	lockdep_init_map_type(&sem->dep_map, name, key, 0, LOCKTYPE_RWSEM);
 #endif
 	sem->count = 0;
 	raw_spin_lock_init(&sem->wait_lock);
@@ -294,3 +294,8 @@ void __downgrade_write(struct rw_semaphore *sem)
 	raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
 }
 
+void rwsem_print_debug(const struct rw_semaphore *sem)
+{
+        printk("RWsem: count: %l\n", sem->count);
+}
+EXPORT_SYMBOL_GPL(rwsem_print_debug);
diff --git a/kernel/locking/rwsem-xadd.c b/kernel/locking/rwsem-xadd.c
index 7628c3f..8b00656 100644
--- a/kernel/locking/rwsem-xadd.c
+++ b/kernel/locking/rwsem-xadd.c
@@ -77,7 +77,7 @@ void __init_rwsem(struct rw_semaphore *sem, const char *name,
 	 * Make sure we are not reinitializing a held semaphore:
 	 */
 	debug_check_no_locks_freed((void *)sem, sizeof(*sem));
-	lockdep_init_map(&sem->dep_map, name, key, 0);
+	lockdep_init_map_type(&sem->dep_map, name, key, 0, LOCKTYPE_RWSEM);
 #endif
 	sem->count = RWSEM_UNLOCKED_VALUE;
 	raw_spin_lock_init(&sem->wait_lock);
diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c
index e2d3bc7..24183cc 100644
--- a/kernel/locking/rwsem.c
+++ b/kernel/locking/rwsem.c
@@ -181,6 +181,21 @@ void up_read_non_owner(struct rw_semaphore *sem)
 
 EXPORT_SYMBOL(up_read_non_owner);
 
+void rwsem_print_debug(const struct rw_semaphore *sem)
+{
+	const char *owner = "Unknown";
+
+#ifdef CONFIG_RWSEM_SPIN_ON_OWNER
+	if (sem->owner)
+		owner = sem->owner->comm;
+	else
+		owner = "None";
+#endif
+
+	printk("RWsem: count: %ld owner: %s\n", sem->count, owner);
+}
+EXPORT_SYMBOL_GPL(rwsem_print_debug);
+
 #endif
 
 
-- 
1.7.10.4


  parent reply	other threads:[~2015-01-12 14:57 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-12 14:57 [RFC 1/4] lockdep: additional lock specific " Sasha Levin
2015-01-12 14:57 ` [RFC 2/4] locking/mutex: additional lock " Sasha Levin
2015-01-12 14:57 ` Sasha Levin [this message]
2015-01-12 14:57 ` [RFC 4/4] locking/spinlock: " Sasha Levin
2015-01-12 15:06 ` [RFC 1/4] lockdep: additional lock specific " Peter Zijlstra
2015-01-12 15:12   ` Sasha Levin
2015-01-12 15:37     ` Peter Zijlstra
2015-01-12 16:06       ` Sasha Levin
2015-01-12 16:23         ` Peter Zijlstra
2015-01-13  5:18           ` Sasha Levin

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=1421074631-18831-3-git-send-email-sasha.levin@oracle.com \
    --to=sasha.levin@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    /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

all inboxes | Powered by JetHome®