Gabe Black has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/33282 )

Change subject: arch,cpu,sim: Route system calls through the workload.
......................................................................

arch,cpu,sim: Route system calls through the workload.

System calls should now be requested from the workload directly and not
routed through ExecContext or ThreadContext interfaces. That removes a
major special case for SE mode from those interfaces.

For now, when the SE workload gets a request for a system call, it
dispatches it to the appropriate Process object. In the future, the
ISA specific Workload subclasses will be responsible for handling system
calls and not the Process classes.

For simplicity, the Workload syscall() method is defined in the base
class but will panic everywhere except when SEWorkload overrides it. In
the future, this mechanism will turn into a way to request generic
services from the workload which are not necessarily system calls. For
instance, it could be a way to request handling of a page fault without
having to have another PseudoInst just for that purpose.

Change-Id: I18d36d64c54adf4f4f17a62e7e006ff2fc0b22f1
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/33282
Reviewed-by: Matthew Poremba <[email protected]>
Maintainer: Gabe Black <[email protected]>
Tested-by: kokoro <[email protected]>
---
M src/arch/arm/faults.cc
M src/arch/riscv/faults.cc
M src/arch/sparc/linux/process.cc
M src/cpu/checker/cpu.hh
M src/cpu/checker/thread_context.hh
M src/cpu/exec_context.hh
M src/cpu/minor/exec_context.hh
M src/cpu/o3/cpu.cc
M src/cpu/o3/cpu.hh
M src/cpu/o3/dyn_inst.hh
M src/cpu/o3/dyn_inst_impl.hh
M src/cpu/o3/thread_context.hh
M src/cpu/o3/thread_state.hh
M src/cpu/simple/exec_context.hh
M src/cpu/simple_thread.hh
M src/cpu/thread_context.hh
M src/sim/faults.cc
M src/sim/pseudo_inst.cc
M src/sim/se_workload.cc
M src/sim/se_workload.hh
M src/sim/workload.hh
21 files changed, 21 insertions(+), 88 deletions(-)

Approvals:
  Matthew Poremba: Looks good to me, approved
  Gabe Black: Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/arch/arm/faults.cc b/src/arch/arm/faults.cc
index 56e1814..c590d78 100644
--- a/src/arch/arm/faults.cc
+++ b/src/arch/arm/faults.cc
@@ -865,7 +865,7 @@

     // As of now, there isn't a 32 bit thumb version of this instruction.
     assert(!machInst.bigThumb);
-    tc->syscall();
+    tc->getSystemPtr()->workload->syscall(tc);

     // Advance the PC since that won't happen automatically.
     PCState pc = tc->pcState();
diff --git a/src/arch/riscv/faults.cc b/src/arch/riscv/faults.cc
index 7a1c7bd..ac4c582 100644
--- a/src/arch/riscv/faults.cc
+++ b/src/arch/riscv/faults.cc
@@ -194,7 +194,7 @@
 void
 SyscallFault::invokeSE(ThreadContext *tc, const StaticInstPtr &inst)
 {
-    tc->syscall();
+    tc->getSystemPtr()->workload->syscall(tc);
 }

 } // namespace RiscvISA
diff --git a/src/arch/sparc/linux/process.cc b/src/arch/sparc/linux/process.cc
index 79bbaee..ce051ba 100644
--- a/src/arch/sparc/linux/process.cc
+++ b/src/arch/sparc/linux/process.cc
@@ -92,7 +92,7 @@
 {
     switch (trapNum) {
       case 0x10: //Linux 32 bit syscall trap
-        tc->syscall();
+        tc->getSystemPtr()->workload->syscall(tc);
         break;
       default:
         SparcProcess::handleTrap(trapNum, tc);
@@ -129,7 +129,7 @@
     switch (trapNum) {
       // case 0x10: // Linux 32 bit syscall trap
       case 0x6d: // Linux 64 bit syscall trap
-        tc->syscall();
+        tc->getSystemPtr()->workload->syscall(tc);
         break;
       case 0x6e: // Linux 64 bit getcontext trap
         getContext(tc);
diff --git a/src/cpu/checker/cpu.hh b/src/cpu/checker/cpu.hh
index f2395d7..f5d7834 100644
--- a/src/cpu/checker/cpu.hh
+++ b/src/cpu/checker/cpu.hh
@@ -610,9 +610,6 @@
     /////////////////////////////////////////////////////

     void wakeup(ThreadID tid) override { }
-    // Assume that the normal CPU's call to syscall was successful.
-    // The checker's state would have already been updated by the syscall.
-    void syscall() override { }

     void
     handleError()
diff --git a/src/cpu/checker/thread_context.hh b/src/cpu/checker/thread_context.hh
index b5a974b..d07de62 100644
--- a/src/cpu/checker/thread_context.hh
+++ b/src/cpu/checker/thread_context.hh
@@ -171,9 +171,6 @@
         actualTC->connectMemPorts(tc);
     }

-    /** Executes a syscall in SE mode. */
-    void syscall() override { return actualTC->syscall(); }
-
     Status status() const override { return actualTC->status(); }

     void
diff --git a/src/cpu/exec_context.hh b/src/cpu/exec_context.hh
index cfef3c3..b1cdbd8 100644
--- a/src/cpu/exec_context.hh
+++ b/src/cpu/exec_context.hh
@@ -300,18 +300,6 @@

     /** @} */

-    /**
-     * @{
-     * @name SysCall Emulation Interfaces
-     */
-
-    /**
-     * Executes a syscall.
-     */
-    virtual void syscall() = 0;
-
-    /** @} */
-
     /** Returns a pointer to the ThreadContext. */
     virtual ThreadContext *tcBase() const = 0;

diff --git a/src/cpu/minor/exec_context.hh b/src/cpu/minor/exec_context.hh
index 81675e6..58301a0 100644
--- a/src/cpu/minor/exec_context.hh
+++ b/src/cpu/minor/exec_context.hh
@@ -419,8 +419,6 @@
         return thread.setMiscReg(reg.index(), val);
     }

-    void syscall() override { thread.syscall(); }
-
     ThreadContext *tcBase() const override { return thread.getTC(); }

     /* @todo, should make stCondFailures persistent somewhere */
diff --git a/src/cpu/o3/cpu.cc b/src/cpu/o3/cpu.cc
index 01938f1..11fac25 100644
--- a/src/cpu/o3/cpu.cc
+++ b/src/cpu/o3/cpu.cc
@@ -914,26 +914,6 @@

 template <class Impl>
 void
-FullO3CPU<Impl>::syscall(ThreadID tid)
-{
-    DPRINTF(O3CPU, "[tid:%i] Executing syscall().\n\n", tid);
-
-    DPRINTF(Activity,"Activity: syscall() called.\n");
-
-    // Temporarily increase this by one to account for the syscall
-    // instruction.
-    ++(this->thread[tid]->funcExeInst);
-
-    // Execute the actual syscall.
-    this->thread[tid]->syscall();
-
-    // Decrease funcExeInst by one as the normal commit will handle
-    // incrementing it.
-    --(this->thread[tid]->funcExeInst);
-}
-
-template <class Impl>
-void
 FullO3CPU<Impl>::serializeThread(CheckpointOut &cp, ThreadID tid) const
 {
     thread[tid]->serialize(cp);
diff --git a/src/cpu/o3/cpu.hh b/src/cpu/o3/cpu.hh
index 0447275..200d343 100644
--- a/src/cpu/o3/cpu.hh
+++ b/src/cpu/o3/cpu.hh
@@ -276,11 +276,6 @@
     void exitThreads();

   public:
-    /** Executes a syscall.
-     * @todo: Determine if this needs to be virtual.
-     */
-    void syscall(ThreadID tid);
-
     /** Starts draining the CPU's pipeline of all instructions in
      * order to stop all memory accesses. */
     DrainState drain() override;
diff --git a/src/cpu/o3/dyn_inst.hh b/src/cpu/o3/dyn_inst.hh
index 5f2a588..8172b9a 100644
--- a/src/cpu/o3/dyn_inst.hh
+++ b/src/cpu/o3/dyn_inst.hh
@@ -248,9 +248,6 @@
     /** Traps to handle specified fault. */
     void trap(const Fault &fault);

-    /** Emulates a syscall. */
-    void syscall() override;
-
   public:

     // The register accessor methods provide the index of the
diff --git a/src/cpu/o3/dyn_inst_impl.hh b/src/cpu/o3/dyn_inst_impl.hh
index 8a6a434..6c6625c 100644
--- a/src/cpu/o3/dyn_inst_impl.hh
+++ b/src/cpu/o3/dyn_inst_impl.hh
@@ -187,19 +187,4 @@
     this->cpu->trap(fault, this->threadNumber, this->staticInst);
 }

-template <class Impl>
-void
-BaseO3DynInst<Impl>::syscall()
-{
-    // HACK: check CPU's nextPC before and after syscall. If it
-    // changes, update this instruction's nextPC because the syscall
-    // must have changed the nextPC.
-    TheISA::PCState curPC = this->cpu->pcState(this->threadNumber);
-    this->cpu->syscall(this->threadNumber);
-    TheISA::PCState newPC = this->cpu->pcState(this->threadNumber);
-    if (!(curPC == newPC)) {
-        this->pcState(newPC);
-    }
-}
-
 #endif//__CPU_O3_DYN_INST_IMPL_HH__
diff --git a/src/cpu/o3/thread_context.hh b/src/cpu/o3/thread_context.hh
index b3eba13..8d6edbf 100644
--- a/src/cpu/o3/thread_context.hh
+++ b/src/cpu/o3/thread_context.hh
@@ -419,13 +419,6 @@
         thread->storeCondFailures = sc_failures;
     }

-    /** Executes a syscall in SE mode. */
-    void
-    syscall() override
-    {
-        return cpu->syscall(thread->threadId());
-    }
-
     /** Reads the funcExeInst counter. */
Counter readFuncExeInst() const override { return thread->funcExeInst; }

diff --git a/src/cpu/o3/thread_state.hh b/src/cpu/o3/thread_state.hh
index 3226832..285adea 100644
--- a/src/cpu/o3/thread_state.hh
+++ b/src/cpu/o3/thread_state.hh
@@ -128,9 +128,6 @@

     /** Returns a pointer to the TC of this thread. */
     ThreadContext *getTC() { return tc; }
-
-    /** Handles the syscall. */
-    void syscall() { process->syscall(tc); }
 };

 #endif // __CPU_O3_THREAD_STATE_HH__
diff --git a/src/cpu/simple/exec_context.hh b/src/cpu/simple/exec_context.hh
index 2b2afd2..fbd2d96 100644
--- a/src/cpu/simple/exec_context.hh
+++ b/src/cpu/simple/exec_context.hh
@@ -496,11 +496,6 @@
         return thread->readStCondFailures();
     }

-    /**
-     * Executes a syscall specified by the callnum.
-     */
-    void syscall() override { thread->syscall(); }
-
     /** Returns a pointer to the ThreadContext. */
     ThreadContext *tcBase() const override { return thread->getTC(); }

diff --git a/src/cpu/simple_thread.hh b/src/cpu/simple_thread.hh
index 5fe52cb..255140f 100644
--- a/src/cpu/simple_thread.hh
+++ b/src/cpu/simple_thread.hh
@@ -585,8 +585,6 @@
         return ThreadState::readFuncExeInst();
     }

-    void syscall() override { process->syscall(this); }
-
RegVal readIntRegFlat(RegIndex idx) const override { return intRegs[idx]; }
     void
     setIntRegFlat(RegIndex idx, RegVal val) override
diff --git a/src/cpu/thread_context.hh b/src/cpu/thread_context.hh
index 8cc7cec..a6f7869 100644
--- a/src/cpu/thread_context.hh
+++ b/src/cpu/thread_context.hh
@@ -292,8 +292,6 @@
     // Same with st cond failures.
     virtual Counter readFuncExeInst() const = 0;

-    virtual void syscall() = 0;
-
     // This function exits the thread context in the CPU and returns
     // 1 if the CPU has no more active threads (meaning it's OK to exit);
// Used in syscall-emulation mode when a thread calls the exit syscall.
diff --git a/src/sim/faults.cc b/src/sim/faults.cc
index d4d3c11..501b5d1 100644
--- a/src/sim/faults.cc
+++ b/src/sim/faults.cc
@@ -67,7 +67,7 @@
 void
 SESyscallFault::invoke(ThreadContext *tc, const StaticInstPtr &inst)
 {
-    tc->syscall();
+    tc->getSystemPtr()->workload->syscall(tc);
     // Move the PC forward since that doesn't happen automatically.
     TheISA::PCState pc = tc->pcState();
     inst->advancePC(pc);
diff --git a/src/sim/pseudo_inst.cc b/src/sim/pseudo_inst.cc
index 7335fda..90db4bb 100644
--- a/src/sim/pseudo_inst.cc
+++ b/src/sim/pseudo_inst.cc
@@ -479,7 +479,7 @@
 m5Syscall(ThreadContext *tc)
 {
     DPRINTF(PseudoInst, "PseudoInst::m5Syscall()\n");
-    tc->syscall();
+    tc->getSystemPtr()->workload->syscall(tc);
 }

 void
diff --git a/src/sim/se_workload.cc b/src/sim/se_workload.cc
index f2a01d5..dccd7ca 100644
--- a/src/sim/se_workload.cc
+++ b/src/sim/se_workload.cc
@@ -27,10 +27,17 @@

 #include "sim/se_workload.hh"

+#include "cpu/thread_context.hh"
 #include "params/SEWorkload.hh"
+#include "sim/process.hh"

 SEWorkload::SEWorkload(const Params &p) : Workload(&p), _params(p)
+{}
+
+void
+SEWorkload::syscall(ThreadContext *tc)
 {
+    tc->getProcessPtr()->syscall(tc);
 }

 SEWorkload *
diff --git a/src/sim/se_workload.hh b/src/sim/se_workload.hh
index b72e824..8deb03b 100644
--- a/src/sim/se_workload.hh
+++ b/src/sim/se_workload.hh
@@ -76,6 +76,8 @@
         // within it.
         panic("No workload symbol table for syscall emulation mode.");
     }
+
+    void syscall(ThreadContext *tc) override;
 };

 #endif // __SIM_SE_WORKLOAD_HH__
diff --git a/src/sim/workload.hh b/src/sim/workload.hh
index 435a24b..7c1b66d 100644
--- a/src/sim/workload.hh
+++ b/src/sim/workload.hh
@@ -69,6 +69,12 @@
     virtual const Loader::SymbolTable &symtab(ThreadContext *tc) = 0;
     virtual bool insertSymbol(const Loader::Symbol &symbol) = 0;

+    virtual void
+    syscall(ThreadContext *tc)
+    {
+        panic("syscall() not implemented.");
+    }
+
     /** @{ */
     /**
      * Add a function-based event to the given function, to be looked

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/33282
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I18d36d64c54adf4f4f17a62e7e006ff2fc0b22f1
Gerrit-Change-Number: 33282
Gerrit-PatchSet: 8
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-Reviewer: Brandon Potter <[email protected]>
Gerrit-Reviewer: Gabe Black <[email protected]>
Gerrit-Reviewer: Giacomo Travaglini <[email protected]>
Gerrit-Reviewer: Matthew Poremba <[email protected]>
Gerrit-Reviewer: kokoro <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to