From 2e4aed16ce98904c05e1f9a17cff805d4f5a266e Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Tue, 22 Nov 2016 12:09:23 +0100 Subject: [PATCH] inline 4 more VM simcalls I had to add some methods to s4u::VM, such as getRamsize() --- include/simgrid/s4u/VirtualMachine.hpp | 1 + include/simgrid/simix.h | 3 -- src/msg/msg_vm.cpp | 53 ++++++++++++++++++++++++-- src/plugins/vm/VirtualMachineImpl.hpp | 2 + src/plugins/vm/s4u_VirtualMachine.cpp | 4 ++ src/simix/libsmx.cpp | 50 ------------------------ src/simix/smx_host_private.h | 2 - src/simix/smx_vm.cpp | 31 --------------- 8 files changed, 56 insertions(+), 90 deletions(-) diff --git a/include/simgrid/s4u/VirtualMachine.hpp b/include/simgrid/s4u/VirtualMachine.hpp index d914d8e35f..b603af48e1 100644 --- a/include/simgrid/s4u/VirtualMachine.hpp +++ b/include/simgrid/s4u/VirtualMachine.hpp @@ -52,6 +52,7 @@ public: void parameters(vm_params_t params); void setParameters(vm_params_t params); + double getRamsize(); /* FIXME: protect me */ simgrid::surf::VirtualMachineImpl* pimpl_vm_ = nullptr; diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index 7afd8d23c7..9b0c8e6da8 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -259,11 +259,8 @@ XBT_PUBLIC(e_smx_state_t) simcall_execution_wait(smx_activity_t execution); /******************************* VM simcalls ********************************/ // Create the vm_workstation at the SURF level -XBT_PUBLIC(void) simcall_vm_start(sg_host_t vm); -XBT_PUBLIC(void) simcall_vm_set_bound(sg_host_t vm, double bound); XBT_PUBLIC(void) simcall_vm_resume(sg_host_t vm); XBT_PUBLIC(void) simcall_vm_save(sg_host_t vm); -XBT_PUBLIC(void) simcall_vm_restore(sg_host_t vm); XBT_PUBLIC(void) simcall_vm_suspend(sg_host_t vm); XBT_PUBLIC(void) simcall_vm_shutdown(sg_host_t vm); diff --git a/src/msg/msg_vm.cpp b/src/msg/msg_vm.cpp index 5c268ac091..acdfbcb347 100644 --- a/src/msg/msg_vm.cpp +++ b/src/msg/msg_vm.cpp @@ -13,6 +13,7 @@ #include "src/plugins/vm/VirtualMachineImpl.hpp" #include "src/plugins/vm/VmHostExt.hpp" +#include "src/simix/ActorImpl.hpp" #include #include @@ -195,11 +196,38 @@ void MSG_vm_destroy(msg_vm_t vm) /** @brief Start a vm (i.e., boot the guest operating system) * @ingroup msg_VMs * - * If the VM cannot be started, an exception is generated. + * If the VM cannot be started (because of memory overprovisionning), an exception is generated. */ void MSG_vm_start(msg_vm_t vm) { - simcall_vm_start(vm); + simgrid::simix::kernelImmediate([vm]() { + simgrid::vm::VmHostExt::ensureVmExtInstalled(); + + simgrid::s4u::VirtualMachine* typedVM = static_cast(vm); + simgrid::s4u::Host* pm = typedVM->pimpl_vm_->getPm(); + if (pm->extension() == nullptr) + pm->extension_set(new simgrid::vm::VmHostExt()); + + long pm_ramsize = pm->extension()->ramsize; + int pm_overcommit = pm->extension()->overcommit; + long vm_ramsize = typedVM->getRamsize(); + + if (pm_ramsize && !pm_overcommit) { /* Only verify that we don't overcommit on need */ + /* Retrieve the memory occupied by the VMs on that host. Yep, we have to traverse all VMs of all hosts for that */ + long total_ramsize_of_vms = 0; + for (simgrid::s4u::VirtualMachine* ws_vm : simgrid::surf::VirtualMachineImpl::allVms_) + if (pm == ws_vm->pimpl_vm_->getPm()) + total_ramsize_of_vms += ws_vm->pimpl_vm_->getRamsize(); + + if (vm_ramsize > pm_ramsize - total_ramsize_of_vms) { + XBT_WARN("cannnot start %s@%s due to memory shortage: vm_ramsize %ld, free %ld, pm_ramsize %ld (bytes).", + sg_host_get_name(vm), sg_host_get_name(pm), vm_ramsize, pm_ramsize - total_ramsize_of_vms, pm_ramsize); + THROWF(vm_error, 0, "Memory shortage on host '%s', VM '%s' cannot be started", pm->cname(), vm->cname()); + } + } + + typedVM->pimpl_vm_->setState(SURF_VM_STATE_RUNNING); + }); if (TRACE_msg_vm_is_enabled()) { container_t vm_container = PJ_container_get(vm->name().c_str()); @@ -919,7 +947,23 @@ void MSG_vm_save(msg_vm_t vm) */ void MSG_vm_restore(msg_vm_t vm) { - simcall_vm_restore(vm); + simgrid::simix::kernelImmediate([vm]() { + if (static_cast(vm)->pimpl_vm_->getState() != 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); + } + }); if (TRACE_msg_vm_is_enabled()) { container_t vm_container = PJ_container_get(vm->cname()); @@ -964,5 +1008,6 @@ msg_host_t MSG_vm_get_pm(msg_vm_t vm) */ void MSG_vm_set_bound(msg_vm_t vm, double bound) { - simcall_vm_set_bound(vm, bound); + simgrid::simix::kernelImmediate( + [vm, bound]() { static_cast(vm)->pimpl_vm_->setBound(bound); }); } diff --git a/src/plugins/vm/VirtualMachineImpl.hpp b/src/plugins/vm/VirtualMachineImpl.hpp index 353f9a9074..4df8c25555 100644 --- a/src/plugins/vm/VirtualMachineImpl.hpp +++ b/src/plugins/vm/VirtualMachineImpl.hpp @@ -56,6 +56,8 @@ extern XBT_PRIVATE simgrid::xbt::signalisMigrating; } +double VirtualMachine::getRamsize() +{ + return pimpl_vm_->params_.ramsize; +} /** @brief Retrieve a copy of the parameters of that VM/PM * @details The ramsize and overcommit fields are used on the PM too */ diff --git a/src/simix/libsmx.cpp b/src/simix/libsmx.cpp index a3bf0a9aa6..1322fcdc24 100644 --- a/src/simix/libsmx.cpp +++ b/src/simix/libsmx.cpp @@ -175,29 +175,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 Start the given VM to the given physical host - * - * \param vm VM - */ -void simcall_vm_start(sg_host_t vm) -{ - simgrid::simix::kernelImmediate(std::bind(SIMIX_vm_start, vm)); -} - -/** - * @brief Function to set the CPU bound of the given SIMIX VM host. - * - * @param host the vm host (a sg_host_t) - * @param bound bound (a double) - */ -void simcall_vm_set_bound(sg_host_t vm, double bound) -{ - simgrid::simix::kernelImmediate( - [vm, bound]() { static_cast(vm)->pimpl_vm_->setBound(bound); }); -} - /** * \ingroup simix_vm_management * \brief Suspend the given VM @@ -231,33 +208,6 @@ void simcall_vm_save(sg_host_t vm) simcall_BODY_vm_save(vm); } -/** - * \ingroup simix_vm_management - * \brief Restore the given VM - * - * \param vm VM - */ -void simcall_vm_restore(sg_host_t vm) -{ - simgrid::simix::kernelImmediate([vm]() { - if (static_cast(vm)->pimpl_vm_->getState() != 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); - } - }); -} - /** * \ingroup simix_vm_management * \brief Shutdown the given VM diff --git a/src/simix/smx_host_private.h b/src/simix/smx_host_private.h index 794df1984c..9482e444ff 100644 --- a/src/simix/smx_host_private.h +++ b/src/simix/smx_host_private.h @@ -73,8 +73,6 @@ 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_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 429bd5cd45..0e85880b79 100644 --- a/src/simix/smx_vm.cpp +++ b/src/simix/smx_vm.cpp @@ -12,7 +12,6 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_vm, simix, "Logging specific to SIMIX Virtual Machines"); -/* works for VMs and PMs */ static long host_get_ramsize(sg_host_t vm, int *overcommit) { s_vm_params_t params; @@ -24,36 +23,6 @@ static long host_get_ramsize(sg_host_t vm, int *overcommit) return params.ramsize; } -/* **** start a VM **** */ -void SIMIX_vm_start(sg_host_t vm) -{ - sg_host_t pm = static_cast(vm)->pimpl_vm_->getPm(); - - simgrid::vm::VmHostExt::ensureVmExtInstalled(); - if (pm->extension() == nullptr) - pm->extension_set(new simgrid::vm::VmHostExt()); - - long pm_ramsize = pm->extension()->ramsize; - int pm_overcommit = pm->extension()->overcommit; - long vm_ramsize = host_get_ramsize(vm, nullptr); - - if (pm_ramsize && !pm_overcommit) { /* Only verify that we don't overcommit on need */ - /* Retrieve the memory occupied by the VMs on that host. Yep, we have to traverse all VMs of all hosts for that */ - long total_ramsize_of_vms = 0; - for (simgrid::s4u::VirtualMachine* ws_vm : simgrid::surf::VirtualMachineImpl::allVms_) - if (pm == ws_vm->pimpl_vm_->getPm()) - total_ramsize_of_vms += ws_vm->pimpl_vm_->getRamsize(); - - if (vm_ramsize > pm_ramsize - total_ramsize_of_vms) { - XBT_WARN("cannnot start %s@%s due to memory shortage: vm_ramsize %ld, free %ld, pm_ramsize %ld (bytes).", - sg_host_get_name(vm), sg_host_get_name(pm), vm_ramsize, pm_ramsize - total_ramsize_of_vms, pm_ramsize); - THROWF(vm_error, 0, "The VM %s cannot be started", vm->name().c_str()); - } - } - - static_cast(vm)->pimpl_vm_->setState(SURF_VM_STATE_RUNNING); -} - /** * @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 -- 2.20.1