X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/05bf7d8e4e62e224875308513bc22fe18bcdbcaa..71d215251ec3eeb3e4192c0e14ec6dea8fd97007:/src/plugins/vm/s4u_VirtualMachine.cpp diff --git a/src/plugins/vm/s4u_VirtualMachine.cpp b/src/plugins/vm/s4u_VirtualMachine.cpp index 5ba43bdf20..2e3a673c1b 100644 --- a/src/plugins/vm/s4u_VirtualMachine.cpp +++ b/src/plugins/vm/s4u_VirtualMachine.cpp @@ -5,6 +5,7 @@ #include "simgrid/s4u/Actor.hpp" #include "simgrid/vm.h" +#include "src/include/surf/surf.hpp" #include "src/plugins/vm/VirtualMachineImpl.hpp" #include "src/plugins/vm/VmHostExt.hpp" #include "src/simix/smx_host_private.hpp" @@ -20,16 +21,21 @@ simgrid::xbt::signal VirtualMachine::on_started; simgrid::xbt::signal VirtualMachine::on_shutdown; simgrid::xbt::signal VirtualMachine::on_suspend; simgrid::xbt::signal VirtualMachine::on_resume; +simgrid::xbt::signal VirtualMachine::on_migration_start; +simgrid::xbt::signal VirtualMachine::on_migration_end; -VirtualMachine::VirtualMachine(const char* name, s4u::Host* physical_host, int core_amount) +VirtualMachine::VirtualMachine(std::string name, s4u::Host* physical_host, int core_amount) : VirtualMachine(name, physical_host, core_amount, 1024) { } -VirtualMachine::VirtualMachine(const char* name, s4u::Host* physical_host, int core_amount, size_t ramsize) +VirtualMachine::VirtualMachine(std::string name, s4u::Host* physical_host, int core_amount, size_t ramsize) : Host(name), pimpl_vm_(new vm::VirtualMachineImpl(this, physical_host, core_amount, ramsize)) { - XBT_DEBUG("Create VM %s", name); + // xbt_assert(s4u::Host::by_name(name) == nullptr, + // "Cannot create a VM named %s: this name is already used by an host or a VM", name.c_str()); + + XBT_DEBUG("Create VM %s", name.c_str()); /* Currently, a VM uses the network resource of its physical host */ pimpl_netpoint = physical_host->pimpl_netpoint; @@ -37,14 +43,11 @@ VirtualMachine::VirtualMachine(const char* name, s4u::Host* physical_host, int c // Create a VCPU for this VM std::vector speeds; for (int i = 0; i < physical_host->get_pstate_count(); i++) - speeds.push_back(physical_host->getPstateSpeed(i)); + speeds.push_back(physical_host->get_pstate_speed(i)); surf_cpu_model_vm->create_cpu(this, &speeds, physical_host->get_core_count()); if (physical_host->get_pstate() != 0) set_pstate(physical_host->get_pstate()); - - /* Make a process container */ - extension_set(new simgrid::simix::Host()); } VirtualMachine::~VirtualMachine() @@ -53,14 +56,6 @@ VirtualMachine::~VirtualMachine() XBT_DEBUG("destroy %s", get_cname()); - /* 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) - */ - extension_set(nullptr); - /* Don't free these things twice: they are the ones of my physical host */ pimpl_netpoint = nullptr; } @@ -78,14 +73,14 @@ void VirtualMachine::start() long pm_ramsize = pm->extension()->ramsize; int pm_overcommit = pm->extension()->overcommit; - long vm_ramsize = this->getRamsize(); + long vm_ramsize = this->get_ramsize(); 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* const& ws_vm : simgrid::vm::VirtualMachineImpl::allVms_) - if (pm == ws_vm->getPm()) - total_ramsize_of_vms += ws_vm->getRamsize(); + if (pm == ws_vm->get_pm()) + total_ramsize_of_vms += ws_vm->get_ramsize(); if (vm_ramsize > pm_ramsize - total_ramsize_of_vms) { XBT_WARN("cannot start %s@%s due to memory shortage: vm_ramsize %ld, free %ld, pm_ramsize %ld (bytes).", @@ -95,7 +90,7 @@ void VirtualMachine::start() } } - this->pimpl_vm_->set_state(SURF_VM_STATE_RUNNING); + this->pimpl_vm_->set_state(VirtualMachine::state::RUNNING); }); on_started(*this); @@ -130,27 +125,27 @@ void VirtualMachine::destroy() Host::destroy(); } -simgrid::s4u::Host* VirtualMachine::getPm() +simgrid::s4u::Host* VirtualMachine::get_pm() { return pimpl_vm_->get_physical_host(); } -void VirtualMachine::setPm(simgrid::s4u::Host* pm) +void VirtualMachine::set_pm(simgrid::s4u::Host* pm) { simgrid::simix::simcall([this, pm]() { pimpl_vm_->set_physical_host(pm); }); } -e_surf_vm_state_t VirtualMachine::getState() +VirtualMachine::state VirtualMachine::get_state() { return simgrid::simix::simcall([this]() { return pimpl_vm_->get_state(); }); } -size_t VirtualMachine::getRamsize() +size_t VirtualMachine::get_ramsize() { return pimpl_vm_->get_ramsize(); } -void VirtualMachine::setRamsize(size_t ramsize) +void VirtualMachine::set_ramsize(size_t ramsize) { pimpl_vm_->set_ramsize(ramsize); } @@ -180,7 +175,7 @@ void VirtualMachine::setRamsize(size_t ramsize) * 2. Note that bound == 0 means no bound (i.e., unlimited). But, if a host has multiple CPU cores, the CPU share of a * computation task (or a VM) never exceeds the capacity of a CPU core. */ -void VirtualMachine::setBound(double bound) +void VirtualMachine::set_bound(double bound) { simgrid::simix::simcall([this, bound]() { pimpl_vm_->set_bound(bound); }); } @@ -202,9 +197,6 @@ sg_vm_t sg_vm_create_core(sg_host_t pm, const char* name) */ sg_vm_t sg_vm_create_multicore(sg_host_t pm, const char* name, int coreAmount) { - xbt_assert(sg_host_by_name(name) == nullptr, - "Cannot create a VM named %s: this name is already used by an host or a VM", name); - return new simgrid::s4u::VirtualMachine(name, pm, coreAmount); } @@ -216,40 +208,40 @@ const char* sg_vm_get_name(sg_vm_t vm) /** @brief Get the physical host of a given VM. */ sg_host_t sg_vm_get_pm(sg_vm_t vm) { - return vm->getPm(); + return vm->get_pm(); } void sg_vm_set_ramsize(sg_vm_t vm, size_t size) { - vm->setRamsize(size); + vm->set_ramsize(size); } size_t sg_vm_get_ramsize(sg_vm_t vm) { - return vm->getRamsize(); + return vm->get_ramsize(); } void sg_vm_set_bound(sg_vm_t vm, double bound) { - vm->setBound(bound); + vm->set_bound(bound); } /** @brief Returns whether the given VM has just created, not running. */ int sg_vm_is_created(sg_vm_t vm) { - return vm->getState() == SURF_VM_STATE_CREATED; + return vm->get_state() == simgrid::s4u::VirtualMachine::state::CREATED; } /** @brief Returns whether the given VM is currently running */ int sg_vm_is_running(sg_vm_t vm) { - return vm->getState() == SURF_VM_STATE_RUNNING; + return vm->get_state() == simgrid::s4u::VirtualMachine::state::RUNNING; } /** @brief Returns whether the given VM is currently suspended, not running. */ int sg_vm_is_suspended(sg_vm_t vm) { - return vm->getState() == SURF_VM_STATE_SUSPENDED; + return vm->get_state() == simgrid::s4u::VirtualMachine::state::SUSPENDED; } /** @brief Start a vm (i.e., boot the guest operating system)