Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
A meta-resource : workstation is simply a CPU and a network card.
authoralegrand <alegrand@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Fri, 10 Dec 2004 04:35:15 +0000 (04:35 +0000)
committeralegrand <alegrand@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Fri, 10 Dec 2004 04:35:15 +0000 (04:35 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@585 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/include/surf/surf.h
src/surf/cpu.c
src/surf/cpu_private.h
src/surf/network.c
src/surf/network_private.h
src/surf/surf_private.h
src/surf/workstation.c
src/surf/workstation_private.h
testsuite/surf/surf_usage2.c [new file with mode: 0644]

index e05156a..66e7041 100644 (file)
@@ -9,6 +9,7 @@
 #define _SURF_SURF_H
 
 #include "xbt/swag.h"
+#include "xbt/dynar.h"
 
 /* Actions and resources are higly connected structures... */
 typedef struct surf_action *surf_action_t;
@@ -38,8 +39,8 @@ typedef struct surf_action {
   s_xbt_swag_hookup_t state_hookup;
   xbt_swag_t state_set;
   xbt_maxmin_float_t cost;     /* cost        */
-  xbt_maxmin_float_t max_duration;/* max_duration (may fluctuate until
-                                    the task is completed) */
+  xbt_maxmin_float_t max_duration;     /* max_duration (may fluctuate until
+                                          the task is completed) */
   xbt_maxmin_float_t remains;  /* How much of that cost remains to
                                 * be done in the currently running task */
   xbt_heap_float_t start;      /* start time  */
@@ -65,6 +66,7 @@ typedef struct surf_resource_public {
   void (*action_recycle) (surf_action_t action);
   void (*action_change_state) (surf_action_t action,
                               e_surf_action_state_t state);
+  const char *name;
 } s_surf_resource_public_t, *surf_resource_public_t;
 
 typedef struct surf_resource {
@@ -86,13 +88,13 @@ typedef enum {
 } e_surf_cpu_state_t;
 
 typedef struct surf_cpu_resource_extension_private
-    *surf_cpu_resource_extension_private_t;
+*surf_cpu_resource_extension_private_t;
 typedef struct surf_cpu_resource_extension_public {
   surf_action_t(*execute) (void *cpu, xbt_maxmin_float_t size);
   surf_action_t(*sleep) (void *cpu, xbt_maxmin_float_t duration);
   void (*suspend) (surf_action_t action);
   void (*resume) (surf_action_t action);
-  e_surf_cpu_state_t(*get_state) (void *cpu);
+   e_surf_cpu_state_t(*get_state) (void *cpu);
 } s_surf_cpu_resource_extension_public_t,
     *surf_cpu_resource_extension_public_t;
 
@@ -106,7 +108,7 @@ void surf_cpu_resource_init(const char *filename);
 
 /* Network resource */
 typedef struct surf_network_resource_extension_private
-    *surf_network_resource_extension_private_t;
+*surf_network_resource_extension_private_t;
 typedef struct surf_network_resource_extension_public {
   surf_action_t(*communicate) (void *src, void *dst,
                               xbt_maxmin_float_t size);
@@ -124,14 +126,16 @@ void surf_network_resource_init(const char *filename);
 
 /* Workstation resource */
 typedef struct surf_workstation_resource_extension_private
-    *surf_workstation_resource_extension_private_t;
+*surf_workstation_resource_extension_private_t;
 typedef struct surf_workstation_resource_extension_public {
   surf_action_t(*execute) (void *workstation, xbt_maxmin_float_t size);
   surf_action_t(*sleep) (void *workstation, xbt_maxmin_float_t duration);
-  e_surf_cpu_state_t(*get_state) (void *workstation);
-  surf_action_t(*communicate) (void *workstation_src,
-                              void *workstation_dst,
-                              xbt_maxmin_float_t size);
+  void (*suspend) (surf_action_t action);
+  void (*resume) (surf_action_t action);
+   e_surf_cpu_state_t(*get_state) (void *workstation);
+   surf_action_t(*communicate) (void *workstation_src,
+                               void *workstation_dst,
+                               xbt_maxmin_float_t size);
 } s_surf_workstation_resource_extension_public_t,
     *surf_workstation_resource_extension_public_t;
 
@@ -149,6 +153,9 @@ void surf_workstation_resource_init(const char *filename);
 /*******************************************/
 
 void surf_init(int *argc, char **argv);        /* initialize common structures */
+
+extern xbt_dynar_t resource_list;      /* list of initialized resources */
+
 xbt_heap_float_t surf_solve(void);     /*  update all states and returns
                                           the time elapsed since last
                                           event */
index 3f40e53..768df15 100644 (file)
@@ -6,14 +6,13 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "cpu_private.h"
-#include "xbt/dict.h"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(cpu, surf,
                                "Logging specific to the SURF CPU module");
 
 surf_cpu_resource_t surf_cpu_resource = NULL;
 
-static xbt_dict_t cpu_set = NULL;
+xbt_dict_t cpu_set = NULL;
 
 static void cpu_free(void *CPU)
 {
@@ -180,8 +179,9 @@ static void action_change_state(surf_action_t action,
 static xbt_heap_float_t share_resources(xbt_heap_float_t now)
 {
   s_surf_action_cpu_t action;
-  return generic_maxmin_share_resources(surf_cpu_resource->common_public->states.running_action_set,
-                                       xbt_swag_offset(action,variable));
+  return generic_maxmin_share_resources(surf_cpu_resource->common_public->
+                                       states.running_action_set,
+                                       xbt_swag_offset(action, variable));
 }
 
 static void update_actions_state(xbt_heap_float_t now,
@@ -197,16 +197,16 @@ static void update_actions_state(xbt_heap_float_t now,
   xbt_swag_foreach_safe(action, next_action, running_actions) {
     action->generic_action.remains -=
        lmm_variable_getvalue(action->variable) * delta;
-    if(action->generic_action.max_duration!=NO_MAX_DURATION)
+    if (action->generic_action.max_duration != NO_MAX_DURATION)
       action->generic_action.max_duration -= delta;
 /*     if(action->generic_action.remains<.00001) action->generic_action.remains=0; */
     if (action->generic_action.remains <= 0) {
       action->generic_action.finish = surf_get_clock();
       action_change_state((surf_action_t) action, SURF_ACTION_DONE);
-    } else if((action->generic_action.max_duration!=NO_MAX_DURATION) && 
-             (action->generic_action.max_duration<=0)) {
+    } else if ((action->generic_action.max_duration != NO_MAX_DURATION) &&
+              (action->generic_action.max_duration <= 0)) {
       action->generic_action.finish = surf_get_clock();
-      action_change_state((surf_action_t) action, SURF_ACTION_DONE);    
+      action_change_state((surf_action_t) action, SURF_ACTION_DONE);
     } else {                   /* Need to check that none of the resource has failed */
       lmm_constraint_t cnst = NULL;
       int i = 0;
@@ -244,7 +244,7 @@ static void update_resource_state(void *id,
 
   if (event_type == cpu->power_event) {
     cpu->power_current = value;
-    lmm_update_constraint_bound(maxmin_system,cpu->constraint,
+    lmm_update_constraint_bound(maxmin_system, cpu->constraint,
                                cpu->power_current * cpu->power_scale);
   } else if (event_type == cpu->state_event) {
     if (value > 0)
@@ -304,12 +304,14 @@ static surf_action_t action_sleep(void *cpu, xbt_maxmin_float_t duration)
 
 static void action_suspend(surf_action_t action)
 {
-  lmm_update_variable_weight(maxmin_system, ((surf_action_cpu_t) action)->variable, 0.0);
+  lmm_update_variable_weight(maxmin_system,
+                            ((surf_action_cpu_t) action)->variable, 0.0);
 }
 
 static void action_resume(surf_action_t action)
 {
-  lmm_update_variable_weight(maxmin_system, ((surf_action_cpu_t) action)->variable, 1.0);
+  lmm_update_variable_weight(maxmin_system,
+                            ((surf_action_cpu_t) action)->variable, 1.0);
 }
 
 static e_surf_cpu_state_t get_state(void *cpu)
@@ -365,6 +367,7 @@ static void surf_cpu_resource_init_internal(void)
   surf_cpu_resource->common_public->action_recycle = action_recycle;
   surf_cpu_resource->common_public->action_change_state =
       action_change_state;
+  surf_cpu_resource->common_public->name = "CPU";
 
   surf_cpu_resource->common_private->resource_used = resource_used;
   surf_cpu_resource->common_private->share_resources = share_resources;
@@ -388,6 +391,8 @@ static void surf_cpu_resource_init_internal(void)
 
 void surf_cpu_resource_init(const char *filename)
 {
+  if (surf_cpu_resource)
+    return;
   surf_cpu_resource_init_internal();
   parse_file(filename);
   xbt_dynar_push(resource_list, &surf_cpu_resource);
index 8424994..506cdcb 100644 (file)
@@ -9,6 +9,7 @@
 #define _SURF_CPU_PRIVATE_H
 
 #include "surf_private.h"
+#include "xbt/dict.h"
 
 typedef struct surf_action_cpu {
   s_surf_action_t generic_action;
@@ -27,4 +28,6 @@ typedef struct cpu {
   lmm_constraint_t constraint;
 } s_cpu_t, *cpu_t;
 
+extern xbt_dict_t cpu_set;
+
 #endif                         /* _SURF_CPU_PRIVATE_H */
index e8d236d..fec83e5 100644 (file)
@@ -6,7 +6,6 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "network_private.h"
-#include "xbt/dict.h"
 
 #define SG_TCP_CTE_GAMMA 20000.0
 
@@ -16,7 +15,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(network, surf,
 surf_network_resource_t surf_network_resource = NULL;
 
 static xbt_dict_t network_link_set = NULL;
-static xbt_dict_t network_card_set = NULL;
+xbt_dict_t network_card_set = NULL;
 
 static int card_number = 0;
 static network_link_t **routing_table = NULL;
@@ -27,8 +26,8 @@ static int *routing_table_size = NULL;
 
 static void create_routing_table(void)
 {
-  routing_table = xbt_new0(network_link_t *,card_number*card_number);
-  routing_table_size = xbt_new0(int,card_number*card_number);
+  routing_table = xbt_new0(network_link_t *, card_number * card_number);
+  routing_table_size = xbt_new0(int, card_number * card_number);
 }
 
 static void network_link_free(void *nw_link)
@@ -41,12 +40,13 @@ static network_link_t network_link_new(const char *name,
                                       tmgr_trace_t bw_trace,
                                       xbt_maxmin_float_t lat_initial,
                                       tmgr_trace_t lat_trace,
-                                      e_surf_network_link_state_t state_initial,
+                                      e_surf_network_link_state_t
+                                      state_initial,
                                       tmgr_trace_t state_trace)
 {
   network_link_t nw_link = xbt_new0(s_network_link_t, 1);
 
-  
+
   nw_link->resource = (surf_resource_t) surf_network_resource;
   nw_link->name = name;
   nw_link->bw_current = bw_initial;
@@ -63,8 +63,7 @@ static network_link_t network_link_new(const char *name,
        tmgr_history_add_trace(history, state_trace, 0.0, 0, nw_link);
 
   nw_link->constraint =
-      lmm_constraint_new(maxmin_system, nw_link,
-                        nw_link->bw_current);
+      lmm_constraint_new(maxmin_system, nw_link, nw_link->bw_current);
 
   xbt_dict_set(network_link_set, name, nw_link, network_link_free);
 
@@ -77,28 +76,27 @@ static int network_card_new(const char *card_name)
 
   xbt_dict_get(network_card_set, card_name, (void *) &card);
 
-  if(!card) {
-    card = xbt_new0(s_network_card_t,1);
-    card->name=xbt_strdup(card_name);
-    card->id=card_number++;
+  if (!card) {
+    card = xbt_new0(s_network_card_t, 1);
+    card->name = xbt_strdup(card_name);
+    card->id = card_number++;
     xbt_dict_set(network_card_set, card_name, card, NULL);
-  } 
+  }
   return card->id;
 }
 
-static void route_new(int src_id, int dst_id,
-                     char* *links, int nb_link)
+static void route_new(int src_id, int dst_id, char **links, int nb_link)
 {
   network_link_t *link_list = NULL;
-  int i ; 
+  int i;
 
-  ROUTE_SIZE(src_id,dst_id) = nb_link;
-  link_list = (ROUTE(src_id,dst_id) = xbt_new0(network_link_t,nb_link));
-  for(i=0; i < nb_link; i++) {
-    xbt_dict_get(network_link_set,links[i], (void *) &(link_list[i]));
+  ROUTE_SIZE(src_id, dst_id) = nb_link;
+  link_list = (ROUTE(src_id, dst_id) = xbt_new0(network_link_t, nb_link));
+  for (i = 0; i < nb_link; i++) {
+    xbt_dict_get(network_link_set, links[i], (void *) &(link_list[i]));
     xbt_free(links[i]);
   }
-  xbt_free(links);  
+  xbt_free(links);
 }
 
 /*  
@@ -140,9 +138,8 @@ static void parse_network_link(void)
 
   surf_parse_trace(&state_trace);
 
-  network_link_new(name, bw_initial, bw_trace, 
-                  lat_initial, lat_trace,
-                  state_initial, state_trace);  
+  network_link_new(name, bw_initial, bw_trace,
+                  lat_initial, lat_trace, state_initial, state_trace);
 }
 
 /*  
@@ -163,22 +160,23 @@ static void parse_route(int fake)
   src_id = network_card_new(surf_parse_text);
 
   token = surf_parse();
-  xbt_assert1((token == TOKEN_WORD), "Parse error line %d", line_pos);  
+  xbt_assert1((token == TOKEN_WORD), "Parse error line %d", line_pos);
   dst_id = network_card_new(surf_parse_text);
 
   token = surf_parse();
-  xbt_assert1((token == TOKEN_LP), "Parse error line %d", line_pos);  
-  
-  while((token = surf_parse())==TOKEN_WORD) {
-    if(!fake) {
+  xbt_assert1((token == TOKEN_LP), "Parse error line %d", line_pos);
+
+  while ((token = surf_parse()) == TOKEN_WORD) {
+    if (!fake) {
       nb_link++;
-      link_name=xbt_realloc(link_name, (nb_link) * sizeof(char*));
-      link_name[(nb_link)-1]=xbt_strdup(surf_parse_text);
+      link_name = xbt_realloc(link_name, (nb_link) * sizeof(char *));
+      link_name[(nb_link) - 1] = xbt_strdup(surf_parse_text);
     }
   }
-  xbt_assert1((token == TOKEN_RP), "Parse error line %d", line_pos);  
+  xbt_assert1((token == TOKEN_RP), "Parse error line %d", line_pos);
 
-  if(!fake) route_new(src_id,dst_id,link_name, nb_link);
+  if (!fake)
+    route_new(src_id, dst_id, link_name, nb_link);
 }
 
 static void parse_file(const char *file)
@@ -296,8 +294,10 @@ static void action_change_state(surf_action_t action,
 static xbt_heap_float_t share_resources(xbt_heap_float_t now)
 {
   s_surf_action_network_t action;
-  return generic_maxmin_share_resources(surf_network_resource->common_public->states.running_action_set,
-                                       xbt_swag_offset(action,variable));
+  return generic_maxmin_share_resources(surf_network_resource->
+                                       common_public->states.
+                                       running_action_set,
+                                       xbt_swag_offset(action, variable));
 }
 
 
@@ -314,9 +314,9 @@ static void update_actions_state(xbt_heap_float_t now,
 
   xbt_swag_foreach_safe(action, next_action, running_actions) {
     deltap = delta;
-    if(action->latency>0) {
-      if(action->latency>deltap) {
-       action->latency-=deltap;
+    if (action->latency > 0) {
+      if (action->latency > deltap) {
+       action->latency -= deltap;
        deltap = 0.0;
       } else {
        deltap -= action->latency;
@@ -324,8 +324,8 @@ static void update_actions_state(xbt_heap_float_t now,
       }
     }
     action->generic_action.remains -=
-      lmm_variable_getvalue(action->variable) * deltap;
-    if(action->generic_action.max_duration!=NO_MAX_DURATION)
+       lmm_variable_getvalue(action->variable) * deltap;
+    if (action->generic_action.max_duration != NO_MAX_DURATION)
       action->generic_action.max_duration -= delta;
 
 /*     if(action->generic_action.remains<.00001) action->generic_action.remains=0; */
@@ -333,10 +333,10 @@ static void update_actions_state(xbt_heap_float_t now,
     if (action->generic_action.remains <= 0) {
       action->generic_action.finish = surf_get_clock();
       action_change_state((surf_action_t) action, SURF_ACTION_DONE);
-    } else if((action->generic_action.max_duration!=NO_MAX_DURATION) && 
-             (action->generic_action.max_duration<=0)) {
+    } else if ((action->generic_action.max_duration != NO_MAX_DURATION) &&
+              (action->generic_action.max_duration <= 0)) {
       action->generic_action.finish = surf_get_clock();
-      action_change_state((surf_action_t) action, SURF_ACTION_DONE);    
+      action_change_state((surf_action_t) action, SURF_ACTION_DONE);
     } else {                   /* Need to check that none of the resource has failed */
       lmm_constraint_t cnst = NULL;
       int i = 0;
@@ -382,11 +382,11 @@ static void update_resource_state(void *id,
     surf_action_network_t action = NULL;
 
     nw_link->lat_current = value;
-    while(lmm_get_var_from_cnst(maxmin_system, nw_link->constraint, &var)) {
-      action  = lmm_variable_id(var);
-      action->lat_current+=delta;
-      lmm_update_variable_bound(maxmin_system, var, 
-                               1/(action->lat_current));
+    while (lmm_get_var_from_cnst(maxmin_system, nw_link->constraint, &var)) {
+      action = lmm_variable_id(var);
+      action->lat_current += delta;
+      lmm_update_variable_bound(maxmin_system, var,
+                               1 / (action->lat_current));
     }
   } else if (event_type == nw_link->state_event) {
     if (value > 0)
@@ -407,8 +407,8 @@ static surf_action_t communicate(void *src, void *dst,
   surf_action_network_t action = NULL;
   network_card_t card_src = src;
   network_card_t card_dst = dst;
-  int route_size = ROUTE_SIZE(card_src->id,card_dst->id);
-  network_link_t *route = ROUTE(card_src->id,card_dst->id);
+  int route_size = ROUTE_SIZE(card_src->id, card_dst->id);
+  network_link_t *route = ROUTE(card_src->id, card_dst->id);
   int i;
 
   action = xbt_new0(s_surf_action_network_t, 1);
@@ -423,22 +423,21 @@ static surf_action_t communicate(void *src, void *dst,
       (surf_resource_t) surf_network_resource;
 
   action->generic_action.state_set =
-    surf_network_resource->common_public->states.running_action_set;
+      surf_network_resource->common_public->states.running_action_set;
 
   xbt_swag_insert(action, action->generic_action.state_set);
 
-  action->variable = lmm_variable_new(maxmin_system, action, 1.0, -1.0, 
+  action->variable = lmm_variable_new(maxmin_system, action, 1.0, -1.0,
                                      route_size);
-  for(i=0; i<route_size; i++)
-    lmm_expand(maxmin_system, route[i]->constraint, action->variable,
-              1.0);
+  for (i = 0; i < route_size; i++)
+    lmm_expand(maxmin_system, route[i]->constraint, action->variable, 1.0);
 
   action->latency = 0.0;
-  for(i=0; i<route_size; i++)
+  for (i = 0; i < route_size; i++)
     action->latency += route[i]->lat_current;
   action->lat_current = action->latency;
-  lmm_update_variable_bound(maxmin_system, action->variable, 
-                           SG_TCP_CTE_GAMMA/action->lat_current);
+  lmm_update_variable_bound(maxmin_system, action->variable,
+                           SG_TCP_CTE_GAMMA / action->lat_current);
 
   return (surf_action_t) action;
 }
@@ -447,12 +446,14 @@ static void finalize(void)
 {
   xbt_dict_free(&network_card_set);
   xbt_dict_free(&network_link_set);
-  xbt_swag_free(surf_network_resource->common_public->states.ready_action_set);
+  xbt_swag_free(surf_network_resource->common_public->states.
+               ready_action_set);
   xbt_swag_free(surf_network_resource->common_public->states.
                running_action_set);
   xbt_swag_free(surf_network_resource->common_public->states.
                failed_action_set);
-  xbt_swag_free(surf_network_resource->common_public->states.done_action_set);
+  xbt_swag_free(surf_network_resource->common_public->states.
+               done_action_set);
   xbt_free(surf_network_resource->common_public);
   xbt_free(surf_network_resource->common_private);
   xbt_free(surf_network_resource->extension_public);
@@ -494,6 +495,7 @@ static void surf_network_resource_init_internal(void)
   surf_network_resource->common_public->action_recycle = action_recycle;
   surf_network_resource->common_public->action_change_state =
       action_change_state;
+  surf_network_resource->common_public->name = "network";
 
   surf_network_resource->common_private->resource_used = resource_used;
   surf_network_resource->common_private->share_resources = share_resources;
@@ -513,6 +515,8 @@ static void surf_network_resource_init_internal(void)
 
 void surf_network_resource_init(const char *filename)
 {
+  if (surf_network_resource)
+    return;
   surf_network_resource_init_internal();
   parse_file(filename);
   xbt_dynar_push(resource_list, &surf_network_resource);
index 0032cd5..963f932 100644 (file)
@@ -9,6 +9,7 @@
 #define _SURF_NETWORK_PRIVATE_H
 
 #include "surf_private.h"
+#include "xbt/dict.h"
 
 typedef enum {
   SURF_NETWORK_LINK_ON = 1,            /* Ready        */
@@ -45,4 +46,6 @@ typedef struct surf_action_network {
   network_card_t dst;
 } s_surf_action_network_t, *surf_action_network_t;
 
+extern xbt_dict_t network_card_set;
+
 #endif                         /* _SURF_NETWORK_PRIVATE_H */
index 23ac7ca..3fbf995 100644 (file)
@@ -37,7 +37,6 @@ e_surf_action_state_t surf_action_get_state(surf_action_t action);
 void surf_action_free(surf_action_t * action);
 void surf_action_change_state(surf_action_t action, e_surf_action_state_t state);
 
-extern xbt_dynar_t resource_list;
 extern lmm_system_t maxmin_system;
 extern tmgr_history_t history;
 
index d153297..8543366 100644 (file)
@@ -7,8 +7,8 @@
 
 #include "xbt/dict.h"
 #include "workstation_private.h"
-/* #include "cpu_private.h" */
-/* #include "network_private.h" */
+#include "cpu_private.h"
+#include "network_private.h"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(workstation, surf,
                                "Logging specific to the SURF workstation module");
@@ -17,23 +17,53 @@ surf_workstation_resource_t surf_workstation_resource = NULL;
 
 static xbt_dict_t workstation_set = NULL;
 
-static workstation_t workstation_new(const char *name)
+static workstation_t workstation_new(const char *name,
+                                    void *cpu, void *card)
 {
-  return NULL;
+  workstation_t workstation = xbt_new0(s_workstation_t, 1);
+
+  workstation->resource = (surf_resource_t) surf_workstation_resource;
+  workstation->name = xbt_strdup(name);
+  workstation->cpu = cpu;
+  workstation->network_card = card;
+
+  return workstation;
+}
+
+static void create_workstations(void)
+{
+  xbt_dict_cursor_t cursor = NULL;
+  char *name = NULL;
+  void *cpu = NULL;
+  void *nw_card = NULL;
+
+  xbt_dict_foreach(cpu_set, cursor, name, cpu) {
+    nw_card = NULL;
+    xbt_dict_get(network_card_set, name, (void *) &nw_card);
+    xbt_assert0(nw_card, "No corresponding card found");
+    xbt_dict_set(workstation_set, name,
+                workstation_new(name, cpu, nw_card), NULL);
+  }
 }
 
 static void *name_service(const char *name)
 {
-  return NULL;
+  void *workstation = NULL;
+
+  xbt_dict_get(workstation_set, name, &workstation);
+
+  return workstation;
 }
 
 static const char *get_resource_name(void *resource_id)
 {
-  return NULL;
+  return ((workstation_t) resource_id)->name;
 }
 
 static int resource_used(void *resource_id)
 {
+  xbt_assert0(0,
+             "Workstation is a virtual resource. I should not be there!");
   return 0;
 }
 
@@ -78,21 +108,48 @@ static void update_resource_state(void *id,
   return;
 }
 
-static surf_action_t communicate(void *workstation_src, 
-                                void *workstation_dst,
-                                xbt_maxmin_float_t size)
+static surf_action_t execute(void *workstation, xbt_maxmin_float_t size)
 {
-  return NULL;
+  return surf_cpu_resource->extension_public->
+      execute(((workstation_t) workstation)->cpu, size);
 }
 
-static surf_action_t execute(void *workstation, xbt_maxmin_float_t size)
+static surf_action_t action_sleep(void *workstation,
+                                 xbt_maxmin_float_t duration)
+{
+  return surf_cpu_resource->extension_public->
+      sleep(((workstation_t) workstation)->cpu, duration);
+}
+
+static void action_suspend(surf_action_t action)
 {
-  return NULL;
+  xbt_assert0(action->resource_type ==
+             ((surf_resource_t) surf_cpu_resource),
+             "Resource type mismatch");
+  surf_cpu_resource->extension_public->suspend(action);
+}
+
+static void action_resume(surf_action_t action)
+{
+  xbt_assert0(action->resource_type ==
+             ((surf_resource_t) surf_cpu_resource),
+             "Resource type mismatch");
+  surf_cpu_resource->extension_public->resume(action);
+}
+
+static surf_action_t communicate(void *workstation_src,
+                                void *workstation_dst,
+                                xbt_maxmin_float_t size)
+{
+  return surf_network_resource->extension_public->
+      communicate(((workstation_t) workstation_src)->network_card,
+                 ((workstation_t) workstation_dst)->network_card, size);
 }
 
 static e_surf_cpu_state_t get_state(void *workstation)
 {
-  return SURF_CPU_OFF;
+  return surf_cpu_resource->extension_public->
+      get_state(((workstation_t) workstation)->cpu);
 }
 
 static void finalize(void)
@@ -129,20 +186,27 @@ static void surf_workstation_resource_init_internal(void)
       surf_action_get_state;
   surf_workstation_resource->common_public->action_free = action_free;
   surf_workstation_resource->common_public->action_cancel = action_cancel;
-  surf_workstation_resource->common_public->action_recycle = action_recycle;
+  surf_workstation_resource->common_public->action_recycle =
+      action_recycle;
   surf_workstation_resource->common_public->action_change_state =
       action_change_state;
+  surf_workstation_resource->common_public->name = "Workstation";
 
   surf_workstation_resource->common_private->resource_used = resource_used;
-  surf_workstation_resource->common_private->share_resources = share_resources;
+  surf_workstation_resource->common_private->share_resources =
+      share_resources;
   surf_workstation_resource->common_private->update_actions_state =
       update_actions_state;
   surf_workstation_resource->common_private->update_resource_state =
       update_resource_state;
   surf_workstation_resource->common_private->finalize = finalize;
 
-  surf_workstation_resource->extension_public->communicate = communicate;
   surf_workstation_resource->extension_public->execute = execute;
+  surf_workstation_resource->extension_public->sleep = action_sleep;
+  surf_workstation_resource->extension_public->suspend = action_suspend;
+  surf_workstation_resource->extension_public->resume = action_resume;
+  surf_workstation_resource->extension_public->get_state = get_state;
+  surf_workstation_resource->extension_public->communicate = communicate;
 
   workstation_set = xbt_dict_new();
 
@@ -151,7 +215,24 @@ static void surf_workstation_resource_init_internal(void)
 
 void surf_workstation_resource_init(const char *filename)
 {
+/*   int i ; */
+/*   surf_resource_t resource =  NULL; */
+
   surf_workstation_resource_init_internal();
-/*   parse_file(filename); */
+  surf_cpu_resource_init(filename);
+  surf_network_resource_init(filename);
+  create_workstations();
   xbt_dynar_push(resource_list, &surf_workstation_resource);
+/*   xbt_dynar_foreach(resource_list, i, resource) { */
+/*     if(resource==surf_cpu_resource) { */
+/*       xbt_dynar_remove_at(resource_list, i, NULL); */
+/*       i--;  */
+/*       continue; */
+/*     } */
+/*     if(resource==surf_network_resource) { */
+/*       xbt_dynar_remove_at(resource_list, i, NULL); */
+/*       i--;  */
+/*       continue; */
+/*     } */
+/*   } */
 }
index 9bc850b..d3e656f 100644 (file)
 
 #include "surf_private.h"
 
-typedef struct workstation_link {
-  surf_resource_t resource;   /* Any such object, added in a trace
-                                should start by this field!!! */
-                              /* Using this object with the public part of
-                                resource does not make sense */
+typedef struct workstation {
+  surf_resource_t resource;    /* Any such object, added in a trace
+                                  should start by this field!!! */
   const char *name;
   void *cpu;
   void *network_card;
diff --git a/testsuite/surf/surf_usage2.c b/testsuite/surf/surf_usage2.c
new file mode 100644 (file)
index 0000000..d4ca537
--- /dev/null
@@ -0,0 +1,115 @@
+/*     $Id$     */
+
+/* A few basic tests for the surf library                                   */
+
+/* Copyright (c) 2004 Arnaud Legrand. All rights reserved.                  */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include <stdio.h>
+#include "surf/surf.h"
+
+const char *string_action(e_surf_action_state_t state);
+const char *string_action(e_surf_action_state_t state)
+{
+  switch (state) {
+  case (SURF_ACTION_READY):
+    return "SURF_ACTION_READY";
+  case (SURF_ACTION_RUNNING):
+    return "SURF_ACTION_RUNNING";
+  case (SURF_ACTION_FAILED):
+    return "SURF_ACTION_FAILED";
+  case (SURF_ACTION_DONE):
+    return "SURF_ACTION_DONE";
+  case (SURF_ACTION_NOT_IN_THE_SYSTEM):
+    return "SURF_ACTION_NOT_IN_THE_SYSTEM";
+  default:
+    return "INVALID STATE";
+  }
+}
+
+
+void test(void);
+void test(void)
+{
+  void *workstationA = NULL;
+  void *workstationB = NULL;
+  surf_action_t actionA = NULL;
+  surf_action_t actionB = NULL;
+  surf_action_t actionC = NULL;
+  surf_action_t commAB = NULL;
+  e_surf_action_state_t stateActionA;
+  e_surf_action_state_t stateActionB;
+  e_surf_action_state_t stateActionC;
+  xbt_maxmin_float_t now = -1.0;
+
+  surf_workstation_resource_init("platform.txt");
+
+  /*********************** WORKSTATION ***********************************/
+  workstationA =
+      surf_workstation_resource->common_public->name_service("Cpu A");
+  workstationB =
+      surf_workstation_resource->common_public->name_service("Cpu B");
+
+  /* Let's check that those two processors exist */
+  printf("%s : %p\n",
+        surf_workstation_resource->common_public->
+        get_resource_name(workstationA), workstationA);
+  printf("%s : %p\n",
+        surf_workstation_resource->common_public->
+        get_resource_name(workstationB), workstationB);
+
+  /* Let's do something on it */
+  actionA =
+      surf_workstation_resource->extension_public->execute(workstationA,
+                                                          1000.0);
+  actionB =
+      surf_workstation_resource->extension_public->execute(workstationB,
+                                                          1000.0);
+  actionC =
+      surf_workstation_resource->extension_public->sleep(workstationB,
+                                                        7.32);
+
+  commAB =
+      surf_workstation_resource->extension_public->
+      communicate(workstationA, workstationB, 150.0);
+
+  surf_solve();                        /* Takes traces into account. Returns 0.0 */
+  do {
+    surf_action_t action = NULL;
+    int i;
+    surf_resource_t resource = NULL;
+
+    now = surf_get_clock();
+    printf("Next Event : " XBT_HEAP_FLOAT_T "\n", now);
+    
+    xbt_dynar_foreach (resource_list,i,resource) {
+      printf("\t %s actions\n", resource->common_public->name);
+      while (action =
+            xbt_swag_extract(resource->common_public->states.
+                             failed_action_set)) {
+       printf("\t * Failed : %p\n", action);
+       resource->common_public->action_free(action);
+      }
+      while (action =
+            xbt_swag_extract(resource->common_public->states.
+                             done_action_set)) {
+       printf("\t * Done : %p\n", action);
+       resource->common_public->action_free(action);
+      }
+    }
+  } while (surf_solve());
+
+  printf("Simulation Terminated\n");
+
+  surf_finalize();
+}
+
+
+int main(int argc, char **argv)
+{
+  surf_init(&argc, argv);      /* Initialize some common structures */
+  test();
+  return 0;
+}