Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752392AbcDAQrs (ORCPT ); Fri, 1 Apr 2016 12:47:48 -0400 Received: from foss.arm.com ([217.140.101.70]:34577 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751744AbcDAQrr (ORCPT ); Fri, 1 Apr 2016 12:47:47 -0400 Date: Fri, 1 Apr 2016 17:47:43 +0100 From: Will Deacon To: Peter Zijlstra Cc: Waiman Long , Ingo Molnar , linux-kernel@vger.kernel.org, Scott J Norton , Douglas Hatch Subject: Re: [PATCH] locking/qrwlock: Allow multiple spinning readers Message-ID: <20160401164742.GD3991@arm.com> References: <1458444079-59601-1-git-send-email-Waiman.Long@hpe.com> <20160329202050.GN3408@twins.programming.kicks-ass.net> <56FDA0D6.4090904@hpe.com> <20160401103143.GJ3448@twins.programming.kicks-ass.net> <20160401104119.GA3604@arm.com> <20160401105457.GO3430@twins.programming.kicks-ass.net> <20160401114303.GA24771@twins.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160401114303.GA24771@twins.programming.kicks-ass.net> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2095 Lines: 61 On Fri, Apr 01, 2016 at 01:43:03PM +0200, Peter Zijlstra wrote: > > Ah, yes, I forgot about that. Lemme go find that discussions and see > > what I can do there. > > Completely untested.. > > --- > include/linux/compiler.h | 20 ++++++++++++++------ > kernel/locking/qspinlock.c | 12 ++++++------ > kernel/sched/core.c | 9 +++++---- > kernel/sched/sched.h | 2 +- > kernel/smp.c | 2 +- > 5 files changed, 27 insertions(+), 18 deletions(-) > > diff --git a/include/linux/compiler.h b/include/linux/compiler.h > index b5ff9881bef8..c64f5897664f 100644 > --- a/include/linux/compiler.h > +++ b/include/linux/compiler.h > @@ -305,7 +305,8 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s > }) > > /** > - * smp_cond_acquire() - Spin wait for cond with ACQUIRE ordering > + * smp_cond_load_acquire() - Spin wait for cond with ACQUIRE ordering > + * @ptr: pointer to the variable wait on > * @cond: boolean expression to wait for > * > * Equivalent to using smp_load_acquire() on the condition variable but employs > @@ -315,11 +316,18 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s > * provides LOAD->LOAD order, together they provide LOAD->{LOAD,STORE} order, > * aka. ACQUIRE. > */ > -#define smp_cond_acquire(cond) do { \ > - while (!(cond)) \ > - cpu_relax(); \ > - smp_rmb(); /* ctrl + rmb := acquire */ \ > -} while (0) > +#define smp_cond_load_acquire(ptr, cond_expr) ({ \ > + typeof(ptr) __PTR = (ptr); \ > + typeof(*ptr) VAL; \ It's a bit grim having a magic variable name, but I have no better suggestion. > + for (;;) { \ > + VAL = READ_ONCE(*__PTR); \ > + if (cond_expr) \ > + break; \ > + cpu_relax(); \ > + } \ > + smp_rmb(); /* ctrl + rmb := acquire */ \ > + VAL; \ > +}) Can you stick some #ifndef guards around this, please? That way I can do my ldxr/wfe-based version for ARM that makes the spinning tolerable. Also, wouldn't this be better suited to barrier.h? Otherwise, I really like this idea. Thanks! Will