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

[Blockable] Set affinity on block

parent 1cf9f0f5
No related branches found
No related tags found
No related merge requests found
......@@ -163,6 +163,10 @@ clang-tidy:
variables:
EMPER_WAKEUP_SEMAPHORE_IMPLEMENTATION: "locked"
.set-affinity-on-block:
variables:
EMPER_SET_AFFINITY_ON_BLOCK: 'true'
test-gcc:
extends:
- .test
......@@ -258,3 +262,8 @@ test-locked-wakeup-semaphore:
extends:
- .test
- .locked-wakeup-semaphore
test-set-affinity-on-block:
extends:
- .test
- .set-affinity-on-block
......@@ -24,8 +24,31 @@ class Blockable : public Logger<logSubsystem> {
workeraffinity_t* affinity = nullptr;
// It would be OK to not initialize this member since it is only set
// and read after affinity has been set to a non nullptr
// value. However, if we do not set it, then clang-tidy complains
// about clang-analyzer-optin.cplusplus.UninitializedObject.
workeraffinity_t affinity_buffer = Fiber::NOT_AFFINE;
Blockable(Runtime& runtime) : runtime(runtime), contextManager(runtime.getContextManager()) {}
void maybeSetAffinity() {
if constexpr (!emper::SET_AFFINITY_ON_BLOCK) return;
// TODO: At some point we may want to have something like
// Runtime::isAffinityCapable() and return here if it is
// not. Although I am not sure if it is worth the overhead.
auto* currentFiber = Context::getCurrentFiber();
auto* affinity = currentFiber->getAffinityBuffer();
if (affinity) {
this->affinity = affinity;
} else {
affinity_buffer = Runtime::getWorkerId();
this->affinity = &affinity_buffer;
}
}
// Older clang-tidy versions show a
// performance-unnecessary-value-param, newer versions do not show
// this error if std::move() is used (as we do).
......@@ -36,6 +59,8 @@ class Blockable : public Logger<logSubsystem> {
LOGD("block() blockedContext is " << Context::getCurrentContext());
maybeSetAffinity();
if constexpr (emper::BLOCKED_CONTEXT_SET) {
blockedContexts.insert(Context::getCurrentContext());
}
......
......@@ -113,4 +113,13 @@ enum class IoCompleterBehavior {
static const enum IoCompleterBehavior IO_COMPLETER_BEHAVIOR =
IoCompleterBehavior::EMPER_IO_COMPLETER_BEHAVIOR;
static const bool SET_AFFINITY_ON_BLOCK =
#ifdef EMPER_SET_AFFINITY_ON_BLOCK
true
#else
false
#endif
;
} // namespace emper
......@@ -95,6 +95,8 @@ class ALIGN_TO_CACHE_LINE Fiber : public Logger<LogSubsystem::F> {
return --referenceCounter;
}
template <LogSubsystem>
friend class Blockable;
friend class adt::MpscQueue<Fiber>;
friend class Scheduler;
friend class Dispatcher;
......
......@@ -129,3 +129,9 @@ option(
choices: ['schedule', 'maybe_wakeup'],
value: 'schedule',
)
option(
'set_affinity_on_block',
type: 'boolean',
value: false,
description: 'Set the affinity when blocking',
)
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