In wd_init_ctx_set, it will try to get the ctx from the most idle device. But requesting ctx from devices is an exclusive behavior. And there is no lock to protect against multi-process contention. In the worst situation, a process will always get 'EBUSY' from wd_request_ctx.
So here add a retry count to avoid a infinite loop.
Signed-off-by: Yang Shen shenyang39@huawei.com --- wd_util.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/wd_util.c b/wd_util.c index 8af0261..bfa3af0 100644 --- a/wd_util.c +++ b/wd_util.c @@ -2420,7 +2420,7 @@ static int wd_init_ctx_set(struct wd_init_attrs *attrs, struct uacce_dev_list *l struct wd_ctx_config *ctx_config = attrs->ctx_config; __u32 count = idx + ctx_set_num; struct uacce_dev *dev; - __u32 i; + __u32 i, cnt = 0;
/* If the ctx set number is 0, the initialization is skipped. */ if (!ctx_set_num) @@ -2437,6 +2437,12 @@ static int wd_init_ctx_set(struct wd_init_attrs *attrs, struct uacce_dev_list *l if (WD_IS_ERR(dev)) return WD_PTR_ERR(dev);
+ if (cnt++ > WD_INIT_RETRY_TIMES) { + WD_ERR("failed to request enough ctx due to timeout!\n"); + return -WD_ETIMEDOUT; + } + + /* self-decrease i to eliminate self-increase on next loop */ i--; continue; } else if (!ctx_config->ctxs[i].ctx) {