Skip to content

Commit 87c5d7f

Browse files
glemcorostedt
authored andcommitted
verification/dot2k: Implement event type detection
Currently dot2k treats all events equally and registers them with a general da_handle_event. This is however just part of the work because some events are necessary to understand when the monitor is entering the initial state. Specifically, the da_handle_start_event takes care of setting the monitor in the initial state and da_handle_start_run_event also registers the current event in the newly enabled monitor. da_handle_start_event can be used on events that only lead to the initial state (as it is currently done in the example monitors), while da_handle_start_run_event could be used on events that are only valid from the initial one. Failing to set at least one of those functions to handle events makes the monitor useless, since it will never be activated. This patch adapts dot2k to parse the events that surely lead to the initial state and set da_handle_start_event for those, if no such event is found but some events are only valid in the initial event, we instead set da_handle_start_run_event (it isn't necessary to set both). We still add a comment to warn the user to make sure this change is matching the model definition. 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 de6f45c commit 87c5d7f

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

tools/verification/dot2/automata.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def __init__(self, file_path, model_name=None):
2626
self.states, self.initial_state, self.final_states = self.__get_state_variables()
2727
self.events = self.__get_event_variables()
2828
self.function = self.__create_matrix()
29+
self.events_start, self.events_start_run = self.__store_init_events()
2930

3031
def __get_model_name(self):
3132
basename = ntpath.basename(self.__dot_path)
@@ -172,3 +173,34 @@ def __create_matrix(self):
172173
cursor += 1
173174

174175
return matrix
176+
177+
def __store_init_events(self):
178+
events_start = [False] * len(self.events)
179+
events_start_run = [False] * len(self.events)
180+
for i, _ in enumerate(self.events):
181+
curr_event_will_init = 0
182+
curr_event_from_init = False
183+
curr_event_used = 0
184+
for j, _ in enumerate(self.states):
185+
if self.function[j][i] != self.invalid_state_str:
186+
curr_event_used += 1
187+
if self.function[j][i] == self.initial_state:
188+
curr_event_will_init += 1
189+
if self.function[0][i] != self.invalid_state_str:
190+
curr_event_from_init = True
191+
# this event always leads to init
192+
if curr_event_will_init and curr_event_used == curr_event_will_init:
193+
events_start[i] = True
194+
# this event is only called from init
195+
if curr_event_from_init and curr_event_used == 1:
196+
events_start_run[i] = True
197+
return events_start, events_start_run
198+
199+
def is_start_event(self, event):
200+
return self.events_start[self.events.index(event)]
201+
202+
def is_start_run_event(self, event):
203+
# prefer handle_start_event if there
204+
if any(self.events_start):
205+
return False
206+
return self.events_start_run[self.events.index(event)]

tools/verification/dot2/dot2k.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,18 @@ def fill_tracepoint_handlers_skel(self):
110110
for event in self.events:
111111
buff.append("static void handle_%s(void *data, /* XXX: fill header */)" % event)
112112
buff.append("{")
113+
handle = "handle_event"
114+
if self.is_start_event(event):
115+
buff.append("\t/* XXX: validate that this event always leads to the initial state */")
116+
handle = "handle_start_event"
117+
elif self.is_start_run_event(event):
118+
buff.append("\t/* XXX: validate that this event is only valid in the initial state */")
119+
handle = "handle_start_run_event"
113120
if self.monitor_type == "per_task":
114121
buff.append("\tstruct task_struct *p = /* XXX: how do I get p? */;");
115-
buff.append("\tda_handle_event_%s(p, %s%s);" % (self.name, event, self.enum_suffix));
122+
buff.append("\tda_%s_%s(p, %s%s);" % (handle, self.name, event, self.enum_suffix));
116123
else:
117-
buff.append("\tda_handle_event_%s(%s%s);" % (self.name, event, self.enum_suffix));
124+
buff.append("\tda_%s_%s(%s%s);" % (handle, self.name, event, self.enum_suffix));
118125
buff.append("}")
119126
buff.append("")
120127
return self.__buff_to_string(buff)

0 commit comments

Comments
 (0)