Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge cpu_update_actions_state_lazy and net_update_actions_state_lazy
authornavarro <navarro@caraja.(none)>
Tue, 22 May 2012 14:29:24 +0000 (16:29 +0200)
committernavarro <navarro@caraja.(none)>
Tue, 22 May 2012 14:29:24 +0000 (16:29 +0200)
src/surf/cpu_cas01.c
src/surf/network.c
src/surf/surf_action.c
src/surf/surf_private.h

index be08fc7..578416f 100644 (file)
@@ -157,51 +157,7 @@ static double cpu_share_resources_full(double now)
 
 static void cpu_update_actions_state_lazy(double now, double delta)
 {
-  surf_action_cpu_Cas01_t action;
-  while ((xbt_heap_size(surf_cpu_model->model_private->action_heap) > 0)
-         && (double_equals(xbt_heap_maxkey(surf_cpu_model->model_private->action_heap), now))) {
-    action = xbt_heap_pop(surf_cpu_model->model_private->action_heap);
-    XBT_DEBUG("Action %p: finish", action);
-    GENERIC_ACTION(action).finish = surf_get_clock();
-#ifdef HAVE_TRACING
-    if (TRACE_is_enabled()) {
-      cpu_Cas01_t cpu =
-          lmm_constraint_id(lmm_get_cnst_from_var
-                            (surf_cpu_model->model_private->maxmin_system,
-                             GENERIC_LMM_ACTION(action).variable, 0));
-      TRACE_surf_host_set_utilization(cpu->generic_resource.name,
-                                      ((surf_action_t)action)->category,
-                                      lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable),
-                                      GENERIC_LMM_ACTION(action).last_update,
-                                      now - GENERIC_LMM_ACTION(action).last_update);
-    }
-#endif
-    /* set the remains to 0 due to precision problems when updating the remaining amount */
-    GENERIC_ACTION(action).remains = 0;
-    surf_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
-    surf_action_lmm_heap_remove(surf_cpu_model->model_private->action_heap,(surf_action_lmm_t)action); //FIXME: strange call since action was already popped
-  }
-#ifdef HAVE_TRACING
-  if (TRACE_is_enabled()) {
-    //defining the last timestamp that we can safely dump to trace file
-    //without losing the event ascending order (considering all CPU's)
-    double smaller = -1;
-    xbt_swag_t running_actions = surf_cpu_model->states.running_action_set;
-    xbt_swag_foreach(action, running_actions) {
-        if (smaller < 0) {
-          smaller = GENERIC_LMM_ACTION(action).last_update;
-          continue;
-        }
-        if (GENERIC_LMM_ACTION(action).last_update < smaller) {
-          smaller = GENERIC_LMM_ACTION(action).last_update;
-        }
-    }
-    if (smaller > 0) {
-      TRACE_last_timestamp_to_dump = smaller;
-    }
-  }
-#endif
-  return;
+  generic_update_actions_state_lazy(now, delta, surf_cpu_model);
 }
 
 static void cpu_update_actions_state_full(double now, double delta)
index 00a3bd2..50524f2 100644 (file)
@@ -428,54 +428,7 @@ static void net_update_actions_state_full(double now, double delta)
 
 static void net_update_actions_state_lazy(double now, double delta)
 {
-  surf_action_network_CM02_t action = NULL;
-
-  while ((xbt_heap_size(surf_network_model->model_private->action_heap) > 0)
-         && (double_equals(xbt_heap_maxkey(surf_network_model->model_private->action_heap), now))) {
-    action = xbt_heap_pop(surf_network_model->model_private->action_heap);
-    XBT_DEBUG("Action %p: finish", action);
-    GENERIC_ACTION(action).finish = surf_get_clock();
-#ifdef HAVE_TRACING
-    if (TRACE_is_enabled()) {
-      int n = lmm_get_number_of_cnst_from_var(surf_network_model->model_private->maxmin_system, GENERIC_LMM_ACTION(action).variable);
-      unsigned int i;
-      for (i = 0; i < n; i++){
-        lmm_constraint_t constraint = lmm_get_cnst_from_var(surf_network_model->model_private->maxmin_system,
-                                                            GENERIC_LMM_ACTION(action).variable,
-                                                            i);
-        link_CM02_t link = lmm_constraint_id(constraint);
-        TRACE_surf_link_set_utilization(link->lmm_resource.generic_resource.name,
-                                        ((surf_action_t)action)->category,
-                                        (lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable)*
-                                            lmm_get_cnst_weight_from_var(surf_network_model->model_private->maxmin_system,
-                                                GENERIC_LMM_ACTION(action).variable,
-                                                i)),
-                                        GENERIC_LMM_ACTION(action).last_update,
-                                        now - GENERIC_LMM_ACTION(action).last_update);
-      }
-    }
-#endif
-
-    // if I am wearing a latency hat
-    if (GENERIC_LMM_ACTION(action).hat == LATENCY) {
-      lmm_update_variable_weight(surf_network_model->model_private->maxmin_system, GENERIC_LMM_ACTION(action).variable,
-                                 action->weight);
-      surf_action_lmm_heap_remove(surf_network_model->model_private->action_heap,(surf_action_lmm_t)action);
-      GENERIC_LMM_ACTION(action).last_update = surf_get_clock();
-
-      // if I am wearing a max_duration or normal hat
-    } else if (GENERIC_LMM_ACTION(action).hat == MAX_DURATION ||
-        GENERIC_LMM_ACTION(action).hat == NORMAL) {
-      // no need to communicate anymore
-      // assume that flows that reached max_duration have remaining of 0
-      GENERIC_ACTION(action).remains = 0;
-      ((surf_action_t)action)->finish = surf_get_clock();
-      surf_network_model->action_state_set((surf_action_t) action,
-                                           SURF_ACTION_DONE);
-      surf_action_lmm_heap_remove(surf_network_model->model_private->action_heap,(surf_action_lmm_t)action);
-    }
-  }
-  return;
+  generic_update_actions_state_lazy(now, delta, surf_network_model);
 }
 
 static void net_update_resource_state(void *id,
index f90a48a..c9b21c5 100644 (file)
@@ -366,3 +366,95 @@ double surf_action_get_remains(surf_action_t action)
   XBT_OUT();
   return action->remains;
 }
+
+void generic_update_actions_state_lazy(double now, double delta, surf_model_t model)
+{
+  surf_action_lmm_t action;
+  while ((xbt_heap_size(model->model_private->action_heap) > 0)
+         && (double_equals(xbt_heap_maxkey(model->model_private->action_heap), now))) {
+    action = xbt_heap_pop(model->model_private->action_heap);
+    XBT_DEBUG("Action %p: finish", action);
+    action->generic_action.finish = surf_get_clock();
+#ifdef HAVE_TRACING
+    if (TRACE_is_enabled()) {
+      if(model == surf_cpu_model){
+      surf_resource_t cpu =
+          lmm_constraint_id(lmm_get_cnst_from_var
+                            (model->model_private->maxmin_system,
+                             action->variable, 0));
+      TRACE_surf_host_set_utilization(cpu->name,
+                                      ((surf_action_t)action)->category,
+                                      lmm_variable_getvalue(action->variable),
+                                      action->last_update,
+                                      now - action->last_update);
+      }
+      else{
+        int n = lmm_get_number_of_cnst_from_var(model->model_private->maxmin_system, action->variable);
+        unsigned int i;
+        for (i = 0; i < n; i++){
+          lmm_constraint_t constraint = lmm_get_cnst_from_var(model->model_private->maxmin_system,
+                                                              action->variable,
+                                                              i);
+          link_CM02_t link = lmm_constraint_id(constraint);
+          TRACE_surf_link_set_utilization(link->lmm_resource.generic_resource.name,
+                                          ((surf_action_t)action)->category,
+                                          (lmm_variable_getvalue(action->variable)*
+                                              lmm_get_cnst_weight_from_var(model->model_private->maxmin_system,
+                                                  action->variable,
+                                                  i)),
+                                          action->last_update,
+                                          now - action->last_update);
+        }
+      }
+    }
+#endif
+
+    if(model == surf_cpu_model){
+      /* set the remains to 0 due to precision problems when updating the remaining amount */
+      action->generic_action.remains = 0;
+      surf_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
+      surf_action_lmm_heap_remove(model->model_private->action_heap,action); //FIXME: strange call since action was already popped
+    }
+    else{
+      // if I am wearing a latency hat
+      if (action->hat == LATENCY) {
+        lmm_update_variable_weight(model->model_private->maxmin_system, action->variable,
+            ((surf_action_network_CM02_t)(action))->weight);
+        surf_action_lmm_heap_remove(model->model_private->action_heap,action);
+        action->last_update = surf_get_clock();
+
+        // if I am wearing a max_duration or normal hat
+      } else if (action->hat == MAX_DURATION ||
+          action->hat == NORMAL) {
+        // no need to communicate anymore
+        // assume that flows that reached max_duration have remaining of 0
+        action->generic_action.remains = 0;
+        ((surf_action_t)action)->finish = surf_get_clock();
+        model->action_state_set((surf_action_t) action,
+                                             SURF_ACTION_DONE);
+        surf_action_lmm_heap_remove(model->model_private->action_heap,action);
+      }
+    }
+  }
+#ifdef HAVE_TRACING
+  if (TRACE_is_enabled() && model == surf_cpu_model) {
+    //defining the last timestamp that we can safely dump to trace file
+    //without losing the event ascending order (considering all CPU's)
+    double smaller = -1;
+    xbt_swag_t running_actions = model->states.running_action_set;
+    xbt_swag_foreach(action, running_actions) {
+        if (smaller < 0) {
+          smaller = action->last_update;
+          continue;
+        }
+        if (action->last_update < smaller) {
+          smaller = action->last_update;
+        }
+    }
+    if (smaller > 0) {
+      TRACE_last_timestamp_to_dump = smaller;
+    }
+  }
+#endif
+  return;
+}
index 35ff671..65f4dab 100644 (file)
@@ -93,6 +93,7 @@ void surf_action_set_category(surf_action_t action,
 #endif
 double surf_action_get_remains(surf_action_t action);
 void generic_update_action_remaining_lazy( surf_action_lmm_t action, double now);
+void generic_update_actions_state_lazy(double now, double delta, surf_model_t model);
 
 FILE *surf_fopen(const char *name, const char *mode);