From: Nicolas Pitre <nico@cam.org>
To: Linus Torvalds <torvalds@osdl.org>
Cc: Russell King <rmk+lkml@arm.linux.org.uk>,
Nick Piggin <nickpiggin@yahoo.com.au>,
Ingo Molnar <mingo@elte.hu>,
David Woodhouse <dwmw2@infradead.org>,
Zwane Mwaikambo <zwane@arm.linux.org.uk>,
lkml <linux-kernel@vger.kernel.org>,
Andrew Morton <akpm@osdl.org>,
Arjan van de Ven <arjanv@infradead.org>,
Steven Rostedt <rostedt@goodmis.org>,
Alan Cox <alan@lxorguk.ukuu.org.uk>,
Christoph Hellwig <hch@infradead.org>, Andi Kleen <ak@suse.de>,
David Howells <dhowells@redhat.com>,
Alexander Viro <viro@parcelfarce.linux.theplanet.co.uk>,
Oleg Nesterov <oleg@tv-sign.ru>, Paul Jackson <pj@sgi.com>
Subject: Re: [patch 04/15] Generic Mutex Subsystem, add-atomic-call-func-x86_64.patch
Date: Tue, 20 Dec 2005 16:18:27 -0500 (EST) [thread overview]
Message-ID: <Pine.LNX.4.64.0512201533120.26663@localhost.localdomain> (raw)
In-Reply-To: <Pine.LNX.4.64.0512201202200.4827@g5.osdl.org>
On Tue, 20 Dec 2005, Linus Torvalds wrote:
>
>
> On Tue, 20 Dec 2005, Russell King wrote:
> >
> > Also, Nico has an alternative idea for mutexes which does not
> > involve decrementing or incrementing - it's an atomic swap.
> > That works out at about the same cycle count on non-Intel ARM
> > CPUs as the present semaphore path. I'm willing to bet that
> > it will be faster than the present semaphore path on Intel ARM
> > CPUs.
>
> Don't be so sure, especially not in the future.
I think we agree. But we still live in the present.
> An atomic "swap" operation is, from a CPU design standpoint, fundamentally
> more expensive that a "load + store".
>
> Now, most ARM architectures don't notice this, because they are all
> in-order, and not SMP-aware anyway. No suble memory ordering, no nothing.
> Which is the only case when "swap" basically becomes a cheap "load+store".
Indeed.
> What I'm trying to say is that a plain "load + store" is almost always
> going to be the best option in the long run.
>
> It's also almost certainly always the best option for UP + non-preempt,
> for both present and future CPU's. The reason is simply that a
> microarchitecture will _always_ be optimized for that case, since it's
> pretty much by definition the common situation.
Which is why each architecture must always have the option of providing
its own fast path implementation according to a number of factors that
cannot be made into a generic layer. But this is the same issue whether
we talk about semaphores or mutexes.
> Is preemption even the common case on ARM? I'd assume not. Why are people
> so interested in the preemption case?
Because embedded people want it. ARM is also about the only
architecture besides x86 that currently sees most of the RT work for the
same reason. And yes preemption does make a difference.
> IOW, why don't you just do
>
> ldr lr,[%0]
> subs lr, lr, %1
> str lr,[%0]
> blmi failure
>
> as the _base_ timings, since that should be the common case. That's the
> drop-dead fastest UP case.
The above is 5 cycles. About the same as the preemption-safe swp-based
mutex implementation on non-Intel ARM. It is broken wrt interrupts when
the swp is not. It doesn't work with preemption while the swp
implementation is potentially smaller with cse and it works in all
cases.
I mean...... what is it with mutexes that you dislike to the point of
bending backward that far, and even after seeing the numbers, with such
a semaphore implementation that _I_ even wouldn't trust people to use
correctly? Yes we should use complete() from interrupt handlers but I
can bet you that a lot of people are still using up() there, and with
the current up() implementation it just _works_ at least on ARM.
> (Btw, inlining _any_ of these except perhaps the above trivial case, is
> probably wrong. None of the ARM chips tend to have caches all that big, I
> bet).
On XScale you should add 2 cycles to branch to the out of line code and
2 other cycles to branch back.
The ARM mutex implementation can save that and have an extremely small
inlined footprint already.
Again what do you dislike so much about mutexes? It must not have much
to do with technical issues at this point. ;-)
Nicolas
next prev parent reply other threads:[~2005-12-20 21:18 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-12-19 1:35 Ingo Molnar
2005-12-19 17:49 ` Zwane Mwaikambo
2005-12-19 20:58 ` David Woodhouse
2005-12-20 4:31 ` Ingo Molnar
2005-12-20 6:30 ` Nicolas Pitre
2005-12-20 8:12 ` Nick Piggin
2005-12-20 14:10 ` Nicolas Pitre
2005-12-20 14:12 ` Nick Piggin
2005-12-20 14:35 ` Nicolas Pitre
2005-12-20 15:05 ` Nick Piggin
2005-12-20 16:35 ` Nicolas Pitre
2005-12-20 19:20 ` Russell King
2005-12-20 19:32 ` Arjan van de Ven
2005-12-20 19:37 ` Russell King
2005-12-20 19:59 ` Nicolas Pitre
2005-12-20 19:43 ` Steven Rostedt
2005-12-20 19:57 ` Russell King
2005-12-20 20:35 ` Horst von Brand
2005-12-20 19:55 ` Nicolas Pitre
2005-12-20 18:27 ` Linus Torvalds
2005-12-20 19:34 ` Russell King
2005-12-20 20:10 ` Linus Torvalds
2005-12-20 21:18 ` Nicolas Pitre [this message]
2005-12-20 22:04 ` Linus Torvalds
2005-12-20 22:19 ` Steven Rostedt
2005-12-20 22:43 ` Nicolas Pitre
2005-12-21 6:00 ` Ingo Molnar
2005-12-21 2:12 ` Nick Piggin
2005-12-20 19:49 ` Nicolas Pitre
2005-12-20 18:25 ` Linus Torvalds
2005-12-21 6:20 ` Ingo Molnar
2005-12-21 4:16 ` Nicolas Pitre
2005-12-21 6:26 ` Ingo Molnar
2005-12-20 4:29 ` Ingo Molnar
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=Pine.LNX.4.64.0512201533120.26663@localhost.localdomain \
--to=nico@cam.org \
--cc=ak@suse.de \
--cc=akpm@osdl.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=arjanv@infradead.org \
--cc=dhowells@redhat.com \
--cc=dwmw2@infradead.org \
--cc=hch@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=nickpiggin@yahoo.com.au \
--cc=oleg@tv-sign.ru \
--cc=pj@sgi.com \
--cc=rmk+lkml@arm.linux.org.uk \
--cc=rostedt@goodmis.org \
--cc=torvalds@osdl.org \
--cc=viro@parcelfarce.linux.theplanet.co.uk \
--cc=zwane@arm.linux.org.uk \
/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®