Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
minor fixes - Adrien / Takahiro
[simgrid.git] / src / surf / cpu_cas01.c
index 0a98541..9b7d5c4 100644 (file)
@@ -8,6 +8,7 @@
 #include "surf/surf_resource.h"
 #include "maxmin_private.h"
 #include "simgrid/sg_config.h"
+#include "surf/cpu_cas01_private.h"
 
 /* the model objects for physical machines and virtual machines */
 surf_model_t surf_cpu_model_pm = NULL;
@@ -24,18 +25,6 @@ typedef struct surf_action_cpu_cas01 {
   s_surf_action_lmm_t generic_lmm_action;
 } s_surf_action_cpu_Cas01_t, *surf_action_cpu_Cas01_t;
 
-typedef struct cpu_Cas01 {
-  s_surf_resource_t generic_resource;
-  s_xbt_swag_hookup_t modified_cpu_hookup;
-  double power_peak;
-  double power_scale;
-  tmgr_trace_event_t power_event;
-  int core;
-  e_surf_resource_state_t state_current;
-  tmgr_trace_event_t state_event;
-  lmm_constraint_t constraint;
-} s_cpu_Cas01_t, *cpu_Cas01_t;
-
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_cpu, surf,
                                 "Logging specific to the SURF CPU IMPROVED module");
 
@@ -43,8 +32,7 @@ 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,
+void *cpu_cas01_create_resource(const char *name, double power_peak,
                                  double power_scale,
                                  tmgr_trace_t power_trace,
                                  int core,
@@ -91,7 +79,7 @@ static void parse_cpu_init(sg_platf_host_cbarg_t host)
   /* This function is called when a platform file is parsed. Physical machines
    * are defined there. Thus, we use the cpu model object for the physical
    * machine layer. */
-  cpu_create_resource(host->id,
+  cpu_cas01_create_resource(host->id,
                       host->power_peak,
                       host->power_scale,
                       host->power_trace,
@@ -134,7 +122,7 @@ static void cpu_add_traces_cpu(void)
   }
 }
 
-static void cpu_define_callbacks()
+static void cpu_define_callbacks_cas01()
 {
   sg_platf_host_add_cb(parse_cpu_init);
   sg_platf_postparse_add_cb(cpu_add_traces_cpu);
@@ -333,7 +321,7 @@ static void cpu_finalize(surf_model_t cpu_model)
   cpu_running_action_set_that_does_not_need_being_checked = NULL;
 }
 
-static void surf_cpu_model_init_internal(surf_model_t cpu_model)
+static surf_model_t surf_cpu_model_init_cas01(void)
 {
   s_surf_action_t action;
   s_surf_action_cpu_Cas01_t comp;
@@ -342,7 +330,7 @@ static void surf_cpu_model_init_internal(surf_model_t cpu_model)
   int select =
       xbt_cfg_get_int(_sg_cfg_set, "cpu/maxmin_selective_update");
 
-  cpu_model = surf_model_init();
+  surf_model_t cpu_model = surf_model_init();
 
   if (!strcmp(optim, "Full")) {
     cpu_model->model_private->update_mechanism = UM_FULL;
@@ -418,6 +406,8 @@ static void surf_cpu_model_init_internal(surf_model_t cpu_model)
         xbt_swag_new(xbt_swag_offset(comp, generic_lmm_action.action_list_hookup));
     cpu_model->model_private->maxmin_system->keep_track = cpu_model->model_private->modified_set;
   }
+
+  return cpu_model;
 }
 
 /*********************************************************************/
@@ -437,30 +427,29 @@ static void surf_cpu_model_init_internal(surf_model_t cpu_model)
 /* } */
 
 
-static void create_cpu_model_object(surf_model_t cpu_model)
+void surf_cpu_model_init_Cas01(void)
 {
   char *optim = xbt_cfg_get_string(_sg_cfg_set, "cpu/optim");
 
-  xbt_assert(cpu_model == NULL, "wrong intialization");
-
-  if (!strcmp(optim, "TI")) {
-    surf_cpu_model_init_ti(cpu_model);
-    return;
-  }
+  xbt_assert(!surf_cpu_model_pm);
+  xbt_assert(!surf_cpu_model_vm);
 
-  surf_cpu_model_init_internal(cpu_model);
-  cpu_define_callbacks();
+  if (strcmp(optim, "TI") == 0) {
+    /* FIXME: do we have to supprot TI? for VM */
+    surf_cpu_model_pm = surf_cpu_model_init_ti();
+    XBT_INFO("TI model is used (it will crashed since this is the hypervisor branch)");
+  } else {
+    surf_cpu_model_pm  = surf_cpu_model_init_cas01();
+    surf_cpu_model_vm  = surf_cpu_model_init_cas01();
 
-  /* cpu_model is registered only to model_list, and not to
-   * model_list_invoke. The shared_resource callback function will be called
-   * from that of the workstation model. */
-  xbt_dynar_push(model_list, &cpu_model);
-}
+    /* cpu_model is registered only to model_list, and not to
+     * model_list_invoke. The shared_resource callback function will be called
+     * from that of the workstation model. */
+    xbt_dynar_push(model_list, &surf_cpu_model_pm);
+    xbt_dynar_push(model_list, &surf_cpu_model_vm);
 
-void surf_cpu_model_init_Cas01(void)
-{
-  create_cpu_model_object(surf_cpu_model_pm);
-  create_cpu_model_object(surf_cpu_model_vm);
+    cpu_define_callbacks_cas01();
+  }
 }
 
 /* TODO: do we address nested virtualization later? */