All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Andev <debiandev@gmail.com>
Cc: Pranith Kumar <pranith@gatech.edu>, LKML <linux-kernel@vger.kernel.org>
Subject: Re: [RFC PATCH 1/1] remove redundant compare, cmpxchg already does it
Date: Thu, 5 Jun 2014 09:22:48 +0200	[thread overview]
Message-ID: <20140605072248.GE3213@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <CAJUuVQ4VioKuVuCTXr3BcfRpYs+9+5bx9m2WLO7Swsnni0tUAw@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1438 bytes --]

On Wed, Jun 04, 2014 at 04:56:50PM -0400, Andev wrote:
> On Wed, Jun 4, 2014 at 4:38 PM, Pranith Kumar <pranith@gatech.edu> wrote:
> > remove a redundant comparision
> >
> > Signed-off-by: Pranith Kumar <bobby.prani@gmail.com>
> > ---
> >  kernel/locking/rwsem-xadd.c | 3 +--
> >  1 file changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/kernel/locking/rwsem-xadd.c b/kernel/locking/rwsem-xadd.c
> > index 1f99664b..6f8bd3c 100644
> > --- a/kernel/locking/rwsem-xadd.c
> > +++ b/kernel/locking/rwsem-xadd.c
> > @@ -249,8 +249,7 @@ static inline bool rwsem_try_write_lock(long count, struct rw_semaphore *sem)
> >  {
> >      if (!(count & RWSEM_ACTIVE_MASK)) {
> >          /* try acquiring the write lock */
> > -        if (sem->count == RWSEM_WAITING_BIAS &&
> > -            cmpxchg(&sem->count, RWSEM_WAITING_BIAS,
> > +        if (cmpxchg(&sem->count, RWSEM_WAITING_BIAS,
> >                  RWSEM_ACTIVE_WRITE_BIAS) == RWSEM_WAITING_BIAS) {
> 
> This was mainly done to avoid the cost of a cmpxchg in case where they
> are not equal. Not sure if it really makes a difference though.

It does, a cache hot cmpxchg instruction is 24 cycles (as is pretty much
any other LOCKed ins, as measured on my WSM-EP), not to mention that
cmpxchg is a RMW so it needs to grab the cacheline in exclusive mode.

A read, which allows the cacheline to remain in shared, and non LOCKed
ops are way faster.

[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

  reply	other threads:[~2014-06-05  7:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-04 20:38 [RFC PATCH 1/1] remove redundant compare, cmpxchg already does it Pranith Kumar
2014-06-04 20:56 ` Andev
2014-06-05  7:22   ` Peter Zijlstra [this message]
2014-06-05 17:54     ` Davidlohr Bueso
2014-06-05 18:08       ` Davidlohr Bueso
2014-06-06  7:01         ` Peter Zijlstra
2014-06-06  3:09     ` Pranith Kumar

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=20140605072248.GE3213@twins.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=debiandev@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pranith@gatech.edu \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.