mirror of
https://github.com/intel/isa-l.git
synced 2024-12-12 09:23:50 +01:00
erasure_code: [perf] get parameters for number of buffers
Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
This commit is contained in:
parent
07af4032ff
commit
9d487fd6db
@ -50,6 +50,9 @@
|
||||
#elif defined (TEST_CUSTOM)
|
||||
# define TEST_TYPE_STR "_cus"
|
||||
#endif
|
||||
#ifndef TEST_SEED
|
||||
# define TEST_SEED 0x1234
|
||||
#endif
|
||||
|
||||
#define MMAX TEST_SOURCES
|
||||
#define KMAX TEST_SOURCES
|
||||
@ -58,6 +61,17 @@
|
||||
|
||||
typedef unsigned char u8;
|
||||
|
||||
void usage(const char *app_name)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"Usage: %s [options]\n"
|
||||
" -h Help\n"
|
||||
" -k <val> Number of source buffers\n"
|
||||
" -p <val> Number of parity buffers\n"
|
||||
" -e <val> Number of simulated buffers with errors (cannot be higher than p or k)\n",
|
||||
app_name);
|
||||
}
|
||||
|
||||
void ec_encode_perf(int m, int k, u8 * a, u8 * g_tbls, u8 ** buffs, struct perf *start)
|
||||
{
|
||||
ec_init_tables(k, m - k, &a[k * k], g_tbls);
|
||||
@ -98,27 +112,85 @@ int ec_decode_perf(int m, int k, u8 * a, u8 * g_tbls, u8 ** buffs, u8 * src_in_e
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i, j, m, k, nerrs, check;
|
||||
int i, j, m, k, p, nerrs, check, ret = -1;
|
||||
void *buf;
|
||||
u8 *temp_buffs[TEST_SOURCES], *buffs[TEST_SOURCES];
|
||||
u8 *temp_buffs[TEST_SOURCES] = { NULL };
|
||||
u8 *buffs[TEST_SOURCES] = { NULL };
|
||||
u8 a[MMAX * KMAX];
|
||||
u8 g_tbls[KMAX * TEST_SOURCES * 32], src_in_err[TEST_SOURCES];
|
||||
u8 src_err_list[TEST_SOURCES];
|
||||
struct perf start;
|
||||
|
||||
// Pick test parameters
|
||||
m = 14;
|
||||
k = 10;
|
||||
/* Set default parameters */
|
||||
k = 8;
|
||||
p = 6;
|
||||
nerrs = 4;
|
||||
const u8 err_list[] = { 2, 4, 5, 7 };
|
||||
|
||||
printf("erasure_code_perf: %dx%d %d\n", m, TEST_LEN(m), nerrs);
|
||||
/* Parse arguments */
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (strcmp(argv[i], "-k") == 0) {
|
||||
k = atoi(argv[++i]);
|
||||
} else if (strcmp(argv[i], "-p") == 0) {
|
||||
p = atoi(argv[++i]);
|
||||
} else if (strcmp(argv[i], "-e") == 0) {
|
||||
nerrs = atoi(argv[++i]);
|
||||
} else if (strcmp(argv[i], "-h") == 0) {
|
||||
usage(argv[0]);
|
||||
return 0;
|
||||
} else {
|
||||
usage(argv[0]);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
m = k + p;
|
||||
|
||||
if (m > MMAX || k > KMAX || nerrs > (m - k)) {
|
||||
printf(" Input test parameter error\n");
|
||||
if (nerrs > k) {
|
||||
printf
|
||||
("Number of errors (%d) cannot be higher than number of data buffers (%d)\n",
|
||||
nerrs, k);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (nerrs > p) {
|
||||
printf
|
||||
("Number of errors (%d) cannot be higher than number of parity buffers (%d)\n",
|
||||
nerrs, p);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (m > MMAX) {
|
||||
printf("Number of total buffers (data and parity) cannot be higher than %d\n",
|
||||
MMAX);
|
||||
return -1;
|
||||
}
|
||||
|
||||
u8 *err_list = malloc(nerrs);
|
||||
if (err_list == NULL) {
|
||||
printf("Error allocating list of array of error indices\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
srand(TEST_SEED);
|
||||
|
||||
for (i = 0; i < nerrs;) {
|
||||
u8 next_err = rand() % k;
|
||||
for (j = 0; j < i; j++)
|
||||
if (next_err == err_list[j])
|
||||
break;
|
||||
if (j != i)
|
||||
continue;
|
||||
err_list[i++] = next_err;
|
||||
}
|
||||
|
||||
printf("Testing with %u data buffers and %u parity buffers (num errors = %u, in [ ", k,
|
||||
p, nerrs);
|
||||
for (i = 0; i < nerrs; i++)
|
||||
printf("%d ", err_list[i]);
|
||||
|
||||
printf("])\n");
|
||||
|
||||
printf("erasure_code_perf: %dx%d %d\n", m, TEST_LEN(m), nerrs);
|
||||
|
||||
memcpy(src_err_list, err_list, nerrs);
|
||||
memset(src_in_err, 0, TEST_SOURCES);
|
||||
for (i = 0; i < nerrs; i++)
|
||||
@ -127,16 +199,16 @@ int main(int argc, char *argv[])
|
||||
// Allocate the arrays
|
||||
for (i = 0; i < m; i++) {
|
||||
if (posix_memalign(&buf, 64, TEST_LEN(m))) {
|
||||
printf("alloc error: Fail\n");
|
||||
return -1;
|
||||
printf("Error allocating buffers\n");
|
||||
goto exit;
|
||||
}
|
||||
buffs[i] = buf;
|
||||
}
|
||||
|
||||
for (i = 0; i < (m - k); i++) {
|
||||
for (i = 0; i < p; i++) {
|
||||
if (posix_memalign(&buf, 64, TEST_LEN(m))) {
|
||||
printf("alloc error: Fail\n");
|
||||
return -1;
|
||||
printf("Error allocating buffers\n");
|
||||
goto exit;
|
||||
}
|
||||
temp_buffs[i] = buf;
|
||||
}
|
||||
@ -159,13 +231,14 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (check == BAD_MATRIX) {
|
||||
printf("BAD MATRIX\n");
|
||||
return check;
|
||||
ret = check;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
for (i = 0; i < nerrs; i++) {
|
||||
if (0 != memcmp(temp_buffs[i], buffs[src_err_list[i]], TEST_LEN(m))) {
|
||||
printf("Fail error recovery (%d, %d, %d) - ", m, k, nerrs);
|
||||
return -1;
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
|
||||
@ -173,5 +246,14 @@ int main(int argc, char *argv[])
|
||||
perf_print(start, (long long)(TEST_LEN(m)) * (k + nerrs));
|
||||
|
||||
printf("done all: Pass\n");
|
||||
return 0;
|
||||
|
||||
ret = 0;
|
||||
|
||||
exit:
|
||||
free(err_list);
|
||||
for (i = 0; i < TEST_SOURCES; i++) {
|
||||
free(buffs[i]);
|
||||
free(temp_buffs[i]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -64,12 +64,26 @@
|
||||
#elif defined (TEST_CUSTOM)
|
||||
# define TEST_TYPE_STR "_cus"
|
||||
#endif
|
||||
#ifndef TEST_SEED
|
||||
# define TEST_SEED 0x1234
|
||||
#endif
|
||||
|
||||
#define MMAX TEST_SOURCES
|
||||
#define KMAX TEST_SOURCES
|
||||
|
||||
typedef unsigned char u8;
|
||||
|
||||
void usage(const char *app_name)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"Usage: %s [options]\n"
|
||||
" -h Help\n"
|
||||
" -k <val> Number of source buffers\n"
|
||||
" -p <val> Number of parity buffers\n"
|
||||
" -e <val> Number of simulated buffers with errors (cannot be higher than p or k)\n",
|
||||
app_name);
|
||||
}
|
||||
|
||||
void dump(unsigned char *buf, int len)
|
||||
{
|
||||
int i;
|
||||
@ -133,29 +147,87 @@ int decode_test(int m, int k, u8 ** update_buffs, u8 ** recov, u8 * a, u8 * src_
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i, j, check, m, k, nerrs;
|
||||
int i, j, check, m, k, p, nerrs, ret = -1;
|
||||
void *buf;
|
||||
u8 *temp_buffs[TEST_SOURCES], *buffs[TEST_SOURCES];
|
||||
u8 *update_buffs[TEST_SOURCES];
|
||||
u8 *perf_update_buffs[TEST_SOURCES];
|
||||
u8 *temp_buffs[TEST_SOURCES] = { NULL };
|
||||
u8 *buffs[TEST_SOURCES] = { NULL };
|
||||
u8 *update_buffs[TEST_SOURCES] = { NULL };
|
||||
u8 *perf_update_buffs[TEST_SOURCES] = { NULL };
|
||||
u8 a[MMAX * KMAX];
|
||||
u8 g_tbls[KMAX * TEST_SOURCES * 32], src_in_err[TEST_SOURCES];
|
||||
u8 src_err_list[TEST_SOURCES], *recov[TEST_SOURCES];
|
||||
struct perf start;
|
||||
|
||||
// Pick test parameters
|
||||
/* Set default parameters */
|
||||
k = 10;
|
||||
m = k + VECT;
|
||||
p = VECT;
|
||||
nerrs = VECT;
|
||||
const u8 err_list[] = { 0, 2, 4, 5, 7, 8 };
|
||||
|
||||
printf(xstr(FUNCTION_UNDER_TEST) "_perf: %dx%d %d\n", m, TEST_LEN(m), nerrs);
|
||||
/* Parse arguments */
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (strcmp(argv[i], "-k") == 0) {
|
||||
k = atoi(argv[++i]);
|
||||
} else if (strcmp(argv[i], "-p") == 0) {
|
||||
p = atoi(argv[++i]);
|
||||
} else if (strcmp(argv[i], "-e") == 0) {
|
||||
nerrs = atoi(argv[++i]);
|
||||
} else if (strcmp(argv[i], "-h") == 0) {
|
||||
usage(argv[0]);
|
||||
return 0;
|
||||
} else {
|
||||
usage(argv[0]);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
m = k + p;
|
||||
|
||||
if (m > MMAX || k > KMAX || nerrs > (m - k)) {
|
||||
printf(" Input test parameter error\n");
|
||||
if (nerrs > k) {
|
||||
printf
|
||||
("Number of errors (%d) cannot be higher than number of data buffers (%d)\n",
|
||||
nerrs, k);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (nerrs > p) {
|
||||
printf
|
||||
("Number of errors (%d) cannot be higher than number of parity buffers (%d)\n",
|
||||
nerrs, p);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (m > MMAX) {
|
||||
printf("Number of total buffers (data and parity) cannot be higher than %d\n",
|
||||
MMAX);
|
||||
return -1;
|
||||
}
|
||||
|
||||
u8 *err_list = malloc(nerrs);
|
||||
if (err_list == NULL) {
|
||||
printf("Error allocating list of array of error indices\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
srand(TEST_SEED);
|
||||
|
||||
for (i = 0; i < nerrs;) {
|
||||
u8 next_err = rand() % k;
|
||||
for (j = 0; j < i; j++)
|
||||
if (next_err == err_list[j])
|
||||
break;
|
||||
if (j != i)
|
||||
continue;
|
||||
err_list[i++] = next_err;
|
||||
}
|
||||
|
||||
printf("Testing with %u data buffers and %u parity buffers (num errors = %u, in [ ", k,
|
||||
p, nerrs);
|
||||
for (i = 0; i < nerrs; i++)
|
||||
printf("%d ", err_list[i]);
|
||||
|
||||
printf("])\n");
|
||||
|
||||
printf(xstr(FUNCTION_UNDER_TEST) "_perf: %dx%d %d\n", m, TEST_LEN(m), nerrs);
|
||||
|
||||
memcpy(src_err_list, err_list, nerrs);
|
||||
memset(src_in_err, 0, TEST_SOURCES);
|
||||
for (i = 0; i < nerrs; i++)
|
||||
@ -164,16 +236,16 @@ int main(int argc, char *argv[])
|
||||
// Allocate the arrays
|
||||
for (i = 0; i < m; i++) {
|
||||
if (posix_memalign(&buf, 64, TEST_LEN(m))) {
|
||||
printf("alloc error: Fail\n");
|
||||
return -1;
|
||||
printf("Error allocating buffers\n");
|
||||
goto exit;
|
||||
}
|
||||
buffs[i] = buf;
|
||||
}
|
||||
|
||||
for (i = 0; i < (m - k); i++) {
|
||||
if (posix_memalign(&buf, 64, TEST_LEN(m))) {
|
||||
printf("alloc error: Fail\n");
|
||||
return -1;
|
||||
printf("Error allocating buffers\n");
|
||||
goto exit;
|
||||
}
|
||||
temp_buffs[i] = buf;
|
||||
memset(temp_buffs[i], 0, TEST_LEN(m)); // initialize the destination buffer to be zero for update function
|
||||
@ -181,16 +253,16 @@ int main(int argc, char *argv[])
|
||||
|
||||
for (i = 0; i < TEST_SOURCES; i++) {
|
||||
if (posix_memalign(&buf, 64, TEST_LEN(m))) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
printf("Error allocating buffers\n");
|
||||
goto exit;
|
||||
}
|
||||
update_buffs[i] = buf;
|
||||
memset(update_buffs[i], 0, TEST_LEN(m)); // initialize the destination buffer to be zero for update function
|
||||
}
|
||||
for (i = 0; i < TEST_SOURCES; i++) {
|
||||
if (posix_memalign(&buf, 64, TEST_LEN(m))) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
printf("Error allocating buffers\n");
|
||||
goto exit;
|
||||
}
|
||||
perf_update_buffs[i] = buf;
|
||||
memset(perf_update_buffs[i], 0, TEST_LEN(m)); // initialize the destination buffer to be zero for update function
|
||||
@ -213,7 +285,7 @@ int main(int argc, char *argv[])
|
||||
dump(update_buffs[k + i], 25);
|
||||
printf("buffs%d :", i);
|
||||
dump(buffs[k + i], 25);
|
||||
return -1;
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
|
||||
@ -262,13 +334,14 @@ int main(int argc, char *argv[])
|
||||
nerrs, g_tbls, perf_update_buffs));
|
||||
if (check) {
|
||||
printf("BAD_MATRIX\n");
|
||||
return -1;
|
||||
ret = check;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
for (i = 0; i < nerrs; i++) {
|
||||
if (0 != memcmp(temp_buffs[i], update_buffs[src_err_list[i]], TEST_LEN(m))) {
|
||||
printf("Fail error recovery (%d, %d, %d) - \n", m, k, nerrs);
|
||||
return -1;
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
|
||||
@ -276,5 +349,16 @@ int main(int argc, char *argv[])
|
||||
perf_print(start, (long long)(TEST_LEN(m)) * (k + nerrs));
|
||||
|
||||
printf("done all: Pass\n");
|
||||
return 0;
|
||||
|
||||
ret = 0;
|
||||
|
||||
exit:
|
||||
free(err_list);
|
||||
for (i = 0; i < TEST_SOURCES; i++) {
|
||||
free(buffs[i]);
|
||||
free(temp_buffs[i]);
|
||||
free(update_buffs[i]);
|
||||
free(perf_update_buffs[i]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user