[PATCH OLK-6.6 0/5] xsched: XCU Partition
Zicheng Qu (5): xsched: switch xcu cgroup subsystem from domain mode to thread mode xsched: fix shares misaccounting when multiple tasks run in one cgroup xsched: suppress excessive error logs during cgroup file retry xsched: fix task stall when quota is disabled xsched: add throttling statistics for xsched groups include/linux/xsched.h | 3 ++- kernel/xsched/cfs.c | 5 ++++- kernel/xsched/cfs_quota.c | 34 +++++++++++++++++++++++++--------- kernel/xsched/cgroup.c | 8 ++------ kernel/xsched/core.c | 6 +++++- 5 files changed, 38 insertions(+), 18 deletions(-) -- 2.34.1
hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/IDA3VP ----------------------------------------- In domain mode: # acts only as a parent, cannot host tasks /sys/fs/cgroup/parent_cg ├─ cgroup.subtree_control = +xcu ├─ child_cg_a/ │ └─ cgroup.procs ├─ child_cg_b/ │ └─ cgroup.procs └─ cgroup.procs (Forbidden) Once xcu is enabled, the parent cgroup is not allowed to attach tasks directly and can only be used as a container for child cgroups. In thread mode: /sys/fs/cgroup/parent_cg ├─ cgroup.procs # tasks can be attached here directly └─ cgroup.subtree_control = +xcu After switching to thread mode, the parent cgroup can both host tasks directly and enable xcu for its subtree in the meantime. Fixes: 43bbefc53356 ("xsched: Add XCU control group implementation and its backend in xsched CFS") Signed-off-by: Zicheng Qu <quzicheng@huawei.com> --- kernel/xsched/cgroup.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/xsched/cgroup.c b/kernel/xsched/cgroup.c index ea495af71a22..ca04c493faa0 100644 --- a/kernel/xsched/cgroup.c +++ b/kernel/xsched/cgroup.c @@ -755,4 +755,5 @@ struct cgroup_subsys xcu_cgrp_subsys = { .dfl_cftypes = xcu_cg_files, .legacy_cftypes = xcu_cg_files, .early_init = false, + .threaded = true }; -- 2.34.1
hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/IDA3VP ----------------------------------------- When a cgroup contains multiple running tasks, the group virtual runtime was previously updated using the xruntime of the first runnable entity multiplied by the group weight. This causes the effective bandwidth to deviate from the configured shares. Update the group virtual runtime calculation to use the accumulated sum_exec_runtime of the group instead, so that the observed compute share matches the configured shares more accurately. Fixes: 43bbefc53356 ("xsched: Add XCU control group implementation and its backend in xsched CFS") Signed-off-by: Zicheng Qu <quzicheng@huawei.com> --- kernel/xsched/cfs.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kernel/xsched/cfs.c b/kernel/xsched/cfs.c index 1cbfd5f0e586..883ba6974450 100644 --- a/kernel/xsched/cfs.c +++ b/kernel/xsched/cfs.c @@ -107,7 +107,10 @@ static void xg_update(struct xsched_group_xcu_priv *xg, int task_delta) for (; xg; xg = &xcg_parent_grp_xcu(xg)) { xg->cfs_rq->nr_running += task_delta; entry = xs_pick_first(xg->cfs_rq); - new_xrt = entry ? entry->xruntime * xg->xse.cfs.weight : XSCHED_TIME_INF; + if (entry) + new_xrt = xg->xse.cfs.sum_exec_runtime * xg->xse.cfs.weight; + else + new_xrt = XSCHED_TIME_INF; xg->cfs_rq->min_xruntime = new_xrt; xg->xse.cfs.xruntime = new_xrt; -- 2.34.1
hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/IDA3VP ----------------------------------------- The cgroup file visibility update path has a retry mechanism controlled by XCUCG_SET_FILE_RETRY_COUNT. Emitting an error log on each failed retry can easily flood the kernel log under transient failure conditions. Remove the per-retry error logging to avoid excessive log noise while keeping the retry behavior unchanged. Fixes: aafde051ac61 ("xsched: Add support for CFS quota for cgroups") Signed-off-by: Zicheng Qu <quzicheng@huawei.com> --- include/linux/xsched.h | 2 +- kernel/xsched/cgroup.c | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/include/linux/xsched.h b/include/linux/xsched.h index 60cb43b4631f..d4dc321bb216 100644 --- a/include/linux/xsched.h +++ b/include/linux/xsched.h @@ -467,7 +467,7 @@ void xsched_quota_refill(struct work_struct *work); #define XCU_QUOTA_RUNTIME_INF -1 #define XCU_SHARES_MIN 1 -#define XCUCG_SET_FILE_RETRY_COUNT 50 +#define XCUCG_SET_FILE_RETRY_COUNT 100 #define XCUCG_SET_FILE_DELAY_MS 10 #define SCHED_CLASS_MAX_LENGTH 4 diff --git a/kernel/xsched/cgroup.c b/kernel/xsched/cgroup.c index ca04c493faa0..02957b33340a 100644 --- a/kernel/xsched/cgroup.c +++ b/kernel/xsched/cgroup.c @@ -46,13 +46,8 @@ static int xcu_cg_set_file_show(struct xsched_group *xg) /* Update visibility of related files based on sched_class */ for (int type_name = XCU_FILE_PERIOD_MS; type_name < NR_XCU_FILE_TYPES; type_name++) { - if (unlikely(!xg->xcu_file[type_name].kn)) { - XSCHED_ERR("Fail to control the file [%d] to be %s @ %s.\n", - type_name, - xg->sched_class == XSCHED_TYPE_CFS ? "visible" : "invisible", - __func__); + if (unlikely(!xg->xcu_file[type_name].kn)) return -EBUSY; - } cgroup_file_show(&xg->xcu_file[type_name], xg->sched_class == XSCHED_TYPE_CFS); } -- 2.34.1
hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/IDA3VP ----------------------------------------- When the quota is set to -1 or 0 (disabled), the group may remain throttled after a previous enforcement because no timer is armed and no explicit unthrottle is performed. This can cause tasks, including AI workloads, to stall indefinitely. Explicitly unthrottle the xsched group when the quota is disabled so that tasks are properly resumed. Fixes: aafde051ac61 ("xsched: Add support for CFS quota for cgroups") Signed-off-by: Zicheng Qu <quzicheng@huawei.com> --- kernel/xsched/cfs_quota.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/kernel/xsched/cfs_quota.c b/kernel/xsched/cfs_quota.c index 2b516ab5592f..11aca4dc711c 100644 --- a/kernel/xsched/cfs_quota.c +++ b/kernel/xsched/cfs_quota.c @@ -19,10 +19,23 @@ static struct workqueue_struct *quota_workqueue; -void xsched_quota_refill(struct work_struct *work) +static void xsched_group_unthrottle(struct xsched_group *xg) { uint32_t id; struct xsched_cu *xcu; + + for_each_active_xcu(xcu, id) { + mutex_lock(&xcu->xcu_lock); + if (!READ_ONCE(xg->perxcu_priv[id].xse.on_rq)) { + enqueue_ctx(&xg->perxcu_priv[id].xse, xcu); + wake_up_interruptible(&xcu->wq_xcu_idle); + } + mutex_unlock(&xcu->xcu_lock); + } +} + +void xsched_quota_refill(struct work_struct *work) +{ struct xsched_group *xg; xg = container_of(work, struct xsched_group, refill_work); @@ -38,14 +51,7 @@ void xsched_quota_refill(struct work_struct *work) return; } - for_each_active_xcu(xcu, id) { - mutex_lock(&xcu->xcu_lock); - if (!READ_ONCE(xg->perxcu_priv[id].xse.on_rq)) { - enqueue_ctx(&xg->perxcu_priv[id].xse, xcu); - wake_up_interruptible(&xcu->wq_xcu_idle); - } - mutex_unlock(&xcu->xcu_lock); - } + xsched_group_unthrottle(xg); } static enum hrtimer_restart quota_timer_cb(struct hrtimer *hrtimer) @@ -95,4 +101,6 @@ void xsched_quota_timeout_update(struct xsched_group *xg) if (xg->quota > 0 && xg->period > 0) hrtimer_start(t, ns_to_ktime(xg->period), HRTIMER_MODE_REL_SOFT); + else + xsched_group_unthrottle(xg); } -- 2.34.1
hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/IDA3VP ----------------------------------------- Track the number of throttle events and the total throttled time for each xsched group by recording nr_throttled, throttled_time and the start time of each throttling interval. The throttling start time is recorded when the group is dequeued due to quota enforcement and the duration is accumulated when the group is unthrottled, providing better observability of quota behavior. Fixes: aafde051ac61 ("xsched: Add support for CFS quota for cgroups") Signed-off-by: Zicheng Qu <quzicheng@huawei.com> --- include/linux/xsched.h | 1 + kernel/xsched/cfs_quota.c | 8 ++++++++ kernel/xsched/core.c | 6 +++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/linux/xsched.h b/include/linux/xsched.h index d4dc321bb216..a277c70b605b 100644 --- a/include/linux/xsched.h +++ b/include/linux/xsched.h @@ -248,6 +248,7 @@ struct xsched_group_xcu_priv { /* Statistics */ int nr_throttled; u64 throttled_time; + ktime_t start_throttled_time; }; enum xcu_file_type { diff --git a/kernel/xsched/cfs_quota.c b/kernel/xsched/cfs_quota.c index 11aca4dc711c..2e17a48c071b 100644 --- a/kernel/xsched/cfs_quota.c +++ b/kernel/xsched/cfs_quota.c @@ -29,6 +29,14 @@ static void xsched_group_unthrottle(struct xsched_group *xg) if (!READ_ONCE(xg->perxcu_priv[id].xse.on_rq)) { enqueue_ctx(&xg->perxcu_priv[id].xse, xcu); wake_up_interruptible(&xcu->wq_xcu_idle); + + if (xg->perxcu_priv[id].start_throttled_time != 0) { + xg->perxcu_priv[id].throttled_time += + ktime_to_ns(ktime_sub(ktime_get(), + xg->perxcu_priv[id].start_throttled_time)); + + xg->perxcu_priv[id].start_throttled_time = 0; + } } mutex_unlock(&xcu->xcu_lock); } diff --git a/kernel/xsched/core.c b/kernel/xsched/core.c index b23f2ca7820b..57479fe800c9 100644 --- a/kernel/xsched/core.c +++ b/kernel/xsched/core.c @@ -411,8 +411,12 @@ int xsched_schedule(void *input_xcu) dequeue_ctx(curr_xse, xcu); #ifdef CONFIG_CGROUP_XCU - if (xsched_quota_exceed(curr_xse->parent_grp)) + if (xsched_quota_exceed(curr_xse->parent_grp)) { dequeue_ctx(&curr_xse->parent_grp->perxcu_priv[xcu->id].xse, xcu); + curr_xse->parent_grp->perxcu_priv[xcu->id].nr_throttled++; + curr_xse->parent_grp->perxcu_priv[xcu->id].start_throttled_time = + ktime_get(); + } #endif xcu->xrq.curr_xse = NULL; -- 2.34.1
反馈: 您发送到kernel@openeuler.org的补丁/补丁集,已成功转换为PR! PR链接地址: https://gitee.com/openeuler/kernel/pulls/19460 邮件列表地址:https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/E56... FeedBack: The patch(es) which you have sent to kernel@openeuler.org mailing list has been converted to a pull request successfully! Pull request link: https://gitee.com/openeuler/kernel/pulls/19460 Mailing list address: https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/E56...
participants (2)
-
patchwork bot -
Zicheng Qu