linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: "Nysal Jan K.A." <nysal@linux.ibm.com>
To: Nicholas Piggin <npiggin@gmail.com>
Cc: Shrikanth Hegde <sshegde@linux.vnet.ibm.com>,
	linuxppc-dev@lists.ozlabs.org,
	Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Subject: Re: [PATCH 2/6] powerpc/qspinlock: stop queued waiters trying to set lock sleepy
Date: Fri, 20 Oct 2023 15:20:23 +0530	[thread overview]
Message-ID: <20231020095023.GA213288@li-80eaad4c-2afd-11b2-a85c-af8123d033e3.ibm.com> (raw)
In-Reply-To: <20231016124305.139923-3-npiggin@gmail.com>

On Mon, Oct 16, 2023 at 10:43:01PM +1000, Nicholas Piggin wrote:
> If a queued waiter notices the lock owner or the previous waiter has
> been preempted, it attempts to mark the lock sleepy, but it does this
> as a try-set operation using the original lock value it got when
> queueing, which will become stale as the queue progresses, and the
> try-set will fail. Drop this and just set the sleepy seen clock.
> 
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
> ---
>  arch/powerpc/lib/qspinlock.c | 24 ++++++++++--------------
>  1 file changed, 10 insertions(+), 14 deletions(-)
> 
> diff --git a/arch/powerpc/lib/qspinlock.c b/arch/powerpc/lib/qspinlock.c
> index 6dd2f46bd3ef..75608ced14c2 100644
> --- a/arch/powerpc/lib/qspinlock.c
> +++ b/arch/powerpc/lib/qspinlock.c
> @@ -247,22 +247,18 @@ static __always_inline void seen_sleepy_lock(void)
>  		this_cpu_write(sleepy_lock_seen_clock, sched_clock());
>  }
>  
> -static __always_inline void seen_sleepy_node(struct qspinlock *lock, u32 val)
> +static __always_inline void seen_sleepy_node(void)
>  {
>  	if (pv_sleepy_lock) {
>  		if (pv_sleepy_lock_interval_ns)
>  			this_cpu_write(sleepy_lock_seen_clock, sched_clock());
> -		if (val & _Q_LOCKED_VAL) {
> -			if (!(val & _Q_SLEEPY_VAL))
> -				try_set_sleepy(lock, val);
> -		}
> +		/* Don't set sleepy because we likely have a stale val */
>  	}
>  }

seen_sleepy_lock() and seen_sleepy_node() are now the same

>  
> -static struct qnode *get_tail_qnode(struct qspinlock *lock, u32 val)
> +static struct qnode *get_tail_qnode(struct qspinlock *lock, int prev_cpu)
>  {
> -	int cpu = decode_tail_cpu(val);
> -	struct qnodes *qnodesp = per_cpu_ptr(&qnodes, cpu);
> +	struct qnodes *qnodesp = per_cpu_ptr(&qnodes, prev_cpu);
>  	int idx;
>  
>  	/*
> @@ -381,9 +377,8 @@ static __always_inline void propagate_yield_cpu(struct qnode *node, u32 val, int
>  }
>  
>  /* Called inside spin_begin() */
> -static __always_inline bool yield_to_prev(struct qspinlock *lock, struct qnode *node, u32 val, bool paravirt)
> +static __always_inline bool yield_to_prev(struct qspinlock *lock, struct qnode *node, int prev_cpu, bool paravirt)
>  {
> -	int prev_cpu = decode_tail_cpu(val);
>  	u32 yield_count;
>  	int yield_cpu;
>  	bool preempted = false;
> @@ -412,7 +407,7 @@ static __always_inline bool yield_to_prev(struct qspinlock *lock, struct qnode *
>  	spin_end();
>  
>  	preempted = true;
> -	seen_sleepy_node(lock, val);
> +	seen_sleepy_node();
>  
>  	smp_rmb();
>  
> @@ -436,7 +431,7 @@ static __always_inline bool yield_to_prev(struct qspinlock *lock, struct qnode *
>  	spin_end();
>  
>  	preempted = true;
> -	seen_sleepy_node(lock, val);
> +	seen_sleepy_node();
>  
>  	smp_rmb(); /* See __yield_to_locked_owner comment */
>  
> @@ -587,7 +582,8 @@ static __always_inline void queued_spin_lock_mcs_queue(struct qspinlock *lock, b
>  	 * head of the waitqueue.
>  	 */
>  	if (old & _Q_TAIL_CPU_MASK) {
> -		struct qnode *prev = get_tail_qnode(lock, old);
> +		int prev_cpu = decode_tail_cpu(old);
> +		struct qnode *prev = get_tail_qnode(lock, prev_cpu);
>  
>  		/* Link @node into the waitqueue. */
>  		WRITE_ONCE(prev->next, node);
> @@ -597,7 +593,7 @@ static __always_inline void queued_spin_lock_mcs_queue(struct qspinlock *lock, b
>  		while (!READ_ONCE(node->locked)) {
>  			spec_barrier();
>  
> -			if (yield_to_prev(lock, node, old, paravirt))
> +			if (yield_to_prev(lock, node, prev_cpu, paravirt))
>  				seen_preempted = true;
>  		}
>  		spec_barrier();
> -- 
> 2.42.0
> 

  reply	other threads:[~2023-10-20  9:51 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-16 12:42 [PATCH 0/6] powerpc/qspinlock: Fix yield latency bug and other Nicholas Piggin
2023-10-16 12:43 ` [PATCH 1/6] powerpc/qspinlock: Fix stale propagated yield_cpu Nicholas Piggin
2023-10-16 12:43 ` [PATCH 2/6] powerpc/qspinlock: stop queued waiters trying to set lock sleepy Nicholas Piggin
2023-10-20  9:50   ` Nysal Jan K.A. [this message]
2023-10-16 12:43 ` [PATCH 3/6] powerpc/qspinlock: propagate owner preemptedness rather than CPU number Nicholas Piggin
2023-10-16 12:43 ` [PATCH 4/6] powerpc/qspinlock: don't propagate the not-sleepy state Nicholas Piggin
2023-10-16 12:43 ` [PATCH 5/6] powerpc/qspinlock: Propagate sleepy if previous waiter is preempted Nicholas Piggin
2023-10-16 12:43 ` [PATCH 6/6] powerpc/qspinlock: Rename yield_propagate_owner tunable Nicholas Piggin
2023-10-18  7:41 ` [PATCH 0/6] powerpc/qspinlock: Fix yield latency bug and other Shrikanth Hegde
2023-10-20 10:04 ` Nysal Jan K.A.
2023-10-20 12:01 ` (subset) " Michael Ellerman
2023-10-27  9:59 ` Michael Ellerman

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=20231020095023.GA213288@li-80eaad4c-2afd-11b2-a85c-af8123d033e3.ibm.com \
    --to=nysal@linux.ibm.com \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=npiggin@gmail.com \
    --cc=srikar@linux.vnet.ibm.com \
    --cc=sshegde@linux.vnet.ibm.com \
    /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;
as well as URLs for NNTP newsgroup(s).