kvm: Maintain a local instruction counter and update totalNumInsts
authorAndreas Sandberg <andreas@sandberg.pp.se>
Tue, 11 Jun 2013 07:24:40 +0000 (09:24 +0200)
committerAndreas Sandberg <andreas@sandberg.pp.se>
Tue, 11 Jun 2013 07:24:40 +0000 (09:24 +0200)
Update the system's totalNumInst counter when exiting from KVM and
maintain an internal absolute instruction count instead of relying on
the one from perf.

src/cpu/kvm/base.cc
src/cpu/kvm/base.hh

index a0aa511eaa09a607b4e65aec59ff730cd71210e7..6ffad82d76ca49054758e24e84707d6e993c6c91 100644 (file)
@@ -80,7 +80,8 @@ BaseKvmCPU::BaseKvmCPU(BaseKvmCPUParams *params)
       pageSize(sysconf(_SC_PAGE_SIZE)),
       tickEvent(*this),
       perfControlledByTimer(params->usePerfOverflow),
-      hostFactor(params->hostFactor)
+      hostFactor(params->hostFactor),
+      ctrInsts(0)
 {
     if (pageSize == -1)
         panic("KVM: Failed to determine host page size (%i)\n",
@@ -416,14 +417,14 @@ BaseKvmCPU::getContext(int tn)
 Counter
 BaseKvmCPU::totalInsts() const
 {
-    return hwInstructions.read();
+    return ctrInsts;
 }
 
 Counter
 BaseKvmCPU::totalOps() const
 {
     hack_once("Pretending totalOps is equivalent to totalInsts()\n");
-    return hwInstructions.read();
+    return ctrInsts;
 }
 
 void
@@ -522,6 +523,8 @@ BaseKvmCPU::kvmRun(Tick ticks)
     numCycles += simCyclesExecuted;;
     ++numVMExits;
     numInsts += instsExecuted;
+    ctrInsts += instsExecuted;
+    system->totalNumInsts += instsExecuted;
 
     DPRINTF(KvmRun, "KVM: Executed %i instructions in %i cycles (%i ticks, sim cycles: %i).\n",
             instsExecuted, hostCyclesExecuted, ticksExecuted, simCyclesExecuted);
index c53f715e36d269dc72417d15631fcb67627b6fcd..81b24a3786d4a630c5fecf2d013ea4c8ac095a79 100644 (file)
@@ -561,6 +561,9 @@ class BaseKvmCPU : public BaseCPU
     Stats::Scalar numInterrupts;
     Stats::Scalar numHypercalls;
     /* @} */
+
+    /** Number of instructions executed by the CPU */
+    Counter ctrInsts;
 };
 
 #endif