From 413ba1fdaf666118c9a340d0c23c466f4b7d7fee Mon Sep 17 00:00:00 2001 From: Ali Saidi Date: Thu, 10 May 2012 18:04:26 -0500 Subject: [PATCH] stats: track if the stats have been enabled and prevent requesting master id Track the point in the initialization where statistics have been registered. After this point registering new masterIds can no longer work as some SimObjects may have sized stats vectors based on the previous value. If someone tries to register a masterId after this point the simulator executes fatal(). --- src/base/statistics.cc | 17 +++++++++++++++++ src/base/statistics.hh | 2 ++ src/python/m5/stats/__init__.py | 2 ++ src/python/swig/stats.i | 2 ++ src/sim/system.cc | 7 ++++--- 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/base/statistics.cc b/src/base/statistics.cc index e3f3ad78b3..545d08cabe 100644 --- a/src/base/statistics.cc +++ b/src/base/statistics.cc @@ -441,6 +441,23 @@ registerResetCallback(Callback *cb) resetQueue.add(cb); } +bool _enabled = false; + +bool +enabled() +{ + return _enabled; +} + +void +enable() +{ + if (_enabled) + fatal("Stats are already enabled"); + + _enabled = true; +} + } // namespace Stats void diff --git a/src/base/statistics.hh b/src/base/statistics.hh index 1f8a593264..cb63af7082 100644 --- a/src/base/statistics.hh +++ b/src/base/statistics.hh @@ -3126,6 +3126,8 @@ sum(Temp val) /** Dump all statistics data to the registered outputs */ void dump(); void reset(); +void enable(); +bool enabled(); /** * Register a callback that should be called whenever statistics are diff --git a/src/python/m5/stats/__init__.py b/src/python/m5/stats/__init__.py index 9b5af84fba..1d7e3bc5d2 100644 --- a/src/python/m5/stats/__init__.py +++ b/src/python/m5/stats/__init__.py @@ -82,6 +82,8 @@ def enable(): stats_dict[stat.name] = stat stat.enable() + internal.stats.enable(); + def prepare(): '''Prepare all stats for data access. This must be done before dumping and serialization.''' diff --git a/src/python/swig/stats.i b/src/python/swig/stats.i index 87810d3058..14a6966b12 100644 --- a/src/python/swig/stats.i +++ b/src/python/swig/stats.i @@ -146,6 +146,8 @@ void schedStatEvent(bool dump, bool reset, Tick when = curTick(), Tick repeat = 0); void processResetQueue(); +void enable(); +bool enabled(); std::list &statsList(); diff --git a/src/sim/system.cc b/src/sim/system.cc index 40f5ea0ced..815a4cf1cd 100644 --- a/src/sim/system.cc +++ b/src/sim/system.cc @@ -410,10 +410,11 @@ System::getMasterId(std::string master_name) } } - // todo: Check if stats are enabled yet - // I just don't know a good way to do it + // Verify that the statistics haven't been enabled yet + // Otherwise objects will have sized their stat buckets and + // they will be too small - if (false) + if (Stats::enabled()) fatal("Can't request a masterId after regStats(). \ You must do so in init().\n");