From: Curtis Dunham Date: Wed, 30 Sep 2015 20:21:55 +0000 (-0500) Subject: base: remove Trace::enabled flag X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=02881a7bf3e5a5920d258d13ed0aed282f252f07;p=gem5.git base: remove Trace::enabled flag The DTRACE() macro tests both Trace::enabled and the specific flag. This change uses the same administrative interface for enabling/disabling tracing, but masks the SimpleFlags settings directly. This eliminates a load for every DTRACE() test, e.g. DPRINTF. --- diff --git a/src/base/debug.cc b/src/base/debug.cc index 2780344a4..6161c9e82 100644 --- a/src/base/debug.cc +++ b/src/base/debug.cc @@ -68,6 +68,8 @@ allFlags() return flags; } +bool SimpleFlag::_active = false; + Flag * findFlag(const std::string &name) { @@ -94,18 +96,34 @@ Flag::~Flag() // should find and remove flag. } +void +SimpleFlag::enableAll() +{ + _active = true; + for (auto& i : allFlags()) + i.second->sync(); +} + +void +SimpleFlag::disableAll() +{ + _active = false; + for (auto& i : allFlags()) + i.second->sync(); +} + void CompoundFlag::enable() { - SimpleFlag::enable(); - for_each(_kids.begin(), _kids.end(), mem_fun(&Flag::enable)); + for (auto& k : _kids) + k->enable(); } void CompoundFlag::disable() { - SimpleFlag::disable(); - for_each(_kids.begin(), _kids.end(), mem_fun(&Flag::disable)); + for (auto& k : _kids) + k->disable(); } struct AllFlags : public Flag diff --git a/src/base/debug.hh b/src/base/debug.hh index 5a03574f1..59a0b6efc 100644 --- a/src/base/debug.hh +++ b/src/base/debug.hh @@ -45,7 +45,6 @@ class Flag protected: const char *_name; const char *_desc; - std::vector _kids; public: Flag(const char *name, const char *desc); @@ -53,33 +52,43 @@ class Flag std::string name() const { return _name; } std::string desc() const { return _desc; } - std::vector kids() { return _kids; } + virtual std::vector kids() { return std::vector(); } virtual void enable() = 0; virtual void disable() = 0; + virtual void sync() {} }; class SimpleFlag : public Flag { + static bool _active; // whether debug tracings are enabled protected: - bool _status; + bool _tracing; // tracing is enabled and flag is on + bool _status; // flag status public: SimpleFlag(const char *name, const char *desc) : Flag(name, desc), _status(false) { } - bool status() const { return _status; } - operator bool() const { return _status; } - bool operator!() const { return !_status; } + bool status() const { return _tracing; } + operator bool() const { return _tracing; } + bool operator!() const { return !_tracing; } + + void enable() { _status = true; sync(); } + void disable() { _status = false; sync(); } + + void sync() { _tracing = _active && _status; } - void enable() { _status = true; } - void disable() { _status = false; } + static void enableAll(); + static void disableAll(); }; -class CompoundFlag : public SimpleFlag +class CompoundFlag : public Flag { protected: + std::vector _kids; + void addFlag(Flag *f) { @@ -99,7 +108,7 @@ class CompoundFlag : public SimpleFlag Flag *f14 = nullptr, Flag *f15 = nullptr, Flag *f16 = nullptr, Flag *f17 = nullptr, Flag *f18 = nullptr, Flag *f19 = nullptr) - : SimpleFlag(name, desc) + : Flag(name, desc) { addFlag(f00); addFlag(f01); addFlag(f02); addFlag(f03); addFlag(f04); addFlag(f05); addFlag(f06); addFlag(f07); addFlag(f08); addFlag(f09); @@ -107,6 +116,8 @@ class CompoundFlag : public SimpleFlag addFlag(f15); addFlag(f16); addFlag(f17); addFlag(f18); addFlag(f19); } + std::vector kids() { return _kids; } + void enable(); void disable(); }; diff --git a/src/base/trace.cc b/src/base/trace.cc index 711d49655..ff1778249 100644 --- a/src/base/trace.cc +++ b/src/base/trace.cc @@ -39,6 +39,7 @@ #include #include +#include "base/debug.hh" #include "base/misc.hh" #include "base/output.hh" #include "base/str.hh" @@ -54,8 +55,6 @@ const std::string &name() namespace Trace { -bool enabled = false; - // This variable holds the output logger for debug information. Other // than setting up/redirecting this logger, do *NOT* reference this // directly @@ -87,6 +86,18 @@ setDebugLogger(Logger *logger) debug_logger = logger; } +void +enable() +{ + Debug::SimpleFlag::enableAll(); +} + +void +disable() +{ + Debug::SimpleFlag::disableAll(); +} + ObjectMatch ignore; void diff --git a/src/base/trace.hh b/src/base/trace.hh index 70e85bf35..2b1d03eff 100644 --- a/src/base/trace.hh +++ b/src/base/trace.hh @@ -116,8 +116,9 @@ std::ostream &output(); /** Delete the current global logger and assign a new one */ void setDebugLogger(Logger *logger); -/** Enable debug logging */ -extern bool enabled; +/** Enable/disable debug logging */ +void enable(); +void disable(); } // namespace Trace @@ -160,7 +161,7 @@ class Named #if TRACING_ON -#define DTRACE(x) ((Debug::x) && Trace::enabled) +#define DTRACE(x) (Debug::x) #define DDUMP(x, data, count) do { \ using namespace Debug; \ diff --git a/src/cpu/exetrace.hh b/src/cpu/exetrace.hh index 51a8c05c9..b7e808a2a 100644 --- a/src/cpu/exetrace.hh +++ b/src/cpu/exetrace.hh @@ -75,9 +75,6 @@ class ExeTracer : public InstTracer if (!Debug::ExecEnable) return NULL; - if (!Trace::enabled) - return NULL; - return new ExeTracerRecord(when, tc, staticInst, pc, macroStaticInst); } diff --git a/src/cpu/inst_pb_trace.cc b/src/cpu/inst_pb_trace.cc index e6ed425ec..400360078 100644 --- a/src/cpu/inst_pb_trace.cc +++ b/src/cpu/inst_pb_trace.cc @@ -123,8 +123,8 @@ InstPBTraceRecord* InstPBTrace::getInstRecord(Tick when, ThreadContext *tc, const StaticInstPtr si, TheISA::PCState pc, const StaticInstPtr mi) { - // Only record the trace if Exec debugging in enabled - if (!Trace::enabled || !Debug::ExecEnable) + // Only record the trace if Exec debugging is enabled + if (!Debug::ExecEnable) return NULL; return new InstPBTraceRecord(*this, when, tc, si, pc, mi); diff --git a/src/cpu/inteltrace.hh b/src/cpu/inteltrace.hh index 4ddf5eac9..fa1b51602 100644 --- a/src/cpu/inteltrace.hh +++ b/src/cpu/inteltrace.hh @@ -71,9 +71,6 @@ class IntelTrace : public InstTracer if (!Debug::ExecEnable) return NULL; - if (!Trace::enabled) - return NULL; - return new IntelTraceRecord(when, tc, staticInst, pc, macroStaticInst); } }; diff --git a/src/python/m5/trace.py b/src/python/m5/trace.py index f34444810..a78b77fc1 100644 --- a/src/python/m5/trace.py +++ b/src/python/m5/trace.py @@ -32,7 +32,7 @@ import util from internal.trace import output, ignore def disable(): - internal.trace.cvar.enabled = False + internal.trace.disable() def enable(): - internal.trace.cvar.enabled = True + internal.trace.enable() diff --git a/src/python/swig/trace.i b/src/python/swig/trace.i index 6525b3e51..50ff7fd3d 100644 --- a/src/python/swig/trace.i +++ b/src/python/swig/trace.i @@ -54,9 +54,11 @@ ignore(const char *expr) Trace::getDebugLogger()->setIgnore(ignore); } -using Trace::enabled; +inline void enable() { Trace::enable(); } +inline void disable() { Trace::disable(); } %} extern void output(const char *string); extern void ignore(const char *expr); -extern bool enabled; +extern void enable(); +extern void disable(); diff --git a/util/cxx_config/main.cc b/util/cxx_config/main.cc index afc166174..2a9588f2e 100644 --- a/util/cxx_config/main.cc +++ b/util/cxx_config/main.cc @@ -117,7 +117,7 @@ main(int argc, char **argv) Stats::initSimStats(); Stats::registerHandlers(CxxConfig::statsReset, CxxConfig::statsDump); - Trace::enabled = true; + Trace::enable(); setDebugFlag("Terminal"); // setDebugFlag("CxxConfig"); diff --git a/util/systemc/main.cc b/util/systemc/main.cc index 2ca6bbe65..f4c7b6305 100644 --- a/util/systemc/main.cc +++ b/util/systemc/main.cc @@ -162,7 +162,7 @@ SimControl::SimControl(sc_core::sc_module_name name, Stats::initSimStats(); Stats::registerHandlers(CxxConfig::statsReset, CxxConfig::statsDump); - Trace::enabled = true; + Trace::enable(); setDebugFlag("Terminal"); checkpoint_restore = false; diff --git a/util/systemc/sc_gem5_control.cc b/util/systemc/sc_gem5_control.cc index 5dd3b1ed5..cf6e0d57c 100644 --- a/util/systemc/sc_gem5_control.cc +++ b/util/systemc/sc_gem5_control.cc @@ -241,7 +241,7 @@ Gem5TopLevelModule::Gem5TopLevelModule(sc_core::sc_module_name name, Stats::initSimStats(); Stats::registerHandlers(CxxConfig::statsReset, CxxConfig::statsDump); - Trace::enabled = true; + Trace::enable(); config_file = new CxxIniFile(); diff --git a/util/tlm/main.cc b/util/tlm/main.cc index 517e4ad43..8add0aeef 100644 --- a/util/tlm/main.cc +++ b/util/tlm/main.cc @@ -142,7 +142,7 @@ SimControl::SimControl(sc_core::sc_module_name name, Stats::initSimStats(); Stats::registerHandlers(CxxConfig::statsReset, CxxConfig::statsDump); - Trace::enabled = true; + Trace::enable(); sim_end = 0; debug = false;