misc lib/raid/ improvements
Hi all,
this series improves the benchmark-based algorithm selection and adds kunit benchmarks for both the XOR and raid6 libraries, and tidies up a few very minor other bits.
diffstat:
lib/raid/Kconfig | 15 ++++++ lib/raid/raid6/Makefile | 2 lib/raid/raid6/algos.c | 112 +++++++++++++++++++++++++--------------------- lib/raid/raid6/tests/raid6_kunit.c | 66 ++++++++++++++++++++++++++- lib/raid/xor/Makefile | 2 lib/raid/xor/tests/Makefile | 2 lib/raid/xor/tests/xor_kunit.c | 64 +++++++++++++++++++++++++- lib/raid/xor/xor-core.c | 55 ++++++++++------------ 8 files changed, 236 insertions(+), 82 deletions(-)
PATCH 1/8 xor: enable lock context analysis
The code doesn't have any locking, so this is trivial.
--- lib/raid/xor/Makefile | 2 ++ lib/raid/xor/tests/Makefile | 2 ++ 2 files changed, 4 insertions(+)
lib/raid/xor/Makefile +2 -0
@@ -1,5 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 +CONTEXT_ANALYSIS := y + ccflags-y += -I $(src) obj-$(CONFIG_XOR_BLOCKS) += xor.o
lib/raid/xor/tests/Makefile +2 -0
@@ -1,3 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only +CONTEXT_ANALYSIS := y + obj-$(CONFIG_XOR_KUNIT_TEST) += xor_kunit.o
Signature · 1 line
2.53.0
PATCH 2/8 xor: improve the runtime selection benchmark
In reply to Christoph HellwigUse plain ktime_get_ns for the timing, use 4 + 1 disks for a realistic load, and report the throughput on the data disks instead of the that on the parity disk, which isn't all that useful.
--- lib/raid/xor/xor-core.c | 55 +++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 29 deletions(-)
lib/raid/xor/xor-core.c +26 -29
@@ -10,7 +10,6 @@#include <linux/gfp.h> #include <linux/slab.h> #include <linux/raid/xor.h> -#include <linux/jiffies.h> #include <linux/preempt.h> #include <linux/static_call.h> #include "xor_impl.h"
@@ -73,59 +72,56 @@ void __init xor_force(struct xor_block_template *tmpl) forced_template = tmpl; } -#define BENCH_SIZE 4096 +#define BENCH_SIZE SZ_4K +#define NR_SRCS 4#define REPS 800U -static void __init -do_xor_speed (struct xor_block_template *tmpl,void *b1,void *b2) +static void __init do_xor_speed (struct xor_block_template *tmpl,void *dest, +void *srcs[NR_SRCS ]) { -int speed; -unsigned long reps; -ktime_t min, start, t0; -void *srcs[1 ] = { b2 }; +u64 t; +int i;preempt_disable (); - - reps =0 ; - t0 =ktime_get (); -/* delay start until time has advanced */ -while ((start =ktime_get ()) == t0) -cpu_relax (); -do { + t =ktime_get_ns (); +for (i =0 ; i <REPS ; i++) {mb ();/* prevent loop optimization */ - tmpl->xor_gen (b1, srcs,1 ,BENCH_SIZE ); + tmpl->xor_gen (dest, srcs,NR_SRCS ,BENCH_SIZE );mb (); - }while (reps++ <REPS || (t0 =ktime_get ()) == start); - min =ktime_sub (t0, start); - + } + t =ktime_get_ns () - t;preempt_enable (); -// bytes/ns == GB/s, multiply by 1000 to get MB/s [not MiB/s] - speed = (1000 * reps *BENCH_SIZE ) / (unsigned int )ktime_to_ns (min); - tmpl->speed = speed; +/* bytes/ns == GB/s, multiply by 1000 to get MB/s [not MiB/s] */ + tmpl->speed =div64_u64 ((u64 )BENCH_SIZE *REPS *NR_SRCS *1000 , t); -pr_info (" %-16s: %5d MB/sec\n" , tmpl->name, speed); +pr_info (" %-16s: %5d MB/sec\n" , tmpl->name, tmpl->speed); }static int __init calibrate_xor_blocks (void ) { -void *b1, *b2;struct xor_block_template *f, *fastest; +void *srcs[NR_SRCS ]; +void *buf, *dest; +int i;if (forced_template)return 0 ; - b1 =kmalloc (PAGE_SIZE *4 ,GFP_KERNEL ); -if (!b1) { + buf =kmalloc (BENCH_SIZE * (NR_SRCS +1 ),GFP_KERNEL ); +if (!buf) {pr_warn ("xor: Yikes! No memory available.\n" );return -ENOMEM ; } - b2 = b1 +2 *PAGE_SIZE +BENCH_SIZE ; +get_random_bytes (buf,BENCH_SIZE * (NR_SRCS +1 )); + dest = buf; +for (i =0 ; i <NR_SRCS ; i++) + srcs[i] = buf + (i +1 ) *BENCH_SIZE ;pr_info ("xor: measuring software checksum speed\n" ); fastest = template_list;for (f = template_list; f; f = f->next) { -do_xor_speed (f, b1, b2); +do_xor_speed (f, dest, srcs);if (f->speed > fastest->speed) fastest = f; }
@@ -133,9 +129,10 @@ static int __init calibrate_xor_blocks(void)pr_info ("xor: using function: %s (%d MB/sec)\n" , fastest->name, fastest->speed); -kfree (b1); +kfree (buf);return 0 ; } +#undef NR_SRCS#ifdef CONFIG_XOR_BLOCKS_ARCH #include "xor_arch.h" /* $SRCARCH/xor_arch.h */
Signature · 1 line
2.53.0
PATCH 3/8 xor/kunit: fix a spelling error
In reply to Christoph Hellwig--- lib/raid/xor/tests/xor_kunit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/raid/xor/tests/xor_kunit.c +1 -1
@@ -85,7 +85,7 @@ static void xor_test(struct kunit *test)xor_generate_random_data ();/* -* If we're not using the entire buffer size, inject randomize +* If we're not using the entire buffer size, inject randomized * alignment into the buffer. */ max_alignment =XOR_KUNIT_MAX_BYTES - len;
Signature · 1 line
2.53.0
PATCH 4/8 xor/kunit: add a benchmark
In reply to Christoph HellwigAdd a benchmark to test the XOR functions for more representative block sizes and numbers of disks. Including 64k would be useful here, but increasing the test buffer size increases the runtime of the functional kunit test too much unfortunately.
The runtime numbers are reported in GB/s as the numbers of modern implementations are basically unreadable as MB/s. This means retro-architectures could report 0, but that is an easy tradeoff.
--- lib/raid/Kconfig | 6 ++++ lib/raid/xor/tests/xor_kunit.c | 62 ++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+)
lib/raid/Kconfig +6 -0
@@ -29,6 +29,12 @@ config XOR_KUNIT_TEST This is intended to help people writing architecture-specific optimized versions. If unsure, say N. +config XOR_BENCHMARK + bool "Benchmark for xor_gen" + depends on XOR_KUNIT_TEST + help + Include benchmarks in the KUnit test suite for xor_gen. + config RAID6_PQ tristate
lib/raid/xor/tests/xor_kunit.c +62 -0
70 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH 5/8 raid6: enable lock context analysis
In reply to Christoph HellwigThe code doesn't have any locking, so this is trivial.
--- lib/raid/raid6/Makefile | 2 ++ 1 file changed, 2 insertions(+)
lib/raid/raid6/Makefile +2 -0
@@ -1,5 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 +CONTEXT_ANALYSIS := y + ccflags-y += -I $(src) ifeq ($(CONFIG_RAID6_PQ_ARCH),y)
Signature · 1 line
2.53.0
PATCH 6/8 raid6: defer implementation selection when built-in
In reply to Christoph HellwigDon't hold up early boot and defer the selection just like we've been doing for the RAID5 XOR code since commit 524ccdbdfb52 ("crypto: xor - defer load time benchmark to a later time").
This will also allow full use of the timing subsystem for benchmarking.
--- lib/raid/raid6/algos.c | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-)
lib/raid/raid6/algos.c +27 -10
@@ -236,16 +236,6 @@ static int __init raid6_select_algo(void)int i, cycle;int error; -if (!IS_ENABLED (CONFIG_RAID6_PQ_BENCHMARK ) || raid6_nr_algos ==1 ) { -pr_info ("raid6: skipped pq benchmark and selected %s\n" , - raid6_algos[raid6_nr_algos -1 ]->name); -static_call_update (raid6_gen_syndrome_impl, - raid6_algos[raid6_nr_algos -1 ]->gen_syndrome); -static_call_update (raid6_xor_syndrome_impl, - raid6_algos[raid6_nr_algos -1 ]->xor_syndrome); -return 0 ; - } -/* prepare the buffer and fill it circularly with gfmul table */ disk_ptr =kmalloc (PAGE_SIZE *RAID6_TEST_DISKS ,GFP_KERNEL );if (!disk_ptr) {
@@ -329,13 +319,40 @@ static int __init raid6_init(void)static_call_update (raid6_recov_datap_impl, raid6_recov_algo->datap);pr_info ("raid6: using %s recovery algorithm\n" , raid6_recov_algo->name); +if (!IS_ENABLED (CONFIG_RAID6_PQ_BENCHMARK ) || raid6_nr_algos ==1 ) { +pr_info ("raid6: skipped pq benchmark and selected %s\n" , + raid6_algos[raid6_nr_algos -1 ]->name); + goto default_algo; + } + +#ifdef MODULE return raid6_select_algo (); +#else +/* +* Pick the last registered implementation as the temporary default until +* calibration happens. +*/ +#endif +default_algo: +static_call_update (raid6_gen_syndrome_impl, + raid6_algos[raid6_nr_algos -1 ]->gen_syndrome); +static_call_update (raid6_xor_syndrome_impl, + raid6_algos[raid6_nr_algos -1 ]->xor_syndrome); +return 0 ; } static void __exit raid6_exit(void) { } +/* +* When built-in we must register the default implementation before md +* initializes, but we don't want calibration to run that early as that +* would delay the boot process. +*/ +#ifndef MODULE +device_initcall (raid6_select_algo); +#endif subsys_initcall (raid6_init);module_exit (raid6_exit);MODULE_LICENSE ("GPL" );
Signature · 1 line
2.53.0