Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp660178rwi; Mon, 10 Oct 2022 05:45:42 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5opqDban86eRSP5cTv50syTkFLhloAzwkASNGFnx+Wdvw6+20GosaTeOE8hn0qv2uoSRoO X-Received: by 2002:a17:907:d08:b0:72f:b107:c07a with SMTP id gn8-20020a1709070d0800b0072fb107c07amr14833399ejc.340.1665405942449; Mon, 10 Oct 2022 05:45:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665405942; cv=none; d=google.com; s=arc-20160816; b=tmirfh40kUZ+ZrbyQHzc36cLfgB0JuplCU/EUgWZ7bNbT87CX0JNaIuQc8/YosON5e 0qOWnAIwEqzcur5iqEbV5X3RJPtJw7A6YzTl44NFRNEDJ4jmkJaNP+yEAlulfvynOepO hTKEo0NTzCsGcZ0jzR2j9ckghVGTInlbDdIFjNSqU2Cfx9HTeh/Nnb9v3VDWgeYFTZtU GiDJOT6HJGXJQU4nx6kWXyXT6Q2bLT79dzeZ+F16S03Az3yyuVUri9sUMYBmhCZwibTl Juc7W3taJL/GV7jMlMHMM3SL6IOk0HDQXJkbFq3C/KidTVolzXYXof06m6McsG8hqJp9 vJqw== 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=swiZpasJ/Xg2mwIKEKKxWOhMenclwtAa4uTWpmNXlBk=; b=SC+3ceeiqUSraobN/0wxL6SPEjRDwwTE6cyp/0E/dj53i/L4phwlpJaP+5Yb9sUj3r 0Tzk56oBTFfm/OaNcHdsVJ/218RIM6LdrnpMIIWWELqrYmw8Gskim8/idI9D9D0gXL+G JiaDB2vTh2fmG6GzAa+QrA2Vomq2aIoS439AuM1yB/fb1Ie1jBg332MgC4qtoJIsaSpw oCVJCIGyDpr4VyrAG+1//xeH7s9fUSj7AzpzMLByuu6eS1kaUED6ksaLjCMc1R86/gla O3ChDppsgghT/Z4Fh96/y1qGphxTPiaSEMMNZh9HkO0H6c7zywXQLnwlD0EdgXLJyGKB HHiA== 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 qa12-20020a170907868c00b0078153dd2836si10373900ejc.505.2022.10.10.05.45.17; Mon, 10 Oct 2022 05:45:42 -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 S231730AbiJJM1t (ORCPT + 99 others); Mon, 10 Oct 2022 08:27:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231513AbiJJM1o (ORCPT ); Mon, 10 Oct 2022 08:27:44 -0400 Received: from gloria.sntech.de (gloria.sntech.de [185.11.138.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8841D61732 for ; Mon, 10 Oct 2022 05:27:43 -0700 (PDT) Received: from p5b1274fa.dip0.t-ipconnect.de ([91.18.116.250] helo=phil.fritz.box) by gloria.sntech.de with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ohrsX-0001kg-4d; Mon, 10 Oct 2022 14:27:29 +0200 From: Heiko Stuebner To: atishp@atishpatra.org, anup@brainfault.org, will@kernel.org, mark.rutland@arm.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Conor.Dooley@microchip.com, ajones@ventanamicro.com, Heiko Stuebner Subject: [PATCH v5 1/2] RISC-V: Cache SBI vendor values Date: Mon, 10 Oct 2022 14:27:25 +0200 Message-Id: <20221010122726.2405153-2-heiko@sntech.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221010122726.2405153-1-heiko@sntech.de> References: <20221010122726.2405153-1-heiko@sntech.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 sbi_get_mvendorid(), sbi_get_marchid() and sbi_get_mimpid() might get called multiple times, though the values of these CSRs should not change during the runtime of a specific machine. So cache the values in the functions and prevent multiple ecalls to read these values. As Andrew Jones noted, at least marchid and mimpid may be negative values when viewed as a long, so we use a separate static bool to indiciate the cached status. Suggested-by: Atish Patra Signed-off-by: Heiko Stuebner --- arch/riscv/kernel/sbi.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c index 775d3322b422..cc618aaa9d11 100644 --- a/arch/riscv/kernel/sbi.c +++ b/arch/riscv/kernel/sbi.c @@ -625,17 +625,41 @@ static inline long sbi_get_firmware_version(void) long sbi_get_mvendorid(void) { - return __sbi_base_ecall(SBI_EXT_BASE_GET_MVENDORID); + static long id; + static bool cached; + + if (!cached) { + id = __sbi_base_ecall(SBI_EXT_BASE_GET_MVENDORID); + cached = true; + } + + return id; } long sbi_get_marchid(void) { - return __sbi_base_ecall(SBI_EXT_BASE_GET_MARCHID); + static long id; + static bool cached; + + if (!cached) { + id = __sbi_base_ecall(SBI_EXT_BASE_GET_MARCHID); + cached = true; + } + + return id; } long sbi_get_mimpid(void) { - return __sbi_base_ecall(SBI_EXT_BASE_GET_MIMPID); + static long id; + static bool cached; + + if (!cached) { + id = __sbi_base_ecall(SBI_EXT_BASE_GET_MIMPID); + cached = true; + } + + return id; } static void sbi_send_cpumask_ipi(const struct cpumask *target) -- 2.35.1