summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabe Black <gabeblack@google.com>2019-10-13 22:54:11 -0700
committerGabe Black <gabeblack@google.com>2019-10-25 22:42:31 +0000
commitfd030fd9f5893e1ce198bf760ab4a7f2704d921b (patch)
tree066536de5ae0448f78e101d0aecb7745c422ae9b /src
parentc73c19effd8f7f9b6e2ec470f04b8f1f43ce7354 (diff)
downloadgem5-fd030fd9f5893e1ce198bf760ab4a7f2704d921b.tar.xz
cpu: Delegate comInstEventQueue methods to the ThreadContexts.
These then just use the comInstEventQueue array from the CPU, but soon they will actually be self contained and allow the thread context to use whatever mechanism it wants. Also, now that the thread contexts need to exist before instruction count based events can be scheduled, setting up max instruction based events needs to happen in init after the CPU subclasses have had a chance to set up the threadContexts vector. Change-Id: I34bb401633d277a60be74e30d5a478a149b972ea Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/22108 Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com> Maintainer: Andreas Sandberg <andreas.sandberg@arm.com> Tested-by: kokoro <noreply+kokoro@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/cpu/base.cc72
-rw-r--r--src/cpu/base.hh9
-rw-r--r--src/cpu/thread_context.cc35
-rw-r--r--src/cpu/thread_context.hh6
4 files changed, 79 insertions, 43 deletions
diff --git a/src/cpu/base.cc b/src/cpu/base.cc
index a4ffb1031..7040cb7ea 100644
--- a/src/cpu/base.cc
+++ b/src/cpu/base.cc
@@ -162,43 +162,6 @@ BaseCPU::BaseCPU(Params *p, bool is_checker)
comInstEventQueue[tid] =
new EventQueue("instruction-based event queue");
- //
- // set up instruction-count-based termination events, if any
- //
- if (p->max_insts_any_thread != 0) {
- const char *cause = "a thread reached the max instruction count";
- for (ThreadID tid = 0; tid < numThreads; ++tid)
- scheduleInstStop(tid, p->max_insts_any_thread, cause);
- }
-
- // Set up instruction-count-based termination events for SimPoints
- // Typically, there are more than one action points.
- // Simulation.py is responsible to take the necessary actions upon
- // exitting the simulation loop.
- if (!p->simpoint_start_insts.empty()) {
- const char *cause = "simpoint starting point found";
- for (size_t i = 0; i < p->simpoint_start_insts.size(); ++i)
- scheduleInstStop(0, p->simpoint_start_insts[i], cause);
- }
-
- if (p->max_insts_all_threads != 0) {
- const char *cause = "all threads reached the max instruction count";
-
- // allocate & initialize shared downcounter: each event will
- // decrement this when triggered; simulation will terminate
- // when counter reaches 0
- int *counter = new int;
- *counter = numThreads;
- for (ThreadID tid = 0; tid < numThreads; ++tid) {
- Event *event = new CountedExitEvent(cause, *counter);
- scheduleInstCountEvent(tid, event, p->max_insts_all_threads);
- }
- }
-
- //
- // set up instruction-count-based termination events, if any
- //
-
functionTracingEnabled = false;
if (p->function_trace) {
const string fname = csprintf("ftrace.%s", name());
@@ -323,6 +286,39 @@ BaseCPU::mwaitAtomic(ThreadID tid, ThreadContext *tc, BaseTLB *dtb)
void
BaseCPU::init()
{
+ // Set up instruction-count-based termination events, if any. This needs
+ // to happen after threadContexts has been constructed.
+ if (params()->max_insts_any_thread != 0) {
+ const char *cause = "a thread reached the max instruction count";
+ for (ThreadID tid = 0; tid < numThreads; ++tid)
+ scheduleInstStop(tid, params()->max_insts_any_thread, cause);
+ }
+
+ // Set up instruction-count-based termination events for SimPoints
+ // Typically, there are more than one action points.
+ // Simulation.py is responsible to take the necessary actions upon
+ // exitting the simulation loop.
+ if (!params()->simpoint_start_insts.empty()) {
+ const char *cause = "simpoint starting point found";
+ for (size_t i = 0; i < params()->simpoint_start_insts.size(); ++i)
+ scheduleInstStop(0, params()->simpoint_start_insts[i], cause);
+ }
+
+ if (params()->max_insts_all_threads != 0) {
+ const char *cause = "all threads reached the max instruction count";
+
+ // allocate & initialize shared downcounter: each event will
+ // decrement this when triggered; simulation will terminate
+ // when counter reaches 0
+ int *counter = new int;
+ *counter = numThreads;
+ for (ThreadID tid = 0; tid < numThreads; ++tid) {
+ Event *event = new CountedExitEvent(cause, *counter);
+ scheduleInstCountEvent(
+ tid, event, params()->max_insts_all_threads);
+ }
+ }
+
if (!params()->switched_out) {
registerThreadContexts();
@@ -735,7 +731,7 @@ BaseCPU::scheduleInstStop(ThreadID tid, Counter insts, const char *cause)
Tick
BaseCPU::getCurrentInstCount(ThreadID tid)
{
- return comInstEventQueue[tid]->getCurTick();
+ return threadContexts[tid]->getCurrentInstCount();
}
AddressMonitor::AddressMonitor() {
diff --git a/src/cpu/base.hh b/src/cpu/base.hh
index 0424945cb..d73f4a2d5 100644
--- a/src/cpu/base.hh
+++ b/src/cpu/base.hh
@@ -468,26 +468,25 @@ class BaseCPU : public ClockedObject
Tick
nextInstEventCount(ThreadID tid)
{
- return comInstEventQueue[tid]->empty() ?
- MaxTick : comInstEventQueue[tid]->nextTick();
+ return threadContexts[tid]->nextInstEventCount();
}
void
serviceInstCountEvents(ThreadID tid, Tick count)
{
- comInstEventQueue[tid]->serviceEvents(count);
+ threadContexts[tid]->serviceInstCountEvents(count);
}
void
scheduleInstCountEvent(ThreadID tid, Event *event, Tick count)
{
- comInstEventQueue[tid]->schedule(event, count);
+ threadContexts[tid]->scheduleInstCountEvent(event, count);
}
void
descheduleInstCountEvent(ThreadID tid, Event *event)
{
- comInstEventQueue[tid]->deschedule(event);
+ threadContexts[tid]->descheduleInstCountEvent(event);
}
public:
diff --git a/src/cpu/thread_context.cc b/src/cpu/thread_context.cc
index dea39015f..1250a3e4c 100644
--- a/src/cpu/thread_context.cc
+++ b/src/cpu/thread_context.cc
@@ -55,6 +55,41 @@
#include "params/BaseCPU.hh"
#include "sim/full_system.hh"
+Tick
+ThreadContext::nextInstEventCount()
+{
+ auto *queue = getCpuPtr()->comInstEventQueue[threadId()];
+ return queue->empty() ? MaxTick : queue->nextTick();
+}
+
+void
+ThreadContext::serviceInstCountEvents(Tick count)
+{
+ auto *queue = getCpuPtr()->comInstEventQueue[threadId()];
+ queue->serviceEvents(count);
+}
+
+void
+ThreadContext::scheduleInstCountEvent(Event *event, Tick count)
+{
+ auto *queue = getCpuPtr()->comInstEventQueue[threadId()];
+ return queue->schedule(event, count);
+}
+
+void
+ThreadContext::descheduleInstCountEvent(Event *event)
+{
+ auto *queue = getCpuPtr()->comInstEventQueue[threadId()];
+ queue->deschedule(event);
+}
+
+Tick
+ThreadContext::getCurrentInstCount()
+{
+ auto *queue = getCpuPtr()->comInstEventQueue[threadId()];
+ return queue->getCurTick();
+}
+
void
ThreadContext::compare(ThreadContext *one, ThreadContext *two)
{
diff --git a/src/cpu/thread_context.hh b/src/cpu/thread_context.hh
index 749b4ca90..a6793a263 100644
--- a/src/cpu/thread_context.hh
+++ b/src/cpu/thread_context.hh
@@ -192,6 +192,12 @@ class ThreadContext : public PCEventScope
virtual EndQuiesceEvent *getQuiesceEvent() = 0;
+ virtual Tick nextInstEventCount();
+ virtual void serviceInstCountEvents(Tick count);
+ virtual void scheduleInstCountEvent(Event *event, Tick count);
+ virtual void descheduleInstCountEvent(Event *event);
+ virtual Tick getCurrentInstCount();
+
// Not necessarily the best location for these...
// Having an extra function just to read these is obnoxious
virtual Tick readLastActivate() = 0;