From: Nicolas Pitre <nico@fluxnic.net>
To: Will Deacon <will.deacon@arm.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Ingo Molnar <mingo@elte.hu>, Thomas Gleixner <tglx@linutronix.de>,
Chris Mason <chris.mason@fusionio.com>,
Arnd Bergmann <arnd@arndb.de>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>
Subject: Re: RFC: mutex: hung tasks on SMP platforms with asm-generic/mutex-xchg.h
Date: Thu, 09 Aug 2012 12:57:33 -0400 (EDT) [thread overview]
Message-ID: <alpine.LFD.2.02.1208091243080.5231@xanadu.home> (raw)
In-Reply-To: <alpine.LFD.2.02.1208091201380.5231@xanadu.home>
On Thu, 9 Aug 2012, Nicolas Pitre wrote:
> On Thu, 9 Aug 2012, Will Deacon wrote:
>
> > I think we could actually fix this entirely in mutex-xchg.h by doing
> > something in fastpath_lock similar to what we do for trylock:
> >
> >
> > diff --git a/include/asm-generic/mutex-xchg.h b/include/asm-generic/mutex-xchg.h
> > index 580a6d3..c082e99 100644
> > --- a/include/asm-generic/mutex-xchg.h
> > +++ b/include/asm-generic/mutex-xchg.h
> > @@ -25,8 +25,19 @@
> > static inline void
> > __mutex_fastpath_lock(atomic_t *count, void (*fail_fn)(atomic_t *))
> > {
> > - if (unlikely(atomic_xchg(count, 0) != 1))
> > - fail_fn(count);
> > + int prev = atomic_xchg(count, 0);
> > +
> > + if (unlikely(prev != 1)) {
> > + if (prev < 0)
> > + /*
> > + * The lock was contended, so we need to restore
> > + * its original state to ensure that any waiting
> > + * tasks are woken up by the unlock slow path.
> > + */
> > + prev = atomic_xchg(count, prev);
> > + if (prev != 1)
> > + fail_fn(count);
> > + }
> > }
> >
> > What do you reckon?
>
> Yes, that looks fine. I'd remove that if (prev < 0) entirely though.
> We'll just swap a 0 for a 0 if the count wasn't < 0, or a 0 for a 1 if
> the mutex just got unlocked which is also fine. This is especially
> beneficial when a native xchg processor instruction is used.
In fact, this suggestion isn't entirely correct either. The inner xchg
in this case should be -1 and not 'count'. If 'count' is 0 and the
mutex becomes contended in the small window between the two xchg's then
the contention mark would be lost again.
In other words, I think this should look like this:
diff --git a/include/asm-generic/mutex-xchg.h b/include/asm-generic/mutex-xchg.h
index 580a6d35c7..44a66c99c8 100644
--- a/include/asm-generic/mutex-xchg.h
+++ b/include/asm-generic/mutex-xchg.h
@@ -25,8 +25,11 @@
static inline void
__mutex_fastpath_lock(atomic_t *count, void (*fail_fn)(atomic_t *))
{
- if (unlikely(atomic_xchg(count, 0) != 1))
- fail_fn(count);
+ if (unlikely(atomic_xchg(count, 0) != 1)) {
+ /* Mark lock contention explicitly */
+ if (likely(atomic_xchg(count, -1) != 1))
+ fail_fn(count);
+ }
}
/**
Nicolas
next prev parent reply other threads:[~2012-08-09 16:57 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-07 11:56 Will Deacon
2012-08-07 13:48 ` Peter Zijlstra
2012-08-07 14:04 ` Will Deacon
2012-08-07 17:14 ` Nicolas Pitre
2012-08-07 17:33 ` Will Deacon
2012-08-07 17:38 ` Will Deacon
2012-08-07 18:28 ` Nicolas Pitre
2012-08-09 5:12 ` Nicolas Pitre
2012-08-09 14:49 ` Will Deacon
2012-08-09 16:17 ` Nicolas Pitre
2012-08-09 16:57 ` Nicolas Pitre [this message]
2012-08-09 17:50 ` Will Deacon
2012-08-09 18:09 ` Nicolas Pitre
2012-08-09 18:17 ` Will Deacon
2012-08-09 20:05 ` Nicolas Pitre
2012-08-13 8:15 ` Peter Zijlstra
2012-08-13 9:13 ` Will Deacon
2012-08-13 13:35 ` Nicolas Pitre
2012-08-13 14:05 ` Peter Zijlstra
2012-08-13 14:11 ` Will Deacon
2012-08-13 14: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=alpine.LFD.2.02.1208091243080.5231@xanadu.home \
--to=nico@fluxnic.net \
--cc=a.p.zijlstra@chello.nl \
--cc=arnd@arndb.de \
--cc=chris.mason@fusionio.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=tglx@linutronix.de \
--cc=will.deacon@arm.com \
/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®