Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp1477316imw; Sat, 16 Jul 2022 07:28:06 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uAhexxs4GA+IxOWb/zUm5e/NMfc+N3eyOE1j9KroPhmcDVBvHK3PZ0VPeb3WEzqMlHJP7r X-Received: by 2002:a17:902:b694:b0:16c:29d9:7308 with SMTP id c20-20020a170902b69400b0016c29d97308mr19356185pls.110.1657981686296; Sat, 16 Jul 2022 07:28:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657981686; cv=none; d=google.com; s=arc-20160816; b=ICyxX8Tj5TflNxl2DM7Nc3MQnDAEhnWqHKHa78m6dzy/F9Q26EDIOvItQX7rnIT6X1 bGEwakn1gkNJmN8Aw3DFfgGr7/xZKFA7XdSqUCOYYPg/d3TMZ7F7haqiYSm4iBp11qm/ xlHXeV1qxLBsRGgJhOTNU/6emtCV2LmMiArraQQFzQRnG6APWn8AIyfa6DR2Um9nypCL JNYzXULb7yb4gYmsEjcJ6XLmJhf0XSk4+BRAqTQhheoJ2W5LyXIfNapGi1ywRHUWfPor KgTKoVqDFPc+5S26gn6LdLAZr4PmCJ964VLoylaxLXP552QTGl+GnvNqUjeGA1qZNtaM 98VA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=PirohyfosfJBaoMKsbm+6i4g8cv1itLcwtBWnUKjuJw=; b=KxUHmimUCLlXDyF33lPZ4D7t+zDhSj9jdui1//o0o6mF/0oO0OcYSL77Goo589x0Nn oFjBDniW2WhUnIKqQlRN3JY+OGoQoBY/5EbWiX41/cszdkwnksCwnRbPxh/gAaToDnEK DgJHWe0+FHQg2uP8PPVr2RCJfsIYEsKNf567zd+V7dFgZ4rCiiJm3fJF6jTLUqgAt8mM /NAfjQNJ+kDF/S3Q/lXGDpmYnygeW8ZoqaPPxvJUtypuNOtHW5LT4g3AkN34ImFpWmW7 ADBAG8I7fmyUxU1Rl9Jppsvs1dBygDYMNSgBajgmi7tJdNLHEVK6Knyan+ry8y4d+8yL PAYQ== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=sntech.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m26-20020a638c1a000000b00419ae793a79si9159165pgd.360.2022.07.16.07.27.51; Sat, 16 Jul 2022 07:28:06 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=sntech.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231700AbiGPOME convert rfc822-to-8bit (ORCPT + 99 others); Sat, 16 Jul 2022 10:12:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231528AbiGPOMD (ORCPT ); Sat, 16 Jul 2022 10:12:03 -0400 Received: from gloria.sntech.de (gloria.sntech.de [185.11.138.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DB78210 for ; Sat, 16 Jul 2022 07:12:00 -0700 (PDT) Received: from p508fdc54.dip0.t-ipconnect.de ([80.143.220.84] helo=phil.localnet) by gloria.sntech.de with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1oCiWP-0000Zy-Tj; Sat, 16 Jul 2022 16:11:53 +0200 From: Heiko Stuebner To: Dao Lu , linux-kernel@vger.kernel.org, Conor Dooley Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , Atish Patra , Anup Patel , Guo Ren , Jisheng Zhang , Randy Dunlap , Niklas Cassel , Qinglin Pan , Alexandre Ghiti , Rob Herring , Tsukasa OI , Yury Norov , "open list:RISC-V ARCHITECTURE" Subject: Re: [PATCH v4] arch/riscv: add Zihintpause support Date: Sat, 16 Jul 2022 16:11:41 +0200 Message-ID: <8823276.lOV4Wx5bFT@phil> In-Reply-To: <18a1126c-393e-9c52-4b30-caee01975ad1@conchuod.ie> References: <20220620201530.3929352-1-daolu@rivosinc.com> <18a1126c-393e-9c52-4b30-caee01975ad1@conchuod.ie> MIME-Version: 1.0 Content-Transfer-Encoding: 8BIT Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_PASS, T_SPF_HELO_TEMPERROR 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 Am Montag, 11. Juli 2022, 22:44:21 CEST schrieb Conor Dooley: > On 20/06/2022 21:15, Dao Lu wrote: > > [PATCH v4] arch/riscv: add Zihintpause support > > A little ornery/pedantic maybe, but the "arch/" isn't needed. > Guess it can easily be fixed on application or if there's a > v5 so there's prob no need to resend. I noticed that the patch prefix on riscv is all over the place in a lot of cases. There are - RISC-V: -riscv: - now arch/riscv: and probably even more. I guess someone should just decide on one prefix that then gets used (and slightly enforced) all the time. Even just modifying applied patches to one specific prefix should already solve the issue in a short time, as I guess most people will just get the appicable prefix from a "git log" ;-) . Heiko > > Implement support for the ZiHintPause extension. > > > > The PAUSE instruction is a HINT that indicates the current hart’s rate > > of instruction retirement should be temporarily reduced or paused. > > > > Reviewed-by: Heiko Stuebner > > Tested-by: Heiko Stuebner > > Signed-off-by: Dao Lu > > --- > > > > v1 -> v2: > > Remove the usage of static branch, use PAUSE if toolchain supports it > > v2 -> v3: > > Added the static branch back, cpu_relax() behavior is kept the same for > > systems that do not support ZiHintPause > > v3 -> v4: > > Adopted the newly added unified static keys for extensions > > --- > > arch/riscv/Makefile | 4 ++++ > > arch/riscv/include/asm/hwcap.h | 5 +++++ > > arch/riscv/include/asm/vdso/processor.h | 21 ++++++++++++++++++--- > > arch/riscv/kernel/cpu.c | 1 + > > arch/riscv/kernel/cpufeature.c | 1 + > > 5 files changed, 29 insertions(+), 3 deletions(-) > > > > diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile > > index 34cf8a598617..6ddacc6f44b9 100644 > > --- a/arch/riscv/Makefile > > +++ b/arch/riscv/Makefile > > @@ -56,6 +56,10 @@ riscv-march-$(CONFIG_RISCV_ISA_C) := $(riscv-march-y)c > > toolchain-need-zicsr-zifencei := $(call cc-option-yn, -march=$(riscv-march-y)_zicsr_zifencei) > > riscv-march-$(toolchain-need-zicsr-zifencei) := $(riscv-march-y)_zicsr_zifencei > > > > +# Check if the toolchain supports Zihintpause extension > > +toolchain-supports-zihintpause := $(call cc-option-yn, -march=$(riscv-march-y)_zihintpause) > > +riscv-march-$(toolchain-supports-zihintpause) := $(riscv-march-y)_zihintpause > > + > > KBUILD_CFLAGS += -march=$(subst fd,,$(riscv-march-y)) > > KBUILD_AFLAGS += -march=$(riscv-march-y) > > > > diff --git a/arch/riscv/include/asm/hwcap.h b/arch/riscv/include/asm/hwcap.h > > index e48eebdd2631..dc47019a0b38 100644 > > --- a/arch/riscv/include/asm/hwcap.h > > +++ b/arch/riscv/include/asm/hwcap.h > > @@ -8,6 +8,7 @@ > > #ifndef _ASM_RISCV_HWCAP_H > > #define _ASM_RISCV_HWCAP_H > > > > +#include > > #include > > #include > > > > @@ -54,6 +55,7 @@ extern unsigned long elf_hwcap; > > enum riscv_isa_ext_id { > > RISCV_ISA_EXT_SSCOFPMF = RISCV_ISA_EXT_BASE, > > RISCV_ISA_EXT_SVPBMT, > > + RISCV_ISA_EXT_ZIHINTPAUSE, > > RISCV_ISA_EXT_ID_MAX = RISCV_ISA_EXT_MAX, > > }; > > > > @@ -64,6 +66,7 @@ enum riscv_isa_ext_id { > > */ > > enum riscv_isa_ext_key { > > RISCV_ISA_EXT_KEY_FPU, /* For 'F' and 'D' */ > > + RISCV_ISA_EXT_KEY_ZIHINTPAUSE, > > RISCV_ISA_EXT_KEY_MAX, > > }; > > > > @@ -83,6 +86,8 @@ static __always_inline int riscv_isa_ext2key(int num) > > return RISCV_ISA_EXT_KEY_FPU; > > case RISCV_ISA_EXT_d: > > return RISCV_ISA_EXT_KEY_FPU; > > + case RISCV_ISA_EXT_ZIHINTPAUSE: > > + return RISCV_ISA_EXT_KEY_ZIHINTPAUSE; > > default: > > return -EINVAL; > > } > > diff --git a/arch/riscv/include/asm/vdso/processor.h b/arch/riscv/include/asm/vdso/processor.h > > index 134388cbaaa1..1e4f8b4aef79 100644 > > --- a/arch/riscv/include/asm/vdso/processor.h > > +++ b/arch/riscv/include/asm/vdso/processor.h > > @@ -4,15 +4,30 @@ > > > > #ifndef __ASSEMBLY__ > > > > +#include > > #include > > +#include > > > > static inline void cpu_relax(void) > > { > > + if (!static_branch_likely(&riscv_isa_ext_keys[RISCV_ISA_EXT_KEY_ZIHINTPAUSE])) { > > #ifdef __riscv_muldiv > > - int dummy; > > - /* In lieu of a halt instruction, induce a long-latency stall. */ > > - __asm__ __volatile__ ("div %0, %0, zero" : "=r" (dummy)); > > + int dummy; > > + /* In lieu of a halt instruction, induce a long-latency stall. */ > > + __asm__ __volatile__ ("div %0, %0, zero" : "=r" (dummy)); > > #endif > > + } else { > > + /* > > + * Reduce instruction retirement. > > + * This assumes the PC changes. > > + */ > > +#ifdef __riscv_zihintpause > > + __asm__ __volatile__ ("pause"); > > +#else > > + /* Encoding of the pause instruction */ > > + __asm__ __volatile__ (".4byte 0x100000F"); > > +#endif > > + } > > barrier(); > > } > > > > diff --git a/arch/riscv/kernel/cpu.c b/arch/riscv/kernel/cpu.c > > index fba9e9f46a8c..a123e92b14dd 100644 > > --- a/arch/riscv/kernel/cpu.c > > +++ b/arch/riscv/kernel/cpu.c > > @@ -89,6 +89,7 @@ int riscv_of_parent_hartid(struct device_node *node) > > static struct riscv_isa_ext_data isa_ext_arr[] = { > > __RISCV_ISA_EXT_DATA(sscofpmf, RISCV_ISA_EXT_SSCOFPMF), > > __RISCV_ISA_EXT_DATA(svpbmt, RISCV_ISA_EXT_SVPBMT), > > + __RISCV_ISA_EXT_DATA(zihintpause, RISCV_ISA_EXT_ZIHINTPAUSE), > > __RISCV_ISA_EXT_DATA("", RISCV_ISA_EXT_MAX), > > }; > > > > diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c > > index 1b3ec44e25f5..708df2c0bc34 100644 > > --- a/arch/riscv/kernel/cpufeature.c > > +++ b/arch/riscv/kernel/cpufeature.c > > @@ -198,6 +198,7 @@ void __init riscv_fill_hwcap(void) > > } else { > > SET_ISA_EXT_MAP("sscofpmf", RISCV_ISA_EXT_SSCOFPMF); > > SET_ISA_EXT_MAP("svpbmt", RISCV_ISA_EXT_SVPBMT); > > + SET_ISA_EXT_MAP("zihintpause", RISCV_ISA_EXT_ZIHINTPAUSE); > > } > > #undef SET_ISA_EXT_MAP > > } >