mirror of
https://github.com/amadvance/snapraid.git
synced 2026-12-03 05:10:16 -05:00
Change commenting style
This commit is contained in:
parent
e47a3a7493
commit
cfd1eac70c
7 changed files with 81 additions and 47 deletions
14
raid/cpu.h
14
raid/cpu.h
|
|
@ -28,9 +28,11 @@ static inline void raid_xgetbv(uint32_t* reg)
|
||||||
{
|
{
|
||||||
/* get the value of the Extended Control Register ecx=0 */
|
/* get the value of the Extended Control Register ecx=0 */
|
||||||
asm volatile (
|
asm volatile (
|
||||||
/* uses a direct encoding of the XGETBV instruction as only recent */
|
/*
|
||||||
/* assemblers support it. */
|
* Uses a direct encoding of the XGETBV instruction as only recent
|
||||||
/* the next line is equivalent to: "xgetbv\n" */
|
* assemblers support it.
|
||||||
|
* the next line is equivalent to: "xgetbv\n"
|
||||||
|
*/
|
||||||
".byte 0x0f, 0x01, 0xd0\n"
|
".byte 0x0f, 0x01, 0xd0\n"
|
||||||
: "=a" (reg[0]), "=d" (reg[3])
|
: "=a" (reg[0]), "=d" (reg[3])
|
||||||
: "c" (0)
|
: "c" (0)
|
||||||
|
|
@ -213,8 +215,10 @@ static inline int raid_cpu_has_avx512bw(void)
|
||||||
* 3) Verify both CPUID.0x7.0:EBX.AVX512F[bit 16] = 1, CPUID.0x7.0:EBX.AVX512BW[bit 30] = 1.
|
* 3) Verify both CPUID.0x7.0:EBX.AVX512F[bit 16] = 1, CPUID.0x7.0:EBX.AVX512BW[bit 30] = 1.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* note that intentionally we don't check for AVX and AVX2 */
|
/*
|
||||||
/* because the documentation doesn't require that */
|
* Note that intentionally we don't check for AVX and AVX2
|
||||||
|
* because the documentation doesn't require that
|
||||||
|
*/
|
||||||
return raid_cpu_match_avx(
|
return raid_cpu_match_avx(
|
||||||
1 << 27, /* Leaf 1, ECX: XSAVE/XGETBV */
|
1 << 27, /* Leaf 1, ECX: XSAVE/XGETBV */
|
||||||
(1 << 16) | (1 << 30), /* Leaf 7, EBX: AVX512F and AVX512BW */
|
(1 << 16) | (1 << 30), /* Leaf 7, EBX: AVX512F and AVX512BW */
|
||||||
|
|
|
||||||
|
|
@ -61,9 +61,11 @@ void raid_sort(int n, int *v)
|
||||||
|
|
||||||
void raid_insert(int n, int *v, int i)
|
void raid_insert(int n, int *v, int i)
|
||||||
{
|
{
|
||||||
/* we don't use binary search because this is intended */
|
/*
|
||||||
/* for very small vectors and we want to optimize the case */
|
* We don't use binary search because this is intended
|
||||||
/* of elements inserted already in order */
|
* for very small vectors and we want to optimize the case
|
||||||
|
* of elements inserted already in order
|
||||||
|
*/
|
||||||
|
|
||||||
/* insert at the end */
|
/* insert at the end */
|
||||||
v[n] = i;
|
v[n] = i;
|
||||||
|
|
|
||||||
|
|
@ -319,19 +319,23 @@ static __always_inline void raid_sse_begin(void)
|
||||||
|
|
||||||
static __always_inline void raid_sse_end(void)
|
static __always_inline void raid_sse_end(void)
|
||||||
{
|
{
|
||||||
/* SSE and AVX code uses non-temporal writes, like MOVNTDQ, */
|
/*
|
||||||
/* that use a weak memory model. To ensure that other processors */
|
* SSE and AVX code uses non-temporal writes, like MOVNTDQ,
|
||||||
/* see correctly the data written, we use a store-store memory */
|
* that use a weak memory model. To ensure that other processors
|
||||||
/* barrier at the end of the asm code */
|
* see correctly the data written, we use a store-store memory
|
||||||
|
* barrier at the end of the asm code
|
||||||
|
*/
|
||||||
asm volatile ("sfence" : : : "memory");
|
asm volatile ("sfence" : : : "memory");
|
||||||
|
|
||||||
/* clobbers registers used in the asm code */
|
/*
|
||||||
/* this is required because in the Windows ABI, */
|
* Clobbers registers used in the asm code
|
||||||
/* registers xmm6-xmm15 should be kept by the callee. */
|
* this is required because in the Windows ABI,
|
||||||
/* this clobber list force the compiler to save any */
|
* registers xmm6-xmm15 should be kept by the callee.
|
||||||
/* register that needs to be saved */
|
* this clobber list force the compiler to save any
|
||||||
/* we check for __SSE2_ because we require that the */
|
* register that needs to be saved
|
||||||
/* compiler supports SSE2 registers in the clobber list */
|
* we check for __SSE2_ because we require that the
|
||||||
|
* compiler supports SSE2 registers in the clobber list
|
||||||
|
*/
|
||||||
#ifdef __SSE2__
|
#ifdef __SSE2__
|
||||||
asm volatile ("" : : : "%xmm0", "%xmm1", "%xmm2", "%xmm3");
|
asm volatile ("" : : : "%xmm0", "%xmm1", "%xmm2", "%xmm3");
|
||||||
asm volatile ("" : : : "%xmm4", "%xmm5", "%xmm6", "%xmm7");
|
asm volatile ("" : : : "%xmm4", "%xmm5", "%xmm6", "%xmm7");
|
||||||
|
|
@ -353,9 +357,11 @@ static __always_inline void raid_avx_end(void)
|
||||||
{
|
{
|
||||||
raid_sse_end();
|
raid_sse_end();
|
||||||
|
|
||||||
/* reset the upper part of the ymm registers */
|
/*
|
||||||
/* to avoid the 70 clocks penalty on the next */
|
* Reset the upper part of the ymm registers
|
||||||
/* xmm register use */
|
* to avoid the 70 clocks penalty on the next
|
||||||
|
* xmm register use
|
||||||
|
*/
|
||||||
asm volatile ("vzeroupper" : : : "memory");
|
asm volatile ("vzeroupper" : : : "memory");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -59,8 +59,10 @@ void **raid_malloc_vector_align(int nd, int n, size_t size, size_t align_size, s
|
||||||
va += size + displacement_size;
|
va += size + displacement_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* reverse order of the data blocks */
|
/*
|
||||||
/* because they are usually accessed from the last one */
|
* Reverse order of the data blocks
|
||||||
|
* because they are usually accessed from the last one
|
||||||
|
*/
|
||||||
for (i = 0; i < nd / 2; ++i) {
|
for (i = 0; i < nd / 2; ++i) {
|
||||||
void *ptr = v[i];
|
void *ptr = v[i];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -114,8 +114,10 @@ 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 */
|
* Recover the nrd data blocks specified in ir[],
|
||||||
|
* using the first nrd parity in ip[] for recovering
|
||||||
|
*/
|
||||||
raid_rec_ptr[nrd - 1](nrd, ir, ip, nd, size, v);
|
raid_rec_ptr[nrd - 1](nrd, ir, ip, nd, size, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -571,9 +573,11 @@ int raid_selftest(void)
|
||||||
ir[np / 2 + i] = nd + i;
|
ir[np / 2 + i] = nd + i;
|
||||||
}
|
}
|
||||||
for (i = 0; i < np - 1; ++i) {
|
for (i = 0; i < np - 1; ++i) {
|
||||||
/* make blocks bad */
|
/*
|
||||||
/* we cannot fill them with 0, because the original */
|
* Make blocks bad
|
||||||
/* data may be already filled with 0 */
|
* we cannot fill them with 0, because the original
|
||||||
|
* data may be already filled with 0
|
||||||
|
*/
|
||||||
memset(v[ir[i]], 0x55, size);
|
memset(v[ir[i]], 0x55, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
38
raid/raid.c
38
raid/raid.c
|
|
@ -230,9 +230,11 @@ void raid_invert(uint8_t *M, uint8_t *V, int n)
|
||||||
for (k = 0; k < n; ++k) {
|
for (k = 0; k < n; ++k) {
|
||||||
uint8_t f;
|
uint8_t f;
|
||||||
|
|
||||||
/* the diagonal element cannot be 0 because */
|
/*
|
||||||
/* we are inverting matrices with all the square */
|
* The diagonal element cannot be 0 because
|
||||||
/* submatrices not singular */
|
* we are inverting matrices with all the square
|
||||||
|
* submatrices not singular
|
||||||
|
*/
|
||||||
BUG_ON(M[k * n + k] == 0);
|
BUG_ON(M[k * n + k] == 0);
|
||||||
|
|
||||||
/* make the diagonal element to be 1 */
|
/* make the diagonal element to be 1 */
|
||||||
|
|
@ -242,8 +244,10 @@ void raid_invert(uint8_t *M, uint8_t *V, int n)
|
||||||
V[k * n + j] = mul(f, V[k * n + j]);
|
V[k * n + j] = mul(f, V[k * n + j]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* make all the elements over and under the diagonal */
|
/*
|
||||||
/* to be zero */
|
* Make all the elements over and under the diagonal
|
||||||
|
* to be zero
|
||||||
|
*/
|
||||||
for (i = 0; i < n; ++i) {
|
for (i = 0; i < n; ++i) {
|
||||||
if (i == k)
|
if (i == k)
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -270,8 +274,10 @@ void raid_delta_gen(int nr, int *id, int *ip, int nd, size_t size, void **v)
|
||||||
int np;
|
int np;
|
||||||
void *latest;
|
void *latest;
|
||||||
|
|
||||||
/* total number of parities we are going to process */
|
/*
|
||||||
/* they are both the used and the unused ones */
|
* Total number of parities we are going to process
|
||||||
|
* they are both the used and the unused ones
|
||||||
|
*/
|
||||||
np = ip[nr - 1] + 1;
|
np = ip[nr - 1] + 1;
|
||||||
|
|
||||||
/* latest missing data block */
|
/* latest missing data block */
|
||||||
|
|
@ -291,8 +297,10 @@ void raid_delta_gen(int nr, int *id, int *ip, int nd, size_t size, void **v)
|
||||||
* to point to the "zero" buffer.
|
* to point to the "zero" buffer.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* the latest parity to use ends the for loop and */
|
/*
|
||||||
/* then it cannot happen to process more of them */
|
* The latest parity to use ends the for loop and
|
||||||
|
* then it cannot happen to process more of them
|
||||||
|
*/
|
||||||
BUG_ON(j >= nr);
|
BUG_ON(j >= nr);
|
||||||
|
|
||||||
/* buffer for missing data blocks */
|
/* buffer for missing data blocks */
|
||||||
|
|
@ -332,8 +340,10 @@ void raid_delta_gen(int nr, int *id, int *ip, int nd, size_t size, void **v)
|
||||||
/* all the parities have to be processed */
|
/* all the parities have to be processed */
|
||||||
BUG_ON(j != nr);
|
BUG_ON(j != nr);
|
||||||
|
|
||||||
/* recompute the parity, note that np may be smaller than the */
|
/*
|
||||||
/* total number of parities available */
|
* Recompute the parity, note that np may be smaller than the
|
||||||
|
* total number of parities available
|
||||||
|
*/
|
||||||
raid_gen(nd, np, size, v);
|
raid_gen(nd, np, size, v);
|
||||||
|
|
||||||
/* restore data buffers as before */
|
/* restore data buffers as before */
|
||||||
|
|
@ -361,8 +371,10 @@ void raid_rec1of1(int *id, int nd, size_t size, void **v)
|
||||||
void *p;
|
void *p;
|
||||||
void *pa;
|
void *pa;
|
||||||
|
|
||||||
/* for PAR1 we can directly compute the missing block */
|
/*
|
||||||
/* and we don't need to use the zero buffer */
|
* For PAR1 we can directly compute the missing block
|
||||||
|
* and we don't need to use the zero buffer
|
||||||
|
*/
|
||||||
p = v[nd];
|
p = v[nd];
|
||||||
pa = v[id[0]];
|
pa = v[id[0]];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,9 +25,11 @@ static __always_inline int raid_invert_fast(uint8_t *M, int n)
|
||||||
for (k = 0; k < n; ++k) {
|
for (k = 0; k < n; ++k) {
|
||||||
uint8_t f;
|
uint8_t f;
|
||||||
|
|
||||||
/* the diagonal element cannot be 0 because */
|
/*
|
||||||
/* we are inverting matrices with all the square */
|
* The diagonal element cannot be 0 because
|
||||||
/* submatrices not singular */
|
* we are inverting matrices with all the square
|
||||||
|
* submatrices not singular
|
||||||
|
*/
|
||||||
if (M[k * n + k] == 0)
|
if (M[k * n + k] == 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
|
@ -36,8 +38,10 @@ static __always_inline int raid_invert_fast(uint8_t *M, int n)
|
||||||
for (j = 0; j < n; ++j)
|
for (j = 0; j < n; ++j)
|
||||||
M[k * n + j] = mul(f, M[k * n + j]);
|
M[k * n + j] = mul(f, M[k * n + j]);
|
||||||
|
|
||||||
/* make all the elements over and under the diagonal */
|
/*
|
||||||
/* to be zero */
|
* Make all the elements over and under the diagonal
|
||||||
|
* to be zero
|
||||||
|
*/
|
||||||
for (i = 0; i < n; ++i) {
|
for (i = 0; i < n; ++i) {
|
||||||
if (i == k)
|
if (i == k)
|
||||||
continue;
|
continue;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue