Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp253493imn; Wed, 27 Jul 2022 05:26:53 -0700 (PDT) X-Google-Smtp-Source: AGRyM1urhpHXKBwmhhTUWykxx5AHbkVHrxaZTcay307b9n9rMJfr2hHfw3QlHSyr/J9inrAfu9v/ X-Received: by 2002:a17:90b:4d12:b0:1f3:22e:781b with SMTP id mw18-20020a17090b4d1200b001f3022e781bmr4467045pjb.137.1658924813544; Wed, 27 Jul 2022 05:26:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658924813; cv=none; d=google.com; s=arc-20160816; b=IK7KU4SnWOhHRpdnOGFm1zebtPd4WXANg8NNxEqI9ldjGmyWcC1Zs6nq6YJByHFGju JuSs6ngLy+F2hsRO+WF75qaqjIFELfgBbCMMJk6aBzPPHSCmhqELiVVVwRF2cg8mhcIh EgF1X8MMi3QfNor2ztfJKxcb9PDyxTF728+BKpvWD7IeNkz/+WSZQVXqTHOioy2PMBK3 SruUJotXa1Z/f1Ht5OMzRKNVLGiZpDhNF4UIUjNlXWwdEFEIj7b/kAZGzv8FW/7Vrw8q ZDar04wR5oknV+4f5T5yUHmrDNIqIJ/AZmQ+3tYq2oM8Wzb8r69Frt9JpuV5owajLYWs 92iA== 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=D17IrGjqfDknOXwcV65EANowXkYAl11/dUWcANUuskM=; b=khkOPpvUNt8utP38+TLgrJtu+TFZscdOxDLDuNCE4AM4F++KeFBtahs6dL780SEgwf 0s4JheMsg435s8mlBUjGvFkvKWoejEQYAS28WGMv5q7wRkqEQh5uK9aSCfY6+OoNr8rH b5/Tjpcf9+XO4IwRtUJw7MtKHDchRQVKq0qsOHrGa5LmAdV870SNnirx3p4HdWmACO8V bdifb7xLMeShyjOSmwvd2nSJvaLpPxu4xBff+GALg6FJRDVQB2aeTQH4JSp5v/R6lQbH upsvFqjwMYibf4PKFU7BBM9dXRFStaJ2DmspQ4EoZoNv9/zszME7bLe3o0mTlPZHZLCF BKNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=oVw67IFK; 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 f7-20020a17090ace0700b001f0463eeeb3si1830124pju.181.2022.07.27.05.26.37; Wed, 27 Jul 2022 05:26:53 -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=oVw67IFK; 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 S232513AbiG0Lxm (ORCPT + 99 others); Wed, 27 Jul 2022 07:53:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232499AbiG0Lxj (ORCPT ); Wed, 27 Jul 2022 07:53:39 -0400 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56B76474F7 for ; Wed, 27 Jul 2022 04:53:37 -0700 (PDT) Received: by mail-lf1-x12a.google.com with SMTP id bf9so26647648lfb.13 for ; Wed, 27 Jul 2022 04:53:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=D17IrGjqfDknOXwcV65EANowXkYAl11/dUWcANUuskM=; b=oVw67IFKfMhTwkj4St44LIOpvrqAZzRqnzv4Y6bOpBCLP1BJqNpuGPO3Uc7xddTl5f j5A6Y8WjaPxg/sdXKtxLKAGFjyuZNwIDaRhBgyALOmxuItXIbngCj3GOK1JQvu30Re7+ r4RD3h5Iak81lXY67URzLu9se5r4YzRWRiKV4ja4WWOi7Sm3fWtDlgzz9ujeab893YDt lGPy2fEMzHxGy9y69eduiSsauiQCxXmD5iGx6aiZ5XXSgvF0uABy161+ThPMqxnMXlY7 bihpQmO442/TV2gnjs+uV/9OYkt1dYFU2GubxhKdlykVWq06MzPO/H1giTFJ7UwN4pDE 31EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=D17IrGjqfDknOXwcV65EANowXkYAl11/dUWcANUuskM=; b=28KrSGqX643t7axdvGKxanSXviCydkBW9U3JuooFOOW/dsLVZmlSmk5Sw5+rUJIZWs HGopuGvLG4R6zecGzoZ+g42m0/f9VIxpGsKroM+ErGX5rxBDd2ONgwVN/1cr3/rYkVgD V2OgQUT591bU8iFAmCyMYKVw6R7hRL3p6pkEq7oWrG+SPh2lut+dBIvA84f0a1zrzqqr ZNcsC4Wf9aWuA6+Z2fyvchG5rOzi32vZsopb2DE9EggIgadWxLoaOKeXDjfRZXK0A5Km 2Y9XKv0kQ+B8UbrfP5IEvoT/WCBM7u9KfbZLvGEUHtC3M9Rglyi4T2WFCIenvCE8gXIB TzCg== X-Gm-Message-State: AJIora/G7JuFY28QpesI8iO4WzhcvGbVjHecc1mnLNU5ddtVAVUSNcd4 jCC84+LTpv9+2+L7U/lpHOfY64PQwUvYCggwjgCtqw== X-Received: by 2002:a05:6512:2304:b0:48a:c120:88dc with SMTP id o4-20020a056512230400b0048ac12088dcmr14529lfu.419.1658922815582; Wed, 27 Jul 2022 04:53:35 -0700 (PDT) MIME-Version: 1.0 References: <20220727043829.151794-1-apatel@ventanamicro.com> <724f176b-02f1-b171-726f-16158c650896@codethink.co.uk> <20a94c3c-85ed-2227-458e-60c780fd4ad7@codethink.co.uk> In-Reply-To: <20a94c3c-85ed-2227-458e-60c780fd4ad7@codethink.co.uk> From: Anup Patel Date: Wed, 27 Jul 2022 17:23:24 +0530 Message-ID: Subject: Re: [PATCH v2] RISC-V: Add mvendorid, marchid, and mimpid to /proc/cpuinfo output To: Ben Dooks Cc: Anup Patel , Palmer Dabbelt , Paul Walmsley , Arnd Bergmann , linux-kernel@vger.kernel.org, Heinrich Schuchardt , Atish Patra , linux-riscv@lists.infradead.org, Nikita Shubin 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 Wed, Jul 27, 2022 at 3:42 PM Ben Dooks wrote: > > On 27/07/2022 11:06, Anup Patel wrote: > > On Wed, Jul 27, 2022 at 2:25 PM Ben Dooks wrote: > >> > >> On 27/07/2022 05:38, Anup Patel wrote: > >>> Identifying the underlying RISC-V implementation can be important > >>> for some of the user space applications. For example, the perf tool > >>> uses arch specific CPU implementation id (i.e. CPUID) to select a > >>> JSON file describing custom perf events on a CPU. > >>> > >>> Currently, there is no way to identify RISC-V implementation so we > >>> add mvendorid, marchid, and mimpid to /proc/cpuinfo output. > >>> > >>> Signed-off-by: Anup Patel > >>> Reviewed-by: Heinrich Schuchardt > >>> Tested-by: Nikita Shubin > >>> --- > >>> Changes since v1: > >>> - Use IS_ENABLED() to check CONFIG defines > >>> - Added RB and TB tags in commit description > >>> --- > >>> arch/riscv/kernel/cpu.c | 51 +++++++++++++++++++++++++++++++++++++++++ > >>> 1 file changed, 51 insertions(+) > >>> > >>> diff --git a/arch/riscv/kernel/cpu.c b/arch/riscv/kernel/cpu.c > >>> index fba9e9f46a8c..04bcc91c91ea 100644 > >>> --- a/arch/riscv/kernel/cpu.c > >>> +++ b/arch/riscv/kernel/cpu.c > >>> @@ -3,10 +3,13 @@ > >>> * Copyright (C) 2012 Regents of the University of California > >>> */ > >>> > >>> +#include > >>> #include > >>> #include > >>> #include > >>> +#include > >>> #include > >>> +#include > >>> #include > >>> #include > >>> > >>> @@ -64,6 +67,50 @@ int riscv_of_parent_hartid(struct device_node *node) > >>> } > >>> > >>> #ifdef CONFIG_PROC_FS > >>> + > >>> +struct riscv_cpuinfo { > >>> + unsigned long mvendorid; > >>> + unsigned long marchid; > >>> + unsigned long mimpid; > >>> +}; > >>> +static DEFINE_PER_CPU(struct riscv_cpuinfo, riscv_cpuinfo); > >>> + > >>> +static int riscv_cpuinfo_starting(unsigned int cpu) > >>> +{ > >>> + struct riscv_cpuinfo *ci = this_cpu_ptr(&riscv_cpuinfo); > >>> + > >>> +#if IS_ENABLED(CONFIG_RISCV_SBI) > >>> + ci->mvendorid = sbi_spec_is_0_1() ? 0 : sbi_get_mvendorid(); > >>> + ci->marchid = sbi_spec_is_0_1() ? 0 : sbi_get_marchid(); > >>> + ci->mimpid = sbi_spec_is_0_1() ? 0 : sbi_get_mimpid(); > >> > >> how about: > >> > >> if (IS_ENABLED(CONFIG_RISCV_SBI)) { > >> ... > >> } ... { > >> > >> or maybe even: > >> > >> > >> if (IS_ENABLED(CONFIG_RISCV_SBI)) { > >> if (sbi_spec_is_0_1()) { > >> ... > >> } > >> } ... { > >> > >> would mean better compile coverage (at the slight exepnese of > >> having "false" sbi_spec_is_0_1() implemenation > > > > Most of the sbi_xyz() functions are not available for NoMMU > > kernel so using "if (IS_ENABLED())" results in compile error. > > How about defining "false" versions for no-mmu case and try > and avoid these #if mountains? Well, we are not simplifying anything by moving from a "#if" ladder to "if ()" ladder. Also, I don't see how the "#if" ladder will grow over time. Regards, Anup > > >> > >>> +#elif IS_ENABLED(CONFIG_RISCV_M_MODE) > >>> + ci->mvendorid = csr_read(CSR_MVENDORID); > >>> + ci->marchid = csr_read(CSR_MARCHID); > >>> + ci->mimpid = csr_read(CSR_MIMPID); > >>> +#else > >>> + ci->mvendorid = 0; > >>> + ci->marchid = 0; > >>> + ci->mimpid = 0; > >>> +#endif > >> > >> Would it be easier to zero out all the fields first and then fill them > >> in if supported? > > > > Clearing out fields before "#if" ladder results in dead assignments. > > Not sure which is worse here, the #if ladder or some possibly dead > assignments. > > -- > Ben Dooks http://www.codethink.co.uk/ > Senior Engineer Codethink - Providing Genius > > https://www.codethink.co.uk/privacy.html