X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/98a7e16b0620dead1ef3f21792ce9f917b4ece58..63ebf4be4ca6a243a64c7ded8df9b96a9d28d3ff:/src/plugins/vm/VmLiveMigration.cpp diff --git a/src/plugins/vm/VmLiveMigration.cpp b/src/plugins/vm/VmLiveMigration.cpp index 7d8c3b12b6..8df22cda3f 100644 --- a/src/plugins/vm/VmLiveMigration.cpp +++ b/src/plugins/vm/VmLiveMigration.cpp @@ -1,20 +1,25 @@ -/* Copyright (c) 2013-2017. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2013-2018. 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 -#include -#include -#include -#include -#include -#include +#include "src/plugins/vm/VmLiveMigration.hpp" +#include "src/instr/instr_private.hpp" +#include "src/plugins/vm/VirtualMachineImpl.hpp" +#include "src/plugins/vm/VmHostExt.hpp" +#include "xbt/ex.hpp" XBT_LOG_NEW_DEFAULT_CATEGORY(vm_live_migration, "S4U virtual machines live migration"); namespace simgrid { namespace vm { +simgrid::xbt::Extension VmMigrationExt::EXTENSION_ID; + +void VmMigrationExt::ensureVmMigrationExtInstalled() +{ + if (not EXTENSION_ID.valid()) + EXTENSION_ID = simgrid::s4u::Host::extension_create(); +} void MigrationRx::operator()() { @@ -22,7 +27,7 @@ void MigrationRx::operator()() bool received_finalize = false; std::string finalize_task_name = - std::string("__mig_stage3:") + vm_->getCname() + "(" + src_pm_->getCname() + "-" + dst_pm_->getCname() + ")"; + std::string("__mig_stage3:") + vm_->get_cname() + "(" + src_pm_->get_cname() + "-" + dst_pm_->get_cname() + ")"; while (not received_finalize) { std::string* payload = static_cast(mbox->get()); @@ -45,74 +50,73 @@ void MigrationRx::operator()() 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; - XBT_DEBUG("VM(%s) moved from PM(%s) to PM(%s)", vm_->getCname(), src_pm_->getCname(), dst_pm_->getCname()); + vm_->getImpl()->isMigrating = false; + XBT_DEBUG("VM(%s) moved from PM(%s) to PM(%s)", vm_->get_cname(), src_pm_->get_cname(), dst_pm_->get_cname()); - if (TRACE_msg_vm_is_enabled()) { + if (TRACE_vm_is_enabled()) { static long long int counter = 0; std::string key = std::to_string(counter); counter++; // start link - container_t msg = simgrid::instr::Container::byName(vm_->getName()); + container_t msg = simgrid::instr::Container::byName(vm_->get_name()); 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()); - existing_container->removeFromParent(); - delete existing_container; + simgrid::instr::Container::byName(vm_->get_name())->removeFromParent(); // 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_->get_cname(), "MSG_VM", simgrid::instr::Container::byName(dst_pm_->get_name())); // end link - msg = simgrid::instr::Container::byName(vm_->getName()); + msg = simgrid::instr::Container::byName(vm_->get_name()); simgrid::instr::Container::getRoot()->getLink("MSG_VM_LINK")->endEvent(msg, "M", key); } // Inform the SRC that the migration has been correctly performed std::string* payload = new std::string("__mig_stage4:"); - *payload = *payload + vm_->getCname() + "(" + src_pm_->getCname() + "-" + dst_pm_->getCname() + ")"; + *payload = *payload + vm_->get_cname() + "(" + src_pm_->get_cname() + "-" + dst_pm_->get_cname() + ")"; mbox_ctl->put(payload, 0); XBT_DEBUG("mig: rx_done"); } -static sg_size_t get_updated_size(double computed, double dp_rate, double dp_cap) +static sg_size_t get_updated_size(double computed, double dp_rate, sg_size_t dp_cap) { - double updated_size = computed * dp_rate; - XBT_DEBUG("updated_size %f dp_rate %f", updated_size, dp_rate); + sg_size_t updated_size = static_cast(computed * dp_rate); + XBT_DEBUG("updated_size %llu dp_rate %f", updated_size, dp_rate); if (updated_size > dp_cap) { updated_size = dp_cap; } - return static_cast(updated_size); + return updated_size; } sg_size_t MigrationTx::sendMigrationData(sg_size_t size, int stage, int stage2_round, double mig_speed, double timeout) { sg_size_t sent = size; std::string* msg = new std::string("__mig_stage"); - *msg = *msg + std::to_string(stage) + ":" + vm_->getCname() + "(" + src_pm_->getCname() + "-" + dst_pm_->getCname() + - ")"; + *msg = *msg + std::to_string(stage) + ":" + vm_->get_cname() + "(" + src_pm_->get_cname() + "-" + + dst_pm_->get_cname() + ")"; - double clock_sta = s4u::Engine::getClock(); + double clock_sta = s4u::Engine::get_clock(); s4u::Activity* comm = nullptr; try { if (mig_speed > 0) - comm = mbox->put_init(msg, size)->setRate(mig_speed)->wait(timeout); + comm = mbox->put_init(msg, size)->set_rate(mig_speed)->wait(timeout); else comm = mbox->put_async(msg, size)->wait(); } catch (xbt_ex& e) { if (comm) { - sg_size_t remaining = static_cast(comm->getRemains()); + sg_size_t remaining = static_cast(comm->get_remaining()); XBT_VERB("timeout (%lf s) in sending_migration_data, remaining %llu bytes of %llu", timeout, remaining, size); sent -= remaining; } + delete msg; } - double clock_end = s4u::Engine::getClock(); + double clock_end = s4u::Engine::get_clock(); double duration = clock_end - clock_sta; double actual_speed = size / duration; @@ -131,13 +135,12 @@ void MigrationTx::operator()() XBT_DEBUG("mig: tx_start"); double host_speed = vm_->getPm()->getSpeed(); - s_vm_params_t params; - vm_->getParameters(¶ms); const sg_size_t ramsize = vm_->getRamsize(); - const double dp_rate = host_speed ? (params.mig_speed * params.dp_intensity) / host_speed : 1; - const double dp_cap = params.dp_cap; - const double mig_speed = params.mig_speed; - double max_downtime = params.max_downtime; + const double dp_rate = + host_speed ? (sg_vm_get_migration_speed(vm_) * sg_vm_get_dirty_page_intensity(vm_)) / host_speed : 1; + const sg_size_t dp_cap = sg_vm_get_working_set_memory(vm_); + const double mig_speed = sg_vm_get_migration_speed(vm_); + double max_downtime = sg_vm_get_max_downtime(vm_); double mig_timeout = 10000000.0; bool skip_stage2 = false; @@ -159,7 +162,7 @@ void MigrationTx::operator()() sg_vm_start_dirty_page_tracking(vm_); double computed_during_stage1 = 0; - double clock_prev_send = s4u::Engine::getClock(); + double clock_prev_send = s4u::Engine::get_clock(); try { /* At stage 1, we do not need timeout. We have to send all the memory pages even though the duration of this @@ -182,7 +185,7 @@ void MigrationTx::operator()() return; } - double clock_post_send = s4u::Engine::getClock(); + double clock_post_send = s4u::Engine::get_clock(); mig_timeout -= (clock_post_send - clock_prev_send); if (mig_timeout < 0) { XBT_VERB("The duration of stage 1 exceeds the timeout value, skip stage 2"); @@ -208,7 +211,7 @@ void MigrationTx::operator()() updated_size = get_updated_size(computed, dp_rate, dp_cap); } - XBT_DEBUG("mig-stage 2:%d updated_size %llu computed_during_stage1 %f dp_rate %f dp_cap %f", stage2_round, + XBT_DEBUG("mig-stage 2:%d updated_size %llu computed_during_stage1 %f dp_rate %f dp_cap %llu", stage2_round, updated_size, computed_during_stage1, dp_rate, dp_cap); /* Check whether the remaining size is below the threshold value. If so, move to stage 3. */ @@ -219,7 +222,7 @@ void MigrationTx::operator()() break; sg_size_t sent = 0; - double clock_prev_send = s4u::Engine::getClock(); + double clock_prev_send = s4u::Engine::get_clock(); try { XBT_DEBUG("Stage 2, gonna send %llu", updated_size); sent = sendMigrationData(updated_size, 2, stage2_round, mig_speed, mig_timeout); @@ -230,7 +233,7 @@ void MigrationTx::operator()() sg_vm_stop_dirty_page_tracking(vm_); return; } - double clock_post_send = s4u::Engine::getClock(); + double clock_post_send = s4u::Engine::get_clock(); if (sent == updated_size) { /* timeout did not happen */ @@ -280,41 +283,87 @@ void MigrationTx::operator()() } } -SG_BEGIN_DECL() +static void onVirtualMachineShutdown(simgrid::s4u::VirtualMachine* vm) +{ + if (vm->getImpl()->isMigrating) { + vm->extension()->rx_->kill(); + vm->extension()->tx_->kill(); + vm->extension()->issuer_->kill(); + vm->getImpl()->isMigrating = false; + } +} + +void sg_vm_live_migration_plugin_init() +{ + sg_vm_dirty_page_tracking_init(); + simgrid::vm::VmMigrationExt::ensureVmMigrationExtInstalled(); + simgrid::s4u::VirtualMachine::onVmShutdown.connect(&onVirtualMachineShutdown); +} + +/* Deprecated. Please use MSG_vm_create_migratable() instead */ +msg_vm_t MSG_vm_create(msg_host_t ind_pm, const char* name, int coreAmount, int ramsize, int mig_netspeed, + int dp_intensity) +{ + return sg_vm_create_migratable(ind_pm, name, coreAmount, ramsize, mig_netspeed, dp_intensity); +} + +simgrid::s4u::VirtualMachine* sg_vm_create_migratable(simgrid::s4u::Host* pm, const char* name, int coreAmount, + int ramsize, int mig_netspeed, int dp_intensity) +{ + simgrid::vm::VmHostExt::ensureVmExtInstalled(); + + /* For the moment, intensity_rate is the percentage against the migration bandwidth */ + + sg_vm_t vm = new simgrid::s4u::VirtualMachine(name, pm, coreAmount, static_cast(ramsize) * 1024 * 1024); + sg_vm_set_dirty_page_intensity(vm, dp_intensity / 100.0); + sg_vm_set_working_set_memory(vm, vm->getRamsize() * 0.9); // assume working set memory is 90% of ramsize + sg_vm_set_migration_speed(vm, mig_netspeed * 1024 * 1024.0); + + XBT_DEBUG("migspeed : %f intensity mem : %d", mig_netspeed * 1024 * 1024.0, dp_intensity); + + return vm; +} + +int sg_vm_is_migrating(simgrid::s4u::VirtualMachine* vm) +{ + return vm->getImpl()->isMigrating; +} + void sg_vm_migrate(simgrid::s4u::VirtualMachine* vm, simgrid::s4u::Host* dst_pm) { simgrid::s4u::Host* src_pm = vm->getPm(); if (src_pm->isOff()) - THROWF(vm_error, 0, "Cannot migrate VM '%s' from host '%s', which is offline.", vm->getCname(), src_pm->getCname()); + THROWF(vm_error, 0, "Cannot migrate VM '%s' from host '%s', which is offline.", vm->get_cname(), + src_pm->get_cname()); if (dst_pm->isOff()) - THROWF(vm_error, 0, "Cannot migrate VM '%s' to host '%s', which is offline.", vm->getCname(), dst_pm->getCname()); + THROWF(vm_error, 0, "Cannot migrate VM '%s' to host '%s', which is offline.", vm->get_cname(), dst_pm->get_cname()); if (vm->getState() != SURF_VM_STATE_RUNNING) - THROWF(vm_error, 0, "Cannot migrate VM '%s' that is not running yet.", vm->getCname()); - if (vm->isMigrating()) - THROWF(vm_error, 0, "Cannot migrate VM '%s' that is already migrating.", vm->getCname()); + THROWF(vm_error, 0, "Cannot migrate VM '%s' that is not running yet.", vm->get_cname()); + if (vm->getImpl()->isMigrating) + THROWF(vm_error, 0, "Cannot migrate VM '%s' that is already migrating.", vm->get_cname()); - vm->pimpl_vm_->isMigrating = true; + vm->getImpl()->isMigrating = true; std::string rx_name = - std::string("__pr_mig_rx:") + vm->getCname() + "(" + src_pm->getCname() + "-" + dst_pm->getCname() + ")"; + std::string("__pr_mig_rx:") + vm->get_cname() + "(" + src_pm->get_cname() + "-" + dst_pm->get_cname() + ")"; std::string tx_name = - std::string("__pr_mig_tx:") + vm->getCname() + "(" + src_pm->getCname() + "-" + dst_pm->getCname() + ")"; + std::string("__pr_mig_tx:") + vm->get_cname() + "(" + src_pm->get_cname() + "-" + dst_pm->get_cname() + ")"; simgrid::s4u::ActorPtr rx = - simgrid::s4u::Actor::createActor(rx_name.c_str(), dst_pm, simgrid::vm::MigrationRx(vm, dst_pm)); + simgrid::s4u::Actor::create(rx_name.c_str(), dst_pm, simgrid::vm::MigrationRx(vm, dst_pm)); simgrid::s4u::ActorPtr tx = - simgrid::s4u::Actor::createActor(tx_name.c_str(), src_pm, simgrid::vm::MigrationTx(vm, dst_pm)); + simgrid::s4u::Actor::create(tx_name.c_str(), src_pm, simgrid::vm::MigrationTx(vm, dst_pm)); + + vm->extension_set(new simgrid::vm::VmMigrationExt(simgrid::s4u::Actor::self(), rx, tx)); /* wait until the migration have finished or on error has occurred */ XBT_DEBUG("wait for reception of the final ACK (i.e. migration has been correctly performed"); simgrid::s4u::MailboxPtr mbox_ctl = simgrid::s4u::Mailbox::byName( - std::string("__mbox_mig_ctl:") + vm->getCname() + "(" + src_pm->getCname() + "-" + dst_pm->getCname() + ")"); + std::string("__mbox_mig_ctl:") + vm->get_cname() + "(" + src_pm->get_cname() + "-" + dst_pm->get_cname() + ")"); delete static_cast(mbox_ctl->get()); - tx->join(); rx->join(); - vm->pimpl_vm_->isMigrating = false; -} + vm->getImpl()->isMigrating = false; }