Skip to content

Commit fbe6c09

Browse files
glemcorostedt
authored andcommitted
rv: Add scpd, snep and sncid per-cpu monitors
Add 3 per-cpu monitors as part of the sched model: * scpd: schedule called with preemption disabled Monitor to ensure schedule is called with preemption disabled * snep: schedule does not enable preempt Monitor to ensure schedule does not enable preempt * sncid: schedule not called with interrupt disabled Monitor to ensure schedule is not called with interrupt disabled To: Ingo Molnar <[email protected]> To: Peter Zijlstra <[email protected]> Cc: Juri Lelli <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: John Kacur <[email protected]> Cc: Clark Williams <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Gabriele Monaco <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 93bac9c commit fbe6c09

File tree

18 files changed

+588
-0
lines changed

18 files changed

+588
-0
lines changed

kernel/trace/rv/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ source "kernel/trace/rv/monitors/sched/Kconfig"
3131
source "kernel/trace/rv/monitors/tss/Kconfig"
3232
source "kernel/trace/rv/monitors/sco/Kconfig"
3333
source "kernel/trace/rv/monitors/snroc/Kconfig"
34+
source "kernel/trace/rv/monitors/scpd/Kconfig"
35+
source "kernel/trace/rv/monitors/snep/Kconfig"
36+
source "kernel/trace/rv/monitors/sncid/Kconfig"
3437
# Add new monitors here
3538

3639
config RV_REACTORS

kernel/trace/rv/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ obj-$(CONFIG_RV_MON_SCHED) += monitors/sched/sched.o
99
obj-$(CONFIG_RV_MON_TSS) += monitors/tss/tss.o
1010
obj-$(CONFIG_RV_MON_SCO) += monitors/sco/sco.o
1111
obj-$(CONFIG_RV_MON_SNROC) += monitors/snroc/snroc.o
12+
obj-$(CONFIG_RV_MON_SCPD) += monitors/scpd/scpd.o
13+
obj-$(CONFIG_RV_MON_SNEP) += monitors/snep/snep.o
14+
obj-$(CONFIG_RV_MON_SNCID) += monitors/sncid/sncid.o
1215
# Add new monitors here
1316
obj-$(CONFIG_RV_REACTORS) += rv_reactors.o
1417
obj-$(CONFIG_RV_REACT_PRINTK) += reactor_printk.o

kernel/trace/rv/monitors/scpd/Kconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# SPDX-License-Identifier: GPL-2.0-only
2+
#
3+
config RV_MON_SCPD
4+
depends on RV
5+
depends on PREEMPT_TRACER
6+
depends on RV_MON_SCHED
7+
default y
8+
select DA_MON_EVENTS_IMPLICIT
9+
bool "scpd monitor"
10+
help
11+
Monitor to ensure schedule is called with preemption disabled.
12+
This monitor is part of the sched monitors collection.
13+
14+
For further information, see:
15+
Documentation/trace/rv/monitor_sched.rst

kernel/trace/rv/monitors/scpd/scpd.c

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
#include <linux/ftrace.h>
3+
#include <linux/tracepoint.h>
4+
#include <linux/kernel.h>
5+
#include <linux/module.h>
6+
#include <linux/init.h>
7+
#include <linux/rv.h>
8+
#include <rv/instrumentation.h>
9+
#include <rv/da_monitor.h>
10+
11+
#define MODULE_NAME "scpd"
12+
13+
#include <trace/events/sched.h>
14+
#include <trace/events/preemptirq.h>
15+
#include <rv_trace.h>
16+
#include <monitors/sched/sched.h>
17+
18+
#include "scpd.h"
19+
20+
static struct rv_monitor rv_scpd;
21+
DECLARE_DA_MON_PER_CPU(scpd, unsigned char);
22+
23+
static void handle_preempt_disable(void *data, unsigned long ip, unsigned long parent_ip)
24+
{
25+
da_handle_event_scpd(preempt_disable_scpd);
26+
}
27+
28+
static void handle_preempt_enable(void *data, unsigned long ip, unsigned long parent_ip)
29+
{
30+
da_handle_start_event_scpd(preempt_enable_scpd);
31+
}
32+
33+
static void handle_schedule_entry(void *data, bool preempt, unsigned long ip)
34+
{
35+
da_handle_event_scpd(schedule_entry_scpd);
36+
}
37+
38+
static void handle_schedule_exit(void *data, bool is_switch, unsigned long ip)
39+
{
40+
da_handle_event_scpd(schedule_exit_scpd);
41+
}
42+
43+
static int enable_scpd(void)
44+
{
45+
int retval;
46+
47+
retval = da_monitor_init_scpd();
48+
if (retval)
49+
return retval;
50+
51+
rv_attach_trace_probe("scpd", preempt_disable, handle_preempt_disable);
52+
rv_attach_trace_probe("scpd", preempt_enable, handle_preempt_enable);
53+
rv_attach_trace_probe("scpd", sched_entry_tp, handle_schedule_entry);
54+
rv_attach_trace_probe("scpd", sched_exit_tp, handle_schedule_exit);
55+
56+
return 0;
57+
}
58+
59+
static void disable_scpd(void)
60+
{
61+
rv_scpd.enabled = 0;
62+
63+
rv_detach_trace_probe("scpd", preempt_disable, handle_preempt_disable);
64+
rv_detach_trace_probe("scpd", preempt_enable, handle_preempt_enable);
65+
rv_detach_trace_probe("scpd", sched_entry_tp, handle_schedule_entry);
66+
rv_detach_trace_probe("scpd", sched_exit_tp, handle_schedule_exit);
67+
68+
da_monitor_destroy_scpd();
69+
}
70+
71+
static struct rv_monitor rv_scpd = {
72+
.name = "scpd",
73+
.description = "schedule called with preemption disabled.",
74+
.enable = enable_scpd,
75+
.disable = disable_scpd,
76+
.reset = da_monitor_reset_all_scpd,
77+
.enabled = 0,
78+
};
79+
80+
static int __init register_scpd(void)
81+
{
82+
rv_register_monitor(&rv_scpd, &rv_sched);
83+
return 0;
84+
}
85+
86+
static void __exit unregister_scpd(void)
87+
{
88+
rv_unregister_monitor(&rv_scpd);
89+
}
90+
91+
module_init(register_scpd);
92+
module_exit(unregister_scpd);
93+
94+
MODULE_LICENSE("GPL");
95+
MODULE_AUTHOR("Gabriele Monaco <[email protected]>");
96+
MODULE_DESCRIPTION("scpd: schedule called with preemption disabled.");

kernel/trace/rv/monitors/scpd/scpd.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* Automatically generated C representation of scpd automaton
4+
* For further information about this format, see kernel documentation:
5+
* Documentation/trace/rv/deterministic_automata.rst
6+
*/
7+
8+
enum states_scpd {
9+
cant_sched_scpd = 0,
10+
can_sched_scpd,
11+
state_max_scpd
12+
};
13+
14+
#define INVALID_STATE state_max_scpd
15+
16+
enum events_scpd {
17+
preempt_disable_scpd = 0,
18+
preempt_enable_scpd,
19+
schedule_entry_scpd,
20+
schedule_exit_scpd,
21+
event_max_scpd
22+
};
23+
24+
struct automaton_scpd {
25+
char *state_names[state_max_scpd];
26+
char *event_names[event_max_scpd];
27+
unsigned char function[state_max_scpd][event_max_scpd];
28+
unsigned char initial_state;
29+
bool final_states[state_max_scpd];
30+
};
31+
32+
static const struct automaton_scpd automaton_scpd = {
33+
.state_names = {
34+
"cant_sched",
35+
"can_sched"
36+
},
37+
.event_names = {
38+
"preempt_disable",
39+
"preempt_enable",
40+
"schedule_entry",
41+
"schedule_exit"
42+
},
43+
.function = {
44+
{ can_sched_scpd, INVALID_STATE, INVALID_STATE, INVALID_STATE },
45+
{ INVALID_STATE, cant_sched_scpd, can_sched_scpd, can_sched_scpd },
46+
},
47+
.initial_state = cant_sched_scpd,
48+
.final_states = { 1, 0 },
49+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
3+
/*
4+
* Snippet to be included in rv_trace.h
5+
*/
6+
7+
#ifdef CONFIG_RV_MON_SCPD
8+
DEFINE_EVENT(event_da_monitor, event_scpd,
9+
TP_PROTO(char *state, char *event, char *next_state, bool final_state),
10+
TP_ARGS(state, event, next_state, final_state));
11+
12+
DEFINE_EVENT(error_da_monitor, error_scpd,
13+
TP_PROTO(char *state, char *event),
14+
TP_ARGS(state, event));
15+
#endif /* CONFIG_RV_MON_SCPD */
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# SPDX-License-Identifier: GPL-2.0-only
2+
#
3+
config RV_MON_SNCID
4+
depends on RV
5+
depends on IRQSOFF_TRACER
6+
depends on RV_MON_SCHED
7+
default y
8+
select DA_MON_EVENTS_IMPLICIT
9+
bool "sncid monitor"
10+
help
11+
Monitor to ensure schedule is not called with interrupt disabled.
12+
This monitor is part of the sched monitors collection.
13+
14+
For further information, see:
15+
Documentation/trace/rv/monitor_sched.rst
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
#include <linux/ftrace.h>
3+
#include <linux/tracepoint.h>
4+
#include <linux/kernel.h>
5+
#include <linux/module.h>
6+
#include <linux/init.h>
7+
#include <linux/rv.h>
8+
#include <rv/instrumentation.h>
9+
#include <rv/da_monitor.h>
10+
11+
#define MODULE_NAME "sncid"
12+
13+
#include <trace/events/sched.h>
14+
#include <trace/events/preemptirq.h>
15+
#include <rv_trace.h>
16+
#include <monitors/sched/sched.h>
17+
18+
#include "sncid.h"
19+
20+
static struct rv_monitor rv_sncid;
21+
DECLARE_DA_MON_PER_CPU(sncid, unsigned char);
22+
23+
static void handle_irq_disable(void *data, unsigned long ip, unsigned long parent_ip)
24+
{
25+
da_handle_event_sncid(irq_disable_sncid);
26+
}
27+
28+
static void handle_irq_enable(void *data, unsigned long ip, unsigned long parent_ip)
29+
{
30+
da_handle_start_event_sncid(irq_enable_sncid);
31+
}
32+
33+
static void handle_schedule_entry(void *data, bool preempt, unsigned long ip)
34+
{
35+
da_handle_start_event_sncid(schedule_entry_sncid);
36+
}
37+
38+
static void handle_schedule_exit(void *data, bool is_switch, unsigned long ip)
39+
{
40+
da_handle_start_event_sncid(schedule_exit_sncid);
41+
}
42+
43+
static int enable_sncid(void)
44+
{
45+
int retval;
46+
47+
retval = da_monitor_init_sncid();
48+
if (retval)
49+
return retval;
50+
51+
rv_attach_trace_probe("sncid", irq_disable, handle_irq_disable);
52+
rv_attach_trace_probe("sncid", irq_enable, handle_irq_enable);
53+
rv_attach_trace_probe("sncid", sched_entry_tp, handle_schedule_entry);
54+
rv_attach_trace_probe("sncid", sched_exit_tp, handle_schedule_exit);
55+
56+
return 0;
57+
}
58+
59+
static void disable_sncid(void)
60+
{
61+
rv_sncid.enabled = 0;
62+
63+
rv_detach_trace_probe("sncid", irq_disable, handle_irq_disable);
64+
rv_detach_trace_probe("sncid", irq_enable, handle_irq_enable);
65+
rv_detach_trace_probe("sncid", sched_entry_tp, handle_schedule_entry);
66+
rv_detach_trace_probe("sncid", sched_exit_tp, handle_schedule_exit);
67+
68+
da_monitor_destroy_sncid();
69+
}
70+
71+
static struct rv_monitor rv_sncid = {
72+
.name = "sncid",
73+
.description = "schedule not called with interrupt disabled.",
74+
.enable = enable_sncid,
75+
.disable = disable_sncid,
76+
.reset = da_monitor_reset_all_sncid,
77+
.enabled = 0,
78+
};
79+
80+
static int __init register_sncid(void)
81+
{
82+
rv_register_monitor(&rv_sncid, &rv_sched);
83+
return 0;
84+
}
85+
86+
static void __exit unregister_sncid(void)
87+
{
88+
rv_unregister_monitor(&rv_sncid);
89+
}
90+
91+
module_init(register_sncid);
92+
module_exit(unregister_sncid);
93+
94+
MODULE_LICENSE("GPL");
95+
MODULE_AUTHOR("Gabriele Monaco <[email protected]>");
96+
MODULE_DESCRIPTION("sncid: schedule not called with interrupt disabled.");
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* Automatically generated C representation of sncid automaton
4+
* For further information about this format, see kernel documentation:
5+
* Documentation/trace/rv/deterministic_automata.rst
6+
*/
7+
8+
enum states_sncid {
9+
can_sched_sncid = 0,
10+
cant_sched_sncid,
11+
state_max_sncid
12+
};
13+
14+
#define INVALID_STATE state_max_sncid
15+
16+
enum events_sncid {
17+
irq_disable_sncid = 0,
18+
irq_enable_sncid,
19+
schedule_entry_sncid,
20+
schedule_exit_sncid,
21+
event_max_sncid
22+
};
23+
24+
struct automaton_sncid {
25+
char *state_names[state_max_sncid];
26+
char *event_names[event_max_sncid];
27+
unsigned char function[state_max_sncid][event_max_sncid];
28+
unsigned char initial_state;
29+
bool final_states[state_max_sncid];
30+
};
31+
32+
static const struct automaton_sncid automaton_sncid = {
33+
.state_names = {
34+
"can_sched",
35+
"cant_sched"
36+
},
37+
.event_names = {
38+
"irq_disable",
39+
"irq_enable",
40+
"schedule_entry",
41+
"schedule_exit"
42+
},
43+
.function = {
44+
{ cant_sched_sncid, INVALID_STATE, can_sched_sncid, can_sched_sncid },
45+
{ INVALID_STATE, can_sched_sncid, INVALID_STATE, INVALID_STATE },
46+
},
47+
.initial_state = can_sched_sncid,
48+
.final_states = { 1, 0 },
49+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
3+
/*
4+
* Snippet to be included in rv_trace.h
5+
*/
6+
7+
#ifdef CONFIG_RV_MON_SNCID
8+
DEFINE_EVENT(event_da_monitor, event_sncid,
9+
TP_PROTO(char *state, char *event, char *next_state, bool final_state),
10+
TP_ARGS(state, event, next_state, final_state));
11+
12+
DEFINE_EVENT(error_da_monitor, error_sncid,
13+
TP_PROTO(char *state, char *event),
14+
TP_ARGS(state, event));
15+
#endif /* CONFIG_RV_MON_SNCID */

0 commit comments

Comments
 (0)