cpu: Make accesses to comInstEventQueue indirect through methods.
authorGabe Black <gabeblack@google.com>
Mon, 14 Oct 2019 05:02:35 +0000 (22:02 -0700)
committerGabe Black <gabeblack@google.com>
Fri, 25 Oct 2019 22:42:31 +0000 (22:42 +0000)
This lets us move the event queue itself around, or change how those
services are provided.

Change-Id: Ie36665b353cf9788968f253cf281a854a6eff4f4
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/22107
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Maintainer: Gabe Black <gabeblack@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
src/base/remote_gdb.cc
src/cpu/base.cc
src/cpu/base.hh
src/cpu/kvm/base.cc
src/cpu/minor/execute.cc
src/cpu/o3/cpu.cc
src/cpu/o3/probe/elastic_trace.cc
src/cpu/simple/base.cc

index 3dde235f01dda3baa6b5d23a49e47922a9d01068..b45ef103732974dfd949e1c4260052b6d15c15c6 100644 (file)
@@ -317,12 +317,6 @@ break_type(char c)
 
 std::map<Addr, HardBreakpoint *> hardBreakMap;
 
-EventQueue *
-getComInstEventQueue(ThreadContext *tc)
-{
-    return tc->getCpuPtr()->comInstEventQueue[tc->threadId()];
-}
-
 }
 
 BaseRemoteGDB::BaseRemoteGDB(System *_system, ThreadContext *c, int _port) :
@@ -759,17 +753,18 @@ BaseRemoteGDB::setTempBreakpoint(Addr bkpt)
 void
 BaseRemoteGDB::scheduleInstCommitEvent(Event *ev, int delta)
 {
-    EventQueue *eq = getComInstEventQueue(tc);
+    auto *cpu = tc->getCpuPtr();
     // Here "ticks" aren't simulator ticks which measure time, they're
     // instructions committed by the CPU.
-    eq->schedule(ev, eq->getCurTick() + delta);
+    cpu->scheduleInstCountEvent(tc->threadId(), ev,
+            cpu->getCurrentInstCount(tc->threadId()) + delta);
 }
 
 void
 BaseRemoteGDB::descheduleInstCommitEvent(Event *ev)
 {
     if (ev->scheduled())
-        getComInstEventQueue(tc)->deschedule(ev);
+        tc->getCpuPtr()->descheduleInstCountEvent(tc->threadId(), ev);
 }
 
 std::map<char, BaseRemoteGDB::GdbCommand> BaseRemoteGDB::command_map = {
index 7e0e79e9635dfd3ea7120aded3c0c226e752bad9..a4ffb1031a0b78a5aea6641cb9276e276ea08bba 100644 (file)
@@ -191,7 +191,7 @@ BaseCPU::BaseCPU(Params *p, bool is_checker)
         *counter = numThreads;
         for (ThreadID tid = 0; tid < numThreads; ++tid) {
             Event *event = new CountedExitEvent(cause, *counter);
-            comInstEventQueue[tid]->schedule(event, p->max_insts_all_threads);
+            scheduleInstCountEvent(tid, event, p->max_insts_all_threads);
         }
     }
 
@@ -726,16 +726,16 @@ BaseCPU::unserialize(CheckpointIn &cp)
 void
 BaseCPU::scheduleInstStop(ThreadID tid, Counter insts, const char *cause)
 {
-    const Tick now(comInstEventQueue[tid]->getCurTick());
+    const Tick now(getCurrentInstCount(tid));
     Event *event(new LocalSimLoopExitEvent(cause, 0));
 
-    comInstEventQueue[tid]->schedule(event, now + insts);
+    scheduleInstCountEvent(tid, event, now + insts);
 }
 
-uint64_t
+Tick
 BaseCPU::getCurrentInstCount(ThreadID tid)
 {
-    return Tick(comInstEventQueue[tid]->getCurTick());
+    return comInstEventQueue[tid]->getCurTick();
 }
 
 AddressMonitor::AddressMonitor() {
index cb23cb1ba72cf2a00d57a1c7e67bcebb7ef81c68..0424945cb296022e32a3d044d5bec6934f345140 100644 (file)
@@ -465,6 +465,31 @@ class BaseCPU : public ClockedObject
      */
     uint64_t getCurrentInstCount(ThreadID tid);
 
+    Tick
+    nextInstEventCount(ThreadID tid)
+    {
+        return comInstEventQueue[tid]->empty() ?
+            MaxTick : comInstEventQueue[tid]->nextTick();
+    }
+
+    void
+    serviceInstCountEvents(ThreadID tid, Tick count)
+    {
+        comInstEventQueue[tid]->serviceEvents(count);
+    }
+
+    void
+    scheduleInstCountEvent(ThreadID tid, Event *event, Tick count)
+    {
+        comInstEventQueue[tid]->schedule(event, count);
+    }
+
+    void
+    descheduleInstCountEvent(ThreadID tid, Event *event)
+    {
+        comInstEventQueue[tid]->deschedule(event);
+    }
+
   public:
     /**
      * @{
index 0b388897623aa5535fcf93084b223251692d934a..384abb0eb7479e7678a331631a20f887a721dcad 100644 (file)
@@ -630,9 +630,7 @@ BaseKvmCPU::tick()
 
       case RunningServiceCompletion:
       case Running: {
-          const uint64_t nextInstEvent(
-              !comInstEventQueue[0]->empty() ?
-              comInstEventQueue[0]->nextTick() : UINT64_MAX);
+          const uint64_t nextInstEvent(nextInstEventCount(0));
           // Enter into KVM and complete pending IO instructions if we
           // have an instruction event pending.
           const Tick ticksToExecute(
@@ -688,7 +686,7 @@ BaseKvmCPU::tick()
           // Service any pending instruction events. The vCPU should
           // have exited in time for the event using the instruction
           // counter configured by setupInstStop().
-          comInstEventQueue[0]->serviceEvents(ctrInsts);
+          serviceInstCountEvents(0, ctrInsts);
 
           if (tryDrain())
               _status = Idle;
@@ -1348,11 +1346,10 @@ BaseKvmCPU::ioctlRun()
 void
 BaseKvmCPU::setupInstStop()
 {
-    if (comInstEventQueue[0]->empty()) {
+    Tick next = nextInstEventCount(0);
+    if (next == MaxTick) {
         setupInstCounter(0);
     } else {
-        const uint64_t next(comInstEventQueue[0]->nextTick());
-
         assert(next > ctrInsts);
         setupInstCounter(next - ctrInsts);
     }
index 24506fcebef649bfe1989906d5b72558941a1675..9317f61f4e37fe4ce7589718e88bb6029c5a917b 100644 (file)
@@ -870,7 +870,7 @@ Execute::doInstCommitAccounting(MinorDynInstPtr inst)
         cpu.system->totalNumInsts++;
 
         /* Act on events related to instruction counts */
-        cpu.comInstEventQueue[inst->id.threadId]->serviceEvents(thread->numInst);
+        cpu.serviceInstCountEvents(inst->id.threadId, thread->numInst);
     }
     thread->numOp++;
     thread->numOps++;
index 5871e65840be1f4b07966a97090f24766ae28cf2..e49d4997e6e6b32b6febe3fa57ecbc82eb1f6060 100644 (file)
@@ -1521,7 +1521,7 @@ FullO3CPU<Impl>::instDone(ThreadID tid, const DynInstPtr &inst)
         system->totalNumInsts++;
 
         // Check for instruction-count-based events.
-        comInstEventQueue[tid]->serviceEvents(thread[tid]->numInst);
+        serviceInstCountEvents(tid, thread[tid]->numInst);
     }
     thread[tid]->numOp++;
     thread[tid]->numOps++;
index 36d8297d1baa0698a5a5beebc12b9b8099c57128..586688600900f6598d41d40904d6531abb2004f2 100644 (file)
@@ -109,8 +109,8 @@ ElasticTrace::regProbeListeners()
     } else {
         // Schedule an event to register all elastic trace probes when
         // specified no. of instructions are committed.
-        cpu->comInstEventQueue[(ThreadID)0]->schedule(&regEtraceListenersEvent,
-                                                      startTraceInst);
+        cpu->scheduleInstCountEvent(
+                0, &regEtraceListenersEvent, startTraceInst);
     }
 }
 
index 248494b4076af7e711bcfa13ac83294bb0074a1e..fc07fedc0f634322af6f753e0e1616c46ed4c5e2 100644 (file)
@@ -500,7 +500,7 @@ BaseSimpleCPU::preExecute()
     t_info.setMemAccPredicate(true);
 
     // check for instruction-count-based events
-    comInstEventQueue[curThread]->serviceEvents(t_info.numInst);
+    serviceInstCountEvents(curThread, t_info.numInst);
 
     // decode the instruction
     inst = gtoh(inst);