arch: cpu: Track kernel stats using the base ISA agnostic type.
authorGabe Black <gabeblack@google.com>
Sun, 28 Apr 2019 02:51:20 +0000 (19:51 -0700)
committerGabe Black <gabeblack@google.com>
Tue, 30 Apr 2019 03:49:40 +0000 (03:49 +0000)
Then cast to the ISA specific type when necessary. This removes
(mostly) an ISA specific aspect to some of the interfaces. The ISA
specific version of the kernel stats still needs to be constructed and
stored in a few places which means that kernel_stats.hh still needs to
be a switching arch header, for instance.

In the future, I'd like to make the kernel its own object like the
Process objects in SE mode, and then it would be able to instantiate
and maintain its own stats.

Change-Id: I8309d49019124f6bea1482aaea5b5b34e8c97433
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/18429
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>

15 files changed:
src/arch/alpha/ev5.cc
src/arch/alpha/idle_event.cc
src/cpu/checker/cpu.cc
src/cpu/checker/thread_context.hh
src/cpu/o3/cpu.cc
src/cpu/o3/regfile.hh
src/cpu/o3/thread_context.hh
src/cpu/simple/base.cc
src/cpu/simple_thread.hh
src/cpu/thread_context.cc
src/cpu/thread_context.hh
src/cpu/thread_state.cc
src/cpu/thread_state.hh
src/kern/kernel_stats.hh
src/sim/pseudo_inst.cc

index bac8e8d48aa1241eb23294fa785788d01b73628d..e3e025e2f89a7ba289fe32e92c8c58b747e7a066 100644 (file)
@@ -219,6 +219,9 @@ int break_ipl = -1;
 void
 ISA::setIpr(int idx, uint64_t val, ThreadContext *tc)
 {
+    auto *stats = dynamic_cast<AlphaISA::Kernel::Statistics *>(
+            tc->getKernelStats());
+    assert(stats || !tc->getKernelStats());
     switch (idx) {
       case IPR_PALtemp0:
       case IPR_PALtemp1:
@@ -267,8 +270,8 @@ ISA::setIpr(int idx, uint64_t val, ThreadContext *tc)
 
       case IPR_PALtemp23:
         // write entire quad w/ no side-effect
-        if (tc->getKernelStats())
-            tc->getKernelStats()->context(ipr[idx], val, tc);
+        if (stats)
+            stats->context(ipr[idx], val, tc);
         ipr[idx] = val;
         break;
 
@@ -291,17 +294,17 @@ ISA::setIpr(int idx, uint64_t val, ThreadContext *tc)
       case IPR_IPLR:
         // only write least significant five bits - interrupt level
         ipr[idx] = val & 0x1f;
-        if (tc->getKernelStats())
-            tc->getKernelStats()->swpipl(ipr[idx]);
+        if (stats)
+            stats->swpipl(ipr[idx]);
         break;
 
       case IPR_DTB_CM:
         if (val & 0x18) {
-            if (tc->getKernelStats())
-                tc->getKernelStats()->mode(Kernel::user, tc);
+            if (stats)
+                stats->mode(Kernel::user, tc);
         } else {
-            if (tc->getKernelStats())
-                tc->getKernelStats()->mode(Kernel::kernel, tc);
+            if (stats)
+                stats->mode(Kernel::kernel, tc);
         }
         M5_FALLTHROUGH;
 
@@ -485,6 +488,9 @@ using namespace AlphaISA;
 Fault
 SimpleThread::hwrei()
 {
+    auto *stats = dynamic_cast<AlphaISA::Kernel::Statistics *>(kernelStats);
+    assert(stats || !kernelStats);
+
     PCState pc = pcState();
     if (!(pc.pc() & 0x3))
         return std::make_shared<UnimplementedOpcodeFault>();
@@ -494,8 +500,8 @@ SimpleThread::hwrei()
 
     CPA::cpa()->swAutoBegin(this, pc.npc());
 
-    if (kernelStats)
-        kernelStats->hwrei();
+    if (stats)
+        stats->hwrei();
 
     // FIXME: XXX check for interrupts? XXX
     return NoFault;
@@ -508,8 +514,11 @@ SimpleThread::hwrei()
 bool
 SimpleThread::simPalCheck(int palFunc)
 {
-    if (kernelStats)
-        kernelStats->callpal(palFunc, this);
+    auto *stats = dynamic_cast<AlphaISA::Kernel::Statistics *>(kernelStats);
+    assert(stats || !kernelStats);
+
+    if (stats)
+        stats->callpal(palFunc, this);
 
     switch (palFunc) {
       case PAL::halt:
index 080dcb22c7d31bd94c8a0f4ea835765667c934bf..df8a0c6619fa4d3975cd234a05d563502dcc9375 100644 (file)
@@ -41,7 +41,10 @@ IdleStartEvent::process(ThreadContext *tc)
 {
     if (tc->getKernelStats()) {
         RegVal val = tc->readMiscRegNoEffect(IPR_PALtemp23);
-        tc->getKernelStats()->setIdleProcess(val, tc);
+        auto *stats = dynamic_cast<AlphaISA::Kernel::Statistics *>(
+                tc->getKernelStats());
+        assert(stats);
+        stats->setIdleProcess(val, tc);
     }
     remove();
 }
index fe1c3d44097a6095441c7e05489307ce8a8d8e3c..7f8eada4c4d5330c8be614d93c15422a1b6a0cae 100644 (file)
@@ -47,7 +47,6 @@
 #include <string>
 
 #include "arch/generic/tlb.hh"
-#include "arch/kernel_stats.hh"
 #include "arch/vtophys.hh"
 #include "cpu/base.hh"
 #include "cpu/simple_thread.hh"
index 26973cdbfb4cbf9c3dae473614dce8bdca2fa440..ed8add66244b2a90f124c72c5bb23a0fa983d1fa 100644 (file)
 #include "debug/Checker.hh"
 
 class EndQuiesceEvent;
+namespace Kernel {
+    class Statistics;
+};
 namespace TheISA {
-    namespace Kernel {
-        class Statistics;
-    };
     class Decoder;
 };
 
@@ -134,7 +134,7 @@ class CheckerThreadContext : public ThreadContext
 
     System *getSystemPtr() override { return actualTC->getSystemPtr(); }
 
-    TheISA::Kernel::Statistics *
+    ::Kernel::Statistics *
     getKernelStats() override
     {
         return actualTC->getKernelStats();
index 621a6a409be41a90de7cc94b2ce6cb64b6ec6010..70417d51f821d6319947cdfab2d99bd5c38c8bd8 100644 (file)
@@ -925,7 +925,10 @@ FullO3CPU<Impl>::hwrei(ThreadID tid)
     // Need to clear the lock flag upon returning from an interrupt.
     this->setMiscRegNoEffect(AlphaISA::MISCREG_LOCKFLAG, false, tid);
 
-    this->thread[tid]->kernelStats->hwrei();
+    auto *stats = dynamic_cast<AlphaISA::Kernel::Statistics *>(
+            this->thread[tid]->kernelStats);
+    assert(stats);
+    stats->hwrei();
 
     // FIXME: XXX check for interrupts? XXX
 #endif
@@ -937,9 +940,10 @@ bool
 FullO3CPU<Impl>::simPalCheck(int palFunc, ThreadID tid)
 {
 #if THE_ISA == ALPHA_ISA
-    if (this->thread[tid]->kernelStats)
-        this->thread[tid]->kernelStats->callpal(palFunc,
-                                                this->threadContexts[tid]);
+    auto *stats = dynamic_cast<AlphaISA::Kernel::Statistics *>(
+            this->thread[tid]->kernelStats);
+    if (stats)
+        stats->callpal(palFunc, this->threadContexts[tid]);
 
     switch (palFunc) {
       case PAL::halt:
index d2fcd0749a41635b9af34eb43541563db7392e88..d4b6602ad173140f1a0cdd8232671e894021edb6 100644 (file)
@@ -48,7 +48,6 @@
 #include <vector>
 
 #include "arch/isa_traits.hh"
-#include "arch/kernel_stats.hh"
 #include "arch/types.hh"
 #include "base/trace.hh"
 #include "config/the_isa.hh"
index b87aac4a759916027b35bcf41c0c4d90a56d8d9d..e5f01871bd861f1f672652caddac8e7e27281358 100644 (file)
@@ -119,7 +119,7 @@ class O3ThreadContext : public ThreadContext
     System *getSystemPtr() override { return cpu->system; }
 
     /** Returns a pointer to this thread's kernel statistics. */
-    TheISA::Kernel::Statistics *
+    ::Kernel::Statistics *
     getKernelStats() override
     {
         return thread->kernelStats;
index b687a17e05cb10231abe22a00785d4ec36dd3f85..298ba9f9e9cf4e76399fe737d240ef0fd41da55c 100644 (file)
@@ -43,7 +43,6 @@
 
 #include "cpu/simple/base.hh"
 
-#include "arch/kernel_stats.hh"
 #include "arch/stacktrace.hh"
 #include "arch/utility.hh"
 #include "arch/vtophys.hh"
index 0d415dc161af8e4948a51fef1b5f988f8a54c997..33f0bbd8a20fa6d5664631bf5bb683f8b7584f9a 100644 (file)
@@ -74,10 +74,8 @@ class CheckerCPU;
 class FunctionProfile;
 class ProfileNode;
 
-namespace TheISA {
-    namespace Kernel {
-        class Statistics;
-    }
+namespace Kernel {
+    class Statistics;
 }
 
 /**
@@ -212,7 +210,7 @@ class SimpleThread : public ThreadState, public ThreadContext
 
     System *getSystemPtr() override { return system; }
 
-    TheISA::Kernel::Statistics *
+    Kernel::Statistics *
     getKernelStats() override
     {
         return ThreadState::getKernelStats();
index 35d96a4e7cfc2dad70eaffa7e2aacc5f5be3cc7c..dea39015f107942eb3aecc612f02bc0401a35db0 100644 (file)
@@ -44,7 +44,6 @@
 #include "cpu/thread_context.hh"
 
 #include "arch/generic/vec_pred_reg.hh"
-#include "arch/kernel_stats.hh"
 #include "base/logging.hh"
 #include "base/trace.hh"
 #include "config/the_isa.hh"
@@ -52,6 +51,7 @@
 #include "cpu/quiesce_event.hh"
 #include "debug/Context.hh"
 #include "debug/Quiesce.hh"
+#include "kern/kernel_stats.hh"
 #include "params/BaseCPU.hh"
 #include "sim/full_system.hh"
 
@@ -139,7 +139,7 @@ ThreadContext::quiesce()
 
     suspend();
     if (getKernelStats())
-       getKernelStats()->quiesce();
+        getKernelStats()->quiesce();
 }
 
 
index 00e97b23c2280370b5900d19282369dcccf1757a..bdf5a008662d00345d315b4109e8c99518ae8958 100644 (file)
@@ -70,10 +70,8 @@ class FSTranslatingPortProxy;
 class PortProxy;
 class Process;
 class System;
-namespace TheISA {
-    namespace Kernel {
-        class Statistics;
-    }
+namespace Kernel {
+    class Statistics;
 }
 
 /**
@@ -150,7 +148,7 @@ class ThreadContext
 
     virtual System *getSystemPtr() = 0;
 
-    virtual TheISA::Kernel::Statistics *getKernelStats() = 0;
+    virtual ::Kernel::Statistics *getKernelStats() = 0;
 
     virtual PortProxy &getPhysProxy() = 0;
 
index 92be17977ea82fab873035e002f9a0c3c4f7d3c0..acb297113fe034c90305c9992738eea495bc8c74 100644 (file)
 
 #include "cpu/thread_state.hh"
 
-#include "arch/kernel_stats.hh"
 #include "base/output.hh"
 #include "cpu/base.hh"
 #include "cpu/profile.hh"
 #include "cpu/quiesce_event.hh"
+#include "kern/kernel_stats.hh"
 #include "mem/fs_translating_port_proxy.hh"
 #include "mem/port.hh"
 #include "mem/port_proxy.hh"
index 574193d0ef24ff2494d6d5df680958f8914675b7..2006339221242f543646b858044819dcb3456a14 100644 (file)
 class EndQuiesceEvent;
 class FunctionProfile;
 class ProfileNode;
-namespace TheISA {
-    namespace Kernel {
-        class Statistics;
-    }
+namespace Kernel {
+    class Statistics;
 }
 
 class Checkpoint;
@@ -98,7 +96,7 @@ struct ThreadState : public Serializable {
 
     void profileSample();
 
-    TheISA::Kernel::Statistics *getKernelStats() { return kernelStats; }
+    Kernel::Statistics *getKernelStats() { return kernelStats; }
 
     PortProxy &getPhysProxy();
 
@@ -185,7 +183,7 @@ struct ThreadState : public Serializable {
     Addr profilePC;
     EndQuiesceEvent *quiesceEvent;
 
-    TheISA::Kernel::Statistics *kernelStats;
+    Kernel::Statistics *kernelStats;
 
   protected:
     Process *process;
index 41071ce08c4fa8ade0ecf117fa81ac7e4efd105a..37dbb9f1538c44871a5dd3713ed11597223fe9e3 100644 (file)
@@ -53,7 +53,7 @@ class Statistics : public Serializable
     virtual ~Statistics() {}
 
     const std::string name() const { return myname; }
-    void regStats(const std::string &name);
+    virtual void regStats(const std::string &name);
 
   public:
     void arm() { _arm++; }
index dc37a8c717cca10b898eaa38e2aef5b553761484..8ffb13e3b33025653c3cf58f7a0b333c901a3271 100644 (file)
@@ -53,7 +53,6 @@
 
 #include <gem5/asm/generic/m5ops.h>
 
-#include "arch/kernel_stats.hh"
 #include "arch/pseudo_inst.hh"
 #include "arch/utility.hh"
 #include "arch/vtophys.hh"
@@ -68,6 +67,7 @@
 #include "debug/Quiesce.hh"
 #include "debug/WorkItems.hh"
 #include "dev/net/dist_iface.hh"
+#include "kern/kernel_stats.hh"
 #include "params/BaseCPU.hh"
 #include "sim/full_system.hh"
 #include "sim/initparam_keys.hh"