From c2e1458746278b761917f62eb890eefbf4bbc938 Mon Sep 17 00:00:00 2001 From: Steve Reinhardt Date: Tue, 17 Aug 2010 05:11:00 -0700 Subject: sim: clean up child handling The old code for handling SimObject children was kind of messy, with children stored both in _values and _children, and inconsistent and potentially buggy handling of SimObject vectors. Now children are always stored in _children, and SimObject vectors are consistently handled using the SimObjectVector class. Also, by deferring the parenting of SimObject-valued parameters until the end (instead of doing it at assignment), we eliminate the hole where one could assign a vector of SimObjects to a parameter then append to that vector, with the appended objects never getting parented properly. This patch induces small stats changes in tests with data races due to changes in the object creation & initialization order. The new code does object vectors in order and so should be more stable. --- src/python/m5/params.py | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) (limited to 'src/python/m5/params.py') diff --git a/src/python/m5/params.py b/src/python/m5/params.py index d9578e157..75dcf094a 100644 --- a/src/python/m5/params.py +++ b/src/python/m5/params.py @@ -49,6 +49,7 @@ import datetime import re import sys import time +import math import proxy import ticks @@ -178,10 +179,42 @@ class VectorParamValue(list): def unproxy(self, base): return [v.unproxy(base) for v in self] -class SimObjVector(VectorParamValue): - def print_ini(self, ini_file): +class SimObjectVector(VectorParamValue): + # support clone operation + def __call__(self, **kwargs): + return SimObjectVector([v(**kwargs) for v in self]) + + def clear_parent(self, old_parent): + for v in self: + v.clear_parent(old_parent) + + def set_parent(self, parent, name): + if len(self) == 1: + self[0].set_parent(parent, name) + else: + width = int(math.ceil(math.log(len(self))/math.log(10))) + for i,v in enumerate(self): + v.set_parent(parent, "%s%0*d" % (name, width, i)) + + def get_parent(self): + parent_set = set(v._parent for v in self) + if len(parent_set) != 1: + raise RuntimeError, \ + "SimObjectVector elements have inconsistent parent value." + return parent_set.pop() + + # return 'cpu0 cpu1' etc. for print_ini() + def get_name(self): + return ' '.join([v._name for v in self]) + + # By iterating through the constituent members of the vector here + # we can nicely handle iterating over all a SimObject's children + # without having to provide lots of special functions on + # SimObjectVector directly. + def descendants(self): for v in self: - v.print_ini(ini_file) + for obj in v.descendants(): + yield obj class VectorParamDesc(ParamDesc): file_ext = 'vptype' @@ -197,7 +230,7 @@ class VectorParamDesc(ParamDesc): tmp_list = [ ParamDesc.convert(self, value) ] if isSimObjectSequence(tmp_list): - return SimObjVector(tmp_list) + return SimObjectVector(tmp_list) else: return VectorParamValue(tmp_list) -- cgit v1.2.3