diff --git a/emper/Common.hpp b/emper/Common.hpp index 4b10454c96f2fd7a00643113298562b9802f350e..9e3832eca10276a7bff8c88206da1723e508d4c9 100644 --- a/emper/Common.hpp +++ b/emper/Common.hpp @@ -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; \ diff --git a/emper/Context.hpp b/emper/Context.hpp index 49f5c2875ccb58077a801211b10345eef085f636..73f29e36ddf307126344d08a220997be87dcadd9 100644 --- a/emper/Context.hpp +++ b/emper/Context.hpp @@ -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); diff --git a/emper/Emper.hpp b/emper/Emper.hpp index 1e8052855263b8a4f2f61fb626e9d8fc2e557d8d..93df71cfd4e46ac04218fdadf54323985f1dfda8 100644 --- a/emper/Emper.hpp +++ b/emper/Emper.hpp @@ -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 diff --git a/eval/SpawnALot.cpp b/eval/SpawnALot.cpp index 4aa6bb199adbb72f998b7861cb609822c49bd387..bc0b7749a14504ba5b5b04604d30e51ef0e82332 100644 --- a/eval/SpawnALot.cpp +++ b/eval/SpawnALot.cpp @@ -1,12 +1,13 @@ // 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; diff --git a/meson.build b/meson.build index 5b3a16e719cfc952bf01850f8f1b630863de2465..dff49db29f40ed32ea2306d6afdd29a673e21075 100644 --- a/meson.build +++ b/meson.build @@ -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)') diff --git a/meson_options.txt b/meson_options.txt index cdf68da00ece07c7831b4c5d8faa10ece92bf9d7..df0459d002b4125e9a312c4986d34b6c64e18b2a 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -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, +)