From e396f1e4676e5145da402afa92aa4a831d95107a Mon Sep 17 00:00:00 2001 From: Andrea Righi Date: Sat, 9 Dec 2023 10:10:52 +0100 Subject: [PATCH 1/7] scx_userland: get rid of strings.h include Use compiler's built-in stack initialization instead of memset(). In this way we can get rid of the string.h include and make cross-compilation easier in certain small environments (i.e., arm). Signed-off-by: Andrea Righi --- scheds/kernel-examples/scx_userland.bpf.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scheds/kernel-examples/scx_userland.bpf.c b/scheds/kernel-examples/scx_userland.bpf.c index f2791a6..a48a7dd 100644 --- a/scheds/kernel-examples/scx_userland.bpf.c +++ b/scheds/kernel-examples/scx_userland.bpf.c @@ -20,7 +20,6 @@ * Copyright (c) 2022 Tejun Heo * Copyright (c) 2022 David Vernet */ -#include #include #include "scx_userland.h" @@ -146,9 +145,8 @@ static void dispatch_user_scheduler(void) static void enqueue_task_in_user_space(struct task_struct *p, u64 enq_flags) { - struct scx_userland_enqueued_task task; + struct scx_userland_enqueued_task task = {}; - memset(&task, 0, sizeof(task)); task.pid = p->pid; task.sum_exec_runtime = p->se.sum_exec_runtime; task.weight = p->scx.weight; From 4c65e71c484e8c80c41f368f3cde5e404d2041b1 Mon Sep 17 00:00:00 2001 From: Andrea Righi Date: Sat, 9 Dec 2023 10:42:34 +0100 Subject: [PATCH 2/7] scx_central: use proper format string for u64 When printing scheduler statistics we use %lu to print u64 values, that works well on 64-bit architectures, but on 32-bit architectures we get errors like the following: 106 | printf("total :%10lu local:%10lu queued:%10lu lost:%10lu\n", | ~~~~^ | | | long unsigned int | %10llu 107 | skel->bss->nr_total, | ~~~~~~~~~~~~~~~~~~~ | | | u64 {aka long long unsigned int} Fix this by using the proper format %llu. Signed-off-by: Andrea Righi --- scheds/kernel-examples/scx_central.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scheds/kernel-examples/scx_central.c b/scheds/kernel-examples/scx_central.c index a3d2240..5015050 100644 --- a/scheds/kernel-examples/scx_central.c +++ b/scheds/kernel-examples/scx_central.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -103,17 +104,17 @@ int main(int argc, char **argv) while (!exit_req && !uei_exited(&skel->bss->uei)) { printf("[SEQ %llu]\n", seq++); - printf("total :%10lu local:%10lu queued:%10lu lost:%10lu\n", + printf("total :%10" PRIu64 " local:%10" PRIu64 " queued:%10" PRIu64 " lost:%10" PRIu64 "\n", skel->bss->nr_total, skel->bss->nr_locals, skel->bss->nr_queued, skel->bss->nr_lost_pids); - printf("timer :%10lu dispatch:%10lu mismatch:%10lu retry:%10lu\n", + printf("timer :%10" PRIu64 " dispatch:%10" PRIu64 " mismatch:%10" PRIu64 " retry:%10" PRIu64 "\n", skel->bss->nr_timers, skel->bss->nr_dispatches, skel->bss->nr_mismatches, skel->bss->nr_retries); - printf("overflow:%10lu\n", + printf("overflow:%10" PRIu64 "\n", skel->bss->nr_overflows); fflush(stdout); sleep(1); From 00c5d2dfb7da7c462187a314df58cc02f06e8bf1 Mon Sep 17 00:00:00 2001 From: Andrea Righi Date: Sat, 9 Dec 2023 11:45:22 +0100 Subject: [PATCH 3/7] scx_qmap: use proper data size for scheduler stats MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We should explicitly use u64 for scheduler statistics to prevent the following build failures on 32-bit architectures: scheds/kernel-examples/scx_qmap.p/scx_qmap.bpf.skel.h: In function ‘scx_qmap__assert’: scheds/kernel-examples/scx_qmap.p/scx_qmap.bpf.skel.h:2560:9: error: static assertion failed: "unexpected size of \'nr_enqueued\'" 2560 | _Static_assert(sizeof(s->bss->nr_enqueued) == 8, "unexpected size of 'nr_enqueued'"); | ^~~~~~~~~~~~~~ scheds/kernel-examples/scx_qmap.p/scx_qmap.bpf.skel.h:2561:9: error: static assertion failed: "unexpected size of \'nr_dispatched\'" 2561 | _Static_assert(sizeof(s->bss->nr_dispatched) == 8, "unexpected size of 'nr_dispatched'"); | ^~~~~~~~~~~~~~ scheds/kernel-examples/scx_qmap.p/scx_qmap.bpf.skel.h:2562:9: error: static assertion failed: "unexpected size of \'nr_reenqueued\'" 2562 | _Static_assert(sizeof(s->bss->nr_reenqueued) == 8, "unexpected size of 'nr_reenqueued'"); | ^~~~~~~~~~~~~~ scheds/kernel-examples/scx_qmap.p/scx_qmap.bpf.skel.h:2563:9: error: static assertion failed: "unexpected size of \'nr_dequeued\'" 2563 | _Static_assert(sizeof(s->bss->nr_dequeued) == 8, "unexpected size of 'nr_dequeued'"); | ^~~~~~~~~~~~~~ scheds/kernel-examples/scx_qmap.p/scx_qmap.bpf.skel.h:2564:9: error: static assertion failed: "unexpected size of \'nr_core_sched_execed\'" 2564 | _Static_assert(sizeof(s->bss->nr_core_sched_execed) == 8, "unexpected size of 'nr_core_sched_execed'"); | ^~~~~~~~~~~~~~ Signed-off-by: Andrea Righi --- scheds/kernel-examples/scx_qmap.bpf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scheds/kernel-examples/scx_qmap.bpf.c b/scheds/kernel-examples/scx_qmap.bpf.c index 831df3f..997a7d3 100644 --- a/scheds/kernel-examples/scx_qmap.bpf.c +++ b/scheds/kernel-examples/scx_qmap.bpf.c @@ -95,8 +95,8 @@ struct { } dispatch_idx_cnt SEC(".maps"); /* Statistics */ -unsigned long nr_enqueued, nr_dispatched, nr_reenqueued, nr_dequeued; -unsigned long nr_core_sched_execed; +u64 nr_enqueued, nr_dispatched, nr_reenqueued, nr_dequeued; +u64 nr_core_sched_execed; s32 BPF_STRUCT_OPS(qmap_select_cpu, struct task_struct *p, s32 prev_cpu, u64 wake_flags) From 14e70fd1349587064ecf3851620117e20c5b3546 Mon Sep 17 00:00:00 2001 From: Andrea Righi Date: Sat, 9 Dec 2023 12:02:27 +0100 Subject: [PATCH 4/7] scx_flatcg: use proper data size for hweight_gen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We should explicitly use u64 for hweight_gen to prevent the following build failures on 32-bit architectures: scheds/kernel-examples/scx_flatcg.p/scx_flatcg.bpf.skel.h: In function ‘scx_flatcg__assert’: scheds/kernel-examples/scx_flatcg.p/scx_flatcg.bpf.skel.h:3523:9: error: static assertion failed: "unexpected size of \'hweight_gen\'" 3523 | _Static_assert(sizeof(s->data->hweight_gen) == 8, "unexpected size of 'hweight_gen'"); Signed-off-by: Andrea Righi --- scheds/kernel-examples/scx_flatcg.bpf.c | 2 +- scheds/kernel-examples/scx_flatcg.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/scheds/kernel-examples/scx_flatcg.bpf.c b/scheds/kernel-examples/scx_flatcg.bpf.c index 84a60d7..9926cbd 100644 --- a/scheds/kernel-examples/scx_flatcg.bpf.c +++ b/scheds/kernel-examples/scx_flatcg.bpf.c @@ -123,7 +123,7 @@ struct { } task_ctx SEC(".maps"); /* gets inc'd on weight tree changes to expire the cached hweights */ -unsigned long hweight_gen = 1; +u64 hweight_gen = 1; static u64 div_round_up(u64 dividend, u64 divisor) { diff --git a/scheds/kernel-examples/scx_flatcg.c b/scheds/kernel-examples/scx_flatcg.c index 6a6e47c..99e719c 100644 --- a/scheds/kernel-examples/scx_flatcg.c +++ b/scheds/kernel-examples/scx_flatcg.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -183,7 +184,7 @@ int main(int argc, char **argv) memcpy(last_stats, acc_stats, sizeof(acc_stats)); - printf("\n[SEQ %6lu cpu=%5.1lf hweight_gen=%lu]\n", + printf("\n[SEQ %6lu cpu=%5.1lf hweight_gen=%" PRIu64 "]\n", seq++, cpu_util * 100.0, skel->data->hweight_gen); printf(" act:%6llu deact:%6llu local:%6llu global:%6llu\n", stats[FCG_STAT_ACT], From 4df979ccb701881cbfa6f40baaad7dc0a256bf55 Mon Sep 17 00:00:00 2001 From: Andrea Righi Date: Sat, 9 Dec 2023 12:19:23 +0100 Subject: [PATCH 5/7] scx_pair: use proper format string for u64 types This prevents some warnings when building scx_pair on 32-bit architectures. Signed-off-by: Andrea Righi --- scheds/kernel-examples/scx_pair.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scheds/kernel-examples/scx_pair.c b/scheds/kernel-examples/scx_pair.c index 693f095..1eb30ef 100644 --- a/scheds/kernel-examples/scx_pair.c +++ b/scheds/kernel-examples/scx_pair.c @@ -6,6 +6,7 @@ */ #include #include +#include #include #include #include @@ -142,18 +143,18 @@ int main(int argc, char **argv) while (!exit_req && !uei_exited(&skel->bss->uei)) { printf("[SEQ %llu]\n", seq++); - printf(" total:%10lu dispatch:%10lu missing:%10lu\n", + printf(" total:%10" PRIu64 " dispatch:%10" PRIu64 " missing:%10" PRIu64 "\n", skel->bss->nr_total, skel->bss->nr_dispatched, skel->bss->nr_missing); - printf(" kicks:%10lu preemptions:%7lu\n", + printf(" kicks:%10" PRIu64 " preemptions:%7" PRIu64 "\n", skel->bss->nr_kicks, skel->bss->nr_preemptions); - printf(" exp:%10lu exp_wait:%10lu exp_empty:%10lu\n", + printf(" exp:%10" PRIu64 " exp_wait:%10" PRIu64 " exp_empty:%10" PRIu64 "\n", skel->bss->nr_exps, skel->bss->nr_exp_waits, skel->bss->nr_exp_empty); - printf("cgnext:%10lu cgcoll:%10lu cgempty:%10lu\n", + printf("cgnext:%10" PRIu64 " cgcoll:%10" PRIu64 " cgempty:%10" PRIu64 "\n", skel->bss->nr_cgrp_next, skel->bss->nr_cgrp_coll, skel->bss->nr_cgrp_empty); From adc01140aab5a54e47b6ae30f3a52f2bec5805fc Mon Sep 17 00:00:00 2001 From: Andrea Righi Date: Sat, 9 Dec 2023 13:47:49 +0100 Subject: [PATCH 6/7] scx_qmap: use proper format string for u64 types This prevents some warnings when building scx_qmap on 32-bit architectures. Signed-off-by: Andrea Righi --- scheds/kernel-examples/scx_qmap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scheds/kernel-examples/scx_qmap.c b/scheds/kernel-examples/scx_qmap.c index d817115..7008b91 100644 --- a/scheds/kernel-examples/scx_qmap.c +++ b/scheds/kernel-examples/scx_qmap.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -90,7 +91,7 @@ int main(int argc, char **argv) long nr_enqueued = skel->bss->nr_enqueued; long nr_dispatched = skel->bss->nr_dispatched; - printf("enq=%lu, dsp=%lu, delta=%ld, reenq=%lu, deq=%lu, core=%lu\n", + printf("enq=%lu, dsp=%lu, delta=%ld, reenq=%" PRIu64 ", deq=%" PRIu64 ", core=%" PRIu64 "\n", nr_enqueued, nr_dispatched, nr_enqueued - nr_dispatched, skel->bss->nr_reenqueued, skel->bss->nr_dequeued, skel->bss->nr_core_sched_execed); From 0637b6a0b5279435a768b44d78b16eb0403af8d9 Mon Sep 17 00:00:00 2001 From: Andrea Righi Date: Sat, 9 Dec 2023 13:50:12 +0100 Subject: [PATCH 7/7] scx_nest: use proper format string for u64 types This prevents some warnings when building scx_nest on 32-bit architectures. Signed-off-by: Andrea Righi --- scheds/c-user/scx_nest.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scheds/c-user/scx_nest.c b/scheds/c-user/scx_nest.c index 3195b69..34b2623 100644 --- a/scheds/c-user/scx_nest.c +++ b/scheds/c-user/scx_nest.c @@ -6,6 +6,7 @@ */ #include #include +#include #include #include #include @@ -143,7 +144,7 @@ static void print_active_nests(const struct scx_nest *skel) total++; } } - printf("%-9s(%2lu): | %s |\n", mask_str, total, cpus); + printf("%-9s(%2" PRIu64 "): | %s |\n", mask_str, total, cpus); } } @@ -209,7 +210,7 @@ int main(int argc, char **argv) print_stat_grp(nest_stat->group); last_grp = nest_stat->group; } - printf("%s=%lu\n", nest_stat->label, stats[nest_stat->idx]); + printf("%s=%" PRIu64 "\n", nest_stat->label, stats[nest_stat->idx]); } printf("\n"); print_active_nests(skel);