Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add the affinity database of each VM
authorTakahiro Hirofuchi <t.hirofuchi+sg@aist.go.jp>
Mon, 28 Oct 2013 17:00:39 +0000 (18:00 +0100)
committerTakahiro Hirofuchi <t.hirofuchi+sg@aist.go.jp>
Mon, 28 Oct 2013 17:00:39 +0000 (18:00 +0100)
include/msg/datatypes.h
src/msg/msg_host.c
src/msg/msg_vm.c
src/simix/smx_vm.c

index 041005d..b3abf3e 100644 (file)
@@ -51,6 +51,8 @@ typedef struct msg_host_priv {
   xbt_dict_t dp_objs;
   double     dp_updated_by_deleted_tasks;
 
+  xbt_dict_t affinity_mask_db;
+
 #ifdef MSG_USE_DEPRECATED
   msg_mailbox_t *mailboxes;     /**< the channels  */
 #endif
index ccfc880..6657f0a 100644 (file)
@@ -52,6 +52,8 @@ msg_host_t __MSG_host_create(smx_host_t workstation)
   priv->dp_enabled = 0;
   priv->dp_updated_by_deleted_tasks = 0;
 
+  priv->affinity_mask_db = xbt_dict_new_homogeneous(NULL);
+
   xbt_lib_set(host_lib, name, MSG_HOST_LEVEL, priv);
   
   return xbt_lib_get_elm_or_null(host_lib, name);
@@ -142,6 +144,7 @@ void __MSG_host_priv_free(msg_host_priv_t priv)
   if (size > 0)
     XBT_WARN("dp_objs: %u pending task?", size);
   xbt_dict_free(&priv->dp_objs);
+  xbt_dict_free(&priv->affinity_mask_db);
 
 #ifdef MSG_USE_DEPRECATED
   if (msg_global->max_channel > 0)
index 63c6dbb..bcb2318 100644 (file)
@@ -328,7 +328,8 @@ static int migration_rx_fun(int argc, char *argv[])
   const char *src_pm_name  = argv[2];
   const char *dst_pm_name  = argv[3];
   msg_vm_t vm = MSG_get_host_by_name(vm_name);
-  msg_vm_t dst_pm = MSG_get_host_by_name(dst_pm_name);
+  msg_host_t src_pm = MSG_get_host_by_name(src_pm_name);
+  msg_host_t dst_pm = MSG_get_host_by_name(dst_pm_name);
 
 
   s_ws_params_t params;
@@ -362,9 +363,21 @@ static int migration_rx_fun(int argc, char *argv[])
   }
 
 
+  /* deinstall the current affinity setting */
+  simcall_vm_set_affinity(vm, src_pm, 0);
+
   simcall_vm_migrate(vm, dst_pm);
   simcall_vm_resume(vm);
 
+  /* install the affinity setting of the VM on the destination pm */
+  {
+    msg_host_priv_t priv = msg_host_resource_priv(vm);
+
+    unsigned long affinity_mask = (unsigned long) xbt_dict_get_or_null_ext(priv->affinity_mask_db, (char *) dst_pm, sizeof(msg_host_t));
+    simcall_vm_set_affinity(vm, dst_pm, affinity_mask);
+    XBT_INFO("set affinity(0x%04lx@%s) for %s", affinity_mask, MSG_host_get_name(dst_pm), MSG_host_get_name(vm));
+  }
+
   {
     char *task_name = get_mig_task_name(vm_name, src_pm_name, dst_pm_name, 4);
 
@@ -1268,5 +1281,17 @@ void MSG_vm_set_bound(msg_vm_t vm, double bound)
  */
 void MSG_vm_set_affinity(msg_vm_t vm, msg_host_t pm, unsigned long mask)
 {
-       return simcall_vm_set_affinity(vm, pm, mask);
+  msg_host_priv_t priv = msg_host_resource_priv(vm);
+
+  if (mask == 0)
+    xbt_dict_remove_ext(priv->affinity_mask_db, (char *) pm, sizeof(pm));
+  else
+    xbt_dict_set_ext(priv->affinity_mask_db, (char *) pm, sizeof(pm), (void *) mask, NULL);
+
+  msg_host_t pm_now = MSG_vm_get_pm(vm);
+  if (pm_now == pm) {
+    XBT_INFO("set affinity(0x%04lx@%s) for %s", mask, MSG_host_get_name(pm), MSG_host_get_name(vm));
+    simcall_vm_set_affinity(vm, pm, mask);
+  } else
+    XBT_INFO("set affinity(0x%04lx@%s) for %s (not active now)", mask, MSG_host_get_name(pm), MSG_host_get_name(vm));
 }
index c7802ad..05a9b45 100644 (file)
@@ -196,6 +196,9 @@ void SIMIX_pre_vm_set_bound(smx_simcall_t simcall, smx_host_t ind_vm, double bou
  */
 void SIMIX_vm_set_affinity(smx_host_t ind_vm, smx_host_t ind_pm, unsigned long mask)
 {
+  /* make sure this at the MSG layer. */
+  xbt_assert(SIMIX_vm_get_pm(ind_vm) == ind_pm);
+
   /* jump to vm_ws_set_vm_affinity(). */
   surf_vm_workstation_model->extension.vm_workstation.set_vm_affinity(ind_vm, ind_pm, mask);
 }