diff mbox series

[v4,5/5] xen: add function name to lock profiling data

Message ID 20190909143134.15379-6-jgross@suse.com (mailing list archive)
State Superseded
Headers show
Series enhance lock debugging | expand

Commit Message

Jürgen Groß Sept. 9, 2019, 2:31 p.m. UTC
A spinlock defined via DEFINE_SPINLOCK() as a static variable local to
a function shows up in lock profiling just with its local variable
name. This results in multiple locks just named "lock".

In order to be able to distinguish those locks in the lock profiling
output add the function name to struct lock_profile and initialize it
with __PRETTY_FUNCTION__ (__func__ or __FUNCTION__ are not usable
outside of functions with some compilers).

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 xen/common/spinlock.c      | 16 +++++++++++++---
 xen/include/xen/spinlock.h |  4 +++-
 2 files changed, 16 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/xen/common/spinlock.c b/xen/common/spinlock.c
index f40a6b5cb2..cb1c65c5e2 100644
--- a/xen/common/spinlock.c
+++ b/xen/common/spinlock.c
@@ -345,6 +345,7 @@  static s_time_t lock_profile_start;
 static struct lock_profile_anc *lock_profile_ancs;
 static struct lock_profile_qhead lock_profile_glb_q;
 static spinlock_t lock_profile_lock = SPIN_LOCK_UNLOCKED;
+static const char *lock_profile_nofunc = __PRETTY_FUNCTION__;
 
 static void spinlock_profile_iterate(lock_profile_subfunc *sub, void *par)
 {
@@ -368,8 +369,10 @@  static void spinlock_profile_print_elem(struct lock_profile *data,
     printk("%s ", type);
     if ( idx != LOCKPROF_IDX_NONE )
         printk("%d ", idx);
-    printk("%s: addr=%p, lockval=%08x, ", data->name, lock,
-           lock->tickets.head_tail);
+    printk("%s", data->name);
+    if ( data->func && strcmp(data->func, lock_profile_nofunc) )
+        printk("@%s", data->func);
+    printk(": addr=%p, lockval=%08x, ", lock, lock->tickets.head_tail);
     if ( lock->debug.cpu == SPINLOCK_NO_CPU )
         printk("not locked\n");
     else
@@ -424,7 +427,14 @@  static void spinlock_profile_ucopy_elem(struct lock_profile *data,
 
     if ( p->pc->nr_elem < p->pc->max_elem )
     {
-        safe_strcpy(elem.name, data->name);
+        if ( data->func && strcmp(data->func, lock_profile_nofunc) )
+        {
+            snprintf(elem.name, sizeof(elem.name), "%s@%s", data->name,
+                     data->func);
+            elem.name[sizeof(elem.name) - 1] = 0;
+        }
+        else
+            safe_strcpy(elem.name, data->name);
         safe_strcpy(elem.type, type);
         elem.idx = idx;
         elem.lock_cnt = data->lock_cnt;
diff --git a/xen/include/xen/spinlock.h b/xen/include/xen/spinlock.h
index eafa522d79..9cbd222b0d 100644
--- a/xen/include/xen/spinlock.h
+++ b/xen/include/xen/spinlock.h
@@ -77,6 +77,7 @@  struct spinlock;
 struct lock_profile {
     struct lock_profile *next;       /* forward link */
     char                *name;       /* lock name */
+    const char          *func;       /* function name */
     struct spinlock     *lock;       /* the lock itself */
     u64                 lock_cnt;    /* # of complete locking ops */
     u64                 block_cnt;   /* # of complete wait for lock */
@@ -91,7 +92,8 @@  struct lock_profile_qhead {
     int32_t                   idx;     /* index for printout */
 };
 
-#define _LOCK_PROFILE(name) { 0, #name, &name, 0, 0, 0, 0, 0 }
+#define _LOCK_PROFILE(name) { 0, #name, __PRETTY_FUNCTION__, &name,           \
+                              0, 0, 0, 0, 0 }
 #define _LOCK_PROFILE_PTR(name)                                               \
     static struct lock_profile * const __lock_profile_##name                  \
     __used_section(".lockprofile.data") =                                     \