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 e6baca2211be..b9a159d1aba8 100644 --- a/include/linux/xsched.h +++ b/include/linux/xsched.h @@ -313,7 +313,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) static inline struct xsched_group_xcu_priv * xse_this_grp_xcu(struct xsched_entity_cfs *xse_cfs) diff --git a/kernel/xsched/cgroup.c b/kernel/xsched/cgroup.c index a12a5cd86094..e2cd8a798438 100644 --- a/kernel/xsched/cgroup.c +++ b/kernel/xsched/cgroup.c @@ -102,6 +102,7 @@ void init_fair_xsched_group(struct xsched_group *xg, { int id = xcu->id; + /* Ensure non-root group has a valid parent */ if (xg != root_xcg && WARN_ON(!xg->parent)) return; @@ -202,11 +203,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 @@ -299,7 +295,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); @@ -548,7 +544,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