Received: by 2002:a05:7412:1703:b0:e2:908c:2ebd with SMTP id dm3csp2405677rdb; Mon, 28 Aug 2023 03:31:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF15lm38DFn+KDGhhzIT6RxmHvaT8voz438WtfQEb3LXsn/sGdzBrljZfxcFVFXWuQO84fq X-Received: by 2002:ac2:5449:0:b0:500:b14a:cc63 with SMTP id d9-20020ac25449000000b00500b14acc63mr4015352lfn.12.1693218685396; Mon, 28 Aug 2023 03:31:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693218685; cv=none; d=google.com; s=arc-20160816; b=tbRrL2Lz0dP62cOit4cCZ7vQ+2azTzjyW4iHQmvLZbMitbcy46RMyKOlVyn3/9YYbW 24iKfuizZHfrtD+2Uy+fQT0ReOtW6IDExG6B68V+8z6Tz9JR3RlIk2JUf3YsjwNfIZMU MzWZMnBwqNcjJReVqmUbyy3fqbu5eoC5lhd6XDYqDShlw8/HzUn62UBOPMN6AJkqyFrD 5M7OdYclqzVrU9dqAmYuvMbV+1vMeWp+rBY4IQmFxNcHeZM2XgO2TaTWcmFmUPLS91up vudyiWaOTRLKCbv8rTkaolZw8mC5Xju1mD9nCdtNWN8S6ttDEp4r6O+XTJfcy37j2QKe PJog== 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=8YtdOwQbF3keZeKkYPwEpkytdCRHXfXHS764nRx6jNs=; fh=1yFZvEczQ0M6q8bKSiyJWWs96oCK5+IxBf7YqlUles8=; b=JAtaHuZsl/onxawjo0I/ZGcX5/o2zZJ4LYD9yvWT3l9mPOKOGEbIqi+uy+cBtiPlkg Kn0HoiHTSMCZAyukVuJ7GVF8iUNmzMLL9D1B78jbHtoRsSl/sZWSmMquG/5xQEx1BVsY xsYW1g2+QigNsfbUs3CGQ5vhZRqZVLG+kLtegg/cPwUnI0Gv7UwlNLfeCARt14ttlOBk ZBs6yoI72sQ0qhCJuHCwAFVcwrMDRTnVl+ZEfgnY2IAlHkIImGTTUnl9hBYl3jAoEbQC UKFetDh1GVMGcN8BfOqbiKd/jTyJ1u+hutsmApFno8MqIVf9zf+eSNE6fPbMuOmYVcRW bNVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ET27Az6r; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p23-20020a170906839700b009889b69c1edsi4431699ejx.697.2023.08.28.03.30.30; Mon, 28 Aug 2023 03:31:25 -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=@kernel.org header.s=k20201202 header.b=ET27Az6r; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231240AbjH1K2g (ORCPT + 99 others); Mon, 28 Aug 2023 06:28:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231425AbjH1K2b (ORCPT ); Mon, 28 Aug 2023 06:28:31 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56B3119A; Mon, 28 Aug 2023 03:28:24 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3609563BC7; Mon, 28 Aug 2023 10:28:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9B186C433C9; Mon, 28 Aug 2023 10:28:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1693218503; bh=n4XE7nxHzlz8l0Qrwy0GwtxS3jAaS4ZgOwDJ7QBRvMM=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=ET27Az6rATIIp9xTqGzMsJiDJ4oiH1GvmgM9gOR9s7J7H7cSv76GEx9ldL7/JMQeO ExJldwFcv2I95wkwSkTCX7rer3fUFVuTfJjpM+pfFx+kA+W49ib0+hEQ/xRSA1uiSN IFBsegGUQAfMXrsI1hRWSquPpQ1JvwD6v4bQ1Vn3S7tut/kKpRC/MSCC74Q5Afa18o V2XtmMvpkRswzCkC0T4THDncHwjfqCM61zy7StNNcVmkyqZ5a434c6oeXOBFge5W24 //TQnh34uEheMdhBvcx38ooqHUscmeT6YfANwhePuUO8jKgXABX5PMtVHRElaHRdOd Deq/GSrJUlr5A== Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-50078eba7afso4780914e87.0; Mon, 28 Aug 2023 03:28:23 -0700 (PDT) X-Gm-Message-State: AOJu0YxTaGGCGaHqewRXHdP8J42pUJ0fCWG6NRu/UaQhskAePfJ1bxlH UQLC9Vp48xc/4RSW1j7a7ElLOioxUAKRBHBm+U0= X-Received: by 2002:a05:6512:220c:b0:4f4:b13a:d683 with SMTP id h12-20020a056512220c00b004f4b13ad683mr22435552lfu.69.1693218501656; Mon, 28 Aug 2023 03:28:21 -0700 (PDT) MIME-Version: 1.0 References: <20230806024715.3061589-1-xiao.w.wang@intel.com> In-Reply-To: From: Ard Biesheuvel Date: Mon, 28 Aug 2023 12:28:09 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] RISC-V: Optimize bitops with Zbb extension To: "Wang, Xiao W" Cc: "paul.walmsley@sifive.com" , "palmer@dabbelt.com" , "aou@eecs.berkeley.edu" , "anup@brainfault.org" , "Li, Haicheng" , "linux-riscv@lists.infradead.org" , "linux-efi@vger.kernel.org" , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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 Sun, 27 Aug 2023 at 11:26, Wang, Xiao W wrote: > > Hi, > > A gentle ping. > Any other comments or suggestions for this patch? Or maybe we would review it in the Linux 6.7 development cycle? > This is going to be 6.7 material at the earliest in any case. I am fine with the change as far as the EFI code is concerned, but I'd suggest dropping EFI_ from the macro name, as it could be #define'd for other reasons too. > > > -----Original Message----- > > From: Wang, Xiao W > > Sent: Sunday, August 6, 2023 6:24 PM > > To: Ard Biesheuvel > > Cc: paul.walmsley@sifive.com; palmer@dabbelt.com; > > aou@eecs.berkeley.edu; anup@brainfault.org; Li, Haicheng > > ; linux-riscv@lists.infradead.org; linux- > > efi@vger.kernel.org; linux-kernel@vger.kernel.org > > Subject: RE: [PATCH] RISC-V: Optimize bitops with Zbb extension > > > > Hi, > > > > > -----Original Message----- > > > From: Ard Biesheuvel > > > Sent: Sunday, August 6, 2023 5:39 PM > > > To: Wang, Xiao W > > > Cc: paul.walmsley@sifive.com; palmer@dabbelt.com; > > > aou@eecs.berkeley.edu; anup@brainfault.org; Li, Haicheng > > > ; linux-riscv@lists.infradead.org; linux- > > > efi@vger.kernel.org; linux-kernel@vger.kernel.org > > > Subject: Re: [PATCH] RISC-V: Optimize bitops with Zbb extension > > > > > > On Sun, 6 Aug 2023 at 04:39, Xiao Wang wrote: > > > > > > > > This patch leverages the alternative mechanism to dynamically optimize > > > > bitops (including __ffs, __fls, ffs, fls) with Zbb instructions. When > > > > Zbb ext is not supported by the runtime CPU, legacy implementation is > > > > used. If Zbb is supported, then the optimized variants will be selected > > > > via alternative patching. > > > > > > > > The legacy bitops support is taken from the generic C implementation as > > > > fallback. > > > > > > > > If the parameter is a build-time constant, we leverage compiler builtin to > > > > calculate the result directly, this approach is inspired by x86 bitops > > > > implementation. > > > > > > > > EFI stub runs before the kernel, so alternative mechanism should not be > > > > used there, this patch introduces a macro EFI_NO_ALTERNATIVE for this > > > > purpose. > > > > > > > > > > Why? The unpatched sequences work fine, no? > > > > It works. But there would be build warning: orphan section `.init.alternative' > > from `./drivers/firmware/efi/libstub/gop.stub.o' being placed in section > > `.init.alternative'. Besides, w/o this MACRO, the optimized variant would > > never be used at runtime, so this patch choose to disable alternative. > > > > BRs, > > Xiao > > > > > > > > > > > > Signed-off-by: Xiao Wang > > > > --- > > > > arch/riscv/include/asm/bitops.h | 266 > > +++++++++++++++++++++++++- > > > > drivers/firmware/efi/libstub/Makefile | 2 +- > > > > 2 files changed, 264 insertions(+), 4 deletions(-) > > > > > > > > diff --git a/arch/riscv/include/asm/bitops.h > > > b/arch/riscv/include/asm/bitops.h > > > > index 3540b690944b..f727f6489cd5 100644 > > > > --- a/arch/riscv/include/asm/bitops.h > > > > +++ b/arch/riscv/include/asm/bitops.h > > > > @@ -15,13 +15,273 @@ > > > > #include > > > > #include > > > > > > > > +#if !defined(CONFIG_RISCV_ISA_ZBB) || defined(EFI_NO_ALTERNATIVE) > > > > #include > > > > -#include > > > > -#include > > > > #include > > > > +#include > > > > +#include > > > > + > > > > +#else > > > > +#include > > > > +#include > > > > + > > > > +#if (BITS_PER_LONG == 64) > > > > +#define CTZW "ctzw " > > > > +#define CLZW "clzw " > > > > +#elif (BITS_PER_LONG == 32) > > > > +#define CTZW "ctz " > > > > +#define CLZW "clz " > > > > +#else > > > > +#error "Unexpected BITS_PER_LONG" > > > > +#endif > > [...]