Skip to content

Commit

Permalink
wd_util: consider sw has no hw ctx and op type
Browse files Browse the repository at this point in the history
sw and hw will share common resources like ctxs and pool.
So handle cases only sw exist, without ctx and op

Signed-off-by: Zhangfei Gao <zhangfei.gao@linaro.org>
  • Loading branch information
zhangfeigao committed Dec 29, 2023
1 parent cb314ae commit bf803df
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions wd_util.c
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 @@ -2452,12 +2457,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

0 comments on commit bf803df

Please sign in to comment.