libwd/0041-uadk_tool-fix-queue-application-failure-from-multipl.patch
JangShui Yang e072f742a4 libwd: update the source code
(cherry picked from commit dc42b3a676205c1a1c922628a993887e1ad2988f)
2024-04-07 18:59:45 +08:00

642 lines
16 KiB
Diff

From 5210ac8a3f616f381d3990e3ca3f92bf23383f25 Mon Sep 17 00:00:00 2001
From: Qi Tao <taoqi10@huawei.com>
Date: Mon, 11 Mar 2024 16:41:41 +0800
Subject: [PATCH 41/44] uadk_tool: fix queue application failure from multiple
devices
Specified device: apply queues from a designated device.
No specified device: apply queues from multiple devices.
Signed-off-by: Qi Tao <taoqi10@huawei.com>
---
uadk_tool/benchmark/hpre_uadk_benchmark.c | 143 ++++++++++++++++-----
uadk_tool/benchmark/sec_uadk_benchmark.c | 141 +++++++++++++++-----
uadk_tool/benchmark/zip_uadk_benchmark.c | 150 ++++++++++++++++------
3 files changed, 329 insertions(+), 105 deletions(-)
diff --git a/uadk_tool/benchmark/hpre_uadk_benchmark.c b/uadk_tool/benchmark/hpre_uadk_benchmark.c
index 729728f..0148e56 100644
--- a/uadk_tool/benchmark/hpre_uadk_benchmark.c
+++ b/uadk_tool/benchmark/hpre_uadk_benchmark.c
@@ -344,21 +344,17 @@ static int hpre_uadk_param_parse(thread_data *tddata, struct acc_option *options
return 0;
}
-static int init_hpre_ctx_config(struct acc_option *options)
+static int specified_device_request_ctx(struct acc_option *options)
{
- struct uacce_dev_list *list, *tmp;
- int subtype = options->subtype;
+ struct uacce_dev_list *list = NULL;
+ struct uacce_dev_list *tmp = NULL;
char *alg = options->algclass;
int mode = options->syncmode;
struct uacce_dev *dev = NULL;
- struct sched_params param;
- int max_node, i;
+ int avail_ctx = 0;
char *dev_name;
int ret = 0;
-
- max_node = numa_max_node() + 1;
- if (max_node <= 0)
- return -EINVAL;
+ int i = 0;
list = wd_get_accel_list(alg);
if (!list) {
@@ -366,15 +362,11 @@ static int init_hpre_ctx_config(struct acc_option *options)
return -ENODEV;
}
- if (strlen(options->device) == 0) {
- dev = list->dev;
- } else {
- for (tmp = list; tmp; tmp = tmp->next) {
- dev_name = strrchr(tmp->dev->dev_root, '/') + 1;
- if (!strcmp(dev_name, options->device)) {
- dev = tmp->dev;
- break;
- }
+ for (tmp = list; tmp != NULL; tmp = tmp->next) {
+ dev_name = strrchr(tmp->dev->dev_root, '/') + 1;
+ if (!strcmp(dev_name, options->device)) {
+ dev = tmp->dev;
+ break;
}
}
@@ -384,30 +376,114 @@ static int init_hpre_ctx_config(struct acc_option *options)
goto free_list;
}
- /* If there is no numa, we defualt config to zero */
- if (dev->numa_id < 0)
- dev->numa_id = 0;
-
- memset(&g_ctx_cfg, 0, sizeof(struct wd_ctx_config));
- g_ctx_cfg.ctx_num = g_ctxnum;
- g_ctx_cfg.ctxs = calloc(g_ctxnum, sizeof(struct wd_ctx));
- if (!g_ctx_cfg.ctxs) {
- ret = -ENOMEM;
+ avail_ctx = wd_get_avail_ctx(dev);
+ if (avail_ctx < 0) {
+ HPRE_TST_PRT("failed to get the number of available ctx from %s\n", options->device);
+ ret = avail_ctx;
+ goto free_list;
+ } else if (avail_ctx < g_ctxnum) {
+ HPRE_TST_PRT("error: not enough ctx available in %s\n", options->device);
+ ret = -ENODEV;
goto free_list;
}
+ /* If there is no numa, we default config to zero */
+ if (dev->numa_id < 0)
+ dev->numa_id = 0;
+
for (i = 0; i < g_ctxnum; i++) {
g_ctx_cfg.ctxs[i].ctx = wd_request_ctx(dev);
if (!g_ctx_cfg.ctxs[i].ctx) {
HPRE_TST_PRT("failed to alloc %dth ctx\n", i);
- ret = -ENODEV;
+ ret = -ENOMEM;
goto free_ctx;
}
-
g_ctx_cfg.ctxs[i].op_type = 0;
g_ctx_cfg.ctxs[i].ctx_mode = (__u8)mode;
}
+ wd_free_list_accels(list);
+ return 0;
+
+free_ctx:
+ for (; i >= 0; i--)
+ wd_release_ctx(g_ctx_cfg.ctxs[i].ctx);
+
+free_list:
+ wd_free_list_accels(list);
+
+ return ret;
+}
+
+static int non_specified_device_request_ctx(struct acc_option *options)
+{
+ char *alg = options->algclass;
+ int mode = options->syncmode;
+ struct uacce_dev *dev = NULL;
+ int ret = 0;
+ int i = 0;
+
+ while (i < g_ctxnum) {
+ dev = wd_get_accel_dev(alg);
+ if (!dev) {
+ HPRE_TST_PRT("failed to get %s device\n", alg);
+ ret = -ENODEV;
+ goto free_ctx;
+ }
+
+ /* If there is no numa, we default config to zero */
+ if (dev->numa_id < 0)
+ dev->numa_id = 0;
+
+ for (; i < g_ctxnum; i++) {
+ g_ctx_cfg.ctxs[i].ctx = wd_request_ctx(dev);
+ if (!g_ctx_cfg.ctxs[i].ctx)
+ break;
+
+ g_ctx_cfg.ctxs[i].op_type = 0;
+ g_ctx_cfg.ctxs[i].ctx_mode = (__u8)mode;
+ }
+
+ free(dev);
+ }
+
+ return 0;
+
+free_ctx:
+ for (; i >= 0; i--)
+ wd_release_ctx(g_ctx_cfg.ctxs[i].ctx);
+
+ return ret;
+}
+
+static int init_hpre_ctx_config(struct acc_option *options)
+{
+ struct sched_params param = {0};
+ int subtype = options->subtype;
+ int mode = options->syncmode;
+ int max_node;
+ int ret = 0;
+
+ max_node = numa_max_node() + 1;
+ if (max_node <= 0)
+ return -EINVAL;
+
+ memset(&g_ctx_cfg, 0, sizeof(struct wd_ctx_config));
+ g_ctx_cfg.ctx_num = g_ctxnum;
+ g_ctx_cfg.ctxs = calloc(g_ctxnum, sizeof(struct wd_ctx));
+ if (!g_ctx_cfg.ctxs)
+ return -ENOMEM;
+
+ if (strlen(options->device) != 0)
+ ret = specified_device_request_ctx(options);
+ else
+ ret = non_specified_device_request_ctx(options);
+
+ if (ret) {
+ HPRE_TST_PRT("failed to request hpre ctx!\n");
+ goto free_ctxs;
+ }
+
switch(subtype) {
case RSA_TYPE:
g_sched = wd_sched_rr_alloc(SCHED_POLICY_RR, 1, max_node, wd_rsa_poll_ctx);
@@ -460,7 +536,7 @@ static int init_hpre_ctx_config(struct acc_option *options)
break;
}
if (ret) {
- HPRE_TST_PRT("failed to get hpre ctx!\n");
+ HPRE_TST_PRT("failed to init hpre ctx!\n");
goto free_sched;
}
@@ -470,12 +546,11 @@ free_sched:
wd_sched_rr_release(g_sched);
free_ctx:
- for (; i >= 0; i--)
+ for (int i = g_ctxnum; i >= 0; i--)
wd_release_ctx(g_ctx_cfg.ctxs[i].ctx);
- free(g_ctx_cfg.ctxs);
-free_list:
- wd_free_list_accels(list);
+free_ctxs:
+ free(g_ctx_cfg.ctxs);
return ret;
}
diff --git a/uadk_tool/benchmark/sec_uadk_benchmark.c b/uadk_tool/benchmark/sec_uadk_benchmark.c
index 2c12c20..56f4fa6 100644
--- a/uadk_tool/benchmark/sec_uadk_benchmark.c
+++ b/uadk_tool/benchmark/sec_uadk_benchmark.c
@@ -544,21 +544,17 @@ static int sec_uadk_param_parse(thread_data *tddata, struct acc_option *options)
return 0;
}
-static int init_ctx_config(struct acc_option *options)
+static int specified_device_request_ctx(struct acc_option *options)
{
- struct uacce_dev_list *list, *tmp;
- struct sched_params param = {0};
- int subtype = options->subtype;
+ struct uacce_dev_list *list = NULL;
+ struct uacce_dev_list *tmp = NULL;
char *alg = options->algclass;
int mode = options->syncmode;
struct uacce_dev *dev = NULL;
- int max_node, i;
+ int avail_ctx = 0;
char *dev_name;
int ret = 0;
-
- max_node = numa_max_node() + 1;
- if (max_node <= 0)
- return -EINVAL;
+ int i = 0;
list = wd_get_accel_list(alg);
if (!list) {
@@ -566,15 +562,11 @@ static int init_ctx_config(struct acc_option *options)
return -ENODEV;
}
- if (strlen(options->device) == 0) {
- dev = list->dev;
- } else {
- for (tmp = list; tmp; tmp = tmp->next) {
- dev_name = strrchr(tmp->dev->dev_root, '/') + 1;
- if (!strcmp(dev_name, options->device)) {
- dev = tmp->dev;
- break;
- }
+ for (tmp = list; tmp != NULL; tmp = tmp->next) {
+ dev_name = strrchr(tmp->dev->dev_root, '/') + 1;
+ if (!strcmp(dev_name, options->device)) {
+ dev = tmp->dev;
+ break;
}
}
@@ -584,18 +576,21 @@ static int init_ctx_config(struct acc_option *options)
goto free_list;
}
- /* If there is no numa, we defualt config to zero */
- if (dev->numa_id < 0)
- dev->numa_id = 0;
-
- memset(&g_ctx_cfg, 0, sizeof(struct wd_ctx_config));
- g_ctx_cfg.ctx_num = g_ctxnum;
- g_ctx_cfg.ctxs = calloc(g_ctxnum, sizeof(struct wd_ctx));
- if (!g_ctx_cfg.ctxs) {
- ret = -ENOMEM;
+ avail_ctx = wd_get_avail_ctx(dev);
+ if (avail_ctx < 0) {
+ SEC_TST_PRT("failed to get the number of available ctx from %s\n", options->device);
+ ret = avail_ctx;
+ goto free_list;
+ } else if (avail_ctx < g_ctxnum) {
+ SEC_TST_PRT("error: not enough ctx available in %s\n", options->device);
+ ret = -ENODEV;
goto free_list;
}
+ /* If there is no numa, we default config to zero */
+ if (dev->numa_id < 0)
+ dev->numa_id = 0;
+
for (i = 0; i < g_ctxnum; i++) {
g_ctx_cfg.ctxs[i].ctx = wd_request_ctx(dev);
if (!g_ctx_cfg.ctxs[i].ctx) {
@@ -603,11 +598,92 @@ static int init_ctx_config(struct acc_option *options)
ret = -ENOMEM;
goto free_ctx;
}
-
g_ctx_cfg.ctxs[i].op_type = 0;
g_ctx_cfg.ctxs[i].ctx_mode = (__u8)mode;
}
+ wd_free_list_accels(list);
+ return 0;
+
+free_ctx:
+ for (; i >= 0; i--)
+ wd_release_ctx(g_ctx_cfg.ctxs[i].ctx);
+
+free_list:
+ wd_free_list_accels(list);
+
+ return ret;
+}
+
+static int non_specified_device_request_ctx(struct acc_option *options)
+{
+ char *alg = options->algclass;
+ int mode = options->syncmode;
+ struct uacce_dev *dev = NULL;
+ int ret = 0;
+ int i = 0;
+
+ while (i < g_ctxnum) {
+ dev = wd_get_accel_dev(alg);
+ if (!dev) {
+ SEC_TST_PRT("failed to get %s device\n", alg);
+ ret = -ENODEV;
+ goto free_ctx;
+ }
+
+ /* If there is no numa, we default config to zero */
+ if (dev->numa_id < 0)
+ dev->numa_id = 0;
+
+ for (; i < g_ctxnum; i++) {
+ g_ctx_cfg.ctxs[i].ctx = wd_request_ctx(dev);
+ if (!g_ctx_cfg.ctxs[i].ctx)
+ break;
+
+ g_ctx_cfg.ctxs[i].op_type = 0;
+ g_ctx_cfg.ctxs[i].ctx_mode = (__u8)mode;
+ }
+
+ free(dev);
+ }
+
+ return 0;
+
+free_ctx:
+ for (; i >= 0; i--)
+ wd_release_ctx(g_ctx_cfg.ctxs[i].ctx);
+
+ return ret;
+}
+
+static int init_ctx_config(struct acc_option *options)
+{
+ struct sched_params param = {0};
+ int subtype = options->subtype;
+ int mode = options->syncmode;
+ int max_node;
+ int ret = 0;
+
+ max_node = numa_max_node() + 1;
+ if (max_node <= 0)
+ return -EINVAL;
+
+ memset(&g_ctx_cfg, 0, sizeof(struct wd_ctx_config));
+ g_ctx_cfg.ctx_num = g_ctxnum;
+ g_ctx_cfg.ctxs = calloc(g_ctxnum, sizeof(struct wd_ctx));
+ if (!g_ctx_cfg.ctxs)
+ return -ENOMEM;
+
+ if (strlen(options->device) != 0)
+ ret = specified_device_request_ctx(options);
+ else
+ ret = non_specified_device_request_ctx(options);
+
+ if (ret) {
+ SEC_TST_PRT("failed to request sec ctx!\n");
+ goto free_ctxs;
+ }
+
switch(subtype) {
case CIPHER_TYPE:
g_sched = wd_sched_rr_alloc(SCHED_POLICY_RR, 1, max_node, wd_cipher_poll_ctx);
@@ -652,7 +728,7 @@ static int init_ctx_config(struct acc_option *options)
break;
}
if (ret) {
- SEC_TST_PRT("failed to cipher ctx!\n");
+ SEC_TST_PRT("failed to init sec ctx!\n");
goto free_sched;
}
@@ -662,12 +738,11 @@ free_sched:
wd_sched_rr_release(g_sched);
free_ctx:
- for (; i >= 0; i--)
+ for (int i = g_ctxnum; i >= 0; i--)
wd_release_ctx(g_ctx_cfg.ctxs[i].ctx);
- free(g_ctx_cfg.ctxs);
-free_list:
- wd_free_list_accels(list);
+free_ctxs:
+ free(g_ctx_cfg.ctxs);
return ret;
}
diff --git a/uadk_tool/benchmark/zip_uadk_benchmark.c b/uadk_tool/benchmark/zip_uadk_benchmark.c
index 1dd3990..e2876a9 100644
--- a/uadk_tool/benchmark/zip_uadk_benchmark.c
+++ b/uadk_tool/benchmark/zip_uadk_benchmark.c
@@ -318,21 +318,17 @@ static int init_ctx_config2(struct acc_option *options)
return 0;
}
-static int init_ctx_config(struct acc_option *options)
+static int specified_device_request_ctx(struct acc_option *options)
{
- struct uacce_dev_list *list, *tmp;
+ struct uacce_dev_list *list = NULL;
+ struct uacce_dev_list *tmp = NULL;
char *alg = options->algclass;
- int optype = options->optype;
int mode = options->syncmode;
struct uacce_dev *dev = NULL;
- int max_node, i;
+ int avail_ctx = 0;
char *dev_name;
int ret = 0;
-
- optype = optype % WD_DIR_MAX;
- max_node = numa_max_node() + 1;
- if (max_node <= 0)
- return -EINVAL;
+ int i = 0;
list = wd_get_accel_list(alg);
if (!list) {
@@ -340,15 +336,11 @@ static int init_ctx_config(struct acc_option *options)
return -ENODEV;
}
- if (strlen(options->device) == 0) {
- dev = list->dev;
- } else {
- for (tmp = list; tmp; tmp = tmp->next) {
- dev_name = strrchr(tmp->dev->dev_root, '/') + 1;
- if (!strcmp(dev_name, options->device)) {
- dev = tmp->dev;
- break;
- }
+ for (tmp = list; tmp != NULL; tmp = tmp->next) {
+ dev_name = strrchr(tmp->dev->dev_root, '/') + 1;
+ if (!strcmp(dev_name, options->device)) {
+ dev = tmp->dev;
+ break;
}
}
@@ -358,29 +350,114 @@ static int init_ctx_config(struct acc_option *options)
goto free_list;
}
- /* If there is no numa, we defualt config to zero */
- if (dev->numa_id < 0)
- dev->numa_id = 0;
-
- memset(&g_ctx_cfg, 0, sizeof(struct wd_ctx_config));
- g_ctx_cfg.ctx_num = g_ctxnum;
- g_ctx_cfg.ctxs = calloc(g_ctxnum, sizeof(struct wd_ctx));
- if (!g_ctx_cfg.ctxs) {
- ret = -ENOMEM;
+ avail_ctx = wd_get_avail_ctx(dev);
+ if (avail_ctx < 0) {
+ ZIP_TST_PRT("failed to get the number of available ctx from %s\n", options->device);
+ ret = avail_ctx;
+ goto free_list;
+ } else if (avail_ctx < g_ctxnum) {
+ ZIP_TST_PRT("error: not enough ctx available in %s\n", options->device);
+ ret = -ENODEV;
goto free_list;
}
- for (i = 0; i < g_ctxnum; i++) {
+ /* If there is no numa, we default config to zero */
+ if (dev->numa_id < 0)
+ dev->numa_id = 0;
+
+ for (; i < g_ctxnum; i++) {
g_ctx_cfg.ctxs[i].ctx = wd_request_ctx(dev);
if (!g_ctx_cfg.ctxs[i].ctx) {
ZIP_TST_PRT("failed to alloc %dth ctx\n", i);
+ ret = -ENOMEM;
goto free_ctx;
}
-
- g_ctx_cfg.ctxs[i].op_type = optype;
+ g_ctx_cfg.ctxs[i].op_type = 0;
g_ctx_cfg.ctxs[i].ctx_mode = (__u8)mode;
}
+ wd_free_list_accels(list);
+ return 0;
+
+free_ctx:
+ for (; i >= 0; i--)
+ wd_release_ctx(g_ctx_cfg.ctxs[i].ctx);
+
+free_list:
+ wd_free_list_accels(list);
+
+ return ret;
+}
+
+static int non_specified_device_request_ctx(struct acc_option *options)
+{
+ char *alg = options->algclass;
+ int mode = options->syncmode;
+ struct uacce_dev *dev = NULL;
+ int ret = 0;
+ int i = 0;
+
+ while (i < g_ctxnum) {
+ dev = wd_get_accel_dev(alg);
+ if (!dev) {
+ ZIP_TST_PRT("failed to get %s device\n", alg);
+ ret = -ENODEV;
+ goto free_ctx;
+ }
+
+ /* If there is no numa, we default config to zero */
+ if (dev->numa_id < 0)
+ dev->numa_id = 0;
+
+ for (; i < g_ctxnum; i++) {
+ g_ctx_cfg.ctxs[i].ctx = wd_request_ctx(dev);
+ if (!g_ctx_cfg.ctxs[i].ctx)
+ break;
+
+ g_ctx_cfg.ctxs[i].op_type = 0;
+ g_ctx_cfg.ctxs[i].ctx_mode = (__u8)mode;
+ }
+
+ free(dev);
+ }
+
+ return 0;
+
+free_ctx:
+ for (; i >= 0; i--)
+ wd_release_ctx(g_ctx_cfg.ctxs[i].ctx);
+
+ return ret;
+}
+
+static int init_ctx_config(struct acc_option *options)
+{
+ int optype = options->optype;
+ int mode = options->syncmode;
+ int max_node;
+ int ret = 0;
+
+ optype = optype % WD_DIR_MAX;
+ max_node = numa_max_node() + 1;
+ if (max_node <= 0)
+ return -EINVAL;
+
+ memset(&g_ctx_cfg, 0, sizeof(struct wd_ctx_config));
+ g_ctx_cfg.ctx_num = g_ctxnum;
+ g_ctx_cfg.ctxs = calloc(g_ctxnum, sizeof(struct wd_ctx));
+ if (!g_ctx_cfg.ctxs)
+ return -ENOMEM;
+
+ if (strlen(options->device) != 0)
+ ret = specified_device_request_ctx(options);
+ else
+ ret = non_specified_device_request_ctx(options);
+
+ if (ret) {
+ ZIP_TST_PRT("failed to request zip ctx!\n");
+ goto free_ctxs;
+ }
+
g_sched = wd_sched_rr_alloc(SCHED_POLICY_RR, 2, max_node, wd_comp_poll_ctx);
if (!g_sched) {
ZIP_TST_PRT("failed to alloc sched!\n");
@@ -394,7 +471,7 @@ static int init_ctx_config(struct acc_option *options)
* All contexts for 2 modes & 2 types.
* The test only uses one kind of contexts at the same time.
*/
- param.numa_id = dev->numa_id;
+ param.numa_id = 0;
param.type = optype;
param.mode = mode;
param.begin = 0;
@@ -407,24 +484,21 @@ static int init_ctx_config(struct acc_option *options)
ret = wd_comp_init(&g_ctx_cfg, g_sched);
if (ret) {
- ZIP_TST_PRT("failed to cipher ctx!\n");
+ ZIP_TST_PRT("failed to init zip ctx!\n");
goto free_sched;
}
- wd_free_list_accels(list);
-
return 0;
free_sched:
wd_sched_rr_release(g_sched);
free_ctx:
- for (; i >= 0; i--)
+ for (int i = g_ctxnum; i >= 0; i--)
wd_release_ctx(g_ctx_cfg.ctxs[i].ctx);
- free(g_ctx_cfg.ctxs);
-free_list:
- wd_free_list_accels(list);
+free_ctxs:
+ free(g_ctx_cfg.ctxs);
return ret;
}
--
2.25.1