Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp3886265ioo; Wed, 25 May 2022 10:00:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxh//WCrGu1pWxLuX+Ph2muX8HoNRmET3oYM3j7+BBb+xkgzR4QRpXfzAB4/YyNsVt+WWAD X-Received: by 2002:a05:6a00:24c1:b0:518:c52f:f5 with SMTP id d1-20020a056a0024c100b00518c52f00f5mr9990625pfv.15.1653498044195; Wed, 25 May 2022 10:00:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653498044; cv=none; d=google.com; s=arc-20160816; b=v3VjLHBQtL5PwHT0T0jnuw/JYc5P7JgLSJToy7w8qpQfqiXsTFsyboE8uKCspnGK0A Yap7HkCDzaprTDbT2e+Qme5Wwup+pPZ2WSFCnQcSSfIX6FX982r3fiZ9/gZh4nqeBvnp wn7045syudL9YiE2qh/+zk4jJ3bqbpr4rDb/e9VuRw/3qFR4J0khwj5o0zGqE85aBMN7 q5U1RsF/HlI5Wbz+eR09XD2EmQeeyTCvkCx8oWgBnW/zPI72EwyVObWvGTQ8SLn1ujfX rVqXzoy96VbYFEFxMxVZ7gPSFyr6bD/bb04kbLZxmMh1U1exUgKJAUHwtDNaaYj99+dQ eOVA== 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:date:subject:cc:to:from:dkim-signature; bh=AOOnQwX8FlMZPsRjdPt59x3rx2ygNvknjVlpR0iASV4=; b=vIhn6UFA1g5JbGUs//aeXfVLEwzCxa3B1KbPKsVr9GGb4k3W8uhtzddCFPfsuGChsw FoQw5DPrhMxtD8jNXEdSo3HnAzoWvHepQvg4yxbcaKaO9q7H+yVBdUbkgk6YuTuDO9Et HLXYv7q6KxEVEf3/42uimLrGmNZ7HQwT+8j1fMxl7A5QKaWMyrhKKV6JU5yF1GjUds3l 4zA5DVhzftCxut0qtNejlfLEqxN//OgPy/9LQ1PGmJ/ZxMuy5ID6vOAFB6HK85Zjq56+ U8rznStLuZvWuHpKgH0gsB4513WkQOMUBCeVYBVCuoXer4oI5WeUwOw72jpmx8fF0+A6 6eNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=YrTSwufL; 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 n20-20020a17090ade9400b001dfb3dc517asi1597129pjv.112.2022.05.25.10.00.30; Wed, 25 May 2022 10:00:44 -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=YrTSwufL; 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 S241890AbiEXVUB (ORCPT + 99 others); Tue, 24 May 2022 17:20:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235550AbiEXVT7 (ORCPT ); Tue, 24 May 2022 17:19:59 -0400 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E7EA56FB4 for ; Tue, 24 May 2022 14:19:58 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id y199so17507703pfb.9 for ; Tue, 24 May 2022 14:19:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=AOOnQwX8FlMZPsRjdPt59x3rx2ygNvknjVlpR0iASV4=; b=YrTSwufLEZ1P7/fW0b/k6bLAK/RaBs/rYT5zdNK+AgXQ3AfBxedshAwy/hCIaDeMum 63fAA5CXnCSlev0yz8w5zJhf+Gl71NBw+ln88+tJe9F2OdZrlckhk6isvq37z+mtIAoB GUUiprEZGCRYxZ3TKbhuCuaR+TCfnqGX+28hhCbYWCcA6wXWnx6tF0Ds0/yuAfu93c0U q9DKy/Dv2xD/oY1wOHTn8NdmF8uUp1br3r5riHE3BXs4JB+s8yMumemO0L0OoONBZGZk tiXTLgZUthwGvfGbljEKg/3YXIK/Tdn9WwXImLUgH03uoTJYhEk7NjuNRtYWoQCs8KrE rvgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=AOOnQwX8FlMZPsRjdPt59x3rx2ygNvknjVlpR0iASV4=; b=p4PADm7oXy4G7MkTFy9Gq/3HtommQgyg0C9RKUDevSLqEhquqejVd0WQfpxLdZ+lA0 hfcA0VLpw/ccJfZyg6wqONRN61t/426/rb1Vym8BOM8tQyZ5Qr8+xvMZSZ1YGB8Mba4+ Tpwha2s0Zbu+O9nzdL3IHFxRNZL7ntjGUfcjcwZAwZWrhHkuejRk4508xuVoFdedeYXN sEhEOhfUnpI/NRWyKVCq3NGRaYBWZkfCOJSM4xDi59XTuihFucliXeTi8md5qhuUgJ4p oPAtIE4BunQ4TjZR9aaFA716PaBTRE7oyhiLMHNnMJ+zR4lAQUBPP6epZ6lilHdJ6fC8 gqag== X-Gm-Message-State: AOAM5328gDwzhRmL8SzYvExNg3J5PtL6GCl6nKxk/tdIiKLRpTysHr3a ZCNDBEI7cSIbt8xNPn81Q8n47pX1ccdHsw== X-Received: by 2002:a05:6a00:170c:b0:510:865f:bf34 with SMTP id h12-20020a056a00170c00b00510865fbf34mr30397811pfc.60.1653427197677; Tue, 24 May 2022 14:19:57 -0700 (PDT) Received: from daolu.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id a4-20020a62d404000000b0050dc7628181sm9833817pfh.91.2022.05.24.14.19.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 May 2022 14:19:57 -0700 (PDT) From: Dao Lu To: linux-kernel@vger.kernel.org Cc: Dao Lu , Heiko Stuebner , Paul Walmsley , Palmer Dabbelt , Albert Ou , Atish Patra , Anup Patel , Randy Dunlap , Rob Herring , Alexandre Ghiti , Qinglin Pan , Tsukasa OI , Jisheng Zhang , linux-riscv@lists.infradead.org (open list:RISC-V ARCHITECTURE) Subject: [PATCH v2] arch/riscv: add Zihintpause support Date: Tue, 24 May 2022 14:19:50 -0700 Message-Id: <20220524211954.1936117-1-daolu@rivosinc.com> X-Mailer: git-send-email 2.36.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 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 arch/riscv/Makefile | 4 ++++ arch/riscv/include/asm/hwcap.h | 1 + arch/riscv/include/asm/vdso/processor.h | 8 +++++++- arch/riscv/kernel/cpu.c | 1 + arch/riscv/kernel/cpufeature.c | 2 ++ 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile index 7d81102cffd4..900a8fda1a2d 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 0734e42f74f2..caa9ee5459b4 100644 --- a/arch/riscv/include/asm/hwcap.h +++ b/arch/riscv/include/asm/hwcap.h @@ -52,6 +52,7 @@ extern unsigned long elf_hwcap; */ enum riscv_isa_ext_id { RISCV_ISA_EXT_SSCOFPMF = RISCV_ISA_EXT_BASE, + RISCV_ISA_EXT_ZIHINTPAUSE, RISCV_ISA_EXT_ID_MAX = RISCV_ISA_EXT_MAX, }; diff --git a/arch/riscv/include/asm/vdso/processor.h b/arch/riscv/include/asm/vdso/processor.h index 134388cbaaa1..4de911a25051 100644 --- a/arch/riscv/include/asm/vdso/processor.h +++ b/arch/riscv/include/asm/vdso/processor.h @@ -8,7 +8,13 @@ static inline void cpu_relax(void) { -#ifdef __riscv_muldiv +#ifdef __riscv_zihintpause + /* + * Reduce instruction retirement. + * This assumes the PC changes. + */ + __asm__ __volatile__ ("pause"); +#elif __riscv_muldiv int dummy; /* In lieu of a halt instruction, induce a long-latency stall. */ __asm__ __volatile__ ("div %0, %0, zero" : "=r" (dummy)); diff --git a/arch/riscv/kernel/cpu.c b/arch/riscv/kernel/cpu.c index ccb617791e56..89e563e9c4cc 100644 --- a/arch/riscv/kernel/cpu.c +++ b/arch/riscv/kernel/cpu.c @@ -88,6 +88,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(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 1b2d42d7f589..37ff06682ae6 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -25,6 +25,7 @@ static DECLARE_BITMAP(riscv_isa, RISCV_ISA_EXT_MAX) __read_mostly; __ro_after_init DEFINE_STATIC_KEY_FALSE(cpu_hwcap_fpu); #endif + /** * riscv_isa_extension_base() - Get base extension word * @@ -192,6 +193,7 @@ void __init riscv_fill_hwcap(void) set_bit(*ext - 'a', this_isa); } else { SET_ISA_EXT_MAP("sscofpmf", RISCV_ISA_EXT_SSCOFPMF); + SET_ISA_EXT_MAP("zihintpause", RISCV_ISA_EXT_ZIHINTPAUSE); } #undef SET_ISA_EXT_MAP } -- 2.36.0