Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp973010pxp; Wed, 16 Mar 2022 23:06:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyWFVMcNkOXlOzbu5W0QSoAMisR2B+op7qutdppetp/4vxfBtfYAgakEqm9dT8fS6KI6zf/ X-Received: by 2002:a17:90b:3a92:b0:1c6:64a5:a403 with SMTP id om18-20020a17090b3a9200b001c664a5a403mr5690534pjb.89.1647497206417; Wed, 16 Mar 2022 23:06:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647497206; cv=none; d=google.com; s=arc-20160816; b=IhQO2+wsfUzBNHOIbFqM+tEV455Yjwvv+GORCwTyQHRp7crAuzy4qcAouygMWHEAGw IfMZefTBiSuBLIohjrtgKeMzHZceDewFaY6S+eFrgGjCXzV5UXId15o8pGFRPnIv/py1 BRBZ/VWIr3wVD8Pbyvury++ENcuUgVcEfy/HvqJ66GBPA1GlNlXEHdfE1ylZAoUtENpW skCk3cKSLKx6g83rcbtUzigof4bVKx7wOL85eJt3yWcviYSXRPAvc5MFoRfeRpy6qzVP vGiEtayBhMm40GggWezivWohZF0r1ULyp8zi2hztf+hrWLTSUDaFJ44Q3s5v1vkFIR6m lVLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:from:cc:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject :dkim-signature; bh=llt+unTQxxB47mMK9cTVf/sVk7YwdP8ahVPZ8vUzo+E=; b=mtk59Ujs2jKN1fcpue+gHV29zLfdX3evDOSjTw4I9cwkWbscWkloeiIvWETR3O3+kz y5J/dLchsVbDhdf8O2+uBdtcNsL5iYArkbYEGTqLsXNYaxE/A281sMQASTONgX947pQd h3isjp7fjLlbI5NDkXFUXhU4o7BLDkBkJE2h5+TJ3MYT/+Dz+4DVPpi2PaNloIaBfA35 ABUKtIpxFOeHa15HwK6JEBO+2AniA7JhCuqCWTWkrg6qXuExSvKxfVjO9z3ifhqX5+Tr Y39UQ2t6E2DsNCWYpPwE59Yl22YOZH0L+6Am5ZOT7+C88USwnHEx8W+EvLZRmcLqPj0O 0NOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=P13QgI0z; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id w28-20020a63af1c000000b003816043eef8si1300986pge.237.2022.03.16.23.06.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 23:06:46 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=P13QgI0z; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 337E828D2AD; Wed, 16 Mar 2022 22:13:17 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347545AbiCPXaD (ORCPT + 99 others); Wed, 16 Mar 2022 19:30:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347074AbiCPX3t (ORCPT ); Wed, 16 Mar 2022 19:29:49 -0400 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4EC0B167EC for ; Wed, 16 Mar 2022 16:28:31 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id e3so3443987pjm.5 for ; Wed, 16 Mar 2022 16:28:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding:cc:from:to; bh=llt+unTQxxB47mMK9cTVf/sVk7YwdP8ahVPZ8vUzo+E=; b=P13QgI0zd+4RAOt3pbwZknViRr2CVhiVAFIRqM5bOGjAu9nzvjSnZusFhYRC5h9qSQ 9JCxra+cscVH+cq1tVm8CjiuMJlxW877K2j6AlCHNuh0DRBNi9EE4AcotfiNoC3XOOLK dhnYjAvGq4qBYfG/ws5BM4JI/1zMJoKWHl+gPx8IkFDWC/CuJ+vSOxvmg3M8IpV/BOKi Oz6nK2qVkXNZ02AyIkvsE3D3PHdimNMIXmdl8ruKlmv4JHoGQeGhFIjnxn/Mq7G4QX+y 2JDewQpoUe01b9wf6IjFRTdrHwJVTBH6ES8hoo446YGPwdfpUHyka6ajuquwNdtxfM3P F7kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:cc:from:to; bh=llt+unTQxxB47mMK9cTVf/sVk7YwdP8ahVPZ8vUzo+E=; b=6Bq+TyJWQqDevq4YeeVQngyKLFR1vym7WE8s78CkDSorK0Xetj4wC0MWuQanm8OD2z E4W46WAOvTEqK5zZE/IMYcworSJp9Mfgztw7717COb+j/+Tgm1GV5Eizv8b1Hq0iNwPb EJ3DrbhvZhKO2qlnD+UV5fpu2pXXvroy2AMBJjrETQtNK+k4sX4DN6v2zU5MYr1WdNHd oYyDYNmbxJ2KD6i4Aht9kexDQnXxEuHdPeGdQH8oV571xAWNp8xlZa9cQCRXpgEZX759 5BnejUHErvGalY0TeFf9XAP7cYtbDufDvB9mA9OyfBaXIsmWT90AGZCfi3y8EZiCN4lR T+1Q== X-Gm-Message-State: AOAM532IQZbJqoSqelUV9bXG55Oy9jZFxmgxbomVsWOPQhrD3wlmt0dI zwdZHSf4pXT/qhALN02pVHa3Dg== X-Received: by 2002:a17:903:11c9:b0:151:9521:d5c7 with SMTP id q9-20020a17090311c900b001519521d5c7mr1923340plh.73.1647473310711; Wed, 16 Mar 2022 16:28:30 -0700 (PDT) Received: from localhost ([12.3.194.138]) by smtp.gmail.com with ESMTPSA id o5-20020a056a0015c500b004f7988f16c3sm4696034pfu.30.2022.03.16.16.28.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 16:28:30 -0700 (PDT) Subject: [PATCH 5/5] RISC-V: Move to queued RW locks Date: Wed, 16 Mar 2022 16:26:00 -0700 Message-Id: <20220316232600.20419-6-palmer@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220316232600.20419-1-palmer@rivosinc.com> References: <20220316232600.20419-1-palmer@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Cc: jonas@southpole.se, stefan.kristiansson@saunalahti.fi, shorne@gmail.com, mingo@redhat.com, Will Deacon , longman@redhat.com, boqun.feng@gmail.com, Paul Walmsley , Palmer Dabbelt , aou@eecs.berkeley.edu, Arnd Bergmann , jszhang@kernel.org, wangkefeng.wang@huawei.com, openrisc@lists.librecores.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-arch@vger.kernel.org, Palmer Dabbelt From: Palmer Dabbelt To: linux-riscv@lists.infradead.org, peterz@infradead.org X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 From: Palmer Dabbelt With the move to fair spinlocks, we might as well move to fair rwlocks. Signed-off-by: Palmer Dabbelt --- arch/riscv/Kconfig | 1 + arch/riscv/include/asm/Kbuild | 2 + arch/riscv/include/asm/spinlock.h | 82 +------------------------ arch/riscv/include/asm/spinlock_types.h | 7 +-- 4 files changed, 5 insertions(+), 87 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 5adcbd9b5e88..feb7030cfb6d 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -38,6 +38,7 @@ config RISCV select ARCH_SUPPORTS_DEBUG_PAGEALLOC if MMU select ARCH_SUPPORTS_HUGETLBFS if MMU select ARCH_USE_MEMTEST + select ARCH_USE_QUEUED_RWLOCKS select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT if MMU select ARCH_WANT_FRAME_POINTERS select ARCH_WANT_HUGE_PMD_SHARE if 64BIT diff --git a/arch/riscv/include/asm/Kbuild b/arch/riscv/include/asm/Kbuild index 42b1961af1a6..e8714070cbb9 100644 --- a/arch/riscv/include/asm/Kbuild +++ b/arch/riscv/include/asm/Kbuild @@ -4,5 +4,7 @@ generic-y += flat.h generic-y += kvm_para.h generic-y += ticket-lock.h generic-y += ticket-lock-types.h +generic-y += qrwlock.h +generic-y += qrwlock_types.h generic-y += user.h generic-y += vmlinux.lds.h diff --git a/arch/riscv/include/asm/spinlock.h b/arch/riscv/include/asm/spinlock.h index 38089cbdea92..97dfb150d18c 100644 --- a/arch/riscv/include/asm/spinlock.h +++ b/arch/riscv/include/asm/spinlock.h @@ -11,86 +11,6 @@ #include #include #include - -static inline void arch_read_lock(arch_rwlock_t *lock) -{ - int tmp; - - __asm__ __volatile__( - "1: lr.w %1, %0\n" - " bltz %1, 1b\n" - " addi %1, %1, 1\n" - " sc.w %1, %1, %0\n" - " bnez %1, 1b\n" - RISCV_ACQUIRE_BARRIER - : "+A" (lock->lock), "=&r" (tmp) - :: "memory"); -} - -static inline void arch_write_lock(arch_rwlock_t *lock) -{ - int tmp; - - __asm__ __volatile__( - "1: lr.w %1, %0\n" - " bnez %1, 1b\n" - " li %1, -1\n" - " sc.w %1, %1, %0\n" - " bnez %1, 1b\n" - RISCV_ACQUIRE_BARRIER - : "+A" (lock->lock), "=&r" (tmp) - :: "memory"); -} - -static inline int arch_read_trylock(arch_rwlock_t *lock) -{ - int busy; - - __asm__ __volatile__( - "1: lr.w %1, %0\n" - " bltz %1, 1f\n" - " addi %1, %1, 1\n" - " sc.w %1, %1, %0\n" - " bnez %1, 1b\n" - RISCV_ACQUIRE_BARRIER - "1:\n" - : "+A" (lock->lock), "=&r" (busy) - :: "memory"); - - return !busy; -} - -static inline int arch_write_trylock(arch_rwlock_t *lock) -{ - int busy; - - __asm__ __volatile__( - "1: lr.w %1, %0\n" - " bnez %1, 1f\n" - " li %1, -1\n" - " sc.w %1, %1, %0\n" - " bnez %1, 1b\n" - RISCV_ACQUIRE_BARRIER - "1:\n" - : "+A" (lock->lock), "=&r" (busy) - :: "memory"); - - return !busy; -} - -static inline void arch_read_unlock(arch_rwlock_t *lock) -{ - __asm__ __volatile__( - RISCV_RELEASE_BARRIER - " amoadd.w x0, %1, %0\n" - : "+A" (lock->lock) - : "r" (-1) - : "memory"); -} - -static inline void arch_write_unlock(arch_rwlock_t *lock) -{ - smp_store_release(&lock->lock, 0); -} +#include #endif /* _ASM_RISCV_SPINLOCK_H */ diff --git a/arch/riscv/include/asm/spinlock_types.h b/arch/riscv/include/asm/spinlock_types.h index 431ee08e26c4..3779f13706fa 100644 --- a/arch/riscv/include/asm/spinlock_types.h +++ b/arch/riscv/include/asm/spinlock_types.h @@ -11,11 +11,6 @@ #endif #include - -typedef struct { - volatile unsigned int lock; -} arch_rwlock_t; - -#define __ARCH_RW_LOCK_UNLOCKED { 0 } +#include #endif /* _ASM_RISCV_SPINLOCK_TYPES_H */ -- 2.34.1