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

[laws] Use WorkerLocalData for stats

parent 919e6b3f
No related branches found
No related tags found
No related merge requests found
Pipeline #60639 passed
......@@ -2,14 +2,13 @@
// Copyright © 2020-2021 Florian Schmaus
#include "LawsDispatcher.hpp"
#include <atomic> // for atomic, memory_order_relaxed
#include "Common.hpp" // for DIE_MSG
#include "Emper.hpp"
#include "LawsStrategy.hpp" // for LawsStrategy, LawsStrategy::FiberSource
#include "NextFiberResult.hpp"
#include "Runtime.hpp"
#include "emper-common.h"
#include "strategies/laws/LawsWorkerStats.hpp"
void LawsDispatcher::recycle(Fiber* fiber) {
// If the ref count has not reached zero yet, do not recycle the
......@@ -37,16 +36,16 @@ void LawsDispatcher::dispatchLoop() {
auto fiberSource = static_cast<LawsStrategy::FiberSource>(next.metadata);
switch (fiberSource) {
case LawsStrategy::FiberSource::fromPriority:
lawsStrategy.dispatchedFiberFromPriority.fetch_add(1, std::memory_order_relaxed);
LawsStrategy::stats.dispatchedFibersFromPriority++;
break;
case LawsStrategy::FiberSource::local:
lawsStrategy.dispatchedFiberFromLocal.fetch_add(1, std::memory_order_relaxed);
LawsStrategy::stats.dispatchedFibersFromLocal++;
break;
case LawsStrategy::FiberSource::stolen:
lawsStrategy.dispatchedFiberStolen.fetch_add(1, std::memory_order_relaxed);
LawsStrategy::stats.dispatchedFibersStolen++;
break;
case LawsStrategy::FiberSource::anywhereQueue:
lawsStrategy.dispatchedFiberFromAnywhere.fetch_add(1, std::memory_order_relaxed);
LawsStrategy::stats.dispatchedFibersFromAnywhereQueue++;
break;
default:
DIE_MSG("Unknown fiber source: " << next.metadata);
......
......@@ -3,29 +3,16 @@
#pragma once
#include "Dispatcher.hpp"
#include "emper-common.h" // IWYU pragma: keep
#include "emper-config.h" // IWYU pragma: keep
class Fiber;
class LawsStrategy;
class Runtime;
class LawsDispatcher : public Dispatcher {
private:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wattributes"
LawsStrategy& lawsStrategy
#ifndef EMPER_STATS
ATTR_UNUSED
#endif
;
#pragma GCC diagnostic pop
void recycle(Fiber* fiber) override;
public:
LawsDispatcher(Runtime& runtime, LawsStrategy& lawsStrategy)
: Dispatcher(runtime), lawsStrategy(lawsStrategy) {}
LawsDispatcher(Runtime& runtime) : Dispatcher(runtime) {}
void dispatchLoop() override;
};
......@@ -2,7 +2,6 @@
// Copyright © 2020-2021 Florian Schmaus
#include "LawsScheduler.hpp"
#include <atomic> // for atomic, memory_order_relaxed
#include <cstdint>
#include "Emper.hpp"
......@@ -10,11 +9,11 @@
#include "NextFiberResult.hpp"
#include "Runtime.hpp"
#include "emper-common.h"
#include "strategies/laws/LawsWorkerStats.hpp"
thread_local LawsScheduler::LawsMpscQueue LawsScheduler::priorityQueue;
LawsScheduler::LawsScheduler(Runtime& runtime, LawsStrategy& lawsStrategy)
: AbstractWorkStealingScheduler(runtime), lawsStrategy(lawsStrategy) {
LawsScheduler::LawsScheduler(Runtime& runtime) : AbstractWorkStealingScheduler(runtime) {
const workerid_t workerCount = runtime.getWorkerCount();
priorityQueues = new LawsScheduler::LawsMpscQueue*[workerCount];
......@@ -38,9 +37,8 @@ void LawsScheduler::scheduleInternal(Fiber& fiber) {
// We found a fiber to schedule on a remote prority queue.
increaseRefCount(fiber);
priorityQueues[affinity]->enqueue(&fiber);
if constexpr (emper::STATS) {
lawsStrategy.scheduledFibersToRemotePriority.fetch_add(1, std::memory_order_relaxed);
}
emper::statsIncr(LawsStrategy::stats.scheduledFibersToPriority);
}
scheduleViaWorkStealing:
......
......@@ -3,12 +3,9 @@
#pragma once
#include "Fiber.hpp"
#include "emper-common.h" // IWYU pragma: keep
#include "emper-config.h" // IWYU pragma: keep
#include "lib/adt/MpscQueue.hpp"
#include "strategies/AbstractWorkStealingScheduler.hpp"
class LawsStrategy;
class Runtime;
struct NextFiberResult;
......@@ -20,20 +17,11 @@ class LawsScheduler : public AbstractWorkStealingScheduler {
static thread_local LawsMpscQueue priorityQueue;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wattributes"
LawsStrategy& lawsStrategy
#ifndef EMPER_STATS
ATTR_UNUSED
#endif
;
#pragma GCC diagnostic pop
protected:
void scheduleInternal(Fiber& fiber) override;
public:
LawsScheduler(Runtime& runtime, LawsStrategy& lawsStrategy);
LawsScheduler(Runtime& runtime);
auto nextFiber() -> NextFiberResult override;
};
......@@ -2,19 +2,20 @@
// Copyright © 2020-2021 Florian Schmaus
#include "LawsStrategy.hpp"
#include <functional>
#include "strategies/laws/LawsDispatcher.hpp" // for LawsDispatcher
#include "strategies/laws/LawsScheduler.hpp" // for LawsScheduler
#include "strategies/laws/LawsStrategyStats.hpp" // for LawsStrategyStats
#include "strategies/laws/LawsWorkerStats.hpp"
thread_local LawsWorkerStats LawsStrategy::stats;
LawsStrategy::LawsStrategy(Runtime& runtime)
: AbstractWorkStealingStrategy(runtime),
scheduler(runtime, *this),
dispatcher(runtime, *this),
scheduledFibersToRemotePriority(0),
dispatchedFiberFromPriority(0),
dispatchedFiberFromLocal(0),
dispatchedFiberStolen(0),
dispatchedFiberFromAnywhere(0) {}
scheduler(runtime),
dispatcher(runtime),
allWorkerStats([] { return &stats; }, runtime) {}
auto LawsStrategy::getScheduler() -> LawsScheduler& { return scheduler; }
......
......@@ -2,10 +2,10 @@
// Copyright © 2020-2021 Florian Schmaus
#pragma once
#include <atomic>
#include <cstdint>
#include <memory>
#include "WorkerLocalData.hpp"
#include "strategies/AbstractWorkStealingScheduler.hpp"
#include "strategies/AbstractWorkStealingStrategy.hpp"
#include "strategies/laws/LawsDispatcher.hpp"
......@@ -15,6 +15,7 @@ class LawsStrategyFactory;
class LawsStrategyStats;
class Runtime;
class RuntimeStrategyStats;
struct LawsWorkerStats;
class LawsStrategy : public AbstractWorkStealingStrategy {
private:
......@@ -29,12 +30,9 @@ class LawsStrategy : public AbstractWorkStealingStrategy {
LawsScheduler scheduler;
LawsDispatcher dispatcher;
// TODO: Align those all to cache line!
std::atomic<std::uint64_t> scheduledFibersToRemotePriority;
std::atomic<std::uint64_t> dispatchedFiberFromPriority;
std::atomic<std::uint64_t> dispatchedFiberFromLocal;
std::atomic<std::uint64_t> dispatchedFiberStolen;
std::atomic<std::uint64_t> dispatchedFiberFromAnywhere;
static thread_local LawsWorkerStats stats;
WorkerLocalData<LawsWorkerStats> allWorkerStats;
LawsStrategy(Runtime& runtime);
......
......@@ -2,45 +2,31 @@
// Copyright © 2020-2021 Florian Schmaus
#include "LawsStrategyStats.hpp"
#include <atomic>
#include <iostream>
#include <string>
#include "LawsStrategy.hpp"
#include "WorkerLocalData.hpp"
LawsStrategyStats::LawsStrategyStats(LawsStrategy& lawsStrategy)
: AbstractWorkStealingStats(lawsStrategy),
scheduledFibersToRemotePriority(lawsStrategy.scheduledFibersToRemotePriority),
dispatchedFiberFromPriority(lawsStrategy.dispatchedFiberFromPriority),
dispatchedFiberFromLocal(lawsStrategy.dispatchedFiberFromLocal),
dispatchedFiberStolen(lawsStrategy.dispatchedFiberStolen),
dispatchedFiberFromAnywhere(lawsStrategy.dispatchedFiberFromAnywhere) {}
auto LawsStrategyStats::getScheduledFibersToRemotePriority() const -> uint64_t {
return scheduledFibersToRemotePriority;
}
auto LawsStrategyStats::getDispatchedFiberFromPriority() const -> uint64_t {
return dispatchedFiberFromPriority;
}
auto LawsStrategyStats::getDispatchedFiberFromLocal() const -> uint64_t {
return dispatchedFiberFromLocal;
}
auto LawsStrategyStats::getDispatchedFiberStolen() const -> uint64_t {
return dispatchedFiberStolen;
}
auto LawsStrategyStats::getDispatchedFiberFromAnywhere() const -> uint64_t {
return dispatchedFiberFromAnywhere;
workerStats(lawsStrategy.allWorkerStats.getSnapshot()) {
for (auto& workerStat : workerStats) {
comulatedWorkerStats += workerStat;
}
}
void LawsStrategyStats::print() {
// TODO: Print also the stats from AbstractWorkStealingStrategy.
std::cout << "LawsStrategyStats"
<< " scheduledFibersToRemotePriority:" << scheduledFibersToRemotePriority
<< " dispatchedFiberFromPriority:" << dispatchedFiberFromPriority
<< " dispatchedFiberFromLocal:" << dispatchedFiberFromLocal
<< " dispatchedFiberStolen:" << dispatchedFiberStolen
<< " dispatchedFiberFromAnywhere:" << dispatchedFiberFromAnywhere << std::endl;
AbstractWorkStealingStats::print();
std::cout << "total-scheduled-fibers-to-priority: "
<< std::to_string(comulatedWorkerStats.scheduledFibersToPriority) << std::endl
<< "total-dispatched-fibers-from-priority: "
<< std::to_string(comulatedWorkerStats.dispatchedFibersFromPriority) << std::endl
<< "total-dispatched-fibers-from-local: "
<< std::to_string(comulatedWorkerStats.dispatchedFibersFromLocal) << std::endl
<< "total-dispatched-fibers-stolen: "
<< std::to_string(comulatedWorkerStats.dispatchedFibersStolen) << std::endl
<< "total-dispatched-fibers-from-anywhere-queue: "
<< std::to_string(comulatedWorkerStats.dispatchedFibersFromAnywhereQueue) << std::endl;
}
......@@ -2,28 +2,19 @@
// Copyright © 2020-2021 Florian Schmaus
#pragma once
#include <cstdint>
#include <vector>
#include "strategies/AbstractWorkStealingStats.hpp"
#include "strategies/laws/LawsWorkerStats.hpp"
class LawsStrategy;
class LawsStrategyStats : public AbstractWorkStealingStats {
private:
const uint64_t scheduledFibersToRemotePriority;
const uint64_t dispatchedFiberFromPriority;
const uint64_t dispatchedFiberFromLocal;
const uint64_t dispatchedFiberStolen;
const uint64_t dispatchedFiberFromAnywhere;
public:
LawsStrategyStats(LawsStrategy& lawsStrategy);
std::vector<LawsWorkerStats> workerStats;
LawsWorkerStats comulatedWorkerStats;
[[nodiscard]] auto getScheduledFibersToRemotePriority() const -> uint64_t;
[[nodiscard]] auto getDispatchedFiberFromPriority() const -> uint64_t;
[[nodiscard]] auto getDispatchedFiberFromLocal() const -> uint64_t;
[[nodiscard]] auto getDispatchedFiberStolen() const -> uint64_t;
[[nodiscard]] auto getDispatchedFiberFromAnywhere() const -> uint64_t;
LawsStrategyStats(LawsStrategy& lawsStrategy);
void print() override;
};
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright © 2020-2021 Florian Schmaus
#pragma once
#include <cstdint>
struct LawsWorkerStats {
uint64_t scheduledFibersToPriority = 0;
uint64_t dispatchedFibersFromPriority = 0;
uint64_t dispatchedFibersFromLocal = 0;
uint64_t dispatchedFibersStolen = 0;
uint64_t dispatchedFibersFromAnywhereQueue = 0;
auto operator+=(const LawsWorkerStats& other) -> LawsWorkerStats& {
scheduledFibersToPriority += other.scheduledFibersToPriority;
dispatchedFibersFromPriority += other.dispatchedFibersFromPriority;
dispatchedFibersFromLocal += other.dispatchedFibersFromLocal;
dispatchedFibersStolen += other.dispatchedFibersStolen;
dispatchedFibersFromAnywhereQueue += other.dispatchedFibersFromAnywhereQueue;
return *this;
}
};
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