@@ -19,16 +19,31 @@ class dot2k(Dot2c):
1919 monitor_type = "per_cpu"
2020
2121 def __init__ (self , file_path , MonitorType , extra_params = {}):
22- super ().__init__ (file_path , extra_params .get ("model_name" ))
23-
24- self .monitor_type = self .monitor_types .get (MonitorType )
25- if self .monitor_type is None :
26- raise ValueError ("Unknown monitor type: %s" % MonitorType )
27-
28- self .monitor_type = MonitorType
22+ self .container = extra_params .get ("container" )
23+ self .parent = extra_params .get ("parent" )
2924 self .__fill_rv_templates_dir ()
30- self .main_c = self .__read_file (self .monitor_templates_dir + "main.c" )
31- self .trace_h = self .__read_file (self .monitor_templates_dir + "trace.h" )
25+
26+ if self .container :
27+ if file_path :
28+ raise ValueError ("A container does not require a dot file" )
29+ if MonitorType :
30+ raise ValueError ("A container does not require a monitor type" )
31+ if self .parent :
32+ raise ValueError ("A container cannot have a parent" )
33+ self .name = extra_params .get ("model_name" )
34+ self .events = []
35+ self .states = []
36+ self .main_c = self .__read_file (self .monitor_templates_dir + "main_container.c" )
37+ self .main_h = self .__read_file (self .monitor_templates_dir + "main_container.h" )
38+ else :
39+ super ().__init__ (file_path , extra_params .get ("model_name" ))
40+
41+ self .monitor_type = self .monitor_types .get (MonitorType )
42+ if self .monitor_type is None :
43+ raise ValueError ("Unknown monitor type: %s" % MonitorType )
44+ self .monitor_type = MonitorType
45+ self .main_c = self .__read_file (self .monitor_templates_dir + "main.c" )
46+ self .trace_h = self .__read_file (self .monitor_templates_dir + "trace.h" )
3247 self .kconfig = self .__read_file (self .monitor_templates_dir + "Kconfig" )
3348 self .enum_suffix = "_%s" % self .name
3449 self .description = extra_params .get ("description" , self .name ) or "auto-generated"
@@ -105,6 +120,14 @@ def __buff_to_string(self, buff):
105120 def fill_monitor_type (self ):
106121 return self .monitor_type .upper ()
107122
123+ def fill_parent (self ):
124+ return "&rv_%s" % self .parent if self .parent else "NULL"
125+
126+ def fill_include_parent (self ):
127+ if self .parent :
128+ return "#include <monitors/%s/%s.h>\n " % (self .parent , self .parent )
129+ return ""
130+
108131 def fill_tracepoint_handlers_skel (self ):
109132 buff = []
110133 for event in self .events :
@@ -146,6 +169,8 @@ def fill_main_c(self):
146169 tracepoint_handlers = self .fill_tracepoint_handlers_skel ()
147170 tracepoint_attach = self .fill_tracepoint_attach_probe ()
148171 tracepoint_detach = self .fill_tracepoint_detach_helper ()
172+ parent = self .fill_parent ()
173+ parent_include = self .fill_include_parent ()
149174
150175 main_c = main_c .replace ("%%MONITOR_TYPE%%" , monitor_type )
151176 main_c = main_c .replace ("%%MIN_TYPE%%" , min_type )
@@ -155,6 +180,8 @@ def fill_main_c(self):
155180 main_c = main_c .replace ("%%TRACEPOINT_ATTACH%%" , tracepoint_attach )
156181 main_c = main_c .replace ("%%TRACEPOINT_DETACH%%" , tracepoint_detach )
157182 main_c = main_c .replace ("%%DESCRIPTION%%" , self .description )
183+ main_c = main_c .replace ("%%PARENT%%" , parent )
184+ main_c = main_c .replace ("%%INCLUDE_PARENT%%" , parent_include )
158185
159186 return main_c
160187
@@ -216,6 +243,14 @@ def fill_tracepoint_args_skel(self, tp_type):
216243 buff .append (" TP_ARGS(%s)" % tp_args_c )
217244 return self .__buff_to_string (buff )
218245
246+ def fill_monitor_deps (self ):
247+ buff = []
248+ buff .append (" # XXX: add dependencies if there" )
249+ if self .parent :
250+ buff .append (" depends on RV_MON_%s" % self .parent .upper ())
251+ buff .append (" default y" )
252+ return self .__buff_to_string (buff )
253+
219254 def fill_trace_h (self ):
220255 trace_h = self .trace_h
221256 monitor_class = self .fill_monitor_class ()
@@ -233,12 +268,19 @@ def fill_trace_h(self):
233268 def fill_kconfig (self ):
234269 kconfig = self .kconfig
235270 monitor_class_type = self .fill_monitor_class_type ()
271+ monitor_deps = self .fill_monitor_deps ()
236272 kconfig = kconfig .replace ("%%MODEL_NAME%%" , self .name )
237273 kconfig = kconfig .replace ("%%MODEL_NAME_UP%%" , self .name .upper ())
238274 kconfig = kconfig .replace ("%%MONITOR_CLASS_TYPE%%" , monitor_class_type )
239275 kconfig = kconfig .replace ("%%DESCRIPTION%%" , self .description )
276+ kconfig = kconfig .replace ("%%MONITOR_DEPS%%" , monitor_deps )
240277 return kconfig
241278
279+ def fill_main_container_h (self ):
280+ main_h = self .main_h
281+ main_h = main_h .replace ("%%MODEL_NAME%%" , self .name )
282+ return main_h
283+
242284 def __patch_file (self , file , marker , line ):
243285 file_to_patch = os .path .join (self .rv_dir , file )
244286 content = self .__read_file (file_to_patch )
@@ -324,19 +366,24 @@ def __get_main_name(self):
324366
325367 def print_files (self ):
326368 main_c = self .fill_main_c ()
327- model_h = self .fill_model_h ()
328369
329370 self .__create_directory ()
330371
331372 path = "%s.c" % self .name
332373 self .__create_file (path , main_c )
333374
334- path = "%s.h" % self .name
335- self .__create_file (path , model_h )
336-
337- trace_h = self .fill_trace_h ()
338- path = "%s_trace.h" % self .name
339- self .__create_file (path , trace_h )
375+ if self .container :
376+ main_h = self .fill_main_container_h ()
377+ path = "%s.h" % self .name
378+ self .__create_file (path , main_h )
379+ else :
380+ model_h = self .fill_model_h ()
381+ path = "%s.h" % self .name
382+ self .__create_file (path , model_h )
383+
384+ trace_h = self .fill_trace_h ()
385+ path = "%s_trace.h" % self .name
386+ self .__create_file (path , trace_h )
340387
341388 kconfig = self .fill_kconfig ()
342389 self .__create_file ("Kconfig" , kconfig )
0 commit comments