From: Frederic Suter Date: Wed, 9 Aug 2017 07:38:43 +0000 (+0200) Subject: move VM start function to s4u X-Git-Tag: v3_17~227 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/e595b191c3e10a96a9d896f6ecec9c4df6707aef?hp=3da93efa890d9764d8c8114cdad59217a4e6f17d move VM start function to s4u --- diff --git a/include/simgrid/s4u/VirtualMachine.hpp b/include/simgrid/s4u/VirtualMachine.hpp index b5dbf216d7..4453039929 100644 --- a/include/simgrid/s4u/VirtualMachine.hpp +++ b/include/simgrid/s4u/VirtualMachine.hpp @@ -45,6 +45,7 @@ private: virtual ~VirtualMachine(); public: + void start(); bool isMigrating(); void getParameters(vm_params_t params); diff --git a/src/msg/msg_vm.cpp b/src/msg/msg_vm.cpp index c441886fe7..1dc7c83390 100644 --- a/src/msg/msg_vm.cpp +++ b/src/msg/msg_vm.cpp @@ -184,34 +184,7 @@ void MSG_vm_destroy(msg_vm_t vm) */ void MSG_vm_start(msg_vm_t vm) { - simgrid::simix::kernelImmediate([vm]() { - simgrid::vm::VmHostExt::ensureVmExtInstalled(); - - simgrid::s4u::Host* pm = vm->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 = vm->getRamsize(); - - if (pm_ramsize && not 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::vm::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).", - vm->getCname(), pm->getCname(), 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->getCname(), vm->getCname()); - } - } - - vm->pimpl_vm_->setState(SURF_VM_STATE_RUNNING); - }); - + vm->start(); if (TRACE_msg_vm_is_enabled()) { container_t vm_container = PJ_container_get(vm->getCname()); type_t type = PJ_type_get("MSG_VM_STATE", vm_container->type); @@ -229,11 +202,10 @@ void MSG_vm_start(msg_vm_t vm) */ void MSG_vm_shutdown(msg_vm_t vm) { - smx_actor_t issuer=SIMIX_process_self(); + smx_actor_t issuer = SIMIX_process_self(); simgrid::simix::kernelImmediate([vm, issuer]() { 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) + // Make sure that processes in the VM are killed in this scheduling round before processing (eg with the VM destroy) MSG_process_sleep(0.); } diff --git a/src/plugins/vm/s4u_VirtualMachine.cpp b/src/plugins/vm/s4u_VirtualMachine.cpp index c874d48283..a937519a20 100644 --- a/src/plugins/vm/s4u_VirtualMachine.cpp +++ b/src/plugins/vm/s4u_VirtualMachine.cpp @@ -5,6 +5,7 @@ #include "src/instr/instr_private.h" #include "src/plugins/vm/VirtualMachineImpl.hpp" +#include "src/plugins/vm/VmHostExt.hpp" #include "src/simix/smx_host_private.h" #include "src/surf/cpu_cas01.hpp" @@ -54,6 +55,38 @@ VirtualMachine::~VirtualMachine() pimpl_netpoint = nullptr; } +void VirtualMachine::start() +{ + simgrid::simix::kernelImmediate([this]() { + simgrid::vm::VmHostExt::ensureVmExtInstalled(); + + simgrid::s4u::Host* pm = this->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 = this->getRamsize(); + + if (pm_ramsize && not 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::vm::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).", + this->getCname(), pm->getCname(), 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->getCname(), + this->getCname()); + } + } + + this->pimpl_vm_->setState(SURF_VM_STATE_RUNNING); + }); +} + bool VirtualMachine::isMigrating() { return pimpl_vm_ && pimpl_vm_->isMigrating;