[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <9d28a5a892f0413a96498bbf711eaa9b354ca895.1750268218.git.tim.c.chen@linux.intel.com>
Date: Wed, 18 Jun 2025 11:28:05 -0700
From: Tim Chen <tim.c.chen@...ux.intel.com>
To: Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...hat.com>,
K Prateek Nayak <kprateek.nayak@....com>,
"Gautham R . Shenoy" <gautham.shenoy@....com>
Cc: Tim Chen <tim.c.chen@...ux.intel.com>,
Juri Lelli <juri.lelli@...hat.com>,
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>,
Tim Chen <tim.c.chen@...el.com>,
Vincent Guittot <vincent.guittot@...aro.org>,
Libo Chen <libo.chen@...cle.com>,
Abel Wu <wuyun.abel@...edance.com>,
Madadi Vineeth Reddy <vineethr@...ux.ibm.com>,
Hillf Danton <hdanton@...a.com>,
Len Brown <len.brown@...el.com>,
linux-kernel@...r.kernel.org,
Chen Yu <yu.c.chen@...el.com>
Subject: [RFC patch v3 17/20] sched: Consider LLC preference when picking tasks from busiest queue
When picking tasks from busiest queue for load balance, we currently
do not consider LLC preference.
Order the task in the busiest queue such that we picked the tasks in the
following order:
1. tasks that prefer dst cpu's LLC
2. tasks that have no preference in LLC
3. tasks that prefer LLC other than the ones they are on
4. tasks that prefer the LLC that they are currently on
This will allow tasks better chances to wind up in its preferred LLC.
Signed-off-by: Tim Chen <tim.c.chen@...ux.intel.com>
---
kernel/sched/fair.c | 66 ++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 65 insertions(+), 1 deletion(-)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 3a8f6fc52055..c9db32c2df63 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -10056,6 +10056,68 @@ static struct task_struct *detach_one_task(struct lb_env *env)
return NULL;
}
+#ifdef CONFIG_SCHED_CACHE
+/*
+ * Prepare lists to detach tasks in the following order:
+ * 1. tasks that prefer dst cpu's LLC
+ * 2. tasks that have no preference in LLC
+ * 3. tasks that prefer LLC other than the ones they are on
+ * 4. tasks that prefer the LLC that they are currently on.
+ */
+static struct list_head
+*order_tasks_by_llc(struct lb_env *env, struct list_head *tasks)
+{
+ struct task_struct *p;
+ LIST_HEAD(pref_old_llc);
+ LIST_HEAD(pref_new_llc);
+ LIST_HEAD(no_pref_llc);
+ LIST_HEAD(pref_other_llc);
+
+ if (!sched_feat(SCHED_CACHE))
+ return tasks;
+
+ if (cpus_share_cache(env->dst_cpu, env->src_cpu))
+ return tasks;
+
+ while (!list_empty(tasks)) {
+ p = list_last_entry(tasks, struct task_struct, se.group_node);
+
+ if (p->preferred_llc == llc_id(env->dst_cpu)) {
+ list_move(&p->se.group_node, &pref_new_llc);
+ continue;
+ }
+
+ if (p->preferred_llc == llc_id(env->src_cpu)) {
+ list_move(&p->se.group_node, &pref_old_llc);
+ continue;
+ }
+
+ if (p->preferred_llc == -1) {
+ list_move(&p->se.group_node, &no_pref_llc);
+ continue;
+ }
+
+ list_move(&p->se.group_node, &pref_other_llc);
+ }
+
+ /*
+ * We detach tasks from list tail in detach tasks. Put tasks
+ * to be chosen first at end of list.
+ */
+ list_splice(&pref_new_llc, tasks);
+ list_splice(&no_pref_llc, tasks);
+ list_splice(&pref_other_llc, tasks);
+ list_splice(&pref_old_llc, tasks);
+ return tasks;
+}
+#else
+static inline struct list_head
+*order_tasks_by_llc(struct lb_env *env, struct list_head *tasks)
+{
+ return tasks;
+}
+#endif
+
/*
* detach_tasks() -- tries to detach up to imbalance load/util/tasks from
* busiest_rq, as part of a balancing operation within domain "sd".
@@ -10064,7 +10126,7 @@ static struct task_struct *detach_one_task(struct lb_env *env)
*/
static int detach_tasks(struct lb_env *env)
{
- struct list_head *tasks = &env->src_rq->cfs_tasks;
+ struct list_head *tasks;
unsigned long util, load;
struct task_struct *p;
int detached = 0;
@@ -10083,6 +10145,8 @@ static int detach_tasks(struct lb_env *env)
if (env->imbalance <= 0)
return 0;
+ tasks = order_tasks_by_llc(env, &env->src_rq->cfs_tasks);
+
while (!list_empty(tasks)) {
/*
* We don't want to steal all, otherwise we may be treated likewise,
--
2.32.0
Powered by blists - more mailing lists