From e1f6f964f4017466a0757af96322d88ebe2a9a8c Mon Sep 17 00:00:00 2001 From: Tejun Heo Date: Sun, 16 Jun 2024 14:10:41 -1000 Subject: [PATCH] tools/sched_ext: Sync from the scx repo (b6ebdc635acf450e9c2e71717500556cd3cf67a1) --- tools/sched_ext/include/scx/common.h | 7 ++- tools/sched_ext/include/scx/compat.bpf.h | 77 ------------------------ tools/sched_ext/include/scx/compat.h | 48 +++------------ tools/sched_ext/scx_central.bpf.c | 3 +- tools/sched_ext/scx_qmap.bpf.c | 28 +++------ tools/sched_ext/scx_qmap.c | 3 +- tools/sched_ext/scx_simple.bpf.c | 1 - 7 files changed, 23 insertions(+), 144 deletions(-) diff --git a/tools/sched_ext/include/scx/common.h b/tools/sched_ext/include/scx/common.h index 49234dad00a15..5b0f901521523 100644 --- a/tools/sched_ext/include/scx/common.h +++ b/tools/sched_ext/include/scx/common.h @@ -28,8 +28,11 @@ typedef int64_t s64; #define SCX_BUG(__fmt, ...) \ do { \ - fprintf(stderr, "%s:%d [scx panic]: %s\n", __FILE__, __LINE__, \ - strerror(errno)); \ + fprintf(stderr, "[SCX_BUG] %s:%d", __FILE__, __LINE__); \ + if (errno) \ + fprintf(stderr, " (%s)\n", strerror(errno)); \ + else \ + fprintf(stderr, "\n"); \ fprintf(stderr, __fmt __VA_OPT__(,) __VA_ARGS__); \ fprintf(stderr, "\n"); \ \ diff --git a/tools/sched_ext/include/scx/compat.bpf.h b/tools/sched_ext/include/scx/compat.bpf.h index 914baac2e9657..1106c7eee279d 100644 --- a/tools/sched_ext/include/scx/compat.bpf.h +++ b/tools/sched_ext/include/scx/compat.bpf.h @@ -15,83 +15,6 @@ __ret; \ }) -/* - * %SCX_KICK_IDLE is a later addition. To support both before and after, use - * %__COMPAT_SCX_KICK_IDLE which becomes 0 on kernels which don't support it. - * Users can use %SCX_KICK_IDLE directly in the future. - */ -#define __COMPAT_SCX_KICK_IDLE \ - __COMPAT_ENUM_OR_ZERO(enum scx_kick_flags, SCX_KICK_IDLE) - -/* - * scx_switch_all() was replaced by %SCX_OPS_SWITCH_PARTIAL. See - * %__COMPAT_SCX_OPS_SWITCH_PARTIAL in compat.h. This can be dropped in the - * future. - */ -void scx_bpf_switch_all(void) __ksym __weak; - -static inline void __COMPAT_scx_bpf_switch_all(void) -{ - if (!bpf_core_enum_value_exists(enum scx_ops_flags, SCX_OPS_SWITCH_PARTIAL)) - scx_bpf_switch_all(); -} - -/* - * scx_bpf_exit() is a new addition. Fall back to scx_bpf_error() if - * unavailable. Users can use scx_bpf_exit() directly in the future. - */ -#define __COMPAT_scx_bpf_exit(code, fmt, args...) \ -({ \ - if (bpf_ksym_exists(scx_bpf_exit_bstr)) \ - scx_bpf_exit((code), fmt, ##args); \ - else \ - scx_bpf_error(fmt, ##args); \ -}) - -/* - * scx_bpf_dump() is a new addition. Ignore if unavailable. Users can use - * scx_bpf_dump() directly in the future. - */ -#define __COMPAT_scx_bpf_dump(fmt, args...) \ -({ \ - if (bpf_ksym_exists(scx_bpf_dump_bstr)) \ - scx_bpf_dump(fmt, ##args); \ -}) - -/* - * scx_bpf_nr_cpu_ids(), scx_bpf_get_possible/online_cpumask() are new. No good - * way to noop these kfuncs. Provide a test macro. Users can assume existence in - * the future. - */ -#define __COMPAT_HAS_CPUMASKS \ - bpf_ksym_exists(scx_bpf_nr_cpu_ids) - -/* - * cpuperf is new. The followings become noop on older kernels. Callers can be - * updated to call cpuperf kfuncs directly in the future. - */ -static inline u32 __COMPAT_scx_bpf_cpuperf_cap(s32 cpu) -{ - if (bpf_ksym_exists(scx_bpf_cpuperf_cap)) - return scx_bpf_cpuperf_cap(cpu); - else - return 1024; -} - -static inline u32 __COMPAT_scx_bpf_cpuperf_cur(s32 cpu) -{ - if (bpf_ksym_exists(scx_bpf_cpuperf_cur)) - return scx_bpf_cpuperf_cur(cpu); - else - return 1024; -} - -static inline void __COMPAT_scx_bpf_cpuperf_set(s32 cpu, u32 perf) -{ - if (bpf_ksym_exists(scx_bpf_cpuperf_set)) - return scx_bpf_cpuperf_set(cpu, perf); -} - /* * Iteration and scx_bpf_consume_task() are new. The following become noop on * older kernels. The users can switch to bpf_for_each(scx_dsq) and directly diff --git a/tools/sched_ext/include/scx/compat.h b/tools/sched_ext/include/scx/compat.h index 47ec920f8776d..9a075e63a3308 100644 --- a/tools/sched_ext/include/scx/compat.h +++ b/tools/sched_ext/include/scx/compat.h @@ -106,23 +106,9 @@ static inline bool __COMPAT_struct_has_field(const char *type, const char *field return false; } -/* - * An ops flag, %SCX_OPS_SWITCH_PARTIAL, replaced scx_bpf_switch_all() which had - * to be called from ops.init(). To support both before and after, use both - * %__COMPAT_SCX_OPS_SWITCH_PARTIAL and %__COMPAT_scx_bpf_switch_all() defined - * in compat.bpf.h. Users can switch to directly using %SCX_OPS_SWITCH_PARTIAL - * in the future. - */ -#define __COMPAT_SCX_OPS_SWITCH_PARTIAL \ +#define SCX_OPS_SWITCH_PARTIAL \ __COMPAT_ENUM_OR_ZERO("scx_ops_flags", "SCX_OPS_SWITCH_PARTIAL") -/* - * scx_bpf_nr_cpu_ids(), scx_bpf_get_possible/online_cpumask() are new. Users - * will be able to assume existence in the future. - */ -#define __COMPAT_HAS_CPUMASKS \ - __COMPAT_has_ksym("scx_bpf_nr_cpu_ids") - /* * DSQ iterator is new. Users will be able to assume existence in the future. */ @@ -157,43 +143,23 @@ static inline long scx_hotplug_seq(void) * and attach it, backward compatibility is automatically maintained where * reasonable. * - * - ops.tick(): Ignored on older kernels with a warning. - * - ops.dump*(): Ignored on older kernels with a warning. - * - ops.exit_dump_len: Cleared to zero on older kernels with a warning. - * - ops.hotplug_seq: Ignored on older kernels. + * ec7e3b0463e1 ("implement-ops") in https://github.com/sched-ext/sched_ext is + * the current minimum required kernel version. */ #define SCX_OPS_OPEN(__ops_name, __scx_name) ({ \ struct __scx_name *__skel; \ \ + SCX_BUG_ON(!__COMPAT_struct_has_field("sched_ext_ops", "dump"), \ + "sched_ext_ops.dump() missing, kernel too old?"); \ + \ __skel = __scx_name##__open(); \ SCX_BUG_ON(!__skel, "Could not open " #__scx_name); \ - \ - if (__COMPAT_struct_has_field("sched_ext_ops", "hotplug_seq")) \ - __skel->struct_ops.__ops_name->hotplug_seq = scx_hotplug_seq(); \ + __skel->struct_ops.__ops_name->hotplug_seq = scx_hotplug_seq(); \ __skel; \ }) #define SCX_OPS_LOAD(__skel, __ops_name, __scx_name, __uei_name) ({ \ UEI_SET_SIZE(__skel, __ops_name, __uei_name); \ - if (!__COMPAT_struct_has_field("sched_ext_ops", "exit_dump_len") && \ - (__skel)->struct_ops.__ops_name->exit_dump_len) { \ - fprintf(stderr, "WARNING: kernel doesn't support setting exit dump len\n"); \ - (__skel)->struct_ops.__ops_name->exit_dump_len = 0; \ - } \ - if (!__COMPAT_struct_has_field("sched_ext_ops", "tick") && \ - (__skel)->struct_ops.__ops_name->tick) { \ - fprintf(stderr, "WARNING: kernel doesn't support ops.tick()\n"); \ - (__skel)->struct_ops.__ops_name->tick = NULL; \ - } \ - if (!__COMPAT_struct_has_field("sched_ext_ops", "dump") && \ - ((__skel)->struct_ops.__ops_name->dump || \ - (__skel)->struct_ops.__ops_name->dump_cpu || \ - (__skel)->struct_ops.__ops_name->dump_task)) { \ - fprintf(stderr, "WARNING: kernel doesn't support ops.dump*()\n"); \ - (__skel)->struct_ops.__ops_name->dump = NULL; \ - (__skel)->struct_ops.__ops_name->dump_cpu = NULL; \ - (__skel)->struct_ops.__ops_name->dump_task = NULL; \ - } \ SCX_BUG_ON(__scx_name##__load((__skel)), "Failed to load skel"); \ }) diff --git a/tools/sched_ext/scx_central.bpf.c b/tools/sched_ext/scx_central.bpf.c index b297ccbd70b4d..1d8fd570eaa71 100644 --- a/tools/sched_ext/scx_central.bpf.c +++ b/tools/sched_ext/scx_central.bpf.c @@ -175,7 +175,7 @@ static bool dispatch_to_cpu(s32 cpu) scx_bpf_dispatch(p, SCX_DSQ_LOCAL_ON | cpu, SCX_SLICE_INF, 0); if (cpu != central_cpu) - scx_bpf_kick_cpu(cpu, __COMPAT_SCX_KICK_IDLE); + scx_bpf_kick_cpu(cpu, SCX_KICK_IDLE); bpf_task_release(p); return true; @@ -305,7 +305,6 @@ int BPF_STRUCT_OPS_SLEEPABLE(central_init) struct bpf_timer *timer; int ret; - __COMPAT_scx_bpf_switch_all(); ret = scx_bpf_create_dsq(FALLBACK_DSQ_ID, -1); if (ret) return ret; diff --git a/tools/sched_ext/scx_qmap.bpf.c b/tools/sched_ext/scx_qmap.bpf.c index e22f190f52249..ce87c0239a03d 100644 --- a/tools/sched_ext/scx_qmap.bpf.c +++ b/tools/sched_ext/scx_qmap.bpf.c @@ -41,7 +41,6 @@ const volatile bool print_shared_dsq; const volatile char exp_prefix[17]; const volatile s32 disallow_tgid; const volatile bool suppress_dump; -const volatile bool switch_partial; u32 test_error_cnt; @@ -222,7 +221,7 @@ void BPF_STRUCT_OPS(qmap_enqueue, struct task_struct *p, u64 enq_flags) scx_bpf_dispatch(p, SHARED_DSQ, 0, enq_flags); cpu = scx_bpf_pick_idle_cpu(p->cpus_ptr, 0); if (cpu >= 0) - scx_bpf_kick_cpu(cpu, __COMPAT_SCX_KICK_IDLE); + scx_bpf_kick_cpu(cpu, SCX_KICK_IDLE); return; } @@ -476,13 +475,13 @@ void BPF_STRUCT_OPS(qmap_dump, struct scx_dump_ctx *dctx) if (!(fifo = bpf_map_lookup_elem(&queue_arr, &i))) return; - __COMPAT_scx_bpf_dump("QMAP FIFO[%d]:", i); + scx_bpf_dump("QMAP FIFO[%d]:", i); bpf_repeat(4096) { if (bpf_map_pop_elem(fifo, &pid)) break; - __COMPAT_scx_bpf_dump(" %d", pid); + scx_bpf_dump(" %d", pid); } - __COMPAT_scx_bpf_dump("\n"); + scx_bpf_dump("\n"); } } @@ -496,9 +495,9 @@ void BPF_STRUCT_OPS(qmap_dump_cpu, struct scx_dump_ctx *dctx, s32 cpu, bool idle if (!(cpuc = bpf_map_lookup_percpu_elem(&cpu_ctx_stor, &zero, cpu))) return; - __COMPAT_scx_bpf_dump("QMAP: dsp_idx=%llu dsp_cnt=%llu avg_weight=%u cpuperf_target=%u", - cpuc->dsp_idx, cpuc->dsp_cnt, cpuc->avg_weight, - cpuc->cpuperf_target); + scx_bpf_dump("QMAP: dsp_idx=%llu dsp_cnt=%llu avg_weight=%u cpuperf_target=%u", + cpuc->dsp_idx, cpuc->dsp_cnt, cpuc->avg_weight, + cpuc->cpuperf_target); } void BPF_STRUCT_OPS(qmap_dump_task, struct scx_dump_ctx *dctx, struct task_struct *p) @@ -510,8 +509,8 @@ void BPF_STRUCT_OPS(qmap_dump_task, struct scx_dump_ctx *dctx, struct task_struc if (!(taskc = bpf_task_storage_get(&task_ctx_stor, p, 0, 0))) return; - __COMPAT_scx_bpf_dump("QMAP: force_local=%d core_sched_seq=%llu", - taskc->force_local, taskc->core_sched_seq); + scx_bpf_dump("QMAP: force_local=%d core_sched_seq=%llu", + taskc->force_local, taskc->core_sched_seq); } /* @@ -525,9 +524,6 @@ static void print_cpus(void) char buf[128] = "", *p; int idx; - if (!__COMPAT_HAS_CPUMASKS) - return; - possible = scx_bpf_get_possible_cpumask(); online = scx_bpf_get_online_cpumask(); @@ -593,9 +589,6 @@ static void monitor_cpuperf(void) const struct cpumask *online; int i, nr_online_cpus = 0; - if (!__COMPAT_HAS_CPUMASKS) - return; - nr_cpu_ids = scx_bpf_nr_cpu_ids(); online = scx_bpf_get_online_cpumask(); @@ -683,9 +676,6 @@ s32 BPF_STRUCT_OPS_SLEEPABLE(qmap_init) struct bpf_timer *timer; s32 ret; - if (!switch_partial) - __COMPAT_scx_bpf_switch_all(); - print_cpus(); ret = scx_bpf_create_dsq(SHARED_DSQ, -1); diff --git a/tools/sched_ext/scx_qmap.c b/tools/sched_ext/scx_qmap.c index e10ceb170793d..bca36de53903d 100644 --- a/tools/sched_ext/scx_qmap.c +++ b/tools/sched_ext/scx_qmap.c @@ -104,8 +104,7 @@ int main(int argc, char **argv) skel->rodata->suppress_dump = true; break; case 'p': - skel->rodata->switch_partial = true; - skel->struct_ops.qmap_ops->flags |= __COMPAT_SCX_OPS_SWITCH_PARTIAL; + skel->struct_ops.qmap_ops->flags |= SCX_OPS_SWITCH_PARTIAL; break; case 'v': verbose = true; diff --git a/tools/sched_ext/scx_simple.bpf.c b/tools/sched_ext/scx_simple.bpf.c index 6fc66ab9877af..ed7e8d535fc5f 100644 --- a/tools/sched_ext/scx_simple.bpf.c +++ b/tools/sched_ext/scx_simple.bpf.c @@ -136,7 +136,6 @@ void BPF_STRUCT_OPS(simple_enable, struct task_struct *p) s32 BPF_STRUCT_OPS_SLEEPABLE(simple_init) { - __COMPAT_scx_bpf_switch_all(); return scx_bpf_create_dsq(SHARED_DSQ, -1); }