From: Martin Quinson Date: Mon, 19 Dec 2016 15:12:13 +0000 (+0100) Subject: convert vm_suspend from SMX to S4U X-Git-Tag: v3_14~25 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/f87227e5b62e9fb276ba2981fc1611789ece532d convert vm_suspend from SMX to S4U --- diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index 8d06139ef4..2eb40a7efa 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -258,7 +258,6 @@ XBT_PUBLIC(void) simcall_execution_set_bound(smx_activity_t execution, double bo XBT_PUBLIC(e_smx_state_t) simcall_execution_wait(smx_activity_t execution); /******************************* VM simcalls ********************************/ -XBT_PUBLIC(void) simcall_vm_suspend(sg_host_t vm); XBT_PUBLIC(void) simcall_vm_shutdown(sg_host_t vm); /**************************** Process simcalls ********************************/ diff --git a/src/msg/msg_vm.cpp b/src/msg/msg_vm.cpp index 2f3b93dfd6..42f207d679 100644 --- a/src/msg/msg_vm.cpp +++ b/src/msg/msg_vm.cpp @@ -711,7 +711,10 @@ static int migration_tx_fun(int argc, char *argv[]) /* Stage3: stop the VM and copy the rest of states. */ XBT_DEBUG("mig-stage3: remaining_size %f", remaining_size); - simcall_vm_suspend(ms->vm); + simgrid::vm::VirtualMachineImpl* pimpl = static_cast(ms->vm)->pimpl_vm_; + pimpl->setState(SURF_VM_STATE_RUNNING); // FIXME: this bypass of the checks in suspend() is not nice + pimpl->isMigrating = false; // FIXME: this bypass of the checks in suspend() is not nice + pimpl->suspend(SIMIX_process_self()); stop_dirty_page_tracking(ms->vm); try { @@ -834,10 +837,10 @@ void MSG_vm_migrate(msg_vm_t vm, msg_host_t dst_pm) */ void MSG_vm_suspend(msg_vm_t vm) { - if (MSG_vm_is_migrating(vm)) - THROWF(vm_error, 0, "Cannot suspend VM '%s', which is migrating", vm->cname()); - - simcall_vm_suspend(vm); + smx_actor_t issuer = SIMIX_process_self(); + simgrid::simix::kernelImmediate([vm,issuer]() { + static_cast(vm)->pimpl_vm_->suspend(issuer); + }); XBT_DEBUG("vm_suspend done"); diff --git a/src/plugins/vm/VirtualMachineImpl.cpp b/src/plugins/vm/VirtualMachineImpl.cpp index 74d2ea749d..11b0f16e75 100644 --- a/src/plugins/vm/VirtualMachineImpl.cpp +++ b/src/plugins/vm/VirtualMachineImpl.cpp @@ -154,9 +154,28 @@ void VirtualMachineImpl::setState(e_surf_vm_state_t state) { vmState_ = state; } -void VirtualMachineImpl::suspend() +void VirtualMachineImpl::suspend(smx_actor_t issuer) { + if (isMigrating) + THROWF(vm_error, 0, "Cannot suspend VM '%s': it is migrating", piface_->cname()); + if (getState() != SURF_VM_STATE_RUNNING) + THROWF(vm_error, 0, "Cannot suspend VM %s: it is not running.", piface_->cname()); + if (issuer->host == piface_) + THROWF(vm_error, 0, "Actor %s cannot suspend the VM %s in which it runs", issuer->cname(), piface_->cname()); + + xbt_swag_t process_list = piface_->extension()->process_list; + XBT_DEBUG("suspend VM(%s), where %d processes exist", piface_->cname(), xbt_swag_size(process_list)); + action_->suspend(); + + smx_actor_t smx_process, smx_process_safe; + xbt_swag_foreach_safe(smx_process, smx_process_safe, process_list) { + XBT_DEBUG("suspend %s", smx_process->name.c_str()); + SIMIX_process_suspend(smx_process, issuer); + } + + XBT_DEBUG("suspend all processes on the VM done done"); + vmState_ = SURF_VM_STATE_SUSPENDED; } @@ -195,7 +214,6 @@ void VirtualMachineImpl::save(smx_actor_t issuer) THROWF(vm_error, 0, "Cannot save VM %s: it is not running.", piface_->cname()); xbt_swag_t process_list = piface_->extension()->process_list; - XBT_DEBUG("Save VM %s, where %d processes exist", piface_->cname(), xbt_swag_size(process_list)); vmState_ = SURF_VM_STATE_SAVING; diff --git a/src/plugins/vm/VirtualMachineImpl.hpp b/src/plugins/vm/VirtualMachineImpl.hpp index ea04c471f8..bc446c9360 100644 --- a/src/plugins/vm/VirtualMachineImpl.hpp +++ b/src/plugins/vm/VirtualMachineImpl.hpp @@ -63,7 +63,7 @@ public: ~VirtualMachineImpl(); /** @brief Suspend the VM */ - virtual void suspend(); + virtual void suspend(smx_actor_t issuer); /** @brief Resume the VM */ virtual void resume(); @@ -71,7 +71,7 @@ public: /** @brief Save the VM */ virtual void save(smx_actor_t issuer); - /** @brief Restore the VM (Not yet implemented) */ + /** @brief Restore the VM */ virtual void restore(); /** @brief Migrate the VM to the destination host */ diff --git a/src/simix/libsmx.cpp b/src/simix/libsmx.cpp index 5afac827ef..dec05d5b30 100644 --- a/src/simix/libsmx.cpp +++ b/src/simix/libsmx.cpp @@ -161,17 +161,6 @@ e_smx_state_t simcall_execution_wait(smx_activity_t execution) return (e_smx_state_t) simcall_BODY_execution_wait(execution); } -/** - * \ingroup simix_vm_management - * \brief Suspend the given VM - * - * \param vm VM - */ -void simcall_vm_suspend(sg_host_t vm) -{ - simcall_BODY_vm_suspend(vm); -} - /** * \ingroup simix_vm_management * \brief Shutdown the given VM diff --git a/src/simix/popping_accessors.h b/src/simix/popping_accessors.h index 70ef173af5..8c57448ad2 100644 --- a/src/simix/popping_accessors.h +++ b/src/simix/popping_accessors.h @@ -14,13 +14,6 @@ */ #include "src/simix/popping_private.h" -static inline sg_host_t simcall_vm_suspend__get__ind_vm(smx_simcall_t simcall) { - return simgrid::simix::unmarshal(simcall->args[0]); -} -static inline void simcall_vm_suspend__set__ind_vm(smx_simcall_t simcall, sg_host_t arg) { - simgrid::simix::marshal(simcall->args[0], arg); -} - static inline sg_host_t simcall_vm_shutdown__get__ind_vm(smx_simcall_t simcall) { return simgrid::simix::unmarshal(simcall->args[0]); } @@ -1118,7 +1111,6 @@ static inline void simcall_run_blocking__set__code(smx_simcall_t simcall, std::f /* The prototype of all simcall handlers, automatically generated for you */ -XBT_PRIVATE void simcall_HANDLER_vm_suspend(smx_simcall_t simcall, sg_host_t ind_vm); XBT_PRIVATE void simcall_HANDLER_vm_shutdown(smx_simcall_t simcall, sg_host_t ind_vm); XBT_PRIVATE void simcall_HANDLER_process_kill(smx_simcall_t simcall, smx_actor_t process); XBT_PRIVATE void simcall_HANDLER_process_killall(smx_simcall_t simcall, int reset_pid); diff --git a/src/simix/popping_bodies.cpp b/src/simix/popping_bodies.cpp index 78d1a92e79..f4de963467 100644 --- a/src/simix/popping_bodies.cpp +++ b/src/simix/popping_bodies.cpp @@ -35,12 +35,6 @@ inline static R simcall(e_smx_simcall_t call, T const&... t) return simgrid::simix::unmarshal(self->simcall.result); } -inline static void simcall_BODY_vm_suspend(sg_host_t ind_vm) { - /* Go to that function to follow the code flow through the simcall barrier */ - if (0) simcall_HANDLER_vm_suspend(&SIMIX_process_self()->simcall, ind_vm); - return simcall(SIMCALL_VM_SUSPEND, ind_vm); - } - inline static void simcall_BODY_vm_shutdown(sg_host_t ind_vm) { /* Go to that function to follow the code flow through the simcall barrier */ if (0) simcall_HANDLER_vm_shutdown(&SIMIX_process_self()->simcall, ind_vm); diff --git a/src/simix/popping_enum.h b/src/simix/popping_enum.h index f7effdb519..168ade770c 100644 --- a/src/simix/popping_enum.h +++ b/src/simix/popping_enum.h @@ -18,7 +18,6 @@ */ typedef enum { SIMCALL_NONE, - SIMCALL_VM_SUSPEND, SIMCALL_VM_SHUTDOWN, SIMCALL_PROCESS_KILL, SIMCALL_PROCESS_KILLALL, diff --git a/src/simix/popping_generated.cpp b/src/simix/popping_generated.cpp index 16081732df..b20e85a13f 100644 --- a/src/simix/popping_generated.cpp +++ b/src/simix/popping_generated.cpp @@ -23,70 +23,71 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_popping); /** @brief Simcalls' names (generated from src/simix/simcalls.in) */ const char* simcall_names[] = { - "SIMCALL_NONE", "SIMCALL_VM_SUSPEND", - "SIMCALL_VM_SHUTDOWN", - "SIMCALL_PROCESS_KILL", - "SIMCALL_PROCESS_KILLALL", - "SIMCALL_PROCESS_CLEANUP", - "SIMCALL_PROCESS_SUSPEND", - "SIMCALL_PROCESS_RESUME", - "SIMCALL_PROCESS_SET_HOST", - "SIMCALL_PROCESS_IS_SUSPENDED", - "SIMCALL_PROCESS_JOIN", - "SIMCALL_PROCESS_SLEEP", - "SIMCALL_EXECUTION_START", - "SIMCALL_EXECUTION_PARALLEL_START", - "SIMCALL_EXECUTION_CANCEL", - "SIMCALL_EXECUTION_SET_PRIORITY", - "SIMCALL_EXECUTION_SET_BOUND", - "SIMCALL_EXECUTION_WAIT", - "SIMCALL_PROCESS_ON_EXIT", - "SIMCALL_PROCESS_AUTO_RESTART_SET", - "SIMCALL_PROCESS_RESTART", - "SIMCALL_MBOX_CREATE", - "SIMCALL_MBOX_SET_RECEIVER", - "SIMCALL_COMM_IPROBE", - "SIMCALL_COMM_SEND", - "SIMCALL_COMM_ISEND", - "SIMCALL_COMM_RECV", - "SIMCALL_COMM_IRECV", - "SIMCALL_COMM_WAITANY", - "SIMCALL_COMM_WAIT", - "SIMCALL_COMM_TEST", - "SIMCALL_COMM_TESTANY", - "SIMCALL_MUTEX_INIT", - "SIMCALL_MUTEX_LOCK", - "SIMCALL_MUTEX_TRYLOCK", - "SIMCALL_MUTEX_UNLOCK", - "SIMCALL_COND_INIT", - "SIMCALL_COND_SIGNAL", - "SIMCALL_COND_WAIT", - "SIMCALL_COND_WAIT_TIMEOUT", - "SIMCALL_COND_BROADCAST", - "SIMCALL_SEM_INIT", - "SIMCALL_SEM_RELEASE", - "SIMCALL_SEM_WOULD_BLOCK", - "SIMCALL_SEM_ACQUIRE", - "SIMCALL_SEM_ACQUIRE_TIMEOUT", - "SIMCALL_SEM_GET_CAPACITY", - "SIMCALL_FILE_READ", - "SIMCALL_FILE_WRITE", - "SIMCALL_FILE_OPEN", - "SIMCALL_FILE_CLOSE", - "SIMCALL_FILE_UNLINK", - "SIMCALL_FILE_GET_SIZE", - "SIMCALL_FILE_TELL", - "SIMCALL_FILE_SEEK", - "SIMCALL_FILE_GET_INFO", - "SIMCALL_FILE_MOVE", - "SIMCALL_STORAGE_GET_FREE_SIZE", - "SIMCALL_STORAGE_GET_USED_SIZE", - "SIMCALL_STORAGE_GET_PROPERTIES", - "SIMCALL_STORAGE_GET_CONTENT", - "SIMCALL_MC_RANDOM", - "SIMCALL_SET_CATEGORY", - "SIMCALL_RUN_KERNEL", - "SIMCALL_RUN_BLOCKING",}; + "SIMCALL_NONE", + "SIMCALL_VM_SHUTDOWN", + "SIMCALL_PROCESS_KILL", + "SIMCALL_PROCESS_KILLALL", + "SIMCALL_PROCESS_CLEANUP", + "SIMCALL_PROCESS_SUSPEND", + "SIMCALL_PROCESS_RESUME", + "SIMCALL_PROCESS_SET_HOST", + "SIMCALL_PROCESS_IS_SUSPENDED", + "SIMCALL_PROCESS_JOIN", + "SIMCALL_PROCESS_SLEEP", + "SIMCALL_EXECUTION_START", + "SIMCALL_EXECUTION_PARALLEL_START", + "SIMCALL_EXECUTION_CANCEL", + "SIMCALL_EXECUTION_SET_PRIORITY", + "SIMCALL_EXECUTION_SET_BOUND", + "SIMCALL_EXECUTION_WAIT", + "SIMCALL_PROCESS_ON_EXIT", + "SIMCALL_PROCESS_AUTO_RESTART_SET", + "SIMCALL_PROCESS_RESTART", + "SIMCALL_MBOX_CREATE", + "SIMCALL_MBOX_SET_RECEIVER", + "SIMCALL_COMM_IPROBE", + "SIMCALL_COMM_SEND", + "SIMCALL_COMM_ISEND", + "SIMCALL_COMM_RECV", + "SIMCALL_COMM_IRECV", + "SIMCALL_COMM_WAITANY", + "SIMCALL_COMM_WAIT", + "SIMCALL_COMM_TEST", + "SIMCALL_COMM_TESTANY", + "SIMCALL_MUTEX_INIT", + "SIMCALL_MUTEX_LOCK", + "SIMCALL_MUTEX_TRYLOCK", + "SIMCALL_MUTEX_UNLOCK", + "SIMCALL_COND_INIT", + "SIMCALL_COND_SIGNAL", + "SIMCALL_COND_WAIT", + "SIMCALL_COND_WAIT_TIMEOUT", + "SIMCALL_COND_BROADCAST", + "SIMCALL_SEM_INIT", + "SIMCALL_SEM_RELEASE", + "SIMCALL_SEM_WOULD_BLOCK", + "SIMCALL_SEM_ACQUIRE", + "SIMCALL_SEM_ACQUIRE_TIMEOUT", + "SIMCALL_SEM_GET_CAPACITY", + "SIMCALL_FILE_READ", + "SIMCALL_FILE_WRITE", + "SIMCALL_FILE_OPEN", + "SIMCALL_FILE_CLOSE", + "SIMCALL_FILE_UNLINK", + "SIMCALL_FILE_GET_SIZE", + "SIMCALL_FILE_TELL", + "SIMCALL_FILE_SEEK", + "SIMCALL_FILE_GET_INFO", + "SIMCALL_FILE_MOVE", + "SIMCALL_STORAGE_GET_FREE_SIZE", + "SIMCALL_STORAGE_GET_USED_SIZE", + "SIMCALL_STORAGE_GET_PROPERTIES", + "SIMCALL_STORAGE_GET_CONTENT", + "SIMCALL_MC_RANDOM", + "SIMCALL_SET_CATEGORY", + "SIMCALL_RUN_KERNEL", + "SIMCALL_RUN_BLOCKING", +}; /** @private * @brief (in kernel mode) unpack the simcall and activate the handler @@ -99,11 +100,6 @@ void SIMIX_simcall_handle(smx_simcall_t simcall, int value) { if (simcall->issuer->context->iwannadie && simcall->call != SIMCALL_PROCESS_CLEANUP) return; switch (simcall->call) { -case SIMCALL_VM_SUSPEND: - simcall_HANDLER_vm_suspend(simcall, 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])); SIMIX_simcall_answer(simcall); diff --git a/src/simix/simcalls.in b/src/simix/simcalls.in index c8de23a905..4c86cca57a 100644 --- a/src/simix/simcalls.in +++ b/src/simix/simcalls.in @@ -36,7 +36,6 @@ # ./include/simgrid/simix.h (otherwise you will get a warning at the # compilation time) -void vm_suspend(sg_host_t ind_vm); void vm_shutdown(sg_host_t ind_vm); void process_kill(smx_actor_t process); diff --git a/src/simix/simcalls.py b/src/simix/simcalls.py index eff39b7a07..e7ab56cfcb 100755 --- a/src/simix/simcalls.py +++ b/src/simix/simcalls.py @@ -75,7 +75,7 @@ class Simcall(object): return ' SIMCALL_%s,' % (self.name.upper()) def string(self): - return ' "SIMCALL_%s",' % self.name.upper() + return ' "SIMCALL_%s",' % self.name.upper() def accessors(self): res = [] @@ -300,10 +300,10 @@ if __name__ == '__main__': '/** @brief Simcalls\' names (generated from src/simix/simcalls.in) */\n') fd.write('const char* simcall_names[] = {\n') - fd.write(' "SIMCALL_NONE",') + fd.write(' "SIMCALL_NONE",\n') handle(fd, Simcall.string, simcalls, simcalls_dict) - fd.write('};\n\n') + fd.write('\n};\n\n') fd.write('/** @private\n') fd.write( diff --git a/src/simix/smx_host_private.h b/src/simix/smx_host_private.h index cc6e69768b..8914ea3b06 100644 --- a/src/simix/smx_host_private.h +++ b/src/simix/smx_host_private.h @@ -67,8 +67,6 @@ 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_suspend(sg_host_t ind_vm, smx_actor_t issuer); -// -- 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 ffea83851a..f70e0f731b 100644 --- a/src/simix/smx_vm.cpp +++ b/src/simix/smx_vm.cpp @@ -12,41 +12,6 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_vm, simix, "Logging specific to SIMIX Virtual Machines"); -/** - * @brief Function to suspend a SIMIX VM host. This function stops the execution of the - * VM. All the processes on this VM will pause. The state of the VM is - * preserved on memory. We can later resume it again. - * - * @param vm the vm host to suspend (a sg_host_t) - */ -void SIMIX_vm_suspend(sg_host_t vm, smx_actor_t issuer) -{ - if (static_cast(vm)->pimpl_vm_->getState() != SURF_VM_STATE_RUNNING) - THROWF(vm_error, 0, "VM(%s) is not running", vm->cname()); - - XBT_DEBUG("suspend VM(%s), where %d processes exist", vm->cname(), xbt_swag_size(sg_host_simix(vm)->process_list)); - - /* jump to vm_ws_suspend. The state will be set. */ - static_cast(vm)->pimpl_vm_->suspend(); - - 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("suspend %s", smx_process->name.c_str()); - SIMIX_process_suspend(smx_process, issuer); - } - - XBT_DEBUG("suspend all processes on the VM done done"); -} - -void simcall_HANDLER_vm_suspend(smx_simcall_t simcall, sg_host_t vm) -{ - xbt_assert(simcall->issuer->host != vm, "cannot suspend the VM where I run"); - - SIMIX_vm_suspend(vm, simcall->issuer); - - XBT_DEBUG("simcall_HANDLER_vm_suspend done"); -} - /** * @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