mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Waiman Long <longman@redhat.com>
To: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>,
	Boqun Feng <boqun.feng@gmail.com>
Cc: linux-kernel@vger.kernel.org, Vernon Lovejoy <vlovejoy@redhat.com>
Subject: Re: [PATCH] locking/qspinlock: Save qspinlock owner CPU into mcs_spinlock
Date: Fri, 3 May 2024 18:33:42 -0400	[thread overview]
Message-ID: <ac4a1b8c-b7c8-47a0-82ad-cbe62a166560@redhat.com> (raw)
In-Reply-To: <20240503215918.639519-1-longman@redhat.com>


On 5/3/24 17:59, Waiman Long wrote:
> When examining a contended spinlock in a crash dump, we can trace out the
> list of lock waiter CPUs waiting for the lock by following the linked
> list of mcs_spinlock structures. However, the actual owner of the lock
> is not there making it hard to figure out who the current lock owner is.
>
> Make it easier to figure out this information by saving the lock owner
> CPU into the mcs_spinlock structure of new MCS lock owner, if available,
> when acquiring the lock in the qspinlock slowpath. We can then follow
> the linked list of mcs_spinlock structures to the end to get an encoded
> CPU number of the lock owner, if set.
>
> This owner information is still not available when the lock is acquired
> directly in the fast path or in the pending code path. There is no easy
> way around that.
>
> The additional cost to get the current CPU number in the slowpath should
> be minimal as it should be in a hot cacheline.
>
> Signed-off-by: Waiman Long <longman@redhat.com>

Oh, I forgot that the mcs_spinlock has no backward information. Please 
ignore this patch and will send an updated one later.

Cheers,
Longman

> ---
>   kernel/locking/mcs_spinlock.h | 10 ++++++++--
>   1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/locking/mcs_spinlock.h b/kernel/locking/mcs_spinlock.h
> index 85251d8771d9..ac0ed0a8f028 100644
> --- a/kernel/locking/mcs_spinlock.h
> +++ b/kernel/locking/mcs_spinlock.h
> @@ -13,11 +13,17 @@
>   #ifndef __LINUX_MCS_SPINLOCK_H
>   #define __LINUX_MCS_SPINLOCK_H
>   
> +/*
> + * Save an encoded version of the current MCS lock owner CPU to the
> + * mcs_spinlock structure of the next lock owner.
> + */
> +#define MCS_LOCKED	(smp_processor_id() + 1)
> +
>   #include <asm/mcs_spinlock.h>
>   
>   struct mcs_spinlock {
>   	struct mcs_spinlock *next;
> -	int locked; /* 1 if lock acquired */
> +	int locked; /* non-zero if lock acquired */
>   	int count;  /* nesting count, see qspinlock.c */
>   };
>   
> @@ -42,7 +48,7 @@ do {									\
>    * unlocking.
>    */
>   #define arch_mcs_spin_unlock_contended(l)				\
> -	smp_store_release((l), 1)
> +	smp_store_release((l), MCS_LOCKED)
>   #endif
>   
>   /*


      reply	other threads:[~2024-05-03 22:33 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-03 21:59 Waiman Long
2024-05-03 22:33 ` Waiman Long [this message]

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=ac4a1b8c-b7c8-47a0-82ad-cbe62a166560@redhat.com \
    --to=longman@redhat.com \
    --cc=boqun.feng@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=vlovejoy@redhat.com \
    --cc=will@kernel.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®