systemc: avoid mutex lock in non async cases
authorEarl Ou <shunhsingou@google.com>
Thu, 17 Sep 2020 06:31:44 +0000 (14:31 +0800)
committerEarl Ou <shunhsingou@google.com>
Wed, 23 Sep 2020 04:05:03 +0000 (04:05 +0000)
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 <shunhsingou@google.com>
Maintainer: Earl Ou <shunhsingou@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
src/systemc/core/scheduler.cc
src/systemc/core/scheduler.hh

index 50a1e6bd3449741fd1f7bcd895f83558c7f20bd4..cc0be7cd4c1ba8f199f98dd43b927b55980eb680 100644 (file)
@@ -259,6 +259,7 @@ Scheduler::asyncRequestUpdate(Channel *c)
 {
     std::lock_guard<std::mutex> lock(asyncListMutex);
     asyncUpdateList.pushLast(c);
+    hasAsyncUpdate = true;
 }
 
 void
@@ -325,11 +326,12 @@ void
 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 {
index 742f9163824152ec074887a08f9691452fb4a01c..13f35ed5f548ad568b7330f3dd3eebb5b3e8962e 100644 (file)
@@ -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 @@ class Scheduler
 
     ChannelList asyncUpdateList;
     std::mutex asyncListMutex;
+    std::atomic<bool> hasAsyncUpdate;
 
     std::map<::Event *, Tick> eventsToSchedule;