[gem5-dev] Change in gem5/gem5[develop]: mem: Optionally share the backing store
Boris Shingarov has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/30994 ) Change subject: mem: Optionally share the backing store .. mem: Optionally share the backing store This patch adds the ability for a host-OS process external to gem5 to access the backing store via POSIX shared memory. The new param shared_backstore of the System object is the filename of the shared memory (i.e., the first argument to shm_open()). Change-Id: I98c948a32a15049a4515e6c02a14595fb5fe379f Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/30994 Reviewed-by: Jason Lowe-Power Maintainer: Jason Lowe-Power Tested-by: kokoro --- M src/mem/physical.cc M src/mem/physical.hh M src/sim/System.py M src/sim/system.cc 4 files changed, 32 insertions(+), 6 deletions(-) Approvals: Jason Lowe-Power: Looks good to me, approved; Looks good to me, approved kokoro: Regressions pass diff --git a/src/mem/physical.cc b/src/mem/physical.cc index 4bd812c..a03f200 100644 --- a/src/mem/physical.cc +++ b/src/mem/physical.cc @@ -71,8 +71,10 @@ PhysicalMemory::PhysicalMemory(const string& _name, const vector& _memories, - bool mmap_using_noreserve) : -_name(_name), size(0), mmapUsingNoReserve(mmap_using_noreserve) + bool mmap_using_noreserve, + const std::string& shared_backstore) : +_name(_name), size(0), mmapUsingNoReserve(mmap_using_noreserve), +sharedBackstore(shared_backstore) { if (mmap_using_noreserve) warn("Not reserving swap space. May cause SIGSEGV on actual usage\n"); @@ -192,7 +194,23 @@ // perform the actual mmap DPRINTF(AddrRanges, "Creating backing store for range %s with size %d\n", range.to_string(), range.size()); -int map_flags = MAP_ANON | MAP_PRIVATE; + +int shm_fd; +int map_flags; + +if (sharedBackstore.empty()) { +shm_fd = -1; +map_flags = MAP_ANON | MAP_PRIVATE; +} else { +DPRINTF(AddrRanges, "Sharing backing store as %s\n", +sharedBackstore.c_str()); +shm_fd = shm_open(sharedBackstore.c_str(), O_CREAT | O_RDWR, 0666); +if (shm_fd == -1) + panic("Shared memory failed"); +if (ftruncate(shm_fd, range.size())) + panic("Setting size of shared memory failed"); +map_flags = MAP_SHARED; +} // to be able to simulate very large memories, the user can opt to // pass noreserve to mmap @@ -202,7 +220,7 @@ uint8_t* pmem = (uint8_t*) mmap(NULL, range.size(), PROT_READ | PROT_WRITE, -map_flags, -1, 0); +map_flags, shm_fd, 0); if (pmem == (uint8_t*) MAP_FAILED) { perror("mmap"); diff --git a/src/mem/physical.hh b/src/mem/physical.hh index 88a5cda..9d4ff9a 100644 --- a/src/mem/physical.hh +++ b/src/mem/physical.hh @@ -127,6 +127,8 @@ // Let the user choose if we reserve swap space when calling mmap const bool mmapUsingNoReserve; +const std::string sharedBackstore; + // The physical memory used to provide the memory in the simulated // system std::vector backingStore; @@ -158,7 +160,8 @@ */ PhysicalMemory(const std::string& _name, const std::vector& _memories, - bool mmap_using_noreserve); + bool mmap_using_noreserve, + const std::string& shared_backstore); /** * Unmap all the backing store we have used. diff --git a/src/sim/System.py b/src/sim/System.py index 61fbe0e..e028f48 100644 --- a/src/sim/System.py +++ b/src/sim/System.py @@ -78,6 +78,10 @@ # I/O bridge or cache mem_ranges = VectorParam.AddrRange([], "Ranges that constitute main memory") +shared_backstore = Param.String("", "backstore's shmem segment filename, " +"use to directly address the backstore from another host-OS process. " +"Leave this empty to unset the MAP_SHARED flag.") + cache_line_size = Param.Unsigned(64, "Cache line size in bytes") redirect_paths = VectorParam.RedirectPath([], "Path redirections") diff --git a/src/sim/system.cc b/src/sim/system.cc index 7841ec0..4e3416e 100644 --- a/src/sim/system.cc +++ b/src/sim/system.cc @@ -213,7 +213,8 @@ #else kvmVM(nullptr), #endif - physmem(name() + ".physmem", p->memories, p->mmap_using_noreserve), + physmem(name() + ".physmem", p->memories, p->mmap_using_noreserve, + p->shared_backstore), memoryMode(p->mem_mode), _cacheLineSize(p->cache_line_size), workItemsBegin(0), -- To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/30994 To unsubscribe, or for help writing mail filters, visit
[gem5-dev] Change in gem5/gem5[develop]: mem: Optionally share the backing store
Boris Shingarov has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/30994 ) Change subject: mem: Optionally share the backing store .. mem: Optionally share the backing store This patch adds the ability for a host-OS process external to gem5 to access the backing store via POSIX shared memory. The new param shared_backstore of the System object is the filename of the shared memory (i.e., the first argument to shm_open()). Change-Id: I98c948a32a15049a4515e6c02a14595fb5fe379f --- M src/mem/physical.cc M src/mem/physical.hh M src/sim/System.py M src/sim/system.cc 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/mem/physical.cc b/src/mem/physical.cc index 4bd812c..80632ce 100644 --- a/src/mem/physical.cc +++ b/src/mem/physical.cc @@ -71,8 +71,10 @@ PhysicalMemory::PhysicalMemory(const string& _name, const vector& _memories, - bool mmap_using_noreserve) : -_name(_name), size(0), mmapUsingNoReserve(mmap_using_noreserve) + bool mmap_using_noreserve, + const std::string& shared_backstore) : +_name(_name), size(0), mmapUsingNoReserve(mmap_using_noreserve), +sharedBackstore(shared_backstore) { if (mmap_using_noreserve) warn("Not reserving swap space. May cause SIGSEGV on actual usage\n"); @@ -192,7 +194,22 @@ // perform the actual mmap DPRINTF(AddrRanges, "Creating backing store for range %s with size %d\n", range.to_string(), range.size()); -int map_flags = MAP_ANON | MAP_PRIVATE; + +int shm_fd; +int map_flags; + +if (sharedBackstore.empty()) { +shm_fd = -1; +map_flags = MAP_ANON | MAP_PRIVATE; +} else { +DPRINTF(AddrRanges, "Sharing backing store as %s\n", +sharedBackstore.c_str()); +shm_fd = shm_open(sharedBackstore.c_str(), O_CREAT | O_RDWR, 0666); +if (shm_fd == -1) + panic("Shared memory failed"); +ftruncate(shm_fd, range.size()); +map_flags = MAP_SHARED; +} // to be able to simulate very large memories, the user can opt to // pass noreserve to mmap @@ -202,7 +219,7 @@ uint8_t* pmem = (uint8_t*) mmap(NULL, range.size(), PROT_READ | PROT_WRITE, -map_flags, -1, 0); +map_flags, shm_fd, 0); if (pmem == (uint8_t*) MAP_FAILED) { perror("mmap"); diff --git a/src/mem/physical.hh b/src/mem/physical.hh index 88a5cda..9d4ff9a 100644 --- a/src/mem/physical.hh +++ b/src/mem/physical.hh @@ -127,6 +127,8 @@ // Let the user choose if we reserve swap space when calling mmap const bool mmapUsingNoReserve; +const std::string sharedBackstore; + // The physical memory used to provide the memory in the simulated // system std::vector backingStore; @@ -158,7 +160,8 @@ */ PhysicalMemory(const std::string& _name, const std::vector& _memories, - bool mmap_using_noreserve); + bool mmap_using_noreserve, + const std::string& shared_backstore); /** * Unmap all the backing store we have used. diff --git a/src/sim/System.py b/src/sim/System.py index 61fbe0e..36b7e3f 100644 --- a/src/sim/System.py +++ b/src/sim/System.py @@ -78,6 +78,8 @@ # I/O bridge or cache mem_ranges = VectorParam.AddrRange([], "Ranges that constitute main memory") +shared_backstore = Param.String("", "backstore's shmem segment filename") + cache_line_size = Param.Unsigned(64, "Cache line size in bytes") redirect_paths = VectorParam.RedirectPath([], "Path redirections") diff --git a/src/sim/system.cc b/src/sim/system.cc index 7057a97..5f5ab54 100644 --- a/src/sim/system.cc +++ b/src/sim/system.cc @@ -213,7 +213,8 @@ #else kvmVM(nullptr), #endif - physmem(name() + ".physmem", p->memories, p->mmap_using_noreserve), + physmem(name() + ".physmem", p->memories, p->mmap_using_noreserve, + p->shared_backstore), memoryMode(p->mem_mode), _cacheLineSize(p->cache_line_size), workItemsBegin(0), -- To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/30994 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: I98c948a32a15049a4515e6c02a14595fb5fe379f Gerrit-Change-Number: 30994 Gerrit-PatchSet: 1 Gerrit-Owner: Boris Shingarov Gerrit-MessageType: newchange ___ gem5-dev mailing list -- gem5-dev@gem5.org To unsubscribe send an email to gem5-dev-le...@gem5.org %(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s