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 <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>
This commit is contained in:
Matthew Poremba
2020-02-13 11:27:07 -08:00
parent 20189987ef
commit 209c0663d5
5 changed files with 77 additions and 3 deletions

View File

@@ -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<uint8_t>(0, 255);
line << rand_uint;
}
return line.str();
}

View File

@@ -29,10 +29,10 @@
#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;

View 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();
}

View 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.

View 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);