-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a per-task monitor as part of the sched model: * snroc: set non runnable on its own context Monitor to ensure set_state happens only in the respective task's context To: Ingo Molnar <mingo@redhat.com> To: Peter Zijlstra <peterz@infradead.org> Cc: Juri Lelli <juri.lelli@redhat.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: John Kacur <jkacur@redhat.com> Cc: Clark Williams <williams@redhat.com> Link: https://lore.kernel.org/20250305140406.350227-5-gmonaco@redhat.com Signed-off-by: Gabriele Monaco <gmonaco@redhat.com> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
- Loading branch information
Gabriele Monaco
authored and
Steven Rostedt (Google)
committed
Mar 24, 2025
1 parent
9fd420a
commit 93bac9c
Showing
8 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# SPDX-License-Identifier: GPL-2.0-only | ||
# | ||
config RV_MON_SNROC | ||
depends on RV | ||
depends on RV_MON_SCHED | ||
default y | ||
select DA_MON_EVENTS_ID | ||
bool "snroc monitor" | ||
help | ||
Monitor to ensure sched_set_state happens only in the respective task's context. | ||
This monitor is part of the sched monitors collection. | ||
|
||
For further information, see: | ||
Documentation/trace/rv/monitor_sched.rst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
#include <linux/ftrace.h> | ||
#include <linux/tracepoint.h> | ||
#include <linux/kernel.h> | ||
#include <linux/module.h> | ||
#include <linux/init.h> | ||
#include <linux/rv.h> | ||
#include <rv/instrumentation.h> | ||
#include <rv/da_monitor.h> | ||
|
||
#define MODULE_NAME "snroc" | ||
|
||
#include <trace/events/sched.h> | ||
#include <rv_trace.h> | ||
#include <monitors/sched/sched.h> | ||
|
||
#include "snroc.h" | ||
|
||
static struct rv_monitor rv_snroc; | ||
DECLARE_DA_MON_PER_TASK(snroc, unsigned char); | ||
|
||
static void handle_sched_set_state(void *data, struct task_struct *tsk, int state) | ||
{ | ||
da_handle_event_snroc(tsk, sched_set_state_snroc); | ||
} | ||
|
||
static void handle_sched_switch(void *data, bool preempt, | ||
struct task_struct *prev, | ||
struct task_struct *next, | ||
unsigned int prev_state) | ||
{ | ||
da_handle_start_event_snroc(prev, sched_switch_out_snroc); | ||
da_handle_event_snroc(next, sched_switch_in_snroc); | ||
} | ||
|
||
static int enable_snroc(void) | ||
{ | ||
int retval; | ||
|
||
retval = da_monitor_init_snroc(); | ||
if (retval) | ||
return retval; | ||
|
||
rv_attach_trace_probe("snroc", sched_set_state_tp, handle_sched_set_state); | ||
rv_attach_trace_probe("snroc", sched_switch, handle_sched_switch); | ||
|
||
return 0; | ||
} | ||
|
||
static void disable_snroc(void) | ||
{ | ||
rv_snroc.enabled = 0; | ||
|
||
rv_detach_trace_probe("snroc", sched_set_state_tp, handle_sched_set_state); | ||
rv_detach_trace_probe("snroc", sched_switch, handle_sched_switch); | ||
|
||
da_monitor_destroy_snroc(); | ||
} | ||
|
||
static struct rv_monitor rv_snroc = { | ||
.name = "snroc", | ||
.description = "set non runnable on its own context.", | ||
.enable = enable_snroc, | ||
.disable = disable_snroc, | ||
.reset = da_monitor_reset_all_snroc, | ||
.enabled = 0, | ||
}; | ||
|
||
static int __init register_snroc(void) | ||
{ | ||
rv_register_monitor(&rv_snroc, &rv_sched); | ||
return 0; | ||
} | ||
|
||
static void __exit unregister_snroc(void) | ||
{ | ||
rv_unregister_monitor(&rv_snroc); | ||
} | ||
|
||
module_init(register_snroc); | ||
module_exit(unregister_snroc); | ||
|
||
MODULE_LICENSE("GPL"); | ||
MODULE_AUTHOR("Gabriele Monaco <gmonaco@redhat.com>"); | ||
MODULE_DESCRIPTION("snroc: set non runnable on its own context."); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
/* | ||
* Automatically generated C representation of snroc automaton | ||
* For further information about this format, see kernel documentation: | ||
* Documentation/trace/rv/deterministic_automata.rst | ||
*/ | ||
|
||
enum states_snroc { | ||
other_context_snroc = 0, | ||
own_context_snroc, | ||
state_max_snroc | ||
}; | ||
|
||
#define INVALID_STATE state_max_snroc | ||
|
||
enum events_snroc { | ||
sched_set_state_snroc = 0, | ||
sched_switch_in_snroc, | ||
sched_switch_out_snroc, | ||
event_max_snroc | ||
}; | ||
|
||
struct automaton_snroc { | ||
char *state_names[state_max_snroc]; | ||
char *event_names[event_max_snroc]; | ||
unsigned char function[state_max_snroc][event_max_snroc]; | ||
unsigned char initial_state; | ||
bool final_states[state_max_snroc]; | ||
}; | ||
|
||
static const struct automaton_snroc automaton_snroc = { | ||
.state_names = { | ||
"other_context", | ||
"own_context" | ||
}, | ||
.event_names = { | ||
"sched_set_state", | ||
"sched_switch_in", | ||
"sched_switch_out" | ||
}, | ||
.function = { | ||
{ INVALID_STATE, own_context_snroc, INVALID_STATE }, | ||
{ own_context_snroc, INVALID_STATE, other_context_snroc }, | ||
}, | ||
.initial_state = other_context_snroc, | ||
.final_states = { 1, 0 }, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
|
||
/* | ||
* Snippet to be included in rv_trace.h | ||
*/ | ||
|
||
#ifdef CONFIG_RV_MON_SNROC | ||
DEFINE_EVENT(event_da_monitor_id, event_snroc, | ||
TP_PROTO(int id, char *state, char *event, char *next_state, bool final_state), | ||
TP_ARGS(id, state, event, next_state, final_state)); | ||
|
||
DEFINE_EVENT(error_da_monitor_id, error_snroc, | ||
TP_PROTO(int id, char *state, char *event), | ||
TP_ARGS(id, state, event)); | ||
#endif /* CONFIG_RV_MON_SNROC */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
digraph state_automaton { | ||
center = true; | ||
size = "7,11"; | ||
{node [shape = plaintext, style=invis, label=""] "__init_other_context"}; | ||
{node [shape = ellipse] "other_context"}; | ||
{node [shape = plaintext] "other_context"}; | ||
{node [shape = plaintext] "own_context"}; | ||
"__init_other_context" -> "other_context"; | ||
"other_context" [label = "other_context", color = green3]; | ||
"other_context" -> "own_context" [ label = "sched_switch_in" ]; | ||
"own_context" [label = "own_context"]; | ||
"own_context" -> "other_context" [ label = "sched_switch_out" ]; | ||
"own_context" -> "own_context" [ label = "sched_set_state" ]; | ||
{ rank = min ; | ||
"__init_other_context"; | ||
"other_context"; | ||
} | ||
} |