From: Ben Gardon <bgardon@google.com>
To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Sean Christopherson <sean.j.christopherson@intel.com>,
Peter Shier <pshier@google.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>,
Waiman Long <longman@redhat.com>,
Davidlohr Bueso <dave@stgolabs.net>,
Ben Gardon <bgardon@google.com>
Subject: [PATCH 2/3] sched: Add needbreak for rwlocks
Date: Tue, 27 Oct 2020 09:49:49 -0700 [thread overview]
Message-ID: <20201027164950.1057601-2-bgardon@google.com> (raw)
In-Reply-To: <20201027164950.1057601-1-bgardon@google.com>
Contention awareness while holding a spin lock is essential for reducing
latency when long running kernel operations can hold that lock. Add the
same contention detection interface for read/write spin locks.
Signed-off-by: Ben Gardon <bgardon@google.com>
---
include/linux/sched.h | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 063cd120b4593..77179160ec3ab 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1870,6 +1870,23 @@ static inline int spin_needbreak(spinlock_t *lock)
#endif
}
+/*
+ * Check if a rwlock is contended.
+ * Returns non-zero if there is another task waiting on the rwlock.
+ * Returns zero if the lock is not contended or the system / underlying
+ * rwlock implementation does not support contention detection.
+ * Technically does not depend on CONFIG_PREEMPTION, but a general need
+ * for low latency.
+ */
+static inline int rwlock_needbreak(rwlock_t *lock)
+{
+#ifdef CONFIG_PREEMPTION
+ return rwlock_is_contended(lock);
+#else
+ return 0;
+#endif
+}
+
static __always_inline bool need_resched(void)
{
return unlikely(tif_need_resched());
--
2.29.0.rc2.309.g374f81d7ae-goog
next prev parent reply other threads:[~2020-10-27 16:50 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-27 16:49 [PATCH 1/3] locking/rwlocks: Add contention detection for rwlocks Ben Gardon
2020-10-27 16:49 ` Ben Gardon [this message]
2020-10-27 16:49 ` [PATCH 3/3] sched: Add cond_resched_rwlock Ben Gardon
2020-10-27 17:56 ` Sean Christopherson
2020-10-27 19:17 ` Peter Zijlstra
2020-10-27 20:17 ` Davidlohr Bueso
2020-10-27 18:44 ` Peter Zijlstra
2020-10-27 18:50 ` Paolo Bonzini
2020-10-30 17:09 ` Waiman Long
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=20201027164950.1057601-2-bgardon@google.com \
--to=bgardon@google.com \
--cc=dave@stgolabs.net \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=pshier@google.com \
--cc=sean.j.christopherson@intel.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