Skip to content
Snippets Groups Projects
Commit 41446763 authored by Florian Schmaus's avatar Florian Schmaus
Browse files

[LAWS] Attempt to steal from all other workers instead of just one

The LAWS strategy, unlike the WS strategy, previously only attempted
to steal from one victim, instead of trying all other workers. This
probably caused SimpleActorTest to sporadically timeout, as all
workers went to sleep.

With this change, LAWS attempts, just like WS, to steal from all other
workers. In a next step, we may want to reduce the duplicated code
resulting from this.

Fixes #6.
parent 3785a5d9
No related branches found
No related tags found
No related merge requests found
Pipeline #55684 passed
......@@ -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) {
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment