Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add the affinity control function in the CPU model
authorTakahiro Hirofuchi <t.hirofuchi+sg@aist.go.jp>
Thu, 24 Oct 2013 09:21:13 +0000 (11:21 +0200)
committerTakahiro Hirofuchi <t.hirofuchi+sg@aist.go.jp>
Thu, 24 Oct 2013 09:21:13 +0000 (11:21 +0200)
src/include/surf/surf.h
src/surf/cpu_cas01.c

index cb867e3..502fdae 100644 (file)
@@ -382,6 +382,12 @@ typedef struct surf_model {
   void (*set_max_duration) (surf_action_t action, double duration);     /**< Set the max duration of an action*/
   void (*set_priority) (surf_action_t action, double priority);     /**< Set the priority of an action */
   void (*set_bound) (surf_action_t action, double bound);     /**< Set the bound (the maximum CPU utilization) of an action */
+
+  /* Note (hypervisor): set_affinity() may be used only in CPU models. It might
+   * be better to move this member to the extension field.
+   **/
+  void (*set_affinity) (surf_action_t action, void *workstation, unsigned long mask);     /**< Set the CPU affinity of an action */
+
 #ifdef HAVE_TRACING
   void (*set_category) (surf_action_t action, const char *category); /**< Set the category of an action */
 #endif
index 8bdaf6f..0692c1b 100644 (file)
@@ -255,6 +255,36 @@ static void cpu_update_resource_state(void *id,
   return;
 }
 
+static void cpu_action_set_affinity(surf_action_t action, void *cpu, unsigned long mask)
+{
+  lmm_variable_t var_obj = ((surf_action_lmm_t) action)->variable;
+
+  surf_model_t cpu_model = action->model_obj;
+  xbt_assert(cpu_model->type == SURF_MODEL_TYPE_CPU);
+  cpu_Cas01_t CPU = surf_cpu_resource_priv(cpu);
+
+  XBT_IN("(%p,%lx)", action, mask);
+
+
+  unsigned long i;
+  for (i = 0; i < CPU->core; i++) {
+    unsigned long has_affinity = (1UL << i) & mask;
+    if (has_affinity) {
+      XBT_INFO("set affinity %p to cpu-%lu@%s", action, i, CPU->generic_resource.name);
+      lmm_expand(cpu_model->model_private->maxmin_system, CPU->constraint_core[i], var_obj, 1.0);
+    } else {
+      XBT_INFO("clear affinity %p to cpu-%lu@%s", action, i, CPU->generic_resource.name);
+      lmm_shrink(cpu_model->model_private->maxmin_system, CPU->constraint_core[i], var_obj);
+    }
+  }
+
+  if (cpu_model->model_private->update_mechanism == UM_LAZY) {
+    XBT_WARN("FIXME (hypervisor): Do we need to do something for the LAZY mode?");
+  }
+
+  XBT_OUT();
+}
+
 static surf_action_t cpu_execute(void *cpu, double size)
 {
   surf_action_cpu_Cas01_t action = NULL;
@@ -279,7 +309,7 @@ static surf_action_t cpu_execute(void *cpu, double size)
   GENERIC_LMM_ACTION(action).variable =
       lmm_variable_new(cpu_model->model_private->maxmin_system, action,
                        GENERIC_ACTION(action).priority,
-                       CPU->power_scale * CPU->power_peak, 1);
+                       CPU->power_scale * CPU->power_peak, 1 + CPU->core); // the basic constraint plus core-specific constraints
   if (cpu_model->model_private->update_mechanism == UM_LAZY) {
     GENERIC_LMM_ACTION(action).index_heap = -1;
     GENERIC_LMM_ACTION(action).last_update = surf_get_clock();
@@ -430,6 +460,7 @@ static surf_model_t surf_cpu_model_init_cas01(void)
   cpu_model->set_max_duration = surf_action_set_max_duration;
   cpu_model->set_priority = surf_action_set_priority;
   cpu_model->set_bound = surf_action_set_bound;
+  cpu_model->set_affinity = cpu_action_set_affinity;
 #ifdef HAVE_TRACING
   cpu_model->set_category = surf_action_set_category;
 #endif