From: Nicolas Pitre <nico@cam.org>
To: Ingo Molnar <mingo@elte.hu>
Cc: Linus Torvalds <torvalds@osdl.org>,
lkml <linux-kernel@vger.kernel.org>,
Andrew Morton <akpm@osdl.org>,
Arjan van de Ven <arjanv@infradead.org>,
Jes Sorensen <jes@trained-monkey.org>,
Zwane Mwaikambo <zwane@arm.linux.org.uk>,
Oleg Nesterov <oleg@tv-sign.ru>,
David Howells <dhowells@redhat.com>,
Alan Cox <alan@lxorguk.ukuu.org.uk>,
Benjamin LaHaise <bcrl@kvack.org>,
Steven Rostedt <rostedt@goodmis.org>,
Christoph Hellwig <hch@infradead.org>, Andi Kleen <ak@suse.de>,
Russell King <rmk+lkml@arm.linux.org.uk>
Subject: Re: [patch 3/3] mutex subsystem: move the core to the new atomic helpers
Date: Thu, 22 Dec 2005 01:50:56 -0500 (EST) [thread overview]
Message-ID: <Pine.LNX.4.64.0512220023060.26663@localhost.localdomain> (raw)
In-Reply-To: <20051221231218.GA6747@elte.hu>
On Thu, 22 Dec 2005, Ingo Molnar wrote:
>
> * Nicolas Pitre <nico@cam.org> wrote:
>
> > This patch moves the core mutex code over to the atomic helpers from
> > previous patch. There is no change for i386 and x86_64, except for
> > the forced unlock state that is now done outside the spinlock (doing
> > so doesn't matter since another CPU could have locked the mutex right
> > away even if it was unlocked inside the spinlock). This however
> > brings great improvements on ARM for example.
>
> i'm wondering how much difference it makes on ARM - could you show us
> the before and after disassembly of the fastpath, to see the
> improvement?
The only way to do an atomic decrement on 99% of all ARM processors in
the field requires disabling interrupts. So for instance:
void __mutex_lock(struct mutex *lock)
{
if (atomic_dec_return(&lock->count) < 0)
__mutex_lock_failed(lock);
}
Would produce:
__mutex_lock_atomic:
mrs r1, cpsr @ local_irq_save
orr r3, r1, #128
msr cpsr_c, r3
ldr r3, [r0, #0]
sub r3, r3, #1
str r3, [r0, #0]
msr cpsr_c, r1 @ local_irq_restore
cmp r3, #0
movge pc, lr
b __mutex_lock_failed
I can measure 23 cycles on an XScale processor for the first 8
instructions which corresponds to the "if (atomic_dec_return(v) < 0)".
It was suggested that a preempt_disable()/preempt_enable() would be
sufficient and probably faster than the IRQ disable... which turned not
to be true for non-XScale ARM variants. It would take 14 instructions
on all variants, and on XScale it needs 20 cycles.
Now with my patch applied, it looks like this:
void __mutex_lock(struct mutex *lock)
{
if (atomic_xchg(&lock->count, 0) != 1)
__mutex_lock_failed(lock);
}
with the following assembly:
__mutex_lock_atomic:
mov r3, #0
swp r2, r3, [r0]
cmp r2, #1
moveq pc, lr
b __mutex_lock_failed
The equivalent of the first 8 instructions in the first example is now
down to 3. And when gcc can cse the constant 0 (which is not
possible with the first example) then it would be only 2 instructions,
which is really nice to inline. And the above takes only 8 cycles on an
XScale instead of 20-23 cycles.
> your patches look OK to me, only one small detail sticks out: i'd
> suggest to rename the atomic_*_contended macros to be arch_mutex_*_...,
> i dont think any other code can make use of it.
OK.
> Also, it would be nice
> to see the actual ARM patches as well, which make use of the new
> infrastructure.
Well, with the generic functions based on atomic_xchg() the generated
code is pretty good actually. I don't think I could pack it more with a
special handler. Well for ARM version 6 I have a kunning idea though...
maybe for tomorrow.
> could you resend them against my latest queue that i just posted? I'll
> look at integrating them tomorrow.
Yes, please find them in following emails.
Nicolas
next prev parent reply other threads:[~2005-12-22 6:51 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-12-21 15:54 [patch 0/8] mutex subsystem, ANNOUNCE Ingo Molnar
2005-12-21 16:04 ` Arjan van de Ven
2005-12-21 18:07 ` Jes Sorensen
2005-12-22 2:36 ` Nick Piggin
2005-12-22 2:57 ` Nick Piggin
2005-12-22 7:19 ` Ingo Molnar
2005-12-22 7:56 ` Nick Piggin
2005-12-22 8:00 ` Arjan van de Ven
2005-12-22 8:10 ` Nick Piggin
2005-12-22 8:21 ` Arjan van de Ven
2005-12-22 8:32 ` Nick Piggin
2005-12-22 8:24 ` Ingo Molnar
2005-12-22 8:37 ` Nick Piggin
2005-12-21 22:43 ` Nicolas Pitre
2005-12-21 22:43 ` [patch 1/3] mutex subsystem: fix additions to the ARM atomic.h Nicolas Pitre
2005-12-21 22:44 ` [patch 2/3] mutex subsystem: add new atomic primitives Nicolas Pitre
2005-12-21 22:44 ` [patch 3/3] mutex subsystem: move the core to the new atomic helpers Nicolas Pitre
2005-12-21 23:12 ` Ingo Molnar
2005-12-22 1:16 ` Matt Mackall
2005-12-22 6:50 ` Nicolas Pitre [this message]
2005-12-22 6:51 ` [patch 2/5] mutex subsystem: add architecture specific mutex primitives Nicolas Pitre
2005-12-22 7:44 ` Nick Piggin
2005-12-22 8:03 ` Nick Piggin
2005-12-22 6:52 ` [patch 1/5] mutex subsystem: fix asm-arm/atomic.h Nicolas Pitre
2005-12-22 6:53 ` [patch 3/5] mutex subsystem: move the core to the new atomic helpers Nicolas Pitre
2005-12-22 6:53 ` [patch 4/5] mutex subsystem: allow architecture defined fast path for mutex_lock_interruptible Nicolas Pitre
2005-12-22 6:53 ` [patch 5/5] mutex subsystem: allow for the fast path to be inlined Nicolas Pitre
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.0512220023060.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=bcrl@kvack.org \
--cc=dhowells@redhat.com \
--cc=hch@infradead.org \
--cc=jes@trained-monkey.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=oleg@tv-sign.ru \
--cc=rmk+lkml@arm.linux.org.uk \
--cc=rostedt@goodmis.org \
--cc=torvalds@osdl.org \
--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®