[gem5-dev] Change in gem5/gem5[develop]: sim-se: Add special paths for MPI, libnuma, ROCm support
Matthew Poremba has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/25367 ) Change subject: sim-se: Add special paths for MPI, libnuma, ROCm support .. 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 <345032938...@cloudbuild.gserviceaccount.com> Reviewed-by: Jason Lowe-Power --- M src/kern/linux/linux.cc M src/kern/linux/linux.hh M src/sim/mem_state.cc M src/sim/mem_state.hh M src/sim/syscall_emul.hh 5 files changed, 77 insertions(+), 3 deletions(-) Approvals: Jason Lowe-Power: Looks good to me, approved Brandon Potter: Looks good to me, approved Gem5 Cloud Project GCB service account: Regressions pass diff --git a/src/kern/linux/linux.cc b/src/kern/linux/linux.cc index 1a8c241..ae1d47c 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 @@ } 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 @@ 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 4b45b8b..5370e2b 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 @@ 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 a6177c3..42d3781 100644 --- a/src/sim/mem_state.cc +++ b/src/sim/mem_state.cc @@ -473,3 +473,20 @@ 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 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 42823ce..1ca80da 100644 --- a/src/sim/mem_state.hh +++
[gem5-dev] Change in gem5/gem5[develop]: sim-se: Add special paths for MPI, libnuma, ROCm support
Matthew Poremba has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/25367 ) Change subject: sim-se: Add special paths for MPI, libnuma, ROCm support .. 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 --- M src/kern/linux/linux.cc M src/kern/linux/linux.hh M src/sim/syscall_emul.hh 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/src/kern/linux/linux.cc b/src/kern/linux/linux.cc index e499776..c37daa1 100644 --- a/src/kern/linux/linux.cc +++ b/src/kern/linux/linux.cc @@ -35,8 +35,10 @@ #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" int Linux::openSpecialFile(std::string path, Process *process, @@ -55,6 +57,15 @@ } 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) { @@ -87,3 +98,47 @@ return csprintf("gem5-user:x:1000:1000:gem5-user,,,:%s:/bin/bash\n", process->tgtCwd); } + +std::string +Linux::procSelfMaps(Process *process, ThreadContext *tc) +{ +std::stringstream file_content; +auto memState = process->getMemState(); + +for (auto vma : memState->vmaList()) { +std::stringstream line; +line << std::hex << vma.start() << "-"; +line << std::hex << vma.end() << " "; +line << "r-xp 00:00 0 "; +line << "[" << vma.getName() << "]" << std::endl; +file_content << line.str(); +} + +return file_content.str(); +} + +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 seed = 1234; +srand(0); +int max = 1E5; +for (int i = 0; i (rand()) / +(static_cast (RAND_MAX/seed)); + +line << (char)rand_fl; +} +return line.str(); +} diff --git a/src/kern/linux/linux.hh b/src/kern/linux/linux.hh index 9325301..c855d57 100644 --- a/src/kern/linux/linux.hh +++ b/src/kern/linux/linux.hh @@ -236,7 +236,9 @@ 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/syscall_emul.hh b/src/sim/syscall_emul.hh index 53b86e2..1ce5351 100644 --- a/src/sim/syscall_emul.hh +++ b/src/sim/syscall_emul.hh @@ -911,7 +911,9 @@ 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); -- To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/25367 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: I00a82788cff9d6f4f16fc56230b18be9b76c4015 Gerrit-Change-Number: 25367 Gerrit-PatchSet: 1 Gerrit-Owner: Matthew Poremba Gerrit-MessageType: newchange ___ gem5-dev mailing list gem5-dev@gem5.org http://m5sim.org/mailman/listinfo/gem5-dev