hulk inclusion category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/8423 -------------------------------- To prevent potential resource leaks and ensure that all resources are properly cleaned up when a task exits, this commit modifies the existing behavior so that any remaining operators are immediately cleared without waiting for their completion. Fixes: 76c15076abcb ("xsched: Add basic scheduler core support") Signed-off-by: Liu Kai <liukai284@huawei.com> --- kernel/xsched/core.c | 18 ++++++------------ kernel/xsched/vstream.c | 21 ++++++++++++++------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/kernel/xsched/core.c b/kernel/xsched/core.c index 5c2fd2f7dbd6..b715b1401043 100644 --- a/kernel/xsched/core.c +++ b/kernel/xsched/core.c @@ -153,21 +153,15 @@ int delete_ctx(struct xsched_context *ctx) struct xsched_cu *xcu = ctx->xse.xcu; struct xsched_entity *curr_xse = xcu->xrq.curr_xse; struct xsched_entity *xse = &ctx->xse; + int pending; - if (xse_integrity_check(xse)) { - XSCHED_ERR("Fail to check xse integrity @ %s\n", __func__); + if (xse_integrity_check(xse)) return -EINVAL; - } - - if (!xse->xcu) { - XSCHED_ERR("Try to delete ctx that is not attached to xcu @ %s\n", - __func__); - return -EINVAL; - } - /* Wait till context has been submitted. */ - while (atomic_read(&xse->kicks_pending_cnt)) - usleep_range(100, 200); + pending = atomic_read(&xse->kicks_pending_cnt); + if (pending > 0) + XSCHED_WARN("Delete xse %d on xcu %u with pending %d kicks\n", + xse->tgid, xcu->id, pending); mutex_lock(&xcu->xcu_lock); if (curr_xse == xse) diff --git a/kernel/xsched/vstream.c b/kernel/xsched/vstream.c index 80986e04d7b0..b39e97682dfb 100644 --- a/kernel/xsched/vstream.c +++ b/kernel/xsched/vstream.c @@ -69,23 +69,30 @@ static int vstream_file_create(struct vstream_info *vs) static void xsched_task_free(struct kref *kref) { struct xsched_context *ctx; - vstream_info_t *vs, *tmp; + vstream_info_t *vs, *tmp_vs; + vstream_metadata_t *vsm, *tmp_vsm; struct xsched_cu *xcu; ctx = container_of(kref, struct xsched_context, kref); xcu = ctx->xse.xcu; - /* Wait utill xse dequeues */ - while (READ_ONCE(ctx->xse.on_rq)) - usleep_range(100, 200); - mutex_lock(&xcu->ctx_list_lock); - list_for_each_entry_safe(vs, tmp, &ctx->vstream_list, ctx_node) { + delete_ctx(ctx); + list_for_each_entry_safe(vs, tmp_vs, &ctx->vstream_list, ctx_node) { list_del(&vs->ctx_node); + + /* delete pending kicks */ + mutex_lock(&xcu->xcu_lock); + spin_lock(&vs->stream_lock); + list_for_each_entry_safe(vsm, tmp_vsm, &vs->metadata_list, node) { + list_del(&vsm->node); + kfree(vsm); + } + spin_unlock(&vs->stream_lock); + mutex_unlock(&xcu->xcu_lock); kfree(vs); } - delete_ctx(ctx); list_del(&ctx->ctx_node); --xcu->nr_ctx; mutex_unlock(&xcu->ctx_list_lock); -- 2.34.1