Austin Harris has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/50007 )
Change subject: sim: Fix fork for multithreaded simulations
......................................................................
sim: Fix fork for multithreaded simulations
Previously, when forking, the thread states were inconsistent.
Now, after a fork, we re-create all the needed threads.
This allows you to run in *single-threaded* mode after a fork.
There would need to be a way to migrate the threads to conintue
in threaded mode.
Change-Id: I399da55de929d3314b45213c0c15fa44d492938c
---
M src/sim/simulate.cc
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/src/sim/simulate.cc b/src/sim/simulate.cc
index 4a00869..c4c8a36 100644
--- a/src/sim/simulate.cc
+++ b/src/sim/simulate.cc
@@ -30,6 +30,8 @@
#include "sim/simulate.hh"
+#include <unistd.h>
+
#include <mutex>
#include <thread>
@@ -84,11 +86,12 @@
{
// The first time simulate() is called from the Python code, we need to
// create a thread for each of event queues referenced by the
- // instantiated sim objects.
- static bool threads_initialized = false;
+ // instantiated sim objects. In fact, this needs to be done for each
new
+ // process we create (e.g., with fork())
+ static int threads_initialized_pid = 0;
static std::vector<std::thread *> threads;
- if (!threads_initialized) {
+ if (threads_initialized_pid != getpid()) {
threadBarrier = new Barrier(numMainEventQueues);
// the main thread (the one we're currently running on)
@@ -98,7 +101,7 @@
threads.push_back(new std::thread(thread_loop,
mainEventQueue[i]));
}
- threads_initialized = true;
+ threads_initialized_pid = getpid();
simulate_limit_event =
new GlobalSimLoopExitEvent(mainEventQueue[0]->getCurTick(),
"simulate() limit reached", 0);
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/50007
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: I399da55de929d3314b45213c0c15fa44d492938c
Gerrit-Change-Number: 50007
Gerrit-PatchSet: 1
Gerrit-Owner: Austin Harris <[email protected]>
Gerrit-CC: Jason Lowe-Power <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s