Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use a mallocator for the Surf actions
authorthiery <thiery@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 1 Feb 2011 16:31:14 +0000 (16:31 +0000)
committerthiery <thiery@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 1 Feb 2011 16:31:14 +0000 (16:31 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@9557 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/surf/cpu.c
src/surf/cpu_im.c
src/surf/cpu_ti.c
src/surf/network.c
src/surf/network_constant.c
src/surf/network_gtnets.c
src/surf/network_im.c
src/surf/surf.c
src/surf/surf_action.c
src/surf/surf_private.h
src/surf/workstation_ptask_L07.c

index 4e3916c..dc1165f 100644 (file)
@@ -161,7 +161,7 @@ static int cpu_action_unref(surf_action_t action)
     if (action->category)
       xbt_free(action->category);
 #endif
     if (action->category)
       xbt_free(action->category);
 #endif
-    free(action);
+    surf_action_free(&action);
     return 1;
   }
   return 0;
     return 1;
   }
   return 0;
index 7af5acc..b5d2f87 100644 (file)
@@ -185,7 +185,7 @@ static int cpu_im_action_unref(surf_action_t action)
     if (action->category)
       xbt_free(action->category);
 #endif
     if (action->category)
       xbt_free(action->category);
 #endif
-    free(action);
+    surf_action_free(&action);
     return 1;
   }
   return 0;
     return 1;
   }
   return 0;
index b1a06fd..75d67a9 100644 (file)
@@ -302,7 +302,7 @@ static int cpu_ti_action_unref(surf_action_t action)
     xbt_heap_remove(cpu_ti_action_heap,
                     ((surf_action_cpu_ti_t) action)->index_heap);
     xbt_swag_insert(ACTION_GET_CPU(action), cpu_ti_modified_cpu);
     xbt_heap_remove(cpu_ti_action_heap,
                     ((surf_action_cpu_ti_t) action)->index_heap);
     xbt_swag_insert(ACTION_GET_CPU(action), cpu_ti_modified_cpu);
-    free(action);
+    surf_action_free(&action);
     return 1;
   }
   return 0;
     return 1;
   }
   return 0;
index c69aaa4..6dee719 100644 (file)
@@ -347,7 +347,7 @@ static int net_action_unref(surf_action_t action)
     if (action->category)
       xbt_free(action->category);
 #endif
     if (action->category)
       xbt_free(action->category);
 #endif
-    free(action);
+    surf_action_free(&action);
     return 1;
   }
   return 0;
     return 1;
   }
   return 0;
index bf73baf..a6978a2 100644 (file)
@@ -41,7 +41,7 @@ static int netcste_action_unref(surf_action_t action)
   action->refcount--;
   if (!action->refcount) {
     xbt_swag_remove(action, action->state_set);
   action->refcount--;
   if (!action->refcount) {
     xbt_swag_remove(action, action->state_set);
-    free(action);
+    surf_action_free(&action);
     return 1;
   }
   return 0;
     return 1;
   }
   return 0;
index 8d6c950..2975603 100644 (file)
@@ -187,7 +187,7 @@ static int action_unref(surf_action_t action)
     if (action->category)
       xbt_free(action->category);
 #endif
     if (action->category)
       xbt_free(action->category);
 #endif
-    free(action);
+    surf_action_free(&action);
     return 1;
   }
   return 0;
     return 1;
   }
   return 0;
index ce981b5..01b323a 100644 (file)
@@ -350,8 +350,7 @@ static int im_net_action_unref(surf_action_t action)
     if (action->category)
       xbt_free(action->category);
 #endif
     if (action->category)
       xbt_free(action->category);
 #endif
-    free(action);
-    action = NULL;
+    surf_action_free(&action);
     return 1;
   }
   return 0;
     return 1;
   }
   return 0;
index 26bfeea..057a81e 100644 (file)
@@ -309,6 +309,7 @@ void surf_init(int *argc, char **argv)
     history = tmgr_history_new();
 
   surf_config_init(argc, argv);
     history = tmgr_history_new();
 
   surf_config_init(argc, argv);
+  surf_action_init();
   if (MC_IS_ENABLED)
     MC_memory_init();
 }
   if (MC_IS_ENABLED)
     MC_memory_init();
 }
@@ -362,6 +363,7 @@ void surf_exit(void)
     tmgr_history_free(history);
     history = NULL;
   }
     tmgr_history_free(history);
     history = NULL;
   }
+  surf_action_exit();
 
   if (surf_path)
     xbt_dynar_free(&surf_path);
 
   if (surf_path)
     xbt_dynar_free(&surf_path);
index 2c34a4e..036deea 100644 (file)
@@ -5,6 +5,8 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "surf_private.h"
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "surf_private.h"
+#include "network_private.h"
+#include "xbt/mallocator.h"
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_kernel);
 
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_kernel);
 
@@ -21,10 +23,54 @@ const char *surf_action_state_names[6] = {
   "SURF_ACTION_NOT_IN_THE_SYSTEM"
 };
 
   "SURF_ACTION_NOT_IN_THE_SYSTEM"
 };
 
+/* Surf actions mallocator */
+static xbt_mallocator_t action_mallocator = NULL;
+static int action_mallocator_allocated_size = 0;
+static void* action_mallocator_new_f(void);
+static void action_mallocator_free_f(void* action);
+static void action_mallocator_reset_f(void* action);
+
+/**
+ * \brief Initializes the action module of Surf.
+ */
+void surf_action_init(void) {
+
+  /* the action mallocator will always provide actions of the following size,
+   * so this size should be set to the maximum size of the surf action structures
+   */
+  action_mallocator_allocated_size = sizeof(s_surf_action_network_CM02_t);
+  action_mallocator = xbt_mallocator_new(128, action_mallocator_new_f,
+      action_mallocator_free_f, action_mallocator_reset_f);
+}
+
+/**
+ * \brief Uninitializes the action module of Surf.
+ */
+void surf_action_exit(void) {
+
+  xbt_mallocator_free(action_mallocator);
+}
+
+static void* action_mallocator_new_f(void) {
+  return xbt_malloc0(action_mallocator_allocated_size);
+}
+
+static void action_mallocator_free_f(void* action) {
+  xbt_free(action);
+}
+
+static void action_mallocator_reset_f(void* action) {
+  memset(action, 0, action_mallocator_allocated_size);
+}
+
 void *surf_action_new(size_t size, double cost, surf_model_t model,
                       int failed)
 {
 void *surf_action_new(size_t size, double cost, surf_model_t model,
                       int failed)
 {
-  surf_action_t action = xbt_malloc0(size);
+  xbt_assert2(size <= action_mallocator_allocated_size,
+      "Cannot create a surf action of size %d: the mallocator only provides actions of size %d",
+      size, action_mallocator_allocated_size);
+
+  surf_action_t action = xbt_mallocator_get(action_mallocator);
   action->refcount = 1;
   action->cost = cost;
   action->remains = cost;
   action->refcount = 1;
   action->cost = cost;
   action->remains = cost;
@@ -75,8 +121,7 @@ double surf_action_get_finish_time(surf_action_t action)
 
 XBT_INLINE void surf_action_free(surf_action_t * action)
 {
 
 XBT_INLINE void surf_action_free(surf_action_t * action)
 {
-  (*action)->model_type->action_cancel(*action);
-  free(*action);
+  xbt_mallocator_release(action_mallocator, *action);
   *action = NULL;
 }
 
   *action = NULL;
 }
 
index cb7b4c4..026ab2f 100644 (file)
@@ -50,6 +50,8 @@ double generic_maxmin_share_resources(xbt_swag_t running_actions,
                                       void (*solve) (lmm_system_t));
 
 /* Generic functions common to all models */
                                       void (*solve) (lmm_system_t));
 
 /* Generic functions common to all models */
+void surf_action_init(void);
+void surf_action_exit(void);
 e_surf_action_state_t surf_action_state_get(surf_action_t action);      /* cannot declare inline since we use a pointer to it */
 double surf_action_get_start_time(surf_action_t action);        /* cannot declare inline since we use a pointer to it */
 double surf_action_get_finish_time(surf_action_t action);       /* cannot declare inline since we use a pointer to it */
 e_surf_action_state_t surf_action_state_get(surf_action_t action);      /* cannot declare inline since we use a pointer to it */
 double surf_action_get_start_time(surf_action_t action);        /* cannot declare inline since we use a pointer to it */
 double surf_action_get_finish_time(surf_action_t action);       /* cannot declare inline since we use a pointer to it */
index 7a9f6b5..a5581e0 100644 (file)
@@ -128,7 +128,7 @@ static int ptask_action_unref(surf_action_t action)
     free(((surf_action_workstation_L07_t) action)->workstation_list);
     free(((surf_action_workstation_L07_t) action)->communication_amount);
     free(((surf_action_workstation_L07_t) action)->computation_amount);
     free(((surf_action_workstation_L07_t) action)->workstation_list);
     free(((surf_action_workstation_L07_t) action)->communication_amount);
     free(((surf_action_workstation_L07_t) action)->computation_amount);
-    free(action);
+    surf_action_free(&action);
     return 1;
   }
   return 0;
     return 1;
   }
   return 0;