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

Provider worker ID as argument in "new worker" hook

parent f2a2a12f
No related branches found
No related tags found
1 merge request!138Provider worker ID in "new worker" hook and change workerid_t from uint8_t to uint16_t.
// SPDX-License-Identifier: LGPL-3.0-or-later // SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright © 2020 Florian Schmaus // Copyright © 2020-2021 Florian Schmaus
#include "ContextManager.hpp" #include "ContextManager.hpp"
#include <cassert> // for assert #include <cassert> // for assert
...@@ -9,12 +9,13 @@ ...@@ -9,12 +9,13 @@
#include "Debug.hpp" // for LOGD #include "Debug.hpp" // for LOGD
#include "Dispatcher.hpp" // for Dispatcher #include "Dispatcher.hpp" // for Dispatcher
#include "Runtime.hpp" // for Runtime #include "Runtime.hpp" // for Runtime
#include "emper-common.h"
#include "emper-config.h" // // IWYU pragma: keep #include "emper-config.h" // // IWYU pragma: keep
class Fiber; class Fiber;
ContextManager::ContextManager(Runtime& runtime) : MemoryManager(runtime), runtime(runtime) { ContextManager::ContextManager(Runtime& runtime) : MemoryManager(runtime), runtime(runtime) {
auto newWorkerHook = [this]() { auto newWorkerHook = [this](ATTR_UNUSED workerid_t workerId) {
for (unsigned int i = 0; i < CONTEXT_MANAGER_FIRST_LAYER_QUEUE_SIZE * 2; ++i) { for (unsigned int i = 0; i < CONTEXT_MANAGER_FIRST_LAYER_QUEUE_SIZE * 2; ++i) {
auto* context = new Context(this->runtime.dispatcher.getDispatchLoop()); auto* context = new Context(this->runtime.dispatcher.getDispatchLoop());
putFreeContext(context); putFreeContext(context);
......
// SPDX-License-Identifier: LGPL-3.0-or-later // SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright © 2020 Florian Schmaus // Copyright © 2020-2021 Florian Schmaus
#pragma once #pragma once
#include "Common.hpp" #include "Common.hpp"
#include "Runtime.hpp" #include "Runtime.hpp"
#include "emper-common.h"
#include "lib/adt/BoundedBumpArray.hpp" #include "lib/adt/BoundedBumpArray.hpp"
#include "lib/adt/WsClQueue.hpp" #include "lib/adt/WsClQueue.hpp"
...@@ -82,6 +83,6 @@ MemoryManager<T, WS_QUEUE_SIZE, WORKER_EXCLUSIVE_QUEUE_SIZE>::MemoryManager(Runt ...@@ -82,6 +83,6 @@ MemoryManager<T, WS_QUEUE_SIZE, WORKER_EXCLUSIVE_QUEUE_SIZE>::MemoryManager(Runt
: workerCount(runtime.getWorkerCount()) { : workerCount(runtime.getWorkerCount()) {
queues = new adt::WsClQueue<void*, WS_QUEUE_SIZE>*[workerCount]; queues = new adt::WsClQueue<void*, WS_QUEUE_SIZE>*[workerCount];
auto newWorkerHook = [this]() { queues[Runtime::getWorkerId()] = &queue; }; auto newWorkerHook = [this](workerid_t workerId) { queues[workerId] = &queue; };
runtime.addNewWorkerHook(newWorkerHook); runtime.addNewWorkerHook(newWorkerHook);
} }
...@@ -217,7 +217,7 @@ auto Runtime::workerLoop(Worker* worker) -> void* { ...@@ -217,7 +217,7 @@ auto Runtime::workerLoop(Worker* worker) -> void* {
DIE_MSG_ERRNO("pthread_setcanceltype() failed"); DIE_MSG_ERRNO("pthread_setcanceltype() failed");
} }
for (const auto& f : newWorkerHooks) f(); for (const auto& f : newWorkerHooks) f(worker->workerId);
workerLatch.count_down_and_wait(); workerLatch.count_down_and_wait();
......
...@@ -48,7 +48,7 @@ class Runtime : public Logger<LogSubsystem::RUNTI> { ...@@ -48,7 +48,7 @@ class Runtime : public Logger<LogSubsystem::RUNTI> {
const workerid_t workerCount; const workerid_t workerCount;
std::vector<std::function<void(void)>> newWorkerHooks; std::vector<std::function<void(workerid_t)>> newWorkerHooks;
Latch workerLatch; Latch workerLatch;
...@@ -80,7 +80,9 @@ class Runtime : public Logger<LogSubsystem::RUNTI> { ...@@ -80,7 +80,9 @@ class Runtime : public Logger<LogSubsystem::RUNTI> {
static auto getDefaultWorkerCount() -> workerid_t; static auto getDefaultWorkerCount() -> workerid_t;
protected: protected:
void addNewWorkerHook(const std::function<void(void)>& hook) { newWorkerHooks.push_back(hook); }; void addNewWorkerHook(const std::function<void(workerid_t)>& hook) {
newWorkerHooks.push_back(hook);
};
template <CallerEnvironment callerEnvironment = CallerEnvironment::EMPER> template <CallerEnvironment callerEnvironment = CallerEnvironment::EMPER>
inline void wakeupSleepingWorkers() { inline void wakeupSleepingWorkers() {
......
// SPDX-License-Identifier: LGPL-3.0-or-later // SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright © 2020 Florian Schmaus // Copyright © 2020-2021 Florian Schmaus
#include "Scheduler.hpp" #include "Scheduler.hpp"
#include "CallerEnvironment.hpp" #include "CallerEnvironment.hpp"
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
Scheduler::Scheduler(Runtime& runtime) : runtime(runtime) {} Scheduler::Scheduler(Runtime& runtime) : runtime(runtime) {}
void Scheduler::addNewWorkerHook(const std::function<void(void)>& hook) { void Scheduler::addNewWorkerHook(const std::function<void(workerid_t)>& hook) {
runtime.addNewWorkerHook(hook); runtime.addNewWorkerHook(hook);
} }
......
...@@ -27,7 +27,7 @@ class Scheduler : public Logger<LogSubsystem::SCHED> { ...@@ -27,7 +27,7 @@ class Scheduler : public Logger<LogSubsystem::SCHED> {
virtual ~Scheduler() = default; virtual ~Scheduler() = default;
void addNewWorkerHook(const std::function<void(void)>& hook); void addNewWorkerHook(const std::function<void(workerid_t)>& hook);
static inline auto getAffinityBuffer(Fiber& fiber) -> workeraffinity_t* { static inline auto getAffinityBuffer(Fiber& fiber) -> workeraffinity_t* {
return fiber.getAffinityBuffer(); return fiber.getAffinityBuffer();
......
...@@ -24,7 +24,7 @@ AbstractWorkStealingScheduler::AbstractWorkStealingScheduler( ...@@ -24,7 +24,7 @@ AbstractWorkStealingScheduler::AbstractWorkStealingScheduler(
const workerid_t workerCount = runtime.getWorkerCount(); const workerid_t workerCount = runtime.getWorkerCount();
queues = new AbstractWorkStealingScheduler::WsQueue<QUEUE_SIZE>*[workerCount]; queues = new AbstractWorkStealingScheduler::WsQueue<QUEUE_SIZE>*[workerCount];
auto newWorkerHook = [this]() { queues[Runtime::getWorkerId()] = &queue; }; auto newWorkerHook = [this](workerid_t workerId) { queues[workerId] = &queue; };
addNewWorkerHook(newWorkerHook); addNewWorkerHook(newWorkerHook);
} }
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "LawsStrategy.hpp" // IWYU pragma: keep #include "LawsStrategy.hpp" // IWYU pragma: keep
#include "NextFiberResult.hpp" #include "NextFiberResult.hpp"
#include "Runtime.hpp" #include "Runtime.hpp"
#include "emper-common.h"
#define EMPER_OVERFLOW_QUEUE #define EMPER_OVERFLOW_QUEUE
...@@ -19,10 +20,7 @@ LawsScheduler::LawsScheduler(Runtime& runtime, LawsStrategy& lawsStrategy) ...@@ -19,10 +20,7 @@ LawsScheduler::LawsScheduler(Runtime& runtime, LawsStrategy& lawsStrategy)
const workerid_t workerCount = runtime.getWorkerCount(); const workerid_t workerCount = runtime.getWorkerCount();
priorityQueues = new LawsScheduler::LawsMpscQueue*[workerCount]; priorityQueues = new LawsScheduler::LawsMpscQueue*[workerCount];
auto newWorkerHook = [this]() { auto newWorkerHook = [this](workerid_t workerId) { priorityQueues[workerId] = &priorityQueue; };
workerid_t workerId = Runtime::getWorkerId();
priorityQueues[workerId] = &priorityQueue;
};
addNewWorkerHook(newWorkerHook); addNewWorkerHook(newWorkerHook);
} }
......
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