From 51d1518dd678eee119fc221b2ab34cb6617a615f Mon Sep 17 00:00:00 2001
From: Florian Fischer <florian.fl.fischer@fau.de>
Date: Mon, 4 Jan 2021 11:32:40 +0100
Subject: [PATCH] make worker wakeup strategy compile time configurable

---
 emper/Emper.hpp   |  8 ++++++++
 emper/Runtime.hpp | 10 ++++++++--
 meson.build       |  1 +
 meson_options.txt |  7 +++++++
 4 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/emper/Emper.hpp b/emper/Emper.hpp
index 0b595e2f..fb560a5e 100644
--- a/emper/Emper.hpp
+++ b/emper/Emper.hpp
@@ -23,6 +23,14 @@ static const bool WORKER_SLEEP =
 		false
 #endif
 		;
+enum class WorkerWakeupStrategy { one, all };
+static const enum WorkerWakeupStrategy WORKER_WAKEUP_STRATEGY =
+#ifdef EMPER_WORKER_WAKEUP_ALL
+		WorkerWakeupStrategy::all
+#else
+		WorkerWakeupStrategy::one
+#endif
+		;
 
 static const bool LIBURCU =
 #ifdef EMPER_LIBURCU
diff --git a/emper/Runtime.hpp b/emper/Runtime.hpp
index c92bfc43..77afac48 100644
--- a/emper/Runtime.hpp
+++ b/emper/Runtime.hpp
@@ -17,6 +17,7 @@
 
 #include "Common.hpp"			// for ALIGN_TO_CACHE_LINE
 #include "Debug.hpp"			// for LogSubsystem, LogSubsystem::RUNTI, Logger
+#include "Emper.hpp"			// for WORKER_NOTIFY
 #include "Scheduler.hpp"	// for Scheduler
 #include "Worker.hpp"
 #include "emper-common.h"			 // for workerid_t
@@ -86,8 +87,13 @@ class Runtime : public Logger<LogSubsystem::RUNTI> {
 
 		std::lock_guard<std::mutex> lk(workerSleepMutex);
 		skipSleep = true;
-		sleepingWorkers.fetch_sub(1, std::memory_order_relaxed);
-		workerSleepConditionVariable.notify_one();
+		if constexpr (emper::WORKER_WAKEUP_STRATEGY == emper::WorkerWakeupStrategy::all) {
+			sleepingWorkers.store(0, std::memory_order_relaxed);
+			workerSleepConditionVariable.notify_all();
+		} else {
+			sleepingWorkers.fetch_sub(1, std::memory_order_relaxed);
+			workerSleepConditionVariable.notify_one();
+		}
 	}
 
 	void dispatcherLoopSleep() {
diff --git a/meson.build b/meson.build
index 06b758c8..80b41e60 100644
--- a/meson.build
+++ b/meson.build
@@ -26,6 +26,7 @@ if option_urcu
 endif
 
 conf_data.set('EMPER_WORKER_SLEEP', get_option('worker_sleep'))
+conf_data.set('EMPER_WORKER_WAKEUP_ALL', get_option('worker_wakeup_strategy') == 'all')
 conf_data.set('EMPER_LOCKED_WS_QUEUE', get_option('locked_ws_queue'))
 conf_data.set('EMPER_OVERFLOW_QUEUE', get_option('overflow_queue'))
 conf_data.set('EMPER_LOCKED_MPSC_QUEUE', get_option('locked_mpsc_queue'))
diff --git a/meson_options.txt b/meson_options.txt
index 1eb8a304..8ae9ba0e 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -16,6 +16,13 @@ option(
   value: true,
   description: 'Enable sleeping worker support',
 )
+option(
+  'worker_wakeup_strategy',
+  type: 'combo',
+  description: 'How many workers should be signaled onNewWork',
+  choices: ['one', 'all'],
+  value: 'one',
+)
 option(
   'locked_ws_queue',
   type: 'boolean',
-- 
GitLab