kvm: Add a stat counting number of instructions executed
authorAndreas Sandberg <andreas@sandberg.pp.se>
Thu, 2 May 2013 10:03:43 +0000 (12:03 +0200)
committerAndreas Sandberg <andreas@sandberg.pp.se>
Thu, 2 May 2013 10:03:43 +0000 (12:03 +0200)
This changeset adds a 'numInsts' stat to the KVM-based CPU. It also
cleans up the variable names in kvmRun to make the distinction between
host cycles and estimated simulated cycles clearer. As a bonus
feature, it also fixes a warning (unreferenced variable) when
compiling in fast mode.

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

index 510d6ae251261aef68f8eed499c8f0291e4aac38..f087b7b1afc3012ad8f3c377e491bb4a697ae464 100644 (file)
@@ -175,6 +175,11 @@ BaseKvmCPU::regStats()
 
     BaseCPU::regStats();
 
+    numInsts
+        .name(name() + ".committedInsts")
+        .desc("Number of instructions committed")
+        ;
+
     numVMExits
         .name(name() + ".numVMExits")
         .desc("total number of KVM exits")
@@ -485,8 +490,10 @@ BaseKvmCPU::kvmRun(Tick ticks)
         hwCycles.stop();
 
 
-    uint64_t cyclesExecuted(hwCycles.read() - baseCycles);
-    Tick ticksExecuted(runTimer->ticksFromHostCycles(cyclesExecuted));
+    const uint64_t hostCyclesExecuted(hwCycles.read() - baseCycles);
+    const uint64_t simCyclesExecuted(hostCyclesExecuted * hostFactor);
+    const uint64_t instsExecuted(hwInstructions.read() - baseInstrs);
+    const Tick ticksExecuted(runTimer->ticksFromHostCycles(hostCyclesExecuted));
 
     if (ticksExecuted < ticks &&
         timerOverflowed &&
@@ -496,14 +503,13 @@ BaseKvmCPU::kvmRun(Tick ticks)
              ticks, ticksExecuted);
     }
 
-    numCycles += cyclesExecuted * hostFactor;
+    /* Update statistics */
+    numCycles += simCyclesExecuted;;
     ++numVMExits;
+    numInsts += instsExecuted;
 
     DPRINTF(KvmRun, "KVM: Executed %i instructions in %i cycles (%i ticks, sim cycles: %i).\n",
-            hwInstructions.read() - baseInstrs,
-            cyclesExecuted,
-            ticksExecuted,
-            cyclesExecuted * hostFactor);
+            instsExecuted, hostCyclesExecuted, ticksExecuted, simCyclesExecuted);
 
     return ticksExecuted + flushCoalescedMMIO();
 }
index 0554f913e83c1c1b85f5bba8871a70b43079cf4d..f46455af60b3482d696ecb4c42ed31fd0639761d 100644 (file)
@@ -510,6 +510,7 @@ class BaseKvmCPU : public BaseCPU
 
   public:
     /* @{ */
+    Stats::Scalar numInsts;
     Stats::Scalar numVMExits;
     Stats::Scalar numMMIO;
     Stats::Scalar numCoalescedMMIO;