From: Gabriel Corona Date: Mon, 4 Jan 2016 11:31:26 +0000 (+0100) Subject: [simix] simcall to run code in kernel mode X-Git-Tag: v3_13~1360 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/f9d7b35c174d52377ef297f786129e0340ae0778 [simix] simcall to run code in kernel mode 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. --- diff --git a/include/simgrid/simix.hpp b/include/simgrid/simix.hpp index 1829bad3a3..5fbc4d5fd8 100644 --- a/include/simgrid/simix.hpp +++ b/include/simgrid/simix.hpp @@ -13,13 +13,33 @@ #include #include #include +#include +#include #include #include +XBT_PUBLIC(void) simcall_run_kernel(std::function const& code); + namespace simgrid { namespace simix { +template +typename std::result_of::type kernel(F&& code) +{ + typedef typename std::result_of::type R; + std::promise 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; diff --git a/src/simix/libsmx.cpp b/src/simix/libsmx.cpp index 1dbcd2001f..3569270bde 100644 --- a/src/simix/libsmx.cpp +++ b/src/simix/libsmx.cpp @@ -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 + #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 const& code) +{ + return simcall_BODY_run_kernel((void*) &code); +} #ifdef HAVE_MC diff --git a/src/simix/popping.cpp b/src/simix/popping.cpp index eef1ea8f72..facf8e844d 100644 --- a/src/simix/popping.cpp +++ b/src/simix/popping.cpp @@ -59,3 +59,9 @@ void SIMIX_simcall_exit(smx_synchro_t synchro) break; } } + +void SIMIX_run_kernel(void* code) +{ + std::function* function = (std::function*) code; + (*function)(); +} \ No newline at end of file diff --git a/src/simix/popping_accessors.h b/src/simix/popping_accessors.h index fd3d6142f2..523515a190 100644 --- a/src/simix/popping_accessors.h +++ b/src/simix/popping_accessors.h @@ -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) { diff --git a/src/simix/popping_bodies.cpp b/src/simix/popping_bodies.cpp index 2d3e86d278..1c50638101 100644 --- a/src/simix/popping_bodies.cpp +++ b/src/simix/popping_bodies.cpp @@ -16,6 +16,7 @@ #include "smx_private.h" #include "src/mc/mc_forward.h" #include "xbt/ex.h" +#include 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) { diff --git a/src/simix/popping_enum.h b/src/simix/popping_enum.h index cd27c75c1a..38aef99d89 100644 --- a/src/simix/popping_enum.h +++ b/src/simix/popping_enum.h @@ -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 diff --git a/src/simix/popping_generated.cpp b/src/simix/popping_generated.cpp index 7ff297f825..7a3bd8bfa0 100644 --- a/src/simix/popping_generated.cpp +++ b/src/simix/popping_generated.cpp @@ -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); diff --git a/src/simix/popping_private.h b/src/simix/popping_private.h index 4f31ac74fa..1a2d667c59 100644 --- a/src/simix/popping_private.h +++ b/src/simix/popping_private.h @@ -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() diff --git a/src/simix/simcalls.in b/src/simix/simcalls.in index ffac959031..7d6ec3b059 100644 --- a/src/simix/simcalls.in +++ b/src/simix/simcalls.in @@ -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 diff --git a/src/simix/simcalls.py b/src/simix/simcalls.py index e1c55e4958..c249a21c08 100755 --- a/src/simix/simcalls.py +++ b/src/simix/simcalls.py @@ -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 \n') handle(fd, Simcall.body, simcalls, simcalls_dict) fd.close() diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index ec4e9d7e0a..6271658400 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -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