Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp1295429pxb; Sun, 11 Apr 2021 14:41:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVcCUwNilFR1jqHovTGSPn7VRTKglBCFkB3Td0DzO5NSc9QXDGL62RgGkF0i0yL25skigl X-Received: by 2002:a17:907:7690:: with SMTP id jv16mr2427303ejc.529.1618177300307; Sun, 11 Apr 2021 14:41:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618177300; cv=none; d=google.com; s=arc-20160816; b=Ms0v6Fn4uV/Bhq9ss59jKGqnx/oHjFylgMpn6m48RBxRVSxD9k2OcDpiA7T5Wcz90Y rVYPXou1dmEvjIn2jIhBFs9QMX8Z5gWWi8IFFRARGItk1AHO2hl9H7E5amSAiJiKXbxK BQdLPD0QfV67I9mudt84OQ9bxlhXtkw/TOwHvCHOvvvL6hqCqahY5T8NI8OZDSH3aWgY y6WtAjzFv6ZsnoeOJ0HR3PRtyfmyW3oo5gvzbhiv0uO9aKdHfF1RRH3lp0tg87UyF6ZH lHyqChLrUtNZRtA7U2FePt1GQuuZnbkrDrUd/6omRbZ+2xDWNOQzki8OR/lomEwFJQTu +EyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:to:from:cc:in-reply-to:subject:date:dkim-signature; bh=6xOdm+Zk4/ZZ/vvuWQaRhSpOzrzYPOE+3wRzoAL0QmI=; b=jIwI6c912Km2EMwN0Uiq7oAdqLAf6wj5Chdsj45C2puV5w7uDcZ+1Ys8F3dxm4yVoX Yus3pSsaBiHSxmuLlhi37a+Y+k6s3j1PVNTGWcrcfbyUsjqAmdPA+2Apq8YBt+XjUNcj 9PZiL7LL6SHIkn5AxhCPn9T0LDD+cqzME6uvAug8VGrPKFful+u+X7jnZSK+kCtMDNhV bJUJ77ZKEs8Jf937fYFls11Y0b++vPoZvtlT6tjXbIu0wpHRK7X7wjeniu9gtyir26B6 j2gFJkHJ1XlsGVGdc2lN+4KuZVlH4wIqHYxTBGg6uXtoifcJ+ETaVTpA1tr+lYYxGG7i wJMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dabbelt-com.20150623.gappssmtp.com header.s=20150623 header.b="v/tHpZPS"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b17si6871316ejp.314.2021.04.11.14.41.17; Sun, 11 Apr 2021 14:41:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@dabbelt-com.20150623.gappssmtp.com header.s=20150623 header.b="v/tHpZPS"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235569AbhDKVL6 (ORCPT + 99 others); Sun, 11 Apr 2021 17:11:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235005AbhDKVL5 (ORCPT ); Sun, 11 Apr 2021 17:11:57 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01312C061574 for ; Sun, 11 Apr 2021 14:11:41 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id d124so7839867pfa.13 for ; Sun, 11 Apr 2021 14:11:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dabbelt-com.20150623.gappssmtp.com; s=20150623; h=date:subject:in-reply-to:cc:from:to:message-id:mime-version :content-transfer-encoding; bh=6xOdm+Zk4/ZZ/vvuWQaRhSpOzrzYPOE+3wRzoAL0QmI=; b=v/tHpZPS+OJvJQ4G+VIJMcUyV5j85u/apZQ0K7QaKLveC1QbRSZ+L6qYrvc8Bqsfpl HOYzLz3xv1iJBYs8XqHGCBQrMC0HPXNBSQWoNi7lIYGzwn+6OZAtXbFTSReUPQ92Xn1D w1LVzXtRqt+1pdYMx/qniqq1IyT+YwCgT6GhcCu4urKSDSzaIUANKYGZNDk4gX7UGTWY ftIbP8qJPm8neCnzIRDBSF8Y2E+Eawi5rCeT6r1sqaU6osptDjJD+9kpRjTWd0MC7alT pF6C+JOhNWBmPJHQV0c5nPjCtxGSjSLLsQVJlxgQesNUHL3ZowCUyTVzCOkyuWNdu7JT T1UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:subject:in-reply-to:cc:from:to:message-id :mime-version:content-transfer-encoding; bh=6xOdm+Zk4/ZZ/vvuWQaRhSpOzrzYPOE+3wRzoAL0QmI=; b=PtpQUZ21C2IgnoIY4DJaDdVtk+4aAxKSG6AEy/2SbDl11Fu4aT5QU9Z3TUE37BZPY+ PD5bj4H1nzkXPvfOuYvdTAC0Tujh26HYIeLEqSaLbDKZWQTbCW4+CudurYzf7Ev077UB yGj7uLtnRQtV2LPhytGM4ihklnZywan32NOnAi+SRxN5QuITC1dVJoLxEd1TihS2Q0Qi iZqslf+h9Jq7wnEbVv+HuEhLMZqVyinQGbXs3QNLDIqCvWaLeNvcpKKBAJ6uUoA29XqF XCaebr4wn1PToOAZIAcfZGk7/SazTBqR6aDpPa6nho+CW+7A7MUDsdrpIy5ag82ZNwHE M8PA== X-Gm-Message-State: AOAM532T6ghaaNkucOXt/K+d/Onifm+Mdb8TyCOIf6AhZ2N56noR0e9Y ai3GHUMRE0hsGFVjVRSP5OL5GAyQ6+clJg== X-Received: by 2002:a63:f008:: with SMTP id k8mr23555000pgh.15.1618175500173; Sun, 11 Apr 2021 14:11:40 -0700 (PDT) Received: from localhost (76-210-143-223.lightspeed.sntcca.sbcglobal.net. [76.210.143.223]) by smtp.gmail.com with ESMTPSA id t5sm2582384pjy.8.2021.04.11.14.11.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Apr 2021 14:11:39 -0700 (PDT) Date: Sun, 11 Apr 2021 14:11:39 -0700 (PDT) X-Google-Original-Date: Sun, 11 Apr 2021 14:11:37 PDT (-0700) Subject: Re: [PATCH] riscv: locks: introduce ticket-based spinlock implementation In-Reply-To: CC: peterz@infradead.org, guoren@kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, guoren@linux.alibaba.com, catalin.marinas@arm.com, will.deacon@arm.com, Arnd Bergmann From: Palmer Dabbelt To: anup@brainfault.org Message-ID: Mime-Version: 1.0 (MHng) Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 24 Mar 2021 05:53:51 PDT (-0700), anup@brainfault.org wrote: > On Wed, Mar 24, 2021 at 6:08 PM Peter Zijlstra wrote: >> >> On Wed, Mar 24, 2021 at 05:58:58PM +0530, Anup Patel wrote: >> > On Wed, Mar 24, 2021 at 3:45 PM wrote: >> > > >> > > From: Guo Ren >> > > >> > > This patch introduces a ticket lock implementation for riscv, along the >> > > same lines as the implementation for arch/arm & arch/csky. >> > > >> > > Signed-off-by: Guo Ren >> > > Cc: Catalin Marinas >> > > Cc: Will Deacon >> > > Cc: Peter Zijlstra >> > > Cc: Palmer Dabbelt >> > > Cc: Anup Patel >> > > Cc: Arnd Bergmann >> > > --- >> > > arch/riscv/Kconfig | 1 + >> > > arch/riscv/include/asm/Kbuild | 1 + >> > > arch/riscv/include/asm/spinlock.h | 158 ++++++++++++-------------------- >> > > arch/riscv/include/asm/spinlock_types.h | 19 ++-- >> > >> > NACK from myside. >> > >> > Linux ARM64 has moved away from ticket spinlock to qspinlock. >> > >> > We should directly go for qspinlock. >> >> I think it is a sensible intermediate step, even if you want to go >> qspinlock. Ticket locks are more or less trivial and get you fairness >> and all that goodness without the mind bending complexity of qspinlock. >> >> Once you have the ticket lock implementation solid (and qrwlock) and >> everything, *then* start to carefully look at qspinlock. > > I do understand qspinlock are relatively complex but the best thing > about qspinlock is it tries to ensure each CPU spins on it's own location. > > Instead of adding ticket spinlock now and later replacing it with qspinlock, > it is better to straight away explore qspinlock hence my NACK. > >> >> Now, arguably arm64 did the heavy lifting of making qspinlock good on >> weak architectures, but if you want to do it right, you still have to >> analyze the whole thing for your own architecture. > > Most of the RISC-V implementations are weak memory ordering so it > makes more sense to explore qspinlock first. I know I'm somewhat late to the party here. I talked with Will (and to a lesser extent Peter) about this a week or two ago and it seems the best way to go here is to start with ticket locks. They're simpler, and in Arm land they performed better until we got to the larger systems. Given that we don't have any high performance implementations of the RISC-V memory model (and likely won't any time soon) it's hard to reason about the performance of anything like this, but at a bare minimum having fair locks is a pretty big positive and ticket locks should have very little overhead while providing fairness. IMO the decision between ticket and queueing locks is really more of a property of the hardware/workload than the ISA, though there are of course some pretty deep ISA dependencies than can make one saner than the other. It seems best to me to just allow users to pick their own flavor of locks, and at least PPC is already doing that. I threw together a quick asm-generic ticket lock that can be selected at compile time, but I want to spend some more time playing with the other architectures before sending anything out.