Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

Commit

Permalink
scx: Replace /sys/kernel/debug/sched/ext with tools/sched_ext/scx_sho…
Browse files Browse the repository at this point in the history
…w_state.py

Now that the state is visible through /sys/kernel/sched_ext,
/sys/kernel/debug/sched/ext isn't needed to determine the current state of
scx. However, /sys/kernel/sched_ext shows only a subset of information that
was available in the debug interface and it can be useful to have access to
the rest for debugging. Remove /sys/kernel/debug/sched/ext and add the drgn
script, tools/sched_ext/scx_show_state.py, which shows the same information.

Signed-off-by: Tejun Heo <[email protected]>
  • Loading branch information
htejun committed Jan 18, 2024
1 parent e7a7781 commit a1392ed
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 35 deletions.
16 changes: 16 additions & 0 deletions Documentation/scheduler/sched-ext.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,25 @@ The current status of the BPF scheduler can be determined as follows:
# cat /sys/kernel/sched_ext/root/ops
simple
``tools/sched_ext/scx_show_state.py`` is a drgn script which shows more
detailed information:

.. code-block:: none
# tools/sched_ext/scx_show_state.py
ops : simple
enabled : 1
switching_all : 1
switched_all : 1
enable_state : enabled (2)
bypass_depth : 0
nr_rejected : 0
If ``CONFIG_SCHED_DEBUG`` is set, whether a given task is on sched_ext can
be determined as follows:

.. code-block:: none
# grep ext /proc/self/sched
ext.enabled : 1
Expand Down
3 changes: 0 additions & 3 deletions kernel/sched/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,6 @@ static __init int sched_init_debug(void)

debugfs_create_file("debug", 0444, debugfs_sched, NULL, &sched_debug_fops);

#ifdef CONFIG_SCHED_CLASS_EXT
debugfs_create_file("ext", 0444, debugfs_sched, NULL, &sched_ext_fops);
#endif
return 0;
}
late_initcall(sched_init_debug);
Expand Down
31 changes: 0 additions & 31 deletions kernel/sched/ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -3724,37 +3724,6 @@ static int scx_ops_enable(struct sched_ext_ops *ops)
return ret;
}

#ifdef CONFIG_SCHED_DEBUG
static int scx_debug_show(struct seq_file *m, void *v)
{
mutex_lock(&scx_ops_enable_mutex);
seq_printf(m, "%-30s: %s\n", "ops", scx_ops.name);
seq_printf(m, "%-30s: %ld\n", "enabled", scx_enabled());
seq_printf(m, "%-30s: %d\n", "switching_all",
READ_ONCE(scx_switching_all));
seq_printf(m, "%-30s: %ld\n", "switched_all", scx_switched_all());
seq_printf(m, "%-30s: %s\n", "enable_state",
scx_ops_enable_state_str[scx_ops_enable_state()]);
seq_printf(m, "%-30s: %d\n", "bypassing", scx_ops_bypassing());
seq_printf(m, "%-30s: %lu\n", "nr_rejected",
atomic_long_read(&scx_nr_rejected));
mutex_unlock(&scx_ops_enable_mutex);
return 0;
}

static int scx_debug_open(struct inode *inode, struct file *file)
{
return single_open(file, scx_debug_show, NULL);
}

const struct file_operations sched_ext_fops = {
.open = scx_debug_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
#endif


/********************************************************************************
* bpf_struct_ops plumbing.
Expand Down
1 change: 0 additions & 1 deletion kernel/sched/ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ void sched_enq_and_set_task(struct sched_enq_and_set_ctx *ctx);

extern const struct sched_class ext_sched_class;
extern const struct bpf_verifier_ops bpf_sched_ext_verifier_ops;
extern const struct file_operations sched_ext_fops;
extern unsigned long scx_watchdog_timeout;
extern unsigned long scx_watchdog_timestamp;

Expand Down
39 changes: 39 additions & 0 deletions tools/sched_ext/scx_show_state.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env drgn
#
# Copyright (C) 2024 Tejun Heo <[email protected]>
# Copyright (C) 2024 Meta Platforms, Inc. and affiliates.

desc = """
This is a drgn script to show the current sched_ext state.
For more info on drgn, visit https://github.com/osandov/drgn.
"""

import drgn
import sys

def err(s):
print(s, file=sys.stderr, flush=True)
sys.exit(1)

def read_int(name):
return int(prog[name].value_())

def read_atomic(name):
return prog[name].counter.value_()

def read_static_key(name):
return prog[name].key.enabled.counter.value_()

def ops_state_str(state):
return prog['scx_ops_enable_state_str'][state].string_().decode()

ops = prog['scx_ops']
enable_state = read_atomic("scx_ops_enable_state_var")

print(f'ops : {ops.name.string_().decode()}')
print(f'enabled : {read_static_key("__scx_ops_enabled")}')
print(f'switching_all : {read_int("scx_switching_all")}')
print(f'switched_all : {read_static_key("__scx_switched_all")}')
print(f'enable_state : {ops_state_str(enable_state)} ({enable_state})')
print(f'bypass_depth : {read_atomic("scx_ops_bypass_depth")}')
print(f'nr_rejected : {read_atomic("scx_nr_rejected")}')

0 comments on commit a1392ed

Please sign in to comment.