diff --git a/emper/Context.hpp b/emper/Context.hpp index fee4f8bbb683df682c8d1359ab55525d64324a09..49f5c2875ccb58077a801211b10345eef085f636 100644 --- a/emper/Context.hpp +++ b/emper/Context.hpp @@ -13,12 +13,15 @@ #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 "lib/math.hpp" class AbstractFiber; class ContextManager; class Dispatcher; class Fibril; +namespace em = emper::lib::math; + extern "C" [[noreturn]] void switch_and_load_context(void** toTos); // *Not* marked as 'noreturn' because save_and_switch_context does // *actually return at some point, unlike the other switch_* @@ -28,7 +31,8 @@ extern "C" [[noreturn]] void switch_context(void** toTos); class ALIGN_TO_CACHE_LINE Context : Logger<LogSubsystem::C> { private: - static const unsigned int CONTEXT_SIZE = 0xffff; // 1024 * 1024 * 4; + static constexpr size_t CONTEXT_SIZE = + em::roundUp(emper::MIN_CONTEXT_STACK_SIZE, emper::ASSUME_PAGE_SIZE); static thread_local Context* currentContext; diff --git a/emper/Emper.hpp b/emper/Emper.hpp index 488b9bf89ee543139efd6889180823e4b92a260f..1e8052855263b8a4f2f61fb626e9d8fc2e557d8d 100644 --- a/emper/Emper.hpp +++ b/emper/Emper.hpp @@ -278,4 +278,9 @@ static const bool CONTEXT_MANAGER_WITH_MEMORY_MANAGER = false #endif ; + +static const size_t ASSUME_PAGE_SIZE = EMPER_ASSUME_PAGE_SIZE; + +static const size_t MIN_CONTEXT_STACK_SIZE = EMPER_MIN_CONTEXT_STACK_SIZE; + } // namespace emper diff --git a/emper/lib/math.hpp b/emper/lib/math.hpp index 953d74450bb34974820a12f7bbd93d133cc5c857..a2e8e95b109b7f6548aa41f5a1201a7f397e7468 100644 --- a/emper/lib/math.hpp +++ b/emper/lib/math.hpp @@ -65,4 +65,8 @@ class RunningAverage { } }; +constexpr size_t roundUp(size_t number, size_t multiple) { + size_t multiple_count = (number + multiple - 1) / multiple; + return multiple_count * multiple; +} } // namespace emper::lib::math diff --git a/meson.build b/meson.build index 91d72dd827ee5f3c8f043f61baf07046ac539b6d..5b3a16e719cfc952bf01850f8f1b630863de2465 100644 --- a/meson.build +++ b/meson.build @@ -70,6 +70,8 @@ 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_MIN_CONTEXT_STACK_SIZE', get_option('min_context_stack_size')) 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 0f7cabd9fad62c0b051124db9a9f0d7a79dfd6c9..cdf68da00ece07c7831b4c5d8faa10ece92bf9d7 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -237,3 +237,17 @@ option( description: 'Use the memory manager in context manager for better context caching. This may increases the memory footprint', value: true ) +option( + 'assume_page_size', + type: 'integer', + description: 'Assume the given page size in bytes', + value: 4096, + min: 1, +) +option( + 'min_context_stack_size', + type: 'integer', + description: 'Set the size in bytes of stacks used by an execution context (will potentially be rounded up to the next page size)', + value: 65536, + min: 1, +)