From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: linux-kernel@vger.kernel.org
Cc: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>,
Waiman Long <longman@redhat.com>,
Boqun Feng <boqun.feng@gmail.com>,
Thomas Gleixner <tglx@linutronix.de>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Subject: [PATCH 2/2] locking: Provide spin_is_contended() on PREEMPT_RT
Date: Mon, 6 Sep 2021 16:30:04 +0200 [thread overview]
Message-ID: <20210906143004.2259141-3-bigeasy@linutronix.de> (raw)
In-Reply-To: <20210906143004.2259141-1-bigeasy@linutronix.de>
spin_is_contended() should return != 0 if there is a waiter pending on
the lock. This can be checked on PREEMPT_RT's spin lock implementation
by checking if the lock as any waiters pending.
Provide spin_is_contended() on PREEMPT_RT by checking if there are any
waiters.
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
include/linux/spinlock_rt.h | 3 ++-
kernel/locking/spinlock_rt.c | 6 ++++++
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/include/linux/spinlock_rt.h b/include/linux/spinlock_rt.h
index 835aedaf68acd..844bc8f9cf091 100644
--- a/include/linux/spinlock_rt.h
+++ b/include/linux/spinlock_rt.h
@@ -39,6 +39,7 @@ extern void rt_spin_unlock(spinlock_t *lock);
extern void rt_spin_lock_unlock(spinlock_t *lock);
extern int rt_spin_trylock_bh(spinlock_t *lock);
extern int rt_spin_trylock(spinlock_t *lock);
+extern int rt_spin_is_contended(spinlock_t *lock);
static __always_inline void spin_lock(spinlock_t *lock)
{
@@ -145,7 +146,7 @@ static __always_inline void spin_unlock_irqrestore(spinlock_t *lock,
#define spin_trylock_irqsave(lock, flags) \
__cond_lock(lock, __spin_trylock_irqsave(lock, flags))
-#define spin_is_contended(lock) (((void)(lock), 0))
+#define spin_is_contended(lock) rt_spin_is_contended(lock)
static inline int spin_is_locked(spinlock_t *lock)
{
diff --git a/kernel/locking/spinlock_rt.c b/kernel/locking/spinlock_rt.c
index d2912e44d61fd..c9acb665277ff 100644
--- a/kernel/locking/spinlock_rt.c
+++ b/kernel/locking/spinlock_rt.c
@@ -118,6 +118,12 @@ int __sched rt_spin_trylock_bh(spinlock_t *lock)
}
EXPORT_SYMBOL(rt_spin_trylock_bh);
+int __sched rt_spin_is_contended(spinlock_t *lock)
+{
+ return rt_mutex_has_waiters(&lock->lock);
+}
+EXPORT_SYMBOL(rt_spin_is_contended);
+
#ifdef CONFIG_DEBUG_LOCK_ALLOC
void __rt_spin_lock_init(spinlock_t *lock, const char *name,
struct lock_class_key *key, bool percpu)
--
2.33.0
next prev parent reply other threads:[~2021-09-06 14:30 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-06 14:30 [PATCH 0/2] locking: Provide {rwlock|spin}_is_contended " Sebastian Andrzej Siewior
2021-09-06 14:30 ` [PATCH 1/2] locking: Wire up rwlock_is_contended() " Sebastian Andrzej Siewior
2021-09-06 14:30 ` Sebastian Andrzej Siewior [this message]
2021-09-07 10:09 ` [PATCH 0/2] locking: Provide {rwlock|spin}_is_contended " Sebastian Andrzej Siewior
2021-09-07 10:34 ` [PATCH] locking: Remove rt_rwlock_is_contended() Sebastian Andrzej Siewior
2021-09-10 16:16 ` Peter Zijlstra
2021-09-10 16:37 ` Sebastian Andrzej Siewior
2021-09-13 11:20 ` Peter Zijlstra
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=20210906143004.2259141-3-bigeasy@linutronix.de \
--to=bigeasy@linutronix.de \
--cc=boqun.feng@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--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®