Compare commits

...

21 commits

Author SHA1 Message Date
Andrea Mazzoleni
fd65dbd9ea Fix undefined behavior by making TommyDS foreach callback signatures take void*
Some checks are pending
Build / build-mac (push) Waiting to run
Build / build-linux (push) Waiting to run
Build / build-arm32 (push) Waiting to run
Build / build-win (push) Waiting to run
CodeQL Advanced / Analyze (c-cpp) (push) Waiting to run
CodeQL Advanced / Analyze (actions) (push) Waiting to run
2026-08-24 23:03:00 +02:00
Andrea Mazzoleni
7250521e66 Clarify fulltest scope and test_count limits in raid README 2026-08-24 22:16:52 +02:00
Andrea Mazzoleni
e43bdda22b Return -1 in raid_check and raid_scan when block size is 0 2026-08-24 22:11:52 +02:00
Andrea Mazzoleni
46a09a380a Check maximum basic CPUID leaf before querying leaf 7 in AVX probing 2026-08-24 22:06:17 +02:00
Andrea Mazzoleni
5ed6a29db2 Document memory helpers, freeing semantics, and design invariants 2026-08-24 22:01:40 +02:00
Andrea Mazzoleni
b9974b7873 Include missing raid docs, mktables, and invtestx in EXTRA_DIST 2026-08-24 21:53:08 +02:00
Andrea Mazzoleni
306f847689 Reset global zero buffer with raid_zero(0) in raid_selftest cleanup 2026-08-24 21:53:08 +02:00
Andrea Mazzoleni
eba07d2173 Include <stddef.h> in raid.h to make the public header self-contained 2026-08-24 21:53:08 +02:00
Andrea Mazzoleni
453fb20d83 Avoid UB in raid_gen memcpy when output aliases input with nd == 1 2026-08-24 21:53:07 +02:00
Andrea Mazzoleni
88442cb10c Avoid writing to healthy parities in raid_rec() using local vector remapping 2026-08-24 21:53:07 +02:00
Andrea Mazzoleni
c1a78092c4 Fix RAID documentation accuracy 2026-08-24 21:53:07 +02:00
Andrea Mazzoleni
03d82a71f4 Document raid_selftest startup execution and mode selection requirements 2026-08-24 21:53:07 +02:00
Andrea Mazzoleni
df4667ffd5 Add NOTES 2026-08-24 21:53:07 +02:00
Andrea Mazzoleni
0ebe2e1e5e Add OTHERS 2026-08-24 21:53:07 +02:00
Andrea Mazzoleni
3f4d7e15fa Reduce SSSE3ext REC1 unrolling from 64 to 32 bytes for better performance 2026-08-24 21:53:07 +02:00
Andrea Mazzoleni
048d0c14b1 Make TEST_COUNT and TEST_SIZE parametric in raid fulltest and test Makefile 2026-08-24 21:53:07 +02:00
Andrea Mazzoleni
4d97df38ce Optimize recovery with P by deriving the final missing block via XOR 2026-08-24 21:53:07 +02:00
Andrea Mazzoleni
d3e67b2fdf Extract common recovery function setup 2026-08-24 17:39:29 +02:00
Andrea Mazzoleni
e74b03a062 Remove unused argument from recovery functions 2026-08-24 17:39:29 +02:00
Andrea Mazzoleni
46ebce4e3c Add specialized P+Q REC2OF2 recovery to all SIMD backends 2026-08-24 17:39:29 +02:00
Andrea Mazzoleni
d4184b9aee Harden public RAID API argument validation 2026-08-24 17:39:29 +02:00
35 changed files with 4121 additions and 704 deletions

View file

@ -195,11 +195,16 @@ 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 \

5
TODO
View file

@ -24,11 +24,6 @@ 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

View file

@ -60,8 +60,10 @@ static inline tommy_uint32_t hash_hash(struct snapraid_hash* hash)
return tommy_hash_u32(0, hash->hash, HASH_MAX);
}
void hash_free(struct snapraid_hash* hash)
static void hash_free(void* void_hash)
{
struct snapraid_hash* hash = void_hash;
free(hash);
}
@ -122,7 +124,7 @@ void state_dup(struct snapraid_state* state)
}
}
tommy_hashdyn_foreach(&hashset, (tommy_foreach_func*)hash_free);
tommy_hashdyn_foreach(&hashset, hash_free);
tommy_hashdyn_done(&hashset);
msg_status("\n");

View file

@ -24,8 +24,10 @@ struct snapraid_content* content_alloc(const char* path, uint64_t dev)
return content;
}
void content_free(struct snapraid_content* content)
void content_free(void* void_content)
{
struct snapraid_content* content = void_content;
free(content);
}
@ -453,8 +455,10 @@ struct snapraid_file* file_dup(struct snapraid_file* copy)
return file;
}
void file_free(struct snapraid_file* file)
void file_free(void* void_file)
{
struct snapraid_file* file = void_file;
free(file->sub);
file->sub = 0;
free(file->blockvec);
@ -679,8 +683,10 @@ struct snapraid_extent* extent_alloc(block_off_t parity_pos, struct snapraid_fil
return extent;
}
void extent_free(struct snapraid_extent* extent)
void extent_free(void* void_extent)
{
struct snapraid_extent* extent = void_extent;
free(extent);
}
@ -730,8 +736,10 @@ struct snapraid_link* link_alloc(const char* sub, const char* linkto, unsigned l
return slink;
}
void link_free(struct snapraid_link* slink)
void link_free(void* void_link)
{
struct snapraid_link* slink = void_link;
free(slink->sub);
free(slink->linkto);
free(slink);
@ -764,8 +772,10 @@ struct snapraid_dir* dir_alloc(const char* sub)
return dir;
}
void dir_free(struct snapraid_dir* dir)
void dir_free(void* void_dir)
{
struct snapraid_dir* dir = void_dir;
free(dir->sub);
free(dir);
}
@ -820,8 +830,10 @@ void dealloc_import(struct snapraid_dealloc* dealloc, struct snapraid_file* file
}
}
void dealloc_free(struct snapraid_dealloc* dealloc)
void dealloc_free(void* void_dealloc)
{
struct snapraid_dealloc* dealloc = void_dealloc;
free(dealloc->sub);
free(dealloc->blockhash);
free(dealloc);
@ -890,19 +902,21 @@ struct snapraid_disk* disk_alloc(const char* name, const char* dir, uint64_t dev
return disk;
}
void disk_free(struct snapraid_disk* disk)
void disk_free(void* void_disk)
{
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);
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_hashdyn_done(&disk->inodeset);
tommy_hashdyn_done(&disk->pathset);
tommy_hashdyn_done(&disk->stampset);
tommy_list_foreach(&disk->linklist, (tommy_foreach_func*)link_free);
tommy_list_foreach(&disk->linklist, link_free);
tommy_hashdyn_done(&disk->linkset);
tommy_list_foreach(&disk->dirlist, (tommy_foreach_func*)dir_free);
tommy_list_foreach(&disk->dirlist, dir_free);
tommy_hashdyn_done(&disk->dirset);
tommy_list_foreach(&disk->dealloclist, (tommy_foreach_func*)dealloc_free);
tommy_list_foreach(&disk->dealloclist, dealloc_free);
#if HAVE_THREAD
thread_mutex_destroy(&disk->fs_mutex);
@ -937,8 +951,10 @@ struct snapraid_extra* extra_alloc(const char* name, const char* dir, uint64_t d
return extra;
}
void extra_free(struct snapraid_extra* extra)
void extra_free(void* void_extra)
{
struct snapraid_extra* extra = void_extra;
free(extra);
}
@ -1565,8 +1581,10 @@ struct snapraid_map* map_alloc(const char* name, unsigned position, block_off_t
return map;
}
void map_free(struct snapraid_map* map)
void map_free(void* void_map)
{
struct snapraid_map* map = void_map;
free(map);
}
@ -1584,8 +1602,10 @@ static int bucket_cmp(const void* void_a, const void* void_b)
return 0;
}
void bucket_free(struct snapraid_bucket* bucket)
void bucket_free(void* void_bucket)
{
struct snapraid_bucket* bucket = void_bucket;
free(bucket);
}
@ -1621,7 +1641,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, (tommy_foreach_func*)bucket_free);
tommy_list_foreach(bucket_list, bucket_free);
tommy_list_init(bucket_list);
log_tag("list:bucket_begin\n");

View file

@ -574,7 +574,7 @@ struct snapraid_content* content_alloc(const char* path, uint64_t dev);
/**
* Deallocate a content.
*/
void content_free(struct snapraid_content* content);
void content_free(void* void_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(struct snapraid_file* file);
void file_free(void* void_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(struct snapraid_extent* extent);
void extent_free(void* void_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(struct snapraid_link* slink);
void link_free(void* void_link);
/**
* Compare a link with a name.
@ -1044,7 +1044,7 @@ struct snapraid_dir* dir_alloc(const char* name);
/**
* Deallocate a dir.
*/
void dir_free(struct snapraid_dir* dir);
void dir_free(void* void_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(struct snapraid_dealloc* dealloc);
void dealloc_free(void* void_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(struct snapraid_disk* disk);
void disk_free(void* void_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(struct snapraid_extra* other);
void extra_free(void* void_extra);
/**
* 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(struct snapraid_map* map);
void map_free(void* void_map);
/**
* Mask used to store additional information in the info bits.
@ -1335,7 +1335,7 @@ struct snapraid_bucket {
tommy_node node;
};
void bucket_free(struct snapraid_bucket* bucket);
void bucket_free(void* void_bucket);
/**
* Insert an bucket record into the hashtable

View file

@ -204,8 +204,10 @@ 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(struct snapraid_import_file* file)
void import_file_free(void* void_file)
{
struct snapraid_import_file* file = void_file;
free(file->path);
free(file->blockimp);
free(file);

View file

@ -44,7 +44,7 @@ struct snapraid_import_file {
/**
* Deallocate an import file.
*/
void import_file_free(struct snapraid_import_file* file);
void import_file_free(void* void_file);
/**
* Fetch a block from the specified hash.

View file

@ -35,8 +35,10 @@ static inline tommy_uint32_t pool_hash(const char* file)
return tommy_hash_u32(0, file, strlen(file));
}
void pool_free(struct snapraid_pool* pool)
static void pool_free(void* void_pool)
{
struct snapraid_pool* pool = void_pool;
free(pool);
}
@ -442,12 +444,12 @@ void state_pool(struct snapraid_state* state)
msg_progress("Cleaning...\n");
/* delete all the remaining links */
tommy_hashdyn_foreach_arg(&poolset, (tommy_foreach_arg_func*)remove_link, pool_dir);
tommy_hashdyn_foreach_arg(&poolset, remove_link, pool_dir);
/* delete empty dirs */
clean_dir(pool_dir);
tommy_hashdyn_foreach(&poolset, (tommy_foreach_func*)pool_free);
tommy_hashdyn_foreach(&poolset, pool_free);
tommy_hashdyn_done(&poolset);
if (count)

View file

@ -74,8 +74,9 @@ static struct snapraid_scan* scan_alloc(struct snapraid_state* state, struct sna
return scan;
}
static void scan_free(struct snapraid_scan* scan)
static void scan_free(void* void_scan)
{
struct snapraid_scan* scan = void_scan;
#if HAVE_THREAD
thread_mutex_destroy(&scan->disk->stamp_mutex);
#endif
@ -2249,7 +2250,7 @@ static int state_diffscan(struct snapraid_state* state, int is_diff)
log_flush();
tommy_list_foreach(&scanlist, (tommy_foreach_func*)scan_free);
tommy_list_foreach(&scanlist, scan_free);
/* check the file-system on all disks */
state_fscheck(state, "after scan");

View file

@ -25,8 +25,10 @@ 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(struct snapraid_search_file* file)
void search_file_free(void* void_file)
{
struct snapraid_search_file* file = void_file;
free(file->path);
free(file);
}

View file

@ -28,7 +28,7 @@ struct snapraid_search_file {
/**
* Deallocate a search file.
*/
void search_file_free(struct snapraid_search_file* file);
void search_file_free(void* void_file);
/**
* Fetch a file from the size, timestamp and name.

View file

@ -2131,8 +2131,8 @@ int snapraid_main(int argc, char* argv[])
#endif
state_done(&state);
tommy_list_foreach(&filterlist_file, (tommy_foreach_func*)filter_free);
tommy_list_foreach(&filterlist_disk, (tommy_foreach_func*)filter_free);
tommy_list_foreach(&filterlist_file, filter_free);
tommy_list_foreach(&filterlist_disk, filter_free);
app_done();
os_done();

View file

@ -202,19 +202,19 @@ void state_init(struct snapraid_state* state)
void state_done(struct snapraid_state* state)
{
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_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_hashdyn_done(&state->importset);
tommy_hashdyn_done(&state->previmportset);
tommy_hashdyn_done(&state->searchset);
tommy_arrayblkof_done(&state->infoarr);
tommy_list_foreach(&state->bucketlist, (tommy_foreach_func*)bucket_free);
tommy_list_foreach(&state->bucketlist, bucket_free);
}
/**
@ -4149,7 +4149,7 @@ static void* state_write_thread(void* arg)
return 0;
bail:
tommy_hashdyn_foreach(&bucket_hash, (tommy_foreach_func*)bucket_free);
tommy_hashdyn_foreach(&bucket_hash, 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, (tommy_foreach_func*)dealloc_free);
tommy_list_foreach(&disk->dealloclist, dealloc_free);
tommy_list_init(&disk->dealloclist);
/* mark the state as needing write */

View file

@ -22,8 +22,10 @@ struct snapraid_thermal* thermal_alloc(uint64_t dev, const char* name)
return thermal;
}
void thermal_free(struct snapraid_thermal* thermal)
void thermal_free(void* void_thermal)
{
struct snapraid_thermal* thermal = void_thermal;
free(thermal);
}

View file

@ -56,7 +56,7 @@ struct snapraid_thermal* thermal_alloc(uint64_t dev, const char* name);
/**
* Deallocate a thermal state.
*/
void thermal_free(struct snapraid_thermal* thermal);
void thermal_free(void* void_thermal);
#endif

1045
raid/NOTES Normal file

File diff suppressed because it is too large Load diff

1111
raid/OTHERS Normal file

File diff suppressed because it is too large Load diff

View file

@ -16,7 +16,10 @@ 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.
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.
void raid_init(void)
Initializes algorithm tables and detects hardware SIMD instruction sets
@ -71,7 +74,12 @@ detect CPU capabilities and initialize mode dispatch.
int raid_selftest(void)
Runs startup verification tests for parity generation, recovery, and
scanning across parity levels 1..6. Returns 0 on success, < 0 on failure.
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.
Memory, Alignment and Aliasing Requirements
@ -166,9 +174,11 @@ Testing and Benchmarks
Standalone test applications located in raid/test/ provide verification and
performance evaluation:
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/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/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)

View file

@ -317,7 +317,8 @@ 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)
memcpy(v[1 + i], v[0], size);
if (v[1 + i] != v[0])
memcpy(v[1 + i], v[0], size);
return;
}
@ -574,7 +575,8 @@ 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)
memcpy(v[1 + i], v[0], size);
if (v[1 + i] != v[0])
memcpy(v[1 + i], v[0], size);
return;
}
@ -736,7 +738,8 @@ 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)
memcpy(v[1 + d], v[0], size);
if (v[1 + d] != v[0])
memcpy(v[1 + d], v[0], size);
return;
}
@ -882,7 +885,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 nr, int *id, int *ip, int nd, size_t size, void **vv)
static __always_inline void raid_rec1_avx2_delta(int *id, int *ip, int nd, size_t size, void **vv)
{
uint8_t **v = (uint8_t **)vv;
uint8_t *p;
@ -891,8 +894,6 @@ static __always_inline void raid_rec1_avx2_delta(int nr, int *id, int *ip, int n
uint8_t V;
size_t i;
(void)nr; /* unused, it's always 1 */
/* setup the coefficients matrix */
G = A(ip[0], id[0]);
@ -946,31 +947,28 @@ static __always_inline void raid_rec1_avx2_delta(int nr, int *id, int *ip, int n
/*
* RAID recovering for two disks AVX2 implementation
*/
static __always_inline void raid_rec2_avx2_delta(int nr, int *id, int *ip, int nd, size_t size, void **vv)
static __always_inline void raid_rec2_avx2_delta(int *id, int *ip, int nd, size_t size, void **vv)
{
uint8_t **v = (uint8_t **)vv;
const int N = 2;
uint8_t *p[N];
uint8_t *pa[N];
uint8_t G[N * N];
uint8_t V[N * N];
uint8_t *p[2];
uint8_t *pa[2];
uint8_t G[2 * 2];
uint8_t V[2 * 2];
size_t i;
int j, k;
(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]);
for (j = 0; j < 2; ++j)
for (k = 0; k < 2; ++k)
G[j * 2 + k] = A(ip[j], id[k]);
/* invert it to solve the system of linear equations */
raid_invert(G, V, N);
raid_invert(G, V, 2);
/* compute delta parity */
raid_delta_gen(N, id, ip, nd, size, vv);
raid_delta_gen(2, id, ip, nd, size, vv);
for (j = 0; j < N; ++j) {
for (j = 0; j < 2; ++j) {
p[j] = v[nd + ip[j]];
pa[j] = v[id[j]];
}
@ -1039,11 +1037,88 @@ static __always_inline void raid_rec2_avx2_delta(int nr, int *id, int *ip, int n
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)
{
@ -1102,7 +1177,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; ++j)
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];
@ -1172,7 +1247,11 @@ static __always_inline void raid_recX_avx2_1234(int nr, int *id, int *ip, int nd
}
}
/* preserve only aligned low/high nibbles, never full delta blocks */
/* preserve the complete P delta before splitting syndrome 0 */
if (has_p)
asm volatile ("vmovdqa %ymm0,%ymm6");
/* preserve only aligned low/high nibbles */
asm volatile ("vpsrlw $4,%ymm0,%ymm4");
asm volatile ("vpand %ymm7,%ymm0,%ymm0");
asm volatile ("vpand %ymm7,%ymm4,%ymm4");
@ -1203,8 +1282,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 every missing block, initializing from coefficient zero */
for (j = 0; j < nr; ++j) {
/* reconstruct all but the last missing block when P is available */
for (j = 0; j < nr - has_p; ++j) {
const uint8_t **t = R[j];
asm volatile ("vbroadcasti128 %0,%%ymm0" : : "m" (t[0][0]));
@ -1226,8 +1305,15 @@ 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();
@ -1238,6 +1324,10 @@ 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)
{
@ -1299,7 +1389,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; ++j)
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];
@ -1374,6 +1464,13 @@ 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.
*
@ -1390,7 +1487,8 @@ static __always_inline void raid_recX_avx2(int nr, int *id, int *ip, int nd, siz
}
/*
* Reconstruct each missing block.
* Reconstruct all but the last missing block when P is
* available.
*
* Keep independent low/high accumulation chains:
*
@ -1400,8 +1498,9 @@ 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; ++j) {
for (j = 0; j < nr - has_p; ++j) {
const uint8_t **t = R[j];
/* coefficient 0 initializes the accumulators */
@ -1429,8 +1528,15 @@ 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();
@ -1438,100 +1544,72 @@ 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 AVX2 extended implementation
* RAID recovering for two disks with P and Q AVX2 implementation
*/
static __always_inline void raid_rec2_avx2ext_delta(int nr, int *id, int *ip, int nd, size_t size, void **vv)
static __always_inline void raid_rec2of2_avx2ext(int *id, int *ip, int nd, size_t size, void **vv)
{
uint8_t **v = (uint8_t **)vv;
const int N = 2;
uint8_t *p[N];
uint8_t *pa[N];
uint8_t G[N * N];
uint8_t V[N * N];
uint8_t *p[2];
uint8_t *pa[2];
uint8_t C[2];
size_t i;
int j, k;
(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);
/* 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(N, id, ip, nd, size, vv);
raid_delta_gen(2, id, ip, nd, size, vv);
for (j = 0; j < N; ++j) {
p[j] = v[nd + ip[j]];
pa[j] = v[id[j]];
}
p[0] = v[nd];
p[1] = v[nd + 1];
pa[0] = v[id[0]];
pa[1] = v[id[1]];
raid_avx_begin();
asm volatile ("vpbroadcastb %0,%%ymm6" : : "m" (gfconst16.low4[0]));
asm volatile ("vpbroadcastb %0,%%ymm7" : : "m" (gfconst16.low4[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]));
/* 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]));
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,%%ymm4" : : "m" (pa[0][i]));
asm volatile ("vpxor %ymm4,%ymm0,%ymm0");
asm volatile ("vmovdqa %0,%%ymm2" : : "m" (pa[0][i]));
asm volatile ("vpxor %ymm2,%ymm0,%ymm0");
/* d1 = p[1] ^ pa[1] */
asm volatile ("vmovdqa %0,%%ymm1" : : "m" (p[1][i]));
asm volatile ("vmovdqa %0,%%ymm4" : : "m" (pa[1][i]));
asm volatile ("vpxor %ymm4,%ymm1,%ymm1");
asm volatile ("vmovdqa %0,%%ymm3" : : "m" (pa[1][i]));
asm volatile ("vpxor %ymm3,%ymm1,%ymm1");
/*
* 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[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");
/* 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");
/* 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");
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[1] = C[0] * d0 ^ C[1] * d1 */
asm volatile ("vmovdqa %%ymm6,%0" : "=m" (pa[1][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]));
/* pa[0] = d0 ^ pa[1] */
asm volatile ("vpxor %ymm6,%ymm0,%ymm0");
asm volatile ("vmovdqa %%ymm0,%0" : "=m" (pa[0][i]));
}
raid_avx_end();
@ -1841,11 +1919,16 @@ static __always_inline void raid_recX_avx2ext_123(int nr, int *id, int *ip, int
}
/*
* RAID recovering AVX2 implementation.
* RAID recovering AVX2 extended 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)
{
@ -1862,6 +1945,8 @@ 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)
@ -1900,16 +1985,18 @@ static __always_inline void raid_recX_avx2ext(int nr, int *id, int *ip, int nd,
BUG_ON(k != nr);
BUG_ON(ns != nd - nr);
/* precompute inverse-matrix multiplication table pointers */
for (j = 0; j < nr; ++j)
/*
* 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)
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.
*
@ -2023,6 +2110,16 @@ 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.
*
@ -2069,8 +2166,30 @@ static __always_inline void raid_recX_avx2ext(int nr, int *id, int *ip, int nd,
asm volatile ("vpand %ymm15,%ymm11,%ymm11");
}
/* reconstruct every missing data block */
for (j = 0; j < nr; ++j) {
/*
* 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) {
const uint8_t **t = R[j];
/* first coefficient initializes the low/high accumulators */
@ -2119,20 +2238,25 @@ 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)
@ -2218,13 +2342,20 @@ void raid_rec1_avx2(int nr, int *id, int *ip, int nd, size_t size, void **vv)
return;
}
raid_rec1_avx2_delta(1, id, ip, nd, size, vv);
raid_rec1_avx2_delta(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);
raid_rec2_avx2_delta(2, id, ip, nd, size, vv);
/* 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);
}
void raid_rec3_avx2(int nr, int *id, int *ip, int nd, size_t size, void **vv)
@ -2264,7 +2395,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(1, id, ip, nd, size, vv);
raid_rec1_avx2_delta(id, ip, nd, size, vv);
return;
}
@ -2277,7 +2408,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_rec2_avx2ext_delta(2, id, ip, nd, size, vv);
raid_rec2of2_avx2ext(id, ip, nd, size, vv);
return;
}

View file

@ -57,8 +57,10 @@ void raid_gen2_avx512bw(int nd, size_t size, void **vv)
int d;
if (nd == 1) {
memcpy(v[1], v[0], size);
memcpy(v[2], v[0], size);
if (v[1] != v[0])
memcpy(v[1], v[0], size);
if (v[2] != v[0])
memcpy(v[2], v[0], size);
return;
}
@ -281,9 +283,12 @@ void raid_gen3_avx512bw(int nd, size_t size, void **vv)
int d;
if (nd == 1) {
memcpy(v[1], v[0], size);
memcpy(v[2], v[0], size);
memcpy(v[3], v[0], size);
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);
return;
}
@ -450,7 +455,8 @@ static __always_inline void raid_genX_avx512bw(int nd, size_t size, void **vv, i
if (nd == 1) {
for (d = 0; d < np; ++d)
memcpy(v[1 + d], v[0], size);
if (v[1 + d] != v[0])
memcpy(v[1 + d], v[0], size);
return;
}
@ -544,10 +550,10 @@ static __always_inline void raid_genX_avx512bw(int nd, size_t size, void **vv, i
}
/*
* RAID recovering AVX512BW implementation.
* Recover multiple data failures using selected parity blocks with AVX512BW.
*
* Compute only the selected syndromes directly from the stored parity
* and surviving data. This avoids raid_delta_gen(), temporary delta
* 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.
*
* AVX512 provides enough registers to keep all six supported syndromes
@ -611,8 +617,11 @@ static __always_inline void raid_recX_avx512bw(int nr, int *id, int *ip, int nd,
BUG_ON(k != nr);
BUG_ON(ns != nd - nr);
/* precompute inverse-matrix multiplication table pointers */
for (j = 0; j < nr; ++j)
/*
* 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)
for (k = 0; k < nr; ++k)
R[j][k] = &raid_gfmulpshufb[V[j * nr + k]][0][0];
@ -632,6 +641,7 @@ 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:
@ -740,6 +750,13 @@ 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");
@ -776,7 +793,11 @@ static __always_inline void raid_recX_avx512bw(int nr, int *id, int *ip, int nd,
}
/*
* Reconstruct every missing data block.
* 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.
*
* Keep independent low/high dependency chains:
*
@ -784,11 +805,12 @@ 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; ++j) {
for (j = 0; j < nr - has_p; ++j) {
const uint8_t **t = R[j];
/* coefficient 0 initializes both accumulators */
@ -842,9 +864,22 @@ 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();
@ -887,9 +922,89 @@ 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);
}

View file

@ -113,10 +113,20 @@ int raid_check(int nr, int *ir, int nd, int np, size_t size, void **v)
/* enforce limit on size */
BUG_ON(size % 64 != 0);
/* enforce limit on number of failures */
BUG_ON(nr >= np); /* >= because we check with extra parity */
/* enforce limit on number of data blocks */
BUG_ON(nd < 1 || nd > RAID_DATA_MAX);
/* enforce limit on number of parity blocks */
BUG_ON(np < 1);
BUG_ON(np > RAID_PARITY_MAX || (raid_mode_active == RAID_MODE_VANDERMONDE_RAID && np > 3));
/* enforce limit on number of failures */
BUG_ON(nr < 0 || nr >= np); /* >= because we check with extra parity */
/* enforce valid vectors */
BUG_ON(v == 0);
BUG_ON(nr > 0 && ir == 0);
/* enforce order in index vector */
BUG_ON(nr >= 2 && ir[0] >= ir[1]);
BUG_ON(nr >= 3 && ir[1] >= ir[2]);
@ -125,8 +135,12 @@ int raid_check(int nr, int *ir, int nd, int np, size_t size, void **v)
BUG_ON(nr >= 6 && ir[4] >= ir[5]);
/* enforce limit on index vector */
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)
@ -153,6 +167,23 @@ int raid_scan(int *ir, int nd, int np, size_t size, void **v)
{
int r;
/* enforce limit on size */
BUG_ON(size % 64 != 0);
/* enforce limit on number of data blocks */
BUG_ON(nd < 1 || nd > RAID_DATA_MAX);
/* enforce limit on number of parity blocks */
BUG_ON(np < 0);
BUG_ON(np > RAID_PARITY_MAX || (raid_mode_active == RAID_MODE_VANDERMONDE_RAID && np > 3));
/* enforce valid vectors */
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;

View file

@ -91,6 +91,11 @@ 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;

View file

@ -18,7 +18,8 @@ static __always_inline void raid_genX_avx2gfni_raid(int nd, size_t size, void **
if (nd == 1) {
for (d = 0; d < np; ++d)
memcpy(v[1 + d], v[0], size);
if (v[1 + d] != v[0])
memcpy(v[1 + d], v[0], size);
return;
}
@ -129,7 +130,8 @@ static __always_inline void raid_genX_avx512gfni_raid(int nd, size_t size, void
if (nd == 1) {
for (d = 0; d < np; ++d)
memcpy(v[1 + d], v[0], size);
if (v[1 + d] != v[0])
memcpy(v[1 + d], v[0], size);
return;
}
@ -212,7 +214,8 @@ static __always_inline void raid_genX_avx2gfni_aes(int nd, size_t size, void **v
if (nd == 1) {
for (d = 0; d < np; ++d)
memcpy(v[1 + d], v[0], size);
if (v[1 + d] != v[0])
memcpy(v[1 + d], v[0], size);
return;
}
@ -330,7 +333,8 @@ static __always_inline void raid_genX_avx512gfni_aes(int nd, size_t size, void *
if (nd == 1) {
for (d = 0; d < np; ++d)
memcpy(v[1 + d], v[0], size);
if (v[1 + d] != v[0])
memcpy(v[1 + d], v[0], size);
return;
}
@ -599,6 +603,16 @@ 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;
@ -649,7 +663,8 @@ static __always_inline void raid_recX_avx512gfni_raid(int nr, int *id, int *ip,
BUG_ON(k != nr);
BUG_ON(ns != nd - nr);
for (j = 0; j < nr; ++j)
/* the last inverse row isn't needed when P is available */
for (j = 0; j < nr - has_p; ++j)
for (k = 0; k < nr; ++k)
R[j][k] = raid_gfaffine_raid[V[j * nr + k]];
@ -712,7 +727,15 @@ static __always_inline void raid_recX_avx512gfni_raid(int nr, int *id, int *ip,
}
}
for (j = 0; j < nr; ++j) {
/* 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) {
const uint8_t **t = R[j];
asm volatile ("vpbroadcastq %0,%%zmm6" : : "m" (t[0][0]));
@ -748,8 +771,14 @@ 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();
@ -944,6 +973,17 @@ 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;
@ -1050,7 +1090,11 @@ static __always_inline void raid_recX_avx512gfni_aes(int nr, int *id, int *ip, i
}
}
for (j = 0; j < nr; ++j) {
/* preserve the complete P delta */
if (has_p)
asm volatile ("vmovdqa64 %zmm0,%zmm30");
for (j = 0; j < nr - has_p; ++j) {
asm volatile ("vpbroadcastb %0,%%zmm6" : : "m" (V[j * nr]));
asm volatile ("vgf2p8mulb %zmm6,%zmm0,%zmm7");
@ -1084,8 +1128,14 @@ 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();
@ -1264,9 +1314,82 @@ 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);
}
@ -1307,9 +1430,68 @@ 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);
}
@ -1350,9 +1532,73 @@ 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);
}
@ -1393,9 +1639,63 @@ 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);
}

View file

@ -581,7 +581,6 @@ 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];
@ -597,17 +596,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 < N; ++j)
for (k = 0; k < N; ++k)
G[j * N + k] = A(ip[j], id[k]);
for (j = 0; j < 2; ++j)
for (k = 0; k < 2; ++k)
G[j * 2 + k] = A(ip[j], id[k]);
/* invert it to solve the system of linear equations */
raid_invert(G, V, N);
raid_invert(G, V, 2);
/* get multiplication tables */
for (j = 0; j < N; ++j)
for (k = 0; k < N; ++k)
T[j][k] = table(V[j * N + k]);
for (j = 0; j < 2; ++j)
for (k = 0; k < 2; ++k)
T[j][k] = table(V[j * 2 + k]);
/* compute delta parity */
raid_delta_gen(2, id, ip, nd, size, vv);

View file

@ -44,7 +44,9 @@
#include <string.h>
/*
* Inverse assert.
* 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.
*/
#define BUG_ON(a) assert(!(a))

View file

@ -4,6 +4,19 @@
#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().
*
@ -64,26 +77,36 @@
unsigned raid_optimal_displacement(int n);
/**
* Aligned malloc.
* Use an alignment suitable for the raid functions.
* Aligned malloc with default RAID alignment (256 bytes).
*
* Stores the base allocation address in @freeptr to be passed to free().
*/
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.
* Use an alignment suitable for the raid functions.
* Returns a vector of @n pointers, each one pointing to a block of
* the specified @size.
*
* 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.
*/
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);

View file

@ -78,10 +78,16 @@ void raid_gen(int nd, int np, size_t size, void **v)
/* enforce limit on size */
BUG_ON(size % 64 != 0);
/* enforce limit on number of failures */
/* enforce limit on number of data blocks */
BUG_ON(nd < 1 || nd > RAID_DATA_MAX);
/* enforce limit on number of parity blocks */
BUG_ON(np < 1);
BUG_ON(np > RAID_PARITY_MAX || (raid_mode_active == RAID_MODE_VANDERMONDE_RAID && np > 3));
/* enforce valid vector */
BUG_ON(v == 0);
BUG_ON(raid_gen_ptr[np - 1] == 0);
raid_gen_ptr[np - 1](nd, size, v);
}
@ -103,10 +109,20 @@ void raid_rec(int nr, int *ir, int nd, int np, size_t size, void **v)
/* enforce limit on size */
BUG_ON(size % 64 != 0);
/* enforce limit on number of failures */
BUG_ON(nr > np);
/* enforce limit on number of data blocks */
BUG_ON(nd < 1 || nd > RAID_DATA_MAX);
/* enforce limit on number of parity blocks */
BUG_ON(np < 1);
BUG_ON(np > RAID_PARITY_MAX || (raid_mode_active == RAID_MODE_VANDERMONDE_RAID && np > 3));
/* enforce limit on number of failures */
BUG_ON(nr < 0 || nr > np);
/* enforce valid vectors */
BUG_ON(v == 0);
BUG_ON(nr > 0 && ir == 0);
/* enforce order in index vector */
BUG_ON(nr >= 2 && ir[0] >= ir[1]);
BUG_ON(nr >= 3 && ir[1] >= ir[2]);
@ -115,6 +131,7 @@ void raid_rec(int nr, int *ir, int nd, int np, size_t size, void **v)
BUG_ON(nr >= 6 && ir[4] >= ir[5]);
/* enforce limit on index vector */
BUG_ON(nr > 0 && ir[0] < 0);
BUG_ON(nr > 0 && ir[nr - 1] >= nd + np);
/* count the number of data blocks to recover */
@ -150,12 +167,40 @@ void raid_rec(int nr, int *ir, int nd, int np, size_t size, void **v)
* Recover the nrd data blocks specified in ir[],
* using the first nrd parity in ip[] for recovering
*/
BUG_ON(raid_rec_ptr[nrd - 1] == 0);
raid_rec_ptr[nrd - 1](nrd, ir, ip, nd, size, v);
}
/* recompute all the parities up to the last bad one */
if (nrp != 0)
raid_gen(nd, ir[nr - 1] - nd + 1, size, v);
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);
}
}
void raid_data(int nr, int *id, int *ip, int nd, size_t size, void **v)
@ -163,10 +208,18 @@ void raid_data(int nr, int *id, int *ip, int nd, size_t size, void **v)
/* enforce limit on size */
BUG_ON(size % 64 != 0);
/* enforce limit on number of data blocks */
BUG_ON(nd < 1 || nd > RAID_DATA_MAX);
/* enforce limit on number of failures */
BUG_ON(nr > nd);
BUG_ON(nr < 0 || nr > nd);
BUG_ON(nr > RAID_PARITY_MAX);
/* enforce valid vectors */
BUG_ON(v == 0);
BUG_ON(nr > 0 && id == 0);
BUG_ON(nr > 0 && ip == 0);
/* enforce order in index vector for data */
BUG_ON(nr >= 2 && id[0] >= id[1]);
BUG_ON(nr >= 3 && id[1] >= id[2]);
@ -175,6 +228,7 @@ void raid_data(int nr, int *id, int *ip, int nd, size_t size, void **v)
BUG_ON(nr >= 6 && id[4] >= id[5]);
/* enforce limit on index vector for data */
BUG_ON(nr > 0 && id[0] < 0);
BUG_ON(nr > 0 && id[nr - 1] >= nd);
/* enforce order in index vector for parity */
@ -185,6 +239,7 @@ void raid_data(int nr, int *id, int *ip, int nd, size_t size, void **v)
BUG_ON(nr >= 6 && ip[4] >= ip[5]);
/* enforce limit on index vector for parity */
BUG_ON(nr > 0 && ip[0] < 0);
BUG_ON(nr > 0 && (ip[nr - 1] >= RAID_PARITY_MAX || (raid_mode_active == RAID_MODE_VANDERMONDE_RAID && ip[nr - 1] >= 3)));
/* if failed data is present */
@ -724,6 +779,12 @@ 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);

View file

@ -250,7 +250,8 @@ 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)
memcpy(v[1 + d], v[0], size);
if (v[1 + d] != v[0])
memcpy(v[1 + d], v[0], size);
return;
}
@ -566,8 +567,7 @@ 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,9 +1045,132 @@ 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);
}

View file

@ -244,7 +244,8 @@ 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)
memcpy(v[1 + d], v[0], size);
if (v[1 + d] != v[0])
memcpy(v[1 + d], v[0], size);
return;
}
@ -518,8 +519,7 @@ 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,8 +816,7 @@ static __always_inline void raid_recX_neon32_123(int nr, int *id, int *ip,
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];
@ -1225,9 +1224,114 @@ 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);
}

View file

@ -26,12 +26,10 @@
* 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 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].
* 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].
*
* To overcome this limitation, a Cauchy matrix [3][4] is used for parity
* computation. A Cauchy matrix ensures that all square submatrices are
@ -121,9 +119,9 @@
* data disks, one for each column. All the 377,342,351,231 square submatrices
* are nonsingular, verified also by brute-force testing.
*
* 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.
* 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
* (See mktables.c for more details on how the matrix is generated.)
*
* The downside is that generic multiplications are required to compute the

View file

@ -4,6 +4,8 @@
#ifndef __RAID_H
#define __RAID_H
#include <stddef.h>
/*
* GF(2^8) reducing polynomial selection.
*
@ -20,8 +22,8 @@
*
* The polynomial used by the original RAID-6 specification and the
* Linux kernel RAID implementation, used with primitive generator g=2.
* Choosing this polynomial ensures on-disk compatibility with existing
* RAID arrays and interchange with other RAID implementations.
* For identically ordered data blocks, the generated P/Q syndrome bytes
* match the Linux RAID6 implementation.
*
* On CPUs supporting Intel GFNI (Galois Field New Instructions),
* generation and recovery are accelerated with vgf2p8affineqb.
@ -63,7 +65,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.
* Ensures maximum compatibility with standard Linux RAID arrays.
* Uses Linux RAID6-compatible P/Q coefficients.
*
* This is the default mode set after calling raid_init().
*/
@ -111,6 +113,9 @@
*
* 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.
*
@ -140,16 +145,26 @@ int raid_mode(int mode);
*
* raid_init() must be called before this function.
*
* 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 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.
*
* The test is immediate, and it's intended to be run at application
* startup to check the integrity of the RAID system.
* 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 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);
@ -198,8 +213,9 @@ void raid_zero(void *zero);
*
* Each parity block allows to recover one data block.
*
* @nd Number of data blocks.
* @np Number of parity blocks to compute.
* @nd Number of data blocks. It must be between 1 and RAID_DATA_MAX.
* @np Number of parity blocks to compute. It must be between 1 and
* RAID_PARITY_MAX. RAID_MODE_VANDERMONDE_RAID supports at most 3.
* @size Size of the blocks pointed to by @v. It must be a multiple of 64.
* @v Vector of pointers to the blocks of data and parity.
* It has (@nd + @np) elements. The starting elements are the blocks for
@ -230,13 +246,16 @@ void raid_gen(int nd, int np, size_t size, void **v);
* This happens even in the case you have more parity blocks than needed,
* and some form of integrity verification would be possible.
*
* @nr Number of failed data and parity blocks to recover.
* @nr Number of failed data and parity blocks to recover. It must be
* between 0 and @np.
* @ir[] Vector of @nr indexes of the failed data and parity blocks.
* The indexes start from 0. They must be in order.
* All indexes must be nonnegative and smaller than @nd + @np.
* The first parity is represented with value @nd, the second with value
* @nd + 1, just like positions in the @v vector.
* @nd Number of data blocks.
* @np Number of parity blocks.
* @nd Number of data blocks. It must be between 1 and RAID_DATA_MAX.
* @np Number of parity blocks. It must be between 1 and RAID_PARITY_MAX.
* RAID_MODE_VANDERMONDE_RAID supports at most 3.
* @size Size of the blocks pointed by @v. It must be a multiple of 64.
* @v Vector of pointers to the blocks of data and parity.
* It has (@nd + @np) elements. The starting elements are the blocks
@ -253,12 +272,16 @@ void raid_rec(int nr, int *ir, int nd, int np, size_t size, void **v);
* This function recovers all the data blocks marked as bad in the @id vector.
* The parity blocks are not modified.
*
* @nr Number of failed data blocks to recover.
* @nr Number of failed data blocks to recover. It must be nonnegative,
* not greater than @nd, and not greater than RAID_PARITY_MAX.
* @id[] Vector of @nr indexes of the data blocks to recover.
* The indexes start from 0. They must be in order.
* All indexes must be nonnegative and smaller than @nd.
* @ip[] Vector of @nr indexes of the parity blocks to use for recovery.
* The indexes start from 0. They must be in order.
* @nd Number of data blocks.
* All indexes must be nonnegative and smaller than RAID_PARITY_MAX.
* In RAID_MODE_VANDERMONDE_RAID they must be smaller than 3.
* @nd Number of data blocks. It must be between 1 and RAID_DATA_MAX.
* @size Size of the blocks pointed to by @v. It must be a multiple of 64.
* @v Vector of pointers to the blocks of data and parity.
* It has (@nd + @ip[@nr - 1] + 1) elements. The starting elements are the
@ -281,13 +304,16 @@ void raid_data(int nr, int *id, int *ip, int nd, size_t size, void **v);
*
* No data or parity blocks are modified.
*
* @nr Number of failed data and parity blocks.
* @nr Number of failed data and parity blocks. It must be nonnegative and
* strictly smaller than @np.
* @ir[] Vector of @nr indexes of the failed data and parity blocks.
* The indexes start from 0. They must be in order.
* All indexes must be nonnegative and smaller than @nd + @np.
* The first parity is represented with value @nd, the second with value
* @nd + 1, just like positions in the @v vector.
* @nd Number of data blocks.
* @np Number of parity blocks.
* @nd Number of data blocks. It must be between 1 and RAID_DATA_MAX.
* @np Number of parity blocks. It must be between 1 and RAID_PARITY_MAX.
* RAID_MODE_VANDERMONDE_RAID supports at most 3.
* @size Size of the blocks pointed by @v. It must be a multiple of 64.
* @v Vector of pointers to the blocks of data and parity.
* It has (@nd + @np) elements. The starting elements are the blocks
@ -311,7 +337,10 @@ 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.
*
* It uses a brute force method, and then the call can be expensive.
* 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.
*
* The expected execution time is proportional to the binomial coefficient
* @np + @nd choose @np - 1, usually written as:
*
@ -331,8 +360,9 @@ int raid_check(int nr, int *ir, int nd, int np, size_t size, void **v);
* The indexes start from 0 and they are in order.
* The first parity is represented with value @nd, the second with value
* @nd + 1, just like positions in the @v vector.
* @nd Number of data blocks.
* @np Number of parity blocks.
* @nd Number of data blocks. It must be between 1 and RAID_DATA_MAX.
* @np Number of parity blocks. It must be between 0 and RAID_PARITY_MAX.
* RAID_MODE_VANDERMONDE_RAID supports at most 3.
* @size Size of the blocks pointed by @v. It must be a multiple of 64.
* @v Vector of pointers to the blocks of data and parity.
* It has (@nd + @np) elements. The starting elements are the blocks

View file

@ -26,7 +26,8 @@ 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)
memcpy(v[1 + i], v[0], size);
if (v[1 + i] != v[0])
memcpy(v[1 + i], v[0], size);
return;
}
@ -131,7 +132,8 @@ 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)
memcpy(v[1 + i], v[0], size);
if (v[1 + i] != v[0])
memcpy(v[1 + i], v[0], size);
return;
}
@ -257,7 +259,8 @@ 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)
memcpy(v[1 + i], v[0], size);
if (v[1 + i] != v[0])
memcpy(v[1 + i], v[0], size);
return;
}
@ -394,7 +397,8 @@ 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)
memcpy(v[1 + i], v[0], size);
if (v[1 + i] != v[0])
memcpy(v[1 + i], v[0], size);
return;
}
@ -545,7 +549,8 @@ 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)
memcpy(v[1 + i], v[0], size);
if (v[1 + i] != v[0])
memcpy(v[1 + i], v[0], size);
return;
}
@ -805,7 +810,8 @@ 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)
memcpy(v[1 + i], v[0], size);
if (v[1 + i] != v[0])
memcpy(v[1 + i], v[0], size);
return;
}
@ -995,7 +1001,8 @@ 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)
memcpy(v[1 + d], v[0], size);
if (v[1 + d] != v[0])
memcpy(v[1 + d], v[0], size);
return;
}
@ -1152,7 +1159,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 nr, int *id, int *ip, int nd, size_t size, void **vv)
static __always_inline void raid_rec1_ssse3_delta(int *id, int *ip, int nd, size_t size, void **vv)
{
uint8_t **v = (uint8_t **)vv;
uint8_t *p;
@ -1161,8 +1168,6 @@ static __always_inline void raid_rec1_ssse3_delta(int nr, int *id, int *ip, int
uint8_t V;
size_t i;
(void)nr; /* unused, it's always 1 */
/* setup the coefficients matrix */
G = A(ip[0], id[0]);
@ -1203,31 +1208,28 @@ static __always_inline void raid_rec1_ssse3_delta(int nr, int *id, int *ip, int
/*
* RAID recovering for two disks SSSE3 implementation
*/
static __always_inline void raid_rec2_ssse3_delta(int nr, int *id, int *ip, int nd, size_t size, void **vv)
static __always_inline void raid_rec2_ssse3_delta(int *id, int *ip, int nd, size_t size, void **vv)
{
uint8_t **v = (uint8_t **)vv;
const int N = 2;
uint8_t *p[N];
uint8_t *pa[N];
uint8_t G[N * N];
uint8_t V[N * N];
uint8_t *p[2];
uint8_t *pa[2];
uint8_t G[2 * 2];
uint8_t V[2 * 2];
size_t i;
int j, k;
(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]);
for (j = 0; j < 2; ++j)
for (k = 0; k < 2; ++k)
G[j * 2 + k] = A(ip[j], id[k]);
/* invert it to solve the system of linear equations */
raid_invert(G, V, N);
raid_invert(G, V, 2);
/* compute delta parity */
raid_delta_gen(N, id, ip, nd, size, vv);
raid_delta_gen(2, id, ip, nd, size, vv);
for (j = 0; j < N; ++j) {
for (j = 0; j < 2; ++j) {
p[j] = v[nd + ip[j]];
pa[j] = v[id[j]];
}
@ -1304,8 +1306,94 @@ static __always_inline void raid_rec2_ssse3_delta(int nr, int *id, int *ip, int
raid_sse_end();
}
static __always_inline void raid_recX_ssse3_1234(int nr, int *id, int *ip,
int nd, size_t size, void **vv)
/*
* 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)
{
uint8_t **v = (uint8_t **)vv;
uint8_t *p[RAID_PARITY_MAX];
@ -1359,7 +1447,7 @@ static __always_inline void raid_recX_ssse3_1234(int nr, int *id, int *ip,
BUG_ON(k != nr);
BUG_ON(ns != nd - nr);
for (j = 0; j < nr; ++j)
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];
@ -1433,6 +1521,10 @@ static __always_inline void raid_recX_ssse3_1234(int nr, int *id, int *ip,
}
}
/* 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.
@ -1476,7 +1568,11 @@ static __always_inline void raid_recX_ssse3_1234(int nr, int *id, int *ip,
asm volatile ("movdqa %%xmm5,%0" : "=m" (pd_high[48]));
}
for (j = 0; j < nr; ++j) {
/*
* 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) {
const uint8_t **t = R[j];
asm volatile ("movdqa %0,%%xmm0" : : "m" (t[0][0]));
@ -1498,15 +1594,31 @@ static __always_inline void raid_recX_ssse3_1234(int nr, int *id, int *ip,
}
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();
}
static __always_inline void raid_recX_ssse3(int nr, int *id, int *ip,
int nd, size_t size, void **vv)
/*
* 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)
{
uint8_t **v = (uint8_t **)vv;
uint8_t *p[RAID_PARITY_MAX];
@ -1560,7 +1672,7 @@ static __always_inline void raid_recX_ssse3(int nr, int *id, int *ip,
BUG_ON(k != nr);
BUG_ON(ns != nd - nr);
for (j = 0; j < nr; ++j)
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];
@ -1604,6 +1716,13 @@ static __always_inline void raid_recX_ssse3(int nr, int *id, int *ip,
}
}
/*
* 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]));
@ -1615,8 +1734,11 @@ static __always_inline void raid_recX_ssse3(int nr, int *id, int *ip,
asm volatile ("movdqa %%xmm1,%0" : "=m" (pd_high[k * 16]));
}
/* reconstruct */
for (j = 0; j < nr; ++j) {
/*
* 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) {
const uint8_t **t = R[j];
asm volatile ("movdqa %0,%%xmm0" : : "m" (t[0][0]));
@ -1638,8 +1760,15 @@ static __always_inline void raid_recX_ssse3(int nr, int *id, int *ip,
}
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();
@ -1647,9 +1776,15 @@ static __always_inline void raid_recX_ssse3(int nr, int *id, int *ip,
#ifdef CONFIG_X86_64
/*
* RAID recovering for one disk SSSE3 extended implementation
* 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.
*/
static __always_inline void raid_rec1_ssse3ext_delta(int nr, int *id, int *ip, int nd, size_t size, void **vv)
static __always_inline void raid_rec1_ssse3ext_delta(int *id, int *ip, int nd, size_t size, void **vv)
{
uint8_t **v = (uint8_t **)vv;
uint8_t *p;
@ -1658,8 +1793,6 @@ static __always_inline void raid_rec1_ssse3ext_delta(int nr, int *id, int *ip, i
uint8_t V;
size_t i;
(void)nr; /* unused, it's always 1 */
/* setup the coefficients matrix */
G = A(ip[0], id[0]);
@ -1678,71 +1811,45 @@ static __always_inline void raid_rec1_ssse3ext_delta(int nr, int *id, int *ip, i
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 += 64) {
for (i = 0; i < size; i += 32) {
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,%xmm12");
asm volatile ("movdqa %xmm4,%xmm13");
asm volatile ("movdqa %xmm4,%xmm14");
asm volatile ("movdqa %xmm4,%xmm15");
asm volatile ("movdqa %xmm4,%xmm10");
asm volatile ("movdqa %xmm4,%xmm11");
asm volatile ("pshufb %xmm0,%xmm12");
asm volatile ("pshufb %xmm1,%xmm13");
asm volatile ("pshufb %xmm2,%xmm14");
asm volatile ("pshufb %xmm3,%xmm15");
asm volatile ("pshufb %xmm0,%xmm10");
asm volatile ("pshufb %xmm1,%xmm11");
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 %xmm12,%xmm0");
asm volatile ("pxor %xmm13,%xmm1");
asm volatile ("pxor %xmm14,%xmm2");
asm volatile ("pxor %xmm15,%xmm3");
asm volatile ("pxor %xmm10,%xmm0");
asm volatile ("pxor %xmm11,%xmm1");
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();
@ -1751,31 +1858,28 @@ static __always_inline void raid_rec1_ssse3ext_delta(int nr, int *id, int *ip, i
/*
* RAID recovering for two disks SSSE3 extended implementation
*/
static __always_inline void raid_rec2_ssse3ext_delta(int nr, int *id, int *ip, int nd, size_t size, void **vv)
static __always_inline void raid_rec2_ssse3ext_delta(int *id, int *ip, int nd, size_t size, void **vv)
{
uint8_t **v = (uint8_t **)vv;
const int N = 2;
uint8_t *p[N];
uint8_t *pa[N];
uint8_t G[N * N];
uint8_t V[N * N];
uint8_t *p[2];
uint8_t *pa[2];
uint8_t G[2 * 2];
uint8_t V[2 * 2];
size_t i;
int j, k;
(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]);
for (j = 0; j < 2; ++j)
for (k = 0; k < 2; ++k)
G[j * 2 + k] = A(ip[j], id[k]);
/* invert it to solve the system of linear equations */
raid_invert(G, V, N);
raid_invert(G, V, 2);
/* compute delta parity */
raid_delta_gen(N, id, ip, nd, size, vv);
raid_delta_gen(2, id, ip, nd, size, vv);
for (j = 0; j < N; ++j) {
for (j = 0; j < 2; ++j) {
p[j] = v[nd + ip[j]];
pa[j] = v[id[j]];
}
@ -1858,8 +1962,88 @@ static __always_inline void raid_rec2_ssse3ext_delta(int nr, int *id, int *ip, 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)
/*
* 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)
{
uint8_t **v = (uint8_t **)vv;
uint8_t *p[RAID_PARITY_MAX];
@ -2108,8 +2292,308 @@ static __always_inline void raid_recX_ssse3ext_123(int nr, int *id, int *ip,
raid_sse_end();
}
static __always_inline void raid_recX_ssse3ext(int nr, int *id, int *ip,
int nd, size_t size, void **vv)
/*
* 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)
{
uint8_t **v = (uint8_t **)vv;
uint8_t *p[RAID_PARITY_MAX];
@ -2453,13 +2937,20 @@ void raid_rec1_ssse3(int nr, int *id, int *ip, int nd, size_t size, void **vv)
return;
}
raid_rec1_ssse3_delta(1, id, ip, nd, size, vv);
raid_rec1_ssse3_delta(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);
raid_rec2_ssse3_delta(2, id, ip, nd, size, vv);
/* 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);
}
void raid_rec3_ssse3(int nr, int *id, int *ip, int nd, size_t size, void **vv)
@ -2497,13 +2988,20 @@ void raid_rec1_ssse3ext(int nr, int *id, int *ip, int nd, size_t size, void **vv
return;
}
raid_rec1_ssse3ext_delta(1, id, ip, nd, size, vv);
raid_rec1_ssse3ext_delta(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);
raid_rec2_ssse3ext_delta(2, id, ip, nd, size, vv);
/* 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);
}
void raid_rec3_ssse3ext(int nr, int *id, int *ip, int nd, size_t size, void **vv)
@ -2515,13 +3013,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(4, id, ip, nd, size, vv);
raid_recX_ssse3ext_12345(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(5, id, ip, nd, size, vv);
raid_recX_ssse3ext_12345(5, id, ip, nd, size, vv);
}
void raid_rec6_ssse3ext(int nr, int *id, int *ip, int nd, size_t size, void **vv)
@ -2529,7 +3027,6 @@ 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)

View file

@ -348,55 +348,11 @@ int raid_test_poly(unsigned mode)
#define test_setup(i) f[i - 1][nf[i - 1]++]
int raid_test_rec(int mode, int nd, size_t size)
static void raid_test_setup_rec(int mode, int np, raid_rec_fn *f[RAID_PARITY_MAX][32], int nf[RAID_PARITY_MAX])
{
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;
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);
(void)mode;
/* counters of functions for each parity level */
for (i = 0; i < np; ++i)
@ -644,6 +600,60 @@ int raid_test_rec(int mode, int nd, size_t size)
}
#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);
@ -709,7 +719,7 @@ bail:
int raid_test_tail(int mode, int nd_max, size_t size)
{
void (*f[RAID_PARITY_MAX][32])(int nr, int *id, int *ip, int nd, size_t size, void **vbuf);
raid_rec_fn *f[RAID_PARITY_MAX][32];
void *v_alloc;
void **v;
void **data;
@ -758,252 +768,8 @@ 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 */
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
}
raid_test_setup_rec(mode, np, f, nf);
/* test all disk counts from 1 to nd_max */
for (nd = 1; nd <= nd_max; ++nd) {
@ -1078,47 +844,9 @@ bail:
/* LCOV_EXCL_STOP */
}
int raid_test_par(int mode, int nd, size_t size)
static void raid_test_setup_par(int mode, int np, raid_gen_fn *f[RAID_PARITY_MAX][32], int nf[RAID_PARITY_MAX])
{
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);
int i;
/* counters of functions for each parity level */
for (i = 0; i < np; ++i)
@ -1328,6 +1056,52 @@ int raid_test_par(int mode, int nd, size_t size)
#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) {

View file

@ -64,11 +64,16 @@ 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
./fulltest $(TEST_COUNT) $(TEST_SIZE)
# Use this target to run a coverage test using lcov
covtest:
@ -86,10 +91,10 @@ sdecovtest:
$(MAKE) clean
$(MAKE) lcov_reset
$(MAKE) COVERAGE=1 all
$(SDE) -p4p -- ./fulltest
$(SDE) -mrm -- ./fulltest
$(SDE) -nhm -- ./fulltest
$(SDE) -hsw -- ./fulltest
$(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 -- ./selftest
$(SDE) -mrm -- ./selftest
$(SDE) -nhm -- ./selftest
@ -109,7 +114,7 @@ sdetest:
$(SDE) -hsw -- ./selftest
$(SDE) -skx -- ./selftest
$(SDE) -icl -- ./selftest
$(SDE) -icl -- ./fulltest
$(SDE) -icl -- ./fulltest $(SDE_TEST_COUNT) $(SDE_TEST_SIZE)
# Use this target to run a speed test on Ice Lake simulator
sdespeed:

View file

@ -21,11 +21,32 @@
#ifdef COVERAGE
#define TEST_COUNT 10
#else
#define TEST_COUNT 32
#define TEST_COUNT 24
#endif
int main(void)
int main(int argc, char *argv[])
{
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();
@ -53,7 +74,10 @@ int main(void)
#endif
#endif
printf("\nPlease wait about 60 seconds...\n\n");
if (test_count >= 32)
printf("\nPlease wait about 60 seconds...\n\n");
else
printf("\nPlease wait...\n\n");
printf("Test sorting...\n");
if (raid_test_sort() != 0) {
@ -84,7 +108,7 @@ int main(void)
}
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 */
@ -92,7 +116,7 @@ int main(void)
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 */
@ -100,7 +124,7 @@ int main(void)
}
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 */
@ -108,44 +132,42 @@ int main(void)
}
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 */