All of lore.kernel.org
 help / color / mirror / Atom feed
From: Juergen Gross <jgross@suse.com>
To: xen-devel@lists.xenproject.org
Cc: Juergen Gross <jgross@suse.com>,
	Stefano Stabellini <sstabellini@kernel.org>, Wei Liu <wl@xen.org>,
	Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
	George Dunlap <George.Dunlap@eu.citrix.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Ian Jackson <ian.jackson@eu.citrix.com>, Tim Deegan <tim@xen.org>,
	Julien Grall <julien.grall@arm.com>,
	Jan Beulich <jbeulich@suse.com>
Subject: [Xen-devel] [PATCH v5 5/5] xen: add function name to lock profiling data
Date: Thu, 12 Sep 2019 15:28:13 +0200	[thread overview]
Message-ID: <20190912132813.6509-6-jgross@suse.com> (raw)
In-Reply-To: <20190912132813.6509-1-jgross@suse.com>

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 --git a/xen/common/spinlock.c b/xen/common/spinlock.c
index 673ef168da..3147bc3a7a 100644
--- a/xen/common/spinlock.c
+++ b/xen/common/spinlock.c
@@ -348,6 +348,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)
 {
@@ -371,8 +372,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
@@ -427,7 +430,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 401cc345fe..49b29f7c54 100644
--- a/xen/include/xen/spinlock.h
+++ b/xen/include/xen/spinlock.h
@@ -78,6 +78,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 */
@@ -92,7 +93,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") =                                     \
-- 
2.16.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  parent reply	other threads:[~2019-09-12 13:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-12 13:28 [Xen-devel] [PATCH v5 0/5] enhance lock debugging Juergen Gross
2019-09-12 13:28 ` [Xen-devel] [PATCH v5 1/5] xen/spinlocks: in debug builds store cpu holding the lock Juergen Gross
2019-09-12 13:36   ` Jan Beulich
2019-09-12 13:42     ` Juergen Gross
2019-09-12 14:30       ` Jan Beulich
2019-09-12 13:28 ` [Xen-devel] [PATCH v5 2/5] xen: add new CONFIG_DEBUG_LOCKS option Juergen Gross
2019-09-12 13:28 ` [Xen-devel] [PATCH v5 3/5] xen: print lock profile info in panic() Juergen Gross
2019-09-12 13:28 ` [Xen-devel] [PATCH v5 4/5] xen: modify lock profiling interface Juergen Gross
2019-09-12 13:28 ` Juergen Gross [this message]
2019-09-13  9:53   ` [Xen-devel] [PATCH v5 5/5] xen: add function name to lock profiling data Jan Beulich
2019-09-13 10:21     ` Juergen Gross

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=20190912132813.6509-6-jgross@suse.com \
    --to=jgross@suse.com \
    --cc=George.Dunlap@eu.citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jbeulich@suse.com \
    --cc=julien.grall@arm.com \
    --cc=konrad.wilk@oracle.com \
    --cc=sstabellini@kernel.org \
    --cc=tim@xen.org \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.