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 2/4] locking/mutex: additional lock information when dumping locks
Date: Mon, 12 Jan 2015 09:57:09 -0500	[thread overview]
Message-ID: <1421074631-18831-2-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>
---
 drivers/usb/storage/usb.c    |    2 +-
 fs/inode.c                   |    3 ++-
 fs/super.c                   |    3 ++-
 include/linux/lockdep.h      |    2 +-
 include/linux/mutex-debug.h  |    2 ++
 include/linux/mutex.h        |    2 +-
 kernel/events/core.c         |    3 ++-
 kernel/locking/lockdep.c     |    8 +++++++-
 kernel/locking/mutex-debug.c |   14 +++++++++++++-
 9 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index d468d02..b0a2565 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -165,7 +165,7 @@ static void us_set_lock_class(struct mutex *mutex,
 
 	BUG_ON(i == config->desc.bNumInterfaces);
 
-	lockdep_set_class(mutex, &us_interface_key[i]);
+	lockdep_set_class_type(mutex, &us_interface_key[i], LOCKTYPE_MUTEX);
 }
 
 #else
diff --git a/fs/inode.c b/fs/inode.c
index 3a53b1d..8e24ff7 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -160,7 +160,8 @@ int inode_init_always(struct super_block *sb, struct inode *inode)
 	lockdep_set_class(&inode->i_lock, &sb->s_type->i_lock_key);
 
 	mutex_init(&inode->i_mutex);
-	lockdep_set_class(&inode->i_mutex, &sb->s_type->i_mutex_key);
+	lockdep_set_class_type(&inode->i_mutex, &sb->s_type->i_mutex_key,
+				LOCKTYPE_MUTEX);
 
 	atomic_set(&inode->i_dio_count, 0);
 
diff --git a/fs/super.c b/fs/super.c
index eae088f..d6b585c 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -217,7 +217,8 @@ static struct super_block *alloc_super(struct file_system_type *type, int flags)
 	s->s_count = 1;
 	atomic_set(&s->s_active, 1);
 	mutex_init(&s->s_vfs_rename_mutex);
-	lockdep_set_class(&s->s_vfs_rename_mutex, &type->s_vfs_rename_key);
+	lockdep_set_class_type(&s->s_vfs_rename_mutex,
+				&type->s_vfs_rename_key, LOCKTYPE_MUTEX);
 	mutex_init(&s->s_dquot.dqio_mutex);
 	mutex_init(&s->s_dquot.dqonoff_mutex);
 	s->s_maxbytes = MAX_NON_LFS;
diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
index 2f4c3fe..cab929b 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, };
+enum LOCK_TYPE { LOCKTYPE_NONE, LOCKTYPE_MUTEX, };
 
 /*
  * Map the lock object (the lock instance) to the lock-class object.
diff --git a/include/linux/mutex-debug.h b/include/linux/mutex-debug.h
index 4ac8b19..ed125d3 100644
--- a/include/linux/mutex-debug.h
+++ b/include/linux/mutex-debug.h
@@ -21,4 +21,6 @@ do {									\
 
 extern void mutex_destroy(struct mutex *lock);
 
+extern void mutex_print_debug(const struct mutex *lock);
+
 #endif
diff --git a/include/linux/mutex.h b/include/linux/mutex.h
index cc31498..cba876d 100644
--- a/include/linux/mutex.h
+++ b/include/linux/mutex.h
@@ -102,7 +102,7 @@ static inline void mutex_destroy(struct mutex *lock) {}
 
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
 # define __DEP_MAP_MUTEX_INITIALIZER(lockname) \
-		, .dep_map = { .name = #lockname }
+		, .dep_map = { .name = #lockname, .type = LOCKTYPE_MUTEX }
 #else
 # define __DEP_MAP_MUTEX_INITIALIZER(lockname)
 #endif
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 4c1ee7f..fef4343 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -6777,7 +6777,8 @@ skip_type:
 
 		cpuctx = per_cpu_ptr(pmu->pmu_cpu_context, cpu);
 		__perf_event_init_context(&cpuctx->ctx);
-		lockdep_set_class(&cpuctx->ctx.mutex, &cpuctx_mutex);
+		lockdep_set_class_type(&cpuctx->ctx.mutex, &cpuctx_mutex,
+					LOCKTYPE_MUTEX);
 		lockdep_set_class(&cpuctx->ctx.lock, &cpuctx_lock);
 		cpuctx->ctx.type = cpu_context;
 		cpuctx->ctx.pmu = pmu;
diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index de4c9aa..07c337d 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -510,8 +510,14 @@ 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;
+
 	switch (t) {
-	case LOCKTYPE_NONE: return;
+	case LOCKTYPE_NONE: break;
+	case LOCKTYPE_MUTEX:
+		mtx = container_of(map, struct mutex, dep_map);
+		mutex_print_debug(mtx);
+		break;
 	}
 }
 
diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
index 5cf6731..e97f763 100644
--- a/kernel/locking/mutex-debug.c
+++ b/kernel/locking/mutex-debug.c
@@ -98,7 +98,7 @@ void debug_mutex_init(struct mutex *lock, const char *name,
 	 * Make sure we are not reinitializing a held lock:
 	 */
 	debug_check_no_locks_freed((void *)lock, sizeof(*lock));
-	lockdep_init_map(&lock->dep_map, name, key, 0);
+	lockdep_init_map_type(&lock->dep_map, name, key, 0, LOCKTYPE_MUTEX);
 #endif
 	lock->magic = lock;
 }
@@ -118,3 +118,15 @@ void mutex_destroy(struct mutex *lock)
 }
 
 EXPORT_SYMBOL_GPL(mutex_destroy);
+
+void mutex_print_debug(const struct mutex *lock)
+{
+	const char *owner = "None";
+	int c = atomic_read(&lock->count);
+
+	if (lock->owner)
+		owner = lock->owner->comm;
+
+	printk("Mutex: counter: %d owner: %s\n", c, owner);
+}
+EXPORT_SYMBOL_GPL(mutex_print_debug);
-- 
1.7.10.4


  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 ` Sasha Levin [this message]
2015-01-12 14:57 ` [RFC 3/4] locking/rwsem: additional lock " Sasha Levin
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-2-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®