Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp730522rwi; Mon, 10 Oct 2022 06:33:49 -0700 (PDT) X-Google-Smtp-Source: AMsMyM63aDRZhqGIT86Sm6RkHQ9LRDLY4VRDchwsYqI7wYH9pGOWYWovJDlGBAR0dCd0hL581XEA X-Received: by 2002:a65:6d8a:0:b0:43c:9fcc:cb24 with SMTP id bc10-20020a656d8a000000b0043c9fcccb24mr16877596pgb.477.1665408829479; Mon, 10 Oct 2022 06:33:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665408829; cv=none; d=google.com; s=arc-20160816; b=wBW4P3CGAyprFnKl3SJCHv+I9ScrH6M7/ZNSA3koZCuvFL5H+TZFwet+29vPV/nRSn 4cF6NaLiPcqVl81bNjXzxvggYUGvPlqLr/8L9dPB+koHzoNz5FChc7iuSBeUdWEBLgNF yd635IgfpLm77YDuW/5zKQIBECI8MhK4ZfF32l3FbVTs354jBX5SRKGZNa/G2X/+Hcaw IihasgbfZkj3J1mkkbMgr+gtIuuAI/ETnXfFQdMS6aLN6zHu7MxINzis90P/mRMLzaaI c0py0ZkV1RVeY8XyDwUCgu7+sgCesRj5S2ATIBA22Eg887/zAUWOUAnI4BIC/e0lgXY1 dqIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=ZY3VUGhKW8CmP8tRkiumn3t63ZndWcrOVy3NInH/4F8=; b=xBTkcsG1lEHBI55JElc6gCxqCIhFf6FqVYOORNp3XnocuQckQYZ5r8LO93x1NQ6kVL x7NmmuL1pey000g6P+qJ4jVb+TwhbK6qEAQ9pfebqWhkJJ+q6kR97J9kKMPYtfSULnDg gMoT6jCZH5bn+fmh4QYb2PbMTTzYAheLBbFoXgCHxxvyQ2dbvikPN456Kqqo4WSlVugU eQ1V6V0hotlrp99sKZ2nTLyUPkVXdwb7cqTMhPbDpykQxDWDxs/seMNXwJF0spxwgNP5 fPcjt1ikVmd1Rh3i+paO6VQnPMQf1hhf2h7D/izSRSh0EtuNHDuNmEUn016A3banz5VM dpPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=WfYSNe53; 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 b5-20020a170902e94500b001755c347071si11656544pll.451.2022.10.10.06.33.37; Mon, 10 Oct 2022 06:33:49 -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=@ventanamicro.com header.s=google header.b=WfYSNe53; 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 S229596AbiJJMqA (ORCPT + 99 others); Mon, 10 Oct 2022 08:46:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229641AbiJJMp6 (ORCPT ); Mon, 10 Oct 2022 08:45:58 -0400 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90D4F6B8F8 for ; Mon, 10 Oct 2022 05:45:57 -0700 (PDT) Received: by mail-lf1-x12d.google.com with SMTP id bp15so16397072lfb.13 for ; Mon, 10 Oct 2022 05:45:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=ZY3VUGhKW8CmP8tRkiumn3t63ZndWcrOVy3NInH/4F8=; b=WfYSNe539shRVw3WcHUUuaSo4y4sxxkTYIo+JJ2wCMAWW2aWI1Eq9mu8QHheZcuj8G Ry+T/Jne36cmdNNXoi9BcZpSv156/ok1H3pu5j2RYmnqpyoSvXXrbFNE4kWXCOPq9sEr AtLTEKdptRqLIylJUqivtWseFoXqJ+k3xxBSz544xUrjyNEIjMcj8s7dO1Fn/r94zogP lYeQzTkfcDqdBWL5FZYMM/6+7yMiLFcqFLtjIBJTEq+ag0t4HbR16ZyChHehVSw80ht5 gsgJAZeTec8t+Id5zNmQwvcFy+bXBjP075aOy+6RA3QwMn2KLxxicyO6T33ctGR0rOUn meMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ZY3VUGhKW8CmP8tRkiumn3t63ZndWcrOVy3NInH/4F8=; b=2L3nnT/rlXhjWgm2f2hqP/Vno4wTjLp3+ObR4xpovqVpCHwihx7mkp7E2qDs71PCK4 D6KZmqwmpML4TQc1s3i66vKpzzRJl441hI4gd56ZDCaoQ0P0wN8ngpj9LixMpo+Qz9uH Y3r1Jn5SRrWlsYXeHZpQN9Ly5ueI/X4SZ8MQWAH/Dz+QLr2jOSXfyj8rsZcM+OQ7BJkn qAwcXEffsLcqS4pY3o55Arezq8ZJLg07ioektezQkNcEP/NM46CwjUDVLdqWaZHFs8QW +Lz+cIE5p2LV0BOD6VMSckGhRUwXkzx6aa1QjWMCU6E8JkqxP31eYqlZ5lfNt5uT+12t qHoQ== X-Gm-Message-State: ACrzQf2NWkHc0X+Y8zhOPkJBzkTaFU7cycZBgfr1q5f34F6Vwld35a86 /hqIAZ2gPZ+9WiiJ46HljsvGTHq4GAkd7u55zc4E6g== X-Received: by 2002:ac2:5616:0:b0:4a2:61f6:85e9 with SMTP id v22-20020ac25616000000b004a261f685e9mr6346865lfd.419.1665405955788; Mon, 10 Oct 2022 05:45:55 -0700 (PDT) MIME-Version: 1.0 References: <20221010122726.2405153-1-heiko@sntech.de> <20221010122726.2405153-2-heiko@sntech.de> In-Reply-To: <20221010122726.2405153-2-heiko@sntech.de> From: Anup Patel Date: Mon, 10 Oct 2022 18:15:45 +0530 Message-ID: Subject: Re: [PATCH v5 1/2] RISC-V: Cache SBI vendor values To: Heiko Stuebner Cc: atishp@atishpatra.org, anup@brainfault.org, will@kernel.org, mark.rutland@arm.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Conor.Dooley@microchip.com, ajones@ventanamicro.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS 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 Mon, Oct 10, 2022 at 5:57 PM Heiko Stuebner wrote: > > 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; This breaks for heterogeneous SMP systems (similar to big.LITTLE) where HARTs will have different marchid even though they belong to same CPU Vendor. Due to the above rationale, the patch adding marchid, mvendorid, and mimpid in /proc/cpuinfo caches these values on a per-CPU basis. Regards, Anup > + > + 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 >