Earl Ou has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/34695 )

Change subject: systemc: avoid mutex lock in non async cases
......................................................................

systemc: avoid mutex lock in non async cases

Avoid acquiring a mutex lock in case there is no async update in the
scheduler. This helps increasing simulation speed by about 4%.

Change-Id: I971c7bf1a1eeb46208eeee6e5da6385c907092b3
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/34695
Reviewed-by: Earl Ou <[email protected]>
Maintainer: Earl Ou <[email protected]>
Tested-by: kokoro <[email protected]>
---
M src/systemc/core/scheduler.cc
M src/systemc/core/scheduler.hh
2 files changed, 5 insertions(+), 1 deletion(-)

Approvals:
  Earl Ou: Looks good to me, approved; Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/systemc/core/scheduler.cc b/src/systemc/core/scheduler.cc
index 50a1e6b..cc0be7c 100644
--- a/src/systemc/core/scheduler.cc
+++ b/src/systemc/core/scheduler.cc
@@ -259,6 +259,7 @@
 {
     std::lock_guard<std::mutex> lock(asyncListMutex);
     asyncUpdateList.pushLast(c);
+    hasAsyncUpdate = true;
 }

 void
@@ -325,11 +326,12 @@
 Scheduler::runUpdate()
 {
     status(StatusUpdate);
-    {
+    if (hasAsyncUpdate) {
         std::lock_guard<std::mutex> lock(asyncListMutex);
         Channel *channel;
         while ((channel = asyncUpdateList.getNext()) != nullptr)
             updateList.pushLast(channel);
+        hasAsyncUpdate = false;
     }

     try {
diff --git a/src/systemc/core/scheduler.hh b/src/systemc/core/scheduler.hh
index 742f916..13f35ed 100644
--- a/src/systemc/core/scheduler.hh
+++ b/src/systemc/core/scheduler.hh
@@ -28,6 +28,7 @@
 #ifndef __SYSTEMC_CORE_SCHEDULER_HH__
 #define __SYSTEMC_CORE_SCHEDULER_HH__

+#include <atomic>
 #include <functional>
 #include <list>
 #include <map>
@@ -529,6 +530,7 @@

     ChannelList asyncUpdateList;
     std::mutex asyncListMutex;
+    std::atomic<bool> hasAsyncUpdate;

     std::map<::Event *, Tick> eventsToSchedule;


--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/34695
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: I971c7bf1a1eeb46208eeee6e5da6385c907092b3
Gerrit-Change-Number: 34695
Gerrit-PatchSet: 4
Gerrit-Owner: Earl Ou <[email protected]>
Gerrit-Reviewer: Earl Ou <[email protected]>
Gerrit-Reviewer: Gabe Black <[email protected]>
Gerrit-Reviewer: Yu-hsin Wang <[email protected]>
Gerrit-Reviewer: kokoro <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to