From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752013AbbJMSXm (ORCPT ); Tue, 13 Oct 2015 14:23:42 -0400 Received: from casper.infradead.org ([85.118.1.10]:34248 "EHLO casper.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751742AbbJMSXl (ORCPT ); Tue, 13 Oct 2015 14:23:41 -0400 Date: Tue, 13 Oct 2015 20:23:38 +0200 From: Peter Zijlstra To: Waiman Long Cc: Ingo Molnar , Thomas Gleixner , "H. Peter Anvin" , x86@kernel.org, linux-kernel@vger.kernel.org, Scott J Norton , Douglas Hatch , Davidlohr Bueso Subject: Re: [PATCH v7 4/5] locking/pvqspinlock: Allow 1 lock stealing attempt Message-ID: <20151013182338.GW3816@twins.programming.kicks-ass.net> References: <1442955044-43895-1-git-send-email-Waiman.Long@hpe.com> <1442955044-43895-5-git-send-email-Waiman.Long@hpe.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1442955044-43895-5-git-send-email-Waiman.Long@hpe.com> User-Agent: Mutt/1.5.21 (2012-12-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 22, 2015 at 04:50:43PM -0400, Waiman Long wrote: > for (;; waitcnt++) { > + loop = SPIN_THRESHOLD; > + while (loop) { > + /* > + * Spin until the lock is free > + */ > + for (; loop && READ_ONCE(l->locked); loop--) > + cpu_relax(); > + /* > + * Seeing the lock is free, this queue head vCPU is > + * the rightful next owner of the lock. However, the > + * lock may have just been stolen by another task which > + * has entered the slowpath. So we need to use atomic > + * operation to make sure that we really get the lock. > + * Otherwise, we have to wait again. > + */ > + if (cmpxchg(&l->locked, 0, _Q_LOCKED_VAL) == 0) > + goto gotlock; > } for (loop = SPIN_THRESHOLD; loop; --loop) { if (!READ_ONCE(l->locked) && cmpxchg(&l->locked, 0, _Q_LOCKED_VA) == 0) goto gotlock; cpu_relax(); }