]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
sched_ext: idle: Introduce scx_bpf_nr_node_ids()
authorAndrea Righi <arighi@nvidia.com>
Mon, 24 Feb 2025 16:49:21 +0000 (17:49 +0100)
committerTejun Heo <tj@kernel.org>
Mon, 24 Feb 2025 17:37:42 +0000 (07:37 -1000)
Similarly to scx_bpf_nr_cpu_ids(), introduce a new kfunc
scx_bpf_nr_node_ids() to expose the maximum number of NUMA nodes in the
system.

BPF schedulers can use this information together with the new node-aware
kfuncs, for example to create per-node DSQs, validate node IDs, etc.

Signed-off-by: Andrea Righi <arighi@nvidia.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
kernel/sched/ext.c
tools/sched_ext/include/scx/common.bpf.h
tools/sched_ext/include/scx/compat.bpf.h

index 95603db36f043d1db3698ae664b1f3aca47b29c7..74b247c36b3df25200cbe37c0361cc6e6b3d163d 100644 (file)
@@ -7113,6 +7113,16 @@ __bpf_kfunc void scx_bpf_cpuperf_set(s32 cpu, u32 perf)
        }
 }
 
+/**
+ * scx_bpf_nr_node_ids - Return the number of possible node IDs
+ *
+ * All valid node IDs in the system are smaller than the returned value.
+ */
+__bpf_kfunc u32 scx_bpf_nr_node_ids(void)
+{
+       return nr_node_ids;
+}
+
 /**
  * scx_bpf_nr_cpu_ids - Return the number of possible CPU IDs
  *
@@ -7325,6 +7335,7 @@ BTF_ID_FLAGS(func, scx_bpf_dump_bstr, KF_TRUSTED_ARGS)
 BTF_ID_FLAGS(func, scx_bpf_cpuperf_cap)
 BTF_ID_FLAGS(func, scx_bpf_cpuperf_cur)
 BTF_ID_FLAGS(func, scx_bpf_cpuperf_set)
+BTF_ID_FLAGS(func, scx_bpf_nr_node_ids)
 BTF_ID_FLAGS(func, scx_bpf_nr_cpu_ids)
 BTF_ID_FLAGS(func, scx_bpf_get_possible_cpumask, KF_ACQUIRE)
 BTF_ID_FLAGS(func, scx_bpf_get_online_cpumask, KF_ACQUIRE)
index ca7cc4108b45f2fbf988d12fbd700ecc072fc98a..0e558775909013f22ce992e70c3fb024192ebbb9 100644 (file)
@@ -70,6 +70,7 @@ void scx_bpf_dump_bstr(char *fmt, unsigned long long *data, u32 data_len) __ksym
 u32 scx_bpf_cpuperf_cap(s32 cpu) __ksym __weak;
 u32 scx_bpf_cpuperf_cur(s32 cpu) __ksym __weak;
 void scx_bpf_cpuperf_set(s32 cpu, u32 perf) __ksym __weak;
+u32 scx_bpf_nr_node_ids(void) __ksym __weak;
 u32 scx_bpf_nr_cpu_ids(void) __ksym __weak;
 int scx_bpf_cpu_node(s32 cpu) __ksym __weak;
 const struct cpumask *scx_bpf_get_possible_cpumask(void) __ksym __weak;
index 5a9bcdb52e797cc57e4c2cdbd4dd84bd6d418fa4..266f94fe479b7f6140231c6e90bd799abe41f446 100644 (file)
@@ -189,6 +189,10 @@ static inline bool __COMPAT_is_enq_cpu_selected(u64 enq_flags)
  *
  * Preserve the following __COMPAT_scx_*_node macros until v6.17.
  */
+#define __COMPAT_scx_bpf_nr_node_ids()                                         \
+       (bpf_ksym_exists(scx_bpf_nr_node_ids) ?                                 \
+        scx_bpf_nr_node_ids() : 1U)
+
 #define __COMPAT_scx_bpf_cpu_node(cpu)                                         \
        (bpf_ksym_exists(scx_bpf_cpu_node) ?                                    \
         scx_bpf_cpu_node(cpu) : 0)