From: Waiman Long <longman@redhat.com>
To: guoren@kernel.org, peterz@infradead.org
Cc: linux-kernel@vger.kernel.org, Guo Ren <guoren@linux.alibaba.com>,
Boqun Feng <boqun.feng@gmail.com>, Will Deacon <will@kernel.org>,
Ingo Molnar <mingo@redhat.com>
Subject: Re: [PATCH] locking/qspinlock: Optimize pending state waiting for unlock
Date: Sat, 24 Dec 2022 20:55:09 -0500 [thread overview]
Message-ID: <08ce1ab6-4678-74ce-43cc-2d3f04d1525d@redhat.com> (raw)
In-Reply-To: <20221224120545.262989-1-guoren@kernel.org>
On 12/24/22 07:05, guoren@kernel.org wrote:
> From: Guo Ren <guoren@linux.alibaba.com>
>
> When we're pending, we only care about lock value. The xchg_tail
> wouldn't affect the pending state. That means the hardware thread
> could stay in a sleep state and leaves the rest execution units'
> resources of pipeline to other hardware threads. This optimization
> may work only for SMT scenarios because the granularity between
> cores is cache-block.
>
> Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
> Signed-off-by: Guo Ren <guoren@kernel.org>
> Cc: Waiman Long <longman@redhat.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Boqun Feng <boqun.feng@gmail.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: Ingo Molnar <mingo@redhat.com>
> ---
> kernel/locking/qspinlock.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/locking/qspinlock.c b/kernel/locking/qspinlock.c
> index 2b23378775fe..ebe6b8ec7cb3 100644
> --- a/kernel/locking/qspinlock.c
> +++ b/kernel/locking/qspinlock.c
> @@ -371,7 +371,7 @@ void __lockfunc queued_spin_lock_slowpath(struct qspinlock *lock, u32 val)
> /*
> * We're pending, wait for the owner to go away.
> *
> - * 0,1,1 -> 0,1,0
> + * 0,1,1 -> *,1,0
> *
> * this wait loop must be a load-acquire such that we match the
> * store-release that clears the locked bit and create lock
Yes, we don't care about the tail.
> @@ -380,7 +380,7 @@ void __lockfunc queued_spin_lock_slowpath(struct qspinlock *lock, u32 val)
> * barriers.
> */
> if (val & _Q_LOCKED_MASK)
> - atomic_cond_read_acquire(&lock->val, !(VAL & _Q_LOCKED_MASK));
> + smp_cond_load_acquire(&lock->locked, !VAL);
>
> /*
> * take ownership and clear the pending bit.
We may save an AND operation here which may be a cycle or two. I
remember that it may be more costly to load a byte instead of an integer
in some arches. So it doesn't seem like that much of an optimization
from my point of view. I know that arm64 will enter a low power state in
this *cond_load_acquire() loop, but I believe any change in the state of
the the lock cacheline will wake it up. So it doesn't really matter if
you are checking a byte or an int.
Do you have any other data point to support your optimization claim?
Cheers,
Longman
next prev parent reply other threads:[~2022-12-25 2:00 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-24 12:05 guoren
2022-12-25 1:55 ` Waiman Long [this message]
2022-12-25 2:57 ` Guo Ren
2022-12-25 3:29 ` Waiman Long
2022-12-25 3:30 ` Waiman Long
2022-12-25 11:59 ` Guo Ren
2023-01-04 20:19 ` Ingo Molnar
2023-01-05 2:31 ` Guo Ren
2023-01-05 10:03 ` Ingo Molnar
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=08ce1ab6-4678-74ce-43cc-2d3f04d1525d@redhat.com \
--to=longman@redhat.com \
--cc=boqun.feng@gmail.com \
--cc=guoren@kernel.org \
--cc=guoren@linux.alibaba.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--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®