From 59b7cad3ec6ae02f53b53865b365101b1856bb93 Mon Sep 17 00:00:00 2001 From: Andreas Hansson Date: Mon, 9 Jan 2012 18:08:20 -0600 Subject: SWIG: Make gem5 compile and link with swig 2.0.4 To make gem5 compile and run with swig 2.0.4 a few minor fixes are necessary, the fail label issues by swig must not be treated as an error by gcc (tested with gcc 4.2.1), and the vector wrappers must have SWIGPY_SLICE_ARG defined which happens in pycontainer.swg, included through std_container.i. By adding the aforementioned include to the vector wrappers everything seems to work. --- src/python/m5/params.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/python/m5') diff --git a/src/python/m5/params.py b/src/python/m5/params.py index ee3678dc9..03917d085 100644 --- a/src/python/m5/params.py +++ b/src/python/m5/params.py @@ -256,6 +256,9 @@ class VectorParamDesc(ParamDesc): self.ptype.cxx_predecls(code) code('%}') code() + # Make sure the SWIGPY_SLICE_ARG is defined through this inclusion + code('%include "std_container.i"') + code() self.ptype.swig_predecls(code) code() code('%include "std_vector.i"') -- cgit v1.2.3 From 68d387ec802083322196f609c755b993771e9d19 Mon Sep 17 00:00:00 2001 From: Ali Saidi Date: Mon, 9 Jan 2012 18:08:20 -0600 Subject: config: support outputing a pickle of the configuration tree --- src/python/m5/SimObject.py | 45 +++++++++++++++++++++++++++++++++++---------- src/python/m5/main.py | 2 ++ src/python/m5/params.py | 9 +++++++++ src/python/m5/simulate.py | 9 +++++++++ 4 files changed, 55 insertions(+), 10 deletions(-) (limited to 'src/python/m5') diff --git a/src/python/m5/SimObject.py b/src/python/m5/SimObject.py index 60693758c..dcc90e1bc 100644 --- a/src/python/m5/SimObject.py +++ b/src/python/m5/SimObject.py @@ -874,29 +874,54 @@ class SimObject(object): if hasattr(self, 'type'): print >>ini_file, 'type=%s' % self.type - child_names = self._children.keys() - child_names.sort() - if len(child_names): + if len(self._children.keys()): print >>ini_file, 'children=%s' % \ - ' '.join(self._children[n].get_name() for n in child_names) + ' '.join(self._children[n].get_name() \ + for n in sorted(self._children.keys())) - param_names = self._params.keys() - param_names.sort() - for param in param_names: + for param in sorted(self._params.keys()): value = self._values.get(param) if value != None: print >>ini_file, '%s=%s' % (param, self._values[param].ini_str()) - port_names = self._ports.keys() - port_names.sort() - for port_name in port_names: + for port_name in sorted(self._ports.keys()): port = self._port_refs.get(port_name, None) if port != None: print >>ini_file, '%s=%s' % (port_name, port.ini_str()) print >>ini_file # blank line between objects + # generate a tree of dictionaries expressing all the parameters in the + # instantiated system for use by scripts that want to do power, thermal + # visualization, and other similar tasks + def get_config_as_dict(self): + d = attrdict() + if hasattr(self, 'type'): + d.type = self.type + if hasattr(self, 'cxx_class'): + d.cxx_class = self.cxx_class + + for param in sorted(self._params.keys()): + value = self._values.get(param) + try: + d[param] = self._values[param].value + except AttributeError: + pass + + for n in sorted(self._children.keys()): + d[self._children[n].get_name()] = self._children[n].get_config_as_dict() + + for port_name in sorted(self._ports.keys()): + port = self._port_refs.get(port_name, None) + if port != None: + # Might want to actually make this reference the object + # in the future, although execing the string problem would + # get some of the way there + d[port_name] = port.ini_str() + + return d + def getCCParams(self): if self._ccParams: return self._ccParams diff --git a/src/python/m5/main.py b/src/python/m5/main.py index 58de62cc3..17e0c2f91 100644 --- a/src/python/m5/main.py +++ b/src/python/m5/main.py @@ -87,6 +87,8 @@ def parse_options(): group("Configuration Options") option("--dump-config", metavar="FILE", default="config.ini", help="Dump configuration output file [Default: %default]") + option("--json-config", metavar="FILE", default="config.json", + help="Create JSON output of the configuration [Default: %default]") # Debugging options group("Debugging Options") diff --git a/src/python/m5/params.py b/src/python/m5/params.py index 03917d085..05fe9b774 100644 --- a/src/python/m5/params.py +++ b/src/python/m5/params.py @@ -228,6 +228,12 @@ class SimObjectVector(VectorParamValue): for obj in v.descendants(): yield obj + def get_config_as_dict(self): + a = [] + for v in self: + a.append(v.get_config_as_dict()) + return a + class VectorParamDesc(ParamDesc): # Convert assigned value to appropriate type. If the RHS is not a # list or tuple, it generates a single-element list. @@ -964,6 +970,9 @@ class Time(ParamValue): def ini_str(self): return str(self) + def get_config_as_dict(self): + return str(self) + # Enumerated types are a little more complex. The user specifies the # type as Enum(foo) where foo is either a list or dictionary of # alternatives (typically strings, but not necessarily so). (In the diff --git a/src/python/m5/simulate.py b/src/python/m5/simulate.py index b4ccf82c1..29d14f75d 100644 --- a/src/python/m5/simulate.py +++ b/src/python/m5/simulate.py @@ -31,6 +31,7 @@ import atexit import os import sys +import json # import the SWIG-wrapped main C++ functions import internal @@ -40,6 +41,7 @@ import SimObject import ticks import objects from util import fatal +from util import attrdict # define a MaxTick parameter MaxTick = 2**63 - 1 @@ -71,6 +73,13 @@ def instantiate(ckpt_dir=None): obj.print_ini(ini_file) ini_file.close() + if options.json_config: + json_file = file(os.path.join(options.outdir, options.json_config), 'w') + d = root.get_config_as_dict() + json.dump(d, json_file, indent=4) + json_file.close() + + # Initialize the global statistics stats.initSimStats() -- cgit v1.2.3 From 51aa7e4a0392d5e8f98bd7a4d09f4026dd21bd0a Mon Sep 17 00:00:00 2001 From: Prakash Ramrakhyani Date: Mon, 9 Jan 2012 18:08:20 -0600 Subject: sim: Enable sampling of run-time for code-sections marked using pseudo insts. This patch adds a mechanism to collect run time samples for specific portions of a benchmark, using work_begin and work_end pseudo instructions.It also enhances the histogram stat to report geometric mean. --- src/python/m5/main.py | 1 - 1 file changed, 1 deletion(-) (limited to 'src/python/m5') diff --git a/src/python/m5/main.py b/src/python/m5/main.py index 17e0c2f91..910cb6ce6 100644 --- a/src/python/m5/main.py +++ b/src/python/m5/main.py @@ -123,7 +123,6 @@ def parse_options(): execfile(options_file, scope) arguments = options.parse_args() - return options,arguments def interact(scope): -- cgit v1.2.3 From e308208f302b6bccff15f7c694e7ed334e870942 Mon Sep 17 00:00:00 2001 From: Ali Saidi Date: Mon, 9 Jan 2012 20:04:28 -0500 Subject: Config: Fix issue with JSON output --- src/python/m5/SimObject.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/python/m5') diff --git a/src/python/m5/SimObject.py b/src/python/m5/SimObject.py index dcc90e1bc..47ca32af2 100644 --- a/src/python/m5/SimObject.py +++ b/src/python/m5/SimObject.py @@ -905,7 +905,15 @@ class SimObject(object): for param in sorted(self._params.keys()): value = self._values.get(param) try: - d[param] = self._values[param].value + # Use native type for those supported by JSON and + # strings for everything else. skipkeys=True seems + # to not work as well as one would hope + if type(self._values[param].value) in \ + [str, unicode, int, long, float, bool, None]: + d[param] = self._values[param].value + else: + d[param] = str(self._values[param]) + except AttributeError: pass -- cgit v1.2.3 From 8f18898e85ade3233502acd0dbc7cf9cd416d880 Mon Sep 17 00:00:00 2001 From: Ali Saidi Date: Tue, 10 Jan 2012 10:17:33 -0600 Subject: config: Fix json output for Python lt 2.6. --- src/python/m5/simulate.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/python/m5') diff --git a/src/python/m5/simulate.py b/src/python/m5/simulate.py index 29d14f75d..38129592c 100644 --- a/src/python/m5/simulate.py +++ b/src/python/m5/simulate.py @@ -31,7 +31,6 @@ import atexit import os import sys -import json # import the SWIG-wrapped main C++ functions import internal @@ -74,10 +73,14 @@ def instantiate(ckpt_dir=None): ini_file.close() if options.json_config: - json_file = file(os.path.join(options.outdir, options.json_config), 'w') - d = root.get_config_as_dict() - json.dump(d, json_file, indent=4) - json_file.close() + try: + import json + json_file = file(os.path.join(options.outdir, options.json_config), 'w') + d = root.get_config_as_dict() + json.dump(d, json_file, indent=4) + json_file.close() + except ImportError: + pass # Initialize the global statistics -- cgit v1.2.3