From 9e3d97c0a7ebb47d98d09968d1edc003ce3f78b7 Mon Sep 17 00:00:00 2001
From: Florian Schmaus <flow@cs.fau.de>
Date: Mon, 10 May 2021 13:45:44 +0200
Subject: [PATCH] [AbstractWorkStealingScheduler] Check AnywhereQueue after a
 few steals

---
 emper/strategies/AbstractWorkStealingScheduler.cpp | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/emper/strategies/AbstractWorkStealingScheduler.cpp b/emper/strategies/AbstractWorkStealingScheduler.cpp
index 8e2bd3fd..e354a126 100644
--- a/emper/strategies/AbstractWorkStealingScheduler.cpp
+++ b/emper/strategies/AbstractWorkStealingScheduler.cpp
@@ -131,8 +131,13 @@ popBottom:
 	}
 
 	{
+		// TODO: Determine if there is a better value than 1/3.
+		const float CHECK_ANYWHERE_QUEUE_AT_PERCENTAGE = 0.33;
 		const workerid_t myWorkerId = Runtime::getWorkerId();
 		const workerid_t workerCount = runtime.getWorkerCount();
+		// NOLINTNEXTLINE(bugprone-narrowing-conversions)
+		const workerid_t checkAnywhereQueueAt = workerCount * CHECK_ANYWHERE_QUEUE_AT_PERCENTAGE;
+
 		workerid_t startWorkerId = Runtime::rand() % workerCount;
 		// TODO: See how reducing the loop bound affects things.
 		for (workerid_t i = 0; i < workerCount; ++i) {
@@ -151,6 +156,13 @@ popBottom:
 				fiberSource = FiberSource::stolen;
 				goto out;
 			}
+
+			// If we failed to steal from a certain number of victims, check
+			// the anywhere queue for new fibers.
+			if (i == checkAnywhereQueueAt) {
+				auto anywhereQueueFiber = nextFiberViaAnywhereQueue();
+				if (anywhereQueueFiber) return *anywhereQueueFiber;
+			}
 		}
 	}
 
-- 
GitLab