Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add the affinity setting function for a VM
authorTakahiro Hirofuchi <t.hirofuchi+sg@aist.go.jp>
Mon, 28 Oct 2013 11:31:29 +0000 (12:31 +0100)
committerTakahiro Hirofuchi <t.hirofuchi+sg@aist.go.jp>
Mon, 28 Oct 2013 11:31:29 +0000 (12:31 +0100)
include/msg/msg.h
include/simgrid/simix.h
src/include/surf/surf.h
src/msg/msg_vm.c
src/simix/smx_host_private.h
src/simix/smx_smurf_private.h
src/simix/smx_user.c
src/simix/smx_vm.c
src/surf/vm_workstation.c

index bda2f18..756f9be 100644 (file)
@@ -426,6 +426,7 @@ XBT_PUBLIC(void) MSG_vm_restore(msg_vm_t vm);
 
 XBT_PUBLIC(msg_host_t) MSG_vm_get_pm(msg_vm_t vm);
 XBT_PUBLIC(void) MSG_vm_set_bound(msg_vm_t vm, double bound);
+XBT_PUBLIC(void) MSG_vm_set_affinity(msg_vm_t vm, msg_host_t pm, unsigned long mask);
 
 /* TODO: do we need this? */
 // XBT_PUBLIC(xbt_dynar_t) MSG_vms_as_dynar(void);
index a262477..7901cdf 100644 (file)
@@ -337,6 +337,7 @@ XBT_PUBLIC(void) simcall_vm_start(smx_host_t vm);
 XBT_PUBLIC(void) simcall_vm_migrate(smx_host_t vm, smx_host_t dst_pm);
 XBT_PUBLIC(void *) simcall_vm_get_pm(smx_host_t vm);
 XBT_PUBLIC(void) simcall_vm_set_bound(smx_host_t vm, double bound);
+XBT_PUBLIC(void) simcall_vm_set_affinity(smx_host_t vm, smx_host_t pm, unsigned long mask);
 XBT_PUBLIC(void) simcall_vm_resume(smx_host_t vm);
 XBT_PUBLIC(void) simcall_vm_save(smx_host_t vm);
 XBT_PUBLIC(void) simcall_vm_restore(smx_host_t vm);
index 502fdae..d0c6714 100644 (file)
@@ -332,6 +332,7 @@ typedef struct surf_vm_workstation_model_extension_public {
   void * (*get_pm) (void *ind_vm_ws); // will be vm_ws_get_pm()
 
   void   (*set_vm_bound) (void *ind_vm_ws, double bound); // will be vm_ws_set_vm_bound()
+  void   (*set_vm_affinity) (void *ind_vm_ws, void *ind_pm_ws, unsigned long mask); // will be vm_ws_set_vm_affinity()
 
 } s_surf_model_extension_vm_workstation_t;
 
index bae0815..63c6dbb 100644 (file)
@@ -1258,3 +1258,15 @@ void MSG_vm_set_bound(msg_vm_t vm, double bound)
 {
        return simcall_vm_set_bound(vm, bound);
 }
+
+
+/** @brief Set the CPU affinity of a given VM.
+ *  @ingroup msg_VMs
+ *
+ * This function changes the CPU affinity of a given VM. Usage is the same as
+ * MSG_task_set_affinity(). See the MSG_task_set_affinity() for details.
+ */
+void MSG_vm_set_affinity(msg_vm_t vm, msg_host_t pm, unsigned long mask)
+{
+       return simcall_vm_set_affinity(vm, pm, mask);
+}
index 2cb3c6e..cfb4a2c 100644 (file)
@@ -139,6 +139,9 @@ void *SIMIX_pre_vm_get_pm(smx_simcall_t simcall, smx_host_t ind_vm);
 void SIMIX_vm_set_bound(smx_host_t ind_vm, double bound);
 void SIMIX_pre_vm_set_bound(smx_simcall_t simcall, smx_host_t ind_vm, double bound);
 
+void SIMIX_vm_set_affinity(smx_host_t ind_vm, smx_host_t ind_pm, unsigned long mask);
+void SIMIX_pre_vm_set_affinity(smx_simcall_t simcall, smx_host_t ind_vm, smx_host_t ind_pm, unsigned long mask);
+
 void SIMIX_host_get_params(smx_host_t ind_vm, ws_params_t params);
 void SIMIX_pre_host_get_params(smx_simcall_t simcall, smx_host_t ind_vm, ws_params_t params);
 
index 2fcd3bc..546079c 100644 (file)
@@ -289,6 +289,7 @@ ACTION(SIMCALL_VM_GET_STATE, vm_get_state, WITH_ANSWER,    TINT(result),  TSPEC(
 ACTION(SIMCALL_VM_MIGRATE,   vm_migrate,   WITH_ANSWER, TVOID(result), TSPEC(ind_vm, smx_host_t), TSPEC(ind_dst_pm, smx_host_t)) sep \
 ACTION(SIMCALL_VM_GET_PM,    vm_get_pm,    WITH_ANSWER,    TPTR(result),  TSPEC(ind_vm, smx_host_t)) sep \
 ACTION(SIMCALL_VM_SET_BOUND,    vm_set_bound,    WITH_ANSWER, TVOID(result), TSPEC(ind_vm, smx_host_t), TDOUBLE(bound)) sep \
+ACTION(SIMCALL_VM_SET_AFFINITY, vm_set_affinity, WITH_ANSWER, TVOID(result), TSPEC(ind_vm, smx_host_t), TSPEC(ind_pm, smx_host_t), TULONG(mask)) sep \
 ACTION(SIMCALL_VM_DESTROY,   vm_destroy,   WITH_ANSWER, TVOID(result), TSPEC(ind_vm, smx_host_t)) sep \
 ACTION(SIMCALL_VM_SUSPEND,   vm_suspend,   WITH_ANSWER, TVOID(result), TSPEC(ind_vm, smx_host_t)) sep \
 ACTION(SIMCALL_VM_RESUME,    vm_resume,    WITH_ANSWER, TVOID(result), TSPEC(ind_vm, smx_host_t)) sep \
index f46a909..84382c5 100644 (file)
@@ -396,6 +396,12 @@ void simcall_vm_set_bound(smx_host_t vm, double bound)
   simcall_BODY_vm_set_bound(vm, bound);
 }
 
+void simcall_vm_set_affinity(smx_host_t vm, smx_host_t pm, unsigned long mask)
+{
+  /* will jump to SIMIX_pre_vm_set_affinity in src/simix/smx_smurf_private.h */
+  simcall_BODY_vm_set_affinity(vm, pm, mask);
+}
+
 void simcall_host_get_params(smx_host_t vm, ws_params_t params)
 {
   /* will jump to SIMIX_pre_host_get_params in src/simix/smx_smurf_private.h */
index c6924ce..c7802ad 100644 (file)
@@ -187,6 +187,25 @@ void SIMIX_pre_vm_set_bound(smx_simcall_t simcall, smx_host_t ind_vm, double bou
 }
 
 
+/**
+ * \brief Function to set the CPU affinity of the given SIMIX VM host.
+ *
+ * \param host the vm host (a smx_host_t)
+ * \param host the pm host (a smx_host_t)
+ * \param mask affinity mask (a unsigned long)
+ */
+void SIMIX_vm_set_affinity(smx_host_t ind_vm, smx_host_t ind_pm, unsigned long mask)
+{
+  /* jump to vm_ws_set_vm_affinity(). */
+  surf_vm_workstation_model->extension.vm_workstation.set_vm_affinity(ind_vm, ind_pm, mask);
+}
+
+void SIMIX_pre_vm_set_affinity(smx_simcall_t simcall, smx_host_t ind_vm, smx_host_t ind_pm, unsigned long mask)
+{
+  SIMIX_vm_set_affinity(ind_vm, ind_pm, mask);
+}
+
+
 /**
  * \brief Function to suspend a SIMIX VM host. This function stops the exection of the
  * VM. All the processes on this VM will pause. The state of the VM is
index da37c53..1d0a398 100644 (file)
@@ -443,9 +443,9 @@ static void vm_ws_action_cancel(surf_action_t action)
 /* Now we can set bound for each task by using MSG_task_set_bound. But, it does
  * not work for the dummy CPU action of a VM. Here, we add the set_bound
  * function for the dummy CPU action. */
-static void vm_ws_set_vm_bound(void *workstation, double bound)
+static void vm_ws_set_vm_bound(void *vm, double bound)
 {
-  surf_resource_t ws = ((surf_resource_t) surf_workstation_resource_priv(workstation));
+  surf_resource_t ws = ((surf_resource_t) surf_workstation_resource_priv(vm));
   xbt_assert(ws->model->type == SURF_MODEL_TYPE_VM_WORKSTATION);
   workstation_VM2013_t vm_ws = (workstation_VM2013_t) ws;
 
@@ -453,6 +453,17 @@ static void vm_ws_set_vm_bound(void *workstation, double bound)
 }
 
 
+/* set the affinity of a VM to the CPU cores of a PM */
+static void vm_ws_set_vm_affinity(void *vm, void *pm, unsigned long mask)
+{
+  surf_resource_t ws = ((surf_resource_t) surf_workstation_resource_priv(vm));
+  xbt_assert(ws->model->type == SURF_MODEL_TYPE_VM_WORKSTATION);
+  workstation_VM2013_t vm_ws = (workstation_VM2013_t) ws;
+
+  surf_cpu_model_pm->set_affinity(vm_ws->cpu_action, pm, mask);
+}
+
+
 static void surf_vm_workstation_model_init_internal(void)
 {
   surf_model_t model = surf_model_init();
@@ -531,6 +542,7 @@ static void surf_vm_workstation_model_init_internal(void)
   model->extension.vm_workstation.restore       = vm_ws_restore;
   model->extension.vm_workstation.get_pm        = vm_ws_get_pm;
   model->extension.vm_workstation.set_vm_bound  = vm_ws_set_vm_bound;
+  model->extension.vm_workstation.set_vm_affinity  = vm_ws_set_vm_affinity;
 
   model->extension.workstation.set_params    = ws_set_params;
   model->extension.workstation.get_params    = ws_get_params;