Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cleanups
[simgrid.git] / src / surf / cpu_im.c
index ca0a98b..66faee8 100644 (file)
@@ -1,6 +1,5 @@
-/*     $Id$     */
-
-/* Copyright (c) 2004 Arnaud Legrand. All rights reserved.                  */
+/* Copyright (c) 2009, 2010. The SimGrid Team.
+ * 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. */
@@ -53,8 +52,14 @@ static cpu_Cas01_im_t cpu_im_new(char *name, double power_peak,
                               tmgr_trace_t state_trace,
                               xbt_dict_t cpu_properties)
 {
-  cpu_Cas01_im_t cpu = xbt_new0(s_cpu_Cas01_im_t, 1);
+  cpu_Cas01_im_t cpu = NULL;
   s_surf_action_cpu_Cas01_im_t action;
+  cpu = xbt_new0(s_cpu_Cas01_im_t, 1);
+
+  #ifdef HAVE_TRACING
+  TRACE_surf_host_declaration (name, power_scale * power_peak);
+  #endif
+
   xbt_assert1(!surf_model_resource_by_name(surf_cpu_model, name),
               "Host '%s' declared several times in the platform file", name);
   cpu->generic_resource.model = surf_cpu_model;
@@ -115,14 +120,11 @@ static void cpu_im_add_traces_cpu(void)
 {
   xbt_dict_cursor_t cursor = NULL;
   char *trace_name, *elm;
-
   static int called = 0;
-
   if (called)
     return;
   called = 1;
 
-
   /* connect all traces relative to hosts */
   xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) {
     tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
@@ -147,6 +149,7 @@ static void cpu_im_add_traces_cpu(void)
 
 static void cpu_im_define_callbacks(const char *file)
 {
+
   surf_parse_reset_parser();
   surfxml_add_callback(STag_surfxml_host_cb_list, parse_cpu_im_init);
   surfxml_add_callback(ETag_surfxml_platform_cb_list, &cpu_im_add_traces_cpu);
@@ -221,6 +224,10 @@ static void cpu_im_update_remains(cpu_Cas01_im_t cpu, double now)
                     lmm_variable_getvalue(GENERIC_LMM_ACTION
                                           (action).variable) * (now -
                                                                 cpu->last_update));
+#ifdef HAVE_TRACING
+      TRACE_surf_host_set_utilization (cpu->generic_resource.name,
+                action->generic_lmm_action.generic_action.data, lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable), cpu->last_update, now-cpu->last_update);
+#endif
       DEBUG2("Update action(%p) remains %lf", action,
              GENERIC_ACTION(action).remains);
     }
@@ -299,6 +306,10 @@ static void cpu_im_update_actions_state(double now, double delta)
     DEBUG1("Action %p: finish", action);
     GENERIC_ACTION(action).finish = surf_get_clock();
     /* set the remains to 0 due to precision problems when updating the remaining amount */
+#ifdef HAVE_TRACING
+    TRACE_surf_host_set_utilization (((cpu_Cas01_im_t)(action->cpu))->generic_resource.name,
+              action->generic_lmm_action.generic_action.data, lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable), ((cpu_Cas01_im_t)(action->cpu))->last_update, now-((cpu_Cas01_im_t)(action->cpu))->last_update);
+#endif
     GENERIC_ACTION(action).remains = 0;
     cpu_im_cpu_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
     cpu_im_update_remains(action->cpu, surf_get_clock());
@@ -311,11 +322,13 @@ static void cpu_im_update_resource_state(void *id,
                                   double value, double date)
 {
   cpu_Cas01_im_t cpu = id;
-
   if (event_type == cpu->power_event) {
     cpu->power_scale = value;
     lmm_update_constraint_bound(cpu_im_maxmin_system, cpu->constraint,
                                 cpu->power_scale * cpu->power_peak);
+#ifdef HAVE_TRACING
+    TRACE_surf_host_set_power (date, cpu->generic_resource.name, cpu->power_scale * cpu->power_peak);
+#endif
     xbt_swag_insert(cpu, cpu_im_modified_cpu);
     if (tmgr_trace_event_free(event_type))
       cpu->power_event = NULL;
@@ -419,6 +432,7 @@ static void cpu_im_action_suspend(surf_action_t action)
 
 static void cpu_im_action_resume(surf_action_t action)
 {
+
   XBT_IN1("(%p)", action);
   if (((surf_action_lmm_t) action)->suspended != 2) {
     lmm_update_variable_weight(cpu_im_maxmin_system,
@@ -486,6 +500,16 @@ static void cpu_im_action_update_index_heap(void *action, int i)
 {
   ((surf_action_cpu_Cas01_im_t) action)->index_heap = i;
 }
+static void cpu_im_create_resource(char *name, double power_peak,
+        double power_scale,
+        tmgr_trace_t power_trace,
+        e_surf_resource_state_t state_initial,
+        tmgr_trace_t state_trace,
+        xbt_dict_t cpu_properties)
+{
+       cpu_im_new(name,power_peak,power_scale,power_trace,
+                                         state_initial,state_trace,cpu_properties);
+}
 
 static void cpu_im_finalize(void)
 {
@@ -545,6 +569,8 @@ static void surf_cpu_im_model_init_internal(void)
   surf_cpu_model->extension.cpu.get_state = cpu_im_get_state;
   surf_cpu_model->extension.cpu.get_speed = cpu_im_get_speed;
   surf_cpu_model->extension.cpu.get_available_speed = cpu_im_get_available_speed;
+  surf_cpu_model->extension.cpu.create_resource = cpu_im_create_resource;
+  surf_cpu_model->extension.cpu.add_traces = cpu_im_add_traces_cpu;
 
   if (!cpu_im_maxmin_system) {
     sg_maxmin_selective_update = 1;