Skip to content

Commit f714fa8

Browse files
committed
wd_util: consider sw has no dev, no hw ctx or op
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>
1 parent cb314ae commit f714fa8

File tree

1 file changed

+32
-35
lines changed

1 file changed

+32
-35
lines changed

wd_util.c

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,6 @@ int wd_init_ctx_config(struct wd_ctx_config_internal *in,
224224
}
225225

226226
for (i = 0; i < cfg->ctx_num; i++) {
227-
if (!cfg->ctxs[i].ctx) {
228-
WD_ERR("invalid: ctx is NULL!\n");
229-
ret = -WD_EINVAL;
230-
goto err_out;
231-
}
232-
233227
clone_ctx_to_internal(cfg->ctxs + i, ctxs + i);
234228
ret = pthread_spin_init(&ctxs[i].lock, PTHREAD_PROCESS_SHARED);
235229
if (ret) {
@@ -1153,17 +1147,21 @@ static int wd_get_wd_ctx(struct wd_env_config_per_numa *config,
11531147
return 0;
11541148

11551149
free_ctx:
1156-
for (j = start; j < i; j++)
1157-
wd_release_ctx(ctx_config->ctxs[j].ctx);
1150+
for (j = start; j < i; j++) {
1151+
if (ctx_config->ctxs[j].ctx)
1152+
wd_release_ctx(ctx_config->ctxs[j].ctx);
1153+
}
11581154
return ret;
11591155
}
11601156

11611157
static void wd_put_wd_ctx(struct wd_ctx_config *ctx_config, __u32 ctx_num)
11621158
{
11631159
__u32 i;
11641160

1165-
for (i = 0; i < ctx_num; i++)
1166-
wd_release_ctx(ctx_config->ctxs[i].ctx);
1161+
for (i = 0; i < ctx_num; i++) {
1162+
if (ctx_config->ctxs[i].ctx)
1163+
wd_release_ctx(ctx_config->ctxs[i].ctx);
1164+
}
11671165
}
11681166

11691167
static int wd_alloc_ctx(struct wd_env_config *config)
@@ -2147,7 +2145,14 @@ int wd_ctx_param_init(struct wd_ctx_params *ctx_params,
21472145
numa_free_nodemask(ctx_params->bmp);
21482146
return -WD_EAGAIN;
21492147
}
2150-
2148+
if (ctx_params->op_type_num == 0) {
2149+
/* set default */
2150+
ctx_params->op_type_num = 1;
2151+
if (ctx_params->ctx_set_num) {
2152+
ctx_params->ctx_set_num[0].sync_ctx_num = 1;
2153+
ctx_params->ctx_set_num[0].async_ctx_num = 1;
2154+
}
2155+
}
21512156
return 0;
21522157
}
21532158

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

2441+
/* sw share common resources, so dev is NULL is treated as error */
24362442
dev = wd_find_dev_by_numa(list, numa_id);
24372443
if (WD_IS_ERR(dev))
2438-
return WD_PTR_ERR(dev);
2444+
return 0;
24392445

24402446
for (i = idx; i < count; i++) {
24412447
ctx_config->ctxs[i].ctx = wd_request_ctx(dev);
@@ -2452,12 +2458,6 @@ static int wd_init_ctx_set(struct wd_init_attrs *attrs, struct uacce_dev_list *l
24522458
/* self-decrease i to eliminate self-increase on next loop */
24532459
i--;
24542460
continue;
2455-
} else if (!ctx_config->ctxs[i].ctx) {
2456-
/*
2457-
* wd_release_ctx_set will release ctx in
2458-
* caller wd_init_ctx_and_sched.
2459-
*/
2460-
return -WD_ENOMEM;
24612461
}
24622462
ctx_config->ctxs[i].op_type = op_type;
24632463
ctx_config->ctxs[i].ctx_mode =
@@ -2557,9 +2557,20 @@ static int wd_alg_ctx_init(struct wd_init_attrs *attrs)
25572557
int numa_cnt, ret;
25582558

25592559
list = wd_get_accel_list(attrs->alg);
2560-
if (!list) {
2561-
WD_ERR("failed to get devices!\n");
2562-
return -WD_ENODEV;
2560+
if (list) {
2561+
/*
2562+
* Not every numa has a device. Therefore, the first thing is to
2563+
* filter the devices in the selected numa node, and the second
2564+
* thing is to obtain the distribution of devices.
2565+
*/
2566+
used_list = wd_get_usable_list(list, used_bmp);
2567+
if (WD_IS_ERR(used_list)) {
2568+
ret = WD_PTR_ERR(used_list);
2569+
WD_ERR("failed to get usable devices(%d)!\n", ret);
2570+
goto out_freelist;
2571+
}
2572+
2573+
wd_init_device_nodemask(used_list, used_bmp);
25632574
}
25642575

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

2574-
/*
2575-
* Not every numa has a device. Therefore, the first thing is to
2576-
* filter the devices in the selected numa node, and the second
2577-
* thing is to obtain the distribution of devices.
2578-
*/
2579-
used_list = wd_get_usable_list(list, used_bmp);
2580-
if (WD_IS_ERR(used_list)) {
2581-
ret = WD_PTR_ERR(used_list);
2582-
WD_ERR("failed to get usable devices(%d)!\n", ret);
2583-
goto out_freelist;
2584-
}
2585-
2586-
wd_init_device_nodemask(used_list, used_bmp);
2587-
25882585
numa_cnt = numa_bitmask_weight(used_bmp);
25892586
if (!numa_cnt) {
25902587
ret = numa_cnt;

0 commit comments

Comments
 (0)