Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of github.com:simgrid/simgrid into dev_7
[simgrid.git] / src / plugins / vm / VmLiveMigration.cpp
index 43f2629..87195a5 100644 (file)
@@ -59,7 +59,7 @@ void MigrationRx::operator()()
     counter++;
 
     // start link
-    container_t msg = instr::Container::by_name(vm_->get_name());
+    auto* msg = instr::Container::by_name(vm_->get_name());
     instr::Container::get_root()->get_link("VM_LINK")->start_event(msg, "M", key);
 
     // destroy existing container of this vm
@@ -73,8 +73,8 @@ void MigrationRx::operator()()
     instr::Container::get_root()->get_link("VM_LINK")->end_event(msg, "M", key);
   }
   // Inform the SRC that the migration has been correctly performed
-  std::string* payload = new std::string("__mig_stage4:");
-  *payload             = *payload + vm_->get_cname() + "(" + src_pm_->get_cname() + "-" + dst_pm_->get_cname() + ")";
+  auto* payload = new std::string("__mig_stage4:");
+  *payload      = *payload + vm_->get_cname() + "(" + src_pm_->get_cname() + "-" + dst_pm_->get_cname() + ")";
 
   mbox_ctl->put(payload, 0);
 
@@ -83,7 +83,7 @@ void MigrationRx::operator()()
 
 static sg_size_t get_updated_size(double computed, double dp_rate, sg_size_t dp_cap)
 {
-  sg_size_t updated_size = static_cast<sg_size_t>(computed * dp_rate);
+  auto updated_size = static_cast<sg_size_t>(computed * dp_rate);
   XBT_DEBUG("updated_size %llu dp_rate %f", updated_size, dp_rate);
   if (updated_size > dp_cap) {
     updated_size = dp_cap;
@@ -95,30 +95,27 @@ static sg_size_t get_updated_size(double computed, double dp_rate, sg_size_t dp_
 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");
+  auto* msg        = new std::string("__mig_stage");
   *msg             = *msg + std::to_string(stage) + ":" + vm_->get_cname() + "(" + src_pm_->get_cname() + "-" +
          dst_pm_->get_cname() + ")";
 
   double clock_sta = s4u::Engine::get_clock();
 
-  s4u::Activity* comm = nullptr;
+  s4u::CommPtr comm = mbox->put_init(msg, size);
+  if (mig_speed > 0)
+    comm->set_rate(mig_speed);
   try {
-    if (mig_speed > 0)
-      comm = mbox->put_init(msg, size)->set_rate(mig_speed)->wait_for(timeout);
-    else
-      comm = mbox->put_async(msg, size)->wait_for(timeout);
+    comm->wait_for(timeout);
   } catch (const Exception&) {
-    if (comm) {
-      sg_size_t remaining = static_cast<sg_size_t>(comm->get_remaining());
-      XBT_VERB("timeout (%lf s) in sending_migration_data, remaining %llu bytes of %llu", timeout, remaining, size);
-      sent -= remaining;
-    }
+    auto remaining = static_cast<sg_size_t>(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::get_clock();
   double duration     = clock_end - clock_sta;
-  double actual_speed = size / duration;
+  double actual_speed = static_cast<double>(size) / duration;
 
   if (stage == 2)
     XBT_DEBUG("mig-stage%d.%d: sent %llu duration %f actual_speed %f (target %f)", stage, stage2_round, size, duration,
@@ -137,7 +134,7 @@ void MigrationTx::operator()()
   double host_speed       = vm_->get_pm()->get_speed();
   const sg_size_t ramsize = vm_->get_ramsize();
   const double dp_rate =
-      host_speed ? (sg_vm_get_migration_speed(vm_) * sg_vm_get_dirty_page_intensity(vm_)) / host_speed : 1;
+      host_speed != 0.0 ? (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_);
@@ -183,7 +180,7 @@ void MigrationTx::operator()()
       XBT_CRITICAL("bug");
   } catch (const Exception&) {
     // hostfailure (if you want to know whether this is the SRC or the DST check directly in send_migration_data code)
-    // Stop the dirty page tracking an return (there is no memory space to release)
+    // Stop the dirty page tracking and return (there is no memory space to release)
     sg_vm_stop_dirty_page_tracking(vm_);
     return;
   }
@@ -222,7 +219,7 @@ void MigrationTx::operator()()
       } catch (const Exception&) {
         // hostfailure (if you want to know whether this is the SRC or the DST check directly in send_migration_data
         // code)
-        // Stop the dirty page tracking an return (there is no memory space to release)
+        // Stop the dirty page tracking and return (there is no memory space to release)
         sg_vm_stop_dirty_page_tracking(vm_);
         return;
       }
@@ -265,7 +262,7 @@ void MigrationTx::operator()()
     sendMigrationData(remaining_size, 3, 0, mig_speed, -1);
   } catch (const Exception&) {
     // hostfailure (if you want to know whether this is the SRC or the DST check directly in send_migration_data code)
-    // Stop the dirty page tracking an return (there is no memory space to release)
+    // Stop the dirty page tracking and return (there is no memory space to release)
     vm_->resume();
     return;
   }
@@ -301,7 +298,7 @@ simgrid::s4u::VirtualMachine* sg_vm_create_migratable(simgrid::s4u::Host* pm, co
 
   /* 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<sg_size_t>(ramsize) * 1024 * 1024);
+  auto* vm = new simgrid::s4u::VirtualMachine(name, pm, coreAmount, static_cast<sg_size_t>(ramsize) * 1024 * 1024);
   sg_vm_set_dirty_page_intensity(vm, dp_intensity / 100.0);
   sg_vm_set_working_set_memory(vm, vm->get_ramsize() * 0.9); // assume working set memory is 90% of ramsize
   sg_vm_set_migration_speed(vm, mig_netspeed * 1024 * 1024.0);