X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/0fd45b48c7de0646ac07216ca943a595cc9ade94..fce09c24b85088743448b2bd504833a3b33937f3:/src/plugins/vm/VmLiveMigration.cpp diff --git a/src/plugins/vm/VmLiveMigration.cpp b/src/plugins/vm/VmLiveMigration.cpp index 2cdd524126..3ef63edfb7 100644 --- a/src/plugins/vm/VmLiveMigration.cpp +++ b/src/plugins/vm/VmLiveMigration.cpp @@ -1,13 +1,13 @@ -/* Copyright (c) 2013-2018. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2013-2019. 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 "src/plugins/vm/VmLiveMigration.hpp" +#include "simgrid/Exception.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"); @@ -66,7 +66,7 @@ void MigrationRx::operator()() simgrid::instr::Container::by_name(vm_->get_name())->remove_from_parent(); // create new container on the new_host location - new simgrid::instr::Container(vm_->get_cname(), "VM", simgrid::instr::Container::by_name(dst_pm_->get_name())); + new simgrid::instr::Container(vm_->get_name(), "VM", simgrid::instr::Container::by_name(dst_pm_->get_name())); // end link msg = simgrid::instr::Container::by_name(vm_->get_name()); @@ -104,9 +104,9 @@ sg_size_t MigrationTx::sendMigrationData(sg_size_t size, int stage, int stage2_r s4u::Activity* comm = nullptr; try { if (mig_speed > 0) - comm = mbox->put_init(msg, size)->set_rate(mig_speed)->wait(timeout); + comm = mbox->put_init(msg, size)->set_rate(mig_speed)->wait_for(timeout); else - comm = mbox->put_async(msg, size)->wait(); + comm = mbox->put_async(msg, size)->wait_for(timeout); } catch (xbt_ex& e) { if (comm) { sg_size_t remaining = static_cast(comm->get_remaining()); @@ -146,7 +146,11 @@ void MigrationTx::operator()() bool skip_stage2 = false; size_t remaining_size = ramsize; - size_t threshold = 0.0; + + double clock_prev_send; + double clock_post_send; + double bandwidth; + size_t threshold; /* check parameters */ if (ramsize == 0) @@ -162,7 +166,7 @@ void MigrationTx::operator()() sg_vm_start_dirty_page_tracking(vm_); double computed_during_stage1 = 0; - double clock_prev_send = s4u::Engine::get_clock(); + 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 @@ -185,7 +189,7 @@ void MigrationTx::operator()() return; } - double clock_post_send = s4u::Engine::get_clock(); + 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"); @@ -193,36 +197,28 @@ void MigrationTx::operator()() } /* estimate bandwidth */ - double bandwidth = ramsize / (clock_post_send - clock_prev_send); - threshold = bandwidth * max_downtime; + bandwidth = ramsize / (clock_post_send - clock_prev_send); + threshold = bandwidth * max_downtime; XBT_DEBUG("actual bandwidth %f (MB/s), threshold %zu", bandwidth / 1024 / 1024, threshold); /* Stage2: send update pages iteratively until the size of remaining states becomes smaller than threshold value. */ if (not skip_stage2) { int stage2_round = 0; - for (;;) { - sg_size_t updated_size = 0; - if (stage2_round == 0) { - /* just after stage1, nothing has been updated. But, we have to send the data updated during stage1 */ - updated_size = get_updated_size(computed_during_stage1, dp_rate, dp_cap); - } else { - double computed = sg_vm_lookup_computed_flops(vm_); - updated_size = get_updated_size(computed, dp_rate, dp_cap); - } + /* just after stage1, nothing has been updated. But, we have to send the data updated during stage1 */ + sg_size_t updated_size = get_updated_size(computed_during_stage1, dp_rate, dp_cap); + remaining_size += updated_size; + XBT_DEBUG("mig-stage2.%d: remaining_size %zu (%s threshold %zu)", stage2_round, remaining_size, + (remaining_size < threshold) ? "<" : ">", threshold); + + /* When the remaining size is below the threshold value, move to stage 3. */ + while (threshold < remaining_size) { 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. */ - remaining_size += updated_size; - XBT_DEBUG("mig-stage2.%d: remaining_size %zu (%s threshold %zu)", stage2_round, remaining_size, - (remaining_size < threshold) ? "<" : ">", threshold); - if (remaining_size < threshold) - break; - - sg_size_t sent = 0; - double clock_prev_send = s4u::Engine::get_clock(); + sg_size_t sent = 0; + 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); @@ -233,31 +229,32 @@ void MigrationTx::operator()() sg_vm_stop_dirty_page_tracking(vm_); return; } - double clock_post_send = s4u::Engine::get_clock(); + + remaining_size -= sent; + double computed = sg_vm_lookup_computed_flops(vm_); + + clock_post_send = s4u::Engine::get_clock(); if (sent == updated_size) { - /* timeout did not happen */ - double bandwidth = updated_size / (clock_post_send - clock_prev_send); - threshold = bandwidth * max_downtime; + bandwidth = updated_size / (clock_post_send - clock_prev_send); + threshold = bandwidth * max_downtime; XBT_DEBUG("actual bandwidth %f, threshold %zu", bandwidth / 1024 / 1024, threshold); - remaining_size -= sent; stage2_round += 1; mig_timeout -= (clock_post_send - clock_prev_send); xbt_assert(mig_timeout > 0); - - } else if (sent < updated_size) { + XBT_DEBUG("mig-stage2.%d: remaining_size %zu (%s threshold %zu)", stage2_round, remaining_size, + (remaining_size < threshold) ? "<" : ">", threshold); + updated_size = get_updated_size(computed, dp_rate, dp_cap); + remaining_size += updated_size; + } else { /* When timeout happens, we move to stage 3. The size of memory pages * updated before timeout must be added to the remaining size. */ XBT_VERB("mig-stage2.%d: timeout, force moving to stage 3. sent %llu / %llu, eta %lf", stage2_round, sent, updated_size, (clock_post_send - clock_prev_send)); - remaining_size -= sent; - - double computed = sg_vm_lookup_computed_flops(vm_); updated_size = get_updated_size(computed, dp_rate, dp_cap); remaining_size += updated_size; break; - } else - XBT_CRITICAL("bug"); + } } } @@ -283,7 +280,7 @@ void MigrationTx::operator()() } } -static void onVirtualMachineShutdown(simgrid::s4u::VirtualMachine& vm) +static void onVirtualMachineShutdown(simgrid::s4u::VirtualMachine const& vm) { if (vm.get_impl()->is_migrating_) { vm.extension()->rx_->kill(); @@ -300,13 +297,6 @@ void sg_vm_live_migration_plugin_init() simgrid::s4u::VirtualMachine::on_shutdown.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) { @@ -333,10 +323,10 @@ void sg_vm_migrate(simgrid::s4u::VirtualMachine* vm, simgrid::s4u::Host* dst_pm) { simgrid::s4u::Host* src_pm = vm->get_pm(); - if (src_pm->is_off()) + if (not src_pm->is_on()) THROWF(vm_error, 0, "Cannot migrate VM '%s' from host '%s', which is offline.", vm->get_cname(), src_pm->get_cname()); - if (dst_pm->is_off()) + if (not dst_pm->is_on()) THROWF(vm_error, 0, "Cannot migrate VM '%s' to host '%s', which is offline.", vm->get_cname(), dst_pm->get_cname()); if (vm->get_state() != simgrid::s4u::VirtualMachine::state::RUNNING) THROWF(vm_error, 0, "Cannot migrate VM '%s' that is not running yet.", vm->get_cname()); @@ -360,7 +350,7 @@ void sg_vm_migrate(simgrid::s4u::VirtualMachine* vm, simgrid::s4u::Host* dst_pm) /* 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::by_name( + simgrid::s4u::Mailbox* mbox_ctl = simgrid::s4u::Mailbox::by_name( std::string("__mbox_mig_ctl:") + vm->get_cname() + "(" + src_pm->get_cname() + "-" + dst_pm->get_cname() + ")"); delete static_cast(mbox_ctl->get()); tx->join();