From c545d23e79c6ac0c7ca5bbe12ae05a626a65d917 Mon Sep 17 00:00:00 2001 From: Emil Tsalapatis Date: Wed, 6 Nov 2024 07:03:34 -0800 Subject: [PATCH] factor enum handling into existing headers/operations --- scheds/c/scx_central.bpf.c | 1 - scheds/c/scx_central.c | 2 - scheds/c/scx_flatcg.bpf.c | 2 +- scheds/c/scx_flatcg.c | 1 + scheds/c/scx_nest.bpf.c | 2 +- scheds/c/scx_nest.c | 1 + scheds/c/scx_pair.bpf.c | 2 +- scheds/c/scx_pair.c | 1 + scheds/c/scx_qmap.bpf.c | 2 +- scheds/c/scx_qmap.c | 2 + scheds/include/scx/common.bpf.h | 1 + scheds/include/scx/common.h | 1 + scheds/include/scx/compat.h | 1 + scheds/include/scx/enums.autogen.bpf.h | 66 +++++++++++++------------- scripts/gen_enums.py | 2 +- 15 files changed, 46 insertions(+), 41 deletions(-) diff --git a/scheds/c/scx_central.bpf.c b/scheds/c/scx_central.bpf.c index f1c4857..6b9e3a0 100644 --- a/scheds/c/scx_central.bpf.c +++ b/scheds/c/scx_central.bpf.c @@ -46,7 +46,6 @@ * Copyright (c) 2022 David Vernet */ #include -#include char _license[] SEC("license") = "GPL"; diff --git a/scheds/c/scx_central.c b/scheds/c/scx_central.c index 5d90d0d..73e9423 100644 --- a/scheds/c/scx_central.c +++ b/scheds/c/scx_central.c @@ -13,7 +13,6 @@ #include #include #include -#include #include "scx_central.bpf.skel.h" const char help_fmt[] = @@ -56,7 +55,6 @@ int main(int argc, char **argv) signal(SIGTERM, sigint_handler); restart: skel = SCX_OPS_OPEN(central_ops, scx_central); - SCX_ENUM_INIT(skel); skel->rodata->central_cpu = 0; skel->rodata->nr_cpu_ids = libbpf_num_possible_cpus(); diff --git a/scheds/c/scx_flatcg.bpf.c b/scheds/c/scx_flatcg.bpf.c index e272bc3..00e25d6 100644 --- a/scheds/c/scx_flatcg.bpf.c +++ b/scheds/c/scx_flatcg.bpf.c @@ -54,7 +54,7 @@ char _license[] SEC("license") = "GPL"; const volatile u32 nr_cpus = 32; /* !0 for veristat, set during init */ -const volatile u64 cgrp_slice_ns = SCX_SLICE_DFL; +const volatile u64 cgrp_slice_ns; const volatile bool fifo_sched; u64 cvtime_now; diff --git a/scheds/c/scx_flatcg.c b/scheds/c/scx_flatcg.c index 5d24ca9..6dd423e 100644 --- a/scheds/c/scx_flatcg.c +++ b/scheds/c/scx_flatcg.c @@ -137,6 +137,7 @@ restart: skel = SCX_OPS_OPEN(flatcg_ops, scx_flatcg); skel->rodata->nr_cpus = libbpf_num_possible_cpus(); + skel->rodata->cgrp_slice_ns = __COMPAT_ENUM_OR_ZERO("scx_public_consts", "SCX_SLICE_DFL"); while ((opt = getopt(argc, argv, "s:i:dfvh")) != -1) { double v; diff --git a/scheds/c/scx_nest.bpf.c b/scheds/c/scx_nest.bpf.c index 9ce113a..0766413 100644 --- a/scheds/c/scx_nest.bpf.c +++ b/scheds/c/scx_nest.bpf.c @@ -47,7 +47,7 @@ enum { const volatile u64 p_remove_ns = 2 * NSEC_PER_MSEC; const volatile u64 r_max = 5; const volatile u64 r_impatient = 2; -const volatile u64 slice_ns = SCX_SLICE_DFL; +const volatile u64 slice_ns; const volatile bool find_fully_idle = false; const volatile u64 sampling_cadence_ns = 1 * NSEC_PER_SEC; const volatile u64 r_depth = 5; diff --git a/scheds/c/scx_nest.c b/scheds/c/scx_nest.c index 42598a9..e1d4115 100644 --- a/scheds/c/scx_nest.c +++ b/scheds/c/scx_nest.c @@ -171,6 +171,7 @@ restart: skel->rodata->nr_cpus = libbpf_num_possible_cpus(); skel->rodata->sampling_cadence_ns = SAMPLING_CADENCE_S * 1000 * 1000 * 1000; + skel->rodata->slice_ns = __COMPAT_ENUM_OR_ZERO("scx_public_consts", "SCX_SLICE_DFL"); while ((opt = getopt(argc, argv, "d:m:i:Is:vh")) != -1) { switch (opt) { diff --git a/scheds/c/scx_pair.bpf.c b/scheds/c/scx_pair.bpf.c index c5d25a3..e3012ff 100644 --- a/scheds/c/scx_pair.bpf.c +++ b/scheds/c/scx_pair.bpf.c @@ -124,7 +124,7 @@ char _license[] SEC("license") = "GPL"; const volatile u32 nr_cpu_ids = 1; /* a pair of CPUs stay on a cgroup for this duration */ -const volatile u32 pair_batch_dur_ns = SCX_SLICE_DFL; +const volatile u32 pair_batch_dur_ns; /* cpu ID -> pair cpu ID */ const volatile s32 RESIZABLE_ARRAY(rodata, pair_cpu); diff --git a/scheds/c/scx_pair.c b/scheds/c/scx_pair.c index c220975..32e5ceb 100644 --- a/scheds/c/scx_pair.c +++ b/scheds/c/scx_pair.c @@ -55,6 +55,7 @@ restart: skel = SCX_OPS_OPEN(pair_ops, scx_pair); skel->rodata->nr_cpu_ids = libbpf_num_possible_cpus(); + skel->rodata->pair_batch_dur_ns = __COMPAT_ENUM_OR_ZERO("scx_public_consts", "SCX_SLICE_DFL"); /* pair up the earlier half to the latter by default, override with -s */ stride = skel->rodata->nr_cpu_ids / 2; diff --git a/scheds/c/scx_qmap.bpf.c b/scheds/c/scx_qmap.bpf.c index 67e2a79..11cbf5b 100644 --- a/scheds/c/scx_qmap.bpf.c +++ b/scheds/c/scx_qmap.bpf.c @@ -33,7 +33,7 @@ enum consts { char _license[] SEC("license") = "GPL"; -const volatile u64 slice_ns = SCX_SLICE_DFL; +const volatile u64 slice_ns; const volatile u32 stall_user_nth; const volatile u32 stall_kernel_nth; const volatile u32 dsp_inf_loop_after; diff --git a/scheds/c/scx_qmap.c b/scheds/c/scx_qmap.c index ac45a02..c4912ab 100644 --- a/scheds/c/scx_qmap.c +++ b/scheds/c/scx_qmap.c @@ -64,6 +64,8 @@ int main(int argc, char **argv) skel = SCX_OPS_OPEN(qmap_ops, scx_qmap); + skel->rodata->slice_ns = __COMPAT_ENUM_OR_ZERO("scx_public_consts", "SCX_SLICE_DFL"); + while ((opt = getopt(argc, argv, "s:e:t:T:l:b:PHd:D:Spvh")) != -1) { switch (opt) { case 's': diff --git a/scheds/include/scx/common.bpf.h b/scheds/include/scx/common.bpf.h index 2d055bd..01ce26c 100644 --- a/scheds/include/scx/common.bpf.h +++ b/scheds/include/scx/common.bpf.h @@ -467,5 +467,6 @@ static inline u32 log2_u64(u64 v) { } #include "compat.bpf.h" +#include "enums.bpf.h" #endif /* __SCX_COMMON_BPF_H */ diff --git a/scheds/include/scx/common.h b/scheds/include/scx/common.h index 5b0f901..1f3a0bd 100644 --- a/scheds/include/scx/common.h +++ b/scheds/include/scx/common.h @@ -71,5 +71,6 @@ typedef int64_t s64; #include "user_exit_info.h" #include "compat.h" +#include "enums.h" #endif /* __SCHED_EXT_COMMON_H */ diff --git a/scheds/include/scx/compat.h b/scheds/include/scx/compat.h index cc56ff9..b50280e 100644 --- a/scheds/include/scx/compat.h +++ b/scheds/include/scx/compat.h @@ -149,6 +149,7 @@ static inline long scx_hotplug_seq(void) __skel = __scx_name##__open(); \ SCX_BUG_ON(!__skel, "Could not open " #__scx_name); \ __skel->struct_ops.__ops_name->hotplug_seq = scx_hotplug_seq(); \ + SCX_ENUM_INIT(__skel); \ __skel; \ }) diff --git a/scheds/include/scx/enums.autogen.bpf.h b/scheds/include/scx/enums.autogen.bpf.h index 8bf4301..86de87d 100644 --- a/scheds/include/scx/enums.autogen.bpf.h +++ b/scheds/include/scx/enums.autogen.bpf.h @@ -5,102 +5,102 @@ * and run it from the root directory to update this file. */ -const volatile u64 __SCX_OPS_NAME_LEN; +const volatile u64 __SCX_OPS_NAME_LEN __weak; #define SCX_OPS_NAME_LEN __SCX_OPS_NAME_LEN -const volatile u64 __SCX_SLICE_DFL; +const volatile u64 __SCX_SLICE_DFL __weak; #define SCX_SLICE_DFL __SCX_SLICE_DFL -const volatile u64 __SCX_SLICE_INF; +const volatile u64 __SCX_SLICE_INF __weak; #define SCX_SLICE_INF __SCX_SLICE_INF -const volatile u64 __SCX_DSQ_FLAG_BUILTIN; +const volatile u64 __SCX_DSQ_FLAG_BUILTIN __weak; #define SCX_DSQ_FLAG_BUILTIN __SCX_DSQ_FLAG_BUILTIN -const volatile u64 __SCX_DSQ_FLAG_LOCAL_ON; +const volatile u64 __SCX_DSQ_FLAG_LOCAL_ON __weak; #define SCX_DSQ_FLAG_LOCAL_ON __SCX_DSQ_FLAG_LOCAL_ON -const volatile u64 __SCX_DSQ_INVALID; +const volatile u64 __SCX_DSQ_INVALID __weak; #define SCX_DSQ_INVALID __SCX_DSQ_INVALID -const volatile u64 __SCX_DSQ_GLOBAL; +const volatile u64 __SCX_DSQ_GLOBAL __weak; #define SCX_DSQ_GLOBAL __SCX_DSQ_GLOBAL -const volatile u64 __SCX_DSQ_LOCAL; +const volatile u64 __SCX_DSQ_LOCAL __weak; #define SCX_DSQ_LOCAL __SCX_DSQ_LOCAL -const volatile u64 __SCX_DSQ_LOCAL_ON; +const volatile u64 __SCX_DSQ_LOCAL_ON __weak; #define SCX_DSQ_LOCAL_ON __SCX_DSQ_LOCAL_ON -const volatile u64 __SCX_DSQ_LOCAL_CPU_MASK; +const volatile u64 __SCX_DSQ_LOCAL_CPU_MASK __weak; #define SCX_DSQ_LOCAL_CPU_MASK __SCX_DSQ_LOCAL_CPU_MASK -const volatile u64 __SCX_TASK_QUEUED; +const volatile u64 __SCX_TASK_QUEUED __weak; #define SCX_TASK_QUEUED __SCX_TASK_QUEUED -const volatile u64 __SCX_TASK_RESET_RUNNABLE_AT; +const volatile u64 __SCX_TASK_RESET_RUNNABLE_AT __weak; #define SCX_TASK_RESET_RUNNABLE_AT __SCX_TASK_RESET_RUNNABLE_AT -const volatile u64 __SCX_TASK_DEQD_FOR_SLEEP; +const volatile u64 __SCX_TASK_DEQD_FOR_SLEEP __weak; #define SCX_TASK_DEQD_FOR_SLEEP __SCX_TASK_DEQD_FOR_SLEEP -const volatile u64 __SCX_TASK_STATE_SHIFT; +const volatile u64 __SCX_TASK_STATE_SHIFT __weak; #define SCX_TASK_STATE_SHIFT __SCX_TASK_STATE_SHIFT -const volatile u64 __SCX_TASK_STATE_BITS; +const volatile u64 __SCX_TASK_STATE_BITS __weak; #define SCX_TASK_STATE_BITS __SCX_TASK_STATE_BITS -const volatile u64 __SCX_TASK_STATE_MASK; +const volatile u64 __SCX_TASK_STATE_MASK __weak; #define SCX_TASK_STATE_MASK __SCX_TASK_STATE_MASK -const volatile u64 __SCX_TASK_CURSOR; +const volatile u64 __SCX_TASK_CURSOR __weak; #define SCX_TASK_CURSOR __SCX_TASK_CURSOR -const volatile u64 __SCX_TASK_NONE; +const volatile u64 __SCX_TASK_NONE __weak; #define SCX_TASK_NONE __SCX_TASK_NONE -const volatile u64 __SCX_TASK_INIT; +const volatile u64 __SCX_TASK_INIT __weak; #define SCX_TASK_INIT __SCX_TASK_INIT -const volatile u64 __SCX_TASK_READY; +const volatile u64 __SCX_TASK_READY __weak; #define SCX_TASK_READY __SCX_TASK_READY -const volatile u64 __SCX_TASK_ENABLED; +const volatile u64 __SCX_TASK_ENABLED __weak; #define SCX_TASK_ENABLED __SCX_TASK_ENABLED -const volatile u64 __SCX_TASK_NR_STATES; +const volatile u64 __SCX_TASK_NR_STATES __weak; #define SCX_TASK_NR_STATES __SCX_TASK_NR_STATES -const volatile u64 __SCX_TASK_DSQ_ON_PRIQ; +const volatile u64 __SCX_TASK_DSQ_ON_PRIQ __weak; #define SCX_TASK_DSQ_ON_PRIQ __SCX_TASK_DSQ_ON_PRIQ -const volatile u64 __SCX_KICK_IDLE; +const volatile u64 __SCX_KICK_IDLE __weak; #define SCX_KICK_IDLE __SCX_KICK_IDLE -const volatile u64 __SCX_KICK_PREEMPT; +const volatile u64 __SCX_KICK_PREEMPT __weak; #define SCX_KICK_PREEMPT __SCX_KICK_PREEMPT -const volatile u64 __SCX_KICK_WAIT; +const volatile u64 __SCX_KICK_WAIT __weak; #define SCX_KICK_WAIT __SCX_KICK_WAIT -const volatile u64 __SCX_ENQ_WAKEUP; +const volatile u64 __SCX_ENQ_WAKEUP __weak; #define SCX_ENQ_WAKEUP __SCX_ENQ_WAKEUP -const volatile u64 __SCX_ENQ_HEAD; +const volatile u64 __SCX_ENQ_HEAD __weak; #define SCX_ENQ_HEAD __SCX_ENQ_HEAD -const volatile u64 __SCX_ENQ_PREEMPT; +const volatile u64 __SCX_ENQ_PREEMPT __weak; #define SCX_ENQ_PREEMPT __SCX_ENQ_PREEMPT -const volatile u64 __SCX_ENQ_REENQ; +const volatile u64 __SCX_ENQ_REENQ __weak; #define SCX_ENQ_REENQ __SCX_ENQ_REENQ -const volatile u64 __SCX_ENQ_LAST; +const volatile u64 __SCX_ENQ_LAST __weak; #define SCX_ENQ_LAST __SCX_ENQ_LAST -const volatile u64 __SCX_ENQ_CLEAR_OPSS; +const volatile u64 __SCX_ENQ_CLEAR_OPSS __weak; #define SCX_ENQ_CLEAR_OPSS __SCX_ENQ_CLEAR_OPSS -const volatile u64 __SCX_ENQ_DSQ_PRIQ; +const volatile u64 __SCX_ENQ_DSQ_PRIQ __weak; #define SCX_ENQ_DSQ_PRIQ __SCX_ENQ_DSQ_PRIQ diff --git a/scripts/gen_enums.py b/scripts/gen_enums.py index 037f4e4..eb0f6c5 100755 --- a/scripts/gen_enums.py +++ b/scripts/gen_enums.py @@ -61,7 +61,7 @@ def gen_enums_bpf_h(): with open(autogen, "w") as f: f.write(warning) for _, symbol in enums: - f.write("const volatile u64 {};\n".format(localvar(symbol))) + f.write("const volatile u64 {} __weak;\n".format(localvar(symbol))) f.write("#define {} {}\n".format(symbol, localvar(symbol))) f.write("\n")