cleanup the RAID5 XOR library v3
Subsystems (16)
Hi all,
the XOR library used for the RAID5 parity is a bit of a mess right now. The main file sits in crypto/ despite not being cryptography and not using the crypto API, with the generic implementations sitting in include/asm-generic and the arch implementations sitting in an asm/ header in theory. The latter doesn't work for many cases, so architectures often build the code directly into the core kernel, or create another module for the architecture code.
Changes this to a single module in lib/ that also contains the architecture optimizations, similar to the library work Eric Biggers has done for the CRC and crypto libraries later. After that it changes to better calling conventions that allow for smarter architecture implementations (although none is contained here yet), and uses static_call to avoid indirection function call overhead.
A git tree is also available here:
git://git.infradead.org/users/hch/misc.git xor-improvements
Gitweb:
https://git.infradead.org/?p=users/hch/misc.git;a=shortlog;h=refs/heads/xor-improvements
Changes since v2:
- drop use of CONFIG_KERNEL_MODE_NEON for arm64
- drop the new __limit_random_u32_below for the unit test
- require 64-bit alignment because sparc64 requires it
- use DEFINE_STATIC_CALL_NULL to avoid exposing a specific xor_gen routine
- keep CONFIG_XOR_BLOCKS_ARCH self-contained in lib/raid/
- don't select library option from kunit test and add a .kunitconfig instead
- fix the module description for the kunit test
- add a case where buffers are at the end of the allocation in the kunit test
- use separate src/dst alignment in the kunit test
- fix and improve the kunit assert message
Changes since v1:
- use lockdep_assert_preemption_enabled()
- improve the commit message for the initial um xor.h cleanup
- further clean up the um arch specific header
- add SPDX identifier to the new build system files
- use bool for xor_forced
- fix an incorrect printk level conversion from warn to info
- include xor_impl.h in xor-neon.c
- remove unused exports for riscv
- simply move the sparc code instead of splititng it
- simplify the makefile for the x86-specific implementations
- remove stray references to xor_blocks in crypto/async_tx
- rework __DO_XOR_BLOCKS to avoid (theoretical) out of bounds references
- improve the kerneldoc API documentration for xor_gen()
- spell the name of the srcs argument to xor_gen correctly in xor.h
- add a kunit test, and a new random helper for it.
Diffstat:
arch/arm64/include/asm/xor.h | 73 -- arch/loongarch/include/asm/xor.h | 68 -- arch/loongarch/include/asm/xor_simd.h | 34 - arch/loongarch/lib/xor_simd_glue.c | 72 -- arch/powerpc/include/asm/xor.h | 47 - arch/powerpc/include/asm/xor_altivec.h | 22 arch/powerpc/lib/xor_vmx.h | 22 arch/powerpc/lib/xor_vmx_glue.c | 63 -- arch/riscv/include/asm/xor.h | 68 -- arch/s390/include/asm/xor.h | 21 arch/sparc/include/asm/xor.h | 9 arch/um/include/asm/xor.h | 24 arch/x86/include/asm/xor_64.h | 28 - b/arch/arm/lib/Makefile | 5 b/arch/arm64/lib/Makefile | 6 b/arch/loongarch/lib/Makefile | 2 b/arch/powerpc/lib/Makefile | 5 b/arch/riscv/lib/Makefile | 1 b/arch/s390/lib/Makefile | 2 b/arch/sparc/include/asm/asm-prototypes.h | 1 b/arch/sparc/lib/Makefile | 2 b/crypto/Kconfig | 2 b/crypto/Makefile | 1 b/crypto/async_tx/async_xor.c | 34 - b/fs/btrfs/raid56.c | 27 - b/include/asm-generic/Kbuild | 1 b/include/linux/raid/xor.h | 27 - b/lib/Kconfig | 1 b/lib/Makefile | 2 b/lib/raid/.kunitconfig | 3 b/lib/raid/Kconfig | 30 + b/lib/raid/Makefile | 3 b/lib/raid/xor/Makefile | 42 + b/lib/raid/xor/alpha/xor.c | 46 - b/lib/raid/xor/alpha/xor_arch.h | 22 b/lib/raid/xor/arm/xor-neon-glue.c | 19 b/lib/raid/xor/arm/xor-neon.c | 22 b/lib/raid/xor/arm/xor.c | 105 ---- b/lib/raid/xor/arm/xor_arch.h | 22 b/lib/raid/xor/arm64/xor-neon-glue.c | 26 + b/lib/raid/xor/arm64/xor-neon.c | 94 +-- b/lib/raid/xor/arm64/xor-neon.h | 6 b/lib/raid/xor/arm64/xor_arch.h | 21 b/lib/raid/xor/loongarch/xor_arch.h | 33 + b/lib/raid/xor/loongarch/xor_simd_glue.c | 37 + b/lib/raid/xor/powerpc/xor_arch.h | 22 b/lib/raid/xor/powerpc/xor_vmx.c | 40 - b/lib/raid/xor/powerpc/xor_vmx.h | 10 b/lib/raid/xor/powerpc/xor_vmx_glue.c | 28 + b/lib/raid/xor/riscv/xor-glue.c | 25 + b/lib/raid/xor/riscv/xor.S | 4 b/lib/raid/xor/riscv/xor_arch.h | 17 b/lib/raid/xor/s390/xor.c | 15 b/lib/raid/xor/s390/xor_arch.h | 13 b/lib/raid/xor/sparc/xor-sparc32.c | 32 - b/lib/raid/xor/sparc/xor-sparc64-glue.c | 48 - b/lib/raid/xor/sparc/xor-sparc64.S | 10 b/lib/raid/xor/sparc/xor_arch.h | 35 + b/lib/raid/xor/tests/Makefile | 3 b/lib/raid/xor/tests/xor_kunit.c | 187 +++++++ b/lib/raid/xor/um/xor_arch.h | 2 b/lib/raid/xor/x86/xor-avx.c | 52 -- b/lib/raid/xor/x86/xor-mmx.c | 120 +--- b/lib/raid/xor/x86/xor-sse.c | 105 +--- b/lib/raid/xor/x86/xor_arch.h | 36 + b/lib/raid/xor/xor-32regs-prefetch.c | 267 ++++++++++ b/lib/raid/xor/xor-32regs.c | 217 ++++++++ b/lib/raid/xor/xor-8regs-prefetch.c | 146 +++++ b/lib/raid/xor/xor-8regs.c | 103 ++++ b/lib/raid/xor/xor-core.c | 192 +++++++ b/lib/raid/xor/xor_impl.h | 56 ++ crypto/xor.c | 174 ------- include/asm-generic/xor.h | 738 ------------------------------ 73 files changed, 1831 insertions(+), 2067 deletions(-)
PATCH 1/26 xor: assert that xor_blocks is not from preemptible user context
Most of the optimized xor_blocks versions require FPU/vector registers, which generally are not supported in interrupt context.
Both callers already are in user context, so enforce this at the highest level.
--- crypto/xor.c | 2 ++ 1 file changed, 2 insertions(+)
crypto/xor.c +2 -0
@@ -28,6 +28,8 @@ xor_blocks(unsigned int src_count, unsigned int bytes, void *dest, void **srcs) {unsigned long *p1, *p2, *p3, *p4; +lockdep_assert_preemption_enabled (); + p1 = (unsigned long *) srcs[0 ];if (src_count ==1 ) { active_template->do_2 (bytes, dest, p1);
Signature · 1 line
2.47.3
PATCH 2/26 arm/xor: remove in_interrupt() handling
In reply to Christoph Hellwigxor_blocks can't be called from interrupt context, so remove the handling for that.
--- arch/arm/include/asm/xor.h | 41 +++++++++++--------------------------- 1 file changed, 12 insertions(+), 29 deletions(-)
arch/arm/include/asm/xor.h +12 -29
@@ -4,7 +4,6 @@* * Copyright (C) 2001 Russell King */ -#include <linux/hardirq.h> #include <asm-generic/xor.h> #include <asm/hwcap.h> #include <asm/neon.h>
@@ -156,13 +155,9 @@ static void xor_neon_2(unsigned long bytes, unsigned long * __restrict p1, const unsigned long * __restrict p2) { - if (in_interrupt()) { -xor_arm4regs_2 (bytes, p1, p2); - } else { -kernel_neon_begin (); - xor_block_neon_inner.do_2 (bytes, p1, p2); -kernel_neon_end (); - } +kernel_neon_begin (); + xor_block_neon_inner.do_2 (bytes, p1, p2); +kernel_neon_end (); } static void
@@ -170,13 +165,9 @@ xor_neon_3(unsigned long bytes, unsigned long * __restrict p1,const unsigned long * __restrict p2, const unsigned long * __restrict p3) { - if (in_interrupt()) { -xor_arm4regs_3 (bytes ,p1 ,p2 ,p3 ); - } else { -kernel_neon_begin (); - xor_block_neon_inner.do_3 (bytes, p1, p2, p3); -kernel_neon_end (); - } +kernel_neon_begin (); + xor_block_neon_inner.do_3 (bytes, p1, p2, p3); +kernel_neon_end (); } static void
@@ -185,13 +176,9 @@ xor_neon_4(unsigned long bytes, unsigned long * __restrict p1,const unsigned long * __restrict p3, const unsigned long * __restrict p4) { - if (in_interrupt()) { -xor_arm4regs_4 (bytes ,p1 ,p2 ,p3 ,p4 ); - } else { -kernel_neon_begin (); - xor_block_neon_inner.do_4 (bytes, p1, p2, p3, p4); -kernel_neon_end (); - } +kernel_neon_begin (); + xor_block_neon_inner.do_4 (bytes, p1, p2, p3, p4); +kernel_neon_end (); } static void
@@ -201,13 +188,9 @@ xor_neon_5(unsigned long bytes, unsigned long * __restrict p1,const unsigned long * __restrict p4, const unsigned long * __restrict p5) { - if (in_interrupt()) { -xor_arm4regs_5 (bytes ,p1 ,p2 ,p3 ,p4 ,p5 ); - } else { -kernel_neon_begin (); - xor_block_neon_inner.do_5 (bytes, p1, p2, p3, p4, p5); -kernel_neon_end (); - } +kernel_neon_begin (); + xor_block_neon_inner.do_5 (bytes, p1, p2, p3, p4, p5); +kernel_neon_end (); } static struct xor_block_template xor_block_neon = {
Signature · 1 line
2.47.3
PATCH 3/26 um/xor: cleanup xor.h
In reply to Christoph HellwigSince commit c055e3eae0f1 ("crypto: xor - use ktime for template benchmarking") the benchmarking works just fine even for TT_MODE_INFCPU, so drop the workarounds. Note that for CPUs supporting AVX2, which includes almost everything built in the last 10 years, the AVX2 implementation is forced anyway.
CONFIG_X86_32 is always correctly set for UM in arch/x86/um/Kconfig, so don't override it either.
--- arch/um/include/asm/xor.h | 16 ---------------- 1 file changed, 16 deletions(-)
arch/um/include/asm/xor.h +0 -16
@@ -2,23 +2,7 @@#ifndef _ASM_UM_XOR_H#define _ASM_UM_XOR_H -#ifdef CONFIG_64BIT -#undef CONFIG_X86_32 -#define TT_CPU_INF_XOR_DEFAULT (AVX_SELECT(&xor_block_sse_pf64)) -#else -#define CONFIG_X86_32 1 -#define TT_CPU_INF_XOR_DEFAULT (AVX_SELECT(&xor_block_8regs)) -#endif -#include <asm/cpufeature.h> #include <../../x86/include/asm/xor.h> -#include <linux/time-internal.h> - -#ifdef CONFIG_UML_TIME_TRAVEL_SUPPORT -#undef XOR_SELECT_TEMPLATE -/* pick an arbitrary one - measuring isn't possible with inf-cpu */ -#define XOR_SELECT_TEMPLATE (x) \ - (time_travel_mode == TT_MODE_INFCPU ? TT_CPU_INF_XOR_DEFAULT : x) -#endif #endif
Signature · 1 line
2.47.3
PATCH 4/26 xor: move to lib/raid/
In reply to Christoph HellwigMove the RAID XOR code to lib/raid/ as it has nothing to do with the crypto API.
--- crypto/Kconfig | 2 -- crypto/Makefile | 1 - lib/Kconfig | 1 + lib/Makefile | 2 +- lib/raid/Kconfig | 4 ++++ lib/raid/Makefile | 3 +++ lib/raid/xor/Makefile | 5 +++++ crypto/xor.c => lib/raid/xor/xor-core.c | 0 8 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 lib/raid/Kconfig create mode 100644 lib/raid/Makefile create mode 100644 lib/raid/xor/Makefile rename crypto/xor.c => lib/raid/xor/xor-core.c (100%)
crypto/Kconfig +0 -2
@@ -2,8 +2,6 @@ # # Generic algorithms support # -config XOR_BLOCKS - tristate # # async_tx api: hardware offloaded memory transfer/transform support
crypto/Makefile +0 -1
@@ -196,7 +196,6 @@ obj-$(CONFIG_CRYPTO_ECRDSA) += ecrdsa_generic.o # # generic algorithms and the async_tx api # -obj-$(CONFIG_XOR_BLOCKS) += xor.o obj-$(CONFIG_ASYNC_CORE) += async_tx/ obj-$(CONFIG_ASYMMETRIC_KEY_TYPE) += asymmetric_keys/ crypto_simd-y := simd.o
lib/Kconfig +1 -0
@@ -138,6 +138,7 @@ config TRACE_MMIO_ACCESS source "lib/crc/Kconfig" source "lib/crypto/Kconfig" +source "lib/raid/Kconfig" config XXHASH tristate
lib/Makefile +1 -1
@@ -120,7 +120,7 @@ endif obj-$(CONFIG_DEBUG_INFO_REDUCED) += debug_info.o CFLAGS_debug_info.o += $(call cc-option, -femit-struct-debug-detailed=any) -obj-y += math/ crc/ crypto/ tests/ vdso/ +obj-y += math/ crc/ crypto/ tests/ vdso/ raid/ obj-$(CONFIG_GENERIC_IOMAP) += iomap.o obj-$(CONFIG_HAS_IOMEM) += iomap_copy.o devres.o
lib/raid/Kconfig new file +4 -0
@@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0 + +config XOR_BLOCKS + tristate
lib/raid/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-y += xor/
lib/raid/xor/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_XOR_BLOCKS) += xor.o + +xor-y += xor-core.o
lib/raid/xor/xor-core.c renamed from crypto/xor.c +0 -0
Signature · 1 line
2.47.3
PATCH 5/26 xor: small cleanups
In reply to Christoph HellwigUpdate the to of file comment to be correct and non-redundant, and drop the unused BH_TRACE define.
--- lib/raid/xor/xor-core.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
lib/raid/xor/xor-core.c +1 -4
@@ -1,14 +1,11 @@// SPDX-License-Identifier: GPL-2.0-or-later /* -* xor.c : Multiple Devices driver for Linux -* * Copyright (C) 1996, 1997, 1998, 1999, 2000, * Ingo Molnar, Matti Aarnio, Jakub Jelinek, Richard Henderson. * -* Dispatch optimized RAID-5 checksumming functions. +* Dispatch optimized XOR parity functions. */ -#define BH_TRACE 0#include <linux/module.h> #include <linux/gfp.h> #include <linux/raid/xor.h>
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH 05/26] xor: small cleanups
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 4 lines
Update the to of file comment to be correct and non-redundant, and drop the unused
BH_TRACEdefine.Signed-off-by Christoph Hellwig <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
PATCH 6/26 xor: cleanup registration and probing
In reply to Christoph HellwigOriginally, the XOR code benchmarked all algorithms at load time, but it has since then been hacked multiple times to allow forcing an algorithm, and then commit 524ccdbdfb52 ("crypto: xor - defer load time benchmark to a later time") changed the logic to a two-step process or registration and benchmarking, but only when built-in.
Rework this, so that the XOR_TRY_TEMPLATES macro magic now always just deals with adding the templates to the list, and benchmarking is always done in a second pass; for modular builds from module_init, and for the built-in case using a separate init call level.
--- lib/raid/xor/xor-core.c | 98 ++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 50 deletions(-)
lib/raid/xor/xor-core.c +48 -50
@@ -52,29 +52,14 @@ EXPORT_SYMBOL(xor_blocks);/* Set of all registered templates. */ static struct xor_block_template *__initdata template_list; +static bool __initdata xor_forced = false; -#ifndef MODULE static void __init do_xor_register (struct xor_block_template *tmpl) { tmpl->next = template_list; template_list = tmpl; } -static int __init register_xor_blocks (void ) -{ - active_template =XOR_SELECT_TEMPLATE (NULL ); - -if (!active_template) { -#define xor_speed do_xor_register -// register all the templates and pick the first as the default -XOR_TRY_TEMPLATES ; -#undef xor_speed - active_template = template_list; - } -return 0 ; -} -#endif -#define BENCH_SIZE 4096#define REPS 800U
@@ -85,9 +70,6 @@ do_xor_speed(struct xor_block_template *tmpl, void *b1, void *b2)unsigned long reps;ktime_t min, start, t0; - tmpl->next = template_list; - template_list = tmpl; -preempt_disable (); reps =0 ;
@@ -111,63 +93,79 @@ do_xor_speed(struct xor_block_template *tmpl, void *b1, void *b2)pr_info (" %-16s: %5d MB/sec\n" , tmpl->name, speed); } -static int __init -calibrate_xor_blocks (void ) +static int __init calibrate_xor_blocks (void ) {void *b1, *b2;struct xor_block_template *f, *fastest; - fastest =XOR_SELECT_TEMPLATE (NULL ); - -if (fastest) { -printk (KERN_INFO "xor: automatically using best " -"checksumming function %-10s\n" , - fastest->name); - goto out; - } +if (xor_forced) +return 0 ; b1 = (void *)__get_free_pages (GFP_KERNEL ,2 );if (!b1) { -printk (KERN_WARNING "xor: Yikes! No memory available.\n" ); +pr_warn ("xor: Yikes! No memory available.\n" );return -ENOMEM ; } b2 = b1 +2 *PAGE_SIZE +BENCH_SIZE ; -/* -* If this arch/cpu has a short-circuited selection, don't loop through -* all the possible functions, just test the best one -*/ - -#define xor_speed (templ) do_xor_speed((templ), b1, b2) - -printk (KERN_INFO "xor: measuring software checksum speed\n" ); - template_list =NULL ; -XOR_TRY_TEMPLATES ; +pr_info ("xor: measuring software checksum speed\n" ); fastest = template_list; -for (f = fastest; f; f = f->next) +for (f = template_list; f; f = f->next) { +do_xor_speed (f, b1, b2);if (f->speed > fastest->speed) fastest = f; - + } + active_template = fastest;pr_info ("xor: using function: %s (%d MB/sec)\n" , fastest->name, fastest->speed); +free_pages ((unsigned long )b1,2 ); +return 0 ; +} + +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. +*/ + active_template =XOR_SELECT_TEMPLATE (NULL ); +if (active_template) { +pr_info ("xor: automatically using best checksumming function %-10s\n" , + active_template->name); + xor_forced = true; +return 0 ; + } + +#define xor_speed do_xor_register +XOR_TRY_TEMPLATES ;#undef xor_speed -free_pages ((unsigned long )b1,2 ); -out: - active_template = fastest; +#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 } -static __exit void xor_exit(void) { } +static __exit void xor_exit(void) +{ +}MODULE_DESCRIPTION ("RAID-5 checksumming functions" );MODULE_LICENSE ("GPL" ); +/* +* When built-in we must register the default template before md, but we don't +* want calibration to run that early as that would delay the boot process. +*/ #ifndef MODULE -/* when built-in xor.o must initialize before drivers/md/md.o */ -core_initcall (register_xor_blocks); +__initcall (calibrate_xor_blocks);#endif - -module_init (calibrate_xor_blocks); +core_initcall (xor_init);module_exit (xor_exit);
Signature · 1 line
2.47.3
PATCH 7/26 xor: split xor.h
In reply to Christoph HellwigKeep xor.h for the public API, and split the struct xor_block_template definition that is only needed by the xor.ko core and architecture-specific optimizations into a separate xor_impl.h header.
--- arch/arm/lib/xor-neon.c | 1 + arch/arm64/lib/xor-neon.c | 1 + arch/s390/lib/xor.c | 2 +- include/linux/raid/xor.h | 22 +--------------------- include/linux/raid/xor_impl.h | 25 +++++++++++++++++++++++++ lib/raid/xor/xor-core.c | 1 + 6 files changed, 30 insertions(+), 22 deletions(-) create mode 100644 include/linux/raid/xor_impl.h
arch/arm/lib/xor-neon.c +1 -0
@@ -6,6 +6,7 @@*/ #include <linux/raid/xor.h> +#include <linux/raid/xor_impl.h> #include <linux/module.h> MODULE_DESCRIPTION ("NEON accelerated XOR implementation" );
arch/arm64/lib/xor-neon.c +1 -0
@@ -7,6 +7,7 @@*/ #include <linux/raid/xor.h> +#include <linux/raid/xor_impl.h> #include <linux/module.h> #include <asm/neon-intrinsics.h>
arch/s390/lib/xor.c +1 -1
@@ -8,7 +8,7 @@#include <linux/types.h> #include <linux/export.h> -#include <linux/raid/xor.h> +#include <linux/raid/xor_impl.h> #include <asm/xor.h> static void xor_xc_2(unsigned long bytes, unsigned long * __restrict p1,
include/linux/raid/xor.h +1 -21
@@ -7,24 +7,4 @@extern void xor_blocks (unsigned int count,unsigned int bytes,void *dest,void **srcs); -struct xor_block_template { -struct xor_block_template *next; -const char *name; -int speed; -void (*do_2)(unsigned long ,unsigned long * __restrict, -const unsigned long * __restrict); -void (*do_3)(unsigned long ,unsigned long * __restrict, -const unsigned long * __restrict, -const unsigned long * __restrict); -void (*do_4)(unsigned long ,unsigned long * __restrict, -const unsigned long * __restrict, -const unsigned long * __restrict, -const unsigned long * __restrict); -void (*do_5)(unsigned long ,unsigned long * __restrict, -const unsigned long * __restrict, -const unsigned long * __restrict, -const unsigned long * __restrict, -const unsigned long * __restrict); -}; - -#endif +#endif /* _XOR_H */
include/linux/raid/xor_impl.h new file +25 -0
@@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _XOR_IMPL_H +#define _XOR_IMPL_H + +struct xor_block_template { +struct xor_block_template *next; +const char *name; +int speed; +void (*do_2)(unsigned long ,unsigned long * __restrict, +const unsigned long * __restrict); +void (*do_3)(unsigned long ,unsigned long * __restrict, +const unsigned long * __restrict, +const unsigned long * __restrict); +void (*do_4)(unsigned long ,unsigned long * __restrict, +const unsigned long * __restrict, +const unsigned long * __restrict, +const unsigned long * __restrict); +void (*do_5)(unsigned long ,unsigned long * __restrict, +const unsigned long * __restrict, +const unsigned long * __restrict, +const unsigned long * __restrict, +const unsigned long * __restrict); +}; + +#endif /* _XOR_IMPL_H */
lib/raid/xor/xor-core.c +1 -0
@@ -9,6 +9,7 @@#include <linux/module.h> #include <linux/gfp.h> #include <linux/raid/xor.h> +#include <linux/raid/xor_impl.h> #include <linux/jiffies.h> #include <linux/preempt.h> #include <asm/xor.h>
Signature · 1 line
2.47.3
PATCH 8/26 xor: remove macro abuse for XOR implementation registrations
In reply to Christoph HellwigDrop the pretty confusing historic XOR_TRY_TEMPLATES and XOR_SELECT_TEMPLATE, and instead let the architectures provide a arch_xor_init that calls either xor_register to register candidates or xor_force to force a specific implementation.
--- arch/alpha/include/asm/xor.h | 29 ++++++++++++---------- arch/arm/include/asm/xor.h | 25 +++++++++---------- arch/arm64/include/asm/xor.h | 18 +++++++------- arch/loongarch/include/asm/xor.h | 42 ++++++++++++-------------------- arch/powerpc/include/asm/xor.h | 31 ++++++++++------------- arch/riscv/include/asm/xor.h | 19 ++++++++------- arch/s390/include/asm/xor.h | 12 ++++----- arch/sparc/include/asm/xor_32.h | 14 +++++------ arch/sparc/include/asm/xor_64.h | 31 +++++++++++------------ arch/x86/include/asm/xor.h | 3 --- arch/x86/include/asm/xor_32.h | 36 ++++++++++++++------------- arch/x86/include/asm/xor_64.h | 18 ++++++++------ arch/x86/include/asm/xor_avx.h | 9 ------- include/asm-generic/xor.h | 8 ------ include/linux/raid/xor_impl.h | 5 ++++ lib/raid/xor/xor-core.c | 41 +++++++++++++++++++++++-------- 16 files changed, 168 insertions(+), 173 deletions(-)
arch/alpha/include/asm/xor.h +16 -13
@@ -851,16 +851,19 @@ static struct xor_block_template xor_block_alpha_prefetch = {/* For grins, also test the generic routines. */ #include <asm-generic/xor.h> -#undef XOR_TRY_TEMPLATES -#define XOR_TRY_TEMPLATES \ - do { \ - xor_speed(&xor_block_8regs); \ - xor_speed(&xor_block_32regs); \ - xor_speed(&xor_block_alpha); \ - xor_speed(&xor_block_alpha_prefetch); \ - } while (0) - -/* Force the use of alpha_prefetch if EV6, as it is significantly -faster in the cold cache case. */ -#define XOR_SELECT_TEMPLATE (FASTEST ) \ - (implver() == IMPLVER_EV6 ? &xor_block_alpha_prefetch : FASTEST) +/* +* Force the use of alpha_prefetch if EV6, as it is significantly faster in the +* cold cache case. +*/ +#define arch_xor_init arch_xor_init +static __always_inline void __init arch_xor_init(void) +{ +if (implver () ==IMPLVER_EV6 ) { +xor_force (&xor_block_alpha_prefetch); + }else { +xor_register (&xor_block_8regs); +xor_register (&xor_block_32regs); +xor_register (&xor_block_alpha); +xor_register (&xor_block_alpha_prefetch); + } +}
arch/arm/include/asm/xor.h +12 -13
@@ -138,15 +138,6 @@ static struct xor_block_template xor_block_arm4regs = { .do_5 = xor_arm4regs_5, }; -#undef XOR_TRY_TEMPLATES -#define XOR_TRY_TEMPLATES \ - do { \ - xor_speed(&xor_block_arm4regs); \ - xor_speed(&xor_block_8regs); \ - xor_speed(&xor_block_32regs); \ - NEON_TEMPLATES; \ - } while (0) -#ifdef CONFIG_KERNEL_MODE_NEON extern struct xor_block_template const xor_block_neon_inner;
@@ -201,8 +192,16 @@ static struct xor_block_template xor_block_neon = { .do_5 = xor_neon_5 }; -#define NEON_TEMPLATES \ - do { if (cpu_has_neon()) xor_speed(&xor_block_neon); } while (0) -#else -#define NEON_TEMPLATES +#endif /* CONFIG_KERNEL_MODE_NEON */ + +#define arch_xor_init arch_xor_init +static __always_inline void __init arch_xor_init(void) +{ +xor_register (&xor_block_arm4regs); +xor_register (&xor_block_8regs); +xor_register (&xor_block_32regs); +#ifdef CONFIG_KERNEL_MODE_NEON +if (cpu_has_neon ()) +xor_register (&xor_block_neon);#endif +}
arch/arm64/include/asm/xor.h +9 -9
@@ -60,14 +60,14 @@ static struct xor_block_template xor_block_arm64 = { .do_4 = xor_neon_4, .do_5 = xor_neon_5 }; -#undef XOR_TRY_TEMPLATES -#define XOR_TRY_TEMPLATES \ - do { \ - xor_speed(&xor_block_8regs); \ - xor_speed(&xor_block_32regs); \ - if (cpu_has_neon()) { \ - xor_speed(&xor_block_arm64);\ - } \ - } while (0) + +#define arch_xor_init arch_xor_init +static __always_inline void __init arch_xor_init(void) +{ +xor_register (&xor_block_8regs); +xor_register (&xor_block_32regs); +if (cpu_has_neon ()) +xor_register (&xor_block_arm64); +}#endif /* ! CONFIG_KERNEL_MODE_NEON */
arch/loongarch/include/asm/xor.h +16 -26
59 lines not on this page · raw message
arch/powerpc/include/asm/xor.h +13 -18
@@ -21,27 +21,22 @@ static struct xor_block_template xor_block_altivec = { .do_4 = xor_altivec_4, .do_5 = xor_altivec_5, }; - -#define XOR_SPEED_ALTIVEC () \ - do { \ - if (cpu_has_feature(CPU_FTR_ALTIVEC)) \ - xor_speed(&xor_block_altivec); \ - } while (0) -#else -#define XOR_SPEED_ALTIVEC () -#endif +#endif /* CONFIG_ALTIVEC */ /* Also try the generic routines. */ #include <asm-generic/xor.h> -#undef XOR_TRY_TEMPLATES -#define XOR_TRY_TEMPLATES \ -do { \ - xor_speed(&xor_block_8regs); \ - xor_speed(&xor_block_8regs_p); \ - xor_speed(&xor_block_32regs); \ - xor_speed(&xor_block_32regs_p); \ - XOR_SPEED_ALTIVEC(); \ -} while (0) +#define arch_xor_init arch_xor_init +static __always_inline void __init arch_xor_init(void) +{ +xor_register (&xor_block_8regs); +xor_register (&xor_block_8regs_p); +xor_register (&xor_block_32regs); +xor_register (&xor_block_32regs_p); +#ifdef CONFIG_ALTIVEC +if (cpu_has_feature (CPU_FTR_ALTIVEC )) +xor_register (&xor_block_altivec); +#endif +}#endif /* _ASM_POWERPC_XOR_H */
arch/riscv/include/asm/xor.h +10 -9
@@ -55,14 +55,15 @@ static struct xor_block_template xor_block_rvv = { .do_4 = xor_vector_4, .do_5 = xor_vector_5 }; +#endif /* CONFIG_RISCV_ISA_V */ -#undef XOR_TRY_TEMPLATES -#define XOR_TRY_TEMPLATES \ - do { \ - xor_speed(&xor_block_8regs); \ - xor_speed(&xor_block_32regs); \ - if (has_vector()) { \ - xor_speed(&xor_block_rvv);\ - } \ - } while (0) +#define arch_xor_init arch_xor_init +static __always_inline void __init arch_xor_init(void) +{ +xor_register (&xor_block_8regs); +xor_register (&xor_block_32regs); +#ifdef CONFIG_RISCV_ISA_V +if (has_vector ()) +xor_register (&xor_block_rvv);#endif +}
arch/s390/include/asm/xor.h +5 -7
@@ -10,12 +10,10 @@extern struct xor_block_template xor_block_xc; -#undef XOR_TRY_TEMPLATES -#define XOR_TRY_TEMPLATES \ -do { \ - xor_speed(&xor_block_xc); \ -} while (0) - -#define XOR_SELECT_TEMPLATE (FASTEST ) (&xor_block_xc) +#define arch_xor_init arch_xor_init +static __always_inline void __init arch_xor_init(void) +{ +xor_force (&xor_block_xc); +}#endif /* _ASM_S390_XOR_H */
arch/sparc/include/asm/xor_32.h +7 -7
@@ -259,10 +259,10 @@ static struct xor_block_template xor_block_SPARC = {/* For grins, also test the generic routines. */ #include <asm-generic/xor.h> -#undef XOR_TRY_TEMPLATES -#define XOR_TRY_TEMPLATES \ - do { \ - xor_speed(&xor_block_8regs); \ - xor_speed(&xor_block_32regs); \ - xor_speed(&xor_block_SPARC); \ - } while (0) +#define arch_xor_init arch_xor_init +static __always_inline void __init arch_xor_init(void) +{ +xor_register (&xor_block_8regs); +xor_register (&xor_block_32regs); +xor_register (&xor_block_SPARC); +}
arch/sparc/include/asm/xor_64.h +14 -17
@@ -60,20 +60,17 @@ static struct xor_block_template xor_block_niagara = { .do_5 = xor_niagara_5, }; -#undef XOR_TRY_TEMPLATES -#define XOR_TRY_TEMPLATES \ - do { \ - xor_speed(&xor_block_VIS); \ - xor_speed(&xor_block_niagara); \ - } while (0) - -/* For VIS for everything except Niagara. */ -#define XOR_SELECT_TEMPLATE (FASTEST ) \ - ((tlb_type == hypervisor && \ - (sun4v_chip_type == SUN4V_CHIP_NIAGARA1 || \ - sun4v_chip_type == SUN4V_CHIP_NIAGARA2 || \ - sun4v_chip_type == SUN4V_CHIP_NIAGARA3 || \ - sun4v_chip_type == SUN4V_CHIP_NIAGARA4 || \ - sun4v_chip_type == SUN4V_CHIP_NIAGARA5)) ? \ - &xor_block_niagara : \ - &xor_block_VIS) +#define arch_xor_init arch_xor_init +static __always_inline void __init arch_xor_init(void) +{ +/* Force VIS for everything except Niagara. */ +if (tlb_type == hypervisor && + (sun4v_chip_type ==SUN4V_CHIP_NIAGARA1 || + sun4v_chip_type ==SUN4V_CHIP_NIAGARA2 || + sun4v_chip_type ==SUN4V_CHIP_NIAGARA3 || + sun4v_chip_type ==SUN4V_CHIP_NIAGARA4 || + sun4v_chip_type ==SUN4V_CHIP_NIAGARA5 )) +xor_force (&xor_block_niagara); +else +xor_force (&xor_block_VIS); +}
arch/x86/include/asm/xor.h +0 -3
@@ -496,7 +496,4 @@ static struct xor_block_template xor_block_sse_pf64 = {# include <asm/xor_64.h> #endif -#define XOR_SELECT_TEMPLATE (FASTEST ) \ - AVX_SELECT(FASTEST) -#endif /* _ASM_X86_XOR_H */
arch/x86/include/asm/xor_32.h +19 -17
@@ -552,22 +552,24 @@ static struct xor_block_template xor_block_pIII_sse = {/* We force the use of the SSE xor block because it can write around L2. We may also be able to load into the L1 only depending on how the cpu deals with a load to a line that is being prefetched. */ -#undef XOR_TRY_TEMPLATES -#define XOR_TRY_TEMPLATES \ -do { \ - AVX_XOR_SPEED; \ - if (boot_cpu_has(X86_FEATURE_XMM)) { \ - xor_speed(&xor_block_pIII_sse); \ - xor_speed(&xor_block_sse_pf64); \ - } else if (boot_cpu_has(X86_FEATURE_MMX)) { \ - xor_speed(&xor_block_pII_mmx); \ - xor_speed(&xor_block_p5_mmx); \ - } else { \ - xor_speed(&xor_block_8regs); \ - xor_speed(&xor_block_8regs_p); \ - xor_speed(&xor_block_32regs); \ - xor_speed(&xor_block_32regs_p); \ - } \ -} while (0) +#define arch_xor_init arch_xor_init +static __always_inline void __init arch_xor_init(void) +{ +if (boot_cpu_has (X86_FEATURE_AVX ) && +boot_cpu_has (X86_FEATURE_OSXSAVE )) { +xor_force (&xor_block_avx); + }else if (boot_cpu_has (X86_FEATURE_XMM )) { +xor_register (&xor_block_pIII_sse); +xor_register (&xor_block_sse_pf64); + }else if (boot_cpu_has (X86_FEATURE_MMX )) { +xor_register (&xor_block_pII_mmx); +xor_register (&xor_block_p5_mmx); + }else { +xor_register (&xor_block_8regs); +xor_register (&xor_block_8regs_p); +xor_register (&xor_block_32regs); +xor_register (&xor_block_32regs_p); + } +}#endif /* _ASM_X86_XOR_32_H */
arch/x86/include/asm/xor_64.h +11 -7
@@ -17,12 +17,16 @@ static struct xor_block_template xor_block_sse = {/* We force the use of the SSE xor block because it can write around L2. We may also be able to load into the L1 only depending on how the cpu deals with a load to a line that is being prefetched. */ -#undef XOR_TRY_TEMPLATES -#define XOR_TRY_TEMPLATES \ -do { \ - AVX_XOR_SPEED; \ - xor_speed(&xor_block_sse_pf64); \ - xor_speed(&xor_block_sse); \ -} while (0) +#define arch_xor_init arch_xor_init +static __always_inline void __init arch_xor_init(void) +{ +if (boot_cpu_has (X86_FEATURE_AVX ) && +boot_cpu_has (X86_FEATURE_OSXSAVE )) { +xor_force (&xor_block_avx); + }else { +xor_register (&xor_block_sse_pf64); +xor_register (&xor_block_sse); + } +}#endif /* _ASM_X86_XOR_64_H */
arch/x86/include/asm/xor_avx.h +0 -9
@@ -166,13 +166,4 @@ static struct xor_block_template xor_block_avx = { .do_5 = xor_avx_5, }; -#define AVX_XOR_SPEED \ -do { \ - if (boot_cpu_has(X86_FEATURE_AVX) && boot_cpu_has(X86_FEATURE_OSXSAVE)) \ - xor_speed(&xor_block_avx); \ -} while (0) - -#define AVX_SELECT (FASTEST ) \ - (boot_cpu_has(X86_FEATURE_AVX) && boot_cpu_has(X86_FEATURE_OSXSAVE) ? &xor_block_avx : FASTEST) -#endif
include/asm-generic/xor.h +0 -8
@@ -728,11 +728,3 @@ static struct xor_block_template xor_block_32regs_p __maybe_unused = { .do_4 = xor_32regs_p_4, .do_5 = xor_32regs_p_5, }; - -#define XOR_TRY_TEMPLATES \ - do { \ - xor_speed(&xor_block_8regs); \ - xor_speed(&xor_block_8regs_p); \ - xor_speed(&xor_block_32regs); \ - xor_speed(&xor_block_32regs_p); \ - } while (0)
include/linux/raid/xor_impl.h +5 -0
@@ -2,6 +2,8 @@ #ifndef _XOR_IMPL_H #define _XOR_IMPL_H +#include <linux/init.h> + struct xor_block_template { struct xor_block_template *next; const char *name;
@@ -22,4 +24,7 @@ struct xor_block_template { const unsigned long * __restrict); }; +void __init xor_register(struct xor_block_template *tmpl); +void __init xor_force (struct xor_block_template *tmpl); +#endif /* _XOR_IMPL_H */
lib/raid/xor/xor-core.c +31 -10
74 lines not on this page · raw message
Signature · 1 line
2.47.3
PATCH 9/26 xor: move generic implementations out of asm-generic/xor.h
In reply to Christoph HellwigMove the generic implementations from asm-generic/xor.h to per-implementaion .c files in lib/raid. This will build them unconditionally even when an architecture forces a specific implementation, but as we'll need at least one generic version for the static_call optimization later on we'll pay that price.
Note that this would cause the second xor_block_8regs instance created by arch/arm/lib/xor-neon.c to be generated instead of discarded as dead code, so add a NO_TEMPLATE symbol to disable it for this case.
--- arch/arm/lib/xor-neon.c | 4 +- include/asm-generic/xor.h | 727 +---------------------------- lib/raid/xor/Makefile | 4 + lib/raid/xor/xor-32regs-prefetch.c | 268 +++++++++++ lib/raid/xor/xor-32regs.c | 219 +++++++++ lib/raid/xor/xor-8regs-prefetch.c | 146 ++++++ lib/raid/xor/xor-8regs.c | 105 +++++ 7 files changed, 748 insertions(+), 725 deletions(-) create mode 100644 lib/raid/xor/xor-32regs-prefetch.c create mode 100644 lib/raid/xor/xor-32regs.c create mode 100644 lib/raid/xor/xor-8regs-prefetch.c create mode 100644 lib/raid/xor/xor-8regs.c
arch/arm/lib/xor-neon.c +2 -2
@@ -26,8 +26,8 @@ MODULE_LICENSE("GPL");#pragma GCC optimize "tree-vectorize"#endif -#pragma GCC diagnostic ignored "-Wunused-variable" -#include <asm-generic/xor.h> +#define NO_TEMPLATE +#include "../../../lib/raid/xor/xor-8regs.c" struct xor_block_template const xor_block_neon_inner = { .name ="__inner_neon__" ,
include/asm-generic/xor.h +4 -723
730 lines not on this page · raw message
lib/raid/xor/Makefile +4 -0
@@ -3,3 +3,7 @@ obj-$(CONFIG_XOR_BLOCKS) += xor.o xor-y += xor-core.o +xor-y += xor-8regs.o +xor-y += xor-32regs.o +xor-y += xor-8regs-prefetch.o +xor-y += xor-32regs-prefetch.o
lib/raid/xor/xor-32regs-prefetch.c new file +268 -0
268 lines not on this page · raw message
lib/raid/xor/xor-32regs.c new file +219 -0
219 lines not on this page · raw message
lib/raid/xor/xor-8regs-prefetch.c new file +146 -0
146 lines not on this page · raw message
lib/raid/xor/xor-8regs.c new file +105 -0
105 lines not on this page · raw message
Signature · 1 line
2.47.3
PATCH 10/26 alpha: move the XOR code to lib/raid/
In reply to Christoph HellwigMove the optimized XOR code out of line into lib/raid.
Note that the giant inline assembly block might be better off as a separate assembly source file now, but I'll leave that to the alpha maintainers.
--- arch/alpha/include/asm/xor.h | 853 +---------------------------------- lib/raid/xor/Makefile | 2 + lib/raid/xor/alpha/xor.c | 849 ++++++++++++++++++++++++++++++++++ 3 files changed, 855 insertions(+), 849 deletions(-) create mode 100644 lib/raid/xor/alpha/xor.c
arch/alpha/include/asm/xor.h +4 -849
@@ -1,856 +1,11 @@/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* -* include/asm-alpha/xor.h -* -* Optimized RAID-5 checksumming functions for alpha EV5 and EV6 -*/ - -extern void -xor_alpha_2 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2); -extern void -xor_alpha_3 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2, -const unsigned long * __restrict p3); -extern void -xor_alpha_4 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2, -const unsigned long * __restrict p3, -const unsigned long * __restrict p4); -extern void -xor_alpha_5 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2, -const unsigned long * __restrict p3, -const unsigned long * __restrict p4, -const unsigned long * __restrict p5); - -extern void -xor_alpha_prefetch_2 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2); -extern void -xor_alpha_prefetch_3 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2, -const unsigned long * __restrict p3); -extern void -xor_alpha_prefetch_4 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2, -const unsigned long * __restrict p3, -const unsigned long * __restrict p4); -extern void -xor_alpha_prefetch_5 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2, -const unsigned long * __restrict p3, -const unsigned long * __restrict p4, -const unsigned long * __restrict p5); -asm(" \n\ -.text \n\ -.align 3 \n\ -.ent xor_alpha_2 \n\ -xor_alpha_2: \n\ -.prologue 0 \n\ -srl $16, 6, $16 \n\ -.align 4 \n\ -2: \n\ -ldq $0,0($17) \n\ -ldq $1,0($18) \n\ -ldq $2,8($17) \n\ -ldq $3,8($18) \n\ -\n\ -ldq $4,16($17) \n\ -ldq $5,16($18) \n\ -ldq $6,24($17) \n\ -ldq $7,24($18) \n\ -\n\ -ldq $19,32($17) \n\ -ldq $20,32($18) \n\ -ldq $21,40($17) \n\ -ldq $22,40($18) \n\ -\n\ -ldq $23,48($17) \n\ -ldq $24,48($18) \n\ -ldq $25,56($17) \n\ -xor $0,$1,$0 # 7 cycles from $1 load \n\ -\n\ -ldq $27,56($18) \n\ -xor $2,$3,$2 \n\ -stq $0,0($17) \n\ -xor $4,$5,$4 \n\ -\n\ -stq $2,8($17) \n\ -xor $6,$7,$6 \n\ -stq $4,16($17) \n\ -xor $19,$20,$19 \n\ -\n\ -stq $6,24($17) \n\ -xor $21,$22,$21 \n\ -stq $19,32($17) \n\ -xor $23,$24,$23 \n\ -\n\ -stq $21,40($17) \n\ -xor $25,$27,$25 \n\ -stq $23,48($17) \n\ -subq $16,1,$16 \n\ -\n\ -stq $25,56($17) \n\ -addq $17,64,$17 \n\ -addq $18,64,$18 \n\ -bgt $16,2b \n\ -\n\ -ret \n\ -.end xor_alpha_2 \n\ -\n\ -.align 3 \n\ -.ent xor_alpha_3 \n\ -xor_alpha_3: \n\ -.prologue 0 \n\ -srl $16, 6, $16 \n\ -.align 4 \n\ -3: \n\ -ldq $0,0($17) \n\ -ldq $1,0($18) \n\ -ldq $2,0($19) \n\ -ldq $3,8($17) \n\ -\n\ -ldq $4,8($18) \n\ -ldq $6,16($17) \n\ -ldq $7,16($18) \n\ -ldq $21,24($17) \n\ -\n\ -ldq $22,24($18) \n\ -ldq $24,32($17) \n\ -ldq $25,32($18) \n\ -ldq $5,8($19) \n\ -\n\ -ldq $20,16($19) \n\ -ldq $23,24($19) \n\ -ldq $27,32($19) \n\ -nop \n\ -\n\ -xor $0,$1,$1 # 8 cycles from $0 load \n\ -xor $3,$4,$4 # 6 cycles from $4 load \n\ -xor $6,$7,$7 # 6 cycles from $7 load \n\ -xor $21,$22,$22 # 5 cycles from $22 load \n\ -\n\ -xor $1,$2,$2 # 9 cycles from $2 load \n\ -xor $24,$25,$25 # 5 cycles from $25 load \n\ -stq $2,0($17) \n\ -xor $4,$5,$5 # 6 cycles from $5 load \n\ -\n\ -stq $5,8($17) \n\ -xor $7,$20,$20 # 7 cycles from $20 load \n\ -stq $20,16($17) \n\ -xor $22,$23,$23 # 7 cycles from $23 load \n\ -\n\ -stq $23,24($17) \n\ -xor $25,$27,$27 # 7 cycles from $27 load \n\ -stq $27,32($17) \n\ -nop \n\ -\n\ -ldq $0,40($17) \n\ -ldq $1,40($18) \n\ -ldq $3,48($17) \n\ -ldq $4,48($18) \n\ -\n\ -ldq $6,56($17) \n\ -ldq $7,56($18) \n\ -ldq $2,40($19) \n\ -ldq $5,48($19) \n\ -\n\ -ldq $20,56($19) \n\ -xor $0,$1,$1 # 4 cycles from $1 load \n\ -xor $3,$4,$4 # 5 cycles from $4 load \n\ -xor $6,$7,$7 # 5 cycles from $7 load \n\ -\n\ -xor $1,$2,$2 # 4 cycles from $2 load \n\ -xor $4,$5,$5 # 5 cycles from $5 load \n\ -stq $2,40($17) \n\ -xor $7,$20,$20 # 4 cycles from $20 load \n\ -\n\ -stq $5,48($17) \n\ -subq $16,1,$16 \n\ -stq $20,56($17) \n\ -addq $19,64,$19 \n\ -\n\ -addq $18,64,$18 \n\ -addq $17,64,$17 \n\ -bgt $16,3b \n\ -ret \n\ -.end xor_alpha_3 \n\ -\n\ -.align 3 \n\ -.ent xor_alpha_4 \n\ -xor_alpha_4: \n\ -.prologue 0 \n\ -srl $16, 6, $16 \n\ -.align 4 \n\ -4: \n\ -ldq $0,0($17) \n\ -ldq $1,0($18) \n\ -ldq $2,0($19) \n\ -ldq $3,0($20) \n\ -\n\ -ldq $4,8($17) \n\ -ldq $5,8($18) \n\ -ldq $6,8($19) \n\ -ldq $7,8($20) \n\ -\n\ -ldq $21,16($17) \n\ -ldq $22,16($18) \n\ -ldq $23,16($19) \n\ -ldq $24,16($20) \n\ -\n\ -ldq $25,24($17) \n\ -xor $0,$1,$1 # 6 cycles from $1 load \n\ -ldq $27,24($18) \n\ -xor $2,$3,$3 # 6 cycles from $3 load \n\ -\n\ -ldq $0,24($19) \n\ -xor $1,$3,$3 \n\ -ldq $1,24($20) \n\ -xor $4,$5,$5 # 7 cycles from $5 load \n\ -\n\ -stq $3,0($17) \n\ -xor $6,$7,$7 \n\ -xor $21,$22,$22 # 7 cycles from $22 load \n\ -xor $5,$7,$7 \n\ -\n\ -stq $7,8($17) \n\ -xor $23,$24,$24 # 7 cycles from $24 load \n\ -ldq $2,32($17) \n\ -xor $22,$24,$24 \n\ -\n\ -ldq $3,32($18) \n\ -ldq $4,32($19) \n\ -ldq $5,32($20) \n\ -xor $25,$27,$27 # 8 cycles from $27 load \n\ -\n\ -ldq $6,40($17) \n\ -ldq $7,40($18) \n\ -ldq $21,40($19) \n\ -ldq $22,40($20) \n\ -\n\ -stq $24,16($17) \n\ -xor $0,$1,$1 # 9 cycles from $1 load \n\ -xor $2,$3,$3 # 5 cycles from $3 load \n\ -xor $27,$1,$1 \n\ -\n\ -stq $1,24($17) \n\ -xor $4,$5,$5 # 5 cycles from $5 load \n\ -ldq $23,48($17) \n\ -ldq $24,48($18) \n\ -\n\ -ldq $25,48($19) \n\ -xor $3,$5,$5 \n\ -ldq $27,48($20) \n\ -ldq $0,56($17) \n\ -\n\ -ldq $1,56($18) \n\ -ldq $2,56($19) \n\ -xor $6,$7,$7 # 8 cycles from $6 load \n\ -ldq $3,56($20) \n\ -\n\ -stq $5,32($17) \n\ -xor $21,$22,$22 # 8 cycles from $22 load \n\ -xor $7,$22,$22 \n\ -xor $23,$24,$24 # 5 cycles from $24 load \n\ -\n\ -stq $22,40($17) \n\ -xor $25,$27,$27 # 5 cycles from $27 load \n\ -xor $24,$27,$27 \n\ -xor $0,$1,$1 # 5 cycles from $1 load \n\ -\n\ -stq $27,48($17) \n\ -xor $2,$3,$3 # 4 cycles from $3 load \n\ -xor $1,$3,$3 \n\ -subq $16,1,$16 \n\ -\n\ -stq $3,56($17) \n\ -addq $20,64,$20 \n\ -addq $19,64,$19 \n\ -addq $18,64,$18 \n\ -\n\ -addq $17,64,$17 \n\ -bgt $16,4b \n\ -ret \n\ -.end xor_alpha_4 \n\ -\n\ -.align 3 \n\ -.ent xor_alpha_5 \n\ -xor_alpha_5: \n\ -.prologue 0 \n\ -srl $16, 6, $16 \n\ -.align 4 \n\ -5: \n\ -ldq $0,0($17) \n\ -ldq $1,0($18) \n\ -ldq $2,0($19) \n\ -ldq $3,0($20) \n\ -\n\ -ldq $4,0($21) \n\ -ldq $5,8($17) \n\ -ldq $6,8($18) \n\ -ldq $7,8($19) \n\ -\n\ -ldq $22,8($20) \n\ -ldq $23,8($21) \n\ -ldq $24,16($17) \n\ -ldq $25,16($18) \n\ -\n\ -ldq $27,16($19) \n\ -xor $0,$1,$1 # 6 cycles from $1 load \n\ -ldq $28,16($20) \n\ -xor $2,$3,$3 # 6 cycles from $3 load \n\ -\n\ -ldq $0,16($21) \n\ -xor $1,$3,$3 \n\ -ldq $1,24($17) \n\ -xor $3,$4,$4 # 7 cycles from $4 load \n\ -\n\ -stq $4,0($17) \n\ -xor $5,$6,$6 # 7 cycles from $6 load \n\ -xor $7,$22,$22 # 7 cycles from $22 load \n\ -xor $6,$23,$23 # 7 cycles from $23 load \n\ -\n\ -ldq $2,24($18) \n\ -xor $22,$23,$23 \n\ -ldq $3,24($19) \n\ -xor $24,$25,$25 # 8 cycles from $25 load \n\ -\n\ -stq $23,8($17) \n\ -xor $25,$27,$27 # 8 cycles from $27 load \n\ -ldq $4,24($20) \n\ -xor $28,$0,$0 # 7 cycles from $0 load \n\ -\n\ -ldq $5,24($21) \n\ -xor $27,$0,$0 \n\ -ldq $6,32($17) \n\ -ldq $7,32($18) \n\ -\n\ -stq $0,16($17) \n\ -xor $1,$2,$2 # 6 cycles from $2 load \n\ -ldq $22,32($19) \n\ -xor $3,$4,$4 # 4 cycles from $4 load \n\ -\n\ -ldq $23,32($20) \n\ -xor $2,$4,$4 \n\ -ldq $24,32($21) \n\ -ldq $25,40($17) \n\ -\n\ -ldq $27,40($18) \n\ -ldq $28,40($19) \n\ -ldq $0,40($20) \n\ -xor $4,$5,$5 # 7 cycles from $5 load \n\ -\n\ -stq $5,24($17) \n\ -xor $6,$7,$7 # 7 cycles from $7 load \n\ -ldq $1,40($21) \n\ -ldq $2,48($17) \n\ -\n\ -ldq $3,48($18) \n\ -xor $7,$22,$22 # 7 cycles from $22 load \n\ -ldq $4,48($19) \n\ -xor $23,$24,$24 # 6 cycles from $24 load \n\ -\n\ -ldq $5,48($20) \n\ -xor $22,$24,$24 \n\ -ldq $6,48($21) \n\ -xor $25,$27,$27 # 7 cycles from $27 load \n\ -\n\ -stq $24,32($17) \n\ -xor $27,$28,$28 # 8 cycles from $28 load \n\ -ldq $7,56($17) \n\ -xor $0,$1,$1 # 6 cycles from $1 load \n\ -\n\ -ldq $22,56($18) \n\ -ldq $23,56($19) \n\ -ldq $24,56($20) \n\ -ldq $25,56($21) \n\ -\n\ -xor $28,$1,$1 \n\ -xor $2,$3,$3 # 9 cycles from $3 load \n\ -xor $3,$4,$4 # 9 cycles from $4 load \n\ -xor $5,$6,$6 # 8 cycles from $6 load \n\ -\n\ -stq $1,40($17) \n\ -xor $4,$6,$6 \n\ -xor $7,$22,$22 # 7 cycles from $22 load \n\ -xor $23,$24,$24 # 6 cycles from $24 load \n\ -\n\ -stq $6,48($17) \n\ -xor $22,$24,$24 \n\ -subq $16,1,$16 \n\ -xor $24,$25,$25 # 8 cycles from $25 load \n\ -\n\ -stq $25,56($17) \n\ -addq $21,64,$21 \n\ -addq $20,64,$20 \n\ -addq $19,64,$19 \n\ -\n\ -addq $18,64,$18 \n\ -addq $17,64,$17 \n\ -bgt $16,5b \n\ -ret \n\ -.end xor_alpha_5 \n\ -\n\ -.align 3 \n\ -.ent xor_alpha_prefetch_2 \n\ -xor_alpha_prefetch_2: \n\ -.prologue 0 \n\ -srl $16, 6, $16 \n\ -\n\ -ldq $31, 0($17) \n\ -ldq $31, 0($18) \n\ -\n\ -ldq $31, 64($17) \n\ -ldq $31, 64($18) \n\ -\n\ -ldq $31, 128($17) \n\ -ldq $31, 128($18) \n\ -\n\ -ldq $31, 192($17) \n\ -ldq $31, 192($18) \n\ -.align 4 \n\ -2: \n\ -ldq $0,0($17) \n\ -ldq $1,0($18) \n\ -ldq $2,8($17) \n\ -ldq $3,8($18) \n\ -\n\ -ldq $4,16($17) \n\ -ldq $5,16($18) \n\ -ldq $6,24($17) \n\ -ldq $7,24($18) \n\ -\n\ -ldq $19,32($17) \n\ -ldq $20,32($18) \n\ -ldq $21,40($17) \n\ -ldq $22,40($18) \n\ -\n\ -ldq $23,48($17) \n\ -ldq $24,48($18) \n\ -ldq $25,56($17) \n\ -ldq $27,56($18) \n\ -\n\ -ldq $31,256($17) \n\ -xor $0,$1,$0 # 8 cycles from $1 load \n\ -ldq $31,256($18) \n\ -xor $2,$3,$2 \n\ -\n\ -stq $0,0($17) \n\ -xor $4,$5,$4 \n\ -stq $2,8($17) \n\ -xor $6,$7,$6 \n\ -\n\ -stq $4,16($17) \n\ -xor $19,$20,$19 \n\ -stq $6,24($17) \n\ -xor $21,$22,$21 \n\ -\n\ -stq $19,32($17) \n\ -xor $23,$24,$23 \n\ -stq $21,40($17) \n\ -xor $25,$27,$25 \n\ -\n\ -stq $23,48($17) \n\ -subq $16,1,$16 \n\ -stq $25,56($17) \n\ -addq $17,64,$17 \n\ -\n\ -addq $18,64,$18 \n\ -bgt $16,2b \n\ -ret \n\ -.end xor_alpha_prefetch_2 \n\ -\n\ -.align 3 \n\ -.ent xor_alpha_prefetch_3 \n\ -xor_alpha_prefetch_3: \n\ -.prologue 0 \n\ -srl $16, 6, $16 \n\ -\n\ -ldq $31, 0($17) \n\ -ldq $31, 0($18) \n\ -ldq $31, 0($19) \n\ -\n\ -ldq $31, 64($17) \n\ -ldq $31, 64($18) \n\ -ldq $31, 64($19) \n\ -\n\ -ldq $31, 128($17) \n\ -ldq $31, 128($18) \n\ -ldq $31, 128($19) \n\ -\n\ -ldq $31, 192($17) \n\ -ldq $31, 192($18) \n\ -ldq $31, 192($19) \n\ -.align 4 \n\ -3: \n\ -ldq $0,0($17) \n\ -ldq $1,0($18) \n\ -ldq $2,0($19) \n\ -ldq $3,8($17) \n\ -\n\ -ldq $4,8($18) \n\ -ldq $6,16($17) \n\ -ldq $7,16($18) \n\ -ldq $21,24($17) \n\ -\n\ -ldq $22,24($18) \n\ -ldq $24,32($17) \n\ -ldq $25,32($18) \n\ -ldq $5,8($19) \n\ -\n\ -ldq $20,16($19) \n\ -ldq $23,24($19) \n\ -ldq $27,32($19) \n\ -nop \n\ -\n\ -xor $0,$1,$1 # 8 cycles from $0 load \n\ -xor $3,$4,$4 # 7 cycles from $4 load \n\ -xor $6,$7,$7 # 6 cycles from $7 load \n\ -xor $21,$22,$22 # 5 cycles from $22 load \n\ -\n\ -xor $1,$2,$2 # 9 cycles from $2 load \n\ -xor $24,$25,$25 # 5 cycles from $25 load \n\ -stq $2,0($17) \n\ -xor $4,$5,$5 # 6 cycles from $5 load \n\ -\n\ -stq $5,8($17) \n\ -xor $7,$20,$20 # 7 cycles from $20 load \n\ -stq $20,16($17) \n\ -xor $22,$23,$23 # 7 cycles from $23 load \n\ -\n\ -stq $23,24($17) \n\ -xor $25,$27,$27 # 7 cycles from $27 load \n\ -stq $27,32($17) \n\ -nop \n\ -\n\ -ldq $0,40($17) \n\ -ldq $1,40($18) \n\ -ldq $3,48($17) \n\ -ldq $4,48($18) \n\ -\n\ -ldq $6,56($17) \n\ -ldq $7,56($18) \n\ -ldq $2,40($19) \n\ -ldq $5,48($19) \n\ -\n\ -ldq $20,56($19) \n\ -ldq $31,256($17) \n\ -ldq $31,256($18) \n\ -ldq $31,256($19) \n\ -\n\ -xor $0,$1,$1 # 6 cycles from $1 load \n\ -xor $3,$4,$4 # 5 cycles from $4 load \n\ -xor $6,$7,$7 # 5 cycles from $7 load \n\ -xor $1,$2,$2 # 4 cycles from $2 load \n\ -\n\ -xor $4,$5,$5 # 5 cycles from $5 load \n\ -xor $7,$20,$20 # 4 cycles from $20 load \n\ -stq $2,40($17) \n\ -subq $16,1,$16 \n\ -\n\ -stq $5,48($17) \n\ -addq $19,64,$19 \n\ -stq $20,56($17) \n\ -addq $18,64,$18 \n\ -\n\ -addq $17,64,$17 \n\ -bgt $16,3b \n\ -ret \n\ -.end xor_alpha_prefetch_3 \n\ -\n\ -.align 3 \n\ -.ent xor_alpha_prefetch_4 \n\ -xor_alpha_prefetch_4: \n\ -.prologue 0 \n\ -srl $16, 6, $16 \n\ -\n\ -ldq $31, 0($17) \n\ -ldq $31, 0($18) \n\ -ldq $31, 0($19) \n\ -ldq $31, 0($20) \n\ -\n\ -ldq $31, 64($17) \n\ -ldq $31, 64($18) \n\ -ldq $31, 64($19) \n\ -ldq $31, 64($20) \n\ -\n\ -ldq $31, 128($17) \n\ -ldq $31, 128($18) \n\ -ldq $31, 128($19) \n\ -ldq $31, 128($20) \n\ -\n\ -ldq $31, 192($17) \n\ -ldq $31, 192($18) \n\ -ldq $31, 192($19) \n\ -ldq $31, 192($20) \n\ -.align 4 \n\ -4: \n\ -ldq $0,0($17) \n\ -ldq $1,0($18) \n\ -ldq $2,0($19) \n\ -ldq $3,0($20) \n\ -\n\ -ldq $4,8($17) \n\ -ldq $5,8($18) \n\ -ldq $6,8($19) \n\ -ldq $7,8($20) \n\ -\n\ -ldq $21,16($17) \n\ -ldq $22,16($18) \n\ -ldq $23,16($19) \n\ -ldq $24,16($20) \n\ -\n\ -ldq $25,24($17) \n\ -xor $0,$1,$1 # 6 cycles from $1 load \n\ -ldq $27,24($18) \n\ -xor $2,$3,$3 # 6 cycles from $3 load \n\ -\n\ -ldq $0,24($19) \n\ -xor $1,$3,$3 \n\ -ldq $1,24($20) \n\ -xor $4,$5,$5 # 7 cycles from $5 load \n\ -\n\ -stq $3,0($17) \n\ -xor $6,$7,$7 \n\ -xor $21,$22,$22 # 7 cycles from $22 load \n\ -xor $5,$7,$7 \n\ -\n\ -stq $7,8($17) \n\ -xor $23,$24,$24 # 7 cycles from $24 load \n\ -ldq $2,32($17) \n\ -xor $22,$24,$24 \n\ -\n\ -ldq $3,32($18) \n\ -ldq $4,32($19) \n\ -ldq $5,32($20) \n\ -xor $25,$27,$27 # 8 cycles from $27 load \n\ -\n\ -ldq $6,40($17) \n\ -ldq $7,40($18) \n\ -ldq $21,40($19) \n\ -ldq $22,40($20) \n\ -\n\ -stq $24,16($17) \n\ -xor $0,$1,$1 # 9 cycles from $1 load \n\ -xor $2,$3,$3 # 5 cycles from $3 load \n\ -xor $27,$1,$1 \n\ -\n\ -stq $1,24($17) \n\ -xor $4,$5,$5 # 5 cycles from $5 load \n\ -ldq $23,48($17) \n\ -xor $3,$5,$5 \n\ -\n\ -ldq $24,48($18) \n\ -ldq $25,48($19) \n\ -ldq $27,48($20) \n\ -ldq $0,56($17) \n\ -\n\ -ldq $1,56($18) \n\ -ldq $2,56($19) \n\ -ldq $3,56($20) \n\ -xor $6,$7,$7 # 8 cycles from $6 load \n\ -\n\ -ldq $31,256($17) \n\ -xor $21,$22,$22 # 8 cycles from $22 load \n\ -ldq $31,256($18) \n\ -xor $7,$22,$22 \n\ -\n\ -ldq $31,256($19) \n\ -xor $23,$24,$24 # 6 cycles from $24 load \n\ -ldq $31,256($20) \n\ -xor $25,$27,$27 # 6 cycles from $27 load \n\ -\n\ -stq $5,32($17) \n\ -xor $24,$27,$27 \n\ -xor $0,$1,$1 # 7 cycles from $1 load \n\ -xor $2,$3,$3 # 6 cycles from $3 load \n\ -\n\ -stq $22,40($17) \n\ -xor $1,$3,$3 \n\ -stq $27,48($17) \n\ -subq $16,1,$16 \n\ -\n\ -stq $3,56($17) \n\ -addq $20,64,$20 \n\ -addq $19,64,$19 \n\ -addq $18,64,$18 \n\ -\n\ -addq $17,64,$17 \n\ -bgt $16,4b \n\ -ret \n\ -.end xor_alpha_prefetch_4 \n\ -\n\ -.align 3 \n\ -.ent xor_alpha_prefetch_5 \n\ -xor_alpha_prefetch_5: \n\ -.prologue 0 \n\ -srl $16, 6, $16 \n\ -\n\ -ldq $31, 0($17) \n\ -ldq $31, 0($18) \n\ -ldq $31, 0($19) \n\ -ldq $31, 0($20) \n\ -ldq $31, 0($21) \n\ -\n\ -ldq $31, 64($17) \n\ -ldq $31, 64($18) \n\ -ldq $31, 64($19) \n\ -ldq $31, 64($20) \n\ -ldq $31, 64($21) \n\ -\n\ -ldq $31, 128($17) \n\ -ldq $31, 128($18) \n\ -ldq $31, 128($19) \n\ -ldq $31, 128($20) \n\ -ldq $31, 128($21) \n\ -\n\ -ldq $31, 192($17) \n\ -ldq $31, 192($18) \n\ -ldq $31, 192($19) \n\ -ldq $31, 192($20) \n\ -ldq $31, 192($21) \n\ -.align 4 \n\ -5: \n\ -ldq $0,0($17) \n\ -ldq $1,0($18) \n\ -ldq $2,0($19) \n\ -ldq $3,0($20) \n\ -\n\ -ldq $4,0($21) \n\ -ldq $5,8($17) \n\ -ldq $6,8($18) \n\ -ldq $7,8($19) \n\ -\n\ -ldq $22,8($20) \n\ -ldq $23,8($21) \n\ -ldq $24,16($17) \n\ -ldq $25,16($18) \n\ -\n\ -ldq $27,16($19) \n\ -xor $0,$1,$1 # 6 cycles from $1 load \n\ -ldq $28,16($20) \n\ -xor $2,$3,$3 # 6 cycles from $3 load \n\ -\n\ -ldq $0,16($21) \n\ -xor $1,$3,$3 \n\ -ldq $1,24($17) \n\ -xor $3,$4,$4 # 7 cycles from $4 load \n\ -\n\ -stq $4,0($17) \n\ -xor $5,$6,$6 # 7 cycles from $6 load \n\ -xor $7,$22,$22 # 7 cycles from $22 load \n\ -xor $6,$23,$23 # 7 cycles from $23 load \n\ -\n\ -ldq $2,24($18) \n\ -xor $22,$23,$23 \n\ -ldq $3,24($19) \n\ -xor $24,$25,$25 # 8 cycles from $25 load \n\ -\n\ -stq $23,8($17) \n\ -xor $25,$27,$27 # 8 cycles from $27 load \n\ -ldq $4,24($20) \n\ -xor $28,$0,$0 # 7 cycles from $0 load \n\ -\n\ -ldq $5,24($21) \n\ -xor $27,$0,$0 \n\ -ldq $6,32($17) \n\ -ldq $7,32($18) \n\ -\n\ -stq $0,16($17) \n\ -xor $1,$2,$2 # 6 cycles from $2 load \n\ -ldq $22,32($19) \n\ -xor $3,$4,$4 # 4 cycles from $4 load \n\ -\n\ -ldq $23,32($20) \n\ -xor $2,$4,$4 \n\ -ldq $24,32($21) \n\ -ldq $25,40($17) \n\ -\n\ -ldq $27,40($18) \n\ -ldq $28,40($19) \n\ -ldq $0,40($20) \n\ -xor $4,$5,$5 # 7 cycles from $5 load \n\ -\n\ -stq $5,24($17) \n\ -xor $6,$7,$7 # 7 cycles from $7 load \n\ -ldq $1,40($21) \n\ -ldq $2,48($17) \n\ -\n\ -ldq $3,48($18) \n\ -xor $7,$22,$22 # 7 cycles from $22 load \n\ -ldq $4,48($19) \n\ -xor $23,$24,$24 # 6 cycles from $24 load \n\ -\n\ -ldq $5,48($20) \n\ -xor $22,$24,$24 \n\ -ldq $6,48($21) \n\ -xor $25,$27,$27 # 7 cycles from $27 load \n\ -\n\ -stq $24,32($17) \n\ -xor $27,$28,$28 # 8 cycles from $28 load \n\ -ldq $7,56($17) \n\ -xor $0,$1,$1 # 6 cycles from $1 load \n\ -\n\ -ldq $22,56($18) \n\ -ldq $23,56($19) \n\ -ldq $24,56($20) \n\ -ldq $25,56($21) \n\ -\n\ -ldq $31,256($17) \n\ -xor $28,$1,$1 \n\ -ldq $31,256($18) \n\ -xor $2,$3,$3 # 9 cycles from $3 load \n\ -\n\ -ldq $31,256($19) \n\ -xor $3,$4,$4 # 9 cycles from $4 load \n\ -ldq $31,256($20) \n\ -xor $5,$6,$6 # 8 cycles from $6 load \n\ -\n\ -stq $1,40($17) \n\ -xor $4,$6,$6 \n\ -xor $7,$22,$22 # 7 cycles from $22 load \n\ -xor $23,$24,$24 # 6 cycles from $24 load \n\ -\n\ -stq $6,48($17) \n\ -xor $22,$24,$24 \n\ -ldq $31,256($21) \n\ -xor $24,$25,$25 # 8 cycles from $25 load \n\ -\n\ -stq $25,56($17) \n\ -subq $16,1,$16 \n\ -addq $21,64,$21 \n\ -addq $20,64,$20 \n\ -\n\ -addq $19,64,$19 \n\ -addq $18,64,$18 \n\ -addq $17,64,$17 \n\ -bgt $16,5b \n\ -\n\ -ret \n\ -.end xor_alpha_prefetch_5 \n\ -" ); - -static struct xor_block_template xor_block_alpha = { - .name ="alpha" , - .do_2 = xor_alpha_2, - .do_3 = xor_alpha_3, - .do_4 = xor_alpha_4, - .do_5 = xor_alpha_5, -}; - -static struct xor_block_template xor_block_alpha_prefetch = { - .name ="alpha prefetch" , - .do_2 = xor_alpha_prefetch_2, - .do_3 = xor_alpha_prefetch_3, - .do_4 = xor_alpha_prefetch_4, - .do_5 = xor_alpha_prefetch_5, -}; - -/* For grins, also test the generic routines. */ +#include <asm/special_insns.h> #include <asm-generic/xor.h> +extern struct xor_block_template xor_block_alpha; +extern struct xor_block_template xor_block_alpha_prefetch; +/* * Force the use of alpha_prefetch if EV6, as it is significantly faster in the * cold cache case.
lib/raid/xor/Makefile +2 -0
@@ -7,3 +7,5 @@ xor-y += xor-8regs.o xor-y += xor-32regs.o xor-y += xor-8regs-prefetch.o xor-y += xor-32regs-prefetch.o + +xor-$(CONFIG_ALPHA) += alpha/xor.o
lib/raid/xor/alpha/xor.c new file +849 -0
849 lines not on this page · raw message
Signature · 1 line
2.47.3
PATCH 11/26 arm: move the XOR code to lib/raid/
In reply to Christoph HellwigMove the optimized XOR into lib/raid and include it it in the main xor.ko instead of building a separate module for it.
---
arch/arm/include/asm/xor.h | 190 +-----------------
arch/arm/lib/Makefile | 5 -
lib/raid/xor/Makefile | 8 +
lib/raid/xor/arm/xor-neon-glue.c | 58 ++++++
{arch/arm/lib => lib/raid/xor/arm}/xor-neon.c | 10 +-
lib/raid/xor/arm/xor.c | 136 +++++++++++++
6 files changed, 205 insertions(+), 202 deletions(-)
create mode 100644 lib/raid/xor/arm/xor-neon-glue.c
rename {arch/arm/lib => lib/raid/xor/arm}/xor-neon.c (74%)
create mode 100644 lib/raid/xor/arm/xor.carch/arm/include/asm/xor.h +2 -188
@@ -1,198 +1,12 @@/* SPDX-License-Identifier: GPL-2.0-only */ /* -* arch/arm/include/asm/xor.h -* * Copyright (C) 2001 Russell King */ #include <asm-generic/xor.h> -#include <asm/hwcap.h> #include <asm/neon.h> -#define __XOR (a1, a2) a1 ^= a2 - -#define GET_BLOCK_2 (dst) \ - __asm__("ldmia %0, {%1, %2}" \ - : "=r" (dst), "=r" (a1), "=r" (a2) \ - : "0" (dst)) - -#define GET_BLOCK_4 (dst) \ - __asm__("ldmia %0, {%1, %2, %3, %4}" \ - : "=r" (dst), "=r" (a1), "=r" (a2), "=r" (a3), "=r" (a4) \ - : "0" (dst)) - -#define XOR_BLOCK_2 (src) \ - __asm__("ldmia %0!, {%1, %2}" \ - : "=r" (src), "=r" (b1), "=r" (b2) \ - : "0" (src)); \ - __XOR(a1, b1); __XOR(a2, b2); - -#define XOR_BLOCK_4 (src) \ - __asm__("ldmia %0!, {%1, %2, %3, %4}" \ - : "=r" (src), "=r" (b1), "=r" (b2), "=r" (b3), "=r" (b4) \ - : "0" (src)); \ - __XOR(a1, b1); __XOR(a2, b2); __XOR(a3, b3); __XOR(a4, b4) - -#define PUT_BLOCK_2 (dst) \ - __asm__ __volatile__("stmia %0!, {%2, %3}" \ - : "=r" (dst) \ - : "0" (dst), "r" (a1), "r" (a2)) - -#define PUT_BLOCK_4 (dst) \ - __asm__ __volatile__("stmia %0!, {%2, %3, %4, %5}" \ - : "=r" (dst) \ - : "0" (dst), "r" (a1), "r" (a2), "r" (a3), "r" (a4)) - -static void -xor_arm4regs_2 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2) -{ -unsigned int lines = bytes /sizeof (unsigned long ) /4 ; - registerunsigned int a1 __asm__("r4" ); - registerunsigned int a2 __asm__("r5" ); - registerunsigned int a3 __asm__("r6" ); - registerunsigned int a4 __asm__("r10" ); - registerunsigned int b1 __asm__("r8" ); - registerunsigned int b2 __asm__("r9" ); - registerunsigned int b3 __asm__("ip" ); - registerunsigned int b4 __asm__("lr" ); - -do { -GET_BLOCK_4 (p1); -XOR_BLOCK_4 (p2); -PUT_BLOCK_4 (p1); - }while (--lines); -} - -static void -xor_arm4regs_3 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2, -const unsigned long * __restrict p3) -{ -unsigned int lines = bytes /sizeof (unsigned long ) /4 ; - registerunsigned int a1 __asm__("r4" ); - registerunsigned int a2 __asm__("r5" ); - registerunsigned int a3 __asm__("r6" ); - registerunsigned int a4 __asm__("r10" ); - registerunsigned int b1 __asm__("r8" ); - registerunsigned int b2 __asm__("r9" ); - registerunsigned int b3 __asm__("ip" ); - registerunsigned int b4 __asm__("lr" ); - -do { -GET_BLOCK_4 (p1); -XOR_BLOCK_4 (p2); -XOR_BLOCK_4 (p3); -PUT_BLOCK_4 (p1); - }while (--lines); -} - -static void -xor_arm4regs_4 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2, -const unsigned long * __restrict p3, -const unsigned long * __restrict p4) -{ -unsigned int lines = bytes /sizeof (unsigned long ) /2 ; - registerunsigned int a1 __asm__("r8" ); - registerunsigned int a2 __asm__("r9" ); - registerunsigned int b1 __asm__("ip" ); - registerunsigned int b2 __asm__("lr" ); - -do { -GET_BLOCK_2 (p1); -XOR_BLOCK_2 (p2); -XOR_BLOCK_2 (p3); -XOR_BLOCK_2 (p4); -PUT_BLOCK_2 (p1); - }while (--lines); -} - -static void -xor_arm4regs_5 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2, -const unsigned long * __restrict p3, -const unsigned long * __restrict p4, -const unsigned long * __restrict p5) -{ -unsigned int lines = bytes /sizeof (unsigned long ) /2 ; - registerunsigned int a1 __asm__("r8" ); - registerunsigned int a2 __asm__("r9" ); - registerunsigned int b1 __asm__("ip" ); - registerunsigned int b2 __asm__("lr" ); - -do { -GET_BLOCK_2 (p1); -XOR_BLOCK_2 (p2); -XOR_BLOCK_2 (p3); -XOR_BLOCK_2 (p4); -XOR_BLOCK_2 (p5); -PUT_BLOCK_2 (p1); - }while (--lines); -} - -static struct xor_block_template xor_block_arm4regs = { - .name ="arm4regs" , - .do_2 = xor_arm4regs_2, - .do_3 = xor_arm4regs_3, - .do_4 = xor_arm4regs_4, - .do_5 = xor_arm4regs_5, -}; - -#ifdef CONFIG_KERNEL_MODE_NEON - -extern struct xor_block_template const xor_block_neon_inner; - -static void -xor_neon_2 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2) -{ -kernel_neon_begin (); - xor_block_neon_inner.do_2 (bytes, p1, p2); -kernel_neon_end (); -} - -static void -xor_neon_3 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2, -const unsigned long * __restrict p3) -{ -kernel_neon_begin (); - xor_block_neon_inner.do_3 (bytes, p1, p2, p3); -kernel_neon_end (); -} - -static void -xor_neon_4 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2, -const unsigned long * __restrict p3, -const unsigned long * __restrict p4) -{ -kernel_neon_begin (); - xor_block_neon_inner.do_4 (bytes, p1, p2, p3, p4); -kernel_neon_end (); -} - -static void -xor_neon_5 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2, -const unsigned long * __restrict p3, -const unsigned long * __restrict p4, -const unsigned long * __restrict p5) -{ -kernel_neon_begin (); - xor_block_neon_inner.do_5 (bytes, p1, p2, p3, p4, p5); -kernel_neon_end (); -} - -static struct xor_block_template xor_block_neon = { - .name ="neon" , - .do_2 = xor_neon_2, - .do_3 = xor_neon_3, - .do_4 = xor_neon_4, - .do_5 = xor_neon_5 -}; - -#endif /* CONFIG_KERNEL_MODE_NEON */ +extern struct xor_block_template xor_block_arm4regs; +extern struct xor_block_template xor_block_neon;#define arch_xor_init arch_xor_init static __always_inline void __init arch_xor_init(void)
arch/arm/lib/Makefile +0 -5
@@ -39,9 +39,4 @@ endif $(obj)/csumpartialcopy.o: $(obj)/csumpartialcopygeneric.S $(obj)/csumpartialcopyuser.o: $(obj)/csumpartialcopygeneric.S -ifeq ($(CONFIG_KERNEL_MODE_NEON),y) - CFLAGS_xor-neon.o += $(CC_FLAGS_FPU) - obj-$(CONFIG_XOR_BLOCKS) += xor-neon.o -endif - obj-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o
lib/raid/xor/Makefile +8 -0
@@ -9,3 +9,11 @@ xor-y += xor-8regs-prefetch.o xor-y += xor-32regs-prefetch.o xor-$(CONFIG_ALPHA) += alpha/xor.o +xor-$(CONFIG_ARM) += arm/xor.o +ifeq ($(CONFIG_ARM),y) +xor-$(CONFIG_KERNEL_MODE_NEON) += arm/xor-neon.o arm/xor-neon-glue.o +endif + + +CFLAGS_arm/xor-neon.o += $(CC_FLAGS_FPU) +CFLAGS_REMOVE_arm/xor-neon.o += $(CC_FLAGS_NO_FPU)
lib/raid/xor/arm/xor-neon-glue.c new file +58 -0
58 lines not on this page · raw message
lib/raid/xor/arm/xor-neon.c renamed from arch/arm/lib/xor-neon.c +1 -9
@@ -1,16 +1,9 @@// SPDX-License-Identifier: GPL-2.0-only /* -* linux/arch/arm/lib/xor-neon.c -* * Copyright (C) 2013 Linaro Ltd <[email protected]> */ -#include <linux/raid/xor.h> #include <linux/raid/xor_impl.h> -#include <linux/module.h> - -MODULE_DESCRIPTION ("NEON accelerated XOR implementation" ); -MODULE_LICENSE ("GPL" );#ifndef __ARM_NEON__#error You should compile this file with '-march=armv7-a -mfloat-abi=softfp -mfpu=neon'
@@ -27,7 +20,7 @@ MODULE_LICENSE("GPL");#endif #define NO_TEMPLATE -#include "../../../lib/raid/xor/xor-8regs.c" +#include "../xor-8regs.c" struct xor_block_template const xor_block_neon_inner = { .name ="__inner_neon__" ,
@@ -36,4 +29,3 @@ struct xor_block_template const xor_block_neon_inner = { .do_4 = xor_8regs_4, .do_5 = xor_8regs_5, }; -EXPORT_SYMBOL (xor_block_neon_inner);
lib/raid/xor/arm/xor.c new file +136 -0
136 lines not on this page · raw message
Signature · 1 line
2.47.3
PATCH 12/26 arm64: move the XOR code to lib/raid/
In reply to Christoph HellwigMove the optimized XOR into lib/raid and include it it in the main xor.ko instead of building a separate module for it.
Note that this drops the CONFIG_KERNEL_MODE_NEON dependency, as that is always set for arm64.
---
arch/arm64/include/asm/xor.h | 58 +------------------
arch/arm64/lib/Makefile | 6 --
lib/raid/xor/Makefile | 4 ++
lib/raid/xor/arm64/xor-neon-glue.c | 57 ++++++++++++++++++
.../lib => lib/raid/xor/arm64}/xor-neon.c | 20 +------
5 files changed, 67 insertions(+), 78 deletions(-)
create mode 100644 lib/raid/xor/arm64/xor-neon-glue.c
rename {arch/arm64/lib => lib/raid/xor/arm64}/xor-neon.c (95%)arch/arm64/include/asm/xor.h +3 -55
@@ -1,73 +1,21 @@/* SPDX-License-Identifier: GPL-2.0-only */ /* -* arch/arm64/include/asm/xor.h -* * Authors: Jackie Liu <[email protected]> * Copyright (C) 2018,Tianjin KYLIN Information Technology Co., Ltd. */ -#include <linux/hardirq.h> #include <asm-generic/xor.h> -#include <asm/hwcap.h> #include <asm/simd.h> -#ifdef CONFIG_KERNEL_MODE_NEON - -extern struct xor_block_template const xor_block_inner_neon; - -static void -xor_neon_2 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2) -{ - scoped_ksimd() - xor_block_inner_neon.do_2 (bytes, p1, p2); -} - -static void -xor_neon_3 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2, -const unsigned long * __restrict p3) -{ - scoped_ksimd() - xor_block_inner_neon.do_3 (bytes, p1, p2, p3); -} - -static void -xor_neon_4 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2, -const unsigned long * __restrict p3, -const unsigned long * __restrict p4) -{ - scoped_ksimd() - xor_block_inner_neon.do_4 (bytes, p1, p2, p3, p4); -} - -static void -xor_neon_5 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2, -const unsigned long * __restrict p3, -const unsigned long * __restrict p4, -const unsigned long * __restrict p5) -{ - scoped_ksimd() - xor_block_inner_neon.do_5 (bytes, p1, p2, p3, p4, p5); -} - -static struct xor_block_template xor_block_arm64 = { - .name ="arm64_neon" , - .do_2 = xor_neon_2, - .do_3 = xor_neon_3, - .do_4 = xor_neon_4, - .do_5 = xor_neon_5 -}; +extern struct xor_block_template xor_block_arm64; +void __init xor_neon_init (void );#define arch_xor_init arch_xor_init static __always_inline void __init arch_xor_init(void) { +xor_neon_init ();xor_register (&xor_block_8regs);xor_register (&xor_block_32regs);if (cpu_has_neon ())xor_register (&xor_block_arm64); } - -#endif /* ! CONFIG_KERNEL_MODE_NEON */
arch/arm64/lib/Makefile +0 -6
@@ -5,12 +5,6 @@ lib-y := clear_user.o delay.o copy_from_user.o \ memset.o memcmp.o strcmp.o strncmp.o strlen.o \ strnlen.o strchr.o strrchr.o tishift.o -ifeq ($(CONFIG_KERNEL_MODE_NEON), y) -obj-$(CONFIG_XOR_BLOCKS) += xor-neon.o -CFLAGS_xor-neon.o += $(CC_FLAGS_FPU) -CFLAGS_REMOVE_xor-neon.o += $(CC_FLAGS_NO_FPU) -endif - lib-$(CONFIG_ARCH_HAS_UACCESS_FLUSHCACHE) += uaccess_flushcache.o obj-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o
lib/raid/xor/Makefile +4 -0
@@ -13,7 +13,11 @@ xor-$(CONFIG_ARM) += arm/xor.o ifeq ($(CONFIG_ARM),y) xor-$(CONFIG_KERNEL_MODE_NEON) += arm/xor-neon.o arm/xor-neon-glue.o endif +xor-$(CONFIG_ARM64) += arm64/xor-neon.o arm64/xor-neon-glue.o CFLAGS_arm/xor-neon.o += $(CC_FLAGS_FPU) CFLAGS_REMOVE_arm/xor-neon.o += $(CC_FLAGS_NO_FPU) + +CFLAGS_arm64/xor-neon.o += $(CC_FLAGS_FPU) +CFLAGS_REMOVE_arm64/xor-neon.o += $(CC_FLAGS_NO_FPU)
lib/raid/xor/arm64/xor-neon-glue.c new file +57 -0
57 lines not on this page · raw message
lib/raid/xor/arm64/xor-neon.c renamed from arch/arm64/lib/xor-neon.c +3 -17
@@ -1,15 +1,13 @@// SPDX-License-Identifier: GPL-2.0-only /* -* arch/arm64/lib/xor-neon.c -* * Authors: Jackie Liu <[email protected]> * Copyright (C) 2018,Tianjin KYLIN Information Technology Co., Ltd. */ -#include <linux/raid/xor.h> #include <linux/raid/xor_impl.h> -#include <linux/module.h> +#include <linux/cache.h> #include <asm/neon-intrinsics.h> +#include <asm/xor.h> static void xor_arm64_neon_2 (unsigned long bytes,unsigned long * __restrict p1,const unsigned long * __restrict p2)
@@ -180,7 +178,6 @@ struct xor_block_template xor_block_inner_neon __ro_after_init = { .do_4 = xor_arm64_neon_4, .do_5 = xor_arm64_neon_5, }; -EXPORT_SYMBOL (xor_block_inner_neon);static inline uint64x2_t eor3 (uint64x2_t p,uint64x2_t q,uint64x2_t r) {
@@ -318,22 +315,11 @@ static void xor_arm64_eor3_5(unsigned long bytes, }while (--lines >0 ); } -static int __init xor_neon_init (void ) +void __init xor_neon_init (void ) {if (cpu_have_named_feature (SHA3 )) { xor_block_inner_neon.do_3 = xor_arm64_eor3_3; xor_block_inner_neon.do_4 = xor_arm64_eor3_4; xor_block_inner_neon.do_5 = xor_arm64_eor3_5; } -return 0 ; } -module_init (xor_neon_init); - -static void __exit xor_neon_exit(void) -{ -} -module_exit (xor_neon_exit); - -MODULE_AUTHOR ("Jackie Liu <[email protected]>" ); -MODULE_DESCRIPTION ("ARMv8 XOR Extensions" ); -MODULE_LICENSE ("GPL" );
Signature · 1 line
2.47.3
PATCH 13/26 loongarch: move the XOR code to lib/raid/
In reply to Christoph HellwigMove the optimized XOR into lib/raid and include it it in xor.ko instead of always building it into the main kernel image.
---
arch/loongarch/include/asm/xor.h | 24 ++----------
arch/loongarch/include/asm/xor_simd.h | 34 ----------------
arch/loongarch/lib/Makefile | 2 -
lib/raid/xor/Makefile | 2 +
.../lib => lib/raid/xor/loongarch}/xor_simd.c | 0
.../lib => lib/raid/xor/loongarch}/xor_simd.h | 0
.../raid/xor/loongarch}/xor_simd_glue.c | 39 +++++++++++--------
.../raid/xor/loongarch}/xor_template.c | 0
8 files changed, 27 insertions(+), 74 deletions(-)
delete mode 100644 arch/loongarch/include/asm/xor_simd.h
rename {arch/loongarch/lib => lib/raid/xor/loongarch}/xor_simd.c (100%)
rename {arch/loongarch/lib => lib/raid/xor/loongarch}/xor_simd.h (100%)
rename {arch/loongarch/lib => lib/raid/xor/loongarch}/xor_simd_glue.c (64%)
rename {arch/loongarch/lib => lib/raid/xor/loongarch}/xor_template.c (100%)arch/loongarch/include/asm/xor.h +3 -21
@@ -6,27 +6,6 @@#define _ASM_LOONGARCH_XOR_H#include <asm/cpu-features.h> -#include <asm/xor_simd.h> - -#ifdef CONFIG_CPU_HAS_LSX -static struct xor_block_template xor_block_lsx = { - .name ="lsx" , - .do_2 = xor_lsx_2, - .do_3 = xor_lsx_3, - .do_4 = xor_lsx_4, - .do_5 = xor_lsx_5, -}; -#endif /* CONFIG_CPU_HAS_LSX */ - -#ifdef CONFIG_CPU_HAS_LASX -static struct xor_block_template xor_block_lasx = { - .name ="lasx" , - .do_2 = xor_lasx_2, - .do_3 = xor_lasx_3, - .do_4 = xor_lasx_4, - .do_5 = xor_lasx_5, -}; -#endif /* CONFIG_CPU_HAS_LASX */ /* * For grins, also test the generic routines.
@@ -38,6 +17,9 @@ static struct xor_block_template xor_block_lasx = {*/ #include <asm-generic/xor.h> +extern struct xor_block_template xor_block_lsx; +extern struct xor_block_template xor_block_lasx; +#define arch_xor_init arch_xor_init static __always_inline void __init arch_xor_init(void) {
arch/loongarch/include/asm/xor_simd.h deleted +0 -34
@@ -1,34 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* -* Copyright (C) 2023 WANG Xuerui <[email protected]> -*/ -#ifndef _ASM_LOONGARCH_XOR_SIMD_H -#define _ASM_LOONGARCH_XOR_SIMD_H - -#ifdef CONFIG_CPU_HAS_LSX -void xor_lsx_2 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2); -void xor_lsx_3 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2,const unsigned long * __restrict p3); -void xor_lsx_4 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2,const unsigned long * __restrict p3, -const unsigned long * __restrict p4); -void xor_lsx_5 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2,const unsigned long * __restrict p3, -const unsigned long * __restrict p4,const unsigned long * __restrict p5); -#endif /* CONFIG_CPU_HAS_LSX */ - -#ifdef CONFIG_CPU_HAS_LASX -void xor_lasx_2 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2); -void xor_lasx_3 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2,const unsigned long * __restrict p3); -void xor_lasx_4 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2,const unsigned long * __restrict p3, -const unsigned long * __restrict p4); -void xor_lasx_5 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2,const unsigned long * __restrict p3, -const unsigned long * __restrict p4,const unsigned long * __restrict p5); -#endif /* CONFIG_CPU_HAS_LASX */ - -#endif /* _ASM_LOONGARCH_XOR_SIMD_H */
arch/loongarch/lib/Makefile +0 -2
@@ -8,6 +8,4 @@ lib-y += delay.o memset.o memcpy.o memmove.o \ obj-$(CONFIG_ARCH_SUPPORTS_INT128) += tishift.o -obj-$(CONFIG_CPU_HAS_LSX) += xor_simd.o xor_simd_glue.o - obj-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o
lib/raid/xor/Makefile +2 -0
@@ -14,6 +14,8 @@ ifeq ($(CONFIG_ARM),y) xor-$(CONFIG_KERNEL_MODE_NEON) += arm/xor-neon.o arm/xor-neon-glue.o endif xor-$(CONFIG_ARM64) += arm64/xor-neon.o arm64/xor-neon-glue.o +xor-$(CONFIG_CPU_HAS_LSX) += loongarch/xor_simd.o +xor-$(CONFIG_CPU_HAS_LSX) += loongarch/xor_simd_glue.o CFLAGS_arm/xor-neon.o += $(CC_FLAGS_FPU)
lib/raid/xor/loongarch/xor_simd.c renamed from arch/loongarch/lib/xor_simd.c +0 -0
lib/raid/xor/loongarch/xor_simd.h renamed from arch/loongarch/lib/xor_simd.h +0 -0
lib/raid/xor/loongarch/xor_simd_glue.c renamed from arch/loongarch/lib/xor_simd_glue.c +22 -17
@@ -5,24 +5,23 @@* Copyright (C) 2023 WANG Xuerui <[email protected]> */ -#include <linux/export.h> #include <linux/sched.h> +#include <linux/raid/xor_impl.h> #include <asm/fpu.h> -#include <asm/xor_simd.h> +#include <asm/xor.h> #include "xor_simd.h" #define MAKE_XOR_GLUE_2 (flavor) \ -void xor_##flavor##_2(unsigned long bytes, unsigned long * __restrict p1, \ +static void xor_##flavor##_2(unsigned long bytes, unsigned long * __restrict p1,\ const unsigned long * __restrict p2) \ { \ kernel_fpu_begin(); \ __xor_##flavor##_2(bytes, p1, p2); \ kernel_fpu_end(); \ } \ -EXPORT_SYMBOL_GPL(xor_##flavor##_2)#define MAKE_XOR_GLUE_3 (flavor) \ -void xor_##flavor##_3(unsigned long bytes, unsigned long * __restrict p1, \ +static void xor_##flavor##_3(unsigned long bytes, unsigned long * __restrict p1,\ const unsigned long * __restrict p2, \ const unsigned long * __restrict p3) \ { \
@@ -30,10 +29,9 @@ void xor_##flavor##_3(unsigned long bytes, unsigned long * __restrict p1, \ __xor_##flavor##_3(bytes, p1, p2, p3); \ kernel_fpu_end(); \ } \ -EXPORT_SYMBOL_GPL(xor_##flavor##_3)#define MAKE_XOR_GLUE_4 (flavor) \ -void xor_##flavor##_4(unsigned long bytes, unsigned long * __restrict p1, \ +static void xor_##flavor##_4(unsigned long bytes, unsigned long * __restrict p1,\ const unsigned long * __restrict p2, \ const unsigned long * __restrict p3, \ const unsigned long * __restrict p4) \
@@ -42,10 +40,9 @@ void xor_##flavor##_4(unsigned long bytes, unsigned long * __restrict p1, \ __xor_##flavor##_4(bytes, p1, p2, p3, p4); \ kernel_fpu_end(); \ } \ -EXPORT_SYMBOL_GPL(xor_##flavor##_4)#define MAKE_XOR_GLUE_5 (flavor) \ -void xor_##flavor##_5(unsigned long bytes, unsigned long * __restrict p1, \ +static void xor_##flavor##_5(unsigned long bytes, unsigned long * __restrict p1,\ const unsigned long * __restrict p2, \ const unsigned long * __restrict p3, \ const unsigned long * __restrict p4, \
@@ -55,18 +52,26 @@ void xor_##flavor##_5(unsigned long bytes, unsigned long * __restrict p1, \ __xor_##flavor##_5(bytes, p1, p2, p3, p4, p5); \ kernel_fpu_end(); \ } \ -EXPORT_SYMBOL_GPL(xor_##flavor##_5) -#define MAKE_XOR_GLUES (flavor) \ - MAKE_XOR_GLUE_2(flavor); \ - MAKE_XOR_GLUE_3(flavor); \ - MAKE_XOR_GLUE_4(flavor); \ - MAKE_XOR_GLUE_5(flavor) +#define MAKE_XOR_GLUES (flavor) \ + MAKE_XOR_GLUE_2(flavor); \ + MAKE_XOR_GLUE_3(flavor); \ + MAKE_XOR_GLUE_4(flavor); \ + MAKE_XOR_GLUE_5(flavor); \ + \ +struct xor_block_template xor_block_##flavor = { \ + .name = __stringify(flavor), \ + .do_2 = xor_##flavor##_2, \ + .do_3 = xor_##flavor##_3, \ + .do_4 = xor_##flavor##_4, \ + .do_5 = xor_##flavor##_5, \ +} +#ifdef CONFIG_CPU_HAS_LSX MAKE_XOR_GLUES (lsx); -#endif +#endif /* CONFIG_CPU_HAS_LSX */ #ifdef CONFIG_CPU_HAS_LASX MAKE_XOR_GLUES (lasx); -#endif +#endif /* CONFIG_CPU_HAS_LASX */
lib/raid/xor/loongarch/xor_template.c renamed from arch/loongarch/lib/xor_template.c +0 -0
Signature · 1 line
2.47.3
PATCH 14/26 powerpc: move the XOR code to lib/raid/
In reply to Christoph HellwigMove the optimized XOR into lib/raid and include it it in xor.ko instead of always building it into the main kernel image.
---
arch/powerpc/include/asm/xor.h | 17 +----
arch/powerpc/include/asm/xor_altivec.h | 22 ------
arch/powerpc/lib/Makefile | 5 --
arch/powerpc/lib/xor_vmx_glue.c | 63 -----------------
lib/raid/xor/Makefile | 5 ++
.../lib => lib/raid/xor/powerpc}/xor_vmx.c | 0
.../lib => lib/raid/xor/powerpc}/xor_vmx.h | 0
lib/raid/xor/powerpc/xor_vmx_glue.c | 67 +++++++++++++++++++
8 files changed, 74 insertions(+), 105 deletions(-)
delete mode 100644 arch/powerpc/include/asm/xor_altivec.h
delete mode 100644 arch/powerpc/lib/xor_vmx_glue.c
rename {arch/powerpc/lib => lib/raid/xor/powerpc}/xor_vmx.c (100%)
rename {arch/powerpc/lib => lib/raid/xor/powerpc}/xor_vmx.h (100%)
create mode 100644 lib/raid/xor/powerpc/xor_vmx_glue.carch/powerpc/include/asm/xor.h +2 -15
@@ -8,24 +8,11 @@#ifndef _ASM_POWERPC_XOR_H#define _ASM_POWERPC_XOR_H -#ifdef CONFIG_ALTIVEC - -#include <asm/cputable.h> #include <asm/cpu_has_feature.h> -#include <asm/xor_altivec.h> - -static struct xor_block_template xor_block_altivec = { - .name ="altivec" , - .do_2 = xor_altivec_2, - .do_3 = xor_altivec_3, - .do_4 = xor_altivec_4, - .do_5 = xor_altivec_5, -}; -#endif /* CONFIG_ALTIVEC */ - -/* Also try the generic routines. */ #include <asm-generic/xor.h> +extern struct xor_block_template xor_block_altivec; +#define arch_xor_init arch_xor_init static __always_inline void __init arch_xor_init(void) {
arch/powerpc/include/asm/xor_altivec.h deleted +0 -22
@@ -1,22 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef _ASM_POWERPC_XOR_ALTIVEC_H -#define _ASM_POWERPC_XOR_ALTIVEC_H - -#ifdef CONFIG_ALTIVEC -void xor_altivec_2 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2); -void xor_altivec_3 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2, -const unsigned long * __restrict p3); -void xor_altivec_4 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2, -const unsigned long * __restrict p3, -const unsigned long * __restrict p4); -void xor_altivec_5 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2, -const unsigned long * __restrict p3, -const unsigned long * __restrict p4, -const unsigned long * __restrict p5); - -#endif -#endif /* _ASM_POWERPC_XOR_ALTIVEC_H */
arch/powerpc/lib/Makefile +0 -5
@@ -73,9 +73,4 @@ obj-$(CONFIG_PPC_LIB_RHEAP) += rheap.o obj-$(CONFIG_FTR_FIXUP_SELFTEST) += feature-fixups-test.o -obj-$(CONFIG_ALTIVEC) += xor_vmx.o xor_vmx_glue.o -CFLAGS_xor_vmx.o += -mhard-float -maltivec $(call cc-option,-mabi=altivec) -# Enable <altivec.h> -CFLAGS_xor_vmx.o += -isystem $(shell $(CC) -print-file-name=include) - obj-$(CONFIG_PPC64) += $(obj64-y)
arch/powerpc/lib/xor_vmx_glue.c deleted +0 -63
63 lines not on this page · raw message
lib/raid/xor/Makefile +5 -0
@@ -16,6 +16,7 @@ endif xor-$(CONFIG_ARM64) += arm64/xor-neon.o arm64/xor-neon-glue.o xor-$(CONFIG_CPU_HAS_LSX) += loongarch/xor_simd.o xor-$(CONFIG_CPU_HAS_LSX) += loongarch/xor_simd_glue.o +xor-$(CONFIG_ALTIVEC) += powerpc/xor_vmx.o powerpc/xor_vmx_glue.o CFLAGS_arm/xor-neon.o += $(CC_FLAGS_FPU)
@@ -23,3 +24,7 @@ CFLAGS_REMOVE_arm/xor-neon.o += $(CC_FLAGS_NO_FPU) CFLAGS_arm64/xor-neon.o += $(CC_FLAGS_FPU) CFLAGS_REMOVE_arm64/xor-neon.o += $(CC_FLAGS_NO_FPU) + +CFLAGS_powerpc/xor_vmx.o += -mhard-float -maltivec \ + $(call cc-option,-mabi=altivec) \ + -isystem $(shell $(CC) -print-file-name=include)
lib/raid/xor/powerpc/xor_vmx.c renamed from arch/powerpc/lib/xor_vmx.c +0 -0
lib/raid/xor/powerpc/xor_vmx.h renamed from arch/powerpc/lib/xor_vmx.h +0 -0
lib/raid/xor/powerpc/xor_vmx_glue.c new file +67 -0
67 lines not on this page · raw message
Signature · 1 line
2.47.3
PATCH 15/26 riscv: move the XOR code to lib/raid/
In reply to Christoph HellwigMove the optimized XOR into lib/raid and include it it in xor.ko instead of always building it into the main kernel image.
---
arch/riscv/include/asm/xor.h | 54 +------------------
arch/riscv/lib/Makefile | 1 -
lib/raid/xor/Makefile | 1 +
lib/raid/xor/riscv/xor-glue.c | 56 ++++++++++++++++++++
{arch/riscv/lib => lib/raid/xor/riscv}/xor.S | 4 --
5 files changed, 59 insertions(+), 57 deletions(-)
create mode 100644 lib/raid/xor/riscv/xor-glue.c
rename {arch/riscv/lib => lib/raid/xor/riscv}/xor.S (92%)arch/riscv/include/asm/xor.h +2 -52
@@ -2,60 +2,10 @@/* * Copyright (C) 2021 SiFive */ - -#include <linux/hardirq.h> -#include <asm-generic/xor.h> -#ifdef CONFIG_RISCV_ISA_V #include <asm/vector.h> -#include <asm/switch_to.h> -#include <asm/asm-prototypes.h> - -static void xor_vector_2 (unsigned long bytes,unsigned long *__restrict p1, -const unsigned long *__restrict p2) -{ -kernel_vector_begin (); -xor_regs_2_ (bytes, p1, p2); -kernel_vector_end (); -} - -static void xor_vector_3 (unsigned long bytes,unsigned long *__restrict p1, -const unsigned long *__restrict p2, -const unsigned long *__restrict p3) -{ -kernel_vector_begin (); -xor_regs_3_ (bytes, p1, p2, p3); -kernel_vector_end (); -} - -static void xor_vector_4 (unsigned long bytes,unsigned long *__restrict p1, -const unsigned long *__restrict p2, -const unsigned long *__restrict p3, -const unsigned long *__restrict p4) -{ -kernel_vector_begin (); -xor_regs_4_ (bytes, p1, p2, p3, p4); -kernel_vector_end (); -} - -static void xor_vector_5 (unsigned long bytes,unsigned long *__restrict p1, -const unsigned long *__restrict p2, -const unsigned long *__restrict p3, -const unsigned long *__restrict p4, -const unsigned long *__restrict p5) -{ -kernel_vector_begin (); -xor_regs_5_ (bytes, p1, p2, p3, p4, p5); -kernel_vector_end (); -} +#include <asm-generic/xor.h> -static struct xor_block_template xor_block_rvv = { - .name ="rvv" , - .do_2 = xor_vector_2, - .do_3 = xor_vector_3, - .do_4 = xor_vector_4, - .do_5 = xor_vector_5 -}; -#endif /* CONFIG_RISCV_ISA_V */ +extern struct xor_block_template xor_block_rvv;#define arch_xor_init arch_xor_init static __always_inline void __init arch_xor_init(void)
arch/riscv/lib/Makefile +0 -1
@@ -16,5 +16,4 @@ lib-$(CONFIG_MMU) += uaccess.o lib-$(CONFIG_64BIT) += tishift.o lib-$(CONFIG_RISCV_ISA_ZICBOZ) += clear_page.o obj-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o -lib-$(CONFIG_RISCV_ISA_V) += xor.o lib-$(CONFIG_RISCV_ISA_V) += riscv_v_helpers.o
lib/raid/xor/Makefile +1 -0
@@ -17,6 +17,7 @@ xor-$(CONFIG_ARM64) += arm64/xor-neon.o arm64/xor-neon-glue.o xor-$(CONFIG_CPU_HAS_LSX) += loongarch/xor_simd.o xor-$(CONFIG_CPU_HAS_LSX) += loongarch/xor_simd_glue.o xor-$(CONFIG_ALTIVEC) += powerpc/xor_vmx.o powerpc/xor_vmx_glue.o +xor-$(CONFIG_RISCV_ISA_V) += riscv/xor.o riscv/xor-glue.o CFLAGS_arm/xor-neon.o += $(CC_FLAGS_FPU)
lib/raid/xor/riscv/xor-glue.c new file +56 -0
56 lines not on this page · raw message
lib/raid/xor/riscv/xor.S renamed from arch/riscv/lib/xor.S +0 -4
@@ -18,7 +18,6 @@ SYM_FUNC_START(xor_regs_2_) bnez a0, xor_regs_2_ ret SYM_FUNC_END(xor_regs_2_) -EXPORT_SYMBOL(xor_regs_2_) SYM_FUNC_START(xor_regs_3_) vsetvli a4, a0, e8, m8, ta, ma
@@ -35,7 +34,6 @@ SYM_FUNC_START(xor_regs_3_) bnez a0, xor_regs_3_ ret SYM_FUNC_END(xor_regs_3_) -EXPORT_SYMBOL(xor_regs_3_) SYM_FUNC_START(xor_regs_4_) vsetvli a5, a0, e8, m8, ta, ma
@@ -55,7 +53,6 @@ SYM_FUNC_START(xor_regs_4_) bnez a0, xor_regs_4_ ret SYM_FUNC_END(xor_regs_4_) -EXPORT_SYMBOL(xor_regs_4_) SYM_FUNC_START(xor_regs_5_) vsetvli a6, a0, e8, m8, ta, ma
@@ -78,4 +75,3 @@ SYM_FUNC_START(xor_regs_5_) bnez a0, xor_regs_5_ ret SYM_FUNC_END(xor_regs_5_) -EXPORT_SYMBOL(xor_regs_5_)
Signature · 1 line
2.47.3
PATCH 16/26 sparc: move the XOR code to lib/raid/
In reply to Christoph HellwigMove the optimized XOR into lib/raid and include it it in xor.ko instead of always building it into the main kernel image.
The code should probably be split into separate files for the two implementations, but for now this just does the trivial move.
--- arch/sparc/include/asm/asm-prototypes.h | 1 - arch/sparc/include/asm/xor.h | 45 ++++++++++++++++--- arch/sparc/lib/Makefile | 2 +- lib/raid/xor/Makefile | 2 + .../raid/xor/sparc/xor-sparc32.c | 23 ++-------- .../raid/xor/sparc/xor-sparc64-glue.c | 26 +++-------- .../xor.S => lib/raid/xor/sparc/xor-sparc64.S | 10 ----- 7 files changed, 52 insertions(+), 57 deletions(-) rename arch/sparc/include/asm/xor_32.h => lib/raid/xor/sparc/xor-sparc32.c (93%) rename arch/sparc/include/asm/xor_64.h => lib/raid/xor/sparc/xor-sparc64-glue.c (74%) rename arch/sparc/lib/xor.S => lib/raid/xor/sparc/xor-sparc64.S (98%)
arch/sparc/include/asm/asm-prototypes.h +0 -1
@@ -14,7 +14,6 @@#include <asm/oplib.h> #include <asm/pgtable.h> #include <asm/trap_block.h> -#include <asm/xor.h> void *__memscan_zero (void *,size_t );void *__memscan_generic (void *,int ,size_t );
arch/sparc/include/asm/xor.h +40 -5
49 lines not on this page · raw message
arch/sparc/lib/Makefile +1 -1
@@ -48,7 +48,7 @@ lib-$(CONFIG_SPARC64) += GENmemcpy.o GENcopy_from_user.o GENcopy_to_user.o lib-$(CONFIG_SPARC64) += GENpatch.o GENpage.o GENbzero.o lib-$(CONFIG_SPARC64) += copy_in_user.o memmove.o -lib-$(CONFIG_SPARC64) += mcount.o ipcsum.o xor.o hweight.o ffs.o +lib-$(CONFIG_SPARC64) += mcount.o ipcsum.o hweight.o ffs.o obj-$(CONFIG_SPARC64) += iomap.o obj-$(CONFIG_SPARC32) += atomic32.o
lib/raid/xor/Makefile +2 -0
@@ -18,6 +18,8 @@ xor-$(CONFIG_CPU_HAS_LSX) += loongarch/xor_simd.o xor-$(CONFIG_CPU_HAS_LSX) += loongarch/xor_simd_glue.o xor-$(CONFIG_ALTIVEC) += powerpc/xor_vmx.o powerpc/xor_vmx_glue.o xor-$(CONFIG_RISCV_ISA_V) += riscv/xor.o riscv/xor-glue.o +xor-$(CONFIG_SPARC32) += sparc/xor-sparc32.o +xor-$(CONFIG_SPARC64) += sparc/xor-sparc64.o sparc/xor-sparc64-glue.o CFLAGS_arm/xor-neon.o += $(CC_FLAGS_FPU)
lib/raid/xor/sparc/xor-sparc32.c renamed from arch/sparc/include/asm/xor_32.h +4 -19
@@ -1,16 +1,12 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* -* include/asm/xor.h -* -* Optimized RAID-5 checksumming functions for 32-bit Sparc. -*/ - +// SPDX-License-Identifier: GPL-2.0-or-later /* * High speed xor_block operation for RAID4/5 utilizing the * ldd/std SPARC instructions. * * Copyright (C) 1999 Jakub Jelinek ([email protected]) */ +#include <linux/raid/xor_impl.h> +#include <asm/xor.h> static void sparc_2(unsigned long bytes, unsigned long * __restrict p1,
@@ -248,21 +244,10 @@ sparc_5(unsigned long bytes, unsigned long * __restrict p1, }while (--lines >0 ); } -static struct xor_block_template xor_block_SPARC = { +struct xor_block_template xor_block_SPARC = { .name ="SPARC" , .do_2 = sparc_2, .do_3 = sparc_3, .do_4 = sparc_4, .do_5 = sparc_5, }; - -/* For grins, also test the generic routines. */ -#include <asm-generic/xor.h> - -#define arch_xor_init arch_xor_init -static __always_inline void __init arch_xor_init(void) -{ -xor_register (&xor_block_8regs); -xor_register (&xor_block_32regs); -xor_register (&xor_block_SPARC); -}
lib/raid/xor/sparc/xor-sparc64-glue.c renamed from arch/sparc/include/asm/xor_64.h +5 -21
@@ -1,7 +1,5 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ +// SPDX-License-Identifier: GPL-2.0-or-later /* -* include/asm/xor.h -* * High speed xor_block operation for RAID4/5 utilizing the * UltraSparc Visual Instruction Set and Niagara block-init * twin-load instructions.
@@ -10,7 +8,8 @@* Copyright (C) 2006 David S. Miller <[email protected]> */ -#include <asm/spitfire.h> +#include <linux/raid/xor_impl.h> +#include <asm/xor.h> void xor_vis_2 (unsigned long bytes,unsigned long * __restrict p1,const unsigned long * __restrict p2);
@@ -29,7 +28,7 @@ void xor_vis_5(unsigned long bytes, unsigned long * __restrict p1,/* XXX Ugh, write cheetah versions... -DaveM */ -static struct xor_block_template xor_block_VIS = { +struct xor_block_template xor_block_VIS = { .name ="VIS" , .do_2 = xor_vis_2, .do_3 = xor_vis_3,
@@ -52,25 +51,10 @@ void xor_niagara_5(unsigned long bytes, unsigned long * __restrict p1,const unsigned long * __restrict p4, const unsigned long * __restrict p5); -static struct xor_block_template xor_block_niagara = { +struct xor_block_template xor_block_niagara = { .name ="Niagara" , .do_2 = xor_niagara_2, .do_3 = xor_niagara_3, .do_4 = xor_niagara_4, .do_5 = xor_niagara_5, }; - -#define arch_xor_init arch_xor_init -static __always_inline void __init arch_xor_init(void) -{ -/* Force VIS for everything except Niagara. */ -if (tlb_type == hypervisor && - (sun4v_chip_type ==SUN4V_CHIP_NIAGARA1 || - sun4v_chip_type ==SUN4V_CHIP_NIAGARA2 || - sun4v_chip_type ==SUN4V_CHIP_NIAGARA3 || - sun4v_chip_type ==SUN4V_CHIP_NIAGARA4 || - sun4v_chip_type ==SUN4V_CHIP_NIAGARA5 )) -xor_force (&xor_block_niagara); -else -xor_force (&xor_block_VIS); -}
lib/raid/xor/sparc/xor-sparc64.S renamed from arch/sparc/lib/xor.S +0 -10
@@ -1,7 +1,5 @@ /* SPDX-License-Identifier: GPL-2.0 */ /* - * arch/sparc64/lib/xor.S - * * High speed xor_block operation for RAID4/5 utilizing the * UltraSparc Visual Instruction Set and Niagara store-init/twin-load. *
@@ -92,7 +90,6 @@ ENTRY(xor_vis_2) retl wr %g0, 0, %fprs ENDPROC(xor_vis_2) -EXPORT_SYMBOL(xor_vis_2) ENTRY(xor_vis_3) rd %fprs, %o5
@@ -159,7 +156,6 @@ ENTRY(xor_vis_3) retl wr %g0, 0, %fprs ENDPROC(xor_vis_3) -EXPORT_SYMBOL(xor_vis_3) ENTRY(xor_vis_4) rd %fprs, %o5
@@ -245,7 +241,6 @@ ENTRY(xor_vis_4) retl wr %g0, 0, %fprs ENDPROC(xor_vis_4) -EXPORT_SYMBOL(xor_vis_4) ENTRY(xor_vis_5) save %sp, -192, %sp
@@ -352,7 +347,6 @@ ENTRY(xor_vis_5) ret restore ENDPROC(xor_vis_5) -EXPORT_SYMBOL(xor_vis_5) /* Niagara versions. */ ENTRY(xor_niagara_2) /* %o0=bytes, %o1=dest, %o2=src */
@@ -399,7 +393,6 @@ ENTRY(xor_niagara_2) /* %o0=bytes, %o1=dest, %o2=src */ ret restore ENDPROC(xor_niagara_2) -EXPORT_SYMBOL(xor_niagara_2) ENTRY(xor_niagara_3) /* %o0=bytes, %o1=dest, %o2=src1, %o3=src2 */ save %sp, -192, %sp
@@ -461,7 +454,6 @@ ENTRY(xor_niagara_3) /* %o0=bytes, %o1=dest, %o2=src1, %o3=src2 */ ret restore ENDPROC(xor_niagara_3) -EXPORT_SYMBOL(xor_niagara_3) ENTRY(xor_niagara_4) /* %o0=bytes, %o1=dest, %o2=src1, %o3=src2, %o4=src3 */ save %sp, -192, %sp
@@ -544,7 +536,6 @@ ENTRY(xor_niagara_4) /* %o0=bytes, %o1=dest, %o2=src1, %o3=src2, %o4=src3 */ ret restore ENDPROC(xor_niagara_4) -EXPORT_SYMBOL(xor_niagara_4) ENTRY(xor_niagara_5) /* %o0=bytes, %o1=dest, %o2=src1, %o3=src2, %o4=src3, %o5=src4 */ save %sp, -192, %sp
@@ -643,4 +634,3 @@ ENTRY(xor_niagara_5) /* %o0=bytes, %o1=dest, %o2=src1, %o3=src2, %o4=src3, %o5=s ret restore ENDPROC(xor_niagara_5) -EXPORT_SYMBOL(xor_niagara_5)
Signature · 1 line
2.47.3
PATCH 17/26 s390: move the XOR code to lib/raid/
In reply to Christoph HellwigMove the optimized XOR into lib/raid and include it it in xor.ko instead of unconditionally building it into the main kernel image.
---
arch/s390/lib/Makefile | 2 +-
lib/raid/xor/Makefile | 1 +
{arch/s390/lib => lib/raid/xor/s390}/xor.c | 2 --
3 files changed, 2 insertions(+), 3 deletions(-)
rename {arch/s390/lib => lib/raid/xor/s390}/xor.c (98%)arch/s390/lib/Makefile +1 -1
@@ -5,7 +5,7 @@ lib-y += delay.o string.o uaccess.o find.o spinlock.o tishift.o lib-y += csum-partial.o -obj-y += mem.o xor.o +obj-y += mem.o lib-$(CONFIG_KPROBES) += probes.o lib-$(CONFIG_UPROBES) += probes.o obj-$(CONFIG_S390_KPROBES_SANITY_TEST) += test_kprobes_s390.o
lib/raid/xor/Makefile +1 -0
@@ -20,6 +20,7 @@ xor-$(CONFIG_ALTIVEC) += powerpc/xor_vmx.o powerpc/xor_vmx_glue.o xor-$(CONFIG_RISCV_ISA_V) += riscv/xor.o riscv/xor-glue.o xor-$(CONFIG_SPARC32) += sparc/xor-sparc32.o xor-$(CONFIG_SPARC64) += sparc/xor-sparc64.o sparc/xor-sparc64-glue.o +xor-$(CONFIG_S390) += s390/xor.o CFLAGS_arm/xor-neon.o += $(CC_FLAGS_FPU)
lib/raid/xor/s390/xor.c renamed from arch/s390/lib/xor.c +0 -2
@@ -7,7 +7,6 @@*/ #include <linux/types.h> -#include <linux/export.h> #include <linux/raid/xor_impl.h> #include <asm/xor.h>
@@ -133,4 +132,3 @@ struct xor_block_template xor_block_xc = { .do_4 = xor_xc_4, .do_5 = xor_xc_5, }; -EXPORT_SYMBOL (xor_block_xc);
Signature · 1 line
2.47.3
PATCH 18/26 x86: move the XOR code to lib/raid/
In reply to Christoph HellwigMove the optimized XOR code out of line into lib/raid.
--- arch/x86/include/asm/xor.h | 518 ++---------------- arch/x86/include/asm/xor_64.h | 32 -- lib/raid/xor/Makefile | 2 + .../xor_avx.h => lib/raid/xor/x86/xor-avx.c | 14 +- .../xor_32.h => lib/raid/xor/x86/xor-mmx.c | 60 +- lib/raid/xor/x86/xor-sse.c | 476 ++++++++++++++++ 6 files changed, 522 insertions(+), 580 deletions(-) delete mode 100644 arch/x86/include/asm/xor_64.h rename arch/x86/include/asm/xor_avx.h => lib/raid/xor/x86/xor-avx.c (95%) rename arch/x86/include/asm/xor_32.h => lib/raid/xor/x86/xor-mmx.c (90%) create mode 100644 lib/raid/xor/x86/xor-sse.c
arch/x86/include/asm/xor.h +31 -487
@@ -2,498 +2,42 @@#ifndef _ASM_X86_XOR_H#define _ASM_X86_XOR_H -/* -* Optimized RAID-5 checksumming functions for SSE. -*/ - -/* -* Cache avoiding checksumming functions utilizing KNI instructions -* Copyright (C) 1999 Zach Brown (with obvious credit due Ingo) -*/ +#include <asm/cpufeature.h> +#include <asm-generic/xor.h> -/* -* Based on -* High-speed RAID5 checksumming functions utilizing SSE instructions. -* Copyright (C) 1998 Ingo Molnar. -*/ +extern struct xor_block_template xor_block_pII_mmx; +extern struct xor_block_template xor_block_p5_mmx; +extern struct xor_block_template xor_block_sse; +extern struct xor_block_template xor_block_sse_pf64; +extern struct xor_block_template xor_block_avx;/* -* x86-64 changes / gcc fixes from Andi Kleen. -* Copyright 2002 Andi Kleen, SuSE Labs. +* When SSE is available, use it as it can write around L2. We may also be able +* to load into the L1 only depending on how the cpu deals with a load to a line +* that is being prefetched. +* +* When AVX2 is available, force using it as it is better by all measures. * -* This hasn't been optimized for the hammer yet, but there are likely -* no advantages to be gotten from x86-64 here anyways. +* 32-bit without MMX can fall back to the generic routines. */ - -#include <asm/fpu/api.h> - -#ifdef CONFIG_X86_32 -/* reduce register pressure */ -# define XOR_CONSTANT_CONSTRAINT "i" -#else -# define XOR_CONSTANT_CONSTRAINT "re" -#endif - -#define OFFS (x) "16*("#x")" -#define PF_OFFS (x) "256+16*("#x")" -#define PF0 (x) " prefetchnta "PF_OFFS(x)"(%[p1]) ;\n" -#define LD (x, y) " movaps "OFFS(x)"(%[p1]), %%xmm"#y" ;\n" -#define ST (x, y) " movaps %%xmm"#y", "OFFS(x)"(%[p1]) ;\n" -#define PF1 (x) " prefetchnta "PF_OFFS(x)"(%[p2]) ;\n" -#define PF2 (x) " prefetchnta "PF_OFFS(x)"(%[p3]) ;\n" -#define PF3 (x) " prefetchnta "PF_OFFS(x)"(%[p4]) ;\n" -#define PF4 (x) " prefetchnta "PF_OFFS(x)"(%[p5]) ;\n" -#define XO1 (x, y) " xorps "OFFS(x)"(%[p2]), %%xmm"#y" ;\n" -#define XO2 (x, y) " xorps "OFFS(x)"(%[p3]), %%xmm"#y" ;\n" -#define XO3 (x, y) " xorps "OFFS(x)"(%[p4]), %%xmm"#y" ;\n" -#define XO4 (x, y) " xorps "OFFS(x)"(%[p5]), %%xmm"#y" ;\n" -#define NOP (x) - -#define BLK64 (pf, op, i) \ - pf(i) \ - op(i, 0) \ - op(i + 1, 1) \ - op(i + 2, 2) \ - op(i + 3, 3) - -static void -xor_sse_2 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2) -{ -unsigned long lines = bytes >>8 ; - -kernel_fpu_begin (); - - asm volatile( -#undef BLOCK -#define BLOCK (i) \ - LD(i, 0) \ - LD(i + 1, 1) \ - PF1(i) \ - PF1(i + 2) \ - LD(i + 2, 2) \ - LD(i + 3, 3) \ - PF0(i + 4) \ - PF0(i + 6) \ - XO1(i, 0) \ - XO1(i + 1, 1) \ - XO1(i + 2, 2) \ - XO1(i + 3, 3) \ - ST(i, 0) \ - ST(i + 1, 1) \ - ST(i + 2, 2) \ - ST(i + 3, 3) \ - - - PF0(0) - PF0(2) - -" .align 32 ;\n" -" 1: ;\n" - - BLOCK(0) - BLOCK(4) - BLOCK(8) - BLOCK(12) - -" add %[inc], %[p1] ;\n" -" add %[inc], %[p2] ;\n" -" dec %[cnt] ;\n" -" jnz 1b ;\n" - : [cnt] "+r" (lines), - [p1] "+r" (p1), [p2] "+r" (p2) - : [inc] XOR_CONSTANT_CONSTRAINT (256UL) - : "memory"); - - kernel_fpu_end(); -} - -static void -xor_sse_2_pf64 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2) -{ -unsigned long lines = bytes >>8 ; - -kernel_fpu_begin (); - - asm volatile( -#undef BLOCK -#define BLOCK (i) \ - BLK64(PF0, LD, i) \ - BLK64(PF1, XO1, i) \ - BLK64(NOP, ST, i) \ - -" .align 32 ;\n" -" 1: ;\n" - - BLOCK(0) - BLOCK(4) - BLOCK(8) - BLOCK(12) - -" add %[inc], %[p1] ;\n" -" add %[inc], %[p2] ;\n" -" dec %[cnt] ;\n" -" jnz 1b ;\n" - : [cnt] "+r" (lines), - [p1] "+r" (p1), [p2] "+r" (p2) - : [inc] XOR_CONSTANT_CONSTRAINT (256UL) - : "memory"); - - kernel_fpu_end(); -} - -static void -xor_sse_3 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2, -const unsigned long * __restrict p3) -{ -unsigned long lines = bytes >>8 ; - -kernel_fpu_begin (); - - asm volatile( -#undef BLOCK -#define BLOCK (i) \ - PF1(i) \ - PF1(i + 2) \ - LD(i, 0) \ - LD(i + 1, 1) \ - LD(i + 2, 2) \ - LD(i + 3, 3) \ - PF2(i) \ - PF2(i + 2) \ - PF0(i + 4) \ - PF0(i + 6) \ - XO1(i, 0) \ - XO1(i + 1, 1) \ - XO1(i + 2, 2) \ - XO1(i + 3, 3) \ - XO2(i, 0) \ - XO2(i + 1, 1) \ - XO2(i + 2, 2) \ - XO2(i + 3, 3) \ - ST(i, 0) \ - ST(i + 1, 1) \ - ST(i + 2, 2) \ - ST(i + 3, 3) \ - - - PF0(0) - PF0(2) - -" .align 32 ;\n" -" 1: ;\n" - - BLOCK(0) - BLOCK(4) - BLOCK(8) - BLOCK(12) - -" add %[inc], %[p1] ;\n" -" add %[inc], %[p2] ;\n" -" add %[inc], %[p3] ;\n" -" dec %[cnt] ;\n" -" jnz 1b ;\n" - : [cnt] "+r" (lines), - [p1] "+r" (p1), [p2] "+r" (p2), [p3] "+r" (p3) - : [inc] XOR_CONSTANT_CONSTRAINT (256UL) - : "memory"); - - kernel_fpu_end(); +#define arch_xor_init arch_xor_init +static __always_inline void __init arch_xor_init(void) +{ +if (boot_cpu_has (X86_FEATURE_AVX ) && +boot_cpu_has (X86_FEATURE_OSXSAVE )) { +xor_force (&xor_block_avx); + }else if (IS_ENABLED (CONFIG_X86_64 ) ||boot_cpu_has (X86_FEATURE_XMM )) { +xor_register (&xor_block_sse); +xor_register (&xor_block_sse_pf64); + }else if (boot_cpu_has (X86_FEATURE_MMX )) { +xor_register (&xor_block_pII_mmx); +xor_register (&xor_block_p5_mmx); + }else { +xor_register (&xor_block_8regs); +xor_register (&xor_block_8regs_p); +xor_register (&xor_block_32regs); +xor_register (&xor_block_32regs_p); + } } -static void -xor_sse_3_pf64 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2, -const unsigned long * __restrict p3) -{ -unsigned long lines = bytes >>8 ; - -kernel_fpu_begin (); - - asm volatile( -#undef BLOCK -#define BLOCK (i) \ - BLK64(PF0, LD, i) \ - BLK64(PF1, XO1, i) \ - BLK64(PF2, XO2, i) \ - BLK64(NOP, ST, i) \ - -" .align 32 ;\n" -" 1: ;\n" - - BLOCK(0) - BLOCK(4) - BLOCK(8) - BLOCK(12) - -" add %[inc], %[p1] ;\n" -" add %[inc], %[p2] ;\n" -" add %[inc], %[p3] ;\n" -" dec %[cnt] ;\n" -" jnz 1b ;\n" - : [cnt] "+r" (lines), - [p1] "+r" (p1), [p2] "+r" (p2), [p3] "+r" (p3) - : [inc] XOR_CONSTANT_CONSTRAINT (256UL) - : "memory"); - - kernel_fpu_end(); -} - -static void -xor_sse_4 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2, -const unsigned long * __restrict p3, -const unsigned long * __restrict p4) -{ -unsigned long lines = bytes >>8 ; - -kernel_fpu_begin (); - - asm volatile( -#undef BLOCK -#define BLOCK (i) \ - PF1(i) \ - PF1(i + 2) \ - LD(i, 0) \ - LD(i + 1, 1) \ - LD(i + 2, 2) \ - LD(i + 3, 3) \ - PF2(i) \ - PF2(i + 2) \ - XO1(i, 0) \ - XO1(i + 1, 1) \ - XO1(i + 2, 2) \ - XO1(i + 3, 3) \ - PF3(i) \ - PF3(i + 2) \ - PF0(i + 4) \ - PF0(i + 6) \ - XO2(i, 0) \ - XO2(i + 1, 1) \ - XO2(i + 2, 2) \ - XO2(i + 3, 3) \ - XO3(i, 0) \ - XO3(i + 1, 1) \ - XO3(i + 2, 2) \ - XO3(i + 3, 3) \ - ST(i, 0) \ - ST(i + 1, 1) \ - ST(i + 2, 2) \ - ST(i + 3, 3) \ - - - PF0(0) - PF0(2) - -" .align 32 ;\n" -" 1: ;\n" - - BLOCK(0) - BLOCK(4) - BLOCK(8) - BLOCK(12) - -" add %[inc], %[p1] ;\n" -" add %[inc], %[p2] ;\n" -" add %[inc], %[p3] ;\n" -" add %[inc], %[p4] ;\n" -" dec %[cnt] ;\n" -" jnz 1b ;\n" - : [cnt] "+r" (lines), [p1] "+r" (p1), - [p2] "+r" (p2), [p3] "+r" (p3), [p4] "+r" (p4) - : [inc] XOR_CONSTANT_CONSTRAINT (256UL) - : "memory"); - - kernel_fpu_end(); -} - -static void -xor_sse_4_pf64 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2, -const unsigned long * __restrict p3, -const unsigned long * __restrict p4) -{ -unsigned long lines = bytes >>8 ; - -kernel_fpu_begin (); - - asm volatile( -#undef BLOCK -#define BLOCK (i) \ - BLK64(PF0, LD, i) \ - BLK64(PF1, XO1, i) \ - BLK64(PF2, XO2, i) \ - BLK64(PF3, XO3, i) \ - BLK64(NOP, ST, i) \ - -" .align 32 ;\n" -" 1: ;\n" - - BLOCK(0) - BLOCK(4) - BLOCK(8) - BLOCK(12) - -" add %[inc], %[p1] ;\n" -" add %[inc], %[p2] ;\n" -" add %[inc], %[p3] ;\n" -" add %[inc], %[p4] ;\n" -" dec %[cnt] ;\n" -" jnz 1b ;\n" - : [cnt] "+r" (lines), [p1] "+r" (p1), - [p2] "+r" (p2), [p3] "+r" (p3), [p4] "+r" (p4) - : [inc] XOR_CONSTANT_CONSTRAINT (256UL) - : "memory"); - - kernel_fpu_end(); -} - -static void -xor_sse_5 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2, -const unsigned long * __restrict p3, -const unsigned long * __restrict p4, -const unsigned long * __restrict p5) -{ -unsigned long lines = bytes >>8 ; - -kernel_fpu_begin (); - - asm volatile( -#undef BLOCK -#define BLOCK (i) \ - PF1(i) \ - PF1(i + 2) \ - LD(i, 0) \ - LD(i + 1, 1) \ - LD(i + 2, 2) \ - LD(i + 3, 3) \ - PF2(i) \ - PF2(i + 2) \ - XO1(i, 0) \ - XO1(i + 1, 1) \ - XO1(i + 2, 2) \ - XO1(i + 3, 3) \ - PF3(i) \ - PF3(i + 2) \ - XO2(i, 0) \ - XO2(i + 1, 1) \ - XO2(i + 2, 2) \ - XO2(i + 3, 3) \ - PF4(i) \ - PF4(i + 2) \ - PF0(i + 4) \ - PF0(i + 6) \ - XO3(i, 0) \ - XO3(i + 1, 1) \ - XO3(i + 2, 2) \ - XO3(i + 3, 3) \ - XO4(i, 0) \ - XO4(i + 1, 1) \ - XO4(i + 2, 2) \ - XO4(i + 3, 3) \ - ST(i, 0) \ - ST(i + 1, 1) \ - ST(i + 2, 2) \ - ST(i + 3, 3) \ - - - PF0(0) - PF0(2) - -" .align 32 ;\n" -" 1: ;\n" - - BLOCK(0) - BLOCK(4) - BLOCK(8) - BLOCK(12) - -" add %[inc], %[p1] ;\n" -" add %[inc], %[p2] ;\n" -" add %[inc], %[p3] ;\n" -" add %[inc], %[p4] ;\n" -" add %[inc], %[p5] ;\n" -" dec %[cnt] ;\n" -" jnz 1b ;\n" - : [cnt] "+r" (lines), [p1] "+r" (p1), [p2] "+r" (p2), - [p3] "+r" (p3), [p4] "+r" (p4), [p5] "+r" (p5) - : [inc] XOR_CONSTANT_CONSTRAINT (256UL) - : "memory"); - - kernel_fpu_end(); -} - -static void -xor_sse_5_pf64 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2, -const unsigned long * __restrict p3, -const unsigned long * __restrict p4, -const unsigned long * __restrict p5) -{ -unsigned long lines = bytes >>8 ; - -kernel_fpu_begin (); - - asm volatile( -#undef BLOCK -#define BLOCK (i) \ - BLK64(PF0, LD, i) \ - BLK64(PF1, XO1, i) \ - BLK64(PF2, XO2, i) \ - BLK64(PF3, XO3, i) \ - BLK64(PF4, XO4, i) \ - BLK64(NOP, ST, i) \ - -" .align 32 ;\n" -" 1: ;\n" - - BLOCK(0) - BLOCK(4) - BLOCK(8) - BLOCK(12) - -" add %[inc], %[p1] ;\n" -" add %[inc], %[p2] ;\n" -" add %[inc], %[p3] ;\n" -" add %[inc], %[p4] ;\n" -" add %[inc], %[p5] ;\n" -" dec %[cnt] ;\n" -" jnz 1b ;\n" - : [cnt] "+r" (lines), [p1] "+r" (p1), [p2] "+r" (p2), - [p3] "+r" (p3), [p4] "+r" (p4), [p5] "+r" (p5) - : [inc] XOR_CONSTANT_CONSTRAINT (256UL) - : "memory"); - - kernel_fpu_end(); -} - -static struct xor_block_template xor_block_sse_pf64 = { - .name ="prefetch64-sse" , - .do_2 = xor_sse_2_pf64, - .do_3 = xor_sse_3_pf64, - .do_4 = xor_sse_4_pf64, - .do_5 = xor_sse_5_pf64, -}; - -#undef LD -#undef XO1 -#undef XO2 -#undef XO3 -#undef XO4 -#undef ST -#undef NOP -#undef BLK64 -#undef BLOCK - -#undef XOR_CONSTANT_CONSTRAINT - -#ifdef CONFIG_X86_32 -# include <asm/xor_32.h> -#else -# include <asm/xor_64.h> -#endif -#endif /* _ASM_X86_XOR_H */
arch/x86/include/asm/xor_64.h deleted +0 -32
@@ -1,32 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef _ASM_X86_XOR_64_H -#define _ASM_X86_XOR_64_H - -static struct xor_block_template xor_block_sse = { - .name ="generic_sse" , - .do_2 = xor_sse_2, - .do_3 = xor_sse_3, - .do_4 = xor_sse_4, - .do_5 = xor_sse_5, -}; - - -/* Also try the AVX routines */ -#include <asm/xor_avx.h> - -/* We force the use of the SSE xor block because it can write around L2. -We may also be able to load into the L1 only depending on how the cpu -deals with a load to a line that is being prefetched. */ -#define arch_xor_init arch_xor_init -static __always_inline void __init arch_xor_init(void) -{ -if (boot_cpu_has (X86_FEATURE_AVX ) && -boot_cpu_has (X86_FEATURE_OSXSAVE )) { -xor_force (&xor_block_avx); - }else { -xor_register (&xor_block_sse_pf64); -xor_register (&xor_block_sse); - } -} - -#endif /* _ASM_X86_XOR_64_H */
lib/raid/xor/Makefile +2 -0
@@ -21,6 +21,8 @@ xor-$(CONFIG_RISCV_ISA_V) += riscv/xor.o riscv/xor-glue.o xor-$(CONFIG_SPARC32) += sparc/xor-sparc32.o xor-$(CONFIG_SPARC64) += sparc/xor-sparc64.o sparc/xor-sparc64-glue.o xor-$(CONFIG_S390) += s390/xor.o +xor-$(CONFIG_X86_32) += x86/xor-avx.o x86/xor-sse.o x86/xor-mmx.o +xor-$(CONFIG_X86_64) += x86/xor-avx.o x86/xor-sse.o CFLAGS_arm/xor-neon.o += $(CC_FLAGS_FPU)
lib/raid/xor/x86/xor-avx.c renamed from arch/x86/include/asm/xor_avx.h +5 -9
@@ -1,18 +1,16 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -#ifndef _ASM_X86_XOR_AVX_H -#define _ASM_X86_XOR_AVX_H - +// SPDX-License-Identifier: GPL-2.0-only /* -* Optimized RAID-5 checksumming functions for AVX +* Optimized XOR parity functions for AVX * * Copyright (C) 2012 Intel Corporation * Author: Jim Kukunas <[email protected]> * * Based on Ingo Molnar and Zach Brown's respective MMX and SSE routines */ -#include <linux/compiler.h> +#include <linux/raid/xor_impl.h> #include <asm/fpu/api.h> +#include <asm/xor.h> #define BLOCK4 (i) \ BLOCK(32 * i, 0) \
@@ -158,12 +156,10 @@ do { \kernel_fpu_end (); } -static struct xor_block_template xor_block_avx = { +struct xor_block_template xor_block_avx = { .name ="avx" , .do_2 = xor_avx_2, .do_3 = xor_avx_3, .do_4 = xor_avx_4, .do_5 = xor_avx_5, }; - -#endif
lib/raid/xor/x86/xor-mmx.c renamed from arch/x86/include/asm/xor_32.h +8 -52
87 lines not on this page · raw message
lib/raid/xor/x86/xor-sse.c new file +476 -0
476 lines not on this page · raw message
Signature · 1 line
2.47.3
PATCH 19/26 xor: avoid indirect calls for arm64-optimized ops
In reply to Christoph HellwigRemove the inner xor_block_templates, and instead have two separate actual template that call into the neon-enabled compilation unit.
--- arch/arm64/include/asm/xor.h | 13 ++-- lib/raid/xor/arm64/xor-neon-glue.c | 95 +++++++++++++++--------------- lib/raid/xor/arm64/xor-neon.c | 73 +++++++++-------------- lib/raid/xor/arm64/xor-neon.h | 30 ++++++++++ 4 files changed, 114 insertions(+), 97 deletions(-) create mode 100644 lib/raid/xor/arm64/xor-neon.h
arch/arm64/include/asm/xor.h +8 -5
@@ -7,15 +7,18 @@#include <asm-generic/xor.h> #include <asm/simd.h> -extern struct xor_block_template xor_block_arm64; -void __init xor_neon_init (void ); +extern struct xor_block_template xor_block_neon; +extern struct xor_block_template xor_block_eor3;#define arch_xor_init arch_xor_init static __always_inline void __init arch_xor_init(void) { -xor_neon_init ();xor_register (&xor_block_8regs);xor_register (&xor_block_32regs); -if (cpu_has_neon ()) -xor_register (&xor_block_arm64); +if (cpu_has_neon ()) { +if (cpu_have_named_feature (SHA3 )) +xor_register (&xor_block_eor3); +else +xor_register (&xor_block_neon); + } }
lib/raid/xor/arm64/xor-neon-glue.c +49 -46
100 lines not on this page · raw message
lib/raid/xor/arm64/xor-neon.c +27 -46
125 lines not on this page · raw message
lib/raid/xor/arm64/xor-neon.h new file +30 -0
@@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +void __xor_neon_2 (unsigned long bytes,unsigned long * __restrict p1, +const unsigned long * __restrict p2); +void __xor_neon_3 (unsigned long bytes,unsigned long * __restrict p1, +const unsigned long * __restrict p2, +const unsigned long * __restrict p3); +void __xor_neon_4 (unsigned long bytes,unsigned long * __restrict p1, +const unsigned long * __restrict p2, +const unsigned long * __restrict p3, +const unsigned long * __restrict p4); +void __xor_neon_5 (unsigned long bytes,unsigned long * __restrict p1, +const unsigned long * __restrict p2, +const unsigned long * __restrict p3, +const unsigned long * __restrict p4, +const unsigned long * __restrict p5); + +#define __xor_eor3_2 __xor_neon_2 +void __xor_eor3_3 (unsigned long bytes,unsigned long * __restrict p1, +const unsigned long * __restrict p2, +const unsigned long * __restrict p3); +void __xor_eor3_4 (unsigned long bytes,unsigned long * __restrict p1, +const unsigned long * __restrict p2, +const unsigned long * __restrict p3, +const unsigned long * __restrict p4); +void __xor_eor3_5 (unsigned long bytes,unsigned long * __restrict p1, +const unsigned long * __restrict p2, +const unsigned long * __restrict p3, +const unsigned long * __restrict p4, +const unsigned long * __restrict p5);
Signature · 1 line
2.47.3
PATCH 20/26 xor: make xor.ko self-contained in lib/raid/
In reply to Christoph HellwigMove the asm/xor.h headers to lib/raid/xor/$(SRCARCH)/xor_arch.h and include/linux/raid/xor_impl.h to lib/raid/xor/xor_impl.h so that the xor.ko module implementation is self-contained in lib/raid/.
As this remove the asm-generic mechanism a new kconfig symbol is added to indicate that a architecture-specific implementations exists, and xor_arch.h should be included.
---
arch/um/include/asm/xor.h | 8 --------
include/asm-generic/Kbuild | 1 -
include/asm-generic/xor.h | 11 -----------
lib/raid/Kconfig | 15 +++++++++++++++
lib/raid/xor/Makefile | 6 ++++++
lib/raid/xor/alpha/xor.c | 4 ++--
.../asm/xor.h => lib/raid/xor/alpha/xor_arch.h | 2 --
lib/raid/xor/arm/xor-neon-glue.c | 4 ++--
lib/raid/xor/arm/xor-neon.c | 2 +-
lib/raid/xor/arm/xor.c | 4 ++--
.../asm/xor.h => lib/raid/xor/arm/xor_arch.h | 2 --
lib/raid/xor/arm64/xor-neon-glue.c | 4 ++--
lib/raid/xor/arm64/xor-neon.c | 4 ++--
.../asm/xor.h => lib/raid/xor/arm64/xor_arch.h | 3 ---
.../xor.h => lib/raid/xor/loongarch/xor_arch.h | 7 -------
lib/raid/xor/loongarch/xor_simd_glue.c | 4 ++--
.../xor.h => lib/raid/xor/powerpc/xor_arch.h | 7 -------
lib/raid/xor/powerpc/xor_vmx_glue.c | 4 ++--
lib/raid/xor/riscv/xor-glue.c | 4 ++--
.../asm/xor.h => lib/raid/xor/riscv/xor_arch.h | 2 --
lib/raid/xor/s390/xor.c | 4 ++--
.../asm/xor.h => lib/raid/xor/s390/xor_arch.h | 6 ------
lib/raid/xor/sparc/xor-sparc32.c | 4 ++--
lib/raid/xor/sparc/xor-sparc64-glue.c | 4 ++--
.../asm/xor.h => lib/raid/xor/sparc/xor_arch.h | 9 ---------
lib/raid/xor/um/xor_arch.h | 2 ++
lib/raid/xor/x86/xor-avx.c | 4 ++--
lib/raid/xor/x86/xor-mmx.c | 4 ++--
lib/raid/xor/x86/xor-sse.c | 4 ++--
.../asm/xor.h => lib/raid/xor/x86/xor_arch.h | 7 -------
lib/raid/xor/xor-32regs-prefetch.c | 3 +--
lib/raid/xor/xor-32regs.c | 3 +--
lib/raid/xor/xor-8regs-prefetch.c | 3 +--
lib/raid/xor/xor-8regs.c | 3 +--
lib/raid/xor/xor-core.c | 18 +++++++++++-------
.../linux/raid => lib/raid/xor}/xor_impl.h | 6 ++++++
36 files changed, 73 insertions(+), 109 deletions(-)
delete mode 100644 arch/um/include/asm/xor.h
delete mode 100644 include/asm-generic/xor.h
rename arch/alpha/include/asm/xor.h => lib/raid/xor/alpha/xor_arch.h (90%)
rename arch/arm/include/asm/xor.h => lib/raid/xor/arm/xor_arch.h (87%)
rename arch/arm64/include/asm/xor.h => lib/raid/xor/arm64/xor_arch.h (89%)
rename arch/loongarch/include/asm/xor.h => lib/raid/xor/loongarch/xor_arch.h (85%)
rename arch/powerpc/include/asm/xor.h => lib/raid/xor/powerpc/xor_arch.h (77%)
rename arch/riscv/include/asm/xor.h => lib/raid/xor/riscv/xor_arch.h (84%)
rename arch/s390/include/asm/xor.h => lib/raid/xor/s390/xor_arch.h (71%)
rename arch/sparc/include/asm/xor.h => lib/raid/xor/sparc/xor_arch.h (81%)
create mode 100644 lib/raid/xor/um/xor_arch.h
rename arch/x86/include/asm/xor.h => lib/raid/xor/x86/xor_arch.h (89%)
rename {include/linux/raid => lib/raid/xor}/xor_impl.h (80%)arch/um/include/asm/xor.h deleted +0 -8
@@ -1,8 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef _ASM_UM_XOR_H -#define _ASM_UM_XOR_H - -#include <asm/cpufeature.h> -#include <../../x86/include/asm/xor.h> - -#endif
include/asm-generic/Kbuild +0 -1
@@ -65,4 +65,3 @@ mandatory-y += vermagic.h mandatory-y += vga.h mandatory-y += video.h mandatory-y += word-at-a-time.h -mandatory-y += xor.h
include/asm-generic/xor.h deleted +0 -11
@@ -1,11 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* -* include/asm-generic/xor.h -* -* Generic optimized RAID-5 checksumming functions. -*/ - -extern struct xor_block_template xor_block_8regs; -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;
lib/raid/Kconfig +15 -0
@@ -2,3 +2,18 @@ config XOR_BLOCKS tristate + +# selected by architectures that provide an optimized XOR implementation +config XOR_BLOCKS_ARCH + depends on XOR_BLOCKS + default y if ALPHA + default y if ARM && KERNEL_MODE_NEON + default y if ARM64 + default y if CPU_HAS_LSX # loongarch + default y if ALTIVEC # powerpc + default y if RISCV_ISA_V + default y if SPARC + default y if S390 + default y if X86_32 + default y if X86_64 + bool
lib/raid/xor/Makefile +6 -0
@@ -1,5 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 +ccflags-y += -I $(src) + obj-$(CONFIG_XOR_BLOCKS) += xor.o xor-y += xor-core.o
@@ -8,6 +10,10 @@ xor-y += xor-32regs.o xor-y += xor-8regs-prefetch.o xor-y += xor-32regs-prefetch.o +ifeq ($(CONFIG_XOR_BLOCKS_ARCH),y) +CFLAGS_xor-core.o += -I$(src)/$(SRCARCH) +endif + xor-$(CONFIG_ALPHA) += alpha/xor.o xor-$(CONFIG_ARM) += arm/xor.o ifeq ($(CONFIG_ARM),y)
lib/raid/xor/alpha/xor.c +2 -2
@@ -2,8 +2,8 @@/* * Optimized XOR parity functions for alpha EV5 and EV6 */ -#include <linux/raid/xor_impl.h> -#include <asm/xor.h> +#include "xor_impl.h" +#include "xor_arch.h" extern void xor_alpha_2(unsigned long bytes, unsigned long * __restrict p1,
lib/raid/xor/alpha/xor_arch.h renamed from arch/alpha/include/asm/xor.h +0 -2
@@ -1,7 +1,6 @@/* SPDX-License-Identifier: GPL-2.0-or-later */ #include <asm/special_insns.h> -#include <asm-generic/xor.h> extern struct xor_block_template xor_block_alpha;extern struct xor_block_template xor_block_alpha_prefetch;
@@ -10,7 +9,6 @@ extern struct xor_block_template xor_block_alpha_prefetch;* Force the use of alpha_prefetch if EV6, as it is significantly faster in the * cold cache case. */ -#define arch_xor_init arch_xor_init static __always_inline void __init arch_xor_init(void) {if (implver () ==IMPLVER_EV6 ) {
lib/raid/xor/arm/xor-neon-glue.c +2 -2
@@ -2,8 +2,8 @@/* * Copyright (C) 2001 Russell King */ -#include <linux/raid/xor_impl.h> -#include <asm/xor.h> +#include "xor_impl.h" +#include "xor_arch.h" extern struct xor_block_template const xor_block_neon_inner;
lib/raid/xor/arm/xor-neon.c +1 -1
@@ -3,7 +3,7 @@* Copyright (C) 2013 Linaro Ltd <[email protected]> */ -#include <linux/raid/xor_impl.h> +#include "xor_impl.h" #ifndef __ARM_NEON__#error You should compile this file with '-march=armv7-a -mfloat-abi=softfp -mfpu=neon'
lib/raid/xor/arm/xor.c +2 -2
@@ -2,8 +2,8 @@/* * Copyright (C) 2001 Russell King */ -#include <linux/raid/xor_impl.h> -#include <asm/xor.h> +#include "xor_impl.h" +#include "xor_arch.h" #define __XOR (a1, a2) a1 ^= a2
lib/raid/xor/arm/xor_arch.h renamed from arch/arm/include/asm/xor.h +0 -2
@@ -2,13 +2,11 @@/* * Copyright (C) 2001 Russell King */ -#include <asm-generic/xor.h> #include <asm/neon.h> extern struct xor_block_template xor_block_arm4regs;extern struct xor_block_template xor_block_neon; -#define arch_xor_init arch_xor_init static __always_inline void __init arch_xor_init(void) {xor_register (&xor_block_arm4regs);
lib/raid/xor/arm64/xor-neon-glue.c +2 -2
@@ -4,9 +4,9 @@* Copyright (C) 2018,Tianjin KYLIN Information Technology Co., Ltd. */ -#include <linux/raid/xor_impl.h> #include <asm/simd.h> -#include <asm/xor.h> +#include "xor_impl.h" +#include "xor_arch.h" #include "xor-neon.h" #define XOR_TEMPLATE (_name) \
lib/raid/xor/arm64/xor-neon.c +2 -2
@@ -4,10 +4,10 @@* Copyright (C) 2018,Tianjin KYLIN Information Technology Co., Ltd. */ -#include <linux/raid/xor_impl.h> #include <linux/cache.h> #include <asm/neon-intrinsics.h> -#include <asm/xor.h> +#include "xor_impl.h" +#include "xor_arch.h" #include "xor-neon.h" void __xor_neon_2(unsigned long bytes, unsigned long * __restrict p1,
lib/raid/xor/arm64/xor_arch.h renamed from arch/arm64/include/asm/xor.h +0 -3
@@ -3,14 +3,11 @@* Authors: Jackie Liu <[email protected]> * Copyright (C) 2018,Tianjin KYLIN Information Technology Co., Ltd. */ - -#include <asm-generic/xor.h> #include <asm/simd.h> extern struct xor_block_template xor_block_neon;extern struct xor_block_template xor_block_eor3; -#define arch_xor_init arch_xor_init static __always_inline void __init arch_xor_init(void) {xor_register (&xor_block_8regs);
lib/raid/xor/loongarch/xor_arch.h renamed from arch/loongarch/include/asm/xor.h +0 -7
@@ -2,9 +2,6 @@/* * Copyright (C) 2023 WANG Xuerui <[email protected]> */ -#ifndef _ASM_LOONGARCH_XOR_H -#define _ASM_LOONGARCH_XOR_H -#include <asm/cpu-features.h> /*
@@ -15,12 +12,10 @@* the scalar ones, maybe for errata or micro-op reasons. It may be * appropriate to revisit this after one or two more uarch generations. */ -#include <asm-generic/xor.h> extern struct xor_block_template xor_block_lsx;extern struct xor_block_template xor_block_lasx; -#define arch_xor_init arch_xor_init static __always_inline void __init arch_xor_init(void) {xor_register (&xor_block_8regs);
@@ -36,5 +31,3 @@ static __always_inline void __init arch_xor_init(void)xor_register (&xor_block_lasx);#endif } - -#endif /* _ASM_LOONGARCH_XOR_H */
lib/raid/xor/loongarch/xor_simd_glue.c +2 -2
@@ -6,9 +6,9 @@*/ #include <linux/sched.h> -#include <linux/raid/xor_impl.h> #include <asm/fpu.h> -#include <asm/xor.h> +#include "xor_impl.h" +#include "xor_arch.h" #include "xor_simd.h" #define MAKE_XOR_GLUE_2 (flavor) \
lib/raid/xor/powerpc/xor_arch.h renamed from arch/powerpc/include/asm/xor.h +0 -7
@@ -5,15 +5,10 @@* * Author: Anton Blanchard <[email protected]> */ -#ifndef _ASM_POWERPC_XOR_H -#define _ASM_POWERPC_XOR_H -#include <asm/cpu_has_feature.h> -#include <asm-generic/xor.h> extern struct xor_block_template xor_block_altivec; -#define arch_xor_init arch_xor_init static __always_inline void __init arch_xor_init(void) {xor_register (&xor_block_8regs);
@@ -25,5 +20,3 @@ static __always_inline void __init arch_xor_init(void)xor_register (&xor_block_altivec);#endif } - -#endif /* _ASM_POWERPC_XOR_H */
lib/raid/xor/powerpc/xor_vmx_glue.c +2 -2
@@ -7,9 +7,9 @@#include <linux/preempt.h> #include <linux/sched.h> -#include <linux/raid/xor_impl.h> #include <asm/switch_to.h> -#include <asm/xor.h> +#include "xor_impl.h" +#include "xor_arch.h" #include "xor_vmx.h" static void xor_altivec_2(unsigned long bytes, unsigned long * __restrict p1,
lib/raid/xor/riscv/xor-glue.c +2 -2
@@ -3,11 +3,11 @@* Copyright (C) 2021 SiFive */ -#include <linux/raid/xor_impl.h> #include <asm/vector.h> #include <asm/switch_to.h> #include <asm/asm-prototypes.h> -#include <asm/xor.h> +#include "xor_impl.h" +#include "xor_arch.h" static void xor_vector_2 (unsigned long bytes,unsigned long *__restrict p1,const unsigned long *__restrict p2)
lib/raid/xor/riscv/xor_arch.h renamed from arch/riscv/include/asm/xor.h +0 -2
@@ -3,11 +3,9 @@* Copyright (C) 2021 SiFive */ #include <asm/vector.h> -#include <asm-generic/xor.h> extern struct xor_block_template xor_block_rvv; -#define arch_xor_init arch_xor_init static __always_inline void __init arch_xor_init(void) {xor_register (&xor_block_8regs);
lib/raid/xor/s390/xor.c +2 -2
@@ -7,8 +7,8 @@*/ #include <linux/types.h> -#include <linux/raid/xor_impl.h> -#include <asm/xor.h> +#include "xor_impl.h" +#include "xor_arch.h" static void xor_xc_2 (unsigned long bytes,unsigned long * __restrict p1,const unsigned long * __restrict p2)
lib/raid/xor/s390/xor_arch.h renamed from arch/s390/include/asm/xor.h +0 -6
@@ -5,15 +5,9 @@* Copyright IBM Corp. 2016 * Author(s): Martin Schwidefsky <[email protected]> */ -#ifndef _ASM_S390_XOR_H -#define _ASM_S390_XOR_H -extern struct xor_block_template xor_block_xc; -#define arch_xor_init arch_xor_init static __always_inline void __init arch_xor_init(void) {xor_force (&xor_block_xc); } - -#endif /* _ASM_S390_XOR_H */
lib/raid/xor/sparc/xor-sparc32.c +2 -2
@@ -5,8 +5,8 @@* * Copyright (C) 1999 Jakub Jelinek ([email protected]) */ -#include <linux/raid/xor_impl.h> -#include <asm/xor.h> +#include "xor_impl.h" +#include "xor_arch.h" static void sparc_2(unsigned long bytes, unsigned long * __restrict p1,
lib/raid/xor/sparc/xor-sparc64-glue.c +2 -2
@@ -8,8 +8,8 @@* Copyright (C) 2006 David S. Miller <[email protected]> */ -#include <linux/raid/xor_impl.h> -#include <asm/xor.h> +#include "xor_impl.h" +#include "xor_arch.h" void xor_vis_2 (unsigned long bytes,unsigned long * __restrict p1,const unsigned long * __restrict p2);
lib/raid/xor/sparc/xor_arch.h renamed from arch/sparc/include/asm/xor.h +0 -9
@@ -3,16 +3,12 @@* Copyright (C) 1997, 1999 Jakub Jelinek ([email protected]) * Copyright (C) 2006 David S. Miller <[email protected]> */ -#ifndef ___ASM_SPARC_XOR_H -#define ___ASM_SPARC_XOR_H -#if defined(__sparc__) && defined(__arch64__)#include <asm/spitfire.h> extern struct xor_block_template xor_block_VIS;extern struct xor_block_template xor_block_niagara; -#define arch_xor_init arch_xor_init static __always_inline void __init arch_xor_init(void) {/* Force VIS for everything except Niagara. */
@@ -28,12 +24,8 @@ static __always_inline void __init arch_xor_init(void) }#else /* sparc64 */ -/* For grins, also test the generic routines. */ -#include <asm-generic/xor.h> -extern struct xor_block_template xor_block_SPARC; -#define arch_xor_init arch_xor_init static __always_inline void __init arch_xor_init(void) {xor_register (&xor_block_8regs);
@@ -41,4 +33,3 @@ static __always_inline void __init arch_xor_init(void) xor_register(&xor_block_SPARC); }#endif /* !sparc64 */ -#endif /* ___ASM_SPARC_XOR_H */
lib/raid/xor/um/xor_arch.h new file +2 -0
@@ -0,0 +1,2 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include <../x86/xor_arch.h>
lib/raid/xor/x86/xor-avx.c +2 -2
@@ -8,9 +8,9 @@* Based on Ingo Molnar and Zach Brown's respective MMX and SSE routines */ #include <linux/compiler.h> -#include <linux/raid/xor_impl.h> #include <asm/fpu/api.h> -#include <asm/xor.h> +#include "xor_impl.h" +#include "xor_arch.h" #define BLOCK4 (i) \ BLOCK(32 * i, 0) \
lib/raid/xor/x86/xor-mmx.c +2 -2
@@ -4,9 +4,9 @@* * Copyright (C) 1998 Ingo Molnar. */ -#include <linux/raid/xor_impl.h> #include <asm/fpu/api.h> -#include <asm/xor.h> +#include "xor_impl.h" +#include "xor_arch.h" #define LD (x, y) " movq 8*("#x")(%1), %%mm"#y" ;\n"#define ST (x, y) " movq %%mm"#y", 8*("#x")(%1) ;\n"
lib/raid/xor/x86/xor-sse.c +2 -2
@@ -12,9 +12,9 @@* x86-64 changes / gcc fixes from Andi Kleen. * Copyright 2002 Andi Kleen, SuSE Labs. */ -#include <linux/raid/xor_impl.h> #include <asm/fpu/api.h> -#include <asm/xor.h> +#include "xor_impl.h" +#include "xor_arch.h" #ifdef CONFIG_X86_32 /* reduce register pressure */
lib/raid/xor/x86/xor_arch.h renamed from arch/x86/include/asm/xor.h +0 -7
@@ -1,9 +1,5 @@/* SPDX-License-Identifier: GPL-2.0-or-later */ -#ifndef _ASM_X86_XOR_H -#define _ASM_X86_XOR_H -#include <asm/cpufeature.h> -#include <asm-generic/xor.h> extern struct xor_block_template xor_block_pII_mmx;extern struct xor_block_template xor_block_p5_mmx;
@@ -20,7 +16,6 @@ extern struct xor_block_template xor_block_avx;* * 32-bit without MMX can fall back to the generic routines. */ -#define arch_xor_init arch_xor_init static __always_inline void __init arch_xor_init(void) { if (boot_cpu_has(X86_FEATURE_AVX) &&
@@ -39,5 +34,3 @@ static __always_inline void __init arch_xor_init(void)xor_register (&xor_block_32regs_p); } } - -#endif /* _ASM_X86_XOR_H */
lib/raid/xor/xor-32regs-prefetch.c +1 -2
@@ -1,7 +1,6 @@// SPDX-License-Identifier: GPL-2.0-or-later #include <linux/prefetch.h> -#include <linux/raid/xor_impl.h> -#include <asm-generic/xor.h> +#include "xor_impl.h" static void xor_32regs_p_2(unsigned long bytes, unsigned long * __restrict p1,
lib/raid/xor/xor-32regs.c +1 -2
@@ -1,6 +1,5 @@// SPDX-License-Identifier: GPL-2.0-or-later -#include <linux/raid/xor_impl.h> -#include <asm-generic/xor.h> +#include "xor_impl.h" static void xor_32regs_2(unsigned long bytes, unsigned long * __restrict p1,
lib/raid/xor/xor-8regs-prefetch.c +1 -2
@@ -1,7 +1,6 @@// SPDX-License-Identifier: GPL-2.0-or-later #include <linux/prefetch.h> -#include <linux/raid/xor_impl.h> -#include <asm-generic/xor.h> +#include "xor_impl.h" static void xor_8regs_p_2(unsigned long bytes, unsigned long * __restrict p1,
lib/raid/xor/xor-8regs.c +1 -2
@@ -1,6 +1,5 @@// SPDX-License-Identifier: GPL-2.0-or-later -#include <linux/raid/xor_impl.h> -#include <asm-generic/xor.h> +#include "xor_impl.h" static void xor_8regs_2(unsigned long bytes, unsigned long * __restrict p1,
lib/raid/xor/xor-core.c +11 -7
@@ -9,10 +9,9 @@#include <linux/module.h> #include <linux/gfp.h> #include <linux/raid/xor.h> -#include <linux/raid/xor_impl.h> #include <linux/jiffies.h> #include <linux/preempt.h> -#include <asm/xor.h> +#include "xor_impl.h" /* The xor routines to use. */ static struct xor_block_template *active_template;
@@ -141,16 +140,21 @@ static int __init calibrate_xor_blocks(void)return 0 ; } -static int __init xor_init (void ) -{ -#ifdef arch_xor_init -arch_xor_init (); +#ifdef CONFIG_XOR_BLOCKS_ARCH +#include "xor_arch.h" /* $SRCARCH/xor_arch.h */ #else +static void __init arch_xor_init (void ) +{xor_register (&xor_block_8regs);xor_register (&xor_block_8regs_p);xor_register (&xor_block_32regs);xor_register (&xor_block_32regs_p); -#endif +} +#endif /* CONFIG_XOR_BLOCKS_ARCH */ + +static int __init xor_init (void ) +{ +arch_xor_init ();/* * If this arch/cpu has a short-circuited selection, don't loop through
lib/raid/xor/xor_impl.h renamed from include/linux/raid/xor_impl.h +6 -0
@@ -24,6 +24,12 @@ struct xor_block_template { const unsigned long * __restrict); }; +/* generic implementations */ +extern struct xor_block_template xor_block_8regs; +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; +void __init xor_register (struct xor_block_template *tmpl);void __init xor_force (struct xor_block_template *tmpl);
Signature · 1 line
2.47.3
PATCH 21/26 xor: add a better public API
In reply to Christoph Hellwigxor_blocks is very annoying to use, because it is limited to 4 + 1 sources / destinations, has an odd argument order and is completely undocumented.
Lift the code that loops around it from btrfs and async_tx/async_xor into common code under the name xor_gen and properly document it.
--- include/linux/raid/xor.h | 2 ++ lib/raid/xor/xor-core.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+)
include/linux/raid/xor.h +2 -0
@@ -7,4 +7,6 @@extern void xor_blocks (unsigned int count,unsigned int bytes,void *dest,void **srcs); +void xor_gen (void *dest,void **srcs,unsigned int src_cnt,unsigned int bytes); +#endif /* _XOR_H */
lib/raid/xor/xor-core.c +32 -0
@@ -46,6 +46,38 @@ xor_blocks(unsigned int src_count, unsigned int bytes, void *dest, void **srcs) }EXPORT_SYMBOL (xor_blocks); +/** +* xor_gen - generate RAID-style XOR information +* @dest: destination vector +* @srcs: source vectors +* @src_cnt: number of source vectors +* @bytes: length in bytes of each vector +* +* Performs bit-wise XOR operation into @dest for each of the @src_cnt vectors +* in @srcs for a length of @bytes bytes. @src_count must be non-zero, and the +* memory pointed to by @dest and each member of @srcs must be at least 64-byte +* aligned. @bytes must be non-zero and a multiple of 512. +* +* Note: for typical RAID uses, @dest either needs to be zeroed, or filled with +* the first disk, which then needs to be removed from @srcs. +*/ +void xor_gen (void *dest,void **srcs,unsigned int src_cnt,unsigned int bytes) +{ +unsigned int src_off =0 ; + +WARN_ON_ONCE (bytes &511 ); + +while (src_cnt >0 ) { +unsigned int this_cnt =min (src_cnt,MAX_XOR_BLOCKS ); + +xor_blocks (this_cnt, bytes, dest, srcs + src_off); + + src_cnt -= this_cnt; + src_off += this_cnt; + } +} +EXPORT_SYMBOL (xor_gen); +/* Set of all registered templates. */ static struct xor_block_template *__initdata template_list;static bool __initdata xor_forced = false;
Signature · 1 line
2.47.3
PATCH 22/26 async_xor: use xor_gen
In reply to Christoph HellwigReplace use of the loop around xor_blocks with the easier to use xor_gen API.
--- crypto/async_tx/async_xor.c | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-)
crypto/async_tx/async_xor.c +10 -24
@@ -103,7 +103,6 @@ do_sync_xor_offs(struct page *dest, unsigned int offset, {int i;int xor_src_cnt =0 ; -int src_off =0 ;void *dest_buf;void **srcs;
@@ -117,23 +116,12 @@ do_sync_xor_offs(struct page *dest, unsigned int offset,if (src_list[i]) srcs[xor_src_cnt++] =page_address (src_list[i]) + (src_offs ? src_offs[i] : offset); - src_cnt = xor_src_cnt; +/* set destination address */ dest_buf =page_address (dest) + offset; -if (submit->flags &ASYNC_TX_XOR_ZERO_DST )memset (dest_buf,0 , len); - -while (src_cnt >0 ) { -/* process up to 'MAX_XOR_BLOCKS' sources */ - xor_src_cnt =min (src_cnt,MAX_XOR_BLOCKS ); -xor_blocks (xor_src_cnt, len, dest_buf, &srcs[src_off]); - -/* drop completed sources */ - src_cnt -= xor_src_cnt; - src_off += xor_src_cnt; - } - +xor_gen (dest_buf, srcs, xor_src_cnt, len);async_tx_sync_epilog (submit); }
@@ -168,11 +156,10 @@ dma_xor_aligned_offsets(struct dma_device *device, unsigned int offset,* * honored flags: ASYNC_TX_ACK, ASYNC_TX_XOR_ZERO_DST, ASYNC_TX_XOR_DROP_DST * -* xor_blocks always uses the dest as a source so the -* ASYNC_TX_XOR_ZERO_DST flag must be set to not include dest data in -* the calculation. The assumption with dma engines is that they only -* use the destination buffer as a source when it is explicitly specified -* in the source list. +* xor_gen always uses the dest as a source so the ASYNC_TX_XOR_ZERO_DST flag +* must be set to not include dest data in the calculation. The assumption with +* dma engines is that they only use the destination buffer as a source when it +* is explicitly specified in the source list. * * src_list note: if the dest is also a source it must be at index zero. * The contents of this array will be overwritten if a scribble region
@@ -259,11 +246,10 @@ EXPORT_SYMBOL_GPL(async_xor_offs);* * honored flags: ASYNC_TX_ACK, ASYNC_TX_XOR_ZERO_DST, ASYNC_TX_XOR_DROP_DST * -* xor_blocks always uses the dest as a source so the -* ASYNC_TX_XOR_ZERO_DST flag must be set to not include dest data in -* the calculation. The assumption with dma engines is that they only -* use the destination buffer as a source when it is explicitly specified -* in the source list. +* xor_gen always uses the dest as a source so the ASYNC_TX_XOR_ZERO_DST flag +* must be set to not include dest data in the calculation. The assumption with +* dma engines is that they only use the destination buffer as a source when it +* is explicitly specified in the source list. * * src_list note: if the dest is also a source it must be at index zero. * The contents of this array will be overwritten if a scribble region
Signature · 1 line
2.47.3
PATCH 23/26 btrfs: use xor_gen
In reply to Christoph HellwigUse the new xor_gen helper instead of open coding the loop around xor_blocks. This helper is very similar to the existing run_xor helper in btrfs, except that the destination buffer is passed explicitly.
--- fs/btrfs/raid56.c | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-)
fs/btrfs/raid56.c +4 -23
@@ -617,26 +617,6 @@ static void cache_rbio(struct btrfs_raid_bio *rbio)spin_unlock (&table->cache_lock); } -/* -* helper function to run the xor_blocks api. It is only -* able to do MAX_XOR_BLOCKS at a time, so we need to -* loop through. -*/ -static void run_xor (void **pages,int src_cnt,ssize_t len) -{ -int src_off =0 ; -int xor_src_cnt =0 ; -void *dest = pages[src_cnt]; - -while (src_cnt >0 ) { - xor_src_cnt =min (src_cnt,MAX_XOR_BLOCKS ); -xor_blocks (xor_src_cnt, len, dest, pages + src_off); - - src_cnt -= xor_src_cnt; - src_off += xor_src_cnt; - } -} -/* * Returns true if the bio list inside this rbio covers an entire stripe (no * rmw required).
@@ -1434,7 +1414,8 @@ static void generate_pq_vertical_step(struct btrfs_raid_bio *rbio, unsigned int }else {/* raid5 */ memcpy (pointers[rbio->nr_data], pointers[0 ], step); -run_xor (pointers +1 , rbio->nr_data -1 , step); +xor_gen (pointers[rbio->nr_data], pointers +1 , rbio->nr_data -1 , + step); }for (stripe = stripe -1 ; stripe >=0 ; stripe--)kunmap_local (pointers[stripe]);
@@ -2034,7 +2015,7 @@ static void recover_vertical_step(struct btrfs_raid_bio *rbio, pointers[rbio->nr_data -1 ] = p;/* Xor in the rest */ -run_xor (pointers, rbio->nr_data -1 , step); +xor_gen (p, pointers, rbio->nr_data -1 , step); } cleanup:
@@ -2672,7 +2653,7 @@ static bool verify_one_parity_step(struct btrfs_raid_bio *rbio, }else {/* RAID5. */ memcpy (pointers[nr_data], pointers[0 ], step); -run_xor (pointers +1 , nr_data -1 , step); +xor_gen (pointers[nr_data], pointers +1 , nr_data -1 , step); }/* Check scrubbing parity and repair it. */
Signature · 1 line
2.47.3
PATCH 24/26 xor: pass the entire operation to the low-level ops
In reply to Christoph HellwigCurrently the high-level xor code chunks up all operations into small units for only up to 1 + 4 vectors, and passes it to four different methods. This means the FPU/vector context is entered and left a lot for wide stripes, and a lot of indirect expensive indirect calls are performed. Switch to passing the entire gen_xor request to the low-level ops, and provide a macro to dispatch it to the existing helper.
This reduce the number of indirect calls and FPU/vector context switches by a factor approaching nr_stripes / 4, and also reduces source and binary code size.
--- include/linux/raid/xor.h | 5 -- lib/raid/xor/alpha/xor.c | 19 ++++---- lib/raid/xor/arm/xor-neon-glue.c | 49 ++------------------ lib/raid/xor/arm/xor-neon.c | 9 +--- lib/raid/xor/arm/xor.c | 10 ++-- lib/raid/xor/arm/xor_arch.h | 3 ++ lib/raid/xor/arm64/xor-neon-glue.c | 44 ++---------------- lib/raid/xor/arm64/xor-neon.c | 20 +++++--- lib/raid/xor/arm64/xor-neon.h | 32 ++----------- lib/raid/xor/loongarch/xor_simd_glue.c | 62 +++++-------------------- lib/raid/xor/powerpc/xor_vmx.c | 40 ++++++++-------- lib/raid/xor/powerpc/xor_vmx.h | 16 +------ lib/raid/xor/powerpc/xor_vmx_glue.c | 49 ++------------------ lib/raid/xor/riscv/xor-glue.c | 43 +++-------------- lib/raid/xor/s390/xor.c | 9 ++-- lib/raid/xor/sparc/xor-sparc32.c | 9 ++-- lib/raid/xor/sparc/xor-sparc64-glue.c | 19 ++++---- lib/raid/xor/x86/xor-avx.c | 29 ++++-------- lib/raid/xor/x86/xor-mmx.c | 64 ++++++++++---------------- lib/raid/xor/x86/xor-sse.c | 63 +++++++++---------------- lib/raid/xor/xor-32regs-prefetch.c | 10 ++-- lib/raid/xor/xor-32regs.c | 9 ++-- lib/raid/xor/xor-8regs-prefetch.c | 11 +++-- lib/raid/xor/xor-8regs.c | 9 ++-- lib/raid/xor/xor-core.c | 47 ++----------------- lib/raid/xor/xor_impl.h | 48 +++++++++++++------ 26 files changed, 224 insertions(+), 504 deletions(-)
include/linux/raid/xor.h +0 -5
@@ -2,11 +2,6 @@#ifndef _XOR_H#define _XOR_H -#define MAX_XOR_BLOCKS 4 - -extern void xor_blocks (unsigned int count,unsigned int bytes, -void *dest,void **srcs); -void xor_gen (void *dest,void **srcs,unsigned int src_cnt,unsigned int bytes);#endif /* _XOR_H */
lib/raid/xor/alpha/xor.c +9 -10
@@ -832,18 +832,17 @@ xor_alpha_prefetch_5: \n\ .end xor_alpha_prefetch_5 \n\ "); +DO_XOR_BLOCKS (alpha, xor_alpha_2, xor_alpha_3, xor_alpha_4, xor_alpha_5); +struct xor_block_template xor_block_alpha = { - .name ="alpha" , - .do_2 = xor_alpha_2, - .do_3 = xor_alpha_3, - .do_4 = xor_alpha_4, - .do_5 = xor_alpha_5, + .name ="alpha" , + .xor_gen = xor_gen_alpha, }; +DO_XOR_BLOCKS (alpha_prefetch, xor_alpha_prefetch_2, xor_alpha_prefetch_3, + xor_alpha_prefetch_4, xor_alpha_prefetch_5); +struct xor_block_template xor_block_alpha_prefetch = { - .name ="alpha prefetch" , - .do_2 = xor_alpha_prefetch_2, - .do_3 = xor_alpha_prefetch_3, - .do_4 = xor_alpha_prefetch_4, - .do_5 = xor_alpha_prefetch_5, + .name ="alpha prefetch" , + .xor_gen = xor_gen_alpha_prefetch, };
lib/raid/xor/arm/xor-neon-glue.c +5 -44
59 lines not on this page · raw message
lib/raid/xor/arm/xor-neon.c +2 -7
@@ -4,6 +4,7 @@*/ #include "xor_impl.h" +#include "xor_arch.h" #ifndef __ARM_NEON__#error You should compile this file with '-march=armv7-a -mfloat-abi=softfp -mfpu=neon'
@@ -22,10 +23,4 @@#define NO_TEMPLATE #include "../xor-8regs.c" -struct xor_block_template const xor_block_neon_inner = { - .name ="__inner_neon__" , - .do_2 = xor_8regs_2, - .do_3 = xor_8regs_3, - .do_4 = xor_8regs_4, - .do_5 = xor_8regs_5, -}; +__DO_XOR_BLOCKS (neon_inner, xor_8regs_2, xor_8regs_3, xor_8regs_4, xor_8regs_5);
lib/raid/xor/arm/xor.c +5 -5
@@ -127,10 +127,10 @@ xor_arm4regs_5(unsigned long bytes, unsigned long * __restrict p1, }while (--lines); } +DO_XOR_BLOCKS (arm4regs, xor_arm4regs_2, xor_arm4regs_3, xor_arm4regs_4, + xor_arm4regs_5); +struct xor_block_template xor_block_arm4regs = { - .name ="arm4regs" , - .do_2 = xor_arm4regs_2, - .do_3 = xor_arm4regs_3, - .do_4 = xor_arm4regs_4, - .do_5 = xor_arm4regs_5, + .name ="arm4regs" , + .xor_gen = xor_gen_arm4regs, };
lib/raid/xor/arm/xor_arch.h +3 -0
@@ -7,6 +7,9 @@extern struct xor_block_template xor_block_arm4regs;extern struct xor_block_template xor_block_neon; +void xor_gen_neon_inner (void *dest,void **srcs,unsigned int src_cnt, +unsigned int bytes); + static __always_inline void __init arch_xor_init(void) {xor_register (&xor_block_arm4regs);
lib/raid/xor/arm64/xor-neon-glue.c +5 -39
55 lines not on this page · raw message
lib/raid/xor/arm64/xor-neon.c +13 -7
@@ -10,7 +10,7 @@#include "xor_arch.h" #include "xor-neon.h" -void __xor_neon_2 (unsigned long bytes,unsigned long * __restrict p1, +static void __xor_neon_2 (unsigned long bytes,unsigned long * __restrict p1,const unsigned long * __restrict p2) {uint64_t *dp1 = (uint64_t *)p1;
@@ -37,7 +37,7 @@ void __xor_neon_2(unsigned long bytes, unsigned long * __restrict p1, }while (--lines >0 ); } -void __xor_neon_3 (unsigned long bytes,unsigned long * __restrict p1, +static void __xor_neon_3 (unsigned long bytes,unsigned long * __restrict p1,const unsigned long * __restrict p2,const unsigned long * __restrict p3) {
@@ -73,7 +73,7 @@ void __xor_neon_3(unsigned long bytes, unsigned long * __restrict p1, }while (--lines >0 ); } -void __xor_neon_4 (unsigned long bytes,unsigned long * __restrict p1, +static void __xor_neon_4 (unsigned long bytes,unsigned long * __restrict p1,const unsigned long * __restrict p2,const unsigned long * __restrict p3,const unsigned long * __restrict p4)
@@ -118,7 +118,7 @@ void __xor_neon_4(unsigned long bytes, unsigned long * __restrict p1, }while (--lines >0 ); } -void __xor_neon_5(unsigned long bytes, unsigned long * __restrict p1, +static void __xor_neon_5(unsigned long bytes, unsigned long * __restrict p1, const unsigned long * __restrict p2, const unsigned long * __restrict p3, const unsigned long * __restrict p4,
@@ -172,6 +172,9 @@ void __xor_neon_5(unsigned long bytes, unsigned long * __restrict p1, }while (--lines >0 ); } +__DO_XOR_BLOCKS (neon_inner, __xor_neon_2, __xor_neon_3, __xor_neon_4, + __xor_neon_5); +static inline uint64x2_t eor3 (uint64x2_t p,uint64x2_t q,uint64x2_t r) {uint64x2_t res;
@@ -182,7 +185,7 @@ static inline uint64x2_t eor3(uint64x2_t p, uint64x2_t q, uint64x2_t r)return res; } -void __xor_eor3_3 (unsigned long bytes,unsigned long * __restrict p1, +static void __xor_eor3_3 (unsigned long bytes,unsigned long * __restrict p1,const unsigned long * __restrict p2,const unsigned long * __restrict p3) {
@@ -216,7 +219,7 @@ void __xor_eor3_3(unsigned long bytes, unsigned long * __restrict p1, }while (--lines >0 ); } -void __xor_eor3_4 (unsigned long bytes,unsigned long * __restrict p1, +static void __xor_eor3_4 (unsigned long bytes,unsigned long * __restrict p1,const unsigned long * __restrict p2,const unsigned long * __restrict p3,const unsigned long * __restrict p4)
@@ -259,7 +262,7 @@ void __xor_eor3_4(unsigned long bytes, unsigned long * __restrict p1, }while (--lines >0 ); } -void __xor_eor3_5(unsigned long bytes, unsigned long * __restrict p1, +static void __xor_eor3_5(unsigned long bytes, unsigned long * __restrict p1, const unsigned long * __restrict p2, const unsigned long * __restrict p3, const unsigned long * __restrict p4,
@@ -304,3 +307,6 @@ void __xor_eor3_5(unsigned long bytes, unsigned long * __restrict p1, dp5 +=8 ; }while (--lines >0 ); } + +__DO_XOR_BLOCKS (eor3_inner, __xor_neon_2, __xor_eor3_3, __xor_eor3_4, + __xor_eor3_5);
lib/raid/xor/arm64/xor-neon.h +4 -28
@@ -1,30 +1,6 @@/* SPDX-License-Identifier: GPL-2.0-only */ -void __xor_neon_2 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2); -void __xor_neon_3 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2, -const unsigned long * __restrict p3); -void __xor_neon_4 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2, -const unsigned long * __restrict p3, -const unsigned long * __restrict p4); -void __xor_neon_5 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2, -const unsigned long * __restrict p3, -const unsigned long * __restrict p4, -const unsigned long * __restrict p5); - -#define __xor_eor3_2 __xor_neon_2 -void __xor_eor3_3 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2, -const unsigned long * __restrict p3); -void __xor_eor3_4 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2, -const unsigned long * __restrict p3, -const unsigned long * __restrict p4); -void __xor_eor3_5 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2, -const unsigned long * __restrict p3, -const unsigned long * __restrict p4, -const unsigned long * __restrict p5); +void xor_gen_neon_inner (void *dest,void **srcs,unsigned int src_cnt, +unsigned int bytes); +void xor_gen_eor3_inner (void *dest,void **srcs,unsigned int src_cnt, +unsigned int bytes);
lib/raid/xor/loongarch/xor_simd_glue.c +11 -51
74 lines not on this page · raw message
lib/raid/xor/powerpc/xor_vmx.c +22 -18
@@ -10,6 +10,7 @@* Sparse (as at v0.5.0) gets very, very confused by this file. * Make it a bit simpler for it. */ +#include "xor_impl.h" #if !defined(__CHECKER__)#include <altivec.h> #else
@@ -49,9 +50,9 @@ typedef vector signed char unative_t; V1##_3 = vec_xor(V1##_3, V2##_3); \ }while (0 ) -void __xor_altivec_2(unsigned long bytes, - unsigned long * __restrict v1_in, - const unsigned long * __restrict v2_in) +static void __xor_altivec_2(unsigned long bytes, +unsigned long * __restrict v1_in, +const unsigned long * __restrict v2_in) {DEFINE (v1);DEFINE (v2);
@@ -68,10 +69,10 @@ void __xor_altivec_2(unsigned long bytes, }while (--lines >0 ); } -void __xor_altivec_3 (unsigned long bytes, -unsigned long * __restrict v1_in, -const unsigned long * __restrict v2_in, -const unsigned long * __restrict v3_in) +static void __xor_altivec_3 (unsigned long bytes, +unsigned long * __restrict v1_in, +const unsigned long * __restrict v2_in, +const unsigned long * __restrict v3_in) {DEFINE (v1);DEFINE (v2);
@@ -92,11 +93,11 @@ void __xor_altivec_3(unsigned long bytes, }while (--lines >0 ); } -void __xor_altivec_4 (unsigned long bytes, -unsigned long * __restrict v1_in, -const unsigned long * __restrict v2_in, -const unsigned long * __restrict v3_in, -const unsigned long * __restrict v4_in) +static void __xor_altivec_4 (unsigned long bytes, +unsigned long * __restrict v1_in, +const unsigned long * __restrict v2_in, +const unsigned long * __restrict v3_in, +const unsigned long * __restrict v4_in) {DEFINE (v1);DEFINE (v2);
@@ -121,12 +122,12 @@ void __xor_altivec_4(unsigned long bytes, }while (--lines >0 ); } -void __xor_altivec_5 (unsigned long bytes, -unsigned long * __restrict v1_in, -const unsigned long * __restrict v2_in, -const unsigned long * __restrict v3_in, -const unsigned long * __restrict v4_in, -const unsigned long * __restrict v5_in) +static void __xor_altivec_5 (unsigned long bytes, +unsigned long * __restrict v1_in, +const unsigned long * __restrict v2_in, +const unsigned long * __restrict v3_in, +const unsigned long * __restrict v4_in, +const unsigned long * __restrict v5_in) {DEFINE (v1);DEFINE (v2);
@@ -154,3 +155,6 @@ void __xor_altivec_5(unsigned long bytes, v5 +=4 ; }while (--lines >0 ); } + +__DO_XOR_BLOCKS (altivec_inner, __xor_altivec_2, __xor_altivec_3, + __xor_altivec_4, __xor_altivec_5);
lib/raid/xor/powerpc/xor_vmx.h +2 -14
@@ -6,17 +6,5 @@* outside of the enable/disable altivec block. */ -void __xor_altivec_2 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2); -void __xor_altivec_3 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2, -const unsigned long * __restrict p3); -void __xor_altivec_4 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2, -const unsigned long * __restrict p3, -const unsigned long * __restrict p4); -void __xor_altivec_5 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2, -const unsigned long * __restrict p3, -const unsigned long * __restrict p4, -const unsigned long * __restrict p5); +void xor_gen_altivec_inner (void *dest,void **srcs,unsigned int src_cnt, +unsigned int bytes);
lib/raid/xor/powerpc/xor_vmx_glue.c +5 -44
61 lines not on this page · raw message
lib/raid/xor/riscv/xor-glue.c +6 -37
54 lines not on this page · raw message
lib/raid/xor/s390/xor.c +4 -5
@@ -125,10 +125,9 @@ static void xor_xc_5(unsigned long bytes, unsigned long * __restrict p1, : : "0", "cc", "memory"); } +DO_XOR_BLOCKS (xc, xor_xc_2, xor_xc_3, xor_xc_4, xor_xc_5); +struct xor_block_template xor_block_xc = { - .name ="xc" , - .do_2 = xor_xc_2, - .do_3 = xor_xc_3, - .do_4 = xor_xc_4, - .do_5 = xor_xc_5, + .name ="xc" , + .xor_gen = xor_gen_xc, };
lib/raid/xor/sparc/xor-sparc32.c +4 -5
@@ -244,10 +244,9 @@ sparc_5(unsigned long bytes, unsigned long * __restrict p1, }while (--lines >0 ); } +DO_XOR_BLOCKS (sparc32, sparc_2, sparc_3, sparc_4, sparc_5); +struct xor_block_template xor_block_SPARC = { - .name ="SPARC" , - .do_2 = sparc_2, - .do_3 = sparc_3, - .do_4 = sparc_4, - .do_5 = sparc_5, + .name ="SPARC" , + .xor_gen = xor_gen_sparc32, };
lib/raid/xor/sparc/xor-sparc64-glue.c +9 -10
@@ -28,12 +28,11 @@ void xor_vis_5(unsigned long bytes, unsigned long * __restrict p1,/* XXX Ugh, write cheetah versions... -DaveM */ +DO_XOR_BLOCKS (vis, xor_vis_2, xor_vis_3, xor_vis_4, xor_vis_5); +struct xor_block_template xor_block_VIS = { - .name ="VIS" , - .do_2 = xor_vis_2, - .do_3 = xor_vis_3, - .do_4 = xor_vis_4, - .do_5 = xor_vis_5, + .name ="VIS" , + .xor_gen = xor_gen_vis, }; void xor_niagara_2(unsigned long bytes, unsigned long * __restrict p1,
@@ -51,10 +50,10 @@ void xor_niagara_5(unsigned long bytes, unsigned long * __restrict p1,const unsigned long * __restrict p4, const unsigned long * __restrict p5); +DO_XOR_BLOCKS (niagara, xor_niagara_2, xor_niagara_3, xor_niagara_4, + xor_niagara_5); +struct xor_block_template xor_block_niagara = { - .name ="Niagara" , - .do_2 = xor_niagara_2, - .do_3 = xor_niagara_3, - .do_4 = xor_niagara_4, - .do_5 = xor_niagara_5, + .name ="Niagara" , + .xor_gen = xor_gen_niagara, };
lib/raid/xor/x86/xor-avx.c +10 -19
@@ -29,8 +29,6 @@ static void xor_avx_2(unsigned long bytes, unsigned long * __restrict p0, {unsigned long lines = bytes >>9 ; -kernel_fpu_begin (); -while (lines--) {#undef BLOCK#define BLOCK (i, reg) \
@@ -47,8 +45,6 @@ do { \ p0 = (unsigned long *)((uintptr_t )p0 +512 ); p1 = (unsigned long *)((uintptr_t )p1 +512 ); } - -kernel_fpu_end (); } static void xor_avx_3(unsigned long bytes, unsigned long * __restrict p0,
@@ -57,8 +53,6 @@ static void xor_avx_3(unsigned long bytes, unsigned long * __restrict p0, {unsigned long lines = bytes >>9 ; -kernel_fpu_begin (); -while (lines--) {#undef BLOCK#define BLOCK (i, reg) \
@@ -78,8 +72,6 @@ do { \ p1 = (unsigned long *)((uintptr_t )p1 +512 ); p2 = (unsigned long *)((uintptr_t )p2 +512 ); } - -kernel_fpu_end (); } static void xor_avx_4(unsigned long bytes, unsigned long * __restrict p0,
@@ -89,8 +81,6 @@ static void xor_avx_4(unsigned long bytes, unsigned long * __restrict p0, {unsigned long lines = bytes >>9 ; -kernel_fpu_begin (); -while (lines--) {#undef BLOCK#define BLOCK (i, reg) \
@@ -113,8 +103,6 @@ do { \ p2 = (unsigned long *)((uintptr_t )p2 +512 ); p3 = (unsigned long *)((uintptr_t )p3 +512 ); } - -kernel_fpu_end (); } static void xor_avx_5(unsigned long bytes, unsigned long * __restrict p0,
@@ -125,8 +113,6 @@ static void xor_avx_5(unsigned long bytes, unsigned long * __restrict p0, {unsigned long lines = bytes >>9 ; -kernel_fpu_begin (); -while (lines--) {#undef BLOCK#define BLOCK (i, reg) \
@@ -152,14 +138,19 @@ do { \ p3 = (unsigned long *)((uintptr_t )p3 +512 ); p4 = (unsigned long *)((uintptr_t )p4 +512 ); } +} + +DO_XOR_BLOCKS (avx_inner, xor_avx_2, xor_avx_3, xor_avx_4, xor_avx_5); +static void xor_gen_avx (void *dest,void **srcs,unsigned int src_cnt, +unsigned int bytes) +{ +kernel_fpu_begin (); +xor_gen_avx_inner (dest, srcs, src_cnt, bytes);kernel_fpu_end (); }struct xor_block_template xor_block_avx = { - .name ="avx" , - .do_2 = xor_avx_2, - .do_3 = xor_avx_3, - .do_4 = xor_avx_4, - .do_5 = xor_avx_5, + .name ="avx" , + .xor_gen = xor_gen_avx, };
lib/raid/xor/x86/xor-mmx.c +24 -40
166 lines not on this page · raw message
lib/raid/xor/x86/xor-sse.c +23 -40
165 lines not on this page · raw message
lib/raid/xor/xor-32regs-prefetch.c +5 -5
@@ -258,10 +258,10 @@ xor_32regs_p_5(unsigned long bytes, unsigned long * __restrict p1, goto once_more; } +DO_XOR_BLOCKS(32regs_p, xor_32regs_p_2, xor_32regs_p_3, xor_32regs_p_4, + xor_32regs_p_5); +struct xor_block_template xor_block_32regs_p = { - .name ="32regs_prefetch" , - .do_2 = xor_32regs_p_2, - .do_3 = xor_32regs_p_3, - .do_4 = xor_32regs_p_4, - .do_5 = xor_32regs_p_5, + .name ="32regs_prefetch" , + .xor_gen = xor_gen_32regs_p, };
lib/raid/xor/xor-32regs.c +4 -5
@@ -209,10 +209,9 @@ 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); +struct xor_block_template xor_block_32regs = { - .name ="32regs" , - .do_2 = xor_32regs_2, - .do_3 = xor_32regs_3, - .do_4 = xor_32regs_4, - .do_5 = xor_32regs_5, + .name ="32regs" , + .xor_gen = xor_gen_32regs, };
lib/raid/xor/xor-8regs-prefetch.c +6 -5
@@ -136,10 +136,11 @@ xor_8regs_p_5(unsigned long bytes, unsigned long * __restrict p1, goto once_more; } + +DO_XOR_BLOCKS(8regs_p, xor_8regs_p_2, xor_8regs_p_3, xor_8regs_p_4, + xor_8regs_p_5); +struct xor_block_template xor_block_8regs_p = { - .name ="8regs_prefetch" , - .do_2 = xor_8regs_p_2, - .do_3 = xor_8regs_p_3, - .do_4 = xor_8regs_p_4, - .do_5 = xor_8regs_p_5, + .name ="8regs_prefetch" , + .xor_gen = xor_gen_8regs_p, };
lib/raid/xor/xor-8regs.c +4 -5
@@ -94,11 +94,10 @@ xor_8regs_5(unsigned long bytes, unsigned long * __restrict p1, }#ifndef NO_TEMPLATE +DO_XOR_BLOCKS(8regs, xor_8regs_2, xor_8regs_3, xor_8regs_4, xor_8regs_5); +struct xor_block_template xor_block_8regs = { - .name ="8regs" , - .do_2 = xor_8regs_2, - .do_3 = xor_8regs_3, - .do_4 = xor_8regs_4, - .do_5 = xor_8regs_5, + .name ="8regs" , + .xor_gen = xor_gen_8regs, };#endif /* NO_TEMPLATE */
lib/raid/xor/xor-core.c +5 -42
75 lines not on this page · raw message
lib/raid/xor/xor_impl.h +34 -14
61 lines not on this page · raw message
Signature · 1 line
2.47.3
PATCH 25/26 xor: use static_call for xor_gen
In reply to Christoph HellwigAvoid the indirect call for xor_generation by using a static_call.
--- lib/raid/xor/xor-core.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
lib/raid/xor/xor-core.c +11 -11
@@ -11,10 +11,10 @@#include <linux/raid/xor.h> #include <linux/jiffies.h> #include <linux/preempt.h> +#include <linux/static_call.h> #include "xor_impl.h" -/* The xor routine to use. */ -static struct xor_block_template *active_template; +DEFINE_STATIC_CALL_NULL (xor_gen_impl, *xor_block_8regs.xor_gen);/** * xor_gen - generate RAID-style XOR information
@@ -36,13 +36,13 @@ void xor_gen(void *dest, void **srcs, unsigned int src_cnt, unsigned int bytes)lockdep_assert_preemption_enabled ();WARN_ON_ONCE (bytes &511 ); - 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 bool __initdata xor_forced = false; +static struct xor_block_template *forced_template;/** * xor_register - register a XOR template
@@ -68,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
@@ -110,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 );
@@ -127,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);
@@ -155,10 +155,10 @@ 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 ; }
@@ -169,7 +169,7 @@ static int __init xor_init(void)* Pick the first template as the temporary default until calibration * happens. */ - active_template = template_list; +static_call_update (xor_gen_impl, template_list->xor_gen);return 0 ;#endif }
Signature · 1 line
2.47.3
PATCH 26/26 xor: add a kunit test case
In reply to Christoph HellwigAdd a test case for the XOR routines loosely based on the CRC kunit test.
--- lib/raid/.kunitconfig | 3 + lib/raid/Kconfig | 11 ++ lib/raid/xor/Makefile | 2 +- lib/raid/xor/tests/Makefile | 3 + lib/raid/xor/tests/xor_kunit.c | 187 +++++++++++++++++++++++++++++++++ 5 files changed, 205 insertions(+), 1 deletion(-) create mode 100644 lib/raid/.kunitconfig create mode 100644 lib/raid/xor/tests/Makefile create mode 100644 lib/raid/xor/tests/xor_kunit.c
lib/raid/.kunitconfig new file +3 -0
@@ -0,0 +1,3 @@ +CONFIG_KUNIT=y +CONFIG_BTRFS_FS=y +CONFIG_XOR_KUNIT_TEST=y
lib/raid/Kconfig +11 -0
@@ -17,3 +17,14 @@ config XOR_BLOCKS_ARCH default y if X86_32 default y if X86_64 bool + +config XOR_KUNIT_TEST + tristate "KUnit tests for xor_gen" if !KUNIT_ALL_TESTS + depends on KUNIT + depends on XOR_BLOCKS + default KUNIT_ALL_TESTS + help + Unit tests for the XOR library functions. + + This is intended to help people writing architecture-specific + optimized versions. If unsure, say N.
lib/raid/xor/Makefile +1 -1
@@ -29,7 +29,7 @@ xor-$(CONFIG_SPARC64) += sparc/xor-sparc64.o sparc/xor-sparc64-glue.o xor-$(CONFIG_S390) += s390/xor.o xor-$(CONFIG_X86_32) += x86/xor-avx.o x86/xor-sse.o x86/xor-mmx.o xor-$(CONFIG_X86_64) += x86/xor-avx.o x86/xor-sse.o - +obj-y += tests/ CFLAGS_arm/xor-neon.o += $(CC_FLAGS_FPU) CFLAGS_REMOVE_arm/xor-neon.o += $(CC_FLAGS_NO_FPU)
lib/raid/xor/tests/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0-only + +obj-$(CONFIG_XOR_KUNIT_TEST) += xor_kunit.o
lib/raid/xor/tests/xor_kunit.c new file +187 -0
187 lines not on this page · raw message
Signature · 1 line
2.47.3
Andrew Morton
maintainerQuoted 8 lines · On Tue, 24 Mar 2026 07:21:36 +0100 Christoph Hellwig <[email protected]> wrote:
the XOR library used for the RAID5 parity is a bit of a mess right now. The main file sits in
crypto/despite not being cryptography and not using the crypto API, with the generic implementations sitting ininclude/asm-genericand the arch implementations sitting in an asm/ header in theory. The latter doesn't work for many cases, so architectures often build the code directly into the core kernel, or create another module for the architecture code.
Quoted 6 lines
Changes this to a single module in
lib/that also contains the architecture optimizations, similar to the library work Eric Biggers has done for the CRC and crypto libraries later. After that it changes to better calling conventions that allow for smarter architecture implementations (although none is contained here yet), and usesstatic_callto avoid indirection function call overhead.
Thanks, I'll update mm.git to this version.
It looks like AI review has found a few things:
https://sashiko.dev/#/patchset/[email protected]
Andrew Morton
maintainerQuoted 8 lines · On Tue, 24 Mar 2026 07:21:36 +0100 Christoph Hellwig <[email protected]> wrote:
the XOR library used for the RAID5 parity is a bit of a mess right now. The main file sits in
crypto/despite not being cryptography and not using the crypto API, with the generic implementations sitting ininclude/asm-genericand the arch implementations sitting in an asm/ header in theory. The latter doesn't work for many cases, so architectures often build the code directly into the core kernel, or create another module for the architecture code.
Quoted 6 lines
Changes this to a single module in
lib/that also contains the architecture optimizations, similar to the library work Eric Biggers has done for the CRC and crypto libraries later. After that it changes to better calling conventions that allow for smarter architecture implementations (although none is contained here yet), and usesstatic_callto avoid indirection function call overhead.
Thanks, I've updated mm.git's mm-nonmm-unstable branch to this version of the patchset.
Quoted 17 lines · Christoph Hellwig
Hi all,
the XOR library used for the RAID5 parity is a bit of a mess right now. The main file sits in
crypto/despite not being cryptography and not using the crypto API, with the generic implementations sitting ininclude/asm-genericand the arch implementations sitting in an asm/ header in theory. The latter doesn't work for many cases, so architectures often build the code directly into the core kernel, or create another module for the architecture code.Changes this to a single module in
lib/that also contains the architecture optimizations, similar to the library work Eric Biggers has done for the CRC and crypto libraries later. After that it changes to better calling conventions that allow for smarter architecture implementations (although none is contained here yet), and usesstatic_callto avoid indirection function call overhead.
Quoted 7 lines
A git tree is also available here:
git://git.infradead.org/users/hch/misc.gitxor-improvementsGitweb:
https://git.infradead.org/?p=users/hch/misc.git;a=shortlog;h=refs/heads/xor-improvements
This generally looks good, but yes, please check the comments from
https://sashiko.dev/#/patchset/[email protected], as Andrew mentioned.
The bug where the test generates length 0 is definitely real. I verified it causes the test to crash on some platforms.
raid_run_ops() calling xor_gen() (indirectly) with preemption disabled looks real as well, though I haven't tested it. If preemption is indeed not the right thing to check, then I guess (following up from
https://lore.kernel.org/linux-crypto/20260303195517.GC2846@sol/) it would need to be something like:
WARN_ON_ONCE(!in_task() || irqs_disabled() || softirq_count() != 0);
Ugly, but we're running out of options.
(This sort of thing is why the functions in lib/crypto/ and lib/crc/ are just supported in all contexts instead. If FPU/vector/SIMD registers cannot be used in the current context, then a scalar fallback is used.)
- Eric
Quoted 3 lines · Eric Biggers
This generally looks good, but yes, please check the comments from
https://sashiko.dev/#/patchset/[email protected], as Andrew mentioned.
Yes, I've looked into them and fixed the, the current version in the git branch already has the changes.
Quoted 8 lines
looks real as well, though I haven't tested it. If preemption is indeed not the right thing to check, then I guess (following up from
https://lore.kernel.org/linux-crypto/20260303195517.GC2846@sol/) it would need to be something like:WARN_ON_ONCE(!in_task() || irqs_disabled() || softirq_count() != 0);Ugly, but we're running out of options.
So far I've just reverted back to the in_interrupted() check we had before. I can switch to the above, though.
Quoted 3 lines
(This sort of thing is why the functions in
lib/crypto/andlib/crc/are just supported in all contexts instead. If FPU/vector/SIMD registers cannot be used in the current context, then a scalar fallback is used.)
We could do this fairly easily, but I'm not sure it is a good idea. The callers of these routines are extremely limited, so we'd have to add code for this which will then only be used by the new extensive test code we'd have to add for it.