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

Use "if constexpr" for EMPER_STATS compile-time feature

parent 6f9b8f88
No related branches found
No related tags found
No related merge requests found
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright © 2020 Florian Schmaus
#pragma once
#include <emper-config.h>
namespace emper {
static const bool STATS =
#ifdef EMPER_STATS
true
#else
false
#endif
;
} // namespace emper
......@@ -12,10 +12,11 @@
#include <cstdlib> // for rand, srand, abort
#include <memory> // for __shared_ptr_access, shared_ptr
#include "Common.hpp" // for DIE_MSG_ERRNO, DIE, DIE_MSG
#include "ContextManager.hpp" // for ContextManager
#include "Debug.hpp" // for DBG, ABORT, LOGD, LOGE
#include "Dispatcher.hpp" // for Dispatcher
#include "Common.hpp" // for DIE_MSG_ERRNO, DIE, DIE_MSG
#include "ContextManager.hpp" // for ContextManager
#include "Debug.hpp" // for DBG, ABORT, LOGD, LOGE
#include "Dispatcher.hpp" // for Dispatcher
#include "Emper.hpp"
#include "Fiber.hpp" // for Fiber
#include "RuntimeStrategy.hpp" // for RuntimeStrategy
#include "RuntimeStrategyStats.hpp" // for RuntimeStrategyStats
......@@ -80,12 +81,12 @@ Runtime::Runtime(workerid_t workerCount, RuntimeStrategy& strategy, unsigned int
if (errno) DIE_MSG_ERRNO("pthread_create() failed");
}
#ifdef EMPER_STATS
int res = std::atexit(&printLastRuntimeStats);
if (res) {
DIE_MSG("could not register printStats() with at_exit()");
if constexpr (emper::STATS) {
int res = std::atexit(&printLastRuntimeStats);
if (res) {
DIE_MSG("could not register printStats() with at_exit()");
}
}
#endif
}
Runtime::~Runtime() {
......
......@@ -2,11 +2,14 @@
// Copyright © 2020 Florian Schmaus
#include "LawsDispatcher.hpp"
#include "LawsStrategy.hpp" // IWYU pragma: keep
#include "Runtime.hpp"
#include "emper-config.h"
#include <atomic> // for atomic, memory_order_relaxed
class Fiber;
#include "Common.hpp" // for DIE_MSG
#include "Emper.hpp"
#include "Fiber.hpp" // for Fiber
#include "LawsStrategy.hpp" // for LawsStrategy, LawsStrategy::FiberSource
#include "Runtime.hpp"
#include "emper-config.h" // for EMPER_WORKER_SLEEP
void LawsDispatcher::dispatchLoop() {
while (true) {
......@@ -24,27 +27,28 @@ void LawsDispatcher::dispatchLoop() {
// boolean initialize to true in order to check if this fiber
// is runnable.
if (isRunnable(fiber)) {
#ifdef EMPER_STATS
LawsStrategy::FiberSource fiberSource =
static_cast<LawsStrategy::FiberSource>(fiber->getFlag());
switch (fiberSource) {
case LawsStrategy::FiberSource::fromPriority:
lawsStrategy.dispatchedFiberFromPriority.fetch_add(1, std::memory_order_relaxed);
break;
case LawsStrategy::FiberSource::fromLocal:
lawsStrategy.dispatchedFiberFromLocal.fetch_add(1, std::memory_order_relaxed);
break;
case LawsStrategy::FiberSource::stolen:
lawsStrategy.dispatchedFiberStolen.fetch_add(1, std::memory_order_relaxed);
break;
case LawsStrategy::FiberSource::mainThread:
lawsStrategy.dispatchedFiberFromMainThread.fetch_add(1, std::memory_order_relaxed);
break;
default:
DIE_MSG("Unknown fiber flag: " << flag);
break;
if constexpr (emper::STATS) {
LawsStrategy::FiberSource fiberSource =
static_cast<LawsStrategy::FiberSource>(fiber->getFlag());
switch (fiberSource) {
case LawsStrategy::FiberSource::fromPriority:
lawsStrategy.dispatchedFiberFromPriority.fetch_add(1, std::memory_order_relaxed);
break;
case LawsStrategy::FiberSource::fromLocal:
lawsStrategy.dispatchedFiberFromLocal.fetch_add(1, std::memory_order_relaxed);
break;
case LawsStrategy::FiberSource::stolen:
lawsStrategy.dispatchedFiberStolen.fetch_add(1, std::memory_order_relaxed);
break;
case LawsStrategy::FiberSource::mainThread:
lawsStrategy.dispatchedFiberFromMainThread.fetch_add(1, std::memory_order_relaxed);
break;
default:
DIE_MSG("Unknown fiber flag: " << flag);
break;
}
}
#endif
// The fiber was marked das runnable. Run it now.
dispatch(fiber);
// Update the affinity if one was set.
......
......@@ -2,11 +2,14 @@
// Copyright © 2020 Florian Schmaus
#include "LawsScheduler.hpp"
#include <atomic> // for atomic, memory_order_relaxed
#include "Common.hpp"
#include "Debug.hpp"
#include "Emper.hpp"
#include "LawsStrategy.hpp" // IWYU pragma: keep
#include "Runtime.hpp"
#include "emper-config.h"
#include "emper-config.h" // for EMPER_WORKER_SLEEP
#define EMPER_OVERFLOW_QUEUE
......@@ -47,9 +50,9 @@ void LawsScheduler::schedule(Fiber& fiber) {
// We found a fiber to schedule on a remote prority queue.
increaseRefCount(fiber);
priorityQueues[affinity]->enqueue(&fiber);
#ifdef EMPER_STATS
lawsStrategy.scheduledFibersToRemotePriority.fetch_add(1, std::memory_order_relaxed);
#endif
if constexpr (emper::STATS) {
lawsStrategy.scheduledFibersToRemotePriority.fetch_add(1, std::memory_order_relaxed);
}
}
scheduleToLocalWsQueue:
......@@ -61,9 +64,9 @@ scheduleToLocalWsQueue:
ABORT("Could not push fiber " << &fiber << " into queue");
#endif
} else {
#ifdef EMPER_STATS
lawsStrategy.scheduledFibersToLocal.fetch_add(1, std::memory_order_relaxed);
#endif
if constexpr (emper::STATS) {
lawsStrategy.scheduledFibersToLocal.fetch_add(1, std::memory_order_relaxed);
}
}
#ifdef EMPER_WORKER_SLEEP
......@@ -75,20 +78,22 @@ auto LawsScheduler::nextFiber() -> Fiber* {
Fiber* fiber = priorityQueue.dequeue();
if (fiber != nullptr) {
// We fetched a fiber from your local priority queue.
#ifdef EMPER_STATS
unsigned int flag = static_cast<unsigned int>(LawsStrategy::FiberSource::fromPriority);
fiber->setFlag(flag);
#endif
if constexpr (emper::STATS) {
unsigned int flag = static_cast<unsigned int>(LawsStrategy::FiberSource::fromPriority);
fiber->setFlag(flag);
}
return fiber;
}
bool poped = queue.popBottom(&fiber);
if (likely(poped)) {
#ifdef EMPER_STATS
unsigned int flag = static_cast<unsigned int>(LawsStrategy::FiberSource::fromLocal);
fiber->setFlag(flag);
#endif
if constexpr (emper::STATS) {
unsigned int flag = static_cast<unsigned int>(LawsStrategy::FiberSource::fromLocal);
fiber->setFlag(flag);
}
return fiber;
}
......@@ -100,10 +105,11 @@ auto LawsScheduler::nextFiber() -> Fiber* {
poped = queues[victim]->popTop(&fiber);
if (poped) {
#ifdef EMPER_STATS
unsigned int flag = static_cast<unsigned int>(LawsStrategy::FiberSource::stolen);
fiber->setFlag(flag);
#endif
if (emper::STATS) {
unsigned int flag = static_cast<unsigned int>(LawsStrategy::FiberSource::stolen);
fiber->setFlag(flag);
}
return fiber;
}
......@@ -112,10 +118,11 @@ auto LawsScheduler::nextFiber() -> Fiber* {
// Try the main thread queue to get work as last resort.
poped = mainThreadQueue->popTop(&fiber);
if (poped) {
#ifdef EMPER_STATS
unsigned int flag = static_cast<unsigned int>(LawsStrategy::FiberSource::mainThread);
fiber->setFlag(flag);
#endif
if constexpr (emper::STATS) {
unsigned int flag = static_cast<unsigned int>(LawsStrategy::FiberSource::mainThread);
fiber->setFlag(flag);
}
return fiber;
}
......
......@@ -2,12 +2,15 @@
// Copyright © 2020 Florian Schmaus
#include "WsScheduler.hpp"
#include <atomic>
#include <ostream>
#include "Common.hpp"
#include "Debug.hpp"
#include "Emper.hpp"
#include "Runtime.hpp"
#include "emper-config.h"
#include "strategies/ws/WsStrategy.hpp"
class Fiber;
......@@ -35,9 +38,9 @@ void WsScheduler::schedule(Fiber& fiber) {
ABORT("Could not push fiber " << &fiber << " into queue");
}
#ifdef EMPER_STATS
wsStrategy.scheduledFibers.fetch_add(1, std::memory_order_relaxed);
#endif
if constexpr (emper::STATS) {
wsStrategy.scheduledFibers.fetch_add(1, std::memory_order_relaxed);
}
#ifdef EMPER_WORKER_SLEEP
notifyRuntimeAboutNewWork();
......@@ -49,9 +52,9 @@ auto WsScheduler::nextFiber() -> Fiber* {
bool poped = queue.popBottom(&fiber);
if (likely(poped)) {
#ifdef EMPER_STATS
wsStrategy.nextFiberFromLocal.fetch_add(1, std::memory_order_relaxed);
#endif
if constexpr (emper::STATS) {
wsStrategy.nextFiberFromLocal.fetch_add(1, std::memory_order_relaxed);
}
return fiber;
}
......@@ -66,9 +69,10 @@ auto WsScheduler::nextFiber() -> Fiber* {
poped = queues[victim]->popTop(&fiber);
if (poped) {
#ifdef EMPER_STATS
wsStrategy.nextFiberStolen.fetch_add(1, std::memory_order_relaxed);
#endif
if constexpr (emper::STATS) {
wsStrategy.nextFiberStolen.fetch_add(1, std::memory_order_relaxed);
}
return fiber;
}
}
......
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