Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp2788171pxm; Mon, 28 Feb 2022 06:10:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJxjZaEp/S0XVwpxWGhILhX6ugwTKe+Z0zx8CyvSnWSSwV8V+EO1o4PE5LUMup4drxPLTLXS X-Received: by 2002:a17:902:dace:b0:14f:f4ac:1102 with SMTP id q14-20020a170902dace00b0014ff4ac1102mr20827981plx.135.1646057456338; Mon, 28 Feb 2022 06:10:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646057456; cv=none; d=google.com; s=arc-20160816; b=bKU0i2sGCIgIlduyd0Mh0U/AUSOO3zHuvIvJrIu/lNgGCyW89uxdW/Fzbe2To0lQoV cA/UGWekqjSYAedLNIB1eKqKRU8V7YV/x7BAG6XYfnQuWfKYSTtaRUgwzS04YHYAic6A lzcum8X04hnZIHYoO1mvwLUtn1ooXBkOiG9nO3QfKVMTgIRijI4yNxXvU3oy6DAX2iN0 kK3fosDJySHT+SVKl26TV8X6hJa0tnccJ42/tLoVYL5SK0jEd/Chej5adHCQ9lcpfBpm UgVn0g4ovirrg8a6ceO6gyCllNN2IbwyEAt9DVfFxhPUufbcP7UA/nApQZmWF8/FEb7h csDg== 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=pHItwHQRCJw3/NMLFZ4U+CA8KLZhljQy1y08UpaRHGE=; b=D01ucLygTq8qiSrEHcM4NJMVfyXJBcVIr68AunH+Nx7TtC7HLztUoa/38cCtFeuv6E uFUrz6NdIvx7YSZJGU9lGUuQBDcnXxxUZrQF1KC48FHfTrm6W5YJ9YU32FcwOUiBmnbK //E8Rtmagj57zx/se9Xn3+s40gLWxGa/XD1O8TlYeb1Lu3TlkpvCI1HaDG63eJwfPz0P umuubezIgq8JPmWvni7hw8753B6PAjEhwciup4QN4q2e1YernFW9Svy7ABiTlB4Amul5 bmWlleKzdFOVIVJzG6lj2QBDaDaFCzwQbGwupAigrqHUS4jIH4gwA7IRNfwjyLCIkUjl U1Bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20210112.gappssmtp.com header.s=20210112 header.b=eJ4T+s0a; 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 x10-20020a63aa4a000000b003784b73126csi8218394pgo.356.2022.02.28.06.10.39; Mon, 28 Feb 2022 06:10:56 -0800 (PST) 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=@brainfault-org.20210112.gappssmtp.com header.s=20210112 header.b=eJ4T+s0a; 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 S234059AbiB1KIc (ORCPT + 99 others); Mon, 28 Feb 2022 05:08:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232172AbiB1KIa (ORCPT ); Mon, 28 Feb 2022 05:08:30 -0500 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7249955B1 for ; Mon, 28 Feb 2022 02:07:51 -0800 (PST) Received: by mail-wr1-x42b.google.com with SMTP id j22so14474232wrb.13 for ; Mon, 28 Feb 2022 02:07:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=pHItwHQRCJw3/NMLFZ4U+CA8KLZhljQy1y08UpaRHGE=; b=eJ4T+s0axsTzcZo2yAVf8S1U/UZXWxjtMh3dZP5HH4wb1mDPGEBIGdfpblep8Jjs69 auBvja0pCIJ19GA/5fPSwITYytbv/iUZuJNIYV5+wkYmku5m4vYvCjirnMxcyD+jSfdf 4BSJwAHE3vt6Ig9o1OgHndyolDqT9jWKLI+x1hGQHHiqnq7LW8O2nwUQ+bTndl5jqyQN cnYbu5A+N1JuMD966rWFxbtfgL0ESbGVIFZX02EX95tJ0UX+KZtLdjpiLCG4EbNs/2xG dOqpfGz/BZKcW2wPb1tMk/Ab37QB1nQERmXJsePEQD27+2I7gZBg18Udyu9Ck1DddfVF zJMw== 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=pHItwHQRCJw3/NMLFZ4U+CA8KLZhljQy1y08UpaRHGE=; b=c6AiRSPQUlLVKE9H817Ooyac4f6br2vfFXiG7B1W/AJfBVszBrluvE4DNgMlkwFGfv t8XENfD6F68rtGF2IAEv+3qGMIUri/1+IQFRfcO3/17aLCuZeWoYOryV7WB94BD4eP0D d7Md686j4qf+kdFh/Eosh/4DFymOx5M7y3QQZGBJmmrtf87V5BIk39b+UZkE+XOqId4m JCHTiOMM3kVDXKwR/uCMCdLkHe6o50W/aCsGj2Y1HvsrpQd9KxfB8l7nHnY0L++bNsvy LhbqCdnOXMhmbUwhSbrIIXd//Z3X/Jumf79F0aIUGawJDFRgO5S5DVhAK/SpRN9tZzVT Dzig== X-Gm-Message-State: AOAM5309niyfDeSpW0n3Tht/Qd3awUZRpouux3YlR27AiKmJvLsT6G+K jYF6qVzM6LtXeaeo2FMfY/r54RKzj8BewWfmouQzTw== X-Received: by 2002:a5d:64a8:0:b0:1ef:f99c:8c12 with SMTP id m8-20020a5d64a8000000b001eff99c8c12mr188308wrp.214.1646042869613; Mon, 28 Feb 2022 02:07:49 -0800 (PST) MIME-Version: 1.0 References: <20220222204811.2281949-1-atishp@rivosinc.com> <20220222204811.2281949-7-atishp@rivosinc.com> In-Reply-To: <20220222204811.2281949-7-atishp@rivosinc.com> From: Anup Patel Date: Mon, 28 Feb 2022 15:37:31 +0530 Message-ID: Subject: Re: [PATCH v5 6/6] RISC-V: Improve /proc/cpuinfo output for ISA extensions To: Atish Patra Cc: "linux-kernel@vger.kernel.org List" , Heiko Stuebner , Albert Ou , Atish Patra , Damien Le Moal , DTML , Jisheng Zhang , Krzysztof Kozlowski , linux-riscv , Palmer Dabbelt , Paul Walmsley , Rob Herring Content-Type: text/plain; charset="UTF-8" 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_NONE, 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 On Wed, Feb 23, 2022 at 2:18 AM Atish Patra wrote: > > Currently, the /proc/cpuinfo outputs the entire riscv,isa string which > is not ideal when we have multiple ISA extensions present in the ISA > string. Some of them may not be enabled in kernel as well. > Same goes for the single letter extensions as well which prints the > entire ISA string. Some of they may not be valid ISA extensions as > well (e.g 'su') > > Parse only the valid & enabled ISA extension and print them. > > Tested-by: Heiko Stuebner > Signed-off-by: Atish Patra Looks good to me. Reviewed-by: Anup Patel Regards, Anup > --- > arch/riscv/include/asm/hwcap.h | 7 +++++ > arch/riscv/kernel/cpu.c | 51 ++++++++++++++++++++++++++++++++-- > 2 files changed, 56 insertions(+), 2 deletions(-) > > diff --git a/arch/riscv/include/asm/hwcap.h b/arch/riscv/include/asm/hwcap.h > index 170bd80da520..691fc9c8099b 100644 > --- a/arch/riscv/include/asm/hwcap.h > +++ b/arch/riscv/include/asm/hwcap.h > @@ -54,6 +54,13 @@ enum riscv_isa_ext_id { > RISCV_ISA_EXT_ID_MAX = RISCV_ISA_EXT_MAX, > }; > > +struct riscv_isa_ext_data { > + /* Name of the extension displayed to userspace via /proc/cpuinfo */ > + char uprop[RISCV_ISA_EXT_NAME_LEN_MAX]; > + /* The logical ISA extension ID */ > + unsigned int isa_ext_id; > +}; > + > unsigned long riscv_isa_extension_base(const unsigned long *isa_bitmap); > > #define riscv_isa_extension_mask(ext) BIT_MASK(RISCV_ISA_EXT_##ext) > diff --git a/arch/riscv/kernel/cpu.c b/arch/riscv/kernel/cpu.c > index ad0a7e9f828b..031ad15a059f 100644 > --- a/arch/riscv/kernel/cpu.c > +++ b/arch/riscv/kernel/cpu.c > @@ -6,6 +6,7 @@ > #include > #include > #include > +#include > #include > #include > > @@ -63,12 +64,57 @@ int riscv_of_parent_hartid(struct device_node *node) > } > > #ifdef CONFIG_PROC_FS > +#define __RISCV_ISA_EXT_DATA(UPROP, EXTID) \ > + { \ > + .uprop = #UPROP, \ > + .isa_ext_id = EXTID, \ > + } > + > +static struct riscv_isa_ext_data isa_ext_arr[] = { > + __RISCV_ISA_EXT_DATA("", RISCV_ISA_EXT_MAX), > +}; > + > +static void print_isa_ext(struct seq_file *f) > +{ > + struct riscv_isa_ext_data *edata; > + int i = 0, arr_sz; > + > + arr_sz = ARRAY_SIZE(isa_ext_arr) - 1; > + > + /* No extension support available */ > + if (arr_sz <= 0) > + return; > + > + seq_puts(f, "isa-ext\t\t: "); > + for (i = 0; i <= arr_sz; i++) { > + edata = &isa_ext_arr[i]; > + if (!__riscv_isa_extension_available(NULL, edata->isa_ext_id)) > + continue; > + seq_printf(f, "%s ", edata->uprop); > + } > + seq_puts(f, "\n"); > +} > + > +/** > + * These are the only valid base (single letter) ISA extensions as per the spec. > + * It also specifies the canonical order in which it appears in the spec. > + * Some of the extension may just be a place holder for now (B, K, P, J). > + * This should be updated once corresponding extensions are ratified. > + */ > +static const char base_riscv_exts[13] = "imafdqcbkjpvh"; > > static void print_isa(struct seq_file *f, const char *isa) > { > - /* Print the entire ISA as it is */ > + int i; > + > seq_puts(f, "isa\t\t: "); > - seq_write(f, isa, strlen(isa)); > + /* Print the rv[64/32] part */ > + seq_write(f, isa, 4); > + for (i = 0; i < sizeof(base_riscv_exts); i++) { > + if (__riscv_isa_extension_available(NULL, base_riscv_exts[i] - 'a')) > + /* Print only enabled the base ISA extensions */ > + seq_write(f, &base_riscv_exts[i], 1); > + } > seq_puts(f, "\n"); > } > > @@ -115,6 +161,7 @@ static int c_show(struct seq_file *m, void *v) > seq_printf(m, "hart\t\t: %lu\n", cpuid_to_hartid_map(cpu_id)); > if (!of_property_read_string(node, "riscv,isa", &isa)) > print_isa(m, isa); > + print_isa_ext(m); > print_mmu(m); > if (!of_property_read_string(node, "compatible", &compat) > && strcmp(compat, "riscv")) > -- > 2.30.2 >