[PATCH v5 0/9] rv: Add scheduler specification monitors

From: Gabriele Monaco
Date: Wed Mar 05 2025 - 09:06:25 EST


This patchset starts including adapted scheduler specifications from
Daniel's task model [1].
As the model is fairly complicated, it is split in several generators
and specifications. The tool used to create the model can output a
unified model, but that would be hardly readable (9k states).

RV allows monitors to run and react concurrently. Running the cumulative
model is equivalent to running single components using the same
reactors, with the advantage that it's easier to point out which
specification failed in case of error.

We allow this by introducing nested monitors, in short, the sysfs
monitor folder will contain a monitor named sched, which is nothing but
an empty container for other monitors. Controlling the sched monitor
(enable, disable, set reactors) controls all nested monitors.

The task model proposed by Daniel includes 12 generators and 33
specifications. The generators are good for documentation but are
usually implied in some specifications.
Not all monitors work out of the box, mainly because of those reasons:
* need to distinguish if preempt disable leads to schedule
* need to distinguish if irq disable comes from an actual irq
* assumptions not always true on SMP

The original task model was designed for PREEMPT_RT and this patchset is
only tested on an upstream kernel with full preemption enabled.

In patch 3-5 are included only some specifications that work without
further modifications. Ideally, we would adapt all specifications and
add them gradually to the sched monitor.

The series is based on 1-2/11 from V4 and won't build without at least
1/11 applied, those two patches are included separately during review.

Patch 1 adds some additional tracepoints in the scheduler's code to
complete the model, the tracepoints were already defined in Daniel's
patches but, as far as I understand, were never submitted

Patch 2 adds the empty sched monitor container and the infrastructure
for nested monitors

Patch 3 adds 2 per-cpu monitors using the tracepoints defined in 2

Patch 4 adds a per-task monitor using the tracepoints defined in 2

Patch 5 adds 3 more per-cpu monitors using the tracepoints defined in 2
and preemptirq tracepoints

Patch 6 adjusts the rv tool to support nested monitors

Patch 7 adjusts the dot2k tool to support nested monitors

Patch 8 adds some documentation for the sched monitors, including
a description of the included specifications

Patch 9 adapts the rv tool to list also filtering by container

Changes since V4:
* fix state given to tracepoint in current_restore_rtlock_saved_state
* removed first 2 patches, added separately

Changes since V3:
* revert skip static_branch_unlikely
* remove argument curr_state from set_state tracepoint
* fix typo

Changes since V2:
* fix reported compilation warnings:
- missing __do_trace_ function if tracepoints are disabled
- remove unused DA_MON_EVENT in sched's Kconfig
* improve condition to detect empty monitor containers

Changes since V1:
* skip static_branch_unlikely in function exporting the tracepoint
* rename function and make clear it should not be called directly
* add missing parameter documentation in rv_register_monitor

Changes since RFC:
* use static_branch_unlikely to trace set_state via external function
* allow nested monitors to be disabled via Kconfig
- they are enabled by default if the container is enabled
* remove need_resched tracepoint as it needs a bit more work
- will come in a following patch together with a monitor using it

[1] - https://bristot.me/linux-task-model
[2] - https://lore.kernel.org/linux-trace-kernel/20250128111926.303093-1-gmonaco@xxxxxxxxxx

To: Steven Rostedt <rostedt@xxxxxxxxxxx>
To: Ingo Molnar <mingo@xxxxxxxxxx>
To: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
To: Juri Lelli <juri.lelli@xxxxxxxxxx>
Cc: John Kacur <jkacur@xxxxxxxxxx>
Cc: Clark Williams <williams@xxxxxxxxxx>
Cc: Tomas Glozar <tglozar@xxxxxxxxxx>
Cc: linux-trace-kernel@xxxxxxxxxxxxxxx

Gabriele Monaco (9):
sched: Add sched tracepoints for RV task model
rv: Add option for nested monitors and include sched
rv: Add sco and tss per-cpu monitors
rv: Add snroc per-task monitor
rv: Add scpd, snep and sncid per-cpu monitors
tools/rv: Add support for nested monitors
verification/dot2k: Add support for nested monitors
Documentation/rv: Add docs for the sched monitors
tools/rv: Allow rv list to filter for container

Documentation/tools/rv/rv-mon-sched.rst | 69 +++++
Documentation/trace/rv/monitor_sched.rst | 171 ++++++++++++
include/linux/rv.h | 4 +-
include/linux/sched.h | 16 ++
include/trace/events/sched.h | 13 +
kernel/sched/core.c | 23 +-
kernel/trace/rv/Kconfig | 7 +
kernel/trace/rv/Makefile | 7 +
kernel/trace/rv/monitors/sched/Kconfig | 11 +
kernel/trace/rv/monitors/sched/sched.c | 38 +++
kernel/trace/rv/monitors/sched/sched.h | 3 +
kernel/trace/rv/monitors/sco/Kconfig | 14 +
kernel/trace/rv/monitors/sco/sco.c | 88 ++++++
kernel/trace/rv/monitors/sco/sco.h | 47 ++++
kernel/trace/rv/monitors/sco/sco_trace.h | 15 +
kernel/trace/rv/monitors/scpd/Kconfig | 15 +
kernel/trace/rv/monitors/scpd/scpd.c | 96 +++++++
kernel/trace/rv/monitors/scpd/scpd.h | 49 ++++
kernel/trace/rv/monitors/scpd/scpd_trace.h | 15 +
kernel/trace/rv/monitors/sncid/Kconfig | 15 +
kernel/trace/rv/monitors/sncid/sncid.c | 96 +++++++
kernel/trace/rv/monitors/sncid/sncid.h | 49 ++++
kernel/trace/rv/monitors/sncid/sncid_trace.h | 15 +
kernel/trace/rv/monitors/snep/Kconfig | 15 +
kernel/trace/rv/monitors/snep/snep.c | 96 +++++++
kernel/trace/rv/monitors/snep/snep.h | 49 ++++
kernel/trace/rv/monitors/snep/snep_trace.h | 15 +
kernel/trace/rv/monitors/snroc/Kconfig | 14 +
kernel/trace/rv/monitors/snroc/snroc.c | 85 ++++++
kernel/trace/rv/monitors/snroc/snroc.h | 47 ++++
kernel/trace/rv/monitors/snroc/snroc_trace.h | 15 +
kernel/trace/rv/monitors/tss/Kconfig | 14 +
kernel/trace/rv/monitors/tss/tss.c | 91 +++++++
kernel/trace/rv/monitors/tss/tss.h | 47 ++++
kernel/trace/rv/monitors/tss/tss_trace.h | 15 +
kernel/trace/rv/monitors/wip/wip.c | 2 +-
kernel/trace/rv/monitors/wwnr/wwnr.c | 2 +-
kernel/trace/rv/rv.c | 154 +++++++++--
kernel/trace/rv/rv.h | 4 +
kernel/trace/rv/rv_reactors.c | 28 +-
kernel/trace/rv/rv_trace.h | 6 +
tools/verification/dot2/dot2k | 27 +-
tools/verification/dot2/dot2k.py | 79 ++++--
.../verification/dot2/dot2k_templates/Kconfig | 1 +
.../verification/dot2/dot2k_templates/main.c | 4 +-
.../dot2/dot2k_templates/main_container.c | 38 +++
.../dot2/dot2k_templates/main_container.h | 3 +
tools/verification/models/sched/sco.dot | 18 ++
tools/verification/models/sched/scpd.dot | 18 ++
tools/verification/models/sched/sncid.dot | 18 ++
tools/verification/models/sched/snep.dot | 18 ++
tools/verification/models/sched/snroc.dot | 18 ++
tools/verification/models/sched/tss.dot | 18 ++
tools/verification/rv/include/in_kernel.h | 2 +-
tools/verification/rv/include/rv.h | 3 +-
tools/verification/rv/src/in_kernel.c | 256 ++++++++++++++----
tools/verification/rv/src/rv.c | 38 ++-
57 files changed, 2007 insertions(+), 127 deletions(-)
create mode 100644 Documentation/tools/rv/rv-mon-sched.rst
create mode 100644 Documentation/trace/rv/monitor_sched.rst
create mode 100644 kernel/trace/rv/monitors/sched/Kconfig
create mode 100644 kernel/trace/rv/monitors/sched/sched.c
create mode 100644 kernel/trace/rv/monitors/sched/sched.h
create mode 100644 kernel/trace/rv/monitors/sco/Kconfig
create mode 100644 kernel/trace/rv/monitors/sco/sco.c
create mode 100644 kernel/trace/rv/monitors/sco/sco.h
create mode 100644 kernel/trace/rv/monitors/sco/sco_trace.h
create mode 100644 kernel/trace/rv/monitors/scpd/Kconfig
create mode 100644 kernel/trace/rv/monitors/scpd/scpd.c
create mode 100644 kernel/trace/rv/monitors/scpd/scpd.h
create mode 100644 kernel/trace/rv/monitors/scpd/scpd_trace.h
create mode 100644 kernel/trace/rv/monitors/sncid/Kconfig
create mode 100644 kernel/trace/rv/monitors/sncid/sncid.c
create mode 100644 kernel/trace/rv/monitors/sncid/sncid.h
create mode 100644 kernel/trace/rv/monitors/sncid/sncid_trace.h
create mode 100644 kernel/trace/rv/monitors/snep/Kconfig
create mode 100644 kernel/trace/rv/monitors/snep/snep.c
create mode 100644 kernel/trace/rv/monitors/snep/snep.h
create mode 100644 kernel/trace/rv/monitors/snep/snep_trace.h
create mode 100644 kernel/trace/rv/monitors/snroc/Kconfig
create mode 100644 kernel/trace/rv/monitors/snroc/snroc.c
create mode 100644 kernel/trace/rv/monitors/snroc/snroc.h
create mode 100644 kernel/trace/rv/monitors/snroc/snroc_trace.h
create mode 100644 kernel/trace/rv/monitors/tss/Kconfig
create mode 100644 kernel/trace/rv/monitors/tss/tss.c
create mode 100644 kernel/trace/rv/monitors/tss/tss.h
create mode 100644 kernel/trace/rv/monitors/tss/tss_trace.h
create mode 100644 tools/verification/dot2/dot2k_templates/main_container.c
create mode 100644 tools/verification/dot2/dot2k_templates/main_container.h
create mode 100644 tools/verification/models/sched/sco.dot
create mode 100644 tools/verification/models/sched/scpd.dot
create mode 100644 tools/verification/models/sched/sncid.dot
create mode 100644 tools/verification/models/sched/snep.dot
create mode 100644 tools/verification/models/sched/snroc.dot
create mode 100644 tools/verification/models/sched/tss.dot


base-commit: 5860c6175c02e9f45af8cf5e6e32772232f5c2f3
--
2.48.1