diff --git a/emper/strategies/laws/LawsScheduler.cpp b/emper/strategies/laws/LawsScheduler.cpp index 3bf7079a8e0bc7d0ba625c792d91f53d8c1008be..138d9ef47a7f6c3016e44a02781bcbab66def4dc 100644 --- a/emper/strategies/laws/LawsScheduler.cpp +++ b/emper/strategies/laws/LawsScheduler.cpp @@ -22,34 +22,40 @@ LawsScheduler::LawsScheduler(Runtime& runtime) : AbstractWorkStealingScheduler(r addNewWorkerHook(newWorkerHook); } +template <CallerEnvironment callerEnvironment> void LawsScheduler::tryScheduleToPriorityQueue(Fiber& fiber) { workeraffinity_t* const affinity_buffer = getAffinityBuffer(fiber); - if (affinity_buffer) { - workeraffinity_t affinity = *affinity_buffer; + if (!affinity_buffer) { + return; + } + + workeraffinity_t affinity = *affinity_buffer; + + if constexpr (callerEnvironment == CallerEnvironment::EMPER) { workerid_t workerId = Runtime::getWorkerId(); if (affinity == workerId) { return; } + } - if (affinity == Fiber::NOT_AFFINE) { - return; - } + if (affinity == Fiber::NOT_AFFINE) { + return; + } - // We found a fiber to schedule on a remote prority queue. - increaseRefCount(fiber); - priorityQueues[affinity]->enqueue(&fiber); + // We found a fiber to schedule on a remote prority queue. + increaseRefCount(fiber); + priorityQueues[affinity]->enqueue(&fiber); - emper::statsIncr(LawsStrategy::stats.scheduledFibersToPriority); - } + emper::statsIncr(LawsStrategy::stats.scheduledFibersToPriority); } void LawsScheduler::scheduleInternal(Fiber& fiber) { - tryScheduleToPriorityQueue(fiber); + tryScheduleToPriorityQueue<CallerEnvironment::EMPER>(fiber); scheduleViaWorkStealing(fiber); } void LawsScheduler::scheduleFromAnywhereInternal(Fiber& fiber) { - tryScheduleToPriorityQueue(fiber); + tryScheduleToPriorityQueue<CallerEnvironment::ANYWHERE>(fiber); enqueueInAnywhereQueue(fiber); onNewWork<CallerEnvironment::ANYWHERE>(); } @@ -57,7 +63,7 @@ void LawsScheduler::scheduleFromAnywhereInternal(Fiber& fiber) { void LawsScheduler::scheduleFromAnywhereInternal(Fiber** fibers, unsigned count) { for (unsigned i = 0; i < count; ++i) { Fiber& fiber = *fibers[i]; - tryScheduleToPriorityQueue(fiber); + tryScheduleToPriorityQueue<CallerEnvironment::ANYWHERE>(fiber); } insertInAnywhereQueue(fibers, count); onNewWork<CallerEnvironment::ANYWHERE>(); diff --git a/emper/strategies/laws/LawsScheduler.hpp b/emper/strategies/laws/LawsScheduler.hpp index 43f7f12b2cf71ac7cc79ef6b319dc208e5a154cc..8f9c168288c1029435ccd936e7b4cc392f0b40a7 100644 --- a/emper/strategies/laws/LawsScheduler.hpp +++ b/emper/strategies/laws/LawsScheduler.hpp @@ -2,6 +2,7 @@ // Copyright © 2020-2021 Florian Schmaus #pragma once +#include "CallerEnvironment.hpp" #include "Fiber.hpp" #include "lib/adt/MpscQueue.hpp" #include "strategies/AbstractWorkStealingScheduler.hpp" @@ -17,6 +18,7 @@ class LawsScheduler : public AbstractWorkStealingScheduler { static thread_local LawsMpscQueue priorityQueue; + template <CallerEnvironment callerEnvironment> void tryScheduleToPriorityQueue(Fiber& fiber); protected: