From: Nicholas Piggin <npiggin@gmail.com>
To: linuxppc-dev@lists.ozlabs.org
Cc: Nicholas Piggin <npiggin@gmail.com>
Subject: [RFC PATCH 14/14] powerpc/qspinlock: use spin_begin/end API
Date: Mon, 11 Jul 2022 13:04:53 +1000 [thread overview]
Message-ID: <20220711030453.150644-15-npiggin@gmail.com> (raw)
In-Reply-To: <20220711030453.150644-1-npiggin@gmail.com>
Use the spin_begin/spin_cpu_relax/spin_end APIs in qspinlock, which helps
to prevent threads issuing a lot of expensive priority nops which may not
have much effect due to immediately executing low then medium priority.
---
arch/powerpc/lib/qspinlock.c | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/arch/powerpc/lib/qspinlock.c b/arch/powerpc/lib/qspinlock.c
index d67b923e4f98..486423d566d3 100644
--- a/arch/powerpc/lib/qspinlock.c
+++ b/arch/powerpc/lib/qspinlock.c
@@ -243,7 +243,7 @@ static void __yield_to_locked_owner(struct qspinlock *lock, u32 val, bool paravi
return;
}
relax:
- cpu_relax();
+ spin_cpu_relax();
}
static void yield_to_locked_owner(struct qspinlock *lock, u32 val, bool paravirt)
@@ -331,7 +331,7 @@ static void yield_to_prev(struct qspinlock *lock, struct qnode *node, int prev_c
}
relax:
- cpu_relax();
+ spin_cpu_relax();
}
@@ -340,6 +340,7 @@ static __always_inline bool try_to_steal_lock(struct qspinlock *lock, bool parav
int iters;
/* Attempt to steal the lock */
+ spin_begin();
for (iters = 0; iters < STEAL_SPINS; iters++) {
u32 val = READ_ONCE(lock->val);
@@ -354,6 +355,7 @@ static __always_inline bool try_to_steal_lock(struct qspinlock *lock, bool parav
if (trylock_with_tail_cpu(lock, val))
return true;
}
+ spin_end();
return false;
}
@@ -404,8 +406,10 @@ static __always_inline void queued_spin_lock_mcs_queue(struct qspinlock *lock, b
WRITE_ONCE(prev->next, node);
/* Wait for mcs node lock to be released */
+ spin_begin();
while (!node->locked)
yield_to_prev(lock, node, prev_cpu, paravirt);
+ spin_end();
/* Clear out stale propagated yield_cpu */
if (paravirt && pv_yield_propagate_owner && node->yield_cpu != -1)
@@ -418,10 +422,12 @@ static __always_inline void queued_spin_lock_mcs_queue(struct qspinlock *lock, b
int set_yield_cpu = -1;
/* We're at the head of the waitqueue, wait for the lock. */
+ spin_begin();
while ((val = READ_ONCE(lock->val)) & _Q_LOCKED_VAL) {
propagate_yield_cpu(node, val, &set_yield_cpu, paravirt);
yield_head_to_locked_owner(lock, val, paravirt, false);
}
+ spin_end();
/* If we're the last queued, must clean up the tail. */
if ((val & _Q_TAIL_CPU_MASK) == tail) {
@@ -436,6 +442,7 @@ static __always_inline void queued_spin_lock_mcs_queue(struct qspinlock *lock, b
int set_yield_cpu = -1;
int iters = 0;
again:
+ spin_begin();
/* We're at the head of the waitqueue, wait for the lock. */
while ((val = READ_ONCE(lock->val)) & _Q_LOCKED_VAL) {
if (iters++ == HEAD_SPINS) {
@@ -446,6 +453,7 @@ static __always_inline void queued_spin_lock_mcs_queue(struct qspinlock *lock, b
yield_head_to_locked_owner(lock, val, paravirt,
pv_yield_allow_steal && (iters > HEAD_SPINS));
}
+ spin_end();
/* If we're the last queued, must clean up the tail. */
if ((val & _Q_TAIL_CPU_MASK) == tail) {
@@ -461,8 +469,13 @@ static __always_inline void queued_spin_lock_mcs_queue(struct qspinlock *lock, b
unlock_next:
/* contended path; must wait for next != NULL (MCS protocol) */
- while (!(next = READ_ONCE(node->next)))
- cpu_relax();
+ next = READ_ONCE(node->next);
+ if (!next) {
+ spin_begin();
+ while (!(next = READ_ONCE(node->next)))
+ cpu_relax();
+ spin_end();
+ }
/*
* Unlock the next mcs waiter node. Release barrier is not required
--
2.35.1
prev parent reply other threads:[~2022-07-11 3:14 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-11 3:04 [RFC PATCH 00/14] add our own qspinlock implementation Nicholas Piggin
2022-07-11 3:04 ` [RFC PATCH 01/14] powerpc/qspinlock: powerpc " Nicholas Piggin
2022-07-11 3:04 ` [RFC PATCH 02/14] powerpc/qspinlock: add mcs queueing for contended waiters Nicholas Piggin
2022-07-11 3:04 ` [RFC PATCH 03/14] powerpc/qspinlock: use a half-word store to unlock to avoid larx/stcx Nicholas Piggin
2022-07-11 3:04 ` [RFC PATCH 04/14] powerpc/qspinlock: convert atomic operations to assembly Nicholas Piggin
2022-07-11 3:04 ` [RFC PATCH 05/14] powerpc/qspinlock: allow new waiters to steal the lock before queueing Nicholas Piggin
2022-07-11 3:04 ` [RFC PATCH 06/14] powerpc/qspinlock: theft prevention to control latency Nicholas Piggin
2022-07-11 3:04 ` [RFC PATCH 07/14] powerpc/qspinlock: store owner CPU in lock word Nicholas Piggin
2022-07-11 3:04 ` [RFC PATCH 08/14] powerpc/qspinlock: paravirt yield to lock owner Nicholas Piggin
2022-07-11 3:04 ` [RFC PATCH 09/14] powerpc/qspinlock: implement option to yield to previous node Nicholas Piggin
2022-07-11 3:04 ` [RFC PATCH 10/14] powerpc/qspinlock: allow stealing when head of queue yields Nicholas Piggin
2022-07-11 3:04 ` [RFC PATCH 11/14] powerpc/qspinlock: allow propagation of yield CPU down the queue Nicholas Piggin
2022-07-11 3:04 ` [RFC PATCH 12/14] powerpc/qspinlock: add ability to prod new queue head CPU Nicholas Piggin
2022-07-11 3:04 ` [RFC PATCH 13/14] powerpc/qspinlock: trylock and initial lock attempt may steal Nicholas Piggin
2022-07-11 3:04 ` Nicholas Piggin [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=20220711030453.150644-15-npiggin@gmail.com \
--to=npiggin@gmail.com \
--cc=linuxppc-dev@lists.ozlabs.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;
as well as URLs for NNTP newsgroup(s).