Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[simix] simcall to run code in kernel mode
authorGabriel Corona <gabriel.corona@loria.fr>
Mon, 4 Jan 2016 11:31:26 +0000 (12:31 +0100)
committerGabriel Corona <gabriel.corona@loria.fr>
Mon, 4 Jan 2016 11:40:02 +0000 (12:40 +0100)
With this, we should be able to limit the number of necessary simcalls
dramatcially. In the long term, we might even get rid of simcalls
altogether and use only this mechanism for process/kernel switching.

include/simgrid/simix.hpp
src/simix/libsmx.cpp
src/simix/popping.cpp
src/simix/popping_accessors.h
src/simix/popping_bodies.cpp
src/simix/popping_enum.h
src/simix/popping_generated.cpp
src/simix/popping_private.h
src/simix/simcalls.in
src/simix/simcalls.py
tools/cmake/DefinePackages.cmake

index 1829bad..5fbc4d5 100644 (file)
 #include <utility>
 #include <memory>
 #include <functional>
+#include <future>
+#include <type_traits>
 
 #include <xbt/function_types.h>
 #include <simgrid/simix.h>
 
+XBT_PUBLIC(void) simcall_run_kernel(std::function<void()> const& code);
+
 namespace simgrid {
 namespace simix {
 
+template<class F>
+typename std::result_of<F()>::type kernel(F&& code)
+{
+  typedef typename std::result_of<F()>::type R;
+  std::promise<R> promise;
+  simcall_run_kernel([&]{
+    try {
+      promise.set_value(code());
+    }
+    catch(...) {
+      promise.set_exception(std::current_exception());
+    }
+  });
+  return promise.get_future().get();
+}
+
 class Context;
 class ContextFactory;
 
index 1dbcd20..3569270 100644 (file)
@@ -11,6 +11,8 @@
 /* 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. */
 
+#include <functional>
+
 #include "src/mc/mc_replay.h"
 #include "smx_private.h"
 #include "src/mc/mc_forward.h"
@@ -1401,7 +1403,10 @@ xbt_dict_t simcall_storage_get_content(smx_storage_t storage)
   return simcall_BODY_storage_get_content(storage);
 }
 
-
+void simcall_run_kernel(std::function<void()> const& code)
+{
+  return simcall_BODY_run_kernel((void*) &code);
+}
 
 #ifdef HAVE_MC
 
index eef1ea8..facf8e8 100644 (file)
@@ -59,3 +59,9 @@ void SIMIX_simcall_exit(smx_synchro_t synchro)
       break;
   }
 }
+
+void SIMIX_run_kernel(void* code)
+{
+  std::function<void()>* function = (std::function<void()>*) code;
+  (*function)();
+}
\ No newline at end of file
index fd3d614..523515a 100644 (file)
@@ -1790,6 +1790,13 @@ static inline const char* simcall_set_category__get__category(smx_simcall_t simc
 static inline void simcall_set_category__set__category(smx_simcall_t simcall, const char* arg) {
     simcall->args[1].cc = arg;
 }
+
+static inline void* simcall_run_kernel__get__code(smx_simcall_t simcall) {
+  return  simcall->args[0].dp;
+}
+static inline void simcall_run_kernel__set__code(smx_simcall_t simcall, void* arg) {
+    simcall->args[0].dp = arg;
+}
 #ifdef HAVE_LATENCY_BOUND_TRACKING
 
 static inline smx_synchro_t simcall_comm_is_latency_bounded__get__comm(smx_simcall_t simcall) {
index 2d3e86d..1c50638 100644 (file)
@@ -16,6 +16,7 @@
 #include "smx_private.h"
 #include "src/mc/mc_forward.h"
 #include "xbt/ex.h"
+#include <simgrid/simix.hpp>
   
 inline static void simcall_BODY_host_on(sg_host_t host) {
     smx_process_t self = SIMIX_process_self();
@@ -2530,6 +2531,27 @@ inline static void simcall_BODY_set_category(smx_synchro_t synchro, const char*
     }    
     
   }
+  
+inline static void simcall_BODY_run_kernel(void* code) {
+    smx_process_t self = SIMIX_process_self();
+
+    /* Go to that function to follow the code flow through the simcall barrier */
+    if (0) SIMIX_run_kernel(code);
+    /* end of the guide intended to the poor programmer wanting to go from MSG to Surf */
+
+    self->simcall.call = SIMCALL_RUN_KERNEL;
+    memset(&self->simcall.result, 0, sizeof(self->simcall.result));
+    memset(self->simcall.args, 0, sizeof(self->simcall.args));
+    self->simcall.args[0].dp = (void*) code;
+    if (self != simix_global->maestro_process) {
+      XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name,
+                SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call);
+      SIMIX_process_yield(self);
+    } else {
+      SIMIX_simcall_handle(&self->simcall, 0);
+    }    
+    
+  }
 #ifdef HAVE_LATENCY_BOUND_TRACKING
   
 inline static int simcall_BODY_comm_is_latency_bounded(smx_synchro_t comm) {
index cd27c75..38aef99 100644 (file)
@@ -133,6 +133,7 @@ typedef enum {
   SIMCALL_ASR_GET_PROPERTIES,
   SIMCALL_MC_RANDOM,
   SIMCALL_SET_CATEGORY,
+  SIMCALL_RUN_KERNEL,
 #ifdef HAVE_LATENCY_BOUND_TRACKING
   SIMCALL_COMM_IS_LATENCY_BOUNDED,
 #endif
index 7ff297f..7a3bd8b 100644 (file)
@@ -138,6 +138,7 @@ const char* simcall_names[] = {
   "SIMCALL_ASR_GET_PROPERTIES",
   "SIMCALL_MC_RANDOM",
   "SIMCALL_SET_CATEGORY",
+  "SIMCALL_RUN_KERNEL",
 #ifdef HAVE_LATENCY_BOUND_TRACKING
   "SIMCALL_COMM_IS_LATENCY_BOUNDED",
 #endif
@@ -715,6 +716,11 @@ case SIMCALL_SET_CATEGORY:
       SIMIX_simcall_answer(simcall);
       break;  
 
+case SIMCALL_RUN_KERNEL:
+       SIMIX_run_kernel( simcall->args[0].dp);
+      SIMIX_simcall_answer(simcall);
+      break;  
+
 #ifdef HAVE_LATENCY_BOUND_TRACKING
 case SIMCALL_COMM_IS_LATENCY_BOUNDED:
       simcall->result.i = SIMIX_comm_is_latency_bounded((smx_synchro_t) simcall->args[0].dp);
index 4f31ac7..1a2d667 100644 (file)
@@ -65,6 +65,7 @@ XBT_PRIVATE void SIMIX_simcall_answer(smx_simcall_t);
 XBT_PRIVATE void SIMIX_simcall_handle(smx_simcall_t, int);
 XBT_PRIVATE void SIMIX_simcall_exit(smx_synchro_t);
 XBT_PRIVATE const char *SIMIX_simcall_name(e_smx_simcall_t kind);
+XBT_PRIVATE void SIMIX_run_kernel(void* code);
 
 SG_END_DECL()
 
index ffac959..7d6ec3b 100644 (file)
@@ -165,6 +165,7 @@ Func - storage_get_content (void*, xbt_dict_t) (storage, void*, smx_storage_t)
 Func H asr_get_properties (void*, xbt_dict_t) (name, const char*)
 Func H mc_random (int) (min, int) (max, int)
 Proc - set_category (void) (synchro, void*, smx_synchro_t) (category, const char*)
+Proc - run_kernel (void) (code, void*)
 ## HAVE_LATENCY_BOUND_TRACKING
 Func - comm_is_latency_bounded (int) (comm, void*, smx_synchro_t)
 ## HAVE_MC
index e1c55e4..c249a21 100755 (executable)
@@ -332,5 +332,6 @@ if __name__=='__main__':
   fd.write('#include "smx_private.h"\n')
   fd.write('#include "src/mc/mc_forward.h"\n')
   fd.write('#include "xbt/ex.h"\n')
+  fd.write('#include <simgrid/simix.hpp>\n')
   handle(fd, Simcall.body, simcalls, simcalls_dict)
   fd.close()
index ec4e9d7..6271658 100644 (file)
@@ -1112,6 +1112,7 @@ set(TESHSUITE_CMAKEFILES_TXT
   teshsuite/simdag/network/p2p/CMakeLists.txt
   teshsuite/simdag/partask/CMakeLists.txt
   teshsuite/simdag/platforms/CMakeLists.txt
+  teshsuite/simix/CMakeLists.txt
   teshsuite/simix/check_defaults/CMakeLists.txt
   teshsuite/simix/stack_overflow/CMakeLists.txt
   teshsuite/smpi/CMakeLists.txt