*** BLURB HERE ***
Hao Fang (14): uadk_tool: test: change the comp_test directory to uadk_tool uadk_tool: test: unified the log print uadk_tool: test: remove comp test unused cmd uadk_tool: test: comp test remove the --ilist/olist cmd uadk_tool: test: remove unuse functions in comp_lib.h uadk_tool: test: reduce duplicate code in hw_blk_compress uadk_tool: test: comp test remove poll_thread_func uadk_tool: test: comp test remove the number in function name uadk_tool: test: comp test remove the batch mode uadk_tool: test: comp test remove the send_thread_func uadk_tool: comp test: move info.in_buf alloction into create_send_tdata uadk_tool: comp test: simplified the test_hw function uadk_tool: comp test: unified the test cmd format uadk_tool: comp test: some fixes found with checkpatch
Qi Tao (1): uadk_tool: fix error in saving the aead dst data
uadk_tool/Makefile.am | 11 +- uadk_tool/benchmark/sec_uadk_benchmark.c | 6 + uadk_tool/benchmark/uadk_benchmark.h | 2 +- uadk_tool/test/comp_lib.c | 1410 ++++++++++++++++++++++ uadk_tool/test/comp_lib.h | 300 +++++ uadk_tool/test/comp_main.c | 1393 +++++++++++++++++++++ uadk_tool/test/comp_main.h | 11 + uadk_tool/test/uadk_test.c | 8 +- 8 files changed, 3133 insertions(+), 8 deletions(-) create mode 100644 uadk_tool/test/comp_lib.c create mode 100644 uadk_tool/test/comp_lib.h create mode 100644 uadk_tool/test/comp_main.c create mode 100644 uadk_tool/test/comp_main.h
From: Hao Fang fanghao11@huawei.com
Now the uadk_tool is the unified test tool but comp test is still in the test/hisi_zip_test, and out of maintained for a long time.
Change the directory is the first step for refactoring the test tool.
Use this cmd for help: uadk_tool test --m zip --help
Signed-off-by: Hao Fang fanghao11@huawei.com Signed-off-by: Qi Tao taoqi10@huawei.com --- uadk_tool/Makefile.am | 11 +- uadk_tool/test/comp_lib.c | 1871 ++++++++++++++++++++++++++++++++++++ uadk_tool/test/comp_lib.h | 352 +++++++ uadk_tool/test/comp_main.c | 1843 +++++++++++++++++++++++++++++++++++ uadk_tool/test/comp_main.h | 9 + uadk_tool/test/uadk_test.c | 8 +- 6 files changed, 4087 insertions(+), 7 deletions(-) create mode 100644 uadk_tool/test/comp_lib.c create mode 100644 uadk_tool/test/comp_lib.h create mode 100644 uadk_tool/test/comp_main.c create mode 100644 uadk_tool/test/comp_main.h
diff --git a/uadk_tool/Makefile.am b/uadk_tool/Makefile.am index 6fa0d9d..5e8d4c5 100644 --- a/uadk_tool/Makefile.am +++ b/uadk_tool/Makefile.am @@ -19,7 +19,8 @@ uadk_tool_SOURCES=uadk_tool.c dfx/uadk_dfx.c dfx/uadk_dfx.h \ benchmark/zip_wd_benchmark.c benchmark/zip_wd_benchmark.h \ benchmark/trng_wd_benchmark.c benchmark/trng_wd_benchmark.h \ test/uadk_test.c test/uadk_test.h \ - test/test_sec.c test/test_sec.h test/sec_template_tv.h + test/test_sec.c test/test_sec.h test/sec_template_tv.h \ + test/comp_main.c test/comp_main.h test/comp_lib.c test/comp_lib.h
if WD_STATIC_DRV AM_CFLAGS+=-Bstatic @@ -36,6 +37,14 @@ uadk_tool_LDADD=-L../.libs -l:libwd.so.2 -l:libwd_crypto.so.2 \ -l:libwd_comp.so.2 -lnuma endif
+# For statistics +uadk_tool_LDADD+=-lm + +if HAVE_ZLIB +uadk_tool_LDADD+=-lz +uadk_tool_CPPFLAGS=-DUSE_ZLIB +endif + if WITH_ZLIB_FSE_DIR AM_CFLAGS += -DZLIB_FSE uadk_tool_LDADD+= $(with_zlib_fse_dir)/libfse.a diff --git a/uadk_tool/test/comp_lib.c b/uadk_tool/test/comp_lib.c new file mode 100644 index 0000000..4009295 --- /dev/null +++ b/uadk_tool/test/comp_lib.c @@ -0,0 +1,1871 @@ +// SPDX-License-Identifier: Apache-2.0 +/* + * Copyright 2020-2021 Huawei Technologies Co.,Ltd. All rights reserved. + * Copyright 2020-2021 Linaro ltd. + */ + +#include <pthread.h> +#include <signal.h> +#include <math.h> +#include <sys/mman.h> +#include <zlib.h> + +#include "comp_lib.h" + +#define SCHED_RR_NAME "sched_rr" + +struct check_rand_ctx { + int off; + unsigned long global_off; + __u32 last; + unsigned short state[3]; +}; + +#define dbg(msg, ...) fprintf(stderr, msg, ##__VA_ARGS__) + +static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_spinlock_t lock; +static int count = 0; + +static struct wd_ctx_config *g_conf; + +int sum_pend = 0, sum_thread_end = 0; + +__attribute__((constructor)) +void lock_constructor(void) +{ + if (pthread_spin_init(&lock, PTHREAD_PROCESS_SHARED) != 0) + exit(1); +} + +__attribute__((destructor)) +void lock_destructor(void) +{ + if (pthread_spin_destroy(&lock) != 0) + exit(1); +} + +void *mmap_alloc(size_t len) +{ + void *p; + long page_size = sysconf(_SC_PAGESIZE); + + if (len % page_size) + return malloc(len); + + p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, + -1, 0); + if (p == MAP_FAILED) + WD_ERR("Failed to allocate %zu bytes\n", len); + + return p == MAP_FAILED ? NULL : p; +} + +int mmap_free(void *addr, size_t len) +{ + long page_size = sysconf(_SC_PAGESIZE); + + if (len % page_size) { + free(addr); + return 0; + } + + return munmap(addr, len); +} + +static int hizip_check_rand(unsigned char *buf, unsigned int size, void *opaque) +{ + int i; + int *j; + __u32 n; + struct check_rand_ctx *rand_ctx = opaque; + + j = &rand_ctx->off; + for (i = 0; i < size; i += 4) { + if (*j) { + /* Something left from a previous run */ + n = rand_ctx->last; + } else { + n = nrand48(rand_ctx->state); + rand_ctx->last = n; + } + for (; *j < 4 && i + *j < size; (*j)++) { + char expected = (n >> (8 * *j)) & 0xff; + char actual = buf[i + *j]; + + if (expected != actual) { + WD_ERR("Invalid decompressed char at offset %lu: expected 0x%x != 0x%x\n", + rand_ctx->global_off + i + *j, expected, + actual); + return -EINVAL; + } + } + if (*j == 4) + *j = 0; + } + rand_ctx->global_off += size; + return 0; +} + +static struct wd_datalist *get_datalist(void *addr, __u32 size) +{ + int count = (int)ceil((double)size / SGE_SIZE); + struct wd_datalist *head, *cur, *tmp; + int i; + + head = calloc(1, sizeof(struct wd_datalist)); + if (!head) { + WD_ERR("failed to alloc datalist head\n"); + return NULL; + } + + cur = head; + + for (i = 0; i < count; i++) { + cur->data = addr; + cur->len = (size > SGE_SIZE) ? SGE_SIZE : size; + addr += SGE_SIZE; + size -= SGE_SIZE; + if (i != count - 1) { + tmp = calloc(1, sizeof(struct wd_datalist)); + cur->next = tmp; + cur = tmp; + } + } + + return head; +} + +/** + * compress() - compress memory buffer. + * @alg_type: alg_type. + * + * This function compress memory buffer. + */ +int hw_blk_compress(int alg_type, int blksize, __u8 data_fmt, void *priv, + unsigned char *dst, __u32 *dstlen, + unsigned char *src, __u32 srclen) +{ + handle_t h_sess; + struct wd_comp_sess_setup setup; + struct sched_params param = {0}; + struct wd_datalist *list; + struct wd_comp_req req; + int ret = 0; + + setup.alg_type = alg_type; + setup.op_type = WD_DIR_COMPRESS; + setup.comp_lv = WD_COMP_L8; + setup.win_sz = WD_COMP_WS_8K; + param.type = setup.op_type; + param.numa_id = 0; + setup.sched_param = ¶m; + h_sess = wd_comp_alloc_sess(&setup); + if (!h_sess) { + fprintf(stderr,"fail to alloc comp sess!\n"); + return -EINVAL; + } + + if (data_fmt) { + WD_ERR("now sge size is %u\n", SGE_SIZE); + list = get_datalist(src, (__u32)srclen); + req.list_src = list; + list = get_datalist(dst, (__u32)*dstlen); + req.list_dst = list; + } else { + req.src = src; + req.dst = dst; + } + + req.src_len = srclen; + req.dst_len = *dstlen; + req.op_type = WD_DIR_COMPRESS; + req.cb = NULL; + req.data_fmt = data_fmt; + req.priv = priv; + + dbg("%s:input req: src_len: %d, dst_len:%d, data_fmt:%d\n", + __func__, req.src_len, req.dst_len, req.data_fmt); + + ret = wd_do_comp_sync(h_sess, &req); + if (ret < 0) { + fprintf(stderr,"fail to do comp sync(ret = %d)!\n", ret); + return ret; + } + + if (req.status) { + fprintf(stderr,"fail to do comp sync(status = %d)!\n", + req.status); + wd_comp_free_sess(h_sess); + return req.status; + } + *dstlen = req.dst_len; + + dbg("%s:input req: src_len: %d, dst_len:%d, data_fmt:%d\n", + __func__, req.src_len, req.dst_len, req.data_fmt); + + wd_comp_free_sess(h_sess); + + return ret; +} + +int hw_blk_decompress(int alg_type, int blksize, __u8 data_fmt, + unsigned char *dst, __u32 *dstlen, + unsigned char *src, __u32 srclen) +{ + handle_t h_sess; + struct wd_comp_sess_setup setup; + struct sched_params param = {0}; + struct wd_datalist *list; + struct wd_comp_req req; + int ret = 0; + + setup.alg_type = alg_type; + setup.op_type = WD_DIR_DECOMPRESS; + param.type = setup.op_type; + param.numa_id = 0; + setup.sched_param = ¶m; + h_sess = wd_comp_alloc_sess(&setup); + if (!h_sess) { + fprintf(stderr,"fail to alloc comp sess!\n"); + return -EINVAL; + } + + if (data_fmt) { + WD_ERR("now sge size is %u\n", SGE_SIZE); + list = get_datalist(src, (__u32)srclen); + req.list_src = list; + list = get_datalist(dst, (__u32)*dstlen); + req.list_dst = list; + } else { + req.src = src; + req.dst = dst; + } + + req.src_len = srclen; + req.dst_len = *dstlen; + req.op_type = WD_DIR_DECOMPRESS; + req.cb = NULL; + req.data_fmt = data_fmt; + + dbg("%s:input req: src:%p, dst:%p,src_len: %d, dst_len:%d\n", + __func__, req.src, req.dst, req.src_len, req.dst_len); + + + ret = wd_do_comp_sync(h_sess, &req); + if (ret < 0) { + fprintf(stderr,"fail to do comp sync(ret = %d)!\n", ret); + return ret; + } + + if (req.status) { + fprintf(stderr,"fail to do comp sync(status = %d)!\n", + req.status); + wd_comp_free_sess(h_sess); + return req.status; + } + *dstlen = req.dst_len; + + dbg("%s:output req: src:%p, dst:%p,src_len: %d, dst_len:%d\n", + __func__, req.src, req.dst, req.src_len, req.dst_len); + + wd_comp_free_sess(h_sess); + + return ret; +} + +int hw_stream_compress(int alg_type, int blksize, __u8 data_fmt, + unsigned char *dst, __u32 *dstlen, + unsigned char *src, __u32 srclen) +{ + handle_t h_sess; + struct wd_comp_sess_setup setup; + struct sched_params param = {0}; + struct wd_comp_req req; + int ret = 0; + + setup.alg_type = alg_type; + setup.op_type = WD_DIR_COMPRESS; + setup.comp_lv = WD_COMP_L8; + setup.win_sz = WD_COMP_WS_8K; + param.type = setup.op_type; + param.numa_id = 0; + setup.sched_param = ¶m; + h_sess = wd_comp_alloc_sess(&setup); + if (!h_sess) { + fprintf(stderr,"fail to alloc comp sess!\n"); + return -EINVAL; + } + req.src = src; + req.src_len = srclen; + req.dst = dst; + req.dst_len = *dstlen; + req.op_type = WD_DIR_COMPRESS; + req.cb = NULL; + req.data_fmt = data_fmt; + + dbg("%s:input req: src:%p, dst:%p,src_len: %d, dst_len:%d\n", + __func__, req.src, req.dst, req.src_len, req.dst_len); + + ret = wd_do_comp_sync2(h_sess, &req); + if (ret < 0) { + fprintf(stderr,"fail to do comp sync(ret = %d)!\n", ret); + return ret; + } + + if (req.status) { + fprintf(stderr,"fail to do comp sync(status = %d)!\n", + req.status); + wd_comp_free_sess(h_sess); + return req.status; + } + *dstlen = req.dst_len; + + dbg("%s:output req: src:%p, dst:%p,src_len: %d, dst_len:%d\n", + __func__, req.src, req.dst, req.src_len, req.dst_len); + + wd_comp_free_sess(h_sess); + + return ret; +} + +int hw_stream_decompress(int alg_type, int blksize, __u8 data_fmt, + unsigned char *dst, __u32 *dstlen, + unsigned char *src, __u32 srclen) +{ + handle_t h_sess; + struct wd_comp_sess_setup setup; + struct sched_params param = {0}; + struct wd_comp_req req; + int ret = 0; + + + setup.alg_type = alg_type; + setup.op_type = WD_DIR_DECOMPRESS; + param.type = setup.op_type; + param.numa_id = 0; + setup.sched_param = ¶m; + h_sess = wd_comp_alloc_sess(&setup); + if (!h_sess) { + fprintf(stderr,"fail to alloc comp sess!\n"); + return -EINVAL; + } + req.src = src; + req.src_len = srclen; + req.dst = dst; + req.dst_len = *dstlen; + req.op_type = WD_DIR_DECOMPRESS; + req.cb = NULL; + req.data_fmt = data_fmt; + + dbg("%s:input req: src:%p, dst:%p,src_len: %d, dst_len:%d\n", + __func__, req.src, req.dst, req.src_len, req.dst_len); + + + ret = wd_do_comp_sync2(h_sess, &req); + if (ret < 0) { + fprintf(stderr,"fail to do comp sync(ret = %d)!\n", ret); + return ret; + } + + if (req.status) { + fprintf(stderr,"fail to do comp sync(status = %d)!\n", + req.status); + wd_comp_free_sess(h_sess); + return req.status; + } + *dstlen = req.dst_len; + + dbg("%s:output req: src:%p, dst:%p,src_len: %d, dst_len:%d\n", + __func__, req.src, req.dst, req.src_len, req.dst_len); + + wd_comp_free_sess(h_sess); + + return ret; +} + +void hizip_prepare_random_input_data(char *buf, size_t len, size_t block_size) +{ + __u32 seed = 0; + unsigned short rand_state[3] = {(seed >> 16) & 0xffff, seed & 0xffff, 0x330e}; + + unsigned long remain_size; + __u32 size; + size_t i, j; + + /* + * TODO: change state for each buffer, to make sure there is no TLB + * aliasing. + */ + remain_size = len; + + while (remain_size > 0) { + if (remain_size > block_size) + size = block_size; + else + size = remain_size; + /* + * Prepare the input buffer with a reproducible sequence of + * numbers. nrand48() returns a pseudo-random number in the + * interval [0; 2^31). It's not really possible to compress a + * pseudo-random stream using deflate, since it can't find any + * string repetition. As a result the output size is bigger, + * with a ratio of 1.041. + */ + for (i = 0; i < size; i += 4) { + __u64 n = nrand48(rand_state); + + for (j = 0; j < 4 && i + j < size; j++) + buf[i + j] = (n >> (8 * j)) & 0xff; + } + + buf += size; + remain_size -= size; + } +} + +int hizip_prepare_random_compressed_data(char *buf, size_t out_len, size_t in_len, + size_t *produced, + struct test_options *opts) +{ + off_t off; + int ret = -EINVAL; + void *init_buf = mmap_alloc(in_len); + size_t in_block_size = opts->block_size; + size_t out_block_size = 2 * in_block_size; + + if (!init_buf) + return -ENOMEM; + + hizip_prepare_random_input_data(init_buf, in_len, opts->block_size); + + /* Compress each chunk separately since we're working in stateless mode */ + for (off = 0; off < in_len; off += in_block_size) { + ret = zlib_deflate(buf, out_block_size, init_buf + off, + in_block_size, produced, opts->alg_type); + if (ret) + break; + buf += out_block_size; + } + + munmap(init_buf, in_len); + return ret; +} + +int hizip_verify_random_output(struct test_options *opts, + struct hizip_test_info *info, + size_t out_sz) +{ + int ret; + int seed = 0; + off_t off = 0; + size_t checked = 0; + size_t total_checked = 0; + struct check_rand_ctx rand_ctx = { + .state = {(seed >> 16) & 0xffff, seed & 0xffff, 0x330e}, + }; + + if (!opts->verify) + return 0; + + if (opts->op_type == WD_DIR_DECOMPRESS) + /* Check plain output */ + return hizip_check_rand((void *)info->out_buf, out_sz, + &rand_ctx); + + do { + ret = hizip_check_output(info->out_buf + off, out_sz, + &checked, hizip_check_rand, &rand_ctx); + if (ret) { + WD_ERR("Check output failed with %d\n", ret); + return ret; + } + total_checked += checked; + off += opts->block_size * EXPANSION_RATIO; + } while (!ret && total_checked < opts->total_len); + + if (rand_ctx.global_off != opts->total_len) { + WD_ERR("Invalid output size %lu != %lu\n", + rand_ctx.global_off, opts->total_len); + return -EINVAL; + } + return 0; +} + +static void *async_cb(struct wd_comp_req *req, void *data) +{ + return NULL; +} + +void *send_thread_func(void *arg) +{ + thread_data_t *tdata = (thread_data_t *)arg; + struct hizip_test_info *info = tdata->info; + struct test_options *opts = info->opts; + size_t src_block_size, dst_block_size; + struct wd_comp_sess_setup setup; + struct sched_params param = {0}; + handle_t h_sess; + int j, ret; + size_t left; + + if (opts->op_type == WD_DIR_COMPRESS) { + src_block_size = opts->block_size; + dst_block_size = opts->block_size * EXPANSION_RATIO; + } else { + src_block_size = opts->block_size * EXPANSION_RATIO; + dst_block_size = opts->block_size; + } + + memset(&setup, 0, sizeof(struct wd_comp_sess_setup)); + setup.alg_type = opts->alg_type; + setup.op_type = opts->op_type; + setup.comp_lv = WD_COMP_L8; + setup.win_sz = WD_COMP_WS_8K; + param.type = setup.op_type; + param.numa_id = 0; + setup.sched_param = ¶m; + h_sess = wd_comp_alloc_sess(&setup); + if (!h_sess) + return NULL; + + for (j = 0; j < opts->compact_run_num; j++) { + if (opts->option & TEST_ZLIB) { + ret = zlib_deflate(info->out_buf, info->out_size, + info->in_buf, info->in_size, + &tdata->sum, opts->alg_type); + continue; + } + /* not TEST_ZLIB */ + left = opts->total_len; + tdata->req.op_type = opts->op_type; + tdata->req.src = info->in_buf; + tdata->req.dst = info->out_buf; + tdata->sum = 0; + while (left > 0) { + tdata->req.src_len = src_block_size; + tdata->req.dst_len = dst_block_size; + tdata->req.cb_param = &tdata->req; + if (opts->sync_mode) { + tdata->req.cb = async_cb; + count++; + ret = wd_do_comp_async(h_sess, &tdata->req); + } else { + tdata->req.cb = NULL; + ret = wd_do_comp_sync(h_sess, &tdata->req); + if (info->opts->faults & INJECT_SIG_WORK) + kill(getpid(), SIGTERM); + } + if (ret < 0) { + WD_ERR("do comp test fail with %d\n", ret); + return (void *)(uintptr_t)ret; + } else if (tdata->req.status) { + return (void *)(uintptr_t)tdata->req.status; + } + if (opts->op_type == WD_DIR_COMPRESS) + left -= src_block_size; + else + left -= dst_block_size; + tdata->req.src += src_block_size; + /* + * It's BLOCK (STATELESS) mode, so user needs to + * combine output buffer by himself. + */ + tdata->req.dst += dst_block_size; + tdata->sum += tdata->req.dst_len; + if (tdata->sum > info->out_size) { + fprintf(stderr, + "%s: exceed OUT limits (%ld > %ld)\n", + __func__, + tdata->sum, info->out_size); + break; + } + } + /* info->total_out are accessed by multiple threads */ + __atomic_add_fetch(&info->total_out, tdata->sum, + __ATOMIC_RELEASE); + } + wd_comp_free_sess(h_sess); + return NULL; +} + +int lib_poll_func(__u32 pos, __u32 expect, __u32 *count) +{ + int ret; + + ret = wd_comp_poll_ctx(pos, expect, count); + if (ret < 0) + return ret; + return 0; +} + +void *poll_thread_func(void *arg) +{ + struct hizip_test_info *info = (struct hizip_test_info *)arg; + int ret = 0, total = 0; + __u32 expected = 0, received; + + if (!info->opts->sync_mode) + return NULL; + while (1) { + if (info->opts->faults & INJECT_SIG_WORK) + kill(getpid(), SIGTERM); + + pthread_mutex_lock(&mutex); + if (!expected) + expected = 1; + if (count == 0) { + pthread_mutex_unlock(&mutex); + usleep(10); + continue; + } + expected = 1; + received = 0; + ret = wd_comp_poll(expected, &received); + if (ret == 0) + total += received; + if (count == total) { + pthread_mutex_unlock(&mutex); + break; + } else { + if (count > total) + expected = count - total; + pthread_mutex_unlock(&mutex); + usleep(10); + } + } + pthread_exit(NULL); +} + +int create_send_threads(struct test_options *opts, + struct hizip_test_info *info, + void *(*send_thread_func)(void *arg)) +{ + pthread_attr_t attr; + thread_data_t *tdatas; + int i, j, num, ret; + + num = opts->thread_num; + info->send_tds = calloc(1, sizeof(pthread_t) * num); + if (!info->send_tds) + return -ENOMEM; + info->send_tnum = num; + tdatas = calloc(1, sizeof(thread_data_t) * num); + if (!tdatas) { + ret = -ENOMEM; + goto out; + } + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); + for (i = 0; i < num; i++) { + tdatas[i].info = info; + ret = pthread_create(&info->send_tds[i], &attr, + send_thread_func, &tdatas[i]); + if (ret < 0) { + fprintf(stderr, "Fail to create send thread %d (%d)\n", + i, ret); + goto out_thd; + } + } + pthread_attr_destroy(&attr); + g_conf = &info->ctx_conf; + return 0; +out_thd: + for (j = 0; j < i; j++) + pthread_cancel(info->send_tds[j]); + free(tdatas); +out: + free(info->send_tds); + return ret; +} + +int create_poll_threads(struct hizip_test_info *info, + void *(*poll_thread_func)(void *arg), + int num) +{ + struct test_options *opts = info->opts; + pthread_attr_t attr; + int i, ret; + + if (!opts->sync_mode) + return 0; + info->poll_tds = calloc(1, sizeof(pthread_t) * num); + if (!info->poll_tds) + return -ENOMEM; + info->poll_tnum = num; + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); + for (i = 0; i < num; i++) { + ret = pthread_create(&info->poll_tds[i], &attr, + poll_thread_func, info); + if (ret < 0) { + fprintf(stderr, "Fail to create send thread %d (%d)\n", + i, ret); + goto out; + } + } + pthread_attr_destroy(&attr); + count = 0; + return 0; +out: + free(info->poll_tds); + return ret; +} + +void free_threads(struct hizip_test_info *info) +{ + if (info->send_tds) + free(info->send_tds); + if (info->poll_tds) + free(info->poll_tds); +} + +int attach_threads(struct test_options *opts, struct hizip_test_info *info) +{ + int i, ret; + void *tret; + + if (opts->sync_mode) { + for (i = 0; i < info->poll_tnum; i++) { + ret = pthread_join(info->poll_tds[i], NULL); + if (ret < 0) + fprintf(stderr, "Fail on poll thread with %d\n", + ret); + } + } + for (i = 0; i < info->send_tnum; i++) { + ret = pthread_join(info->send_tds[i], &tret); + if (ret < 0) + fprintf(stderr, "Fail on send thread with %d\n", ret); + } + return (int)(uintptr_t)tret; +} + +void gen_random_data(void *buf, size_t len) +{ + int i; + uint32_t seed = 0; + unsigned short rand_state[3] = {(seed >> 16) & 0xffff, + seed & 0xffff, + 0x330e}; + + for (i = 0; i < len >> 3; i++) + *((uint64_t *)buf + i) = nrand48(rand_state); +} + +int calculate_md5(comp_md5_t *md5, const void *buf, size_t len) +{ + if (!md5 || !buf || !len) + return -EINVAL; + MD5_Init(&md5->md5_ctx); + MD5_Update(&md5->md5_ctx, buf, len); + MD5_Final(md5->md, &md5->md5_ctx); + return 0; +} + +void dump_md5(comp_md5_t *md5) +{ + int i; + + for (i = 0; i < MD5_DIGEST_LENGTH - 1; i++) + printf("%02x-", md5->md[i]); + printf("%02x\n", md5->md[i]); +} + +int cmp_md5(comp_md5_t *orig, comp_md5_t *final) +{ + int i; + + if (!orig || !final) + return -EINVAL; + for (i = 0; i < MD5_DIGEST_LENGTH; i++) { + if (orig->md[i] != final->md[i]) { + printf("Original MD5: "); + dump_md5(orig); + printf("Final MD5: "); + dump_md5(final); + return -EINVAL; + } + } + return 0; +} + +static void *async2_cb(struct wd_comp_req *req, void *data) +{ + sem_t *sem = (sem_t *)data; + + if (sem) + sem_post(sem); + return NULL; +} + +/* used in BATCH mode */ +static void *async5_cb(struct wd_comp_req *req, void *data) +{ + thread_data_t *tdata = (thread_data_t *)data; + + pthread_spin_lock(&lock); + tdata->pcnt++; + if (tdata->batch_flag && (tdata->pcnt == tdata->bcnt)) { + tdata->pcnt = 0; + tdata->bcnt = 0; + tdata->batch_flag = 0; + pthread_spin_unlock(&lock); + sem_post(&tdata->sem); + } else + pthread_spin_unlock(&lock); + return NULL; +} + +void init_chunk_list(chunk_list_t *list, void *buf, size_t buf_sz, + size_t chunk_sz) +{ + chunk_list_t *p = NULL; + int i, count; + size_t sum; + + count = (buf_sz + chunk_sz - 1) / chunk_sz; + for (i = 0, sum = 0, p = list; i < count && sum <= buf_sz; i++, p++) { + p->addr = buf + sum; + p->size = MIN(buf_sz - sum, chunk_sz); + if (i == count - 1) + p->next = NULL; + else + p->next = p + 1; + sum += p->size; + } +} + +chunk_list_t *create_chunk_list(void *buf, size_t buf_sz, size_t chunk_sz) +{ + chunk_list_t *list; + int count; + + count = (buf_sz + chunk_sz - 1) / chunk_sz; + if (count > HIZIP_CHUNK_LIST_ENTRIES) + count = HIZIP_CHUNK_LIST_ENTRIES; + if (buf_sz / chunk_sz > count) + return NULL; + /* allocate entries with additional one */ + list = malloc(sizeof(chunk_list_t) * (count + 1)); + if (!list) + return NULL; + init_chunk_list(list, buf, buf_sz, chunk_sz); + return list; +} + +void free_chunk_list(chunk_list_t *list) +{ + free(list); +} + +/* + * Deflate a data block with compressed header. + */ +static int chunk_deflate2(void *in, size_t in_sz, void *out, size_t *out_sz, + struct test_options *opts) +{ + int alg_type = opts->alg_type; + z_stream strm; + int windowBits; + int ret; + + switch (alg_type) { + case WD_ZLIB: + windowBits = 15; + break; + case WD_DEFLATE: + windowBits = -15; + break; + case WD_GZIP: + windowBits = 15 + 16; + break; + default: + printf("algorithm %d unsupported by zlib\n", alg_type); + return -EINVAL; + } + memset(&strm, 0, sizeof(z_stream)); + strm.next_in = in; + strm.avail_in = in_sz; + strm.next_out = out; + strm.avail_out = *out_sz; + + ret = deflateInit2(&strm, Z_BEST_SPEED, Z_DEFLATED, windowBits, + 8, Z_DEFAULT_STRATEGY); + if (ret != Z_OK) { + printf("deflateInit2: %d\n", ret); + return -EINVAL; + } + + do { + ret = deflate(&strm, Z_FINISH); + if ((ret == Z_STREAM_ERROR) || (ret == Z_BUF_ERROR)) { + printf("defalte error %d - %s\n", ret, strm.msg); + ret = -ENOSR; + break; + } else if (!strm.avail_in) { + if (ret != Z_STREAM_END) + printf("deflate unexpected return: %d\n", ret); + ret = 0; + break; + } else if (!strm.avail_out) { + printf("deflate out of memory\n"); + ret = -ENOSPC; + break; + } + } while (ret == Z_OK); + + deflateEnd(&strm); + *out_sz = *out_sz - strm.avail_out; + return ret; +} + +/* + * This function is used in BLOCK mode. Each compressing in BLOCK mode + * produces compression header. + */ +static int chunk_inflate2(void *in, size_t in_sz, void *out, size_t *out_sz, + struct test_options *opts) +{ + z_stream strm; + int ret; + + memset(&strm, 0, sizeof(z_stream)); + /* Window size of 15, +32 for auto-decoding gzip/zlib */ + ret = inflateInit2(&strm, 15 + 32); + if (ret != Z_OK) { + printf("zlib inflateInit: %d\n", ret); + return -EINVAL; + } + + strm.next_in = in; + strm.avail_in = in_sz; + strm.next_out = out; + strm.avail_out = *out_sz; + do { + ret = inflate(&strm, Z_NO_FLUSH); + if ((ret < 0) || (ret == Z_NEED_DICT)) { + printf("zlib error %d - %s\n", ret, strm.msg); + goto out; + } + if (!strm.avail_out) { + if (!strm.avail_in || (ret == Z_STREAM_END)) + break; + printf("%s: avail_out is empty!\n", __func__); + goto out; + } + } while (strm.avail_in && (ret != Z_STREAM_END)); + inflateEnd(&strm); + *out_sz = *out_sz - strm.avail_out; + return 0; +out: + inflateEnd(&strm); + ret = -EINVAL; + return ret; +} + +/* + * Compress a list of chunk data and produce a list of chunk data by software. + * in_list & out_list should be formated first. + */ +int sw_deflate2(chunk_list_t *in_list, + chunk_list_t *out_list, + struct test_options *opts) +{ + chunk_list_t *p, *q; + int ret = -EINVAL; + + for (p = in_list, q = out_list; p && q; p = p->next, q = q->next) { + ret = chunk_deflate2(p->addr, p->size, q->addr, &q->size, + opts); + if (ret) + return ret; + } + return ret; +} + +/* + * Compress a list of chunk data and produce a list of chunk data by software. + * in_list & out_list should be formated first. + */ +int sw_inflate2(chunk_list_t *in_list, chunk_list_t *out_list, + struct test_options *opts) +{ + chunk_list_t *p, *q; + int ret = -EINVAL; + + for (p = in_list, q = out_list; p && q; p = p->next, q = q->next) { + ret = chunk_inflate2(p->addr, p->size, q->addr, &q->size, + opts); + if (ret) + return ret; + } + return ret; +} + +int hw_deflate4(handle_t h_dfl, + chunk_list_t *in_list, + chunk_list_t *out_list, + struct test_options *opts, + sem_t *sem) +{ + struct wd_comp_req *reqs; + chunk_list_t *p = in_list, *q = out_list; + int i, ret; + + if (!in_list || !out_list || !opts || !sem) + return -EINVAL; + /* reqs array could make async operations in parallel */ + reqs = malloc(sizeof(struct wd_comp_req) * HIZIP_CHUNK_LIST_ENTRIES); + if (!reqs) + return -ENOMEM; + + for (i = 0; p && q; p = p->next, q = q->next, i++) { + reqs[i].src = p->addr; + reqs[i].src_len = p->size; + reqs[i].dst = q->addr; + reqs[i].dst_len = q->size; + reqs[i].op_type = WD_DIR_COMPRESS; + + if (opts->sync_mode) { + reqs[i].cb = async2_cb; + reqs[i].cb_param = sem; + } + do { + if (opts->sync_mode) { + ret = wd_do_comp_async(h_dfl, &reqs[i]); + if (!ret) { + __atomic_add_fetch(&sum_pend, 1, + __ATOMIC_ACQ_REL); + sem_wait(sem); + } + } else + ret = wd_do_comp_sync(h_dfl, &reqs[i]); + } while (ret == -WD_EBUSY); + if (ret) + goto out; + q->size = reqs[i].dst_len; + /* make sure olist has the same length with ilist */ + if (!p->next) + q->next = NULL; + i++; + } + free(reqs); + return 0; +out: + free(reqs); + return ret; +} + +int hw_inflate4(handle_t h_ifl, + chunk_list_t *in_list, + chunk_list_t *out_list, + struct test_options *opts, + sem_t *sem) +{ + struct wd_comp_req *reqs; + chunk_list_t *p, *q; + int i = 0, ret; + + /* reqs array could make async operations in parallel */ + reqs = calloc(1, sizeof(struct wd_comp_req) * HIZIP_CHUNK_LIST_ENTRIES); + if (!reqs) + return -ENOMEM; + for (p = in_list, q = out_list; p && q; p = p->next, q = q->next) { + reqs[i].src = p->addr; + reqs[i].src_len = p->size; + reqs[i].dst = q->addr; + reqs[i].dst_len = q->size; + reqs[i].op_type = WD_DIR_DECOMPRESS; + if (opts->sync_mode) { + reqs[i].cb = async2_cb; + reqs[i].cb_param = sem; + } + do { + if (opts->sync_mode) { + ret = wd_do_comp_async(h_ifl, &reqs[i]); + if (!ret) { + __atomic_add_fetch(&sum_pend, 1, + __ATOMIC_ACQ_REL); + sem_wait(sem); + } + } else + ret = wd_do_comp_sync(h_ifl, &reqs[i]); + } while (ret == -WD_EBUSY); + if (ret) + goto out; + q->size = reqs[i].dst_len; + /* make sure olist has the same length with ilist */ + if (!p->next) + q->next = NULL; + i++; + } + free(reqs); + return 0; +out: + free(reqs); + return ret; +} + +/* used in BATCH mode */ +int hw_deflate5(handle_t h_dfl, + chunk_list_t *in_list, + chunk_list_t *out_list, + thread_data_t *tdata) +{ + struct hizip_test_info *info = tdata->info; + struct test_options *opts = info->opts; + struct wd_comp_req *reqs = tdata->reqs; + chunk_list_t *p = in_list, *q = out_list; + int i = 0, ret = 0; + + if (!in_list || !out_list || !opts) + return -EINVAL; + for (p = in_list, q = out_list; p && q; p = p->next, q = q->next) { + reqs[i].src = p->addr; + reqs[i].src_len = p->size; + reqs[i].dst = q->addr; + reqs[i].dst_len = q->size; + reqs[i].op_type = WD_DIR_COMPRESS; + reqs[i].data_fmt = opts->data_fmt; + if (opts->sync_mode) { + reqs[i].cb = async5_cb; + reqs[i].cb_param = tdata; + } else { + reqs[i].cb = NULL; + reqs[i].cb_param = NULL; + } + if (opts->sync_mode) { + do { + ret = wd_do_comp_async(h_dfl, &reqs[i]); + } while (ret == -WD_EBUSY); + if (ret < 0) + goto out; + __atomic_add_fetch(&sum_pend, 1, __ATOMIC_ACQ_REL); + pthread_spin_lock(&lock); + tdata->bcnt++; + if (((i + 1) == opts->batch_num) || !p->next) { + tdata->batch_flag = 1; + pthread_spin_unlock(&lock); + sem_wait(&tdata->sem); + } else + pthread_spin_unlock(&lock); + } else { + do { + ret = wd_do_comp_sync(h_dfl, &reqs[i]); + } while (ret == -WD_EBUSY); + if (ret) + goto out; + } + q->size = reqs[i].dst_len; + i = (i + 1) % opts->batch_num; + /* make sure olist has the same length with ilist */ + if (!p->next) + q->next = NULL; + } + return 0; +out: + return ret; +} + +/* used in BATCH mode */ +int hw_inflate5(handle_t h_ifl, + chunk_list_t *in_list, + chunk_list_t *out_list, + thread_data_t *tdata) +{ + struct hizip_test_info *info = tdata->info; + struct test_options *opts = info->opts; + struct wd_comp_req *reqs = tdata->reqs; + chunk_list_t *p = in_list, *q = out_list; + int ret = 0, i = 0; + + if (!in_list || !out_list || !opts) + return -EINVAL; + for (p = in_list, q = out_list; p && q; p = p->next, q = q->next) { + reqs[i].src = p->addr; + reqs[i].src_len = p->size; + reqs[i].dst = q->addr; + reqs[i].dst_len = q->size; + reqs[i].op_type = WD_DIR_DECOMPRESS; + reqs[i].data_fmt = opts->data_fmt; + if (opts->sync_mode) { + reqs[i].cb = async5_cb; + reqs[i].cb_param = tdata; + } else { + reqs[i].cb = NULL; + reqs[i].cb_param = NULL; + } + if (opts->sync_mode) { + do { + ret = wd_do_comp_async(h_ifl, &reqs[i]); + } while (ret == -WD_EBUSY); + if (ret < 0) + goto out; + __atomic_add_fetch(&sum_pend, 1, __ATOMIC_ACQ_REL); + pthread_spin_lock(&lock); + tdata->bcnt++; + if (((i + 1) == opts->batch_num) || !p->next) { + tdata->batch_flag = 1; + pthread_spin_unlock(&lock); + sem_wait(&tdata->sem); + } else + pthread_spin_unlock(&lock); + } else { + do { + ret = wd_do_comp_sync(h_ifl, &reqs[i]); + } while (ret == -WD_EBUSY); + if (ret) + goto out; + } + q->size = reqs[i].dst_len; + i = (i + 1) % opts->batch_num; + /* make sure olist has the same length with ilist */ + if (!p->next) + q->next = NULL; + } + return 0; +out: + return ret; +} + +/* + * info->in_buf & info->out_buf should be allocated first. + * Thread 0 shares info->out_buf. Other threads need to create its own + * dst buffer. + */ +int create_send_tdata(struct test_options *opts, + struct hizip_test_info *info) +{ + thread_data_t *tdata; + chunk_list_t *in_list, *out_list; + int i, j, num, ret; + + if (!opts || !info || !info->in_chunk_sz || !info->out_chunk_sz) + return -EINVAL; + num = opts->thread_num; + info->send_tds = calloc(1, sizeof(pthread_t) * num); + if (!info->send_tds) + return -ENOMEM; + info->send_tnum = num; + info->tdatas = calloc(1, sizeof(thread_data_t) * num); + if (!info->tdatas) { + ret = -ENOMEM; + goto out; + } + if (!opts->batch_num) + opts->batch_num = 1; + else if (opts->batch_num > HIZIP_CHUNK_LIST_ENTRIES) + opts->batch_num = HIZIP_CHUNK_LIST_ENTRIES; + if (opts->is_stream) { + in_list = create_chunk_list(info->in_buf, info->in_size, + info->in_size); + } else { + in_list = create_chunk_list(info->in_buf, info->in_size, + info->in_chunk_sz); + } + if (!in_list) { + ret = -EINVAL; + goto out_in; + } + if (opts->option & TEST_THP) { + ret = madvise(info->in_buf, info->in_size, MADV_HUGEPAGE); + if (ret) { + printf("madvise(MADV_HUGEPAGE)"); + goto out_in; + } + } + for (i = 0; i < num; i++) { + tdata = &info->tdatas[i]; + /* src address is shared among threads */ + tdata->tid = i; + tdata->src_sz = info->in_size; + tdata->src = info->in_buf; + tdata->in_list = in_list; + tdata->dst_sz = info->out_size; + tdata->dst = mmap_alloc(tdata->dst_sz); + if (!tdata->dst) { + ret = -ENOMEM; + goto out_dst; + } + if (opts->option & TEST_THP) { + ret = madvise(tdata->dst, tdata->dst_sz, MADV_HUGEPAGE); + if (ret) { + printf("madvise(MADV_HUGEPAGE)"); + goto out_dst; + } + } + /* + * Without memset, valgrind reports uninitialized buf + * for writing to file. + */ + memset(tdata->dst, 0, tdata->dst_sz); + if (opts->is_stream) { + out_list = create_chunk_list(tdata->dst, + tdata->dst_sz, + tdata->dst_sz); + } else { + out_list = create_chunk_list(tdata->dst, + tdata->dst_sz, + info->out_chunk_sz); + } + tdata->out_list = out_list; + if (!tdata->out_list) { + ret = -EINVAL; + goto out_list; + } + calculate_md5(&tdata->md5, tdata->src, tdata->src_sz); + tdata->reqs = malloc(sizeof(struct wd_comp_req) * + opts->batch_num); + if (!tdata->reqs) + goto out_list; + sem_init(&tdata->sem, 0, 0); + tdata->info = info; + } + return 0; +out_list: + mmap_free(tdata->dst, tdata->dst_sz); +out_dst: + for (j = 0; j < i; j++) { + pthread_cancel(info->send_tds[j]); + free_chunk_list(info->tdatas[j].out_list); + mmap_free(info->tdatas[j].dst, info->tdatas[j].dst_sz); + } + free_chunk_list(in_list); +out_in: + free(info->tdatas); +out: + free(info->send_tds); + return ret; +} + +int create_poll_tdata(struct test_options *opts, + struct hizip_test_info *info, + int poll_num) +{ + thread_data_t *tdatas; + int i, ret; + + if (opts->sync_mode == 0) + return 0; + else if (poll_num <= 0) + return -EINVAL; + info->poll_tnum = poll_num; + info->poll_tds = calloc(1, sizeof(pthread_t) * poll_num); + if (!info->poll_tds) + return -ENOMEM; + info->p_tdatas = calloc(1, sizeof(thread_data_t) * poll_num); + if (!info->p_tdatas) { + ret = -ENOMEM; + goto out; + } + tdatas = info->p_tdatas; + for (i = 0; i < poll_num; i++) { + tdatas[i].tid = i; + tdatas[i].info = info; + } + return 0; +out: + free(info->poll_tds); + return ret; +} + +/* + * Free source and destination buffer contained in sending threads. + * Free sending threads and polling threads. + */ +void free2_threads(struct hizip_test_info *info) +{ + thread_data_t *tdatas = info->tdatas; + int i; + + if (info->send_tds) + free(info->send_tds); + if (info->poll_tds) { + free(info->poll_tds); + free(info->p_tdatas); + } + free_chunk_list(tdatas[0].in_list); + for (i = 0; i < info->send_tnum; i++) { + free_chunk_list(tdatas[i].out_list); + free(tdatas[i].reqs); + } + /* info->out_buf is bound to tdatas[0].dst */ + for (i = 0; i < info->send_tnum; i++) + mmap_free(tdatas[i].dst, tdatas[i].dst_sz); + free(info->tdatas); + mmap_free(info->in_buf, info->in_size); +} + +int attach2_threads(struct test_options *opts, + struct hizip_test_info *info, + void *(*send_thread_func)(void *arg), + void *(*poll_thread_func)(void *arg)) +{ + int i, j, ret, num; + void *tret; + pthread_attr_t attr; + + num = opts->thread_num; + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); + for (i = 0; i < num; i++) { + ret = pthread_create(&info->send_tds[i], &attr, + send_thread_func, &info->tdatas[i]); + if (ret < 0) { + printf("Fail to create send thread %d (%d)\n", i, ret); + goto out; + } + } + if (opts->sync_mode && !opts->use_env) { + for (i = 0; i < opts->poll_num; i++) { + ret = pthread_create(&info->poll_tds[i], &attr, + poll_thread_func, + &info->tdatas[i]); + if (ret < 0) { + printf("Fail to create poll thread %d (%d)\n", + i, ret); + goto out_poll; + } + } + for (i = 0; i < info->poll_tnum; i++) { + ret = pthread_join(info->poll_tds[i], &tret); + if (ret < 0) { + fprintf(stderr, "Fail on poll thread with %d\n", + ret); + goto out_poll; + } + } + } + for (i = 0; i < info->send_tnum; i++) { + ret = pthread_join(info->send_tds[i], &tret); + if (ret < 0) { + fprintf(stderr, "Fail on send thread with %d\n", ret); + goto out_poll; + } + } + pthread_attr_destroy(&attr); + return (int)(uintptr_t)tret; +out_poll: + for (j = 0; j < i; j++) + pthread_cancel(info->poll_tds[j]); + i = opts->thread_num; +out: + for (j = 0; j < i; j++) + pthread_cancel(info->send_tds[j]); + pthread_attr_destroy(&attr); + return ret; +} + +void *poll2_thread_func(void *arg) +{ + thread_data_t *tdata = (thread_data_t *)arg; + struct hizip_test_info *info = tdata->info; + __u32 received; + int ret = 0; + struct timeval start_tvl, end_tvl; + int pending; + int end_threads; + + gettimeofday(&start_tvl, NULL); + while (1) { + end_threads = __atomic_load_n(&sum_thread_end, + __ATOMIC_ACQUIRE); + pending = __atomic_load_n(&sum_pend, __ATOMIC_ACQUIRE); + if ((end_threads == info->send_tnum) && (pending == 0)) + break; + else if (pending == 0) + continue; + received = 0; + ret = wd_comp_poll(pending, &received); + if (ret == 0) { + __atomic_sub_fetch(&sum_pend, + received, + __ATOMIC_ACQ_REL); + } + } + gettimeofday(&end_tvl, NULL); + timersub(&end_tvl, &start_tvl, &start_tvl); + pthread_exit(NULL); +} + +/* + * Choose a device and check whether it can afford the requested contexts. + * Return a list whose the first device is chosen. + */ +struct uacce_dev_list *get_dev_list(struct test_options *opts, + int children) +{ + struct uacce_dev_list *list, *p, *head = NULL, *prev = NULL; + int max_q_num; + + list = wd_get_accel_list("zlib"); + if (!list) + return NULL; + + p = list; + /* Find one device matching the requested contexts. */ + while (p) { + max_q_num = wd_get_avail_ctx(p->dev); + /* + * Check whether there's enough contexts. + * There may be multiple taskes running together. + * The number of multiple taskes is specified in children. + */ + if (max_q_num < 4 * opts->q_num * children) { + if (!head) + head = p; + prev = p; + p = p->next; + } else + break; + } + + if (!p) { + WD_ERR("Request too much contexts: %d\n", + opts->q_num * 4 * children); + goto out; + } + + /* Adjust p to the head of list if p is in the middle. */ + if (p && (p != list)) { + prev->next = p->next; + p->next = head; + return p; + } + return list; +out: + wd_free_list_accels(list); + return NULL; +} + +/* + * Initialize context numbers by the four times of opts->q_num. + * [sync, async] * [compress, decompress] = 4 + */ +int init_ctx_config(struct test_options *opts, void *priv, + struct wd_sched **sched) +{ + struct hizip_test_info *info = priv; + struct wd_ctx_config *ctx_conf = &info->ctx_conf; + struct sched_params param; + int i, j, ret = -EINVAL; + int q_num = opts->q_num; + + + __atomic_store_n(&sum_pend, 0, __ATOMIC_RELEASE); + __atomic_store_n(&sum_thread_end, 0, __ATOMIC_RELEASE); + *sched = wd_sched_rr_alloc(SCHED_POLICY_RR, 2, 2, lib_poll_func); + if (!*sched) { + WD_ERR("wd_sched_rr_alloc fail\n"); + goto out_sched; + } + + (*sched)->name = SCHED_RR_NAME; + + memset(ctx_conf, 0, sizeof(struct wd_ctx_config)); + ctx_conf->ctx_num = q_num * 4; + ctx_conf->ctxs = calloc(1, q_num * 4 * sizeof(struct wd_ctx)); + if (!ctx_conf->ctxs) { + WD_ERR("Not enough memory to allocate contexts.\n"); + ret = -ENOMEM; + goto out_ctx; + } + for (i = 0; i < ctx_conf->ctx_num; i++) { + ctx_conf->ctxs[i].ctx = wd_request_ctx(info->list->dev); + if (!ctx_conf->ctxs[i].ctx) { + WD_ERR("Fail to allocate context #%d\n", i); + ret = -EINVAL; + goto out_req; + } + } + /* + * All contexts for 2 modes & 2 types. + * The test only uses one kind of contexts at the same time. + */ + for (i = 0; i < q_num; i++) { + ctx_conf->ctxs[i].ctx_mode = 0; + ctx_conf->ctxs[i].op_type = 0; + } + param.numa_id = 0; + param.mode = 0; + param.type = 0; + param.begin = 0; + param.end = q_num - 1; + ret = wd_sched_rr_instance((const struct wd_sched *)*sched, ¶m); + if (ret < 0) { + WD_ERR("Fail to fill sched region.\n"); + goto out_fill; + } + for (i = q_num; i < q_num * 2; i++) { + ctx_conf->ctxs[i].ctx_mode = 0; + ctx_conf->ctxs[i].op_type = 1; + } + param.mode = 0; + param.type = 1; + param.begin = q_num; + param.end = q_num * 2 - 1; + ret = wd_sched_rr_instance((const struct wd_sched *)*sched, ¶m); + if (ret < 0) { + WD_ERR("Fail to fill sched region.\n"); + goto out_fill; + } + for (i = q_num * 2; i < q_num * 3; i++) { + ctx_conf->ctxs[i].ctx_mode = 1; + ctx_conf->ctxs[i].op_type = 0; + } + param.mode = 1; + param.type = 0; + param.begin = q_num * 2; + param.end = q_num * 3 - 1; + ret = wd_sched_rr_instance((const struct wd_sched *)*sched, ¶m); + if (ret < 0) { + WD_ERR("Fail to fill sched region.\n"); + goto out_fill; + } + for (i = q_num * 3; i < q_num * 4; i++) { + ctx_conf->ctxs[i].ctx_mode = 1; + ctx_conf->ctxs[i].op_type = 1; + } + param.mode = 1; + param.type = 1; + param.begin = q_num * 3; + param.end = q_num * 4 - 1; + ret = wd_sched_rr_instance((const struct wd_sched *)*sched, ¶m); + if (ret < 0) { + WD_ERR("Fail to fill sched region.\n"); + goto out_fill; + } + + ret = wd_comp_init(ctx_conf, *sched); + if (ret) + goto out_fill; + return ret; + +out_fill: + for (i = 0; i < ctx_conf->ctx_num; j++) + wd_release_ctx(ctx_conf->ctxs[i].ctx); +out_req: + free(ctx_conf->ctxs); +out_ctx: + wd_sched_rr_release(*sched); +out_sched: + return ret; +} + +void uninit_config(void *priv, struct wd_sched *sched) +{ + struct hizip_test_info *info = priv; + struct wd_ctx_config *ctx_conf = &info->ctx_conf; + int i; + + wd_comp_uninit(); + for (i = 0; i < ctx_conf->ctx_num; i++) + wd_release_ctx(ctx_conf->ctxs[i].ctx); + free(ctx_conf->ctxs); + wd_sched_rr_release(sched); +} + +int parse_common_option(const char opt, const char *optarg, + struct test_options *opts) +{ + switch (opt) { + case 'b': + opts->block_size = strtol(optarg, NULL, 0); + if (opts->block_size <= 0) + return 1; + break; + case 'l': + opts->compact_run_num = strtol(optarg, NULL, 0); + if (opts->compact_run_num <= 0) + return 1; + break; + case 'n': + opts->run_num = strtol(optarg, NULL, 0); + SYS_ERR_COND(opts->run_num > MAX_RUNS, + "No more than %d runs supported\n", MAX_RUNS); + if (opts->run_num <= 0) + return 1; + break; + case 'q': + opts->q_num = strtol(optarg, NULL, 0); + if (opts->q_num <= 0) + return 1; + break; + case 'd': + opts->op_type = WD_DIR_DECOMPRESS; + break; + case 'F': + opts->is_file = true; + break; + case 'S': + opts->is_stream = MODE_STREAM; + break; + case 's': + opts->total_len = strtol(optarg, NULL, 0); + SYS_ERR_COND(opts->total_len <= 0, "invalid size '%s'\n", + optarg); + break; + case 't': + opts->thread_num = strtol(optarg, NULL, 0); + SYS_ERR_COND(opts->thread_num < 0, "invalid thread num '%s'\n", + optarg); + break; + case 'm': + opts->sync_mode = strtol(optarg, NULL, 0); + SYS_ERR_COND(opts->sync_mode < 0 || opts->sync_mode > 1, + "invalid sync mode '%s'\n", optarg); + break; + case 'V': + opts->verify = true; + break; + case 'v': + opts->verbose = true; + break; + case 'a': + opts->alg_type = WD_DEFLATE; + break; + case 'z': + opts->alg_type = WD_ZLIB; + break; + case 'L': + opts->data_fmt = WD_SGL_BUF; + break; + case 'Z': + opts->alg_type = WD_LZ77_ZSTD; + break; + default: + return 1; + } + + return 0; +} + +#ifdef HAVE_ZLIB + +#include <zlib.h> + +/* + * Try to decompress a buffer using zLib's inflate(). Call compare_output with + * the decompressed stream as argument + * + * Return 0 on success, or an error. + */ +int hizip_check_output(void *buf, size_t size, size_t *checked, + check_output_fn compare_output, void *opaque) +{ + int ret, ret2; + unsigned char *out_buffer; + const size_t out_buf_size = 0x100000; + z_stream stream = { + .next_in = buf, + .avail_in = size, + }; + + out_buffer = calloc(1, out_buf_size); + if (!out_buffer) + return -ENOMEM; + + stream.next_out = out_buffer; + stream.avail_out = out_buf_size; + + /* Window size of 15, +32 for auto-decoding gzip/zlib */ + ret = inflateInit2(&stream, 15 + 32); + if (ret != Z_OK) { + WD_ERR("zlib inflateInit: %d\n", ret); + ret = -EINVAL; + goto out_free_buf; + } + + do { + ret = inflate(&stream, Z_NO_FLUSH); + if (ret < 0 || ret == Z_NEED_DICT) { + WD_ERR("zlib error %d - %s\n", ret, stream.msg); + ret = -ENOSR; + break; + } + + ret2 = compare_output(out_buffer, out_buf_size - + stream.avail_out, opaque); + /* compare_output should print diagnostic messages. */ + if (ret2) { + ret = Z_STREAM_ERROR; + break; + } + + if (!stream.avail_out) { + stream.next_out = out_buffer; + stream.avail_out = out_buf_size; + } + } while (ret != Z_STREAM_END); + + if (ret == Z_STREAM_END || ret == Z_OK) { + *checked = stream.total_out; + ret = 0; + } + + inflateEnd(&stream); +out_free_buf: + free(out_buffer); + return ret; +} + +int zlib_deflate(void *output, unsigned int out_size, + void *input, unsigned int in_size, + unsigned long *produced, int alg_type) +{ + int ret; + int windowBits; + z_stream stream = { + .next_in = input, + .avail_in = in_size, + .next_out = output, + .avail_out = out_size, + }; + + switch (alg_type) { + case WD_ZLIB: + windowBits = 15; + break; + case WD_DEFLATE: + windowBits = -15; + break; + case WD_GZIP: + windowBits = 15 + 16; + break; + default: + WD_ERR("algorithm %d unsupported by zlib\n", alg_type); + return -EINVAL; + } + + ret = deflateInit2(&stream, Z_BEST_SPEED, Z_DEFLATED, windowBits, 9, + Z_DEFAULT_STRATEGY); + if (ret != Z_OK) { + WD_ERR("zlib deflateInit: %d\n", ret); + return -EINVAL; + } + + do { + ret = deflate(&stream, Z_FINISH); + if (ret == Z_STREAM_ERROR || ret == Z_BUF_ERROR) { + WD_ERR("zlib error %d - %s\n", ret, stream.msg); + ret = -ENOSR; + break; + } else if (!stream.avail_in) { + if (ret != Z_STREAM_END) + WD_ERR("unexpected deflate return value %d\n", ret); + *produced = stream.total_out; + ret = 0; + break; + } else if (!stream.avail_out) { + WD_ERR("No more output available\n"); + ret = -ENOSPC; + break; + } + } while (ret == Z_OK); + + deflateEnd(&stream); + + return ret; +} +#endif diff --git a/uadk_tool/test/comp_lib.h b/uadk_tool/test/comp_lib.h new file mode 100644 index 0000000..95b5a31 --- /dev/null +++ b/uadk_tool/test/comp_lib.h @@ -0,0 +1,352 @@ +// SPDX-License-Identifier: Apache-2.0 +/* + * Copyright 2020-2021 Huawei Technologies Co.,Ltd. All rights reserved. + * Copyright 2020-2021 Linaro ltd. + */ + +#ifndef TEST_LIB_H_ +#define TEST_LIB_H_ + +#include <errno.h> +#include <openssl/md5.h> +#include <semaphore.h> +#include <stdio.h> +#include <stdlib.h> +#include <stdbool.h> +#include <sys/resource.h> +#include <sys/mman.h> +#include <sys/stat.h> +#include <sys/time.h> +#include <unistd.h> +#include "config.h" +#include "include/wd_comp.h" +#include "include/wd_sched.h" + +#define SYS_ERR_COND(cond, msg, ...) \ +do { \ + if (cond) { \ + if (errno) \ + perror(msg); \ + else \ + fprintf(stderr, msg, ##__VA_ARGS__); \ + exit(EXIT_FAILURE); \ + } \ +} while (0) + +enum mode { + MODE_BLOCK, + MODE_STREAM, +}; + +#define __ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask)) +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1) +#define MIN(a, b) ((a < b) ? a : b) + +/* + * I observed a worst case of 1.041x expansion with random data, but let's say 2 + * just in case. TODO: reduce this + */ +#define EXPANSION_RATIO 2 +/* The INFLATION_RATIO is high for text file. */ +#define INFLATION_RATIO 24 + +#define SGE_SIZE (8 * 1024) + +#define HIZIP_CHUNK_LIST_ENTRIES 32768 + +struct test_options { + int alg_type; + int op_type; + + /* bytes of data for a request */ + int block_size; + int q_num; + unsigned long total_len; + +#define MAX_RUNS 1024 + int run_num; + /* tasks running in parallel */ + int compact_run_num; + + /* send thread number */ + int thread_num; + /* poll thread number -- ASYNC */ + int poll_num; + /* 0: sync mode, 1: async mode */ + int sync_mode; + /* + * positive value: the number of messages are sent at a time. + * 0: batch mode is disabled. + * batch mode is only valid for ASYNC operations. + */ + int batch_num; + /* input file */ + int fd_in; + /* output file */ + int fd_out; + /* inlist file */ + int fd_ilist; + /* outlist file */ + int fd_olist; + + /* 0: pbuffer, 1: sgl */ + __u8 data_fmt; + + bool verify; + bool verbose; + bool is_decomp; + bool is_stream; + bool is_file; + bool use_env; + + int warmup_num; + +#define PERFORMANCE (1UL << 0) +#define TEST_ZLIB (1UL << 1) +#define TEST_THP (1UL << 2) + unsigned long option; + +#define STATS_NONE 0 +#define STATS_PRETTY 1 +#define STATS_CSV 2 + unsigned long display_stats; + + /* bind test case related below */ + int children; + +#define INJECT_SIG_BIND (1UL << 0) +#define INJECT_SIG_WORK (1UL << 1) +#define INJECT_TLB_FAULT (1UL << 2) + unsigned long faults; + +}; + +typedef struct _comp_md5_t { + MD5_CTX md5_ctx; + unsigned char md[MD5_DIGEST_LENGTH]; +} comp_md5_t; + +typedef struct hizip_chunk_list { + void *addr; + size_t size; + struct hizip_chunk_list *next; +} chunk_list_t; + +typedef struct _thread_data_t { + struct hizip_test_info *info; + struct wd_comp_req req; + comp_md5_t md5; + void *src; + void *dst; + size_t src_sz; + size_t dst_sz; + size_t sum; /* produced bytes for OUT */ + int tid; /* thread ID */ + int bcnt; /* batch mode: count */ + int pcnt; /* batch mode: poll count */ + int flush_bcnt; /* batch mode: flush count that is less batch_num */ + /* + * batch mode: set flag and wait batch end in sending thread. + * Clear batch flag if pcnt == bcnt in polling thread. + * batch_flag could replace flush_bcnt. + */ + int batch_flag; + sem_t sem; + chunk_list_t *in_list; + chunk_list_t *out_list; + struct wd_comp_req *reqs; +} thread_data_t; + +struct hizip_test_info { + struct test_options *opts; + char *in_buf, *out_buf; + size_t in_size, out_size; + /* in_chunk_sz & out_chunk_sz are used to format entries in list */ + size_t in_chunk_sz, out_chunk_sz; + size_t total_out; + struct uacce_dev_list *list; + handle_t h_sess; + struct wd_ctx_config ctx_conf; + pthread_t *send_tds; + int send_tnum; + pthread_t *poll_tds; + int poll_tnum; + /* tdatas: send thread data array, p_tdatas: poll thread data array */ + thread_data_t *tdatas; + thread_data_t *p_tdatas; + struct hizip_stats *stats; + struct { + struct timespec setup_time; + struct timespec start_time; + struct timespec end_time; + struct timespec setup_cputime; + struct timespec start_cputime; + struct timespec end_cputime; + struct rusage setup_rusage; + struct rusage start_rusage; + struct rusage end_rusage; + } tv; +}; + +extern int sum_pend, sum_thread_end; + +void *send_thread_func(void *arg); +void *poll_thread_func(void *arg); +void *sw_dfl_sw_ifl(void *arg); +int create_send_threads(struct test_options *opts, + struct hizip_test_info *info, + void *(*send_thread_func)(void *arg)); +int create_poll_threads(struct hizip_test_info *info, + void *(*poll_thread_func)(void *arg), + int num); +void free_threads(struct hizip_test_info *info); +int attach_threads(struct test_options *opts, + struct hizip_test_info *info); + +void gen_random_data(void *buf, size_t len); +int calculate_md5(comp_md5_t *md5, const void *buf, size_t len); +void dump_md5(comp_md5_t *md5); +int cmp_md5(comp_md5_t *orig, comp_md5_t *final); +void init_chunk_list(chunk_list_t *list, void *buf, size_t buf_sz, + size_t chunk_sz); +chunk_list_t *create_chunk_list(void *buf, size_t buf_sz, size_t chunk_sz); +void free_chunk_list(chunk_list_t *list); +int sw_deflate2(chunk_list_t *in_list, + chunk_list_t *out_list, + struct test_options *opts); +int sw_inflate2(chunk_list_t *in_list, + chunk_list_t *out_list, + struct test_options *opts); +int hw_deflate4(handle_t h_dfl, + chunk_list_t *in_list, + chunk_list_t *out_list, + struct test_options *opts, + sem_t *sem); +int hw_inflate4(handle_t h_ifl, + chunk_list_t *in_list, + chunk_list_t *out_list, + struct test_options *opts, + sem_t *sem); +int hw_deflate5(handle_t h_dfl, + chunk_list_t *in_list, + chunk_list_t *out_list, + thread_data_t *tdata); +int hw_inflate5(handle_t h_ifl, + chunk_list_t *in_list, + chunk_list_t *out_list, + thread_data_t *tdata); +int create_send_tdata(struct test_options *opts, + struct hizip_test_info *info); +int create_poll_tdata(struct test_options *opts, + struct hizip_test_info *info, + int poll_num); +void free2_threads(struct hizip_test_info *info); +int attach2_threads(struct test_options *opts, + struct hizip_test_info *info, + void *(*send_thread_func)(void *arg), + void *(*poll_thread_func)(void *arg)); +void *poll2_thread_func(void *arg); +int run_self_test(struct test_options *opts); +int run_cmd(struct test_options *opts); +int init_ctx_config(struct test_options *opts, + void *priv, + struct wd_sched **sched + ); +void uninit_config(void *priv, struct wd_sched *sched); +struct uacce_dev_list *get_dev_list(struct test_options *opts, int children); + +void hizip_prepare_random_input_data(char *buf, size_t len, size_t block_size); +int hizip_prepare_random_compressed_data(char *buf, size_t out_len, + size_t in_len, size_t *produced, + struct test_options *opts); + +int hizip_verify_random_output(struct test_options *opts, + struct hizip_test_info *info, + size_t out_sz); + +void *mmap_alloc(size_t len); +int mmap_free(void *addr, size_t len); + +int lib_poll_func(__u32 pos, __u32 expect, __u32 *count); +typedef int (*check_output_fn)(unsigned char *buf, unsigned int size, void *opaque); + +/* for block interface */ +int hw_blk_compress(int alg_type, int blksize, __u8 data_fmt, void *priv, + unsigned char *dst, __u32 *dstlen, + unsigned char *src, __u32 srclen); + +int hw_blk_decompress(int alg_type, int blksize, __u8 data_fmt, + unsigned char *dst, __u32 *dstlen, + unsigned char *src, __u32 srclen); + +/* for stream memory interface */ +int hw_stream_compress(int alg_type, int blksize, __u8 data_fmt, + unsigned char *dst, __u32 *dstlen, + unsigned char *src, __u32 srclen); + +int hw_stream_decompress(int alg_type, int blksize, __u8 data_fmt, + unsigned char *dst, __u32 *dstlen, + unsigned char *src, __u32 srclen); + +#ifdef USE_ZLIB +int hizip_check_output(void *buf, size_t size, size_t *checked, + check_output_fn check_output, void *opaque); +int zlib_deflate(void *output, unsigned int out_size, + void *input, unsigned int in_size, unsigned long *produced, + int alg_type); +#else +static inline int hizip_check_output(void *buf, size_t size, size_t *checked, + check_output_fn check_output, + void *opaque) +{ + static bool printed = false; + + if (!printed) { + WD_ERR("no zlib available, output buffer won't be checked\n"); + printed = true; + } + return -ENOSYS; +} +static inline int zlib_deflate(void *output, unsigned int out_size, void *input, + unsigned int in_size, unsigned long *produced, + int alg_type) +{ + WD_ERR("no zlib available\n"); + return -ENOSYS; +} +#endif + +static inline void hizip_test_adjust_len(struct test_options *opts) +{ + /* + * Align size to the next block. We allow non-power-of-two block sizes. + */ + opts->total_len = (opts->total_len + opts->block_size - 1) / + opts->block_size * opts->block_size; +} + +#define COMMON_OPTSTRING "hb:n:q:l:FSs:Vvzt:m:dacLZ" + +#define COMMON_HELP "%s [opts]\n" \ + " -b <size> block size\n" \ + " -n <num> number of runs\n" \ + " -q <num> number of queues\n" \ + " -l <num> number of compact runs\n" \ + " -F input file, default no input\n" \ + " -S stream mode, default block mode\n" \ + " -s <size> total size\n" \ + " -V verify output\n" \ + " -v display detailed performance information\n" \ + " -a test deflate algorithm, default gzip\n" \ + " -z test zlib algorithm, default gzip\n" \ + " -t <num> number of thread per process\n" \ + " -m <mode> mode of queues: 0 sync, 1 async\n" \ + " -d test decompression, default compression\n" \ + " -c use cpu to do zlib\n" \ + " -L test sgl type buffer, default pbuffer\n" \ + " -Z test lz77_zstd algorithm, default gzip\n" \ + "\n\n" + +int parse_common_option(const char opt, const char *optarg, + struct test_options *opts); +#endif /* TEST_LIB_H_ */ diff --git a/uadk_tool/test/comp_main.c b/uadk_tool/test/comp_main.c new file mode 100644 index 0000000..a21a952 --- /dev/null +++ b/uadk_tool/test/comp_main.c @@ -0,0 +1,1843 @@ +// SPDX-License-Identifier: Apache-2.0 +/* + * Copyright 2020-2021 Huawei Technologies Co.,Ltd. All rights reserved. + * Copyright 2020-2021 Linaro ltd. + */ +#include <linux/perf_event.h> +#include <asm/unistd.h> /* For __NR_perf_event_open */ +#include <fenv.h> +#include <getopt.h> +#include <inttypes.h> +#include <math.h> +#include <signal.h> +#include <time.h> +#include <sys/ioctl.h> +#include <sys/mman.h> +#include <sys/types.h> +#include <sys/wait.h> +#include <unistd.h> + +#include "comp_lib.h" + +#define POLL_STRING_LEN 128 + +enum hizip_stats_variable { + ST_SETUP_TIME, + ST_RUN_TIME, + ST_CPU_TIME, + + /* CPU usage */ + ST_USER_TIME, + ST_SYSTEM_TIME, + + /* Faults */ + ST_MINFLT, + ST_MAJFLT, + + /* Context switches */ + ST_INVCTX, + ST_VCTX, + + /* Signals */ + ST_SIGNALS, + + /* Aggregated */ + ST_SPEED, + ST_TOTAL_SPEED, + ST_CPU_IDLE, + ST_FAULTS, + ST_IOPF, + + ST_COMPRESSION_RATIO, + + NUM_STATS +}; + +struct hizip_stats { + double v[NUM_STATS]; +}; + +extern int perf_event_open(struct perf_event_attr *attr, + pid_t pid, int cpu, int group_fd, + unsigned long flags); +extern int perf_event_get(const char *event_name, int **perf_fds, int *nr_fds); +extern unsigned long long perf_event_put(int *perf_fds, int nr_fds); +extern void stat_setup(struct hizip_test_info *info); +extern void stat_start(struct hizip_test_info *info); +extern void stat_end(struct hizip_test_info *info); + +static size_t count_chunk_list_sz(chunk_list_t *list) +{ + size_t sum = 0; + chunk_list_t *p; + + for (p = list; p; p = p->next) + sum += p->size; + return sum; +} + +static void *sw_dfl_hw_ifl(void *arg) +{ + thread_data_t *tdata = (thread_data_t *)arg; + struct hizip_test_info *info = tdata->info; + struct test_options *opts = info->opts; + struct wd_comp_sess_setup setup = {0}; + struct sched_params param = {0}; + handle_t h_ifl; + void *tbuf; + size_t tbuf_sz; + chunk_list_t *tlist; + comp_md5_t final_md5 = {{0}}; + int i, ret; + __u32 tout_sz; + + tbuf_sz = tdata->src_sz * EXPANSION_RATIO; + tbuf = mmap_alloc(tbuf_sz); + if (!tbuf) + return (void *)(uintptr_t)(-ENOMEM); + tlist = create_chunk_list(tbuf, tbuf_sz, + info->in_chunk_sz * EXPANSION_RATIO); + if (!tlist) { + ret = -ENOMEM; + goto out; + } + if (opts->option & PERFORMANCE) { + /* hack: + * memset buffer and trigger page fault early in the cpu + * instead of later in the SMMU + * Enhance performance in sva case + * no impact to non-sva case + */ + memset(tbuf, 5, tbuf_sz); + } + if (opts->is_stream) { + /* STREAM mode: only one entry in the list */ + init_chunk_list(tdata->in_list, tdata->src, + tdata->src_sz, tdata->src_sz); + for (i = 0; i < opts->compact_run_num; i++) { + init_chunk_list(tlist, tbuf, tbuf_sz, tbuf_sz); + init_chunk_list(tdata->out_list, tdata->dst, + tdata->dst_sz, tdata->dst_sz); + ret = sw_deflate2(tdata->in_list, tlist, opts); + if (ret) { + printf("Fail to deflate by zlib: %d\n", ret); + goto out_strm; + } + tout_sz = tdata->dst_sz; + ret = hw_stream_decompress(opts->alg_type, + opts->block_size, + opts->data_fmt, + tdata->dst, + &tout_sz, + tlist->addr, + tlist->size); + if (ret) { + printf("Fail to inflate by HW: %d\n", ret); + goto out_strm; + } + ret = calculate_md5(&tdata->md5, tdata->in_list->addr, + tdata->in_list->size); + if (ret) { + printf("Fail to generate MD5 (%d)\n", ret); + goto out_strm; + } + ret = calculate_md5(&final_md5, tdata->out_list->addr, + tout_sz); + if (ret) { + printf("Fail to generate MD5 (%d)\n", ret); + goto out_strm; + } + ret = cmp_md5(&tdata->md5, &final_md5); + if (ret) { + printf("MD5 is unmatched (%d) at %dth times on " + "thread %d\n", ret, i, tdata->tid); + goto out_strm; + } + } + free_chunk_list(tlist); + mmap_free(tbuf, tbuf_sz); + return NULL; + } + + /* BLOCK mode */ + setup.alg_type = opts->alg_type; + setup.op_type = WD_DIR_DECOMPRESS; + + param.type = setup.op_type; + param.numa_id = 0; + setup.sched_param = ¶m; + h_ifl = wd_comp_alloc_sess(&setup); + if (!h_ifl) { + ret = -EINVAL; + goto out_strm; + } + + init_chunk_list(tdata->in_list, tdata->src, tdata->src_sz, + info->in_chunk_sz); + for (i = 0; i < opts->compact_run_num; i++) { + init_chunk_list(tlist, tbuf, tbuf_sz, + info->in_chunk_sz * EXPANSION_RATIO); + init_chunk_list(tdata->out_list, tdata->dst, tdata->dst_sz, + info->out_chunk_sz); + ret = sw_deflate2(tdata->in_list, tlist, opts); + if (ret) { + printf("Fail to deflate by zlib: %d\n", ret); + goto out_run; + } + ret = hw_inflate4(h_ifl, tlist, tdata->out_list, opts, + &tdata->sem); + if (ret) { + printf("Fail to inflate by HW: %d\n", ret); + goto out_run; + } + ret = calculate_md5(&tdata->md5, tdata->src, tdata->src_sz); + if (ret) { + printf("Fail to generate MD5 (%d)\n", ret); + goto out_run; + } + ret = calculate_md5(&final_md5, tdata->dst, tdata->dst_sz); + if (ret) { + printf("Fail to generate MD5 (%d)\n", ret); + goto out_run; + } + ret = cmp_md5(&tdata->md5, &final_md5); + if (ret) { + printf("MD5 is unmatched (%d) at %dth times on " + "thread %d\n", ret, i, tdata->tid); + goto out_run; + } + } + wd_comp_free_sess(h_ifl); + free_chunk_list(tlist); + mmap_free(tbuf, tbuf_sz); + /* mark sending thread to end */ + __atomic_add_fetch(&sum_thread_end, 1, __ATOMIC_ACQ_REL); + return NULL; +out_run: + wd_comp_free_sess(h_ifl); +out_strm: + free_chunk_list(tlist); +out: + mmap_free(tbuf, tbuf_sz); + return (void *)(uintptr_t)(ret); +} + +static void *hw_dfl_sw_ifl(void *arg) +{ + thread_data_t *tdata = (thread_data_t *)arg; + struct hizip_test_info *info = tdata->info; + struct test_options *opts = info->opts; + struct wd_comp_sess_setup setup = {0}; + struct sched_params param = {0}; + handle_t h_dfl; + void *tbuf; + size_t tbuf_sz; + chunk_list_t *tlist; + comp_md5_t final_md5 = {{0}}; + int i, ret; + __u32 tmp_sz; + + tbuf_sz = tdata->src_sz * EXPANSION_RATIO; + tbuf = mmap_alloc(tbuf_sz); + if (!tbuf) + return (void *)(uintptr_t)(-ENOMEM); + tlist = create_chunk_list(tbuf, tbuf_sz, + opts->block_size * EXPANSION_RATIO); + if (!tlist) { + ret = -ENOMEM; + goto out; + } + if (opts->option & PERFORMANCE) { + /* hack: + * memset buffer and trigger page fault early in the cpu + * instead of later in the SMMU + * Enhance performance in sva case + * no impact to non-sva case + */ + memset(tbuf, 5, tbuf_sz); + } + if (opts->is_stream) { + /* STREAM mode: only one entry in the list */ + init_chunk_list(tdata->in_list, tdata->src, + tdata->src_sz, tdata->src_sz); + for (i = 0; i < opts->compact_run_num; i++) { + init_chunk_list(tlist, tbuf, tbuf_sz, tbuf_sz); + init_chunk_list(tdata->out_list, tdata->dst, + tdata->dst_sz, tdata->dst_sz); + tmp_sz = tbuf_sz; + ret = hw_stream_compress(opts->alg_type, + opts->block_size, + opts->data_fmt, + tlist->addr, + &tmp_sz, + tdata->src, + tdata->src_sz); + if (ret) { + printf("Fail to deflate by HW: %d\n", ret); + goto out_strm; + } + tlist->size = tmp_sz; // write back + ret = sw_inflate2(tlist, tdata->out_list, opts); + if (ret) { + printf("Fail to inflate by zlib: %d\n", ret); + goto out_strm; + } + ret = calculate_md5(&tdata->md5, tdata->in_list->addr, + tdata->in_list->size); + if (ret) { + printf("Fail to generate MD5 (%d)\n", ret); + goto out_strm; + } + ret = calculate_md5(&final_md5, tdata->out_list->addr, + tdata->out_list->size); + if (ret) { + printf("Fail to generate MD5 (%d)\n", ret); + goto out_strm; + } + ret = cmp_md5(&tdata->md5, &final_md5); + if (ret) { + printf("MD5 is unmatched (%d) at %dth times on " + "thread %d\n", ret, i, tdata->tid); + goto out_strm; + } + } + free_chunk_list(tlist); + mmap_free(tbuf, tbuf_sz); + return NULL; + } + + /* BLOCK mode */ + setup.alg_type = opts->alg_type; + setup.op_type = WD_DIR_COMPRESS; + param.type = setup.op_type; + param.numa_id = 0; + setup.sched_param = ¶m; + h_dfl = wd_comp_alloc_sess(&setup); + if (!h_dfl) { + ret = -EINVAL; + goto out_strm; + } + + init_chunk_list(tdata->in_list, tdata->src, tdata->src_sz, + info->in_chunk_sz); + for (i = 0; i < opts->compact_run_num; i++) { + init_chunk_list(tlist, tbuf, tbuf_sz, + opts->block_size * EXPANSION_RATIO); + init_chunk_list(tdata->out_list, tdata->dst, tdata->dst_sz, + info->out_chunk_sz); + ret = hw_deflate4(h_dfl, tdata->in_list, tlist, opts, + &tdata->sem); + if (ret) { + printf("Fail to deflate by HW: %d\n", ret); + goto out_run; + } + ret = sw_inflate2(tlist, tdata->out_list, opts); + if (ret) { + printf("Fail to inflate by zlib: %d\n", ret); + goto out_run; + } + ret = calculate_md5(&tdata->md5, tdata->src, tdata->src_sz); + if (ret) { + printf("Fail to generate MD5 (%d)\n", ret); + goto out_run; + } + ret = calculate_md5(&final_md5, tdata->dst, tdata->dst_sz); + if (ret) { + printf("Fail to generate MD5 (%d)\n", ret); + goto out_run; + } + ret = cmp_md5(&tdata->md5, &final_md5); + if (ret) { + printf("MD5 is unmatched (%d) at %dth times on " + "thread %d\n", ret, i, tdata->tid); + goto out_run; + } + } + wd_comp_free_sess(h_dfl); + free_chunk_list(tlist); + mmap_free(tbuf, tbuf_sz); + /* mark sending thread to end */ + __atomic_add_fetch(&sum_thread_end, 1, __ATOMIC_ACQ_REL); + return NULL; +out_run: + wd_comp_free_sess(h_dfl); +out_strm: + free_chunk_list(tlist); +out: + mmap_free(tbuf, tbuf_sz); + return (void *)(uintptr_t)(ret); +} + +static void *hw_dfl_hw_ifl(void *arg) +{ + thread_data_t *tdata = (thread_data_t *)arg; + struct hizip_test_info *info = tdata->info; + struct test_options *opts = info->opts; + struct wd_comp_sess_setup setup = {0}; + struct sched_params param = {0}; + handle_t h_dfl, h_ifl; + void *tbuf; + size_t tbuf_sz; + chunk_list_t *tlist; + comp_md5_t final_md5 = {{0}}; + int i, ret; + __u32 tmp_sz, tout_sz; + + tbuf_sz = tdata->src_sz * EXPANSION_RATIO; + tbuf = mmap_alloc(tbuf_sz); + if (!tbuf) + return (void *)(uintptr_t)(-ENOMEM); + if (opts->option & PERFORMANCE) { + /* hack: + * memset buffer and trigger page fault early in the cpu + * instead of later in the SMMU + * Enhance performance in sva case + * no impact to non-sva case + */ + memset(tbuf, 5, tbuf_sz); + } + if (opts->is_stream) { + for (i = 0; i < opts->compact_run_num; i++) { + tmp_sz = tbuf_sz; + ret = hw_stream_compress(opts->alg_type, + opts->block_size, + opts->data_fmt, + tbuf, + &tmp_sz, + tdata->src, + tdata->src_sz); + if (ret) { + printf("Fail to deflate by HW: %d\n", ret); + goto out; + } + tout_sz = tdata->dst_sz; + ret = hw_stream_decompress(opts->alg_type, + opts->block_size, + opts->data_fmt, + tdata->dst, + &tout_sz, + tbuf, + tmp_sz); + if (ret) { + printf("Fail to inflate by HW: %d\n", ret); + goto out; + } + ret = calculate_md5(&tdata->md5, tdata->in_list->addr, + tdata->in_list->size); + if (ret) { + printf("Fail to generate MD5 (%d)\n", ret); + goto out; + } + ret = calculate_md5(&final_md5, tdata->dst, tout_sz); + if (ret) { + printf("Fail to generate MD5 (%d)\n", ret); + goto out; + } + ret = cmp_md5(&tdata->md5, &final_md5); + if (ret) { + printf("MD5 is unmatched (%d) at %dth times on " + "thread %d\n", ret, i, tdata->tid); + goto out; + } + } + mmap_free(tbuf, tbuf_sz); + return NULL; + } + + /* BLOCK mode */ + tlist = create_chunk_list(tbuf, tbuf_sz, + opts->block_size * EXPANSION_RATIO); + if (!tlist) { + ret = -ENOMEM; + goto out; + } + + setup.alg_type = opts->alg_type; + setup.op_type = WD_DIR_COMPRESS; + param.type = setup.op_type; + param.numa_id = 0; + setup.sched_param = ¶m; + h_dfl = wd_comp_alloc_sess(&setup); + if (!h_dfl) { + ret = -EINVAL; + goto out_dfl; + } + + setup.op_type = WD_DIR_DECOMPRESS; + param.type = setup.op_type; + setup.sched_param = ¶m; + h_ifl = wd_comp_alloc_sess(&setup); + if (!h_ifl) { + ret = -EINVAL; + goto out_ifl; + } + + for (i = 0; i < opts->compact_run_num; i++) { + init_chunk_list(tlist, tbuf, tbuf_sz, + opts->block_size * EXPANSION_RATIO); + init_chunk_list(tdata->out_list, tdata->dst, + tdata->dst_sz, + info->out_chunk_sz); + ret = hw_deflate4(h_dfl, tdata->in_list, tlist, opts, + &tdata->sem); + if (ret) { + printf("Fail to deflate by HW: %d\n", ret); + goto out_run; + } + ret = hw_inflate4(h_ifl, tlist, tdata->out_list, opts, + &tdata->sem); + if (ret) { + printf("Fail to inflate by HW: %d\n", ret); + goto out_run; + } + ret = calculate_md5(&tdata->md5, tdata->src, tdata->src_sz); + if (ret) { + printf("Fail to generate MD5 (%d)\n", ret); + goto out_run; + } + ret = calculate_md5(&final_md5, tdata->dst, tdata->dst_sz); + if (ret) { + printf("Fail to generate MD5 (%d)\n", ret); + goto out_run; + } + ret = cmp_md5(&tdata->md5, &final_md5); + if (ret) { + printf("MD5 is unmatched (%d) at %dth times on " + "thread %d\n", ret, i, tdata->tid); + goto out_run; + } + } + wd_comp_free_sess(h_ifl); + wd_comp_free_sess(h_dfl); + free_chunk_list(tlist); + mmap_free(tbuf, tbuf_sz); + /* mark sending thread to end */ + __atomic_add_fetch(&sum_thread_end, 1, __ATOMIC_ACQ_REL); + return NULL; +out_run: + wd_comp_free_sess(h_ifl); +out_ifl: + wd_comp_free_sess(h_dfl); +out_dfl: + free_chunk_list(tlist); +out: + mmap_free(tbuf, tbuf_sz); + return (void *)(uintptr_t)(ret); +} + +static void *hw_dfl_perf(void *arg) +{ + thread_data_t *tdata = (thread_data_t *)arg; + struct hizip_test_info *info = tdata->info; + struct test_options *opts = info->opts; + struct wd_comp_sess_setup setup = {0}; + struct sched_params param = {0}; + handle_t h_dfl; + int i, ret; + uint32_t tout_sz; + + if (opts->is_stream) { + for (i = 0; i < opts->compact_run_num; i++) { + tout_sz = tdata->dst_sz; + ret = hw_stream_compress(opts->alg_type, + opts->block_size, + opts->data_fmt, + tdata->dst, + &tout_sz, + tdata->src, + tdata->src_sz); + if (ret) { + printf("Fail to deflate by HW: %d\n", ret); + return (void *)(uintptr_t)ret; + } + } + tdata->out_list->addr = tdata->dst; + tdata->out_list->size = tout_sz; + tdata->out_list->next = NULL; + return NULL; + } + + setup.alg_type = opts->alg_type; + setup.op_type = WD_DIR_COMPRESS; + param.type = setup.op_type; + param.numa_id = 0; + setup.sched_param = ¶m; + h_dfl = wd_comp_alloc_sess(&setup); + if (!h_dfl) + return (void *)(uintptr_t)(-EINVAL); + + for (i = 0; i < opts->compact_run_num; i++) { + init_chunk_list(tdata->out_list, tdata->dst, + tdata->dst_sz, + info->out_chunk_sz); + ret = hw_deflate4(h_dfl, tdata->in_list, tdata->out_list, opts, + &tdata->sem); + if (ret) { + printf("Fail to deflate by HW: %d\n", ret); + goto out; + } + } + wd_comp_free_sess(h_dfl); + /* mark sending thread to end */ + __atomic_add_fetch(&sum_thread_end, 1, __ATOMIC_ACQ_REL); + return NULL; +out: + wd_comp_free_sess(h_dfl); + return (void *)(uintptr_t)(ret); +} + +static void *hw_ifl_perf(void *arg) +{ + thread_data_t *tdata = (thread_data_t *)arg; + struct hizip_test_info *info = tdata->info; + struct test_options *opts = info->opts; + struct wd_comp_sess_setup setup = {0}; + struct sched_params param = {0}; + handle_t h_ifl; + int i, ret; + uint32_t tout_sz; + + if (opts->is_stream) { + for (i = 0; i < opts->compact_run_num; i++) { + tout_sz = tdata->dst_sz; + ret = hw_stream_decompress(opts->alg_type, + opts->block_size, + opts->data_fmt, + tdata->dst, + &tout_sz, + tdata->in_list->addr, + tdata->in_list->size); + if (ret) { + printf("Fail to inflate by HW: %d\n", ret); + return (void *)(uintptr_t)ret; + } + tdata->out_list->addr = tdata->dst; + tdata->out_list->size = tout_sz; + tdata->out_list->next = NULL; + } + return NULL; + } + + setup.alg_type = opts->alg_type; + setup.op_type = WD_DIR_DECOMPRESS; + param.type = setup.op_type; + param.numa_id = 0; + setup.sched_param = ¶m; + h_ifl = wd_comp_alloc_sess(&setup); + if (!h_ifl) + return (void *)(uintptr_t)(-EINVAL); + + for (i = 0; i < opts->compact_run_num; i++) { + init_chunk_list(tdata->out_list, tdata->dst, + tdata->dst_sz, + info->out_chunk_sz); + ret = hw_inflate4(h_ifl, tdata->in_list, tdata->out_list, opts, + &tdata->sem); + if (ret) { + printf("Fail to inflate by HW: %d\n", ret); + goto out; + } + } + wd_comp_free_sess(h_ifl); + /* mark sending thread to end */ + __atomic_add_fetch(&sum_thread_end, 1, __ATOMIC_ACQ_REL); + return NULL; +out: + wd_comp_free_sess(h_ifl); + return (void *)(uintptr_t)(ret); +} + +/* BATCH mode is used */ +void *hw_dfl_perf3(void *arg) +{ + thread_data_t *tdata = (thread_data_t *)arg; + struct hizip_test_info *info = tdata->info; + struct test_options *opts = info->opts; + struct wd_comp_sess_setup setup = {0}; + struct sched_params param = {0}; + handle_t h_dfl; + int i, ret; + uint32_t tout_sz; + + if (opts->is_stream) { + for (i = 0; i < opts->compact_run_num; i++) { + tout_sz = tdata->dst_sz; + ret = hw_stream_compress(opts->alg_type, + opts->block_size, + opts->data_fmt, + tdata->dst, + &tout_sz, + tdata->src, + tdata->src_sz); + if (ret) { + printf("Fail to deflate by HW: %d\n", ret); + return (void *)(uintptr_t)ret; + } + } + tdata->out_list->addr = tdata->dst; + tdata->out_list->size = tout_sz; + tdata->out_list->next = NULL; + return NULL; + } + + setup.alg_type = opts->alg_type; + setup.op_type = WD_DIR_COMPRESS; + param.type = setup.op_type; + param.numa_id = 0; + setup.sched_param = ¶m; + h_dfl = wd_comp_alloc_sess(&setup); + if (!h_dfl) + return (void *)(uintptr_t)(-EINVAL); + + for (i = 0; i < opts->compact_run_num; i++) { + init_chunk_list(tdata->out_list, tdata->dst, + tdata->dst_sz, + info->out_chunk_sz); + ret = hw_deflate5(h_dfl, tdata->in_list, tdata->out_list, + tdata); + if (ret) { + printf("Fail to deflate by HW: %d\n", ret); + goto out; + } + } + wd_comp_free_sess(h_dfl); + /* mark sending thread to end */ + __atomic_add_fetch(&sum_thread_end, 1, __ATOMIC_ACQ_REL); + return NULL; +out: + wd_comp_free_sess(h_dfl); + return (void *)(uintptr_t)(ret); +} + +/* BATCH mode is used */ +void *hw_ifl_perf3(void *arg) +{ + thread_data_t *tdata = (thread_data_t *)arg; + struct hizip_test_info *info = tdata->info; + struct test_options *opts = info->opts; + struct wd_comp_sess_setup setup = {0}; + struct sched_params param = {0}; + handle_t h_ifl; + int i, ret; + uint32_t tout_sz; + + if (opts->is_stream) { + for (i = 0; i < opts->compact_run_num; i++) { + tout_sz = tdata->dst_sz; + ret = hw_stream_decompress(opts->alg_type, + opts->block_size, + opts->data_fmt, + tdata->dst, + &tout_sz, + tdata->src, + tdata->src_sz); + if (ret) { + printf("Fail to inflate by HW: %d\n", ret); + return (void *)(uintptr_t)ret; + } + tdata->out_list->addr = tdata->dst; + tdata->out_list->size = tout_sz; + tdata->out_list->next = NULL; + } + return NULL; + } + + setup.alg_type = opts->alg_type; + setup.op_type = WD_DIR_DECOMPRESS; + param.type = setup.op_type; + param.numa_id = 0; + setup.sched_param = ¶m; + h_ifl = wd_comp_alloc_sess(&setup); + if (!h_ifl) + return (void *)(uintptr_t)(-EINVAL); + + for (i = 0; i < opts->compact_run_num; i++) { + init_chunk_list(tdata->out_list, tdata->dst, + tdata->dst_sz, + info->out_chunk_sz); + ret = hw_inflate5(h_ifl, tdata->in_list, tdata->out_list, + tdata); + if (ret) { + printf("Fail to inflate by HW: %d\n", ret); + goto out; + } + } + wd_comp_free_sess(h_ifl); + /* mark sending thread to end */ + __atomic_add_fetch(&sum_thread_end, 1, __ATOMIC_ACQ_REL); + return NULL; +out: + wd_comp_free_sess(h_ifl); + return (void *)(uintptr_t)(ret); +} + +/* + * Load both ilist file. + */ +int load_ilist(struct hizip_test_info *info, char *model) +{ + struct test_options *opts = info->opts; + thread_data_t *tdata = &info->tdatas[0]; + chunk_list_t *p; + size_t sum = 0; + ssize_t file_sz = 0; + void *addr; + + if (!strcmp(model, "hw_ifl_perf")) { + if (!opts->is_stream) { + if (opts->fd_ilist < 0) { + printf("Missing IN list file!\n"); + return -EINVAL; + } + p = tdata->in_list; + addr = info->in_buf; + while (p) { + file_sz = read(opts->fd_ilist, p, + sizeof(chunk_list_t)); + if (file_sz < 0) + return -EFAULT; + p->addr = addr; + sum += file_sz; + if (p->next) + p->next = p + 1; + addr += p->size; + p = p->next; + } + } + } + return (int)sum; +} + +/* + * Load compression/decompression content. + */ +int load_file_data(struct hizip_test_info *info) +{ + struct test_options *opts = info->opts; + size_t file_sz; + + file_sz = read(opts->fd_in, info->in_buf, info->in_size); + if (file_sz < info->in_size) { + printf("Expect to read %ld bytes. " + "But only read %ld bytes!\n", + info->in_size, file_sz); + return -EFAULT; + } + return (int)file_sz; +} + +/* + * Store both olist file. opts->is_file must be enabled first. + */ +int store_olist(struct hizip_test_info *info, char *model) +{ + struct test_options *opts = info->opts; + thread_data_t *tdata = &info->tdatas[0]; + chunk_list_t *p; + size_t sum = 0; + ssize_t file_sz = 0; + + if (!opts->is_stream) { + if (opts->fd_olist >= 0) { + /* compress with BLOCK */ + p = tdata->out_list; + while (p) { + file_sz = write(opts->fd_olist, p, + sizeof(chunk_list_t)); + if (file_sz < sizeof(chunk_list_t)) + return -EFAULT; + file_sz = write(opts->fd_out, p->addr, + p->size); + if (file_sz < p->size) + return -EFAULT; + p = p->next; + sum += file_sz; + } + } else { + /* decompress with BLOCK */ + p = tdata->out_list; + while (p) { + file_sz = write(opts->fd_out, p->addr, + p->size); + if (file_sz < p->size) + return -EFAULT; + p = p->next; + sum += file_sz; + } + } + } else if (opts->is_stream) { + p = tdata->out_list; + file_sz = write(opts->fd_out, p->addr, p->size); + if (file_sz < p->size) + return -EFAULT; + sum = file_sz; + } + return (int)sum; +} + +static int nonenv_resource_init(struct test_options *opts, + struct hizip_test_info *info, + struct wd_sched **sched) +{ + int ret; + + info->list = get_dev_list(opts, 1); + if (!info->list) + return -EINVAL; + ret = init_ctx_config(opts, info, sched); + if (ret < 0) { + wd_free_list_accels(info->list); + return ret; + } + return 0; +} + +static void nonenv_resource_uninit(struct test_options *opts, + struct hizip_test_info *info, + struct wd_sched *sched) +{ + uninit_config(info, sched); + wd_free_list_accels(info->list); +} + +static bool event_unavailable = false; + +int test_hw(struct test_options *opts, char *model) +{ + struct hizip_test_info info = {0}; + struct wd_sched *sched = NULL; + double ilen, usec, speed; + char zbuf[120]; + int ret, zbuf_idx, ifl_flag = 0; + void *(*func)(void *); + size_t tbuf_sz = 0; + void *tbuf = NULL; + struct stat statbuf; + chunk_list_t *tlist = NULL; + int div; + __u32 num; + __u8 enable; + int nr_fds = 0; + int *perf_fds = NULL; + struct hizip_stats stats; + + if (!opts || !model) { + ret = -EINVAL; + goto out; + } + info.opts = opts; + info.stats = &stats; + + if (!event_unavailable && + perf_event_get("iommu/dev_fault", &perf_fds, &nr_fds)) { + printf("IOPF statistic unavailable\n"); + /* No need to retry and print an error on every run */ + event_unavailable = true; + } + stat_setup(&info); + + memset(zbuf, 0, 120); + if (!strcmp(model, "sw_dfl_hw_ifl")) { + func = sw_dfl_hw_ifl; + info.in_size = opts->total_len; + if (opts->is_stream) + info.out_size = opts->total_len; + else + info.out_size = opts->total_len; + info.in_chunk_sz = opts->block_size; + info.out_chunk_sz = opts->block_size; + zbuf_idx = sprintf(zbuf, "Mix SW deflate and HW %s %s inflate", + opts->sync_mode ? "ASYNC" : "SYNC", + opts->is_stream ? "STREAM" : "BLOCK"); + } else if (!strcmp(model, "hw_dfl_sw_ifl")) { + func = hw_dfl_sw_ifl; + info.in_size = opts->total_len; + info.out_size = opts->total_len; + info.in_chunk_sz = opts->block_size; + info.out_chunk_sz = opts->block_size; + zbuf_idx = sprintf(zbuf, "Mix HW %s %s deflate and SW inflate", + opts->sync_mode ? "ASYNC" : "SYNC", + opts->is_stream ? "STREAM" : "BLOCK"); + } else if (!strcmp(model, "hw_dfl_hw_ifl")) { + func = hw_dfl_hw_ifl; + info.in_size = opts->total_len; + if (opts->is_stream) + info.out_size = opts->total_len; + else + info.out_size = opts->total_len; + info.in_chunk_sz = opts->block_size; + info.out_chunk_sz = opts->block_size; + zbuf_idx = sprintf(zbuf, + "Mix HW %s %s deflate and HW %s %s inflate", + opts->sync_mode ? "ASYNC" : "SYNC", + opts->is_stream ? "STREAM" : "BLOCK", + opts->sync_mode ? "ASYNC" : "SYNC", + opts->is_stream ? "STREAM" : "BLOCK"); + } else if (!strcmp(model, "hw_dfl_perf")) { + func = hw_dfl_perf; + info.in_size = opts->total_len; + info.out_size = opts->total_len * EXPANSION_RATIO; + info.in_chunk_sz = opts->block_size; + info.out_chunk_sz = opts->block_size * EXPANSION_RATIO; + zbuf_idx = sprintf(zbuf, "HW %s %s deflate", + opts->sync_mode ? "ASYNC" : "SYNC", + opts->is_stream ? "STREAM" : "BLOCK"); + } else if (!strcmp(model, "hw_dfl_perf3")) { + func = hw_dfl_perf3; + info.in_size = opts->total_len; + info.out_size = opts->total_len * EXPANSION_RATIO; + info.in_chunk_sz = opts->block_size; + info.out_chunk_sz = opts->block_size * EXPANSION_RATIO; + zbuf_idx = sprintf(zbuf, "HW %s %s deflate", + opts->sync_mode ? "ASYNC" : "SYNC", + opts->is_stream ? "STREAM" : "BLOCK"); + } else if (!strcmp(model, "hw_ifl_perf")) { + func = hw_ifl_perf; + info.in_size = opts->total_len; + info.out_size = opts->total_len * INFLATION_RATIO; + info.in_chunk_sz = opts->block_size; + info.out_chunk_sz = opts->block_size * INFLATION_RATIO; + zbuf_idx = sprintf(zbuf, "HW %s %s inflate", + opts->sync_mode ? "ASYNC" : "SYNC", + opts->is_stream ? "STREAM" : "BLOCK"); + ifl_flag = 1; + } else if (!strcmp(model, "hw_ifl_perf3")) { + func = hw_ifl_perf3; + info.in_size = opts->total_len * EXPANSION_RATIO; + info.out_size = opts->total_len; + info.in_chunk_sz = opts->block_size; + info.out_chunk_sz = opts->block_size * INFLATION_RATIO; + zbuf_idx = sprintf(zbuf, "HW %s %s inflate", + opts->sync_mode ? "ASYNC" : "SYNC", + opts->is_stream ? "STREAM" : "BLOCK"); + ifl_flag = 1; + } else { + printf("Wrong model is specified:%s\n", model); + ret = -EINVAL; + goto out; + } + + if (opts->use_env) + ret = wd_comp_env_init(NULL); + else + ret = nonenv_resource_init(opts, &info, &sched); + if (ret < 0) + goto out; + + if (opts->faults & INJECT_SIG_BIND) + kill(getpid(), SIGTERM); + + if (opts->use_env) { + ret = wd_comp_get_env_param(0, opts->op_type, opts->sync_mode, &num, &enable); + if (ret < 0) + goto out; + } + + if (opts->is_file) { + ret = fstat(opts->fd_in, &statbuf); + if (ret < 0) + goto out_src; + opts->total_len = statbuf.st_size; + info.in_size = opts->total_len; + if (ifl_flag) + info.out_size = opts->total_len * INFLATION_RATIO; + else + info.out_size = opts->total_len * EXPANSION_RATIO; + /* + * If fd_ilist exists, it's inflation. + * Make sure block inflation has enough room. + */ + if (opts->fd_ilist >= 0) { + ret = fstat(opts->fd_ilist, &statbuf); + if (!ret) { + div = statbuf.st_size / sizeof(chunk_list_t); + info.in_chunk_sz = (info.in_size + div - 1) / + div; + info.out_chunk_sz = (info.out_size + div - 1) / + div; + } + } + } + info.in_buf = mmap_alloc(info.in_size); + if (!info.in_buf) { + ret = -ENOMEM; + goto out_src; + } + ret = create_send_tdata(opts, &info); + if (ret) + goto out_send; + ret = create_poll_tdata(opts, &info, opts->poll_num); + if (ret) + goto out_poll; + if (opts->is_file) { + /* in_list is created by create_send3_threads(). */ + ret = load_file_data(&info); + if (ret < 0) + goto out_buf; + ret = load_ilist(&info, model); + if (ret < 0) + goto out_buf; + } else { + if (ifl_flag) { + thread_data_t *tdata = info.tdatas; + tbuf_sz = info.in_size / EXPANSION_RATIO; + tbuf = mmap_alloc(tbuf_sz); + if (!tbuf) { + ret = -ENOMEM; + goto out_buf; + } + tlist = create_chunk_list(tbuf, tbuf_sz, + opts->block_size / + EXPANSION_RATIO); + init_chunk_list(tlist, tbuf, tbuf_sz, + opts->block_size / EXPANSION_RATIO); + gen_random_data(tbuf, tbuf_sz); + ret = sw_deflate2(tlist, tdata[0].in_list, opts); + if (ret) { + free_chunk_list(tlist); + mmap_free(tbuf, tbuf_sz); + goto out_buf; + } + free_chunk_list(tlist); + mmap_free(tbuf, tbuf_sz); + } else + gen_random_data(info.in_buf, info.in_size); + } + if (opts->faults & INJECT_TLB_FAULT) { + /* + * Now unmap the buffers and retry the access. Normally we + * should get an access fault, but if the TLB wasn't properly + * invalidated, the access succeeds and corrupts memory! + * This test requires small jobs, to make sure that we reuse + * the same TLB entry between the tests. Run for example with + * "-s 0x1000 -b 0x1000". + */ + ret = munmap(info.in_buf, info.in_size); + if (ret) { + printf("Failed to unmap."); + goto out_buf; + } + /* A warning if the parameters might produce false positives */ + if (opts->total_len > 0x54000) + fprintf(stderr, "NOTE: test might trash the TLB\n"); + } + stat_start(&info); + ret = attach2_threads(opts, &info, func, poll2_thread_func); + if (ret) + goto out_buf; + stat_end(&info); + info.stats->v[ST_IOPF] = perf_event_put(perf_fds, nr_fds); + if (opts->is_file) + store_olist(&info, model); + + usec = info.stats->v[ST_RUN_TIME] / 1000; + if (opts->op_type == WD_DIR_DECOMPRESS) + ilen = (float)count_chunk_list_sz(info.tdatas[0].out_list); + else + ilen = opts->total_len; + ilen *= opts->thread_num * opts->compact_run_num; + speed = ilen * 1000 * 1000 / 1024 / 1024 / usec; + if (opts->sync_mode) { + zbuf_idx += sprintf(zbuf + zbuf_idx, + " with %d send + %d poll threads", + opts->thread_num, + opts->poll_num); + } else { + zbuf_idx += sprintf(zbuf + zbuf_idx, + " with %d send threads", + opts->thread_num); + } + if (!strcmp(model, "hw_dfl_perf") || !strcmp(model, "hw_ifl_perf") || + !strcmp(model, "hw_dfl_perf3") || !strcmp(model, "hw_ifl_perf3")) { + printf("%s at %.2fMB/s in %f usec (BLK:%d, Bnum:%d).\n", + zbuf, speed, usec, opts->block_size, opts->batch_num); + } else { + printf("%s in %f usec (BLK:%d, Bnum:%d).\n", + zbuf, usec, opts->block_size, opts->batch_num); + } + free2_threads(&info); + if (opts->use_env) + wd_comp_env_uninit(); + else + nonenv_resource_uninit(opts, &info, sched); + usleep(1000); + return 0; +out_buf: +out_poll: + free2_threads(&info); + if (opts->use_env) + wd_comp_env_uninit(); + else + nonenv_resource_uninit(opts, &info, sched); + printf("Fail to run %s() (%d)!\n", model, ret); + return ret; +out_send: + mmap_free(info.in_buf, info.in_size); +out_src: + if (opts->use_env) + wd_comp_env_uninit(); + else + nonenv_resource_uninit(opts, &info, sched); +out: + printf("Fail to run %s() (%d)!\n", model, ret); + return ret; +} + +int run_self_test(struct test_options *opts) +{ + int i, f_ret = 0; + char poll_str[POLL_STRING_LEN]; + + printf("Start to run self test!\n"); + opts->alg_type = WD_ZLIB; + opts->data_fmt = WD_FLAT_BUF; + opts->sync_mode = 0; + opts->q_num = 16; + for (i = 0; i < 10; i++) { + opts->sync_mode = 0; + switch (i) { + case 0: + opts->thread_num = 1; + break; + case 1: + opts->thread_num = 2; + break; + case 2: + opts->thread_num = 4; + break; + case 3: + opts->thread_num = 8; + break; + case 4: + opts->thread_num = 16; + break; + case 5: + opts->thread_num = 1; + opts->is_stream = 1; + break; + case 6: + opts->thread_num = 2; + opts->is_stream = 1; + break; + case 7: + opts->thread_num = 4; + opts->is_stream = 1; + break; + case 8: + opts->thread_num = 8; + opts->is_stream = 1; + break; + case 9: + opts->thread_num = 16; + opts->is_stream = 1; + break; + } + f_ret |= test_hw(opts, "hw_dfl_perf"); + f_ret |= test_hw(opts, "hw_ifl_perf"); + } + opts->is_stream = 0; /* restore to BLOCK mode */ + for (i = 0; i < 5; i++) { + opts->thread_num = 8; + switch (i) { + case 0: + opts->sync_mode = 0; + break; + case 1: + opts->sync_mode = 1; opts->poll_num = 1; + break; + case 2: + opts->sync_mode = 1; opts->poll_num = 2; + break; + case 3: + opts->sync_mode = 1; opts->poll_num = 4; + break; + case 4: + opts->sync_mode = 1; opts->poll_num = 8; + break; + default: + return -EINVAL; + } + if (opts->use_env && opts->poll_num) { + memset(poll_str, 0, POLL_STRING_LEN); + sprintf(poll_str, + "sync-comp:8@0,sync-decomp:8@0," + "async-comp:8@0,async-decomp:8@0"); + setenv("WD_COMP_CTX_NUM", poll_str, 1); + memset(poll_str, 0, POLL_STRING_LEN); + sprintf(poll_str, "%d@0", opts->poll_num), + setenv("WD_COMP_ASYNC_POLL_NUM", poll_str, 1); + } + f_ret |= test_hw(opts, "sw_dfl_hw_ifl"); + f_ret |= test_hw(opts, "hw_dfl_sw_ifl"); + f_ret |= test_hw(opts, "hw_dfl_hw_ifl"); + f_ret |= test_hw(opts, "hw_dfl_perf"); + f_ret |= test_hw(opts, "hw_ifl_perf"); + } + if (!f_ret) + printf("Run self test successfully!\n"); + return f_ret; +} + +static int set_default_opts(struct test_options *opts) +{ + if (!opts->block_size) + opts->block_size = 8192; + if (!opts->total_len) { + if (opts->block_size) + opts->total_len = opts->block_size * 10; + else + opts->total_len = 8192 * 10; + } + if (!opts->thread_num) + opts->thread_num = 1; + if (!opts->q_num) + opts->q_num = opts->thread_num; + if (!opts->compact_run_num) + opts->compact_run_num = 1; + if (!opts->poll_num) + opts->poll_num = 1; + if (opts->alg_type == WD_COMP_ALG_MAX) + opts->alg_type = WD_GZIP; + return 0; +} + +static int run_one_cmd(struct test_options *opts) +{ + int ret; + + if (opts->op_type == WD_DIR_COMPRESS) { + if (opts->verify) + ret = test_hw(opts, "hw_dfl_sw_ifl"); + else + ret = test_hw(opts, "hw_dfl_perf"); + } else { + if (opts->verify) + ret = test_hw(opts, "sw_dfl_hw_ifl"); + else + ret = test_hw(opts, "hw_ifl_perf"); + } + return ret; +} + +int run_cmd(struct test_options *opts) +{ + int ret = 0, i; + int nr_children = 0, status; + pid_t pid, *pids = NULL; + bool success = true; + + set_default_opts(opts); + if (opts->children) { + pids = calloc(opts->children, sizeof(pid_t)); + if (!pids) + return -ENOMEM; + for (i = 0; i < opts->children; i++) { + pid = fork(); + if (pid < 0) { + printf("cannot fork: %d\n", errno); + success = false; + break; + } else if (pid > 0) { + /* Parent */ + pids[nr_children++] = pid; + continue; + } + /* Child */ + ret = run_one_cmd(opts); + return ret; + } + for (i = 0; i < nr_children; i++) { + pid = pids[i]; + ret = waitpid(pid, &status, 0); + if (ret < 0) { + printf("wait(pid=%d) error %d\n", pid, errno); + success = false; + continue; + } + if (WIFEXITED(status)) { + ret = WEXITSTATUS(status); + if (ret) { + printf("child %d returned with %d\n", + pid, ret); + success = false; + } + } else if (WIFSIGNALED(status)) { + ret = WTERMSIG(status); + printf("child %d killed by sig %d\n", pid, ret); + success = false; + } else { + printf("unexpected status for child %d\n", pid); + success = false; + } + } + if (success == false) { + printf("Failed to run spawn test!\n"); + if (!ret) + ret = -EINVAL; + } + } else + ret = run_one_cmd(opts); + return ret; +} + +int perf_event_open(struct perf_event_attr *attr, + pid_t pid, int cpu, int group_fd, + unsigned long flags) +{ + return syscall(__NR_perf_event_open, attr, pid, cpu, group_fd, flags); +} + +unsigned long long perf_event_put(int *perf_fds, int nr_fds); + +int perf_event_get(const char *event_name, int **perf_fds, int *nr_fds) +{ + int ret; + int cpu; + FILE *fd; + int nr_cpus; + unsigned int event_id; + char event_id_file[256]; + struct perf_event_attr event = { + .type = PERF_TYPE_TRACEPOINT, + .size = sizeof(event), + .disabled = true, + }; + + *perf_fds = NULL; + *nr_fds = 0; + + nr_cpus = sysconf(_SC_NPROCESSORS_ONLN); + if (nr_cpus <= 0) { + WD_ERR("invalid number of CPUs\n"); + return nr_cpus; + } + + ret = snprintf(event_id_file, sizeof(event_id_file), + "/sys/kernel/debug/tracing/events/%s/id", event_name); + if (ret >= sizeof(event_id_file)) { + WD_ERR("event_id buffer overflow\n"); + return -EOVERFLOW; + } + fd = fopen(event_id_file, "r"); + if (fd == NULL) { + ret = -errno; + WD_ERR("Couldn't open file %s\n", event_id_file); + return ret; + } + + if (fscanf(fd, "%d", &event_id) != 1) { + WD_ERR("Couldn't parse file %s\n", event_id_file); + return -EINVAL; + } + fclose(fd); + event.config = event_id; + + *perf_fds = calloc(nr_cpus, sizeof(int)); + if (!*perf_fds) + return -ENOMEM; + *nr_fds = nr_cpus; + + /* + * An event is bound to either a CPU or a PID. If we want both, we need + * to open the event on all CPUs. Note that we can't use a perf group + * since they have to be on the same CPU. + */ + for (cpu = 0; cpu < nr_cpus; cpu++) { + int fd = perf_event_open(&event, -1, cpu, -1, 0); + + if (fd < 0) { + WD_ERR("Couldn't get perf event %s on CPU%d: %d\n", + event_name, cpu, errno); + perf_event_put(*perf_fds, cpu); + return fd; + } + + ioctl(fd, PERF_EVENT_IOC_RESET, 0); + ioctl(fd, PERF_EVENT_IOC_ENABLE, 0); + (*perf_fds)[cpu] = fd; + } + + return 0; +} + +/* + * Closes the perf fd and return the sample count. If it wasn't open, return 0. + */ +unsigned long long perf_event_put(int *perf_fds, int nr_fds) +{ + int ret; + int cpu; + uint64_t count, total = 0; + + if (!perf_fds) + return 0; + + for (cpu = 0; cpu < nr_fds; cpu++) { + int fd = perf_fds[cpu]; + + if (fd <= 0) { + WD_ERR("Invalid perf fd %d\n", cpu); + continue; + } + + ioctl(fd, PERF_EVENT_IOC_DISABLE, 0); + + ret = read(fd, &count, sizeof(count)); + if (ret < sizeof(count)) + WD_ERR("Couldn't read perf event for CPU%d\n", cpu); + + total += count; + close(fd); + + } + + free(perf_fds); + return total; +} + +static void set_thp(struct test_options *opts) +{ + char *p; + char s[14]; + FILE *file; + + file = fopen("/sys/kernel/mm/transparent_hugepage/enabled", "r"); + if (!file) + goto out_err; + p = fgets(s, 14, file); + fclose(file); + if (!p) + goto out_err; + + if (strcmp(s, "never") == 0) { + printf("Cannot test THP with enable=never\n"); + return; + } + + file = fopen("/sys/kernel/mm/transparent_hugepage/defrag", "r"); + if (!file) + goto out_err; + p = fgets(s, 14, file); + fclose(file); + if (!p) + goto out_err; + + if (strcmp(s, "defer") == 0 || strcmp(s, "never") == 0) { + printf("Cannot test THP with defrag=%s\n", s); + return; + } + + return; +out_err: + printf("THP unsupported?\n"); +} + +void stat_setup(struct hizip_test_info *info) +{ + clock_gettime(CLOCK_MONOTONIC_RAW, &info->tv.setup_time); + clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &info->tv.setup_cputime); + getrusage(RUSAGE_SELF, &info->tv.setup_rusage); +} + +void stat_start(struct hizip_test_info *info) +{ + clock_gettime(CLOCK_MONOTONIC_RAW, &info->tv.start_time); + clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &info->tv.start_cputime); + getrusage(RUSAGE_SELF, &info->tv.start_rusage); +} + +void stat_end(struct hizip_test_info *info) +{ + struct test_options *opts = info->opts; + struct hizip_stats *stats = info->stats; + double v; + size_t total_out; + unsigned long total_len; + + total_out = __atomic_load_n(&info->total_out, __ATOMIC_ACQUIRE); + clock_gettime(CLOCK_MONOTONIC_RAW, &info->tv.end_time); + clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &info->tv.end_cputime); + getrusage(RUSAGE_SELF, &info->tv.end_rusage); + + stats->v[ST_SETUP_TIME] = (info->tv.start_time.tv_sec - + info->tv.setup_time.tv_sec) * 1000000000 + + info->tv.start_time.tv_nsec - + info->tv.setup_time.tv_nsec; + stats->v[ST_RUN_TIME] = (info->tv.end_time.tv_sec - + info->tv.start_time.tv_sec) * 1000000000 + + info->tv.end_time.tv_nsec - + info->tv.start_time.tv_nsec; + + stats->v[ST_CPU_TIME] = (info->tv.end_cputime.tv_sec - + info->tv.setup_cputime.tv_sec) * 1000000000 + + info->tv.end_cputime.tv_nsec - + info->tv.setup_cputime.tv_nsec; + stats->v[ST_USER_TIME] = (info->tv.end_rusage.ru_utime.tv_sec - + info->tv.setup_rusage.ru_utime.tv_sec) * + 1000000 + + info->tv.end_rusage.ru_utime.tv_usec - + info->tv.setup_rusage.ru_utime.tv_usec; + stats->v[ST_SYSTEM_TIME] = (info->tv.end_rusage.ru_stime.tv_sec - + info->tv.setup_rusage.ru_stime.tv_sec) * + 1000000 + + info->tv.end_rusage.ru_stime.tv_usec - + info->tv.setup_rusage.ru_stime.tv_usec; + + stats->v[ST_MINFLT] = info->tv.end_rusage.ru_minflt - + info->tv.setup_rusage.ru_minflt; + stats->v[ST_MAJFLT] = info->tv.end_rusage.ru_majflt - + info->tv.setup_rusage.ru_majflt; + + stats->v[ST_VCTX] = info->tv.end_rusage.ru_nvcsw - + info->tv.setup_rusage.ru_nvcsw; + stats->v[ST_INVCTX] = info->tv.end_rusage.ru_nivcsw - + info->tv.setup_rusage.ru_nivcsw; + + stats->v[ST_SIGNALS] = info->tv.end_rusage.ru_nsignals - + info->tv.setup_rusage.ru_nsignals; + + /* check last loop is enough, same as below hizip_verify_output */ + stats->v[ST_COMPRESSION_RATIO] = (double)opts->total_len / + total_out * 100; + + total_len = opts->total_len * opts->compact_run_num; + /* ST_RUN_TIME records nanoseconds */ + stats->v[ST_SPEED] = (total_len * opts->thread_num * 1000) / + (1.024 * 1.024 * stats->v[ST_RUN_TIME]); + + stats->v[ST_TOTAL_SPEED] = (total_len * opts->thread_num * 1000) / + ((stats->v[ST_RUN_TIME] + + stats->v[ST_SETUP_TIME]) * 1.024 * 1.024); + + v = stats->v[ST_RUN_TIME] + stats->v[ST_SETUP_TIME]; + stats->v[ST_CPU_IDLE] = (v - stats->v[ST_CPU_TIME]) / v * 100; + stats->v[ST_FAULTS] = stats->v[ST_MAJFLT] + stats->v[ST_MINFLT]; +} + +static void handle_sigbus(int sig) +{ + printf("SIGBUS!\n"); + _exit(0); +} + +int test_comp_entry(int argc, char *argv[]) +{ + struct test_options opts = { + .alg_type = WD_GZIP, + .op_type = WD_DIR_COMPRESS, + .q_num = 1, + .run_num = 1, + .compact_run_num = 1, + .thread_num = 1, + .sync_mode = 0, + .block_size = 512000, + .total_len = opts.block_size * 10, + .verify = false, + .verbose = false, + .is_decomp = false, + .is_stream = false, + .is_file = false, + .display_stats = STATS_PRETTY, + .children = 0, + .faults = 0, + .data_fmt = 0, + }; + struct option long_options[] = { + {"self", no_argument, 0, 0 }, + {"in", required_argument, 0, 0 }, + {"out", required_argument, 0, 0 }, + {"ilist", required_argument, 0, 0 }, + {"olist", required_argument, 0, 0 }, + {"env", no_argument, 0, 0 }, + {0, 0, 0, 0 }, + }; + int show_help = 0; + int opt, option_idx; + int self = 0; + + opts.fd_in = -1; + opts.fd_out = -1; + opts.fd_ilist = -1; + opts.fd_olist = -1; + opts.alg_type = WD_COMP_ALG_MAX; + while ((opt = getopt_long(argc, argv, COMMON_OPTSTRING "f:o:w:k:r:", + long_options, &option_idx)) != -1) { + switch (opt) { + case 0: + switch (option_idx) { + case 0: /* self */ + self = 1; + break; + case 1: /* in */ + if (optarg) { + opts.fd_in = open(optarg, O_RDONLY); + if (opts.fd_in < 0) { + printf("Fail to open %s\n", + optarg); + show_help = 1; + } else + opts.is_file = true; + } else { + printf("Input file is missing!\n"); + show_help = 1; + } + if (lseek(opts.fd_in, 0, SEEK_SET) < 0) { + printf("Fail on lseek()!\n"); + show_help = 1; + } + break; + case 2: /* out */ + if (optarg) { + opts.fd_out = open(optarg, + O_CREAT | O_WRONLY, + S_IWUSR | S_IRGRP | + S_IROTH); + if (opts.fd_out < 0) { + printf("Fail to open %s\n", + optarg); + show_help = 1; + } else + opts.is_file = true; + } else { + printf("Output file is missing!\n"); + show_help = 1; + } + if (lseek(opts.fd_out, 0, SEEK_SET) < 0) { + printf("Fail on lseek()!\n"); + show_help = 1; + } + break; + case 3: /* ilist */ + if (!optarg) { + printf("IN list file is missing!\n"); + show_help = 1; + break; + } + opts.fd_ilist = open(optarg, O_RDONLY); + if (opts.fd_ilist < 0) { + printf("Fail to open %s\n", optarg); + show_help = 1; + break; + } + opts.is_file = true; + if (lseek(opts.fd_ilist, 0, SEEK_SET) < 0) { + printf("Fail on lseek()!\n"); + show_help = 1; + break; + } + break; + case 4: /* olist */ + if (!optarg) { + printf("OUT list file is missing!\n"); + show_help = 1; + break; + } + opts.fd_olist = open(optarg, + O_CREAT | O_WRONLY, + S_IWUSR | S_IRGRP | + S_IROTH); + if (opts.fd_olist < 0) { + printf("Fail to open %s\n", optarg); + show_help = 1; + break; + } + opts.is_file = true; + if (lseek(opts.fd_olist, 0, SEEK_SET) < 0) { + printf("Fail on lseek()!\n"); + show_help = 1; + break; + } + break; + case 5: /* env */ + opts.use_env = true; + break; + default: + show_help = 1; + break; + } + break; + case 'f': + if (strcmp(optarg, "none") == 0) { + opts.display_stats = STATS_NONE; + } else if (strcmp(optarg, "csv") == 0) { + opts.display_stats = STATS_CSV; + } else if (strcmp(optarg, "pretty") == 0) { + opts.display_stats = STATS_PRETTY; + } else { + SYS_ERR_COND(1, "invalid argument to -f: '%s'\n", optarg); + break; + } + break; + case 'o': + switch (optarg[0]) { + case 'p': + opts.option |= PERFORMANCE; + break; + case 't': + opts.option |= TEST_THP; + set_thp(&opts); + break; + default: + SYS_ERR_COND(1, "invalid argument to -o: '%s'\n", optarg); + break; + } + break; + case 'c': + opts.option |= TEST_ZLIB; + break; + case 'r': + opts.children = strtol(optarg, NULL, 0); + if (opts.children < 0) + show_help = 1; + break; + case 'k': + switch (optarg[0]) { + case 'b': + opts.faults |= INJECT_SIG_BIND; + break; + case 't': + opts.faults |= INJECT_TLB_FAULT; + break; + case 'w': + opts.faults |= INJECT_SIG_WORK; + break; + default: + SYS_ERR_COND(1, "invalid argument to -k: '%s'\n", optarg); + break; + } + break; + default: + show_help = parse_common_option(opt, optarg, &opts); + break; + } + } + + signal(SIGBUS, handle_sigbus); + + if (!show_help) { + if (self) + return run_self_test(&opts); + return run_cmd(&opts); + } + + hizip_test_adjust_len(&opts); + + SYS_ERR_COND(show_help || optind > argc, + COMMON_HELP + " -f <format> output format for the statistics\n" + " 'none' do not output statistics\n" + " 'pretty' human readable format\n" + " 'csv' raw, machine readable\n" + " -o <mode> options\n" + " 'perf' prefaults the output pages\n" + " 'thp' try to enable transparent huge pages\n" + " 'zlib' use zlib instead of the device\n" + " -r <children> number of children to create\n" + " -k <mode> kill thread\n" + " 'bind' kills the process after bind\n" + " 'tlb' tries to access an unmapped buffer\n" + " 'work' kills the process while the queue is working\n", + argv[0] + ); + return 0; +} diff --git a/uadk_tool/test/comp_main.h b/uadk_tool/test/comp_main.h new file mode 100644 index 0000000..dcf3980 --- /dev/null +++ b/uadk_tool/test/comp_main.h @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: Apache-2.0 */ + +#ifndef TEST_COMP_H +#define TEST_COMP_H + + +int test_comp_entry(int argc, char *argv[]); + +#endif /* TEST_COMP_H */ diff --git a/uadk_tool/test/uadk_test.c b/uadk_tool/test/uadk_test.c index 760cef9..cdb547b 100644 --- a/uadk_tool/test/uadk_test.c +++ b/uadk_tool/test/uadk_test.c @@ -11,6 +11,7 @@ #include <sys/ipc.h> #include <sys/shm.h>
+#include "comp_main.h" #include "test_sec.h"
enum uadk_test_op_type { @@ -23,11 +24,6 @@ int test_hpre_entry(int argc, char *argv[]) return 0; }
-int test_zip_entry(int argc, char *argv[]) -{ - return 0; -} - void print_test_help(void) { printf("NAME\n"); @@ -67,7 +63,7 @@ void acc_test_run(int argc, char *argv[]) } else if (!strcmp(input_module, "sec")) { (void)test_sec_entry(argc, argv); } else if (!strcmp(input_module, "zip")) { - (void)test_zip_entry(argc, argv); + (void)test_comp_entry(argc, argv); } else { print_test_help(); printf("failed to parse module parameter!\n");
From: Hao Fang fanghao11@huawei.com
Add DEBUG_LOG macro to control dbg print.
Use the COMP_TST_PRT() to unified the err log print.
Signed-off-by: Hao Fang fanghao11@huawei.com Signed-off-by: Qi Tao taoqi10@huawei.com --- uadk_tool/test/comp_lib.c | 118 +++++++++++++++--------------- uadk_tool/test/comp_lib.h | 8 +++ uadk_tool/test/comp_main.c | 144 ++++++++++++++++++------------------- 3 files changed, 138 insertions(+), 132 deletions(-)
diff --git a/uadk_tool/test/comp_lib.c b/uadk_tool/test/comp_lib.c index 4009295..c2e4410 100644 --- a/uadk_tool/test/comp_lib.c +++ b/uadk_tool/test/comp_lib.c @@ -21,8 +21,6 @@ struct check_rand_ctx { unsigned short state[3]; };
-#define dbg(msg, ...) fprintf(stderr, msg, ##__VA_ARGS__) - static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_spinlock_t lock; static int count = 0; @@ -56,7 +54,7 @@ void *mmap_alloc(size_t len) p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (p == MAP_FAILED) - WD_ERR("Failed to allocate %zu bytes\n", len); + COMP_TST_PRT("Failed to allocate %zu bytes\n", len);
return p == MAP_FAILED ? NULL : p; } @@ -94,7 +92,7 @@ static int hizip_check_rand(unsigned char *buf, unsigned int size, void *opaque) char actual = buf[i + *j];
if (expected != actual) { - WD_ERR("Invalid decompressed char at offset %lu: expected 0x%x != 0x%x\n", + COMP_TST_PRT("Invalid decompressed char at offset %lu: expected 0x%x != 0x%x\n", rand_ctx->global_off + i + *j, expected, actual); return -EINVAL; @@ -115,7 +113,7 @@ static struct wd_datalist *get_datalist(void *addr, __u32 size)
head = calloc(1, sizeof(struct wd_datalist)); if (!head) { - WD_ERR("failed to alloc datalist head\n"); + COMP_TST_PRT("failed to alloc datalist head\n"); return NULL; }
@@ -162,12 +160,12 @@ int hw_blk_compress(int alg_type, int blksize, __u8 data_fmt, void *priv, setup.sched_param = ¶m; h_sess = wd_comp_alloc_sess(&setup); if (!h_sess) { - fprintf(stderr,"fail to alloc comp sess!\n"); + COMP_TST_PRT("fail to alloc comp sess!\n"); return -EINVAL; }
if (data_fmt) { - WD_ERR("now sge size is %u\n", SGE_SIZE); + COMP_TST_PRT("now sge size is %u\n", SGE_SIZE); list = get_datalist(src, (__u32)srclen); req.list_src = list; list = get_datalist(dst, (__u32)*dstlen); @@ -189,12 +187,12 @@ int hw_blk_compress(int alg_type, int blksize, __u8 data_fmt, void *priv,
ret = wd_do_comp_sync(h_sess, &req); if (ret < 0) { - fprintf(stderr,"fail to do comp sync(ret = %d)!\n", ret); + COMP_TST_PRT("fail to do comp sync(ret = %d)!\n", ret); return ret; }
if (req.status) { - fprintf(stderr,"fail to do comp sync(status = %d)!\n", + COMP_TST_PRT("fail to do comp sync(status = %d)!\n", req.status); wd_comp_free_sess(h_sess); return req.status; @@ -227,12 +225,12 @@ int hw_blk_decompress(int alg_type, int blksize, __u8 data_fmt, setup.sched_param = ¶m; h_sess = wd_comp_alloc_sess(&setup); if (!h_sess) { - fprintf(stderr,"fail to alloc comp sess!\n"); + COMP_TST_PRT("fail to alloc comp sess!\n"); return -EINVAL; }
if (data_fmt) { - WD_ERR("now sge size is %u\n", SGE_SIZE); + COMP_TST_PRT("now sge size is %u\n", SGE_SIZE); list = get_datalist(src, (__u32)srclen); req.list_src = list; list = get_datalist(dst, (__u32)*dstlen); @@ -254,12 +252,12 @@ int hw_blk_decompress(int alg_type, int blksize, __u8 data_fmt,
ret = wd_do_comp_sync(h_sess, &req); if (ret < 0) { - fprintf(stderr,"fail to do comp sync(ret = %d)!\n", ret); + COMP_TST_PRT("fail to do comp sync(ret = %d)!\n", ret); return ret; }
if (req.status) { - fprintf(stderr,"fail to do comp sync(status = %d)!\n", + COMP_TST_PRT("fail to do comp sync(status = %d)!\n", req.status); wd_comp_free_sess(h_sess); return req.status; @@ -293,7 +291,7 @@ int hw_stream_compress(int alg_type, int blksize, __u8 data_fmt, setup.sched_param = ¶m; h_sess = wd_comp_alloc_sess(&setup); if (!h_sess) { - fprintf(stderr,"fail to alloc comp sess!\n"); + COMP_TST_PRT("fail to alloc comp sess!\n"); return -EINVAL; } req.src = src; @@ -309,12 +307,12 @@ int hw_stream_compress(int alg_type, int blksize, __u8 data_fmt,
ret = wd_do_comp_sync2(h_sess, &req); if (ret < 0) { - fprintf(stderr,"fail to do comp sync(ret = %d)!\n", ret); + COMP_TST_PRT("fail to do comp sync(ret = %d)!\n", ret); return ret; }
if (req.status) { - fprintf(stderr,"fail to do comp sync(status = %d)!\n", + COMP_TST_PRT("fail to do comp sync(status = %d)!\n", req.status); wd_comp_free_sess(h_sess); return req.status; @@ -347,7 +345,7 @@ int hw_stream_decompress(int alg_type, int blksize, __u8 data_fmt, setup.sched_param = ¶m; h_sess = wd_comp_alloc_sess(&setup); if (!h_sess) { - fprintf(stderr,"fail to alloc comp sess!\n"); + COMP_TST_PRT("fail to alloc comp sess!\n"); return -EINVAL; } req.src = src; @@ -364,12 +362,12 @@ int hw_stream_decompress(int alg_type, int blksize, __u8 data_fmt,
ret = wd_do_comp_sync2(h_sess, &req); if (ret < 0) { - fprintf(stderr,"fail to do comp sync(ret = %d)!\n", ret); + COMP_TST_PRT("fail to do comp sync(ret = %d)!\n", ret); return ret; }
if (req.status) { - fprintf(stderr,"fail to do comp sync(status = %d)!\n", + COMP_TST_PRT("fail to do comp sync(status = %d)!\n", req.status); wd_comp_free_sess(h_sess); return req.status; @@ -477,7 +475,7 @@ int hizip_verify_random_output(struct test_options *opts, ret = hizip_check_output(info->out_buf + off, out_sz, &checked, hizip_check_rand, &rand_ctx); if (ret) { - WD_ERR("Check output failed with %d\n", ret); + COMP_TST_PRT("Check output failed with %d\n", ret); return ret; } total_checked += checked; @@ -485,7 +483,7 @@ int hizip_verify_random_output(struct test_options *opts, } while (!ret && total_checked < opts->total_len);
if (rand_ctx.global_off != opts->total_len) { - WD_ERR("Invalid output size %lu != %lu\n", + COMP_TST_PRT("Invalid output size %lu != %lu\n", rand_ctx.global_off, opts->total_len); return -EINVAL; } @@ -557,7 +555,7 @@ void *send_thread_func(void *arg) kill(getpid(), SIGTERM); } if (ret < 0) { - WD_ERR("do comp test fail with %d\n", ret); + COMP_TST_PRT("do comp test fail with %d\n", ret); return (void *)(uintptr_t)ret; } else if (tdata->req.status) { return (void *)(uintptr_t)tdata->req.status; @@ -574,7 +572,7 @@ void *send_thread_func(void *arg) tdata->req.dst += dst_block_size; tdata->sum += tdata->req.dst_len; if (tdata->sum > info->out_size) { - fprintf(stderr, + COMP_TST_PRT( "%s: exceed OUT limits (%ld > %ld)\n", __func__, tdata->sum, info->out_size); @@ -662,7 +660,7 @@ int create_send_threads(struct test_options *opts, ret = pthread_create(&info->send_tds[i], &attr, send_thread_func, &tdatas[i]); if (ret < 0) { - fprintf(stderr, "Fail to create send thread %d (%d)\n", + COMP_TST_PRT( "Fail to create send thread %d (%d)\n", i, ret); goto out_thd; } @@ -699,7 +697,7 @@ int create_poll_threads(struct hizip_test_info *info, ret = pthread_create(&info->poll_tds[i], &attr, poll_thread_func, info); if (ret < 0) { - fprintf(stderr, "Fail to create send thread %d (%d)\n", + COMP_TST_PRT( "Fail to create send thread %d (%d)\n", i, ret); goto out; } @@ -729,14 +727,14 @@ int attach_threads(struct test_options *opts, struct hizip_test_info *info) for (i = 0; i < info->poll_tnum; i++) { ret = pthread_join(info->poll_tds[i], NULL); if (ret < 0) - fprintf(stderr, "Fail on poll thread with %d\n", + COMP_TST_PRT( "Fail on poll thread with %d\n", ret); } } for (i = 0; i < info->send_tnum; i++) { ret = pthread_join(info->send_tds[i], &tret); if (ret < 0) - fprintf(stderr, "Fail on send thread with %d\n", ret); + COMP_TST_PRT( "Fail on send thread with %d\n", ret); } return (int)(uintptr_t)tret; } @@ -768,8 +766,8 @@ void dump_md5(comp_md5_t *md5) int i;
for (i = 0; i < MD5_DIGEST_LENGTH - 1; i++) - printf("%02x-", md5->md[i]); - printf("%02x\n", md5->md[i]); + COMP_TST_PRT("%02x-", md5->md[i]); + COMP_TST_PRT("%02x\n", md5->md[i]); }
int cmp_md5(comp_md5_t *orig, comp_md5_t *final) @@ -780,9 +778,9 @@ int cmp_md5(comp_md5_t *orig, comp_md5_t *final) return -EINVAL; for (i = 0; i < MD5_DIGEST_LENGTH; i++) { if (orig->md[i] != final->md[i]) { - printf("Original MD5: "); + COMP_TST_PRT("Original MD5: "); dump_md5(orig); - printf("Final MD5: "); + COMP_TST_PRT("Final MD5: "); dump_md5(final); return -EINVAL; } @@ -881,7 +879,7 @@ static int chunk_deflate2(void *in, size_t in_sz, void *out, size_t *out_sz, windowBits = 15 + 16; break; default: - printf("algorithm %d unsupported by zlib\n", alg_type); + COMP_TST_PRT("algorithm %d unsupported by zlib\n", alg_type); return -EINVAL; } memset(&strm, 0, sizeof(z_stream)); @@ -893,23 +891,23 @@ static int chunk_deflate2(void *in, size_t in_sz, void *out, size_t *out_sz, ret = deflateInit2(&strm, Z_BEST_SPEED, Z_DEFLATED, windowBits, 8, Z_DEFAULT_STRATEGY); if (ret != Z_OK) { - printf("deflateInit2: %d\n", ret); + COMP_TST_PRT("deflateInit2: %d\n", ret); return -EINVAL; }
do { ret = deflate(&strm, Z_FINISH); if ((ret == Z_STREAM_ERROR) || (ret == Z_BUF_ERROR)) { - printf("defalte error %d - %s\n", ret, strm.msg); + COMP_TST_PRT("defalte error %d - %s\n", ret, strm.msg); ret = -ENOSR; break; } else if (!strm.avail_in) { if (ret != Z_STREAM_END) - printf("deflate unexpected return: %d\n", ret); + COMP_TST_PRT("deflate unexpected return: %d\n", ret); ret = 0; break; } else if (!strm.avail_out) { - printf("deflate out of memory\n"); + COMP_TST_PRT("deflate out of memory\n"); ret = -ENOSPC; break; } @@ -934,7 +932,7 @@ static int chunk_inflate2(void *in, size_t in_sz, void *out, size_t *out_sz, /* Window size of 15, +32 for auto-decoding gzip/zlib */ ret = inflateInit2(&strm, 15 + 32); if (ret != Z_OK) { - printf("zlib inflateInit: %d\n", ret); + COMP_TST_PRT("zlib inflateInit: %d\n", ret); return -EINVAL; }
@@ -945,13 +943,13 @@ static int chunk_inflate2(void *in, size_t in_sz, void *out, size_t *out_sz, do { ret = inflate(&strm, Z_NO_FLUSH); if ((ret < 0) || (ret == Z_NEED_DICT)) { - printf("zlib error %d - %s\n", ret, strm.msg); + COMP_TST_PRT("zlib error %d - %s\n", ret, strm.msg); goto out; } if (!strm.avail_out) { if (!strm.avail_in || (ret == Z_STREAM_END)) break; - printf("%s: avail_out is empty!\n", __func__); + COMP_TST_PRT("%s: avail_out is empty!\n", __func__); goto out; } } while (strm.avail_in && (ret != Z_STREAM_END)); @@ -1271,7 +1269,7 @@ int create_send_tdata(struct test_options *opts, if (opts->option & TEST_THP) { ret = madvise(info->in_buf, info->in_size, MADV_HUGEPAGE); if (ret) { - printf("madvise(MADV_HUGEPAGE)"); + COMP_TST_PRT("madvise(MADV_HUGEPAGE)"); goto out_in; } } @@ -1291,7 +1289,7 @@ int create_send_tdata(struct test_options *opts, if (opts->option & TEST_THP) { ret = madvise(tdata->dst, tdata->dst_sz, MADV_HUGEPAGE); if (ret) { - printf("madvise(MADV_HUGEPAGE)"); + COMP_TST_PRT("madvise(MADV_HUGEPAGE)"); goto out_dst; } } @@ -1413,7 +1411,7 @@ int attach2_threads(struct test_options *opts, ret = pthread_create(&info->send_tds[i], &attr, send_thread_func, &info->tdatas[i]); if (ret < 0) { - printf("Fail to create send thread %d (%d)\n", i, ret); + COMP_TST_PRT("Fail to create send thread %d (%d)\n", i, ret); goto out; } } @@ -1423,7 +1421,7 @@ int attach2_threads(struct test_options *opts, poll_thread_func, &info->tdatas[i]); if (ret < 0) { - printf("Fail to create poll thread %d (%d)\n", + COMP_TST_PRT("Fail to create poll thread %d (%d)\n", i, ret); goto out_poll; } @@ -1431,7 +1429,7 @@ int attach2_threads(struct test_options *opts, for (i = 0; i < info->poll_tnum; i++) { ret = pthread_join(info->poll_tds[i], &tret); if (ret < 0) { - fprintf(stderr, "Fail on poll thread with %d\n", + COMP_TST_PRT( "Fail on poll thread with %d\n", ret); goto out_poll; } @@ -1440,7 +1438,7 @@ int attach2_threads(struct test_options *opts, for (i = 0; i < info->send_tnum; i++) { ret = pthread_join(info->send_tds[i], &tret); if (ret < 0) { - fprintf(stderr, "Fail on send thread with %d\n", ret); + COMP_TST_PRT( "Fail on send thread with %d\n", ret); goto out_poll; } } @@ -1522,7 +1520,7 @@ struct uacce_dev_list *get_dev_list(struct test_options *opts, }
if (!p) { - WD_ERR("Request too much contexts: %d\n", + COMP_TST_PRT("Request too much contexts: %d\n", opts->q_num * 4 * children); goto out; } @@ -1557,7 +1555,7 @@ int init_ctx_config(struct test_options *opts, void *priv, __atomic_store_n(&sum_thread_end, 0, __ATOMIC_RELEASE); *sched = wd_sched_rr_alloc(SCHED_POLICY_RR, 2, 2, lib_poll_func); if (!*sched) { - WD_ERR("wd_sched_rr_alloc fail\n"); + COMP_TST_PRT("wd_sched_rr_alloc fail\n"); goto out_sched; }
@@ -1567,14 +1565,14 @@ int init_ctx_config(struct test_options *opts, void *priv, ctx_conf->ctx_num = q_num * 4; ctx_conf->ctxs = calloc(1, q_num * 4 * sizeof(struct wd_ctx)); if (!ctx_conf->ctxs) { - WD_ERR("Not enough memory to allocate contexts.\n"); + COMP_TST_PRT("Not enough memory to allocate contexts.\n"); ret = -ENOMEM; goto out_ctx; } for (i = 0; i < ctx_conf->ctx_num; i++) { ctx_conf->ctxs[i].ctx = wd_request_ctx(info->list->dev); if (!ctx_conf->ctxs[i].ctx) { - WD_ERR("Fail to allocate context #%d\n", i); + COMP_TST_PRT("Fail to allocate context #%d\n", i); ret = -EINVAL; goto out_req; } @@ -1594,7 +1592,7 @@ int init_ctx_config(struct test_options *opts, void *priv, param.end = q_num - 1; ret = wd_sched_rr_instance((const struct wd_sched *)*sched, ¶m); if (ret < 0) { - WD_ERR("Fail to fill sched region.\n"); + COMP_TST_PRT("Fail to fill sched region.\n"); goto out_fill; } for (i = q_num; i < q_num * 2; i++) { @@ -1607,7 +1605,7 @@ int init_ctx_config(struct test_options *opts, void *priv, param.end = q_num * 2 - 1; ret = wd_sched_rr_instance((const struct wd_sched *)*sched, ¶m); if (ret < 0) { - WD_ERR("Fail to fill sched region.\n"); + COMP_TST_PRT("Fail to fill sched region.\n"); goto out_fill; } for (i = q_num * 2; i < q_num * 3; i++) { @@ -1620,7 +1618,7 @@ int init_ctx_config(struct test_options *opts, void *priv, param.end = q_num * 3 - 1; ret = wd_sched_rr_instance((const struct wd_sched *)*sched, ¶m); if (ret < 0) { - WD_ERR("Fail to fill sched region.\n"); + COMP_TST_PRT("Fail to fill sched region.\n"); goto out_fill; } for (i = q_num * 3; i < q_num * 4; i++) { @@ -1633,7 +1631,7 @@ int init_ctx_config(struct test_options *opts, void *priv, param.end = q_num * 4 - 1; ret = wd_sched_rr_instance((const struct wd_sched *)*sched, ¶m); if (ret < 0) { - WD_ERR("Fail to fill sched region.\n"); + COMP_TST_PRT("Fail to fill sched region.\n"); goto out_fill; }
@@ -1772,7 +1770,7 @@ int hizip_check_output(void *buf, size_t size, size_t *checked, /* Window size of 15, +32 for auto-decoding gzip/zlib */ ret = inflateInit2(&stream, 15 + 32); if (ret != Z_OK) { - WD_ERR("zlib inflateInit: %d\n", ret); + COMP_TST_PRT("zlib inflateInit: %d\n", ret); ret = -EINVAL; goto out_free_buf; } @@ -1780,7 +1778,7 @@ int hizip_check_output(void *buf, size_t size, size_t *checked, do { ret = inflate(&stream, Z_NO_FLUSH); if (ret < 0 || ret == Z_NEED_DICT) { - WD_ERR("zlib error %d - %s\n", ret, stream.msg); + COMP_TST_PRT("zlib error %d - %s\n", ret, stream.msg); ret = -ENOSR; break; } @@ -1834,31 +1832,31 @@ int zlib_deflate(void *output, unsigned int out_size, windowBits = 15 + 16; break; default: - WD_ERR("algorithm %d unsupported by zlib\n", alg_type); + COMP_TST_PRT("algorithm %d unsupported by zlib\n", alg_type); return -EINVAL; }
ret = deflateInit2(&stream, Z_BEST_SPEED, Z_DEFLATED, windowBits, 9, Z_DEFAULT_STRATEGY); if (ret != Z_OK) { - WD_ERR("zlib deflateInit: %d\n", ret); + COMP_TST_PRT("zlib deflateInit: %d\n", ret); return -EINVAL; }
do { ret = deflate(&stream, Z_FINISH); if (ret == Z_STREAM_ERROR || ret == Z_BUF_ERROR) { - WD_ERR("zlib error %d - %s\n", ret, stream.msg); + COMP_TST_PRT("zlib error %d - %s\n", ret, stream.msg); ret = -ENOSR; break; } else if (!stream.avail_in) { if (ret != Z_STREAM_END) - WD_ERR("unexpected deflate return value %d\n", ret); + COMP_TST_PRT("unexpected deflate return value %d\n", ret); *produced = stream.total_out; ret = 0; break; } else if (!stream.avail_out) { - WD_ERR("No more output available\n"); + COMP_TST_PRT("No more output available\n"); ret = -ENOSPC; break; } diff --git a/uadk_tool/test/comp_lib.h b/uadk_tool/test/comp_lib.h index 95b5a31..4d11a84 100644 --- a/uadk_tool/test/comp_lib.h +++ b/uadk_tool/test/comp_lib.h @@ -33,6 +33,14 @@ do { \ } \ } while (0)
+#ifdef DEBUG_LOG +#define dbg(msg, ...) fprintf(stderr, msg, ##__VA_ARGS__) +#else +#define dbg(msg, ...) +#endif + +#define COMP_TST_PRT printf + enum mode { MODE_BLOCK, MODE_STREAM, diff --git a/uadk_tool/test/comp_main.c b/uadk_tool/test/comp_main.c index a21a952..39f8525 100644 --- a/uadk_tool/test/comp_main.c +++ b/uadk_tool/test/comp_main.c @@ -120,7 +120,7 @@ static void *sw_dfl_hw_ifl(void *arg) tdata->dst_sz, tdata->dst_sz); ret = sw_deflate2(tdata->in_list, tlist, opts); if (ret) { - printf("Fail to deflate by zlib: %d\n", ret); + COMP_TST_PRT("Fail to deflate by zlib: %d\n", ret); goto out_strm; } tout_sz = tdata->dst_sz; @@ -132,24 +132,24 @@ static void *sw_dfl_hw_ifl(void *arg) tlist->addr, tlist->size); if (ret) { - printf("Fail to inflate by HW: %d\n", ret); + COMP_TST_PRT("Fail to inflate by HW: %d\n", ret); goto out_strm; } ret = calculate_md5(&tdata->md5, tdata->in_list->addr, tdata->in_list->size); if (ret) { - printf("Fail to generate MD5 (%d)\n", ret); + COMP_TST_PRT("Fail to generate MD5 (%d)\n", ret); goto out_strm; } ret = calculate_md5(&final_md5, tdata->out_list->addr, tout_sz); if (ret) { - printf("Fail to generate MD5 (%d)\n", ret); + COMP_TST_PRT("Fail to generate MD5 (%d)\n", ret); goto out_strm; } ret = cmp_md5(&tdata->md5, &final_md5); if (ret) { - printf("MD5 is unmatched (%d) at %dth times on " + COMP_TST_PRT("MD5 is unmatched (%d) at %dth times on " "thread %d\n", ret, i, tdata->tid); goto out_strm; } @@ -181,28 +181,28 @@ static void *sw_dfl_hw_ifl(void *arg) info->out_chunk_sz); ret = sw_deflate2(tdata->in_list, tlist, opts); if (ret) { - printf("Fail to deflate by zlib: %d\n", ret); + COMP_TST_PRT("Fail to deflate by zlib: %d\n", ret); goto out_run; } ret = hw_inflate4(h_ifl, tlist, tdata->out_list, opts, &tdata->sem); if (ret) { - printf("Fail to inflate by HW: %d\n", ret); + COMP_TST_PRT("Fail to inflate by HW: %d\n", ret); goto out_run; } ret = calculate_md5(&tdata->md5, tdata->src, tdata->src_sz); if (ret) { - printf("Fail to generate MD5 (%d)\n", ret); + COMP_TST_PRT("Fail to generate MD5 (%d)\n", ret); goto out_run; } ret = calculate_md5(&final_md5, tdata->dst, tdata->dst_sz); if (ret) { - printf("Fail to generate MD5 (%d)\n", ret); + COMP_TST_PRT("Fail to generate MD5 (%d)\n", ret); goto out_run; } ret = cmp_md5(&tdata->md5, &final_md5); if (ret) { - printf("MD5 is unmatched (%d) at %dth times on " + COMP_TST_PRT("MD5 is unmatched (%d) at %dth times on " "thread %d\n", ret, i, tdata->tid); goto out_run; } @@ -273,30 +273,30 @@ static void *hw_dfl_sw_ifl(void *arg) tdata->src, tdata->src_sz); if (ret) { - printf("Fail to deflate by HW: %d\n", ret); + COMP_TST_PRT("Fail to deflate by HW: %d\n", ret); goto out_strm; } tlist->size = tmp_sz; // write back ret = sw_inflate2(tlist, tdata->out_list, opts); if (ret) { - printf("Fail to inflate by zlib: %d\n", ret); + COMP_TST_PRT("Fail to inflate by zlib: %d\n", ret); goto out_strm; } ret = calculate_md5(&tdata->md5, tdata->in_list->addr, tdata->in_list->size); if (ret) { - printf("Fail to generate MD5 (%d)\n", ret); + COMP_TST_PRT("Fail to generate MD5 (%d)\n", ret); goto out_strm; } ret = calculate_md5(&final_md5, tdata->out_list->addr, tdata->out_list->size); if (ret) { - printf("Fail to generate MD5 (%d)\n", ret); + COMP_TST_PRT("Fail to generate MD5 (%d)\n", ret); goto out_strm; } ret = cmp_md5(&tdata->md5, &final_md5); if (ret) { - printf("MD5 is unmatched (%d) at %dth times on " + COMP_TST_PRT("MD5 is unmatched (%d) at %dth times on " "thread %d\n", ret, i, tdata->tid); goto out_strm; } @@ -328,27 +328,27 @@ static void *hw_dfl_sw_ifl(void *arg) ret = hw_deflate4(h_dfl, tdata->in_list, tlist, opts, &tdata->sem); if (ret) { - printf("Fail to deflate by HW: %d\n", ret); + COMP_TST_PRT("Fail to deflate by HW: %d\n", ret); goto out_run; } ret = sw_inflate2(tlist, tdata->out_list, opts); if (ret) { - printf("Fail to inflate by zlib: %d\n", ret); + COMP_TST_PRT("Fail to inflate by zlib: %d\n", ret); goto out_run; } ret = calculate_md5(&tdata->md5, tdata->src, tdata->src_sz); if (ret) { - printf("Fail to generate MD5 (%d)\n", ret); + COMP_TST_PRT("Fail to generate MD5 (%d)\n", ret); goto out_run; } ret = calculate_md5(&final_md5, tdata->dst, tdata->dst_sz); if (ret) { - printf("Fail to generate MD5 (%d)\n", ret); + COMP_TST_PRT("Fail to generate MD5 (%d)\n", ret); goto out_run; } ret = cmp_md5(&tdata->md5, &final_md5); if (ret) { - printf("MD5 is unmatched (%d) at %dth times on " + COMP_TST_PRT("MD5 is unmatched (%d) at %dth times on " "thread %d\n", ret, i, tdata->tid); goto out_run; } @@ -407,7 +407,7 @@ static void *hw_dfl_hw_ifl(void *arg) tdata->src, tdata->src_sz); if (ret) { - printf("Fail to deflate by HW: %d\n", ret); + COMP_TST_PRT("Fail to deflate by HW: %d\n", ret); goto out; } tout_sz = tdata->dst_sz; @@ -419,23 +419,23 @@ static void *hw_dfl_hw_ifl(void *arg) tbuf, tmp_sz); if (ret) { - printf("Fail to inflate by HW: %d\n", ret); + COMP_TST_PRT("Fail to inflate by HW: %d\n", ret); goto out; } ret = calculate_md5(&tdata->md5, tdata->in_list->addr, tdata->in_list->size); if (ret) { - printf("Fail to generate MD5 (%d)\n", ret); + COMP_TST_PRT("Fail to generate MD5 (%d)\n", ret); goto out; } ret = calculate_md5(&final_md5, tdata->dst, tout_sz); if (ret) { - printf("Fail to generate MD5 (%d)\n", ret); + COMP_TST_PRT("Fail to generate MD5 (%d)\n", ret); goto out; } ret = cmp_md5(&tdata->md5, &final_md5); if (ret) { - printf("MD5 is unmatched (%d) at %dth times on " + COMP_TST_PRT("MD5 is unmatched (%d) at %dth times on " "thread %d\n", ret, i, tdata->tid); goto out; } @@ -481,28 +481,28 @@ static void *hw_dfl_hw_ifl(void *arg) ret = hw_deflate4(h_dfl, tdata->in_list, tlist, opts, &tdata->sem); if (ret) { - printf("Fail to deflate by HW: %d\n", ret); + COMP_TST_PRT("Fail to deflate by HW: %d\n", ret); goto out_run; } ret = hw_inflate4(h_ifl, tlist, tdata->out_list, opts, &tdata->sem); if (ret) { - printf("Fail to inflate by HW: %d\n", ret); + COMP_TST_PRT("Fail to inflate by HW: %d\n", ret); goto out_run; } ret = calculate_md5(&tdata->md5, tdata->src, tdata->src_sz); if (ret) { - printf("Fail to generate MD5 (%d)\n", ret); + COMP_TST_PRT("Fail to generate MD5 (%d)\n", ret); goto out_run; } ret = calculate_md5(&final_md5, tdata->dst, tdata->dst_sz); if (ret) { - printf("Fail to generate MD5 (%d)\n", ret); + COMP_TST_PRT("Fail to generate MD5 (%d)\n", ret); goto out_run; } ret = cmp_md5(&tdata->md5, &final_md5); if (ret) { - printf("MD5 is unmatched (%d) at %dth times on " + COMP_TST_PRT("MD5 is unmatched (%d) at %dth times on " "thread %d\n", ret, i, tdata->tid); goto out_run; } @@ -547,7 +547,7 @@ static void *hw_dfl_perf(void *arg) tdata->src, tdata->src_sz); if (ret) { - printf("Fail to deflate by HW: %d\n", ret); + COMP_TST_PRT("Fail to deflate by HW: %d\n", ret); return (void *)(uintptr_t)ret; } } @@ -573,7 +573,7 @@ static void *hw_dfl_perf(void *arg) ret = hw_deflate4(h_dfl, tdata->in_list, tdata->out_list, opts, &tdata->sem); if (ret) { - printf("Fail to deflate by HW: %d\n", ret); + COMP_TST_PRT("Fail to deflate by HW: %d\n", ret); goto out; } } @@ -608,7 +608,7 @@ static void *hw_ifl_perf(void *arg) tdata->in_list->addr, tdata->in_list->size); if (ret) { - printf("Fail to inflate by HW: %d\n", ret); + COMP_TST_PRT("Fail to inflate by HW: %d\n", ret); return (void *)(uintptr_t)ret; } tdata->out_list->addr = tdata->dst; @@ -634,7 +634,7 @@ static void *hw_ifl_perf(void *arg) ret = hw_inflate4(h_ifl, tdata->in_list, tdata->out_list, opts, &tdata->sem); if (ret) { - printf("Fail to inflate by HW: %d\n", ret); + COMP_TST_PRT("Fail to inflate by HW: %d\n", ret); goto out; } } @@ -670,7 +670,7 @@ void *hw_dfl_perf3(void *arg) tdata->src, tdata->src_sz); if (ret) { - printf("Fail to deflate by HW: %d\n", ret); + COMP_TST_PRT("Fail to deflate by HW: %d\n", ret); return (void *)(uintptr_t)ret; } } @@ -696,7 +696,7 @@ void *hw_dfl_perf3(void *arg) ret = hw_deflate5(h_dfl, tdata->in_list, tdata->out_list, tdata); if (ret) { - printf("Fail to deflate by HW: %d\n", ret); + COMP_TST_PRT("Fail to deflate by HW: %d\n", ret); goto out; } } @@ -732,7 +732,7 @@ void *hw_ifl_perf3(void *arg) tdata->src, tdata->src_sz); if (ret) { - printf("Fail to inflate by HW: %d\n", ret); + COMP_TST_PRT("Fail to inflate by HW: %d\n", ret); return (void *)(uintptr_t)ret; } tdata->out_list->addr = tdata->dst; @@ -758,7 +758,7 @@ void *hw_ifl_perf3(void *arg) ret = hw_inflate5(h_ifl, tdata->in_list, tdata->out_list, tdata); if (ret) { - printf("Fail to inflate by HW: %d\n", ret); + COMP_TST_PRT("Fail to inflate by HW: %d\n", ret); goto out; } } @@ -786,7 +786,7 @@ int load_ilist(struct hizip_test_info *info, char *model) if (!strcmp(model, "hw_ifl_perf")) { if (!opts->is_stream) { if (opts->fd_ilist < 0) { - printf("Missing IN list file!\n"); + COMP_TST_PRT("Missing IN list file!\n"); return -EINVAL; } p = tdata->in_list; @@ -818,7 +818,7 @@ int load_file_data(struct hizip_test_info *info)
file_sz = read(opts->fd_in, info->in_buf, info->in_size); if (file_sz < info->in_size) { - printf("Expect to read %ld bytes. " + COMP_TST_PRT("Expect to read %ld bytes. " "But only read %ld bytes!\n", info->in_size, file_sz); return -EFAULT; @@ -930,7 +930,7 @@ int test_hw(struct test_options *opts, char *model)
if (!event_unavailable && perf_event_get("iommu/dev_fault", &perf_fds, &nr_fds)) { - printf("IOPF statistic unavailable\n"); + COMP_TST_PRT("IOPF statistic unavailable\n"); /* No need to retry and print an error on every run */ event_unavailable = true; } @@ -1012,7 +1012,7 @@ int test_hw(struct test_options *opts, char *model) opts->is_stream ? "STREAM" : "BLOCK"); ifl_flag = 1; } else { - printf("Wrong model is specified:%s\n", model); + COMP_TST_PRT("Wrong model is specified:%s\n", model); ret = -EINVAL; goto out; } @@ -1114,12 +1114,12 @@ int test_hw(struct test_options *opts, char *model) */ ret = munmap(info.in_buf, info.in_size); if (ret) { - printf("Failed to unmap."); + COMP_TST_PRT("Failed to unmap."); goto out_buf; } /* A warning if the parameters might produce false positives */ if (opts->total_len > 0x54000) - fprintf(stderr, "NOTE: test might trash the TLB\n"); + COMP_TST_PRT( "NOTE: test might trash the TLB\n"); } stat_start(&info); ret = attach2_threads(opts, &info, func, poll2_thread_func); @@ -1149,10 +1149,10 @@ int test_hw(struct test_options *opts, char *model) } if (!strcmp(model, "hw_dfl_perf") || !strcmp(model, "hw_ifl_perf") || !strcmp(model, "hw_dfl_perf3") || !strcmp(model, "hw_ifl_perf3")) { - printf("%s at %.2fMB/s in %f usec (BLK:%d, Bnum:%d).\n", + COMP_TST_PRT("%s at %.2fMB/s in %f usec (BLK:%d, Bnum:%d).\n", zbuf, speed, usec, opts->block_size, opts->batch_num); } else { - printf("%s in %f usec (BLK:%d, Bnum:%d).\n", + COMP_TST_PRT("%s in %f usec (BLK:%d, Bnum:%d).\n", zbuf, usec, opts->block_size, opts->batch_num); } free2_threads(&info); @@ -1169,7 +1169,7 @@ out_poll: wd_comp_env_uninit(); else nonenv_resource_uninit(opts, &info, sched); - printf("Fail to run %s() (%d)!\n", model, ret); + COMP_TST_PRT("Fail to run %s() (%d)!\n", model, ret); return ret; out_send: mmap_free(info.in_buf, info.in_size); @@ -1179,7 +1179,7 @@ out_src: else nonenv_resource_uninit(opts, &info, sched); out: - printf("Fail to run %s() (%d)!\n", model, ret); + COMP_TST_PRT("Fail to run %s() (%d)!\n", model, ret); return ret; }
@@ -1188,7 +1188,7 @@ int run_self_test(struct test_options *opts) int i, f_ret = 0; char poll_str[POLL_STRING_LEN];
- printf("Start to run self test!\n"); + COMP_TST_PRT("Start to run self test!\n"); opts->alg_type = WD_ZLIB; opts->data_fmt = WD_FLAT_BUF; opts->sync_mode = 0; @@ -1274,7 +1274,7 @@ int run_self_test(struct test_options *opts) f_ret |= test_hw(opts, "hw_ifl_perf"); } if (!f_ret) - printf("Run self test successfully!\n"); + COMP_TST_PRT("Run self test successfully!\n"); return f_ret; }
@@ -1334,7 +1334,7 @@ int run_cmd(struct test_options *opts) for (i = 0; i < opts->children; i++) { pid = fork(); if (pid < 0) { - printf("cannot fork: %d\n", errno); + COMP_TST_PRT("cannot fork: %d\n", errno); success = false; break; } else if (pid > 0) { @@ -1350,28 +1350,28 @@ int run_cmd(struct test_options *opts) pid = pids[i]; ret = waitpid(pid, &status, 0); if (ret < 0) { - printf("wait(pid=%d) error %d\n", pid, errno); + COMP_TST_PRT("wait(pid=%d) error %d\n", pid, errno); success = false; continue; } if (WIFEXITED(status)) { ret = WEXITSTATUS(status); if (ret) { - printf("child %d returned with %d\n", + COMP_TST_PRT("child %d returned with %d\n", pid, ret); success = false; } } else if (WIFSIGNALED(status)) { ret = WTERMSIG(status); - printf("child %d killed by sig %d\n", pid, ret); + COMP_TST_PRT("child %d killed by sig %d\n", pid, ret); success = false; } else { - printf("unexpected status for child %d\n", pid); + COMP_TST_PRT("unexpected status for child %d\n", pid); success = false; } } if (success == false) { - printf("Failed to run spawn test!\n"); + COMP_TST_PRT("Failed to run spawn test!\n"); if (!ret) ret = -EINVAL; } @@ -1510,7 +1510,7 @@ static void set_thp(struct test_options *opts) goto out_err;
if (strcmp(s, "never") == 0) { - printf("Cannot test THP with enable=never\n"); + COMP_TST_PRT("Cannot test THP with enable=never\n"); return; }
@@ -1523,13 +1523,13 @@ static void set_thp(struct test_options *opts) goto out_err;
if (strcmp(s, "defer") == 0 || strcmp(s, "never") == 0) { - printf("Cannot test THP with defrag=%s\n", s); + COMP_TST_PRT("Cannot test THP with defrag=%s\n", s); return; }
return; out_err: - printf("THP unsupported?\n"); + COMP_TST_PRT("THP unsupported?\n"); }
void stat_setup(struct hizip_test_info *info) @@ -1616,7 +1616,7 @@ void stat_end(struct hizip_test_info *info)
static void handle_sigbus(int sig) { - printf("SIGBUS!\n"); + COMP_TST_PRT("SIGBUS!\n"); _exit(0); }
@@ -1672,17 +1672,17 @@ int test_comp_entry(int argc, char *argv[]) if (optarg) { opts.fd_in = open(optarg, O_RDONLY); if (opts.fd_in < 0) { - printf("Fail to open %s\n", + COMP_TST_PRT("Fail to open %s\n", optarg); show_help = 1; } else opts.is_file = true; } else { - printf("Input file is missing!\n"); + COMP_TST_PRT("Input file is missing!\n"); show_help = 1; } if (lseek(opts.fd_in, 0, SEEK_SET) < 0) { - printf("Fail on lseek()!\n"); + COMP_TST_PRT("Fail on lseek()!\n"); show_help = 1; } break; @@ -1693,42 +1693,42 @@ int test_comp_entry(int argc, char *argv[]) S_IWUSR | S_IRGRP | S_IROTH); if (opts.fd_out < 0) { - printf("Fail to open %s\n", + COMP_TST_PRT("Fail to open %s\n", optarg); show_help = 1; } else opts.is_file = true; } else { - printf("Output file is missing!\n"); + COMP_TST_PRT("Output file is missing!\n"); show_help = 1; } if (lseek(opts.fd_out, 0, SEEK_SET) < 0) { - printf("Fail on lseek()!\n"); + COMP_TST_PRT("Fail on lseek()!\n"); show_help = 1; } break; case 3: /* ilist */ if (!optarg) { - printf("IN list file is missing!\n"); + COMP_TST_PRT("IN list file is missing!\n"); show_help = 1; break; } opts.fd_ilist = open(optarg, O_RDONLY); if (opts.fd_ilist < 0) { - printf("Fail to open %s\n", optarg); + COMP_TST_PRT("Fail to open %s\n", optarg); show_help = 1; break; } opts.is_file = true; if (lseek(opts.fd_ilist, 0, SEEK_SET) < 0) { - printf("Fail on lseek()!\n"); + COMP_TST_PRT("Fail on lseek()!\n"); show_help = 1; break; } break; case 4: /* olist */ if (!optarg) { - printf("OUT list file is missing!\n"); + COMP_TST_PRT("OUT list file is missing!\n"); show_help = 1; break; } @@ -1737,13 +1737,13 @@ int test_comp_entry(int argc, char *argv[]) S_IWUSR | S_IRGRP | S_IROTH); if (opts.fd_olist < 0) { - printf("Fail to open %s\n", optarg); + COMP_TST_PRT("Fail to open %s\n", optarg); show_help = 1; break; } opts.is_file = true; if (lseek(opts.fd_olist, 0, SEEK_SET) < 0) { - printf("Fail on lseek()!\n"); + COMP_TST_PRT("Fail on lseek()!\n"); show_help = 1; break; }
From: Hao Fang fanghao11@huawei.com
Remove the -F/-n/-v cmd.
Signed-off-by: Hao Fang fanghao11@huawei.com Signed-off-by: Qi Tao taoqi10@huawei.com --- uadk_tool/test/comp_lib.c | 13 ------------- uadk_tool/test/comp_lib.h | 8 +------- uadk_tool/test/comp_main.c | 2 -- 3 files changed, 1 insertion(+), 22 deletions(-)
diff --git a/uadk_tool/test/comp_lib.c b/uadk_tool/test/comp_lib.c index c2e4410..5e33d88 100644 --- a/uadk_tool/test/comp_lib.c +++ b/uadk_tool/test/comp_lib.c @@ -1678,13 +1678,6 @@ int parse_common_option(const char opt, const char *optarg, if (opts->compact_run_num <= 0) return 1; break; - case 'n': - opts->run_num = strtol(optarg, NULL, 0); - SYS_ERR_COND(opts->run_num > MAX_RUNS, - "No more than %d runs supported\n", MAX_RUNS); - if (opts->run_num <= 0) - return 1; - break; case 'q': opts->q_num = strtol(optarg, NULL, 0); if (opts->q_num <= 0) @@ -1693,9 +1686,6 @@ int parse_common_option(const char opt, const char *optarg, case 'd': opts->op_type = WD_DIR_DECOMPRESS; break; - case 'F': - opts->is_file = true; - break; case 'S': opts->is_stream = MODE_STREAM; break; @@ -1717,9 +1707,6 @@ int parse_common_option(const char opt, const char *optarg, case 'V': opts->verify = true; break; - case 'v': - opts->verbose = true; - break; case 'a': opts->alg_type = WD_DEFLATE; break; diff --git a/uadk_tool/test/comp_lib.h b/uadk_tool/test/comp_lib.h index 4d11a84..775c72b 100644 --- a/uadk_tool/test/comp_lib.h +++ b/uadk_tool/test/comp_lib.h @@ -71,8 +71,6 @@ struct test_options { int q_num; unsigned long total_len;
-#define MAX_RUNS 1024 - int run_num; /* tasks running in parallel */ int compact_run_num;
@@ -101,7 +99,6 @@ struct test_options { __u8 data_fmt;
bool verify; - bool verbose; bool is_decomp; bool is_stream; bool is_file; @@ -333,18 +330,15 @@ static inline void hizip_test_adjust_len(struct test_options *opts) opts->block_size * opts->block_size; }
-#define COMMON_OPTSTRING "hb:n:q:l:FSs:Vvzt:m:dacLZ" +#define COMMON_OPTSTRING "hb:q:l:Ss:Vzt:m:dacLZ"
#define COMMON_HELP "%s [opts]\n" \ " -b <size> block size\n" \ - " -n <num> number of runs\n" \ " -q <num> number of queues\n" \ " -l <num> number of compact runs\n" \ - " -F input file, default no input\n" \ " -S stream mode, default block mode\n" \ " -s <size> total size\n" \ " -V verify output\n" \ - " -v display detailed performance information\n" \ " -a test deflate algorithm, default gzip\n" \ " -z test zlib algorithm, default gzip\n" \ " -t <num> number of thread per process\n" \ diff --git a/uadk_tool/test/comp_main.c b/uadk_tool/test/comp_main.c index 39f8525..9f0e7de 100644 --- a/uadk_tool/test/comp_main.c +++ b/uadk_tool/test/comp_main.c @@ -1626,14 +1626,12 @@ int test_comp_entry(int argc, char *argv[]) .alg_type = WD_GZIP, .op_type = WD_DIR_COMPRESS, .q_num = 1, - .run_num = 1, .compact_run_num = 1, .thread_num = 1, .sync_mode = 0, .block_size = 512000, .total_len = opts.block_size * 10, .verify = false, - .verbose = false, .is_decomp = false, .is_stream = false, .is_file = false,
From: Hao Fang fanghao11@huawei.com
The cmd --ilist and --olist just use for compress file in block mode, but the block mode can be verified by the memory buffer compress testcase.
Just remove the self defined protocol will simplified the tool.
Signed-off-by: Hao Fang fanghao11@huawei.com Signed-off-by: Qi Tao taoqi10@huawei.com --- uadk_tool/test/comp_lib.h | 4 -- uadk_tool/test/comp_main.c | 139 ++----------------------------------- 2 files changed, 7 insertions(+), 136 deletions(-)
diff --git a/uadk_tool/test/comp_lib.h b/uadk_tool/test/comp_lib.h index 775c72b..6b6a9f4 100644 --- a/uadk_tool/test/comp_lib.h +++ b/uadk_tool/test/comp_lib.h @@ -90,10 +90,6 @@ struct test_options { int fd_in; /* output file */ int fd_out; - /* inlist file */ - int fd_ilist; - /* outlist file */ - int fd_olist;
/* 0: pbuffer, 1: sgl */ __u8 data_fmt; diff --git a/uadk_tool/test/comp_main.c b/uadk_tool/test/comp_main.c index 9f0e7de..872d4de 100644 --- a/uadk_tool/test/comp_main.c +++ b/uadk_tool/test/comp_main.c @@ -771,43 +771,6 @@ out: return (void *)(uintptr_t)(ret); }
-/* - * Load both ilist file. - */ -int load_ilist(struct hizip_test_info *info, char *model) -{ - struct test_options *opts = info->opts; - thread_data_t *tdata = &info->tdatas[0]; - chunk_list_t *p; - size_t sum = 0; - ssize_t file_sz = 0; - void *addr; - - if (!strcmp(model, "hw_ifl_perf")) { - if (!opts->is_stream) { - if (opts->fd_ilist < 0) { - COMP_TST_PRT("Missing IN list file!\n"); - return -EINVAL; - } - p = tdata->in_list; - addr = info->in_buf; - while (p) { - file_sz = read(opts->fd_ilist, p, - sizeof(chunk_list_t)); - if (file_sz < 0) - return -EFAULT; - p->addr = addr; - sum += file_sz; - if (p->next) - p->next = p + 1; - addr += p->size; - p = p->next; - } - } - } - return (int)sum; -} - /* * Load compression/decompression content. */ @@ -827,9 +790,9 @@ int load_file_data(struct hizip_test_info *info) }
/* - * Store both olist file. opts->is_file must be enabled first. + * Store both output file. opts->is_file must be enabled first. */ -int store_olist(struct hizip_test_info *info, char *model) +int store_file(struct hizip_test_info *info, char *model) { struct test_options *opts = info->opts; thread_data_t *tdata = &info->tdatas[0]; @@ -838,34 +801,9 @@ int store_olist(struct hizip_test_info *info, char *model) ssize_t file_sz = 0;
if (!opts->is_stream) { - if (opts->fd_olist >= 0) { - /* compress with BLOCK */ - p = tdata->out_list; - while (p) { - file_sz = write(opts->fd_olist, p, - sizeof(chunk_list_t)); - if (file_sz < sizeof(chunk_list_t)) - return -EFAULT; - file_sz = write(opts->fd_out, p->addr, - p->size); - if (file_sz < p->size) - return -EFAULT; - p = p->next; - sum += file_sz; - } - } else { - /* decompress with BLOCK */ - p = tdata->out_list; - while (p) { - file_sz = write(opts->fd_out, p->addr, - p->size); - if (file_sz < p->size) - return -EFAULT; - p = p->next; - sum += file_sz; - } - } - } else if (opts->is_stream) { + COMP_TST_PRT("Invalid, file need stream mode!\n"); + return -EINVAL; + } else { p = tdata->out_list; file_sz = write(opts->fd_out, p->addr, p->size); if (file_sz < p->size) @@ -914,7 +852,6 @@ int test_hw(struct test_options *opts, char *model) void *tbuf = NULL; struct stat statbuf; chunk_list_t *tlist = NULL; - int div; __u32 num; __u8 enable; int nr_fds = 0; @@ -1043,20 +980,6 @@ int test_hw(struct test_options *opts, char *model) info.out_size = opts->total_len * INFLATION_RATIO; else info.out_size = opts->total_len * EXPANSION_RATIO; - /* - * If fd_ilist exists, it's inflation. - * Make sure block inflation has enough room. - */ - if (opts->fd_ilist >= 0) { - ret = fstat(opts->fd_ilist, &statbuf); - if (!ret) { - div = statbuf.st_size / sizeof(chunk_list_t); - info.in_chunk_sz = (info.in_size + div - 1) / - div; - info.out_chunk_sz = (info.out_size + div - 1) / - div; - } - } } info.in_buf = mmap_alloc(info.in_size); if (!info.in_buf) { @@ -1074,9 +997,6 @@ int test_hw(struct test_options *opts, char *model) ret = load_file_data(&info); if (ret < 0) goto out_buf; - ret = load_ilist(&info, model); - if (ret < 0) - goto out_buf; } else { if (ifl_flag) { thread_data_t *tdata = info.tdatas; @@ -1128,7 +1048,7 @@ int test_hw(struct test_options *opts, char *model) stat_end(&info); info.stats->v[ST_IOPF] = perf_event_put(perf_fds, nr_fds); if (opts->is_file) - store_olist(&info, model); + (void)store_file(&info, model);
usec = info.stats->v[ST_RUN_TIME] / 1000; if (opts->op_type == WD_DIR_DECOMPRESS) @@ -1644,8 +1564,6 @@ int test_comp_entry(int argc, char *argv[]) {"self", no_argument, 0, 0 }, {"in", required_argument, 0, 0 }, {"out", required_argument, 0, 0 }, - {"ilist", required_argument, 0, 0 }, - {"olist", required_argument, 0, 0 }, {"env", no_argument, 0, 0 }, {0, 0, 0, 0 }, }; @@ -1655,8 +1573,6 @@ int test_comp_entry(int argc, char *argv[])
opts.fd_in = -1; opts.fd_out = -1; - opts.fd_ilist = -1; - opts.fd_olist = -1; opts.alg_type = WD_COMP_ALG_MAX; while ((opt = getopt_long(argc, argv, COMMON_OPTSTRING "f:o:w:k:r:", long_options, &option_idx)) != -1) { @@ -1705,48 +1621,7 @@ int test_comp_entry(int argc, char *argv[]) show_help = 1; } break; - case 3: /* ilist */ - if (!optarg) { - COMP_TST_PRT("IN list file is missing!\n"); - show_help = 1; - break; - } - opts.fd_ilist = open(optarg, O_RDONLY); - if (opts.fd_ilist < 0) { - COMP_TST_PRT("Fail to open %s\n", optarg); - show_help = 1; - break; - } - opts.is_file = true; - if (lseek(opts.fd_ilist, 0, SEEK_SET) < 0) { - COMP_TST_PRT("Fail on lseek()!\n"); - show_help = 1; - break; - } - break; - case 4: /* olist */ - if (!optarg) { - COMP_TST_PRT("OUT list file is missing!\n"); - show_help = 1; - break; - } - opts.fd_olist = open(optarg, - O_CREAT | O_WRONLY, - S_IWUSR | S_IRGRP | - S_IROTH); - if (opts.fd_olist < 0) { - COMP_TST_PRT("Fail to open %s\n", optarg); - show_help = 1; - break; - } - opts.is_file = true; - if (lseek(opts.fd_olist, 0, SEEK_SET) < 0) { - COMP_TST_PRT("Fail on lseek()!\n"); - show_help = 1; - break; - } - break; - case 5: /* env */ + case 3: /* env */ opts.use_env = true; break; default:
From: Hao Fang fanghao11@huawei.com
Signed-off-by: Hao Fang fanghao11@huawei.com Signed-off-by: Qi Tao taoqi10@huawei.com --- uadk_tool/test/comp_lib.c | 252 +------------------------------------ uadk_tool/test/comp_lib.h | 33 +---- uadk_tool/test/comp_main.c | 2 - 3 files changed, 3 insertions(+), 284 deletions(-)
diff --git a/uadk_tool/test/comp_lib.c b/uadk_tool/test/comp_lib.c index 5e33d88..50399eb 100644 --- a/uadk_tool/test/comp_lib.c +++ b/uadk_tool/test/comp_lib.c @@ -25,8 +25,6 @@ static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_spinlock_t lock; static int count = 0;
-static struct wd_ctx_config *g_conf; - int sum_pend = 0, sum_thread_end = 0;
__attribute__((constructor)) @@ -71,40 +69,6 @@ int mmap_free(void *addr, size_t len) return munmap(addr, len); }
-static int hizip_check_rand(unsigned char *buf, unsigned int size, void *opaque) -{ - int i; - int *j; - __u32 n; - struct check_rand_ctx *rand_ctx = opaque; - - j = &rand_ctx->off; - for (i = 0; i < size; i += 4) { - if (*j) { - /* Something left from a previous run */ - n = rand_ctx->last; - } else { - n = nrand48(rand_ctx->state); - rand_ctx->last = n; - } - for (; *j < 4 && i + *j < size; (*j)++) { - char expected = (n >> (8 * *j)) & 0xff; - char actual = buf[i + *j]; - - if (expected != actual) { - COMP_TST_PRT("Invalid decompressed char at offset %lu: expected 0x%x != 0x%x\n", - rand_ctx->global_off + i + *j, expected, - actual); - return -EINVAL; - } - } - if (*j == 4) - *j = 0; - } - rand_ctx->global_off += size; - return 0; -} - static struct wd_datalist *get_datalist(void *addr, __u32 size) { int count = (int)ceil((double)size / SGE_SIZE); @@ -382,114 +346,6 @@ int hw_stream_decompress(int alg_type, int blksize, __u8 data_fmt, return ret; }
-void hizip_prepare_random_input_data(char *buf, size_t len, size_t block_size) -{ - __u32 seed = 0; - unsigned short rand_state[3] = {(seed >> 16) & 0xffff, seed & 0xffff, 0x330e}; - - unsigned long remain_size; - __u32 size; - size_t i, j; - - /* - * TODO: change state for each buffer, to make sure there is no TLB - * aliasing. - */ - remain_size = len; - - while (remain_size > 0) { - if (remain_size > block_size) - size = block_size; - else - size = remain_size; - /* - * Prepare the input buffer with a reproducible sequence of - * numbers. nrand48() returns a pseudo-random number in the - * interval [0; 2^31). It's not really possible to compress a - * pseudo-random stream using deflate, since it can't find any - * string repetition. As a result the output size is bigger, - * with a ratio of 1.041. - */ - for (i = 0; i < size; i += 4) { - __u64 n = nrand48(rand_state); - - for (j = 0; j < 4 && i + j < size; j++) - buf[i + j] = (n >> (8 * j)) & 0xff; - } - - buf += size; - remain_size -= size; - } -} - -int hizip_prepare_random_compressed_data(char *buf, size_t out_len, size_t in_len, - size_t *produced, - struct test_options *opts) -{ - off_t off; - int ret = -EINVAL; - void *init_buf = mmap_alloc(in_len); - size_t in_block_size = opts->block_size; - size_t out_block_size = 2 * in_block_size; - - if (!init_buf) - return -ENOMEM; - - hizip_prepare_random_input_data(init_buf, in_len, opts->block_size); - - /* Compress each chunk separately since we're working in stateless mode */ - for (off = 0; off < in_len; off += in_block_size) { - ret = zlib_deflate(buf, out_block_size, init_buf + off, - in_block_size, produced, opts->alg_type); - if (ret) - break; - buf += out_block_size; - } - - munmap(init_buf, in_len); - return ret; -} - -int hizip_verify_random_output(struct test_options *opts, - struct hizip_test_info *info, - size_t out_sz) -{ - int ret; - int seed = 0; - off_t off = 0; - size_t checked = 0; - size_t total_checked = 0; - struct check_rand_ctx rand_ctx = { - .state = {(seed >> 16) & 0xffff, seed & 0xffff, 0x330e}, - }; - - if (!opts->verify) - return 0; - - if (opts->op_type == WD_DIR_DECOMPRESS) - /* Check plain output */ - return hizip_check_rand((void *)info->out_buf, out_sz, - &rand_ctx); - - do { - ret = hizip_check_output(info->out_buf + off, out_sz, - &checked, hizip_check_rand, &rand_ctx); - if (ret) { - COMP_TST_PRT("Check output failed with %d\n", ret); - return ret; - } - total_checked += checked; - off += opts->block_size * EXPANSION_RATIO; - } while (!ret && total_checked < opts->total_len); - - if (rand_ctx.global_off != opts->total_len) { - COMP_TST_PRT("Invalid output size %lu != %lu\n", - rand_ctx.global_off, opts->total_len); - return -EINVAL; - } - return 0; -} - static void *async_cb(struct wd_comp_req *req, void *data) { return NULL; @@ -587,7 +443,7 @@ void *send_thread_func(void *arg) return NULL; }
-int lib_poll_func(__u32 pos, __u32 expect, __u32 *count) +static int lib_poll_func(__u32 pos, __u32 expect, __u32 *count) { int ret;
@@ -635,110 +491,6 @@ void *poll_thread_func(void *arg) pthread_exit(NULL); }
-int create_send_threads(struct test_options *opts, - struct hizip_test_info *info, - void *(*send_thread_func)(void *arg)) -{ - pthread_attr_t attr; - thread_data_t *tdatas; - int i, j, num, ret; - - num = opts->thread_num; - info->send_tds = calloc(1, sizeof(pthread_t) * num); - if (!info->send_tds) - return -ENOMEM; - info->send_tnum = num; - tdatas = calloc(1, sizeof(thread_data_t) * num); - if (!tdatas) { - ret = -ENOMEM; - goto out; - } - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); - for (i = 0; i < num; i++) { - tdatas[i].info = info; - ret = pthread_create(&info->send_tds[i], &attr, - send_thread_func, &tdatas[i]); - if (ret < 0) { - COMP_TST_PRT( "Fail to create send thread %d (%d)\n", - i, ret); - goto out_thd; - } - } - pthread_attr_destroy(&attr); - g_conf = &info->ctx_conf; - return 0; -out_thd: - for (j = 0; j < i; j++) - pthread_cancel(info->send_tds[j]); - free(tdatas); -out: - free(info->send_tds); - return ret; -} - -int create_poll_threads(struct hizip_test_info *info, - void *(*poll_thread_func)(void *arg), - int num) -{ - struct test_options *opts = info->opts; - pthread_attr_t attr; - int i, ret; - - if (!opts->sync_mode) - return 0; - info->poll_tds = calloc(1, sizeof(pthread_t) * num); - if (!info->poll_tds) - return -ENOMEM; - info->poll_tnum = num; - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); - for (i = 0; i < num; i++) { - ret = pthread_create(&info->poll_tds[i], &attr, - poll_thread_func, info); - if (ret < 0) { - COMP_TST_PRT( "Fail to create send thread %d (%d)\n", - i, ret); - goto out; - } - } - pthread_attr_destroy(&attr); - count = 0; - return 0; -out: - free(info->poll_tds); - return ret; -} - -void free_threads(struct hizip_test_info *info) -{ - if (info->send_tds) - free(info->send_tds); - if (info->poll_tds) - free(info->poll_tds); -} - -int attach_threads(struct test_options *opts, struct hizip_test_info *info) -{ - int i, ret; - void *tret; - - if (opts->sync_mode) { - for (i = 0; i < info->poll_tnum; i++) { - ret = pthread_join(info->poll_tds[i], NULL); - if (ret < 0) - COMP_TST_PRT( "Fail on poll thread with %d\n", - ret); - } - } - for (i = 0; i < info->send_tnum; i++) { - ret = pthread_join(info->send_tds[i], &tret); - if (ret < 0) - COMP_TST_PRT( "Fail on send thread with %d\n", ret); - } - return (int)(uintptr_t)tret; -} - void gen_random_data(void *buf, size_t len) { int i; @@ -761,7 +513,7 @@ int calculate_md5(comp_md5_t *md5, const void *buf, size_t len) return 0; }
-void dump_md5(comp_md5_t *md5) +static void dump_md5(comp_md5_t *md5) { int i;
diff --git a/uadk_tool/test/comp_lib.h b/uadk_tool/test/comp_lib.h index 6b6a9f4..447707f 100644 --- a/uadk_tool/test/comp_lib.h +++ b/uadk_tool/test/comp_lib.h @@ -193,20 +193,9 @@ extern int sum_pend, sum_thread_end;
void *send_thread_func(void *arg); void *poll_thread_func(void *arg); -void *sw_dfl_sw_ifl(void *arg); -int create_send_threads(struct test_options *opts, - struct hizip_test_info *info, - void *(*send_thread_func)(void *arg)); -int create_poll_threads(struct hizip_test_info *info, - void *(*poll_thread_func)(void *arg), - int num); -void free_threads(struct hizip_test_info *info); -int attach_threads(struct test_options *opts, - struct hizip_test_info *info);
void gen_random_data(void *buf, size_t len); int calculate_md5(comp_md5_t *md5, const void *buf, size_t len); -void dump_md5(comp_md5_t *md5); int cmp_md5(comp_md5_t *orig, comp_md5_t *final); void init_chunk_list(chunk_list_t *list, void *buf, size_t buf_sz, size_t chunk_sz); @@ -247,8 +236,7 @@ int attach2_threads(struct test_options *opts, void *(*send_thread_func)(void *arg), void *(*poll_thread_func)(void *arg)); void *poll2_thread_func(void *arg); -int run_self_test(struct test_options *opts); -int run_cmd(struct test_options *opts); + int init_ctx_config(struct test_options *opts, void *priv, struct wd_sched **sched @@ -256,19 +244,9 @@ int init_ctx_config(struct test_options *opts, void uninit_config(void *priv, struct wd_sched *sched); struct uacce_dev_list *get_dev_list(struct test_options *opts, int children);
-void hizip_prepare_random_input_data(char *buf, size_t len, size_t block_size); -int hizip_prepare_random_compressed_data(char *buf, size_t out_len, - size_t in_len, size_t *produced, - struct test_options *opts); - -int hizip_verify_random_output(struct test_options *opts, - struct hizip_test_info *info, - size_t out_sz); - void *mmap_alloc(size_t len); int mmap_free(void *addr, size_t len);
-int lib_poll_func(__u32 pos, __u32 expect, __u32 *count); typedef int (*check_output_fn)(unsigned char *buf, unsigned int size, void *opaque);
/* for block interface */ @@ -317,15 +295,6 @@ static inline int zlib_deflate(void *output, unsigned int out_size, void *input, } #endif
-static inline void hizip_test_adjust_len(struct test_options *opts) -{ - /* - * Align size to the next block. We allow non-power-of-two block sizes. - */ - opts->total_len = (opts->total_len + opts->block_size - 1) / - opts->block_size * opts->block_size; -} - #define COMMON_OPTSTRING "hb:q:l:Ss:Vzt:m:dacLZ"
#define COMMON_HELP "%s [opts]\n" \ diff --git a/uadk_tool/test/comp_main.c b/uadk_tool/test/comp_main.c index 872d4de..241a188 100644 --- a/uadk_tool/test/comp_main.c +++ b/uadk_tool/test/comp_main.c @@ -1693,8 +1693,6 @@ int test_comp_entry(int argc, char *argv[]) return run_cmd(&opts); }
- hizip_test_adjust_len(&opts); - SYS_ERR_COND(show_help || optind > argc, COMMON_HELP " -f <format> output format for the statistics\n"
From: Hao Fang fanghao11@huawei.com
hw_blk_compress/hw_stream_compress can do the double direction compress.
Signed-off-by: Hao Fang fanghao11@huawei.com Signed-off-by: Qi Tao taoqi10@huawei.com --- uadk_tool/test/comp_lib.c | 169 ++++++------------------------------- uadk_tool/test/comp_lib.h | 14 +-- uadk_tool/test/comp_main.c | 64 ++++++-------- 3 files changed, 52 insertions(+), 195 deletions(-)
diff --git a/uadk_tool/test/comp_lib.c b/uadk_tool/test/comp_lib.c index 50399eb..6f45d07 100644 --- a/uadk_tool/test/comp_lib.c +++ b/uadk_tool/test/comp_lib.c @@ -99,12 +99,9 @@ static struct wd_datalist *get_datalist(void *addr, __u32 size) }
/** - * compress() - compress memory buffer. - * @alg_type: alg_type. - * - * This function compress memory buffer. + * hw_blk_compress() - compress memory buffer. */ -int hw_blk_compress(int alg_type, int blksize, __u8 data_fmt, void *priv, +int hw_blk_compress(struct test_options *opts, void *priv, unsigned char *dst, __u32 *dstlen, unsigned char *src, __u32 srclen) { @@ -112,11 +109,11 @@ int hw_blk_compress(int alg_type, int blksize, __u8 data_fmt, void *priv, struct wd_comp_sess_setup setup; struct sched_params param = {0}; struct wd_datalist *list; - struct wd_comp_req req; + struct wd_comp_req req = {0}; int ret = 0;
- setup.alg_type = alg_type; - setup.op_type = WD_DIR_COMPRESS; + setup.alg_type = opts->alg_type; + setup.op_type = opts->op_type; setup.comp_lv = WD_COMP_L8; setup.win_sz = WD_COMP_WS_8K; param.type = setup.op_type; @@ -128,8 +125,8 @@ int hw_blk_compress(int alg_type, int blksize, __u8 data_fmt, void *priv, return -EINVAL; }
- if (data_fmt) { - COMP_TST_PRT("now sge size is %u\n", SGE_SIZE); + if (opts->data_fmt) { + COMP_TST_PRT("now sge size is %d\n", SGE_SIZE); list = get_datalist(src, (__u32)srclen); req.list_src = list; list = get_datalist(dst, (__u32)*dstlen); @@ -141,94 +138,29 @@ int hw_blk_compress(int alg_type, int blksize, __u8 data_fmt, void *priv,
req.src_len = srclen; req.dst_len = *dstlen; - req.op_type = WD_DIR_COMPRESS; + req.op_type = opts->op_type; req.cb = NULL; - req.data_fmt = data_fmt; + req.data_fmt = opts->data_fmt; req.priv = priv;
- dbg("%s:input req: src_len: %d, dst_len:%d, data_fmt:%d\n", - __func__, req.src_len, req.dst_len, req.data_fmt); - - ret = wd_do_comp_sync(h_sess, &req); - if (ret < 0) { - COMP_TST_PRT("fail to do comp sync(ret = %d)!\n", ret); - return ret; - } - - if (req.status) { - COMP_TST_PRT("fail to do comp sync(status = %d)!\n", - req.status); - wd_comp_free_sess(h_sess); - return req.status; - } - *dstlen = req.dst_len; - - dbg("%s:input req: src_len: %d, dst_len:%d, data_fmt:%d\n", - __func__, req.src_len, req.dst_len, req.data_fmt); - - wd_comp_free_sess(h_sess); - - return ret; -} - -int hw_blk_decompress(int alg_type, int blksize, __u8 data_fmt, - unsigned char *dst, __u32 *dstlen, - unsigned char *src, __u32 srclen) -{ - handle_t h_sess; - struct wd_comp_sess_setup setup; - struct sched_params param = {0}; - struct wd_datalist *list; - struct wd_comp_req req; - int ret = 0; - - setup.alg_type = alg_type; - setup.op_type = WD_DIR_DECOMPRESS; - param.type = setup.op_type; - param.numa_id = 0; - setup.sched_param = ¶m; - h_sess = wd_comp_alloc_sess(&setup); - if (!h_sess) { - COMP_TST_PRT("fail to alloc comp sess!\n"); - return -EINVAL; - } - - if (data_fmt) { - COMP_TST_PRT("now sge size is %u\n", SGE_SIZE); - list = get_datalist(src, (__u32)srclen); - req.list_src = list; - list = get_datalist(dst, (__u32)*dstlen); - req.list_dst = list; - } else { - req.src = src; - req.dst = dst; - } - - req.src_len = srclen; - req.dst_len = *dstlen; - req.op_type = WD_DIR_DECOMPRESS; - req.cb = NULL; - req.data_fmt = data_fmt; - - dbg("%s:input req: src:%p, dst:%p,src_len: %d, dst_len:%d\n", + dbg("%s:input req: src:%p, dst:%p, src_len: %u, dst_len:%u\n", __func__, req.src, req.dst, req.src_len, req.dst_len);
- ret = wd_do_comp_sync(h_sess, &req); if (ret < 0) { COMP_TST_PRT("fail to do comp sync(ret = %d)!\n", ret); + wd_comp_free_sess(h_sess); return ret; } - if (req.status) { - COMP_TST_PRT("fail to do comp sync(status = %d)!\n", + COMP_TST_PRT("fail to do comp sync(status = %u)!\n", req.status); wd_comp_free_sess(h_sess); return req.status; } *dstlen = req.dst_len;
- dbg("%s:output req: src:%p, dst:%p,src_len: %d, dst_len:%d\n", + dbg("%s:output req: src:%p, dst:%p,src_len: %u, dst_len:%u\n", __func__, req.src, req.dst, req.src_len, req.dst_len);
wd_comp_free_sess(h_sess); @@ -236,18 +168,21 @@ int hw_blk_decompress(int alg_type, int blksize, __u8 data_fmt, return ret; }
-int hw_stream_compress(int alg_type, int blksize, __u8 data_fmt, +/** + * hw_stream_compress() - compress memory buffer. + */ +int hw_stream_compress(struct test_options *opts, unsigned char *dst, __u32 *dstlen, unsigned char *src, __u32 srclen) { handle_t h_sess; struct wd_comp_sess_setup setup; struct sched_params param = {0}; - struct wd_comp_req req; + struct wd_comp_req req = {0}; int ret = 0;
- setup.alg_type = alg_type; - setup.op_type = WD_DIR_COMPRESS; + setup.alg_type = opts->alg_type; + setup.op_type = opts->op_type; setup.comp_lv = WD_COMP_L8; setup.win_sz = WD_COMP_WS_8K; param.type = setup.op_type; @@ -262,83 +197,29 @@ int hw_stream_compress(int alg_type, int blksize, __u8 data_fmt, req.src_len = srclen; req.dst = dst; req.dst_len = *dstlen; - req.op_type = WD_DIR_COMPRESS; + req.op_type = opts->op_type; req.cb = NULL; - req.data_fmt = data_fmt; + req.data_fmt = opts->data_fmt;
- dbg("%s:input req: src:%p, dst:%p,src_len: %d, dst_len:%d\n", + dbg("%s:input req: src:%p, dst:%p, src_len: %u, dst_len:%u\n", __func__, req.src, req.dst, req.src_len, req.dst_len);
ret = wd_do_comp_sync2(h_sess, &req); if (ret < 0) { COMP_TST_PRT("fail to do comp sync(ret = %d)!\n", ret); - return ret; - } - - if (req.status) { - COMP_TST_PRT("fail to do comp sync(status = %d)!\n", - req.status); wd_comp_free_sess(h_sess); - return req.status; - } - *dstlen = req.dst_len; - - dbg("%s:output req: src:%p, dst:%p,src_len: %d, dst_len:%d\n", - __func__, req.src, req.dst, req.src_len, req.dst_len); - - wd_comp_free_sess(h_sess); - - return ret; -} - -int hw_stream_decompress(int alg_type, int blksize, __u8 data_fmt, - unsigned char *dst, __u32 *dstlen, - unsigned char *src, __u32 srclen) -{ - handle_t h_sess; - struct wd_comp_sess_setup setup; - struct sched_params param = {0}; - struct wd_comp_req req; - int ret = 0; - - - setup.alg_type = alg_type; - setup.op_type = WD_DIR_DECOMPRESS; - param.type = setup.op_type; - param.numa_id = 0; - setup.sched_param = ¶m; - h_sess = wd_comp_alloc_sess(&setup); - if (!h_sess) { - COMP_TST_PRT("fail to alloc comp sess!\n"); - return -EINVAL; - } - req.src = src; - req.src_len = srclen; - req.dst = dst; - req.dst_len = *dstlen; - req.op_type = WD_DIR_DECOMPRESS; - req.cb = NULL; - req.data_fmt = data_fmt; - - dbg("%s:input req: src:%p, dst:%p,src_len: %d, dst_len:%d\n", - __func__, req.src, req.dst, req.src_len, req.dst_len); - - - ret = wd_do_comp_sync2(h_sess, &req); - if (ret < 0) { - COMP_TST_PRT("fail to do comp sync(ret = %d)!\n", ret); return ret; }
if (req.status) { - COMP_TST_PRT("fail to do comp sync(status = %d)!\n", + COMP_TST_PRT("fail to do comp sync(status = %u)!\n", req.status); wd_comp_free_sess(h_sess); return req.status; } *dstlen = req.dst_len;
- dbg("%s:output req: src:%p, dst:%p,src_len: %d, dst_len:%d\n", + dbg("%s:output req: src:%p, dst:%p,src_len: %u, dst_len:%u\n", __func__, req.src, req.dst, req.src_len, req.dst_len);
wd_comp_free_sess(h_sess); diff --git a/uadk_tool/test/comp_lib.h b/uadk_tool/test/comp_lib.h index 447707f..cc6054e 100644 --- a/uadk_tool/test/comp_lib.h +++ b/uadk_tool/test/comp_lib.h @@ -249,24 +249,16 @@ int mmap_free(void *addr, size_t len);
typedef int (*check_output_fn)(unsigned char *buf, unsigned int size, void *opaque);
-/* for block interface */ -int hw_blk_compress(int alg_type, int blksize, __u8 data_fmt, void *priv, +/* for block memory interface */ +int hw_blk_compress(struct test_options *opts, void *priv, unsigned char *dst, __u32 *dstlen, unsigned char *src, __u32 srclen);
-int hw_blk_decompress(int alg_type, int blksize, __u8 data_fmt, - unsigned char *dst, __u32 *dstlen, - unsigned char *src, __u32 srclen); - /* for stream memory interface */ -int hw_stream_compress(int alg_type, int blksize, __u8 data_fmt, +int hw_stream_compress(struct test_options *opts, unsigned char *dst, __u32 *dstlen, unsigned char *src, __u32 srclen);
-int hw_stream_decompress(int alg_type, int blksize, __u8 data_fmt, - unsigned char *dst, __u32 *dstlen, - unsigned char *src, __u32 srclen); - #ifdef USE_ZLIB int hizip_check_output(void *buf, size_t size, size_t *checked, check_output_fn check_output, void *opaque); diff --git a/uadk_tool/test/comp_main.c b/uadk_tool/test/comp_main.c index 241a188..6446591 100644 --- a/uadk_tool/test/comp_main.c +++ b/uadk_tool/test/comp_main.c @@ -124,13 +124,11 @@ static void *sw_dfl_hw_ifl(void *arg) goto out_strm; } tout_sz = tdata->dst_sz; - ret = hw_stream_decompress(opts->alg_type, - opts->block_size, - opts->data_fmt, - tdata->dst, - &tout_sz, - tlist->addr, - tlist->size); + ret = hw_stream_compress(opts, + tdata->dst, + &tout_sz, + tlist->addr, + tlist->size); if (ret) { COMP_TST_PRT("Fail to inflate by HW: %d\n", ret); goto out_strm; @@ -265,9 +263,7 @@ static void *hw_dfl_sw_ifl(void *arg) init_chunk_list(tdata->out_list, tdata->dst, tdata->dst_sz, tdata->dst_sz); tmp_sz = tbuf_sz; - ret = hw_stream_compress(opts->alg_type, - opts->block_size, - opts->data_fmt, + ret = hw_stream_compress(opts, tlist->addr, &tmp_sz, tdata->src, @@ -399,9 +395,7 @@ static void *hw_dfl_hw_ifl(void *arg) if (opts->is_stream) { for (i = 0; i < opts->compact_run_num; i++) { tmp_sz = tbuf_sz; - ret = hw_stream_compress(opts->alg_type, - opts->block_size, - opts->data_fmt, + ret = hw_stream_compress(opts, tbuf, &tmp_sz, tdata->src, @@ -411,13 +405,11 @@ static void *hw_dfl_hw_ifl(void *arg) goto out; } tout_sz = tdata->dst_sz; - ret = hw_stream_decompress(opts->alg_type, - opts->block_size, - opts->data_fmt, - tdata->dst, - &tout_sz, - tbuf, - tmp_sz); + ret = hw_stream_compress(opts, + tdata->dst, + &tout_sz, + tbuf, + tmp_sz); if (ret) { COMP_TST_PRT("Fail to inflate by HW: %d\n", ret); goto out; @@ -539,9 +531,7 @@ static void *hw_dfl_perf(void *arg) if (opts->is_stream) { for (i = 0; i < opts->compact_run_num; i++) { tout_sz = tdata->dst_sz; - ret = hw_stream_compress(opts->alg_type, - opts->block_size, - opts->data_fmt, + ret = hw_stream_compress(opts, tdata->dst, &tout_sz, tdata->src, @@ -600,13 +590,11 @@ static void *hw_ifl_perf(void *arg) if (opts->is_stream) { for (i = 0; i < opts->compact_run_num; i++) { tout_sz = tdata->dst_sz; - ret = hw_stream_decompress(opts->alg_type, - opts->block_size, - opts->data_fmt, - tdata->dst, - &tout_sz, - tdata->in_list->addr, - tdata->in_list->size); + ret = hw_stream_compress(opts, + tdata->dst, + &tout_sz, + tdata->in_list->addr, + tdata->in_list->size); if (ret) { COMP_TST_PRT("Fail to inflate by HW: %d\n", ret); return (void *)(uintptr_t)ret; @@ -662,9 +650,7 @@ void *hw_dfl_perf3(void *arg) if (opts->is_stream) { for (i = 0; i < opts->compact_run_num; i++) { tout_sz = tdata->dst_sz; - ret = hw_stream_compress(opts->alg_type, - opts->block_size, - opts->data_fmt, + ret = hw_stream_compress(opts, tdata->dst, &tout_sz, tdata->src, @@ -724,13 +710,11 @@ void *hw_ifl_perf3(void *arg) if (opts->is_stream) { for (i = 0; i < opts->compact_run_num; i++) { tout_sz = tdata->dst_sz; - ret = hw_stream_decompress(opts->alg_type, - opts->block_size, - opts->data_fmt, - tdata->dst, - &tout_sz, - tdata->src, - tdata->src_sz); + ret = hw_stream_compress(opts, + tdata->dst, + &tout_sz, + tdata->src, + tdata->src_sz); if (ret) { COMP_TST_PRT("Fail to inflate by HW: %d\n", ret); return (void *)(uintptr_t)ret;
From: Hao Fang fanghao11@huawei.com
Remove the poll_thread_func() and rename poll2_thread_func() as the poll_thread_func().
Signed-off-by: Hao Fang fanghao11@huawei.com Signed-off-by: Qi Tao taoqi10@huawei.com --- uadk_tool/test/comp_lib.c | 44 ++++---------------------------------- uadk_tool/test/comp_lib.h | 1 - uadk_tool/test/comp_main.c | 6 +++--- 3 files changed, 7 insertions(+), 44 deletions(-)
diff --git a/uadk_tool/test/comp_lib.c b/uadk_tool/test/comp_lib.c index 6f45d07..f4711ac 100644 --- a/uadk_tool/test/comp_lib.c +++ b/uadk_tool/test/comp_lib.c @@ -21,7 +21,6 @@ struct check_rand_ctx { unsigned short state[3]; };
-static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_spinlock_t lock; static int count = 0;
@@ -334,44 +333,6 @@ static int lib_poll_func(__u32 pos, __u32 expect, __u32 *count) return 0; }
-void *poll_thread_func(void *arg) -{ - struct hizip_test_info *info = (struct hizip_test_info *)arg; - int ret = 0, total = 0; - __u32 expected = 0, received; - - if (!info->opts->sync_mode) - return NULL; - while (1) { - if (info->opts->faults & INJECT_SIG_WORK) - kill(getpid(), SIGTERM); - - pthread_mutex_lock(&mutex); - if (!expected) - expected = 1; - if (count == 0) { - pthread_mutex_unlock(&mutex); - usleep(10); - continue; - } - expected = 1; - received = 0; - ret = wd_comp_poll(expected, &received); - if (ret == 0) - total += received; - if (count == total) { - pthread_mutex_unlock(&mutex); - break; - } else { - if (count > total) - expected = count - total; - pthread_mutex_unlock(&mutex); - usleep(10); - } - } - pthread_exit(NULL); -} - void gen_random_data(void *buf, size_t len) { int i; @@ -1088,7 +1049,7 @@ out: return ret; }
-void *poll2_thread_func(void *arg) +void *poll_thread_func(void *arg) { thread_data_t *tdata = (thread_data_t *)arg; struct hizip_test_info *info = tdata->info; @@ -1100,6 +1061,9 @@ void *poll2_thread_func(void *arg)
gettimeofday(&start_tvl, NULL); while (1) { + if (info->opts->faults & INJECT_SIG_WORK) + kill(getpid(), SIGTERM); + end_threads = __atomic_load_n(&sum_thread_end, __ATOMIC_ACQUIRE); pending = __atomic_load_n(&sum_pend, __ATOMIC_ACQUIRE); diff --git a/uadk_tool/test/comp_lib.h b/uadk_tool/test/comp_lib.h index cc6054e..67e9079 100644 --- a/uadk_tool/test/comp_lib.h +++ b/uadk_tool/test/comp_lib.h @@ -235,7 +235,6 @@ int attach2_threads(struct test_options *opts, struct hizip_test_info *info, void *(*send_thread_func)(void *arg), void *(*poll_thread_func)(void *arg)); -void *poll2_thread_func(void *arg);
int init_ctx_config(struct test_options *opts, void *priv, diff --git a/uadk_tool/test/comp_main.c b/uadk_tool/test/comp_main.c index 6446591..02a5d5e 100644 --- a/uadk_tool/test/comp_main.c +++ b/uadk_tool/test/comp_main.c @@ -537,7 +537,7 @@ static void *hw_dfl_perf(void *arg) tdata->src, tdata->src_sz); if (ret) { - COMP_TST_PRT("Fail to deflate by HW: %d\n", ret); + COMP_TST_PRT("Fail to deflate by HW(stm): %d\n", ret); return (void *)(uintptr_t)ret; } } @@ -563,7 +563,7 @@ static void *hw_dfl_perf(void *arg) ret = hw_deflate4(h_dfl, tdata->in_list, tdata->out_list, opts, &tdata->sem); if (ret) { - COMP_TST_PRT("Fail to deflate by HW: %d\n", ret); + COMP_TST_PRT("Fail to deflate by HW(blk): %d\n", ret); goto out; } } @@ -1026,7 +1026,7 @@ int test_hw(struct test_options *opts, char *model) COMP_TST_PRT( "NOTE: test might trash the TLB\n"); } stat_start(&info); - ret = attach2_threads(opts, &info, func, poll2_thread_func); + ret = attach2_threads(opts, &info, func, poll_thread_func); if (ret) goto out_buf; stat_end(&info);
From: Hao Fang fanghao11@huawei.com
The devil numbers in function name is hard to read.
Signed-off-by: Hao Fang fanghao11@huawei.com Signed-off-by: Qi Tao taoqi10@huawei.com --- uadk_tool/test/comp_lib.c | 30 +++++++++++++++++++----------- uadk_tool/test/comp_lib.h | 14 ++++++++------ uadk_tool/test/comp_main.c | 28 ++++++++++++++-------------- 3 files changed, 41 insertions(+), 31 deletions(-)
diff --git a/uadk_tool/test/comp_lib.c b/uadk_tool/test/comp_lib.c index f4711ac..9a8a39d 100644 --- a/uadk_tool/test/comp_lib.c +++ b/uadk_tool/test/comp_lib.c @@ -454,7 +454,7 @@ void free_chunk_list(chunk_list_t *list) /* * Deflate a data block with compressed header. */ -static int chunk_deflate2(void *in, size_t in_sz, void *out, size_t *out_sz, +static int chunk_deflate(void *in, size_t in_sz, void *out, size_t *out_sz, struct test_options *opts) { int alg_type = opts->alg_type; @@ -516,7 +516,7 @@ static int chunk_deflate2(void *in, size_t in_sz, void *out, size_t *out_sz, * This function is used in BLOCK mode. Each compressing in BLOCK mode * produces compression header. */ -static int chunk_inflate2(void *in, size_t in_sz, void *out, size_t *out_sz, +static int chunk_inflate(void *in, size_t in_sz, void *out, size_t *out_sz, struct test_options *opts) { z_stream strm; @@ -560,7 +560,7 @@ out: * Compress a list of chunk data and produce a list of chunk data by software. * in_list & out_list should be formated first. */ -int sw_deflate2(chunk_list_t *in_list, +int sw_deflate(chunk_list_t *in_list, chunk_list_t *out_list, struct test_options *opts) { @@ -568,7 +568,7 @@ int sw_deflate2(chunk_list_t *in_list, int ret = -EINVAL;
for (p = in_list, q = out_list; p && q; p = p->next, q = q->next) { - ret = chunk_deflate2(p->addr, p->size, q->addr, &q->size, + ret = chunk_deflate(p->addr, p->size, q->addr, &q->size, opts); if (ret) return ret; @@ -577,17 +577,17 @@ int sw_deflate2(chunk_list_t *in_list, }
/* - * Compress a list of chunk data and produce a list of chunk data by software. + * Deompress a list of chunk data and produce a list of chunk data by software. * in_list & out_list should be formated first. */ -int sw_inflate2(chunk_list_t *in_list, chunk_list_t *out_list, +int sw_inflate(chunk_list_t *in_list, chunk_list_t *out_list, struct test_options *opts) { chunk_list_t *p, *q; int ret = -EINVAL;
for (p = in_list, q = out_list; p && q; p = p->next, q = q->next) { - ret = chunk_inflate2(p->addr, p->size, q->addr, &q->size, + ret = chunk_inflate(p->addr, p->size, q->addr, &q->size, opts); if (ret) return ret; @@ -595,7 +595,11 @@ int sw_inflate2(chunk_list_t *in_list, chunk_list_t *out_list, return ret; }
-int hw_deflate4(handle_t h_dfl, +/* + * Compress a list of chunk data and produce a list of chunk data by hardware. + * in_list & out_list should be formated first. + */ +int hw_deflate(handle_t h_dfl, chunk_list_t *in_list, chunk_list_t *out_list, struct test_options *opts, @@ -649,7 +653,11 @@ out: return ret; }
-int hw_inflate4(handle_t h_ifl, +/* + * Decompress a list of chunk data and produce a list of chunk data by hardware. + * in_list & out_list should be formated first. + */ +int hw_inflate(handle_t h_ifl, chunk_list_t *in_list, chunk_list_t *out_list, struct test_options *opts, @@ -966,7 +974,7 @@ out: * Free source and destination buffer contained in sending threads. * Free sending threads and polling threads. */ -void free2_threads(struct hizip_test_info *info) +void free_threads_tdata(struct hizip_test_info *info) { thread_data_t *tdatas = info->tdatas; int i; @@ -989,7 +997,7 @@ void free2_threads(struct hizip_test_info *info) mmap_free(info->in_buf, info->in_size); }
-int attach2_threads(struct test_options *opts, +int attach_threads(struct test_options *opts, struct hizip_test_info *info, void *(*send_thread_func)(void *arg), void *(*poll_thread_func)(void *arg)) diff --git a/uadk_tool/test/comp_lib.h b/uadk_tool/test/comp_lib.h index 67e9079..cd16b1d 100644 --- a/uadk_tool/test/comp_lib.h +++ b/uadk_tool/test/comp_lib.h @@ -197,26 +197,28 @@ void *poll_thread_func(void *arg); void gen_random_data(void *buf, size_t len); int calculate_md5(comp_md5_t *md5, const void *buf, size_t len); int cmp_md5(comp_md5_t *orig, comp_md5_t *final); + void init_chunk_list(chunk_list_t *list, void *buf, size_t buf_sz, size_t chunk_sz); chunk_list_t *create_chunk_list(void *buf, size_t buf_sz, size_t chunk_sz); void free_chunk_list(chunk_list_t *list); -int sw_deflate2(chunk_list_t *in_list, +int sw_deflate(chunk_list_t *in_list, chunk_list_t *out_list, struct test_options *opts); -int sw_inflate2(chunk_list_t *in_list, +int sw_inflate(chunk_list_t *in_list, chunk_list_t *out_list, struct test_options *opts); -int hw_deflate4(handle_t h_dfl, +int hw_deflate(handle_t h_dfl, chunk_list_t *in_list, chunk_list_t *out_list, struct test_options *opts, sem_t *sem); -int hw_inflate4(handle_t h_ifl, +int hw_inflate(handle_t h_ifl, chunk_list_t *in_list, chunk_list_t *out_list, struct test_options *opts, sem_t *sem); + int hw_deflate5(handle_t h_dfl, chunk_list_t *in_list, chunk_list_t *out_list, @@ -230,8 +232,8 @@ int create_send_tdata(struct test_options *opts, int create_poll_tdata(struct test_options *opts, struct hizip_test_info *info, int poll_num); -void free2_threads(struct hizip_test_info *info); -int attach2_threads(struct test_options *opts, +void free_threads_tdata(struct hizip_test_info *info); +int attach_threads(struct test_options *opts, struct hizip_test_info *info, void *(*send_thread_func)(void *arg), void *(*poll_thread_func)(void *arg)); diff --git a/uadk_tool/test/comp_main.c b/uadk_tool/test/comp_main.c index 02a5d5e..21fb920 100644 --- a/uadk_tool/test/comp_main.c +++ b/uadk_tool/test/comp_main.c @@ -118,7 +118,7 @@ static void *sw_dfl_hw_ifl(void *arg) init_chunk_list(tlist, tbuf, tbuf_sz, tbuf_sz); init_chunk_list(tdata->out_list, tdata->dst, tdata->dst_sz, tdata->dst_sz); - ret = sw_deflate2(tdata->in_list, tlist, opts); + ret = sw_deflate(tdata->in_list, tlist, opts); if (ret) { COMP_TST_PRT("Fail to deflate by zlib: %d\n", ret); goto out_strm; @@ -177,12 +177,12 @@ static void *sw_dfl_hw_ifl(void *arg) info->in_chunk_sz * EXPANSION_RATIO); init_chunk_list(tdata->out_list, tdata->dst, tdata->dst_sz, info->out_chunk_sz); - ret = sw_deflate2(tdata->in_list, tlist, opts); + ret = sw_deflate(tdata->in_list, tlist, opts); if (ret) { COMP_TST_PRT("Fail to deflate by zlib: %d\n", ret); goto out_run; } - ret = hw_inflate4(h_ifl, tlist, tdata->out_list, opts, + ret = hw_inflate(h_ifl, tlist, tdata->out_list, opts, &tdata->sem); if (ret) { COMP_TST_PRT("Fail to inflate by HW: %d\n", ret); @@ -273,7 +273,7 @@ static void *hw_dfl_sw_ifl(void *arg) goto out_strm; } tlist->size = tmp_sz; // write back - ret = sw_inflate2(tlist, tdata->out_list, opts); + ret = sw_inflate(tlist, tdata->out_list, opts); if (ret) { COMP_TST_PRT("Fail to inflate by zlib: %d\n", ret); goto out_strm; @@ -321,13 +321,13 @@ static void *hw_dfl_sw_ifl(void *arg) opts->block_size * EXPANSION_RATIO); init_chunk_list(tdata->out_list, tdata->dst, tdata->dst_sz, info->out_chunk_sz); - ret = hw_deflate4(h_dfl, tdata->in_list, tlist, opts, + ret = hw_deflate(h_dfl, tdata->in_list, tlist, opts, &tdata->sem); if (ret) { COMP_TST_PRT("Fail to deflate by HW: %d\n", ret); goto out_run; } - ret = sw_inflate2(tlist, tdata->out_list, opts); + ret = sw_inflate(tlist, tdata->out_list, opts); if (ret) { COMP_TST_PRT("Fail to inflate by zlib: %d\n", ret); goto out_run; @@ -470,13 +470,13 @@ static void *hw_dfl_hw_ifl(void *arg) init_chunk_list(tdata->out_list, tdata->dst, tdata->dst_sz, info->out_chunk_sz); - ret = hw_deflate4(h_dfl, tdata->in_list, tlist, opts, + ret = hw_deflate(h_dfl, tdata->in_list, tlist, opts, &tdata->sem); if (ret) { COMP_TST_PRT("Fail to deflate by HW: %d\n", ret); goto out_run; } - ret = hw_inflate4(h_ifl, tlist, tdata->out_list, opts, + ret = hw_inflate(h_ifl, tlist, tdata->out_list, opts, &tdata->sem); if (ret) { COMP_TST_PRT("Fail to inflate by HW: %d\n", ret); @@ -560,7 +560,7 @@ static void *hw_dfl_perf(void *arg) init_chunk_list(tdata->out_list, tdata->dst, tdata->dst_sz, info->out_chunk_sz); - ret = hw_deflate4(h_dfl, tdata->in_list, tdata->out_list, opts, + ret = hw_deflate(h_dfl, tdata->in_list, tdata->out_list, opts, &tdata->sem); if (ret) { COMP_TST_PRT("Fail to deflate by HW(blk): %d\n", ret); @@ -619,7 +619,7 @@ static void *hw_ifl_perf(void *arg) init_chunk_list(tdata->out_list, tdata->dst, tdata->dst_sz, info->out_chunk_sz); - ret = hw_inflate4(h_ifl, tdata->in_list, tdata->out_list, opts, + ret = hw_inflate(h_ifl, tdata->in_list, tdata->out_list, opts, &tdata->sem); if (ret) { COMP_TST_PRT("Fail to inflate by HW: %d\n", ret); @@ -996,7 +996,7 @@ int test_hw(struct test_options *opts, char *model) init_chunk_list(tlist, tbuf, tbuf_sz, opts->block_size / EXPANSION_RATIO); gen_random_data(tbuf, tbuf_sz); - ret = sw_deflate2(tlist, tdata[0].in_list, opts); + ret = sw_deflate(tlist, tdata[0].in_list, opts); if (ret) { free_chunk_list(tlist); mmap_free(tbuf, tbuf_sz); @@ -1026,7 +1026,7 @@ int test_hw(struct test_options *opts, char *model) COMP_TST_PRT( "NOTE: test might trash the TLB\n"); } stat_start(&info); - ret = attach2_threads(opts, &info, func, poll_thread_func); + ret = attach_threads(opts, &info, func, poll_thread_func); if (ret) goto out_buf; stat_end(&info); @@ -1059,7 +1059,7 @@ int test_hw(struct test_options *opts, char *model) COMP_TST_PRT("%s in %f usec (BLK:%d, Bnum:%d).\n", zbuf, usec, opts->block_size, opts->batch_num); } - free2_threads(&info); + free_threads_tdata(&info); if (opts->use_env) wd_comp_env_uninit(); else @@ -1068,7 +1068,7 @@ int test_hw(struct test_options *opts, char *model) return 0; out_buf: out_poll: - free2_threads(&info); + free_threads_tdata(&info); if (opts->use_env) wd_comp_env_uninit(); else
From: Hao Fang fanghao11@huawei.com
Signed-off-by: Hao Fang fanghao11@huawei.com Signed-off-by: Qi Tao taoqi10@huawei.com --- uadk_tool/test/comp_lib.c | 147 +----------------------------------- uadk_tool/test/comp_lib.h | 23 ------ uadk_tool/test/comp_main.c | 150 ++----------------------------------- 3 files changed, 6 insertions(+), 314 deletions(-)
diff --git a/uadk_tool/test/comp_lib.c b/uadk_tool/test/comp_lib.c index 9a8a39d..4eee19f 100644 --- a/uadk_tool/test/comp_lib.c +++ b/uadk_tool/test/comp_lib.c @@ -391,24 +391,6 @@ static void *async2_cb(struct wd_comp_req *req, void *data) return NULL; }
-/* used in BATCH mode */ -static void *async5_cb(struct wd_comp_req *req, void *data) -{ - thread_data_t *tdata = (thread_data_t *)data; - - pthread_spin_lock(&lock); - tdata->pcnt++; - if (tdata->batch_flag && (tdata->pcnt == tdata->bcnt)) { - tdata->pcnt = 0; - tdata->bcnt = 0; - tdata->batch_flag = 0; - pthread_spin_unlock(&lock); - sem_post(&tdata->sem); - } else - pthread_spin_unlock(&lock); - return NULL; -} - void init_chunk_list(chunk_list_t *list, void *buf, size_t buf_sz, size_t chunk_sz) { @@ -707,128 +689,6 @@ out: return ret; }
-/* used in BATCH mode */ -int hw_deflate5(handle_t h_dfl, - chunk_list_t *in_list, - chunk_list_t *out_list, - thread_data_t *tdata) -{ - struct hizip_test_info *info = tdata->info; - struct test_options *opts = info->opts; - struct wd_comp_req *reqs = tdata->reqs; - chunk_list_t *p = in_list, *q = out_list; - int i = 0, ret = 0; - - if (!in_list || !out_list || !opts) - return -EINVAL; - for (p = in_list, q = out_list; p && q; p = p->next, q = q->next) { - reqs[i].src = p->addr; - reqs[i].src_len = p->size; - reqs[i].dst = q->addr; - reqs[i].dst_len = q->size; - reqs[i].op_type = WD_DIR_COMPRESS; - reqs[i].data_fmt = opts->data_fmt; - if (opts->sync_mode) { - reqs[i].cb = async5_cb; - reqs[i].cb_param = tdata; - } else { - reqs[i].cb = NULL; - reqs[i].cb_param = NULL; - } - if (opts->sync_mode) { - do { - ret = wd_do_comp_async(h_dfl, &reqs[i]); - } while (ret == -WD_EBUSY); - if (ret < 0) - goto out; - __atomic_add_fetch(&sum_pend, 1, __ATOMIC_ACQ_REL); - pthread_spin_lock(&lock); - tdata->bcnt++; - if (((i + 1) == opts->batch_num) || !p->next) { - tdata->batch_flag = 1; - pthread_spin_unlock(&lock); - sem_wait(&tdata->sem); - } else - pthread_spin_unlock(&lock); - } else { - do { - ret = wd_do_comp_sync(h_dfl, &reqs[i]); - } while (ret == -WD_EBUSY); - if (ret) - goto out; - } - q->size = reqs[i].dst_len; - i = (i + 1) % opts->batch_num; - /* make sure olist has the same length with ilist */ - if (!p->next) - q->next = NULL; - } - return 0; -out: - return ret; -} - -/* used in BATCH mode */ -int hw_inflate5(handle_t h_ifl, - chunk_list_t *in_list, - chunk_list_t *out_list, - thread_data_t *tdata) -{ - struct hizip_test_info *info = tdata->info; - struct test_options *opts = info->opts; - struct wd_comp_req *reqs = tdata->reqs; - chunk_list_t *p = in_list, *q = out_list; - int ret = 0, i = 0; - - if (!in_list || !out_list || !opts) - return -EINVAL; - for (p = in_list, q = out_list; p && q; p = p->next, q = q->next) { - reqs[i].src = p->addr; - reqs[i].src_len = p->size; - reqs[i].dst = q->addr; - reqs[i].dst_len = q->size; - reqs[i].op_type = WD_DIR_DECOMPRESS; - reqs[i].data_fmt = opts->data_fmt; - if (opts->sync_mode) { - reqs[i].cb = async5_cb; - reqs[i].cb_param = tdata; - } else { - reqs[i].cb = NULL; - reqs[i].cb_param = NULL; - } - if (opts->sync_mode) { - do { - ret = wd_do_comp_async(h_ifl, &reqs[i]); - } while (ret == -WD_EBUSY); - if (ret < 0) - goto out; - __atomic_add_fetch(&sum_pend, 1, __ATOMIC_ACQ_REL); - pthread_spin_lock(&lock); - tdata->bcnt++; - if (((i + 1) == opts->batch_num) || !p->next) { - tdata->batch_flag = 1; - pthread_spin_unlock(&lock); - sem_wait(&tdata->sem); - } else - pthread_spin_unlock(&lock); - } else { - do { - ret = wd_do_comp_sync(h_ifl, &reqs[i]); - } while (ret == -WD_EBUSY); - if (ret) - goto out; - } - q->size = reqs[i].dst_len; - i = (i + 1) % opts->batch_num; - /* make sure olist has the same length with ilist */ - if (!p->next) - q->next = NULL; - } - return 0; -out: - return ret; -} - /* * info->in_buf & info->out_buf should be allocated first. * Thread 0 shares info->out_buf. Other threads need to create its own @@ -853,10 +713,6 @@ int create_send_tdata(struct test_options *opts, ret = -ENOMEM; goto out; } - if (!opts->batch_num) - opts->batch_num = 1; - else if (opts->batch_num > HIZIP_CHUNK_LIST_ENTRIES) - opts->batch_num = HIZIP_CHUNK_LIST_ENTRIES; if (opts->is_stream) { in_list = create_chunk_list(info->in_buf, info->in_size, info->in_size); @@ -915,8 +771,7 @@ int create_send_tdata(struct test_options *opts, goto out_list; } calculate_md5(&tdata->md5, tdata->src, tdata->src_sz); - tdata->reqs = malloc(sizeof(struct wd_comp_req) * - opts->batch_num); + tdata->reqs = malloc(sizeof(struct wd_comp_req)); if (!tdata->reqs) goto out_list; sem_init(&tdata->sem, 0, 0); diff --git a/uadk_tool/test/comp_lib.h b/uadk_tool/test/comp_lib.h index cd16b1d..bbd7db0 100644 --- a/uadk_tool/test/comp_lib.h +++ b/uadk_tool/test/comp_lib.h @@ -80,12 +80,6 @@ struct test_options { int poll_num; /* 0: sync mode, 1: async mode */ int sync_mode; - /* - * positive value: the number of messages are sent at a time. - * 0: batch mode is disabled. - * batch mode is only valid for ASYNC operations. - */ - int batch_num; /* input file */ int fd_in; /* output file */ @@ -143,15 +137,6 @@ typedef struct _thread_data_t { size_t dst_sz; size_t sum; /* produced bytes for OUT */ int tid; /* thread ID */ - int bcnt; /* batch mode: count */ - int pcnt; /* batch mode: poll count */ - int flush_bcnt; /* batch mode: flush count that is less batch_num */ - /* - * batch mode: set flag and wait batch end in sending thread. - * Clear batch flag if pcnt == bcnt in polling thread. - * batch_flag could replace flush_bcnt. - */ - int batch_flag; sem_t sem; chunk_list_t *in_list; chunk_list_t *out_list; @@ -219,14 +204,6 @@ int hw_inflate(handle_t h_ifl, struct test_options *opts, sem_t *sem);
-int hw_deflate5(handle_t h_dfl, - chunk_list_t *in_list, - chunk_list_t *out_list, - thread_data_t *tdata); -int hw_inflate5(handle_t h_ifl, - chunk_list_t *in_list, - chunk_list_t *out_list, - thread_data_t *tdata); int create_send_tdata(struct test_options *opts, struct hizip_test_info *info); int create_poll_tdata(struct test_options *opts, diff --git a/uadk_tool/test/comp_main.c b/uadk_tool/test/comp_main.c index 21fb920..aabb8cc 100644 --- a/uadk_tool/test/comp_main.c +++ b/uadk_tool/test/comp_main.c @@ -635,126 +635,6 @@ out: return (void *)(uintptr_t)(ret); }
-/* BATCH mode is used */ -void *hw_dfl_perf3(void *arg) -{ - thread_data_t *tdata = (thread_data_t *)arg; - struct hizip_test_info *info = tdata->info; - struct test_options *opts = info->opts; - struct wd_comp_sess_setup setup = {0}; - struct sched_params param = {0}; - handle_t h_dfl; - int i, ret; - uint32_t tout_sz; - - if (opts->is_stream) { - for (i = 0; i < opts->compact_run_num; i++) { - tout_sz = tdata->dst_sz; - ret = hw_stream_compress(opts, - tdata->dst, - &tout_sz, - tdata->src, - tdata->src_sz); - if (ret) { - COMP_TST_PRT("Fail to deflate by HW: %d\n", ret); - return (void *)(uintptr_t)ret; - } - } - tdata->out_list->addr = tdata->dst; - tdata->out_list->size = tout_sz; - tdata->out_list->next = NULL; - return NULL; - } - - setup.alg_type = opts->alg_type; - setup.op_type = WD_DIR_COMPRESS; - param.type = setup.op_type; - param.numa_id = 0; - setup.sched_param = ¶m; - h_dfl = wd_comp_alloc_sess(&setup); - if (!h_dfl) - return (void *)(uintptr_t)(-EINVAL); - - for (i = 0; i < opts->compact_run_num; i++) { - init_chunk_list(tdata->out_list, tdata->dst, - tdata->dst_sz, - info->out_chunk_sz); - ret = hw_deflate5(h_dfl, tdata->in_list, tdata->out_list, - tdata); - if (ret) { - COMP_TST_PRT("Fail to deflate by HW: %d\n", ret); - goto out; - } - } - wd_comp_free_sess(h_dfl); - /* mark sending thread to end */ - __atomic_add_fetch(&sum_thread_end, 1, __ATOMIC_ACQ_REL); - return NULL; -out: - wd_comp_free_sess(h_dfl); - return (void *)(uintptr_t)(ret); -} - -/* BATCH mode is used */ -void *hw_ifl_perf3(void *arg) -{ - thread_data_t *tdata = (thread_data_t *)arg; - struct hizip_test_info *info = tdata->info; - struct test_options *opts = info->opts; - struct wd_comp_sess_setup setup = {0}; - struct sched_params param = {0}; - handle_t h_ifl; - int i, ret; - uint32_t tout_sz; - - if (opts->is_stream) { - for (i = 0; i < opts->compact_run_num; i++) { - tout_sz = tdata->dst_sz; - ret = hw_stream_compress(opts, - tdata->dst, - &tout_sz, - tdata->src, - tdata->src_sz); - if (ret) { - COMP_TST_PRT("Fail to inflate by HW: %d\n", ret); - return (void *)(uintptr_t)ret; - } - tdata->out_list->addr = tdata->dst; - tdata->out_list->size = tout_sz; - tdata->out_list->next = NULL; - } - return NULL; - } - - setup.alg_type = opts->alg_type; - setup.op_type = WD_DIR_DECOMPRESS; - param.type = setup.op_type; - param.numa_id = 0; - setup.sched_param = ¶m; - h_ifl = wd_comp_alloc_sess(&setup); - if (!h_ifl) - return (void *)(uintptr_t)(-EINVAL); - - for (i = 0; i < opts->compact_run_num; i++) { - init_chunk_list(tdata->out_list, tdata->dst, - tdata->dst_sz, - info->out_chunk_sz); - ret = hw_inflate5(h_ifl, tdata->in_list, tdata->out_list, - tdata); - if (ret) { - COMP_TST_PRT("Fail to inflate by HW: %d\n", ret); - goto out; - } - } - wd_comp_free_sess(h_ifl); - /* mark sending thread to end */ - __atomic_add_fetch(&sum_thread_end, 1, __ATOMIC_ACQ_REL); - return NULL; -out: - wd_comp_free_sess(h_ifl); - return (void *)(uintptr_t)(ret); -} - /* * Load compression/decompression content. */ @@ -903,15 +783,6 @@ int test_hw(struct test_options *opts, char *model) zbuf_idx = sprintf(zbuf, "HW %s %s deflate", opts->sync_mode ? "ASYNC" : "SYNC", opts->is_stream ? "STREAM" : "BLOCK"); - } else if (!strcmp(model, "hw_dfl_perf3")) { - func = hw_dfl_perf3; - info.in_size = opts->total_len; - info.out_size = opts->total_len * EXPANSION_RATIO; - info.in_chunk_sz = opts->block_size; - info.out_chunk_sz = opts->block_size * EXPANSION_RATIO; - zbuf_idx = sprintf(zbuf, "HW %s %s deflate", - opts->sync_mode ? "ASYNC" : "SYNC", - opts->is_stream ? "STREAM" : "BLOCK"); } else if (!strcmp(model, "hw_ifl_perf")) { func = hw_ifl_perf; info.in_size = opts->total_len; @@ -922,16 +793,6 @@ int test_hw(struct test_options *opts, char *model) opts->sync_mode ? "ASYNC" : "SYNC", opts->is_stream ? "STREAM" : "BLOCK"); ifl_flag = 1; - } else if (!strcmp(model, "hw_ifl_perf3")) { - func = hw_ifl_perf3; - info.in_size = opts->total_len * EXPANSION_RATIO; - info.out_size = opts->total_len; - info.in_chunk_sz = opts->block_size; - info.out_chunk_sz = opts->block_size * INFLATION_RATIO; - zbuf_idx = sprintf(zbuf, "HW %s %s inflate", - opts->sync_mode ? "ASYNC" : "SYNC", - opts->is_stream ? "STREAM" : "BLOCK"); - ifl_flag = 1; } else { COMP_TST_PRT("Wrong model is specified:%s\n", model); ret = -EINVAL; @@ -1051,13 +912,12 @@ int test_hw(struct test_options *opts, char *model) " with %d send threads", opts->thread_num); } - if (!strcmp(model, "hw_dfl_perf") || !strcmp(model, "hw_ifl_perf") || - !strcmp(model, "hw_dfl_perf3") || !strcmp(model, "hw_ifl_perf3")) { - COMP_TST_PRT("%s at %.2fMB/s in %f usec (BLK:%d, Bnum:%d).\n", - zbuf, speed, usec, opts->block_size, opts->batch_num); + if (!strcmp(model, "hw_dfl_perf") || !strcmp(model, "hw_ifl_perf")) { + COMP_TST_PRT("%s at %.2fMB/s in %f usec (BLK:%d).\n", + zbuf, speed, usec, opts->block_size); } else { - COMP_TST_PRT("%s in %f usec (BLK:%d, Bnum:%d).\n", - zbuf, usec, opts->block_size, opts->batch_num); + COMP_TST_PRT("%s in %f usec (BLK:%d).\n", + zbuf, usec, opts->block_size); } free_threads_tdata(&info); if (opts->use_env)
From: Hao Fang fanghao11@huawei.com
Remove the redundant send_thread_func(), the kill and zlib test case is still reserved can be added in other function flow.
Signed-off-by: Hao Fang fanghao11@huawei.com Signed-off-by: Qi Tao taoqi10@huawei.com --- uadk_tool/test/comp_lib.c | 114 ++++--------------------------------- uadk_tool/test/comp_main.c | 12 ++++ 2 files changed, 23 insertions(+), 103 deletions(-)
diff --git a/uadk_tool/test/comp_lib.c b/uadk_tool/test/comp_lib.c index 4eee19f..3b47dfa 100644 --- a/uadk_tool/test/comp_lib.c +++ b/uadk_tool/test/comp_lib.c @@ -22,7 +22,6 @@ struct check_rand_ctx { };
static pthread_spinlock_t lock; -static int count = 0;
int sum_pend = 0, sum_thread_end = 0;
@@ -209,13 +208,16 @@ int hw_stream_compress(struct test_options *opts, wd_comp_free_sess(h_sess); return ret; } - if (req.status) { COMP_TST_PRT("fail to do comp sync(status = %u)!\n", req.status); wd_comp_free_sess(h_sess); return req.status; } + + if (opts->faults & INJECT_SIG_WORK) + kill(getpid(), SIGTERM); + *dstlen = req.dst_len;
dbg("%s:output req: src:%p, dst:%p,src_len: %u, dst_len:%u\n", @@ -226,103 +228,6 @@ int hw_stream_compress(struct test_options *opts, return ret; }
-static void *async_cb(struct wd_comp_req *req, void *data) -{ - return NULL; -} - -void *send_thread_func(void *arg) -{ - thread_data_t *tdata = (thread_data_t *)arg; - struct hizip_test_info *info = tdata->info; - struct test_options *opts = info->opts; - size_t src_block_size, dst_block_size; - struct wd_comp_sess_setup setup; - struct sched_params param = {0}; - handle_t h_sess; - int j, ret; - size_t left; - - if (opts->op_type == WD_DIR_COMPRESS) { - src_block_size = opts->block_size; - dst_block_size = opts->block_size * EXPANSION_RATIO; - } else { - src_block_size = opts->block_size * EXPANSION_RATIO; - dst_block_size = opts->block_size; - } - - memset(&setup, 0, sizeof(struct wd_comp_sess_setup)); - setup.alg_type = opts->alg_type; - setup.op_type = opts->op_type; - setup.comp_lv = WD_COMP_L8; - setup.win_sz = WD_COMP_WS_8K; - param.type = setup.op_type; - param.numa_id = 0; - setup.sched_param = ¶m; - h_sess = wd_comp_alloc_sess(&setup); - if (!h_sess) - return NULL; - - for (j = 0; j < opts->compact_run_num; j++) { - if (opts->option & TEST_ZLIB) { - ret = zlib_deflate(info->out_buf, info->out_size, - info->in_buf, info->in_size, - &tdata->sum, opts->alg_type); - continue; - } - /* not TEST_ZLIB */ - left = opts->total_len; - tdata->req.op_type = opts->op_type; - tdata->req.src = info->in_buf; - tdata->req.dst = info->out_buf; - tdata->sum = 0; - while (left > 0) { - tdata->req.src_len = src_block_size; - tdata->req.dst_len = dst_block_size; - tdata->req.cb_param = &tdata->req; - if (opts->sync_mode) { - tdata->req.cb = async_cb; - count++; - ret = wd_do_comp_async(h_sess, &tdata->req); - } else { - tdata->req.cb = NULL; - ret = wd_do_comp_sync(h_sess, &tdata->req); - if (info->opts->faults & INJECT_SIG_WORK) - kill(getpid(), SIGTERM); - } - if (ret < 0) { - COMP_TST_PRT("do comp test fail with %d\n", ret); - return (void *)(uintptr_t)ret; - } else if (tdata->req.status) { - return (void *)(uintptr_t)tdata->req.status; - } - if (opts->op_type == WD_DIR_COMPRESS) - left -= src_block_size; - else - left -= dst_block_size; - tdata->req.src += src_block_size; - /* - * It's BLOCK (STATELESS) mode, so user needs to - * combine output buffer by himself. - */ - tdata->req.dst += dst_block_size; - tdata->sum += tdata->req.dst_len; - if (tdata->sum > info->out_size) { - COMP_TST_PRT( - "%s: exceed OUT limits (%ld > %ld)\n", - __func__, - tdata->sum, info->out_size); - break; - } - } - /* info->total_out are accessed by multiple threads */ - __atomic_add_fetch(&info->total_out, tdata->sum, - __ATOMIC_RELEASE); - } - wd_comp_free_sess(h_sess); - return NULL; -} - static int lib_poll_func(__u32 pos, __u32 expect, __u32 *count) { int ret; @@ -382,7 +287,7 @@ int cmp_md5(comp_md5_t *orig, comp_md5_t *final) return 0; }
-static void *async2_cb(struct wd_comp_req *req, void *data) +static void *async_cb(struct wd_comp_req *req, void *data) { sem_t *sem = (sem_t *)data;
@@ -606,7 +511,7 @@ int hw_deflate(handle_t h_dfl, reqs[i].op_type = WD_DIR_COMPRESS;
if (opts->sync_mode) { - reqs[i].cb = async2_cb; + reqs[i].cb = async_cb; reqs[i].cb_param = sem; } do { @@ -617,8 +522,11 @@ int hw_deflate(handle_t h_dfl, __ATOMIC_ACQ_REL); sem_wait(sem); } - } else + } else { ret = wd_do_comp_sync(h_dfl, &reqs[i]); + if (opts->faults & INJECT_SIG_WORK) + kill(getpid(), SIGTERM); + } } while (ret == -WD_EBUSY); if (ret) goto out; @@ -660,7 +568,7 @@ int hw_inflate(handle_t h_ifl, reqs[i].dst_len = q->size; reqs[i].op_type = WD_DIR_DECOMPRESS; if (opts->sync_mode) { - reqs[i].cb = async2_cb; + reqs[i].cb = async_cb; reqs[i].cb_param = sem; } do { diff --git a/uadk_tool/test/comp_main.c b/uadk_tool/test/comp_main.c index aabb8cc..3b5bfa5 100644 --- a/uadk_tool/test/comp_main.c +++ b/uadk_tool/test/comp_main.c @@ -531,6 +531,12 @@ static void *hw_dfl_perf(void *arg) if (opts->is_stream) { for (i = 0; i < opts->compact_run_num; i++) { tout_sz = tdata->dst_sz; + if (opts->option & TEST_ZLIB) { + ret = zlib_deflate(info->out_buf, info->out_size, + info->in_buf, info->in_size, + &tdata->sum, opts->alg_type); + continue; + } ret = hw_stream_compress(opts, tdata->dst, &tout_sz, @@ -590,6 +596,12 @@ static void *hw_ifl_perf(void *arg) if (opts->is_stream) { for (i = 0; i < opts->compact_run_num; i++) { tout_sz = tdata->dst_sz; + if (opts->option & TEST_ZLIB) { + ret = zlib_deflate(info->out_buf, info->out_size, + info->in_buf, info->in_size, + &tdata->sum, opts->alg_type); + continue; + } ret = hw_stream_compress(opts, tdata->dst, &tout_sz,
From: Hao Fang fanghao11@huawei.com
Signed-off-by: Hao Fang fanghao11@huawei.com Signed-off-by: Qi Tao taoqi10@huawei.com --- uadk_tool/test/comp_lib.c | 51 ++++++++++++++++++++++---------------- uadk_tool/test/comp_main.c | 11 +++----- 2 files changed, 33 insertions(+), 29 deletions(-)
diff --git a/uadk_tool/test/comp_lib.c b/uadk_tool/test/comp_lib.c index 3b47dfa..6d07229 100644 --- a/uadk_tool/test/comp_lib.c +++ b/uadk_tool/test/comp_lib.c @@ -607,44 +607,48 @@ int create_send_tdata(struct test_options *opts, { thread_data_t *tdata; chunk_list_t *in_list, *out_list; - int i, j, num, ret; + int i, j, ret;
if (!opts || !info || !info->in_chunk_sz || !info->out_chunk_sz) return -EINVAL; - num = opts->thread_num; - info->send_tds = calloc(1, sizeof(pthread_t) * num); + + info->send_tds = calloc(1, sizeof(pthread_t) * opts->thread_num); if (!info->send_tds) return -ENOMEM; - info->send_tnum = num; - info->tdatas = calloc(1, sizeof(thread_data_t) * num); + info->send_tnum = opts->thread_num; + info->tdatas = calloc(1, sizeof(thread_data_t) * opts->thread_num); if (!info->tdatas) { ret = -ENOMEM; goto out; } - if (opts->is_stream) { - in_list = create_chunk_list(info->in_buf, info->in_size, - info->in_size); - } else { - in_list = create_chunk_list(info->in_buf, info->in_size, - info->in_chunk_sz); + + info->in_buf = mmap_alloc(info->in_size); + if (!info->in_buf) { + ret = -ENOMEM; + goto out_in; } + + if (opts->is_stream) + in_list = create_chunk_list(info->in_buf, info->in_size, info->in_size); + else + in_list = create_chunk_list(info->in_buf, info->in_size, info->in_chunk_sz); if (!in_list) { ret = -EINVAL; - goto out_in; + goto out_ilist; } + if (opts->option & TEST_THP) { ret = madvise(info->in_buf, info->in_size, MADV_HUGEPAGE); if (ret) { COMP_TST_PRT("madvise(MADV_HUGEPAGE)"); - goto out_in; + goto out_ilist; } } - for (i = 0; i < num; i++) { + for (i = 0; i < opts->thread_num; i++) { tdata = &info->tdatas[i]; - /* src address is shared among threads */ tdata->tid = i; tdata->src_sz = info->in_size; - tdata->src = info->in_buf; + tdata->src = info->in_buf; /* src address is shared among threads */ tdata->in_list = in_list; tdata->dst_sz = info->out_size; tdata->dst = mmap_alloc(tdata->dst_sz); @@ -676,25 +680,27 @@ int create_send_tdata(struct test_options *opts, tdata->out_list = out_list; if (!tdata->out_list) { ret = -EINVAL; - goto out_list; + goto out_olist; } calculate_md5(&tdata->md5, tdata->src, tdata->src_sz); tdata->reqs = malloc(sizeof(struct wd_comp_req)); if (!tdata->reqs) - goto out_list; + goto out_olist; sem_init(&tdata->sem, 0, 0); tdata->info = info; } + return 0; -out_list: +out_olist: mmap_free(tdata->dst, tdata->dst_sz); out_dst: for (j = 0; j < i; j++) { - pthread_cancel(info->send_tds[j]); free_chunk_list(info->tdatas[j].out_list); mmap_free(info->tdatas[j].dst, info->tdatas[j].dst_sz); } free_chunk_list(in_list); +out_ilist: + mmap_free(info->in_buf, info->in_size); out_in: free(info->tdatas); out: @@ -744,11 +750,13 @@ void free_threads_tdata(struct hizip_test_info *info)
if (info->send_tds) free(info->send_tds); + if (info->poll_tds) { free(info->poll_tds); free(info->p_tdatas); } - free_chunk_list(tdatas[0].in_list); + + free_chunk_list(tdatas[0].in_list); /* src address is shared among threads */ for (i = 0; i < info->send_tnum; i++) { free_chunk_list(tdatas[i].out_list); free(tdatas[i].reqs); @@ -756,6 +764,7 @@ void free_threads_tdata(struct hizip_test_info *info) /* info->out_buf is bound to tdatas[0].dst */ for (i = 0; i < info->send_tnum; i++) mmap_free(tdatas[i].dst, tdatas[i].dst_sz); + free(info->tdatas); mmap_free(info->in_buf, info->in_size); } diff --git a/uadk_tool/test/comp_main.c b/uadk_tool/test/comp_main.c index 3b5bfa5..dcd7bd3 100644 --- a/uadk_tool/test/comp_main.c +++ b/uadk_tool/test/comp_main.c @@ -838,14 +838,10 @@ int test_hw(struct test_options *opts, char *model) else info.out_size = opts->total_len * EXPANSION_RATIO; } - info.in_buf = mmap_alloc(info.in_size); - if (!info.in_buf) { - ret = -ENOMEM; - goto out_src; - } + ret = create_send_tdata(opts, &info); if (ret) - goto out_send; + goto out_src; ret = create_poll_tdata(opts, &info, opts->poll_num); if (ret) goto out_poll; @@ -947,8 +943,7 @@ out_poll: nonenv_resource_uninit(opts, &info, sched); COMP_TST_PRT("Fail to run %s() (%d)!\n", model, ret); return ret; -out_send: - mmap_free(info.in_buf, info.in_size); + out_src: if (opts->use_env) wd_comp_env_uninit();
From: Hao Fang fanghao11@huawei.com
Function wraped like: uadk_res_init(), prepare_src_data(), perfdata_print().
And alloc/free of data memory are optimized.
Signed-off-by: Hao Fang fanghao11@huawei.com Signed-off-by: Qi Tao taoqi10@huawei.com --- uadk_tool/test/comp_lib.c | 79 ++++++++----- uadk_tool/test/comp_lib.h | 7 +- uadk_tool/test/comp_main.c | 230 ++++++++++++++++++------------------- 3 files changed, 166 insertions(+), 150 deletions(-)
diff --git a/uadk_tool/test/comp_lib.c b/uadk_tool/test/comp_lib.c index 6d07229..0229a27 100644 --- a/uadk_tool/test/comp_lib.c +++ b/uadk_tool/test/comp_lib.c @@ -602,7 +602,7 @@ out: * Thread 0 shares info->out_buf. Other threads need to create its own * dst buffer. */ -int create_send_tdata(struct test_options *opts, +static int create_send_tdata(struct test_options *opts, struct hizip_test_info *info) { thread_data_t *tdata; @@ -708,65 +708,84 @@ out: return ret; }
-int create_poll_tdata(struct test_options *opts, - struct hizip_test_info *info, - int poll_num) +static void free_send_tdata(struct hizip_test_info *info) +{ + thread_data_t *tdatas = info->tdatas; + int i; + + free(info->send_tds); + + /* src address is shared among threads */ + free_chunk_list(tdatas[0].in_list); + for (i = 0; i < info->send_tnum; i++) { + free_chunk_list(tdatas[i].out_list); + free(tdatas[i].reqs); + } + + /* info->out_buf is bound to tdatas[0].dst */ + for (i = 0; i < info->send_tnum; i++) + mmap_free(tdatas[i].dst, tdatas[i].dst_sz); + + free(info->tdatas); + mmap_free(info->in_buf, info->in_size); +} + +static int create_poll_tdata(struct test_options *opts, struct hizip_test_info *info) { thread_data_t *tdatas; int i, ret;
if (opts->sync_mode == 0) return 0; - else if (poll_num <= 0) + + if (opts->poll_num <= 0) return -EINVAL; - info->poll_tnum = poll_num; - info->poll_tds = calloc(1, sizeof(pthread_t) * poll_num); + + info->poll_tnum = opts->poll_num; + info->poll_tds = calloc(1, sizeof(pthread_t) * opts->poll_num); if (!info->poll_tds) return -ENOMEM; - info->p_tdatas = calloc(1, sizeof(thread_data_t) * poll_num); + info->p_tdatas = calloc(1, sizeof(thread_data_t) * opts->poll_num); if (!info->p_tdatas) { ret = -ENOMEM; goto out; } tdatas = info->p_tdatas; - for (i = 0; i < poll_num; i++) { + for (i = 0; i < opts->poll_num; i++) { tdatas[i].tid = i; tdatas[i].info = info; } + return 0; out: free(info->poll_tds); return ret; }
+int create_threads_tdata(struct test_options *opts, struct hizip_test_info *info) +{ + int ret; + + ret = create_send_tdata(opts, info); + if (ret) + return ret; + ret = create_poll_tdata(opts, info); + if (ret) + free_send_tdata(info); + + return ret; +} + /* * Free source and destination buffer contained in sending threads. * Free sending threads and polling threads. */ void free_threads_tdata(struct hizip_test_info *info) { - thread_data_t *tdatas = info->tdatas; - int i; - - if (info->send_tds) - free(info->send_tds); - - if (info->poll_tds) { - free(info->poll_tds); - free(info->p_tdatas); - } - - free_chunk_list(tdatas[0].in_list); /* src address is shared among threads */ - for (i = 0; i < info->send_tnum; i++) { - free_chunk_list(tdatas[i].out_list); - free(tdatas[i].reqs); - } - /* info->out_buf is bound to tdatas[0].dst */ - for (i = 0; i < info->send_tnum; i++) - mmap_free(tdatas[i].dst, tdatas[i].dst_sz); + free(info->poll_tds); + free(info->p_tdatas);
- free(info->tdatas); - mmap_free(info->in_buf, info->in_size); + free_send_tdata(info); }
int attach_threads(struct test_options *opts, diff --git a/uadk_tool/test/comp_lib.h b/uadk_tool/test/comp_lib.h index bbd7db0..ea7a51b 100644 --- a/uadk_tool/test/comp_lib.h +++ b/uadk_tool/test/comp_lib.h @@ -204,12 +204,9 @@ int hw_inflate(handle_t h_ifl, struct test_options *opts, sem_t *sem);
-int create_send_tdata(struct test_options *opts, - struct hizip_test_info *info); -int create_poll_tdata(struct test_options *opts, - struct hizip_test_info *info, - int poll_num); +int create_threads_tdata(struct test_options *opts, struct hizip_test_info *info); void free_threads_tdata(struct hizip_test_info *info); + int attach_threads(struct test_options *opts, struct hizip_test_info *info, void *(*send_thread_func)(void *arg), diff --git a/uadk_tool/test/comp_main.c b/uadk_tool/test/comp_main.c index dcd7bd3..c36dca0 100644 --- a/uadk_tool/test/comp_main.c +++ b/uadk_tool/test/comp_main.c @@ -689,12 +689,15 @@ int store_file(struct hizip_test_info *info, char *model) return (int)sum; }
-static int nonenv_resource_init(struct test_options *opts, - struct hizip_test_info *info, - struct wd_sched **sched) +static int uadk_res_init(struct test_options *opts, + struct hizip_test_info *info, + struct wd_sched **sched) { int ret;
+ if (opts->use_env) + return wd_comp_env_init(NULL); + info->list = get_dev_list(opts, 1); if (!info->list) return -EINVAL; @@ -706,33 +709,105 @@ static int nonenv_resource_init(struct test_options *opts, return 0; }
-static void nonenv_resource_uninit(struct test_options *opts, - struct hizip_test_info *info, - struct wd_sched *sched) +static void uadk_res_uninit(struct test_options *opts, + struct hizip_test_info *info, + struct wd_sched *sched) { + if (opts->use_env) + return wd_comp_env_uninit(); + uninit_config(info, sched); wd_free_list_accels(info->list); }
static bool event_unavailable = false;
-int test_hw(struct test_options *opts, char *model) +static int prepare_src_data(struct test_options *opts, struct hizip_test_info *info, int direction) +{ + chunk_list_t *tlist = NULL; + size_t tbuf_sz = 0; + void *tbuf = NULL; + int ret; + + if (direction) { /* if is inflate, need prepare the compressed data by sw */ + thread_data_t *tdata = info->tdatas; + tbuf_sz = info->in_size / EXPANSION_RATIO; + tbuf = mmap_alloc(tbuf_sz); + if (!tbuf) { + ret = -ENOMEM; + return ret; + } + tlist = create_chunk_list(tbuf, tbuf_sz, + opts->block_size / + EXPANSION_RATIO); + init_chunk_list(tlist, tbuf, tbuf_sz, + opts->block_size / EXPANSION_RATIO); + gen_random_data(tbuf, tbuf_sz); + ret = sw_deflate(tlist, tdata[0].in_list, opts); + if (ret) { + free_chunk_list(tlist); + mmap_free(tbuf, tbuf_sz); + return ret; + } + free_chunk_list(tlist); + mmap_free(tbuf, tbuf_sz); + } else { /* if is deflate, get the random data directly */ + gen_random_data(info->in_buf, info->in_size); + } + + return ret; +} + +static void perfdata_print(struct test_options *opts, struct hizip_test_info *info, + int zbuf_idx, char *zbuf, char *model) +{ + double ilen, usec, speed; + + usec = info->stats->v[ST_RUN_TIME] / 1000; + + if (opts->op_type == WD_DIR_DECOMPRESS) + ilen = (float)count_chunk_list_sz(info->tdatas[0].out_list); + else + ilen = opts->total_len; + + ilen *= opts->thread_num * opts->compact_run_num; + speed = ilen * 1000 * 1000 / 1024 / 1024 / usec; + + if (opts->sync_mode) { + zbuf_idx += sprintf(zbuf + zbuf_idx, + " with %d send + %d poll threads", + opts->thread_num, + opts->poll_num); + } else { + zbuf_idx += sprintf(zbuf + zbuf_idx, + " with %d send threads", + opts->thread_num); + } + + if (!strcmp(model, "hw_dfl_perf") || !strcmp(model, "hw_ifl_perf")) { + COMP_TST_PRT("%s at %.2fMB/s in %f usec (BLK:%d)..\n", + zbuf, speed, usec, opts->block_size); + } else { + COMP_TST_PRT("%s in %f usec (BLK:%d)...\n", + zbuf, usec, opts->block_size); + } + +} + +static int test_hw(struct test_options *opts, char *model) { struct hizip_test_info info = {0}; struct wd_sched *sched = NULL; - double ilen, usec, speed; - char zbuf[120]; - int ret, zbuf_idx, ifl_flag = 0; + struct hizip_stats stats; + int *perf_fds = NULL; void *(*func)(void *); - size_t tbuf_sz = 0; - void *tbuf = NULL; struct stat statbuf; - chunk_list_t *tlist = NULL; - __u32 num; - __u8 enable; + int ifl_flag = 0; + int ret, zbuf_idx; + char zbuf[120]; int nr_fds = 0; - int *perf_fds = NULL; - struct hizip_stats stats; + __u8 enable; + __u32 num;
if (!opts || !model) { ret = -EINVAL; @@ -741,8 +816,7 @@ int test_hw(struct test_options *opts, char *model) info.opts = opts; info.stats = &stats;
- if (!event_unavailable && - perf_event_get("iommu/dev_fault", &perf_fds, &nr_fds)) { + if (!event_unavailable && perf_event_get("iommu/dev_fault", &perf_fds, &nr_fds)) { COMP_TST_PRT("IOPF statistic unavailable\n"); /* No need to retry and print an error on every run */ event_unavailable = true; @@ -750,36 +824,22 @@ int test_hw(struct test_options *opts, char *model) stat_setup(&info);
memset(zbuf, 0, 120); + info.in_size = opts->total_len; + info.out_size = opts->total_len; + info.in_chunk_sz = opts->block_size; + info.out_chunk_sz = opts->block_size; if (!strcmp(model, "sw_dfl_hw_ifl")) { func = sw_dfl_hw_ifl; - info.in_size = opts->total_len; - if (opts->is_stream) - info.out_size = opts->total_len; - else - info.out_size = opts->total_len; - info.in_chunk_sz = opts->block_size; - info.out_chunk_sz = opts->block_size; zbuf_idx = sprintf(zbuf, "Mix SW deflate and HW %s %s inflate", opts->sync_mode ? "ASYNC" : "SYNC", opts->is_stream ? "STREAM" : "BLOCK"); } else if (!strcmp(model, "hw_dfl_sw_ifl")) { func = hw_dfl_sw_ifl; - info.in_size = opts->total_len; - info.out_size = opts->total_len; - info.in_chunk_sz = opts->block_size; - info.out_chunk_sz = opts->block_size; zbuf_idx = sprintf(zbuf, "Mix HW %s %s deflate and SW inflate", opts->sync_mode ? "ASYNC" : "SYNC", opts->is_stream ? "STREAM" : "BLOCK"); } else if (!strcmp(model, "hw_dfl_hw_ifl")) { func = hw_dfl_hw_ifl; - info.in_size = opts->total_len; - if (opts->is_stream) - info.out_size = opts->total_len; - else - info.out_size = opts->total_len; - info.in_chunk_sz = opts->block_size; - info.out_chunk_sz = opts->block_size; zbuf_idx = sprintf(zbuf, "Mix HW %s %s deflate and HW %s %s inflate", opts->sync_mode ? "ASYNC" : "SYNC", @@ -788,18 +848,14 @@ int test_hw(struct test_options *opts, char *model) opts->is_stream ? "STREAM" : "BLOCK"); } else if (!strcmp(model, "hw_dfl_perf")) { func = hw_dfl_perf; - info.in_size = opts->total_len; info.out_size = opts->total_len * EXPANSION_RATIO; - info.in_chunk_sz = opts->block_size; info.out_chunk_sz = opts->block_size * EXPANSION_RATIO; zbuf_idx = sprintf(zbuf, "HW %s %s deflate", opts->sync_mode ? "ASYNC" : "SYNC", opts->is_stream ? "STREAM" : "BLOCK"); } else if (!strcmp(model, "hw_ifl_perf")) { func = hw_ifl_perf; - info.in_size = opts->total_len; info.out_size = opts->total_len * INFLATION_RATIO; - info.in_chunk_sz = opts->block_size; info.out_chunk_sz = opts->block_size * INFLATION_RATIO; zbuf_idx = sprintf(zbuf, "HW %s %s inflate", opts->sync_mode ? "ASYNC" : "SYNC", @@ -811,10 +867,7 @@ int test_hw(struct test_options *opts, char *model) goto out; }
- if (opts->use_env) - ret = wd_comp_env_init(NULL); - else - ret = nonenv_resource_init(opts, &info, &sched); + ret = uadk_res_init(opts, &info, &sched); if (ret < 0) goto out;
@@ -822,7 +875,8 @@ int test_hw(struct test_options *opts, char *model) kill(getpid(), SIGTERM);
if (opts->use_env) { - ret = wd_comp_get_env_param(0, opts->op_type, opts->sync_mode, &num, &enable); + ret = wd_comp_get_env_param(0, opts->op_type, opts->sync_mode, + &num, &enable); if (ret < 0) goto out; } @@ -839,43 +893,20 @@ int test_hw(struct test_options *opts, char *model) info.out_size = opts->total_len * EXPANSION_RATIO; }
- ret = create_send_tdata(opts, &info); + ret = create_threads_tdata(opts, &info); if (ret) goto out_src; - ret = create_poll_tdata(opts, &info, opts->poll_num); - if (ret) - goto out_poll; + if (opts->is_file) { - /* in_list is created by create_send3_threads(). */ ret = load_file_data(&info); if (ret < 0) goto out_buf; } else { - if (ifl_flag) { - thread_data_t *tdata = info.tdatas; - tbuf_sz = info.in_size / EXPANSION_RATIO; - tbuf = mmap_alloc(tbuf_sz); - if (!tbuf) { - ret = -ENOMEM; - goto out_buf; - } - tlist = create_chunk_list(tbuf, tbuf_sz, - opts->block_size / - EXPANSION_RATIO); - init_chunk_list(tlist, tbuf, tbuf_sz, - opts->block_size / EXPANSION_RATIO); - gen_random_data(tbuf, tbuf_sz); - ret = sw_deflate(tlist, tdata[0].in_list, opts); - if (ret) { - free_chunk_list(tlist); - mmap_free(tbuf, tbuf_sz); - goto out_buf; - } - free_chunk_list(tlist); - mmap_free(tbuf, tbuf_sz); - } else - gen_random_data(info.in_buf, info.in_size); + ret = prepare_src_data(opts, &info, ifl_flag); + if (ret < 0) + goto out_buf; } + if (opts->faults & INJECT_TLB_FAULT) { /* * Now unmap the buffers and retry the access. Normally we @@ -894,61 +925,30 @@ int test_hw(struct test_options *opts, char *model) if (opts->total_len > 0x54000) COMP_TST_PRT( "NOTE: test might trash the TLB\n"); } + stat_start(&info); ret = attach_threads(opts, &info, func, poll_thread_func); if (ret) goto out_buf; stat_end(&info); + info.stats->v[ST_IOPF] = perf_event_put(perf_fds, nr_fds); if (opts->is_file) (void)store_file(&info, model);
- usec = info.stats->v[ST_RUN_TIME] / 1000; - if (opts->op_type == WD_DIR_DECOMPRESS) - ilen = (float)count_chunk_list_sz(info.tdatas[0].out_list); - else - ilen = opts->total_len; - ilen *= opts->thread_num * opts->compact_run_num; - speed = ilen * 1000 * 1000 / 1024 / 1024 / usec; - if (opts->sync_mode) { - zbuf_idx += sprintf(zbuf + zbuf_idx, - " with %d send + %d poll threads", - opts->thread_num, - opts->poll_num); - } else { - zbuf_idx += sprintf(zbuf + zbuf_idx, - " with %d send threads", - opts->thread_num); - } - if (!strcmp(model, "hw_dfl_perf") || !strcmp(model, "hw_ifl_perf")) { - COMP_TST_PRT("%s at %.2fMB/s in %f usec (BLK:%d).\n", - zbuf, speed, usec, opts->block_size); - } else { - COMP_TST_PRT("%s in %f usec (BLK:%d).\n", - zbuf, usec, opts->block_size); - } + perfdata_print(opts, &info, zbuf_idx, zbuf, model); + free_threads_tdata(&info); - if (opts->use_env) - wd_comp_env_uninit(); - else - nonenv_resource_uninit(opts, &info, sched); + + uadk_res_uninit(opts, &info, sched); + usleep(1000); + return 0; out_buf: -out_poll: free_threads_tdata(&info); - if (opts->use_env) - wd_comp_env_uninit(); - else - nonenv_resource_uninit(opts, &info, sched); - COMP_TST_PRT("Fail to run %s() (%d)!\n", model, ret); - return ret; - out_src: - if (opts->use_env) - wd_comp_env_uninit(); - else - nonenv_resource_uninit(opts, &info, sched); + uadk_res_uninit(opts, &info, sched); out: COMP_TST_PRT("Fail to run %s() (%d)!\n", model, ret); return ret;
From: Hao Fang fanghao11@huawei.com
The old format: Such as: uadk_tool --m zip -b 8192 -s 8192000 -t 8 New: uadk_tool --m zip --blksize 8192 --size 8192000 --thread 8
Signed-off-by: Hao Fang fanghao11@huawei.com Signed-off-by: Qi Tao taoqi10@huawei.com --- uadk_tool/test/comp_lib.c | 273 +++++++++++++++++++++++++++++-------- uadk_tool/test/comp_lib.h | 59 +++++--- uadk_tool/test/comp_main.c | 205 +++------------------------- uadk_tool/test/comp_main.h | 6 +- 4 files changed, 279 insertions(+), 264 deletions(-)
diff --git a/uadk_tool/test/comp_lib.c b/uadk_tool/test/comp_lib.c index 0229a27..6c2062d 100644 --- a/uadk_tool/test/comp_lib.c +++ b/uadk_tool/test/comp_lib.c @@ -5,6 +5,7 @@ */
#include <pthread.h> +#include <getopt.h> #include <signal.h> #include <math.h> #include <sys/mman.h> @@ -640,7 +641,7 @@ static int create_send_tdata(struct test_options *opts, if (opts->option & TEST_THP) { ret = madvise(info->in_buf, info->in_size, MADV_HUGEPAGE); if (ret) { - COMP_TST_PRT("madvise(MADV_HUGEPAGE)"); + COMP_TST_PRT("failed to madvise(MADV_HUGEPAGE) src_buf(%ld)!\n", info->in_size); goto out_ilist; } } @@ -659,7 +660,7 @@ static int create_send_tdata(struct test_options *opts, if (opts->option & TEST_THP) { ret = madvise(tdata->dst, tdata->dst_sz, MADV_HUGEPAGE); if (ret) { - COMP_TST_PRT("madvise(MADV_HUGEPAGE)"); + COMP_TST_PRT("failed to madvise(MADV_HUGEPAGE) dst_buf(%ld)!\n", tdata->dst_sz); goto out_dst; } } @@ -1060,63 +1061,225 @@ void uninit_config(void *priv, struct wd_sched *sched) wd_sched_rr_release(sched); }
-int parse_common_option(const char opt, const char *optarg, +static void set_thp(struct test_options *opts) +{ +#define MAX_BUFF_SIZE 14 + char *p; + char s[MAX_BUFF_SIZE]; + FILE *file; + + file = fopen("/sys/kernel/mm/transparent_hugepage/enabled", "r"); + if (!file) + goto out_err; + p = fgets(s, MAX_BUFF_SIZE, file); + fclose(file); + if (!p) + goto out_err; + + if (strcmp(s, "never") == 0) { + COMP_TST_PRT("Cannot test THP with enable=never\n"); + return; + } + + file = fopen("/sys/kernel/mm/transparent_hugepage/defrag", "r"); + if (!file) + goto out_err; + p = fgets(s, MAX_BUFF_SIZE, file); + fclose(file); + if (!p) + goto out_err; + + if (strcmp(s, "defer") == 0 || strcmp(s, "never") == 0) { + COMP_TST_PRT("Cannot test THP with defrag=%s\n", s); + return; + } + + return; +out_err: + COMP_TST_PRT("THP unsupported?\n"); +} + +int parse_common_option(int argc, char *argv[], struct test_options *opts) { - switch (opt) { - case 'b': - opts->block_size = strtol(optarg, NULL, 0); - if (opts->block_size <= 0) - return 1; - break; - case 'l': - opts->compact_run_num = strtol(optarg, NULL, 0); - if (opts->compact_run_num <= 0) + int opt, option_idx; + struct option long_options[] = { + {"help", no_argument, 0, 0 }, + {"self", no_argument, 0, 1 }, + {"in", required_argument, 0, 2 }, + {"out", required_argument, 0, 3 }, + {"env", no_argument, 0, 4 }, + {"blksize", required_argument, 0, 5 }, + {"qnum", required_argument, 0, 6 }, + {"loop", required_argument, 0, 7 }, + {"stream", no_argument, 0, 8 }, + {"size", required_argument, 0, 9 }, + {"verify", no_argument, 0, 10 }, + {"alg", required_argument, 0, 11 }, + {"inf", no_argument, 0, 12 }, + {"thread", required_argument, 0, 13 }, + {"mode", required_argument, 0, 14 }, + {"sgl", no_argument, 0, 15 }, + /* still keep these proprietary cmds listd below*/ + {"sformat", required_argument, 0, 20 }, + {"option", required_argument, 0, 21 }, + {"fork", required_argument, 0, 22 }, + {"kill", required_argument, 0, 23 }, + {0, 0, 0, 24 }, + }; + + opts->fd_in = -1; + opts->fd_out = -1; + opts->alg_type = WD_COMP_ALG_MAX; + while ((opt = getopt_long(argc, argv, "", long_options, &option_idx)) != -1) { + switch (opt) { + case 0: return 1; - break; - case 'q': - opts->q_num = strtol(optarg, NULL, 0); - if (opts->q_num <= 0) + case 1: + opts->self = 1; + break; + case 2: /* input file */ + if (optarg) { + opts->fd_in = open(optarg, O_RDONLY); + if (opts->fd_in < 0) { + COMP_TST_PRT("Fail to open %s\n", + optarg); + return 1; + } else + opts->is_file = true; + } else { + COMP_TST_PRT("Input file is missing!\n"); + return 1; + } + if (lseek(opts->fd_in, 0, SEEK_SET) < 0) { + COMP_TST_PRT("Fail on lseek()!\n"); + return 1; + } + break; + case 3: /* output file */ + if (optarg) { + opts->fd_out = open(optarg, + O_CREAT | O_WRONLY, + S_IWUSR | S_IRGRP | + S_IROTH); + if (opts->fd_out < 0) { + COMP_TST_PRT("Fail to open %s\n", + optarg); + return 1; + } else + opts->is_file = true; + } else { + COMP_TST_PRT("Output file is missing!\n"); + return 1; + } + if (lseek(opts->fd_out, 0, SEEK_SET) < 0) { + COMP_TST_PRT("Fail on lseek()!\n"); + return 1; + } + break; + case 4: /* env */ + opts->use_env = true; + break; + case 5: + opts->block_size = strtol(optarg, NULL, 0); + if (opts->block_size <= 0) + return 1; + break; + case 6: + opts->q_num = strtol(optarg, NULL, 0); + if (opts->q_num <= 0) + return 1; + break; + case 7: + opts->compact_run_num = strtol(optarg, NULL, 0); + if (opts->compact_run_num <= 0) + return 1; + break; + case 8: + opts->is_stream = MODE_STREAM; + break; + case 9: + opts->total_len = strtol(optarg, NULL, 0); + SYS_ERR_COND(opts->total_len <= 0, "invalid size '%s'\n", + optarg); + break; + case 10: + opts->verify = true; + break; + case 11: + opts->alg_type = strtol(optarg, NULL, 0); + if (opts->alg_type >= WD_COMP_ALG_MAX) + return 1; + break; + case 12: + opts->op_type = WD_DIR_DECOMPRESS; + break; + case 13: + opts->thread_num = strtol(optarg, NULL, 0); + SYS_ERR_COND(opts->thread_num < 0, "invalid thread num '%s'\n", + optarg); + break; + case 14: + opts->sync_mode = strtol(optarg, NULL, 0); + SYS_ERR_COND(opts->sync_mode < 0 || opts->sync_mode > 1, + "invalid sync mode '%s'\n", optarg); + break; + case 15: /* reserved */ + opts->data_fmt = WD_SGL_BUF; + break; + case 20: + if (strcmp(optarg, "none") == 0) { + opts->display_stats = STATS_NONE; + } else if (strcmp(optarg, "csv") == 0) { + opts->display_stats = STATS_CSV; + } else if (strcmp(optarg, "pretty") == 0) { + opts->display_stats = STATS_PRETTY; + } else { + SYS_ERR_COND(1, "invalid argument to --sformat: '%s'\n", optarg); + break; + } + break; + case 21: + switch (optarg[0]) { + case 'p': + opts->option |= PERFORMANCE; + break; + case 't': + opts->option |= TEST_THP; + set_thp(opts); + break; + case 'c': + opts->option |= TEST_ZLIB; + break; + default: + SYS_ERR_COND(1, "invalid argument to --option: '%s'\n", optarg); + break; + } + break; + case 22: + opts->children = strtol(optarg, NULL, 0); + if (opts->children < 0) + return 1; + break; + case 23: + switch (optarg[0]) { + case 'b': + opts->faults |= INJECT_SIG_BIND; + break; + case 't': + opts->faults |= INJECT_TLB_FAULT; + break; + case 'w': + opts->faults |= INJECT_SIG_WORK; + break; + default: + SYS_ERR_COND(1, "invalid argument to --kill: '%s'\n", optarg); + return 1; + } + break; + default: return 1; - break; - case 'd': - opts->op_type = WD_DIR_DECOMPRESS; - break; - case 'S': - opts->is_stream = MODE_STREAM; - break; - case 's': - opts->total_len = strtol(optarg, NULL, 0); - SYS_ERR_COND(opts->total_len <= 0, "invalid size '%s'\n", - optarg); - break; - case 't': - opts->thread_num = strtol(optarg, NULL, 0); - SYS_ERR_COND(opts->thread_num < 0, "invalid thread num '%s'\n", - optarg); - break; - case 'm': - opts->sync_mode = strtol(optarg, NULL, 0); - SYS_ERR_COND(opts->sync_mode < 0 || opts->sync_mode > 1, - "invalid sync mode '%s'\n", optarg); - break; - case 'V': - opts->verify = true; - break; - case 'a': - opts->alg_type = WD_DEFLATE; - break; - case 'z': - opts->alg_type = WD_ZLIB; - break; - case 'L': - opts->data_fmt = WD_SGL_BUF; - break; - case 'Z': - opts->alg_type = WD_LZ77_ZSTD; - break; - default: - return 1; + } }
return 0; diff --git a/uadk_tool/test/comp_lib.h b/uadk_tool/test/comp_lib.h index ea7a51b..eda1d59 100644 --- a/uadk_tool/test/comp_lib.h +++ b/uadk_tool/test/comp_lib.h @@ -66,6 +66,9 @@ struct test_options { int alg_type; int op_type;
+ /* self-test */ + int self; + /* bytes of data for a request */ int block_size; int q_num; @@ -264,23 +267,43 @@ static inline int zlib_deflate(void *output, unsigned int out_size, void *input,
#define COMMON_OPTSTRING "hb:q:l:Ss:Vzt:m:dacLZ"
-#define COMMON_HELP "%s [opts]\n" \ - " -b <size> block size\n" \ - " -q <num> number of queues\n" \ - " -l <num> number of compact runs\n" \ - " -S stream mode, default block mode\n" \ - " -s <size> total size\n" \ - " -V verify output\n" \ - " -a test deflate algorithm, default gzip\n" \ - " -z test zlib algorithm, default gzip\n" \ - " -t <num> number of thread per process\n" \ - " -m <mode> mode of queues: 0 sync, 1 async\n" \ - " -d test decompression, default compression\n" \ - " -c use cpu to do zlib\n" \ - " -L test sgl type buffer, default pbuffer\n" \ - " -Z test lz77_zstd algorithm, default gzip\n" \ - "\n\n" - -int parse_common_option(const char opt, const char *optarg, +#define COMMON_HELP "%s test --m zip [opts]\n\n" \ + " --self run self test\n" \ + " --blksize single block size, default 128000\n" \ + " --qnum number of queues, default 1\n" \ + " --loop loop count of test runs, default 1\n" \ + " --stream stream mode, default block mode\n" \ + " --size total data size, default 10 * blksize\n" \ + " --verify verify output\n" \ + " --thread number of thread per process\n" \ + " --mode mode of queues: default sync\n" \ + " '0' sync, '1' async\n" \ + " --inf test decompression, default compression\n"\ + " --sgl test sgl type buffer, default pbuffer\n" \ + " --alg test algorithm, default gzip\n" \ + " '0' deflate\n" \ + " '1' zlib\n" \ + " '2' gzip\n" \ + " '3' lz77_zstd\n" \ + " --in intput file to be compressed\n" \ + " --out output file after compressed\n" \ + " --env enable environment variable settings\n" \ + " --sformat output format for the statistics\n" \ + " 'none' do not output statistics\n" \ + " 'pretty' human readable format\n" \ + " 'csv' raw, machine readable\n" \ + " --option options\n" \ + " 'p' prefaults the output pages\n" \ + " 't' try to enable transparent huge pages\n"\ + " 'c' use cpu software zlib\n" \ + " --fork number of children to create\n" \ + " --kill kill thread\n" \ + " 'b' kills the process after bind\n" \ + " 't' tries to access an unmapped buffer\n" \ + " 'w' kills the process while the queue is working\n" \ + " --help command help \n\n" + +int parse_common_option(int argc, char *argv[], struct test_options *opts); + #endif /* TEST_LIB_H_ */ diff --git a/uadk_tool/test/comp_main.c b/uadk_tool/test/comp_main.c index c36dca0..3cf39ac 100644 --- a/uadk_tool/test/comp_main.c +++ b/uadk_tool/test/comp_main.c @@ -6,7 +6,6 @@ #include <linux/perf_event.h> #include <asm/unistd.h> /* For __NR_perf_event_open */ #include <fenv.h> -#include <getopt.h> #include <inttypes.h> #include <math.h> #include <signal.h> @@ -1052,13 +1051,9 @@ int run_self_test(struct test_options *opts) static int set_default_opts(struct test_options *opts) { if (!opts->block_size) - opts->block_size = 8192; - if (!opts->total_len) { - if (opts->block_size) - opts->total_len = opts->block_size * 10; - else - opts->total_len = 8192 * 10; - } + opts->block_size = 128000; + if (!opts->total_len) + opts->total_len = opts->block_size * 10; if (!opts->thread_num) opts->thread_num = 1; if (!opts->q_num) @@ -1098,6 +1093,10 @@ int run_cmd(struct test_options *opts) bool success = true;
set_default_opts(opts); + + if (opts->self) + return run_self_test(opts); + if (opts->children) { pids = calloc(opts->children, sizeof(pid_t)); if (!pids) @@ -1266,43 +1265,6 @@ unsigned long long perf_event_put(int *perf_fds, int nr_fds) return total; }
-static void set_thp(struct test_options *opts) -{ - char *p; - char s[14]; - FILE *file; - - file = fopen("/sys/kernel/mm/transparent_hugepage/enabled", "r"); - if (!file) - goto out_err; - p = fgets(s, 14, file); - fclose(file); - if (!p) - goto out_err; - - if (strcmp(s, "never") == 0) { - COMP_TST_PRT("Cannot test THP with enable=never\n"); - return; - } - - file = fopen("/sys/kernel/mm/transparent_hugepage/defrag", "r"); - if (!file) - goto out_err; - p = fgets(s, 14, file); - fclose(file); - if (!p) - goto out_err; - - if (strcmp(s, "defer") == 0 || strcmp(s, "never") == 0) { - COMP_TST_PRT("Cannot test THP with defrag=%s\n", s); - return; - } - - return; -out_err: - COMP_TST_PRT("THP unsupported?\n"); -} - void stat_setup(struct hizip_test_info *info) { clock_gettime(CLOCK_MONOTONIC_RAW, &info->tv.setup_time); @@ -1393,15 +1355,17 @@ static void handle_sigbus(int sig)
int test_comp_entry(int argc, char *argv[]) { + int show_help = 0; struct test_options opts = { .alg_type = WD_GZIP, .op_type = WD_DIR_COMPRESS, + .self = 0, .q_num = 1, .compact_run_num = 1, .thread_num = 1, .sync_mode = 0, - .block_size = 512000, - .total_len = opts.block_size * 10, + .block_size = 0, + .total_len = 0, .verify = false, .is_decomp = false, .is_stream = false, @@ -1411,155 +1375,18 @@ int test_comp_entry(int argc, char *argv[]) .faults = 0, .data_fmt = 0, }; - struct option long_options[] = { - {"self", no_argument, 0, 0 }, - {"in", required_argument, 0, 0 }, - {"out", required_argument, 0, 0 }, - {"env", no_argument, 0, 0 }, - {0, 0, 0, 0 }, - }; - int show_help = 0; - int opt, option_idx; - int self = 0;
opts.fd_in = -1; opts.fd_out = -1; opts.alg_type = WD_COMP_ALG_MAX; - while ((opt = getopt_long(argc, argv, COMMON_OPTSTRING "f:o:w:k:r:", - long_options, &option_idx)) != -1) { - switch (opt) { - case 0: - switch (option_idx) { - case 0: /* self */ - self = 1; - break; - case 1: /* in */ - if (optarg) { - opts.fd_in = open(optarg, O_RDONLY); - if (opts.fd_in < 0) { - COMP_TST_PRT("Fail to open %s\n", - optarg); - show_help = 1; - } else - opts.is_file = true; - } else { - COMP_TST_PRT("Input file is missing!\n"); - show_help = 1; - } - if (lseek(opts.fd_in, 0, SEEK_SET) < 0) { - COMP_TST_PRT("Fail on lseek()!\n"); - show_help = 1; - } - break; - case 2: /* out */ - if (optarg) { - opts.fd_out = open(optarg, - O_CREAT | O_WRONLY, - S_IWUSR | S_IRGRP | - S_IROTH); - if (opts.fd_out < 0) { - COMP_TST_PRT("Fail to open %s\n", - optarg); - show_help = 1; - } else - opts.is_file = true; - } else { - COMP_TST_PRT("Output file is missing!\n"); - show_help = 1; - } - if (lseek(opts.fd_out, 0, SEEK_SET) < 0) { - COMP_TST_PRT("Fail on lseek()!\n"); - show_help = 1; - } - break; - case 3: /* env */ - opts.use_env = true; - break; - default: - show_help = 1; - break; - } - break; - case 'f': - if (strcmp(optarg, "none") == 0) { - opts.display_stats = STATS_NONE; - } else if (strcmp(optarg, "csv") == 0) { - opts.display_stats = STATS_CSV; - } else if (strcmp(optarg, "pretty") == 0) { - opts.display_stats = STATS_PRETTY; - } else { - SYS_ERR_COND(1, "invalid argument to -f: '%s'\n", optarg); - break; - } - break; - case 'o': - switch (optarg[0]) { - case 'p': - opts.option |= PERFORMANCE; - break; - case 't': - opts.option |= TEST_THP; - set_thp(&opts); - break; - default: - SYS_ERR_COND(1, "invalid argument to -o: '%s'\n", optarg); - break; - } - break; - case 'c': - opts.option |= TEST_ZLIB; - break; - case 'r': - opts.children = strtol(optarg, NULL, 0); - if (opts.children < 0) - show_help = 1; - break; - case 'k': - switch (optarg[0]) { - case 'b': - opts.faults |= INJECT_SIG_BIND; - break; - case 't': - opts.faults |= INJECT_TLB_FAULT; - break; - case 'w': - opts.faults |= INJECT_SIG_WORK; - break; - default: - SYS_ERR_COND(1, "invalid argument to -k: '%s'\n", optarg); - break; - } - break; - default: - show_help = parse_common_option(opt, optarg, &opts); - break; - } - } + show_help = parse_common_option(argc, argv, &opts);
signal(SIGBUS, handle_sigbus);
- if (!show_help) { - if (self) - return run_self_test(&opts); - return run_cmd(&opts); + if (show_help) { + SYS_ERR_COND(show_help || optind > argc, COMMON_HELP, argv[0]); + return 0; }
- SYS_ERR_COND(show_help || optind > argc, - COMMON_HELP - " -f <format> output format for the statistics\n" - " 'none' do not output statistics\n" - " 'pretty' human readable format\n" - " 'csv' raw, machine readable\n" - " -o <mode> options\n" - " 'perf' prefaults the output pages\n" - " 'thp' try to enable transparent huge pages\n" - " 'zlib' use zlib instead of the device\n" - " -r <children> number of children to create\n" - " -k <mode> kill thread\n" - " 'bind' kills the process after bind\n" - " 'tlb' tries to access an unmapped buffer\n" - " 'work' kills the process while the queue is working\n", - argv[0] - ); - return 0; + return run_cmd(&opts); } diff --git a/uadk_tool/test/comp_main.h b/uadk_tool/test/comp_main.h index dcf3980..2550b8d 100644 --- a/uadk_tool/test/comp_main.h +++ b/uadk_tool/test/comp_main.h @@ -1,9 +1,11 @@ /* SPDX-License-Identifier: Apache-2.0 */ +/* + * Copyright 2024 Huawei Technologies Co.,Ltd. All rights reserved. + */
#ifndef TEST_COMP_H #define TEST_COMP_H
- int test_comp_entry(int argc, char *argv[]);
-#endif /* TEST_COMP_H */ +#endif /* TEST_COMP_H */ \ No newline at end of file
From: Hao Fang fanghao11@huawei.com
1.fixes found with chechpatch. 2.code format alignment.
Signed-off-by: Hao Fang fanghao11@huawei.com Signed-off-by: Qi Tao taoqi10@huawei.com --- uadk_tool/test/comp_lib.c | 75 +++++++++--------- uadk_tool/test/comp_lib.h | 39 ++++------ uadk_tool/test/comp_main.c | 151 +++++++++++++++++++------------------ 3 files changed, 126 insertions(+), 139 deletions(-)
diff --git a/uadk_tool/test/comp_lib.c b/uadk_tool/test/comp_lib.c index 6c2062d..014aa98 100644 --- a/uadk_tool/test/comp_lib.c +++ b/uadk_tool/test/comp_lib.c @@ -343,7 +343,7 @@ void free_chunk_list(chunk_list_t *list) * Deflate a data block with compressed header. */ static int chunk_deflate(void *in, size_t in_sz, void *out, size_t *out_sz, - struct test_options *opts) + struct test_options *opts) { int alg_type = opts->alg_type; z_stream strm; @@ -405,7 +405,7 @@ static int chunk_deflate(void *in, size_t in_sz, void *out, size_t *out_sz, * produces compression header. */ static int chunk_inflate(void *in, size_t in_sz, void *out, size_t *out_sz, - struct test_options *opts) + struct test_options *opts) { z_stream strm; int ret; @@ -449,15 +449,14 @@ out: * in_list & out_list should be formated first. */ int sw_deflate(chunk_list_t *in_list, - chunk_list_t *out_list, - struct test_options *opts) + chunk_list_t *out_list, + struct test_options *opts) { chunk_list_t *p, *q; int ret = -EINVAL;
for (p = in_list, q = out_list; p && q; p = p->next, q = q->next) { - ret = chunk_deflate(p->addr, p->size, q->addr, &q->size, - opts); + ret = chunk_deflate(p->addr, p->size, q->addr, &q->size, opts); if (ret) return ret; } @@ -469,7 +468,7 @@ int sw_deflate(chunk_list_t *in_list, * in_list & out_list should be formated first. */ int sw_inflate(chunk_list_t *in_list, chunk_list_t *out_list, - struct test_options *opts) + struct test_options *opts) { chunk_list_t *p, *q; int ret = -EINVAL; @@ -488,10 +487,10 @@ int sw_inflate(chunk_list_t *in_list, chunk_list_t *out_list, * in_list & out_list should be formated first. */ int hw_deflate(handle_t h_dfl, - chunk_list_t *in_list, - chunk_list_t *out_list, - struct test_options *opts, - sem_t *sem) + chunk_list_t *in_list, + chunk_list_t *out_list, + struct test_options *opts, + sem_t *sem) { struct wd_comp_req *reqs; chunk_list_t *p = in_list, *q = out_list; @@ -549,10 +548,10 @@ out: * in_list & out_list should be formated first. */ int hw_inflate(handle_t h_ifl, - chunk_list_t *in_list, - chunk_list_t *out_list, - struct test_options *opts, - sem_t *sem) + chunk_list_t *in_list, + chunk_list_t *out_list, + struct test_options *opts, + sem_t *sem) { struct wd_comp_req *reqs; chunk_list_t *p, *q; @@ -641,7 +640,7 @@ static int create_send_tdata(struct test_options *opts, if (opts->option & TEST_THP) { ret = madvise(info->in_buf, info->in_size, MADV_HUGEPAGE); if (ret) { - COMP_TST_PRT("failed to madvise(MADV_HUGEPAGE) src_buf(%ld)!\n", info->in_size); + COMP_TST_PRT("failed to madvise(MADV_HUGEPAGE) src_buf(%zu)!\n", info->in_size); goto out_ilist; } } @@ -660,7 +659,7 @@ static int create_send_tdata(struct test_options *opts, if (opts->option & TEST_THP) { ret = madvise(tdata->dst, tdata->dst_sz, MADV_HUGEPAGE); if (ret) { - COMP_TST_PRT("failed to madvise(MADV_HUGEPAGE) dst_buf(%ld)!\n", tdata->dst_sz); + COMP_TST_PRT("failed to madvise(MADV_HUGEPAGE) dst_buf(%zu)!\n", tdata->dst_sz); goto out_dst; } } @@ -790,9 +789,9 @@ void free_threads_tdata(struct hizip_test_info *info) }
int attach_threads(struct test_options *opts, - struct hizip_test_info *info, - void *(*send_thread_func)(void *arg), - void *(*poll_thread_func)(void *arg)) + struct hizip_test_info *info, + void *(*send_thread_func)(void *arg), + void *(*poll_thread_func)(void *arg)) { int i, j, ret, num; void *tret; @@ -816,15 +815,14 @@ int attach_threads(struct test_options *opts, &info->tdatas[i]); if (ret < 0) { COMP_TST_PRT("Fail to create poll thread %d (%d)\n", - i, ret); + i, ret); goto out_poll; } } for (i = 0; i < info->poll_tnum; i++) { ret = pthread_join(info->poll_tds[i], &tret); if (ret < 0) { - COMP_TST_PRT( "Fail on poll thread with %d\n", - ret); + COMP_TST_PRT("Fail on poll thread with %d\n", ret); goto out_poll; } } @@ -832,7 +830,7 @@ int attach_threads(struct test_options *opts, for (i = 0; i < info->send_tnum; i++) { ret = pthread_join(info->send_tds[i], &tret); if (ret < 0) { - COMP_TST_PRT( "Fail on send thread with %d\n", ret); + COMP_TST_PRT("Fail on send thread with %d\n", ret); goto out_poll; } } @@ -947,7 +945,6 @@ int init_ctx_config(struct test_options *opts, void *priv, int i, j, ret = -EINVAL; int q_num = opts->q_num;
- __atomic_store_n(&sum_pend, 0, __ATOMIC_RELEASE); __atomic_store_n(&sum_thread_end, 0, __ATOMIC_RELEASE); *sched = wd_sched_rr_alloc(SCHED_POLICY_RR, 2, 2, lib_poll_func); @@ -1120,7 +1117,7 @@ int parse_common_option(int argc, char *argv[], {"thread", required_argument, 0, 13 }, {"mode", required_argument, 0, 14 }, {"sgl", no_argument, 0, 15 }, - /* still keep these proprietary cmds listd below*/ + /* still keep these proprietary cmds listd below*/ {"sformat", required_argument, 0, 20 }, {"option", required_argument, 0, 21 }, {"fork", required_argument, 0, 22 }, @@ -1138,15 +1135,14 @@ int parse_common_option(int argc, char *argv[], case 1: opts->self = 1; break; - case 2: /* input file */ + case 2: /* input file */ if (optarg) { opts->fd_in = open(optarg, O_RDONLY); if (opts->fd_in < 0) { - COMP_TST_PRT("Fail to open %s\n", - optarg); + COMP_TST_PRT("Fail to open %s\n", optarg); return 1; - } else - opts->is_file = true; + } + opts->is_file = true; } else { COMP_TST_PRT("Input file is missing!\n"); return 1; @@ -1156,18 +1152,17 @@ int parse_common_option(int argc, char *argv[], return 1; } break; - case 3: /* output file */ + case 3: /* output file */ if (optarg) { opts->fd_out = open(optarg, - O_CREAT | O_WRONLY, - S_IWUSR | S_IRGRP | - S_IROTH); + O_CREAT | O_WRONLY, + S_IWUSR | S_IRGRP | + S_IROTH); if (opts->fd_out < 0) { - COMP_TST_PRT("Fail to open %s\n", - optarg); + COMP_TST_PRT("Fail to open %s\n", optarg); return 1; - } else - opts->is_file = true; + } + opts->is_file = true; } else { COMP_TST_PRT("Output file is missing!\n"); return 1; @@ -1177,7 +1172,7 @@ int parse_common_option(int argc, char *argv[], return 1; } break; - case 4: /* env */ + case 4: /* environment variable */ opts->use_env = true; break; case 5: diff --git a/uadk_tool/test/comp_lib.h b/uadk_tool/test/comp_lib.h index eda1d59..8f61b1c 100644 --- a/uadk_tool/test/comp_lib.h +++ b/uadk_tool/test/comp_lib.h @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +/* SPDX-License-Identifier: Apache-2.0 */ /* * Copyright 2020-2021 Huawei Technologies Co.,Ltd. All rights reserved. * Copyright 2020-2021 Linaro ltd. @@ -190,35 +190,26 @@ void init_chunk_list(chunk_list_t *list, void *buf, size_t buf_sz, size_t chunk_sz); chunk_list_t *create_chunk_list(void *buf, size_t buf_sz, size_t chunk_sz); void free_chunk_list(chunk_list_t *list); -int sw_deflate(chunk_list_t *in_list, - chunk_list_t *out_list, - struct test_options *opts); -int sw_inflate(chunk_list_t *in_list, - chunk_list_t *out_list, - struct test_options *opts); -int hw_deflate(handle_t h_dfl, - chunk_list_t *in_list, - chunk_list_t *out_list, - struct test_options *opts, - sem_t *sem); -int hw_inflate(handle_t h_ifl, - chunk_list_t *in_list, - chunk_list_t *out_list, - struct test_options *opts, - sem_t *sem); +int sw_deflate(chunk_list_t *in_list, chunk_list_t *out_list, + struct test_options *opts); +int sw_inflate(chunk_list_t *in_list, chunk_list_t *out_list, + struct test_options *opts); +int hw_deflate(handle_t h_dfl, chunk_list_t *in_list, chunk_list_t *out_list, + struct test_options *opts, sem_t *sem); +int hw_inflate(handle_t h_ifl, chunk_list_t *in_list, chunk_list_t *out_list, + struct test_options *opts, sem_t *sem);
int create_threads_tdata(struct test_options *opts, struct hizip_test_info *info); void free_threads_tdata(struct hizip_test_info *info);
int attach_threads(struct test_options *opts, - struct hizip_test_info *info, - void *(*send_thread_func)(void *arg), - void *(*poll_thread_func)(void *arg)); + struct hizip_test_info *info, + void *(*send_thread_func)(void *arg), + void *(*poll_thread_func)(void *arg));
int init_ctx_config(struct test_options *opts, void *priv, - struct wd_sched **sched - ); + struct wd_sched **sched); void uninit_config(void *priv, struct wd_sched *sched); struct uacce_dev_list *get_dev_list(struct test_options *opts, int children);
@@ -248,7 +239,7 @@ static inline int hizip_check_output(void *buf, size_t size, size_t *checked, check_output_fn check_output, void *opaque) { - static bool printed = false; + static bool printed;
if (!printed) { WD_ERR("no zlib available, output buffer won't be checked\n"); @@ -301,7 +292,7 @@ static inline int zlib_deflate(void *output, unsigned int out_size, void *input, " 'b' kills the process after bind\n" \ " 't' tries to access an unmapped buffer\n" \ " 'w' kills the process while the queue is working\n" \ - " --help command help \n\n" + " --help command help\n\n"
int parse_common_option(int argc, char *argv[], struct test_options *opts); diff --git a/uadk_tool/test/comp_main.c b/uadk_tool/test/comp_main.c index 3cf39ac..3bdfea6 100644 --- a/uadk_tool/test/comp_main.c +++ b/uadk_tool/test/comp_main.c @@ -56,14 +56,14 @@ struct hizip_stats { double v[NUM_STATS]; };
-extern int perf_event_open(struct perf_event_attr *attr, - pid_t pid, int cpu, int group_fd, - unsigned long flags); -extern int perf_event_get(const char *event_name, int **perf_fds, int *nr_fds); -extern unsigned long long perf_event_put(int *perf_fds, int nr_fds); -extern void stat_setup(struct hizip_test_info *info); -extern void stat_start(struct hizip_test_info *info); -extern void stat_end(struct hizip_test_info *info); +int perf_event_open(struct perf_event_attr *attr, + pid_t pid, int cpu, int group_fd, + unsigned long flags); +int perf_event_get(const char *event_name, int **perf_fds, int *nr_fds); +unsigned long long perf_event_put(int *perf_fds, int nr_fds); +void stat_setup(struct hizip_test_info *info); +void stat_start(struct hizip_test_info *info); +void stat_end(struct hizip_test_info *info);
static size_t count_chunk_list_sz(chunk_list_t *list) { @@ -146,8 +146,8 @@ static void *sw_dfl_hw_ifl(void *arg) } ret = cmp_md5(&tdata->md5, &final_md5); if (ret) { - COMP_TST_PRT("MD5 is unmatched (%d) at %dth times on " - "thread %d\n", ret, i, tdata->tid); + COMP_TST_PRT("MD5 is unmatched (%d) at %dth times on thread %d\n", + ret, i, tdata->tid); goto out_strm; } } @@ -157,8 +157,8 @@ static void *sw_dfl_hw_ifl(void *arg) }
/* BLOCK mode */ - setup.alg_type = opts->alg_type; - setup.op_type = WD_DIR_DECOMPRESS; + setup.alg_type = opts->alg_type; + setup.op_type = WD_DIR_DECOMPRESS;
param.type = setup.op_type; param.numa_id = 0; @@ -173,7 +173,7 @@ static void *sw_dfl_hw_ifl(void *arg) info->in_chunk_sz); for (i = 0; i < opts->compact_run_num; i++) { init_chunk_list(tlist, tbuf, tbuf_sz, - info->in_chunk_sz * EXPANSION_RATIO); + info->in_chunk_sz * EXPANSION_RATIO); init_chunk_list(tdata->out_list, tdata->dst, tdata->dst_sz, info->out_chunk_sz); ret = sw_deflate(tdata->in_list, tlist, opts); @@ -182,7 +182,7 @@ static void *sw_dfl_hw_ifl(void *arg) goto out_run; } ret = hw_inflate(h_ifl, tlist, tdata->out_list, opts, - &tdata->sem); + &tdata->sem); if (ret) { COMP_TST_PRT("Fail to inflate by HW: %d\n", ret); goto out_run; @@ -199,8 +199,8 @@ static void *sw_dfl_hw_ifl(void *arg) } ret = cmp_md5(&tdata->md5, &final_md5); if (ret) { - COMP_TST_PRT("MD5 is unmatched (%d) at %dth times on " - "thread %d\n", ret, i, tdata->tid); + COMP_TST_PRT("MD5 is unmatched (%d) at %dth times on thread %d\n", + ret, i, tdata->tid); goto out_run; } } @@ -291,8 +291,8 @@ static void *hw_dfl_sw_ifl(void *arg) } ret = cmp_md5(&tdata->md5, &final_md5); if (ret) { - COMP_TST_PRT("MD5 is unmatched (%d) at %dth times on " - "thread %d\n", ret, i, tdata->tid); + COMP_TST_PRT("MD5 is unmatched (%d) at %dth times on thread %d\n", + ret, i, tdata->tid); goto out_strm; } } @@ -302,8 +302,8 @@ static void *hw_dfl_sw_ifl(void *arg) }
/* BLOCK mode */ - setup.alg_type = opts->alg_type; - setup.op_type = WD_DIR_COMPRESS; + setup.alg_type = opts->alg_type; + setup.op_type = WD_DIR_COMPRESS; param.type = setup.op_type; param.numa_id = 0; setup.sched_param = ¶m; @@ -317,11 +317,11 @@ static void *hw_dfl_sw_ifl(void *arg) info->in_chunk_sz); for (i = 0; i < opts->compact_run_num; i++) { init_chunk_list(tlist, tbuf, tbuf_sz, - opts->block_size * EXPANSION_RATIO); + opts->block_size * EXPANSION_RATIO); init_chunk_list(tdata->out_list, tdata->dst, tdata->dst_sz, info->out_chunk_sz); ret = hw_deflate(h_dfl, tdata->in_list, tlist, opts, - &tdata->sem); + &tdata->sem); if (ret) { COMP_TST_PRT("Fail to deflate by HW: %d\n", ret); goto out_run; @@ -343,8 +343,8 @@ static void *hw_dfl_sw_ifl(void *arg) } ret = cmp_md5(&tdata->md5, &final_md5); if (ret) { - COMP_TST_PRT("MD5 is unmatched (%d) at %dth times on " - "thread %d\n", ret, i, tdata->tid); + COMP_TST_PRT("MD5 is unmatched (%d) at %dth times on thread %d\n", + ret, i, tdata->tid); goto out_run; } } @@ -426,8 +426,8 @@ static void *hw_dfl_hw_ifl(void *arg) } ret = cmp_md5(&tdata->md5, &final_md5); if (ret) { - COMP_TST_PRT("MD5 is unmatched (%d) at %dth times on " - "thread %d\n", ret, i, tdata->tid); + COMP_TST_PRT("MD5 is unmatched (%d) at %dth times on thread %d\n", + ret, i, tdata->tid); goto out; } } @@ -443,8 +443,8 @@ static void *hw_dfl_hw_ifl(void *arg) goto out; }
- setup.alg_type = opts->alg_type; - setup.op_type = WD_DIR_COMPRESS; + setup.alg_type = opts->alg_type; + setup.op_type = WD_DIR_COMPRESS; param.type = setup.op_type; param.numa_id = 0; setup.sched_param = ¶m; @@ -465,18 +465,18 @@ static void *hw_dfl_hw_ifl(void *arg)
for (i = 0; i < opts->compact_run_num; i++) { init_chunk_list(tlist, tbuf, tbuf_sz, - opts->block_size * EXPANSION_RATIO); + opts->block_size * EXPANSION_RATIO); init_chunk_list(tdata->out_list, tdata->dst, tdata->dst_sz, info->out_chunk_sz); ret = hw_deflate(h_dfl, tdata->in_list, tlist, opts, - &tdata->sem); + &tdata->sem); if (ret) { COMP_TST_PRT("Fail to deflate by HW: %d\n", ret); goto out_run; } ret = hw_inflate(h_ifl, tlist, tdata->out_list, opts, - &tdata->sem); + &tdata->sem); if (ret) { COMP_TST_PRT("Fail to inflate by HW: %d\n", ret); goto out_run; @@ -493,8 +493,8 @@ static void *hw_dfl_hw_ifl(void *arg) } ret = cmp_md5(&tdata->md5, &final_md5); if (ret) { - COMP_TST_PRT("MD5 is unmatched (%d) at %dth times on " - "thread %d\n", ret, i, tdata->tid); + COMP_TST_PRT("MD5 is unmatched (%d) at %dth times on thread %d\n", + ret, i, tdata->tid); goto out_run; } } @@ -552,8 +552,8 @@ static void *hw_dfl_perf(void *arg) return NULL; }
- setup.alg_type = opts->alg_type; - setup.op_type = WD_DIR_COMPRESS; + setup.alg_type = opts->alg_type; + setup.op_type = WD_DIR_COMPRESS; param.type = setup.op_type; param.numa_id = 0; setup.sched_param = ¶m; @@ -566,7 +566,7 @@ static void *hw_dfl_perf(void *arg) tdata->dst_sz, info->out_chunk_sz); ret = hw_deflate(h_dfl, tdata->in_list, tdata->out_list, opts, - &tdata->sem); + &tdata->sem); if (ret) { COMP_TST_PRT("Fail to deflate by HW(blk): %d\n", ret); goto out; @@ -617,8 +617,8 @@ static void *hw_ifl_perf(void *arg) return NULL; }
- setup.alg_type = opts->alg_type; - setup.op_type = WD_DIR_DECOMPRESS; + setup.alg_type = opts->alg_type; + setup.op_type = WD_DIR_DECOMPRESS; param.type = setup.op_type; param.numa_id = 0; setup.sched_param = ¶m; @@ -631,7 +631,7 @@ static void *hw_ifl_perf(void *arg) tdata->dst_sz, info->out_chunk_sz); ret = hw_inflate(h_ifl, tdata->in_list, tdata->out_list, opts, - &tdata->sem); + &tdata->sem); if (ret) { COMP_TST_PRT("Fail to inflate by HW: %d\n", ret); goto out; @@ -656,9 +656,8 @@ int load_file_data(struct hizip_test_info *info)
file_sz = read(opts->fd_in, info->in_buf, info->in_size); if (file_sz < info->in_size) { - COMP_TST_PRT("Expect to read %ld bytes. " - "But only read %ld bytes!\n", - info->in_size, file_sz); + COMP_TST_PRT("Expect to read %zu bytes, but only read %zu bytes!\n", + info->in_size, file_sz); return -EFAULT; } return (int)file_sz; @@ -678,13 +677,14 @@ int store_file(struct hizip_test_info *info, char *model) if (!opts->is_stream) { COMP_TST_PRT("Invalid, file need stream mode!\n"); return -EINVAL; - } else { - p = tdata->out_list; - file_sz = write(opts->fd_out, p->addr, p->size); - if (file_sz < p->size) - return -EFAULT; - sum = file_sz; } + + p = tdata->out_list; + file_sz = write(opts->fd_out, p->addr, p->size); + if (file_sz < p->size) + return -EFAULT; + sum = file_sz; + return (int)sum; }
@@ -719,17 +719,17 @@ static void uadk_res_uninit(struct test_options *opts, wd_free_list_accels(info->list); }
-static bool event_unavailable = false; +static bool event_unavailable;
static int prepare_src_data(struct test_options *opts, struct hizip_test_info *info, int direction) { + thread_data_t *tdata = info->tdatas; chunk_list_t *tlist = NULL; size_t tbuf_sz = 0; void *tbuf = NULL; int ret;
if (direction) { /* if is inflate, need prepare the compressed data by sw */ - thread_data_t *tdata = info->tdatas; tbuf_sz = info->in_size / EXPANSION_RATIO; tbuf = mmap_alloc(tbuf_sz); if (!tbuf) { @@ -758,7 +758,7 @@ static int prepare_src_data(struct test_options *opts, struct hizip_test_info *i }
static void perfdata_print(struct test_options *opts, struct hizip_test_info *info, - int zbuf_idx, char *zbuf, char *model) + int zbuf_idx, char *zbuf, char *model) { double ilen, usec, speed;
@@ -785,10 +785,10 @@ static void perfdata_print(struct test_options *opts, struct hizip_test_info *in
if (!strcmp(model, "hw_dfl_perf") || !strcmp(model, "hw_ifl_perf")) { COMP_TST_PRT("%s at %.2fMB/s in %f usec (BLK:%d)..\n", - zbuf, speed, usec, opts->block_size); + zbuf, speed, usec, opts->block_size); } else { COMP_TST_PRT("%s in %f usec (BLK:%d)...\n", - zbuf, usec, opts->block_size); + zbuf, usec, opts->block_size); }
} @@ -922,7 +922,7 @@ static int test_hw(struct test_options *opts, char *model) } /* A warning if the parameters might produce false positives */ if (opts->total_len > 0x54000) - COMP_TST_PRT( "NOTE: test might trash the TLB\n"); + COMP_TST_PRT("NOTE: test might trash the TLB\n"); }
stat_start(&info); @@ -1034,7 +1034,7 @@ int run_self_test(struct test_options *opts) "async-comp:8@0,async-decomp:8@0"); setenv("WD_COMP_CTX_NUM", poll_str, 1); memset(poll_str, 0, POLL_STRING_LEN); - sprintf(poll_str, "%d@0", opts->poll_num), + sprintf(poll_str, "%d@0", opts->poll_num); setenv("WD_COMP_ASYNC_POLL_NUM", poll_str, 1); } f_ret |= test_hw(opts, "sw_dfl_hw_ifl"); @@ -1127,8 +1127,7 @@ int run_cmd(struct test_options *opts) if (WIFEXITED(status)) { ret = WEXITSTATUS(status); if (ret) { - COMP_TST_PRT("child %d returned with %d\n", - pid, ret); + COMP_TST_PRT("child %d returned with %d\n", pid, ret); success = false; } } else if (WIFSIGNALED(status)) { @@ -1145,14 +1144,16 @@ int run_cmd(struct test_options *opts) if (!ret) ret = -EINVAL; } - } else + } else { ret = run_one_cmd(opts); + } + return ret; }
int perf_event_open(struct perf_event_attr *attr, - pid_t pid, int cpu, int group_fd, - unsigned long flags) + pid_t pid, int cpu, int group_fd, + unsigned long flags) { return syscall(__NR_perf_event_open, attr, pid, cpu, group_fd, flags); } @@ -1294,27 +1295,27 @@ void stat_end(struct hizip_test_info *info)
stats->v[ST_SETUP_TIME] = (info->tv.start_time.tv_sec - info->tv.setup_time.tv_sec) * 1000000000 + - info->tv.start_time.tv_nsec - - info->tv.setup_time.tv_nsec; + info->tv.start_time.tv_nsec - + info->tv.setup_time.tv_nsec; stats->v[ST_RUN_TIME] = (info->tv.end_time.tv_sec - info->tv.start_time.tv_sec) * 1000000000 + - info->tv.end_time.tv_nsec - - info->tv.start_time.tv_nsec; + info->tv.end_time.tv_nsec - + info->tv.start_time.tv_nsec;
stats->v[ST_CPU_TIME] = (info->tv.end_cputime.tv_sec - info->tv.setup_cputime.tv_sec) * 1000000000 + - info->tv.end_cputime.tv_nsec - - info->tv.setup_cputime.tv_nsec; + info->tv.end_cputime.tv_nsec - + info->tv.setup_cputime.tv_nsec; stats->v[ST_USER_TIME] = (info->tv.end_rusage.ru_utime.tv_sec - info->tv.setup_rusage.ru_utime.tv_sec) * - 1000000 + - info->tv.end_rusage.ru_utime.tv_usec - - info->tv.setup_rusage.ru_utime.tv_usec; + 1000000 + + info->tv.end_rusage.ru_utime.tv_usec - + info->tv.setup_rusage.ru_utime.tv_usec; stats->v[ST_SYSTEM_TIME] = (info->tv.end_rusage.ru_stime.tv_sec - info->tv.setup_rusage.ru_stime.tv_sec) * - 1000000 + - info->tv.end_rusage.ru_stime.tv_usec - - info->tv.setup_rusage.ru_stime.tv_usec; + 1000000 + + info->tv.end_rusage.ru_stime.tv_usec - + info->tv.setup_rusage.ru_stime.tv_usec;
stats->v[ST_MINFLT] = info->tv.end_rusage.ru_minflt - info->tv.setup_rusage.ru_minflt; @@ -1331,12 +1332,12 @@ void stat_end(struct hizip_test_info *info)
/* check last loop is enough, same as below hizip_verify_output */ stats->v[ST_COMPRESSION_RATIO] = (double)opts->total_len / - total_out * 100; + total_out * 100;
total_len = opts->total_len * opts->compact_run_num; /* ST_RUN_TIME records nanoseconds */ stats->v[ST_SPEED] = (total_len * opts->thread_num * 1000) / - (1.024 * 1.024 * stats->v[ST_RUN_TIME]); + (1.024 * 1.024 * stats->v[ST_RUN_TIME]);
stats->v[ST_TOTAL_SPEED] = (total_len * opts->thread_num * 1000) / ((stats->v[ST_RUN_TIME] + @@ -1350,7 +1351,7 @@ void stat_end(struct hizip_test_info *info) static void handle_sigbus(int sig) { COMP_TST_PRT("SIGBUS!\n"); - _exit(0); + _exit(0); }
int test_comp_entry(int argc, char *argv[])
When testing the async encryption performance of the AEAD algorithm, the same bd_pool may not be processed completely and is sent as a new request in the next loop. As a result, incorrect encrypted data is stored in the dst. When the incorrect encrypted data is stored for decryption, a decryption error occurs.
This problem can be solved by restricting the sending times of the first bd_pool only once and saving the dst data in the first bd_pool to a file for decryption.
Signed-off-by: Qi Tao taoqi10@huawei.com --- uadk_tool/benchmark/sec_uadk_benchmark.c | 6 ++++++ uadk_tool/benchmark/uadk_benchmark.h | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/uadk_tool/benchmark/sec_uadk_benchmark.c b/uadk_tool/benchmark/sec_uadk_benchmark.c index 411d0c4..469ef8b 100644 --- a/uadk_tool/benchmark/sec_uadk_benchmark.c +++ b/uadk_tool/benchmark/sec_uadk_benchmark.c @@ -1356,6 +1356,12 @@ static void *sec_uadk_aead_async(void *arg) break; try_cnt = 0; i = count % MAX_POOL_LENTH; + + if (i == 0 && count > 0) { + count++; + continue; + } + areq.src = uadk_pool->bds[i].src; areq.dst = uadk_pool->bds[i].dst; areq.mac = uadk_pool->bds[i].mac; diff --git a/uadk_tool/benchmark/uadk_benchmark.h b/uadk_tool/benchmark/uadk_benchmark.h index 0def4b9..6d82905 100644 --- a/uadk_tool/benchmark/uadk_benchmark.h +++ b/uadk_tool/benchmark/uadk_benchmark.h @@ -32,7 +32,7 @@ #define MAX_DEVICE_NAME 64
#define MAX_BLOCK_NM 16384 /* BLOCK_NUM must 4 times of POOL_LENTH */ -#define MAX_POOL_LENTH 4096 +#define MAX_POOL_LENTH 8192 #define MAX_TRY_CNT 5000 #define SEND_USLEEP 100 #define SEC_2_USEC 1000000