sim-se: Add special paths for MPI, libnuma, ROCm support
authorMatthew Poremba <matthew.poremba@amd.com>
Thu, 13 Feb 2020 19:27:07 +0000 (11:27 -0800)
committerMatthew Poremba <matthew.poremba@amd.com>
Wed, 25 Mar 2020 21:55:21 +0000 (21:55 +0000)
Add new pseudo files which are read by various runtime libraries
including MPI, libnuma, and ROCm. New paths include /proc/self/maps,
/dev/urandom, and /sys/devices/system/cpu/online.

Change-Id: I00a82788cff9d6f4f16fc56230b18be9b76c4015
Signed-off-by: Brandon Potter <Brandon.Potter@amd.com>
Signed-off-by: Michael LeBeane <Michael.Lebeane@amd.com>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/25367
Tested-by: Gem5 Cloud Project GCB service account <345032938727@cloudbuild.gserviceaccount.com>
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
src/kern/linux/linux.cc
src/kern/linux/linux.hh
src/sim/mem_state.cc
src/sim/mem_state.hh
src/sim/syscall_emul.hh

index 1a8c24129e758eead100fddd6dd2849e3881ae8f..ae1d47c3f652c62790ec1292831b1258d67461d5 100644 (file)
 
 #include "cpu/base.hh"
 #include "debug/SyscallVerbose.hh"
+#include "sim/mem_state.hh"
 #include "sim/process.hh"
 #include "sim/system.hh"
+#include "sim/vma.hh"
+
+// The OS methods are called statically. Instantiate the random number
+// generator for access to /dev/urandom here.
+Random Linux::random;
 
 int
 Linux::openSpecialFile(std::string path, Process *process,
@@ -53,6 +59,15 @@ Linux::openSpecialFile(std::string path, Process *process,
     } else if (path.compare(0, 11, "/etc/passwd") == 0) {
         data = Linux::etcPasswd(process, tc);
         matched = true;
+    } else if (path.compare(0, 15, "/proc/self/maps") == 0) {
+        data = Linux::procSelfMaps(process, tc);
+        matched = true;
+    } else if (path.compare(0, 30, "/sys/devices/system/cpu/online") == 0) {
+        data = Linux::cpuOnline(process, tc);
+        matched = true;
+    } else if (path.compare(0, 12 ,"/dev/urandom") == 0) {
+        data = Linux::devRandom(process, tc);
+        matched = true;
     }
 
     if (matched) {
@@ -85,3 +100,33 @@ Linux::etcPasswd(Process *process, ThreadContext *tc)
     return csprintf("gem5-user:x:1000:1000:gem5-user,,,:%s:/bin/bash\n",
                     process->tgtCwd);
 }
+
+std::string
+Linux::procSelfMaps(Process *process, ThreadContext *tc)
+{
+    return process->memState->printVmaList();
+}
+
+std::string
+Linux::cpuOnline(Process *process, ThreadContext *tc)
+{
+    return csprintf("0-%d\n",
+                    tc->getSystemPtr()->numContexts() - 1);
+}
+
+std::string
+Linux::devRandom(Process *process, ThreadContext *tc)
+{
+    DPRINTFR(SyscallVerbose,
+             "%d: %s: open: generating urandom\n",
+             curTick(), tc->getCpuPtr()->name());
+
+    std::stringstream line;
+    int max = 1E5;
+    for (int i = 0; i < max; i++) {
+        uint8_t rand_uint = random.random<uint8_t>(0, 255);
+
+        line << rand_uint;
+    }
+    return line.str();
+}
index 4b45b8bf314fd767c2cbbc3cdb63659f935ca149..5370e2ba763b06a035552c1c1cdddc9bbfcfab7e 100644 (file)
 #ifndef __LINUX_HH__
 #define __LINUX_HH__
 
-#include "base/types.hh"
-
 #include <string>
 
+#include "base/random.hh"
+#include "base/types.hh"
 #include "kern/operatingsystem.hh"
 #include "sim/process.hh"
 
@@ -230,11 +230,16 @@ class Linux : public OperatingSystem
         int64_t ru_nivcsw;              //!< involuntary "
     };
 
+    // For /dev/urandom accesses
+    static Random random;
+
     static int openSpecialFile(std::string path, Process *process,
                                ThreadContext *tc);
     static std::string procMeminfo(Process *process, ThreadContext *tc);
     static std::string etcPasswd(Process *process, ThreadContext *tc);
+    static std::string procSelfMaps(Process *process, ThreadContext *tc);
     static std::string cpuOnline(Process *process, ThreadContext *tc);
+    static std::string devRandom(Process *process, ThreadContext *tc);
 
     // For futex system call
     static const unsigned TGT_FUTEX_WAIT                = 0;
index a6177c3c28aac5ee32e277d36bf14ce3744c15b1..42d37819fac212e4fd056a70c05450f749553e7a 100644 (file)
@@ -473,3 +473,20 @@ MemState::extendMmap(Addr length)
 
     return start;
 }
+
+std::string
+MemState::printVmaList()
+{
+    std::stringstream file_content;
+
+    for (auto vma : _vmaList) {
+        std::stringstream line;
+        line << std::hex << vma.start() << "-";
+        line << std::hex << vma.end() << " ";
+        line << "r-xp 00000000 00:00 0 ";
+        line << "[" << vma.getName() << "]" << std::endl;
+        file_content << line.str();
+    }
+
+    return file_content.str();
+}
index 42823ce0136de3b5e663652b1e739c9e77ae3a6f..1ca80dab101de1322a033297695bdfb7a7d84691 100644 (file)
@@ -203,6 +203,11 @@ class MemState : public Serializable
         paramIn(cp, "mmapEnd", _mmapEnd);
     }
 
+    /**
+     * Print the list of VMAs in a format similar to /proc/self/maps
+     */
+    std::string printVmaList();
+
   private:
     /**
      * Owner process of MemState. Used to manipulate page tables.
index 1270855353f317bcb83605f4eba6a324aa53bc08..e1a23a087eb2c32aa6f0909bf0df1df71e90b81a 100644 (file)
@@ -876,7 +876,9 @@ openatFunc(SyscallDesc *desc, ThreadContext *tc,
     int sim_fd = -1;
     std::string used_path;
     std::vector<std::string> special_paths =
-            { "/proc/meminfo/", "/system/", "/platform/", "/etc/passwd" };
+            { "/proc/meminfo/", "/system/", "/platform/", "/etc/passwd",
+              "/proc/self/maps", "/dev/urandom",
+              "/sys/devices/system/cpu/online" };
     for (auto entry : special_paths) {
         if (startswith(path, entry)) {
             sim_fd = OS::openSpecialFile(abs_path, p, tc);