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;