summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Sandberg <andreas@sandberg.pp.se>2013-06-11 09:18:25 +0200
committerAndreas Sandberg <andreas@sandberg.pp.se>2013-06-11 09:18:25 +0200
commit0793d0727bf13f3dc1f41ac24cab04f4ab1f6b2a (patch)
tree60a1e800d9fb1f7462c21708dc2eb096788e56af
parent247e4e9ab41bafcfcbde725bb40e6a7b5628f1de (diff)
downloadgem5-0793d0727bf13f3dc1f41ac24cab04f4ab1f6b2a.tar.xz
cpu: Add support for scheduling multiple inst/load stop events
Currently, the only way to get a CPU to stop after a fixed number of instructions/loads is to set a property on the CPU that causes a SimLoopExitEvent to be scheduled when the CPU is constructed. This is clearly not ideal in cases where the simulation script wants the CPU to stop at multiple instruction counts (e.g., SimPoint generation). This changeset adds the methods scheduleInstStop() and scheduleLoadStop() to the BaseCPU. These methods are exported to Python and are designed to be used from the simulation script. By using these methods instead of the old properties, a simulation script can schedule a stop at any point during simulation or schedule multiple stops. The number of instructions specified when scheduling a stop is relative to the current point of execution.
-rw-r--r--src/cpu/BaseCPU.py2
-rw-r--r--src/cpu/base.cc37
-rw-r--r--src/cpu/base.hh30
3 files changed, 57 insertions, 12 deletions
diff --git a/src/cpu/BaseCPU.py b/src/cpu/BaseCPU.py
index b98ddee6e..f52c6b11f 100644
--- a/src/cpu/BaseCPU.py
+++ b/src/cpu/BaseCPU.py
@@ -99,6 +99,8 @@ class BaseCPU(MemObject):
bool switchedOut();
void flushTLBs();
Counter totalInsts();
+ void scheduleInstStop(ThreadID tid, Counter insts, const char *cause);
+ void scheduleLoadStop(ThreadID tid, Counter loads, const char *cause);
''')
@classmethod
diff --git a/src/cpu/base.cc b/src/cpu/base.cc
index c7c1dadda..5b76f3f7c 100644
--- a/src/cpu/base.cc
+++ b/src/cpu/base.cc
@@ -147,10 +147,8 @@ BaseCPU::BaseCPU(Params *p, bool is_checker)
//
if (p->max_insts_any_thread != 0) {
const char *cause = "a thread reached the max instruction count";
- for (ThreadID tid = 0; tid < numThreads; ++tid) {
- Event *event = new SimLoopExitEvent(cause, 0);
- comInstEventQueue[tid]->schedule(event, p->max_insts_any_thread);
- }
+ for (ThreadID tid = 0; tid < numThreads; ++tid)
+ scheduleInstStop(tid, p->max_insts_any_thread, cause);
}
// Set up instruction-count-based termination events for SimPoints
@@ -159,10 +157,8 @@ BaseCPU::BaseCPU(Params *p, bool is_checker)
// 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) {
- Event *event = new SimLoopExitEvent(cause, 0);
- comInstEventQueue[0]->schedule(event, p->simpoint_start_insts[i]);
- }
+ 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) {
@@ -189,10 +185,8 @@ BaseCPU::BaseCPU(Params *p, bool is_checker)
//
if (p->max_loads_any_thread != 0) {
const char *cause = "a thread reached the max load count";
- for (ThreadID tid = 0; tid < numThreads; ++tid) {
- Event *event = new SimLoopExitEvent(cause, 0);
- comLoadEventQueue[tid]->schedule(event, p->max_loads_any_thread);
- }
+ for (ThreadID tid = 0; tid < numThreads; ++tid)
+ scheduleLoadStop(tid, p->max_loads_any_thread, cause);
}
if (p->max_loads_all_threads != 0) {
@@ -572,6 +566,25 @@ BaseCPU::unserialize(Checkpoint *cp, const std::string &section)
}
void
+BaseCPU::scheduleInstStop(ThreadID tid, Counter insts, const char *cause)
+{
+ const Tick now(comInstEventQueue[tid]->getCurTick());
+ Event *event(new SimLoopExitEvent(cause, 0));
+
+ comInstEventQueue[tid]->schedule(event, now + insts);
+}
+
+void
+BaseCPU::scheduleLoadStop(ThreadID tid, Counter loads, const char *cause)
+{
+ const Tick now(comLoadEventQueue[tid]->getCurTick());
+ Event *event(new SimLoopExitEvent(cause, 0));
+
+ comLoadEventQueue[tid]->schedule(event, now + loads);
+}
+
+
+void
BaseCPU::traceFunctionsInternal(Addr pc)
{
if (!debugSymbolTable)
diff --git a/src/cpu/base.hh b/src/cpu/base.hh
index 65f596132..0a3600764 100644
--- a/src/cpu/base.hh
+++ b/src/cpu/base.hh
@@ -395,6 +395,36 @@ class BaseCPU : public MemObject
virtual Counter totalOps() const = 0;
+ /**
+ * Schedule an event that exits the simulation loops after a
+ * predefined number of instructions.
+ *
+ * This method is usually called from the configuration script to
+ * get an exit event some time in the future. It is typically used
+ * when the script wants to simulate for a specific number of
+ * instructions rather than ticks.
+ *
+ * @param tid Thread monitor.
+ * @param insts Number of instructions into the future.
+ * @param cause Cause to signal in the exit event.
+ */
+ void scheduleInstStop(ThreadID tid, Counter insts, const char *cause);
+
+ /**
+ * Schedule an event that exits the simulation loops after a
+ * predefined number of load operations.
+ *
+ * This method is usually called from the configuration script to
+ * get an exit event some time in the future. It is typically used
+ * when the script wants to simulate for a specific number of
+ * loads rather than ticks.
+ *
+ * @param tid Thread monitor.
+ * @param loads Number of load instructions into the future.
+ * @param cause Cause to signal in the exit event.
+ */
+ void scheduleLoadStop(ThreadID tid, Counter loads, const char *cause);
+
// Function tracing
private:
bool functionTracingEnabled;