Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp105997iob; Tue, 17 May 2022 20:21:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzwf3tBSqhsv9fo8ogTckgH0gevbT8K4DkDACGIfcw2krRZVZY8JB6ygnKNPX3qCgXhACPt X-Received: by 2002:a17:903:2c8:b0:161:51d6:61b with SMTP id s8-20020a17090302c800b0016151d6061bmr18664852plk.23.1652844111607; Tue, 17 May 2022 20:21:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652844111; cv=none; d=google.com; s=arc-20160816; b=SdUEAL6cPpwMITOMT2qFuHcydE4pd5qJxfLDzV+zyS/JYV0roZ7PhB+vnCYczpbbln YS5bvBIDyZ4EA1rTnzSYpapi6gnCqR2BYS8pN0V9RIO0halQDCpnZy4osTV6CCN7eX63 vAbdUCF4nlBKh39L0qsAk6EIp//bBxaCcT9YWNxW5KaofRuzEv3Sh41T6pwupKvEJW8z 4RiMcedrDTc9gsbJBbH0kaXbm49axrWAywrePuUUNMIJuTrB1qQd1qwg51vo52v1jixv W39Uy6IDUx9T7+4+fM1IZnKkM2iV/KnBB7eV3H14sIAJS9XKJ4/5Ck8C7bUP8S7xm9Vz HMTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=yscMU/RU+AXLwmB6v1rGAUVcwDvl6A89GKD2cL8coQ4=; b=P1BjgRcWx99owAJn94oMiQ4jEK9z6kHLjfWkPAxF28mkW6Kp7rESpV2X6cFNQ0TaIq Hd+JMPCUpFI/b3GpVN03zszAKU7BV310ce0cmiPOQ/KWxH06huOFJJ5yiPWCg78Y3cG1 yqE52n1HsEtU3uAL5u/yQYMH+rlnJeOhFFhzPrreKOtcZqVbb0rCsAyzdiijXgIdBAap pTjt/CVbeQVHo5C9eBMosRzLr89iNR08ilwtvOg5AFSDJON4bSFofmt4MihkUWSyL9nQ mNbhoViulFCMTh+hZ57mEZmNsVpmTK7dbjGNP/dLwIPw8N5N3owLODrE3GrnMhadOJ0e 7+8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hQeQSS+V; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id b15-20020a63cf4f000000b003c19e2b283esi949134pgj.494.2022.05.17.20.21.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 20:21:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hQeQSS+V; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BD4085DA5E; Tue, 17 May 2022 20:20:37 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242984AbiEQQmq (ORCPT + 99 others); Tue, 17 May 2022 12:42:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351106AbiEQQmp (ORCPT ); Tue, 17 May 2022 12:42:45 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE1EC403D7 for ; Tue, 17 May 2022 09:42:43 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 82EB9B8181B for ; Tue, 17 May 2022 16:42:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 73A2DC385B8; Tue, 17 May 2022 16:42:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1652805761; bh=1IrxNJ1bp3kbA2oD6OHuufL2ZTrxl/ACrlKCvG7jTxQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=hQeQSS+V1lj64xDAGzkxKJCHnkihMRbBKk2KbalQc+XmCt4HPchv4lCVWrSfzd2Od 5K9XN4lutNDsC40vvqk8mXq0gt+/ob0xmC3xmHOjP5iI7Kh/J2VY2WTe5UVmzEk3uH YDKCHwuDl7AEKV/0qhQOD4dXaCjUxV7iIGJlNg1kxu7e/RDsyVbHof/Vr2HYcw2FXG Vdmt22FdW9mQG5UDeUIpwIXE5D3u+PeV5Dt6Aie3aCTujOhLapO+j8pGhnxZKoPV4Q Izz8BTiWQmqm8/WksnkH830yWMBwQZe8w3ylhaGQ85eS+VAL26Dlw2J0L8CNHZCqtg EsTsYVHVsDQfg== Date: Wed, 18 May 2022 00:33:52 +0800 From: Jisheng Zhang To: Anup Patel Cc: Anup Patel , Atish Patra , Paul Walmsley , Palmer Dabbelt , Albert Ou , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , Alexandre Ghiti , linux-riscv , "linux-kernel@vger.kernel.org List" , kasan-dev@googlegroups.com Subject: Re: [PATCH v2 2/4] riscv: introduce unified static key mechanism for CPU features Message-ID: References: <20220508160749.984-1-jszhang@kernel.org> <20220508160749.984-3-jszhang@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Tue, May 17, 2022 at 09:31:50AM +0530, Anup Patel wrote: > On Mon, May 16, 2022 at 11:02 PM Jisheng Zhang wrote: > > ... > > Currently, RISCV_ISA_EXT_MAX equals to 64 while the base ID is 26. > > In those 26 base IDs, only F/D and V need static key, it means > > we waste at least 24 static keys. > > If you want to save space of unused static keys then there are other > ways. > > For example, you can create a small static key array which has > many-to-one relation with the ISA extension numbers. For ISA extension "any problem in computer science can be solved with another layer of indirection" ;) I see your points, thanks very much! But I think the array should be a static inline function to make use of compiler optimization to avoid the array references for performance. And the static key check maybe used in modules, I want to export less vars. I'm cooking the patches, will send out for review soon. > which are always ON or always OFF, we can use fixed FALSE and > TRUE keys. Something like below. > > enum riscv_isa_ext_key { > RISCV_ISA_EXT_KEY_FALSE = 0, > RISCV_ISA_EXT_KEY_TRUE, > RISCV_ISA_EXT_KEY_FLOAD, /* For 'F' and 'D' */ > RISCV_ISA_EXT_KEY_VECTOR, /* For all vector extensions */ > RISCV_ISA_EXT_KEY_SVINVAL, > RISCV_ISA_EXT_KEY_SSCOFPMT, > RISCV_ISA_EXT_KEY_MAX, > }; > > extern unsigned char __riscv_isa_ext_id2key[RISCV_ISA_EXT_ID_MAX]; > extern struct static_key_false __riscv_isa_ext_keys[RISCV_ISA_EXT_KEY_MAX]; > > static __always_inline bool __riscv_isa_extension_keycheck(unsigned int ext) > { > if (RISCV_ISA_EXT_ID_MAX <= ext) > return false; > return static_branch_unlikely(&__riscv_isa_ext_keys[__riscv_isa_ext_id2key[ext]]); > } > #define riscv_isa_extension_keycheck(ext) \ > __riscv_isa_extension_keycheck(RISCV_ISA_EXT_##ext) >