[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20140618133656.GA4729@laptop.dumpdata.com>
Date: Wed, 18 Jun 2014 09:36:56 -0400
From: Konrad Rzeszutek Wilk <konrad.wilk@...cle.com>
To: Paolo Bonzini <pbonzini@...hat.com>
Cc: Peter Zijlstra <a.p.zijlstra@...llo.nl>, Waiman.Long@...com,
tglx@...utronix.de, mingo@...nel.org, linux-arch@...r.kernel.org,
linux-kernel@...r.kernel.org,
virtualization@...ts.linux-foundation.org,
xen-devel@...ts.xenproject.org, kvm@...r.kernel.org,
paolo.bonzini@...il.com, boris.ostrovsky@...cle.com,
paulmck@...ux.vnet.ibm.com, riel@...hat.com,
torvalds@...ux-foundation.org, raghavendra.kt@...ux.vnet.ibm.com,
david.vrabel@...rix.com, oleg@...hat.com, gleb@...hat.com,
scott.norton@...com, chegu_vinod@...com,
Peter Zijlstra <peterz@...radead.org>
Subject: Re: [PATCH 03/11] qspinlock: Add pending bit
On Wed, Jun 18, 2014 at 01:29:48PM +0200, Paolo Bonzini wrote:
> Il 17/06/2014 22:36, Konrad Rzeszutek Wilk ha scritto:
> >+ /* One more attempt - but if we fail mark it as pending. */
> >+ if (val == _Q_LOCKED_VAL) {
> >+ new = Q_LOCKED_VAL |_Q_PENDING_VAL;
> >+
> >+ old = atomic_cmpxchg(&lock->val, val, new);
> >+ if (old == _Q_LOCKED_VAL) /* YEEY! */
> >+ return;
> >+ val = old;
> >+ }
>
> Note that Peter's code is in a for(;;) loop:
>
>
> + for (;;) {
> + /*
> + * If we observe any contention; queue.
> + */
> + if (val & ~_Q_LOCKED_MASK)
> + goto queue;
> +
> + new = _Q_LOCKED_VAL;
> + if (val == new)
> + new |= _Q_PENDING_VAL;
> +
> + old = atomic_cmpxchg(&lock->val, val, new);
> + if (old == val)
> + break;
> +
> + val = old;
> + }
> +
> + /*
> + * we won the trylock
> + */
> + if (new == _Q_LOCKED_VAL)
> + return;
>
> So what you'd have is basically:
>
> /*
> * One more attempt if no one is already in queue. Perhaps
> * they have unlocked the spinlock already.
> */
> if (val == _Q_LOCKED_VAL && atomic_read(&lock->val) == 0) {
> old = atomic_cmpxchg(&lock->val, 0, _Q_LOCKED_VAL);
> if (old == 0) /* YEEY! */
> return;
> val = old;
> }
>
> But I agree with Waiman that this is unlikely to trigger often enough. It
> does have to be handled in the slowpath for correctness, but the most likely
> path is (0,0,1)->(0,1,1).
<nods>
>
> Paolo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists