From: Martin Quinson Date: Tue, 3 Mar 2020 22:54:55 +0000 (+0100) Subject: close gforge bug 18137 (allow different stack sizes): that was possible since years... X-Git-Tag: v3.26~840 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/27ef78997bbc722303efdb9826ea745a3814a82a close gforge bug 18137 (allow different stack sizes): that was possible since years, actually --- diff --git a/ChangeLog b/ChangeLog index aedd899ef9..1fdc62cb7f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -21,7 +21,9 @@ C interface: - Many MSG tests were converted to the new S4U's interface in C, that was extended for that. -Fixed bugs (FG#.. -> framagit bugs; FG!.. -> FG merge requests; GH: GitHub): +Fixed bugs (FG#.. -> FramaGit bugs; FG!.. -> FG merge requests) + (FG: issues on Framagit; GH: issues on GitHub; GF: issues on GForge) + - GF#18137: Allow different stack sizes? - FG#41: Add sg_actor_create C interface - FG#43: xbt::random needs some care - FG#48: The Impossible Did Happen (yet again) diff --git a/docs/source/Configuring_SimGrid.rst b/docs/source/Configuring_SimGrid.rst index 6ff989bc32..3c06083083 100644 --- a/docs/source/Configuring_SimGrid.rst +++ b/docs/source/Configuring_SimGrid.rst @@ -782,10 +782,16 @@ stacks), leading to segfaults with corrupted stack traces. If you want to push the scalability limits of your code, you might want to reduce the ``contexts/stack-size`` item. Its default value is 8192 (in KiB), while our Chord simulation works with stacks as small -as 16 KiB, for example. This *setting is ignored* when using the -thread factory. Instead, you should compile SimGrid and your -application with ``-fsplit-stack``. Note that this compilation flag is -not compatible with the model checker right now. +as 16 KiB, for example. You can ensure that some actors have a specific +size by simply changing the value of this configuration item before +creating these actors. The :cpp:func:`simgrid::s4u::Engine::set_config` +functions are handy for that. + +This *setting is ignored* when using the thread factory (because there +is no way to modify the stack size with C++ system threads). Instead, +you should compile SimGrid and your application with +``-fsplit-stack``. Note that this compilation flag is not compatible +with the model checker right now. The operating system should only allocate memory for the pages of the stack which are actually used and you might not need to use this in diff --git a/src/kernel/context/ContextBoost.cpp b/src/kernel/context/ContextBoost.cpp index d79a549d5e..ae9ade0c56 100644 --- a/src/kernel/context/ContextBoost.cpp +++ b/src/kernel/context/ContextBoost.cpp @@ -24,6 +24,7 @@ BoostContext* BoostContextFactory::create_context(std::function&& code, BoostContext::BoostContext(std::function&& code, actor::ActorImpl* actor, SwappedContextFactory* factory) : SwappedContext(std::move(code), actor, factory) { + XBT_VERB("Creating a context of stack %uMb", smx_context_stack_size / 1024 / 1024); /* if the user provided a function for the process then use it, otherwise it is the context for maestro */ if (has_code()) { #if BOOST_VERSION < 106100 diff --git a/src/kernel/context/ContextRaw.cpp b/src/kernel/context/ContextRaw.cpp index 47fe3f057c..4cc658a0cf 100644 --- a/src/kernel/context/ContextRaw.cpp +++ b/src/kernel/context/ContextRaw.cpp @@ -197,12 +197,13 @@ RawContext* RawContextFactory::create_context(std::function&& code, acto RawContext::RawContext(std::function&& code, actor::ActorImpl* actor, SwappedContextFactory* factory) : SwappedContext(std::move(code), actor, factory) { - if (has_code()) { - this->stack_top_ = raw_makecontext(get_stack(), smx_context_stack_size, smx_ctx_wrapper, this); - } else { - if (MC_is_active()) - MC_ignore_heap(&stack_top_, sizeof(stack_top_)); - } + XBT_VERB("Creating a context of stack %uMb", smx_context_stack_size / 1024 / 1024); + if (has_code()) { + this->stack_top_ = raw_makecontext(get_stack(), smx_context_stack_size, smx_ctx_wrapper, this); + } else { + if (MC_is_active()) + MC_ignore_heap(&stack_top_, sizeof(stack_top_)); + } } void RawContext::swap_into_for_real(SwappedContext* to_) diff --git a/src/kernel/context/ContextSwapped.cpp b/src/kernel/context/ContextSwapped.cpp index afbaa915c0..d64dac46d4 100644 --- a/src/kernel/context/ContextSwapped.cpp +++ b/src/kernel/context/ContextSwapped.cpp @@ -69,7 +69,7 @@ thread_local SwappedContext* SwappedContext::worker_context_ = nullptr; SwappedContext::SwappedContext(std::function&& code, smx_actor_t actor, SwappedContextFactory* factory) : Context(std::move(code), actor), factory_(*factory) { - // Save maestro (=context created first) in preparation for run_all + // Save maestro (=first created context) in preparation for run_all if (not SIMIX_context_is_parallel() && factory_.maestro_context_ == nullptr) factory_.maestro_context_ = this; diff --git a/src/kernel/context/ContextThread.cpp b/src/kernel/context/ContextThread.cpp index 798b05099f..f31f2e3f9d 100644 --- a/src/kernel/context/ContextThread.cpp +++ b/src/kernel/context/ContextThread.cpp @@ -24,6 +24,8 @@ namespace context { ThreadContextFactory::ThreadContextFactory() : ContextFactory() { + if (smx_context_stack_size != 8 * 1024 * 1024) + XBT_INFO("Stack size modifications are ignored by thread factory."); if (SIMIX_context_is_parallel()) ParallelThreadContext::initialize(); } diff --git a/src/kernel/context/ContextUnix.cpp b/src/kernel/context/ContextUnix.cpp index 0b6f7a8129..6e2ebe54c3 100644 --- a/src/kernel/context/ContextUnix.cpp +++ b/src/kernel/context/ContextUnix.cpp @@ -49,6 +49,7 @@ UContext* UContextFactory::create_context(std::function&& code, actor::A UContext::UContext(std::function&& code, actor::ActorImpl* actor, SwappedContextFactory* factory) : SwappedContext(std::move(code), actor, factory) { + XBT_VERB("Creating a context of stack %uMb", smx_context_stack_size / 1024 / 1024); /* if the user provided a function for the actor then use it. If not, nothing to do for maestro. */ if (has_code()) { getcontext(&this->uc_); diff --git a/teshsuite/kernel/CMakeLists.txt b/teshsuite/kernel/CMakeLists.txt new file mode 100644 index 0000000000..45a5cb9a2f --- /dev/null +++ b/teshsuite/kernel/CMakeLists.txt @@ -0,0 +1,15 @@ +foreach(x context-stacksize) + add_executable (${x} EXCLUDE_FROM_ALL ${x}/${x}.cpp) + target_link_libraries(${x} simgrid) + set_target_properties(${x} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${x}) + add_dependencies(tests ${x}) + + set(teshsuite_src ${teshsuite_src} ${CMAKE_CURRENT_SOURCE_DIR}/${x}/${x}.cpp) +endforeach() + +## Add the tests. +## Some need to be run with all factories, some don't need tesh to run + +# Only with the raw contexts +ADD_TESH_FACTORIES(tesh-kern-context-stacksize "raw;boost;ucontext" --setenv bindir=${CMAKE_BINARY_DIR}/teshsuite/kernel/context-stacksize --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/kernel/context-stacksize --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms --cd ${CMAKE_BINARY_DIR}/teshsuite/kernel/context-stacksize ${CMAKE_HOME_DIRECTORY}/teshsuite/kernel/context-stacksize/context-stacksize.tesh) + diff --git a/teshsuite/kernel/context-stacksize/context-stacksize.cpp b/teshsuite/kernel/context-stacksize/context-stacksize.cpp new file mode 100644 index 0000000000..49cba2e840 --- /dev/null +++ b/teshsuite/kernel/context-stacksize/context-stacksize.cpp @@ -0,0 +1,34 @@ +/* Copyright (c) 2010-2020. The SimGrid Team. All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + +/* This code tests that we can change the stack-size between the actors creation. */ + +#include "simgrid/s4u.hpp" + +XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example"); + +static void actor() +{ + XBT_INFO("Hello"); +} + +int main(int argc, char* argv[]) +{ + simgrid::s4u::Engine e(&argc, argv); + e.load_platform(argv[1]); + + simgrid::s4u::Actor::create("actor", simgrid::s4u::Host::by_name("Tremblay"), actor); + e.set_config("contexts/stack-size:16384"); + simgrid::s4u::Actor::create("actor", simgrid::s4u::Host::by_name("Tremblay"), actor); + e.set_config("contexts/stack-size", 32 * 1024); + simgrid::s4u::Actor::create("actor", simgrid::s4u::Host::by_name("Tremblay"), actor); + e.set_config("contexts/stack-size", 64 * 1024); + simgrid::s4u::Actor::create("actor", simgrid::s4u::Host::by_name("Tremblay"), actor); + + e.run(); + XBT_INFO("Simulation time %g", e.get_clock()); + + return 0; +} diff --git a/teshsuite/kernel/context-stacksize/context-stacksize.tesh b/teshsuite/kernel/context-stacksize/context-stacksize.tesh new file mode 100644 index 0000000000..dd05180159 --- /dev/null +++ b/teshsuite/kernel/context-stacksize/context-stacksize.tesh @@ -0,0 +1,16 @@ + +! ignore .*Using Boost contexts. Welcome to the 21th century. +! ignore .*Activating SYSV context factory +! ignore .*Using raw contexts. Because the glibc is just not good enough for us. + +$ ./context-stacksize --log=simix_context.thresh:verbose --log=no_loc ${platfdir}/small_platform.xml +> [::(0) 0.000000] [simix_context/VERBOSE] Creating a context of stack 8Mb +> [0.000000] [simix_context/VERBOSE] Creating a context of stack 8Mb +> [0.000000] [simix_context/VERBOSE] Creating a context of stack 16Mb +> [0.000000] [simix_context/VERBOSE] Creating a context of stack 32Mb +> [0.000000] [simix_context/VERBOSE] Creating a context of stack 64Mb +> [Tremblay:actor:(1) 0.000000] [s4u_test/INFO] Hello +> [Tremblay:actor:(2) 0.000000] [s4u_test/INFO] Hello +> [Tremblay:actor:(3) 0.000000] [s4u_test/INFO] Hello +> [Tremblay:actor:(4) 0.000000] [s4u_test/INFO] Hello +> [0.000000] [s4u_test/INFO] Simulation time 0 diff --git a/teshsuite/simix/generic-simcalls/generic-simcalls.tesh b/teshsuite/simix/generic-simcalls/generic-simcalls.tesh index e798ebb439..66f0276cad 100644 --- a/teshsuite/simix/generic-simcalls/generic-simcalls.tesh +++ b/teshsuite/simix/generic-simcalls/generic-simcalls.tesh @@ -1,3 +1,5 @@ + +! ignore .*Stack size modifications are ignored by thread factory. $ ${bindir:=.}/generic-simcalls --cfg=contexts/stack-size:96 ${srcdir:=.}/examples/platforms/small_platform.xml > [Tremblay:master:(1) 0.000000] [test/INFO] Start > [0.000000] [test/INFO] kernel diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index b2118916b3..d957410401 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -1019,6 +1019,7 @@ set(CMAKEFILES_TXT examples/deprecated/simdag/CMakeLists.txt teshsuite/java/CMakeLists.txt + teshsuite/kernel/CMakeLists.txt teshsuite/lua/CMakeLists.txt teshsuite/mc/CMakeLists.txt teshsuite/msg/CMakeLists.txt