Skip to content

Commit 431844b

Browse files
arighihtejun
authored andcommitted
sched_ext: Provide a sysfs enable_seq counter
As discussed during the distro-centric session within the sched_ext Microconference at LPC 2024, introduce a sequence counter that is incremented every time a BPF scheduler is loaded. This feature can help distributions in diagnosing potential performance regressions by identifying systems where users are running (or have ran) custom BPF schedulers. Example: arighi@virtme-ng~> cat /sys/kernel/sched_ext/enable_seq 0 arighi@virtme-ng~> sudo scx_simple local=1 global=0 ^CEXIT: unregistered from user space arighi@virtme-ng~> cat /sys/kernel/sched_ext/enable_seq 1 In this way user-space tools (such as Ubuntu's apport and similar) are able to gather and include this information in bug reports. Cc: Giovanni Gherdovich <[email protected]> Cc: Kleber Sacilotto de Souza <[email protected]> Cc: Marcelo Henrique Cerri <[email protected]> Cc: Phil Auld <[email protected]> Signed-off-by: Andrea Righi <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent 62d3726 commit 431844b

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

Documentation/scheduler/sched-ext.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ The current status of the BPF scheduler can be determined as follows:
8383
# cat /sys/kernel/sched_ext/root/ops
8484
simple
8585
86+
You can check if any BPF scheduler has ever been loaded since boot by examining
87+
this monotonically incrementing counter (a value of zero indicates that no BPF
88+
scheduler has been loaded):
89+
90+
.. code-block:: none
91+
92+
# cat /sys/kernel/sched_ext/enable_seq
93+
1
94+
8695
``tools/sched_ext/scx_show_state.py`` is a drgn script which shows more
8796
detailed information:
8897

@@ -96,6 +105,7 @@ detailed information:
96105
enable_state : enabled (2)
97106
bypass_depth : 0
98107
nr_rejected : 0
108+
enable_seq : 1
99109
100110
If ``CONFIG_SCHED_DEBUG`` is set, whether a given task is on sched_ext can
101111
be determined as follows:

kernel/sched/ext.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,13 @@ static struct scx_exit_info *scx_exit_info;
874874
static atomic_long_t scx_nr_rejected = ATOMIC_LONG_INIT(0);
875875
static atomic_long_t scx_hotplug_seq = ATOMIC_LONG_INIT(0);
876876

877+
/*
878+
* A monotically increasing sequence number that is incremented every time a
879+
* scheduler is enabled. This can be used by to check if any custom sched_ext
880+
* scheduler has ever been used in the system.
881+
*/
882+
static atomic_long_t scx_enable_seq = ATOMIC_LONG_INIT(0);
883+
877884
/*
878885
* The maximum amount of time in jiffies that a task may be runnable without
879886
* being scheduled on a CPU. If this timeout is exceeded, it will trigger
@@ -4154,11 +4161,19 @@ static ssize_t scx_attr_hotplug_seq_show(struct kobject *kobj,
41544161
}
41554162
SCX_ATTR(hotplug_seq);
41564163

4164+
static ssize_t scx_attr_enable_seq_show(struct kobject *kobj,
4165+
struct kobj_attribute *ka, char *buf)
4166+
{
4167+
return sysfs_emit(buf, "%ld\n", atomic_long_read(&scx_enable_seq));
4168+
}
4169+
SCX_ATTR(enable_seq);
4170+
41574171
static struct attribute *scx_global_attrs[] = {
41584172
&scx_attr_state.attr,
41594173
&scx_attr_switch_all.attr,
41604174
&scx_attr_nr_rejected.attr,
41614175
&scx_attr_hotplug_seq.attr,
4176+
&scx_attr_enable_seq.attr,
41624177
NULL,
41634178
};
41644179

@@ -5177,6 +5192,8 @@ static int scx_ops_enable(struct sched_ext_ops *ops, struct bpf_link *link)
51775192
kobject_uevent(scx_root_kobj, KOBJ_ADD);
51785193
mutex_unlock(&scx_ops_enable_mutex);
51795194

5195+
atomic_long_inc(&scx_enable_seq);
5196+
51805197
return 0;
51815198

51825199
err_del:

tools/sched_ext/scx_show_state.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ def ops_state_str(state):
3737
print(f'enable_state : {ops_state_str(enable_state)} ({enable_state})')
3838
print(f'bypass_depth : {read_atomic("scx_ops_bypass_depth")}')
3939
print(f'nr_rejected : {read_atomic("scx_nr_rejected")}')
40+
print(f'enable_seq : {read_atomic("scx_enable_seq")}')

0 commit comments

Comments
 (0)