Skip to content

Commit 9c6cfe8

Browse files
glemcorostedt
authored andcommitted
verification/dot2k: Simplify manual steps in monitor creation
This patch reduces and simplifies the manual steps still needed in creating a new RV monitor. It extends the dot2k script to create a tracepoint snippet and a Kconfig file for the newly generated monitor. Those files can be kept in the monitor's directory but shall be included in the main tracepoint header and Kconfig. Together with the checklist, dot2k now suggests the lines to add to those files for inclusion and the Makefile line to compile the new monitor: Writing the monitor into the directory monitor_name Almost done, checklist - Edit the monitor_name/monitor_name.c to add the instrumentation - Edit kernel/trace/rv/rv_trace.h: Add this line where other tracepoints are included and DA_MON_EVENTS_ID is defined: #include <monitors/monitor_name/monitor_name_trace.h> - Edit kernel/trace/rv/Makefile: Add this line where other monitors are included: obj-$(CONFIG_RV_MON_MONITOR_NAME) += monitors/monitor_name/monitor_name.o - Edit kernel/trace/rv/Kconfig: Add this line where other monitors are included: source "kernel/trace/rv/monitors/monitor_name/Kconfig" - Move monitor_name/ to the kernel's monitor directory (kernel/trace/rv/monitors) Cc: Juri Lelli <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: John Kacur <[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 bc3d482 commit 9c6cfe8

File tree

5 files changed

+110
-5
lines changed

5 files changed

+110
-5
lines changed

tools/verification/dot2/dot2k

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ if __name__ == '__main__':
3535
monitor.print_files()
3636
print("Almost done, checklist")
3737
print(" - Edit the %s/%s.c to add the instrumentation" % (monitor.name, monitor.name))
38-
print(" - Edit include/trace/events/rv.h to add the tracepoint entry")
39-
print(" - Move it to the kernel's monitor directory")
40-
print(" - Edit kernel/trace/rv/Makefile")
41-
print(" - Edit kernel/trace/rv/Kconfig")
38+
print(monitor.fill_tracepoint_tooltip())
39+
print(monitor.fill_makefile_tooltip())
40+
print(monitor.fill_kconfig_tooltip())
41+
print(" - Move %s/ to the kernel's monitor directory (%s/monitors)" % (monitor.name, monitor.rv_dir))

tools/verification/dot2/dot2k.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
class dot2k(Dot2c):
1616
monitor_types = { "global" : 1, "per_cpu" : 2, "per_task" : 3 }
1717
monitor_templates_dir = "dot2/dot2k_templates/"
18+
rv_dir = "kernel/trace/rv"
1819
monitor_type = "per_cpu"
1920

2021
def __init__(self, file_path, MonitorType, extra_params={}):
@@ -27,6 +28,8 @@ def __init__(self, file_path, MonitorType, extra_params={}):
2728
self.monitor_type = MonitorType
2829
self.__fill_rv_templates_dir()
2930
self.main_c = self.__open_file(self.monitor_templates_dir + "main.c")
31+
self.trace_h = self.__open_file(self.monitor_templates_dir + "trace.h")
32+
self.kconfig = self.__open_file(self.monitor_templates_dir + "Kconfig")
3033
self.enum_suffix = "_%s" % self.name
3134
self.description = extra_params.get("description", self.name) or "auto-generated"
3235

@@ -144,6 +147,82 @@ def fill_model_h(self):
144147

145148
return self.__buff_to_string(buff)
146149

150+
def fill_monitor_class_type(self):
151+
if self.monitor_type == "per_task":
152+
return "DA_MON_EVENTS_ID"
153+
return "DA_MON_EVENTS_IMPLICIT"
154+
155+
def fill_monitor_class(self):
156+
if self.monitor_type == "per_task":
157+
return "da_monitor_id"
158+
return "da_monitor"
159+
160+
def fill_tracepoint_args_skel(self, tp_type):
161+
buff = []
162+
tp_args_event = [
163+
("char *", "state"),
164+
("char *", "event"),
165+
("char *", "next_state"),
166+
("bool ", "final_state"),
167+
]
168+
tp_args_error = [
169+
("char *", "state"),
170+
("char *", "event"),
171+
]
172+
tp_args_id = ("int ", "id")
173+
tp_args = tp_args_event if tp_type == "event" else tp_args_error
174+
if self.monitor_type == "per_task":
175+
tp_args.insert(0, tp_args_id)
176+
tp_proto_c = ", ".join([a+b for a,b in tp_args])
177+
tp_args_c = ", ".join([b for a,b in tp_args])
178+
buff.append(" TP_PROTO(%s)," % tp_proto_c)
179+
buff.append(" TP_ARGS(%s)" % tp_args_c)
180+
return self.__buff_to_string(buff)
181+
182+
def fill_trace_h(self):
183+
trace_h = self.trace_h
184+
monitor_class = self.fill_monitor_class()
185+
monitor_class_type = self.fill_monitor_class_type()
186+
tracepoint_args_skel_event = self.fill_tracepoint_args_skel("event")
187+
tracepoint_args_skel_error = self.fill_tracepoint_args_skel("error")
188+
trace_h = trace_h.replace("%%MODEL_NAME%%", self.name)
189+
trace_h = trace_h.replace("%%MODEL_NAME_UP%%", self.name.upper())
190+
trace_h = trace_h.replace("%%MONITOR_CLASS%%", monitor_class)
191+
trace_h = trace_h.replace("%%MONITOR_CLASS_TYPE%%", monitor_class_type)
192+
trace_h = trace_h.replace("%%TRACEPOINT_ARGS_SKEL_EVENT%%", tracepoint_args_skel_event)
193+
trace_h = trace_h.replace("%%TRACEPOINT_ARGS_SKEL_ERROR%%", tracepoint_args_skel_error)
194+
return trace_h
195+
196+
def fill_kconfig(self):
197+
kconfig = self.kconfig
198+
monitor_class_type = self.fill_monitor_class_type()
199+
kconfig = kconfig.replace("%%MODEL_NAME%%", self.name)
200+
kconfig = kconfig.replace("%%MODEL_NAME_UP%%", self.name.upper())
201+
kconfig = kconfig.replace("%%MONITOR_CLASS_TYPE%%", monitor_class_type)
202+
kconfig = kconfig.replace("%%DESCRIPTION%%", self.description)
203+
return kconfig
204+
205+
def fill_tracepoint_tooltip(self):
206+
monitor_class_type = self.fill_monitor_class_type()
207+
return """ - Edit %s/rv_trace.h:
208+
Add this line where other tracepoints are included and %s is defined:
209+
#include <monitors/%s/%s_trace.h>
210+
""" % (self.rv_dir, monitor_class_type, self.name, self.name)
211+
212+
def fill_kconfig_tooltip(self):
213+
return """ - Edit %s/Kconfig:
214+
Add this line where other monitors are included:
215+
source \"kernel/trace/rv/monitors/%s/Kconfig\"
216+
""" % (self.rv_dir, self.name)
217+
218+
def fill_makefile_tooltip(self):
219+
name = self.name
220+
name_up = name.upper()
221+
return """ - Edit %s/Makefile:
222+
Add this line where other monitors are included:
223+
obj-$(CONFIG_RV_MON_%s) += monitors/%s/%s.o
224+
""" % (self.rv_dir, name_up, name, name)
225+
147226
def __create_directory(self):
148227
try:
149228
os.mkdir(self.name)
@@ -182,3 +261,10 @@ def print_files(self):
182261

183262
path = "%s.h" % self.name
184263
self.__create_file(path, model_h)
264+
265+
trace_h = self.fill_trace_h()
266+
path = "%s_trace.h" % self.name
267+
self.__create_file(path, trace_h)
268+
269+
kconfig = self.fill_kconfig()
270+
self.__create_file("Kconfig", kconfig)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
config RV_MON_%%MODEL_NAME_UP%%
2+
depends on RV
3+
select %%MONITOR_CLASS_TYPE%%
4+
bool "%%MODEL_NAME%% monitor"
5+
help
6+
%%DESCRIPTION%%

tools/verification/dot2/dot2k_templates/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* XXX: include required tracepoint headers, e.g.,
1515
* #include <trace/events/sched.h>
1616
*/
17-
#include <trace/events/rv.h>
17+
#include <rv_trace.h>
1818

1919
/*
2020
* This is the self-generated part of the monitor. Generally, there is no need
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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_%%MODEL_NAME_UP%%
8+
DEFINE_EVENT(event_%%MONITOR_CLASS%%, event_%%MODEL_NAME%%,
9+
%%TRACEPOINT_ARGS_SKEL_EVENT%%);
10+
11+
DEFINE_EVENT(error_%%MONITOR_CLASS%%, error_%%MODEL_NAME%%,
12+
%%TRACEPOINT_ARGS_SKEL_ERROR%%);
13+
#endif /* CONFIG_RV_MON_%%MODEL_NAME_UP%% */

0 commit comments

Comments
 (0)