From: Peter Zijlstra <peterz@infradead.org>
To: Jason Low <jason.low2@hpe.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Ding Tianhong <dingtianhong@huawei.com>,
Thomas Gleixner <tglx@linutronix.de>,
Will Deacon <Will.Deacon@arm.com>, Ingo Molnar <mingo@redhat.com>,
imre.deak@intel.com, linux-kernel@vger.kernel.org,
Waiman Long <Waiman.Long@hpe.com>,
Davidlohr Bueso <dave@stgolabs.net>,
Tim Chen <tim.c.chen@linux.intel.com>,
terry.rudd@hpe.com, "Paul E. McKenney" <paulmck@us.ibm.com>,
jason.low2@hp.com
Subject: Re: [PATCH v4] locking/mutex: Prevent lock starvation when spinning is disabled
Date: Fri, 19 Aug 2016 14:13:28 +0200 [thread overview]
Message-ID: <20160819121328.GD10153@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <1471579876.4991.51.camel@j-VirtualBox>
On Thu, Aug 18, 2016 at 09:11:16PM -0700, Jason Low wrote:
> 3. Only clear yield_to_waiter if the thread is the top waiter and not if it
> is a non-top waiter that received a signal.
Ah, and that is an equivalent condition to the singular one I use to
test if we need to set pending, since if we just add waiter and its the
top waiter, it must be the only waiter.
How about something like so on top?
--- a/kernel/locking/mutex.c
+++ b/kernel/locking/mutex.c
@@ -74,7 +74,6 @@ EXPORT_SYMBOL(__mutex_init);
*/
__visible void __sched __mutex_lock_slowpath(atomic_t *lock_count);
-
static inline bool need_yield_to_waiter(struct mutex *lock);
/**
@@ -457,6 +456,12 @@ static bool mutex_optimistic_spin(struct
}
#endif
+static inline bool
+__mutex_waiter_is_head(struct mutex *lock, struct mutex_waiter *waiter)
+{
+ return list_first_entry(&lock->wait_list, struct mutex_waiter, list) == waiter;
+}
+
#if !defined(CONFIG_MUTEX_SPIN_ON_OWNER) && defined(CONFIG_SMP)
#define MUTEX_WAKEUP_THRESHOLD 16
@@ -471,7 +476,7 @@ static inline void clear_yield_to_waiter
struct mutex_waiter *waiter)
{
/* Only clear yield_to_waiter if we are the top waiter. */
- if (lock->wait_list.next == &waiter->list && lock->yield_to_waiter)
+ if (lock->yield_to_waiter && __mutex_waiter_is_head(lock, waiter))
lock->yield_to_waiter = false;
}
@@ -648,7 +653,7 @@ __mutex_lock_common(struct mutex *lock,
* If this is the first waiter, mark the lock as having pending
* waiters, if we happen to acquire it while doing so, yay!
*/
- if (list_is_singular(&lock->wait_list) &&
+ if (__mutex_waiter_is_head(lock, &waiter) &&
__mutex_trylock_pending(lock))
goto remove_waiter;
next prev parent reply other threads:[~2016-08-19 12:14 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-19 0:39 [PATCH v4] locking/mutex: Prevent lock starvation when spinning is disabled Jason Low
2016-08-19 4:11 ` Jason Low
2016-08-19 12:13 ` Peter Zijlstra [this message]
2016-08-19 16:57 ` Waiman Long
2016-08-19 19:33 ` Peter Zijlstra
2016-08-19 19:45 ` Linus Torvalds
2016-08-23 12:45 ` 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=20160819121328.GD10153@twins.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=Waiman.Long@hpe.com \
--cc=Will.Deacon@arm.com \
--cc=dave@stgolabs.net \
--cc=dingtianhong@huawei.com \
--cc=imre.deak@intel.com \
--cc=jason.low2@hp.com \
--cc=jason.low2@hpe.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=paulmck@us.ibm.com \
--cc=terry.rudd@hpe.com \
--cc=tglx@linutronix.de \
--cc=tim.c.chen@linux.intel.com \
--cc=torvalds@linux-foundation.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