Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Factorize some code in the parser, hide some functions and variables, avoid useless...
[simgrid.git] / src / surf / workstation_ptask_L07.c
index 2eb7dcb..b72a43d 100644 (file)
@@ -6,6 +6,7 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "xbt/ex.h"
+#include "xbt/str.h"
 #include "xbt/dict.h"
 #include "surf_private.h"
 /* extern lmm_system_t maxmin_system; */
@@ -360,7 +361,7 @@ static void update_actions_state(double now, double delta)
 
 static void update_resource_state(void *id,
                                  tmgr_trace_event_t event_type,
-                                 double value)
+                                 double value, double date)
 {
   cpu_L07_t cpu = id;
   link_L07_t nw_link = id;
@@ -374,10 +375,11 @@ static void update_resource_state(void *id,
     } else if (event_type == nw_link->lat_event) {
       lmm_variable_t var = NULL;
       surf_action_workstation_L07_t action = NULL;
+      lmm_element_t elem = NULL;
 
       nw_link->lat_current = value;
-      while (lmm_get_var_from_cnst
-            (ptask_maxmin_system, nw_link->constraint, &var)) {
+      while ((var = lmm_get_var_from_cnst
+            (ptask_maxmin_system, nw_link->constraint, &elem))) {
        
 
        action = lmm_variable_id(var);
@@ -399,7 +401,7 @@ static void update_resource_state(void *id,
     if (event_type == cpu->power_event) {
       cpu->power_current = value;
       lmm_update_constraint_bound(ptask_maxmin_system, cpu->constraint,
-                                 cpu->power_current);
+                                 cpu->power_current * cpu->power_scale);
     } else if (event_type == cpu->state_event) {
       if (value > 0)
        cpu->state_current = SURF_CPU_ON;
@@ -485,10 +487,8 @@ static surf_action_t execute_parallel_task(int workstation_nb,
   int nb_host = 0;
   double latency = 0.0;
 
-  if (parallel_task_link_set == NULL) {
-    parallel_task_link_set =
-       xbt_dict_new_ext(workstation_nb * workstation_nb * 10);
-  }
+  if (parallel_task_link_set == NULL)
+    parallel_task_link_set = xbt_dict_new();
 
   xbt_dict_reset(parallel_task_link_set);
 
@@ -713,6 +713,7 @@ static cpu_L07_t cpu_new(const char *name, double power_scale,
   cpu->properties =  current_property_set;
 
   xbt_dict_set(workstation_set, name, cpu, cpu_free);
+
   return cpu;
 }
 
@@ -729,7 +730,7 @@ static void parse_cpu_init(void)
   e_surf_cpu_state_t state_initial = SURF_CPU_OFF;
   tmgr_trace_t state_trace = NULL;
 
-  surf_parse_get_double(&power_scale, A_surfxml_host_power);
+  power_scale = get_cpu_power(A_surfxml_host_power);
   surf_parse_get_double(&power_initial, A_surfxml_host_availability);
   surf_parse_get_trace(&power_trace, A_surfxml_host_availability_file);
 
@@ -837,7 +838,6 @@ static void parse_link_init(void)
   current_property_set = xbt_dict_new();
   link_new(name_link, bw_initial, bw_trace, lat_initial, lat_trace,
                   state_initial_link, state_trace, policy_initial_link, current_property_set);
-
  }
 
 static void route_new(int src_id, int dst_id,
@@ -867,15 +867,15 @@ static void parse_route_set_endpoints(void)
   if (cpu_tmp != NULL)
     dst_id = cpu_tmp->id;
 
-  route_link_list = xbt_dynar_new(sizeof(char*), &free_string);
+  route_action = A_surfxml_route_action;
 }
 
 static void parse_route_set_route(void)
 {
   char* name;
   if (src_id != -1 && dst_id != -1) {
-     name = bprintf("%d##%d",src_id, dst_id);
-     xbt_dict_set(route_table, name, route_link_list, NULL);
+     name = bprintf("%x#%x",src_id, dst_id);
+     manage_route(route_table, name, route_action, 0);
      free(name);
   }
 }
@@ -883,6 +883,7 @@ static void parse_route_set_route(void)
 static void add_loopback(void)
 {
   int i;
+
   /* Adding loopback if needed */
   for (i = 0; i < nb_workstation; i++)
     if (!ROUTE(i, i).size) {
@@ -898,32 +899,137 @@ static void add_loopback(void)
     }
 }
 
-static void add_route()
+static void add_route(void)
 {
     xbt_ex_t e;
     int nb_link = 0;
     unsigned int cpt = 0;
     int link_list_capacity = 0;
     link_L07_t *link_list = NULL;
+    xbt_dict_cursor_t cursor = NULL;
+    char *key,*data, *end;
+    const char *sep = "#";
+    xbt_dynar_t links, keys;
+       char* link = NULL;
 
     if (routing_table == NULL) create_routing_table();
 
-    src_id = atoi(xbt_dynar_get_as(keys, 0, char*));
-    dst_id = atoi(xbt_dynar_get_as(keys, 1, char*));
+    xbt_dict_foreach(route_table, cursor, key, data) {
+       nb_link = 0;
+       links = (xbt_dynar_t)data;
+       keys = xbt_str_split_str(key, sep);
+       
+       src_id = strtol(xbt_dynar_get_as(keys, 0, char*), &end, 16);
+       dst_id = strtol(xbt_dynar_get_as(keys, 1, char*), &end, 16);
+
+       link_list_capacity = xbt_dynar_length(links);
+       link_list = xbt_new(link_L07_t, link_list_capacity);
+
+       
+       xbt_dynar_foreach (links, cpt, link) {
+         TRY {
+           link_list[nb_link++] = xbt_dict_get(link_set, link);
+         }
+         CATCH(e) {
+           RETHROW1("Link %s not found (dict raised this exception: %s)", link);
+         }    
+       }
+       route_new(src_id, dst_id, link_list, nb_link);
+   }
+}
 
-    link_list_capacity = xbt_dynar_length(links);
-    link_list = xbt_new(link_L07_t, link_list_capacity);
+static void add_traces(void) {   
+   xbt_dict_cursor_t cursor=NULL;
+   char *trace_name,*elm;
+   
+   if (!trace_connect_list_host_avail) return;
+   /* 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);
+      
+      xbt_assert1(host, "Host %s undefined", elm);
+      xbt_assert1(trace, "Trace %s undefined", trace_name);
+      
+      host->state_event = tmgr_history_add_trace(history, trace, 0.0, 0, host); 
+   }
 
-    char* link = NULL;
-    xbt_dynar_foreach (links, cpt, link) {
-      TRY {
-        link_list[nb_link++] = xbt_dict_get(link_set, link);
-      }
-      CATCH(e) {
-        RETHROW1("Link %s not found (dict raised this exception: %s)", link);
-      }    
-    }
-    route_new(src_id, dst_id, link_list, nb_link);
+   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);
+      
+      xbt_assert1(host, "Host %s undefined", elm);
+      xbt_assert1(trace, "Trace %s undefined", trace_name);
+      
+      host->power_event = tmgr_history_add_trace(history, trace, 0.0, 0, host); 
+   }
+
+   /* Connect traces relative to network */
+   xbt_dict_foreach(trace_connect_list_link_avail, cursor, trace_name, elm) {
+      tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
+      link_L07_t link = xbt_dict_get_or_null(link_set, elm);
+      
+      xbt_assert1(link, "Link %s undefined", elm);
+      xbt_assert1(trace, "Trace %s undefined", trace_name);
+      
+      link->state_event = tmgr_history_add_trace(history, trace, 0.0, 0, link);
+   }
+
+   xbt_dict_foreach(trace_connect_list_bandwidth, cursor, trace_name, elm) {
+      tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
+      link_L07_t link = xbt_dict_get_or_null(link_set, elm);
+      
+      xbt_assert1(link, "Link %s undefined", elm);
+      xbt_assert1(trace, "Trace %s undefined", trace_name);
+      
+      link->bw_event = tmgr_history_add_trace(history, trace, 0.0, 0, link);
+   }
+   
+   xbt_dict_foreach(trace_connect_list_latency, cursor, trace_name, elm) {
+      tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
+      link_L07_t link = xbt_dict_get_or_null(link_set, elm);
+      
+      xbt_assert1(link, "Link %s undefined", elm);
+      xbt_assert1(trace, "Trace %s undefined", trace_name);
+      
+      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;
+        }
+     }
+   }
+*/
+   xbt_dict_free(&trace_connect_list_host_avail);
+   xbt_dict_free(&trace_connect_list_power);
+   xbt_dict_free(&trace_connect_list_link_avail);
+   xbt_dict_free(&trace_connect_list_bandwidth);
+   xbt_dict_free(&trace_connect_list_latency);
+   
+   xbt_dict_free(&traces_set_list); 
 }
 
 static void define_callbacks(const char *file)
@@ -934,13 +1040,23 @@ static void define_callbacks(const char *file)
   surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties);
   surfxml_add_callback(STag_surfxml_link_cb_list, &parse_link_init);
   surfxml_add_callback(STag_surfxml_route_cb_list, &parse_route_set_endpoints);
-  surfxml_add_callback(ETag_surfxml_link_c_ctn_cb_list, &parse_route_elem);
   surfxml_add_callback(ETag_surfxml_route_cb_list, &parse_route_set_route);
-  surfxml_add_callback(STag_surfxml_platform_cb_list, &init_route_table);
   surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_route);
   surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_loopback);
+  surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_traces);
+  surfxml_add_callback(STag_surfxml_set_cb_list, &parse_sets);
+  surfxml_add_callback(STag_surfxml_route_c_multi_cb_list, &parse_route_multi_set_endpoints);
+  surfxml_add_callback(ETag_surfxml_route_c_multi_cb_list, &parse_route_multi_set_route);
+  surfxml_add_callback(STag_surfxml_foreach_cb_list, &parse_foreach);
+  surfxml_add_callback(STag_surfxml_cluster_cb_list, &parse_cluster);
+  surfxml_add_callback(STag_surfxml_trace_cb_list, &parse_trace_init);
+  surfxml_add_callback(ETag_surfxml_trace_cb_list, &parse_trace_finalize);
+  surfxml_add_callback(STag_surfxml_trace_c_connect_cb_list, &parse_trace_c_connect);
+  surfxml_add_callback(STag_surfxml_random_cb_list, &init_randomness);
+  surfxml_add_callback(ETag_surfxml_random_cb_list, &add_randomness);
 }
 
+
 /**************************************/
 /********* Module  creation ***********/
 /**************************************/
@@ -1045,8 +1161,7 @@ void surf_workstation_model_init_ptask_L07(const char *filename)
   define_callbacks(filename);
 
   update_model_description(surf_workstation_model_description,
-                             surf_workstation_model_description_size,
-                             "ptask_L07",
-                             (surf_model_t) surf_workstation_model);
+                          "ptask_L07",
+                          (surf_model_t) surf_workstation_model);
   xbt_dynar_push(model_list, &surf_workstation_model);
 }