[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <bd767d696636f233f30f334d41f46ce45c256948.1754712565.git.tim.c.chen@linux.intel.com>
Date: Sat, 9 Aug 2025 13:04:04 +0800
From: Chen Yu <yu.c.chen@...el.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: Vincent Guittot <vincent.guittot@...aro.org>,
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>,
Libo Chen <libo.chen@...cle.com>,
Madadi Vineeth Reddy <vineethr@...ux.ibm.com>,
Hillf Danton <hdanton@...a.com>,
Shrikanth Hegde <sshegde@...ux.ibm.com>,
Jianyong Wu <jianyong.wu@...look.com>,
Yangyu Chen <cyy@...self.name>,
Tingyin Duan <tingyin.duan@...il.com>,
Vern Hao <vernhao@...cent.com>,
Len Brown <len.brown@...el.com>,
Tim Chen <tim.c.chen@...ux.intel.com>,
Aubrey Li <aubrey.li@...el.com>,
Zhao Liu <zhao1.liu@...el.com>,
Chen Yu <yu.chen.surf@...il.com>,
Chen Yu <yu.c.chen@...el.com>,
linux-kernel@...r.kernel.org
Subject: [RFC PATCH v4 10/28] sched: Calculate the number of tasks that have LLC preference on a runqueue
From: Tim Chen <tim.c.chen@...ux.intel.com>
Track for each run queue, the number of tasks that have a LLC preference
and how many of those tasks are running in its preferred LLC. This is
similar to nr_numa_running and nr_preferred_running for NUMA balance,
and will be used by the cache-aware load balancing in subsequent patches.
Signed-off-by: Tim Chen <tim.c.chen@...ux.intel.com>
---
kernel/sched/core.c | 12 +++++++++++
kernel/sched/fair.c | 51 +++++++++++++++++++++++++++++++++++++++++++-
kernel/sched/sched.h | 7 ++++++
3 files changed, 69 insertions(+), 1 deletion(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index a5fb3057b1c4..a97a8039ce91 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -499,6 +499,18 @@ void __trace_set_current_state(int state_value)
}
EXPORT_SYMBOL(__trace_set_current_state);
+#ifdef CONFIG_SMP
+int task_llc(const struct task_struct *p)
+{
+ return per_cpu(sd_llc_id, task_cpu(p));
+}
+#else
+int task_llc(const struct task_struct *p)
+{
+ return 0;
+}
+#endif
+
/*
* Serialization rules:
*
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 94ad84ba19e1..f964d5a44fcc 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -1195,6 +1195,24 @@ static inline int llc_idx(int cpu)
return per_cpu(sd_llc_idx, cpu);
}
+static void account_llc_enqueue(struct rq *rq, struct task_struct *p)
+{
+ if (!sched_feat(SCHED_CACHE))
+ return;
+
+ rq->nr_llc_running += (p->preferred_llc != -1);
+ rq->nr_pref_llc_running += (p->preferred_llc == task_llc(p));
+}
+
+static void account_llc_dequeue(struct rq *rq, struct task_struct *p)
+{
+ if (!sched_feat(SCHED_CACHE))
+ return;
+
+ rq->nr_llc_running -= (p->preferred_llc != -1);
+ rq->nr_pref_llc_running -= (p->preferred_llc == task_llc(p));
+}
+
void mm_init_sched(struct mm_struct *mm, struct mm_sched __percpu *_pcpu_sched)
{
unsigned long epoch;
@@ -1303,8 +1321,11 @@ void account_mm_sched(struct rq *rq, struct task_struct *p, s64 delta_exec)
if (mm->mm_sched_cpu != -1)
mm_sched_llc = per_cpu(sd_llc_id, mm->mm_sched_cpu);
- if (p->preferred_llc != mm_sched_llc)
+ if (p->preferred_llc != mm_sched_llc) {
+ account_llc_dequeue(rq, p);
p->preferred_llc = mm_sched_llc;
+ account_llc_enqueue(rq, p);
+ }
}
static void task_tick_cache(struct rq *rq, struct task_struct *p)
@@ -1408,6 +1429,17 @@ void init_sched_mm(struct task_struct *p)
work->next = work;
}
+void reset_llc_stats(struct rq *rq)
+{
+ if (!sched_feat(SCHED_CACHE))
+ return;
+
+ if (rq->nr_llc_running)
+ rq->nr_llc_running = 0;
+
+ rq->nr_pref_llc_running = 0;
+}
+
#else
static inline void account_mm_sched(struct rq *rq, struct task_struct *p,
@@ -1418,6 +1450,17 @@ void init_sched_mm(struct task_struct *p) { }
static void task_tick_cache(struct rq *rq, struct task_struct *p) { }
+static void account_llc_enqueue(struct rq *rq, struct task_struct *p)
+{
+}
+
+static void account_llc_dequeue(struct rq *rq, struct task_struct *p)
+{
+}
+
+void reset_llc_stats(struct rq *rq)
+{
+}
#endif
static inline
@@ -3957,6 +4000,7 @@ account_entity_enqueue(struct cfs_rq *cfs_rq, struct sched_entity *se)
struct rq *rq = rq_of(cfs_rq);
account_numa_enqueue(rq, task_of(se));
+ account_llc_enqueue(rq, task_of(se));
list_add(&se->group_node, &rq->cfs_tasks);
}
#endif
@@ -3970,10 +4014,15 @@ account_entity_dequeue(struct cfs_rq *cfs_rq, struct sched_entity *se)
#ifdef CONFIG_SMP
if (entity_is_task(se)) {
account_numa_dequeue(rq_of(cfs_rq), task_of(se));
+ account_llc_dequeue(rq_of(cfs_rq), task_of(se));
list_del_init(&se->group_node);
}
#endif
cfs_rq->nr_queued--;
+
+ /* safeguard? */
+ if (!parent_entity(se) && !cfs_rq->nr_queued)
+ reset_llc_stats(rq_of(cfs_rq));
}
/*
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index c37c74dfce25..8026e2c66e9f 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -1106,6 +1106,10 @@ struct rq {
unsigned int nr_preferred_running;
unsigned int numa_migrate_on;
#endif
+#ifdef CONFIG_SCHED_CACHE
+ unsigned int nr_pref_llc_running;
+ unsigned int nr_llc_running;
+#endif
#ifdef CONFIG_NO_HZ_COMMON
#ifdef CONFIG_SMP
unsigned long last_blocked_load_update_tick;
@@ -1967,6 +1971,9 @@ init_numa_balancing(unsigned long clone_flags, struct task_struct *p)
#endif /* !CONFIG_NUMA_BALANCING */
+void reset_llc_stats(struct rq *rq);
+int task_llc(const struct task_struct *p);
+
#ifdef CONFIG_SMP
static inline void
--
2.25.1
Powered by blists - more mailing lists