Skip to contentSkip to conversation

LTL per-cpu monitor type and real-time scheduling monitor

PATCH In review Nam Cao 3 participants 11 messages Aug 11, 2025 – Jul 15

Subsystems (4)
lore
Share & tools
lore

Nam Cao

author
#0 lore raw

v3 cover LTL per-cpu monitor type and real-time scheduling monitor

Hi,

This series adds support for linear temporal logic per-cpu monitor type, analogous to deterministic automaton per-cpu monitor. Then a new per-cpu monitor is added which validates real-time scheduling.

Nam Cao (5):
rv/ltl: Prepare for other monitor types
rv/ltl: Support per-cpu monitors verification/rvgen/ltl: Support per-cpu monitor generation
sched: Add task enqueue/dequeue trace points
rv: Add rts monitor

 Documentation/trace/rv/monitor_rtapp.rst      |  19 +++
 include/linux/rv.h                            |   4 +
 include/rv/ltl_monitor.h                      | 115 +++++++++-----
 include/trace/events/sched.h                  |  13 ++
 kernel/sched/core.c                           |   8 +-
 kernel/trace/rv/Kconfig                       |   5 +
 kernel/trace/rv/Makefile                      |   1 +
 .../trace/rv/monitors/pagefault/pagefault.h   |   2 +
 kernel/trace/rv/monitors/rts/Kconfig          |  17 +++
 kernel/trace/rv/monitors/rts/rts.c            | 144 ++++++++++++++++++
 kernel/trace/rv/monitors/rts/rts.h            | 126 +++++++++++++++
 kernel/trace/rv/monitors/rts/rts_trace.h      |  15 ++
 kernel/trace/rv/monitors/sleep/sleep.h        |   2 +
 kernel/trace/rv/rv_trace.h                    |  47 ++++++
 tools/verification/models/rtapp/rts.ltl       |   5 +
 tools/verification/rvgen/rvgen/ltl2k.py       |  48 +++++-
 .../rvgen/rvgen/templates/ltl2k/main.c        |   9 +-
 .../rvgen/rvgen/templates/ltl2k/trace.h       |   7 +-
 18 files changed, 538 insertions(+), 49 deletions(-)
 create mode 100644 kernel/trace/rv/monitors/rts/Kconfig
 create mode 100644 kernel/trace/rv/monitors/rts/rts.c
 create mode 100644 kernel/trace/rv/monitors/rts/rts.h
 create mode 100644 kernel/trace/rv/monitors/rts/rts_trace.h
 create mode 100644 tools/verification/models/rtapp/rts.ltl
Signature · 1 line
2.39.5
author
#1 lore raw

PATCH v3 1/5 rv/ltl: Prepare for other monitor types

rv/ltl_monitor.h is the template file used by all LTL monitors. But only per-task monitor is supported.

Prepare to support for other monitor types:

- Change the monitored target type into an opaque type which will be defined differently depending on the monitor type. This type is only defined as struct task_struct * for now.

- Separate out the per-task-specific printf format and arguments, so that rv_cond_react() can be shared with other monitor types.

No functional change intended.

---
v2: define the macros for DA usage as well

---
 include/linux/rv.h                            |  4 +
 include/rv/ltl_monitor.h                      | 85 +++++++++++--------
 .../trace/rv/monitors/pagefault/pagefault.h   |  2 +
 kernel/trace/rv/monitors/sleep/sleep.h        |  2 +
 4 files changed, 58 insertions(+), 35 deletions(-)
include/linux/rv.h +4 -0
index 14410a42faef..10a8be730d89 100644
@@ -13,6 +13,10 @@
 #define MAX_DA_NAME_LEN			32
 #define MAX_DA_RETRY_RACING_EVENTS	3
 
+#define RV_MON_GLOBAL	0
+#define RV_MON_PER_CPU	1
+#define RV_MON_PER_TASK	2
+
 #ifdef CONFIG_RV
 #include <linux/bitops.h>
 #include <linux/types.h>
include/rv/ltl_monitor.h +50 -35

178 lines not on this page · raw message

kernel/trace/rv/monitors/pagefault/pagefault.h +2 -0
index c580ec194009..d449af84c24c 100644
@@ -11,6 +11,8 @@
 
 #define MONITOR_NAME pagefault
 
+#define LTL_MONITOR_TYPE RV_MON_PER_TASK
+
 enum ltl_atom {
 	LTL_PAGEFAULT,
 	LTL_RT,
kernel/trace/rv/monitors/sleep/sleep.h +2 -0
index 2ab46fd218d2..0c87875d9040 100644
@@ -11,6 +11,8 @@
 
 #define MONITOR_NAME sleep
 
+#define LTL_MONITOR_TYPE RV_MON_PER_TASK
+
 enum ltl_atom {
 	LTL_ABORT_SLEEP,
 	LTL_BLOCK_ON_RT_MUTEX,
Signature · 1 line
2.39.5
author
#2 lore raw

PATCH v3 2/5 rv/ltl: Support per-cpu monitors

In reply to Nam Cao

Add support for per-cpu run-time verification linear temporal logic monitors. This is analogous to deterministic automaton per-cpu monitors.

---
v3: fixup build issue on sh4
v2: Rename "implicit" to "cpu"

---
 include/rv/ltl_monitor.h   | 32 ++++++++++++++++++++++++++
 kernel/trace/rv/Kconfig    |  4 ++++
 kernel/trace/rv/rv_trace.h | 46 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 82 insertions(+)
include/rv/ltl_monitor.h +32 -0
index 9dabc5b133a3..5c0197a59db0 100644
@@ -23,12 +23,21 @@
 
 typedef struct task_struct *monitor_target;
 
+#elif LTL_MONITOR_TYPE == RV_MON_PER_CPU
+
+#define TARGET_PRINT_FORMAT "%u"
+#define TARGET_PRINT_ARGS(cpu) cpu
+
+typedef unsigned int monitor_target;
+
 #endif
 
 #ifdef CONFIG_RV_REACTORS
 #define RV_MONITOR_NAME CONCATENATE(rv_, MONITOR_NAME)
 static struct rv_monitor RV_MONITOR_NAME;
 
+static struct ltl_monitor *ltl_get_monitor(monitor_target target);
+
 static void rv_cond_react(monitor_target target)
 {
 	if (!rv_reacting_on() || !RV_MONITOR_NAME.react)
@@ -54,6 +63,13 @@ static struct ltl_monitor *ltl_get_monitor(monitor_target target)
 {
 	return &target->rv[ltl_monitor_slot].ltl_mon;
 }
+#elif LTL_MONITOR_TYPE == RV_MON_PER_CPU
+static DEFINE_PER_CPU(struct ltl_monitor, ltl_monitor);
+
+static struct ltl_monitor *ltl_get_monitor(unsigned int cpu)
+{
+	return per_cpu_ptr(&ltl_monitor, cpu);
+}
 #endif
 
 static void ltl_target_init(monitor_target target, bool target_creation)
@@ -108,6 +124,22 @@ static void ltl_monitor_destroy(void)
 	rv_put_task_monitor_slot(ltl_monitor_slot);
 	ltl_monitor_slot = RV_PER_TASK_MONITOR_INIT;
 }
+
+#elif LTL_MONITOR_TYPE == RV_MON_PER_CPU
+
+static int ltl_monitor_init(void)
+{
+	unsigned int cpu;
+
+	for_each_possible_cpu(cpu)
+		ltl_target_init(cpu, false);
+	return 0;
+}
+
+static void ltl_monitor_destroy(void)
+{
+}
+
 #endif
 
 static void ltl_illegal_state(monitor_target target, struct ltl_monitor *mon)
kernel/trace/rv/Kconfig +4 -0
index 5b4be87ba59d..7ef89006ed50 100644
@@ -16,6 +16,10 @@ config DA_MON_EVENTS_ID
 	select RV_MON_MAINTENANCE_EVENTS
 	bool
 
+config LTL_MON_EVENTS_CPU
+	select RV_MON_EVENTS
+	bool
+
 config LTL_MON_EVENTS_ID
 	select RV_MON_EVENTS
 	bool
kernel/trace/rv/rv_trace.h +46 -0

54 lines not on this page · raw message

Signature · 1 line
2.39.5
author
#3 lore raw

PATCH v3 3/5 verification/rvgen/ltl: Support per-cpu monitor generation

In reply to Nam Cao

Add support to generate per-cpu LTL monitors. Similar to generating per-cpu monitors from .dot files, the "-t per_cpu" parameter can be used to generate per-cpu monitors from .ltl files.

---
v3: re-write the description in ltl_atoms_init() to be more precise
v2: Rename "implicit" to "cpu"

---
 tools/verification/rvgen/rvgen/ltl2k.py       | 48 ++++++++++++++++---
 .../rvgen/rvgen/templates/ltl2k/main.c        |  9 ++--
 .../rvgen/rvgen/templates/ltl2k/trace.h       |  7 ++-
 3 files changed, 50 insertions(+), 14 deletions(-)
tools/verification/rvgen/rvgen/ltl2k.py +42 -6
index b075f98d50c4..f291d1f03d05 100644
@@ -57,9 +57,16 @@ class ltl2k(generator.Monitor):
     template_dir = "ltl2k"
 
     def __init__(self, file_path, MonitorType, extra_params={}):
-        if MonitorType != "per_task":
-            raise NotImplementedError("Only per_task monitor is supported for LTL")
+        if MonitorType == "per_task":
+            self._target_arg = "struct task_struct *task"
+            self._target = "task"
+        elif MonitorType == "per_cpu":
+            self._target_arg = "unsigned int cpu"
+            self._target = "cpu"
+        else:
+            raise NotImplementedError(f"LTL does not support monitor type {MonitorType}")
         super().__init__(extra_params)
+        self.monitor_type = MonitorType
         with open(file_path) as f:
             self.atoms, self.ba, self.ltl = ltl2ba.create_graph(f.read())
         self.atoms_abbr = abbreviate_atoms(self.atoms)
@@ -67,6 +74,13 @@ class ltl2k(generator.Monitor):
         if not self.name:
             self.name = Path(file_path).stem
 
+    def _fill_monitor_type(self) -> str:
+        if self.monitor_type == "per_task":
+            return "#define LTL_MONITOR_TYPE RV_MON_PER_TASK"
+        if self.monitor_type == "per_cpu":
+            return "#define LTL_MONITOR_TYPE RV_MON_PER_CPU"
+        assert False
+
     def _fill_states(self) -> str:
         buf = [
             "enum ltl_buchi_state {",
@@ -174,7 +188,7 @@ class ltl2k(generator.Monitor):
 
     def _fill_start(self):
         buf = [
-            "static void ltl_start(struct task_struct *task, struct ltl_monitor *mon)",
+            "static void ltl_start(%s, struct ltl_monitor *mon)" % self._target_arg,
             "{"
         ]
 
@@ -205,7 +219,7 @@ class ltl2k(generator.Monitor):
         buff = []
         buff.append("static void handle_example_event(void *data, /* XXX: fill header */)")
         buff.append("{")
-        buff.append("\tltl_atom_update(task, LTL_%s, true/false);" % self.atoms[0])
+        buff.append("\tltl_atom_update(%s, LTL_%s, true/false);" % (self._target, self.atoms[0]))
         buff.append("}")
         buff.append("")
         return '\n'.join(buff)
@@ -241,6 +255,9 @@ class ltl2k(generator.Monitor):
             ""
         ]
 
+        buf.append(self._fill_monitor_type())
+        buf.append('')
+
         buf.extend(self._fill_atoms())
         buf.append('')
 
@@ -259,13 +276,32 @@ class ltl2k(generator.Monitor):
         return '\n'.join(buf)
 
     def fill_monitor_class_type(self):
-        return "LTL_MON_EVENTS_ID"
+        if self.monitor_type == "per_task":
+            return "LTL_MON_EVENTS_ID"
+        if self.monitor_type == "per_cpu":
+            return "LTL_MON_EVENTS_CPU"
+        assert False
 
     def fill_monitor_class(self):
-        return "ltl_monitor_id"
+        if self.monitor_type == "per_task":
+            return "ltl_monitor_id"
+        if self.monitor_type == "per_cpu":
+            return "ltl_monitor_cpu"
+        assert False
+
+    def fill_tracepoint_args_skel(self, tp_type):
+        if tp_type == "event":
+            return \
+                ("\tTP_PROTO(%s, char *states, char *atoms, char *next),\n" % self._target_arg) + \
+                ("\tTP_ARGS(%s, states, atoms, next)" % self._target)
+        if tp_type == "error":
+            return \
+                ("\tTP_PROTO(%s),\n" % self._target_arg) + \
+                ("\tTP_ARGS(%s)" % self._target)
 
     def fill_main_c(self):
         main_c = super().fill_main_c()
         main_c = main_c.replace("%%ATOMS_INIT%%", self.fill_atoms_init())
+        main_c = main_c.replace("%%TARGET_ARG%%", self._target_arg)
 
         return main_c
tools/verification/rvgen/rvgen/templates/ltl2k/main.c +5 -4
index f85d076fbf78..c6b51a04c360 100644
@@ -23,7 +23,7 @@
 #include "%%MODEL_NAME%%.h"
 #include <rv/ltl_monitor.h>
 
-static void ltl_atoms_fetch(struct task_struct *task, struct ltl_monitor *mon)
+static void ltl_atoms_fetch(%%TARGET_ARG%%, struct ltl_monitor *mon)
 {
 	/*
 	 * This is called everytime the Buchi automaton is triggered.
@@ -36,13 +36,14 @@ static void ltl_atoms_fetch(struct task_struct *task, struct ltl_monitor *mon)
 	 */
 }
 
-static void ltl_atoms_init(struct task_struct *task, struct ltl_monitor *mon, bool task_creation)
+static void ltl_atoms_init(%%TARGET_ARG%%, struct ltl_monitor *mon, bool target_creation)
 {
 	/*
 	 * This should initialize as many atomic propositions as possible.
 	 *
-	 * @task_creation indicates whether the task is being created. This is
-	 * false if the task is already running before the monitor is enabled.
+	 * @target_creation indicates whether the monitored target is being
+	 * created. This is false if the monitor target exists already before
+	 * the monitor is enabled.
 	 */
 %%ATOMS_INIT%%
 }
tools/verification/rvgen/rvgen/templates/ltl2k/trace.h +3 -4
index 49394c4b0f1c..87d3a1308926 100644
@@ -6,9 +6,8 @@
 
 #ifdef CONFIG_RV_MON_%%MODEL_NAME_UP%%
 DEFINE_EVENT(event_%%MONITOR_CLASS%%, event_%%MODEL_NAME%%,
-	     TP_PROTO(struct task_struct *task, char *states, char *atoms, char *next),
-	     TP_ARGS(task, states, atoms, next));
+%%TRACEPOINT_ARGS_SKEL_EVENT%%);
+
 DEFINE_EVENT(error_%%MONITOR_CLASS%%, error_%%MODEL_NAME%%,
-	     TP_PROTO(struct task_struct *task),
-	     TP_ARGS(task));
+%%TRACEPOINT_ARGS_SKEL_ERROR%%);
 #endif /* CONFIG_RV_MON_%%MODEL_NAME_UP%% */
Signature · 1 line
2.39.5
author
#4 lore raw

PATCH v3 4/5 sched: Add task enqueue/dequeue trace points

In reply to Nam Cao

Add trace points into enqueue_task() and dequeue_task(). They are useful to implement RV monitor which validates RT scheduling.

---
Cc: Ingo Molnar <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Juri Lelli <[email protected]>
Cc: Vincent Guittot <[email protected]>
Cc: Dietmar Eggemann <[email protected]>
Cc: Ben Segall <[email protected]>
Cc: Mel Gorman <[email protected]>
Cc: Valentin Schneider <[email protected]>
Cc: K Prateek Nayak <[email protected]>
---
v3: fix up build issue on !SMP
v2: Move the tracepoints to cover all task enqueue/dequeue, not just RT

---
 include/trace/events/sched.h | 13 +++++++++++++
 kernel/sched/core.c          |  8 +++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)
include/trace/events/sched.h +13 -0
index 7b2645b50e78..696d22af5a98 100644
@@ -896,6 +896,19 @@ DECLARE_TRACE(sched_set_need_resched,
 	TP_PROTO(struct task_struct *tsk, int cpu, int tif),
 	TP_ARGS(tsk, cpu, tif));
 
+/*
+ * The two trace points below may not work as expected for fair tasks due
+ * to delayed dequeue. See:
+ * https://lore.kernel.org/lkml/[email protected]/
+ */
+DECLARE_TRACE(enqueue_task,
+	TP_PROTO(int cpu, struct task_struct *task),
+	TP_ARGS(cpu, task));
+
+DECLARE_TRACE(dequeue_task,
+	TP_PROTO(int cpu, struct task_struct *task),
+	TP_ARGS(cpu, task));
+
 #endif /* _TRACE_SCHED_H */
 
 /* This part must be outside protection */
kernel/sched/core.c +7 -1
index be00629f0ba4..6367799aa023 100644
@@ -2077,6 +2077,8 @@ unsigned long get_wchan(struct task_struct *p)
 
 void enqueue_task(struct rq *rq, struct task_struct *p, int flags)
 {
+	trace_enqueue_task_tp(cpu_of(rq), p);
+
 	if (!(flags & ENQUEUE_NOCLOCK))
 		update_rq_clock(rq);
 
@@ -2119,7 +2121,11 @@ inline bool dequeue_task(struct rq *rq, struct task_struct *p, int flags)
 	 * and mark the task ->sched_delayed.
 	 */
 	uclamp_rq_dec(rq, p);
-	return p->sched_class->dequeue_task(rq, p, flags);
+	if (p->sched_class->dequeue_task(rq, p, flags)) {
+		trace_dequeue_task_tp(cpu_of(rq), p);
+		return true;
+	}
+	return false;
 }
 
 void activate_task(struct rq *rq, struct task_struct *p, int flags)
Signature · 1 line
2.39.5
author
#10 lore raw

PATCH v3 5/5 Add rts monitor

In reply to Nam Cao

Add "real-time scheduling" monitor, which validates that SCHED_RR and SCHED_FIFO tasks are scheduled before tasks with normal and extensible scheduling policies

---
Cc: Ingo Molnar <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Juri Lelli <[email protected]>
Cc: Vincent Guittot <[email protected]>
Cc: Dietmar Eggemann <[email protected]>
Cc: Ben Segall <[email protected]>
Cc: Mel Gorman <[email protected]>
Cc: Valentin Schneider <[email protected]>
Cc: K Prateek Nayak <[email protected]>
---
v3:
- move document file and specification file to be under rtapp
v2:
- use the new tracepoints
- move to be under the rtapp container monitor
- re-generate with the modified scripts
- fixup incorrect enqueued status

---
 Documentation/trace/rv/monitor_rtapp.rst |  19 +++
 kernel/trace/rv/Kconfig                  |   1 +
 kernel/trace/rv/Makefile                 |   1 +
 kernel/trace/rv/monitors/rts/Kconfig     |  17 +++
 kernel/trace/rv/monitors/rts/rts.c       | 144 +++++++++++++++++++++++
 kernel/trace/rv/monitors/rts/rts.h       | 126 ++++++++++++++++++++
 kernel/trace/rv/monitors/rts/rts_trace.h |  15 +++
 kernel/trace/rv/rv_trace.h               |   1 +
 tools/verification/models/rtapp/rts.ltl  |   5 +
 9 files changed, 329 insertions(+)
 create mode 100644 kernel/trace/rv/monitors/rts/Kconfig
 create mode 100644 kernel/trace/rv/monitors/rts/rts.c
 create mode 100644 kernel/trace/rv/monitors/rts/rts.h
 create mode 100644 kernel/trace/rv/monitors/rts/rts_trace.h
 create mode 100644 tools/verification/models/rtapp/rts.ltl
Documentation/trace/rv/monitor_rtapp.rst +19 -0
index c8104eda924a..40001ace5612 100644
@@ -131,3 +131,22 @@ special cases:
     real-time-safe because preemption is disabled for the duration.
   - `FUTEX_LOCK_PI` is included in the allowlist for the same reason as
     `BLOCK_ON_RT_MUTEX`.
+
+Monitor rts
++++++++++++
+
+The real-time scheduling monitor validates that tasks with real-time scheduling
+policies (`SCHED_FIFO` and `SCHED_RR`) are always scheduled before tasks with
+normal and extensible scheduling policies (`SCHED_OTHER`, `SCHED_BATCH`,
+`SCHED_IDLE`, `SCHED_EXT`):
+
+.. literalinclude:: ../../../tools/verification/models/rtapp/rts.ltl
+
+Note that this monitor may report errors if real-time throttling or fair
+deadline server is enabled. These mechanisms prevent real-time tasks from
+monopolying the CPU by giving tasks with normal and extensible scheduling
+policies a chance to run. They give system administrators a chance to kill a
+misbehaved real-time task. However, they violate the scheduling priorities and
+may cause latency to well-behaved real-time tasks. Thus, if you see errors from
+this monitor, consider disabling real-time throttling and the fair deadline
+server.
kernel/trace/rv/Kconfig +1 -0
index 7ef89006ed50..e9007ed32aea 100644
@@ -67,6 +67,7 @@ source "kernel/trace/rv/monitors/opid/Kconfig"
 source "kernel/trace/rv/monitors/rtapp/Kconfig"
 source "kernel/trace/rv/monitors/pagefault/Kconfig"
 source "kernel/trace/rv/monitors/sleep/Kconfig"
+source "kernel/trace/rv/monitors/rts/Kconfig"
 # Add new rtapp monitors here
 
 # Add new monitors here
kernel/trace/rv/Makefile +1 -0
index 750e4ad6fa0f..d7bfc7ae6677 100644
@@ -17,6 +17,7 @@ obj-$(CONFIG_RV_MON_STS) += monitors/sts/sts.o
 obj-$(CONFIG_RV_MON_NRP) += monitors/nrp/nrp.o
 obj-$(CONFIG_RV_MON_SSSW) += monitors/sssw/sssw.o
 obj-$(CONFIG_RV_MON_OPID) += monitors/opid/opid.o
+obj-$(CONFIG_RV_MON_RTS) += monitors/rts/rts.o
 # Add new monitors here
 obj-$(CONFIG_RV_REACTORS) += rv_reactors.o
 obj-$(CONFIG_RV_REACT_PRINTK) += reactor_printk.o
kernel/trace/rv/monitors/rts/Kconfig new file +17 -0
new file mode 100644
index 000000000000..5481b371bce1
@@ -0,0 +1,17 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+config RV_MON_RTS
+	depends on RV
+	select RV_LTL_MONITOR
+	depends on RV_MON_RTAPP
+	default y
+	select LTL_MON_EVENTS_CPU
+	bool "rts monitor"
+	help
+	  Add support for RTS (real-time scheduling) monitor which validates
+	  that real-time-priority tasks are scheduled before SCHED_OTHER tasks.
+
+	  This monitor may report an error if RT throttling or deadline server
+	  is enabled.
+
+	  Say Y if you are debugging or testing a real-time system.
kernel/trace/rv/monitors/rts/rts.c new file +144 -0

144 lines not on this page · raw message

kernel/trace/rv/monitors/rts/rts.h new file +126 -0

126 lines not on this page · raw message

kernel/trace/rv/monitors/rts/rts_trace.h new file +15 -0
new file mode 100644
index 000000000000..ac4ea84162f7
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+/*
+ * Snippet to be included in rv_trace.h
+ */
+
+#ifdef CONFIG_RV_MON_RTS
+DEFINE_EVENT(event_ltl_monitor_cpu, event_rts,
+	TP_PROTO(unsigned int cpu, char *states, char *atoms, char *next),
+	TP_ARGS(cpu, states, atoms, next));
+
+DEFINE_EVENT(error_ltl_monitor_cpu, error_rts,
+	TP_PROTO(unsigned int cpu),
+	TP_ARGS(cpu));
+#endif /* CONFIG_RV_MON_RTS */
kernel/trace/rv/rv_trace.h +1 -0
index bf7cca6579ec..7b3a6fb8ca6f 100644
@@ -221,6 +221,7 @@ DECLARE_EVENT_CLASS(error_ltl_monitor_cpu,
 
 	TP_printk("cpu%u: violation detected", __entry->cpu)
 );
+#include <monitors/rts/rts_trace.h>
 // Add new monitors based on CONFIG_LTL_MON_EVENTS_CPU here
 
 #endif /* CONFIG_LTL_MON_EVENTS_CPU */
tools/verification/models/rtapp/rts.ltl new file +5 -0
new file mode 100644
index 000000000000..90872bca46b1
@@ -0,0 +1,5 @@
+RULE = always (RT_TASK_ENQUEUED imply SCHEDULE_RT_NEXT)
+
+SCHEDULE_RT_NEXT = (not SCHED_SWITCH) until (SCHED_SWITCH_RT or EXCEPTIONS)
+
+EXCEPTIONS = SCHED_SWITCH_DL or not RT_TASK_ENQUEUED
Signature · 1 line
2.39.5
maintainer
#5 lore raw

Re: [PATCH v3 4/5] sched: Add task enqueue/dequeue trace points

In reply to Nam Cao
Quoted 5 lines · Nam Cao

Add trace points into enqueue_task() and dequeue_task(). They are useful to implement RV monitor which validates RT scheduling.

---

Peter, Ingo, this patch adds new tracepoints in the scheduler do agree with the change, can we get an Ack?

Thanks,
Gabriele

Quoted 72 lines
Cc Ingo Molnar <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Juri Lelli <[email protected]>
Cc Vincent Guittot <[email protected]>
Cc Dietmar Eggemann <[email protected]>
Cc Ben Segall <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Valentin Schneider <[email protected]>
Cc K Prateek Nayak <[email protected]>

---
v3: fix up build issue on !SMP
v2: Move the tracepoints to cover all task enqueue/dequeue, not just RT
---
 include/trace/events/sched.h | 13 +++++++++++++ kernel/sched/core.c          |  8 +++++++-

 2 files changed, 20 insertions(+), 1 deletion(-)
include/trace/events/sched.h +0 -0
index 7b2645b50e78..696d22af5a98 100644
@@ -896,6 +896,19 @@ DECLARE_TRACE(sched_set_need_resched,
  	TP_PROTO(struct task_struct *tsk, int cpu, int tif),
  	TP_ARGS(tsk, cpu, tif));


+/*
+ * The two trace points below may not work as expected for fair tasks due
+ * to delayed dequeue. See:
+ *
https://lore.kernel.org/lkml/[email protected]/
+ */

include/trace/events/sched.h +8 -0
+DECLARE_TRACE(enqueue_task,
+	TP_PROTO(int cpu, struct task_struct *task),
+	TP_ARGS(cpu, task));
+
+DECLARE_TRACE(dequeue_task,
+	TP_PROTO(int cpu, struct task_struct *task),
+	TP_ARGS(cpu, task));
+

 #endif /* _TRACE_SCHED_H */

 /* This part must be outside protection */

kernel/sched/core.c +0 -0
index be00629f0ba4..6367799aa023 100644
@@ -2077,6 +2077,8 @@ unsigned long get_wchan(struct task_struct *p)


 void enqueue_task(struct rq *rq, struct task_struct *p, int flags) {

kernel/sched/core.c +2 -0
+	trace_enqueue_task_tp(cpu_of(rq), p);
+

  if (!(flags & ENQUEUE_NOCLOCK))
  update_rq_clock(rq);

kernel/sched/core.c +5 -1
@@ -2119,7 +2121,11 @@ inline bool dequeue_task(struct rq *rq, struct
 task_struct *p, int flags)
  	 * and mark the task ->sched_delayed.
  	 */
  	uclamp_rq_dec(rq, p);
-	return p->sched_class->dequeue_task(rq, p, flags);
+	if (p->sched_class->dequeue_task(rq, p, flags)) {
+		trace_dequeue_task_tp(cpu_of(rq), p);
+		return true;
+	}
+	return false;
  }


 void activate_task(struct rq *rq, struct task_struct *p, int flags)

maintainer
#6 lore raw

Re: [PATCH v3 4/5] sched: Add task enqueue/dequeue trace points

Quoted 9 lines · On Wed, 13 Aug 2025 08:50:39 +0200 Gabriele Monaco <[email protected]> wrote:
Quoted 5 lines · Nam Cao

Add trace points into enqueue_task() and dequeue_task(). They are useful to implement RV monitor which validates RT scheduling.

---

Peter, Ingo, this patch adds new tracepoints in the scheduler do agree with the change, can we get an Ack?

Are we still waiting on an Ack for this?

I see it in the archive of Patchwork:

https://patchwork.kernel.org/project/linux-trace-kernel/list/?series=989907&state=%2A&archive=both

-- Steve

maintainer
#7 lore raw

Re: [PATCH v3 4/5] sched: Add task enqueue/dequeue trace points

Quoted 7 lines · Steven Rostedt
Quoted 4 lines · On Wed, 13 Aug 2025 08:50:39 +0200 Gabriele Monaco <[email protected]> wrote:
Quoted 3 lines · Nam Cao

Add trace points into enqueue_task() and dequeue_task(). They are useful to implement RV monitor which validates RT scheduling.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

---

Peter, Ingo, this patch adds new tracepoints in the scheduler do agree with the change, can we get an Ack?

Are we still waiting on an Ack for this?

Yes, but since I'm planning to rebase the patches requiring it on other changes I held this back. I will likely send everything for the next development cycle after merging those new dependencies.

An Ack is surely welcome also now but not urgent.

Thanks,
Gabriele

Quoted 7 lines

I see it in the archive of Patchwork:


https://patchwork.kernel.org/project/linux-trace-kernel/list/?series=989907&state=%2A&archive=both

-- Steve

author
#8 lore raw

Re: [PATCH v3 4/5] sched: Add task enqueue/dequeue trace points

Quoted 5 lines · Gabriele Monaco

Yes, but since I'm planning to rebase the patches requiring it on other changes I held this back. I will likely send everything for the next development cycle after merging those new dependencies.

An Ack is surely welcome also now but not urgent.

I forgot that this exists.

Searching my mail box again, Peter had some comments, but in the v2 thread and not this one.

So let me revise and send v4.

Nam

maintainer
#9 lore raw

Re: [PATCH v3 4/5] sched: Add task enqueue/dequeue trace points

Quoted 7 lines · Nam Cao
Quoted 6 lines · Gabriele Monaco

Yes, but since I'm planning to rebase the patches requiring it on other changes
I held this back. I will likely send everything for the next development cycle
after merging those new dependencies.

Quoted 8 lines
Quoted 1 line

An Ack is surely welcome also now but not urgent.

I forgot that this exists.

Searching my mail box again, Peter had some comments, but in the v2 thread and not this one.

So let me revise and send v4.

Uh I just realised this was your version. I had one along with the dl monitors. I applied Peter's comments and also Prateek chipped in, if you're sending the per-CPU LTL series again, please use [1].

Thanks,
Gabriele

[1] - https://lore.kernel.org/lkml/[email protected]/