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
// Copyright © 2020 Florian Schmaus
// Copyright © 2020-2021 Florian Schmaus
#include "ContextManager.hpp"
#include <cassert> // for assert
......@@ -9,12 +9,13 @@
#include "Debug.hpp" // for LOGD
#include "Dispatcher.hpp" // for Dispatcher
#include "Runtime.hpp" // for Runtime
#include "emper-common.h"
#include "emper-config.h" // // IWYU pragma: keep
class Fiber;
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) {
auto* context = new Context(this->runtime.dispatcher.getDispatchLoop());
putFreeContext(context);
......
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright © 2020 Florian Schmaus
// Copyright © 2020-2021 Florian Schmaus
#pragma once
#include "Common.hpp"
#include "Runtime.hpp"
#include "emper-common.h"
#include "lib/adt/BoundedBumpArray.hpp"
#include "lib/adt/WsClQueue.hpp"
......@@ -82,6 +83,6 @@ MemoryManager<T, WS_QUEUE_SIZE, WORKER_EXCLUSIVE_QUEUE_SIZE>::MemoryManager(Runt
: workerCount(runtime.getWorkerCount()) {
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);
}
......@@ -217,7 +217,7 @@ auto Runtime::workerLoop(Worker* worker) -> void* {
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();
......
......@@ -48,7 +48,7 @@ class Runtime : public Logger<LogSubsystem::RUNTI> {
const workerid_t workerCount;
std::vector<std::function<void(void)>> newWorkerHooks;
std::vector<std::function<void(workerid_t)>> newWorkerHooks;
Latch workerLatch;
......@@ -80,7 +80,9 @@ class Runtime : public Logger<LogSubsystem::RUNTI> {
static auto getDefaultWorkerCount() -> workerid_t;
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>
inline void wakeupSleepingWorkers() {
......
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright © 2020 Florian Schmaus
// Copyright © 2020-2021 Florian Schmaus
#include "Scheduler.hpp"
#include "CallerEnvironment.hpp"
......@@ -7,7 +7,7 @@
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);
}
......
......@@ -27,7 +27,7 @@ class Scheduler : public Logger<LogSubsystem::SCHED> {
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* {
return fiber.getAffinityBuffer();
......
......@@ -24,7 +24,7 @@ AbstractWorkStealingScheduler::AbstractWorkStealingScheduler(
const workerid_t workerCount = runtime.getWorkerCount();
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);
}
......
......@@ -9,6 +9,7 @@
#include "LawsStrategy.hpp" // IWYU pragma: keep
#include "NextFiberResult.hpp"
#include "Runtime.hpp"
#include "emper-common.h"
#define EMPER_OVERFLOW_QUEUE
......@@ -19,10 +20,7 @@ LawsScheduler::LawsScheduler(Runtime& runtime, LawsStrategy& lawsStrategy)
const workerid_t workerCount = runtime.getWorkerCount();
priorityQueues = new LawsScheduler::LawsMpscQueue*[workerCount];
auto newWorkerHook = [this]() {
workerid_t workerId = Runtime::getWorkerId();
priorityQueues[workerId] = &priorityQueue;
};
auto newWorkerHook = [this](workerid_t workerId) { priorityQueues[workerId] = &priorityQueue; };
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