diff --git a/Makefile.am b/Makefile.am index 7aa7750a..1a58fc47 100644 --- a/Makefile.am +++ b/Makefile.am @@ -195,16 +195,11 @@ EXTRA_DIST = \ configure.windows-x86 configure.windows-x64 snapraid.conf.example.windows \ m4/ax_pthread.m4 \ m4/m4_ax_check_compile_flag.m4 \ - raid/README \ - raid/NOTES \ - raid/OTHERS \ - raid/mktables.c \ raid/test/Makefile \ raid/test/fulltest.c \ raid/test/selftest.c \ raid/test/speedtest.c \ raid/test/invtest.c \ - raid/test/invtestx.c \ makeslackware.sh.in \ makeslackdist.sh.in \ pkg/snapraid.SlackBuild.in \ diff --git a/TODO b/TODO index 5c0e630f..a58b42eb 100644 --- a/TODO +++ b/TODO @@ -24,6 +24,11 @@ All done ? * Enable MuseAir and disable random seed +* Optimize rec2of2 SIMD recovery for P+Q: add specialized AVX2, AVX512 and GFNI + fast paths for recovering two failed data disks when ip[0] == 0 && ip[1] == 1. + Exploit the RAID6 closed-form solution to reduce recovery from 4 generic GF + multiplications to 2 GF multiplications plus XOR (Dy = C0*Pd ^ C1*Qd, Dx = Pd ^ Dy). + * Check Reliability Test. We can derive Failure probability from MBTF https://github.com/linuxhw/SMART https://github.com/linuxhw/EnterpriseDrive diff --git a/cmdline/dup.c b/cmdline/dup.c index 39e3b66e..873be3f8 100644 --- a/cmdline/dup.c +++ b/cmdline/dup.c @@ -60,10 +60,8 @@ static inline tommy_uint32_t hash_hash(struct snapraid_hash* hash) return tommy_hash_u32(0, hash->hash, HASH_MAX); } -static void hash_free(void* void_hash) +void hash_free(struct snapraid_hash* hash) { - struct snapraid_hash* hash = void_hash; - free(hash); } @@ -124,7 +122,7 @@ void state_dup(struct snapraid_state* state) } } - tommy_hashdyn_foreach(&hashset, hash_free); + tommy_hashdyn_foreach(&hashset, (tommy_foreach_func*)hash_free); tommy_hashdyn_done(&hashset); msg_status("\n"); diff --git a/cmdline/elem.c b/cmdline/elem.c index ac192970..c5b13d96 100644 --- a/cmdline/elem.c +++ b/cmdline/elem.c @@ -24,10 +24,8 @@ struct snapraid_content* content_alloc(const char* path, uint64_t dev) return content; } -void content_free(void* void_content) +void content_free(struct snapraid_content* content) { - struct snapraid_content* content = void_content; - free(content); } @@ -455,10 +453,8 @@ struct snapraid_file* file_dup(struct snapraid_file* copy) return file; } -void file_free(void* void_file) +void file_free(struct snapraid_file* file) { - struct snapraid_file* file = void_file; - free(file->sub); file->sub = 0; free(file->blockvec); @@ -683,10 +679,8 @@ struct snapraid_extent* extent_alloc(block_off_t parity_pos, struct snapraid_fil return extent; } -void extent_free(void* void_extent) +void extent_free(struct snapraid_extent* extent) { - struct snapraid_extent* extent = void_extent; - free(extent); } @@ -736,10 +730,8 @@ struct snapraid_link* link_alloc(const char* sub, const char* linkto, unsigned l return slink; } -void link_free(void* void_link) +void link_free(struct snapraid_link* slink) { - struct snapraid_link* slink = void_link; - free(slink->sub); free(slink->linkto); free(slink); @@ -772,10 +764,8 @@ struct snapraid_dir* dir_alloc(const char* sub) return dir; } -void dir_free(void* void_dir) +void dir_free(struct snapraid_dir* dir) { - struct snapraid_dir* dir = void_dir; - free(dir->sub); free(dir); } @@ -830,10 +820,8 @@ void dealloc_import(struct snapraid_dealloc* dealloc, struct snapraid_file* file } } -void dealloc_free(void* void_dealloc) +void dealloc_free(struct snapraid_dealloc* dealloc) { - struct snapraid_dealloc* dealloc = void_dealloc; - free(dealloc->sub); free(dealloc->blockhash); free(dealloc); @@ -902,21 +890,19 @@ struct snapraid_disk* disk_alloc(const char* name, const char* dir, uint64_t dev return disk; } -void disk_free(void* void_disk) +void disk_free(struct snapraid_disk* disk) { - struct snapraid_disk* disk = void_disk; - - tommy_list_foreach(&disk->filelist, file_free); - tommy_list_foreach(&disk->deletedlist, file_free); - tommy_tree_foreach(&disk->fs_file, extent_free); + tommy_list_foreach(&disk->filelist, (tommy_foreach_func*)file_free); + tommy_list_foreach(&disk->deletedlist, (tommy_foreach_func*)file_free); + tommy_tree_foreach(&disk->fs_file, (tommy_foreach_func*)extent_free); tommy_hashdyn_done(&disk->inodeset); tommy_hashdyn_done(&disk->pathset); tommy_hashdyn_done(&disk->stampset); - tommy_list_foreach(&disk->linklist, link_free); + tommy_list_foreach(&disk->linklist, (tommy_foreach_func*)link_free); tommy_hashdyn_done(&disk->linkset); - tommy_list_foreach(&disk->dirlist, dir_free); + tommy_list_foreach(&disk->dirlist, (tommy_foreach_func*)dir_free); tommy_hashdyn_done(&disk->dirset); - tommy_list_foreach(&disk->dealloclist, dealloc_free); + tommy_list_foreach(&disk->dealloclist, (tommy_foreach_func*)dealloc_free); #if HAVE_THREAD thread_mutex_destroy(&disk->fs_mutex); @@ -951,10 +937,8 @@ struct snapraid_extra* extra_alloc(const char* name, const char* dir, uint64_t d return extra; } -void extra_free(void* void_extra) +void extra_free(struct snapraid_extra* extra) { - struct snapraid_extra* extra = void_extra; - free(extra); } @@ -1581,10 +1565,8 @@ struct snapraid_map* map_alloc(const char* name, unsigned position, block_off_t return map; } -void map_free(void* void_map) +void map_free(struct snapraid_map* map) { - struct snapraid_map* map = void_map; - free(map); } @@ -1602,10 +1584,8 @@ static int bucket_cmp(const void* void_a, const void* void_b) return 0; } -void bucket_free(void* void_bucket) +void bucket_free(struct snapraid_bucket* bucket) { - struct snapraid_bucket* bucket = void_bucket; - free(bucket); } @@ -1641,7 +1621,7 @@ void bucket_insert(tommy_hashdyn* bucket_hash, time_t time_at, block_off_t count void bucket_to_list(tommy_hashdyn* bucket_hash, tommy_list* bucket_list, block_off_t* bucketcount) { /* clear previous list */ - tommy_list_foreach(bucket_list, bucket_free); + tommy_list_foreach(bucket_list, (tommy_foreach_func*)bucket_free); tommy_list_init(bucket_list); log_tag("list:bucket_begin\n"); diff --git a/cmdline/elem.h b/cmdline/elem.h index e4a1f097..73b67468 100644 --- a/cmdline/elem.h +++ b/cmdline/elem.h @@ -574,7 +574,7 @@ struct snapraid_content* content_alloc(const char* path, uint64_t dev); /** * Deallocate a content. */ -void content_free(void* void_content); +void content_free(struct snapraid_content* content); /** * Allocate a filter pattern for files and directories. @@ -850,7 +850,7 @@ struct snapraid_file* file_dup(struct snapraid_file* copy); /** * Deallocate a file. */ -void file_free(void* void_file); +void file_free(struct snapraid_file* file); /** * Rename a file. @@ -955,7 +955,7 @@ struct snapraid_extent* extent_alloc(block_off_t parity_pos, struct snapraid_fil /** * Deallocate a extent. */ -void extent_free(void* void_extent); +void extent_free(struct snapraid_extent* extent); /** * Compare extent by parity position. @@ -1001,7 +1001,7 @@ struct snapraid_link* link_alloc(const char* name, const char* slink, unsigned l /** * Deallocate a link. */ -void link_free(void* void_link); +void link_free(struct snapraid_link* slink); /** * Compare a link with a name. @@ -1044,7 +1044,7 @@ struct snapraid_dir* dir_alloc(const char* name); /** * Deallocate a dir. */ -void dir_free(void* void_dir); +void dir_free(struct snapraid_dir* dir); /** * Compare a dir with a name. @@ -1067,7 +1067,7 @@ struct snapraid_dealloc* dealloc_alloc(unsigned block_size, const char* sub, dat /** * Deallocate a dealloc. */ -void dealloc_free(void* void_dealloc); +void dealloc_free(struct snapraid_dealloc* dealloc); /** * Import file hash in the dealloc. @@ -1082,7 +1082,7 @@ struct snapraid_disk* disk_alloc(const char* name, const char* dir, uint64_t dev /** * Deallocate a disk. */ -void disk_free(void* void_disk); +void disk_free(struct snapraid_disk* disk); /** * Allocate a extra disk. @@ -1092,7 +1092,7 @@ struct snapraid_extra* extra_alloc(const char* name, const char* dir, uint64_t d /** * Deallocate a other disk. */ -void extra_free(void* void_extra); +void extra_free(struct snapraid_extra* other); /** * Get the size of the disk in blocks. @@ -1219,7 +1219,7 @@ struct snapraid_map* map_alloc(const char* name, unsigned position, block_off_t /** * Deallocate a disk mapping. */ -void map_free(void* void_map); +void map_free(struct snapraid_map* map); /** * Mask used to store additional information in the info bits. @@ -1335,7 +1335,7 @@ struct snapraid_bucket { tommy_node node; }; -void bucket_free(void* void_bucket); +void bucket_free(struct snapraid_bucket* bucket); /** * Insert an bucket record into the hashtable diff --git a/cmdline/import.c b/cmdline/import.c index 40df5f52..a50cfa9c 100644 --- a/cmdline/import.c +++ b/cmdline/import.c @@ -204,10 +204,8 @@ static void import_dealloc(struct snapraid_state* state, const char* dir, struct tommy_list_insert_tail(&state->importlist, &file->nodelist, file); } -void import_file_free(void* void_file) +void import_file_free(struct snapraid_import_file* file) { - struct snapraid_import_file* file = void_file; - free(file->path); free(file->blockimp); free(file); diff --git a/cmdline/import.h b/cmdline/import.h index 8aef9b0d..fcc7f34a 100644 --- a/cmdline/import.h +++ b/cmdline/import.h @@ -44,7 +44,7 @@ struct snapraid_import_file { /** * Deallocate an import file. */ -void import_file_free(void* void_file); +void import_file_free(struct snapraid_import_file* file); /** * Fetch a block from the specified hash. diff --git a/cmdline/pool.c b/cmdline/pool.c index 8e504ce5..d3707d92 100644 --- a/cmdline/pool.c +++ b/cmdline/pool.c @@ -35,10 +35,8 @@ static inline tommy_uint32_t pool_hash(const char* file) return tommy_hash_u32(0, file, strlen(file)); } -static void pool_free(void* void_pool) +void pool_free(struct snapraid_pool* pool) { - struct snapraid_pool* pool = void_pool; - free(pool); } @@ -444,12 +442,12 @@ void state_pool(struct snapraid_state* state) msg_progress("Cleaning...\n"); /* delete all the remaining links */ - tommy_hashdyn_foreach_arg(&poolset, remove_link, pool_dir); + tommy_hashdyn_foreach_arg(&poolset, (tommy_foreach_arg_func*)remove_link, pool_dir); /* delete empty dirs */ clean_dir(pool_dir); - tommy_hashdyn_foreach(&poolset, pool_free); + tommy_hashdyn_foreach(&poolset, (tommy_foreach_func*)pool_free); tommy_hashdyn_done(&poolset); if (count) diff --git a/cmdline/scan.c b/cmdline/scan.c index 998f0c99..2d22d914 100644 --- a/cmdline/scan.c +++ b/cmdline/scan.c @@ -74,9 +74,8 @@ static struct snapraid_scan* scan_alloc(struct snapraid_state* state, struct sna return scan; } -static void scan_free(void* void_scan) +static void scan_free(struct snapraid_scan* scan) { - struct snapraid_scan* scan = void_scan; #if HAVE_THREAD thread_mutex_destroy(&scan->disk->stamp_mutex); #endif @@ -2250,7 +2249,7 @@ static int state_diffscan(struct snapraid_state* state, int is_diff) log_flush(); - tommy_list_foreach(&scanlist, scan_free); + tommy_list_foreach(&scanlist, (tommy_foreach_func*)scan_free); /* check the file-system on all disks */ state_fscheck(state, "after scan"); diff --git a/cmdline/search.c b/cmdline/search.c index 6d614e36..59b01c89 100644 --- a/cmdline/search.c +++ b/cmdline/search.c @@ -25,10 +25,8 @@ static void search_file(struct snapraid_state* state, const char* path, data_off tommy_hashdyn_insert(&state->searchset, &file->node, file, file_hash); } -void search_file_free(void* void_file) +void search_file_free(struct snapraid_search_file* file) { - struct snapraid_search_file* file = void_file; - free(file->path); free(file); } diff --git a/cmdline/search.h b/cmdline/search.h index 55c8fef3..6eb8d62c 100644 --- a/cmdline/search.h +++ b/cmdline/search.h @@ -28,7 +28,7 @@ struct snapraid_search_file { /** * Deallocate a search file. */ -void search_file_free(void* void_file); +void search_file_free(struct snapraid_search_file* file); /** * Fetch a file from the size, timestamp and name. diff --git a/cmdline/snapraid.c b/cmdline/snapraid.c index 7a8c3196..90612556 100644 --- a/cmdline/snapraid.c +++ b/cmdline/snapraid.c @@ -2131,8 +2131,8 @@ int snapraid_main(int argc, char* argv[]) #endif state_done(&state); - tommy_list_foreach(&filterlist_file, filter_free); - tommy_list_foreach(&filterlist_disk, filter_free); + tommy_list_foreach(&filterlist_file, (tommy_foreach_func*)filter_free); + tommy_list_foreach(&filterlist_disk, (tommy_foreach_func*)filter_free); app_done(); os_done(); diff --git a/cmdline/state.c b/cmdline/state.c index 14946845..18cb85ab 100644 --- a/cmdline/state.c +++ b/cmdline/state.c @@ -202,19 +202,19 @@ void state_init(struct snapraid_state* state) void state_done(struct snapraid_state* state) { - tommy_list_foreach(&state->disklist, disk_free); - tommy_list_foreach(&state->extralist, extra_free); - tommy_list_foreach(&state->maplist, map_free); - tommy_list_foreach(&state->contentlist, content_free); - tommy_list_foreach(&state->filterlist, filter_free); - tommy_list_foreach(&state->importlist, import_file_free); - tommy_list_foreach(&state->thermallist, thermal_free); - tommy_hashdyn_foreach(&state->searchset, search_file_free); + tommy_list_foreach(&state->disklist, (tommy_foreach_func*)disk_free); + tommy_list_foreach(&state->extralist, (tommy_foreach_func*)extra_free); + tommy_list_foreach(&state->maplist, (tommy_foreach_func*)map_free); + tommy_list_foreach(&state->contentlist, (tommy_foreach_func*)content_free); + tommy_list_foreach(&state->filterlist, (tommy_foreach_func*)filter_free); + tommy_list_foreach(&state->importlist, (tommy_foreach_func*)import_file_free); + tommy_list_foreach(&state->thermallist, (tommy_foreach_func*)thermal_free); + tommy_hashdyn_foreach(&state->searchset, (tommy_foreach_func*)search_file_free); tommy_hashdyn_done(&state->importset); tommy_hashdyn_done(&state->previmportset); tommy_hashdyn_done(&state->searchset); tommy_arrayblkof_done(&state->infoarr); - tommy_list_foreach(&state->bucketlist, bucket_free); + tommy_list_foreach(&state->bucketlist, (tommy_foreach_func*)bucket_free); } /** @@ -4149,7 +4149,7 @@ static void* state_write_thread(void* arg) return 0; bail: - tommy_hashdyn_foreach(&bucket_hash, bucket_free); + tommy_hashdyn_foreach(&bucket_hash, (tommy_foreach_func*)bucket_free); tommy_hashdyn_done(&bucket_hash); return context; } @@ -5017,7 +5017,7 @@ void state_commit(struct snapraid_state* state) if (!tommy_list_empty(&disk->dealloclist)) { /* clear the dealloc list */ - tommy_list_foreach(&disk->dealloclist, dealloc_free); + tommy_list_foreach(&disk->dealloclist, (tommy_foreach_func*)dealloc_free); tommy_list_init(&disk->dealloclist); /* mark the state as needing write */ diff --git a/cmdline/thermal.c b/cmdline/thermal.c index 36ee1926..53199f01 100644 --- a/cmdline/thermal.c +++ b/cmdline/thermal.c @@ -22,10 +22,8 @@ struct snapraid_thermal* thermal_alloc(uint64_t dev, const char* name) return thermal; } -void thermal_free(void* void_thermal) +void thermal_free(struct snapraid_thermal* thermal) { - struct snapraid_thermal* thermal = void_thermal; - free(thermal); } diff --git a/cmdline/thermal.h b/cmdline/thermal.h index 5e23ddb3..82fe8f61 100644 --- a/cmdline/thermal.h +++ b/cmdline/thermal.h @@ -56,7 +56,7 @@ struct snapraid_thermal* thermal_alloc(uint64_t dev, const char* name); /** * Deallocate a thermal state. */ -void thermal_free(void* void_thermal); +void thermal_free(struct snapraid_thermal* thermal); #endif diff --git a/raid/NOTES b/raid/NOTES index b6fe2330..d01b181c 100644 --- a/raid/NOTES +++ b/raid/NOTES @@ -81,13 +81,8 @@ Recovery: * A recurring RECX local cost is repeated coefficient table/matrix loading or broadcasting inside the data loop. -* Specialized P+Q rec2of2 recovery reduces 4 GF multiplications to 2 GF - multiplications and 1 XOR, implemented across scalar int8 and all SIMD backends. - -* When P is among the selected parity blocks, optimized SIMD RECX paths - reconstruct only nr - 1 missing blocks through the inverse matrix and derive - the final missing block from the raw P delta by XORing the blocks already - reconstructed. +* Specialized SIMD P+Q rec2of2 recovery is a distinct optimization + opportunity. The scalar int8 implementation already has the formula. Architecture and validation: @@ -249,19 +244,19 @@ REC2OF2: * The row uses ip = { 0, 1 }, meaning P and Q. -* Scalar int8 and all SIMD REC2 implementations have a specialized P+Q fast path - and call raid_rec2of2_*(). +* raid_rec2_int8() has an existing specialized P+Q fast path and calls + raid_rec2of2_int8(). -* This makes the row a direct benchmark for the specialized P+Q recovery - implementation. +* SIMD REC2 implementations do not have the equivalent specialized P+Q + fast path. They execute the generic 2x2 recovery algorithm with P and Q. + +* This makes the row useful as a direct benchmark for deciding whether a + specialized SIMD rec2of2 implementation is worthwhile. REC2OF3 and REC2OF4: * The rows use { Q, R } and { R, S } respectively, avoiding the P+Q fast case. -* REC2OF3 and REC2OF4 remain useful control rows because they do not match - ip = { 0, 1 } and therefore continue to exercise the generic REC2 paths. - * They measure generic 2x2 recovery with different selected-parity positions, exposing the difference between exact selected-syndrome fusion and prefix-based delta generation. @@ -695,7 +690,9 @@ REC2 status: * Generic REC2 uses the fused path where available and retains local split reuse in the delta-based paths. -* Scalar int8 and all SIMD backends implement specialized rec2of2 P+Q recovery. +* Scalar int8 already has specialized rec2of2 P+Q recovery. + +* Specialized SIMD rec2of2 P+Q is a possible further optimization. Specialized rec2of2 P+Q @@ -710,19 +707,25 @@ can be reduced to: This needs only two GF multiplications for Dy, followed by one XOR for Dx, instead of the generic 2x2 reconstruction with four GF multiplications. -All backends implement this specialization: +The scalar int8 implementation already uses this specialization. -* Scalar int8 (raid_rec2of2_int8) -* SSSE3 and SSSE3 ext (raid_rec2of2_ssse3, raid_rec2of2_ssse3ext) -* AVX2 and AVX2 ext (raid_rec2of2_avx2, raid_rec2of2_avx2ext) -* AVX512BW (raid_rec2of2_avx512bw) -* AVX2 GFNI and AVX512 GFNI (RAID and AES variants) -* AArch64 NEON and AArch32 NEON (raid_rec2of2_neon, raid_rec2of2_neon32) +SIMD REC2 backends use the generic 2x2 matrix solution even when +ip = { 0, 1 }. -The rec2of2 benchmark row directly measures this specialized P+Q fast path. +Potential targets include: -REC2OF3 and REC2OF4 remain useful control rows because they do not match -ip = { 0, 1 } and therefore continue to exercise the generic REC2 paths. +* SSSE3 +* AVX2 +* AVX512BW +* AVX2 GFNI +* AVX512 GFNI +* NEON + +The rec2of2 benchmark row exists specifically to measure whether these +specializations are worth adding. + +Practical priority remains low because simultaneous loss of two data disks is an +exceptional real-world case. RECX delta handling @@ -743,15 +746,6 @@ For GFNI paths: * the byte syndromes remain directly in SIMD registers * no nibble split is needed -When P is among the selected parity blocks, optimized RECX paths can reconstruct -only nr - 1 missing blocks through the inverse matrix and derive the final block -from the raw P delta by XORing the blocks already reconstructed. This removes -one complete inverse-matrix reconstruction row without adding another -source-data pass. - -On the tested x86 implementations, this improved the affected multi-disk -recovery paths by roughly 8% to 12%, depending on the backend and failure count. - RECX shuffle-table pointer precomputation ---------------------------------------- @@ -888,8 +882,7 @@ Preferred optimizations are basic/local: * exploit coefficient 0 or 1 only when it stays simple and does not add harmful branching or complexity * use limited spatial unrolling only when it exposes ILP without excessive - register pressure; SSSE3ext REC1 was faster with a two-way 32-byte unroll - than with the tested four-way 64-byte version + register pressure Avoid unless new measurements provide a concrete reason: @@ -928,15 +921,6 @@ Inline assembly and portability constraints The SIMD code intentionally uses multiple small or large asm volatile blocks and keeps SIMD state live across them. -raid_selftest() is intended to run at every library startup after the RAID mode -has been selected. It verifies only the currently selected mode, so changing -the mode requires running the self test again before that mode is used. - -Besides checking the RAID algorithms, it verifies the SIMD implementations -actually selected for that mode on the current CPU, compiler, and ABI, -providing runtime protection against implementation or compiler-related -miscompilation. - Important project constraints: * Assembly blocks that dereference pointers internally must model memory effects @@ -952,11 +936,6 @@ Important project constraints: It is not a fully explicit extended-asm dataflow model, so future compiler portability changes should be reviewed carefully. -* This is primarily a compiler and ABI portability consideration rather than a - known correctness issue in the current implementation. raid_selftest() - verifies the selected mode and implementation at startup so that failures - affecting actual RAID results are detected before normal use. - * Do not assume x86-32 has xmm8..xmm15 or ymm8..ymm15. * AArch32 NEON is a separate backend. Do not assume the AArch64 register or ABI diff --git a/raid/OTHERS b/raid/OTHERS index d6adc13c..0c97ea94 100644 --- a/raid/OTHERS +++ b/raid/OTHERS @@ -84,9 +84,7 @@ SnapRAID: A storage-oriented RAID engine specialized for large fixed-size extended Cauchy construction. * Generation and SIMD recovery have parity-count-specific GEN1..GEN6 and - REC1..REC6 entry points, plus RAID-specific fast cases such as rec1of1, - reduced P+Q rec2of2 reconstruction, and deriving the final RECX block from - the P delta when P is available. + REC1..REC6 entry points, plus important fast cases such as rec1of1. * Current optimized backends include x86 SSSE3, AVX2, AVX512BW and GFNI, plus AArch64 and AArch32 NEON. @@ -107,9 +105,8 @@ Linux RAID6: A kernel RAID6 P+Q engine. It is much less general than a * x86 generation contains spatial x1/x2/x4 variants, explicit prefetch, and non-temporal final stores in optimized paths. -* Recovery is specifically designed for one or two failures. Although the - public RAID6 recovery interface accepts an arbitrary byte count, it is - typically used with PAGE_SIZE-sized buffers and optimized for that workload. +* Recovery is specifically designed for one or two failures. The public RAID6 + recovery interface operates on at most PAGE_SIZE at a time. * Architecture coverage is broad: x86, ARM NEON, PowerPC, s390, RISC-V vector, LoongArch SIMD, and generic integer implementations. @@ -243,10 +240,10 @@ SnapRAID: Large storage blocks, normally 256 KiB, and one to six parity levels. source or parity buffers are expensive enough to influence kernel design. -Linux RAID6: Kernel RAID6 with exactly P+Q. Recovery is typically performed on - PAGE_SIZE-sized buffers. The tiny fixed parity count permits - formulas and kernels that would not generalize to many parity - outputs. +Linux RAID6: Kernel RAID6 with exactly P+Q. Generation is a streaming storage + operation, but the recovery interface is page-sized. The tiny + fixed parity count permits formulas and kernels that would not + generalize to many parity outputs. OpenZFS RAIDZ: Filesystem RAID with one to three parity columns, dynamic row geometry and ABD buffers. Cache-blocked processing and repeated @@ -592,8 +589,8 @@ Linux RAID6: Uses formulas specific to the RAID6 failure cases. Two-data * This is an algorithmic specialization made possible by exactly two parity equations. -* The typical PAGE_SIZE recovery workload makes additional passes much less - costly than they would be over a full SnapRAID block. +* The recovery API limit of PAGE_SIZE makes additional passes much less costly + than they would be over a full SnapRAID block. OpenZFS RAIDZ: Dispatches directly among rec_p, rec_q, rec_r, rec_pq, rec_pr, rec_qr and rec_pqr according to missing data count and available diff --git a/raid/README b/raid/README index b475a360..ca8566fe 100644 --- a/raid/README +++ b/raid/README @@ -16,10 +16,7 @@ Public API Header: #include "raid.h" Before invoking any generation or recovery functions, call raid_init() once to -detect CPU capabilities and initialize mode dispatch. Then select the RAID mode -to use, if different from the default, and call raid_selftest(). raid_selftest() -verifies only the currently selected mode and is intended to be run at every -library startup before normal RAID operations. +detect CPU capabilities and initialize mode dispatch. void raid_init(void) Initializes algorithm tables and detects hardware SIMD instruction sets @@ -74,12 +71,7 @@ library startup before normal RAID operations. int raid_selftest(void) Runs startup verification tests for parity generation, recovery, and - scanning across parity levels supported by the currently selected mode. - It is intended to be called at every library startup after the RAID mode - has been selected, to verify the selected implementation on the current - CPU, compiler, and ABI. If the mode is changed later, the self test should - be run again before using the new mode. Returns 0 on success, < 0 on - failure. + scanning across parity levels 1..6. Returns 0 on success, < 0 on failure. Memory, Alignment and Aliasing Requirements @@ -174,11 +166,9 @@ Testing and Benchmarks Standalone test applications located in raid/test/ provide verification and performance evaluation: - raid/test/selftest Quick startup self-test exercising raid_selftest(). - raid/test/fulltest Comprehensive test suite verifying parity generation and - tail recovery for 1..251 data disks, and all multi-disk - failure recovery combinations for up to TEST_COUNT disks - (default 24/32). + raid/test/selftest Quick startup self-test verifying basic correctness. + raid/test/fulltest Exhaustive test suite testing all combinations of data + disks (1..251) and single/multi-disk failure recovery. raid/test/invtest Matrix inversion test verifying non-singularity for all square submatrices of the Cauchy matrix. raid/test/speedtest Benchmark measuring single-thread throughput (MiB/s) diff --git a/raid/avx2.c b/raid/avx2.c index 3354afa0..dfe230ac 100644 --- a/raid/avx2.c +++ b/raid/avx2.c @@ -317,8 +317,7 @@ static __always_inline void raid_gen3_avx2ext_gen(int nd, size_t size, void **vv /* special case with only one data disk */ if (l == 0) { for (i = 0; i < 3; ++i) - if (v[1 + i] != v[0]) - memcpy(v[1 + i], v[0], size); + memcpy(v[1 + i], v[0], size); return; } @@ -575,8 +574,7 @@ static __always_inline void raid_gen4_avx2ext_gen(int nd, size_t size, void **vv /* special case with only one data disk */ if (l == 0) { for (i = 0; i < 4; ++i) - if (v[1 + i] != v[0]) - memcpy(v[1 + i], v[0], size); + memcpy(v[1 + i], v[0], size); return; } @@ -738,8 +736,7 @@ static __always_inline void raid_genX_avx2ext(int nd, size_t size, void **vv, in /* special case with only one data disk */ if (l == 0) { for (d = 0; d < np; ++d) - if (v[1 + d] != v[0]) - memcpy(v[1 + d], v[0], size); + memcpy(v[1 + d], v[0], size); return; } @@ -885,7 +882,7 @@ static __always_inline void raid_genX_avx2ext(int nd, size_t size, void **vv, in /* * RAID recovering for one disk AVX2 implementation */ -static __always_inline void raid_rec1_avx2_delta(int *id, int *ip, int nd, size_t size, void **vv) +static __always_inline void raid_rec1_avx2_delta(int nr, int *id, int *ip, int nd, size_t size, void **vv) { uint8_t **v = (uint8_t **)vv; uint8_t *p; @@ -894,6 +891,8 @@ static __always_inline void raid_rec1_avx2_delta(int *id, int *ip, int nd, size_ uint8_t V; size_t i; + (void)nr; /* unused, it's always 1 */ + /* setup the coefficients matrix */ G = A(ip[0], id[0]); @@ -947,28 +946,31 @@ static __always_inline void raid_rec1_avx2_delta(int *id, int *ip, int nd, size_ /* * RAID recovering for two disks AVX2 implementation */ -static __always_inline void raid_rec2_avx2_delta(int *id, int *ip, int nd, size_t size, void **vv) +static __always_inline void raid_rec2_avx2_delta(int nr, int *id, int *ip, int nd, size_t size, void **vv) { uint8_t **v = (uint8_t **)vv; - uint8_t *p[2]; - uint8_t *pa[2]; - uint8_t G[2 * 2]; - uint8_t V[2 * 2]; + const int N = 2; + uint8_t *p[N]; + uint8_t *pa[N]; + uint8_t G[N * N]; + uint8_t V[N * N]; size_t i; int j, k; + (void)nr; /* unused, it's always 2 */ + /* setup the coefficients matrix */ - for (j = 0; j < 2; ++j) - for (k = 0; k < 2; ++k) - G[j * 2 + k] = A(ip[j], id[k]); + for (j = 0; j < N; ++j) + for (k = 0; k < N; ++k) + G[j * N + k] = A(ip[j], id[k]); /* invert it to solve the system of linear equations */ - raid_invert(G, V, 2); + raid_invert(G, V, N); /* compute delta parity */ - raid_delta_gen(2, id, ip, nd, size, vv); + raid_delta_gen(N, id, ip, nd, size, vv); - for (j = 0; j < 2; ++j) { + for (j = 0; j < N; ++j) { p[j] = v[nd + ip[j]]; pa[j] = v[id[j]]; } @@ -1037,88 +1039,11 @@ static __always_inline void raid_rec2_avx2_delta(int *id, int *ip, int nd, size_ raid_avx_end(); } -/* - * Recover failure of two data blocks using P and Q AVX2 implementation. - */ -static __always_inline void raid_rec2of2_avx2(int *id, int *ip, int nd, size_t size, void **vv) -{ - uint8_t **v = (uint8_t **)vv; - uint8_t *p; - uint8_t *pa; - uint8_t *q; - uint8_t *qa; - uint8_t C[2]; - size_t i; - - /* get multiplication coefficients */ - C[0] = inv(powgen(id[1] - id[0]) ^ 1); - C[1] = inv(powgen(id[0]) ^ powgen(id[1])); - - /* compute delta parity */ - raid_delta_gen(2, id, ip, nd, size, vv); - - p = v[nd]; - q = v[nd + 1]; - pa = v[id[0]]; - qa = v[id[1]]; - - raid_avx_begin(); - - asm volatile ("vpbroadcastb %0,%%ymm7" : : "m" (gfconst16.low4[0])); - - for (i = 0; i < size; i += 32) { - /* Pd */ - asm volatile ("vmovdqa %0,%%ymm0" : : "m" (p[i])); - asm volatile ("vpxor %0,%%ymm0,%%ymm0" : : "m" (pa[i])); - - /* Qd */ - asm volatile ("vmovdqa %0,%%ymm1" : : "m" (q[i])); - asm volatile ("vpxor %0,%%ymm1,%%ymm1" : : "m" (qa[i])); - - /* split Pd and Qd */ - asm volatile ("vpsrlw $4,%ymm0,%ymm2"); - asm volatile ("vpsrlw $4,%ymm1,%ymm3"); - asm volatile ("vpand %ymm7,%ymm0,%ymm4"); - asm volatile ("vpand %ymm7,%ymm1,%ymm5"); - asm volatile ("vpand %ymm7,%ymm2,%ymm2"); - asm volatile ("vpand %ymm7,%ymm3,%ymm3"); - - /* C0 * Pd */ - asm volatile ("vbroadcasti128 %0,%%ymm6" : : "m" (raid_gfmulpshufb[C[0]][0][0])); - asm volatile ("vpshufb %ymm4,%ymm6,%ymm6"); - - asm volatile ("vbroadcasti128 %0,%%ymm4" : : "m" (raid_gfmulpshufb[C[0]][1][0])); - asm volatile ("vpshufb %ymm2,%ymm4,%ymm4"); - asm volatile ("vpxor %ymm4,%ymm6,%ymm6"); - - /* C1 * Qd */ - asm volatile ("vbroadcasti128 %0,%%ymm4" : : "m" (raid_gfmulpshufb[C[1]][0][0])); - asm volatile ("vpshufb %ymm5,%ymm4,%ymm4"); - asm volatile ("vpxor %ymm4,%ymm6,%ymm6"); - - asm volatile ("vbroadcasti128 %0,%%ymm4" : : "m" (raid_gfmulpshufb[C[1]][1][0])); - asm volatile ("vpshufb %ymm3,%ymm4,%ymm4"); - asm volatile ("vpxor %ymm4,%ymm6,%ymm6"); - - /* Dy = ymm6, Dx = Pd ^ Dy */ - asm volatile ("vpxor %ymm6,%ymm0,%ymm0"); - - asm volatile ("vmovdqa %%ymm0,%0" : "=m" (pa[i])); - asm volatile ("vmovdqa %%ymm6,%0" : "=m" (qa[i])); - } - - raid_avx_end(); -} - /* * RAID recovering AVX2 implementation optimized for up to four failures. * * Compute all selected syndromes in one scan of the surviving data, then * retain only their low/high nibbles while reconstructing the missing data. - * - * If P is available, keep the complete P delta syndrome in ymm6. - * Reconstruct only nr - 1 missing blocks through the inverse matrix and - * obtain the last block by XORing the reconstructed blocks out of Pdelta. */ static __always_inline void raid_recX_avx2_1234(int nr, int *id, int *ip, int nd, size_t size, void **vv) { @@ -1177,7 +1102,7 @@ static __always_inline void raid_recX_avx2_1234(int nr, int *id, int *ip, int nd BUG_ON(ns != nd - nr); /* precompute inverse-matrix multiplication table pointers */ - for (j = 0; j < nr - has_p; ++j) + for (j = 0; j < nr; ++j) for (k = 0; k < nr; ++k) R[j][k] = &raid_gfmulpshufb[V[j * nr + k]][0][0]; @@ -1247,11 +1172,7 @@ static __always_inline void raid_recX_avx2_1234(int nr, int *id, int *ip, int nd } } - /* preserve the complete P delta before splitting syndrome 0 */ - if (has_p) - asm volatile ("vmovdqa %ymm0,%ymm6"); - - /* preserve only aligned low/high nibbles */ + /* preserve only aligned low/high nibbles, never full delta blocks */ asm volatile ("vpsrlw $4,%ymm0,%ymm4"); asm volatile ("vpand %ymm7,%ymm0,%ymm0"); asm volatile ("vpand %ymm7,%ymm4,%ymm4"); @@ -1282,8 +1203,8 @@ static __always_inline void raid_recX_avx2_1234(int nr, int *id, int *ip, int nd asm volatile ("vmovdqa %%ymm4,%0" : "=m" (pd_high[96])); } - /* reconstruct all but the last missing block when P is available */ - for (j = 0; j < nr - has_p; ++j) { + /* reconstruct every missing block, initializing from coefficient zero */ + for (j = 0; j < nr; ++j) { const uint8_t **t = R[j]; asm volatile ("vbroadcasti128 %0,%%ymm0" : : "m" (t[0][0])); @@ -1305,15 +1226,8 @@ static __always_inline void raid_recX_avx2_1234(int nr, int *id, int *ip, int nd } asm volatile ("vpxor %ymm1,%ymm0,%ymm0"); - - if (has_p) - asm volatile ("vpxor %ymm0,%ymm6,%ymm6"); - asm volatile ("vmovdqa %%ymm0,%0" : "=m" (pa[j][i])); } - - if (has_p) - asm volatile ("vmovdqa %%ymm6,%0" : "=m" (pa[nr - 1][i])); } raid_avx_end(); @@ -1324,10 +1238,6 @@ static __always_inline void raid_recX_avx2_1234(int nr, int *id, int *ip, int nd * * Compute all selected syndromes in a single pass over the surviving data. * Syndrome accumulators are kept in memory to minimize register pressure. - * - * If P is available, keep the complete P delta syndrome in ymm6. - * Reconstruct only nr - 1 missing blocks through the inverse matrix and - * obtain the last block by XORing the reconstructed blocks out of Pdelta. */ static __always_inline void raid_recX_avx2(int nr, int *id, int *ip, int nd, size_t size, void **vv) { @@ -1389,7 +1299,7 @@ static __always_inline void raid_recX_avx2(int nr, int *id, int *ip, int nd, siz BUG_ON(ns != nd - nr); /* precompute inverse-matrix multiplication table pointers */ - for (j = 0; j < nr - has_p; ++j) + for (j = 0; j < nr; ++j) for (k = 0; k < nr; ++k) R[j][k] = &raid_gfmulpshufb[V[j * nr + k]][0][0]; @@ -1464,13 +1374,6 @@ static __always_inline void raid_recX_avx2(int nr, int *id, int *ip, int nd, siz } } - /* - * Preserve the complete P delta before pd_low[0] is - * destructively converted to low/high nibble form. - */ - if (has_p) - asm volatile ("vmovdqa %0,%%ymm6" : : "m" (pd_low[0])); - /* * All survivor reads for this chunk are now complete. * @@ -1487,8 +1390,7 @@ static __always_inline void raid_recX_avx2(int nr, int *id, int *ip, int nd, siz } /* - * Reconstruct all but the last missing block when P is - * available. + * Reconstruct each missing block. * * Keep independent low/high accumulation chains: * @@ -1498,9 +1400,8 @@ static __always_inline void raid_recX_avx2(int nr, int *id, int *ip, int nd, siz * ymm3 = high table/result * ymm4 = syndrome low * ymm5 = syndrome high - * ymm6 = remaining P delta */ - for (j = 0; j < nr - has_p; ++j) { + for (j = 0; j < nr; ++j) { const uint8_t **t = R[j]; /* coefficient 0 initializes the accumulators */ @@ -1528,15 +1429,8 @@ static __always_inline void raid_recX_avx2(int nr, int *id, int *ip, int nd, siz } asm volatile ("vpxor %ymm1,%ymm0,%ymm0"); - - if (has_p) - asm volatile ("vpxor %ymm0,%ymm6,%ymm6"); - asm volatile ("vmovdqa %%ymm0,%0" : "=m" (pa[j][i])); } - - if (has_p) - asm volatile ("vmovdqa %%ymm6,%0" : "=m" (pa[nr - 1][i])); } raid_avx_end(); @@ -1544,72 +1438,100 @@ static __always_inline void raid_recX_avx2(int nr, int *id, int *ip, int nd, siz #ifdef CONFIG_X86_64 /* - * RAID recovering for two disks with P and Q AVX2 implementation + * RAID recovering for two disks AVX2 extended implementation */ -static __always_inline void raid_rec2of2_avx2ext(int *id, int *ip, int nd, size_t size, void **vv) +static __always_inline void raid_rec2_avx2ext_delta(int nr, int *id, int *ip, int nd, size_t size, void **vv) { uint8_t **v = (uint8_t **)vv; - uint8_t *p[2]; - uint8_t *pa[2]; - uint8_t C[2]; + const int N = 2; + uint8_t *p[N]; + uint8_t *pa[N]; + uint8_t G[N * N]; + uint8_t V[N * N]; size_t i; + int j, k; - /* get multiplication coefficients */ - C[0] = inv(powgen(id[1] - id[0]) ^ 1); - C[1] = inv(powgen(id[0]) ^ powgen(id[1])); + (void)nr; /* unused, it's always 2 */ + + /* setup the coefficients matrix */ + for (j = 0; j < N; ++j) + for (k = 0; k < N; ++k) + G[j * N + k] = A(ip[j], id[k]); + + /* invert it to solve the system of linear equations */ + raid_invert(G, V, N); /* compute delta parity */ - raid_delta_gen(2, id, ip, nd, size, vv); + raid_delta_gen(N, id, ip, nd, size, vv); - p[0] = v[nd]; - p[1] = v[nd + 1]; - pa[0] = v[id[0]]; - pa[1] = v[id[1]]; + for (j = 0; j < N; ++j) { + p[j] = v[nd + ip[j]]; + pa[j] = v[id[j]]; + } raid_avx_begin(); - asm volatile ("vpbroadcastb %0,%%ymm7" : : "m" (gfconst16.low4[0])); + asm volatile ("vpbroadcastb %0,%%ymm6" : : "m" (gfconst16.low4[0])); - /* the multiplication tables are constant for the whole recovery */ - asm volatile ("vbroadcasti128 %0,%%ymm8" : : "m" (raid_gfmulpshufb[C[0]][0][0])); - asm volatile ("vbroadcasti128 %0,%%ymm9" : : "m" (raid_gfmulpshufb[C[0]][1][0])); - asm volatile ("vbroadcasti128 %0,%%ymm10" : : "m" (raid_gfmulpshufb[C[1]][0][0])); - asm volatile ("vbroadcasti128 %0,%%ymm11" : : "m" (raid_gfmulpshufb[C[1]][1][0])); + /* the inverse matrix V[] is constant for the whole recovery */ + asm volatile ("vbroadcasti128 %0,%%ymm8" : : "m" (raid_gfmulpshufb[V[0]][0][0])); + asm volatile ("vbroadcasti128 %0,%%ymm9" : : "m" (raid_gfmulpshufb[V[0]][1][0])); + asm volatile ("vbroadcasti128 %0,%%ymm10" : : "m" (raid_gfmulpshufb[V[1]][0][0])); + asm volatile ("vbroadcasti128 %0,%%ymm11" : : "m" (raid_gfmulpshufb[V[1]][1][0])); + asm volatile ("vbroadcasti128 %0,%%ymm12" : : "m" (raid_gfmulpshufb[V[2]][0][0])); + asm volatile ("vbroadcasti128 %0,%%ymm13" : : "m" (raid_gfmulpshufb[V[2]][1][0])); + asm volatile ("vbroadcasti128 %0,%%ymm14" : : "m" (raid_gfmulpshufb[V[3]][0][0])); + asm volatile ("vbroadcasti128 %0,%%ymm15" : : "m" (raid_gfmulpshufb[V[3]][1][0])); for (i = 0; i < size; i += 32) { /* d0 = p[0] ^ pa[0] */ asm volatile ("vmovdqa %0,%%ymm0" : : "m" (p[0][i])); - asm volatile ("vmovdqa %0,%%ymm2" : : "m" (pa[0][i])); - asm volatile ("vpxor %ymm2,%ymm0,%ymm0"); + asm volatile ("vmovdqa %0,%%ymm4" : : "m" (pa[0][i])); + asm volatile ("vpxor %ymm4,%ymm0,%ymm0"); /* d1 = p[1] ^ pa[1] */ asm volatile ("vmovdqa %0,%%ymm1" : : "m" (p[1][i])); - asm volatile ("vmovdqa %0,%%ymm3" : : "m" (pa[1][i])); - asm volatile ("vpxor %ymm3,%ymm1,%ymm1"); + asm volatile ("vmovdqa %0,%%ymm4" : : "m" (pa[1][i])); + asm volatile ("vpxor %ymm4,%ymm1,%ymm1"); - /* C[0] * d0 */ - asm volatile ("vpsrlw $4,%ymm0,%ymm5"); - asm volatile ("vpand %ymm7,%ymm0,%ymm4"); - asm volatile ("vpand %ymm7,%ymm5,%ymm5"); - asm volatile ("vpshufb %ymm4,%ymm8,%ymm2"); - asm volatile ("vpshufb %ymm5,%ymm9,%ymm3"); - asm volatile ("vpxor %ymm3,%ymm2,%ymm6"); + /* + * Split both deltas into low/high nibbles once. + * + * ymm0 = d0 low + * ymm2 = d0 high + * ymm1 = d1 low + * ymm3 = d1 high + */ + asm volatile ("vpsrlw $4,%ymm0,%ymm2"); + asm volatile ("vpsrlw $4,%ymm1,%ymm3"); + asm volatile ("vpand %ymm6,%ymm0,%ymm0"); + asm volatile ("vpand %ymm6,%ymm2,%ymm2"); + asm volatile ("vpand %ymm6,%ymm1,%ymm1"); + asm volatile ("vpand %ymm6,%ymm3,%ymm3"); - /* C[1] * d1 */ - asm volatile ("vpsrlw $4,%ymm1,%ymm5"); - asm volatile ("vpand %ymm7,%ymm1,%ymm4"); - asm volatile ("vpand %ymm7,%ymm5,%ymm5"); - asm volatile ("vpshufb %ymm4,%ymm10,%ymm2"); - asm volatile ("vpshufb %ymm5,%ymm11,%ymm3"); - asm volatile ("vpxor %ymm2,%ymm6,%ymm6"); - asm volatile ("vpxor %ymm3,%ymm6,%ymm6"); + /* pa[0] = V[0] * d0 ^ V[1] * d1 */ + asm volatile ("vpshufb %ymm0,%ymm8,%ymm4"); + asm volatile ("vpshufb %ymm2,%ymm9,%ymm5"); + asm volatile ("vpxor %ymm5,%ymm4,%ymm4"); - /* pa[1] = C[0] * d0 ^ C[1] * d1 */ - asm volatile ("vmovdqa %%ymm6,%0" : "=m" (pa[1][i])); + asm volatile ("vpshufb %ymm1,%ymm10,%ymm5"); + asm volatile ("vpxor %ymm5,%ymm4,%ymm4"); + asm volatile ("vpshufb %ymm3,%ymm11,%ymm5"); + asm volatile ("vpxor %ymm5,%ymm4,%ymm4"); - /* pa[0] = d0 ^ pa[1] */ - asm volatile ("vpxor %ymm6,%ymm0,%ymm0"); - asm volatile ("vmovdqa %%ymm0,%0" : "=m" (pa[0][i])); + asm volatile ("vmovdqa %%ymm4,%0" : "=m" (pa[0][i])); + + /* pa[1] = V[2] * d0 ^ V[3] * d1 */ + asm volatile ("vpshufb %ymm0,%ymm12,%ymm4"); + asm volatile ("vpshufb %ymm2,%ymm13,%ymm5"); + asm volatile ("vpxor %ymm5,%ymm4,%ymm4"); + + asm volatile ("vpshufb %ymm1,%ymm14,%ymm5"); + asm volatile ("vpxor %ymm5,%ymm4,%ymm4"); + asm volatile ("vpshufb %ymm3,%ymm15,%ymm5"); + asm volatile ("vpxor %ymm5,%ymm4,%ymm4"); + + asm volatile ("vmovdqa %%ymm4,%0" : "=m" (pa[1][i])); } raid_avx_end(); @@ -1919,16 +1841,11 @@ static __always_inline void raid_recX_avx2ext_123(int nr, int *id, int *ip, int } /* - * RAID recovering AVX2 extended implementation. + * RAID recovering AVX2 implementation. * * Compute only the selected syndromes, keeping them in registers. * This avoids raid_delta_gen(), temporary syndrome buffers, and the * generation of unused parity rows. - * - * If P is available, preserve the complete P delta syndrome and - * reconstruct only nr - 1 missing blocks through the inverse matrix. - * The last missing block is obtained by XORing the reconstructed blocks - * out of Pdelta. */ static __always_inline void raid_recX_avx2ext(int nr, int *id, int *ip, int nd, size_t size, void **vv) { @@ -1945,8 +1862,6 @@ static __always_inline void raid_recX_avx2ext(int nr, int *id, int *ip, int nd, int ns; int has_p; - BUG_ON(nr < 1 || nr > RAID_PARITY_MAX); - /* setup the coefficients matrix */ for (j = 0; j < nr; ++j) for (k = 0; k < nr; ++k) @@ -1985,18 +1900,16 @@ static __always_inline void raid_recX_avx2ext(int nr, int *id, int *ip, int nd, BUG_ON(k != nr); BUG_ON(ns != nd - nr); - /* - * If P is available, the last inverse-matrix row is not needed. - * The corresponding missing block is reconstructed by XOR. - */ - for (j = 0; j < nr - has_p; ++j) + /* precompute inverse-matrix multiplication table pointers */ + for (j = 0; j < nr; ++j) for (k = 0; k < nr; ++k) R[j][k] = &raid_gfmulpshufb[V[j * nr + k]][0][0]; raid_avx_begin(); + asm volatile ("vpbroadcastb %0,%%ymm15" : : "m" (gfconst16.low4[0])); + for (i = 0; i < size; i += 32) { - asm volatile ("vpbroadcastb %0,%%ymm15" : : "m" (gfconst16.low4[0])); /* * Start each syndrome with the corresponding stored parity. * @@ -2110,16 +2023,6 @@ static __always_inline void raid_recX_avx2ext(int nr, int *id, int *ip, int nd, } } - /* - * Preserve the complete P delta before splitting syndrome 0. - * - * ymm14 is no longer needed by syndrome generation and is not - * used by the split. After the split, Pdelta is moved to ymm15, - * freeing ymm14 again for reconstruction. - */ - if (has_p) - asm volatile ("vmovdqa %ymm0,%ymm14"); - /* * Split every completed syndrome once. * @@ -2166,30 +2069,8 @@ static __always_inline void raid_recX_avx2ext(int nr, int *id, int *ip, int nd, asm volatile ("vpand %ymm15,%ymm11,%ymm11"); } - /* - * The nibble mask is no longer needed. - * - * Move the complete P delta from the temporary register to - * ymm15, which remains the P accumulator for reconstruction. - * ymm14 is now free again as the multiplication temporary. - */ - if (has_p) - asm volatile ("vmovdqa %ymm14,%ymm15"); - - /* - * Reconstruct the missing data blocks. - * - * If P is available, only nr - 1 outputs are reconstructed - * through the inverse matrix. Each reconstructed output is - * XORed out of ymm15. The remaining value is the final - * missing block. - * - * ymm12 = low accumulator - * ymm13 = high accumulator - * ymm14 = multiplication table / result - * ymm15 = remaining Pdelta, if has_p - */ - for (j = 0; j < nr - has_p; ++j) { + /* reconstruct every missing data block */ + for (j = 0; j < nr; ++j) { const uint8_t **t = R[j]; /* first coefficient initializes the low/high accumulators */ @@ -2238,25 +2119,20 @@ static __always_inline void raid_recX_avx2ext(int nr, int *id, int *ip, int nd, asm volatile ("vbroadcasti128 %0,%%ymm14" : : "m" (t[5][0])); asm volatile ("vpshufb %ymm10,%ymm14,%ymm14"); asm volatile ("vpxor %ymm14,%ymm12,%ymm12"); + asm volatile ("vbroadcasti128 %0,%%ymm14" : : "m" (t[5][16])); asm volatile ("vpshufb %ymm11,%ymm14,%ymm14"); asm volatile ("vpxor %ymm14,%ymm13,%ymm13"); } asm volatile ("vpxor %ymm13,%ymm12,%ymm12"); - - if (has_p) - asm volatile ("vpxor %ymm12,%ymm15,%ymm15"); - asm volatile ("vmovdqa %%ymm12,%0" : "=m" (pa[j][i])); } - - if (has_p) - asm volatile ("vmovdqa %%ymm15,%0" : "=m" (pa[nr - 1][i])); } raid_avx_end(); } + #endif void raid_gen2_avx2_raid(int nd, size_t size, void **vv) @@ -2342,20 +2218,13 @@ void raid_rec1_avx2(int nr, int *id, int *ip, int nd, size_t size, void **vv) return; } - raid_rec1_avx2_delta(id, ip, nd, size, vv); + raid_rec1_avx2_delta(1, id, ip, nd, size, vv); } void raid_rec2_avx2(int nr, int *id, int *ip, int nd, size_t size, void **vv) { BUG_ON(nr != 2); - - /* if recovering with P,Q use the specialized function */ - if (ip[0] == 0 && ip[1] == 1) { - raid_rec2of2_avx2(id, ip, nd, size, vv); - return; - } - - raid_rec2_avx2_delta(id, ip, nd, size, vv); + raid_rec2_avx2_delta(2, id, ip, nd, size, vv); } void raid_rec3_avx2(int nr, int *id, int *ip, int nd, size_t size, void **vv) @@ -2395,7 +2264,7 @@ void raid_rec1_avx2ext(int nr, int *id, int *ip, int nd, size_t size, void **vv) /* if recovering with Q uses the delta function */ if (ip[0] == 1) { - raid_rec1_avx2_delta(id, ip, nd, size, vv); + raid_rec1_avx2_delta(1, id, ip, nd, size, vv); return; } @@ -2408,7 +2277,7 @@ void raid_rec2_avx2ext(int nr, int *id, int *ip, int nd, size_t size, void **vv) /* if recovering with P,Q uses the delta function */ if (ip[0] == 0 && ip[1] == 1) { - raid_rec2of2_avx2ext(id, ip, nd, size, vv); + raid_rec2_avx2ext_delta(2, id, ip, nd, size, vv); return; } diff --git a/raid/avx512.c b/raid/avx512.c index d23f67d6..621a34bb 100644 --- a/raid/avx512.c +++ b/raid/avx512.c @@ -57,10 +57,8 @@ void raid_gen2_avx512bw(int nd, size_t size, void **vv) int d; if (nd == 1) { - if (v[1] != v[0]) - memcpy(v[1], v[0], size); - if (v[2] != v[0]) - memcpy(v[2], v[0], size); + memcpy(v[1], v[0], size); + memcpy(v[2], v[0], size); return; } @@ -283,12 +281,9 @@ void raid_gen3_avx512bw(int nd, size_t size, void **vv) int d; if (nd == 1) { - if (v[1] != v[0]) - memcpy(v[1], v[0], size); - if (v[2] != v[0]) - memcpy(v[2], v[0], size); - if (v[3] != v[0]) - memcpy(v[3], v[0], size); + memcpy(v[1], v[0], size); + memcpy(v[2], v[0], size); + memcpy(v[3], v[0], size); return; } @@ -455,8 +450,7 @@ static __always_inline void raid_genX_avx512bw(int nd, size_t size, void **vv, i if (nd == 1) { for (d = 0; d < np; ++d) - if (v[1 + d] != v[0]) - memcpy(v[1 + d], v[0], size); + memcpy(v[1 + d], v[0], size); return; } @@ -550,10 +544,10 @@ static __always_inline void raid_genX_avx512bw(int nd, size_t size, void **vv, i } /* - * Recover multiple data failures using selected parity blocks with AVX512BW. + * RAID recovering AVX512BW implementation. * - * Compute only the selected syndromes, keeping them in registers. - * This avoids raid_delta_gen(), temporary syndrome buffers, recomputation of + * Compute only the selected syndromes directly from the stored parity + * and surviving data. This avoids raid_delta_gen(), temporary delta * parity blocks, and generation of unused parity rows. * * AVX512 provides enough registers to keep all six supported syndromes @@ -617,11 +611,8 @@ static __always_inline void raid_recX_avx512bw(int nr, int *id, int *ip, int nd, BUG_ON(k != nr); BUG_ON(ns != nd - nr); - /* - * If P is available, the last missing block is reconstructed - * directly from Pdelta, so the last inverse row isn't needed. - */ - for (j = 0; j < nr - has_p; ++j) + /* precompute inverse-matrix multiplication table pointers */ + for (j = 0; j < nr; ++j) for (k = 0; k < nr; ++k) R[j][k] = &raid_gfmulpshufb[V[j * nr + k]][0][0]; @@ -641,7 +632,6 @@ static __always_inline void raid_recX_avx512bw(int nr, int *id, int *ip, int nd, * zmm13 source high nibble * zmm14 low multiplication table / result * zmm15 high multiplication table / result - * zmm30 remaining P delta, if has_p * zmm31 low-nibble mask * * After syndrome splitting: @@ -750,13 +740,6 @@ static __always_inline void raid_recX_avx512bw(int nr, int *id, int *ip, int nd, } } - /* - * Preserve the complete P delta before syndrome 0 is - * destructively split into low/high nibbles. - */ - if (has_p) - asm volatile ("vmovdqa64 %zmm0,%zmm30"); - /* split every completed syndrome once into low/high nibbles */ asm volatile ("vpsrlw $4,%zmm0,%zmm1"); asm volatile ("vpandq %zmm31,%zmm0,%zmm0"); @@ -793,11 +776,7 @@ static __always_inline void raid_recX_avx512bw(int nr, int *id, int *ip, int nd, } /* - * Reconstruct the missing data blocks. - * - * If P is available, reconstruct only nr - 1 blocks through - * the inverse matrix. XOR each result out of zmm30, leaving - * the final missing block in zmm30. + * Reconstruct every missing data block. * * Keep independent low/high dependency chains: * @@ -805,12 +784,11 @@ static __always_inline void raid_recX_avx512bw(int nr, int *id, int *ip, int nd, * zmm13 high accumulator * zmm14 low multiplication table/result * zmm15 high multiplication table/result - * zmm30 remaining P delta, if has_p * * This is intentional. Do not serialize low/high products * through a single temporary register. */ - for (j = 0; j < nr - has_p; ++j) { + for (j = 0; j < nr; ++j) { const uint8_t **t = R[j]; /* coefficient 0 initializes both accumulators */ @@ -864,22 +842,9 @@ static __always_inline void raid_recX_avx512bw(int nr, int *id, int *ip, int nd, asm volatile ("vpxorq %zmm15,%zmm13,%zmm13"); } - /* combine low/high products into the reconstructed block */ asm volatile ("vpxorq %zmm13,%zmm12,%zmm12"); - - /* - * Remove the reconstructed block from Pdelta. - * After nr - 1 iterations zmm30 contains the final - * missing data block. - */ - if (has_p) - asm volatile ("vpxorq %zmm12,%zmm30,%zmm30"); - asm volatile ("vmovdqa64 %%zmm12,%0" : "=m" (pa[j][i])); } - - if (has_p) - asm volatile ("vmovdqa64 %%zmm30,%0" : "=m" (pa[nr - 1][i])); } raid_avx_end(); @@ -922,89 +887,9 @@ void raid_rec1_avx512bw(int nr, int *id, int *ip, int nd, size_t size, void **vv raid_recX_avx512bw(1, id, ip, nd, size, vv); } -/* - * Recover failure of two data blocks using P and Q AVX512BW implementation. - */ -static __always_inline void raid_rec2of2_avx512bw(int *id, int *ip, int nd, size_t size, void **vv) -{ - uint8_t **v = (uint8_t **)vv; - uint8_t *p; - uint8_t *pa; - uint8_t *q; - uint8_t *qa; - uint8_t C[2]; - size_t i; - - /* get multiplication coefficients */ - C[0] = inv(powgen(id[1] - id[0]) ^ 1); - C[1] = inv(powgen(id[0]) ^ powgen(id[1])); - - /* compute delta parity */ - raid_delta_gen(2, id, ip, nd, size, vv); - - p = v[nd]; - q = v[nd + 1]; - pa = v[id[0]]; - qa = v[id[1]]; - - raid_avx_begin(); - - asm volatile ("vpbroadcastb %0,%%zmm31" : : "m" (gfconst16.low4[0])); - - /* keep both multiplication-table pairs resident */ - asm volatile ("vbroadcasti32x4 %0,%%zmm16" : : "m" (raid_gfmulpshufb[C[0]][0][0])); - asm volatile ("vbroadcasti32x4 %0,%%zmm17" : : "m" (raid_gfmulpshufb[C[0]][1][0])); - asm volatile ("vbroadcasti32x4 %0,%%zmm18" : : "m" (raid_gfmulpshufb[C[1]][0][0])); - asm volatile ("vbroadcasti32x4 %0,%%zmm19" : : "m" (raid_gfmulpshufb[C[1]][1][0])); - - for (i = 0; i < size; i += 64) { - /* Pd */ - asm volatile ("vmovdqa64 %0,%%zmm0" : : "m" (p[i])); - asm volatile ("vpxord %0,%%zmm0,%%zmm0" : : "m" (pa[i])); - - /* Qd */ - asm volatile ("vmovdqa64 %0,%%zmm1" : : "m" (q[i])); - asm volatile ("vpxord %0,%%zmm1,%%zmm1" : : "m" (qa[i])); - - /* split Pd and Qd */ - asm volatile ("vpsrlw $4,%zmm0,%zmm2"); - asm volatile ("vpsrlw $4,%zmm1,%zmm3"); - asm volatile ("vpandq %zmm31,%zmm0,%zmm4"); - asm volatile ("vpandq %zmm31,%zmm1,%zmm5"); - asm volatile ("vpandq %zmm31,%zmm2,%zmm2"); - asm volatile ("vpandq %zmm31,%zmm3,%zmm3"); - - /* C0 * Pd */ - asm volatile ("vpshufb %zmm4,%zmm16,%zmm6"); - asm volatile ("vpshufb %zmm2,%zmm17,%zmm7"); - asm volatile ("vpxord %zmm7,%zmm6,%zmm6"); - - /* C1 * Qd */ - asm volatile ("vpshufb %zmm5,%zmm18,%zmm7"); - asm volatile ("vpxord %zmm7,%zmm6,%zmm6"); - asm volatile ("vpshufb %zmm3,%zmm19,%zmm7"); - asm volatile ("vpxord %zmm7,%zmm6,%zmm6"); - - /* Dy = zmm6, Dx = Pd ^ Dy */ - asm volatile ("vpxord %zmm6,%zmm0,%zmm0"); - - asm volatile ("vmovdqa64 %%zmm0,%0" : "=m" (pa[i])); - asm volatile ("vmovdqa64 %%zmm6,%0" : "=m" (qa[i])); - } - - raid_avx_end(); -} - void raid_rec2_avx512bw(int nr, int *id, int *ip, int nd, size_t size, void **vv) { BUG_ON(nr != 2); - - /* if recovering with P,Q use the specialized function */ - if (ip[0] == 0 && ip[1] == 1) { - raid_rec2of2_avx512bw(id, ip, nd, size, vv); - return; - } - raid_recX_avx512bw(2, id, ip, nd, size, vv); } diff --git a/raid/check.c b/raid/check.c index 89c03c91..fd519f82 100644 --- a/raid/check.c +++ b/raid/check.c @@ -138,9 +138,6 @@ int raid_check(int nr, int *ir, int nd, int np, size_t size, void **v) BUG_ON(nr > 0 && ir[0] < 0); BUG_ON(nr > 0 && ir[nr - 1] >= nd + np); - if (size == 0) - return -1; - /* count failed data disk */ rd = 0; while (rd < nr && ir[rd] < nd) @@ -181,9 +178,6 @@ int raid_scan(int *ir, int nd, int np, size_t size, void **v) BUG_ON(v == 0); BUG_ON(np > 1 && ir == 0); - if (size == 0) - return -1; - /* check the special case of no failure */ if (np != 0 && raid_check(0, 0, nd, np, size, v) == 0) return 0; diff --git a/raid/cpu.h b/raid/cpu.h index d49c6673..7dd19d68 100644 --- a/raid/cpu.h +++ b/raid/cpu.h @@ -91,11 +91,6 @@ static inline int raid_cpu_match_avx(uint32_t leaf_1_ecx, uint32_t leaf_7_ebx, u { uint32_t reg[4]; - /* check that leaf 7 is supported */ - raid_cpuid(0, 0, reg); - if (reg[0] < 7) - return 0; - raid_cpuid(1, 0, reg); if ((reg[2] & leaf_1_ecx) != leaf_1_ecx) return 0; diff --git a/raid/gfni.c b/raid/gfni.c index 9fd6fb99..0d91dca8 100644 --- a/raid/gfni.c +++ b/raid/gfni.c @@ -18,8 +18,7 @@ static __always_inline void raid_genX_avx2gfni_raid(int nd, size_t size, void ** if (nd == 1) { for (d = 0; d < np; ++d) - if (v[1 + d] != v[0]) - memcpy(v[1 + d], v[0], size); + memcpy(v[1 + d], v[0], size); return; } @@ -130,8 +129,7 @@ static __always_inline void raid_genX_avx512gfni_raid(int nd, size_t size, void if (nd == 1) { for (d = 0; d < np; ++d) - if (v[1 + d] != v[0]) - memcpy(v[1 + d], v[0], size); + memcpy(v[1 + d], v[0], size); return; } @@ -214,8 +212,7 @@ static __always_inline void raid_genX_avx2gfni_aes(int nd, size_t size, void **v if (nd == 1) { for (d = 0; d < np; ++d) - if (v[1 + d] != v[0]) - memcpy(v[1 + d], v[0], size); + memcpy(v[1 + d], v[0], size); return; } @@ -333,8 +330,7 @@ static __always_inline void raid_genX_avx512gfni_aes(int nd, size_t size, void * if (nd == 1) { for (d = 0; d < np; ++d) - if (v[1 + d] != v[0]) - memcpy(v[1 + d], v[0], size); + memcpy(v[1 + d], v[0], size); return; } @@ -603,16 +599,6 @@ static __always_inline void raid_recX_avx2gfni_raid(int nr, int *id, int *ip, in raid_avx_end(); } -/* - * Recover multiple data failures using selected parity blocks with AVX512 GFNI. - * - * Compute only the selected syndromes, keeping them in registers. - * This avoids raid_delta_gen(), temporary syndrome buffers, recomputation of - * parity blocks, and generation of unused parity rows. - * - * If P is available, reconstruct only nr - 1 missing blocks through the - * inverse matrix and derive the last missing block from the P delta by XOR. - */ static __always_inline void raid_recX_avx512gfni_raid(int nr, int *id, int *ip, int nd, size_t size, void **vv) { uint8_t **v = (uint8_t **)vv; @@ -663,8 +649,7 @@ static __always_inline void raid_recX_avx512gfni_raid(int nr, int *id, int *ip, BUG_ON(k != nr); BUG_ON(ns != nd - nr); - /* the last inverse row isn't needed when P is available */ - for (j = 0; j < nr - has_p; ++j) + for (j = 0; j < nr; ++j) for (k = 0; k < nr; ++k) R[j][k] = raid_gfaffine_raid[V[j * nr + k]]; @@ -727,15 +712,7 @@ static __always_inline void raid_recX_avx512gfni_raid(int nr, int *id, int *ip, } } - /* preserve the complete P delta */ - if (has_p) - asm volatile ("vmovdqa64 %zmm0,%zmm30"); - - /* - * If P is available, reconstruct only nr - 1 blocks through - * the inverse matrix. The final block remains in zmm30. - */ - for (j = 0; j < nr - has_p; ++j) { + for (j = 0; j < nr; ++j) { const uint8_t **t = R[j]; asm volatile ("vpbroadcastq %0,%%zmm6" : : "m" (t[0][0])); @@ -771,14 +748,8 @@ static __always_inline void raid_recX_avx512gfni_raid(int nr, int *id, int *ip, asm volatile ("vpxorq %zmm8,%zmm7,%zmm7"); } - if (has_p) - asm volatile ("vpxorq %zmm7,%zmm30,%zmm30"); - asm volatile ("vmovdqa64 %%zmm7,%0" : "=m" (pa[j][i])); } - - if (has_p) - asm volatile ("vmovdqa64 %%zmm30,%0" : "=m" (pa[nr - 1][i])); } raid_avx_end(); @@ -973,17 +944,6 @@ static __always_inline void raid_recX_avx2gfni_aes(int nr, int *id, int *ip, int raid_avx_end(); } -/* - * Recover multiple data failures using selected parity blocks with AVX512 GFNI - * and the AES polynomial. - * - * Compute only the selected syndromes, keeping them in registers. - * This avoids raid_delta_gen(), temporary syndrome buffers, recomputation of - * parity blocks, and generation of unused parity rows. - * - * If P is available, reconstruct only nr - 1 missing blocks through the - * inverse matrix and derive the last missing block from the P delta by XOR. - */ static __always_inline void raid_recX_avx512gfni_aes(int nr, int *id, int *ip, int nd, size_t size, void **vv) { uint8_t **v = (uint8_t **)vv; @@ -1090,11 +1050,7 @@ static __always_inline void raid_recX_avx512gfni_aes(int nr, int *id, int *ip, i } } - /* preserve the complete P delta */ - if (has_p) - asm volatile ("vmovdqa64 %zmm0,%zmm30"); - - for (j = 0; j < nr - has_p; ++j) { + for (j = 0; j < nr; ++j) { asm volatile ("vpbroadcastb %0,%%zmm6" : : "m" (V[j * nr])); asm volatile ("vgf2p8mulb %zmm6,%zmm0,%zmm7"); @@ -1128,14 +1084,8 @@ static __always_inline void raid_recX_avx512gfni_aes(int nr, int *id, int *ip, i asm volatile ("vpxorq %zmm8,%zmm7,%zmm7"); } - if (has_p) - asm volatile ("vpxorq %zmm7,%zmm30,%zmm30"); - asm volatile ("vmovdqa64 %%zmm7,%0" : "=m" (pa[j][i])); } - - if (has_p) - asm volatile ("vmovdqa64 %%zmm30,%0" : "=m" (pa[nr - 1][i])); } raid_avx_end(); @@ -1314,82 +1264,9 @@ void raid_rec1_avx2gfni_raid(int nr, int *id, int *ip, int nd, size_t size, void raid_recX_avx2gfni_raid(1, id, ip, nd, size, vv); } -/* - * Recover failure of two data blocks using P and Q AVX2 RAID GFNI implementation. - */ -static __always_inline void raid_rec2of2_avx2gfni_raid(int *id, int *ip, int nd, size_t size, void **vv) -{ - uint8_t **v = (uint8_t **)vv; - uint8_t *p; - uint8_t *pa; - uint8_t *q; - uint8_t *qa; - const uint8_t *T[2]; - uint8_t C[2]; - size_t i; - - C[0] = inv(powgen(id[1] - id[0]) ^ 1); - C[1] = inv(powgen(id[0]) ^ powgen(id[1])); - - T[0] = raid_gfaffine_raid[C[0]]; - T[1] = raid_gfaffine_raid[C[1]]; - - /* compute delta parity */ - raid_delta_gen(2, id, ip, nd, size, vv); - - p = v[nd]; - q = v[nd + 1]; - pa = v[id[0]]; - qa = v[id[1]]; - - raid_avx_begin(); - - asm volatile ("vpbroadcastq %0,%%ymm14" : : "m" (T[0][0])); - asm volatile ("vpbroadcastq %0,%%ymm15" : : "m" (T[1][0])); - - for (i = 0; i < size; i += 64) { - /* Pd, two 32-byte lanes */ - asm volatile ("vmovdqa %0,%%ymm0" : : "m" (p[i])); - asm volatile ("vmovdqa %0,%%ymm1" : : "m" (p[i + 32])); - asm volatile ("vpxor %0,%%ymm0,%%ymm0" : : "m" (pa[i])); - asm volatile ("vpxor %0,%%ymm1,%%ymm1" : : "m" (pa[i + 32])); - - /* Qd, two 32-byte lanes */ - asm volatile ("vmovdqa %0,%%ymm2" : : "m" (q[i])); - asm volatile ("vmovdqa %0,%%ymm3" : : "m" (q[i + 32])); - asm volatile ("vpxor %0,%%ymm2,%%ymm2" : : "m" (qa[i])); - asm volatile ("vpxor %0,%%ymm3,%%ymm3" : : "m" (qa[i + 32])); - - /* Dy = C0 * Pd ^ C1 * Qd */ - asm volatile ("vgf2p8affineqb $0,%ymm14,%ymm0,%ymm4"); - asm volatile ("vgf2p8affineqb $0,%ymm14,%ymm1,%ymm5"); - asm volatile ("vgf2p8affineqb $0,%ymm15,%ymm2,%ymm6"); - asm volatile ("vgf2p8affineqb $0,%ymm15,%ymm3,%ymm7"); - asm volatile ("vpxor %ymm6,%ymm4,%ymm4"); - asm volatile ("vpxor %ymm7,%ymm5,%ymm5"); - - /* Dx = Pd ^ Dy */ - asm volatile ("vpxor %ymm4,%ymm0,%ymm0"); - asm volatile ("vpxor %ymm5,%ymm1,%ymm1"); - - asm volatile ("vmovdqa %%ymm0,%0" : "=m" (pa[i])); - asm volatile ("vmovdqa %%ymm1,%0" : "=m" (pa[i + 32])); - asm volatile ("vmovdqa %%ymm4,%0" : "=m" (qa[i])); - asm volatile ("vmovdqa %%ymm5,%0" : "=m" (qa[i + 32])); - } - - raid_avx_end(); -} - void raid_rec2_avx2gfni_raid(int nr, int *id, int *ip, int nd, size_t size, void **vv) { BUG_ON(nr != 2); - - if (ip[0] == 0 && ip[1] == 1) { - raid_rec2of2_avx2gfni_raid(id, ip, nd, size, vv); - return; - } - raid_recX_avx2gfni_raid(2, id, ip, nd, size, vv); } @@ -1430,68 +1307,9 @@ void raid_rec1_avx512gfni_raid(int nr, int *id, int *ip, int nd, size_t size, vo raid_recX_avx512gfni_raid(1, id, ip, nd, size, vv); } -/* - * Recover failure of two data blocks using P and Q AVX512 RAID GFNI implementation. - */ -static __always_inline void raid_rec2of2_avx512gfni_raid(int *id, int *ip, int nd, size_t size, void **vv) -{ - uint8_t **v = (uint8_t **)vv; - uint8_t *p; - uint8_t *pa; - uint8_t *q; - uint8_t *qa; - const uint8_t *T[2]; - uint8_t C[2]; - size_t i; - - C[0] = inv(powgen(id[1] - id[0]) ^ 1); - C[1] = inv(powgen(id[0]) ^ powgen(id[1])); - - T[0] = raid_gfaffine_raid[C[0]]; - T[1] = raid_gfaffine_raid[C[1]]; - - raid_delta_gen(2, id, ip, nd, size, vv); - - p = v[nd]; - q = v[nd + 1]; - pa = v[id[0]]; - qa = v[id[1]]; - - raid_avx_begin(); - - asm volatile ("vpbroadcastq %0,%%zmm14" : : "m" (T[0][0])); - asm volatile ("vpbroadcastq %0,%%zmm15" : : "m" (T[1][0])); - - for (i = 0; i < size; i += 64) { - asm volatile ("vmovdqa64 %0,%%zmm0" : : "m" (p[i])); - asm volatile ("vpxorq %0,%%zmm0,%%zmm0" : : "m" (pa[i])); - - asm volatile ("vmovdqa64 %0,%%zmm1" : : "m" (q[i])); - asm volatile ("vpxorq %0,%%zmm1,%%zmm1" : : "m" (qa[i])); - - asm volatile ("vgf2p8affineqb $0,%zmm14,%zmm0,%zmm2"); - asm volatile ("vgf2p8affineqb $0,%zmm15,%zmm1,%zmm3"); - asm volatile ("vpxorq %zmm3,%zmm2,%zmm2"); - - /* Dx = Pd ^ Dy */ - asm volatile ("vpxorq %zmm2,%zmm0,%zmm0"); - - asm volatile ("vmovdqa64 %%zmm0,%0" : "=m" (pa[i])); - asm volatile ("vmovdqa64 %%zmm2,%0" : "=m" (qa[i])); - } - - raid_avx_end(); -} - void raid_rec2_avx512gfni_raid(int nr, int *id, int *ip, int nd, size_t size, void **vv) { BUG_ON(nr != 2); - - if (ip[0] == 0 && ip[1] == 1) { - raid_rec2of2_avx512gfni_raid(id, ip, nd, size, vv); - return; - } - raid_recX_avx512gfni_raid(2, id, ip, nd, size, vv); } @@ -1532,73 +1350,9 @@ void raid_rec1_avx2gfni_aes(int nr, int *id, int *ip, int nd, size_t size, void raid_recX_avx2gfni_aes(1, id, ip, nd, size, vv); } -/* - * Recover failure of two data blocks using P and Q AVX2 AES GFNI implementation. - */ -static __always_inline void raid_rec2of2_avx2gfni_aes(int *id, int *ip, int nd, size_t size, void **vv) -{ - uint8_t **v = (uint8_t **)vv; - uint8_t *p; - uint8_t *pa; - uint8_t *q; - uint8_t *qa; - uint8_t C[2]; - size_t i; - - C[0] = inv(powgen(id[1] - id[0]) ^ 1); - C[1] = inv(powgen(id[0]) ^ powgen(id[1])); - - raid_delta_gen(2, id, ip, nd, size, vv); - - p = v[nd]; - q = v[nd + 1]; - pa = v[id[0]]; - qa = v[id[1]]; - - raid_avx_begin(); - - asm volatile ("vpbroadcastb %0,%%ymm14" : : "m" (C[0])); - asm volatile ("vpbroadcastb %0,%%ymm15" : : "m" (C[1])); - - for (i = 0; i < size; i += 64) { - asm volatile ("vmovdqa %0,%%ymm0" : : "m" (p[i])); - asm volatile ("vmovdqa %0,%%ymm1" : : "m" (p[i + 32])); - asm volatile ("vpxor %0,%%ymm0,%%ymm0" : : "m" (pa[i])); - asm volatile ("vpxor %0,%%ymm1,%%ymm1" : : "m" (pa[i + 32])); - - asm volatile ("vmovdqa %0,%%ymm2" : : "m" (q[i])); - asm volatile ("vmovdqa %0,%%ymm3" : : "m" (q[i + 32])); - asm volatile ("vpxor %0,%%ymm2,%%ymm2" : : "m" (qa[i])); - asm volatile ("vpxor %0,%%ymm3,%%ymm3" : : "m" (qa[i + 32])); - - asm volatile ("vgf2p8mulb %ymm14,%ymm0,%ymm4"); - asm volatile ("vgf2p8mulb %ymm14,%ymm1,%ymm5"); - asm volatile ("vgf2p8mulb %ymm15,%ymm2,%ymm6"); - asm volatile ("vgf2p8mulb %ymm15,%ymm3,%ymm7"); - asm volatile ("vpxor %ymm6,%ymm4,%ymm4"); - asm volatile ("vpxor %ymm7,%ymm5,%ymm5"); - - asm volatile ("vpxor %ymm4,%ymm0,%ymm0"); - asm volatile ("vpxor %ymm5,%ymm1,%ymm1"); - - asm volatile ("vmovdqa %%ymm0,%0" : "=m" (pa[i])); - asm volatile ("vmovdqa %%ymm1,%0" : "=m" (pa[i + 32])); - asm volatile ("vmovdqa %%ymm4,%0" : "=m" (qa[i])); - asm volatile ("vmovdqa %%ymm5,%0" : "=m" (qa[i + 32])); - } - - raid_avx_end(); -} - void raid_rec2_avx2gfni_aes(int nr, int *id, int *ip, int nd, size_t size, void **vv) { BUG_ON(nr != 2); - - if (ip[0] == 0 && ip[1] == 1) { - raid_rec2of2_avx2gfni_aes(id, ip, nd, size, vv); - return; - } - raid_recX_avx2gfni_aes(2, id, ip, nd, size, vv); } @@ -1639,63 +1393,9 @@ void raid_rec1_avx512gfni_aes(int nr, int *id, int *ip, int nd, size_t size, voi raid_recX_avx512gfni_aes(1, id, ip, nd, size, vv); } -/* - * Recover failure of two data blocks using P and Q AVX512 AES GFNI implementation. - */ -static __always_inline void raid_rec2of2_avx512gfni_aes(int *id, int *ip, int nd, size_t size, void **vv) -{ - uint8_t **v = (uint8_t **)vv; - uint8_t *p; - uint8_t *pa; - uint8_t *q; - uint8_t *qa; - uint8_t C[2]; - size_t i; - - C[0] = inv(powgen(id[1] - id[0]) ^ 1); - C[1] = inv(powgen(id[0]) ^ powgen(id[1])); - - raid_delta_gen(2, id, ip, nd, size, vv); - - p = v[nd]; - q = v[nd + 1]; - pa = v[id[0]]; - qa = v[id[1]]; - - raid_avx_begin(); - - asm volatile ("vpbroadcastb %0,%%zmm14" : : "m" (C[0])); - asm volatile ("vpbroadcastb %0,%%zmm15" : : "m" (C[1])); - - for (i = 0; i < size; i += 64) { - asm volatile ("vmovdqa64 %0,%%zmm0" : : "m" (p[i])); - asm volatile ("vpxorq %0,%%zmm0,%%zmm0" : : "m" (pa[i])); - - asm volatile ("vmovdqa64 %0,%%zmm1" : : "m" (q[i])); - asm volatile ("vpxorq %0,%%zmm1,%%zmm1" : : "m" (qa[i])); - - asm volatile ("vgf2p8mulb %zmm14,%zmm0,%zmm2"); - asm volatile ("vgf2p8mulb %zmm15,%zmm1,%zmm3"); - asm volatile ("vpxorq %zmm3,%zmm2,%zmm2"); - - asm volatile ("vpxorq %zmm2,%zmm0,%zmm0"); - - asm volatile ("vmovdqa64 %%zmm0,%0" : "=m" (pa[i])); - asm volatile ("vmovdqa64 %%zmm2,%0" : "=m" (qa[i])); - } - - raid_avx_end(); -} - void raid_rec2_avx512gfni_aes(int nr, int *id, int *ip, int nd, size_t size, void **vv) { BUG_ON(nr != 2); - - if (ip[0] == 0 && ip[1] == 1) { - raid_rec2of2_avx512gfni_aes(id, ip, nd, size, vv); - return; - } - raid_recX_avx512gfni_aes(2, id, ip, nd, size, vv); } diff --git a/raid/int.c b/raid/int.c index 7c27e436..2036f589 100644 --- a/raid/int.c +++ b/raid/int.c @@ -581,6 +581,7 @@ void raid_rec2_int8(int nr, int *id, int *ip, int nd, size_t size, void **vv) uint8_t *pa; uint8_t *q; uint8_t *qa; + const int N = 2; const uint8_t *T[2][2]; uint8_t G[2 * 2]; uint8_t V[2 * 2]; @@ -596,17 +597,17 @@ void raid_rec2_int8(int nr, int *id, int *ip, int nd, size_t size, void **vv) } /* setup the coefficients matrix */ - for (j = 0; j < 2; ++j) - for (k = 0; k < 2; ++k) - G[j * 2 + k] = A(ip[j], id[k]); + for (j = 0; j < N; ++j) + for (k = 0; k < N; ++k) + G[j * N + k] = A(ip[j], id[k]); /* invert it to solve the system of linear equations */ - raid_invert(G, V, 2); + raid_invert(G, V, N); /* get multiplication tables */ - for (j = 0; j < 2; ++j) - for (k = 0; k < 2; ++k) - T[j][k] = table(V[j * 2 + k]); + for (j = 0; j < N; ++j) + for (k = 0; k < N; ++k) + T[j][k] = table(V[j * N + k]); /* compute delta parity */ raid_delta_gen(2, id, ip, nd, size, vv); diff --git a/raid/internal.h b/raid/internal.h index f34f376f..1ac13e63 100644 --- a/raid/internal.h +++ b/raid/internal.h @@ -44,9 +44,7 @@ #include /* - * Inverse assert used to check internal invariants and API preconditions. - * It is intentionally based on assert() so that all checks can be disabled - * with NDEBUG. When disabled, callers must satisfy all documented preconditions. + * Inverse assert. */ #define BUG_ON(a) assert(!(a)) diff --git a/raid/memory.h b/raid/memory.h index 3cc6d768..65e63efc 100644 --- a/raid/memory.h +++ b/raid/memory.h @@ -4,19 +4,6 @@ #ifndef __RAID_MEMORY_H #define __RAID_MEMORY_H -/** - * Memory allocation and benchmark layout helpers. - * - * This module provides optional utility functions to allocate SIMD-aligned and - * cache-displaced memory buffers for test suites, benchmarks, and Direct I/O. - * The core RAID engine (raid.h) remains zero-allocation and operates on - * preallocated buffers. - * - * Like other internal helpers in this library, these functions intentionally do - * not validate against arithmetic overflow. Callers are responsible for passing - * reasonable and bounded arguments. - */ - /** * Memory alignment provided by raid_malloc(). * @@ -77,36 +64,26 @@ unsigned raid_optimal_displacement(int n); /** - * Aligned malloc with default RAID alignment (256 bytes). - * - * Stores the base allocation address in @freeptr to be passed to free(). + * Aligned malloc. + * Use an alignment suitable for the raid functions. */ void *raid_malloc(size_t size, void **freeptr); /** * Arbitrary aligned malloc. - * - * Allocates a buffer of @size bytes aligned to @align_size bytes. - * Stores the base allocation address in @freeptr to be passed to free(). */ void *raid_malloc_align(size_t size, size_t align_size, void **freeptr); /** * Aligned vector allocation. - * - * Allocates an array of @n pointers, each one pointing to a block of - * the specified @size with optimal L1 displacement and stride perturbation. - * - * Freeing requires two calls: free(*freeptr) for the data buffer, - * and free(v) for the pointer vector. + * Use an alignment suitable for the raid functions. + * Returns a vector of @n pointers, each one pointing to a block of + * the specified @size. */ void **raid_malloc_vector(int n, size_t size, void **freeptr); /** * Arbitrary aligned vector allocation. - * - * Freeing requires two calls: free(*freeptr) for the data buffer, - * and free(v) for the pointer vector. */ void **raid_malloc_vector_align(int n, size_t size, size_t align_size, ssize_t displacement_size, ssize_t wrap_size, void **freeptr); diff --git a/raid/module.c b/raid/module.c index c5fa05b4..3007a88c 100644 --- a/raid/module.c +++ b/raid/module.c @@ -172,35 +172,8 @@ void raid_rec(int nr, int *ir, int nd, int np, size_t size, void **v) } /* recompute all the parities up to the last bad one */ - if (nrp != 0) { - void *v_gen[RAID_DATA_MAX + RAID_PARITY_MAX]; - int max_p = ir[nr - 1] - nd + 1; - int i, j; - - /* copy data block pointers */ - for (i = 0; i < nd; ++i) - v_gen[i] = v[i]; - - /* - * Setup parity pointers. - * To avoid writing into healthy parity blocks (which may be read-only), - * redirect each healthy parity to the buffer of the next bad parity. - * Because raid_gen() generates and writes parities in increasing order, - * the subsequent bad parity will overwrite any intermediate data. - */ - for (i = 0, j = 0; i < max_p; ++i) { - if (j < nrp && ir[nrd + j] == nd + i) { - /* this parity has to be recovered */ - v_gen[nd + i] = v[nd + i]; - ++j; - } else { - /* this parity is healthy, redirect to the next bad parity */ - v_gen[nd + i] = v[ir[nrd + j]]; - } - } - - raid_gen(nd, max_p, size, v_gen); - } + if (nrp != 0) + raid_gen(nd, ir[nr - 1] - nd + 1, size, v); } void raid_data(int nr, int *id, int *ip, int nd, size_t size, void **v) @@ -779,12 +752,6 @@ int raid_selftest(void) ret = 0; bail: - /* - * Reset the global zero buffer so that it does not point to - * the deallocated memory. - */ - raid_zero(0); - free(v); free(v_alloc); diff --git a/raid/neon.c b/raid/neon.c index 7af6ae34..71ed4ecd 100644 --- a/raid/neon.c +++ b/raid/neon.c @@ -250,8 +250,7 @@ static __always_inline void raid_genX_neon(int nd, size_t size, void **vv, int n /* special case with only one data disk */ if (l == 0) { for (d = 0; d < np; ++d) - if (v[1 + d] != v[0]) - memcpy(v[1 + d], v[0], size); + memcpy(v[1 + d], v[0], size); return; } @@ -567,7 +566,8 @@ static __always_inline void raid_genX_neon(int nd, size_t size, void **vv, int n raid_neon_end(); } -static __always_inline void raid_recX_neon(int nr, int *id, int *ip, int nd, size_t size, void **vv) +static __always_inline void raid_recX_neon(int nr, int *id, int *ip, + int nd, size_t size, void **vv) { uint8_t **v = (uint8_t **)vv; uint8_t *p[RAID_PARITY_MAX]; @@ -1045,132 +1045,9 @@ void raid_rec1_neon(int nr, int *id, int *ip, int nd, size_t size, void **vv) raid_recX_neon(1, id, ip, nd, size, vv); } -/* - * Recover failure of two data blocks using P and Q AArch64 NEON implementation. - */ -static __always_inline void raid_rec2of2_neon(int *id, int *ip, int nd, size_t size, void **vv) -{ - uint8_t **v = (uint8_t **)vv; - uint8_t *p; - uint8_t *pa; - uint8_t *q; - uint8_t *qa; - uint8_t C[2]; - size_t i; - - C[0] = inv(powgen(id[1] - id[0]) ^ 1); - C[1] = inv(powgen(id[0]) ^ powgen(id[1])); - - raid_delta_gen(2, id, ip, nd, size, vv); - - p = v[nd]; - q = v[nd + 1]; - pa = v[id[0]]; - qa = v[id[1]]; - - raid_neon_begin(); - - asm volatile ( - "ldr q28, %0\n" - "ldr q20, %1\n" - "ldr q21, %2\n" - "ldr q22, %3\n" - "ldr q23, %4\n" - : - : "m" (gfconst16.low4[0]), - "m" (raid_gfmulpshufb[C[0]][0][0]), - "m" (raid_gfmulpshufb[C[0]][1][0]), - "m" (raid_gfmulpshufb[C[1]][0][0]), - "m" (raid_gfmulpshufb[C[1]][1][0]) - ); - - for (i = 0; i < size; i += 32) { - asm volatile ( - /* Pd, two lanes */ - "ldr q0, %4\n" - "ldr q1, %5\n" - "ldr q12, %8\n" - "ldr q13, %9\n" - "eor v0.16b, v0.16b, v12.16b\n" - "eor v1.16b, v1.16b, v13.16b\n" - - /* preserve Pd for Dx */ - "mov v8.16b, v0.16b\n" - "mov v9.16b, v1.16b\n" - - /* Qd, two lanes */ - "ldr q2, %6\n" - "ldr q3, %7\n" - "ldr q12, %10\n" - "ldr q13, %11\n" - "eor v2.16b, v2.16b, v12.16b\n" - "eor v3.16b, v3.16b, v13.16b\n" - - /* split Pd */ - "ushr v4.16b, v0.16b, #4\n" - "ushr v5.16b, v1.16b, #4\n" - "and v0.16b, v0.16b, v28.16b\n" - "and v1.16b, v1.16b, v28.16b\n" - "and v4.16b, v4.16b, v28.16b\n" - "and v5.16b, v5.16b, v28.16b\n" - - /* split Qd */ - "ushr v6.16b, v2.16b, #4\n" - "ushr v7.16b, v3.16b, #4\n" - "and v2.16b, v2.16b, v28.16b\n" - "and v3.16b, v3.16b, v28.16b\n" - "and v6.16b, v6.16b, v28.16b\n" - "and v7.16b, v7.16b, v28.16b\n" - - /* C0 * Pd */ - "tbl v10.16b, {v20.16b}, v0.16b\n" - "tbl v11.16b, {v20.16b}, v1.16b\n" - "tbl v12.16b, {v21.16b}, v4.16b\n" - "tbl v13.16b, {v21.16b}, v5.16b\n" - "eor v10.16b, v10.16b, v12.16b\n" - "eor v11.16b, v11.16b, v13.16b\n" - - /* C1 * Qd */ - "tbl v12.16b, {v22.16b}, v2.16b\n" - "tbl v13.16b, {v22.16b}, v3.16b\n" - "tbl v14.16b, {v23.16b}, v6.16b\n" - "tbl v15.16b, {v23.16b}, v7.16b\n" - "eor v12.16b, v12.16b, v14.16b\n" - "eor v13.16b, v13.16b, v15.16b\n" - - /* Dy */ - "eor v10.16b, v10.16b, v12.16b\n" - "eor v11.16b, v11.16b, v13.16b\n" - - /* Dx = Pd ^ Dy */ - "eor v8.16b, v8.16b, v10.16b\n" - "eor v9.16b, v9.16b, v11.16b\n" - - "str q8, %0\n" - "str q9, %1\n" - "str q10, %2\n" - "str q11, %3\n" - : "=m" (pa[i]), "=m" (pa[i + 16]), - "=m" (qa[i]), "=m" (qa[i + 16]) - : "m" (p[i]), "m" (p[i + 16]), - "m" (q[i]), "m" (q[i + 16]), - "m" (pa[i]), "m" (pa[i + 16]), - "m" (qa[i]), "m" (qa[i + 16]) - ); - } - - raid_neon_end(); -} - void raid_rec2_neon(int nr, int *id, int *ip, int nd, size_t size, void **vv) { BUG_ON(nr != 2); - - if (ip[0] == 0 && ip[1] == 1) { - raid_rec2of2_neon(id, ip, nd, size, vv); - return; - } - raid_recX_neon(2, id, ip, nd, size, vv); } diff --git a/raid/neon32.c b/raid/neon32.c index 1483a6ff..04c839b1 100644 --- a/raid/neon32.c +++ b/raid/neon32.c @@ -244,8 +244,7 @@ static __always_inline void raid_genX_neon32(int nd, size_t size, /* special case with only one data disk */ if (l == 0) { for (d = 0; d < np; ++d) - if (v[1 + d] != v[0]) - memcpy(v[1 + d], v[0], size); + memcpy(v[1 + d], v[0], size); return; } @@ -519,7 +518,8 @@ static __always_inline void raid_genX_neon32(int nd, size_t size, raid_neon32_end(); } -static __always_inline void raid_recX_neon32_123(int nr, int *id, int *ip, int nd, size_t size, void **vv) +static __always_inline void raid_recX_neon32_123(int nr, int *id, int *ip, + int nd, size_t size, void **vv) { uint8_t **v = (uint8_t **)vv; uint8_t *p[RAID_PARITY_MAX]; @@ -816,7 +816,8 @@ static __always_inline void raid_recX_neon32_123(int nr, int *id, int *ip, int n raid_neon32_end(); } -static __always_inline void raid_recX_neon32(int nr, int *id, int *ip, int nd, size_t size, void **vv) +static __always_inline void raid_recX_neon32(int nr, int *id, int *ip, + int nd, size_t size, void **vv) { uint8_t **v = (uint8_t **)vv; uint8_t *p[RAID_PARITY_MAX]; @@ -1224,114 +1225,9 @@ void raid_rec1_neon32(int nr, int *id, int *ip, int nd, size_t size, void **vv) raid_recX_neon32_123(1, id, ip, nd, size, vv); } -/* - * Recover failure of two data blocks using P and Q AArch32 NEON implementation. - */ -static __always_inline void raid_rec2of2_neon32(int *id, int *ip, int nd, size_t size, void **vv) -{ - uint8_t **v = (uint8_t **)vv; - uint8_t *p; - uint8_t *pa; - uint8_t *q; - uint8_t *qa; - uint8_t C[2]; - size_t i; - - C[0] = inv(powgen(id[1] - id[0]) ^ 1); - C[1] = inv(powgen(id[0]) ^ powgen(id[1])); - - raid_delta_gen(2, id, ip, nd, size, vv); - - p = v[nd]; - q = v[nd + 1]; - pa = v[id[0]]; - qa = v[id[1]]; - - raid_neon32_begin(); - - /* q15 = nibble mask, q9-q12 = C0/C1 low/high tables */ - asm volatile ( - "vld1.8 {q15}, %0\n" - "vld1.8 {q9}, %1\n" - "vld1.8 {q10}, %2\n" - "vld1.8 {q11}, %3\n" - "vld1.8 {q12}, %4\n" - : - : "Q" (gfconst16.low4[0]), - "Q" (raid_gfmulpshufb[C[0]][0][0]), - "Q" (raid_gfmulpshufb[C[0]][1][0]), - "Q" (raid_gfmulpshufb[C[1]][0][0]), - "Q" (raid_gfmulpshufb[C[1]][1][0]) - ); - - for (i = 0; i < size; i += 16) { - asm volatile ( - /* Pd */ - "vld1.8 {q0}, %2\n" - "vld1.8 {q13}, %4\n" - "veor q0, q0, q13\n" - - /* Qd */ - "vld1.8 {q1}, %3\n" - "vld1.8 {q13}, %5\n" - "veor q1, q1, q13\n" - - /* split Pd */ - "vmov q2, q0\n" - "vshr.u8 q3, q0, #4\n" - "vand q2, q2, q15\n" - "vand q3, q3, q15\n" - - /* split Qd */ - "vmov q4, q1\n" - "vshr.u8 q5, q1, #4\n" - "vand q4, q4, q15\n" - "vand q5, q5, q15\n" - - /* C0 low * Pd low -> q6 */ - "vtbl.8 d12, {d18-d19}, d4\n" - "vtbl.8 d13, {d18-d19}, d5\n" - - /* C0 high * Pd high -> q7 */ - "vtbl.8 d14, {d20-d21}, d6\n" - "vtbl.8 d15, {d20-d21}, d7\n" - "veor q6, q6, q7\n" - - /* C1 low * Qd low -> q7 */ - "vtbl.8 d14, {d22-d23}, d8\n" - "vtbl.8 d15, {d22-d23}, d9\n" - - /* C1 high * Qd high -> q8 */ - "vtbl.8 d16, {d24-d25}, d10\n" - "vtbl.8 d17, {d24-d25}, d11\n" - "veor q7, q7, q8\n" - - /* Dy */ - "veor q6, q6, q7\n" - - /* Dx = Pd ^ Dy */ - "veor q0, q0, q6\n" - - "vst1.8 {q0}, %0\n" - "vst1.8 {q6}, %1\n" - : "=Q" (pa[i]), "=Q" (qa[i]) - : "Q" (p[i]), "Q" (q[i]), - "Q" (pa[i]), "Q" (qa[i]) - ); - } - - raid_neon32_end(); -} - void raid_rec2_neon32(int nr, int *id, int *ip, int nd, size_t size, void **vv) { BUG_ON(nr != 2); - - if (ip[0] == 0 && ip[1] == 1) { - raid_rec2of2_neon32(id, ip, nd, size, vv); - return; - } - raid_recX_neon32_123(2, id, ip, nd, size, vv); } diff --git a/raid/raid.c b/raid/raid.c index c2aab876..b5d07407 100644 --- a/raid/raid.c +++ b/raid/raid.c @@ -26,10 +26,12 @@ * and divisions by 2 in GF(2^8) are very fast. It is similar to ZFS RAIDZ3, * which uses powers of 4 instead of 2^-1. * - * Unfortunately, this method does not extend reliably beyond triple parity. - * Vandermonde matrices do not guarantee that all square submatrices are - * nonsingular, which is required to recover every possible combination of - * missing disks [2, Chap. 11, Problem 7][2, Chap. 11, Theorem 8]. + * Unfortunately, this method does not extend beyond triple parity because + * no choice of power coefficients guarantees solvable equations for all + * combinations of missing disks. This is expected: a Vandermonde matrix, + * used in this method, does not ensure that all submatrices are nonsingular + * [2, Chap. 11, Problem 7], which is required for an MDS (Maximum Distance + * Separable) code [2, Chap. 11, Theorem 8]. * * To overcome this limitation, a Cauchy matrix [3][4] is used for parity * computation. A Cauchy matrix ensures that all square submatrices are @@ -119,9 +121,9 @@ * data disks, one for each column. All the 377,342,351,231 square submatrices * are nonsingular, verified also by brute-force testing. * - * The construction can be extended to additional parity rows while reducing - * the maximum number of data columns accordingly. In GF(2^8), the Extended - * Cauchy construction requires data + parity <= 257 + * This matrix can be extended to support any number of parities by simply + * adding additional rows and removing one column for each new row to maintain + * the condition i + j < 255. * (See mktables.c for more details on how the matrix is generated.) * * The downside is that generic multiplications are required to compute the diff --git a/raid/raid.h b/raid/raid.h index 459adeba..d88fe8bb 100644 --- a/raid/raid.h +++ b/raid/raid.h @@ -4,8 +4,6 @@ #ifndef __RAID_H #define __RAID_H -#include - /* * GF(2^8) reducing polynomial selection. * @@ -22,8 +20,8 @@ * * The polynomial used by the original RAID-6 specification and the * Linux kernel RAID implementation, used with primitive generator g=2. - * For identically ordered data blocks, the generated P/Q syndrome bytes - * match the Linux RAID6 implementation. + * Choosing this polynomial ensures on-disk compatibility with existing + * RAID arrays and interchange with other RAID implementations. * * On CPUs supporting Intel GFNI (Galois Field New Instructions), * generation and recovery are accelerated with vgf2p8affineqb. @@ -65,7 +63,7 @@ * * Provides high performance on modern CPUs with SSSE3, AVX2, AVX-512, GFNI, or NEON support. * On GFNI CPUs, the standard RAID field is accelerated using affine transformations. - * Uses Linux RAID6-compatible P/Q coefficients. + * Ensures maximum compatibility with standard Linux RAID arrays. * * This is the default mode set after calling raid_init(). */ @@ -113,9 +111,6 @@ * * You must call this function before any other RAID function. * - * After selecting the RAID mode to use, raid_selftest() should be called - * before using the RAID system. - * * Initialization modifies global RAID state and must not be called * concurrently with any other RAID function. * @@ -145,26 +140,16 @@ int raid_mode(int mode); * * raid_init() must be called before this function. * - * The RAID mode to use must be selected before calling this function. - * raid_init() selects RAID_MODE_CAUCHY_RAID by default; raid_mode() may be - * used to select a different mode. The self test verifies only the currently - * selected RAID mode. + * If a mode different from the default is required, raid_mode() must be + * called before this function. The self test verifies the currently selected + * RAID mode. * - * The test is immediate and is intended to be run at every application - * startup after the RAID mode has been selected. It verifies the RAID - * implementation selected for the current mode, CPU, compiler, and ABI - * before it is used. - * - * If the RAID mode is changed later, this function should be called again - * before using the new mode. + * The test is immediate, and it's intended to be run at application + * startup to check the integrity of the RAID system. * * The test modifies global RAID state and must not be called concurrently * with any other RAID function. * - * The test resets the zero buffer to 0 via raid_zero(0) upon completion. - * A valid zero buffer must be set with raid_zero() afterwards before calling - * recovery functions (raid_rec(), raid_data()). - * * It returns 0 on success. */ int raid_selftest(void); @@ -337,10 +322,7 @@ int raid_check(int nr, int *ir, int nd, int np, size_t size, void **v); * first one encountered is returned. This function does not check that the * returned combination is unique. * - * This function is primarily intended as a reference implementation and to - * demonstrate how raid_check() can be used to locate failed blocks. It uses - * an exhaustive brute force search and is not intended for production use. - * + * It uses a brute force method, and then the call can be expensive. * The expected execution time is proportional to the binomial coefficient * @np + @nd choose @np - 1, usually written as: * diff --git a/raid/ssse3.c b/raid/ssse3.c index c5165bf1..922d9744 100644 --- a/raid/ssse3.c +++ b/raid/ssse3.c @@ -26,8 +26,7 @@ static __always_inline void raid_gen3_ssse3_gen(int nd, size_t size, void **vv, /* special case with only one data disk */ if (l == 0) { for (i = 0; i < 3; ++i) - if (v[1 + i] != v[0]) - memcpy(v[1 + i], v[0], size); + memcpy(v[1 + i], v[0], size); return; } @@ -132,8 +131,7 @@ static __always_inline void raid_gen4_ssse3_gen(int nd, size_t size, void **vv, /* special case with only one data disk */ if (l == 0) { for (i = 0; i < 4; ++i) - if (v[1 + i] != v[0]) - memcpy(v[1 + i], v[0], size); + memcpy(v[1 + i], v[0], size); return; } @@ -259,8 +257,7 @@ void raid_gen5_ssse3_raid(int nd, size_t size, void **vv) /* special case with only one data disk */ if (l == 0) { for (i = 0; i < 5; ++i) - if (v[1 + i] != v[0]) - memcpy(v[1 + i], v[0], size); + memcpy(v[1 + i], v[0], size); return; } @@ -397,8 +394,7 @@ void raid_gen6_ssse3_raid(int nd, size_t size, void **vv) /* special case with only one data disk */ if (l == 0) { for (i = 0; i < 6; ++i) - if (v[1 + i] != v[0]) - memcpy(v[1 + i], v[0], size); + memcpy(v[1 + i], v[0], size); return; } @@ -549,8 +545,7 @@ static __always_inline void raid_gen3_ssse3ext_gen(int nd, size_t size, void **v /* special case with only one data disk */ if (l == 0) { for (i = 0; i < 3; ++i) - if (v[1 + i] != v[0]) - memcpy(v[1 + i], v[0], size); + memcpy(v[1 + i], v[0], size); return; } @@ -810,8 +805,7 @@ static __always_inline void raid_gen4_ssse3ext_gen(int nd, size_t size, void **v /* special case with only one data disk */ if (l == 0) { for (i = 0; i < 4; ++i) - if (v[1 + i] != v[0]) - memcpy(v[1 + i], v[0], size); + memcpy(v[1 + i], v[0], size); return; } @@ -1001,8 +995,7 @@ static __always_inline void raid_genX_ssse3ext(int nd, size_t size, void **vv, i /* special case with only one data disk */ if (l == 0) { for (d = 0; d < np; ++d) - if (v[1 + d] != v[0]) - memcpy(v[1 + d], v[0], size); + memcpy(v[1 + d], v[0], size); return; } @@ -1159,7 +1152,7 @@ static __always_inline void raid_genX_ssse3ext(int nd, size_t size, void **vv, i /* * RAID recovering for one disk SSSE3 implementation */ -static __always_inline void raid_rec1_ssse3_delta(int *id, int *ip, int nd, size_t size, void **vv) +static __always_inline void raid_rec1_ssse3_delta(int nr, int *id, int *ip, int nd, size_t size, void **vv) { uint8_t **v = (uint8_t **)vv; uint8_t *p; @@ -1168,6 +1161,8 @@ static __always_inline void raid_rec1_ssse3_delta(int *id, int *ip, int nd, size uint8_t V; size_t i; + (void)nr; /* unused, it's always 1 */ + /* setup the coefficients matrix */ G = A(ip[0], id[0]); @@ -1208,28 +1203,31 @@ static __always_inline void raid_rec1_ssse3_delta(int *id, int *ip, int nd, size /* * RAID recovering for two disks SSSE3 implementation */ -static __always_inline void raid_rec2_ssse3_delta(int *id, int *ip, int nd, size_t size, void **vv) +static __always_inline void raid_rec2_ssse3_delta(int nr, int *id, int *ip, int nd, size_t size, void **vv) { uint8_t **v = (uint8_t **)vv; - uint8_t *p[2]; - uint8_t *pa[2]; - uint8_t G[2 * 2]; - uint8_t V[2 * 2]; + const int N = 2; + uint8_t *p[N]; + uint8_t *pa[N]; + uint8_t G[N * N]; + uint8_t V[N * N]; size_t i; int j, k; + (void)nr; /* unused, it's always 2 */ + /* setup the coefficients matrix */ - for (j = 0; j < 2; ++j) - for (k = 0; k < 2; ++k) - G[j * 2 + k] = A(ip[j], id[k]); + for (j = 0; j < N; ++j) + for (k = 0; k < N; ++k) + G[j * N + k] = A(ip[j], id[k]); /* invert it to solve the system of linear equations */ - raid_invert(G, V, 2); + raid_invert(G, V, N); /* compute delta parity */ - raid_delta_gen(2, id, ip, nd, size, vv); + raid_delta_gen(N, id, ip, nd, size, vv); - for (j = 0; j < 2; ++j) { + for (j = 0; j < N; ++j) { p[j] = v[nd + ip[j]]; pa[j] = v[id[j]]; } @@ -1306,94 +1304,8 @@ static __always_inline void raid_rec2_ssse3_delta(int *id, int *ip, int nd, size raid_sse_end(); } -/* - * Recover failure of two data blocks using P and Q SSSE3 implementation. - */ -static __always_inline void raid_rec2of2_ssse3(int *id, int *ip, int nd, size_t size, void **vv) -{ - uint8_t **v = (uint8_t **)vv; - uint8_t *p; - uint8_t *pa; - uint8_t *q; - uint8_t *qa; - uint8_t C[2]; - size_t i; - - /* get multiplication coefficients */ - C[0] = inv(powgen(id[1] - id[0]) ^ 1); - C[1] = inv(powgen(id[0]) ^ powgen(id[1])); - - /* compute delta parity */ - raid_delta_gen(2, id, ip, nd, size, vv); - - p = v[nd]; - q = v[nd + 1]; - pa = v[id[0]]; - qa = v[id[1]]; - - raid_sse_begin(); - - asm volatile ("movdqa %0,%%xmm7" : : "m" (gfconst16.low4[0])); - - for (i = 0; i < size; i += 16) { - /* Pd */ - asm volatile ("movdqa %0,%%xmm0" : : "m" (p[i])); - asm volatile ("pxor %0,%%xmm0" : : "m" (pa[i])); - - /* Qd */ - asm volatile ("movdqa %0,%%xmm1" : : "m" (q[i])); - asm volatile ("pxor %0,%%xmm1" : : "m" (qa[i])); - - /* split Pd and Qd into low/high nibbles */ - asm volatile ("movdqa %xmm0,%xmm4"); - asm volatile ("movdqa %xmm1,%xmm5"); - asm volatile ("movdqa %xmm0,%xmm2"); - asm volatile ("movdqa %xmm1,%xmm3"); - asm volatile ("psrlw $4,%xmm2"); - asm volatile ("psrlw $4,%xmm3"); - asm volatile ("pand %xmm7,%xmm4"); - asm volatile ("pand %xmm7,%xmm5"); - asm volatile ("pand %xmm7,%xmm2"); - asm volatile ("pand %xmm7,%xmm3"); - - /* C0 * Pd */ - asm volatile ("movdqa %0,%%xmm6" : : "m" (raid_gfmulpshufb[C[0]][0][0])); - asm volatile ("pshufb %xmm4,%xmm6"); - - asm volatile ("movdqa %0,%%xmm4" : : "m" (raid_gfmulpshufb[C[0]][1][0])); - asm volatile ("pshufb %xmm2,%xmm4"); - asm volatile ("pxor %xmm4,%xmm6"); - - /* C1 * Qd */ - asm volatile ("movdqa %0,%%xmm4" : : "m" (raid_gfmulpshufb[C[1]][0][0])); - asm volatile ("pshufb %xmm5,%xmm4"); - asm volatile ("pxor %xmm4,%xmm6"); - - asm volatile ("movdqa %0,%%xmm4" : : "m" (raid_gfmulpshufb[C[1]][1][0])); - asm volatile ("pshufb %xmm3,%xmm4"); - asm volatile ("pxor %xmm4,%xmm6"); - - /* xmm6 = Dy, xmm0 = Pd, so Dx = Pd ^ Dy */ - asm volatile ("pxor %xmm6,%xmm0"); - - asm volatile ("movdqa %%xmm0,%0" : "=m" (pa[i])); - asm volatile ("movdqa %%xmm6,%0" : "=m" (qa[i])); - } - - raid_sse_end(); -} - -/* - * RAID recovering SSSE3 implementation optimized for up to four failures. - * - * If P is available, keep the complete P delta syndrome in xmm6. - * Reconstruct only nr - 1 missing blocks through the inverse matrix and - * obtain the last block by XORing the reconstructed blocks out of Pdelta. - * - * After the survivor scan xmm6 is no longer needed, leaving it available - * for the P delta accumulator. - */ -static __always_inline void raid_recX_ssse3_1234(int nr, int *id, int *ip, int nd, size_t size, void **vv) +static __always_inline void raid_recX_ssse3_1234(int nr, int *id, int *ip, + int nd, size_t size, void **vv) { uint8_t **v = (uint8_t **)vv; uint8_t *p[RAID_PARITY_MAX]; @@ -1447,7 +1359,7 @@ static __always_inline void raid_recX_ssse3_1234(int nr, int *id, int *ip, int n BUG_ON(k != nr); BUG_ON(ns != nd - nr); - for (j = 0; j < nr - has_p; ++j) + for (j = 0; j < nr; ++j) for (k = 0; k < nr; ++k) R[j][k] = &raid_gfmulpshufb[V[j * nr + k]][0][0]; @@ -1521,10 +1433,6 @@ static __always_inline void raid_recX_ssse3_1234(int nr, int *id, int *ip, int n } } - /* preserve the complete P delta before splitting syndrome 0 */ - if (has_p) - asm volatile ("movdqa %xmm0,%xmm6"); - /* * Split completed syndromes once and store the low/high nibbles. * The survivor scan is already complete. @@ -1568,11 +1476,7 @@ static __always_inline void raid_recX_ssse3_1234(int nr, int *id, int *ip, int n asm volatile ("movdqa %%xmm5,%0" : "=m" (pd_high[48])); } - /* - * Reconstruct all but the last missing block when P is - * available. xmm6 keeps the remaining P delta. - */ - for (j = 0; j < nr - has_p; ++j) { + for (j = 0; j < nr; ++j) { const uint8_t **t = R[j]; asm volatile ("movdqa %0,%%xmm0" : : "m" (t[0][0])); @@ -1594,31 +1498,15 @@ static __always_inline void raid_recX_ssse3_1234(int nr, int *id, int *ip, int n } asm volatile ("pxor %xmm1,%xmm0"); - - if (has_p) - asm volatile ("pxor %xmm0,%xmm6"); - asm volatile ("movdqa %%xmm0,%0" : "=m" (pa[j][i])); } - - if (has_p) - asm volatile ("movdqa %%xmm6,%0" : "=m" (pa[nr - 1][i])); } raid_sse_end(); } -/* - * RAID recovering SSSE3 implementation. - * - * If P is available, keep the complete P delta syndrome in xmm6. - * Reconstruct only nr - 1 missing blocks through the inverse matrix and - * obtain the last block by XORing the reconstructed blocks out of Pdelta. - * - * The completed syndromes are kept in temporary memory, leaving xmm6 - * available for the P delta accumulator during reconstruction. - */ -static __always_inline void raid_recX_ssse3(int nr, int *id, int *ip, int nd, size_t size, void **vv) +static __always_inline void raid_recX_ssse3(int nr, int *id, int *ip, + int nd, size_t size, void **vv) { uint8_t **v = (uint8_t **)vv; uint8_t *p[RAID_PARITY_MAX]; @@ -1672,7 +1560,7 @@ static __always_inline void raid_recX_ssse3(int nr, int *id, int *ip, int nd, si BUG_ON(k != nr); BUG_ON(ns != nd - nr); - for (j = 0; j < nr - has_p; ++j) + for (j = 0; j < nr; ++j) for (k = 0; k < nr; ++k) R[j][k] = &raid_gfmulpshufb[V[j * nr + k]][0][0]; @@ -1716,13 +1604,6 @@ static __always_inline void raid_recX_ssse3(int nr, int *id, int *ip, int nd, si } } - /* - * Preserve the complete P delta before pd_low[0] is converted - * to its low-nibble representation. - */ - if (has_p) - asm volatile ("movdqa %0,%%xmm6" : : "m" (pd_low[0])); - /* convert all completed raw syndromes to low/high nibble form */ for (k = 0; k < nr; ++k) { asm volatile ("movdqa %0,%%xmm0" : : "m" (pd_low[k * 16])); @@ -1734,11 +1615,8 @@ static __always_inline void raid_recX_ssse3(int nr, int *id, int *ip, int nd, si asm volatile ("movdqa %%xmm1,%0" : "=m" (pd_high[k * 16])); } - /* - * Reconstruct all but the last missing block when P is - * available. xmm6 keeps the remaining P delta. - */ - for (j = 0; j < nr - has_p; ++j) { + /* reconstruct */ + for (j = 0; j < nr; ++j) { const uint8_t **t = R[j]; asm volatile ("movdqa %0,%%xmm0" : : "m" (t[0][0])); @@ -1760,15 +1638,8 @@ static __always_inline void raid_recX_ssse3(int nr, int *id, int *ip, int nd, si } asm volatile ("pxor %xmm1,%xmm0"); - - if (has_p) - asm volatile ("pxor %xmm0,%xmm6"); - asm volatile ("movdqa %%xmm0,%0" : "=m" (pa[j][i])); } - - if (has_p) - asm volatile ("movdqa %%xmm6,%0" : "=m" (pa[nr - 1][i])); } raid_sse_end(); @@ -1776,15 +1647,9 @@ static __always_inline void raid_recX_ssse3(int nr, int *id, int *ip, int nd, si #ifdef CONFIG_X86_64 /* - * RAID recovering for one disk SSSE3 extended implementation. - * - * Process two 16-byte blocks per iteration, grouping equal operations across - * both lanes to expose instruction-level parallelism. - * - * A four-way 64-byte unroll was tested but is slower than this two-way 32-byte - * implementation. + * RAID recovering for one disk SSSE3 extended implementation */ -static __always_inline void raid_rec1_ssse3ext_delta(int *id, int *ip, int nd, size_t size, void **vv) +static __always_inline void raid_rec1_ssse3ext_delta(int nr, int *id, int *ip, int nd, size_t size, void **vv) { uint8_t **v = (uint8_t **)vv; uint8_t *p; @@ -1793,6 +1658,8 @@ static __always_inline void raid_rec1_ssse3ext_delta(int *id, int *ip, int nd, s uint8_t V; size_t i; + (void)nr; /* unused, it's always 1 */ + /* setup the coefficients matrix */ G = A(ip[0], id[0]); @@ -1811,45 +1678,71 @@ static __always_inline void raid_rec1_ssse3ext_delta(int *id, int *ip, int nd, s asm volatile ("movdqa %0,%%xmm4" : : "m" (raid_gfmulpshufb[V][0][0])); asm volatile ("movdqa %0,%%xmm5" : : "m" (raid_gfmulpshufb[V][1][0])); - for (i = 0; i < size; i += 32) { + for (i = 0; i < size; i += 64) { asm volatile ("movdqa %0,%%xmm0" : : "m" (p[i])); asm volatile ("movdqa %0,%%xmm1" : : "m" (p[i + 16])); + asm volatile ("movdqa %0,%%xmm2" : : "m" (p[i + 32])); + asm volatile ("movdqa %0,%%xmm3" : : "m" (p[i + 48])); asm volatile ("movdqa %0,%%xmm8" : : "m" (pa[i])); asm volatile ("movdqa %0,%%xmm9" : : "m" (pa[i + 16])); + asm volatile ("movdqa %0,%%xmm10" : : "m" (pa[i + 32])); + asm volatile ("movdqa %0,%%xmm11" : : "m" (pa[i + 48])); asm volatile ("pxor %xmm8,%xmm0"); asm volatile ("pxor %xmm9,%xmm1"); + asm volatile ("pxor %xmm10,%xmm2"); + asm volatile ("pxor %xmm11,%xmm3"); asm volatile ("movdqa %xmm0,%xmm8"); asm volatile ("movdqa %xmm1,%xmm9"); + asm volatile ("movdqa %xmm2,%xmm10"); + asm volatile ("movdqa %xmm3,%xmm11"); asm volatile ("psrlw $4,%xmm8"); asm volatile ("psrlw $4,%xmm9"); + asm volatile ("psrlw $4,%xmm10"); + asm volatile ("psrlw $4,%xmm11"); asm volatile ("pand %xmm7,%xmm0"); asm volatile ("pand %xmm7,%xmm1"); + asm volatile ("pand %xmm7,%xmm2"); + asm volatile ("pand %xmm7,%xmm3"); asm volatile ("pand %xmm7,%xmm8"); asm volatile ("pand %xmm7,%xmm9"); + asm volatile ("pand %xmm7,%xmm10"); + asm volatile ("pand %xmm7,%xmm11"); - asm volatile ("movdqa %xmm4,%xmm10"); - asm volatile ("movdqa %xmm4,%xmm11"); + asm volatile ("movdqa %xmm4,%xmm12"); + asm volatile ("movdqa %xmm4,%xmm13"); + asm volatile ("movdqa %xmm4,%xmm14"); + asm volatile ("movdqa %xmm4,%xmm15"); - asm volatile ("pshufb %xmm0,%xmm10"); - asm volatile ("pshufb %xmm1,%xmm11"); + asm volatile ("pshufb %xmm0,%xmm12"); + asm volatile ("pshufb %xmm1,%xmm13"); + asm volatile ("pshufb %xmm2,%xmm14"); + asm volatile ("pshufb %xmm3,%xmm15"); asm volatile ("movdqa %xmm5,%xmm0"); asm volatile ("movdqa %xmm5,%xmm1"); + asm volatile ("movdqa %xmm5,%xmm2"); + asm volatile ("movdqa %xmm5,%xmm3"); asm volatile ("pshufb %xmm8,%xmm0"); asm volatile ("pshufb %xmm9,%xmm1"); + asm volatile ("pshufb %xmm10,%xmm2"); + asm volatile ("pshufb %xmm11,%xmm3"); - asm volatile ("pxor %xmm10,%xmm0"); - asm volatile ("pxor %xmm11,%xmm1"); + asm volatile ("pxor %xmm12,%xmm0"); + asm volatile ("pxor %xmm13,%xmm1"); + asm volatile ("pxor %xmm14,%xmm2"); + asm volatile ("pxor %xmm15,%xmm3"); asm volatile ("movdqa %%xmm0,%0" : "=m" (pa[i])); asm volatile ("movdqa %%xmm1,%0" : "=m" (pa[i + 16])); + asm volatile ("movdqa %%xmm2,%0" : "=m" (pa[i + 32])); + asm volatile ("movdqa %%xmm3,%0" : "=m" (pa[i + 48])); } raid_sse_end(); @@ -1858,28 +1751,31 @@ static __always_inline void raid_rec1_ssse3ext_delta(int *id, int *ip, int nd, s /* * RAID recovering for two disks SSSE3 extended implementation */ -static __always_inline void raid_rec2_ssse3ext_delta(int *id, int *ip, int nd, size_t size, void **vv) +static __always_inline void raid_rec2_ssse3ext_delta(int nr, int *id, int *ip, int nd, size_t size, void **vv) { uint8_t **v = (uint8_t **)vv; - uint8_t *p[2]; - uint8_t *pa[2]; - uint8_t G[2 * 2]; - uint8_t V[2 * 2]; + const int N = 2; + uint8_t *p[N]; + uint8_t *pa[N]; + uint8_t G[N * N]; + uint8_t V[N * N]; size_t i; int j, k; + (void)nr; /* unused, it's always 2 */ + /* setup the coefficients matrix */ - for (j = 0; j < 2; ++j) - for (k = 0; k < 2; ++k) - G[j * 2 + k] = A(ip[j], id[k]); + for (j = 0; j < N; ++j) + for (k = 0; k < N; ++k) + G[j * N + k] = A(ip[j], id[k]); /* invert it to solve the system of linear equations */ - raid_invert(G, V, 2); + raid_invert(G, V, N); /* compute delta parity */ - raid_delta_gen(2, id, ip, nd, size, vv); + raid_delta_gen(N, id, ip, nd, size, vv); - for (j = 0; j < 2; ++j) { + for (j = 0; j < N; ++j) { p[j] = v[nd + ip[j]]; pa[j] = v[id[j]]; } @@ -1962,88 +1858,8 @@ static __always_inline void raid_rec2_ssse3ext_delta(int *id, int *ip, int nd, s raid_sse_end(); } -/* - * Recover failure of two data blocks using P and Q SSSE3 extended implementation. - */ -static __always_inline void raid_rec2of2_ssse3ext(int *id, int *ip, int nd, size_t size, void **vv) -{ - uint8_t **v = (uint8_t **)vv; - uint8_t *p; - uint8_t *pa; - uint8_t *q; - uint8_t *qa; - uint8_t C[2]; - size_t i; - - /* get multiplication coefficients */ - C[0] = inv(powgen(id[1] - id[0]) ^ 1); - C[1] = inv(powgen(id[0]) ^ powgen(id[1])); - - /* compute delta parity */ - raid_delta_gen(2, id, ip, nd, size, vv); - - p = v[nd]; - q = v[nd + 1]; - pa = v[id[0]]; - qa = v[id[1]]; - - raid_sse_begin(); - - asm volatile ("movdqa %0,%%xmm7" : : "m" (gfconst16.low4[0])); - - /* keep the four multiplication tables resident */ - asm volatile ("movdqa %0,%%xmm8" : : "m" (raid_gfmulpshufb[C[0]][0][0])); - asm volatile ("movdqa %0,%%xmm9" : : "m" (raid_gfmulpshufb[C[0]][1][0])); - asm volatile ("movdqa %0,%%xmm10" : : "m" (raid_gfmulpshufb[C[1]][0][0])); - asm volatile ("movdqa %0,%%xmm11" : : "m" (raid_gfmulpshufb[C[1]][1][0])); - - for (i = 0; i < size; i += 16) { - /* Pd */ - asm volatile ("movdqa %0,%%xmm0" : : "m" (p[i])); - asm volatile ("pxor %0,%%xmm0" : : "m" (pa[i])); - - /* Qd */ - asm volatile ("movdqa %0,%%xmm1" : : "m" (q[i])); - asm volatile ("pxor %0,%%xmm1" : : "m" (qa[i])); - - /* split Pd and Qd */ - asm volatile ("movdqa %xmm0,%xmm4"); - asm volatile ("movdqa %xmm1,%xmm5"); - asm volatile ("movdqa %xmm0,%xmm2"); - asm volatile ("movdqa %xmm1,%xmm3"); - asm volatile ("psrlw $4,%xmm2"); - asm volatile ("psrlw $4,%xmm3"); - asm volatile ("pand %xmm7,%xmm4"); - asm volatile ("pand %xmm7,%xmm5"); - asm volatile ("pand %xmm7,%xmm2"); - asm volatile ("pand %xmm7,%xmm3"); - - /* C0 * Pd */ - asm volatile ("movdqa %xmm8,%xmm6"); - asm volatile ("pshufb %xmm4,%xmm6"); - asm volatile ("movdqa %xmm9,%xmm12"); - asm volatile ("pshufb %xmm2,%xmm12"); - asm volatile ("pxor %xmm12,%xmm6"); - - /* C1 * Qd */ - asm volatile ("movdqa %xmm10,%xmm12"); - asm volatile ("pshufb %xmm5,%xmm12"); - asm volatile ("pxor %xmm12,%xmm6"); - asm volatile ("movdqa %xmm11,%xmm12"); - asm volatile ("pshufb %xmm3,%xmm12"); - asm volatile ("pxor %xmm12,%xmm6"); - - /* Dy = xmm6, Dx = Pd ^ Dy */ - asm volatile ("pxor %xmm6,%xmm0"); - - asm volatile ("movdqa %%xmm0,%0" : "=m" (pa[i])); - asm volatile ("movdqa %%xmm6,%0" : "=m" (qa[i])); - } - - raid_sse_end(); -} - -static __always_inline void raid_recX_ssse3ext_123(int nr, int *id, int *ip, int nd, size_t size, void **vv) +static __always_inline void raid_recX_ssse3ext_123(int nr, int *id, int *ip, + int nd, size_t size, void **vv) { uint8_t **v = (uint8_t **)vv; uint8_t *p[RAID_PARITY_MAX]; @@ -2292,308 +2108,8 @@ static __always_inline void raid_recX_ssse3ext_123(int nr, int *id, int *ip, int raid_sse_end(); } -/* - * RAID recovering SSSE3 extended implementation optimized for up to five - * failures. - * - * If P is available, keep the complete P delta syndrome in xmm10. - * Reconstruct only nr - 1 missing blocks through the inverse matrix and - * obtain the last block by XORing the reconstructed blocks out of Pdelta. - * - * With at most five failures the low/high syndrome pairs use xmm0..xmm9, - * leaving xmm10 available for the P delta accumulator. - */ -static __always_inline void raid_recX_ssse3ext_12345(int nr, int *id, int *ip, int nd, size_t size, void **vv) -{ - uint8_t **v = (uint8_t **)vv; - uint8_t *p[RAID_PARITY_MAX]; - uint8_t *pa[RAID_PARITY_MAX]; - uint8_t *src[RAID_DATA_MAX]; - uint8_t G[RAID_PARITY_MAX * RAID_PARITY_MAX]; - uint8_t V[RAID_PARITY_MAX * RAID_PARITY_MAX]; - const uint8_t *S[RAID_DATA_MAX][RAID_PARITY_MAX]; - const uint8_t *R[RAID_PARITY_MAX][RAID_PARITY_MAX]; - size_t i; - int d, j, k, s; - int ns; - int has_p; - - BUG_ON(nr < 1 || nr > 5); - - for (j = 0; j < nr; ++j) - for (k = 0; k < nr; ++k) - G[j * nr + k] = A(ip[j], id[k]); - - raid_invert(G, V, nr); - - for (j = 0; j < nr; ++j) { - p[j] = v[nd + ip[j]]; - pa[j] = v[id[j]]; - } - - /* ip[] is ordered. If P is available, it is always ip[0] */ - has_p = ip[0] == 0; - - ns = 0; - k = 0; - - for (d = 0; d < nd; ++d) { - if (k < nr && d == id[k]) { - ++k; - continue; - } - - src[ns] = v[d]; - - for (j = 0; j < nr; ++j) - S[ns][j] = &raid_gfmulpshufb[A(ip[j], d)][0][0]; - - ++ns; - } - - BUG_ON(k != nr); - BUG_ON(ns != nd - nr); - - /* - * If P is available the last inverse-matrix row isn't needed. - * The corresponding missing block is obtained by XOR. - */ - for (j = 0; j < nr - has_p; ++j) - for (k = 0; k < nr; ++k) - R[j][k] = &raid_gfmulpshufb[V[j * nr + k]][0][0]; - - raid_sse_begin(); - - for (i = 0; i < size; i += 16) { - /* - * xmm15 is reused by reconstruction, therefore reload the - * nibble mask on every iteration. - */ - asm volatile ("movdqa %0,%%xmm15" : : "m" (gfconst16.low4[0])); - - /* - * Raw syndrome accumulators: - * - * xmm0 syndrome 0 - * xmm1 syndrome 1 - * xmm2 syndrome 2 - * xmm3 syndrome 3 - * xmm4 syndrome 4 - * - * xmm10 remains free for Pdelta. - */ - asm volatile ("movdqa %0,%%xmm0" : : "m" (p[0][i])); - - if (nr >= 2) - asm volatile ("movdqa %0,%%xmm1" : : "m" (p[1][i])); - - if (nr >= 3) - asm volatile ("movdqa %0,%%xmm2" : : "m" (p[2][i])); - - if (nr >= 4) - asm volatile ("movdqa %0,%%xmm3" : : "m" (p[3][i])); - - if (nr >= 5) - asm volatile ("movdqa %0,%%xmm4" : : "m" (p[4][i])); - - /* add all surviving data contributions */ - for (s = 0; s < ns; ++s) { - const uint8_t **t = S[s]; - - asm volatile ("movdqa %0,%%xmm6" : : "m" (src[s][i])); - - /* - * P has coefficient 1 for every data disk. - * XOR the original source before splitting it. - */ - if (has_p) { - asm volatile ("pxor %xmm6,%xmm0"); - - asm volatile ("movdqa %xmm6,%xmm7"); - asm volatile ("psrlw $4,%xmm7"); - asm volatile ("pand %xmm15,%xmm6"); - asm volatile ("pand %xmm15,%xmm7"); - } else { - asm volatile ("movdqa %xmm6,%xmm7"); - asm volatile ("psrlw $4,%xmm7"); - asm volatile ("pand %xmm15,%xmm6"); - asm volatile ("pand %xmm15,%xmm7"); - - asm volatile ("movdqa %0,%%xmm8" : : "m" (t[0][0])); - asm volatile ("movdqa %0,%%xmm9" : : "m" (t[0][16])); - asm volatile ("pshufb %xmm6,%xmm8"); - asm volatile ("pshufb %xmm7,%xmm9"); - asm volatile ("pxor %xmm8,%xmm0"); - asm volatile ("pxor %xmm9,%xmm0"); - } - - if (nr >= 2) { - asm volatile ("movdqa %0,%%xmm8" : : "m" (t[1][0])); - asm volatile ("movdqa %0,%%xmm9" : : "m" (t[1][16])); - asm volatile ("pshufb %xmm6,%xmm8"); - asm volatile ("pshufb %xmm7,%xmm9"); - asm volatile ("pxor %xmm8,%xmm1"); - asm volatile ("pxor %xmm9,%xmm1"); - } - - if (nr >= 3) { - asm volatile ("movdqa %0,%%xmm8" : : "m" (t[2][0])); - asm volatile ("movdqa %0,%%xmm9" : : "m" (t[2][16])); - asm volatile ("pshufb %xmm6,%xmm8"); - asm volatile ("pshufb %xmm7,%xmm9"); - asm volatile ("pxor %xmm8,%xmm2"); - asm volatile ("pxor %xmm9,%xmm2"); - } - - if (nr >= 4) { - asm volatile ("movdqa %0,%%xmm8" : : "m" (t[3][0])); - asm volatile ("movdqa %0,%%xmm9" : : "m" (t[3][16])); - asm volatile ("pshufb %xmm6,%xmm8"); - asm volatile ("pshufb %xmm7,%xmm9"); - asm volatile ("pxor %xmm8,%xmm3"); - asm volatile ("pxor %xmm9,%xmm3"); - } - - if (nr >= 5) { - asm volatile ("movdqa %0,%%xmm8" : : "m" (t[4][0])); - asm volatile ("movdqa %0,%%xmm9" : : "m" (t[4][16])); - asm volatile ("pshufb %xmm6,%xmm8"); - asm volatile ("pshufb %xmm7,%xmm9"); - asm volatile ("pxor %xmm8,%xmm4"); - asm volatile ("pxor %xmm9,%xmm4"); - } - } - - /* - * Preserve the complete P delta before splitting syndrome 0. - * - * xmm10 = M0 ^ M1 ^ ... ^ M(nr-1) - */ - if (has_p) - asm volatile ("movdqa %xmm0,%xmm10"); - - /* - * Expand backwards to low/high syndrome pairs: - * - * xmm0/xmm1 syndrome 0 low/high - * xmm2/xmm3 syndrome 1 low/high - * xmm4/xmm5 syndrome 2 low/high - * xmm6/xmm7 syndrome 3 low/high - * xmm8/xmm9 syndrome 4 low/high - * - * xmm10 remains the complete remaining P delta. - */ - if (nr >= 5) { - asm volatile ("movdqa %xmm4,%xmm8"); - asm volatile ("movdqa %xmm4,%xmm9"); - asm volatile ("psrlw $4,%xmm9"); - asm volatile ("pand %xmm15,%xmm8"); - asm volatile ("pand %xmm15,%xmm9"); - } - - if (nr >= 4) { - asm volatile ("movdqa %xmm3,%xmm6"); - asm volatile ("movdqa %xmm3,%xmm7"); - asm volatile ("psrlw $4,%xmm7"); - asm volatile ("pand %xmm15,%xmm6"); - asm volatile ("pand %xmm15,%xmm7"); - } - - if (nr >= 3) { - asm volatile ("movdqa %xmm2,%xmm4"); - asm volatile ("movdqa %xmm2,%xmm5"); - asm volatile ("psrlw $4,%xmm5"); - asm volatile ("pand %xmm15,%xmm4"); - asm volatile ("pand %xmm15,%xmm5"); - } - - if (nr >= 2) { - asm volatile ("movdqa %xmm1,%xmm2"); - asm volatile ("movdqa %xmm1,%xmm3"); - asm volatile ("psrlw $4,%xmm3"); - asm volatile ("pand %xmm15,%xmm2"); - asm volatile ("pand %xmm15,%xmm3"); - } - - asm volatile ("movdqa %xmm0,%xmm1"); - asm volatile ("psrlw $4,%xmm1"); - asm volatile ("pand %xmm15,%xmm0"); - asm volatile ("pand %xmm15,%xmm1"); - - /* - * Reconstruct all but the last missing block when P is - * available. - * - * xmm12/xmm13 = low/high output accumulators - * xmm14/xmm15 = multiplication temporaries - * xmm10 = remaining P delta - */ - for (j = 0; j < nr - has_p; ++j) { - const uint8_t **t = R[j]; - - /* coefficient 0 initializes both accumulators */ - asm volatile ("movdqa %0,%%xmm12" : : "m" (t[0][0])); - asm volatile ("movdqa %0,%%xmm13" : : "m" (t[0][16])); - asm volatile ("pshufb %xmm0,%xmm12"); - asm volatile ("pshufb %xmm1,%xmm13"); - - if (nr >= 2) { - asm volatile ("movdqa %0,%%xmm14" : : "m" (t[1][0])); - asm volatile ("movdqa %0,%%xmm15" : : "m" (t[1][16])); - asm volatile ("pshufb %xmm2,%xmm14"); - asm volatile ("pshufb %xmm3,%xmm15"); - asm volatile ("pxor %xmm14,%xmm12"); - asm volatile ("pxor %xmm15,%xmm13"); - } - - if (nr >= 3) { - asm volatile ("movdqa %0,%%xmm14" : : "m" (t[2][0])); - asm volatile ("movdqa %0,%%xmm15" : : "m" (t[2][16])); - asm volatile ("pshufb %xmm4,%xmm14"); - asm volatile ("pshufb %xmm5,%xmm15"); - asm volatile ("pxor %xmm14,%xmm12"); - asm volatile ("pxor %xmm15,%xmm13"); - } - - if (nr >= 4) { - asm volatile ("movdqa %0,%%xmm14" : : "m" (t[3][0])); - asm volatile ("movdqa %0,%%xmm15" : : "m" (t[3][16])); - asm volatile ("pshufb %xmm6,%xmm14"); - asm volatile ("pshufb %xmm7,%xmm15"); - asm volatile ("pxor %xmm14,%xmm12"); - asm volatile ("pxor %xmm15,%xmm13"); - } - - if (nr >= 5) { - asm volatile ("movdqa %0,%%xmm14" : : "m" (t[4][0])); - asm volatile ("movdqa %0,%%xmm15" : : "m" (t[4][16])); - asm volatile ("pshufb %xmm8,%xmm14"); - asm volatile ("pshufb %xmm9,%xmm15"); - asm volatile ("pxor %xmm14,%xmm12"); - asm volatile ("pxor %xmm15,%xmm13"); - } - - asm volatile ("pxor %xmm13,%xmm12"); - - /* - * Remove the reconstructed block from Pdelta. - * After nr - 1 iterations xmm10 contains the final - * missing block. - */ - if (has_p) - asm volatile ("pxor %xmm12,%xmm10"); - - asm volatile ("movdqa %%xmm12,%0" : "=m" (pa[j][i])); - } - - if (has_p) - asm volatile ("movdqa %%xmm10,%0" : "=m" (pa[nr - 1][i])); - } - - raid_sse_end(); -} - -static __always_inline void raid_recX_ssse3ext(int nr, int *id, int *ip, int nd, size_t size, void **vv) +static __always_inline void raid_recX_ssse3ext(int nr, int *id, int *ip, + int nd, size_t size, void **vv) { uint8_t **v = (uint8_t **)vv; uint8_t *p[RAID_PARITY_MAX]; @@ -2937,20 +2453,13 @@ void raid_rec1_ssse3(int nr, int *id, int *ip, int nd, size_t size, void **vv) return; } - raid_rec1_ssse3_delta(id, ip, nd, size, vv); + raid_rec1_ssse3_delta(1, id, ip, nd, size, vv); } void raid_rec2_ssse3(int nr, int *id, int *ip, int nd, size_t size, void **vv) { BUG_ON(nr != 2); - - /* if recovering with P,Q use the specialized function */ - if (ip[0] == 0 && ip[1] == 1) { - raid_rec2of2_ssse3(id, ip, nd, size, vv); - return; - } - - raid_rec2_ssse3_delta(id, ip, nd, size, vv); + raid_rec2_ssse3_delta(2, id, ip, nd, size, vv); } void raid_rec3_ssse3(int nr, int *id, int *ip, int nd, size_t size, void **vv) @@ -2988,20 +2497,13 @@ void raid_rec1_ssse3ext(int nr, int *id, int *ip, int nd, size_t size, void **vv return; } - raid_rec1_ssse3ext_delta(id, ip, nd, size, vv); + raid_rec1_ssse3ext_delta(1, id, ip, nd, size, vv); } void raid_rec2_ssse3ext(int nr, int *id, int *ip, int nd, size_t size, void **vv) { BUG_ON(nr != 2); - - /* if recovering with P,Q use the specialized function */ - if (ip[0] == 0 && ip[1] == 1) { - raid_rec2of2_ssse3ext(id, ip, nd, size, vv); - return; - } - - raid_rec2_ssse3ext_delta(id, ip, nd, size, vv); + raid_rec2_ssse3ext_delta(2, id, ip, nd, size, vv); } void raid_rec3_ssse3ext(int nr, int *id, int *ip, int nd, size_t size, void **vv) @@ -3013,13 +2515,13 @@ void raid_rec3_ssse3ext(int nr, int *id, int *ip, int nd, size_t size, void **vv void raid_rec4_ssse3ext(int nr, int *id, int *ip, int nd, size_t size, void **vv) { BUG_ON(nr != 4); - raid_recX_ssse3ext_12345(4, id, ip, nd, size, vv); + raid_recX_ssse3ext(4, id, ip, nd, size, vv); } void raid_rec5_ssse3ext(int nr, int *id, int *ip, int nd, size_t size, void **vv) { BUG_ON(nr != 5); - raid_recX_ssse3ext_12345(5, id, ip, nd, size, vv); + raid_recX_ssse3ext(5, id, ip, nd, size, vv); } void raid_rec6_ssse3ext(int nr, int *id, int *ip, int nd, size_t size, void **vv) @@ -3027,6 +2529,7 @@ void raid_rec6_ssse3ext(int nr, int *id, int *ip, int nd, size_t size, void **vv BUG_ON(nr != 6); raid_recX_ssse3ext(6, id, ip, nd, size, vv); } + #endif void raid_register_ssse3(void) diff --git a/raid/test.c b/raid/test.c index 04b11177..ef4e907b 100644 --- a/raid/test.c +++ b/raid/test.c @@ -348,11 +348,55 @@ int raid_test_poly(unsigned mode) #define test_setup(i) f[i - 1][nf[i - 1]++] -static void raid_test_setup_rec(int mode, int np, raid_rec_fn *f[RAID_PARITY_MAX][32], int nf[RAID_PARITY_MAX]) +int raid_test_rec(int mode, int nd, size_t size) { + void (*f[RAID_PARITY_MAX][32])(int nr, int *id, int *ip, int nd, size_t size, void **vbuf); + void *v_alloc; + void **v; + void **data; + void **parity; + void **test; + void *data_save[RAID_PARITY_MAX]; + void *parity_save[RAID_PARITY_MAX]; + void *waste; + int nv; + int id[RAID_PARITY_MAX]; + int ip[RAID_PARITY_MAX]; int i; + int j; + int nr; + int nf[RAID_PARITY_MAX]; + int np; - (void)mode; + raid_mode(mode); + if (mode == RAID_MODE_VANDERMONDE_RAID) + np = 3; + else + np = RAID_PARITY_MAX; + + nv = nd + np * 2 + 2; + + v = raid_malloc_vector(nv, size, &v_alloc); + if (!v) { + /* LCOV_EXCL_START */ + return -1; + /* LCOV_EXCL_STOP */ + } + + data = v; + parity = v + nd; + test = v + nd + np; + + for (i = 0; i < np; ++i) + parity_save[i] = parity[i]; + + memset(v[nv - 2], 0, size); + raid_zero(v[nv - 2]); + + waste = v[nv - 1]; + + /* fill with pseudo-random data with the arbitrary seed "1" */ + raid_mrand_vector(1, nd, size, v); /* counters of functions for each parity level */ for (i = 0; i < np; ++i) @@ -600,60 +644,6 @@ static void raid_test_setup_rec(int mode, int np, raid_rec_fn *f[RAID_PARITY_MAX } #endif } -} - -int raid_test_rec(int mode, int nd, size_t size) -{ - raid_rec_fn *f[RAID_PARITY_MAX][32]; - void *v_alloc; - void **v; - void **data; - void **parity; - void **test; - void *data_save[RAID_PARITY_MAX]; - void *parity_save[RAID_PARITY_MAX]; - void *waste; - int nv; - int id[RAID_PARITY_MAX]; - int ip[RAID_PARITY_MAX]; - int i; - int j; - int nr; - int nf[RAID_PARITY_MAX]; - int np; - - raid_mode(mode); - if (mode == RAID_MODE_VANDERMONDE_RAID) - np = 3; - else - np = RAID_PARITY_MAX; - - nv = nd + np * 2 + 2; - - v = raid_malloc_vector(nv, size, &v_alloc); - if (!v) { - /* LCOV_EXCL_START */ - return -1; - /* LCOV_EXCL_STOP */ - } - - data = v; - parity = v + nd; - test = v + nd + np; - - for (i = 0; i < np; ++i) - parity_save[i] = parity[i]; - - memset(v[nv - 2], 0, size); - raid_zero(v[nv - 2]); - - waste = v[nv - 1]; - - /* fill with pseudo-random data with the arbitrary seed "1" */ - raid_mrand_vector(1, nd, size, v); - - /* setup recov functions */ - raid_test_setup_rec(mode, np, f, nf); /* compute the parity */ raid_gen_ref(nd, np, size, v); @@ -719,7 +709,7 @@ bail: int raid_test_tail(int mode, int nd_max, size_t size) { - raid_rec_fn *f[RAID_PARITY_MAX][32]; + void (*f[RAID_PARITY_MAX][32])(int nr, int *id, int *ip, int nd, size_t size, void **vbuf); void *v_alloc; void **v; void **data; @@ -768,8 +758,252 @@ int raid_test_tail(int mode, int nd_max, size_t size) /* fill with pseudo-random data with the arbitrary seed "1" */ raid_mrand_vector(1, nd_max, size, v); + /* counters of functions for each parity level */ + for (i = 0; i < np; ++i) + nf[i] = 0; + /* setup recov functions */ - raid_test_setup_rec(mode, np, f, nf); + for (i = 1; i <= np; ++i) { + switch (i) { + case 1: + test_setup(i) = raid_rec1_int8; + break; + case 2: + test_setup(i) = raid_rec2_int8; + break; + default: + test_setup(i) = raid_recX_int8; + break; + } +#ifdef CONFIG_X86 + if (raid_cpu_has_ssse3()) { + switch (i) { + case 1: + test_setup(i) = raid_rec1_ssse3; + break; + case 2: + test_setup(i) = raid_rec2_ssse3; + break; + case 3: + test_setup(i) = raid_rec3_ssse3; + break; + case 4: + test_setup(i) = raid_rec4_ssse3; + break; + case 5: + test_setup(i) = raid_rec5_ssse3; + break; + case 6: + test_setup(i) = raid_rec6_ssse3; + break; + } +#ifdef CONFIG_X86_64 + switch (i) { + case 1: + test_setup(i) = raid_rec1_ssse3ext; + break; + case 2: + test_setup(i) = raid_rec2_ssse3ext; + break; + case 3: + test_setup(i) = raid_rec3_ssse3ext; + break; + case 4: + test_setup(i) = raid_rec4_ssse3ext; + break; + case 5: + test_setup(i) = raid_rec5_ssse3ext; + break; + case 6: + test_setup(i) = raid_rec6_ssse3ext; + break; + } +#endif + } + if (raid_cpu_has_avx2()) { + switch (i) { + case 1: + test_setup(i) = raid_rec1_avx2; + break; + case 2: + test_setup(i) = raid_rec2_avx2; + break; + case 3: + test_setup(i) = raid_rec3_avx2; + break; + case 4: + test_setup(i) = raid_rec4_avx2; + break; + case 5: + test_setup(i) = raid_rec5_avx2; + break; + case 6: + test_setup(i) = raid_rec6_avx2; + break; + } + } +#ifdef CONFIG_X86_64 + if (raid_cpu_has_avx512bw()) { + switch (i) { + case 1: + test_setup(i) = raid_rec1_avx512bw; + break; + case 2: + test_setup(i) = raid_rec2_avx512bw; + break; + case 3: + test_setup(i) = raid_rec3_avx512bw; + break; + case 4: + test_setup(i) = raid_rec4_avx512bw; + break; + case 5: + test_setup(i) = raid_rec5_avx512bw; + break; + case 6: + test_setup(i) = raid_rec6_avx512bw; + break; + } + } + if (mode == RAID_MODE_CAUCHY_RAID || mode == RAID_MODE_CAUCHY_AES) { + if (raid_cpu_has_avx2gfni()) { + if (mode == RAID_MODE_CAUCHY_AES) { + switch (i) { + case 1: + test_setup(i) = raid_rec1_avx2gfni_aes; + break; + case 2: + test_setup(i) = raid_rec2_avx2gfni_aes; + break; + case 3: + test_setup(i) = raid_rec3_avx2gfni_aes; + break; + case 4: + test_setup(i) = raid_rec4_avx2gfni_aes; + break; + case 5: + test_setup(i) = raid_rec5_avx2gfni_aes; + break; + case 6: + test_setup(i) = raid_rec6_avx2gfni_aes; + break; + } + } else { + switch (i) { + case 1: + test_setup(i) = raid_rec1_avx2gfni_raid; + break; + case 2: + test_setup(i) = raid_rec2_avx2gfni_raid; + break; + case 3: + test_setup(i) = raid_rec3_avx2gfni_raid; + break; + case 4: + test_setup(i) = raid_rec4_avx2gfni_raid; + break; + case 5: + test_setup(i) = raid_rec5_avx2gfni_raid; + break; + case 6: + test_setup(i) = raid_rec6_avx2gfni_raid; + break; + } + } + } + if (raid_cpu_has_avx512gfni()) { + if (mode == RAID_MODE_CAUCHY_AES) { + switch (i) { + case 1: + test_setup(i) = raid_rec1_avx512gfni_aes; + break; + case 2: + test_setup(i) = raid_rec2_avx512gfni_aes; + break; + case 3: + test_setup(i) = raid_rec3_avx512gfni_aes; + break; + case 4: + test_setup(i) = raid_rec4_avx512gfni_aes; + break; + case 5: + test_setup(i) = raid_rec5_avx512gfni_aes; + break; + case 6: + test_setup(i) = raid_rec6_avx512gfni_aes; + break; + } + } else { + switch (i) { + case 1: + test_setup(i) = raid_rec1_avx512gfni_raid; + break; + case 2: + test_setup(i) = raid_rec2_avx512gfni_raid; + break; + case 3: + test_setup(i) = raid_rec3_avx512gfni_raid; + break; + case 4: + test_setup(i) = raid_rec4_avx512gfni_raid; + break; + case 5: + test_setup(i) = raid_rec5_avx512gfni_raid; + break; + case 6: + test_setup(i) = raid_rec6_avx512gfni_raid; + break; + } + } + } + } +#endif +#endif +#ifdef CONFIG_NEON + switch (i) { + case 1: + test_setup(i) = raid_rec1_neon; + break; + case 2: + test_setup(i) = raid_rec2_neon; + break; + case 3: + test_setup(i) = raid_rec3_neon; + break; + case 4: + test_setup(i) = raid_rec4_neon; + break; + case 5: + test_setup(i) = raid_rec5_neon; + break; + case 6: + test_setup(i) = raid_rec6_neon; + break; + } +#endif +#ifdef CONFIG_NEON32 + switch (i) { + case 1: + test_setup(i) = raid_rec1_neon32; + break; + case 2: + test_setup(i) = raid_rec2_neon32; + break; + case 3: + test_setup(i) = raid_rec3_neon32; + break; + case 4: + test_setup(i) = raid_rec4_neon32; + break; + case 5: + test_setup(i) = raid_rec5_neon32; + break; + case 6: + test_setup(i) = raid_rec6_neon32; + break; + } +#endif + } /* test all disk counts from 1 to nd_max */ for (nd = 1; nd <= nd_max; ++nd) { @@ -844,9 +1078,47 @@ bail: /* LCOV_EXCL_STOP */ } -static void raid_test_setup_par(int mode, int np, raid_gen_fn *f[RAID_PARITY_MAX][32], int nf[RAID_PARITY_MAX]) +int raid_test_par(int mode, int nd, size_t size) { - int i; + void (*f[RAID_PARITY_MAX][32])(int nd, size_t size, void **vbuf); + void *v_alloc; + void **v; + int nv; + int i, j, k; + int nf[RAID_PARITY_MAX]; + int np; + + raid_mode(mode); + if (mode == RAID_MODE_VANDERMONDE_RAID) + np = 3; + else + np = RAID_PARITY_MAX; + + nv = nd + np * 2; + + v = raid_malloc_vector(nv, size, &v_alloc); + if (!v) { + /* LCOV_EXCL_START */ + return -1; + /* LCOV_EXCL_STOP */ + } + + /* check memory */ + if (raid_mtest_vector(nv, size, v) != 0) { + /* LCOV_EXCL_START */ + goto bail; + /* LCOV_EXCL_STOP */ + } + + /* fill with pseudo-random data with the arbitrary seed "2" */ + raid_mrand_vector(2, nv, size, v); + + /* compute the parity */ + raid_gen_ref(nd, np, size, v); + + /* copy in back buffers */ + for (i = 0; i < np; ++i) + memcpy(v[nd + np + i], v[nd + i], size); /* counters of functions for each parity level */ for (i = 0; i < np; ++i) @@ -1056,52 +1328,6 @@ static void raid_test_setup_par(int mode, int np, raid_gen_fn *f[RAID_PARITY_MAX #endif #endif } -} - -int raid_test_par(int mode, int nd, size_t size) -{ - raid_gen_fn *f[RAID_PARITY_MAX][32]; - void *v_alloc; - void **v; - int nv; - int i, j, k; - int nf[RAID_PARITY_MAX]; - int np; - - raid_mode(mode); - if (mode == RAID_MODE_VANDERMONDE_RAID) - np = 3; - else - np = RAID_PARITY_MAX; - - nv = nd + np * 2; - - v = raid_malloc_vector(nv, size, &v_alloc); - if (!v) { - /* LCOV_EXCL_START */ - return -1; - /* LCOV_EXCL_STOP */ - } - - /* check memory */ - if (raid_mtest_vector(nv, size, v) != 0) { - /* LCOV_EXCL_START */ - goto bail; - /* LCOV_EXCL_STOP */ - } - - /* fill with pseudo-random data with the arbitrary seed "2" */ - raid_mrand_vector(2, nv, size, v); - - /* compute the parity */ - raid_gen_ref(nd, np, size, v); - - /* copy in back buffers */ - for (i = 0; i < np; ++i) - memcpy(v[nd + np + i], v[nd + i], size); - - /* setup parity generation functions */ - raid_test_setup_par(mode, np, f, nf); /* check all the functions */ for (k = 0; k < np; ++k) { diff --git a/raid/test/Makefile b/raid/test/Makefile index 0471ad3f..c4f29947 100644 --- a/raid/test/Makefile +++ b/raid/test/Makefile @@ -64,16 +64,11 @@ mktables: mktables.o tables.c: mktables ./mktables > tables.c -TEST_COUNT ?= 32 -TEST_SIZE ?= 256 -SDE_TEST_COUNT ?= 8 -SDE_TEST_SIZE ?= 256 - # Use this target to run a complete test test: ./selftest ./speedtest - ./fulltest $(TEST_COUNT) $(TEST_SIZE) + ./fulltest # Use this target to run a coverage test using lcov covtest: @@ -91,10 +86,10 @@ sdecovtest: $(MAKE) clean $(MAKE) lcov_reset $(MAKE) COVERAGE=1 all - $(SDE) -p4p -- ./fulltest $(SDE_TEST_COUNT) $(SDE_TEST_SIZE) - $(SDE) -mrm -- ./fulltest $(SDE_TEST_COUNT) $(SDE_TEST_SIZE) - $(SDE) -nhm -- ./fulltest $(SDE_TEST_COUNT) $(SDE_TEST_SIZE) - $(SDE) -hsw -- ./fulltest $(SDE_TEST_COUNT) $(SDE_TEST_SIZE) + $(SDE) -p4p -- ./fulltest + $(SDE) -mrm -- ./fulltest + $(SDE) -nhm -- ./fulltest + $(SDE) -hsw -- ./fulltest $(SDE) -p4p -- ./selftest $(SDE) -mrm -- ./selftest $(SDE) -nhm -- ./selftest @@ -114,7 +109,7 @@ sdetest: $(SDE) -hsw -- ./selftest $(SDE) -skx -- ./selftest $(SDE) -icl -- ./selftest - $(SDE) -icl -- ./fulltest $(SDE_TEST_COUNT) $(SDE_TEST_SIZE) + $(SDE) -icl -- ./fulltest # Use this target to run a speed test on Ice Lake simulator sdespeed: diff --git a/raid/test/fulltest.c b/raid/test/fulltest.c index 011dcaf2..c1611359 100644 --- a/raid/test/fulltest.c +++ b/raid/test/fulltest.c @@ -21,32 +21,11 @@ #ifdef COVERAGE #define TEST_COUNT 10 #else -#define TEST_COUNT 24 +#define TEST_COUNT 32 #endif -int main(int argc, char *argv[]) +int main(void) { - int test_count = TEST_COUNT; - int test_size = TEST_SIZE; - - if (argc > 1) { - test_count = atoi(argv[1]); - if (test_count < RAID_PARITY_MAX || test_count > RAID_DATA_MAX) { - printf("Invalid TEST_COUNT %d (must be between %d and %d)\n", - test_count, RAID_PARITY_MAX, RAID_DATA_MAX); - return EXIT_FAILURE; - } - } - - if (argc > 2) { - test_size = atoi(argv[2]); - if (test_size <= 0 || (test_size % 64) != 0) { - printf("Invalid TEST_SIZE %d (must be positive and multiple of 64)\n", - test_size); - return EXIT_FAILURE; - } - } - printf("Full sanity test for the RAID Cauchy library\n\n"); raid_init(); @@ -74,10 +53,7 @@ int main(int argc, char *argv[]) #endif #endif - if (test_count >= 32) - printf("\nPlease wait about 60 seconds...\n\n"); - else - printf("\nPlease wait...\n\n"); + printf("\nPlease wait about 60 seconds...\n\n"); printf("Test sorting...\n"); if (raid_test_sort() != 0) { @@ -108,7 +84,7 @@ int main(int argc, char *argv[]) } printf("Test Vandermonde RAID parity generation with %u data disks...\n", RAID_DATA_MAX); - if (raid_test_par(RAID_MODE_VANDERMONDE_RAID, RAID_DATA_MAX, test_size) != 0) { + if (raid_test_par(RAID_MODE_VANDERMONDE_RAID, RAID_DATA_MAX, TEST_SIZE) != 0) { /* LCOV_EXCL_START */ goto bail; /* LCOV_EXCL_STOP */ @@ -116,7 +92,7 @@ int main(int argc, char *argv[]) printf("Test Cauchy RAID parity generation with 1-%u data disks...\n", RAID_DATA_MAX); for (int i = 1; i <= RAID_DATA_MAX; ++i) { - if (raid_test_par(RAID_MODE_CAUCHY_RAID, i, test_size) != 0) { + if (raid_test_par(RAID_MODE_CAUCHY_RAID, i, TEST_SIZE) != 0) { /* LCOV_EXCL_START */ goto bail; /* LCOV_EXCL_STOP */ @@ -124,7 +100,7 @@ int main(int argc, char *argv[]) } printf("Test Cauchy AES parity generation with 1-%u data disks...\n", RAID_DATA_MAX); for (int i = 1; i <= RAID_DATA_MAX; ++i) { - if (raid_test_par(RAID_MODE_CAUCHY_AES, i, test_size) != 0) { + if (raid_test_par(RAID_MODE_CAUCHY_AES, i, TEST_SIZE) != 0) { /* LCOV_EXCL_START */ goto bail; /* LCOV_EXCL_STOP */ @@ -132,42 +108,44 @@ int main(int argc, char *argv[]) } printf("Test Vandermonde RAID tail recovering with 1-%u data disks...\n", RAID_DATA_MAX); - if (raid_test_tail(RAID_MODE_VANDERMONDE_RAID, RAID_DATA_MAX, test_size) != 0) { + if (raid_test_tail(RAID_MODE_VANDERMONDE_RAID, RAID_DATA_MAX, TEST_SIZE) != 0) { /* LCOV_EXCL_START */ goto bail; /* LCOV_EXCL_STOP */ } printf("Test Cauchy RAID tail recovering with 1-%u data disks...\n", RAID_DATA_MAX); - if (raid_test_tail(RAID_MODE_CAUCHY_RAID, RAID_DATA_MAX, test_size) != 0) { + if (raid_test_tail(RAID_MODE_CAUCHY_RAID, RAID_DATA_MAX, TEST_SIZE) != 0) { /* LCOV_EXCL_START */ goto bail; /* LCOV_EXCL_STOP */ } printf("Test Cauchy AES tail recovering with 1-%u data disks...\n", RAID_DATA_MAX); - if (raid_test_tail(RAID_MODE_CAUCHY_AES, RAID_DATA_MAX, test_size) != 0) { + if (raid_test_tail(RAID_MODE_CAUCHY_AES, RAID_DATA_MAX, TEST_SIZE) != 0) { /* LCOV_EXCL_START */ goto bail; /* LCOV_EXCL_STOP */ } - printf("Test Vandermonde RAID recovering with all combinations of %u data and 3 parity blocks...\n", test_count); - if (raid_test_rec(RAID_MODE_VANDERMONDE_RAID, test_count, test_size) != 0) { + printf("Test Vandermonde RAID recovering with all combinations of %u data and 3 parity blocks...\n", TEST_COUNT); + if (raid_test_rec(RAID_MODE_VANDERMONDE_RAID, TEST_COUNT, TEST_SIZE) != 0) { /* LCOV_EXCL_START */ goto bail; /* LCOV_EXCL_STOP */ } - printf("Test Cauchy RAID recovering with all combinations of %u data and 6 parity blocks...\n", test_count); - if (raid_test_rec(RAID_MODE_CAUCHY_RAID, test_count, test_size) != 0) { + + printf("Test Cauchy RAID recovering with all combinations of %u data and 6 parity blocks...\n", TEST_COUNT); + if (raid_test_rec(RAID_MODE_CAUCHY_RAID, TEST_COUNT, TEST_SIZE) != 0) { /* LCOV_EXCL_START */ goto bail; /* LCOV_EXCL_STOP */ } - printf("Test Cauchy AES recovering with all combinations of %u data and 6 parity blocks...\n", test_count); - if (raid_test_rec(RAID_MODE_CAUCHY_AES, test_count, test_size) != 0) { + + printf("Test Cauchy AES recovering with all combinations of %u data and 6 parity blocks...\n", TEST_COUNT); + if (raid_test_rec(RAID_MODE_CAUCHY_AES, TEST_COUNT, TEST_SIZE) != 0) { /* LCOV_EXCL_START */ goto bail; /* LCOV_EXCL_STOP */