Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge remote-tracking branch 'origin/libdw2'
[simgrid.git] / src / surf / surf_action.c
index e05e199..86e752d 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2009, 2010. The SimGrid Team.
+/* Copyright (c) 2009-2013. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -6,6 +6,9 @@
 
 #include "surf_private.h"
 #include "network_private.h"
+#include "maxmin_private.h"
+#include "surf/datatypes.h"
+#include "cpu_cas01_private.h"
 #include "xbt/mallocator.h"
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_kernel);
@@ -311,7 +314,7 @@ void generic_update_action_remaining_lazy( surf_action_lmm_t action, double now)
   delta = now - action->last_update;
 
   if (action->generic_action.remains > 0) {
-    XBT_DEBUG("Updating action(%p): remains was %lf, last_update was: %lf", action, action->generic_action.remains, action->last_update);
+    XBT_DEBUG("Updating action(%p): remains was %f, last_update was: %f", action, action->generic_action.remains, action->last_update);
     double_update(&(action->generic_action.remains),
         action->last_value * delta);
 
@@ -328,7 +331,7 @@ void generic_update_action_remaining_lazy( surf_action_lmm_t action, double now)
           now - action->last_update);
     }
 #endif
-    XBT_DEBUG("Updating action(%p): remains is now %lf", action,
+    XBT_DEBUG("Updating action(%p): remains is now %f", action,
         action->generic_action.remains);
   }
 
@@ -368,14 +371,34 @@ double surf_action_get_remains(surf_action_t action)
   return action->remains;
 }
 
+/**
+ * Update the CPU total energy for a finished action
+ *
+ */
+void update_resource_energy(surf_model_t model, surf_action_lmm_t action)
+{
+    if(model == surf_cpu_model){
+        cpu_Cas01_t cpu_model = (cpu_Cas01_t)lmm_constraint_id(lmm_get_cnst_from_var
+                                                                                 (model->model_private->maxmin_system,
+                                                                                                 action->variable, 0));
+
+        if( cpu_model->energy->last_updated < surf_get_clock()) {
+               double load = lmm_constraint_get_usage(cpu_model->constraint) / cpu_model->power_peak;
+               cpu_update_energy(cpu_model, load);
+        }
+    }
+}
+
+
+
+
 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();
+    XBT_DEBUG("Something happened to action %p", action);
 #ifdef HAVE_TRACING
     if (TRACE_is_enabled()) {
       if(model == surf_cpu_model){
@@ -411,6 +434,10 @@ void generic_update_actions_state_lazy(double now, double delta, surf_model_t mo
 #endif
 
     if(model == surf_cpu_model){
+      action->generic_action.finish = surf_get_clock();
+
+      update_resource_energy(model, action);
+
       /* 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);
@@ -419,6 +446,7 @@ void generic_update_actions_state_lazy(double now, double delta, surf_model_t mo
     else{
       // if I am wearing a latency hat
       if (action->hat == LATENCY) {
+        XBT_DEBUG("Latency paid for action %p. Activating", action);
         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);
@@ -429,7 +457,9 @@ void generic_update_actions_state_lazy(double now, double delta, surf_model_t mo
           action->hat == NORMAL) {
         // no need to communicate anymore
         // assume that flows that reached max_duration have remaining of 0
-        action->generic_action.remains = 0;
+       action->generic_action.finish = surf_get_clock();
+       XBT_DEBUG("Action %p finished", action);
+       action->generic_action.remains = 0;
         ((surf_action_t)action)->finish = surf_get_clock();
         model->action_state_set((surf_action_t) action,
                                              SURF_ACTION_DONE);
@@ -559,6 +589,8 @@ void generic_update_actions_state_full(double now, double delta, surf_model_t mo
       if (model->gap_remove && model == surf_network_model)
         model->gap_remove(action);
     }
+
+    update_resource_energy(model, action);
   }
 
   return;