diff mbox series

[08/10] sched_ext: idle: introduce SCX_PICK_IDLE_NODE

Message ID 20241220154107.287478-9-arighi@nvidia.com (mailing list archive)
State New
Headers show
Series [01/10] sched/topology: introduce for_each_numa_hop_node() / sched_numa_hop_node() | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Andrea Righi Dec. 20, 2024, 3:11 p.m. UTC
Introduce a flag to restrict the selection of an idle CPU to a specific
NUMA node.

Signed-off-by: Andrea Righi <arighi@nvidia.com>
---
 kernel/sched/ext.c      |  1 +
 kernel/sched/ext_idle.c | 11 +++++++++--
 2 files changed, 10 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
index 143938e935f1..da5c15bd3c56 100644
--- a/kernel/sched/ext.c
+++ b/kernel/sched/ext.c
@@ -773,6 +773,7 @@  enum scx_deq_flags {
 
 enum scx_pick_idle_cpu_flags {
 	SCX_PICK_IDLE_CORE	= 1LLU << 0,	/* pick a CPU whose SMT siblings are also idle */
+	SCX_PICK_IDLE_NODE	= 1LLU << 1,	/* pick a CPU in the same target NUMA node */
 };
 
 enum scx_kick_flags {
diff --git a/kernel/sched/ext_idle.c b/kernel/sched/ext_idle.c
index 444f2a15f1d4..013deaa08f12 100644
--- a/kernel/sched/ext_idle.c
+++ b/kernel/sched/ext_idle.c
@@ -199,6 +199,12 @@  static s32 scx_pick_idle_cpu(const struct cpumask *cpus_allowed, int node, u64 f
 		cpu = pick_idle_cpu_from_node(cpus_allowed, n, flags);
 		if (cpu >= 0)
 			break;
+		/*
+		 * Check if the search is restricted to the same core or
+		 * the same node.
+		 */
+		if (flags & SCX_PICK_IDLE_NODE)
+			break;
 	}
 
 	return cpu;
@@ -495,7 +501,8 @@  static s32 scx_select_cpu_dfl(struct task_struct *p, s32 prev_cpu,
 		 * Search for any fully idle core in the same LLC domain.
 		 */
 		if (llc_cpus) {
-			cpu = pick_idle_cpu_from_node(llc_cpus, node, SCX_PICK_IDLE_CORE);
+			cpu = scx_pick_idle_cpu(llc_cpus, node,
+						SCX_PICK_IDLE_CORE | SCX_PICK_IDLE_NODE);
 			if (cpu >= 0)
 				goto cpu_found;
 		}
@@ -533,7 +540,7 @@  static s32 scx_select_cpu_dfl(struct task_struct *p, s32 prev_cpu,
 	 * Search for any idle CPU in the same LLC domain.
 	 */
 	if (llc_cpus) {
-		cpu = pick_idle_cpu_from_node(llc_cpus, node, 0);
+		cpu = scx_pick_idle_cpu(llc_cpus, node, SCX_PICK_IDLE_NODE);
 		if (cpu >= 0)
 			goto cpu_found;
 	}