* xchg in fastpath for mutex unlock [mutex-xchg.h]
@ 2012-09-28 10:48 Shantanu Gupta
2012-10-01 21:45 ` Borislav Petkov
0 siblings, 1 reply; 2+ messages in thread
From: Shantanu Gupta @ 2012-09-28 10:48 UTC (permalink / raw)
To: linux-kernel
Hello,
I am currently studying mutex(es) and was referring to linux sources
for it's implementation. However I noticed one shortcoming, in
"/include/asm-generic/mutex-xchg.h" of the master branch inside
__mutex_fastpath_trylock, Why doesn't the kernel use a cmpxchg instead
of dirtying the value with xchg ?
(The only thing that came to my mind was that x86_x64 implementation
mentioned that all x86_x64 cpu(s) have cmpxchg leading me to
assumption that certain archs can have xchg but not cmpxchg, so is it
this way just to work with architectures without a cmpxchg but with
xchg ?)
Thanks,
Rick
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: xchg in fastpath for mutex unlock [mutex-xchg.h]
2012-09-28 10:48 xchg in fastpath for mutex unlock [mutex-xchg.h] Shantanu Gupta
@ 2012-10-01 21:45 ` Borislav Petkov
0 siblings, 0 replies; 2+ messages in thread
From: Borislav Petkov @ 2012-10-01 21:45 UTC (permalink / raw)
To: Shantanu Gupta; +Cc: linux-kernel
On Fri, Sep 28, 2012 at 04:18:41PM +0530, Shantanu Gupta wrote:
> Hello,
>
> I am currently studying mutex(es) and was referring to linux sources
> for it's implementation. However I noticed one shortcoming, in
> "/include/asm-generic/mutex-xchg.h" of the master branch inside
> __mutex_fastpath_trylock, Why doesn't the kernel use a cmpxchg instead
> of dirtying the value with xchg ?
>
> (The only thing that came to my mind was that x86_x64 implementation
> mentioned that all x86_x64 cpu(s) have cmpxchg leading me to
> assumption that certain archs can have xchg but not cmpxchg, so is it
> this way just to work with architectures without a cmpxchg but with
> xchg ?)
Yes.
Btw, 'git annotate' helps with such questions-to-self sometimes. Because
if you do
$ git annotate include/asm-generic/mutex-xchg.h
you can find the following patch adding __mutex_fastpath_trylock:
commit 620a6fd185c084aa617c411f711533f01ea673c9
Author: Ingo Molnar <mingo@elte.hu>
Date: Mon Jan 9 15:59:17 2006 -0800
[PATCH] mutex subsystem, add asm-generic/mutex-[dec|xchg|null].h implementations
Add three (generic) mutex fastpath implementations.
The mutex-xchg.h implementation is atomic_xchg() based, and should
work fine on every architecture.
The mutex-dec.h implementation is atomic_dec_return() based - this
one too should work on every architecture, but might not perform the
most optimally on architectures that have no atomic-dec/inc instructions.
The mutex-null.h implementation forces all calls into the slowpath. This
is used for mutex debugging, but it can also be used on platforms that do
not want (or need) a fastpath at all.
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Arjan van de Ven <arjan@infradead.org>
HTH.
--
Regards/Gruss,
Boris.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-10-01 21:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-28 10:48 xchg in fastpath for mutex unlock [mutex-xchg.h] Shantanu Gupta
2012-10-01 21:45 ` Borislav Petkov
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®