From: Martin Quinson Date: Mon, 19 Dec 2016 15:42:35 +0000 (+0100) Subject: convert the last vm simcall into s4u code X-Git-Tag: v3_14~23 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/4aea7e49e47243417f094ee62b8e43de066e56d2 convert the last vm simcall into s4u code --- diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index 2eb40a7efa..93176f4f51 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -257,9 +257,6 @@ XBT_PUBLIC(void) simcall_execution_set_priority(smx_activity_t execution, double XBT_PUBLIC(void) simcall_execution_set_bound(smx_activity_t execution, double bound); XBT_PUBLIC(e_smx_state_t) simcall_execution_wait(smx_activity_t execution); -/******************************* VM simcalls ********************************/ -XBT_PUBLIC(void) simcall_vm_shutdown(sg_host_t vm); - /**************************** Process simcalls ********************************/ /* Constructor and Destructor */ XBT_PUBLIC(smx_actor_t) simcall_process_create(const char *name, diff --git a/src/msg/msg_vm.cpp b/src/msg/msg_vm.cpp index 6a9bf584d8..341b4ac3df 100644 --- a/src/msg/msg_vm.cpp +++ b/src/msg/msg_vm.cpp @@ -237,15 +237,19 @@ void MSG_vm_start(msg_vm_t vm) } } -/** @brief Immediately kills all processes within the given VM. Any memory that they allocated will be leaked. +/** @brief Immediately kills all processes within the given VM. * @ingroup msg_VMs * - * FIXME: No extra delay occurs. If you want to simulate this too, you want to use a #MSG_process_sleep() or something. - * I'm not quite sure. + * Any memory that they allocated will be leaked, unless you used #MSG_process_on_exit(). + * + * No extra delay occurs. If you want to simulate this too, you want to use a #MSG_process_sleep(). */ void MSG_vm_shutdown(msg_vm_t vm) { - simcall_vm_shutdown(vm); + smx_actor_t issuer=SIMIX_process_self(); + simgrid::simix::kernelImmediate([vm,issuer]() { + static_cast(vm)->pimpl_vm_->shutdown(issuer); + }); // Make sure that the processes in the VM are killed in this scheduling round before processing // (eg with the VM destroy) diff --git a/src/plugins/vm/VirtualMachineImpl.cpp b/src/plugins/vm/VirtualMachineImpl.cpp index 412cbd13a2..c3f7e05826 100644 --- a/src/plugins/vm/VirtualMachineImpl.cpp +++ b/src/plugins/vm/VirtualMachineImpl.cpp @@ -246,6 +246,32 @@ void VirtualMachineImpl::restore() } } +/** @brief Power off a VM. + * + * All hosted processes will be killed, but the VM state is preserved on memory. + * It can later be restarted. + * + * @param issuer the actor requesting the shutdown + */ +void VirtualMachineImpl::shutdown(smx_actor_t issuer) +{ + if (getState() != SURF_VM_STATE_RUNNING) + THROWF(vm_error, 0, "Cannot shutdown VM %s: it is not running", piface_->cname()); + + xbt_swag_t process_list = piface_->extension()->process_list; + XBT_DEBUG("shutdown VM %s, that contains %d processes", piface_->cname(), xbt_swag_size(process_list)); + + smx_actor_t smx_process, smx_process_safe; + xbt_swag_foreach_safe(smx_process, smx_process_safe, process_list) { + XBT_DEBUG("kill %s", smx_process->cname()); + SIMIX_process_kill(smx_process, issuer); + } + + setState(SURF_VM_STATE_CREATED); + + /* FIXME: we may have to do something at the surf layer, e.g., vcpu action */ +} + /** @brief returns the physical machine on which the VM is running **/ s4u::Host* VirtualMachineImpl::getPm() { diff --git a/src/plugins/vm/VirtualMachineImpl.hpp b/src/plugins/vm/VirtualMachineImpl.hpp index 8af4347fff..2c6e95e9b5 100644 --- a/src/plugins/vm/VirtualMachineImpl.hpp +++ b/src/plugins/vm/VirtualMachineImpl.hpp @@ -74,6 +74,9 @@ public: /** @brief Restore (read from disk+resume) the VM */ virtual void restore(); + /** @brief Shutdown the VM */ + virtual void shutdown(smx_actor_t issuer); + /** @brief Change the physical host on which the given VM is running */ virtual void setPm(s4u::Host* dest); diff --git a/src/simix/libsmx.cpp b/src/simix/libsmx.cpp index dec05d5b30..c92f4e3b5c 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 Shutdown the given VM - * - * \param vm VM - */ -void simcall_vm_shutdown(sg_host_t vm) -{ - simcall_BODY_vm_shutdown(vm); -} - /** * \ingroup simix_process_management * \brief Kills a SIMIX process. diff --git a/src/simix/popping_accessors.h b/src/simix/popping_accessors.h index 8c57448ad2..c4108f4e64 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_shutdown__get__ind_vm(smx_simcall_t simcall) { - return simgrid::simix::unmarshal(simcall->args[0]); -} -static inline void simcall_vm_shutdown__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]); } @@ -1111,7 +1104,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_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); XBT_PRIVATE void simcall_HANDLER_process_suspend(smx_simcall_t simcall, smx_actor_t process); diff --git a/src/simix/popping_bodies.cpp b/src/simix/popping_bodies.cpp index f4de963467..774b702eb5 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_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); - return simcall(SIMCALL_VM_SHUTDOWN, 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); diff --git a/src/simix/popping_enum.h b/src/simix/popping_enum.h index 168ade770c..b10d358b45 100644 --- a/src/simix/popping_enum.h +++ b/src/simix/popping_enum.h @@ -18,7 +18,6 @@ */ typedef enum { SIMCALL_NONE, - SIMCALL_VM_SHUTDOWN, SIMCALL_PROCESS_KILL, SIMCALL_PROCESS_KILLALL, SIMCALL_PROCESS_CLEANUP, diff --git a/src/simix/popping_generated.cpp b/src/simix/popping_generated.cpp index b20e85a13f..742c404c69 100644 --- a/src/simix/popping_generated.cpp +++ b/src/simix/popping_generated.cpp @@ -24,7 +24,6 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_popping); /** @brief Simcalls' names (generated from src/simix/simcalls.in) */ const char* simcall_names[] = { "SIMCALL_NONE", - "SIMCALL_VM_SHUTDOWN", "SIMCALL_PROCESS_KILL", "SIMCALL_PROCESS_KILLALL", "SIMCALL_PROCESS_CLEANUP", @@ -100,11 +99,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_SHUTDOWN: - simcall_HANDLER_vm_shutdown(simcall, 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); diff --git a/src/simix/simcalls.in b/src/simix/simcalls.in index 4c86cca57a..9adf7d2407 100644 --- a/src/simix/simcalls.in +++ b/src/simix/simcalls.in @@ -36,8 +36,6 @@ # ./include/simgrid/simix.h (otherwise you will get a warning at the # compilation time) -void vm_shutdown(sg_host_t ind_vm); - void process_kill(smx_actor_t process); void process_killall(int reset_pid); void process_cleanup(smx_actor_t process) [[nohandler]]; diff --git a/src/simix/smx_host_private.h b/src/simix/smx_host_private.h index 8914ea3b06..0db9188999 100644 --- a/src/simix/smx_host_private.h +++ b/src/simix/smx_host_private.h @@ -66,10 +66,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_shutdown(sg_host_t ind_vm, smx_actor_t issuer); -// -- - SG_END_DECL() #endif diff --git a/src/simix/smx_vm.cpp b/src/simix/smx_vm.cpp deleted file mode 100644 index f70e0f731b..0000000000 --- a/src/simix/smx_vm.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* Copyright (c) 2007-2015. 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. */ - -#include "mc/mc.h" -#include "simgrid/s4u/VirtualMachine.hpp" -#include "smx_private.h" -#include "src/plugins/vm/VirtualMachineImpl.hpp" -#include "src/plugins/vm/VmHostExt.hpp" -#include "src/surf/HostImpl.hpp" - -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_vm, simix, "Logging specific to SIMIX Virtual Machines"); - -/** - * @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 - * preserved on memory. We can later start it again. - * - * @param vm the VM to shutdown (a sg_host_t) - */ -void SIMIX_vm_shutdown(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("shutdown VM %s, that contains %d processes", vm->cname(), xbt_swag_size(sg_host_simix(vm)->process_list)); - - 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("kill %s", smx_process->name.c_str()); - SIMIX_process_kill(smx_process, issuer); - } - - /* FIXME: we may have to do something at the surf layer, e.g., vcpu action */ - static_cast(vm)->pimpl_vm_->setState(SURF_VM_STATE_CREATED); -} - -void simcall_HANDLER_vm_shutdown(smx_simcall_t simcall, sg_host_t vm) -{ - SIMIX_vm_shutdown(vm, simcall->issuer); -} diff --git a/src/xbt/log.c b/src/xbt/log.c index 7b919f069b..67c19a8a78 100644 --- a/src/xbt/log.c +++ b/src/xbt/log.c @@ -228,7 +228,6 @@ static void xbt_log_connect_categories(void) XBT_LOG_CONNECT(simix_process); XBT_LOG_CONNECT(simix_popping); XBT_LOG_CONNECT(simix_synchro); - XBT_LOG_CONNECT(simix_vm); /* smpi */ /* SMPI categories are connected in smpi_global.c */ diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index 871545281f..1e3d6be6b5 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -363,7 +363,6 @@ set(SIMIX_SRC src/simix/smx_network.cpp src/simix/ActorImpl.cpp src/simix/smx_synchro.cpp - src/simix/smx_vm.cpp src/simix/popping.cpp src/kernel/activity/ActivityImpl.cpp src/kernel/activity/SynchroComm.cpp