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=-2.3 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,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 B2933C282C2 for ; Fri, 25 Jan 2019 10:00:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 80C99218B0 for ; Fri, 25 Jan 2019 10:00:23 +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="Isy0UTGd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728017AbfAYKAW (ORCPT ); Fri, 25 Jan 2019 05:00:22 -0500 Received: from merlin.infradead.org ([205.233.59.134]:39850 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726761AbfAYKAV (ORCPT ); Fri, 25 Jan 2019 05:00:21 -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=xLWtiRK6HWBdJtzwGQTLtkaf47wxYHKRnUWUvc8e0Mc=; b=Isy0UTGdpRkaBaDuA7MoVyuDW WRprMA20hT6LMoKChXnjLeSUAqjuqEPJgHuMltWr9US4MPR8AnEsww5hb7ITsUtS2LCwn0uCvtkpn 6s1LpTfojs5Q3c+Sbi730Laekc1xMNXogs5IAr6d+QLCazjUJpYlSo2QAKLLoNWIpT/VQ2K4oxX/W kQgoT1OPa/9Yntq8ZMxDsido6kJR/wMBQrentvckA1GWA516G3L6/kIjld2gN24DYKumBvmThsu2O wS0wXI2wLABaRDOaZdWE/MmdGhbRfMloYrz9HOxiFRHa60xvcBYAYJV6ZWNH/XBfGV4QzeuKqy+k7 FQGYwCc5A==; 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 1gmyHG-0003ew-O1; Fri, 25 Jan 2019 09:59:59 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id CC971201EC16E; Fri, 25 Jan 2019 10:59:55 +0100 (CET) Date: Fri, 25 Jan 2019 10:59:55 +0100 From: Peter Zijlstra To: Alexei Starovoitov Cc: Alexei Starovoitov , davem@davemloft.net, daniel@iogearbox.net, jakub.kicinski@netronome.com, netdev@vger.kernel.org, kernel-team@fb.com, mingo@redhat.com, will.deacon@arm.com, Paul McKenney , jannh@google.com Subject: Re: [PATCH v4 bpf-next 1/9] bpf: introduce bpf_spin_lock Message-ID: <20190125095955.GA4500@hirez.programming.kicks-ass.net> References: <20190124041403.2100609-1-ast@kernel.org> <20190124041403.2100609-2-ast@kernel.org> <20190124180109.GA27771@hirez.programming.kicks-ass.net> <20190124235857.xyb5xx2ufr6x5mbt@ast-mbp.dhcp.thefacebook.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190124235857.xyb5xx2ufr6x5mbt@ast-mbp.dhcp.thefacebook.com> 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 24, 2019 at 03:58:59PM -0800, Alexei Starovoitov wrote: > On Thu, Jan 24, 2019 at 07:01:09PM +0100, Peter Zijlstra wrote: > > > - on architectures that don't support queued_spin_lock trivial lock is used. > > > Note that arch_spin_lock cannot be used, since not all archs agree that > > > zero == unlocked and sizeof(arch_spinlock_t) != sizeof(__u32). > > > > I really don't much like direct usage of qspinlock; esp. not as a > > surprise. > > > > Why does it matter if 0 means unlocked; that's what > > __ARCH_SPIN_LOCK_UNLOCKED is for. > > > > I get the sizeof(__u32) thing, but why not key off of that? > > what do you mean by 'key off of that' ? > to use arch_spinlock_t instead of qspinlock ? > That was my first attempt, but then I painfully found that > its size on parisc is 16 bytes and we're not going to penalize bpf > to waste that much space because of single architecture. > sizeof(arch_spinlock_t) can be 1 byte too (on sparc). PowerPC has 8 bytes for some config options IIRC. > That would fit in __u32, but I figured it's cleaner to use qspinlock > on all archs that support it and dumb_spin_lock on archs that dont. > > Another option is use to arch_spinlock_t when its sizeof==4 That's what I meant. > and use dumb_spin_lock otherwise. > It's doable, but imo still less clean than using qspinlock > due to zero init. Since zero init is a lot less map work > that zero inits all elements already. > > If arch_spinlock_t is used than at map init time we would need to > walk all elements and do __ARCH_SPIN_LOCK_UNLOCKED assignment > (and maps can have millions of elements). > Not horrible, but 100% waste of cycles for x86/arm64 where qspinlock > is used. Such waste can be workaround further by doing ugly > #idef __ARCH_SPIN_LOCK_UNLOCKED == 0 -> don't do init loop. > And then add another #ifdef for archs with sizeof(arch_spinlock_t)!=4 > to keep zero init for all map types that support bpf_spin_lock > via dumb_spin_lock. > Clearly at that point we're getting into ugliness everywhere. > Hence I've used qspinlock directly. OK; I see.. but do these locks really have enough contention to run into trouble with the simple test-and-set lock? [ I tried to propose a simple ticket lock, but then realized the virt archs (s390,powerpc,etc.) would hate that and deleted everything again ] Argh, what a mess..