Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1884670pxp; Mon, 21 Mar 2022 07:03:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzYbrlOdggAOMUvkcDA4o6zXtRaBzAMLkxfz8gyQjJzzYrPFAsHitSUSm2uVt1BDn364Noi X-Received: by 2002:a17:906:3ec7:b0:6d6:e52b:b with SMTP id d7-20020a1709063ec700b006d6e52b000bmr21166981ejj.521.1647871433157; Mon, 21 Mar 2022 07:03:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647871433; cv=none; d=google.com; s=arc-20160816; b=KWkyNUgiKKOAqVIimDigtM+RswfrtLzJtS1fAXJ1TKF0/10D9mWk9Np6cBYdHurHLc SV8lUrHMGUUat2njQBdZZ1kLNYrdU5ZYEwX4kTpE+mORETzbzVKtYYfakJj54aGxo1h9 u/W/iIn9GYhYFcyYUK2efmkqkvX+79E0DkLkj25e3xa2PvhCd33NXW3I89QjOtf8YIXe k2lkiYon7+mPbTuT2Hs1gpKmAoeJkNYIsdQ1mrIWVwxW0a2jwqbpOQWCbiX/zszLWBYe 83jEyvbsR9+Y0lvlIIMn0yuqz1j2sD4g74scaMrI5LrWDtb6WOoFeKalLkkPrThTsjKQ 1aQg== 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=udZZwCkDvht+/ZkTVpsoov30eC/vSqk3+YzF/CtgcQo=; b=PX+sj8qRx36lJeCHMm8VlUIv6usg+0b44PQ6p0yeUx4KbxTvXdrtfQ6LwzdYJhm0Sk nfdTFE/z31m9hgJtjCDaTWhXZy3U67FspvUBVFj45ku5yDYxopdZqmJESQlmcn3LWxGj qS0FHm0sBs2LOwlCFHAederx+e/NMJZffwQHtg/AizZ2dMAYLBsKBcNVAtsISOyksReT tnsLPw0RxlCmUQD0jg5pWR6442XVWS2Z+fHY0j8DAfj+jVFZPFJn8CLkADiOrqtW7Und DGlgNbTd6/5jdl7nHv9X9aw650MEMvK+/0G3TrCe5QiW0lzHneIZ3UdQXuLKgH1djZDP MCiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=sK5EqUes; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v3-20020a1709067d8300b006df76385f42si7157953ejo.994.2022.03.21.07.03.23; Mon, 21 Mar 2022 07:03:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=sK5EqUes; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241386AbiCRWtl (ORCPT + 99 others); Fri, 18 Mar 2022 18:49:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241382AbiCRWti (ORCPT ); Fri, 18 Mar 2022 18:49:38 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A79621777D6 for ; Fri, 18 Mar 2022 15:48:18 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id w4so8182348ply.13 for ; Fri, 18 Mar 2022 15:48:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=date:subject:in-reply-to:cc:from:to:message-id:mime-version :content-transfer-encoding; bh=udZZwCkDvht+/ZkTVpsoov30eC/vSqk3+YzF/CtgcQo=; b=sK5EqUes8d1oJOXfxUzYGp9+QruHGINR3qWOR7SRTDQu8Fd0WzF8gkI5j8Lh7PNNmu TrE+w1H9yumVErYj1LEY4HqILtkJ5DBxebo9yUvw1u6aO8pKI19uRBS9Z9phinJeUh7V Pb0N7TFf83eDyx29IgXm5P3Z32Kd5kZ4ieG65+IS5c9eA5H+x0zaeRLY23ymQOQnvChX 6IB0n2M78pBJAE4jfc9poKP4Z0TbIFiZjRy7dWo9Q8NAyixN277LrHE2bUpla0MA6GsG 1O7uzt8ZuwBFP201/weLwvxeDKuZlLiym/B76RKDph/A55LySFhhKJ44FHFAkFp+eYw5 t+rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:subject:in-reply-to:cc:from:to:message-id :mime-version:content-transfer-encoding; bh=udZZwCkDvht+/ZkTVpsoov30eC/vSqk3+YzF/CtgcQo=; b=pu8Uw+h52W4bRHC+MLKEBlA0dj+dezjmyahGFMa0gV8XyMhxFrRCPfSkk70/IwVwq0 yMzJBBEaBmzAomI5QacMtlhWYa44k+kvA8SGMi1OYPJ439DPczCYPQJ2sHMBw9pBV09Y 2k0HaKB9bjhzGu6l82AJXNPWe6UllY7g5gKeSKxSepRQJb7+kyPmQmz4Bc+o7zcDCRb2 4/6ZYd02XpchGjt9tnlIkbq7v/jU8xtkrHn6BxP4DcZP0UVPzyNk8vL2c3/DB9vS91GM NMceAYLDWj9hjwFoLcdGO6BqlWGV6rgYeGdlGVZ/boOUrff+Mru2rCtk804QfH6LRfVR uFWA== X-Gm-Message-State: AOAM530ajqzUPbEZGrkq3+IkRTPFm7Pas08HG1nXmhWEmg9sI8saFrF6 hqMseFiZBRQNI4BHzLVypl39MOMeLSpYBA== X-Received: by 2002:a17:902:ce08:b0:153:8d90:a109 with SMTP id k8-20020a170902ce0800b001538d90a109mr1744437plg.157.1647643698169; Fri, 18 Mar 2022 15:48:18 -0700 (PDT) Received: from localhost ([12.3.194.138]) by smtp.gmail.com with ESMTPSA id w8-20020a63a748000000b0038117e18f02sm8301624pgo.29.2022.03.18.15.48.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Mar 2022 15:48:17 -0700 (PDT) Date: Fri, 18 Mar 2022 15:48:17 -0700 (PDT) X-Google-Original-Date: Fri, 18 Mar 2022 15:48:15 PDT (-0700) Subject: Re: [PATCH] csky: Move to generic ticket-spinlock In-Reply-To: <20220318083421.2062259-1-guoren@kernel.org> CC: linux-csky@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, guoren@linux.alibaba.com From: Palmer Dabbelt To: guoren@kernel.org Message-ID: Mime-Version: 1.0 (MHng) Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 18 Mar 2022 01:34:21 PDT (-0700), guoren@kernel.org wrote: > From: Guo Ren > > There is no benefit from custom implementation for ticket-spinlock, > so move to generic ticket-spinlock for easy maintenance. > > Signed-off-by: Guo Ren > Cc: Palmer Dabbelt Thanks, one less port to look at ;) Looks like there were a few comments on the v1, and I wasn't going to target this at the upcoming merge window anyway because I wanted to give the various RISC-V vendors time to test stuff. LMK if you want me to add this to the others, but I was planning on posting a stable tag either way so no big deal on my end. > --- > arch/csky/include/asm/Kbuild | 2 + > arch/csky/include/asm/spinlock.h | 82 +------------------------- > arch/csky/include/asm/spinlock_types.h | 20 +------ > 3 files changed, 4 insertions(+), 100 deletions(-) > > diff --git a/arch/csky/include/asm/Kbuild b/arch/csky/include/asm/Kbuild > index 904a18a818be..d94434288c31 100644 > --- a/arch/csky/include/asm/Kbuild > +++ b/arch/csky/include/asm/Kbuild > @@ -3,6 +3,8 @@ generic-y += asm-offsets.h > generic-y += extable.h > generic-y += gpio.h > generic-y += kvm_para.h > +generic-y += ticket-lock.h > +generic-y += ticket-lock-types.h > generic-y += qrwlock.h > generic-y += user.h > generic-y += vmlinux.lds.h > diff --git a/arch/csky/include/asm/spinlock.h b/arch/csky/include/asm/spinlock.h > index 69f5aa249c5f..8bc179ba0d8d 100644 > --- a/arch/csky/include/asm/spinlock.h > +++ b/arch/csky/include/asm/spinlock.h > @@ -3,87 +3,7 @@ > #ifndef __ASM_CSKY_SPINLOCK_H > #define __ASM_CSKY_SPINLOCK_H > > -#include > -#include > - > -/* > - * Ticket-based spin-locking. > - */ > -static inline void arch_spin_lock(arch_spinlock_t *lock) > -{ > - arch_spinlock_t lockval; > - u32 ticket_next = 1 << TICKET_NEXT; > - u32 *p = &lock->lock; > - u32 tmp; > - > - asm volatile ( > - "1: ldex.w %0, (%2) \n" > - " mov %1, %0 \n" > - " add %0, %3 \n" > - " stex.w %0, (%2) \n" > - " bez %0, 1b \n" > - : "=&r" (tmp), "=&r" (lockval) > - : "r"(p), "r"(ticket_next) > - : "cc"); > - > - while (lockval.tickets.next != lockval.tickets.owner) > - lockval.tickets.owner = READ_ONCE(lock->tickets.owner); > - > - smp_mb(); > -} > - > -static inline int arch_spin_trylock(arch_spinlock_t *lock) > -{ > - u32 tmp, contended, res; > - u32 ticket_next = 1 << TICKET_NEXT; > - u32 *p = &lock->lock; > - > - do { > - asm volatile ( > - " ldex.w %0, (%3) \n" > - " movi %2, 1 \n" > - " rotli %1, %0, 16 \n" > - " cmpne %1, %0 \n" > - " bt 1f \n" > - " movi %2, 0 \n" > - " add %0, %0, %4 \n" > - " stex.w %0, (%3) \n" > - "1: \n" > - : "=&r" (res), "=&r" (tmp), "=&r" (contended) > - : "r"(p), "r"(ticket_next) > - : "cc"); > - } while (!res); > - > - if (!contended) > - smp_mb(); > - > - return !contended; > -} > - > -static inline void arch_spin_unlock(arch_spinlock_t *lock) > -{ > - smp_mb(); > - WRITE_ONCE(lock->tickets.owner, lock->tickets.owner + 1); > -} > - > -static inline int arch_spin_value_unlocked(arch_spinlock_t lock) > -{ > - return lock.tickets.owner == lock.tickets.next; > -} > - > -static inline int arch_spin_is_locked(arch_spinlock_t *lock) > -{ > - return !arch_spin_value_unlocked(READ_ONCE(*lock)); > -} > - > -static inline int arch_spin_is_contended(arch_spinlock_t *lock) > -{ > - struct __raw_tickets tickets = READ_ONCE(lock->tickets); > - > - return (tickets.next - tickets.owner) > 1; > -} > -#define arch_spin_is_contended arch_spin_is_contended > - > +#include > #include > > #endif /* __ASM_CSKY_SPINLOCK_H */ > diff --git a/arch/csky/include/asm/spinlock_types.h b/arch/csky/include/asm/spinlock_types.h > index db87a12c3827..0bb7f6022a3b 100644 > --- a/arch/csky/include/asm/spinlock_types.h > +++ b/arch/csky/include/asm/spinlock_types.h > @@ -3,25 +3,7 @@ > #ifndef __ASM_CSKY_SPINLOCK_TYPES_H > #define __ASM_CSKY_SPINLOCK_TYPES_H > > -#ifndef __LINUX_SPINLOCK_TYPES_RAW_H > -# error "please don't include this file directly" > -#endif > - > -#define TICKET_NEXT 16 > - > -typedef struct { > - union { > - u32 lock; > - struct __raw_tickets { > - /* little endian */ > - u16 owner; > - u16 next; > - } tickets; > - }; > -} arch_spinlock_t; > - > -#define __ARCH_SPIN_LOCK_UNLOCKED { { 0 } } > - > +#include > #include > > #endif /* __ASM_CSKY_SPINLOCK_TYPES_H */