Received: by 2002:ac2:464d:0:0:0:0:0 with SMTP id s13csp3570727lfo; Mon, 23 May 2022 08:08:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyj+wEcZ0ykSV8Hwotjy4SSD4NGDcm9ZTtdYZX/CFZZs5a7Isa7b/NN8xaxYrSHLCZJkmtJ X-Received: by 2002:a17:90b:3910:b0:1df:e147:6d85 with SMTP id ob16-20020a17090b391000b001dfe1476d85mr23156645pjb.18.1653318520823; Mon, 23 May 2022 08:08:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653318520; cv=none; d=google.com; s=arc-20160816; b=tGfgc+C8yLx3IIFLuwrbCE3xLsyTaGvrIOmWvPdHE22ha4vYX1QkL1YUFZ8G+qnGXe RPPkDmUYbbFp28tP8f1u8YYj0RJZKDpKEmRzDtGv6OvQOl2I865ARK3+h8TKI6SrJyTW bRRsbpMCf7NYLrDLcuw/j7WXnFHtP+3pOSRuXpCz1KTc8BIEYEJLL8GDqowG2GChFHAS /2Ve1x5+Hs4kyUkLFX4cJJyUYuhVaXj82+xYSjNo9bFBjzwlIXMT5Wa6kzJ4+QKAZVmq sVIrtalfh1L99/myoiQPrk1oktXqrokjNHojuy4fVLW3wK6B2ggY1DWNa6a9JuYCmS2v lh1Q== 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=Ys4XdVscv5VNlcHHCYpLwgVZ+X8P1XO1ISLGENGjWOQ=; b=SwYyJ+4F/N6uv2sFc0yQzWTqCr8oOduI20/2/EV8ggNcjbDpKy03kU40KS55teRc+A TirvzcRNDC6K5DAVRgS6kOspaHR4xGk9HcVJw9IXFS8iZC5ltp6DpvzzbSjOflUuhaoU 3mlcpzSp5TazcT4pOia189sWB/3Kum6gwhmIHL+0K7uQFng8KBH54ssWR79kepewqd1a MN02YxSlnhzFvl2hYNQe+iqFrB3zsxJJy/ZBoUr/pbv+WZzv8MjNXpckuXJvKQbN5a/D tRVAUKBQj+PxLq+2JtHPs4Z+J601BKMv9zQg+0uefMPkPa1mLAP9xH8uMiXtLyTPQoVx BWeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20210112.gappssmtp.com header.s=20210112 header.b=BjX2AvhJ; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id y11-20020a17090aa40b00b001dfab05243bsi13933697pjp.181.2022.05.23.08.08.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 08:08:40 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@brainfault-org.20210112.gappssmtp.com header.s=20210112 header.b=BjX2AvhJ; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5ABB45C845; Mon, 23 May 2022 08:08:14 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237659AbiEWPIH (ORCPT + 99 others); Mon, 23 May 2022 11:08:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237628AbiEWPIF (ORCPT ); Mon, 23 May 2022 11:08:05 -0400 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 F1D475C74D for ; Mon, 23 May 2022 08:08:00 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id u3so21841132wrg.3 for ; Mon, 23 May 2022 08:08:00 -0700 (PDT) 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=Ys4XdVscv5VNlcHHCYpLwgVZ+X8P1XO1ISLGENGjWOQ=; b=BjX2AvhJL3a02i3+eGBxYQWW6FMsRR6Yrw5epDlnSmm4uVdIfmQG/bBKQ5CXnKJehC gtN1AFqiK55TTf7VuHoIvbUZl3DuWzeGARd+XPNlKkTp4JPYZlb6SRbke/i8x3o0uHHU +2EXNbvx2pVc1LY/DNgXEFgUMDFGP3IqFiOKR82Q0bimMXPKgTkPBFqWW27RGtupMw00 mZs6wkMjwJc+2Xs5uLu1CMxKi3ocrm5uTL4olmG7jKmysExazGkgyfYQv/Fd70CQhiyf /NrIXUtXCURW8JEtBCkUAC2dxCuo2XnWQaVXRQflZPuYCtUSqXaSlHrUaE77P6Zi/U3t Kkkw== 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=Ys4XdVscv5VNlcHHCYpLwgVZ+X8P1XO1ISLGENGjWOQ=; b=Vh6Kcw5axyWc6WEuDbPe07k2kp90q13I9+YLlRmjWUBW8+51HhzO5cJ/lHCVPKzhF+ ypnQFkC+0XtThdXTiI9f9DOAaEQjk3o/G8YV8VijzpWZKfF+rvX2y3T3V8l7HQh0eetJ KWUEYaV8Sr3jfyK0OrpC8B40ebC1WzUASKGsZyrvPaYgCaQZTjgI678XjY1dCrb2MwFZ Prb6b+KyrEActWPrQ93pK4n9BepsrfeWV6xTIsrllNhGnpZFvggj7afqrzCxubNfdswv 8NgQxdXxdVhfGMR+Yd9prGcOLBa0UZKt8bw/kK3Ag8qrrh5m2eQr1zQECDJJJ5eHUoJQ SvWA== X-Gm-Message-State: AOAM530m7VKkHy/T858alOYf4OgF3jC8sGJw0OsfFCL3uvcV4YiyL/Rv 8/LJUa8asG5APrOJvdc7Ed/HamqD3aLZnU2dpUAmDA== X-Received: by 2002:a5d:6c6b:0:b0:1ea:77ea:dde8 with SMTP id r11-20020a5d6c6b000000b001ea77eadde8mr19522626wrz.690.1653318479248; Mon, 23 May 2022 08:07:59 -0700 (PDT) MIME-Version: 1.0 References: <20220522153543.2656-1-jszhang@kernel.org> <20220522153543.2656-2-jszhang@kernel.org> In-Reply-To: <20220522153543.2656-2-jszhang@kernel.org> From: Anup Patel Date: Mon, 23 May 2022 20:37:47 +0530 Message-ID: Subject: Re: [PATCH v2 1/2] riscv: introduce unified static key mechanism for ISA extensions To: Jisheng Zhang Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , Atish Patra , linux-riscv , "linux-kernel@vger.kernel.org List" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Sun, May 22, 2022 at 9:14 PM Jisheng Zhang wrote: > > Currently, riscv has several extensions which may not be supported on > all riscv platforms, for example, FPU and so on. To support unified > kernel Image style, we need to check whether the feature is supported > or not. If the check sits at hot code path, then performance will be > impacted a lot. static key can be used to solve the issue. In the past, > FPU support has been converted to use static key mechanism. I believe > we will have similar cases in the future. > > This patch tries to add an unified mechanism to use static keys for > some ISA extensions by implementing an array of default-false static keys > and enabling them when detected. > > Signed-off-by: Jisheng Zhang Looks good to me. Reviewed-by: Anup Patel Regards, Anup > --- > arch/riscv/include/asm/hwcap.h | 25 +++++++++++++++++++++++++ > arch/riscv/kernel/cpufeature.c | 7 +++++++ > 2 files changed, 32 insertions(+) > > diff --git a/arch/riscv/include/asm/hwcap.h b/arch/riscv/include/asm/hwcap.h > index 0734e42f74f2..d3e113fe7366 100644 > --- a/arch/riscv/include/asm/hwcap.h > +++ b/arch/riscv/include/asm/hwcap.h > @@ -12,6 +12,7 @@ > #include > > #ifndef __ASSEMBLY__ > +#include > /* > * This yields a mask that user programs can use to figure out what > * instruction set this cpu supports. > @@ -55,6 +56,16 @@ enum riscv_isa_ext_id { > RISCV_ISA_EXT_ID_MAX = RISCV_ISA_EXT_MAX, > }; > > +/* > + * This enum represents the logical ID for each RISC-V ISA extension static > + * keys. We can use static key to optimize code path if some ISA extensions > + * are available. > + */ > +enum riscv_isa_ext_key { > + RISCV_ISA_EXT_KEY_FPU, /* For 'F' and 'D' */ > + RISCV_ISA_EXT_KEY_MAX, > +}; > + > struct riscv_isa_ext_data { > /* Name of the extension displayed to userspace via /proc/cpuinfo */ > char uprop[RISCV_ISA_EXT_NAME_LEN_MAX]; > @@ -62,6 +73,20 @@ struct riscv_isa_ext_data { > unsigned int isa_ext_id; > }; > > +extern struct static_key_false riscv_isa_ext_keys[RISCV_ISA_EXT_KEY_MAX]; > + > +static __always_inline int riscv_isa_ext2key(int num) > +{ > + switch (num) { > + case RISCV_ISA_EXT_f: > + return RISCV_ISA_EXT_KEY_FPU; > + case RISCV_ISA_EXT_d: > + return RISCV_ISA_EXT_KEY_FPU; > + default: > + return -EINVAL; > + } > +} > + > 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/cpufeature.c b/arch/riscv/kernel/cpufeature.c > index 1b2d42d7f589..89f886b35357 100644 > --- a/arch/riscv/kernel/cpufeature.c > +++ b/arch/riscv/kernel/cpufeature.c > @@ -24,6 +24,8 @@ static DECLARE_BITMAP(riscv_isa, RISCV_ISA_EXT_MAX) __read_mostly; > #ifdef CONFIG_FPU > __ro_after_init DEFINE_STATIC_KEY_FALSE(cpu_hwcap_fpu); > #endif > +__ro_after_init DEFINE_STATIC_KEY_ARRAY_FALSE(riscv_isa_ext_keys, RISCV_ISA_EXT_KEY_MAX); > +EXPORT_SYMBOL(riscv_isa_ext_keys); > > /** > * riscv_isa_extension_base() - Get base extension word > @@ -232,6 +234,11 @@ void __init riscv_fill_hwcap(void) > print_str[j++] = (char)('a' + i); > pr_info("riscv: ELF capabilities %s\n", print_str); > > + for_each_set_bit(i, riscv_isa, RISCV_ISA_EXT_MAX) { > + j = riscv_isa_ext2key(i); > + if (j >= 0) > + static_branch_enable(&riscv_isa_ext_keys[j]); > + } > #ifdef CONFIG_FPU > if (elf_hwcap & (COMPAT_HWCAP_ISA_F | COMPAT_HWCAP_ISA_D)) > static_branch_enable(&cpu_hwcap_fpu); > -- > 2.34.1 >