deflate work ./sample/uadk_comp --lib /tmp/build/lib/libhisi_zlib.so --drv hisi_zlib --optype 0 --alg gzip <Makefile >out
infalte still has issue(zlib error -5 - (null)), for demo purpose ./sample/uadk_comp --lib /tmp/build/lib/libhisi_zlib.so --drv hisi_zlib --optype 1 --alg gzip <out >dst
vimdiff Makefile dst
Signed-off-by: Zhangfei Gao zhangfei.gao@linaro.org --- include/wd_comp.h | 3 ++ libwd_comp.map | 2 ++ sample/uadk_comp.c | 58 ++++++++++++++++++++++++------- wd_comp.c | 86 +++++++++++++++++++++++++++++++++++----------- 4 files changed, 117 insertions(+), 32 deletions(-)
diff --git a/include/wd_comp.h b/include/wd_comp.h index 45b0d0b..2774eb4 100644 --- a/include/wd_comp.h +++ b/include/wd_comp.h @@ -256,6 +256,9 @@ void wd_comp_ctx_num_uninit(void); int wd_comp_get_env_param(__u32 node, __u32 type, __u32 mode, __u32 *num, __u8 *is_enable);
+int wd_comp_attach_worker(char *lib_path, char *drv_name, char *alg_name); +void wd_comp_stop_worker(void); + #ifdef __cplusplus } #endif diff --git a/libwd_comp.map b/libwd_comp.map index ce3e051..01a20ca 100644 --- a/libwd_comp.map +++ b/libwd_comp.map @@ -37,5 +37,7 @@ global: wd_inflateReset; wd_inflateEnd;
+ wd_comp_attach_worker; + wd_comp_stop_worker; local: *; }; diff --git a/sample/uadk_comp.c b/sample/uadk_comp.c index 908c7bc..9b9e593 100644 --- a/sample/uadk_comp.c +++ b/sample/uadk_comp.c @@ -21,6 +21,8 @@
struct request_config { char algname[MAX_ALG_LEN]; + char drvname[MAX_ALG_LEN]; + char libname[MAX_ALG_LEN]; enum wd_comp_alg_type alg; enum wd_comp_level complv; enum wd_comp_op_type optype; @@ -127,6 +129,18 @@ out: return NULL; }
+static struct uacce_dev_list *get_dev_list_from_drv(char *drv_name, char *alg_name) +{ + /* Todo + * need realize wd_get_accel_list(const char *drv_name) + */ + + // hack for simple + if (!drv_name || (strcmp(drv_name, "hisi_zlib") == 0)) + return NULL; + else + return get_dev_list(alg_name); +} static int lib_poll_func(__u32 pos, __u32 expect, __u32 *count) { int ret; @@ -386,10 +400,19 @@ static int operation(FILE *source, FILE *dest) { int ret;
- ret = uadk_comp_ctx_init(); - if (ret) { - fprintf(stderr, "%s fail to init ctx!\n", __func__); - return ret; + if (config.list) { + /* only hardware accelerator need ctx and sched for queue resource */ + ret = uadk_comp_ctx_init(); + if (ret) { + fprintf(stderr, "%s fail to init ctx!\n", __func__); + return ret; + } + } else { + ret = wd_comp_attach_worker(config.libname, config.drvname, config.algname); + if (ret) { + fprintf(stderr, "%s fail to attach worker!\n", __func__); + return ret; + } }
ret = uadk_comp_sess_init(); @@ -420,7 +443,11 @@ out_sess_uninit: uadk_comp_sess_uninit();
out_ctx_uninit: - uadk_comp_ctx_uninit(); + + if (config.list) + uadk_comp_ctx_uninit(); + else + wd_comp_stop_worker();
return ret; } @@ -438,6 +465,8 @@ static void print_help(void) "The window size for compression(8K as default).\n" "\t[--complv]: " "The compression level(8 as default).\n" + "\t[--drv]: The driver using for the alg.\n" + "\t[--lib]: shared library of the driver.\n" "\t[--help] " "Print Help (this message) and exit\n" ""); @@ -455,6 +484,9 @@ int main(int argc, char *argv[]) {"complv", required_argument, 0, 2}, {"optype", required_argument, 0, 3}, {"winsize", required_argument, 0, 4}, + {"drv", required_argument, 0, 5}, + {"lib", required_argument, 0, 6}, + {0, 0, 0, 0} };
@@ -468,13 +500,7 @@ int main(int argc, char *argv[]) help = 1; break; case 1: - config.list = get_dev_list(optarg); - if (!config.list) { - cowfail("Can't find your algorithm!\n"); - help = 1; - } else { - strcpy(config.algname, optarg); - } + strcpy(config.algname, optarg); break; case 2: config.complv = strtol(optarg, NULL, 0); @@ -485,6 +511,12 @@ int main(int argc, char *argv[]) case 4: config.winsize = strtol(optarg, NULL, 0); break; + case 5: + strcpy(config.drvname, optarg); + break; + case 6: + strcpy(config.libname, optarg); + break; default: help = 1; cowfail("bad input test parameter!\n"); @@ -497,6 +529,8 @@ int main(int argc, char *argv[]) exit(-1); }
+ config.list = get_dev_list_from_drv(config.drvname, config.algname); + ret = operation(stdin, stdout); if (ret) cowfail("So sad for we do something wrong!\n"); diff --git a/wd_comp.c b/wd_comp.c index 03e4ea1..ad9e006 100644 --- a/wd_comp.c +++ b/wd_comp.c @@ -63,6 +63,45 @@ static void wd_comp_close_driver(void) } }
+int wd_comp_attach_worker(char *lib_path, char *drv_name, char *alg_name) +{ + struct wd_alg_driver *adapter = wd_comp_setting.driver; + int ret; + + if (!adapter) { + wd_comp_setting.driver = adapter = uadk_adapter_alloc(); + if (!adapter) + return -WD_EINVAL; + } + + ret = uadk_adapter_parse(adapter, lib_path, drv_name, alg_name); + if (ret) { + uadk_adapter_free(adapter); + WD_ERR("failed to parse adapter\n"); + return -WD_EINVAL; + } + + ret = wd_alg_driver_init(adapter, NULL); + if (ret) { + uadk_adapter_free(adapter); + WD_ERR("failed to init adapter\n"); + return -WD_EINVAL; + } + + return 0; +} + +void wd_comp_stop_worker(void) +{ + struct wd_alg_driver *adapter = wd_comp_setting.driver; + + if (adapter) { + wd_alg_driver_exit(adapter); + uadk_adapter_free(adapter); + wd_comp_setting.driver = NULL; + } +} + static int wd_comp_open_driver(void) { struct wd_alg_driver *adapter = NULL; @@ -430,12 +469,14 @@ handle_t wd_comp_alloc_sess(struct wd_comp_sess_setup *setup) sess->win_sz = setup->win_sz; sess->stream_pos = WD_COMP_STREAM_NEW;
- /* Some simple scheduler don't need scheduling parameters */ - sess->sched_key = (void *)wd_comp_setting.sched.sched_init( - wd_comp_setting.sched.h_sched_ctx, setup->sched_param); - if (WD_IS_ERR(sess->sched_key)) { - WD_ERR("failed to init session schedule key!\n"); - goto sched_err; + if (wd_comp_setting.sched.sched_init) { + /* Some simple scheduler don't need scheduling parameters */ + sess->sched_key = (void *)wd_comp_setting.sched.sched_init( + wd_comp_setting.sched.h_sched_ctx, setup->sched_param); + if (WD_IS_ERR(sess->sched_key)) { + WD_ERR("failed to init session schedule key!\n"); + goto sched_err; + } }
return (handle_t)sess; @@ -569,23 +610,28 @@ static int wd_comp_sync_job(struct wd_comp_sess *sess, __u32 idx; int ret;
- idx = wd_comp_setting.sched.pick_next_ctx(h_sched_ctx, - sess->sched_key, - CTX_MODE_SYNC); - ret = wd_check_ctx(config, CTX_MODE_SYNC, idx); - if (unlikely(ret)) - return ret; - - wd_dfx_msg_cnt(config->msg_cnt, WD_CTX_CNT_NUM, idx); - ctx = config->ctxs + idx; - msg_handle.send = wd_comp_setting.driver->send; msg_handle.recv = wd_comp_setting.driver->recv;
- pthread_spin_lock(&ctx->lock); - ret = wd_handle_msg_sync(wd_comp_setting.driver, &msg_handle, ctx->ctx, msg, - NULL, config->epoll_en); - pthread_spin_unlock(&ctx->lock); + if (wd_comp_setting.sched.pick_next_ctx) { + idx = wd_comp_setting.sched.pick_next_ctx(h_sched_ctx, + sess->sched_key, + CTX_MODE_SYNC); + ret = wd_check_ctx(config, CTX_MODE_SYNC, idx); + if (unlikely(ret)) + return ret; + + wd_dfx_msg_cnt(config->msg_cnt, WD_CTX_CNT_NUM, idx); + ctx = config->ctxs + idx; + + pthread_spin_lock(&ctx->lock); + ret = wd_handle_msg_sync(wd_comp_setting.driver, &msg_handle, ctx->ctx, msg, + NULL, config->epoll_en); + pthread_spin_unlock(&ctx->lock); + } else { + ret = wd_handle_msg_sync(wd_comp_setting.driver, &msg_handle, 0, msg, + NULL, config->epoll_en); + }
return ret; }