Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Surf: factorize resource sets into common_public
[simgrid.git] / src / surf / workstation_ptask_L07.c
index aeecdd6..971e1b6 100644 (file)
@@ -9,7 +9,6 @@
 #include "xbt/str.h"
 #include "xbt/dict.h"
 #include "surf_private.h"
-/* extern lmm_system_t maxmin_system; */
 
 typedef enum {
   SURF_WORKSTATION_RESOURCE_CPU,
@@ -124,11 +123,6 @@ static void update_action_bound(surf_action_workstation_L07_t action)
 /******* Resource Public     **********/
 /**************************************/
 
-static void *name_service(const char *name)
-{
-  return xbt_dict_get_or_null(workstation_set, name);
-}
-
 static const char *get_resource_name(void *resource_id)
 {
   /* We can freely cast as a cpu_L07_t because it has the same
@@ -176,12 +170,6 @@ static void action_cancel(surf_action_t action)
   return;
 }
 
-static void action_recycle(surf_action_t action)
-{
-  DIE_IMPOSSIBLE;
-  return;
-}
-
 /* action_change_state is inherited from the surf module */
 /* action_set_data is inherited from the surf module */
 
@@ -248,7 +236,7 @@ static double share_resources(double now)
   surf_action_workstation_L07_t action = NULL;
 
   xbt_swag_t running_actions =
-    surf_workstation_model->common_public->states.running_action_set;
+    surf_workstation_model->common_public.states.running_action_set;
   double min = generic_maxmin_share_resources(running_actions,
                                               xbt_swag_offset(s_action,
                                                               variable),
@@ -280,7 +268,7 @@ static void update_actions_state(double now, double delta)
   surf_action_workstation_L07_t action = NULL;
   surf_action_workstation_L07_t next_action = NULL;
   xbt_swag_t running_actions =
-    surf_workstation_model->common_public->states.running_action_set;
+    surf_workstation_model->common_public.states.running_action_set;
 
   xbt_swag_foreach_safe(action, next_action, running_actions) {
     deltap = delta;
@@ -425,21 +413,12 @@ static void finalize(void)
   int i, j;
 
   xbt_dict_free(&link_set);
-  xbt_dict_free(&workstation_set);
   if (parallel_task_link_set != NULL) {
     xbt_dict_free(&parallel_task_link_set);
   }
-  xbt_swag_free(surf_workstation_model->common_public->
-                states.ready_action_set);
-  xbt_swag_free(surf_workstation_model->common_public->
-                states.running_action_set);
-  xbt_swag_free(surf_workstation_model->common_public->
-                states.failed_action_set);
-  xbt_swag_free(surf_workstation_model->common_public->
-                states.done_action_set);
-
-  free(surf_workstation_model->common_public);
-  free(surf_workstation_model->common_private);
+
+  surf_model_exit((surf_model_t)surf_workstation_model);
+
   free(surf_workstation_model->extension_public);
 
   free(surf_workstation_model);
@@ -538,7 +517,7 @@ static surf_action_t execute_parallel_task(int workstation_nb,
   action->communication_amount = communication_amount;
   action->latency = latency;
   action->generic_action.state_set =
-    surf_workstation_model->common_public->states.running_action_set;
+    surf_workstation_model->common_public.states.running_action_set;
 
   xbt_swag_insert(action, action->generic_action.state_set);
   action->rate = rate;
@@ -685,7 +664,7 @@ static cpu_L07_t cpu_new(const char *name, double power_scale,
                          tmgr_trace_t state_trace, xbt_dict_t cpu_properties)
 {
   cpu_L07_t cpu = xbt_new0(s_cpu_L07_t, 1);
-  xbt_assert1(!xbt_dict_get_or_null(workstation_set, name),
+  xbt_assert1(!surf_model_resource_by_name(surf_workstation_model, name),
               "Host '%s' declared several times in the platform file.", name);
 
   cpu->model = (surf_model_t) surf_workstation_model;
@@ -713,7 +692,7 @@ static cpu_L07_t cpu_new(const char *name, double power_scale,
   /*add the property set */
   cpu->properties = current_property_set;
 
-  xbt_dict_set(workstation_set, name, cpu, cpu_free);
+  xbt_dict_set(surf_model_resource_set(surf_workstation_model), name, cpu, cpu_free);
 
   return cpu;
 }
@@ -857,12 +836,12 @@ static void parse_route_set_endpoints(void)
 {
   cpu_L07_t cpu_tmp = NULL;
 
-  cpu_tmp = (cpu_L07_t) name_service(A_surfxml_route_src);
+  cpu_tmp = (cpu_L07_t) surf_model_resource_by_name(surf_workstation_model, A_surfxml_route_src);
   xbt_assert1(cpu_tmp, "Invalid cpu %s", A_surfxml_route_src);
   if (cpu_tmp != NULL)
     src_id = cpu_tmp->id;
 
-  cpu_tmp = (cpu_L07_t) name_service(A_surfxml_route_dst);
+  cpu_tmp = (cpu_L07_t) surf_model_resource_by_name(surf_workstation_model, A_surfxml_route_dst);
   xbt_assert1(cpu_tmp, "Invalid cpu %s", A_surfxml_route_dst);
   if (cpu_tmp != NULL)
     dst_id = cpu_tmp->id;
@@ -950,7 +929,7 @@ static void add_traces(void)
   /* Connect traces relative to cpu */
   xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) {
     tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
-    cpu_L07_t host = xbt_dict_get_or_null(workstation_set, elm);
+    cpu_L07_t host = surf_model_resource_by_name(surf_workstation_model, elm);
 
     xbt_assert1(host, "Host %s undefined", elm);
     xbt_assert1(trace, "Trace %s undefined", trace_name);
@@ -960,7 +939,7 @@ static void add_traces(void)
 
   xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
     tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
-    cpu_L07_t host = xbt_dict_get_or_null(workstation_set, elm);
+    cpu_L07_t host = surf_model_resource_by_name(surf_workstation_model, elm);
 
     xbt_assert1(host, "Host %s undefined", elm);
     xbt_assert1(trace, "Trace %s undefined", trace_name);
@@ -998,34 +977,6 @@ static void add_traces(void)
 
     link->lat_event = tmgr_history_add_trace(history, trace, 0.0, 0, link);
   }
-/*
-
-   xbt_dynar_foreach (traces_connect_list, cpt, value) {
-     trace_connect = xbt_str_split_str(value, "#");
-     trace_id        = xbt_dynar_get_as(trace_connect, 0, char*);
-     connect_element = atoi(xbt_dynar_get_as(trace_connect, 1, char*));
-     connect_kind    = atoi(xbt_dynar_get_as(trace_connect, 2, char*));
-     connector_id    = xbt_dynar_get_as(trace_connect, 3, char*);
-
-     xbt_assert1((trace = xbt_dict_get_or_null(traces_set_list, trace_id)), "Trace %s undefined", trace_id);
-
-     if (connect_element == A_surfxml_trace_c_connect_element_HOST) {
-        xbt_assert1((host = xbt_dict_get_or_null(workstation_set, connector_id)), "Host %s undefined", connector_id);
-        switch (connect_kind) {
-           case A_surfxml_trace_c_connect_kind_AVAILABILITY: host->state_event = tmgr_history_add_trace(history, trace, 0.0, 0, host); break;
-           case A_surfxml_trace_c_connect_kind_POWER: host->power_event = tmgr_history_add_trace(history, trace, 0.0, 0, host); break;
-        }
-     }
-     else {
-        xbt_assert1((link = xbt_dict_get_or_null(link_set, connector_id)), "Link %s undefined", connector_id);
-        switch (connect_kind) {
-           case A_surfxml_trace_c_connect_kind_AVAILABILITY: link->state_event = tmgr_history_add_trace(history, trace, 0.0, 0, link); break;
-           case A_surfxml_trace_c_connect_kind_BANDWIDTH: link->bw_event = tmgr_history_add_trace(history, trace, 0.0, 0, link); break;
-           case A_surfxml_trace_c_connect_kind_LATENCY: link->lat_event = tmgr_history_add_trace(history, trace, 0.0, 0, link); break;
-        }
-     }
-   }
-*/
 }
 
 static void define_callbacks(const char *file)
@@ -1049,49 +1000,34 @@ static void define_callbacks(const char *file)
 
 static void model_init_internal(void)
 {
-  s_surf_action_t action;
-
   surf_workstation_model = xbt_new0(s_surf_workstation_model_t, 1);
 
-  surf_workstation_model->common_private =
-    xbt_new0(s_surf_model_private_t, 1);
-  surf_workstation_model->common_public = xbt_new0(s_surf_model_public_t, 1);
+  surf_model_init((surf_model_t)surf_workstation_model);
   surf_workstation_model->extension_public =
     xbt_new0(s_surf_workstation_model_extension_public_t, 1);
 
-  surf_workstation_model->common_public->states.ready_action_set =
-    xbt_swag_new(xbt_swag_offset(action, state_hookup));
-  surf_workstation_model->common_public->states.running_action_set =
-    xbt_swag_new(xbt_swag_offset(action, state_hookup));
-  surf_workstation_model->common_public->states.failed_action_set =
-    xbt_swag_new(xbt_swag_offset(action, state_hookup));
-  surf_workstation_model->common_public->states.done_action_set =
-    xbt_swag_new(xbt_swag_offset(action, state_hookup));
-
-  surf_workstation_model->common_public->name_service = name_service;
-  surf_workstation_model->common_public->get_resource_name =
+  surf_workstation_model->common_public.get_resource_name =
     get_resource_name;
-  surf_workstation_model->common_public->action_get_state =
+  surf_workstation_model->common_public.action_get_state =
     surf_action_get_state;
-  surf_workstation_model->common_public->action_get_start_time =
+  surf_workstation_model->common_public.action_get_start_time =
     surf_action_get_start_time;
-  surf_workstation_model->common_public->action_get_finish_time =
+  surf_workstation_model->common_public.action_get_finish_time =
     surf_action_get_finish_time;
-  surf_workstation_model->common_public->action_use = action_use;
-  surf_workstation_model->common_public->action_free = action_free;
-  surf_workstation_model->common_public->action_cancel = action_cancel;
-  surf_workstation_model->common_public->action_recycle = action_recycle;
-  surf_workstation_model->common_public->action_change_state =
+  surf_workstation_model->common_public.action_use = action_use;
+  surf_workstation_model->common_public.action_free = action_free;
+  surf_workstation_model->common_public.action_cancel = action_cancel;
+  surf_workstation_model->common_public.action_change_state =
     surf_action_change_state;
-  surf_workstation_model->common_public->action_set_data =
+  surf_workstation_model->common_public.action_set_data =
     surf_action_set_data;
-  surf_workstation_model->common_public->suspend = action_suspend;
-  surf_workstation_model->common_public->resume = action_resume;
-  surf_workstation_model->common_public->is_suspended = action_is_suspended;
-  surf_workstation_model->common_public->set_max_duration =
+  surf_workstation_model->common_public.suspend = action_suspend;
+  surf_workstation_model->common_public.resume = action_resume;
+  surf_workstation_model->common_public.is_suspended = action_is_suspended;
+  surf_workstation_model->common_public.set_max_duration =
     action_set_max_duration;
-  surf_workstation_model->common_public->set_priority = action_set_priority;
-  surf_workstation_model->common_public->name = "Workstation ptask_L07";
+  surf_workstation_model->common_public.set_priority = action_set_priority;
+  surf_workstation_model->common_public.name = "Workstation ptask_L07";
 
   surf_workstation_model->common_private->resource_used = resource_used;
   surf_workstation_model->common_private->share_resources = share_resources;
@@ -1119,9 +1055,8 @@ static void model_init_internal(void)
     get_link_latency;
   surf_workstation_model->extension_public->link_shared = link_shared;
 
-  surf_workstation_model->common_public->get_properties = get_properties;
+  surf_workstation_model->common_public.get_properties = get_properties;
 
-  workstation_set = xbt_dict_new();
   link_set = xbt_dict_new();
 
   if (!ptask_maxmin_system)