diff --git a/Makefile.am b/Makefile.am index b38c5ce6..ef719914 100644 --- a/Makefile.am +++ b/Makefile.am @@ -40,8 +40,8 @@ pkginclude_HEADERS = include/wd.h include/wd_internal.h include/wd_cipher.h incl include/wd_udma.h include/wd_join_gather.h \ include/wd_bmm.h -nobase_pkginclude_HEADERS = v1/wd.h v1/wd_cipher.h v1/wd_aead.h v1/uacce.h v1/wd_dh.h \ - v1/wd_digest.h v1/wd_rsa.h v1/wd_bmm.h +nobase_pkginclude_HEADERS=v1/wd.h v1/wd_cipher.h v1/wd_aead.h v1/wd_dh.h v1/wd_digest.h \ + v1/wd_rsa.h v1/wd_bmm.h v1/wd_ecc.h v1/wd_comp.h lib_LTLIBRARIES=libwd.la libwd_comp.la libwd_crypto.la libwd_dae.la libwd_udma.la @@ -120,20 +120,20 @@ if WD_STATIC_DRV AM_CFLAGS += -DWD_STATIC_DRV -fPIC AM_CFLAGS += -DWD_NO_LOG -libwd_la_LIBADD = $(libwd_la_OBJECTS) -ldl -lnuma +libwd_la_LIBADD = $(libwd_la_OBJECTS) -ldl -lnuma -lpthread -lrt -libwd_comp_la_LIBADD = $(libwd_la_OBJECTS) -ldl -lnuma +libwd_comp_la_LIBADD = $(libwd_la_OBJECTS) -ldl -lnuma -lpthread libwd_comp_la_DEPENDENCIES = libwd.la -libhisi_zip_la_LIBADD = -ldl +libhisi_zip_la_LIBADD = -ldl -lpthread -libwd_crypto_la_LIBADD = -lwd -ldl -lnuma -lm -lpthread +libwd_crypto_la_LIBADD = -lwd -ldl -lnuma -lpthread libwd_crypto_la_DEPENDENCIES = libwd.la libwd_udma_la_LIBADD = $(libwd_la_OBJECTS) -ldl -lnuma -lm -lpthread libwd_udma_la_DEPENDENCIES = libwd.la -libwd_dae_la_LIBADD = $(libwd_la_OBJECTS) -ldl -lnuma +libwd_dae_la_LIBADD = $(libwd_la_OBJECTS) -ldl -lnuma -lm -lpthread libwd_dae_la_DEPENDENCIES = libwd.la libhisi_sec_la_LIBADD = $(libwd_la_OBJECTS) $(libwd_crypto_la_OBJECTS) @@ -164,19 +164,19 @@ UADK_V1_SYMBOL= -Wl,--version-script,$(top_srcdir)/v1/libwd.map libwd_la_LDFLAGS=$(UADK_VERSION) $(UADK_WD_SYMBOL) $(UADK_V1_SYMBOL) libwd_la_LIBADD= -ldl -lnuma -libwd_comp_la_LIBADD= -lwd -ldl -lnuma -libwd_comp_la_LDFLAGS=$(UADK_VERSION) $(UADK_COMP_SYMBOL) -lpthread +libwd_comp_la_LIBADD= -lwd -ldl -lnuma -lpthread +libwd_comp_la_LDFLAGS=$(UADK_VERSION) $(UADK_COMP_SYMBOL) libwd_comp_la_DEPENDENCIES= libwd.la -libwd_crypto_la_LIBADD= -lwd -ldl -lnuma -libwd_crypto_la_LDFLAGS=$(UADK_VERSION) $(UADK_CRYPTO_SYMBOL) -lpthread +libwd_crypto_la_LIBADD= -lwd -ldl -lnuma -lpthread +libwd_crypto_la_LDFLAGS=$(UADK_VERSION) $(UADK_CRYPTO_SYMBOL) libwd_crypto_la_DEPENDENCIES= libwd.la libwd_udma_la_LIBADD= -lwd -ldl -lnuma -lm -lpthread libwd_udma_la_LDFLAGS=$(UADK_VERSION) $(UADK_DAE_SYMBOL) libwd_udma_la_DEPENDENCIES= libwd.la -libwd_dae_la_LIBADD= -lwd -ldl -lnuma -lm +libwd_dae_la_LIBADD= -lwd -ldl -lnuma -lm -lpthread libwd_dae_la_LDFLAGS=$(UADK_VERSION) $(UADK_DAE_SYMBOL) libwd_dae_la_DEPENDENCIES= libwd.la diff --git a/docs/wd_environment_variable b/docs/wd_environment_variable index 828208aa..914def34 100644 --- a/docs/wd_environment_variable +++ b/docs/wd_environment_variable @@ -13,13 +13,6 @@ offer process level WD configures. 1. WD environment variables define ================================== -WD__ASYNC_POLL_EN ----------------------- - - Define if enble polling threads in WD. WD__ASYNC_POLL_EN=1 means enable - polling threads in WD, otherwise caller should poll finished request by - WD APIs. - WD_COMP_CTX_NUM ----------------- diff --git a/include/wd_aead.h b/include/wd_aead.h index 4b5095f9..3585c862 100644 --- a/include/wd_aead.h +++ b/include/wd_aead.h @@ -254,7 +254,8 @@ void wd_aead_ctx_num_uninit(void); * @type: operation type. * @mode: 0: sync mode, 1: async mode * @num: return ctx num. - * @is_enable return enable inner poll flag. + * @is_enable: return enable inner poll flag, inner poll is not + * supported, and is_enable will always be 0. * * If the current algorithm library does not require the type parameter, * the type parameter is invalid. The function returns 0 to indicate that diff --git a/include/wd_cipher.h b/include/wd_cipher.h index a6f8be12..383d3153 100644 --- a/include/wd_cipher.h +++ b/include/wd_cipher.h @@ -218,7 +218,8 @@ void wd_cipher_ctx_num_uninit(void); * @type: operation type. * @mode: 0: sync mode, 1: async mode * @num: return ctx num. - * @is_enable return enable inner poll flag. + * @is_enable: return enable inner poll flag, inner poll is not + * supported, and is_enable will always be 0. */ int wd_cipher_get_env_param(__u32 node, __u32 type, __u32 mode, __u32 *num, __u8 *is_enable); diff --git a/include/wd_comp.h b/include/wd_comp.h index 5d095369..2cbefd74 100644 --- a/include/wd_comp.h +++ b/include/wd_comp.h @@ -251,7 +251,8 @@ void wd_comp_ctx_num_uninit(void); * @type: operation type. * @mode: 0: sync mode, 1: async mode * @num: return ctx num. - * @is_enable return enable inner poll flag. + * @is_enable: return enable inner poll flag, inner poll is not + * supported, and is_enable will always be 0. * * If the current algorithm library does not require the type parameter, * the type parameter is invalid. The function returns 0 to indicate that diff --git a/include/wd_digest.h b/include/wd_digest.h index 42a95db3..410c7f99 100644 --- a/include/wd_digest.h +++ b/include/wd_digest.h @@ -278,7 +278,8 @@ void wd_digest_ctx_num_uninit(void); * @type: operation type. * @mode: 0: sync mode, 1: async mode * @num: return ctx num. - * @is_enable return enable inner poll flag. + * @is_enable: return enable inner poll flag, inner poll is not + * supported, and is_enable will always be 0. */ int wd_digest_get_env_param(__u32 node, __u32 type, __u32 mode, __u32 *num, __u8 *is_enable); diff --git a/include/wd_ecc.h b/include/wd_ecc.h index 18c1c0d0..d8689510 100644 --- a/include/wd_ecc.h +++ b/include/wd_ecc.h @@ -548,7 +548,8 @@ void wd_ecc_ctx_num_uninit(void); * @type: operation type. * @mode: 0: sync mode, 1: async mode * @num: return ctx num. - * @is_enable return enable inner poll flag. + * @is_enable: return enable inner poll flag, inner poll is not + * supported, and is_enable will always be 0. */ int wd_ecc_get_env_param(__u32 node, __u32 type, __u32 mode, __u32 *num, __u8 *is_enable); diff --git a/include/wd_rsa.h b/include/wd_rsa.h index 9c914325..b0ead0a7 100644 --- a/include/wd_rsa.h +++ b/include/wd_rsa.h @@ -239,7 +239,8 @@ void wd_rsa_ctx_num_uninit(void); * @type: operation type. * @mode: 0: sync mode, 1: async mode * @num: return ctx num. - * @is_enable return enable inner poll flag. + * @is_enable: return enable inner poll flag, inner poll is not + * supported, and is_enable will always be 0. */ int wd_rsa_get_env_param(__u32 node, __u32 type, __u32 mode, __u32 *num, __u8 *is_enable); diff --git a/include/wd_util.h b/include/wd_util.h index 2abceec2..56dd9bab 100644 --- a/include/wd_util.h +++ b/include/wd_util.h @@ -27,6 +27,10 @@ extern "C" { for ((i) = 0, (config_numa) = (config)->config_per_numa; \ (i) < (config)->numa_num; (config_numa)++, (i)++) +#define COMP_ALG "comp" +#define CTX_COMP_ALG "zlib-comp gzip-comp deflate-comp lz77_zstd-comp lz4-comp lz77_only-comp" +#define CTX_DECOMP_ALG "zlib-decomp gzip-decomp deflate-decomp lz77_zstd-decomp lz4-decomp lz77_only-decomp" + enum wd_status { WD_UNINIT, WD_INITING, @@ -78,16 +82,10 @@ struct wd_env_config_per_numa { /* Resource begin */ struct uacce_dev *dev; int dev_num; - /* This can be made statically currently */ - unsigned long async_poll_num; - void *async_task_queue_array; }; struct wd_env_config { struct wd_env_config_per_numa *config_per_numa; - /* Let's make it as a gobal config, not per numa */ - bool enable_internal_poll; - /* resource config */ struct wd_sched *sched; bool internal_sched; @@ -270,28 +268,6 @@ int wd_check_datalist(struct wd_datalist *head, __u64 size); */ int wd_parse_ctx_num(struct wd_env_config *config, const char *s); -/* - * wd_parse_async_poll_en() - Parse async polling thread related environment - * variable and store it. - * @config: Pointer of wd_env_config which is used to store environment - * variable information. - * @s: Related environment variable string. - * - * More information, please see docs/wd_environment_variable. - */ -int wd_parse_async_poll_en(struct wd_env_config *config, const char *s); - -/* - * wd_parse_async_poll_num() - Parse async polling thread related environment - * variable and store it. - * @config: Pointer of wd_env_config which is used to store environment - * variable information. - * @s: Related environment variable string. - * - * More information, please see docs/wd_environment_variable. - */ -int wd_parse_async_poll_num(struct wd_env_config *config, const char *s); - /* * wd_alg_env_init() - Init wd algorithm environment variable configurations. * This is a help function which can be used by specific @@ -320,15 +296,6 @@ int wd_alg_env_init(struct wd_env_config *env_config, void wd_alg_env_uninit(struct wd_env_config *env_config, const struct wd_alg_ops *ops); -/* - * wd_add_task_to_async_queue() - Add an async request to its related async - * task queue. - * @config: Pointer of wd_env_config which is used to store environment - * variable information. - * @idx: Index of ctx in config. - */ -int wd_add_task_to_async_queue(struct wd_env_config *config, __u32 idx); - /* * dump_env_info() - dump wd algorithm ctx info. * @config: Pointer of wd_env_config which is used to store environment diff --git a/test/sanity_test.sh b/test/sanity_test.sh index e7650934..50ba77f4 100755 --- a/test/sanity_test.sh +++ b/test/sanity_test.sh @@ -397,8 +397,6 @@ run_zip_test_v2() return 0 fi export WD_COMP_CTX_NUM="sync-comp:4@0,sync-decomp:4@0,async-comp:4@0,async-decomp:4@0" - export WD_COMP_ASYNC_POLL_EN=1 - export WD_COMP_ASYNC_POLL_NUM="4@0" # test without environment variables # limit test text file in 8MB rm -fr /tmp/textfile diff --git a/uadk_tool/benchmark/zip_uadk_benchmark.c b/uadk_tool/benchmark/zip_uadk_benchmark.c index 092f7108..d0f1795f 100644 --- a/uadk_tool/benchmark/zip_uadk_benchmark.c +++ b/uadk_tool/benchmark/zip_uadk_benchmark.c @@ -803,12 +803,19 @@ static void free_uadk_bd_pool(void) static int init_uadk_rsv_pool(struct acc_option *option) { struct wd_mempool_setup pool_setup; - char *alg = option->algclass; + char alg[CRYPTO_MAX_ALG_NAME]; u32 insize = g_pktlen; handle_t h_ctx; u32 outsize; int i, j; + if (option->optype == 1) + snprintf(alg, CRYPTO_MAX_ALG_NAME - 1, "%s-decomp", + option->algclass); + else + snprintf(alg, CRYPTO_MAX_ALG_NAME - 1, "%s-comp", + option->algclass); + h_ctx = wd_find_ctx(alg); if (!h_ctx) { ZIP_TST_PRT("failed to find a ctx for alg: %s\n", option->algname); diff --git a/v1/drv/hisi_zip_udrv.c b/v1/drv/hisi_zip_udrv.c index d4e5dc44..b73a9293 100644 --- a/v1/drv/hisi_zip_udrv.c +++ b/v1/drv/hisi_zip_udrv.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "v1/wd_util.h" #include "v1/wd_comp.h" #include "v1/wd_cipher.h" @@ -132,21 +133,27 @@ struct zip_fill_sqe_ops { void (*fill_sqe_hw_info)(void *ssqe, struct wcrypto_comp_msg *msg); }; -static unsigned int g_err_print_enable = 1; +static timer_t g_timerid; +static sig_atomic_t g_err_print_enable = 1; -static void zip_err_print_alarm_end(int sig) +static void zip_err_print_alarm_end(union sigval sv) { - if (sig == SIGALRM) { - g_err_print_enable = 1; - alarm(0); - } + timer_delete(g_timerid); + g_err_print_enable = 1; } static void zip_err_print_time_start(void) { - g_err_print_enable = 0; - signal(SIGALRM, zip_err_print_alarm_end); - alarm(PRINT_TIME_INTERVAL); + struct itimerspec its = {0}; + struct sigevent sev = {0}; + + sev.sigev_notify = SIGEV_THREAD; + sev.sigev_notify_function = zip_err_print_alarm_end; + sev.sigev_value.sival_ptr = &g_timerid; + timer_create(CLOCK_REALTIME, &sev, &g_timerid); + + its.it_value.tv_sec = PRINT_TIME_INTERVAL; + timer_settime(g_timerid, 0, &its, NULL); } static void zip_err_bd_print(__u16 ctx_st, __u32 status, __u32 type) @@ -155,6 +162,7 @@ static void zip_err_bd_print(__u16 ctx_st, __u32 status, __u32 type) WD_ERR("bad status(ctx_st=0x%x, s=0x%x, t=%u)\n", ctx_st, status, type); } else if (g_err_print_enable == 1) { + g_err_print_enable = 0; WD_ERR("bad status(ctx_st=0x%x, s=0x%x, t=%u)\n", ctx_st, status, type); zip_err_print_time_start(); diff --git a/v1/wd.c b/v1/wd.c index bab2712f..f008695f 100644 --- a/v1/wd.c +++ b/v1/wd.c @@ -18,12 +18,12 @@ #include #include #include +#include #include #include #include #include #include -#include #include #include diff --git a/v1/wd_util.c b/v1/wd_util.c index eae148b0..cb9c9603 100644 --- a/v1/wd_util.c +++ b/v1/wd_util.c @@ -156,7 +156,7 @@ void wd_free_id(__u8 *buf, __u32 size, __u32 id, __u32 id_max) int wd_init_cookie_pool(struct wd_cookie_pool *pool, __u32 cookies_size, __u32 cookies_num) { - __u64 total_size = cookies_size * cookies_num; + __u64 total_size = (__u64)cookies_size * cookies_num; pool->cookies = calloc(1, total_size + cookies_num); if (!pool->cookies) diff --git a/wd_aead.c b/wd_aead.c index 74d652bf..a9e6279a 100644 --- a/wd_aead.c +++ b/wd_aead.c @@ -413,8 +413,7 @@ static void cleanup_session(struct wd_aead_sess *sess) sess->mm_ops.free(sess->mm_ops.usr, sess->ckey); sess->mm_ops.free(sess->mm_ops.usr, sess->akey); - if (sess) - free(sess); + free(sess); } static int wd_aead_sess_eops_init(struct wd_aead_sess *sess) @@ -960,9 +959,6 @@ int wd_do_aead_async(handle_t h_sess, struct wd_aead_req *req) } wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx); - ret = wd_add_task_to_async_queue(&wd_aead_env_config, idx); - if (ret) - goto fail_with_msg; return 0; @@ -1042,15 +1038,10 @@ int wd_aead_poll(__u32 expt, __u32 *count) return sched->poll_policy(h_ctx, expt, count); } -static const struct wd_config_variable table[] = { - { .name = "WD_AEAD_CTX_NUM", - .def_val = "sync:2@0,async:2@0", - .parse_fn = wd_parse_ctx_num - }, - { .name = "WD_AEAD_ASYNC_POLL_EN", - .def_val = "0", - .parse_fn = wd_parse_async_poll_en - } +static const struct wd_config_variable table = { + .name = "WD_AEAD_CTX_NUM", + .def_val = "sync:2@0,async:2@0", + .parse_fn = wd_parse_ctx_num }; static const struct wd_alg_ops wd_aead_ops = { @@ -1065,8 +1056,8 @@ int wd_aead_env_init(struct wd_sched *sched) { wd_aead_env_config.sched = sched; - return wd_alg_env_init(&wd_aead_env_config, table, - &wd_aead_ops, ARRAY_SIZE(table), NULL); + return wd_alg_env_init(&wd_aead_env_config, &table, + &wd_aead_ops, 1, NULL); } void wd_aead_env_uninit(void) @@ -1083,8 +1074,8 @@ int wd_aead_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode) if (ret) return ret; - return wd_alg_env_init(&wd_aead_env_config, table, - &wd_aead_ops, ARRAY_SIZE(table), &ctx_attr); + return wd_alg_env_init(&wd_aead_env_config, &table, + &wd_aead_ops, 1, &ctx_attr); } void wd_aead_ctx_num_uninit(void) diff --git a/wd_cipher.c b/wd_cipher.c index 1c54d729..5258191f 100644 --- a/wd_cipher.c +++ b/wd_cipher.c @@ -805,9 +805,6 @@ int wd_do_cipher_async(handle_t h_sess, struct wd_cipher_req *req) } wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx); - ret = wd_add_task_to_async_queue(&wd_cipher_env_config, idx); - if (ret) - goto fail_with_msg; return 0; @@ -888,15 +885,10 @@ int wd_cipher_poll(__u32 expt, __u32 *count) return sched->poll_policy(h_ctx, expt, count); } -static const struct wd_config_variable table[] = { - { .name = "WD_CIPHER_CTX_NUM", - .def_val = "sync:2@0,async:2@0", - .parse_fn = wd_parse_ctx_num - }, - { .name = "WD_CIPHER_ASYNC_POLL_EN", - .def_val = "0", - .parse_fn = wd_parse_async_poll_en - } +static const struct wd_config_variable table = { + .name = "WD_CIPHER_CTX_NUM", + .def_val = "sync:2@0,async:2@0", + .parse_fn = wd_parse_ctx_num }; static const struct wd_alg_ops wd_cipher_ops = { @@ -911,8 +903,8 @@ int wd_cipher_env_init(struct wd_sched *sched) { wd_cipher_env_config.sched = sched; - return wd_alg_env_init(&wd_cipher_env_config, table, - &wd_cipher_ops, ARRAY_SIZE(table), NULL); + return wd_alg_env_init(&wd_cipher_env_config, &table, + &wd_cipher_ops, 1, NULL); } void wd_cipher_env_uninit(void) @@ -929,8 +921,8 @@ int wd_cipher_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode) if (ret) return ret; - return wd_alg_env_init(&wd_cipher_env_config, table, - &wd_cipher_ops, ARRAY_SIZE(table), &ctx_attr); + return wd_alg_env_init(&wd_cipher_env_config, &table, + &wd_cipher_ops, 1, &ctx_attr); } void wd_cipher_ctx_num_uninit(void) diff --git a/wd_comp.c b/wd_comp.c index 00445b29..7a2b0bc2 100644 --- a/wd_comp.c +++ b/wd_comp.c @@ -148,7 +148,7 @@ static int wd_comp_init_nolock(struct wd_ctx_config *config, struct wd_sched *sc if (ret < 0) return ret; - wd_comp_setting.config.alg_name = "zlib gzip deflate lz77_zstd lz4 lz77_only"; + wd_comp_setting.config.alg_name = COMP_ALG; ret = wd_init_ctx_config(&wd_comp_setting.config, config); if (ret < 0) return ret; @@ -883,9 +883,6 @@ int wd_do_comp_async(handle_t h_sess, struct wd_comp_req *req) } wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx); - ret = wd_add_task_to_async_queue(&wd_comp_env_config, idx); - if (unlikely(ret)) - goto fail_with_msg; return 0; @@ -911,19 +908,10 @@ int wd_comp_poll(__u32 expt, __u32 *count) return sched->poll_policy(h_sched_ctx, expt, count); } -static const struct wd_config_variable table[] = { - { .name = "WD_COMP_CTX_NUM", - .def_val = "sync-comp:1@0,sync-decomp:1@0,async-comp:1@0,async-decomp:1@0", - .parse_fn = wd_parse_ctx_num - }, - { .name = "WD_COMP_ASYNC_POLL_EN", - .def_val = "0", - .parse_fn = wd_parse_async_poll_en - }, - { .name = "WD_COMP_ASYNC_POLL_NUM", - .def_val = "1@0", - .parse_fn = wd_parse_async_poll_num - } +static const struct wd_config_variable table = { + .name = "WD_COMP_CTX_NUM", + .def_val = "sync-comp:1@0,sync-decomp:1@0,async-comp:1@0,async-decomp:1@0", + .parse_fn = wd_parse_ctx_num }; static const struct wd_alg_ops wd_comp_ops = { @@ -938,8 +926,8 @@ int wd_comp_env_init(struct wd_sched *sched) { wd_comp_env_config.sched = sched; - return wd_alg_env_init(&wd_comp_env_config, table, - &wd_comp_ops, ARRAY_SIZE(table), NULL); + return wd_alg_env_init(&wd_comp_env_config, &table, + &wd_comp_ops, 1, NULL); } void wd_comp_env_uninit(void) @@ -961,8 +949,8 @@ int wd_comp_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode) if (ret) return ret; - return wd_alg_env_init(&wd_comp_env_config, table, - &wd_comp_ops, ARRAY_SIZE(table), &ctx_attr); + return wd_alg_env_init(&wd_comp_env_config, &table, + &wd_comp_ops, 1, &ctx_attr); } void wd_comp_ctx_num_uninit(void) diff --git a/wd_dh.c b/wd_dh.c index 0c1372c5..9a0176b8 100644 --- a/wd_dh.c +++ b/wd_dh.c @@ -446,9 +446,6 @@ int wd_do_dh_async(handle_t sess, struct wd_dh_req *req) } wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx); - ret = wd_add_task_to_async_queue(&wd_dh_env_config, idx); - if (ret) - goto fail_with_msg; return WD_SUCCESS; @@ -659,15 +656,10 @@ void wd_dh_free_sess(handle_t sess) free(sess_t); } -static const struct wd_config_variable table[] = { - { .name = "WD_DH_CTX_NUM", - .def_val = "sync:2@0,async:2@0", - .parse_fn = wd_parse_ctx_num - }, - { .name = "WD_DH_ASYNC_POLL_EN", - .def_val = "0", - .parse_fn = wd_parse_async_poll_en - } +static const struct wd_config_variable table = { + .name = "WD_DH_CTX_NUM", + .def_val = "sync:2@0,async:2@0", + .parse_fn = wd_parse_ctx_num }; static const struct wd_alg_ops wd_dh_ops = { @@ -682,8 +674,8 @@ int wd_dh_env_init(struct wd_sched *sched) { wd_dh_env_config.sched = sched; - return wd_alg_env_init(&wd_dh_env_config, table, - &wd_dh_ops, ARRAY_SIZE(table), NULL); + return wd_alg_env_init(&wd_dh_env_config, &table, + &wd_dh_ops, 1, NULL); } void wd_dh_env_uninit(void) @@ -700,8 +692,8 @@ int wd_dh_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode) if (ret) return ret; - return wd_alg_env_init(&wd_dh_env_config, table, - &wd_dh_ops, ARRAY_SIZE(table), &ctx_attr); + return wd_alg_env_init(&wd_dh_env_config, &table, + &wd_dh_ops, 1, &ctx_attr); } void wd_dh_ctx_num_uninit(void) diff --git a/wd_digest.c b/wd_digest.c index 0b37f8ba..e0341e6b 100644 --- a/wd_digest.c +++ b/wd_digest.c @@ -759,9 +759,6 @@ int wd_do_digest_async(handle_t h_sess, struct wd_digest_req *req) } wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx); - ret = wd_add_task_to_async_queue(&wd_digest_env_config, idx); - if (ret) - goto fail_with_msg; return 0; @@ -843,15 +840,10 @@ int wd_digest_poll(__u32 expt, __u32 *count) return sched->poll_policy(h_ctx, expt, count); } -static const struct wd_config_variable table[] = { - { .name = "WD_DIGEST_CTX_NUM", - .def_val = "sync:2@0,async:2@0", - .parse_fn = wd_parse_ctx_num - }, - { .name = "WD_DIGEST_ASYNC_POLL_EN", - .def_val = "0", - .parse_fn = wd_parse_async_poll_en - } +static const struct wd_config_variable table = { + .name = "WD_DIGEST_CTX_NUM", + .def_val = "sync:2@0,async:2@0", + .parse_fn = wd_parse_ctx_num }; static const struct wd_alg_ops wd_digest_ops = { @@ -866,8 +858,8 @@ int wd_digest_env_init(struct wd_sched *sched) { wd_digest_env_config.sched = sched; - return wd_alg_env_init(&wd_digest_env_config, table, - &wd_digest_ops, ARRAY_SIZE(table), NULL); + return wd_alg_env_init(&wd_digest_env_config, &table, + &wd_digest_ops, 1, NULL); } void wd_digest_env_uninit(void) @@ -884,8 +876,8 @@ int wd_digest_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode) if (ret) return ret; - return wd_alg_env_init(&wd_digest_env_config, table, - &wd_digest_ops, ARRAY_SIZE(table), &ctx_attr); + return wd_alg_env_init(&wd_digest_env_config, &table, + &wd_digest_ops, 1, &ctx_attr); } void wd_digest_ctx_num_uninit(void) diff --git a/wd_ecc.c b/wd_ecc.c index 2c88d0a1..dae8a05d 100644 --- a/wd_ecc.c +++ b/wd_ecc.c @@ -2348,9 +2348,6 @@ int wd_do_ecc_async(handle_t sess, struct wd_ecc_req *req) } wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx); - ret = wd_add_task_to_async_queue(&wd_ecc_env_config, idx); - if (ret) - goto fail_with_msg; return WD_SUCCESS; @@ -2430,15 +2427,10 @@ int wd_ecc_poll(__u32 expt, __u32 *count) return wd_ecc_setting.sched.poll_policy(h_sched_sess, expt, count); } -static const struct wd_config_variable table[] = { - { .name = "WD_ECC_CTX_NUM", - .def_val = "sync:2@0,async:2@0", - .parse_fn = wd_parse_ctx_num - }, - { .name = "WD_ECC_ASYNC_POLL_EN", - .def_val = "0", - .parse_fn = wd_parse_async_poll_en - } +static const struct wd_config_variable table = { + .name = "WD_ECC_CTX_NUM", + .def_val = "sync:2@0,async:2@0", + .parse_fn = wd_parse_ctx_num }; static const struct wd_alg_ops wd_ecc_ops = { @@ -2453,8 +2445,8 @@ int wd_ecc_env_init(struct wd_sched *sched) { wd_ecc_env_config.sched = sched; - return wd_alg_env_init(&wd_ecc_env_config, table, - &wd_ecc_ops, ARRAY_SIZE(table), NULL); + return wd_alg_env_init(&wd_ecc_env_config, &table, + &wd_ecc_ops, 1, NULL); } void wd_ecc_env_uninit(void) @@ -2471,8 +2463,8 @@ int wd_ecc_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode) if (ret) return ret; - return wd_alg_env_init(&wd_ecc_env_config, table, - &wd_ecc_ops, ARRAY_SIZE(table), &ctx_attr); + return wd_alg_env_init(&wd_ecc_env_config, &table, + &wd_ecc_ops, 1, &ctx_attr); } void wd_ecc_ctx_num_uninit(void) diff --git a/wd_rsa.c b/wd_rsa.c index bc78c6ac..93ec3364 100644 --- a/wd_rsa.c +++ b/wd_rsa.c @@ -507,9 +507,6 @@ int wd_do_rsa_async(handle_t sess, struct wd_rsa_req *req) } wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx); - ret = wd_add_task_to_async_queue(&wd_rsa_env_config, idx); - if (ret) - goto fail_with_msg; return WD_SUCCESS; @@ -1271,15 +1268,10 @@ void wd_rsa_get_prikey(handle_t sess, struct wd_rsa_prikey **prikey) *prikey = ((struct wd_rsa_sess *)sess)->prikey; } -static const struct wd_config_variable table[] = { - { .name = "WD_RSA_CTX_NUM", - .def_val = "sync:2@0,async:2@0", - .parse_fn = wd_parse_ctx_num - }, - { .name = "WD_RSA_ASYNC_POLL_EN", - .def_val = "0", - .parse_fn = wd_parse_async_poll_en - } +static const struct wd_config_variable table = { + .name = "WD_RSA_CTX_NUM", + .def_val = "sync:2@0,async:2@0", + .parse_fn = wd_parse_ctx_num }; static const struct wd_alg_ops wd_rsa_ops = { @@ -1294,8 +1286,8 @@ int wd_rsa_env_init(struct wd_sched *sched) { wd_rsa_env_config.sched = sched; - return wd_alg_env_init(&wd_rsa_env_config, table, - &wd_rsa_ops, ARRAY_SIZE(table), NULL); + return wd_alg_env_init(&wd_rsa_env_config, &table, + &wd_rsa_ops, 1, NULL); } void wd_rsa_env_uninit(void) @@ -1312,8 +1304,8 @@ int wd_rsa_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode) if (ret) return ret; - return wd_alg_env_init(&wd_rsa_env_config, table, - &wd_rsa_ops, ARRAY_SIZE(table), &ctx_attr); + return wd_alg_env_init(&wd_rsa_env_config, &table, + &wd_rsa_ops, 1, &ctx_attr); } void wd_rsa_ctx_num_uninit(void) diff --git a/wd_util.c b/wd_util.c index bf82fc14..707cdb5f 100644 --- a/wd_util.c +++ b/wd_util.c @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include "wd_sched.h" @@ -72,27 +71,6 @@ static const char *wd_env_name[WD_TYPE_MAX] = { "WD_JOIN_GATHER_CTX_NUM", }; -struct async_task { - __u32 idx; -}; - -struct async_task_queue { - struct async_task *head; - int depth; - /* the producer offset of task queue */ - int prod; - /* the consumer offset of task queue */ - int cons; - int cur_task; - int left_task; - int end; - sem_t empty_sem; - sem_t full_sem; - pthread_mutex_t lock; - pthread_t tid; - int (*alg_poll_ctx)(__u32, __u32, __u32 *); -}; - struct drv_lib_list { void *dlhandle; struct drv_lib_list *next; @@ -264,6 +242,7 @@ int wd_init_ctx_config(struct wd_ctx_config_internal *in, struct wd_ctx_config *cfg) { struct wd_ctx_internal *ctxs; + char *alg_name; __u32 i, j; int ret; @@ -296,7 +275,15 @@ int wd_init_ctx_config(struct wd_ctx_config_internal *in, goto err_out; } - ret = wd_insert_ctx_list(cfg->ctxs[i].ctx, in->alg_name); + alg_name = in->alg_name; + if (strcmp(in->alg_name, COMP_ALG) == 0) { + if (cfg->ctxs[i].op_type == 0) + alg_name = CTX_COMP_ALG; + else + alg_name = CTX_DECOMP_ALG; + } + + ret = wd_insert_ctx_list(cfg->ctxs[i].ctx, alg_name); if (ret) { WD_ERR("failed to add ctx to mem list!\n"); goto err_out; @@ -328,6 +315,9 @@ int wd_init_sched(struct wd_sched *in, struct wd_sched *from) in->h_sched_ctx = from->h_sched_ctx; in->name = strdup(from->name); + if (!in->name) + return -WD_ENOMEM; + in->sched_init = from->sched_init; in->pick_next_ctx = from->pick_next_ctx; in->poll_policy = from->poll_policy; @@ -782,17 +772,6 @@ static int str_to_bool(const char *s, bool *target) return 0; } -int wd_parse_async_poll_en(struct wd_env_config *config, const char *s) -{ - int ret; - - ret = str_to_bool(s, &config->enable_internal_poll); - if (ret) - WD_ERR("failed to parse async poll enable flag(%s)!\n", s); - - return ret; -} - static int parse_num_on_numa(const char *s, int *num, int *node) { char *sep, *start, *left; @@ -1034,41 +1013,6 @@ int wd_parse_ctx_num(struct wd_env_config *config, const char *s) return parse_ctx_num(config, s); } -int wd_parse_async_poll_num(struct wd_env_config *config, const char *s) -{ - struct wd_env_config_per_numa *config_numa; - char *left, *section, *start; - int node, poll_num, ret; - - if (!config->enable_internal_poll) { - WD_ERR("internal poll not enabled, skip parse poll number!\n"); - return 0; - } - - start = strdup(s); - if (!start) - return -ENOMEM; - - left = start; - while ((section = strsep(&left, ","))) { - ret = parse_num_on_numa(section, &poll_num, &node); - if (ret) - goto out; - config_numa = wd_get_config_numa(config, node); - if (!config_numa) { - ret = -WD_EINVAL; - goto out; - } - config_numa->async_poll_num = poll_num; - } - - free(start); - return 0; -out: - free(start); - return ret; -} - static int wd_parse_env(struct wd_env_config *config) { const struct wd_config_variable *var; @@ -1117,8 +1061,6 @@ static int wd_parse_ctx_attr(struct wd_env_config *env_config, /* Use default sched and disable internal poll */ env_config->sched = NULL; - env_config->enable_internal_poll = 0; - config_numa->async_poll_num = 0; return 0; } @@ -1345,21 +1287,17 @@ static int wd_init_sched_config(struct wd_env_config *config, { struct wd_env_config_per_numa *config_numa; int i, j, ret, max_node, type_num; - void *func = NULL; type_num = config->op_type_num; max_node = numa_max_node() + 1; if (max_node <= 0) return -WD_EINVAL; - if (!config->enable_internal_poll) - func = alg_poll_ctx; - config->internal_sched = false; if (!config->sched) { WD_ERR("no sched is specified, alloc a default sched!\n"); config->sched = wd_sched_rr_alloc(SCHED_POLICY_RR, type_num, - max_node, func); + max_node, alg_poll_ctx); if (!config->sched) return -WD_ENOMEM; @@ -1386,339 +1324,6 @@ static int wd_init_sched_config(struct wd_env_config *config, return ret; } -static struct async_task_queue *find_async_queue(struct wd_env_config *config, - __u32 idx) -{ - struct wd_env_config_per_numa *config_numa; - struct wd_ctx_range **ctx_table; - struct async_task_queue *head; - unsigned long offset = 0; - __u32 i, num = 0; - - FOREACH_NUMA(i, config, config_numa) { - num += config_numa->sync_ctx_num + config_numa->async_ctx_num; - if (idx < num) - break; - } - - if (i == config->numa_num) { - WD_ERR("failed to find a proper numa node!\n"); - return NULL; - } - - if (!config_numa->async_poll_num) { - WD_ERR("invalid: async_poll_num of numa is zero!\n"); - return NULL; - } - - ctx_table = config_numa->ctx_table; - for (i = 0; i < config_numa->op_type_num; i++) { - if (idx <= ctx_table[CTX_MODE_ASYNC][i].end && - idx >= ctx_table[CTX_MODE_ASYNC][i].begin) { - offset = (idx - ctx_table[CTX_MODE_ASYNC][i].begin) % - config_numa->async_poll_num; - break; - } - } - - if (i == config_numa->op_type_num) { - WD_ERR("failed to find async queue for ctx: idx %u!\n", idx); - return NULL; - } - - head = (struct async_task_queue *)config_numa->async_task_queue_array; - - return head + offset; -} - -int wd_add_task_to_async_queue(struct wd_env_config *config, __u32 idx) -{ - struct async_task_queue *task_queue; - struct async_task *task; - int curr_prod, ret; - - if (!config->enable_internal_poll) - return 0; - - task_queue = find_async_queue(config, idx); - if (!task_queue) - return -WD_EINVAL; - - ret = sem_wait(&task_queue->empty_sem); - if (ret) { - WD_ERR("failed to wait empty_sem!\n"); - return ret; - } - - pthread_mutex_lock(&task_queue->lock); - - /* get an available async task and fill ctx idx */ - curr_prod = task_queue->prod; - task = task_queue->head + curr_prod; - task->idx = idx; - - /* update global information of task queue */ - task_queue->prod = (curr_prod + 1) % task_queue->depth; - task_queue->cur_task++; - task_queue->left_task--; - - pthread_mutex_unlock(&task_queue->lock); - - ret = sem_post(&task_queue->full_sem); - if (ret) { - WD_ERR("failed to post full_sem!\n"); - goto err_out; - } - - return 0; - -err_out: - pthread_mutex_lock(&task_queue->lock); - task_queue->left_task++; - task_queue->cur_task--; - task_queue->prod = curr_prod; - pthread_mutex_unlock(&task_queue->lock); - sem_post(&task_queue->empty_sem); - - return ret; -} - -static void *async_poll_process_func(void *args) -{ - struct async_task_queue *task_queue = args; - struct async_task *head, *task; - __u32 count; - int cons, ret; - - while (1) { - if (sem_wait(&task_queue->full_sem)) { - if (errno == EINTR) { - continue; - } - } - if (__atomic_load_n(&task_queue->end, __ATOMIC_ACQUIRE)) { - __atomic_store_n(&task_queue->end, 0, __ATOMIC_RELEASE); - goto out; - } - - pthread_mutex_lock(&task_queue->lock); - - /* async sending message isn't submitted yet */ - if (task_queue->cons == task_queue->prod) { - pthread_mutex_unlock(&task_queue->lock); - sem_post(&task_queue->full_sem); - continue; - } - - cons = task_queue->cons; - head = task_queue->head; - task = head + cons; - - task_queue->cons = (cons + 1) % task_queue->depth; - task_queue->cur_task--; - task_queue->left_task++; - - pthread_mutex_unlock(&task_queue->lock); - - ret = task_queue->alg_poll_ctx(task->idx, 1, &count); - if (ret < 0) { - pthread_mutex_lock(&task_queue->lock); - task_queue->cons = cons; - task_queue->cur_task++; - task_queue->left_task--; - pthread_mutex_unlock(&task_queue->lock); - if (ret == -WD_EAGAIN) { - sem_post(&task_queue->full_sem); - continue; - } else - goto out; - } - - if (sem_post(&task_queue->empty_sem)) - goto out; - } -out: - return NULL; -} - -static int wd_init_one_task_queue(struct async_task_queue *task_queue, - void *alg_poll_ctx) - -{ - struct async_task *head; - pthread_t thread_id; - pthread_attr_t attr; - int depth, ret; - - task_queue->depth = depth = WD_ASYNC_DEF_QUEUE_DEPTH; - - head = calloc(task_queue->depth, sizeof(*head)); - if (!head) - return -WD_ENOMEM; - - task_queue->head = head; - task_queue->left_task = depth; - task_queue->alg_poll_ctx = alg_poll_ctx; - - if (sem_init(&task_queue->empty_sem, 0, depth)) { - WD_ERR("failed to init empty_sem!\n"); - goto err_free_head; - } - - if (sem_init(&task_queue->full_sem, 0, 0)) { - WD_ERR("failed to init full_sem!\n"); - goto err_uninit_empty_sem; - } - - if (pthread_mutex_init(&task_queue->lock, NULL)) { - WD_ERR("failed to init task queue's mutex lock!\n"); - goto err_uninit_full_sem; - } - - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - task_queue->tid = 0; - if (pthread_create(&thread_id, &attr, async_poll_process_func, - task_queue)) { - WD_ERR("failed to create poll thread!\n"); - goto err_destory_mutex; - } - - task_queue->tid = thread_id; - pthread_attr_destroy(&attr); - - return 0; - -err_destory_mutex: - pthread_attr_destroy(&attr); - pthread_mutex_destroy(&task_queue->lock); -err_uninit_full_sem: - sem_destroy(&task_queue->full_sem); -err_uninit_empty_sem: - sem_destroy(&task_queue->empty_sem); -err_free_head: - free(head); - ret = -errno; - return ret; -} - -static void wd_uninit_one_task_queue(struct async_task_queue *task_queue) -{ - /* - * If there's no async task, async_poll_process_func() is sleeping - * on task_queue->full_sem. It'll cause that threads could not - * be end and memory leak. - */ - sem_post(&task_queue->full_sem); - __atomic_store_n(&task_queue->end, 1, __ATOMIC_RELEASE); - while (__atomic_load_n(&task_queue->end, __ATOMIC_ACQUIRE)) - sched_yield(); - - pthread_mutex_destroy(&task_queue->lock); - sem_destroy(&task_queue->full_sem); - sem_destroy(&task_queue->empty_sem); - free(task_queue->head); - task_queue->head = NULL; -} - -static int wd_init_async_polling_thread_per_numa(struct wd_env_config *config, - struct wd_env_config_per_numa *config_numa, - void *alg_poll_ctx) -{ - struct async_task_queue *task_queue, *queue_head; - int i, j, ret; - double num; - - if (!config_numa->async_ctx_num) - return 0; - - if (!config_numa->async_poll_num) { - WD_ERR("invalid async poll num (%lu) is set.\n", - config_numa->async_poll_num); - WD_ERR("change to default value: %d\n", WD_ASYNC_DEF_POLL_NUM); - config_numa->async_poll_num = WD_ASYNC_DEF_POLL_NUM; - } - - num = MIN(config_numa->async_poll_num, config_numa->async_ctx_num); - - /* make max task queues as the number of async ctxs */ - queue_head = calloc(config_numa->async_ctx_num, sizeof(*queue_head)); - if (!queue_head) - return -WD_ENOMEM; - - task_queue = queue_head; - for (i = 0; i < num; task_queue++, i++) { - ret = wd_init_one_task_queue(task_queue, alg_poll_ctx); - if (ret) { - for (j = 0; j < i; task_queue++, j++) - wd_uninit_one_task_queue(task_queue); - free(queue_head); - return ret; - } - } - - config_numa->async_task_queue_array = (void *)queue_head; - - return 0; -} - -static void wd_uninit_async_polling_thread_per_numa(struct wd_env_config *cfg, - struct wd_env_config_per_numa *config_numa) -{ - struct async_task_queue *task_queue, *head; - double num; - int i; - - if (!config_numa || !config_numa->async_task_queue_array) - return; - - head = config_numa->async_task_queue_array; - task_queue = head; - num = MIN(config_numa->async_poll_num, config_numa->async_ctx_num); - - for (i = 0; i < num; task_queue++, i++) - wd_uninit_one_task_queue(task_queue); - free(head); - config_numa->async_task_queue_array = NULL; -} - -static int wd_init_async_polling_thread(struct wd_env_config *config, - void *alg_poll_ctx) -{ - struct wd_env_config_per_numa *config_numa; - int i, ret; - - if (!config->enable_internal_poll) - return 0; - - FOREACH_NUMA(i, config, config_numa) { - ret = wd_init_async_polling_thread_per_numa(config, config_numa, - alg_poll_ctx); - if (ret) - goto out; - } - - return 0; - -out: - FOREACH_NUMA(i, config, config_numa) - wd_uninit_async_polling_thread_per_numa(config, config_numa); - - return ret; -} - -static void wd_uninit_async_polling_thread(struct wd_env_config *config) -{ - struct wd_env_config_per_numa *config_numa; - int i; - - if (!config->enable_internal_poll) - return; - - FOREACH_NUMA(i, config, config_numa) - wd_uninit_async_polling_thread_per_numa(config, config_numa); -} - static int wd_init_resource(struct wd_env_config *config, const struct wd_alg_ops *ops) { @@ -1736,14 +1341,8 @@ static int wd_init_resource(struct wd_env_config *config, if (ret) goto err_uninit_sched; - ret = wd_init_async_polling_thread(config, ops->alg_poll_ctx); - if (ret) - goto err_uninit_alg; - return 0; -err_uninit_alg: - ops->alg_uninit(); err_uninit_sched: wd_uninit_sched_config(config); err_uninit_ctx: @@ -1754,7 +1353,6 @@ static int wd_init_resource(struct wd_env_config *config, static void wd_uninit_resource(struct wd_env_config *config, const struct wd_alg_ops *ops) { - wd_uninit_async_polling_thread(config); ops->alg_uninit(); wd_uninit_sched_config(config); wd_free_ctx(config); @@ -1808,7 +1406,7 @@ int wd_alg_get_env_param(struct wd_env_config *env_config, return -WD_EINVAL; } - *is_enable = env_config->enable_internal_poll; + *is_enable = 0; config_numa = wd_get_config_numa(env_config, attr.node); if (!config_numa) @@ -2104,13 +1702,13 @@ static int wd_env_set_ctx_nums(const char *alg_name, const char *name, const cha ret = wd_get_alg_type(alg_name, alg_type); if (ret) - return ret; + goto free_start; list = wd_get_accel_list(alg_type); if (!list) { WD_ERR("failed to get devices!\n"); - free(start); - return -WD_ENODEV; + ret = -WD_ENODEV; + goto free_start; } left = start; @@ -2121,6 +1719,7 @@ static int wd_env_set_ctx_nums(const char *alg_name, const char *name, const cha } wd_free_list_accels(list); +free_start: free(start); return ret; }