Formatting & doxygen docs for new syscall emulation code.
[gem5.git] / cpu / simple_cpu / simple_cpu.cc
index 3179b7b1f420c30a70b8dfc1b7bbaba3a22fd8bc..476f28ea003aea0d207c1ce9f43a959bb7c0e3a5 100644 (file)
 #else // !FULL_SYSTEM
 #include "eio/eio.hh"
 #include "mem/functional_mem/functional_memory.hh"
-#include "sim/prog.hh"
 #endif // FULL_SYSTEM
 
 using namespace std;
 
 SimpleCPU::TickEvent::TickEvent(SimpleCPU *c)
-    : Event(&mainEventQueue, "SimpleCPU::TickEvent", 100), cpu(c)
+    : Event(&mainEventQueue, 100), cpu(c)
 {
 }
 
@@ -94,7 +93,7 @@ SimpleCPU::TickEvent::description()
 
 
 SimpleCPU::CacheCompletionEvent::CacheCompletionEvent(SimpleCPU *_cpu)
-    : Event(&mainEventQueue, "SimpleCPU::CacheCompletionEvent"),
+    : Event(&mainEventQueue),
       cpu(_cpu)
 {
 }
@@ -159,8 +158,9 @@ SimpleCPU::SimpleCPU(const string &_name, Process *_process,
     memReq->data = new uint8_t[64];
 
     numInst = 0;
+    startNumInst = 0;
     numLoad = 0;
-    last_idle = 0;
+    startNumLoad = 0;
     lastIcacheStall = 0;
     lastDcacheStall = 0;
 
@@ -171,7 +171,6 @@ SimpleCPU::~SimpleCPU()
 {
 }
 
-
 void
 SimpleCPU::switchOut()
 {
@@ -217,6 +216,8 @@ SimpleCPU::execCtxStatusChg(int thread_num) {
 void
 SimpleCPU::regStats()
 {
+    using namespace Statistics;
+
     BaseCPU::regStats();
 
     numInsts
@@ -229,11 +230,6 @@ SimpleCPU::regStats()
         .desc("Number of memory references")
         ;
 
-    idleCycles
-        .name(name() + ".idle_cycles")
-        .desc("Number of idle cycles")
-        ;
-
     idleFraction
         .name(name() + ".idle_fraction")
         .desc("Percentage of idle cycles")
@@ -251,17 +247,22 @@ SimpleCPU::regStats()
         .prereq(dcacheStallCycles)
         ;
 
-    idleFraction = idleCycles / simTicks;
-
-    numInsts = Statistics::scalar(numInst);
+    numInsts = Statistics::scalar(numInst) - Statistics::scalar(startNumInst);
     simInsts += numInsts;
 }
 
+void
+SimpleCPU::resetStats()
+{
+    startNumInst = numInst;
+}
+
 void
 SimpleCPU::serialize(ostream &os)
 {
     SERIALIZE_ENUM(_status);
     SERIALIZE_SCALAR(inst);
+    nameOut(os, csprintf("%s.xc", name()));
     xc->serialize(os);
     nameOut(os, csprintf("%s.tickEvent", name()));
     tickEvent.serialize(os);
@@ -270,14 +271,14 @@ SimpleCPU::serialize(ostream &os)
 }
 
 void
-SimpleCPU::unserialize(const IniFile *db, const string &section)
+SimpleCPU::unserialize(Checkpoint *cp, const string &section)
 {
     UNSERIALIZE_ENUM(_status);
     UNSERIALIZE_SCALAR(inst);
-    xc->unserialize(db, section);
-    tickEvent.unserialize(db, csprintf("%s.tickEvent", name()));
+    xc->unserialize(cp, csprintf("%s.xc", section));
+    tickEvent.unserialize(cp, csprintf("%s.tickEvent", section));
     cacheCompletionEvent
-        .unserialize(db, csprintf("%s.cacheCompletionEvent", name()));
+        .unserialize(cp, csprintf("%s.cacheCompletionEvent", section));
 }
 
 void
@@ -626,7 +627,32 @@ SimpleCPU::tick()
         xc->func_exe_insn++;
 
         fault = si->execute(this, xc, traceData);
-
+#ifdef FS_MEASURE
+        if (!(xc->misspeculating()) && (xc->system->bin)) {
+            SWContext *ctx = xc->swCtx;
+            if (ctx && !ctx->callStack.empty()) {
+                if (si->isCall()) {
+                    ctx->calls++;
+                }
+                if (si->isReturn()) {
+                     if (ctx->calls == 0) {
+                        fnCall *top = ctx->callStack.top();
+                        DPRINTF(TCPIP, "Removing %s from callstack.\n", top->name);
+                        delete top;
+                        ctx->callStack.pop();
+                        if (ctx->callStack.empty())
+                            xc->system->nonPath->activate();
+                        else
+                            ctx->callStack.top()->myBin->activate();
+
+                        xc->system->dumpState(xc);
+                    } else {
+                        ctx->calls--;
+                    }
+                }
+            }
+        }
+#endif
         if (si->isMemRef()) {
             numMemRefs++;
         }