Matthew Poremba has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/25366 )

Change subject: sim-se: Switch to new MemState API
......................................................................

sim-se: Switch to new MemState API

Switch over to the new MemState API by specifying memory regions for
stack in each ISA, changing brkFunc to use MemState for heap memory,
and calling the MemState fixup in fixupStackFault (renamed to just
fixupFault).

Change-Id: Ie3559a68ce476daedf1a3f28b168a8fbc7face5e
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/25366
Reviewed-by: Jason Lowe-Power <power...@gmail.com>
Maintainer: Jason Lowe-Power <power...@gmail.com>
Tested-by: kokoro <noreply+kok...@google.com>
---
M src/arch/arm/process.cc
M src/arch/mips/process.cc
M src/arch/power/process.cc
M src/arch/riscv/process.cc
M src/arch/riscv/tlb.cc
M src/arch/sparc/faults.cc
M src/arch/sparc/process.cc
M src/arch/x86/faults.cc
M src/arch/x86/process.cc
M src/arch/x86/pseudo_inst.cc
M src/arch/x86/tlb.cc
M src/gpu-compute/compute_unit.cc
M src/gpu-compute/gpu_tlb.cc
M src/mem/se_translating_port_proxy.cc
M src/sim/faults.cc
M src/sim/process.cc
M src/sim/process.hh
M src/sim/syscall_emul.cc
18 files changed, 32 insertions(+), 80 deletions(-)

Approvals:
  Jason Lowe-Power: Looks good to me, approved; Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/arch/arm/process.cc b/src/arch/arm/process.cc
index c672444..12003f8 100644
--- a/src/arch/arm/process.cc
+++ b/src/arch/arm/process.cc
@@ -371,8 +371,8 @@
memState->setStackSize(memState->getStackBase() - memState->getStackMin());

     // map memory
-    allocateMem(roundDown(memState->getStackMin(), pageSize),
-                          roundUp(memState->getStackSize(), pageSize));
+    memState->mapRegion(roundDown(memState->getStackMin(), pageSize),
+ roundUp(memState->getStackSize(), pageSize), "stack");

     // map out initial stack contents
     IntType sentry_base = memState->getStackBase() - sentry_size;
diff --git a/src/arch/mips/process.cc b/src/arch/mips/process.cc
index a610fbe..3e7b378 100644
--- a/src/arch/mips/process.cc
+++ b/src/arch/mips/process.cc
@@ -151,8 +151,8 @@
     memState->setStackMin(roundDown(memState->getStackMin(), pageSize));
memState->setStackSize(memState->getStackBase() - memState->getStackMin());
     // map memory
-    allocateMem(memState->getStackMin(), roundUp(memState->getStackSize(),
-                pageSize));
+    memState->mapRegion(memState->getStackMin(),
+ roundUp(memState->getStackSize(), pageSize), "stack");

     // map out initial stack contents; leave room for argc
     IntType argv_array_base = memState->getStackMin() + intSize;
diff --git a/src/arch/power/process.cc b/src/arch/power/process.cc
index 5cb9823..914c99f 100644
--- a/src/arch/power/process.cc
+++ b/src/arch/power/process.cc
@@ -200,8 +200,8 @@
     memState->setStackSize(memState->getStackBase() - stack_min);

     // map memory
-    allocateMem(roundDown(stack_min, pageSize),
-                roundUp(memState->getStackSize(), pageSize));
+    memState->mapRegion(roundDown(stack_min, pageSize),
+ roundUp(memState->getStackSize(), pageSize), "stack");

     // map out initial stack contents
     uint32_t sentry_base = memState->getStackBase() - sentry_size;
diff --git a/src/arch/riscv/process.cc b/src/arch/riscv/process.cc
index 474ed68..4026836 100644
--- a/src/arch/riscv/process.cc
+++ b/src/arch/riscv/process.cc
@@ -147,8 +147,8 @@
                    addrSize + 2 * sizeof(IntType) * auxv.size();
     stack_top &= -2*addrSize;
     memState->setStackSize(memState->getStackBase() - stack_top);
-    allocateMem(roundDown(stack_top, pageSize),
-            roundUp(memState->getStackSize(), pageSize));
+    memState->mapRegion(roundDown(stack_top, pageSize),
+ roundUp(memState->getStackSize(), pageSize), "stack");

     // Copy random bytes (for AT_RANDOM) to stack
     memState->setStackMin(memState->getStackMin() - RandomBytes);
diff --git a/src/arch/riscv/tlb.cc b/src/arch/riscv/tlb.cc
index 1bf557a..ac4eca7 100644
--- a/src/arch/riscv/tlb.cc
+++ b/src/arch/riscv/tlb.cc
@@ -392,7 +392,7 @@

     if (!pte && mode != Execute) {
         // Check if we just need to grow the stack.
-        if (process->fixupStackFault(vaddr)) {
+        if (process->fixupFault(vaddr)) {
             // If we did, lookup the entry for the new page.
             pte = process->pTable->lookup(vaddr);
         }
diff --git a/src/arch/sparc/faults.cc b/src/arch/sparc/faults.cc
index dc68c01..4197613 100644
--- a/src/arch/sparc/faults.cc
+++ b/src/arch/sparc/faults.cc
@@ -683,7 +683,7 @@

     Process *p = tc->getProcessPtr();
     const EmulationPageTable::Entry *pte = p->pTable->lookup(vaddr);
-    if (!pte && p->fixupStackFault(vaddr))
+    if (!pte && p->fixupFault(vaddr))
         pte = p->pTable->lookup(vaddr);
     panic_if(!pte, "Tried to access unmapped address %#x.\n", vaddr);

diff --git a/src/arch/sparc/process.cc b/src/arch/sparc/process.cc
index c55e9cb..8dfe2e9 100644
--- a/src/arch/sparc/process.cc
+++ b/src/arch/sparc/process.cc
@@ -317,8 +317,8 @@
memState->setStackSize(memState->getStackBase() - memState->getStackMin());

     // Allocate space for the stack
-    allocateMem(roundDown(memState->getStackMin(), pageSize),
-                roundUp(memState->getStackSize(), pageSize));
+    memState->mapRegion(roundDown(memState->getStackMin(), pageSize),
+ roundUp(memState->getStackSize(), pageSize), "stack");

     // map out initial stack contents
     IntType sentry_base = memState->getStackBase() - sentry_size;
diff --git a/src/arch/x86/faults.cc b/src/arch/x86/faults.cc
index cb11eac..ca890c3 100644
--- a/src/arch/x86/faults.cc
+++ b/src/arch/x86/faults.cc
@@ -47,6 +47,7 @@
 #include "cpu/thread_context.hh"
 #include "debug/Faults.hh"
 #include "sim/full_system.hh"
+#include "sim/process.hh"

 namespace X86ISA
 {
@@ -151,7 +152,7 @@
             } else {
                 tc->setMiscReg(MISCREG_CR2, (uint32_t)addr);
             }
-        } else {
+        } else if (!tc->getProcessPtr()->fixupFault(addr)) {
             PageFaultErrorCode code = errorCode;
             const char *modeStr = "";
             if (code.fetch)
diff --git a/src/arch/x86/process.cc b/src/arch/x86/process.cc
index b98bb87..b298362 100644
--- a/src/arch/x86/process.cc
+++ b/src/arch/x86/process.cc
@@ -178,7 +178,7 @@
     argsInit(PageBytes);

     // Set up the vsyscall page for this process.
-    allocateMem(vsyscallPage.base, vsyscallPage.size);
+    memState->mapRegion(vsyscallPage.base, vsyscallPage.size, "vsyscall");
     uint8_t vtimeBlob[] = {
         0x48,0xc7,0xc0,0xc9,0x00,0x00,0x00,    // mov    $0xc9,%rax
         0x0f,0x05,                             // syscall
@@ -629,7 +629,7 @@
     }

     // Set up the vsyscall page for this process.
-    allocateMem(vsyscallPage.base, vsyscallPage.size);
+    memState->mapRegion(vsyscallPage.base, vsyscallPage.size, "vsyscall");
     uint8_t vsyscallBlob[] = {
         0x51,       // push %ecx
         0x52,       // push %edp
@@ -934,7 +934,7 @@
     Addr stack_end = roundDown(stack_base - stack_size, pageSize);

     DPRINTF(Stack, "Mapping the stack: 0x%x %dB\n", stack_end, stack_size);
-    allocateMem(stack_end, stack_size);
+    memState->mapRegion(stack_end, stack_size, "stack");

     // map out initial stack contents
     IntType sentry_base = stack_base - sentry_size;
diff --git a/src/arch/x86/pseudo_inst.cc b/src/arch/x86/pseudo_inst.cc
index 2cc67dd..e8fcfd3 100644
--- a/src/arch/x86/pseudo_inst.cc
+++ b/src/arch/x86/pseudo_inst.cc
@@ -49,7 +49,7 @@
     DPRINTF(PseudoInst, "PseudoInst::m5PageFault()\n");

     Process *p = tc->getProcessPtr();
-    if (!p->fixupStackFault(tc->readMiscReg(MISCREG_CR2))) {
+    if (!p->fixupFault(tc->readMiscReg(MISCREG_CR2))) {
         PortProxy &proxy = tc->getVirtProxy();
         // at this point we should have 6 values on the interrupt stack
         int size = 6;
diff --git a/src/arch/x86/tlb.cc b/src/arch/x86/tlb.cc
index 740b6bc..46bab48 100644
--- a/src/arch/x86/tlb.cc
+++ b/src/arch/x86/tlb.cc
@@ -399,7 +399,7 @@
                         p->pTable->lookup(vaddr);
                     if (!pte && mode != Execute) {
                         // Check if we just need to grow the stack.
-                        if (p->fixupStackFault(vaddr)) {
+                        if (p->fixupFault(vaddr)) {
// If we did, lookup the entry for the new page.
                             pte = p->pTable->lookup(vaddr);
                         }
@@ -487,7 +487,7 @@

         if (!pte && mode != Execute) {
             // Check if we just need to grow the stack.
-            if (process->fixupStackFault(vaddr)) {
+            if (process->fixupFault(vaddr)) {
                 // If we did, lookup the entry for the new page.
                 pte = process->pTable->lookup(vaddr);
             }
diff --git a/src/gpu-compute/compute_unit.cc b/src/gpu-compute/compute_unit.cc
index 4cf7f41..59bc6a0 100644
--- a/src/gpu-compute/compute_unit.cc
+++ b/src/gpu-compute/compute_unit.cc
@@ -782,7 +782,7 @@
             Addr paddr;

             if (!p->pTable->translate(vaddr, paddr)) {
-                if (!p->fixupStackFault(vaddr)) {
+                if (!p->fixupFault(vaddr)) {
                     panic("CU%d: WF[%d][%d]: Fault on addr %#x!\n",
                           cu_id, gpuDynInst->simdId, gpuDynInst->wfSlotId,
                           vaddr);
diff --git a/src/gpu-compute/gpu_tlb.cc b/src/gpu-compute/gpu_tlb.cc
index 73194de..12fb9aa 100644
--- a/src/gpu-compute/gpu_tlb.cc
+++ b/src/gpu-compute/gpu_tlb.cc
@@ -521,7 +521,7 @@
                             if (timing)
                                 latency += missLatency2;

-                            if (p->fixupStackFault(vaddr))
+                            if (p->fixupFault(vaddr))
                                 pte = p->pTable->lookup(vaddr);
                         }

@@ -1044,7 +1044,7 @@
     #endif
const EmulationPageTable::Entry *pte = p->pTable->lookup(vaddr);
             if (!pte && sender_state->tlbMode != BaseTLB::Execute &&
-                    p->fixupStackFault(vaddr)) {
+                    p->fixupFault(vaddr)) {
                 pte = p->pTable->lookup(vaddr);
             }

@@ -1248,7 +1248,7 @@
                 const EmulationPageTable::Entry *pte =
                         p->pTable->lookup(vaddr);
                 if (!pte && sender_state->tlbMode != BaseTLB::Execute &&
-                        p->fixupStackFault(vaddr)) {
+                        p->fixupFault(vaddr)) {
                     pte = p->pTable->lookup(vaddr);
                 }

diff --git a/src/mem/se_translating_port_proxy.cc b/src/mem/se_translating_port_proxy.cc
index 8af628f..bc1153e 100644
--- a/src/mem/se_translating_port_proxy.cc
+++ b/src/mem/se_translating_port_proxy.cc
@@ -57,7 +57,7 @@
         if (allocating == Always) {
             process->allocateMem(roundDown(addr, pageBytes), pageBytes);
             return true;
- } else if (allocating == NextPage && process->fixupStackFault(addr)) {
+        } else if (allocating == NextPage && process->fixupFault(addr)) {
             // We've accessed the next page on the stack.
             return true;
         }
diff --git a/src/sim/faults.cc b/src/sim/faults.cc
index 6a63529..c2ce978 100644
--- a/src/sim/faults.cc
+++ b/src/sim/faults.cc
@@ -66,7 +66,7 @@
     bool handled = false;
     if (!FullSystem) {
         Process *p = tc->getProcessPtr();
-        handled = p->fixupStackFault(vaddr);
+        handled = p->fixupFault(vaddr);
     }
     if (!handled)
panic("Page table fault when accessing virtual address %#x\n", vaddr);
diff --git a/src/sim/process.cc b/src/sim/process.cc
index 8cd12b5..36f413f 100644
--- a/src/sim/process.cc
+++ b/src/sim/process.cc
@@ -352,33 +352,9 @@
 }

 bool
-Process::fixupStackFault(Addr vaddr)
+Process::fixupFault(Addr vaddr)
 {
-    Addr stack_min = memState->getStackMin();
-    Addr stack_base = memState->getStackBase();
-    Addr max_stack_size = memState->getMaxStackSize();
-
-    // Check if this is already on the stack and there's just no page there
-    // yet.
-    if (vaddr >= stack_min && vaddr < stack_base) {
-        allocateMem(roundDown(vaddr, PageBytes), PageBytes);
-        return true;
-    }
-
-    // We've accessed the next page of the stack, so extend it to include
-    // this address.
-    if (vaddr < stack_min && vaddr >= stack_base - max_stack_size) {
-        while (vaddr < stack_min) {
-            stack_min -= TheISA::PageBytes;
-            if (stack_base - stack_min > max_stack_size)
-                fatal("Maximum stack size exceeded\n");
-            allocateMem(stack_min, TheISA::PageBytes);
-            inform("Increasing stack size by one page.");
-        }
-        memState->setStackMin(stack_min);
-        return true;
-    }
-    return false;
+    return memState->fixupFault(vaddr);
 }

 void
diff --git a/src/sim/process.hh b/src/sim/process.hh
index 7c152ae..350057e 100644
--- a/src/sim/process.hh
+++ b/src/sim/process.hh
@@ -108,7 +108,7 @@

/// Attempt to fix up a fault at vaddr by allocating a page on the stack.
     /// @return Whether the fault has been fixed.
-    bool fixupStackFault(Addr vaddr);
+    bool fixupFault(Addr vaddr);

     // After getting registered with system object, tell process which
     // system-wide context id it is assigned.
diff --git a/src/sim/syscall_emul.cc b/src/sim/syscall_emul.cc
index d3743a3..08432e1 100644
--- a/src/sim/syscall_emul.cc
+++ b/src/sim/syscall_emul.cc
@@ -254,39 +254,14 @@

     // in Linux at least, brk(0) returns the current break value
// (note that the syscall and the glibc function have different behavior)
-    if (new_brk == 0)
+    if (new_brk == 0 || (new_brk == brk_point))
         return brk_point;

-    if (new_brk > brk_point) {
-        // might need to allocate some new pages
-        for (ChunkGenerator gen(brk_point,
-                                new_brk - brk_point,
-                                PageBytes); !gen.done(); gen.next()) {
-            if (!p->pTable->translate(gen.addr()))
- p->allocateMem(roundDown(gen.addr(), PageBytes), PageBytes);
+    mem_state->updateBrkRegion(brk_point, new_brk);

-            // if the address is already there, zero it out
-            else {
-                uint8_t zero = 0;
-                PortProxy &tp = tc->getVirtProxy();
-
-                // split non-page aligned accesses
-                Addr next_page = roundUp(gen.addr(), PageBytes);
-                uint32_t size_needed = next_page - gen.addr();
-                tp.memsetBlob(gen.addr(), zero, size_needed);
-                if (gen.addr() + PageBytes > next_page &&
-                    next_page < new_brk &&
-                    p->pTable->translate(next_page)) {
-                    size_needed = PageBytes - size_needed;
-                    tp.memsetBlob(next_page, zero, size_needed);
-                }
-            }
-        }
-    }
-
-    mem_state->setBrkPoint(new_brk);
     DPRINTF_SYSCALL(Verbose, "brk: break point changed to: %#X\n",
                     mem_state->getBrkPoint());
+
     return mem_state->getBrkPoint();
 }


--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/25366
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: Ie3559a68ce476daedf1a3f28b168a8fbc7face5e
Gerrit-Change-Number: 25366
Gerrit-PatchSet: 16
Gerrit-Owner: Matthew Poremba <matthew.pore...@amd.com>
Gerrit-Reviewer: Alec Roelke <ar...@virginia.edu>
Gerrit-Reviewer: Andreas Sandberg <andreas.sandb...@arm.com>
Gerrit-Reviewer: Gabe Black <gabebl...@google.com>
Gerrit-Reviewer: Giacomo Travaglini <giacomo.travagl...@arm.com>
Gerrit-Reviewer: Jason Lowe-Power <power...@gmail.com>
Gerrit-Reviewer: Matthew Poremba <matthew.pore...@amd.com>
Gerrit-Reviewer: Michael LeBeane <michael.lebe...@amd.com>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to