Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752064AbbGMMbn (ORCPT ); Mon, 13 Jul 2015 08:31:43 -0400 Received: from casper.infradead.org ([85.118.1.10]:53721 "EHLO casper.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751994AbbGMMbm (ORCPT ); Mon, 13 Jul 2015 08:31:42 -0400 Date: Mon, 13 Jul 2015 14:31:36 +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 Subject: Re: [PATCH 1/7] locking/pvqspinlock: Only kick CPU at unlock time Message-ID: <20150713123136.GX18673@twins.programming.kicks-ass.net> References: <1436647018-49734-1-git-send-email-Waiman.Long@hp.com> <1436647018-49734-2-git-send-email-Waiman.Long@hp.com> <20150713120202.GG3644@twins.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150713120202.GG3644@twins.programming.kicks-ass.net> 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 Content-Length: 1681 Lines: 46 On Mon, Jul 13, 2015 at 02:02:02PM +0200, Peter Zijlstra wrote: > On Sat, Jul 11, 2015 at 04:36:52PM -0400, Waiman Long wrote: > > @@ -181,9 +187,9 @@ static void pv_wait_node(struct mcs_spinlock *node) > > pv_wait(&pn->state, vcpu_halted); > > > > /* > > - * Reset the vCPU state to avoid unncessary CPU kicking > > + * Reset the state except when vcpu_hashed is set. > > */ > > - WRITE_ONCE(pn->state, vcpu_running); > > + cmpxchg(&pn->state, vcpu_halted, vcpu_running); > > Why? Suppose we did get advanced into the hashed state, and then get a > (spurious) wakeup, this means we'll observe our ->locked == 1 condition > and fall out of pv_wait_node(). > > We'll then enter pv_wait_head(), which with your modification: > > > @@ -229,19 +244,42 @@ static void pv_wait_head(struct qspinlock *lock, struct mcs_spinlock *node) > > { > > struct pv_node *pn = (struct pv_node *)node; > > struct __qspinlock *l = (void *)lock; > > - struct qspinlock **lp = NULL; > > + struct qspinlock **lp; > > int loop; > > > > + /* > > + * Initialize lp to a non-NULL value if it has already been in the > > + * pv_hashed state so that pv_hash() won't be called again. > > + */ > > + lp = (READ_ONCE(pn->state) == vcpu_hashed) ? (struct qspinlock **)1 > > + : NULL; Because that ^ > > for (;;) { > > + WRITE_ONCE(pn->state, vcpu_running); > > Will instantly and unconditionally write vcpu_running. > > -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/