[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20251106-20251010_shubhang_os_amperecomputing_com-v1-1-7535957d8ac6@os.amperecomputing.com>
Date: Thu, 06 Nov 2025 23:32:02 -0800
From: Shubhang Kaushik via B4 Relay <devnull+shubhang.os.amperecomputing.com@...nel.org>
To: Ingo Molnar <mingo@...hat.com>, Peter Zijlstra <peterz@...radead.org>,
Juri Lelli <juri.lelli@...hat.com>,
Vincent Guittot <vincent.guittot@...aro.org>,
Dietmar Eggemann <dietmar.eggemann@....com>,
Steven Rostedt <rostedt@...dmis.org>, Ben Segall <bsegall@...gle.com>,
Mel Gorman <mgorman@...e.de>, Valentin Schneider <vschneid@...hat.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Aaron Lu <ziqianlu@...edance.com>, Josh Don <joshdon@...gle.com>,
Ben Segall <bsegall@...gle.com>, Shubhang Kaushik <sh@...two.org>,
"Christoph Lameter (Ampere)" <cl@...two.org>
Cc: linux-kernel@...r.kernel.org,
Shubhang Kaushik <shubhang@...amperecomputing.com>
Subject: [PATCH RESEND] sched/fair: Add helper to handle leaf cfs_rq
addition
From: Shubhang Kaushik <shubhang@...amperecomputing.com>
Refactor the logic for adding a cfs_rq to the leaf list into a helper
function.
The existing code repeated the logic to check if the cfs_rq was
throttled and added it to the leaf list. This change extracts that
logic into the static inline helper `__cfs_rq_maybe_add_leaf()`, which
is a more robust naming convention for an internal helper.
This refactoring removes code duplication and makes the parent function,
`propagate_entity_cfs_rq()`, cleaner and easier to read.
Signed-off-by: Shubhang Kaushik <shubhang@...amperecomputing.com>
---
kernel/sched/fair.c | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 25970dbbb27959bc130d288d5f80677f75f8db8b..13140fab37ce7870f8079e789ff24c409747e27d 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -13169,6 +13169,18 @@ prio_changed_fair(struct rq *rq, struct task_struct *p, int oldprio)
}
#ifdef CONFIG_FAIR_GROUP_SCHED
+/*
+ * If a task gets attached to this cfs_rq and, before being queued,
+ * it gets migrated to another CPU (e.g., due to reasons like affinity change),
+ * this cfs_rq must remain on leaf cfs_rq list. This allows the
+ * removed load to decay properly; otherwise, it can cause a fairness problem.
+ */
+static inline void __cfs_rq_maybe_add_leaf(struct cfs_rq *cfs_rq)
+{
+ if (!cfs_rq_pelt_clock_throttled(cfs_rq))
+ list_add_leaf_cfs_rq(cfs_rq);
+}
+
/*
* Propagate the changes of the sched_entity across the tg tree to make it
* visible to the root
@@ -13177,14 +13189,7 @@ static void propagate_entity_cfs_rq(struct sched_entity *se)
{
struct cfs_rq *cfs_rq = cfs_rq_of(se);
- /*
- * If a task gets attached to this cfs_rq and before being queued,
- * it gets migrated to another CPU due to reasons like affinity
- * change, make sure this cfs_rq stays on leaf cfs_rq list to have
- * that removed load decayed or it can cause faireness problem.
- */
- if (!cfs_rq_pelt_clock_throttled(cfs_rq))
- list_add_leaf_cfs_rq(cfs_rq);
+ __cfs_rq_maybe_add_leaf(cfs_rq);
/* Start to propagate at parent */
se = se->parent;
@@ -13194,8 +13199,7 @@ static void propagate_entity_cfs_rq(struct sched_entity *se)
update_load_avg(cfs_rq, se, UPDATE_TG);
- if (!cfs_rq_pelt_clock_throttled(cfs_rq))
- list_add_leaf_cfs_rq(cfs_rq);
+ __cfs_rq_maybe_add_leaf(cfs_rq);
}
assert_list_leaf_cfs_rq(rq_of(cfs_rq));
---
base-commit: 6146a0f1dfae5d37442a9ddcba012add260bceb0
change-id: 20251106-20251010_shubhang_os_amperecomputing_com-218ddcbcf820
Best regards,
--
Shubhang Kaushik <shubhang@...amperecomputing.com>
Powered by blists - more mailing lists