diff --git a/src/sim/core.cc b/src/sim/core.cc index 8b3624582e..ace699a3c3 100644 --- a/src/sim/core.cc +++ b/src/sim/core.cc @@ -41,6 +41,13 @@ using namespace std; +namespace Gem5Internal +{ + +__thread Tick *_curTickPtr; + +} // namespace Gem5Internal + namespace SimClock { /// The simulated frequency of curTick(). (In ticks per second) Tick Frequency; diff --git a/src/sim/core.hh b/src/sim/core.hh index 2e443e76ed..c5920490d7 100644 --- a/src/sim/core.hh +++ b/src/sim/core.hh @@ -39,10 +39,17 @@ #include #include "base/types.hh" -#include "sim/eventq.hh" + +namespace Gem5Internal +{ + +// This pointer is maintained by curEventQueue in src/sim/eventq.hh. +extern __thread Tick *_curTickPtr; + +} // namespace Gem5Internal /// The universal simulation clock. -inline Tick curTick() { return _curEventQueue->getCurTick(); } +inline Tick curTick() { return *Gem5Internal::_curTickPtr; } /// These are variables that are set based on the simulator frequency ///@{ diff --git a/src/sim/eventq.hh b/src/sim/eventq.hh index 45a5ab8d75..5fb0877746 100644 --- a/src/sim/eventq.hh +++ b/src/sim/eventq.hh @@ -48,6 +48,7 @@ #include "base/types.hh" #include "base/uncontended_mutex.hh" #include "debug/Event.hh" +#include "sim/core.hh" #include "sim/serialize.hh" class EventQueue; // forward declaration @@ -81,7 +82,7 @@ extern bool inParallelMode; EventQueue *getEventQueue(uint32_t index); inline EventQueue *curEventQueue() { return _curEventQueue; } -inline void curEventQueue(EventQueue *q) { _curEventQueue = q; } +inline void curEventQueue(EventQueue *q); /** * Common base class for Event and GlobalEvent, so they can share flag @@ -617,6 +618,8 @@ operator!=(const Event &l, const Event &r) class EventQueue { private: + friend void curEventQueue(EventQueue *); + std::string objName; Event *head; Tick _curTick; @@ -968,6 +971,13 @@ class EventQueue } }; +inline void +curEventQueue(EventQueue *q) +{ + _curEventQueue = q; + Gem5Internal::_curTickPtr = (q == nullptr) ? nullptr : &q->_curTick; +} + void dumpMainQueue(); class EventManager