mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Borislav Petkov <bp@alien8.de>
To: Shantanu Gupta <shans95g@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: xchg in fastpath for mutex unlock [mutex-xchg.h]
Date: Mon, 1 Oct 2012 23:45:57 +0200	[thread overview]
Message-ID: <20121001214557.GA19126@liondog.tnic> (raw)
In-Reply-To: <CAPDArR+9Kd+Rzgxj9FgQR0NCayZskXkq4bg3U-GRpCKFP5uC+Q@mail.gmail.com>

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.

      reply	other threads:[~2012-10-01 21:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-28 10:48 Shantanu Gupta
2012-10-01 21:45 ` Borislav Petkov [this message]

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=20121001214557.GA19126@liondog.tnic \
    --to=bp@alien8.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=shans95g@gmail.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®