cpu-kvm: convert kvm base to new style stats
authoreavivi <eavivi@ucdavis.edu>
Mon, 31 Aug 2020 20:45:53 +0000 (13:45 -0700)
committerEden Avivi <eavivi@ucdavis.edu>
Thu, 3 Sep 2020 01:03:17 +0000 (01:03 +0000)
Change-Id: Iab2e99720cf9ac58edfcbdcedc944264eb12b7e1
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/33796
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
Maintainer: Jason Lowe-Power <power.jg@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
src/cpu/kvm/base.cc
src/cpu/kvm/base.hh

index 0afab1e8415f1e563abf0e7fee30ffb13ca09882..5e3ffd723ec2b31ed0cde5c0713b1603c1d6c729 100644 (file)
@@ -75,7 +75,7 @@ BaseKvmCPU::BaseKvmCPU(BaseKvmCPUParams *params)
                 false, Event::CPU_Tick_Pri),
       activeInstPeriod(0),
       perfControlledByTimer(params->usePerfOverflow),
-      hostFactor(params->hostFactor),
+      hostFactor(params->hostFactor), stats(this),
       ctrInsts(0)
 {
     if (pageSize == -1)
@@ -258,62 +258,22 @@ BaseKvmCPU::startupThread()
 
 }
 
-void
-BaseKvmCPU::regStats()
+BaseKvmCPU::StatGroup::StatGroup(Stats::Group *parent)
+    : Stats::Group(parent),
+    ADD_STAT(committedInsts, "Number of instructions committed"),
+    ADD_STAT(numVMExits, "total number of KVM exits"),
+    ADD_STAT(numVMHalfEntries,
+     "number of KVM entries to finalize pending operations"),
+    ADD_STAT(numExitSignal, "exits due to signal delivery"),
+    ADD_STAT(numMMIO, "number of VM exits due to memory mapped IO"),
+    ADD_STAT(numCoalescedMMIO,
+     "number of coalesced memory mapped IO requests"),
+    ADD_STAT(numIO, "number of VM exits due to legacy IO"),
+    ADD_STAT(numHalt,
+     "number of VM exits due to wait for interrupt instructions"),
+    ADD_STAT(numInterrupts, "number of interrupts delivered"),
+    ADD_STAT(numHypercalls, "number of hypercalls")
 {
-    using namespace Stats;
-
-    BaseCPU::regStats();
-
-    numInsts
-        .name(name() + ".committedInsts")
-        .desc("Number of instructions committed")
-        ;
-
-    numVMExits
-        .name(name() + ".numVMExits")
-        .desc("total number of KVM exits")
-        ;
-
-    numVMHalfEntries
-        .name(name() + ".numVMHalfEntries")
-        .desc("number of KVM entries to finalize pending operations")
-        ;
-
-    numExitSignal
-        .name(name() + ".numExitSignal")
-        .desc("exits due to signal delivery")
-        ;
-
-    numMMIO
-        .name(name() + ".numMMIO")
-        .desc("number of VM exits due to memory mapped IO")
-        ;
-
-    numCoalescedMMIO
-        .name(name() + ".numCoalescedMMIO")
-        .desc("number of coalesced memory mapped IO requests")
-        ;
-
-    numIO
-        .name(name() + ".numIO")
-        .desc("number of VM exits due to legacy IO")
-        ;
-
-    numHalt
-        .name(name() + ".numHalt")
-        .desc("number of VM exits due to wait for interrupt instructions")
-        ;
-
-    numInterrupts
-        .name(name() + ".numInterrupts")
-        .desc("number of interrupts delivered")
-        ;
-
-    numHypercalls
-        .name(name() + ".numHypercalls")
-        .desc("number of hypercalls")
-        ;
 }
 
 void
@@ -672,7 +632,7 @@ BaseKvmCPU::tick()
           if (_kvmRun->exit_reason !=  KVM_EXIT_INTR) {
               _status = RunningService;
           } else {
-              ++numExitSignal;
+              ++stats.numExitSignal;
               _status = Running;
           }
 
@@ -735,7 +695,7 @@ BaseKvmCPU::kvmRun(Tick ticks)
         // then immediately exits.
         DPRINTF(KvmRun, "KVM: Delivering IO without full guest entry\n");
 
-        ++numVMHalfEntries;
+        ++stats.numVMHalfEntries;
 
         // Send a KVM_KICK_SIGNAL to the vCPU thread (i.e., this
         // thread). The KVM control signal is masked while executing
@@ -803,7 +763,7 @@ BaseKvmCPU::kvmRun(Tick ticks)
 
         /* Update statistics */
         numCycles += simCyclesExecuted;;
-        numInsts += instsExecuted;
+        stats.committedInsts += instsExecuted;
         ctrInsts += instsExecuted;
         system->totalNumInsts += instsExecuted;
 
@@ -813,7 +773,7 @@ BaseKvmCPU::kvmRun(Tick ticks)
                 instsExecuted, hostCyclesExecuted, ticksExecuted, simCyclesExecuted);
     }
 
-    ++numVMExits;
+    ++stats.numVMExits;
 
     return ticksExecuted + flushCoalescedMMIO();
 }
@@ -821,7 +781,7 @@ BaseKvmCPU::kvmRun(Tick ticks)
 void
 BaseKvmCPU::kvmNonMaskableInterrupt()
 {
-    ++numInterrupts;
+    ++stats.numInterrupts;
     if (ioctl(KVM_NMI) == -1)
         panic("KVM: Failed to deliver NMI to virtual CPU\n");
 }
@@ -829,7 +789,7 @@ BaseKvmCPU::kvmNonMaskableInterrupt()
 void
 BaseKvmCPU::kvmInterrupt(const struct kvm_interrupt &interrupt)
 {
-    ++numInterrupts;
+    ++stats.numInterrupts;
     if (ioctl(KVM_INTERRUPT, (void *)&interrupt) == -1)
         panic("KVM: Failed to deliver interrupt to virtual CPU\n");
 }
@@ -1000,20 +960,20 @@ BaseKvmCPU::handleKvmExit()
 
       case KVM_EXIT_IO:
       {
-        ++numIO;
+        ++stats.numIO;
         Tick ticks = handleKvmExitIO();
         _status = dataPort.nextIOState();
         return ticks;
       }
 
       case KVM_EXIT_HYPERCALL:
-        ++numHypercalls;
+        ++stats.numHypercalls;
         return handleKvmExitHypercall();
 
       case KVM_EXIT_HLT:
         /* The guest has halted and is waiting for interrupts */
         DPRINTF(Kvm, "handleKvmExitHalt\n");
-        ++numHalt;
+        ++stats.numHalt;
 
         // Suspend the thread until the next interrupt arrives
         thread->suspend();
@@ -1028,7 +988,7 @@ BaseKvmCPU::handleKvmExit()
                 _kvmRun->mmio.is_write,
                 _kvmRun->mmio.phys_addr, _kvmRun->mmio.len);
 
-        ++numMMIO;
+        ++stats.numMMIO;
         Tick ticks = doMMIOAccess(_kvmRun->mmio.phys_addr, _kvmRun->mmio.data,
                                   _kvmRun->mmio.len, _kvmRun->mmio.is_write);
         // doMMIOAccess could have triggered a suspend, in which case we don't
@@ -1195,7 +1155,7 @@ BaseKvmCPU::flushCoalescedMMIO()
         DPRINTF(KvmIO, "KVM: Handling coalesced MMIO (addr: 0x%x, len: %u)\n",
                 ent.phys_addr, ent.len);
 
-        ++numCoalescedMMIO;
+        ++stats.numCoalescedMMIO;
         ticks += doMMIOAccess(ent.phys_addr, ent.data, ent.len, true);
 
         mmioRing->first = (mmioRing->first + 1) % KVM_COALESCED_MMIO_MAX;
index e999499caa28bc1d0100c4b6e26a25592f803ba2..73465af378f2886df5029ee4776c8815e83562af 100644 (file)
@@ -82,7 +82,6 @@ class BaseKvmCPU : public BaseCPU
 
     void init() override;
     void startup() override;
-    void regStats() override;
 
     void serializeThread(CheckpointOut &cp, ThreadID tid) const override;
     void unserializeThread(CheckpointIn &cp, ThreadID tid) override;
@@ -782,16 +781,19 @@ class BaseKvmCPU : public BaseCPU
 
   public:
     /* @{ */
-    Stats::Scalar numInsts;
-    Stats::Scalar numVMExits;
-    Stats::Scalar numVMHalfEntries;
-    Stats::Scalar numExitSignal;
-    Stats::Scalar numMMIO;
-    Stats::Scalar numCoalescedMMIO;
-    Stats::Scalar numIO;
-    Stats::Scalar numHalt;
-    Stats::Scalar numInterrupts;
-    Stats::Scalar numHypercalls;
+    struct StatGroup : public Stats::Group {
+        StatGroup(Stats::Group *parent);
+        Stats::Scalar committedInsts;
+        Stats::Scalar numVMExits;
+        Stats::Scalar numVMHalfEntries;
+        Stats::Scalar numExitSignal;
+        Stats::Scalar numMMIO;
+        Stats::Scalar numCoalescedMMIO;
+        Stats::Scalar numIO;
+        Stats::Scalar numHalt;
+        Stats::Scalar numInterrupts;
+        Stats::Scalar numHypercalls;
+    } stats;
     /* @} */
 
     /** Number of instructions executed by the CPU */