Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Introduce sg_storage_size_t type
[simgrid.git] / src / surf / cpu_cas01.c
index dad0cbd..3430431 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2009-2011. The SimGrid Team.
+/* Copyright (c) 2009-2013. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -22,6 +22,19 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_cpu, surf,
 static xbt_swag_t
     cpu_running_action_set_that_does_not_need_being_checked = NULL;
 
+/* Additionnal callback function to cleanup some data, called from surf_resource_free */
+
+static void cpu_cas01_cleanup(void* r){
+  cpu_Cas01_t cpu = (cpu_Cas01_t)r;
+  unsigned int iter;
+  xbt_dynar_t power_tuple = NULL;
+  xbt_dynar_foreach(cpu->energy->power_range_watts_list, iter, power_tuple)
+    xbt_dynar_free(&power_tuple);
+  xbt_dynar_free(&cpu->energy->power_range_watts_list);
+  xbt_dynar_free(&cpu->power_peak_list);
+  xbt_free(cpu->energy);
+  return;
+}
 
 /* This function is registered as a callback to sg_platf_new_host() and never called directly */
 static void *cpu_create_resource(const char *name, xbt_dynar_t power_peak,
@@ -40,7 +53,7 @@ static void *cpu_create_resource(const char *name, xbt_dynar_t power_peak,
              name);
   cpu = (cpu_Cas01_t) surf_resource_new(sizeof(s_cpu_Cas01_t),
                                         surf_cpu_model, name,
-                                        cpu_properties);
+                                        cpu_properties,  &cpu_cas01_cleanup);
   cpu->power_peak = xbt_dynar_get_as(power_peak, pstate, double);
   cpu->power_peak_list = power_peak;
   cpu->pstate = pstate;
@@ -161,7 +174,7 @@ static void cpu_update_actions_state_full(double now, double delta)
 
 xbt_dynar_t cpu_get_watts_range_list(cpu_Cas01_t cpu_model)
 {
-       xbt_dynar_t power_range_list = xbt_dynar_new(sizeof(xbt_dynar_t), NULL);
+       xbt_dynar_t power_range_list;
        xbt_dynar_t power_tuple;
        int i = 0, pstate_nb=0;
        xbt_dynar_t current_power_values;
@@ -176,6 +189,8 @@ xbt_dynar_t cpu_get_watts_range_list(cpu_Cas01_t cpu_model)
        if (all_power_values_str == NULL)
                return NULL;
 
+
+       power_range_list = xbt_dynar_new(sizeof(xbt_dynar_t), NULL);
        xbt_dynar_t all_power_values = xbt_str_split(all_power_values_str, ",");
 
        pstate_nb = xbt_dynar_length(all_power_values);
@@ -197,12 +212,17 @@ xbt_dynar_t cpu_get_watts_range_list(cpu_Cas01_t cpu_model)
                xbt_dynar_push_as(power_tuple, double, max_power);
 
                xbt_dynar_push_as(power_range_list, xbt_dynar_t, power_tuple);
+               xbt_dynar_free(&current_power_values);
        }
-
+       xbt_dynar_free(&all_power_values);
        return power_range_list;
 
 }
 
+/**
+ * Computes the power consumed by the host according to the current pstate and processor load
+ *
+ */
 static double cpu_get_current_watts_value(cpu_Cas01_t cpu_model, double cpu_load)
 {
        xbt_dynar_t power_range_list = cpu_model->energy->power_range_watts_list;
@@ -264,8 +284,6 @@ static void cpu_update_resource_state(void *id,
   lmm_variable_t var = NULL;
   lmm_element_t elem = NULL;
 
-  surf_watched_hosts();
-
   if (event_type == cpu->power_event) {
     cpu->power_scale = value;
     lmm_update_constraint_bound(surf_cpu_model->model_private->maxmin_system, cpu->constraint,
@@ -286,9 +304,11 @@ static void cpu_update_resource_state(void *id,
     if (tmgr_trace_event_free(event_type))
       cpu->power_event = NULL;
   } else if (event_type == cpu->state_event) {
-    if (value > 0)
+    if (value > 0) {
+      if(cpu->state_current == SURF_RESOURCE_OFF)
+        xbt_dynar_push_as(host_that_restart, char*, (cpu->generic_resource.name));
       cpu->state_current = SURF_RESOURCE_ON;
-    else {
+    else {
       lmm_constraint_t cnst = cpu->constraint;
 
       cpu->state_current = SURF_RESOURCE_OFF;