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

[Context] Add option for context alignment

parent 64916077
No related branches found
No related tags found
1 merge request!331[Context] Make context size configurable
......@@ -30,7 +30,7 @@ using func_t = std::function<void()>;
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#define CACHE_LINE_SIZE 64
#define CACHE_LINE_SIZE EMPER_ASSUME_CACHE_LINE_SIZE
#define ALIGN_TO_CACHE_LINE alignas(CACHE_LINE_SIZE)
#define CACHE_LINE_EXCLUSIVE(T, symbol) \
std::aligned_storage<CACHE_LINE_SIZE, CACHE_LINE_SIZE>::type __##symbol##_mem; \
......
......@@ -13,6 +13,7 @@
#include "Common.hpp" // for func_t, DIE, ALIGN_TO_CACHE_LINE
#include "Debug.hpp" // for LOGD, LogSubsystem, LogSubsystem::C, Logger
#include "Emper.hpp" // for Emper::DEBUG
#include "emper-config.h"
#include "lib/math.hpp"
class AbstractFiber;
......@@ -29,7 +30,7 @@ extern "C" [[noreturn]] void switch_and_load_context(void** toTos);
extern "C" void save_and_switch_context(void** toTos, void** fromTos);
extern "C" [[noreturn]] void switch_context(void** toTos);
class ALIGN_TO_CACHE_LINE Context : Logger<LogSubsystem::C> {
class EMPER_CONTEXT_ALIGNAS Context : Logger<LogSubsystem::C> {
private:
static constexpr size_t CONTEXT_SIZE =
em::roundUp(emper::MIN_CONTEXT_STACK_SIZE, emper::ASSUME_PAGE_SIZE);
......
......@@ -283,4 +283,6 @@ static const size_t ASSUME_PAGE_SIZE = EMPER_ASSUME_PAGE_SIZE;
static const size_t MIN_CONTEXT_STACK_SIZE = EMPER_MIN_CONTEXT_STACK_SIZE;
static const size_t ASSUME_CACHE_LINE_SIZE = EMPER_ASSUME_CACHE_LINE_SIZE;
} // namespace emper
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright © 2020 Florian Schmaus
// Copyright © 2020-2022 Florian Schmaus
#include <chrono> // for nanoseconds, time_point, dur...
#include <cstdint> // for uint8_t, uint64_t
#include <cstdlib> // for EXIT_SUCCESS
#include <iostream> // for operator<<, basic_ostream
#include <thread> // for thread
#include "BinaryPrivateSemaphore.hpp" // for BPS
#include "BinaryPrivateSemaphore.hpp"
#include "Common.hpp"
#include "CountingPrivateSemaphore.hpp" // for CPS
#include "Fiber.hpp" // for Fiber
#include "PrivateSemaphore.hpp" // for PS
......@@ -14,8 +15,6 @@
#include "emper-common.h" // for UNUSED_ARG
#include "lib/DebugUtil.hpp" // for enableStacktraceOnAborts
#define CACHE_LINE_SIZE 64
static void spawnALotThreadsRecursiveTFun(unsigned int depth, unsigned int width,
unsigned int current_depth) {
if (current_depth == depth) return;
......
......@@ -54,6 +54,8 @@ endif
continuation_stealing_mode = get_option('continuation_stealing_mode')
locked_ws_queue = get_option('locked_ws_queue')
assume_page_size = get_option('assume_page_size')
assume_cache_line_size = get_option('assume_cache_line_size')
conf_data.set('EMPER_WORKER_SLEEP', get_option('worker_sleep'))
conf_data.set('EMPER_WORKER_WAKEUP_STRATEGY', get_option('worker_wakeup_strategy'))
......@@ -70,8 +72,21 @@ conf_data.set('EMPER_CONTINUATION_STEALING_MODE', continuation_stealing_mode)
conf_data.set('EMPER_CONTINUATION_STEALING_MADVISE_STACK', get_option('continuation_stealing_madvise_stack'))
conf_data.set('EMPER_BUILD_WITH_CLANG', cpp_is_clang)
conf_data.set('EMPER_CONTEXT_MANAGER_WITH_MEMORY_MANAGER', get_option('context_manager_with_memory_manager'))
conf_data.set('EMPER_ASSUME_PAGE_SIZE', get_option('assume_page_size'))
conf_data.set('EMPER_ASSUME_PAGE_SIZE', assume_page_size)
conf_data.set('EMPER_MIN_CONTEXT_STACK_SIZE', get_option('min_context_stack_size'))
conf_data.set('EMPER_ASSUME_CACHE_LINE_SIZE', assume_cache_line_size)
context_alignment = get_option('context_alignment')
if context_alignment == 'none'
context_alignas = ''
elif context_alignment == 'cache_line_size'
context_alignas = 'alignas(' + cache_line_size + ')'
elif context_alignment == 'page_size'
context_alignas = 'alignas(' + page_size + ')'
else
error('Unknown context alignment option: ' + context_alignment)
endif
conf_data.set('EMPER_CONTEXT_ALIGNAS', context_alignas)
if continuation_stealing_mode == 'locked' and not locked_ws_queue
error('*Locked* continuation stealing only works with locked work-stealing queues (locked_ws_queue=true)')
......
......@@ -251,3 +251,17 @@ option(
value: 65536,
min: 1,
)
option(
'context_alignment',
type: 'combo',
description: 'Use the select mechanism to determine the alignment of contexts',
choices: ['none', 'cache_line_size', 'page_size'],
value: 'none',
)
option(
'assume_cache_line_size',
type: 'integer',
description: 'Assume the given cache-line size in bytes',
value: 64,
min: 1,
)
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