Gabe Black has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/38996 )

Change subject: sim: Break the eventq.hh dependency in core.hh.
......................................................................

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 <gabe.bl...@gmail.com>
Tested-by: kokoro <noreply+kok...@google.com>
Reviewed-by: Daniel Carvalho <oda...@yahoo.com.br>
Reviewed-by: Jason Lowe-Power <power...@gmail.com>
---
M src/sim/core.cc
M src/sim/core.hh
M src/sim/eventq.hh
3 files changed, 27 insertions(+), 3 deletions(-)

Approvals:
  Jason Lowe-Power: Looks good to me, approved
  Daniel Carvalho: Looks good to me, but someone else must approve
  Gabe Black: Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/sim/core.cc b/src/sim/core.cc
index 8b36245..ace699a 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 2e443e7..c592049 100644
--- a/src/sim/core.hh
+++ b/src/sim/core.hh
@@ -39,10 +39,17 @@
 #include <string>

 #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 45a5ab8..5fb0877 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 @@
 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 @@
 class EventQueue
 {
   private:
+    friend void curEventQueue(EventQueue *);
+
     std::string objName;
     Event *head;
     Tick _curTick;
@@ -968,6 +971,13 @@
     }
 };

+inline void
+curEventQueue(EventQueue *q)
+{
+    _curEventQueue = q;
+    Gem5Internal::_curTickPtr = (q == nullptr) ? nullptr : &q->_curTick;
+}
+
 void dumpMainQueue();

 class EventManager

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/38996
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I8341b40fe75e90672eb1d70e1a368975fcbfe926
Gerrit-Change-Number: 38996
Gerrit-PatchSet: 5
Gerrit-Owner: Gabe Black <gabe.bl...@gmail.com>
Gerrit-Reviewer: Daniel Carvalho <oda...@yahoo.com.br>
Gerrit-Reviewer: Gabe Black <gabe.bl...@gmail.com>
Gerrit-Reviewer: Giacomo Travaglini <giacomo.travagl...@arm.com>
Gerrit-Reviewer: Jason Lowe-Power <ja...@lowepower.com>
Gerrit-Reviewer: Jason Lowe-Power <power...@gmail.com>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to