[PATCH v3 openEuler-26.09 0/3] Introduce xsched dmem
Introduce xsched dmem Liu Kai (3): xsched: replace magic number with SCHED_CLASS_MAX_LENGTH for scheduler class string length xsched: simplify root group check by direct comparison with root_xcg xsched: add is_offline check in work function include/linux/xsched.h | 5 ++--- kernel/xsched/cfs_quota.c | 5 +++-- kernel/xsched/cgroup.c | 20 ++++++-------------- 3 files changed, 11 insertions(+), 19 deletions(-) -- 2.34.1
hulk inclusion category: cleanup bugzilla: https://atomgit.com/openeuler/kernel/issues/8423 -------------------------------- This commit replaces a hardcoded magic number used for the maximum length of scheduler class name strings with the named constant SCHED_CLASS_MAX_LENGTH. No functional change is introduced, this is a pure cleanup for better code hygiene. Signed-off-by: Liu Kai <liukai284@huawei.com> --- include/linux/xsched.h | 3 +-- kernel/xsched/cgroup.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/include/linux/xsched.h b/include/linux/xsched.h index a0ed200409f6..b160d93ba337 100644 --- a/include/linux/xsched.h +++ b/include/linux/xsched.h @@ -39,6 +39,7 @@ #define XSCHED_CFS_WEIGHT_DFLT 1024 #define XSCHED_CFS_QUOTA_PERIOD_MS (100 * NSEC_PER_MSEC) #define XSCHED_CFG_SHARE_DFLT 1024 +#define SCHED_CLASS_MAX_LENGTH 4 /* * A default kick slice for RT class XSEs. @@ -491,8 +492,6 @@ void xsched_quota_refill(struct work_struct *work); #define XCUCG_SET_FILE_RETRY_COUNT 100 #define XCUCG_SET_FILE_DELAY_MS 10 -#define SCHED_CLASS_MAX_LENGTH 4 - #endif static inline u64 xs_calc_delta(u64 delta_exec, u32 base_weight, u32 weight) diff --git a/kernel/xsched/cgroup.c b/kernel/xsched/cgroup.c index 3060ad16f3e8..24d799e9301f 100644 --- a/kernel/xsched/cgroup.c +++ b/kernel/xsched/cgroup.c @@ -34,7 +34,7 @@ static LIST_HEAD(xcg_attach_list); static DEFINE_MUTEX(xcg_mutex); static DEFINE_MUTEX(xcu_file_show_mutex); -static const char xcu_sched_name[XSCHED_TYPE_NUM][4] = { +static const char xcu_sched_name[XSCHED_TYPE_NUM][SCHED_CLASS_MAX_LENGTH] = { [XSCHED_TYPE_RT] = "rt", [XSCHED_TYPE_CFS] = "cfs" }; -- 2.34.1
hulk inclusion category: cleanup bugzilla: https://atomgit.com/openeuler/kernel/issues/8423 -------------------------------- Replace the dedicated xsched_group_is_root() helper function with a direct pointer comparison against the global root_xcg. Since the root scheduling group is a singleton and uniquely identified by root_xcg, this approach is functionally equivalent but more efficient and straightforward. All existing callers have been updated accordingly. This is a clean, non-functional refactor that enhances maintainability. Signed-off-by: Liu Kai <liukai284@huawei.com> --- include/linux/xsched.h | 2 +- kernel/xsched/cgroup.c | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/include/linux/xsched.h b/include/linux/xsched.h index b160d93ba337..b06157944010 100644 --- a/include/linux/xsched.h +++ b/include/linux/xsched.h @@ -314,7 +314,7 @@ struct xsched_group { (__xse) = &(xse_parent_grp_xcu((__xse))->xse)) #define for_each_xsched_group(__xg) \ - for (; (__xg) && (__xg)->parent; (__xg) = (__xg)->parent) + for (; (__xg) != root_xcg; (__xg) = (__xg)->parent) /** * Only group xsched entities are permitted to call. diff --git a/kernel/xsched/cgroup.c b/kernel/xsched/cgroup.c index 24d799e9301f..94df3005bf36 100644 --- a/kernel/xsched/cgroup.c +++ b/kernel/xsched/cgroup.c @@ -103,6 +103,7 @@ void xsched_group_perxcu_init(struct xsched_group *xg, const struct xsched_class *class; int id = xcu->id; + /* Ensure non-root group has a valid parent */ if (xg != root_xcg && WARN_ON(!xg->parent)) return; @@ -206,11 +207,6 @@ inline struct xsched_group *xcu_cg_from_css(struct cgroup_subsys_state *css) return css ? container_of(css, struct xsched_group, css) : NULL; } -static inline bool xsched_group_is_root(struct xsched_group *xg) -{ - return xg && !xg->parent; -} - /** * xcu_css_alloc() - Allocate and init xcu cgroup. * @parent_css: css of parent xcu cgroup @@ -303,7 +299,7 @@ static void xcu_css_offline(struct cgroup_subsys_state *css) cancel_work_sync(&xcg->refill_work); cancel_work_sync(&xcg->file_show_work); - if (!xsched_group_is_root(xcg)) { + if (xcg != root_xcg) { switch (xcg->sched_class) { case XSCHED_TYPE_CFS: xcu_cfs_cg_deinit(xcg); @@ -552,7 +548,7 @@ static ssize_t xcu_sched_class_write(struct kernfs_open_file *of, char *buf, xg = xcu_cg_from_css(css); /* only the first level of root can switch scheduler type */ - if (!xsched_group_is_root(xg->parent)) { + if (xg->parent != root_xcg) { css_put(css); return -EINVAL; } -- 2.34.1
hulk inclusion category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/8423 -------------------------------- Introduce a check for the is_offline flag at the beginning of the work function to prevent scheduling or accounting operations on cgroups that have already been offlined. This avoids potential use-after-free, inconsistent state updates, or unnecessary processing on entities that are no longer part of the active hierarchy. Fixes: aafde051ac61 ("xsched: Add support for CFS quota for cgroups") Signed-off-by: Liu Kai <liukai284@huawei.com> --- kernel/xsched/cfs_quota.c | 5 +++-- kernel/xsched/cgroup.c | 8 ++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/kernel/xsched/cfs_quota.c b/kernel/xsched/cfs_quota.c index 9de74d547931..6a1089abbaef 100644 --- a/kernel/xsched/cfs_quota.c +++ b/kernel/xsched/cfs_quota.c @@ -79,9 +79,10 @@ static void xsched_group_unthrottle(struct xsched_group *xg) void xsched_quota_refill(struct work_struct *work) { - struct xsched_group *xg; + struct xsched_group *xg = container_of(work, struct xsched_group, refill_work); - xg = container_of(work, struct xsched_group, refill_work); + if (READ_ONCE(xg->is_offline)) + return; spin_lock(&xg->lock); xg->runtime = max((xg->runtime - xg->quota), (s64)0); diff --git a/kernel/xsched/cgroup.c b/kernel/xsched/cgroup.c index 94df3005bf36..d780eb97ec47 100644 --- a/kernel/xsched/cgroup.c +++ b/kernel/xsched/cgroup.c @@ -242,14 +242,10 @@ static void xcu_css_free(struct cgroup_subsys_state *css) static void delay_xcu_cg_set_file_show_workfn(struct work_struct *work) { - struct xsched_group *xg; - - xg = container_of(work, struct xsched_group, file_show_work); + struct xsched_group *xg = container_of(work, struct xsched_group, file_show_work); - if (!xg) { - XSCHED_ERR("xsched_group cannot be null @ %s", __func__); + if (READ_ONCE(xg->is_offline)) return; - } for (int i = 0; i < XCUCG_SET_FILE_RETRY_COUNT; i++) { if (!xcu_cg_set_file_show(xg, xg->sched_class)) -- 2.34.1
反馈: 您发送到kernel@openeuler.org的补丁/补丁集,转换为PR失败! 邮件列表地址:https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/DK6... 失败原因:应用补丁/补丁集失败,Patch failed at 0001 xsched: replace magic number with SCHED_CLASS_MAX_LENGTH for scheduler class string length 建议解决方法:请查看失败原因, 确认补丁是否可以应用在当前期望分支的最新代码上 FeedBack: The patch(es) which you have sent to kernel@openeuler.org has been converted to PR failed! Mailing list address: https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/DK6... Failed Reason: apply patch(es) failed, Patch failed at 0001 xsched: replace magic number with SCHED_CLASS_MAX_LENGTH for scheduler class string length Suggest Solution: please checkout if the failed patch(es) can work on the newest codes in expected branch
participants (2)
-
Liu Kai -
patchwork bot