[gem5-dev] [S] Change in gem5/gem5[develop]: sim: handle async events in main thread only

2023-02-07 Thread Earl Ou (Gerrit) via gem5-dev
Earl Ou has submitted this change. (  
https://gem5-review.googlesource.com/c/public/gem5/+/67533?usp=email )


Change subject: sim: handle async events in main thread only
..

sim: handle async events in main thread only

In the current implementation pollqueue is not thread safe. The design
of multi threads handle async events is thus causing issue in parallel
environment. Given the low rate of async events, it should be OK to only
handle them in the main thread to avoid unexpected racing issues.

Change-Id: Iddd512235e84e9d77f60985bb1771aa4cc693004
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/67533
Reviewed-by: Gabe Black 
Reviewed-by: Yu-hsin Wang 
Maintainer: Gabe Black 
Tested-by: kokoro 
---
M src/sim/simulate.cc
1 file changed, 23 insertions(+), 24 deletions(-)

Approvals:
  Yu-hsin Wang: Looks good to me, but someone else must approve
  Gabe Black: Looks good to me, approved; Looks good to me, approved
  kokoro: Regressions pass




diff --git a/src/sim/simulate.cc b/src/sim/simulate.cc
index 86d516d..abd2b1d 100644
--- a/src/sim/simulate.cc
+++ b/src/sim/simulate.cc
@@ -43,7 +43,6 @@
 #include "sim/simulate.hh"

 #include 
-#include 
 #include 

 #include "base/logging.hh"
@@ -274,28 +273,6 @@


 /**
- * Test and clear the global async_event flag, such that each time the
- * flag is cleared, only one thread returns true (and thus is assigned
- * to handle the corresponding async event(s)).
- */
-static bool
-testAndClearAsyncEvent()
-{
-static std::mutex mutex;
-
-bool was_set = false;
-mutex.lock();
-
-if (async_event) {
-was_set = true;
-async_event = false;
-}
-
-mutex.unlock();
-return was_set;
-}
-
-/**
  * The main per-thread simulation loop. This loop is executed by all
  * simulation threads (the main thread and the subordinate threads) in
  * parallel.
@@ -307,6 +284,8 @@
 curEventQueue(eventq);
 eventq->handleAsyncInsertions();

+bool mainQueue = eventq == getEventQueue(0);
+
 while (1) {
 // there should always be at least one event (the SimLoopExitEvent
 // we just scheduled) in the queue
@@ -314,7 +293,8 @@
 assert(curTick() <= eventq->nextTick() &&
"event scheduled in the past");

-if (async_event && testAndClearAsyncEvent()) {
+if (mainQueue && async_event) {
+async_event = false;
 // Take the event queue lock in case any of the service
 // routines want to schedule new events.
 std::lock_guard lock(*eventq);

--
To view, visit  
https://gem5-review.googlesource.com/c/public/gem5/+/67533?usp=email
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: Iddd512235e84e9d77f60985bb1771aa4cc693004
Gerrit-Change-Number: 67533
Gerrit-PatchSet: 7
Gerrit-Owner: Earl Ou 
Gerrit-Reviewer: Earl Ou 
Gerrit-Reviewer: Gabe Black 
Gerrit-Reviewer: Jason Lowe-Power 
Gerrit-Reviewer: Yu-hsin Wang 
Gerrit-Reviewer: kokoro 
Gerrit-MessageType: merged
___
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org


[gem5-dev] [S] Change in gem5/gem5[develop]: sim: handle async events in main thread only

2023-02-01 Thread Earl Ou (Gerrit) via gem5-dev
Earl Ou has uploaded this change for review. (  
https://gem5-review.googlesource.com/c/public/gem5/+/67533?usp=email )



Change subject: sim: handle async events in main thread only
..

sim: handle async events in main thread only

Change-Id: Iddd512235e84e9d77f60985bb1771aa4cc693004
---
M src/sim/simulate.cc
1 file changed, 12 insertions(+), 1 deletion(-)



diff --git a/src/sim/simulate.cc b/src/sim/simulate.cc
index 86d516d..78ba33a 100644
--- a/src/sim/simulate.cc
+++ b/src/sim/simulate.cc
@@ -307,6 +307,8 @@
 curEventQueue(eventq);
 eventq->handleAsyncInsertions();

+bool mainQueue = eventq == getEventQueue(0);
+
 while (1) {
 // there should always be at least one event (the SimLoopExitEvent
 // we just scheduled) in the queue
@@ -314,7 +316,7 @@
 assert(curTick() <= eventq->nextTick() &&
"event scheduled in the past");

-if (async_event && testAndClearAsyncEvent()) {
+if (mainQueue && async_event && testAndClearAsyncEvent()) {
 // Take the event queue lock in case any of the service
 // routines want to schedule new events.
 std::lock_guard lock(*eventq);

--
To view, visit  
https://gem5-review.googlesource.com/c/public/gem5/+/67533?usp=email
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: Iddd512235e84e9d77f60985bb1771aa4cc693004
Gerrit-Change-Number: 67533
Gerrit-PatchSet: 1
Gerrit-Owner: Earl Ou 
Gerrit-MessageType: newchange
___
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org