Skip to contentSkip to conversation

sched_ext: Move built-in idle CPU selection policy to a separate file

PATCH Superseded Andrea Righi 2 participants 2 messages Jan 25, 2025 – Jan 27, 2025 Scheduler

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 sched_ext: Move built-in idle CPU selection policy to a separate file

As ext.c is becoming quite large, move the idle CPU selection policy to separate files (ext_idle.c / ext_idle.h) for better code readability.

Moreover, group together all the idle CPU selection kfunc's to the same btf_kfunc_id_set block.

No functional changes, this is purely code reorganization.

---
 MAINTAINERS                 |   3 +-
 kernel/sched/build_policy.c |   1 +
 kernel/sched/ext.c          | 737 +----------------------------------
 kernel/sched/ext_idle.c     | 740 ++++++++++++++++++++++++++++++++++++
 kernel/sched/ext_idle.h     |  40 ++
 5 files changed, 797 insertions(+), 724 deletions(-)
 create mode 100644 kernel/sched/ext_idle.c
 create mode 100644 kernel/sched/ext_idle.h

ChangeLog v1 -> v2:
- move idle kfuncs to a separate btf ids set (scx_kfunc_set_idle)
- declare idle functions as extern prototypes with an "scx_idle_" prefix

MAINTAINERS +1 -2
index 4e3a9c3fcb8c..021ef04afa00 100644
@@ -21006,8 +21006,7 @@ S:	Maintained
 W:	https://github.com/sched-ext/scx
 T:	git://git.kernel.org/pub/scm/linux/kernel/git/tj/sched_ext.git
 F:	include/linux/sched/ext.h
-F:	kernel/sched/ext.h
-F:	kernel/sched/ext.c
+F:	kernel/sched/ext*
 F:	tools/sched_ext/
 F:	tools/testing/selftests/sched_ext
 
kernel/sched/build_policy.c +1 -0
index fae1f5c921eb..72d97aa8b726 100644
@@ -61,6 +61,7 @@
 
 #ifdef CONFIG_SCHED_CLASS_EXT
 # include "ext.c"
+# include "ext_idle.c"
 #endif
 
 #include "syscalls.c"
kernel/sched/ext.c +15 -722

815 lines not on this page · raw message

kernel/sched/ext_idle.c new file +740 -0

740 lines not on this page · raw message

kernel/sched/ext_idle.h new file +40 -0
new file mode 100644
index 000000000000..2b0502c4356a
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * BPF extensible scheduler class: Documentation/scheduler/sched-ext.rst
+ *
+ * Copyright (c) 2022 Meta Platforms, Inc. and affiliates.
+ * Copyright (c) 2022 Tejun Heo <[email protected]>
+ * Copyright (c) 2022 David Vernet <[email protected]>
+ * Copyright (c) 2024 Andrea Righi <[email protected]>
+ */
+#ifndef _KERNEL_SCHED_EXT_IDLE_H
+#define _KERNEL_SCHED_EXT_IDLE_H
+
+extern struct static_key_false scx_builtin_idle_enabled;
+
+#ifdef CONFIG_SMP
+extern struct static_key_false scx_selcpu_topo_llc;
+extern struct static_key_false scx_selcpu_topo_numa;
+
+void scx_idle_update_selcpu_topology(void);
+void scx_idle_reset_masks(void);
+void scx_idle_init_masks(void);
+bool scx_idle_test_and_clear_cpu(int cpu);
+s32 scx_pick_idle_cpu(const struct cpumask *cpus_allowed, u64 flags);
+#else /* !CONFIG_SMP */
+static inline void scx_idle_update_selcpu_topology(void) {}
+static inline void scx_idle_reset_masks(void) {}
+static inline void scx_idle_init_masks(void) {}
+static inline bool scx_idle_test_and_clear_cpu(int cpu) { return false; }
+static inline s32 scx_pick_idle_cpu(const struct cpumask *cpus_allowed, u64 flags)
+{
+	return -EBUSY;
+}
+#endif /* CONFIG_SMP */
+
+s32 scx_select_cpu_dfl(struct task_struct *p, s32 prev_cpu, u64 wake_flags, bool *found);
+
+extern const struct btf_kfunc_id_set scx_kfunc_set_select_cpu;
+extern const struct btf_kfunc_id_set scx_kfunc_set_idle;
+
+#endif /* _KERNEL_SCHED_EXT_IDLE_H */
Signature · 1 line
2.48.1
#1 lore raw

On Sat, Jan 25, 2025 at 10:39:11PM +0100, Andrea Righi wrote:
...

kernel/sched/ext.c static int __init scx_init(void) · line 7118

Quoted 10 lines
kernel/sched/ext.c +6 -0
@@ -7823,6 +7110,12 @@ static int __init scx_init(void)
 					     &scx_kfunc_set_unlocked)) ||
 	    (ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_SYSCALL,
 					     &scx_kfunc_set_unlocked)) ||
+	    (ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS,
+					     &scx_kfunc_set_idle)) ||
+	    (ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_TRACING,
+					     &scx_kfunc_set_idle)) ||
+	    (ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_SYSCALL,
+					     &scx_kfunc_set_idle)) ||

Just one more change. Can you please make the set themselves static in ext_idle.c and then register them from its own init function which is called from scx_init()?

Thanks.

Signature · 1 line
tejun