Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
enable the bandwidth capping of migration traffic
[simgrid.git] / src / msg / msg_vm.c
index 9ab63ae..7bd7b98 100644 (file)
@@ -117,7 +117,6 @@ int MSG_vm_is_running(msg_vm_t vm)
   return __MSG_vm_is_state(vm, SURF_VM_STATE_RUNNING);
 }
 
-#if 0
 /** @brief Returns whether the given VM is currently migrating
  *  @ingroup msg_VMs
  */
@@ -125,7 +124,6 @@ int MSG_vm_is_migrating(msg_vm_t vm)
 {
   return __MSG_vm_is_state(vm, SURF_VM_STATE_MIGRATING);
 }
-#endif
 
 /** @brief Returns whether the given VM is currently suspended, not running.
  *  @ingroup msg_VMs
@@ -222,6 +220,30 @@ msg_vm_t MSG_vm_create_core(msg_host_t ind_pm, const char *name)
   return ind_vm;
 }
 
+/** @brief Destroy a VM. Destroy the VM object from the simulation.
+ *  @ingroup msg_VMs
+ */
+void MSG_vm_destroy(msg_vm_t vm)
+{
+  /* First, terminate all processes on the VM if necessary */
+  if (MSG_vm_is_running(vm))
+      simcall_vm_shutdown(vm);
+
+  if (!MSG_vm_is_created(vm)) {
+    XBT_CRITICAL("shutdown the given VM before destroying it");
+    DIE_IMPOSSIBLE;
+  }
+
+  /* Then, destroy the VM object */
+  simcall_vm_destroy(vm);
+
+  __MSG_host_destroy(vm);
+
+  #ifdef HAVE_TRACING
+  TRACE_msg_vm_end(vm);
+  #endif
+}
+
 
 /** @brief Start a vm (i.e., boot the guest operating system)
  *  @ingroup msg_VMs
@@ -444,6 +466,8 @@ static double lookup_computed_flop_counts(msg_vm_t vm, int stage2_round_for_fanc
   return total;
 }
 
+// TODO Is this code redundant with the information provided by
+// msg_process_t MSG_process_create(const char *name, xbt_main_func_t code, void *data, msg_host_t host)
 void MSG_host_add_task(msg_host_t host, msg_task_t task)
 {
   msg_host_priv_t priv = msg_host_resource_priv(host);
@@ -497,11 +521,16 @@ void MSG_host_del_task(msg_host_t host, msg_task_t task)
 
 
 static void send_migration_data(const char *vm_name, const char *src_pm_name, const char *dst_pm_name,
-    double size, char *mbox, int stage, int stage2_round)
+    double size, char *mbox, int stage, int stage2_round, double mig_speed)
 {
   char *task_name = get_mig_task_name(vm_name, src_pm_name, dst_pm_name, stage);
   msg_task_t task = MSG_task_create(task_name, 0, size, NULL);
-  msg_error_t ret = MSG_task_send(task, mbox);
+
+  msg_error_t ret;
+  if (mig_speed > 0)
+    ret = MSG_task_send_bounded(task, mbox, mig_speed);
+  else
+    ret = MSG_task_send(task, mbox);
   xbt_assert(ret == MSG_OK);
 
   if (stage == 2)
@@ -535,6 +564,7 @@ static int migration_tx_fun(int argc, char *argv[])
   const double max_downtime = params.max_downtime;
   const double dp_rate      = params.dp_rate;
   const double dp_cap       = params.dp_cap;
+  const double mig_speed    = params.mig_speed;
   double remaining_size = ramsize + devsize;
   double threshold = max_downtime * 125 * 1000 * 1000;
 
@@ -549,7 +579,7 @@ static int migration_tx_fun(int argc, char *argv[])
   /* Stage1: send all memory pages to the destination. */
   start_dirty_page_tracking(vm);
 
-  send_migration_data(vm_name, src_pm_name, dst_pm_name, ramsize, mbox, 1, 0);
+  send_migration_data(vm_name, src_pm_name, dst_pm_name, ramsize, mbox, 1, 0, mig_speed);
 
   remaining_size -= ramsize;
 
@@ -583,7 +613,7 @@ static int migration_tx_fun(int argc, char *argv[])
     if (remaining_size < threshold)
       break;
 
-    send_migration_data(vm_name, src_pm_name, dst_pm_name, updated_size, mbox, 2, stage2_round);
+    send_migration_data(vm_name, src_pm_name, dst_pm_name, updated_size, mbox, 2, stage2_round, mig_speed);
 
     remaining_size -= updated_size;
     stage2_round += 1;
@@ -596,7 +626,7 @@ stage3:
   simcall_vm_suspend(vm);
   stop_dirty_page_tracking(vm);
 
-  send_migration_data(vm_name, src_pm_name, dst_pm_name, remaining_size, mbox, 3, 0);
+  send_migration_data(vm_name, src_pm_name, dst_pm_name, remaining_size, mbox, 3, 0, mig_speed);
 
   xbt_free(mbox);
 
@@ -773,32 +803,9 @@ void MSG_vm_restore(msg_vm_t vm)
 }
 
 
-/** @brief Destroy a VM. Destroy the VM object from the simulation.
- *  @ingroup msg_VMs
- */
-void MSG_vm_destroy(msg_vm_t vm)
-{
-  /* First, terminate all processes on the VM if necessary */
-  if (MSG_vm_is_running(vm))
-      simcall_vm_shutdown(vm);
-
-  if (!MSG_vm_is_created(vm)) {
-    XBT_CRITICAL("shutdown the given VM before destroying it");
-    DIE_IMPOSSIBLE;
-  }
-
-  /* Then, destroy the VM object */
-  simcall_vm_destroy(vm);
-
-  __MSG_host_destroy(vm);
-
-  #ifdef HAVE_TRACING
-  TRACE_msg_vm_end(vm);
-  #endif
-}
 
 
-/** @brief Get the physical host of a givne VM.
+/** @brief Get the physical host of a given VM.
  *  @ingroup msg_VMs
  */
 msg_host_t MSG_vm_get_pm(msg_vm_t vm)