Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Modify structures to support different sources of avaibility trace
authorjbrv <jean-baptiste.herve@esial.net>
Fri, 8 Jun 2012 13:19:37 +0000 (15:19 +0200)
committerjbrv <jean-baptiste.herve@esial.net>
Fri, 8 Jun 2012 13:19:37 +0000 (15:19 +0200)
renamed function : tmgr_trace_new() to tmgr_trace_new_from_file()

include/simgrid/platf.h
src/surf/cpu_ti.c
src/surf/surf_routing.c
src/surf/surfxml_parse.c
src/surf/surfxml_parseplatf.c
src/surf/trace_mgr.c
src/surf/trace_mgr_private.h
testsuite/surf/trace_usage.c

index fb46ea8..ecbef2d 100644 (file)
@@ -19,7 +19,7 @@ XBT_PUBLIC(sg_routing_edge_t) sg_routing_edge_by_name_or_null(const char *name);
 
 
 typedef struct tmgr_trace *tmgr_trace_t; /**< Opaque structure defining an availability trace */
-XBT_PUBLIC(tmgr_trace_t) tmgr_trace_new(const char *filename);
+XBT_PUBLIC(tmgr_trace_t) tmgr_trace_new_from_file(const char *filename);
 XBT_PUBLIC(tmgr_trace_t) tmgr_trace_new_from_string(const char *id,
                                                     const char *input,
                                                     double periodicity);
index b1c3d1d..34a301c 100644 (file)
@@ -73,12 +73,12 @@ static surf_cpu_ti_trace_t surf_cpu_ti_trace_new(tmgr_trace_t power_trace)
   trace = xbt_new0(s_surf_cpu_ti_trace_t, 1);
   trace->time_points =
       xbt_malloc0(sizeof(double) *
-                  (xbt_dynar_length(power_trace->event_list) + 1));
+                  (xbt_dynar_length(power_trace->s_list.event_list) + 1));
   trace->integral =
       xbt_malloc0(sizeof(double) *
-                  (xbt_dynar_length(power_trace->event_list) + 1));
-  trace->nb_points = xbt_dynar_length(power_trace->event_list);
-  xbt_dynar_foreach(power_trace->event_list, cpt, val) {
+                  (xbt_dynar_length(power_trace->s_list.event_list) + 1));
+  trace->nb_points = xbt_dynar_length(power_trace->s_list.event_list);
+  xbt_dynar_foreach(power_trace->s_list.event_list, cpt, val) {
     trace->time_points[i] = time;
     trace->integral[i] = integral;
     integral += val.delta * val.value;
@@ -116,8 +116,8 @@ static surf_cpu_ti_tgmr_t cpu_ti_parse_trace(tmgr_trace_t power_trace,
   }
 
   /* only one point available, fixed trace */
-  if (xbt_dynar_length(power_trace->event_list) == 1) {
-    xbt_dynar_get_cpy(power_trace->event_list, 0, &val);
+  if (xbt_dynar_length(power_trace->s_list.event_list) == 1) {
+    xbt_dynar_get_cpy(power_trace->s_list.event_list, 0, &val);
     trace->type = TRACE_FIXED;
     trace->value = val.value;
     return trace;
@@ -127,7 +127,7 @@ static surf_cpu_ti_tgmr_t cpu_ti_parse_trace(tmgr_trace_t power_trace,
   trace->power_trace = power_trace;
 
   /* count the total time of trace file */
-  xbt_dynar_foreach(power_trace->event_list, cpt, val) {
+  xbt_dynar_foreach(power_trace->s_list.event_list, cpt, val) {
     total_time += val.delta;
   }
   trace->trace = surf_cpu_ti_trace_new(power_trace);
@@ -172,10 +172,10 @@ static void* cpu_ti_create_resource(const char *name, double power_peak,
   if (state_trace)
     cpu->state_event =
         tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu);
-  if (power_trace && xbt_dynar_length(power_trace->event_list) > 1) {
+  if (power_trace && xbt_dynar_length(power_trace->s_list.event_list) > 1) {
     /* add a fake trace event if periodicity == 0 */
-    xbt_dynar_get_cpy(power_trace->event_list,
-                      xbt_dynar_length(power_trace->event_list) - 1, &val);
+    xbt_dynar_get_cpy(power_trace->s_list.event_list,
+                      xbt_dynar_length(power_trace->s_list.event_list) - 1, &val);
     if (val.delta == 0) {
       empty_trace = tmgr_empty_trace_new();
       cpu->power_event =
@@ -244,10 +244,10 @@ static void add_traces_cpu_ti(void)
     cpu->avail_trace = cpu_ti_parse_trace(trace, cpu->power_scale);
 
     /* add a fake trace event if periodicity == 0 */
-    if (trace && xbt_dynar_length(trace->event_list) > 1) {
+    if (trace && xbt_dynar_length(trace->s_list.event_list) > 1) {
       s_tmgr_event_t val;
-      xbt_dynar_get_cpy(trace->event_list,
-                        xbt_dynar_length(trace->event_list) - 1, &val);
+      xbt_dynar_get_cpy(trace->s_list.event_list,
+                        xbt_dynar_length(trace->s_list.event_list) - 1, &val);
       if (val.delta == 0) {
         tmgr_trace_t empty_trace;
         empty_trace = tmgr_empty_trace_new();
@@ -506,8 +506,8 @@ static void cpu_ti_update_resource_state(void *id,
     xbt_swag_insert(cpu, cpu_ti_modified_cpu);
 
     power_trace = cpu->avail_trace->power_trace;
-    xbt_dynar_get_cpy(power_trace->event_list,
-                      xbt_dynar_length(power_trace->event_list) - 1, &val);
+    xbt_dynar_get_cpy(power_trace->s_list.event_list,
+                      xbt_dynar_length(power_trace->s_list.event_list) - 1, &val);
     /* free old trace */
     surf_cpu_ti_free_tmgr(cpu->avail_trace);
     cpu->power_scale = val.value;
@@ -714,7 +714,7 @@ static double surf_cpu_ti_get_power_scale(surf_cpu_ti_tgmr_t trace,
   point =
       surf_cpu_ti_binary_search(trace->trace->time_points, reduced_a, 0,
                                 trace->trace->nb_points - 1);
-  xbt_dynar_get_cpy(trace->power_trace->event_list, point, &val);
+  xbt_dynar_get_cpy(trace->power_trace->s_list.event_list, point, &val);
   return val.value;
 }
 
index 5b730ed..aacc229 100644 (file)
@@ -803,7 +803,7 @@ static void routing_parse_cluster(sg_platf_cluster_cbarg_t cluster)
         xbt_dict_set(patterns, "radical", bprintf("%d", i), NULL);
         char *avail_file = xbt_str_varsubst(cluster->availability_trace, patterns);
         XBT_DEBUG("\tavailability_file=\"%s\"", avail_file);
-        host.power_trace = tmgr_trace_new(avail_file);
+        host.power_trace = tmgr_trace_new_from_file(avail_file);
         xbt_free(avail_file);
       } else {
         XBT_DEBUG("\tavailability_file=\"\"");
@@ -812,7 +812,7 @@ static void routing_parse_cluster(sg_platf_cluster_cbarg_t cluster)
       if (strcmp(cluster->state_trace, "")) {
         char *avail_file = xbt_str_varsubst(cluster->state_trace, patterns);
         XBT_DEBUG("\tstate_file=\"%s\"", avail_file);
-        host.state_trace = tmgr_trace_new(avail_file);
+        host.state_trace = tmgr_trace_new_from_file(avail_file);
         xbt_free(avail_file);
       } else {
         XBT_DEBUG("\tstate_file=\"\"");
index 312fdd9..ac5d93b 100644 (file)
@@ -389,8 +389,8 @@ void ETag_surfxml_host(void)    {
   host.power_peak = get_cpu_power(A_surfxml_host_power);
   host.power_scale = surf_parse_get_double( A_surfxml_host_availability);
   host.core_amount = surf_parse_get_int(A_surfxml_host_core);
-  host.power_trace = tmgr_trace_new(A_surfxml_host_availability_file);
-  host.state_trace = tmgr_trace_new(A_surfxml_host_state_file);
+  host.power_trace = tmgr_trace_new_from_file(A_surfxml_host_availability_file);
+  host.state_trace = tmgr_trace_new_from_file(A_surfxml_host_state_file);
   xbt_assert((A_surfxml_host_state == A_surfxml_host_state_ON) ||
         (A_surfxml_host_state == A_surfxml_host_state_OFF), "Invalid state");
   if (A_surfxml_host_state == A_surfxml_host_state_ON)
@@ -475,8 +475,8 @@ void STag_surfxml_peer(void){
        peer.bw_out = surf_parse_get_double(A_surfxml_peer_bw_out);
        peer.lat = surf_parse_get_double(A_surfxml_peer_lat);
        peer.coord = A_surfxml_peer_coordinates;
-       peer.availability_trace = tmgr_trace_new(A_surfxml_peer_availability_file);
-       peer.state_trace = tmgr_trace_new(A_surfxml_peer_state_file);
+       peer.availability_trace = tmgr_trace_new_from_file(A_surfxml_peer_availability_file);
+       peer.state_trace = tmgr_trace_new_from_file(A_surfxml_peer_state_file);
 
        surfxml_call_cb_functions(STag_surfxml_peer_cb_list);
        sg_platf_new_peer(&peer);
@@ -495,9 +495,9 @@ void ETag_surfxml_link(void){
 
   link.id = A_surfxml_link_id;
   link.bandwidth = surf_parse_get_double(A_surfxml_link_bandwidth);
-  link.bandwidth_trace = tmgr_trace_new(A_surfxml_link_bandwidth_file);
+  link.bandwidth_trace = tmgr_trace_new_from_file(A_surfxml_link_bandwidth_file);
   link.latency = surf_parse_get_double(A_surfxml_link_latency);
-  link.latency_trace = tmgr_trace_new(A_surfxml_link_latency_file);
+  link.latency_trace = tmgr_trace_new_from_file(A_surfxml_link_latency_file);
 
   switch (A_surfxml_link_state) {
   case A_surfxml_link_state_ON:
@@ -510,7 +510,7 @@ void ETag_surfxml_link(void){
     surf_parse_error("invalid state for link %s", link.id);
     break;
   }
-  link.state_trace = tmgr_trace_new(A_surfxml_link_state_file);
+  link.state_trace = tmgr_trace_new_from_file(A_surfxml_link_state_file);
 
   switch (A_surfxml_link_sharing_policy) {
   case A_surfxml_link_sharing_policy_SHARED:
index 4e5a4a7..9555060 100644 (file)
@@ -75,7 +75,7 @@ static void parse_Etag_trace(void)
 {
   tmgr_trace_t trace;
   if (!trace_file || strcmp(trace_file, "") != 0) {
-    trace = tmgr_trace_new(trace_file);
+    trace = tmgr_trace_new_from_file(trace_file);
   } else if (strcmp(surfxml_pcdata, "") == 0) {
       trace = NULL;
   } else {
index c49bd7c..c42d11d 100644 (file)
@@ -55,7 +55,8 @@ tmgr_trace_t tmgr_trace_new_from_string(const char *id, const char *input,
               "Invalid periodicity %lg (must be positive)", periodicity);
 
   trace = xbt_new0(s_tmgr_trace_t, 1);
-  trace->event_list = xbt_dynar_new(sizeof(s_tmgr_event_t), NULL);
+  trace->type = e_trace_list;
+  trace->s_list.event_list = xbt_dynar_new(sizeof(s_tmgr_event_t), NULL);
 
   list = xbt_str_split(input, "\n\r");
 
@@ -79,10 +80,10 @@ tmgr_trace_t tmgr_trace_new_from_string(const char *id, const char *input,
       }
       last_event->delta = event.delta - last_event->delta;
     }
-    xbt_dynar_push(trace->event_list, &event);
+    xbt_dynar_push(trace->s_list.event_list, &event);
     last_event =
-        xbt_dynar_get_ptr(trace->event_list,
-                          xbt_dynar_length(trace->event_list) - 1);
+        xbt_dynar_get_ptr(trace->s_list.event_list,
+                          xbt_dynar_length(trace->s_list.event_list) - 1);
   }
   if (last_event)
     last_event->delta = periodicity;
@@ -96,7 +97,7 @@ tmgr_trace_t tmgr_trace_new_from_string(const char *id, const char *input,
   return trace;
 }
 
-tmgr_trace_t tmgr_trace_new(const char *filename)
+tmgr_trace_t tmgr_trace_new_from_file(const char *filename)
 {
   char *tstr = NULL;
   FILE *f = NULL;
@@ -131,11 +132,11 @@ tmgr_trace_t tmgr_empty_trace_new(void)
   s_tmgr_event_t event;
 
   trace = xbt_new0(s_tmgr_trace_t, 1);
-  trace->event_list = xbt_dynar_new(sizeof(s_tmgr_event_t), NULL);
+  trace->s_list.event_list = xbt_dynar_new(sizeof(s_tmgr_event_t), NULL);
 
   event.delta = 0.0;
   event.value = 0.0;
-  xbt_dynar_push(trace->event_list, &event);
+  xbt_dynar_push(trace->s_list.event_list, &event);
 
   return trace;
 }
@@ -144,7 +145,7 @@ XBT_INLINE void tmgr_trace_free(tmgr_trace_t trace)
 {
   if (!trace)
     return;
-  xbt_dynar_free(&(trace->event_list));
+  xbt_dynar_free(&(trace->s_list.event_list));
   free(trace);
 }
 
@@ -160,7 +161,7 @@ tmgr_trace_event_t tmgr_history_add_trace(tmgr_history_t h,
   trace_event->idx = offset;
   trace_event->model = model;
 
-  xbt_assert((trace_event->idx < xbt_dynar_length(trace->event_list)),
+  xbt_assert((trace_event->idx < xbt_dynar_length(trace->s_list.event_list)),
               "You're referring to an event that does not exist!");
 
   xbt_heap_push(h->heap, trace_event, start_time);
@@ -193,12 +194,12 @@ tmgr_trace_event_t tmgr_history_get_next_event_leq(tmgr_history_t h,
     return NULL;
 
   trace = trace_event->trace;
-  event = xbt_dynar_get_ptr(trace->event_list, trace_event->idx);
+  event = xbt_dynar_get_ptr(trace->s_list.event_list, trace_event->idx);
 
   *value = event->value;
   *model = trace_event->model;
 
-  if (trace_event->idx < xbt_dynar_length(trace->event_list) - 1) {
+  if (trace_event->idx < xbt_dynar_length(trace->s_list.event_list) - 1) {
     xbt_heap_push(h->heap, trace_event, event_date + event->delta);
     trace_event->idx++;
   } else if (event->delta > 0) {        /* Last element, checking for periodicity */
index 5f72a84..dd5e09e 100644 (file)
@@ -16,10 +16,37 @@ typedef struct tmgr_event {
   double value;
 } s_tmgr_event_t, *tmgr_event_t;
 
+enum e_trace_type {
+  e_trace_list, e_trace_uniform, e_trace_exponential, e_trace_weibull
+};
+
 typedef struct tmgr_trace {
-  xbt_dynar_t event_list;
+  enum e_trace_type type;
+  union {
+    struct {
+      xbt_dynar_t event_list;
+    } s_list;
+    struct {
+      double alpha;
+      double beta;
+      s_tmgr_event_t next_event;
+      /* and probably other things */
+    } s_uniform;
+    struct {
+      double lambda;
+      s_tmgr_event_t next_event;
+      /* and probably other things */
+    } s_exponential;
+    struct {
+      double lambda;
+      double k;
+      s_tmgr_event_t next_event;
+      /* and probably other things */
+    } s_weibull;
+  };
 } s_tmgr_trace_t;
 
+
 typedef struct tmgr_trace_event {
   tmgr_trace_t trace;
   unsigned int idx;
index 897fe6c..95514f5 100644 (file)
@@ -23,8 +23,8 @@ void test(void);
 void test(void)
 {
   tmgr_history_t history = tmgr_history_new();
-  tmgr_trace_t trace_A = tmgr_trace_new("trace_A.txt");
-  tmgr_trace_t trace_B = tmgr_trace_new("trace_B.txt");
+  tmgr_trace_t trace_A = tmgr_trace_new_from_file("trace_A.txt");
+  tmgr_trace_t trace_B = tmgr_trace_new_from_file("trace_B.txt");
   double next_event_date = -1.0;
   double value = -1.0;
   char *resource = NULL;