]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
sched_ext: Expose exit_cpu to BPF and userspace
authorChangwoo Min <changwoo@igalia.com>
Wed, 29 Apr 2026 08:23:18 +0000 (17:23 +0900)
committerTejun Heo <tj@kernel.org>
Wed, 29 Apr 2026 08:44:34 +0000 (22:44 -1000)
Extend struct user_exit_info with an exit_cpu field so BPF schedulers
and the userspace report path can see the CPU that triggered the exit,
matching the kernel-side dump.

UEI_RECORD() defaults the field to -1 before the CO-RE-gated copy so
that running against an older kernel without exit_cpu stays
distinguishable from "exit happened on CPU 0".

UEI_REPORT() appends "on CPU N" to the EXIT line when the value is
valid, surfacing the most diagnostically useful piece of exit info to
any sched_ext userspace tool without needing to crack open the debug
dump.

Signed-off-by: Changwoo Min <changwoo@igalia.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
tools/sched_ext/include/scx/user_exit_info.bpf.h
tools/sched_ext/include/scx/user_exit_info.h
tools/sched_ext/include/scx/user_exit_info_common.h

index e7ac6611a99014cb9d27c3d1de83bf88b778c867..98cab643c8d9adca2fd6105a35c75ee806b80eea 100644 (file)
@@ -32,6 +32,9 @@
                                  __uei_name##_dump_len, (__ei)->dump);         \
        if (bpf_core_field_exists((__ei)->exit_code))                           \
                __uei_name.exit_code = (__ei)->exit_code;                       \
+       __uei_name.exit_cpu = -1;                                               \
+       if (bpf_core_field_exists((__ei)->exit_cpu))                            \
+               __uei_name.exit_cpu = (__ei)->exit_cpu;                         \
        /* use __sync to force memory barrier */                                \
        __sync_val_compare_and_swap(&__uei_name.kind, __uei_name.kind,          \
                                    (__ei)->kind);                              \
index 399697fa372fb1ecac9b3296c175f3444bc9381a..56a02b549aef9f670ffcfb0fe7d52302e53a5bcd 100644 (file)
@@ -39,6 +39,8 @@
        fprintf(stderr, "EXIT: %s", __uei->reason);                             \
        if (__uei->msg[0] != '\0')                                              \
                fprintf(stderr, " (%s)", __uei->msg);                           \
+       if (__uei->exit_cpu >= 0)                                               \
+               fprintf(stderr, " on CPU %d", __uei->exit_cpu);                 \
        fputs("\n", stderr);                                                    \
        __uei->exit_code;                                                       \
 })
index 2d0981aedd89818c7d64187e37c91afe899a47ed..76e2a055eb4b0e76edd4863acc98dfe403f797e7 100644 (file)
@@ -22,6 +22,11 @@ enum uei_sizes {
 
 struct user_exit_info {
        int             kind;
+       /*
+        * CPU that triggered the exit, or -1 if unset (e.g. running on an
+        * older kernel that does not expose this field).
+        */
+       s32             exit_cpu;
        s64             exit_code;
        char            reason[UEI_REASON_LEN];
        char            msg[UEI_MSG_LEN];