Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add a specific file to manage tracing in SimDag
[simgrid.git] / src / surf / cpu_cas01.c
index 578416f..b492ee1 100644 (file)
@@ -7,6 +7,7 @@
 #include "surf_private.h"
 #include "surf/surf_resource.h"
 #include "maxmin_private.h"
+#include "simgrid/sg_config.h"
 
 surf_model_t surf_cpu_model = NULL;
 
@@ -36,12 +37,11 @@ typedef struct cpu_Cas01 {
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_cpu, surf,
                                 "Logging specific to the SURF CPU IMPROVED module");
 
-
-
 static xbt_swag_t
     cpu_running_action_set_that_does_not_need_being_checked = NULL;
 
 
+/* This function is registered as a callback to sg_platf_new_host() and never called directly */
 static void *cpu_create_resource(const char *name, double power_peak,
                                  double power_scale,
                                  tmgr_trace_t power_trace,
@@ -52,7 +52,7 @@ static void *cpu_create_resource(const char *name, double power_peak,
 {
   cpu_Cas01_t cpu = NULL;
 
-  xbt_assert(!surf_cpu_resource_by_name(name),
+  xbt_assert(!surf_cpu_resource_priv(surf_cpu_resource_by_name(name)),
              "Host '%s' declared several times in the platform file",
              name);
   cpu = (cpu_Cas01_t) surf_resource_new(sizeof(s_cpu_Cas01_t),
@@ -79,7 +79,7 @@ static void *cpu_create_resource(const char *name, double power_peak,
 
   xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, cpu);
 
-  return cpu;
+  return xbt_lib_get_elm_or_null(host_lib, name);;
 }
 
 
@@ -162,45 +162,7 @@ static void cpu_update_actions_state_lazy(double now, double delta)
 
 static void cpu_update_actions_state_full(double now, double delta)
 {
-  surf_action_cpu_Cas01_t action = NULL;
-  surf_action_cpu_Cas01_t next_action = NULL;
-  xbt_swag_t running_actions = surf_cpu_model->states.running_action_set;
-  xbt_swag_foreach_safe(action, next_action, running_actions) {
-#ifdef HAVE_TRACING
-    if (TRACE_is_enabled()) {
-      cpu_Cas01_t x =
-          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(x->generic_resource.name,
-                                      ((surf_action_t)action)->category,
-                                      lmm_variable_getvalue(GENERIC_LMM_ACTION(action).
-                                       variable),
-                                      now - delta,
-                                      delta);
-      TRACE_last_timestamp_to_dump = now - delta;
-    }
-#endif
-    double_update(&(GENERIC_ACTION(action).remains),
-                  lmm_variable_getvalue(GENERIC_LMM_ACTION(action).
-                                        variable) * delta);
-    if (GENERIC_LMM_ACTION(action).generic_action.max_duration !=
-        NO_MAX_DURATION)
-      double_update(&(GENERIC_ACTION(action).max_duration), delta);
-    if ((GENERIC_ACTION(action).remains <= 0) &&
-        (lmm_get_variable_weight(GENERIC_LMM_ACTION(action).variable) >
-         0)) {
-      GENERIC_ACTION(action).finish = surf_get_clock();
-      surf_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
-    } else if ((GENERIC_ACTION(action).max_duration != NO_MAX_DURATION) &&
-               (GENERIC_ACTION(action).max_duration <= 0)) {
-      GENERIC_ACTION(action).finish = surf_get_clock();
-      surf_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
-    }
-  }
-
-  return;
+  generic_update_actions_state_full(now, delta, surf_cpu_model);
 }
 
 static void cpu_update_resource_state(void *id,
@@ -211,6 +173,8 @@ static void cpu_update_resource_state(void *id,
   lmm_variable_t var = NULL;
   lmm_element_t elem = NULL;
 
+  surf_watched_hosts();
+
   if (event_type == cpu->power_event) {
     cpu->power_scale = value;
     lmm_update_constraint_bound(surf_cpu_model->model_private->maxmin_system, cpu->constraint,
@@ -263,7 +227,7 @@ static void cpu_update_resource_state(void *id,
 static surf_action_t cpu_execute(void *cpu, double size)
 {
   surf_action_cpu_Cas01_t action = NULL;
-  cpu_Cas01_t CPU = cpu;
+  cpu_Cas01_t CPU = surf_cpu_resource_priv(cpu);
 
   XBT_IN("(%s,%g)", surf_resource_name(CPU), size);
   action =
@@ -296,7 +260,7 @@ static surf_action_t cpu_action_sleep(void *cpu, double duration)
   if (duration > 0)
     duration = MAX(duration, MAXMIN_PRECISION);
 
-  XBT_IN("(%s,%g)", surf_resource_name(cpu), duration);
+  XBT_IN("(%s,%g)", surf_resource_name(surf_cpu_resource_priv(cpu)), duration);
   action = (surf_action_cpu_Cas01_t) cpu_execute(cpu, 1.0);
   // FIXME: sleep variables should not consume 1.0 in lmm_expand
   GENERIC_ACTION(action).max_duration = duration;
@@ -326,18 +290,18 @@ static surf_action_t cpu_action_sleep(void *cpu, double duration)
 
 static e_surf_resource_state_t cpu_get_state(void *cpu)
 {
-  return ((cpu_Cas01_t) cpu)->state_current;
+  return ((cpu_Cas01_t)surf_cpu_resource_priv(cpu))->state_current;
 }
 
 static double cpu_get_speed(void *cpu, double load)
 {
-  return load * (((cpu_Cas01_t) cpu)->power_peak);
+  return load * ((cpu_Cas01_t)surf_cpu_resource_priv(cpu))->power_peak;
 }
 
 static double cpu_get_available_speed(void *cpu)
 {
   /* number between 0 and 1 */
-  return ((cpu_Cas01_t) cpu)->power_scale;
+  return ((cpu_Cas01_t)surf_cpu_resource_priv(cpu))->power_scale;
 }
 
 static void cpu_finalize(void)
@@ -361,9 +325,9 @@ static void surf_cpu_model_init_internal()
   s_surf_action_t action;
   s_surf_action_cpu_Cas01_t comp;
 
-  char *optim = xbt_cfg_get_string(_surf_cfg_set, "cpu/optim");
+  char *optim = xbt_cfg_get_string(_sg_cfg_set, "cpu/optim");
   int select =
-      xbt_cfg_get_int(_surf_cfg_set, "cpu/maxmin_selective_update");
+      xbt_cfg_get_int(_sg_cfg_set, "cpu/maxmin_selective_update");
 
   surf_cpu_model = surf_model_init();
 
@@ -376,7 +340,7 @@ static void surf_cpu_model_init_internal()
     xbt_assert((select == 1)
                ||
                (xbt_cfg_is_default_value
-                (_surf_cfg_set, "cpu/maxmin_selective_update")),
+                (_sg_cfg_set, "cpu/maxmin_selective_update")),
                "Disabling selective update while using the lazy update mechanism is dumb!");
   } else {
     xbt_die("Unsupported optimization (%s) for this model", optim);
@@ -427,7 +391,6 @@ static void surf_cpu_model_init_internal()
   surf_cpu_model->extension.cpu.get_speed = cpu_get_speed;
   surf_cpu_model->extension.cpu.get_available_speed =
       cpu_get_available_speed;
-  surf_cpu_model->extension.cpu.create_resource = cpu_create_resource;
   surf_cpu_model->extension.cpu.add_traces = cpu_add_traces_cpu;
 
   if (!surf_cpu_model->model_private->maxmin_system) {
@@ -461,7 +424,7 @@ static void surf_cpu_model_init_internal()
 
 void surf_cpu_model_init_Cas01()
 {
-  char *optim = xbt_cfg_get_string(_surf_cfg_set, "cpu/optim");
+  char *optim = xbt_cfg_get_string(_sg_cfg_set, "cpu/optim");
 
   if (surf_cpu_model)
     return;