Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix function get_route
[simgrid.git] / src / surf / workstation_KCCFLN05.c
index 7b1a9b3..c91ad04 100644 (file)
@@ -9,7 +9,7 @@
 #include "xbt/dict.h"
 #include "workstation_KCCFLN05_private.h"
 
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(workstation_KCCFLN05, surf,
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_workstation, surf,
                                "Logging specific to the SURF workstation module (KCCFLN05)");
 
 static int nb_workstation = 0;
@@ -17,7 +17,7 @@ static s_route_KCCFLN05_t *routing_table = NULL;
 #define ROUTE(i,j) routing_table[(i)+(j)*nb_workstation]
 static network_link_KCCFLN05_t loopback = NULL;
 
-static xbt_dict_t network_link_set = NULL;
+/*xbt_dict_t network_link_set = NULL;*/
 
 /* convenient function */
 static void __update_cpu_usage(cpu_KCCFLN05_t cpu)
@@ -108,26 +108,25 @@ static int action_free(surf_action_t action)
       lmm_variable_free(maxmin_system,
                        ((surf_action_workstation_KCCFLN05_t) action)->
                        variable);
-
-    if(src) {
+    if(src)
       xbt_dynar_foreach(src->outgoing_communications, cpt, act)
        if (act == action) {
          xbt_dynar_remove_at(src->outgoing_communications, cpt, &act);
-         
          break;
        }    
-      if(!xbt_dynar_length(src->outgoing_communications))
-       __update_cpu_usage(src);
-    }
-    if(dst) {
+
+    if(dst)
       xbt_dynar_foreach(dst->incomming_communications, cpt, act)
        if (act == action) {
          xbt_dynar_remove_at(dst->incomming_communications, cpt, &act);
          break;
        }
-      if(!xbt_dynar_length(dst->incomming_communications))
-       __update_cpu_usage(dst);
-    }
+
+    if(src && (!xbt_dynar_length(src->outgoing_communications)))
+      __update_cpu_usage(src);
+    if(dst && (!xbt_dynar_length(dst->incomming_communications)))
+      __update_cpu_usage(dst);
+
     free(action);
     return 1;
   }
@@ -152,6 +151,7 @@ static void action_recycle(surf_action_t action)
 static void action_suspend(surf_action_t action)
 {
   XBT_IN1("(%p))",action);
+  ((surf_action_workstation_KCCFLN05_t) action)->suspended = 1;
   lmm_update_variable_weight(maxmin_system,
                             ((surf_action_workstation_KCCFLN05_t)
                              action)->variable, 0.0);
@@ -161,17 +161,22 @@ static void action_suspend(surf_action_t action)
 static void action_resume(surf_action_t action)
 {
   XBT_IN1("(%p)",action);
-  lmm_update_variable_weight(maxmin_system,
-                            ((surf_action_workstation_KCCFLN05_t)
-                             action)->variable, 1.0);
+  if(((surf_action_workstation_KCCFLN05_t)action)->lat_current==0.0)
+    lmm_update_variable_weight(maxmin_system,
+                              ((surf_action_workstation_KCCFLN05_t)
+                               action)->variable, 1.0);
+  else
+    lmm_update_variable_weight(maxmin_system,
+                              ((surf_action_workstation_KCCFLN05_t) action)->variable, 
+                              ((surf_action_workstation_KCCFLN05_t) action)->lat_current);
+
+  ((surf_action_workstation_KCCFLN05_t) action)->suspended = 0;
   XBT_OUT;
 }
 
 static int action_is_suspended(surf_action_t action)
 {
-  return (lmm_get_variable_weight
-         (((surf_action_workstation_KCCFLN05_t) action)->variable) ==
-         0.0);
+  return (((surf_action_workstation_KCCFLN05_t) action)->suspended);
 }
 
 static void action_set_max_duration(surf_action_t action, double duration)
@@ -252,8 +257,13 @@ static void update_actions_state(double now, double delta)
        surf_double_update(&(deltap), action->latency);
        action->latency = 0.0;
       }
-      if ((action->latency == 0.0) && !(action->suspended))
-       lmm_update_variable_weight(maxmin_system, action->variable, 1.0);
+      if ((action->latency == 0.0) && !(action->suspended)) {
+       if((action)->lat_current==0.0)
+         lmm_update_variable_weight(maxmin_system,action->variable, 1.0);
+       else
+         lmm_update_variable_weight(maxmin_system, action->variable, 
+                                    action->lat_current);
+      }
     }
     surf_double_update(&(action->generic_action.remains),
                       lmm_variable_getvalue(action->variable) * deltap);
@@ -324,6 +334,9 @@ static void update_resource_state(void *id,
        else 
          lmm_update_variable_bound(maxmin_system, action->variable,
                                    min(action->rate,SG_TCP_CTE_GAMMA / (2.0 * action->lat_current)));
+       if(!(action->suspended))
+         lmm_update_variable_weight(maxmin_system, action->variable, 
+                                    action->lat_current);
       }
     } else if (event_type == nw_link->state_event) {
       if (value > 0)
@@ -411,6 +424,7 @@ static surf_action_t execute(void *cpu, double size)
   action->generic_action.finish = -1.0;
   action->generic_action.resource_type =
       (surf_resource_t) surf_workstation_resource;
+  action->suspended = 0;
 
   if (CPU->state_current == SURF_CPU_ON)
     action->generic_action.state_set =
@@ -452,6 +466,11 @@ static double get_speed(void *cpu, double load)
   return load*(((cpu_KCCFLN05_t) cpu)->power_scale);
 }
 
+static double get_available_speed(void *cpu)
+{
+  return ((cpu_KCCFLN05_t) cpu)->power_current;
+}
+
 static surf_action_t communicate(void *src, void *dst, double size, double rate)
 {
   surf_action_workstation_KCCFLN05_t action = NULL;
@@ -541,6 +560,19 @@ static surf_action_t execute_parallel_task(int cpu_nb,
   return NULL;
 }
 
+/* returns a NULL-terminated array of network_link_KCCFLN05_t */
+static const void** get_route(void *src, void *dst) {
+  cpu_KCCFLN05_t card_src = src;
+  cpu_KCCFLN05_t card_dst = dst;
+  route_KCCFLN05_t route = &(ROUTE(card_src->id, card_dst->id));
+  int route_size = route->size;
+
+  /* add NULL at the end of the array if not present */
+  route->links = xbt_realloc(route->links, (route_size+1) * sizeof(route_KCCFLN05_t));
+  route->links[route_size] = NULL;
+
+  return (const void**) route->links;
+}
 
 /**************************************/
 /*** Resource Creation & Destruction **/
@@ -887,8 +919,11 @@ static void resource_init_internal(void)
   surf_workstation_resource->extension_public->execute = execute;
   surf_workstation_resource->extension_public->sleep = action_sleep;
   surf_workstation_resource->extension_public->get_state = resource_get_state;
+  surf_workstation_resource->extension_public->get_speed = get_speed;
+  surf_workstation_resource->extension_public->get_available_speed = get_available_speed;
   surf_workstation_resource->extension_public->communicate = communicate;
   surf_workstation_resource->extension_public->execute_parallel_task = execute_parallel_task;
+  surf_workstation_resource->extension_public->get_route = get_route;
 
   workstation_set = xbt_dict_new();
   network_link_set = xbt_dict_new();