From dbae853c4de0c0d66c97c961c370448bee5e1ab4 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sun, 20 Nov 2016 17:59:16 +0100 Subject: [PATCH] inline 2 more VM functions, and kill a simcall --- src/simix/libsmx.cpp | 37 +++++++++++++++++++++++-- src/simix/popping_accessors.h | 15 ++-------- src/simix/popping_bodies.cpp | 29 +++++-------------- src/simix/popping_enum.h | 1 - src/simix/popping_generated.cpp | 30 ++++++-------------- src/simix/simcalls.in | 1 - src/simix/smx_host_private.h | 4 --- src/simix/smx_vm.cpp | 49 --------------------------------- 8 files changed, 54 insertions(+), 112 deletions(-) diff --git a/src/simix/libsmx.cpp b/src/simix/libsmx.cpp index 13bbba3d67..95f8dfa7d2 100644 --- a/src/simix/libsmx.cpp +++ b/src/simix/libsmx.cpp @@ -295,7 +295,23 @@ void simcall_vm_save(sg_host_t vm) */ void simcall_vm_restore(sg_host_t vm) { - simcall_BODY_vm_restore(vm); + simgrid::simix::kernelImmediate([vm]() { + if (SIMIX_vm_get_state(vm) != SURF_VM_STATE_SAVED) + THROWF(vm_error, 0, "VM(%s) was not saved", vm->name().c_str()); + + XBT_DEBUG("restore VM(%s), where %d processes exist", vm->name().c_str(), + xbt_swag_size(sg_host_simix(vm)->process_list)); + + /* jump to vm_ws_restore() */ + static_cast(vm)->pimpl_vm_->restore(); + + smx_actor_t smx_process, smx_process_safe; + xbt_swag_foreach_safe(smx_process, smx_process_safe, sg_host_simix(vm)->process_list) + { + XBT_DEBUG("resume %s", smx_process->name.c_str()); + SIMIX_process_resume(smx_process); + } + }); } /** @@ -317,7 +333,24 @@ void simcall_vm_shutdown(sg_host_t vm) */ void simcall_vm_destroy(sg_host_t vm) { - simgrid::simix::kernelImmediate(std::bind(SIMIX_vm_destroy, vm)); + simgrid::simix::kernelImmediate([vm]() { + /* this code basically performs a similar thing like SIMIX_host_destroy() */ + XBT_DEBUG("destroy %s", vm->name().c_str()); + + /* FIXME: this is really strange that everything fails if the next line is removed. + * This is as if we shared these data with the PM, which definitely should not be the case... + * + * We need to test that suspending a VM does not suspends the processes running on its PM, for example. + * Or we need to simplify this code enough to make it actually readable (but this sounds harder than testing) + */ + vm->extension_set(nullptr); + + /* Don't free these things twice: they are the ones of my physical host */ + vm->pimpl_cpu = nullptr; + vm->pimpl_netcard = nullptr; + + vm->destroy(); + }); } /** diff --git a/src/simix/popping_accessors.h b/src/simix/popping_accessors.h index b7d2284995..4601e40e4a 100644 --- a/src/simix/popping_accessors.h +++ b/src/simix/popping_accessors.h @@ -42,13 +42,6 @@ static inline void simcall_vm_save__set__ind_vm(smx_simcall_t simcall, sg_host_t simgrid::simix::marshal(simcall->args[0], arg); } -static inline sg_host_t simcall_vm_restore__get__ind_vm(smx_simcall_t simcall) { - return simgrid::simix::unmarshal(simcall->args[0]); -} -static inline void simcall_vm_restore__set__ind_vm(smx_simcall_t simcall, sg_host_t arg) { - simgrid::simix::marshal(simcall->args[0], arg); -} - static inline smx_actor_t simcall_process_kill__get__process(smx_simcall_t simcall) { return simgrid::simix::unmarshal(simcall->args[0]); } @@ -215,13 +208,11 @@ static inline double simcall_execution_parallel_start__get__rate(smx_simcall_t s static inline void simcall_execution_parallel_start__set__rate(smx_simcall_t simcall, double arg) { simgrid::simix::marshal(simcall->args[6], arg); } -static inline double simcall_execution_parallel_start__get__timeout(smx_simcall_t simcall) -{ +static inline double simcall_execution_parallel_start__get__timeout(smx_simcall_t simcall) { return simgrid::simix::unmarshal(simcall->args[7]); } -static inline void simcall_execution_parallel_start__set__timeout(smx_simcall_t simcall, double arg) -{ - simgrid::simix::marshal(simcall->args[7], arg); +static inline void simcall_execution_parallel_start__set__timeout(smx_simcall_t simcall, double arg) { + simgrid::simix::marshal(simcall->args[7], arg); } static inline smx_activity_t simcall_execution_parallel_start__get__result(smx_simcall_t simcall){ return simgrid::simix::unmarshal(simcall->result); diff --git a/src/simix/popping_bodies.cpp b/src/simix/popping_bodies.cpp index de6f79485d..8986295e89 100644 --- a/src/simix/popping_bodies.cpp +++ b/src/simix/popping_bodies.cpp @@ -43,8 +43,7 @@ inline static void simcall_BODY_vm_suspend(sg_host_t ind_vm) { inline static void simcall_BODY_vm_resume(sg_host_t ind_vm) { /* Go to that function to follow the code flow through the simcall barrier */ - if (0) - SIMIX_vm_resume(ind_vm); + if (0) SIMIX_vm_resume(ind_vm); return simcall(SIMCALL_VM_RESUME, ind_vm); } @@ -60,13 +59,6 @@ inline static void simcall_BODY_vm_save(sg_host_t ind_vm) { return simcall(SIMCALL_VM_SAVE, ind_vm); } -inline static void simcall_BODY_vm_restore(sg_host_t ind_vm) { - /* Go to that function to follow the code flow through the simcall barrier */ - if (0) - SIMIX_vm_restore(ind_vm); - return simcall(SIMCALL_VM_RESTORE, ind_vm); - } - inline static void simcall_BODY_process_kill(smx_actor_t process) { /* Go to that function to follow the code flow through the simcall barrier */ if (0) simcall_HANDLER_process_kill(&SIMIX_process_self()->simcall, process); @@ -93,8 +85,7 @@ inline static void simcall_BODY_process_suspend(smx_actor_t process) { inline static void simcall_BODY_process_resume(smx_actor_t process) { /* Go to that function to follow the code flow through the simcall barrier */ - if (0) - SIMIX_process_resume(process); + if (0) SIMIX_process_resume(process); return simcall(SIMCALL_PROCESS_RESUME, process); } @@ -127,17 +118,11 @@ inline static smx_activity_t simcall_BODY_execution_start(const char* name, doub if (0) simcall_HANDLER_execution_start(&SIMIX_process_self()->simcall, name, flops_amount, priority, bound); return simcall(SIMCALL_EXECUTION_START, name, flops_amount, priority, bound); } - - inline static smx_activity_t simcall_BODY_execution_parallel_start(const char* name, int host_nb, - sg_host_t* host_list, double* flops_amount, - double* bytes_amount, double amount, double rate, - double timeout) - { - /* Go to that function to follow the code flow through the simcall barrier */ - if (0) - SIMIX_execution_parallel_start(name, host_nb, host_list, flops_amount, bytes_amount, amount, rate, timeout); - return simcall( - SIMCALL_EXECUTION_PARALLEL_START, name, host_nb, host_list, flops_amount, bytes_amount, amount, rate, timeout); + +inline static smx_activity_t simcall_BODY_execution_parallel_start(const char* name, int host_nb, sg_host_t* host_list, double* flops_amount, double* bytes_amount, double amount, double rate, double timeout) { + /* Go to that function to follow the code flow through the simcall barrier */ + if (0) SIMIX_execution_parallel_start(name, host_nb, host_list, flops_amount, bytes_amount, amount, rate, timeout); + return simcall(SIMCALL_EXECUTION_PARALLEL_START, name, host_nb, host_list, flops_amount, bytes_amount, amount, rate, timeout); } inline static void simcall_BODY_execution_cancel(smx_activity_t execution) { diff --git a/src/simix/popping_enum.h b/src/simix/popping_enum.h index ffd838e53b..cd8d89d307 100644 --- a/src/simix/popping_enum.h +++ b/src/simix/popping_enum.h @@ -22,7 +22,6 @@ typedef enum { SIMCALL_VM_RESUME, SIMCALL_VM_SHUTDOWN, SIMCALL_VM_SAVE, - SIMCALL_VM_RESTORE, SIMCALL_PROCESS_KILL, SIMCALL_PROCESS_KILLALL, SIMCALL_PROCESS_CLEANUP, diff --git a/src/simix/popping_generated.cpp b/src/simix/popping_generated.cpp index 872041e5a6..43c6d26b5d 100644 --- a/src/simix/popping_generated.cpp +++ b/src/simix/popping_generated.cpp @@ -27,7 +27,6 @@ const char* simcall_names[] = { "SIMCALL_VM_RESUME", "SIMCALL_VM_SHUTDOWN", "SIMCALL_VM_SAVE", - "SIMCALL_VM_RESTORE", "SIMCALL_PROCESS_KILL", "SIMCALL_PROCESS_KILLALL", "SIMCALL_PROCESS_CLEANUP", @@ -109,9 +108,9 @@ case SIMCALL_VM_SUSPEND: break; case SIMCALL_VM_RESUME: - SIMIX_vm_resume(simgrid::simix::unmarshal(simcall->args[0])); - SIMIX_simcall_answer(simcall); - break; + SIMIX_vm_resume(simgrid::simix::unmarshal(simcall->args[0])); + SIMIX_simcall_answer(simcall); + break; case SIMCALL_VM_SHUTDOWN: simcall_HANDLER_vm_shutdown(simcall, simgrid::simix::unmarshal(simcall->args[0])); @@ -123,11 +122,6 @@ case SIMCALL_VM_SAVE: SIMIX_simcall_answer(simcall); break; -case SIMCALL_VM_RESTORE: - SIMIX_vm_restore(simgrid::simix::unmarshal(simcall->args[0])); - SIMIX_simcall_answer(simcall); - break; - case SIMCALL_PROCESS_KILL: simcall_HANDLER_process_kill(simcall, simgrid::simix::unmarshal(simcall->args[0])); SIMIX_simcall_answer(simcall); @@ -148,9 +142,9 @@ case SIMCALL_PROCESS_SUSPEND: break; case SIMCALL_PROCESS_RESUME: - SIMIX_process_resume(simgrid::simix::unmarshal(simcall->args[0])); - SIMIX_simcall_answer(simcall); - break; + SIMIX_process_resume(simgrid::simix::unmarshal(simcall->args[0])); + SIMIX_simcall_answer(simcall); + break; case SIMCALL_PROCESS_SET_HOST: simcall_HANDLER_process_set_host(simcall, simgrid::simix::unmarshal(simcall->args[0]), simgrid::simix::unmarshal(simcall->args[1])); @@ -176,15 +170,9 @@ case SIMCALL_EXECUTION_START: break; case SIMCALL_EXECUTION_PARALLEL_START: - simgrid::simix::marshal( - simcall->result, - SIMIX_execution_parallel_start( - simgrid::simix::unmarshal(simcall->args[0]), simgrid::simix::unmarshal(simcall->args[1]), - simgrid::simix::unmarshal(simcall->args[2]), simgrid::simix::unmarshal(simcall->args[3]), - simgrid::simix::unmarshal(simcall->args[4]), simgrid::simix::unmarshal(simcall->args[5]), - simgrid::simix::unmarshal(simcall->args[6]), simgrid::simix::unmarshal(simcall->args[7]))); - SIMIX_simcall_answer(simcall); - break; + simgrid::simix::marshal(simcall->result, SIMIX_execution_parallel_start(simgrid::simix::unmarshal(simcall->args[0]), simgrid::simix::unmarshal(simcall->args[1]), simgrid::simix::unmarshal(simcall->args[2]), simgrid::simix::unmarshal(simcall->args[3]), simgrid::simix::unmarshal(simcall->args[4]), simgrid::simix::unmarshal(simcall->args[5]), simgrid::simix::unmarshal(simcall->args[6]), simgrid::simix::unmarshal(simcall->args[7]))); + SIMIX_simcall_answer(simcall); + break; case SIMCALL_EXECUTION_CANCEL: SIMIX_execution_cancel(simgrid::simix::unmarshal(simcall->args[0])); diff --git a/src/simix/simcalls.in b/src/simix/simcalls.in index 887b1b6a4d..1aa78dd556 100644 --- a/src/simix/simcalls.in +++ b/src/simix/simcalls.in @@ -40,7 +40,6 @@ void vm_suspend(sg_host_t ind_vm); void vm_resume(sg_host_t ind_vm) [[nohandler]]; void vm_shutdown(sg_host_t ind_vm); void vm_save(sg_host_t ind_vm); -void vm_restore(sg_host_t ind_vm) [[nohandler]]; void process_kill(smx_actor_t process); void process_killall(int reset_pid); diff --git a/src/simix/smx_host_private.h b/src/simix/smx_host_private.h index 16a099a27e..0e0d387973 100644 --- a/src/simix/smx_host_private.h +++ b/src/simix/smx_host_private.h @@ -67,16 +67,12 @@ XBT_PRIVATE void SIMIX_execution_finish(simgrid::kernel::activity::Exec *exec); XBT_PRIVATE void SIMIX_set_category(smx_activity_t synchro, const char *category); /* vm related stuff */ -XBT_PRIVATE void SIMIX_vm_destroy(sg_host_t ind_vm); -// -- XBT_PRIVATE void SIMIX_vm_resume(sg_host_t ind_vm); XBT_PRIVATE void SIMIX_vm_suspend(sg_host_t ind_vm, smx_actor_t issuer); // -- XBT_PRIVATE void SIMIX_vm_save(sg_host_t ind_vm, smx_actor_t issuer); -XBT_PRIVATE void SIMIX_vm_restore(sg_host_t ind_vm); -// -- XBT_PRIVATE void SIMIX_vm_start(sg_host_t ind_vm); XBT_PRIVATE void SIMIX_vm_shutdown(sg_host_t ind_vm, smx_actor_t issuer); diff --git a/src/simix/smx_vm.cpp b/src/simix/smx_vm.cpp index f6d3396b46..cd04a97195 100644 --- a/src/simix/smx_vm.cpp +++ b/src/simix/smx_vm.cpp @@ -183,30 +183,6 @@ void simcall_HANDLER_vm_save(smx_simcall_t simcall, sg_host_t vm) SIMIX_vm_save(vm, simcall->issuer); } -/** - * @brief Function to restore a SIMIX VM host. This function restart the execution of the - * VM. All the processes on this VM will run again. - * - * @param vm the vm host to restore (a sg_host_t) - */ -void SIMIX_vm_restore(sg_host_t vm) -{ - if (SIMIX_vm_get_state(vm) != SURF_VM_STATE_SAVED) - THROWF(vm_error, 0, "VM(%s) was not saved", vm->name().c_str()); - - XBT_DEBUG("restore VM(%s), where %d processes exist", - vm->name().c_str(), xbt_swag_size(sg_host_simix(vm)->process_list)); - - /* jump to vm_ws_restore() */ - static_cast(vm)->pimpl_vm_->restore(); - - smx_actor_t smx_process, smx_process_safe; - xbt_swag_foreach_safe(smx_process, smx_process_safe, sg_host_simix(vm)->process_list) { - XBT_DEBUG("resume %s", smx_process->name.c_str()); - SIMIX_process_resume(smx_process); - } -} - /** * @brief Function to shutdown a SIMIX VM host. This function powers off the * VM. All the processes on this VM will be killed. But, the state of the VM is @@ -236,28 +212,3 @@ void simcall_HANDLER_vm_shutdown(smx_simcall_t simcall, sg_host_t vm) { SIMIX_vm_shutdown(vm, simcall->issuer); } - -/** - * @brief Function to destroy a SIMIX VM host. - * - * @param vm the vm host to destroy (a sg_host_t) - */ -void SIMIX_vm_destroy(sg_host_t vm) -{ - /* this code basically performs a similar thing like SIMIX_host_destroy() */ - XBT_DEBUG("destroy %s", vm->name().c_str()); - - /* FIXME: this is really strange that everything fails if the next line is removed. - * This is as if we shared these data with the PM, which definitely should not be the case... - * - * We need to test that suspending a VM does not suspends the processes running on its PM, for example. - * Or we need to simplify this code enough to make it actually readable (but this sounds harder than testing) - */ - vm->extension_set(nullptr); - - /* Don't free these things twice: they are the ones of my physical host */ - vm->pimpl_cpu = nullptr; - vm->pimpl_netcard = nullptr; - - vm->destroy(); -} -- 2.20.1