tools/sched_ext: Receive updates from SCX repo
Tejun Heo
reviewerPATCH 1/1 tools/sched_ext: Receive updates from SCX repo
From 8da7bf2cee2735dbd2478cf07672ff0d243ce6ed Mon Sep 17 00:00:00 2001
From: Tejun Heo <[email protected]>
Date: Thu, 12 Dec 2024 16:16:57 -1000
Receive tools/sched_ext updates form https://github.com/sched-ext/scx to sync userspace bits:
- scx_bpf_dump_header() added which can be used to print out basic scheduler info on dump.
- BPF possible/online CPU iterators added.
- CO-RE enums added. The enums are autogenerated from vmlinux.h. Include the generated artifacts in tools/sched_ext to keep the Makefile simpler.
- Other misc changes.
Signed-off-by Tejun Heo <[email protected]>
---
Applying to sched_ext/for-6.14. Thanks.
tools/sched_ext/include/scx/common.bpf.h | 83 +++++++++++++- tools/sched_ext/include/scx/common.h | 6 + tools/sched_ext/include/scx/compat.h | 1 + .../sched_ext/include/scx/enums.autogen.bpf.h | 105 ++++++++++++++++++ tools/sched_ext/include/scx/enums.autogen.h | 41 +++++++ tools/sched_ext/include/scx/enums.bpf.h | 12 ++ tools/sched_ext/include/scx/enums.h | 27 +++++ tools/sched_ext/include/scx/user_exit_info.h | 9 +- tools/sched_ext/scx_central.bpf.c | 2 +- tools/sched_ext/scx_central.c | 1 + tools/sched_ext/scx_flatcg.bpf.c | 2 +- tools/sched_ext/scx_flatcg.c | 1 + tools/sched_ext/scx_qmap.bpf.c | 2 +- tools/sched_ext/scx_qmap.c | 2 + 14 files changed, 286 insertions(+), 8 deletions(-) create mode 100644 tools/sched_ext/include/scx/enums.autogen.bpf.h create mode 100644 tools/sched_ext/include/scx/enums.autogen.h create mode 100644 tools/sched_ext/include/scx/enums.bpf.h create mode 100644 tools/sched_ext/include/scx/enums.h
tools/sched_ext/include/scx/common.bpf.h +81 -2
@@ -9,7 +9,7 @@#ifdef LSP #define __bpf__ -#include "../vmlinux/vmlinux.h" +#include "../vmlinux.h" #else #include "vmlinux.h" #endif
@@ -24,6 +24,10 @@#define PF_EXITING 0x00000004#define CLOCK_MONOTONIC 1 +extern int LINUX_KERNEL_VERSION __kconfig; +extern const char CONFIG_CC_VERSION_TEXT[64] __kconfig __weak; +extern const char CONFIG_LOCALVERSION[64] __kconfig __weak; +/* * Earlier versions of clang/pahole lost upper 32bits in 64bit enums which can * lead to really confusing misbehaviors. Let's trigger a build failure.
@@ -98,7 +102,7 @@ void ___scx_bpf_bstr_format_checker(const char *fmt, ...) {} _Pragma("GCC diagnostic push") \ _Pragma("GCC diagnostic ignored \"-Wint-conversion\"") \___bpf_fill (___param, args); \ -_Pragma ("GCC diagnostic pop" ) \ +_Pragma ("GCC diagnostic pop" )/* * scx_bpf_exit() wraps the scx_bpf_exit_bstr() kfunc with variadic arguments
@@ -136,6 +140,20 @@ void ___scx_bpf_bstr_format_checker(const char *fmt, ...) {} ___scx_bpf_bstr_format_checker(fmt, ##args); \ }) +/* +* scx_bpf_dump_header() is a wrapper around scx_bpf_dump that adds a header +* of system information for debugging. +*/ +#define scx_bpf_dump_header () \ +({ \ + scx_bpf_dump("kernel: %d.%d.%d %s\ncc: %s\n", \ + LINUX_KERNEL_VERSION >> 16, \ + LINUX_KERNEL_VERSION >> 8 & 0xFF, \ + LINUX_KERNEL_VERSION & 0xFF, \ + CONFIG_LOCALVERSION, \ + CONFIG_CC_VERSION_TEXT); \ +}) + #define BPF_STRUCT_OPS(name, args...) \ SEC("struct_ops/"#name) \ BPF_PROG(name, ##args)
@@ -317,6 +335,66 @@ u32 bpf_cpumask_any_and_distribute(const struct cpumask *src1, const struct cpumask *src2) __ksym; u32 bpf_cpumask_weight(const struct cpumask *cpumask) __ksym; +int bpf_iter_bits_new(struct bpf_iter_bits *it, const u64 *unsafe_ptr__ign, u32 nr_words) __ksym; +int *bpf_iter_bits_next (struct bpf_iter_bits *it) __ksym; +void bpf_iter_bits_destroy(struct bpf_iter_bits *it) __ksym; + +#define def_iter_struct (name) \ +struct bpf_iter_##name { \ + struct bpf_iter_bits it; \ + const struct cpumask *bitmap; \ +}; + +#define def_iter_new (name) \ +static inline int bpf_iter_##name##_new( \ + struct bpf_iter_##name *it, const u64 *unsafe_ptr__ign, u32 nr_words) \ +{ \ + it->bitmap = scx_bpf_get_##name##_cpumask(); \ + return bpf_iter_bits_new(&it->it, (const u64 *)it->bitmap, \ + sizeof(struct cpumask) / 8); \ +} + +#define def_iter_next (name) \ +static inline int *bpf_iter_##name##_next(struct bpf_iter_##name *it) { \ + return bpf_iter_bits_next(&it->it); \ +} + +#define def_iter_destroy (name) \ +static inline void bpf_iter_##name##_destroy(struct bpf_iter_##name *it) { \ + scx_bpf_put_cpumask(it->bitmap); \ + bpf_iter_bits_destroy(&it->it); \ +} +#define def_for_each_cpu (cpu, name) for_each_##name##_cpu(cpu) + +/// Provides iterator for possible and online cpus. +/// +/// # Example +/// +/// ``` +/// static inline void example_use() { +/// int *cpu; +/// +/// for_each_possible_cpu(cpu){ +/// bpf_printk("CPU %d is possible", *cpu); +/// } +/// +/// for_each_online_cpu(cpu){ +/// bpf_printk("CPU %d is online", *cpu); +/// } +/// } +/// ``` +def_iter_struct (possible); +def_iter_new (possible); +def_iter_next (possible); +def_iter_destroy (possible); +#define for_each_possible_cpu (cpu) bpf_for_each(possible, cpu, NULL, 0) + +def_iter_struct (online); +def_iter_new (online); +def_iter_next (online); +def_iter_destroy (online); +#define for_each_online_cpu (cpu) bpf_for_each(online, cpu, NULL, 0) +/* * Access a cpumask in read-only mode (typically to check bits). */
@@ -423,5 +501,6 @@ static inline u32 log2_u64(u64 v) }#include "compat.bpf.h" +#include "enums.bpf.h" #endif /* __SCX_COMMON_BPF_H */
tools/sched_ext/include/scx/common.h +6 -0
@@ -71,5 +71,11 @@ typedef int64_t s64;#include "user_exit_info.h" #include "compat.h" +#include "enums.h" + +/* not available when building kernel tools/sched_ext */ +#if __has_include(<lib/sdt_task.h>) +#include <lib/sdt_task.h> +#endif #endif /* __SCHED_EXT_COMMON_H */
tools/sched_ext/include/scx/compat.h +1 -0
@@ -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; \ })
tools/sched_ext/include/scx/enums.autogen.bpf.h new file +105 -0
105 lines not on this page · raw message
tools/sched_ext/include/scx/enums.autogen.h new file +41 -0
41 lines not on this page · raw message
tools/sched_ext/include/scx/enums.bpf.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Convenience macros for getting/setting struct scx_enums instances. +* +* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. +*/ +#ifndef __SCX_ENUMS_BPF_H +#define __SCX_ENUMS_BPF_H + +#include "enums.autogen.bpf.h" + +#endif /* __SCX_ENUMS_BPF_H */
tools/sched_ext/include/scx/enums.h new file +27 -0
@@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Define struct scx_enums that stores the load-time values of enums +* used by the BPF program. +* +* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. +*/ + +#ifndef __SCX_ENUMS_H +#define __SCX_ENUMS_H + +static inline void __ENUM_set (u64 *val,char *type,char *name) +{ +bool res; + + res =__COMPAT_read_enum (type, name, val); +SCX_BUG_ON (!res,"enum not found(%s)" , name); +} + +#define SCX_ENUM_SET (skel, type, name) do { \ + __ENUM_set(&skel->rodata->__##name, #type, #name); \ + } while (0) + + +#include "enums.autogen.h" + +#endif /* __SCX_ENUMS_H */
tools/sched_ext/include/scx/user_exit_info.h +6 -3
@@ -10,6 +10,11 @@#ifndef __USER_EXIT_INFO_H#define __USER_EXIT_INFO_H +#ifdef LSP +#define __bpf__ +#include "../vmlinux.h" +#endif +enum uei_sizes {UEI_REASON_LEN =128 , UEI_MSG_LEN = 1024,
@@ -25,9 +30,7 @@ struct user_exit_info {#ifdef __bpf__ -#ifdef LSP -#include "../vmlinux/vmlinux.h" -#else +#ifndef LSP #include "vmlinux.h" #endif #include <bpf/bpf_core_read.h>
tools/sched_ext/scx_central.bpf.c +1 -1
@@ -57,7 +57,7 @@ enum {const volatile s32 central_cpu;const volatile u32 nr_cpu_ids =1 ;/* !0 for veristat, set during init */ -const volatile u64 slice_ns =SCX_SLICE_DFL ; +const volatile u64 slice_ns;bool timer_pinned = true;u64 nr_total, nr_locals, nr_queued, nr_lost_pids;
tools/sched_ext/scx_central.c +1 -0
@@ -58,6 +58,7 @@ int main(int argc, char **argv) skel->rodata->central_cpu =0 ; skel->rodata->nr_cpu_ids =libbpf_num_possible_cpus (); + skel->rodata->slice_ns =__COMPAT_ENUM_OR_ZERO ("scx_public_consts" ,"SCX_SLICE_DFL" );while ((opt =getopt (argc, argv,"s:c:pvh" )) !=-1 ) {switch (opt) {
tools/sched_ext/scx_flatcg.bpf.c +1 -1
@@ -57,7 +57,7 @@ enum { 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;
tools/sched_ext/scx_flatcg.c +1 -0
@@ -137,6 +137,7 @@ int main(int argc, char **argv) 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;
tools/sched_ext/scx_qmap.bpf.c +1 -1
@@ -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;
tools/sched_ext/scx_qmap.c +2 -0
@@ -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' :
Signature · 1 line
2.47.1