Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add a cleanup callback to surf_resource_t, useful to free data allocated in cpu models
authorAugustin Degomme <degomme@idpann.imag.fr>
Mon, 23 Sep 2013 15:57:44 +0000 (17:57 +0200)
committerAugustin Degomme <degomme@idpann.imag.fr>
Mon, 23 Sep 2013 15:57:44 +0000 (17:57 +0200)
Removes a few leaks

src/include/surf/surf.h
src/include/surf/surf_resource.h
src/include/surf/surf_resource_lmm.h
src/surf/cpu_cas01.c
src/surf/cpu_ti.c
src/surf/storage.c
src/surf/workstation_ptask_L07.c

index e93f43f..afeb5f7 100644 (file)
@@ -377,6 +377,7 @@ typedef struct surf_resource {
   surf_model_t model;
   char *name;
   xbt_dict_t properties;
+  void_f_pvoid_t free_f;
 } s_surf_resource_t, *surf_resource_t;
 
 /**
index dc66869..1723e85 100644 (file)
 static XBT_INLINE
     surf_resource_t surf_resource_new(size_t childsize,
                                       surf_model_t model, const char *name,
-                                      xbt_dict_t props)
+                                      xbt_dict_t props, void_f_pvoid_t free_f)
 {
   surf_resource_t res = xbt_malloc0(childsize);
   res->model = model;
   res->name = xbt_strdup(name);
   res->properties = props;
+  res->free_f=free_f;
   return res;
 }
 
 static XBT_INLINE void surf_resource_free(void *r)
 {
   surf_resource_t resource = r;
+  if(resource->free_f)
+    resource->free_f(r);
   free(resource->name);
   xbt_dict_free(&resource->properties);
   free(resource);
index 992f70d..1f50786 100644 (file)
@@ -28,7 +28,7 @@ static XBT_INLINE
 
   surf_resource_lmm_t res =
       (surf_resource_lmm_t) surf_resource_new(childsize, model, name,
-                                              props);
+                                              props, NULL);
 
   res->constraint = lmm_constraint_new(system, res, constraint_value);
   res->state_current = state_init;
index b3aeec0..671f363 100644 (file)
@@ -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_cas1_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_cas1_cleanup);
   cpu->power_peak = xbt_dynar_get_as(power_peak, pstate, double);
   cpu->power_peak_list = power_peak;
   cpu->pstate = pstate;
index 127d1ea..629faaf 100644 (file)
@@ -161,7 +161,7 @@ static void* cpu_ti_create_resource(const char *name, xbt_dynar_t power_peak,
               name);
   xbt_assert(core==1,"Multi-core not handled with this model yet");
   cpu = (cpu_ti_t) surf_resource_new(sizeof(s_cpu_ti_t),
-          surf_cpu_model, name,cpu_properties);
+          surf_cpu_model, name,cpu_properties, NULL);
   cpu->action_set =
       xbt_swag_new(xbt_swag_offset(ti_action, cpu_list_hookup));
 
index e00a721..e5d8d02 100644 (file)
@@ -205,7 +205,7 @@ static void* storage_create_resource(const char* id, const char* model,
               "Storage '%s' declared several times in the platform file",
               id);
   storage = (storage_t) surf_resource_new(sizeof(s_storage_t),
-          surf_storage_model, id, properties);
+          surf_storage_model, id, properties, NULL);
 
   storage->generic_resource.name = xbt_strdup(id);
   storage->state_current = SURF_RESOURCE_ON;
index 9d46e74..eb62dcf 100644 (file)
@@ -668,7 +668,7 @@ static void* ptask_cpu_create_resource(const char *name, double power_scale,
               name);
 
   cpu = (cpu_L07_t) surf_resource_new(sizeof(s_cpu_L07_t),
-          surf_workstation_model, name,cpu_properties);
+          surf_workstation_model, name,cpu_properties, NULL);
 
   cpu->type = SURF_WORKSTATION_RESOURCE_CPU;
   cpu->info = xbt_lib_get_or_null(host_lib, name, ROUTING_HOST_LEVEL);