[RFC PATCH v2 2/9] tracing/sched: Add IRQ preemption lifecycle tracepoints

From
Karl Mehltretter <hidden>
Date
2026-11-07 17:13:13
Also in
linux-doc, linux-rt-devel, lkml
Reply to
Karl Mehltretter, 2026-11-07
Tracepoints around __schedule() do not identify the start and end of one
preempt_schedule_irq() invocation. The calling task may switch out and
resume on another CPU before the invocation returns.

Add bare entry and exit tracepoints around the generic helper using
DECLARE_TRACE() so they are not exported in tracefs. Record the task
that called preempt_schedule_irq() as the owner in both tracepoints so
consumers can follow the invocation across switches and migration.
Sample the preempt count and interrupt state before dispatching
tracepoint callbacks.

The tracepoints bracket preempt_schedule_irq() only. They do not cover
architecture-specific interrupt-return work or establish that the helper
was reached from a physical interrupt.

Signed-off-by: Karl Mehltretter <redacted>
---
 include/trace/events/sched.h | 26 ++++++++++++++++++++++++++
 kernel/sched/core.c          |  6 ++++++
 2 files changed, 32 insertions(+)
diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h
index 535860581f159..c7aeaa85d27ef 100644
--- a/include/trace/events/sched.h
+++ b/include/trace/events/sched.h
@@ -896,6 +896,32 @@ DECLARE_TRACE(sched_set_need_resched,
 	TP_PROTO(struct task_struct *tsk, int cpu, int tif),
 	TP_ARGS(tsk, cpu, tif));
 
+/*
+ * sched_irq_preempt_entry - begin preempt_schedule_irq() processing
+ * @owner: task whose interrupted execution will resume after scheduling
+ * @pc: preempt count sampled at the call site, before tracing bookkeeping
+ * @irq_off: interrupt state sampled at the same call site
+ *
+ * Emitted after entry assertions and context-tracking setup, with zero
+ * preempt count and local interrupts disabled. Exception-return paths can
+ * also use this scheduler entrypoint.
+ */
+DECLARE_TRACE(sched_irq_preempt_entry,
+	      TP_PROTO(struct task_struct *owner, unsigned long pc, bool irq_off),
+	      TP_ARGS(owner, pc, irq_off));
+
+/*
+ * sched_irq_preempt_exit - original preempt_schedule_irq() invocation resumes
+ * @owner: task saved by the matching entry, possibly on a different CPU
+ * @pc: preempt count sampled at the call site, before tracing bookkeeping
+ * @irq_off: interrupt state sampled at the same call site
+ *
+ * Emitted with local interrupts disabled before restoring context tracking.
+ */
+DECLARE_TRACE(sched_irq_preempt_exit,
+	      TP_PROTO(struct task_struct *owner, unsigned long pc, bool irq_off),
+	      TP_ARGS(owner, pc, irq_off));
+
 #define DL_OTHER 0
 #define DL_TASK 1
 #define DL_SERVER_FAIR 2
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 04b62c16fa8ca..e5c476d27eca7 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -7649,12 +7649,16 @@ EXPORT_SYMBOL_GPL(preempt_schedule_notrace);
  */
 asmlinkage __visible void __sched preempt_schedule_irq(void)
 {
+	struct task_struct *owner = current;
 	enum ctx_state prev_state;
 
 	/* Catch callers which need to be fixed */
 	BUG_ON(preempt_count() || !irqs_disabled());
 
 	prev_state = exception_enter();
+	/* Sample before tracing bookkeeping can change the observed context. */
+	if (trace_sched_irq_preempt_entry_tp_enabled())
+		trace_sched_irq_preempt_entry_tp(owner, preempt_count(), irqs_disabled());
 
 	do {
 		preempt_disable();
@@ -7664,6 +7668,8 @@ asmlinkage __visible void __sched preempt_schedule_irq(void)
 		sched_preempt_enable_no_resched();
 	} while (need_resched());
 
+	if (trace_sched_irq_preempt_exit_tp_enabled())
+		trace_sched_irq_preempt_exit_tp(owner, preempt_count(), irqs_disabled());
 	exception_exit(prev_state);
 }
 
-- 
2.39.5 (Apple Git-154)
Thread (10 messages) 10 messages, 1 author, last reply 1d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help