diff --git a/emper/strategies/laws/LawsScheduler.cpp b/emper/strategies/laws/LawsScheduler.cpp index 75f8d4684fb1ebeb80ebca896b705a0686430d6c..1432b3d017ca5c4f1990f68e84b90a36f092b78b 100644 --- a/emper/strategies/laws/LawsScheduler.cpp +++ b/emper/strategies/laws/LawsScheduler.cpp @@ -94,24 +94,29 @@ auto LawsScheduler::nextFiber() -> Fiber* { return fiber; } + // TODO: The code below is nearly duplicated, besides the statsk + // part, in WsScheduler, deduplicate. + const workerid_t myWorkerId = Runtime::getWorkerId(); const workerid_t workerCount = runtime.getWorkerCount(); workerid_t startWorkerId = Runtime::rand() % workerCount; + // TODO: See how reducing the loop bound affects things. + for (workerid_t i = 0; i < workerCount; ++i) { + workerid_t victim = (startWorkerId + i) % workerCount; - if (unlikely(startWorkerId == Runtime::getWorkerId())) startWorkerId++; - workerid_t victim = startWorkerId % workerCount; + // Don't steal from ourselves. + if (unlikely(victim == myWorkerId)) continue; - poped = queues[victim]->popTop(&fiber); - if (poped) { - if constexpr (emper::STATS) { - auto flag = static_cast<unsigned int>(LawsStrategy::FiberSource::stolen); - fiber->setFlag(flag); - } + poped = queues[victim]->popTop(&fiber); + if (poped) { + if constexpr (emper::STATS) { + auto flag = static_cast<unsigned int>(LawsStrategy::FiberSource::stolen); + fiber->setFlag(flag); + } - return fiber; + return fiber; + } } - // TODO: Reduce pressure on mainThreadQueue by only checking every N-th time. - // Try the "scheduled from anywhere" queue to get work as last resort. fiber = dequeFiberFromAnywhereQueue(); if (fiber) { diff --git a/emper/strategies/ws/WsScheduler.cpp b/emper/strategies/ws/WsScheduler.cpp index 2cb8a1d16a7dc475286428a516f1c1bf4ed9dd29..720a99a5838686951e9c10f7f00941509c87cb52 100644 --- a/emper/strategies/ws/WsScheduler.cpp +++ b/emper/strategies/ws/WsScheduler.cpp @@ -54,6 +54,8 @@ auto WsScheduler::nextFiber() -> Fiber* { return fiber; } + // TODO: The code below is nearly duplicated, besides the stats + // part, in LawsScheduler, deduplicate. const workerid_t myWorkerId = Runtime::getWorkerId(); const workerid_t workerCount = runtime.getWorkerCount(); workerid_t startWorkerId = Runtime::rand() % workerCount;