Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 656C2421F04; Thu, 26 Feb 2026 15:12:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772118739; cv=none; b=Po2iQX/FxA/1lxtEAKGi3HXa4MZyzbVPedg9jKO/WgOdKNhaPNbyU3GekdKBSV2zLsFA/MPAcaZoGxt8/IKkIPn0stybnaxXleKv5JoKQ58pwgiXTc2ZNJruTfYArKtvY+CThu2d5QQ5PXzHZ8I9K3u6vKmvZzPyxUbj64blBCY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772118739; c=relaxed/simple; bh=r43Ot/Gf+AkJHCAymfFONDwegkg1nJgXhSbrXGuVbME=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZJsLytBnb+WHPrA0V+iFd3qAmPDK9+z4JGMXsJFRLMSSrqhvnnWgOlqKzRPQ2ZESTIYsMY7wcDghykfEPqObH7+QGtERTQ+qkp5e5PhypdT3sVHeOInIBRzlG7wxHV+jQ4je+gKUyd1YTqE+j2JSG5tCbRaZXH88cYmz6K/ej+E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=0lLke88Z; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="0lLke88Z" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=dnAqm1mQgBL7YCaDnwjea9MVbvJi6fB59bRdgxzHRfQ=; b=0lLke88ZORd7FsP4CXpACuAHde G+oGLjzsBhaZHraeqqDivfxfZWCm4ROZxEFdgYr1SqqrHyaZMGKmnU0TC9tNkr4CT420xJEzxh9Lx K/RLoOseLaA94JEjz/WZ9ATki+rNhCPZRBNOnEn8lXDJCqZOClP5EWYyzrJC9gyWYIy3CnZitFvtH k3HWnv0fDpBhz5YMPmXsLWiQQkOdYZWJnJ8CX2ukw7Pg8kW8rslvn913bFW6BP4sSazhwrve1Ld2Q EOgMxPX5svvrd6cMQB6Uov1O9PUtVxtVdVUoj9XmVxFNfJaXZemUFGVQSO215kU+ZiD9757bDT/dH BXSJUfgQ==; Received: from [4.28.11.157] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1vvd1q-00000006Qsd-3Nhg; Thu, 26 Feb 2026 15:11:50 +0000 From: Christoph Hellwig To: Andrew Morton Cc: Richard Henderson , Matt Turner , Magnus Lindholm , Russell King , Catalin Marinas , Will Deacon , Huacai Chen , WANG Xuerui , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , "Christophe Leroy (CS GROUP)" , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , "David S. Miller" , Andreas Larsson , Richard Weinberger , Anton Ivanov , Johannes Berg , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Herbert Xu , Dan Williams , Chris Mason , David Sterba , Arnd Bergmann , Song Liu , Yu Kuai , Li Nan , linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, loongarch@lists.linux.dev, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, linux-um@lists.infradead.org, linux-crypto@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-arch@vger.kernel.org, linux-raid@vger.kernel.org Subject: [PATCH 25/25] xor: use static_call for xor_gen Date: Thu, 26 Feb 2026 07:10:37 -0800 Message-ID: <20260226151106.144735-26-hch@lst.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260226151106.144735-1-hch@lst.de> References: <20260226151106.144735-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-alpha@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Avoid the indirect call for xor_generation by using a static_call. Signed-off-by: Christoph Hellwig --- lib/raid/xor/xor-32regs.c | 2 +- lib/raid/xor/xor-core.c | 29 ++++++++++++++--------------- lib/raid/xor/xor_impl.h | 4 ++++ 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/lib/raid/xor/xor-32regs.c b/lib/raid/xor/xor-32regs.c index acb4a10d1e95..759a31f76414 100644 --- a/lib/raid/xor/xor-32regs.c +++ b/lib/raid/xor/xor-32regs.c @@ -209,7 +209,7 @@ xor_32regs_5(unsigned long bytes, unsigned long * __restrict p1, } while (--lines > 0); } -DO_XOR_BLOCKS(32regs, xor_32regs_2, xor_32regs_3, xor_32regs_4, xor_32regs_5); +__DO_XOR_BLOCKS(32regs, xor_32regs_2, xor_32regs_3, xor_32regs_4, xor_32regs_5); struct xor_block_template xor_block_32regs = { .name = "32regs", diff --git a/lib/raid/xor/xor-core.c b/lib/raid/xor/xor-core.c index f18dcc57004b..2ab03dd294bf 100644 --- a/lib/raid/xor/xor-core.c +++ b/lib/raid/xor/xor-core.c @@ -11,10 +11,14 @@ #include #include #include +#include #include "xor_impl.h" -/* The xor routine to use. */ -static struct xor_block_template *active_template; +/* + * Provide a temporary default until the fastest or forced implementation is + * picked. + */ +DEFINE_STATIC_CALL(xor_gen_impl, xor_gen_32regs); /** * xor_gen - generate RAID-style XOR information @@ -32,13 +36,13 @@ static struct xor_block_template *active_template; void xor_gen(void *dest, void **srcs, unsigned int src_cnt, unsigned int bytes) { WARN_ON_ONCE(in_interrupt()); - active_template->xor_gen(dest, srcs, src_cnt, bytes); + static_call(xor_gen_impl)(dest, srcs, src_cnt, bytes); } EXPORT_SYMBOL(xor_gen); /* Set of all registered templates. */ static struct xor_block_template *__initdata template_list; -static int __initdata xor_forced = false; +static struct xor_block_template *forced_template; /** * xor_register - register a XOR template @@ -64,7 +68,7 @@ void __init xor_register(struct xor_block_template *tmpl) */ void __init xor_force(struct xor_block_template *tmpl) { - active_template = tmpl; + forced_template = tmpl; } #define BENCH_SIZE 4096 @@ -106,7 +110,7 @@ static int __init calibrate_xor_blocks(void) void *b1, *b2; struct xor_block_template *f, *fastest; - if (xor_forced) + if (forced_template) return 0; b1 = (void *) __get_free_pages(GFP_KERNEL, 2); @@ -123,7 +127,7 @@ static int __init calibrate_xor_blocks(void) if (f->speed > fastest->speed) fastest = f; } - active_template = fastest; + static_call_update(xor_gen_impl, fastest->xor_gen); pr_info("xor: using function: %s (%d MB/sec)\n", fastest->name, fastest->speed); @@ -151,21 +155,16 @@ static int __init xor_init(void) * If this arch/cpu has a short-circuited selection, don't loop through * all the possible functions, just use the best one. */ - if (active_template) { + if (forced_template) { pr_info("xor: automatically using best checksumming function %-10s\n", - active_template->name); - xor_forced = true; + forced_template->name); + static_call_update(xor_gen_impl, forced_template->xor_gen); return 0; } #ifdef MODULE return calibrate_xor_blocks(); #else - /* - * Pick the first template as the temporary default until calibration - * happens. - */ - active_template = template_list; return 0; #endif } diff --git a/lib/raid/xor/xor_impl.h b/lib/raid/xor/xor_impl.h index 968dd07df627..f11910162b08 100644 --- a/lib/raid/xor/xor_impl.h +++ b/lib/raid/xor/xor_impl.h @@ -50,6 +50,10 @@ extern struct xor_block_template xor_block_32regs; extern struct xor_block_template xor_block_8regs_p; extern struct xor_block_template xor_block_32regs_p; +/* default call until updated */ +void xor_gen_32regs(void *dest, void **srcs, unsigned int src_cnt, + unsigned int bytes); + void __init xor_register(struct xor_block_template *tmpl); void __init xor_force(struct xor_block_template *tmpl); -- 2.47.3