From: Matthew Poremba Date: Thu, 13 Feb 2020 19:27:07 +0000 (-0800) Subject: sim-se: Add special paths for MPI, libnuma, ROCm support X-Git-Tag: v20.0.0.0~259 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=209c0663d54dd5b734ea9bd397246d9d36149b1b;p=gem5.git sim-se: Add special paths for MPI, libnuma, ROCm support 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 Signed-off-by: Michael LeBeane 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 --- diff --git a/src/kern/linux/linux.cc b/src/kern/linux/linux.cc index 1a8c24129..ae1d47c3f 100644 --- a/src/kern/linux/linux.cc +++ b/src/kern/linux/linux.cc @@ -33,8 +33,14 @@ #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(0, 255); + + line << rand_uint; + } + return line.str(); +} diff --git a/src/kern/linux/linux.hh b/src/kern/linux/linux.hh index 4b45b8bf3..5370e2ba7 100644 --- a/src/kern/linux/linux.hh +++ b/src/kern/linux/linux.hh @@ -29,10 +29,10 @@ #ifndef __LINUX_HH__ #define __LINUX_HH__ -#include "base/types.hh" - #include +#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; diff --git a/src/sim/mem_state.cc b/src/sim/mem_state.cc index a6177c3c2..42d37819f 100644 --- a/src/sim/mem_state.cc +++ b/src/sim/mem_state.cc @@ -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(); +} diff --git a/src/sim/mem_state.hh b/src/sim/mem_state.hh index 42823ce01..1ca80dab1 100644 --- a/src/sim/mem_state.hh +++ b/src/sim/mem_state.hh @@ -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. diff --git a/src/sim/syscall_emul.hh b/src/sim/syscall_emul.hh index 127085535..e1a23a087 100644 --- a/src/sim/syscall_emul.hh +++ b/src/sim/syscall_emul.hh @@ -876,7 +876,9 @@ openatFunc(SyscallDesc *desc, ThreadContext *tc, int sim_fd = -1; std::string used_path; std::vector 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);