From: tip-bot for Oleg Nesterov <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: peterz@infradead.org, tglx@linutronix.de,
linux-kernel@vger.kernel.org, hpa@zytor.com, amir73il@gmail.com,
tytso@mit.edu, willy@infradead.org,
torvalds@linux-foundation.org, longman@redhat.com,
dave@stgolabs.net, jack@suse.cz, oleg@redhat.com,
mingo@kernel.org
Subject: [tip:locking/core] locking/rwsem: Simplify the is-owner-spinnable checks
Date: Fri, 25 May 2018 02:51:16 -0700 [thread overview]
Message-ID: <tip-1b22fc609cecd1b16c4a015e1a6b3c9717484e3a@git.kernel.org> (raw)
In-Reply-To: <20180518165534.GA22348@redhat.com>
Commit-ID: 1b22fc609cecd1b16c4a015e1a6b3c9717484e3a
Gitweb: https://git.kernel.org/tip/1b22fc609cecd1b16c4a015e1a6b3c9717484e3a
Author: Oleg Nesterov <oleg@redhat.com>
AuthorDate: Fri, 18 May 2018 18:55:35 +0200
Committer: Ingo Molnar <mingo@kernel.org>
CommitDate: Fri, 25 May 2018 08:11:47 +0200
locking/rwsem: Simplify the is-owner-spinnable checks
Add the trivial owner_on_cpu() helper for rwsem_can_spin_on_owner() and
rwsem_spin_on_owner(), it also allows to make rwsem_can_spin_on_owner()
a bit more clear.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Waiman Long <longman@redhat.com>
Cc: Amir Goldstein <amir73il@gmail.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Jan Kara <jack@suse.cz>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Theodore Y. Ts'o <tytso@mit.edu>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/20180518165534.GA22348@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
kernel/locking/rwsem-xadd.c | 25 +++++++++++++------------
1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/kernel/locking/rwsem-xadd.c b/kernel/locking/rwsem-xadd.c
index a90336779375..3064c50e181e 100644
--- a/kernel/locking/rwsem-xadd.c
+++ b/kernel/locking/rwsem-xadd.c
@@ -347,6 +347,15 @@ static inline bool rwsem_try_write_lock_unqueued(struct rw_semaphore *sem)
}
}
+static inline bool owner_on_cpu(struct task_struct *owner)
+{
+ /*
+ * As lock holder preemption issue, we both skip spinning if
+ * task is not on cpu or its cpu is preempted
+ */
+ return owner->on_cpu && !vcpu_is_preempted(task_cpu(owner));
+}
+
static inline bool rwsem_can_spin_on_owner(struct rw_semaphore *sem)
{
struct task_struct *owner;
@@ -359,17 +368,10 @@ static inline bool rwsem_can_spin_on_owner(struct rw_semaphore *sem)
rcu_read_lock();
owner = READ_ONCE(sem->owner);
- if (!owner || !is_rwsem_owner_spinnable(owner)) {
- ret = !owner; /* !owner is spinnable */
- goto done;
+ if (owner) {
+ ret = is_rwsem_owner_spinnable(owner) &&
+ owner_on_cpu(owner);
}
-
- /*
- * As lock holder preemption issue, we both skip spinning if task is not
- * on cpu or its cpu is preempted
- */
- ret = owner->on_cpu && !vcpu_is_preempted(task_cpu(owner));
-done:
rcu_read_unlock();
return ret;
}
@@ -398,8 +400,7 @@ static noinline bool rwsem_spin_on_owner(struct rw_semaphore *sem)
* abort spinning when need_resched or owner is not running or
* owner's cpu is preempted.
*/
- if (!owner->on_cpu || need_resched() ||
- vcpu_is_preempted(task_cpu(owner))) {
+ if (need_resched() || !owner_on_cpu(owner)) {
rcu_read_unlock();
return false;
}
next prev parent reply other threads:[~2018-05-25 9:51 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-15 21:49 [PATCH v4 0/2] locking/rwsem: Fix DEBUG_RWSEM warning from thaw_super() Waiman Long
2018-05-15 21:49 ` [PATCH v4 1/2] locking/rwsem: Add a new RWSEM_ANONYMOUSLY_OWNED flag Waiman Long
2018-05-16 10:34 ` [tip:locking/urgent] " tip-bot for Waiman Long
2018-05-16 10:48 ` [PATCH v4 1/2] " Oleg Nesterov
2018-05-16 11:59 ` Peter Zijlstra
2018-05-16 13:11 ` Waiman Long
2018-05-16 15:27 ` Oleg Nesterov
2018-05-16 12:19 ` Matthew Wilcox
2018-05-18 7:02 ` Ingo Molnar
2018-05-18 8:41 ` Oleg Nesterov
2018-05-18 9:40 ` Ingo Molnar
2018-05-18 16:55 ` [PATCH] locking/rwsem: simplify the is-owner-spinnable checks Oleg Nesterov
2018-05-18 17:00 ` Waiman Long
2018-05-25 9:51 ` tip-bot for Oleg Nesterov [this message]
2018-05-15 21:49 ` [PATCH v4 2/2] locking/percpu-rwsem: Annotate rwsem ownership transfer by setting RWSEM_OWNER_UNKNOWN Waiman Long
2018-05-16 5:37 ` Amir Goldstein
2018-05-16 13:17 ` Waiman Long
2018-05-16 10:35 ` [tip:locking/urgent] " tip-bot for 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=tip-1b22fc609cecd1b16c4a015e1a6b3c9717484e3a@git.kernel.org \
--to=tipbot@zytor.com \
--cc=amir73il@gmail.com \
--cc=dave@stgolabs.net \
--cc=hpa@zytor.com \
--cc=jack@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mingo@kernel.org \
--cc=oleg@redhat.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=tytso@mit.edu \
--cc=willy@infradead.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).