From: lizhi <lizhi206@huawei.com> Uadk supports obtaining device bandwidth usage through device name, algorithm name, and op_type. Upstream: Yes AR: AR20230722287656 Feature or Bugfix: Feature Signed-off-by: lizhi <lizhi206@huawei.com> --- uadk_tool/dfx/uadk_dfx.c | 96 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 89 insertions(+), 7 deletions(-) diff --git a/uadk_tool/dfx/uadk_dfx.c b/uadk_tool/dfx/uadk_dfx.c index a344082..2734723 100644 --- a/uadk_tool/dfx/uadk_dfx.c +++ b/uadk_tool/dfx/uadk_dfx.c @@ -17,6 +17,12 @@ #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) #define PRIVILEGE_FLAG 0666 +enum dfx_usage_type { + DISPLAY_DEVICE = 0, + DISPLAY_ALG_NAME, + DISPLAY_OP_TYPE +}; + struct uadk_env_var { const char *module; const char *alg; @@ -37,6 +43,7 @@ enum dfx_op_type { DISPLAY_DIR, DISPLAY_ENV, DISPLAY_COUNT, + DISPLAY_USAGE, DISPLAY_HELP, }; @@ -177,6 +184,77 @@ static void uadk_exe_path(void) printf("exe path: %s\n", dir); } +static void uadk_dev_usage_read(int argc, char *argv[]) +{ + char device[64] = "hisi_sec2-0"; + char alg_name[256] = "cipher"; + struct uacce_dev_list *list; + struct uacce_dev_list *tmp = NULL; + struct uacce_dev *dev = NULL; + int option_index = 0; + int op_type = 0, ret; + char *dev_name; + int opt; + + static struct option long_options[] = { + {"device", required_argument, 0, 0}, + {"alg_name", required_argument, 0, 1}, + {"op_type", required_argument, 0, 2}, + {0, 0, 0, 0} + }; + + while (1) { + opt = getopt_long(argc, argv, "", long_options, &option_index); + if (opt == -1) + break; + + switch (opt) { + case DISPLAY_DEVICE: + strcpy(device, optarg); + break; + case DISPLAY_ALG_NAME: + strcpy(alg_name, optarg); + break; + case DISPLAY_OP_TYPE: + op_type = strtol(optarg, NULL, 0); + break; + default: + printf("bad input parameter, exit!\n"); + return; + } + } + + list = wd_get_accel_list(alg_name); + if (!list) { + printf("no device support alg_name %s, exit!\n", alg_name); + return; + } + + for (tmp = list; tmp != NULL; tmp = tmp->next) { + dev_name = strrchr(tmp->dev->dev_root, '/') + 1; + if (!strcmp(dev_name, device)) { + dev = tmp->dev; + break; + } + } + + if (!dev) { + printf("no device name is %s, exit!\n", device); + goto free_list; + } + + ret = wd_get_dev_usage(dev, alg_name, op_type); + if (ret < 0) { + printf("failed to get usage ret %d!\n", ret); + goto free_list; + } + + printf("%s %s op type %d usage is %d\n", device, alg_name, op_type, ret); + +free_list: + wd_free_list_accels(list); +} + void print_dfx_help(void) { printf("NAME\n"); @@ -205,6 +283,7 @@ void dfx_cmd_parse(int argc, char *argv[]) {"dir", no_argument, 0, DISPLAY_DIR}, {"env", required_argument, 0, DISPLAY_ENV}, {"count", no_argument, 0, DISPLAY_COUNT}, + {"usage", no_argument, 0, DISPLAY_USAGE}, {"help", no_argument, 0, DISPLAY_HELP}, {0, 0, 0, 0} }; @@ -212,15 +291,15 @@ void dfx_cmd_parse(int argc, char *argv[]) while (1) { opt = getopt_long(argc, argv, "", long_options, &option_index); if (opt == -1) - break; + return; switch (opt) { case DISPLAY_VERSION: wd_get_version(); - break; + return; case DISPLAY_DIR: uadk_exe_path(); - break; + return; case DISPLAY_ENV: input_module = optarg; check_module = uadk_check_module(input_module); @@ -230,17 +309,20 @@ void dfx_cmd_parse(int argc, char *argv[]) print_dfx_help(); printf("failed to parse module parameter!\n"); } - break; + return; case DISPLAY_COUNT: uadk_shared_read(); - break; + return; + case DISPLAY_USAGE: + uadk_dev_usage_read(argc, argv); + return; case DISPLAY_HELP: print_dfx_help(); - break; + return; default: printf("bad input parameter, exit!\n"); print_dfx_help(); - break; + return; } } } -- 2.33.0