Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
close gforge bug 18137 (allow different stack sizes): that was possible since years...
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Tue, 3 Mar 2020 22:54:55 +0000 (23:54 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Tue, 3 Mar 2020 22:56:43 +0000 (23:56 +0100)
12 files changed:
ChangeLog
docs/source/Configuring_SimGrid.rst
src/kernel/context/ContextBoost.cpp
src/kernel/context/ContextRaw.cpp
src/kernel/context/ContextSwapped.cpp
src/kernel/context/ContextThread.cpp
src/kernel/context/ContextUnix.cpp
teshsuite/kernel/CMakeLists.txt [new file with mode: 0644]
teshsuite/kernel/context-stacksize/context-stacksize.cpp [new file with mode: 0644]
teshsuite/kernel/context-stacksize/context-stacksize.tesh [new file with mode: 0644]
teshsuite/simix/generic-simcalls/generic-simcalls.tesh
tools/cmake/DefinePackages.cmake

index aedd899..1fdc62c 100644 (file)
--- 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)
index 6ff989b..3c06083 100644 (file)
@@ -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
index d79a549..ae9ade0 100644 (file)
@@ -24,6 +24,7 @@ BoostContext* BoostContextFactory::create_context(std::function<void()>&& code,
 BoostContext::BoostContext(std::function<void()>&& 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
index 47fe3f0..4cc658a 100644 (file)
@@ -197,12 +197,13 @@ RawContext* RawContextFactory::create_context(std::function<void()>&& code, acto
 RawContext::RawContext(std::function<void()>&& 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_)
index afbaa91..d64dac4 100644 (file)
@@ -69,7 +69,7 @@ thread_local SwappedContext* SwappedContext::worker_context_ = nullptr;
 SwappedContext::SwappedContext(std::function<void()>&& 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;
 
index 798b050..f31f2e3 100644 (file)
@@ -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();
 }
index 0b6f7a8..6e2ebe5 100644 (file)
@@ -49,6 +49,7 @@ UContext* UContextFactory::create_context(std::function<void()>&& code, actor::A
 UContext::UContext(std::function<void()>&& 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 (file)
index 0000000..45a5cb9
--- /dev/null
@@ -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 (file)
index 0000000..49cba2e
--- /dev/null
@@ -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 (file)
index 0000000..dd05180
--- /dev/null
@@ -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
index e798ebb..66f0276 100644 (file)
@@ -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
index b211891..d957410 100644 (file)
@@ -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