From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.3 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_PASS, USER_AGENT_MUTT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5DB2DC169C4 for ; Thu, 31 Jan 2019 08:51:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3CC8B218D2 for ; Thu, 31 Jan 2019 08:51:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="hwh0zWRU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725895AbfAaIvf (ORCPT ); Thu, 31 Jan 2019 03:51:35 -0500 Received: from merlin.infradead.org ([205.233.59.134]:58636 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725961AbfAaIve (ORCPT ); Thu, 31 Jan 2019 03:51:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=/FoziSL54VDx8QeyMnyohGk8gHpcVh9SYBJkkQJ7vYY=; b=hwh0zWRU2mHlESptYz7hcceoL k6JYk0hE+WfMI6szDOkYG4k8bJJUPbhwHP/nkLmxjeqKcNap8nEBVJQQsg5gtw7qC7ByOBt72w6sz otcst2HweAL0Fflz7g9aojs7qFSvPBV2I8OvYF0pbde4dx33AMUoMbS3G/IdgbD0+jU9WHoSC0Sb/ F4scVHgWXmfoTTDunx2oEId3WPrWyzq+8pxOzZEvm79lTmLEtMm/RJ9YCXfAjvJQf9CRdRgLnaQ2d cr7fApn8Nq2dcg+QYL4q2+HVyXr1GaOPgoNjNHTEPlIori5MVXsv0eBzhPcb361rC76dMFK+I+3LM 32VWsnh4w==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gp84B-000362-Mj; Thu, 31 Jan 2019 08:51:23 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 3F65020276ABC; Thu, 31 Jan 2019 09:51:22 +0100 (CET) Date: Thu, 31 Jan 2019 09:51:22 +0100 From: Peter Zijlstra To: Alexei Starovoitov Cc: Alexei Starovoitov , davem@davemloft.net, daniel@iogearbox.net, jannh@google.com, paulmck@linux.ibm.com, will.deacon@arm.com, mingo@redhat.com, netdev@vger.kernel.org, kernel-team@fb.com, Nicholas Piggin Subject: Re: [PATCH v5 bpf-next 1/9] bpf: introduce bpf_spin_lock Message-ID: <20190131085122.GE3103@hirez.programming.kicks-ass.net> References: <20190128025010.342241-1-ast@kernel.org> <20190128025010.342241-2-ast@kernel.org> <20190130210529.GI2278@hirez.programming.kicks-ass.net> <20190130213418.gxbyfbmuiohn7vj4@ast-mbp.dhcp.thefacebook.com> <20190131084952.GG2296@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190131084952.GG2296@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Thu, Jan 31, 2019 at 09:49:52AM +0100, Peter Zijlstra wrote: > On Wed, Jan 30, 2019 at 01:34:19PM -0800, Alexei Starovoitov wrote: > > On Wed, Jan 30, 2019 at 10:05:29PM +0100, Peter Zijlstra wrote: > > > +static inline void __bpf_spin_lock(struct bpf_spin_lock *lock) > > > +{ > > > + atomic_t *l = (void *)lock; > > > + do { > > > + atomic_cond_read_relaxed(l, !VAL); > > > > wow. that's quite a macro magic. > > Yeah, C sucks for not having lambdas, this was the best we could come up > with. > > This basically allows architectures to optimize the > wait-for-variable-to-change thing. Currently only ARM64 does that, I > have a horrible horrible patch that makes x86 use MONITOR/MWAIT for > this, and I suppose POWER should use it but doesn't. Nick, do you guys want something like this? --- diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h index fbe8df433019..111984c5670d 100644 --- a/arch/powerpc/include/asm/barrier.h +++ b/arch/powerpc/include/asm/barrier.h @@ -99,6 +99,20 @@ do { \ #define barrier_nospec() #endif /* CONFIG_PPC_BARRIER_NOSPEC */ +#define smp_cond_load_relaxed(ptr, cond_expr) ({ \ + typeof(ptr) __PTR = (ptr); \ + typeof(*ptr) VAL = READ_ONCE(*__PTR); \ + if (unlikely(!(cond_expr))) { \ + spin_begin(); \ + do { \ + spin_cpu_relax(); \ + VAL = READ_ONCE(*__PTR); \ + } while (!(cond_expr)); \ + spin_end(); \ + } \ + VAL; \ +}) + #include #endif /* _ASM_POWERPC_BARRIER_H */