From b86461ce94f7e6cab8dc00393a30624dbf778b54 Mon Sep 17 00:00:00 2001 From: Earl Ou Date: Thu, 17 Sep 2020 14:31:44 +0800 Subject: [PATCH] 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 Maintainer: Earl Ou Tested-by: kokoro --- src/systemc/core/scheduler.cc | 4 +++- src/systemc/core/scheduler.hh | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/systemc/core/scheduler.cc b/src/systemc/core/scheduler.cc index 50a1e6bd3..cc0be7cd4 100644 --- a/src/systemc/core/scheduler.cc +++ b/src/systemc/core/scheduler.cc @@ -259,6 +259,7 @@ Scheduler::asyncRequestUpdate(Channel *c) { std::lock_guard lock(asyncListMutex); asyncUpdateList.pushLast(c); + hasAsyncUpdate = true; } void @@ -325,11 +326,12 @@ void Scheduler::runUpdate() { status(StatusUpdate); - { + if (hasAsyncUpdate) { std::lock_guard 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 742f91638..13f35ed5f 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 #include #include #include @@ -529,6 +530,7 @@ class Scheduler ChannelList asyncUpdateList; std::mutex asyncListMutex; + std::atomic hasAsyncUpdate; std::map<::Event *, Tick> eventsToSchedule; -- 2.30.2