Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge tag 'v3_9_90' into hypervisor
[simgrid.git] / src / surf / vm_workstation.c
index 2310a77..145d1c8 100644 (file)
@@ -32,7 +32,7 @@ static void vm_ws_create(const char *name, void *ind_phys_workstation)
    * create a physical workstation resource, but specifying the size of
    * s_workstation_VM2013_t and the vm workstation model object. */
   workstation_CLM03_t ws = (workstation_CLM03_t) surf_resource_new(sizeof(s_workstation_VM2013_t),
-      surf_vm_workstation_model, name, NULL);
+      surf_vm_workstation_model, name, NULL, NULL);
 
   /* Currently, we assume a VM has no storage. */
   ws->storage = NULL;
@@ -71,7 +71,8 @@ static void vm_ws_create(const char *name, void *ind_phys_workstation)
   /* We can assume one core and cas01 cpu for the first step.
    * Do xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, cpu) if you get the resource. */
   cpu_cas01_create_resource(name, // name
-      sub_cpu->power_peak,        // host->power_peak,
+      sub_cpu->power_peak_list,        // host->power_peak,
+      sub_cpu->pstate,
       1,                          // host->power_scale,
       NULL,                       // host->power_trace,
       1,                          // host->core_amount,
@@ -194,6 +195,17 @@ static void vm_ws_destroy(void *ind_vm_workstation)
    * free other objects than lmm_constraint. */
   surf_model_t cpu_model = cpu->generic_resource.model;
   lmm_constraint_free(cpu_model->model_private->maxmin_system, cpu->constraint);
+  {
+    unsigned long i;
+    for (i = 0; i < cpu->core; i++) {
+      void *cnst_id = cpu->constraint_core[i]->id;
+      lmm_constraint_free(cpu_model->model_private->maxmin_system, cpu->constraint_core[i]);
+      xbt_free(cnst_id);
+    }
+
+    xbt_free(cpu->constraint_core);
+  }
+
   surf_resource_free(cpu);
 
   /* Free the network resource of the VM. */
@@ -258,32 +270,13 @@ static void vm_ws_restore(void *ind_vm_ws)
   vm_ws->current_state = SURF_VM_STATE_RUNNING;
 }
 
-
 static double get_solved_value(surf_action_t cpu_action)
 {
-  int found = 0;
-  /* NOTE: Do not use surf_workstation_model's maxmin_system. It is not used. */
-  lmm_system_t pm_system = surf_cpu_model_pm->model_private->maxmin_system;
-  lmm_variable_t var = NULL;
-
-  xbt_swag_foreach(var, &pm_system->variable_set) {
-    XBT_DEBUG("var id %p id_int %d double %f", var->id, var->id_int, var->value);
-    if (var->id == cpu_action) {
-      found = 1;
-      break;
-    }
-  }
+  lmm_variable_t var = ((surf_action_lmm_t) cpu_action)->variable;
 
-  if (found)
-    return var->value;
-
-  XBT_CRITICAL("bug: cannot found the solved variable of the action %p", cpu_action);
-  DIE_IMPOSSIBLE;
-  return -1; /* NOT REACHED */
+  return var->value;
 }
 
-
-
 /* In the real world, processes on the guest operating system will be somewhat
  * degraded due to virtualization overhead. The total CPU share that these
  * processes get is smaller than that of the VM process gets on a host
@@ -369,7 +362,7 @@ static double vm_ws_share_resources(surf_model_t workstation_model, double now)
 
 
   /* FIXME: 3. do we have to re-initialize our cpu_action object? */
-#if 1
+#if 0
   /* iterate for all hosts including virtual machines */
   xbt_lib_foreach(host_lib, cursor, key, ind_host) {
     workstation_CLM03_t ws_clm03 = ind_host[SURF_WKS_LEVEL];
@@ -451,9 +444,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;
 
@@ -461,6 +454,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();
@@ -487,6 +491,7 @@ static void surf_vm_workstation_model_init_internal(void)
 //   model->set_max_duration = ws_action_set_max_duration;
   model->set_priority     = ws_action_set_priority;
   model->set_bound        = ws_action_set_bound;
+  model->set_affinity     = ws_action_set_affinity;
 // #ifdef HAVE_TRACING
 //   model->set_category     = ws_action_set_category;
 // #endif
@@ -538,6 +543,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;