hulk inclusion category: cleanup bugzilla: https://atomgit.com/openeuler/kernel/issues/8423 -------------------------------- The fields nr_throttled, start_throttled_time, and throttled_time are exclusively used in the CFS scheduling path and have no meaning in non-CFS contexts. To improve code clarity and data structure organization, these members are now moved from the generic xsched_group_xcu_priv structure into the CFS-specific xsched_rq_cfs sub-structure. - Encapsulates throttling state within the CFS context where it is actually used, making the code easier to maintain and extend. - Reduces unnecessary fields for non-CFS schedulers. Signed-off-by: Liu Kai <liukai284@huawei.com> --- include/linux/xsched.h | 11 ++++++----- kernel/xsched/cfs_quota.c | 27 ++++++++++++++------------- kernel/xsched/cgroup.c | 9 +++++---- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/include/linux/xsched.h b/include/linux/xsched.h index 76b4ce815870..ade26d148809 100644 --- a/include/linux/xsched.h +++ b/include/linux/xsched.h @@ -85,6 +85,10 @@ struct xsched_rq_cfs { struct rb_root_cached ctx_timeline; bool throttled; + /* Statistics */ + int nr_throttled; + u64 throttled_time; + ktime_t start_throttled_time; }; /* Base XSched runqueue object structure that contains both mutual and @@ -244,11 +248,6 @@ struct xsched_group_xcu_priv { struct xsched_entity xse; /* xse of this group on runqueue */ struct xsched_rq_cfs *cfs_rq; /* cfs runqueue "owned" by this group */ struct xsched_rq_rt *rt_rq; /* rt runqueue "owned" by this group */ - - /* Statistics */ - int nr_throttled; - u64 throttled_time; - ktime_t start_throttled_time; }; enum xcu_file_type { @@ -308,6 +307,8 @@ struct xsched_group { #define xsched_cfs_rq_of(xse) (xse_parent_grp_xcu((xse))->cfs_rq) +#define xsched_group_cfs_rq(__xg, __id) ((__xg)->perxcu_priv[(__id)].cfs_rq) + #define for_each_xse(__xse) \ for (; (__xse) && (__xse)->parent_grp; \ (__xse) = &(xse_parent_grp_xcu((__xse))->xse)) diff --git a/kernel/xsched/cfs_quota.c b/kernel/xsched/cfs_quota.c index dbf6f88e3f07..713bd6436cb7 100644 --- a/kernel/xsched/cfs_quota.c +++ b/kernel/xsched/cfs_quota.c @@ -22,19 +22,20 @@ static struct workqueue_struct *quota_workqueue; static void xsched_group_throttle(struct xsched_group *xg, struct xsched_cu *xcu) { int xcu_id = xcu->id; - ktime_t now = ktime_get(); + struct xsched_rq_cfs *cfs_rq; if (!xg || READ_ONCE(xg->is_offline)) return; lockdep_assert_held(&xcu->xcu_lock); - if (xg->perxcu_priv[xcu_id].cfs_rq->throttled) + cfs_rq = xsched_group_cfs_rq(xg, xcu_id); + if (cfs_rq->throttled) return; - xg->perxcu_priv[xcu_id].cfs_rq->throttled = true; - xg->perxcu_priv[xcu_id].nr_throttled++; - xg->perxcu_priv[xcu_id].start_throttled_time = now; + cfs_rq->throttled = true; + cfs_rq->nr_throttled++; + cfs_rq->start_throttled_time = ktime_get(); /** * When an xse triggers XCU throttling, only the corresponding gse is @@ -47,6 +48,7 @@ static void xsched_group_throttle(struct xsched_group *xg, struct xsched_cu *xcu static void xsched_group_unthrottle(struct xsched_group *xg) { + struct xsched_rq_cfs *cfs_rq; struct xsched_cu *xcu; ktime_t now = ktime_get(); int id; @@ -59,8 +61,8 @@ static void xsched_group_unthrottle(struct xsched_group *xg) return; } - if (!xg->perxcu_priv[id].cfs_rq || - !xg->perxcu_priv[id].cfs_rq->throttled) { + cfs_rq = xsched_group_cfs_rq(xg, id); + if (!cfs_rq || !cfs_rq->throttled) { mutex_unlock(&xcu->xcu_lock); continue; } @@ -69,13 +71,12 @@ static void xsched_group_unthrottle(struct xsched_group *xg) * Avoid inserting empty groups into the rbtree; * only mark them as throttled. */ - xg->perxcu_priv[id].cfs_rq->throttled = false; - xg->perxcu_priv[id].throttled_time += - ktime_to_ns(ktime_sub(now, - xg->perxcu_priv[id].start_throttled_time)); - xg->perxcu_priv[id].start_throttled_time = 0; + cfs_rq->throttled = false; + cfs_rq->throttled_time += ktime_to_ns( + ktime_sub(now, cfs_rq->start_throttled_time)); + cfs_rq->start_throttled_time = 0; - if (xg->perxcu_priv[id].cfs_rq->nr_running > 0) { + if (cfs_rq->nr_running > 0) { enqueue_ctx(&xg->perxcu_priv[id].xse, xcu); wake_up_interruptible(&xcu->wq_xcu_idle); } diff --git a/kernel/xsched/cgroup.c b/kernel/xsched/cgroup.c index c9779f4224e0..95a09485f667 100644 --- a/kernel/xsched/cgroup.c +++ b/kernel/xsched/cgroup.c @@ -686,20 +686,21 @@ static int xcu_stat(struct seq_file *sf, void *v) { struct cgroup_subsys_state *css = seq_css(sf); struct xsched_group *xcucg = xcu_cg_from_css(css); + struct xsched_rq_cfs *cfs_rq; u64 nr_throttled = 0; u64 throttled_time = 0; u64 exec_runtime = 0; int xcu_id; - struct xsched_cu *xcu; if (xcucg->sched_class == XSCHED_TYPE_RT) { seq_printf(sf, "RT group stat is not supported @ %s.\n", __func__); return 0; } - for_each_active_xcu(xcu, xcu_id) { - nr_throttled += xcucg->perxcu_priv[xcu_id].nr_throttled; - throttled_time += xcucg->perxcu_priv[xcu_id].throttled_time; + for (xcu_id = 0; xcu_id < num_active_xcu; xcu_id++) { + cfs_rq = xsched_group_cfs_rq(xcucg, xcu_id); + nr_throttled += cfs_rq->nr_throttled; + throttled_time += cfs_rq->throttled_time; exec_runtime += xcucg->perxcu_priv[xcu_id].xse.cfs.sum_exec_runtime; } -- 2.34.1