Skip to content

Commit

Permalink
wd_util: consider sw has no dev, no hw ctx or op
Browse files Browse the repository at this point in the history
sw and hw will share common resources like ctxs and pool.
sw may works on platform no accerator dev, or has dev but
no ctx, or sw driver has no op.
Ignore these error as normal cases.

Signed-off-by: Zhangfei Gao <zhangfei.gao@linaro.org>
  • Loading branch information
zhangfeigao committed Dec 29, 2023
1 parent cb314ae commit f714fa8
Showing 1 changed file with 32 additions and 35 deletions.
67 changes: 32 additions & 35 deletions wd_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,6 @@ int wd_init_ctx_config(struct wd_ctx_config_internal *in,
}

for (i = 0; i < cfg->ctx_num; i++) {
if (!cfg->ctxs[i].ctx) {
WD_ERR("invalid: ctx is NULL!\n");
ret = -WD_EINVAL;
goto err_out;
}

clone_ctx_to_internal(cfg->ctxs + i, ctxs + i);
ret = pthread_spin_init(&ctxs[i].lock, PTHREAD_PROCESS_SHARED);
if (ret) {
Expand Down Expand Up @@ -1153,17 +1147,21 @@ static int wd_get_wd_ctx(struct wd_env_config_per_numa *config,
return 0;

free_ctx:
for (j = start; j < i; j++)
wd_release_ctx(ctx_config->ctxs[j].ctx);
for (j = start; j < i; j++) {
if (ctx_config->ctxs[j].ctx)
wd_release_ctx(ctx_config->ctxs[j].ctx);
}
return ret;
}

static void wd_put_wd_ctx(struct wd_ctx_config *ctx_config, __u32 ctx_num)
{
__u32 i;

for (i = 0; i < ctx_num; i++)
wd_release_ctx(ctx_config->ctxs[i].ctx);
for (i = 0; i < ctx_num; i++) {
if (ctx_config->ctxs[i].ctx)
wd_release_ctx(ctx_config->ctxs[i].ctx);
}
}

static int wd_alloc_ctx(struct wd_env_config *config)
Expand Down Expand Up @@ -2147,7 +2145,14 @@ int wd_ctx_param_init(struct wd_ctx_params *ctx_params,
numa_free_nodemask(ctx_params->bmp);
return -WD_EAGAIN;
}

if (ctx_params->op_type_num == 0) {
/* set default */
ctx_params->op_type_num = 1;
if (ctx_params->ctx_set_num) {
ctx_params->ctx_set_num[0].sync_ctx_num = 1;
ctx_params->ctx_set_num[0].async_ctx_num = 1;
}
}
return 0;
}

Expand Down Expand Up @@ -2433,9 +2438,10 @@ static int wd_init_ctx_set(struct wd_init_attrs *attrs, struct uacce_dev_list *l
if (!ctx_set_num)
return 0;

/* sw share common resources, so dev is NULL is treated as error */
dev = wd_find_dev_by_numa(list, numa_id);
if (WD_IS_ERR(dev))
return WD_PTR_ERR(dev);
return 0;

for (i = idx; i < count; i++) {
ctx_config->ctxs[i].ctx = wd_request_ctx(dev);
Expand All @@ -2452,12 +2458,6 @@ static int wd_init_ctx_set(struct wd_init_attrs *attrs, struct uacce_dev_list *l
/* self-decrease i to eliminate self-increase on next loop */
i--;
continue;
} else if (!ctx_config->ctxs[i].ctx) {
/*
* wd_release_ctx_set will release ctx in
* caller wd_init_ctx_and_sched.
*/
return -WD_ENOMEM;
}
ctx_config->ctxs[i].op_type = op_type;
ctx_config->ctxs[i].ctx_mode =
Expand Down Expand Up @@ -2557,9 +2557,20 @@ static int wd_alg_ctx_init(struct wd_init_attrs *attrs)
int numa_cnt, ret;

list = wd_get_accel_list(attrs->alg);
if (!list) {
WD_ERR("failed to get devices!\n");
return -WD_ENODEV;
if (list) {
/*
* Not every numa has a device. Therefore, the first thing is to
* filter the devices in the selected numa node, and the second
* thing is to obtain the distribution of devices.
*/
used_list = wd_get_usable_list(list, used_bmp);
if (WD_IS_ERR(used_list)) {
ret = WD_PTR_ERR(used_list);
WD_ERR("failed to get usable devices(%d)!\n", ret);
goto out_freelist;
}

wd_init_device_nodemask(used_list, used_bmp);
}

op_type_num = ctx_params->op_type_num;
Expand All @@ -2571,20 +2582,6 @@ static int wd_alg_ctx_init(struct wd_init_attrs *attrs)
goto out_freelist;
}

/*
* Not every numa has a device. Therefore, the first thing is to
* filter the devices in the selected numa node, and the second
* thing is to obtain the distribution of devices.
*/
used_list = wd_get_usable_list(list, used_bmp);
if (WD_IS_ERR(used_list)) {
ret = WD_PTR_ERR(used_list);
WD_ERR("failed to get usable devices(%d)!\n", ret);
goto out_freelist;
}

wd_init_device_nodemask(used_list, used_bmp);

numa_cnt = numa_bitmask_weight(used_bmp);
if (!numa_cnt) {
ret = numa_cnt;
Expand Down

0 comments on commit f714fa8

Please sign in to comment.