Three policies are customized for numa configuration:
1.If a node is enabled, all nodes share the same configuration.
user input: sync-comp:5@0,sync-decomp:3@2
real set: sync-comp:5@0,sync-comp:5@2,sync-decomp:0@2,sync-decomp:3@2
2.If there are same type configurations, use the maximum ctx number.
user input: sync-comp:5@0,sync-comp:3@2
real set: sync-comp:5@0,sync-comp:5@2
3.If the number of queues is 0, ignore this configuration.
user input: sync-comp:0@0,sync-comp:3@2
real set: sync-comp:3@2
Signed-off-by: Wenkai Lin <linwenkai6(a)hisilicon.com>
---
wd_cipher.c | 13 +++++++++++--
wd_comp.c | 14 +++++++++++++-
wd_dh.c | 12 +++++++++++-
wd_ecc.c | 12 +++++++++++-
wd_rsa.c | 12 +++++++++++-
wd_util.c | 25 ++++++++++++++++---------
6 files changed, 73 insertions(+), 15 deletions(-)
diff --git a/wd_cipher.c b/wd_cipher.c
index e7c2007..77d81ea 100644
--- a/wd_cipher.c
+++ b/wd_cipher.c
@@ -384,6 +384,7 @@ int wd_cipher_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_p
{
struct wd_ctx_nums cipher_ctx_num[WD_CIPHER_DECRYPTION + 1] = {0};
struct wd_ctx_params cipher_ctx_params = {0};
+ struct bitmask *inner_bmp;
int ret = 0;
bool flag;
@@ -411,6 +412,13 @@ int wd_cipher_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_p
goto out_uninit;
}
+ cipher_ctx_params.bmp = inner_bmp = numa_allocate_nodemask();
+ if (!inner_bmp) {
+ WD_ERR("fail to allocate nodemask.\n");
+ ret = -WD_ENOMEM;
+ goto out_dlopen;
+ }
+
res_retry:
memset(&wd_cipher_setting.config, 0, sizeof(struct wd_ctx_config_internal));
@@ -419,10 +427,9 @@ res_retry:
if (!wd_cipher_setting.driver) {
WD_ERR("fail to bind a valid driver.\n");
ret = -WD_EINVAL;
- goto out_dlopen;
+ goto out_bmp;
}
-
cipher_ctx_params.ctx_set_num = cipher_ctx_num;
ret = wd_ctx_param_init(&cipher_ctx_params, ctx_params,
wd_cipher_setting.driver,
@@ -459,6 +466,8 @@ res_retry:
out_driver:
wd_alg_drv_unbind(wd_cipher_setting.driver);
+out_bmp:
+ numa_free_nodemask(inner_bmp);
out_dlopen:
wd_dlclose_drv(wd_cipher_setting.dlh_list);
out_uninit:
diff --git a/wd_comp.c b/wd_comp.c
index ed1d128..4d6fbb3 100644
--- a/wd_comp.c
+++ b/wd_comp.c
@@ -206,6 +206,7 @@ int wd_comp_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_par
{
struct wd_ctx_nums comp_ctx_num[WD_DIR_MAX] = {0};
struct wd_ctx_params comp_ctx_params;
+ struct bitmask *inner_bmp;
int ret = 0;
bool flag;
@@ -233,6 +234,13 @@ int wd_comp_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_par
goto out_uninit;
}
+ comp_ctx_params.bmp = inner_bmp = numa_allocate_nodemask();
+ if (!inner_bmp) {
+ WD_ERR("fail to allocate nodemask.\n");
+ ret = -WD_ENOMEM;
+ goto out_dlopen;
+ }
+
res_retry:
memset(&wd_comp_setting.config, 0, sizeof(struct wd_ctx_config_internal));
@@ -240,7 +248,7 @@ res_retry:
wd_comp_setting.driver = wd_alg_drv_bind(task_type, alg);
if (!wd_comp_setting.driver) {
WD_ERR("fail to bind a valid driver.\n");
- goto out_dlopen;
+ goto out_bmp;
}
comp_ctx_params.ctx_set_num = comp_ctx_num;
@@ -274,10 +282,14 @@ res_retry:
wd_alg_set_init(&wd_comp_setting.status);
+ numa_free_nodemask(inner_bmp);
+
return 0;
out_driver:
wd_alg_drv_unbind(wd_comp_setting.driver);
+out_bmp:
+ numa_free_nodemask(inner_bmp);
out_dlopen:
wd_dlclose_drv(wd_comp_setting.dlh_list);
out_uninit:
diff --git a/wd_dh.c b/wd_dh.c
index 7c57449..be0346b 100644
--- a/wd_dh.c
+++ b/wd_dh.c
@@ -197,6 +197,7 @@ int wd_dh_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_param
{
struct wd_ctx_nums dh_ctx_num[WD_DH_PHASE2] = {0};
struct wd_ctx_params dh_ctx_params = {0};
+ struct bitmask *inner_bmp;
bool flag;
int ret;
@@ -224,6 +225,13 @@ int wd_dh_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_param
goto out_clear_init;
}
+ dh_ctx_params.bmp = inner_bmp = numa_allocate_nodemask();
+ if (!inner_bmp) {
+ ret = -WD_ENOMEM;
+ WD_ERR("fail to allocate nodemask.\n");
+ goto out_dlopen;
+ }
+
res_retry:
memset(&wd_dh_setting.config, 0, sizeof(struct wd_ctx_config_internal));
@@ -232,7 +240,7 @@ res_retry:
if (!wd_dh_setting.driver) {
WD_ERR("fail to bind a valid driver.\n");
ret = -WD_EINVAL;
- goto out_dlopen;
+ goto out_bmp;
}
dh_ctx_params.ctx_set_num = dh_ctx_num;
@@ -270,6 +278,8 @@ res_retry:
out_driver:
wd_alg_drv_unbind(wd_dh_setting.driver);
+out_bmp:
+ numa_free_nodemask(inner_bmp);
out_dlopen:
wd_dlclose_drv(wd_dh_setting.dlh_list);
out_clear_init:
diff --git a/wd_ecc.c b/wd_ecc.c
index fbe2d16..f1a3f0d 100644
--- a/wd_ecc.c
+++ b/wd_ecc.c
@@ -253,6 +253,7 @@ int wd_ecc_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_para
{
struct wd_ctx_nums ecc_ctx_num[WD_EC_OP_MAX] = {0};
struct wd_ctx_params ecc_ctx_params = {0};
+ struct bitmask *inner_bmp;
bool flag;
int ret;
@@ -280,6 +281,13 @@ int wd_ecc_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_para
goto out_clear_init;
}
+ ecc_ctx_params.bmp = inner_bmp = numa_allocate_nodemask();
+ if (!inner_bmp) {
+ WD_ERR("fail to allocate nodemask.\n");
+ ret = -WD_ENOMEM;
+ goto out_dlopen;
+ }
+
res_retry:
memset(&wd_ecc_setting.config, 0, sizeof(struct wd_ctx_config_internal));
@@ -288,7 +296,7 @@ res_retry:
if (!wd_ecc_setting.driver) {
WD_ERR("failed to bind a valid driver!\n");
ret = -WD_EINVAL;
- goto out_dlopen;
+ goto out_bmp;
}
ecc_ctx_params.ctx_set_num = ecc_ctx_num;
@@ -326,6 +334,8 @@ res_retry:
out_driver:
wd_alg_drv_unbind(wd_ecc_setting.driver);
+out_bmp:
+ numa_free_nodemask(inner_bmp);
out_dlopen:
wd_dlclose_drv(wd_ecc_setting.dlh_list);
out_clear_init:
diff --git a/wd_rsa.c b/wd_rsa.c
index 64c833b..7b62017 100644
--- a/wd_rsa.c
+++ b/wd_rsa.c
@@ -238,6 +238,7 @@ int wd_rsa_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_para
{
struct wd_ctx_nums rsa_ctx_num[WD_RSA_GENKEY] = {0};
struct wd_ctx_params rsa_ctx_params = {0};
+ struct bitmask *inner_bmp;
bool flag;
int ret;
@@ -265,6 +266,13 @@ int wd_rsa_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_para
goto out_clear_init;
}
+ rsa_ctx_params.bmp = inner_bmp = numa_allocate_nodemask();
+ if (!inner_bmp) {
+ WD_ERR("fail to allocate nodemask.\n");
+ ret = -WD_ENOMEM;
+ goto out_dlopen;
+ }
+
res_retry:
memset(&wd_rsa_setting.config, 0, sizeof(struct wd_ctx_config_internal));
@@ -273,7 +281,7 @@ res_retry:
if (!wd_rsa_setting.driver) {
WD_ERR("failed to bind a valid driver!\n");
ret = -WD_EINVAL;
- goto out_dlopen;
+ goto out_bmp;
}
rsa_ctx_params.ctx_set_num = rsa_ctx_num;
@@ -311,6 +319,8 @@ res_retry:
out_driver:
wd_alg_drv_unbind(wd_rsa_setting.driver);
+out_bmp:
+ numa_free_nodemask(inner_bmp);
out_dlopen:
wd_dlclose_drv(wd_rsa_setting.dlh_list);
out_clear_init:
diff --git a/wd_util.c b/wd_util.c
index fe5ece2..9b5486b 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -21,6 +21,7 @@
#define WD_RECV_MAX_CNT_NOSLEEP 200000000
#define PRIVILEGE_FLAG 600
#define MIN(a, b) ((a) > (b) ? (b) : (a))
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define WD_INIT_SLEEP_UTIME 1000
#define WD_INIT_RETRY_TIMES 10000
@@ -2010,9 +2011,10 @@ static void add_lib_to_list(struct drv_lib_list *head,
tmp->next = node;
}
-static int wd_set_ctx_nums(struct wd_ctx_nums *ctx_nums, const char *section,
+static int wd_set_ctx_nums(struct wd_ctx_params *ctx_params, const char *section,
__u32 op_type_num, int is_comp)
{
+ struct wd_ctx_nums *ctxs = ctx_params->ctx_set_num;
int i, j, ctx_num, node, ret;
char *ctx_section;
const char *type;
@@ -2031,18 +2033,24 @@ static int wd_set_ctx_nums(struct wd_ctx_nums *ctx_nums, const char *section,
if (ret)
return ret;
- /* Allocate queues evenly on each numa */
+ /* If the number of ctxs is set to 0, skip the configuration */
+ if (!ctx_num)
+ return 0;
+
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 there're multiple configurations, use the maximum ctx number */
if (!i)
- ctx_nums[j].sync_ctx_num = ctx_num;
+ ctxs[j].sync_ctx_num = MAX(ctxs[j].sync_ctx_num, ctx_num);
else
- ctx_nums[j].async_ctx_num = ctx_num;
+ ctxs[j].async_ctx_num = MAX(ctxs[j].async_ctx_num, ctx_num);
+ /* enable a node here, all enabled nodes share the same configuration */
+ numa_bitmask_setbit(ctx_params->bmp, node);
return 0;
}
}
@@ -2050,9 +2058,8 @@ static int wd_set_ctx_nums(struct wd_ctx_nums *ctx_nums, const char *section,
return -WD_EINVAL;
}
-/* return 0 for success, others failed */
static int wd_env_set_ctx_nums(const char *name, const char *var_s,
- struct wd_ctx_nums *ctx_nums, __u32 size)
+ struct wd_ctx_params *ctx_params, __u32 size)
{
char *left, *section, *start;
int is_comp;
@@ -2067,7 +2074,7 @@ static int wd_env_set_ctx_nums(const char *name, const char *var_s,
left = start;
while ((section = strsep(&left, ","))) {
- ret = wd_set_ctx_nums(ctx_nums, section, size, is_comp);
+ ret = wd_set_ctx_nums(ctx_params, section, size, is_comp);
if (ret < 0)
goto out_free_str;
}
@@ -2089,7 +2096,7 @@ int wd_ctx_param_init(struct wd_ctx_params *ctx_params,
var_s = secure_getenv(env_name);
if (var_s && strlen(var_s)) {
/* environment variable has the highest priority */
- ret = wd_env_set_ctx_nums(env_name, var_s, ctx_params->ctx_set_num, max_op_type);
+ ret = wd_env_set_ctx_nums(env_name, var_s, ctx_params, max_op_type);
if (ret) {
WD_ERR("fail to init ctx nums from %s!\n", env_name);
return -WD_EINVAL;
@@ -2109,13 +2116,13 @@ int wd_ctx_param_init(struct wd_ctx_params *ctx_params,
}
/* user_ctx_params is also not set, use driver's defalut queue_num */
+ ctx_params->bmp = NULL;
for (i = 0; i < driver->op_type_num; i++) {
ctx_params->ctx_set_num[i].sync_ctx_num = driver->queue_num;
ctx_params->ctx_set_num[i].async_ctx_num = driver->queue_num;
}
}
- ctx_params->bmp = NULL;
ctx_params->op_type_num = driver->op_type_num;
if (ctx_params->op_type_num > max_op_type) {
WD_ERR("fail to check driver op type numbers.\n");
--
2.30.0