From 4d7384e9dfcc0514b64e19eae69684ab195b7d80 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Mon, 11 Jan 2021 23:44:10 -0800 Subject: [PATCH] sim: Break the eventq.hh dependency in core.hh. The original implementation of curTick used a thread local variable, _curEventQueue, and its getCurTick() method, to retrieve the curTick for the currently active event queue. That meant that core.hh needed to include eventq.hh so that the EventQueue type was available, which also indirectly brought in a lot of other dependencies. Unfortunately this couldn't easily be fixed by making curTick() non-inline since this added a significant amount of overhead when tested. Instead, this change makes the code in core.hh/core.cc keep a pointer directly to a Tick. The code which sets _curEventQueue now also sets that pointer when _curEventQueue changes. The way curTick() now reaches into the guts of the current EventQueue directly is not great from a modularity perspective, but if curTick is considered an extension of the EventQueue, then it's just odd that this part is broken out into a different file. Change-Id: I8341b40fe75e90672eb1d70e1a368975fcbfe926 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/38996 Maintainer: Gabe Black Tested-by: kokoro Reviewed-by: Daniel Carvalho Reviewed-by: Jason Lowe-Power --- src/sim/core.cc | 7 +++++++ src/sim/core.hh | 11 +++++++++-- src/sim/eventq.hh | 12 +++++++++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/sim/core.cc b/src/sim/core.cc index 8b3624582..ace699a3c 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 2e443e76e..c5920490d 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 45a5ab8d7..5fb087774 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 -- 2.30.2