[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <288c7d1d-e1b4-4ea1-8877-8b7de033b24a@ghiti.fr>
Date: Thu, 12 Jun 2025 15:00:33 +0200
From: Alexandre Ghiti <alex@...ti.fr>
To: Kuan-Wei Chiu <visitorckw@...il.com>, paul.walmsley@...ive.com,
palmer@...belt.com, aou@...s.berkeley.edu, akpm@...ux-foundation.org
Cc: linux-riscv@...ts.infradead.org, linux-kernel@...r.kernel.org,
jserv@...s.ncku.edu.tw, Yu-Chun Lin <eleanor15x@...il.com>
Subject: Re: [PATCH v3 3/3] riscv: Optimize gcd() performance on RISC-V
without Zbb extension
On 6/6/25 15:47, Kuan-Wei Chiu wrote:
> The binary GCD implementation uses FFS (find first set), which benefits
> from hardware support for the ctz instruction, provided by the Zbb
> extension on RISC-V. Without Zbb, this results in slower
> software-emulated behavior.
>
> Previously, RISC-V always used the binary GCD, regardless of actual
> hardware support. This patch improves runtime efficiency by disabling
> the efficient_ffs_key static branch when Zbb is either not enabled in
> the kernel (config) or not supported on the executing CPU. This selects
> the odd-even GCD implementation, which is faster in the absence of
> efficient FFS.
>
> This change ensures the most suitable GCD algorithm is chosen
> dynamically based on actual hardware capabilities.
>
> Co-developed-by: Yu-Chun Lin <eleanor15x@...il.com>
> Signed-off-by: Yu-Chun Lin <eleanor15x@...il.com>
> Signed-off-by: Kuan-Wei Chiu <visitorckw@...il.com>
> ---
> arch/riscv/kernel/setup.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
> index f7c9a1caa83e..785c7104fde7 100644
> --- a/arch/riscv/kernel/setup.c
> +++ b/arch/riscv/kernel/setup.c
> @@ -21,6 +21,8 @@
> #include <linux/efi.h>
> #include <linux/crash_dump.h>
> #include <linux/panic_notifier.h>
> +#include <linux/jump_label.h>
> +#include <linux/gcd.h>
>
> #include <asm/acpi.h>
> #include <asm/alternative.h>
> @@ -361,6 +363,9 @@ void __init setup_arch(char **cmdline_p)
>
> riscv_user_isa_enable();
> riscv_spinlock_init();
> +
> + if (!IS_ENABLED(CONFIG_RISCV_ISA_ZBB) || !riscv_isa_extension_available(NULL, ZBB))
> + static_branch_disable(&efficient_ffs_key);
> }
>
> bool arch_cpu_is_hotpluggable(int cpu)
Acked-by: Alexandre Ghiti <alexghiti@...osinc.com>
Thanks,
Alex
Powered by blists - more mailing lists