Fix the system clock at 1THz making 1 simulation tick = 1 ps
[gem5.git] / cpu / base.cc
index 8d97bc3309fe9ab92997e7241a2f385162ea561a..8b94b85332a7c2177ac3b750bc87adf22a9f9ad8 100644 (file)
@@ -36,6 +36,7 @@
 #include "base/output.hh"
 #include "cpu/base.hh"
 #include "cpu/exec_context.hh"
+#include "cpu/profile.hh"
 #include "cpu/sampler/sampler.hh"
 #include "sim/param.hh"
 #include "sim/sim_events.hh"
@@ -142,8 +143,19 @@ BaseCPU::BaseCPU(Params *p)
             e->schedule(p->functionTraceStart);
         }
     }
+#if FULL_SYSTEM
+    profileEvent = NULL;
+    if (params->profile)
+        profileEvent = new ProfileEvent(this, params->profile);
+#endif
 }
 
+BaseCPU::Params::Params()
+{
+#if FULL_SYSTEM
+    profile = false;
+#endif
+}
 
 void
 BaseCPU::enableFunctionTrace()
@@ -162,6 +174,16 @@ BaseCPU::init()
         registerExecContexts();
 }
 
+void
+BaseCPU::startup()
+{
+#if FULL_SYSTEM
+    if (!params->deferRegistration && profileEvent)
+        profileEvent->schedule(curTick);
+#endif
+}
+
+
 void
 BaseCPU::regStats()
 {
@@ -231,11 +253,33 @@ BaseCPU::takeOverFrom(BaseCPU *oldCPU)
     for (int i = 0; i < NumInterruptLevels; ++i)
         interrupts[i] = oldCPU->interrupts[i];
     intstatus = oldCPU->intstatus;
+
+    for (int i = 0; i < execContexts.size(); ++i)
+        if (execContexts[i]->profile)
+            execContexts[i]->profile->clear();
+
+    if (profileEvent)
+        profileEvent->schedule(curTick);
 #endif
 }
 
 
 #if FULL_SYSTEM
+BaseCPU::ProfileEvent::ProfileEvent(BaseCPU *_cpu, int _interval)
+    : Event(&mainEventQueue), cpu(_cpu), interval(_interval)
+{ }
+
+void
+BaseCPU::ProfileEvent::process()
+{
+    for (int i = 0, size = cpu->execContexts.size(); i < size; ++i) {
+        ExecContext *xc = cpu->execContexts[i];
+        xc->profile->sample(xc->profileNode, xc->profilePC);
+    }
+
+    schedule(curTick + interval);
+}
+
 void
 BaseCPU::post_interrupt(int int_num, int index)
 {