Brandon Potter has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/12309

Change subject: syscall_emul: enhance clone for KvmCPU
......................................................................

syscall_emul: enhance clone for KvmCPU

This patch enables clone to work with the KvmCPU, which will
allow running multi-threaded applications at near hardware
speeds with the KvmCPU model.

Change-Id: I2879e20518bf6c0c19fbc7e11b1583c22b59ef3b
---
M src/arch/x86/process.cc
M src/mem/multi_level_page_table.hh
M src/mem/page_table.hh
M src/sim/process.cc
M src/sim/process.hh
M src/sim/syscall_emul.hh
6 files changed, 33 insertions(+), 2 deletions(-)



diff --git a/src/arch/x86/process.cc b/src/arch/x86/process.cc
index a19ec43..dd47cc1 100644
--- a/src/arch/x86/process.cc
+++ b/src/arch/x86/process.cc
@@ -171,6 +171,9 @@
                          SyscallDesc *_syscallDescs, int _numSyscallDescs)
     : X86Process(params, objFile, _syscallDescs, _numSyscallDescs)
 {
+    if (kvmInSE)
+        panic("KVM CPU model does not support 32 bit processes");
+
     _gdtStart = ULL(0xffffd000);
     _gdtSize = PageBytes;

@@ -210,6 +213,9 @@
 {
     X86Process::initState();

+    if (useForClone)
+        return;
+
     argsInit(PageBytes);

     auto p_table = memState->_pTable;
diff --git a/src/mem/multi_level_page_table.hh b/src/mem/multi_level_page_table.hh
index bd40d37..f517eaf 100644
--- a/src/mem/multi_level_page_table.hh
+++ b/src/mem/multi_level_page_table.hh
@@ -204,6 +204,9 @@
     void
     initState(ThreadContext* tc) override
     {
+        if (shared)
+            return;
+
         _basePtr = prepTopTable<EntryTypes...>(system, pageSize);
     }

diff --git a/src/mem/page_table.hh b/src/mem/page_table.hh
index 447d3a5..d02b5f5 100644
--- a/src/mem/page_table.hh
+++ b/src/mem/page_table.hh
@@ -75,7 +75,7 @@
     EmulationPageTable(
             const std::string &__name, uint64_t _pid, Addr _pageSize) :
             pageSize(_pageSize), offsetMask(mask(floorLog2(_pageSize))),
-            _pid(_pid), _name(__name)
+            _pid(_pid), _name(__name), shared(false)
     {
         assert(isPowerOf2(pageSize));
     }
@@ -96,6 +96,10 @@
         ReadOnly    = 8,
     };

+    // flag used by initState to determine when the page table should be
+    // cleared
+    bool shared;
+
     virtual void initState(ThreadContext* tc) {};

     // for DPRINTF compatibility
diff --git a/src/sim/process.cc b/src/sim/process.cc
index 3a3f66a..7d1a9e2 100644
--- a/src/sim/process.cc
+++ b/src/sim/process.cc
@@ -105,6 +105,7 @@
 Process::Process(ProcessParams *params, ObjectFile *obj_file)
     : SimObject(params), system(params->system),
       kvmInSE(params->kvmInSE),
+      useForClone(false),
       objFile(obj_file),
       argv(params->cmd), envp(params->env),
       host_cwd(checkPathRedirect(params->cwd)), tgt_cwd(params->cwd),
diff --git a/src/sim/process.hh b/src/sim/process.hh
index 35d1c31..182c62e 100644
--- a/src/sim/process.hh
+++ b/src/sim/process.hh
@@ -155,6 +155,11 @@
     Stats::Scalar numSyscalls;  // track how many system calls are executed

     bool kvmInSE;   // running KVM requires special initialization
+    /**
+     * Flag used by initState to determine when the page table should be
+     * cleared.
+     */
+    bool useForClone;

     ObjectFile *objFile;
     std::vector<std::string> argv;
diff --git a/src/sim/syscall_emul.hh b/src/sim/syscall_emul.hh
index 3f61b59..fc1b7ca 100644
--- a/src/sim/syscall_emul.hh
+++ b/src/sim/syscall_emul.hh
@@ -1467,6 +1467,8 @@

     pp->pid = temp_pid;
     pp->ppid = (flags & OS::TGT_CLONE_THREAD) ? p->ppid() : p->pid();
+    pp->useArchPT = p->_params->useArchPT;
+    pp->kvmInSE = p->kvmInSE;
     Process *cp = pp->create();
     delete pp;

@@ -1487,6 +1489,8 @@
     auto child_mem_state = cp->memState;
     if (flags & OS::TGT_CLONE_THREAD) {
         auto child_p_table = child_mem_state->_pTable;
+        child_p_table->shared = true;
+        cp->useForClone = true;
     }
     cp->initState();
     p->clone(tc, ctc, cp, flags);
@@ -1548,7 +1552,15 @@
     ctc->setIntReg(TheISA::SyscallPseudoReturnReg, 1);
 #endif

-    ctc->pcState(tc->nextInstAddr());
+    if (p->kvmInSE) {
+#if THE_ISA == X86_ISA
+        ctc->pcState(tc->readIntReg(TheISA::INTREG_RCX));
+#else
+        panic("KVM CPU model is not supported in SE mode for this ISA");
+#endif
+    } else {
+        ctc->pcState(tc->nextInstAddr());
+    }
     ctc->activate();

     return cp->pid();

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

Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: I2879e20518bf6c0c19fbc7e11b1583c22b59ef3b
Gerrit-Change-Number: 12309
Gerrit-PatchSet: 1
Gerrit-Owner: Brandon Potter <[email protected]>
Gerrit-Reviewer: Alexandru DuČ›u <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to