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>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	George Dunlap <george.dunlap@citrix.com>,
	Jan Beulich <jbeulich@suse.com>, Julien Grall <julien@xen.org>,
	Stefano Stabellini <sstabellini@kernel.org>, Wei Liu <wl@xen.org>,
	Alejandro Vallejo <alejandro.vallejo@cloud.com>,
	Julien Grall <jgrall@amazon.com>
Subject: [PATCH v5 05/13] xen/spinlock: make struct lock_profile rspinlock_t aware
Date: Thu, 14 Mar 2024 08:20:21 +0100	[thread overview]
Message-ID: <20240314072029.16937-6-jgross@suse.com> (raw)
In-Reply-To: <20240314072029.16937-1-jgross@suse.com>

Struct lock_profile contains a pointer to the spinlock it is associated
with. Prepare support of differing spinlock_t and rspinlock_t types by
adding a type indicator of the pointer. Use the highest bit of the
block_cnt member for this indicator in order to not grow the struct
while hurting only the slow path with slightly less performant code.
Note that this requires a cast when printing the value in order to be
format compliant.

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Alejandro Vallejo <alejandro.vallejo@cloud.com>
Acked-by: Julien Grall <jgrall@amazon.com>
---
V2:
- new patch
V5:
- use bool for is_rlock (Julien Grall)
- use unsigned int for lockval in spinlock_profile_print_elem()
  (Jan Beulich)
- don't use anonymous union (Jan Beulich)
---
 xen/common/spinlock.c      | 28 ++++++++++++++++++++--------
 xen/include/xen/spinlock.h | 14 ++++++++++----
 2 files changed, 30 insertions(+), 12 deletions(-)

diff --git a/xen/common/spinlock.c b/xen/common/spinlock.c
index 5ef0ac7f89..0e8b525cec 100644
--- a/xen/common/spinlock.c
+++ b/xen/common/spinlock.c
@@ -538,19 +538,31 @@ static void spinlock_profile_iterate(lock_profile_subfunc *sub, void *par)
 static void cf_check spinlock_profile_print_elem(struct lock_profile *data,
     int32_t type, int32_t idx, void *par)
 {
-    struct spinlock *lock = data->lock;
+    unsigned int cpu;
+    unsigned int lockval;
+
+    if ( data->is_rlock )
+    {
+        cpu = data->ptr.rlock->debug.cpu;
+        lockval = data->ptr.rlock->tickets.head_tail;
+    }
+    else
+    {
+        cpu = data->ptr.lock->debug.cpu;
+        lockval = data->ptr.lock->tickets.head_tail;
+    }
 
     printk("%s ", lock_profile_ancs[type].name);
     if ( type != LOCKPROF_TYPE_GLOBAL )
         printk("%d ", idx);
-    printk("%s: addr=%p, lockval=%08x, ", data->name, lock,
-           lock->tickets.head_tail);
-    if ( lock->debug.cpu == SPINLOCK_NO_CPU )
+    printk("%s: addr=%p, lockval=%08x, ", data->name, data->ptr.lock, lockval);
+    if ( cpu == SPINLOCK_NO_CPU )
         printk("not locked\n");
     else
-        printk("cpu=%d\n", lock->debug.cpu);
-    printk("  lock:%" PRId64 "(%" PRI_stime "), block:%" PRId64 "(%" PRI_stime ")\n",
-           data->lock_cnt, data->time_hold, data->block_cnt, data->time_block);
+        printk("cpu=%u\n", cpu);
+    printk("  lock:%" PRIu64 "(%" PRI_stime "), block:%" PRIu64 "(%" PRI_stime ")\n",
+           data->lock_cnt, data->time_hold, (uint64_t)data->block_cnt,
+           data->time_block);
 }
 
 void cf_check spinlock_profile_printall(unsigned char key)
@@ -680,7 +692,7 @@ static int __init cf_check lock_prof_init(void)
     {
         (*q)->next = lock_profile_glb_q.elem_q;
         lock_profile_glb_q.elem_q = *q;
-        (*q)->lock->profile = *q;
+        (*q)->ptr.lock->profile = *q;
     }
 
     _lock_profile_register_struct(LOCKPROF_TYPE_GLOBAL,
diff --git a/xen/include/xen/spinlock.h b/xen/include/xen/spinlock.h
index afa24c8e29..49c5115f52 100644
--- a/xen/include/xen/spinlock.h
+++ b/xen/include/xen/spinlock.h
@@ -77,13 +77,19 @@ union lock_debug { };
 */
 
 struct spinlock;
+/* Temporary hack until a dedicated struct rspinlock is existing. */
+#define rspinlock spinlock
 
 struct lock_profile {
     struct lock_profile *next;       /* forward link */
     const char          *name;       /* lock name */
-    struct spinlock     *lock;       /* the lock itself */
+    union {
+        struct spinlock *lock;       /* the lock itself */
+        struct rspinlock *rlock;     /* the recursive lock itself */
+    } ptr;
     uint64_t            lock_cnt;    /* # of complete locking ops */
-    uint64_t            block_cnt;   /* # of complete wait for lock */
+    uint64_t            block_cnt:63; /* # of complete wait for lock */
+    bool                is_rlock:1;  /* use rlock pointer */
     s_time_t            time_hold;   /* cumulated lock time */
     s_time_t            time_block;  /* cumulated wait time */
     s_time_t            time_locked; /* system time of last locking */
@@ -95,7 +101,7 @@ struct lock_profile_qhead {
     int32_t                   idx;     /* index for printout */
 };
 
-#define LOCK_PROFILE_(lockname) { .name = #lockname, .lock = &(lockname), }
+#define LOCK_PROFILE_(lockname) { .name = #lockname, .ptr.lock = &(lockname), }
 #define LOCK_PROFILE_PTR_(name)                                               \
     static struct lock_profile * const lock_profile__##name                   \
     __used_section(".lockprofile.data") =                                     \
@@ -128,7 +134,7 @@ struct lock_profile_qhead {
             break;                                                            \
         }                                                                     \
         prof->name = #l;                                                      \
-        prof->lock = &(s)->l;                                                 \
+        prof->ptr.lock = &(s)->l;                                             \
         prof->next = (s)->profile_head.elem_q;                                \
         (s)->profile_head.elem_q = prof;                                      \
     } while( 0 )
-- 
2.35.3



  parent reply	other threads:[~2024-03-14  7:21 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-14  7:20 [PATCH v5 00/13] xen/spinlock: make recursive spinlocks a dedicated type Juergen Gross
2024-03-14  7:20 ` [PATCH v5 01/13] xen/spinlock: remove misra rule 21.1 violations Juergen Gross
2024-03-14  7:32   ` Jan Beulich
2024-03-14 10:13     ` Jürgen Groß
2024-03-14  7:20 ` [PATCH v5 02/13] xen/spinlock: introduce new type for recursive spinlocks Juergen Gross
2024-03-18 14:35   ` Jan Beulich
2024-03-14  7:20 ` [PATCH v5 03/13] xen/spinlock: rename recursive lock functions Juergen Gross
2024-03-14  7:20 ` [PATCH v5 04/13] xen/spinlock: add rspin_[un]lock_irq[save|restore]() Juergen Gross
2024-03-18 14:43   ` Jan Beulich
2024-03-18 15:55     ` Jürgen Groß
2024-03-18 15:59       ` Jan Beulich
2024-03-18 16:05         ` Jürgen Groß
2024-03-18 16:08           ` Jan Beulich
2024-03-18 16:09             ` Jürgen Groß
2024-03-14  7:20 ` Juergen Gross [this message]
2024-03-14  7:20 ` [PATCH v5 06/13] xen/spinlock: add explicit non-recursive locking functions Juergen Gross
2024-03-14  7:20 ` [PATCH v5 07/13] xen/spinlock: add another function level Juergen Gross
2024-03-18 14:49   ` Jan Beulich
2024-03-14  7:20 ` [PATCH v5 08/13] xen/spinlock: add missing rspin_is_locked() and rspin_barrier() Juergen Gross
2024-03-18 14:57   ` Jan Beulich
2024-03-18 15:31     ` Jürgen Groß
2024-03-18 15:44       ` Jan Beulich
2024-03-18 15:49         ` Jürgen Groß
2024-03-14  7:20 ` [PATCH v5 09/13] xen/spinlock: split recursive spinlocks from normal ones Juergen Gross
2024-03-18 14:59   ` Jan Beulich
2024-03-14  7:20 ` [PATCH v5 10/13] xen/spinlock: let all is_locked and trylock variants return bool Juergen Gross
2024-03-18 15:00   ` Jan Beulich
2024-03-14  7:20 ` [PATCH v5 11/13] xen/spinlock: support higher number of cpus Juergen Gross
2024-03-18 15:08   ` Jan Beulich
2024-03-18 15:56     ` Jürgen Groß
2024-03-14  7:20 ` [PATCH v5 12/13] xen/rwlock: raise the number of possible cpus Juergen Gross
2024-03-18 15:39   ` Jan Beulich
2024-03-18 16:00     ` Jürgen Groß
2024-03-18 16:05       ` Jan Beulich
2024-03-18 16:06         ` Jürgen Groß
2024-03-14  7:20 ` [PATCH v5 13/13] xen: allow up to 16383 cpus Juergen Gross
2024-03-14  7:26   ` Jan Beulich
2024-03-14 10:14     ` Jürgen Groß

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=20240314072029.16937-6-jgross@suse.com \
    --to=jgross@suse.com \
    --cc=alejandro.vallejo@cloud.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=george.dunlap@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=jgrall@amazon.com \
    --cc=julien@xen.org \
    --cc=sstabellini@kernel.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.