From: Frederic Suter Date: Tue, 26 Dec 2017 09:57:08 +0000 (+0100) Subject: allow zero-cost migration (a.k.a. setPm) X-Git-Tag: v3.19~404 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/98a7e16b0620dead1ef3f21792ce9f917b4ece58 allow zero-cost migration (a.k.a. setPm) remove assert in suspend related to migration to be able to use it during the migration (was a crappy hack before). This implies that we assume that migration is a blocking operation (which is it) and that nobody will try to let another process do a suspend. --- diff --git a/include/simgrid/s4u/VirtualMachine.hpp b/include/simgrid/s4u/VirtualMachine.hpp index a655e4905e..3510e78ce2 100644 --- a/include/simgrid/s4u/VirtualMachine.hpp +++ b/include/simgrid/s4u/VirtualMachine.hpp @@ -55,6 +55,7 @@ public: void getParameters(vm_params_t params); void setParameters(vm_params_t params); simgrid::s4u::Host* getPm(); + void setPm(simgrid::s4u::Host * pm); size_t getRamsize(); void setRamsize(size_t ramsize); void setBound(double bound); diff --git a/src/plugins/vm/VirtualMachineImpl.cpp b/src/plugins/vm/VirtualMachineImpl.cpp index 8b5f1c8502..9ba6c33151 100644 --- a/src/plugins/vm/VirtualMachineImpl.cpp +++ b/src/plugins/vm/VirtualMachineImpl.cpp @@ -151,10 +151,9 @@ void VirtualMachineImpl::setState(e_surf_vm_state_t state) { vmState_ = state; } + void VirtualMachineImpl::suspend(smx_actor_t issuer) { - if (isMigrating) - THROWF(vm_error, 0, "Cannot suspend VM '%s': it is migrating", piface_->getCname()); if (getState() != SURF_VM_STATE_RUNNING) THROWF(vm_error, 0, "Cannot suspend VM %s: it is not running.", piface_->getCname()); if (issuer->host == piface_) diff --git a/src/plugins/vm/VmLiveMigration.cpp b/src/plugins/vm/VmLiveMigration.cpp index 46286f94d7..7d8c3b12b6 100644 --- a/src/plugins/vm/VmLiveMigration.cpp +++ b/src/plugins/vm/VmLiveMigration.cpp @@ -36,25 +36,16 @@ void MigrationRx::operator()() // Here Stage 1, 2 and 3 have been performed. // Hence complete the migration - // Copy the reference to the vm (if SRC crashes now, do_migration will free ms) - // This is clearly ugly but I (Adrien) need more time to do something cleaner (actually we should copy the whole ms - // structure at the beginning and free it at the end of each function) - simgrid::s4u::VirtualMachine* vm = vm_; - simgrid::s4u::Host* dst_pm = dst_pm_; - - // Make sure that we cannot get interrupted between the migrate and the resume to not end in an inconsistent state - simgrid::simix::kernelImmediate([vm, dst_pm]() { - /* Update the vm location */ - /* precopy migration makes the VM temporally paused */ - xbt_assert(vm->getState() == SURF_VM_STATE_SUSPENDED); - - /* Update the vm location and resume it */ - vm->pimpl_vm_->setPm(dst_pm); - vm->resume(); - }); + /* Update the vm location */ + /* precopy migration makes the VM temporally paused */ + xbt_assert(vm_->getState() == SURF_VM_STATE_SUSPENDED); + + /* Update the vm location and resume it */ + vm_->setPm(dst_pm_); + vm_->resume(); // Now the VM is running on the new host (the migration is completed) (even if the SRC crash) - vm->pimpl_vm_->isMigrating = false; + vm_->pimpl_vm_->isMigrating = false; XBT_DEBUG("VM(%s) moved from PM(%s) to PM(%s)", vm_->getCname(), src_pm_->getCname(), dst_pm_->getCname()); if (TRACE_msg_vm_is_enabled()) { @@ -63,19 +54,19 @@ void MigrationRx::operator()() counter++; // start link - container_t msg = simgrid::instr::Container::byName(vm->getName()); + container_t msg = simgrid::instr::Container::byName(vm_->getName()); simgrid::instr::Container::getRoot()->getLink("MSG_VM_LINK")->startEvent(msg, "M", key); // destroy existing container of this vm - container_t existing_container = simgrid::instr::Container::byName(vm->getName()); + container_t existing_container = simgrid::instr::Container::byName(vm_->getName()); existing_container->removeFromParent(); delete existing_container; // create new container on the new_host location - new simgrid::instr::Container(vm->getCname(), "MSG_VM", simgrid::instr::Container::byName(dst_pm_->getName())); + new simgrid::instr::Container(vm_->getCname(), "MSG_VM", simgrid::instr::Container::byName(dst_pm_->getName())); // end link - msg = simgrid::instr::Container::byName(vm->getName()); + msg = simgrid::instr::Container::byName(vm_->getName()); simgrid::instr::Container::getRoot()->getLink("MSG_VM_LINK")->endEvent(msg, "M", key); } // Inform the SRC that the migration has been correctly performed @@ -303,6 +294,8 @@ void sg_vm_migrate(simgrid::s4u::VirtualMachine* vm, simgrid::s4u::Host* dst_pm) if (vm->isMigrating()) THROWF(vm_error, 0, "Cannot migrate VM '%s' that is already migrating.", vm->getCname()); + vm->pimpl_vm_->isMigrating = true; + std::string rx_name = std::string("__pr_mig_rx:") + vm->getCname() + "(" + src_pm->getCname() + "-" + dst_pm->getCname() + ")"; std::string tx_name = diff --git a/src/plugins/vm/s4u_VirtualMachine.cpp b/src/plugins/vm/s4u_VirtualMachine.cpp index 153625cd68..197e4dd71b 100644 --- a/src/plugins/vm/s4u_VirtualMachine.cpp +++ b/src/plugins/vm/s4u_VirtualMachine.cpp @@ -122,6 +122,11 @@ simgrid::s4u::Host* VirtualMachine::getPm() return pimpl_vm_->getPm(); } +void VirtualMachine::setPm(simgrid::s4u::Host* pm) +{ + simgrid::simix::kernelImmediate([this, pm]() { pimpl_vm_->setPm(pm); }); +} + e_surf_vm_state_t VirtualMachine::getState() { return pimpl_vm_->getState();