[PATCH v2] sched_ext: Add tracepoint for scheduler exit

Pat Somaru <[email protected]>
Newsgroups dev.linux.lists.sched-ext,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
sched_ext schedulers have state in BPF programs and kernel. scx_dump
provides kernel state and BPF program state on error, but this is static
in what it can provide.

Add a sched_ext_exit tracepoint in scx_claim_exit() so that BPF programs
can dynamically inspect scheduler specific state at the moment of exit.
Pass the exiting scx_sched so attached programs can read its state, and,
since exits propagate through a hierarchy of sub-schedulers, identify
which scheduler each event belongs to.

Signed-off-by: Pat Somaru <[email protected]>
---
v2: pass sch to the tracepoint and record name/level so exits in a
    scheduler hierarchy are attributable (Tejun)
v1: https://lore.kernel.org/all/[email protected]/

Tested by attaching to the raw tracepoint and unregistering a scheduler:

  # bpftrace -e 'rawtracepoint:sched_ext_exit {
        $sch = (struct scx_sched *)arg0;
        printf("sch=%p name=%s level=%d kind=%ld\n",
               $sch, $sch->ops.name, $sch->level, (int64)arg1); }'

  Attached 1 probe
  sch=0xff1f39c90f1c7000 name=mitosis_1.1.0_x86_64_unknown_linux_gnu level=0 kind=64

 include/trace/events/sched_ext.h | 23 +++++++++++++++++++++++
 kernel/sched/ext/ext.c           |  2 ++
 2 files changed, 25 insertions(+)

diff --git a/include/trace/events/sched_ext.h b/include/trace/events/sched_ext.h
index d1bf5acd59c5..ce1179478e8b 100644
--- a/include/trace/events/sched_ext.h
+++ b/include/trace/events/sched_ext.h
@@ -84,6 +84,29 @@ TRACE_EVENT(sched_ext_bypass_lb,
 	)
 );
 
+TRACE_EVENT(sched_ext_exit,
+
+	TP_PROTO(struct scx_sched *sch, __u32 kind),
+
+	TP_ARGS(sch, kind),
+
+	TP_STRUCT__entry(
+		__string(	name,	sch->ops.name	)
+		__field(	__s32,	level		)
+		__field(	__u32,	kind		)
+	),
+
+	TP_fast_assign(
+		__assign_str(name);
+		__entry->level		= sch->level;
+		__entry->kind		= kind;
+	),
+
+	TP_printk("sched %s level %d kind %u",
+		  __get_str(name), __entry->level, __entry->kind
+	)
+);
+
 #endif /* _TRACE_SCHED_EXT_H */
 
 /* This part must be outside protection */
diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c
index 1a0ec985da77..6ec774435cd1 100644
--- a/kernel/sched/ext/ext.c
+++ b/kernel/sched/ext/ext.c
@@ -5730,6 +5730,8 @@ static bool scx_claim_exit(struct scx_sched *sch, enum scx_exit_kind kind)
 	 */
 	WRITE_ONCE(sch->aborting, true);
 
+	trace_sched_ext_exit(sch, kind);
+
 	/*
 	 * Propagate exits to descendants immediately. Each has a dedicated
 	 * helper kthread and can run in parallel. While most of disabling is

base-commit: 57194a3172ba0123e8f37c4574a8e2863ab67622
-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.