sched_ext: Documentation: Document events sysfs file and module parameters
Subsystems (3)
PATCH v2 1/2 sched_ext: Documentation: Document events sysfs file and module parameters
Two categories of sched_ext diagnostics are currently undocumented:
1. Per-scheduler events sysfs file
Each active BPF scheduler exposes a set of diagnostic counters at /sys/kernel/sched_ext/<name>/events. These counters are defined (with detailed comments) in kernel/sched/ext_internal.h but have no corresponding documentation in sched-ext.rst. BPF scheduler developers must read kernel source to understand what each counter means.
Add a description of the events file, an example of its output, and a brief explanation of every counter.
2. Module parameters
kernel/sched/ext.c registers two parameters under the sched_ext. prefix (slice_bypass_us, bypass_lb_intv_us) via module_param_cb() with MODULE_PARM_DESC() strings, but sched-ext.rst makes no mention of them. Users who need to tune bypass-mode behavior have no in-tree documentation to consult.
Add a "Module Parameters" section documenting both knobs: their default values, valid ranges (taken from the set_*() validators in ext.c), and the note from the source that they are primarily for debugging.
No functional changes.
--- Documentation/scheduler/sched-ext.rst | 68 +++++++++++++++++++++++++++ 1 file changed, 68 insertions(+)
Documentation/scheduler/sched-ext.rst +68 -0
@@ -93,6 +93,55 @@ scheduler has been loaded): # cat /sys/kernel/sched_ext/enable_seq 1 +Each running scheduler also exposes a per-scheduler ``events`` file under +``/sys/kernel/sched_ext/<scheduler-name>/events`` that tracks diagnostic +counters. Each counter occupies one ``name value`` line: + +.. code-block:: none + + # cat /sys/kernel/sched_ext/simple/events + SCX_EV_SELECT_CPU_FALLBACK 0 + SCX_EV_DISPATCH_LOCAL_DSQ_OFFLINE 0 + SCX_EV_DISPATCH_KEEP_LAST 123 + SCX_EV_ENQ_SKIP_EXITING 0 + SCX_EV_ENQ_SKIP_MIGRATION_DISABLED 0 + SCX_EV_REENQ_IMMED 0 + SCX_EV_REENQ_LOCAL_REPEAT 0 + SCX_EV_REFILL_SLICE_DFL 456789 + SCX_EV_BYPASS_DURATION 0 + SCX_EV_BYPASS_DISPATCH 0 + SCX_EV_BYPASS_ACTIVATE 0 + SCX_EV_INSERT_NOT_OWNED 0 + SCX_EV_SUB_BYPASS_DISPATCH 0 + +The counters are described in ``kernel/sched/ext_internal.h``; briefly: + +* ``SCX_EV_SELECT_CPU_FALLBACK``: ops.select_cpu() returned a CPU unusable by + the task and the core scheduler silently picked a fallback CPU. +* ``SCX_EV_DISPATCH_LOCAL_DSQ_OFFLINE``: a local-DSQ dispatch was redirected + to the global DSQ because the target CPU went offline. +* ``SCX_EV_DISPATCH_KEEP_LAST``: a task continued running because no other + task was available (only when ``SCX_OPS_ENQ_LAST`` is not set). +* ``SCX_EV_ENQ_SKIP_EXITING``: an exiting task was dispatched to the local DSQ + directly, bypassing ops.enqueue() (only when ``SCX_OPS_ENQ_EXITING`` is not set). +* ``SCX_EV_ENQ_SKIP_MIGRATION_DISABLED``: a migration-disabled task was + dispatched to its local DSQ directly (only when + ``SCX_OPS_ENQ_MIGRATION_DISABLED`` is not set). +* ``SCX_EV_REENQ_IMMED``: a task dispatched with ``SCX_ENQ_IMMED`` was + re-enqueued because the target CPU was not available for immediate execution. +* ``SCX_EV_REENQ_LOCAL_REPEAT``: a reenqueue of the local DSQ triggered + another reenqueue; recurring counts indicate incorrect ``SCX_ENQ_REENQ`` + handling in the BPF scheduler. +* ``SCX_EV_REFILL_SLICE_DFL``: a task's time slice was refilled with the + default value (``SCX_SLICE_DFL``). +* ``SCX_EV_BYPASS_DURATION``: total nanoseconds spent in bypass mode. +* ``SCX_EV_BYPASS_DISPATCH``: number of tasks dispatched while in bypass mode. +* ``SCX_EV_BYPASS_ACTIVATE``: number of times bypass mode was activated. +* ``SCX_EV_INSERT_NOT_OWNED``: attempted to insert a task into a DSQ not owned + by this scheduler; such attempts are silently ignored. +* ``SCX_EV_SUB_BYPASS_DISPATCH``: tasks dispatched from sub-scheduler bypass + DSQs (only relevant with ``CONFIG_EXT_SUB_SCHED``). + ``tools/sched_ext/scx_show_state.py`` is a drgn script which shows more detailed information:
@@ -441,6 +490,25 @@ Where to Look scheduling. Tasks with CPU affinity are direct-dispatched in FIFO order; all others are scheduled in user space by a simple vruntime scheduler. +Module Parameters +================= + +sched_ext exposes two module parameters under the ``sched_ext.`` prefix that +control bypass-mode behaviour. These knobs are primarily for debugging; there +is usually no reason to change them during normal operation. They can be read +and written at runtime (mode 0600) via +``/sys/module/sched_ext/parameters/``. + +``sched_ext.slice_bypass_us`` (default: 5000 µs) + The time slice assigned to all tasks when the scheduler is in bypass mode, + i.e. during BPF scheduler load, unload, and error recovery. Valid range is + 100 µs to 100 ms. + +``sched_ext.bypass_lb_intv_us`` (default: 500000 µs) + The interval at which the bypass-mode load balancer redistributes tasks + across CPUs. Set to 0 to disable load balancing during bypass mode. Valid + range is 0 to 10 s. + ABI Instability ===============
Signature · 1 line
2.43.0
PATCH v2 2/2 selftests/sched_ext: Return non-zero exit code on test failure
runner.c always returned 0 regardless of test results. The kselftest framework (tools/testing/selftests/kselftest/runner.sh) invokes the runner binary and treats a non-zero exit code as a test failure; with the old code, failed sched_ext tests were silently hidden from the parent harness even though individual "not ok" TAP lines were emitted.
Return 1 when at least one test failed, 0 when all tests passed or were skipped.
--- tools/testing/selftests/sched_ext/runner.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/sched_ext/runner.c +1 -1
@@ -217,7 +217,7 @@ int main(int argc, char **argv)printf (" - %s\n" , failed_tests[i]); } -return 0 ; +return failed >0 ?1 :0 ; }void scx_test_register (struct scx_test *test)
Signature · 1 line
2.43.0
Re: [PATCH 2/2] selftests/sched_ext: Return non-zero exit code on test failure
Quoted 10 lines · zhidao su
runner.calways returned 0 regardless of test results. The kselftest framework (tools/testing/selftests/kselftest/runner.sh) invokes the runner binary and treats a non-zero exit code as a test failure; with the old code, failedsched_exttests were silently hidden from the parent harness even though individual "not ok" TAP lines were emitted.Return 1 when at least one test failed, 0 when all tests passed or were skipped.
Signed-off-by zhidao su <[email protected]>
Makes sense.
Thanks,
-Andrea
Quoted 20 lines
--- tools/testing/selftests/sched_ext/runner.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/testing/selftests/sched_ext/runner.c +1
-1@@ -217,7 +217,7 @@ int main(int argc, char **argv)printf (" - %s\n" , failed_tests[i]); } -return 0 ; +return failed >0 ?1 :0 ; }void scx_test_register (struct scx_test *test)Signature · 1 line
2.43.0
Andrea Righi
reviewerHi,
Quoted 20 lines · zhidao su
Two categories of
sched_extdiagnostics are currently undocumented:1. Per-scheduler events sysfs file
Each active BPF scheduler exposes a set of diagnostic counters at /sys/kernel/sched_ext/<name>/events. These counters are defined (with detailed comments) inkernel/sched/ext_internal.hbut have no corresponding documentation insched-ext.rst. BPF scheduler developers must read kernel source to understand what each counter means.Add a description of the events file, an example of its output, and a brief explanation of every counter.
2. Module parameters
kernel/sched/ext.cregisters two parameters under thesched_ext. prefix (slice_bypass_us,bypass_lb_intv_us) viamodule_param_cb()withMODULE_PARM_DESC()strings, butsched-ext.rstmakes no mention of them. Users who need to tune bypass-mode behavior have no in-tree documentation to consult.
Quoted 8 lines
Add a "Module Parameters" section documenting both knobs: their default values, valid ranges (taken from the set_*() validators in
ext.c), and the note from the source that they are primarily for debugging.No functional changes.
Signed-off-by zhidao su <[email protected]>
Thanks for documenting this. Comments below.
Quoted 9 lines
--- Documentation/scheduler/sched-ext.rst | 68 +++++++++++++++++++++++++++ 1 file changed, 68 insertions(+)Documentation/scheduler/sched-ext.rst +0
-0
Documentation/scheduler/sched-ext.rst scheduler has been loaded): · line 97
Quoted 5 lines
Documentation/scheduler/sched-ext.rst +2
-0@@ -93,6 +93,55 @@ scheduler has been loaded): # cat /sys/kernel/sched_ext/enable_seq 1 +Each running scheduler also exposes a per-scheduler ``events`` file under +``/sys/kernel/sched_ext/<scheduler-name>/events`` that tracks diagnostic
The right path is /sys/kernel/sched_ext/root/events. And now that we have sub-schedulers it's probably worth mentioning that sub-scheduler events file is located at /sys/kernel/sched_ext/root/sub/sub-<cgroup_id>/events.
Quoted 51 lines
Documentation/scheduler/sched-ext.rst +47
-0+counters. Each counter occupies one ``name value`` line: + +.. code-block:: none + + # cat /sys/kernel/sched_ext/simple/events + SCX_EV_SELECT_CPU_FALLBACK 0 + SCX_EV_DISPATCH_LOCAL_DSQ_OFFLINE 0 + SCX_EV_DISPATCH_KEEP_LAST 123 + SCX_EV_ENQ_SKIP_EXITING 0 + SCX_EV_ENQ_SKIP_MIGRATION_DISABLED 0 + SCX_EV_REENQ_IMMED 0 + SCX_EV_REENQ_LOCAL_REPEAT 0 + SCX_EV_REFILL_SLICE_DFL 456789 + SCX_EV_BYPASS_DURATION 0 + SCX_EV_BYPASS_DISPATCH 0 + SCX_EV_BYPASS_ACTIVATE 0 + SCX_EV_INSERT_NOT_OWNED 0 + SCX_EV_SUB_BYPASS_DISPATCH 0 + +The counters are described in ``kernel/sched/ext_internal.h``; briefly: + +* ``SCX_EV_SELECT_CPU_FALLBACK``: ops.select_cpu() returned a CPU unusable by + the task and the core scheduler silently picked a fallback CPU. +* ``SCX_EV_DISPATCH_LOCAL_DSQ_OFFLINE``: a local-DSQ dispatch was redirected + to the global DSQ because the target CPU went offline. +* ``SCX_EV_DISPATCH_KEEP_LAST``: a task continued running because no other + task was available (only when ``SCX_OPS_ENQ_LAST`` is not set). +* ``SCX_EV_ENQ_SKIP_EXITING``: an exiting task was dispatched to the local DSQ + directly, bypassing ops.enqueue() (only when ``SCX_OPS_ENQ_EXITING`` is not set). +* ``SCX_EV_ENQ_SKIP_MIGRATION_DISABLED``: a migration-disabled task was + dispatched to its local DSQ directly (only when + ``SCX_OPS_ENQ_MIGRATION_DISABLED`` is not set). +* ``SCX_EV_REENQ_IMMED``: a task dispatched with ``SCX_ENQ_IMMED`` was + re-enqueued because the target CPU was not available for immediate execution. +* ``SCX_EV_REENQ_LOCAL_REPEAT``: a reenqueue of the local DSQ triggered + another reenqueue; recurring counts indicate incorrect ``SCX_ENQ_REENQ`` + handling in the BPF scheduler. +* ``SCX_EV_REFILL_SLICE_DFL``: a task's time slice was refilled with the + default value (``SCX_SLICE_DFL``). +* ``SCX_EV_BYPASS_DURATION``: total nanoseconds spent in bypass mode. +* ``SCX_EV_BYPASS_DISPATCH``: number of tasks dispatched while in bypass mode. +* ``SCX_EV_BYPASS_ACTIVATE``: number of times bypass mode was activated. +* ``SCX_EV_INSERT_NOT_OWNED``: attempted to insert a task into a DSQ not owned + by this scheduler; such attempts are silently ignored. +* ``SCX_EV_SUB_BYPASS_DISPATCH``: tasks dispatched from sub-scheduler bypass + DSQs (only relevant with ``CONFIG_EXT_SUB_SCHED``). + ``tools/sched_ext/scx_show_state.py`` is a drgn script which shows more detailed information:
Documentation/scheduler/sched-ext.rst Where to Look · line 496
Quoted 7 lines
Documentation/scheduler/sched-ext.rst +4
-0@@ -441,6 +490,25 @@ Where to Look scheduling. Tasks with CPU affinity are direct-dispatched in FIFO order; all others are scheduled in user space by a simple vruntime scheduler. +Module Parameters +================= + +sched_ext exposes two module parameters under the ``sched_ext.`` prefix that
Maybe ``sched_ext.`` namespace?
Quoted 21 lines
Documentation/scheduler/sched-ext.rst +15
-0+control bypass-mode behaviour. These knobs are primarily for debugging; there +is usually no reason to change them during normal operation. They can be read +and written at runtime (mode 0600) via +``/sys/module/sched_ext/parameters/``. + +``sched_ext.slice_bypass_us`` (default: 5000 µs) + The time slice assigned to all tasks when the scheduler is in bypass mode, + i.e. during BPF scheduler load, unload, and error recovery. Valid range is + 100 µs to 100 ms. + +``sched_ext.bypass_lb_intv_us`` (default: 500000 µs) + The interval at which the bypass-mode load balancer redistributes tasks + across CPUs. Set to 0 to disable load balancing during bypass mode. Valid + range is 0 to 10 s. + ABI Instability ===============Signature · 1 line
2.43.0
Thanks,
-Andrea
Quoted 3 lines · Andrea Righi
The right path is
/sys/kernel/sched_ext/root/events. And now that we have sub-schedulers it's probably worth mentioning that sub-scheduler events file is located at /sys/kernel/sched_ext/root/sub/sub-<cgroup_id>/events.
Fixed in v2: the path is now /sys/kernel/sched_ext/root/events, and the sub-scheduler path /sys/kernel/sched_ext/root/sub/sub-<cgroup_id>/events is mentioned as well.
Quoted 1 line
Maybe ``sched_ext.`` namespace?
Fixed in v2.
Thanks for the review,
zhidao
v2 cover sched_ext: documentation and selftest fixes
In reply to zhidao suFrom: Su Zhidao <[email protected]>
Document undocumented sched_ext diagnostics (events sysfs file and module parameters), and fix the selftest runner exit code.
Changes since v1:
- Patch 1: fix events path to /sys/kernel/sched_ext/root/events, add sub-scheduler path /sys/kernel/sched_ext/root/sub/sub-<cgroup_id>/events (reported by Andrea Righi)
- Patch 1: change "prefix" to "namespace" for the module parameter section (reported by Andrea Righi)
- Patch 2: no changes
Su Zhidao (2):
sched_ext: Documentation: Document events sysfs file and module
parameters
selftests/sched_ext: Return non-zero exit code on test failure
Documentation/scheduler/sched-ext.rst | 70 ++++++++++++++++++++++ tools/testing/selftests/sched_ext/Makefile | 3 + tools/testing/selftests/sched_ext/runner.c | 2 +- 3 files changed, 74 insertions(+), 1 deletion(-)
Signature · 1 line
2.43.0
PATCH v2 1/2 sched_ext: Documentation: Document events sysfs file and module parameters
From: Su Zhidao <[email protected]>
Two categories of sched_ext diagnostics are currently undocumented:
1. Per-scheduler events sysfs file
Each active BPF scheduler exposes a set of diagnostic counters at /sys/kernel/sched_ext/root/events. Sub-schedulers expose their counters at /sys/kernel/sched_ext/root/sub/sub-<cgroup_id>/events. These counters are defined (with detailed comments) in kernel/sched/ext_internal.h but have no corresponding documentation in sched-ext.rst. BPF scheduler developers must read kernel source to understand what each counter means.
Add a description of the events file, an example of its output, and a brief explanation of every counter.
2. Module parameters
kernel/sched/ext.c registers two parameters under the sched_ext. namespace (slice_bypass_us, bypass_lb_intv_us) via module_param_cb() with MODULE_PARM_DESC() strings, but sched-ext.rst makes no mention of them. Users who need to tune bypass-mode behavior have no in-tree documentation to consult.
Add a "Module Parameters" section documenting both knobs: their default values, valid ranges (taken from the set_*() validators in ext.c), and the note from the source that they are primarily for debugging.
No functional changes.
--- Documentation/scheduler/sched-ext.rst | 70 ++++++++++++++++++++++ tools/testing/selftests/sched_ext/Makefile | 3 + 2 files changed, 73 insertions(+)
Documentation/scheduler/sched-ext.rst +70 -0
@@ -93,6 +93,57 @@ scheduler has been loaded): # cat /sys/kernel/sched_ext/enable_seq 1 +Each running scheduler also exposes a per-scheduler ``events`` file under +``/sys/kernel/sched_ext/root/events`` that tracks diagnostic counters. +Sub-schedulers expose their counters at +``/sys/kernel/sched_ext/root/sub/sub-<cgroup_id>/events``. +Each counter occupies one ``name value`` line: + +.. code-block:: none + + # cat /sys/kernel/sched_ext/root/events + SCX_EV_SELECT_CPU_FALLBACK 0 + SCX_EV_DISPATCH_LOCAL_DSQ_OFFLINE 0 + SCX_EV_DISPATCH_KEEP_LAST 123 + SCX_EV_ENQ_SKIP_EXITING 0 + SCX_EV_ENQ_SKIP_MIGRATION_DISABLED 0 + SCX_EV_REENQ_IMMED 0 + SCX_EV_REENQ_LOCAL_REPEAT 0 + SCX_EV_REFILL_SLICE_DFL 456789 + SCX_EV_BYPASS_DURATION 0 + SCX_EV_BYPASS_DISPATCH 0 + SCX_EV_BYPASS_ACTIVATE 0 + SCX_EV_INSERT_NOT_OWNED 0 + SCX_EV_SUB_BYPASS_DISPATCH 0 + +The counters are described in ``kernel/sched/ext_internal.h``; briefly: + +* ``SCX_EV_SELECT_CPU_FALLBACK``: ops.select_cpu() returned a CPU unusable by + the task and the core scheduler silently picked a fallback CPU. +* ``SCX_EV_DISPATCH_LOCAL_DSQ_OFFLINE``: a local-DSQ dispatch was redirected + to the global DSQ because the target CPU went offline. +* ``SCX_EV_DISPATCH_KEEP_LAST``: a task continued running because no other + task was available (only when ``SCX_OPS_ENQ_LAST`` is not set). +* ``SCX_EV_ENQ_SKIP_EXITING``: an exiting task was dispatched to the local DSQ + directly, bypassing ops.enqueue() (only when ``SCX_OPS_ENQ_EXITING`` is not set). +* ``SCX_EV_ENQ_SKIP_MIGRATION_DISABLED``: a migration-disabled task was + dispatched to its local DSQ directly (only when + ``SCX_OPS_ENQ_MIGRATION_DISABLED`` is not set). +* ``SCX_EV_REENQ_IMMED``: a task dispatched with ``SCX_ENQ_IMMED`` was + re-enqueued because the target CPU was not available for immediate execution. +* ``SCX_EV_REENQ_LOCAL_REPEAT``: a reenqueue of the local DSQ triggered + another reenqueue; recurring counts indicate incorrect ``SCX_ENQ_REENQ`` + handling in the BPF scheduler. +* ``SCX_EV_REFILL_SLICE_DFL``: a task's time slice was refilled with the + default value (``SCX_SLICE_DFL``). +* ``SCX_EV_BYPASS_DURATION``: total nanoseconds spent in bypass mode. +* ``SCX_EV_BYPASS_DISPATCH``: number of tasks dispatched while in bypass mode. +* ``SCX_EV_BYPASS_ACTIVATE``: number of times bypass mode was activated. +* ``SCX_EV_INSERT_NOT_OWNED``: attempted to insert a task into a DSQ not owned + by this scheduler; such attempts are silently ignored. +* ``SCX_EV_SUB_BYPASS_DISPATCH``: tasks dispatched from sub-scheduler bypass + DSQs (only relevant with ``CONFIG_EXT_SUB_SCHED``). + ``tools/sched_ext/scx_show_state.py`` is a drgn script which shows more detailed information:
@@ -441,6 +492,25 @@ Where to Look scheduling. Tasks with CPU affinity are direct-dispatched in FIFO order; all others are scheduled in user space by a simple vruntime scheduler. +Module Parameters +================= + +sched_ext exposes two module parameters under the ``sched_ext.`` namespace that +control bypass-mode behaviour. These knobs are primarily for debugging; there +is usually no reason to change them during normal operation. They can be read +and written at runtime (mode 0600) via +``/sys/module/sched_ext/parameters/``. + +``sched_ext.slice_bypass_us`` (default: 5000 µs) + The time slice assigned to all tasks when the scheduler is in bypass mode, + i.e. during BPF scheduler load, unload, and error recovery. Valid range is + 100 µs to 100 ms. + +``sched_ext.bypass_lb_intv_us`` (default: 500000 µs) + The interval at which the bypass-mode load balancer redistributes tasks + across CPUs. Set to 0 to disable load balancing during bypass mode. Valid + range is 0 to 10 s. + ABI Instability ===============
tools/testing/selftests/sched_ext/Makefile +3 -0
@@ -162,8 +162,11 @@ endef all_test_bpfprogs := $(foreach prog,$(wildcard *.bpf.c),$(INCLUDE_DIR)/$(patsubst %.c,%.skel.h,$(prog))) auto-test-targets := \ + consume_immed \ create_dsq \ dequeue \ + dsq_reenq \ + enq_immed \ enq_last_no_enq_fails \ ddsp_bogus_dsq_fail \ ddsp_vtimelocal_fail \
Signature · 1 line
2.43.0
PATCH v2 2/2 selftests/sched_ext: Return non-zero exit code on test failure
In reply to zhidao suFrom: Su Zhidao <[email protected]>
runner.c always returned 0 regardless of test results. The kselftest framework (tools/testing/selftests/kselftest/runner.sh) invokes the runner binary and treats a non-zero exit code as a test failure; with the old code, failed sched_ext tests were silently hidden from the parent harness even though individual "not ok" TAP lines were emitted.
Return 1 when at least one test failed, 0 when all tests passed or were skipped.
--- tools/testing/selftests/sched_ext/runner.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/sched_ext/runner.c +1 -1
@@ -217,7 +217,7 @@ int main(int argc, char **argv)printf (" - %s\n" , failed_tests[i]); } -return 0 ; +return failed >0 ?1 :0 ; }void scx_test_register (struct scx_test *test)
Signature · 1 line
2.43.0
Tejun Heo
reviewerHello,
Applied 1-2 to sched_ext/for-7.1 with the following modification to 1/2:
Fixed SCX_EV_INSERT_NOT_OWNED description - the check is whether the task (not the DSQ) is owned by the scheduler.
Thanks.
--
tejun