wd_env_set_ctx_nums is used to parse the configuration information about the number of CTXs from a specific environment variable and set the configuration information to the ctx_nums array.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- include/wd_util.h | 8 ++++++ wd_util.c | 66 +++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 72 insertions(+), 2 deletions(-)
diff --git a/include/wd_util.h b/include/wd_util.h index a730f36..434f068 100644 --- a/include/wd_util.h +++ b/include/wd_util.h @@ -482,6 +482,14 @@ void wd_dlclose_drv(void *dlh_list); */ int wd_get_lib_file_path(char *lib_file, char *lib_path, bool is_dir);
+/** + * wd_env_set_ctx_ctx_nums() - Set the ctx_set_num by parsing the environment variable. + * @name: the name of the environment variable. + * @ctx_nums: array to be initialized. + * @size: array size. + */ +int wd_env_set_ctx_nums(const char *name, struct wd_ctx_nums *ctx_nums, __u32 size); + /** * wd_dfx_msg_cnt() - Message counter interface for ctx * @msg: Shared memory addr. diff --git a/wd_util.c b/wd_util.c index dab4fc8..b8a3355 100644 --- a/wd_util.c +++ b/wd_util.c @@ -2017,8 +2017,10 @@ int wd_ctx_param_init(struct wd_ctx_params *ctx_params, }
for (i = 0; i < ctx_params->op_type_num; i++) { - ctx_set_num[i].sync_ctx_num = driver->queue_num; - ctx_set_num[i].async_ctx_num = driver->queue_num; + if (!ctx_set_num[i].sync_ctx_num || !ctx_set_num[i].async_ctx_num) { + ctx_set_num[i].sync_ctx_num = driver->queue_num; + ctx_set_num[i].async_ctx_num = driver->queue_num; + } } } else { ctx_params->bmp = user_ctx_params->bmp; @@ -2581,3 +2583,63 @@ void wd_alg_attrs_uninit(struct wd_init_attrs *attrs) wd_sched_rr_release(alg_sched); }
+static int wd_set_ctx_nums(struct wd_ctx_nums *ctx_nums, const char *section, + __u32 op_type_num, int is_comp) +{ + int i, j, ctx_num, node, ret; + char *ctx_section; + const char *type; + + if (is_comp && op_type_num > ARRAY_SIZE(comp_ctx_type)) + return -WD_EINVAL; + + ctx_section = index(section, ':'); + ctx_section++; + ret = parse_num_on_numa(ctx_section, &ctx_num, &node); + if (ret) + return ret; + + for (i = 0; i < CTX_MODE_MAX; i++) { + for (j = 0; j < op_type_num; j++) { + type = is_comp ? comp_ctx_type[i][j] : ctx_type[i][0]; + if (strncmp(section, type, strlen(type))) + continue; + + if (!i) + ctx_nums[j].sync_ctx_num = ctx_num; + else + ctx_nums[j].async_ctx_num = ctx_num; + + return 0; + } + } + + return -WD_EINVAL; +} + +int wd_env_set_ctx_nums(const char *name, struct wd_ctx_nums *ctx_nums, __u32 size) +{ + char *left, *section, *start, *var_s; + int ret, is_comp; + + is_comp = strncmp(name, "WD_COMP_CTX_NUM", strlen(name)) ? 0 : 1; + + var_s = secure_getenv(name); + if (!var_s || !strlen(var_s)) + return 0; + + start = strdup(var_s); + if (!start) + return -WD_ENOMEM; + + left = start; + while ((section = strsep(&left, ","))) { + ret = wd_set_ctx_nums(ctx_nums, section, size, is_comp); + if (ret) + goto out_free_str; + } + +out_free_str: + free(start); + return ret; +}