Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755144AbbGOKDR (ORCPT ); Wed, 15 Jul 2015 06:03:17 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:45749 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750996AbbGOKDP (ORCPT ); Wed, 15 Jul 2015 06:03:15 -0400 Date: Wed, 15 Jul 2015 12:03:09 +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 v2 5/6] locking/pvqspinlock: Opportunistically defer kicking to unlock time Message-ID: <20150715100309.GJ2859@worktop.programming.kicks-ass.net> References: <1436926417-20256-1-git-send-email-Waiman.Long@hp.com> <1436926417-20256-6-git-send-email-Waiman.Long@hp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1436926417-20256-6-git-send-email-Waiman.Long@hp.com> User-Agent: Mutt/1.5.22.1 (2013-10-16) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2602 Lines: 73 On Tue, Jul 14, 2015 at 10:13:36PM -0400, Waiman Long wrote: > +static void pv_kick_node(struct qspinlock *lock, struct mcs_spinlock *node) > { > struct pv_node *pn = (struct pv_node *)node; > > + if (xchg(&pn->state, vcpu_running) == vcpu_running) > + return; > + > /* > + * Kicking the next node at lock time can actually be a bit faster > + * than doing it at unlock time because the critical section time > + * overlaps with the wakeup latency of the next node. However, if the > + * VM is too overcommmitted, it can happen that we need to kick the > + * CPU again at unlock time (double-kick). To avoid that and also to > + * fully utilize the kick-ahead functionality at unlock time, > + * the kicking will be deferred under either one of the following > + * 2 conditions: > * > + * 1) The VM guest has too few vCPUs that kick-ahead is not even > + * enabled. In this case, the chance of double-kick will be > + * higher. > + * 2) The node after the next one is also in the halted state. > * > + * In this case, the hashed flag is set to indicate that hashed > + * table has been filled and _Q_SLOW_VAL is set. > */ > - if (xchg(&pn->state, vcpu_running) == vcpu_halted) { > - pvstat_inc(pvstat_lock_kick); > - pv_kick(pn->cpu); > + if ((!pv_kick_ahead || pv_get_kick_node(pn, 1)) && > + (xchg(&pn->hashed, 1) == 0)) { > + struct __qspinlock *l = (void *)lock; > + > + /* > + * As this is the same vCPU that will check the _Q_SLOW_VAL > + * value and the hash table later on at unlock time, no atomic > + * instruction is needed. > + */ > + WRITE_ONCE(l->locked, _Q_SLOW_VAL); > + (void)pv_hash(lock, pn); > + return; > } > + > + /* > + * Kicking the vCPU even if it is not really halted is safe. > + */ > + pvstat_inc(pvstat_lock_kick); > + pv_kick(pn->cpu); > } > > /* > @@ -513,6 +545,13 @@ static void pv_wait_head(struct qspinlock *lock, struct mcs_spinlock *node) > cpu_relax(); > } > > + if (!lp && (xchg(&pn->hashed, 1) == 1)) > + /* > + * The hashed table & _Q_SLOW_VAL had been filled > + * by the lock holder. > + */ > + lp = (struct qspinlock **)-1; > + > if (!lp) { /* ONCE */ > lp = pv_hash(lock, pn); > /* *groan*, so you complained the previous version of this patch was too complex, but let me say I vastly preferred it to this one :/ -- 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/