Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix memleak
[simgrid.git] / src / surf / cpu_ti.cpp
index e312e6e..2be282c 100644 (file)
@@ -6,7 +6,7 @@
 #define SURF_MODEL_CPUTI_H_
 
 extern "C" {
 #define SURF_MODEL_CPUTI_H_
 
 extern "C" {
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_cpu_ti, surf,
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_cpu_ti, surf_cpu,
                                 "Logging specific to the SURF CPU TRACE INTEGRATION module");
 }
 
                                 "Logging specific to the SURF CPU TRACE INTEGRATION module");
 }
 
@@ -145,7 +145,7 @@ double CpuTiTrace::integrateSimplePoint(double a)
   ind = binarySearch(p_timePoints, a, 0, m_nbPoints - 1);
   integral += p_integral[ind];
   XBT_DEBUG
   ind = binarySearch(p_timePoints, a, 0, m_nbPoints - 1);
   integral += p_integral[ind];
   XBT_DEBUG
-      ("a %lf ind %d integral %lf ind + 1 %lf ind %lf time +1 %lf time %lf",
+      ("a %f ind %d integral %f ind + 1 %f ind %f time +1 %f time %f",
        a, ind, integral, p_integral[ind + 1], p_integral[ind],
        p_timePoints[ind + 1], p_timePoints[ind]);
   double_update(&a_aux, p_timePoints[ind]);
        a, ind, integral, p_integral[ind + 1], p_integral[ind],
        p_timePoints[ind + 1], p_timePoints[ind]);
   double_update(&a_aux, p_timePoints[ind]);
@@ -154,7 +154,7 @@ double CpuTiTrace::integrateSimplePoint(double a)
         ((p_integral[ind + 1] -
           p_integral[ind]) / (p_timePoints[ind + 1] -
                               p_timePoints[ind])) * (a - p_timePoints[ind]);
         ((p_integral[ind + 1] -
           p_integral[ind]) / (p_timePoints[ind + 1] -
                               p_timePoints[ind])) * (a - p_timePoints[ind]);
-  XBT_DEBUG("Integral a %lf = %lf", a, integral);
+  XBT_DEBUG("Integral a %f = %f", a, integral);
 
   return integral;
 }
 
   return integral;
 }
@@ -203,14 +203,14 @@ double CpuTiTgmr::solve(double a, double amount)
     return (a + (amount / m_value));
   }
 
     return (a + (amount / m_value));
   }
 
-  XBT_DEBUG("amount %lf total %lf", amount, m_total);
+  XBT_DEBUG("amount %f total %f", amount, m_total);
 /* Reduce the problem to one where amount <= trace_total */
   quotient = (int) (floor(amount / m_total));
   reduced_amount = (m_total) * ((amount / m_total) -
                                      floor(amount / m_total));
   reduced_a = a - (m_lastTime) * (int) (floor(a / m_lastTime));
 
 /* Reduce the problem to one where amount <= trace_total */
   quotient = (int) (floor(amount / m_total));
   reduced_amount = (m_total) * ((amount / m_total) -
                                      floor(amount / m_total));
   reduced_a = a - (m_lastTime) * (int) (floor(a / m_lastTime));
 
-  XBT_DEBUG("Quotient: %d reduced_amount: %lf reduced_a: %lf", quotient,
+  XBT_DEBUG("Quotient: %d reduced_amount: %f reduced_a: %f", quotient,
          reduced_amount, reduced_a);
 
 /* Now solve for new_amount which is <= trace_total */
          reduced_amount, reduced_a);
 
 /* Now solve for new_amount which is <= trace_total */
@@ -312,12 +312,13 @@ CpuTiTgmr::CpuTiTgmr(tmgr_trace_t power_trace, double value)
   double total_time = 0.0;
   s_tmgr_event_t val;
   unsigned int cpt;
   double total_time = 0.0;
   s_tmgr_event_t val;
   unsigned int cpt;
+  p_trace = 0;
 
 /* no availability file, fixed trace */
   if (!power_trace) {
     m_type = TRACE_FIXED;
     m_value = value;
 
 /* no availability file, fixed trace */
   if (!power_trace) {
     m_type = TRACE_FIXED;
     m_value = value;
-    XBT_DEBUG("No availabily trace. Constant value = %lf", value);
+    XBT_DEBUG("No availability trace. Constant value = %lf", value);
     return;
   }
 
     return;
   }
 
@@ -361,7 +362,7 @@ int CpuTiTrace::binarySearch(double *array, double a, int low, int high)
   int mid;
   do {
     mid = low + (high - low) / 2;
   int mid;
   do {
     mid = low + (high - low) / 2;
-    XBT_DEBUG("a %lf low %d high %d mid %d value %lf", a, low, high, mid,
+    XBT_DEBUG("a %f low %d high %d mid %d value %f", a, low, high, mid,
         array[mid]);
 
     if (array[mid] > a)
         array[mid]);
 
     if (array[mid] > a)
@@ -374,19 +375,45 @@ int CpuTiTrace::binarySearch(double *array, double a, int low, int high)
   return low;
 }
 
   return low;
 }
 
+/*************
+ * CallBacks *
+ *************/
+
+static void parse_cpu_ti_init(sg_platf_host_cbarg_t host){
+  ((CpuTiModelPtr)surf_cpu_model_pm)->parseInit(host);
+}
+
+static void add_traces_cpu_ti(){
+  surf_cpu_model_pm->addTraces();
+}
+
+static void cpu_ti_define_callbacks()
+{
+  sg_platf_host_add_cb(parse_cpu_ti_init);
+  sg_platf_postparse_add_cb(add_traces_cpu_ti);
+}
+
 /*********
  * Model *
  *********/
 
 /*********
  * Model *
  *********/
 
+void surf_cpu_model_init_ti()
+{
+  xbt_assert(!surf_cpu_model_pm,"CPU model already initialized. This should not happen.");
+  surf_cpu_model_pm = new CpuTiModel();
+  cpu_ti_define_callbacks();
+  ModelPtr model = static_cast<ModelPtr>(surf_cpu_model_pm);
+  xbt_dynar_push(model_list, &model);
+}
+
 CpuTiModel::CpuTiModel() : CpuModel("cpu_ti")
 {
 CpuTiModel::CpuTiModel() : CpuModel("cpu_ti")
 {
-  xbt_assert(!surf_cpu_model,"CPU model already initialized. This should not happen.");
-  surf_cpu_model = this;
-  CpuTiAction action;
+  xbt_assert(!surf_cpu_model_pm,"CPU model already initialized. This should not happen.");
+  ActionPtr action = NULL;
   CpuTi cpu;
 
   cpu_ti_running_action_set_that_does_not_need_being_checked =
   CpuTi cpu;
 
   cpu_ti_running_action_set_that_does_not_need_being_checked =
-      xbt_swag_new(xbt_swag_offset(action, p_stateHookup));
+      xbt_swag_new(xbt_swag_offset(*action, p_stateHookup));
 
   cpu_ti_modified_cpu =
       xbt_swag_new(xbt_swag_offset(cpu, p_modifiedCpuHookup));
 
   cpu_ti_modified_cpu =
       xbt_swag_new(xbt_swag_offset(cpu, p_modifiedCpuHookup));
@@ -394,11 +421,6 @@ CpuTiModel::CpuTiModel() : CpuModel("cpu_ti")
   cpu_ti_action_heap = xbt_heap_new(8, NULL);
   xbt_heap_set_update_callback(cpu_ti_action_heap,
                                cpu_ti_action_update_index_heap);
   cpu_ti_action_heap = xbt_heap_new(8, NULL);
   xbt_heap_set_update_callback(cpu_ti_action_heap,
                                cpu_ti_action_update_index_heap);
-  /* Define callbacks */
-  //TODO sg_platf_host_add_cb(parse_cpu_ti_init);
-  //TODO sg_platf_postparse_add_cb(add_traces_cpu_ti);
-
-  xbt_dynar_push(model_list, &surf_cpu_model);
 }
 
 CpuTiModel::~CpuTiModel()
 }
 
 CpuTiModel::~CpuTiModel()
@@ -407,17 +429,7 @@ CpuTiModel::~CpuTiModel()
   xbt_lib_cursor_t cursor;
   char *key;
 
   xbt_lib_cursor_t cursor;
   char *key;
 
-  xbt_lib_foreach(host_lib, cursor, key, cpu){
-    if(cpu[SURF_CPU_LEVEL])
-    {
-        CpuTiPtr CPU = dynamic_cast<CpuTiPtr>(static_cast<ResourcePtr>(cpu[SURF_CPU_LEVEL]));
-        xbt_swag_free(CPU->p_actionSet);
-        delete CPU->p_availTrace;
-    }
-  }
-
-  delete surf_cpu_model;
-  surf_cpu_model = NULL;
+  surf_cpu_model_pm = NULL;
 
   xbt_swag_free
       (cpu_ti_running_action_set_that_does_not_need_being_checked);
 
   xbt_swag_free
       (cpu_ti_running_action_set_that_does_not_need_being_checked);
@@ -430,6 +442,7 @@ void CpuTiModel::parseInit(sg_platf_host_cbarg_t host)
 {
   createResource(host->id,
         host->power_peak,
 {
   createResource(host->id,
         host->power_peak,
+        host->pstate,
         host->power_scale,
         host->power_trace,
         host->core_amount,
         host->power_scale,
         host->power_trace,
         host->core_amount,
@@ -439,7 +452,8 @@ void CpuTiModel::parseInit(sg_platf_host_cbarg_t host)
 }
 
 CpuTiPtr CpuTiModel::createResource(const char *name,
 }
 
 CpuTiPtr CpuTiModel::createResource(const char *name,
-                          double powerPeak,
+                              xbt_dynar_t powerPeak,
+                              int pstate,
                            double powerScale,
                            tmgr_trace_t powerTrace,
                            int core,
                            double powerScale,
                            tmgr_trace_t powerTrace,
                            int core,
@@ -447,20 +461,17 @@ CpuTiPtr CpuTiModel::createResource(const char *name,
                            tmgr_trace_t stateTrace,
                            xbt_dict_t cpuProperties)
 {
                            tmgr_trace_t stateTrace,
                            xbt_dict_t cpuProperties)
 {
-  tmgr_trace_t empty_trace;
-  s_tmgr_event_t val;
-  CpuTiActionPtr cpuAction;
   xbt_assert(core==1,"Multi-core not handled with this model yet");
   xbt_assert(!surf_cpu_resource_priv(surf_cpu_resource_by_name(name)),
               "Host '%s' declared several times in the platform file",
               name);
   xbt_assert(core==1,"Multi-core not handled with this model yet");
   xbt_assert(!surf_cpu_resource_priv(surf_cpu_resource_by_name(name)),
               "Host '%s' declared several times in the platform file",
               name);
-  CpuTiPtr cpu = new CpuTi(this, name, powerPeak, powerScale, powerTrace,
+  CpuTiPtr cpu = new CpuTi(this, name, powerPeak, pstate, powerScale, powerTrace,
                           core, stateInitial, stateTrace, cpuProperties);
   xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, static_cast<ResourcePtr>(cpu));
   return (CpuTiPtr) xbt_lib_get_elm_or_null(host_lib, name);
 }
 
                           core, stateInitial, stateTrace, cpuProperties);
   xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, static_cast<ResourcePtr>(cpu));
   return (CpuTiPtr) xbt_lib_get_elm_or_null(host_lib, name);
 }
 
-CpuTiActionPtr CpuTiModel::createAction(double cost, bool failed)
+CpuTiActionPtr CpuTiModel::createAction(double /*cost*/, bool /*failed*/)
 {
   return NULL;//new CpuTiAction(this, cost, failed);
 }
 {
   return NULL;//new CpuTiAction(this, cost, failed);
 }
@@ -472,18 +483,18 @@ double CpuTiModel::shareResources(double now)
 
 /* iterates over modified cpus to update share resources */
   xbt_swag_foreach_safe(_cpu, _cpu_next, cpu_ti_modified_cpu) {
 
 /* iterates over modified cpus to update share resources */
   xbt_swag_foreach_safe(_cpu, _cpu_next, cpu_ti_modified_cpu) {
-    ((CpuTiPtr)_cpu)->updateActionFinishDate(now);
+    static_cast<CpuTiPtr>(_cpu)->updateActionFinishDate(now);
   }
 /* get the min next event if heap not empty */
   if (xbt_heap_size(cpu_ti_action_heap) > 0)
     min_action_duration = xbt_heap_maxkey(cpu_ti_action_heap) - now;
 
   }
 /* get the min next event if heap not empty */
   if (xbt_heap_size(cpu_ti_action_heap) > 0)
     min_action_duration = xbt_heap_maxkey(cpu_ti_action_heap) - now;
 
-  XBT_DEBUG("Share resources, min next event date: %lf", min_action_duration);
+  XBT_DEBUG("Share resources, min next event date: %f", min_action_duration);
 
   return min_action_duration;
 }
 
 
   return min_action_duration;
 }
 
-void CpuTiModel::updateActionsState(double now, double delta)
+void CpuTiModel::updateActionsState(double now, double /*delta*/)
 {
   while ((xbt_heap_size(cpu_ti_action_heap) > 0)
          && (xbt_heap_maxkey(cpu_ti_action_heap) <= now)) {
 {
   while ((xbt_heap_size(cpu_ti_action_heap) > 0)
          && (xbt_heap_maxkey(cpu_ti_action_heap) <= now)) {
@@ -493,7 +504,7 @@ void CpuTiModel::updateActionsState(double now, double delta)
     /* set the remains to 0 due to precision problems when updating the remaining amount */
     action->m_remains = 0;
     action->setState(SURF_ACTION_DONE);
     /* set the remains to 0 due to precision problems when updating the remaining amount */
     action->m_remains = 0;
     action->setState(SURF_ACTION_DONE);
-    /* update remaining amout of all actions */
+    /* update remaining amount of all actions */
     action->p_cpu->updateRemainingAmount(surf_get_clock());
   }
 }
     action->p_cpu->updateRemainingAmount(surf_get_clock());
   }
 }
@@ -512,7 +523,7 @@ void CpuTiModel::addTraces()
 /* connect all traces relative to hosts */
   xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) {
     tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
 /* connect all traces relative to hosts */
   xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) {
     tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
-    CpuTiPtr cpu = (CpuTiPtr) surf_cpu_resource_priv(surf_cpu_resource_by_name(elm));
+    CpuTiPtr cpu = static_cast<CpuTiPtr>(surf_cpu_resource_priv(surf_cpu_resource_by_name(elm)));
 
     xbt_assert(cpu, "Host %s undefined", elm);
     xbt_assert(trace, "Trace %s undefined", trace_name);
 
     xbt_assert(cpu, "Host %s undefined", elm);
     xbt_assert(trace, "Trace %s undefined", trace_name);
@@ -523,12 +534,12 @@ void CpuTiModel::addTraces()
       continue;
     }
     XBT_DEBUG("Add state trace: %s to CPU(%s)", trace_name, elm);
       continue;
     }
     XBT_DEBUG("Add state trace: %s to CPU(%s)", trace_name, elm);
-    cpu->p_stateEvent = tmgr_history_add_trace(history, trace, 0.0, 0, cpu);
+    cpu->p_stateEvent = tmgr_history_add_trace(history, trace, 0.0, 0, static_cast<ResourcePtr>(cpu));
   }
 
   xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
     tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
   }
 
   xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
     tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
-    CpuTiPtr cpu = (CpuTiPtr) surf_cpu_resource_priv(surf_cpu_resource_by_name(elm));
+    CpuTiPtr cpu = dynamic_cast<CpuTiPtr>(static_cast<ResourcePtr>(surf_cpu_resource_priv(surf_cpu_resource_by_name(elm))));
 
     xbt_assert(cpu, "Host %s undefined", elm);
     xbt_assert(trace, "Trace %s undefined", trace_name);
 
     xbt_assert(cpu, "Host %s undefined", elm);
     xbt_assert(trace, "Trace %s undefined", trace_name);
@@ -549,7 +560,7 @@ void CpuTiModel::addTraces()
         empty_trace = tmgr_empty_trace_new();
         cpu->p_powerEvent =
             tmgr_history_add_trace(history, empty_trace,
         empty_trace = tmgr_empty_trace_new();
         cpu->p_powerEvent =
             tmgr_history_add_trace(history, empty_trace,
-                                   cpu->p_availTrace->m_lastTime, 0, cpu);
+                                   cpu->p_availTrace->m_lastTime, 0, static_cast<ResourcePtr>(cpu));
       }
     }
   }
       }
     }
   }
@@ -558,12 +569,13 @@ void CpuTiModel::addTraces()
 /************
  * Resource *
  ************/
 /************
  * Resource *
  ************/
-CpuTi::CpuTi(CpuTiModelPtr model, const char *name, double powerPeak,
-        double powerScale, tmgr_trace_t powerTrace, int core,
+CpuTi::CpuTi(CpuTiModelPtr model, const char *name, xbt_dynar_t powerPeak,
+        int pstate, double powerScale, tmgr_trace_t powerTrace, int core,
         e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace,
        xbt_dict_t properties) :
         e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace,
        xbt_dict_t properties) :
-       Cpu(model, name, properties), p_stateCurrent(stateInitial) {
-  m_powerPeak = powerPeak;
+       Resource(model, name, properties), Cpu(model, name, properties) {
+  p_powerEvent = NULL;
+  p_stateCurrent = stateInitial;
   m_powerScale = powerScale;
   m_core = core;
   tmgr_trace_t empty_trace;            
   m_powerScale = powerScale;
   m_core = core;
   tmgr_trace_t empty_trace;            
@@ -571,35 +583,52 @@ CpuTi::CpuTi(CpuTiModelPtr model, const char *name, double powerPeak,
   xbt_assert(core==1,"Multi-core not handled with this model yet");
   XBT_DEBUG("power scale %lf", powerScale);
   p_availTrace = new CpuTiTgmr(powerTrace, powerScale);
   xbt_assert(core==1,"Multi-core not handled with this model yet");
   XBT_DEBUG("power scale %lf", powerScale);
   p_availTrace = new CpuTiTgmr(powerTrace, powerScale);
+
+  CpuTiActionPtr action = NULL;
+  p_actionSet = xbt_swag_new(xbt_swag_offset(*action, p_cpuListHookup));
+
+  m_lastUpdate = 0;
+
+  xbt_dynar_get_cpy(powerPeak, 0, &m_powerPeak);
+  xbt_dynar_free(&powerPeak);  /* kill memory leak */
+  m_pstate = pstate;
+  XBT_DEBUG("CPU create: peak=%f, pstate=%d", m_powerPeak, m_pstate);
+
+  p_modifiedCpuHookup.prev = 0;
+  p_modifiedCpuHookup.next = 0;
+
   if (stateTrace)
   if (stateTrace)
-    p_stateEvent = tmgr_history_add_trace(history, stateTrace, 0.0, 0, this);
+    p_stateEvent = tmgr_history_add_trace(history, stateTrace, 0.0, 0, static_cast<ResourcePtr>(this));
   if (powerTrace && xbt_dynar_length(powerTrace->s_list.event_list) > 1) {
     // add a fake trace event if periodicity == 0 
     xbt_dynar_get_cpy(powerTrace->s_list.event_list,
                       xbt_dynar_length(powerTrace->s_list.event_list) - 1, &val);
     if (val.delta == 0) {
       empty_trace = tmgr_empty_trace_new();
   if (powerTrace && xbt_dynar_length(powerTrace->s_list.event_list) > 1) {
     // add a fake trace event if periodicity == 0 
     xbt_dynar_get_cpy(powerTrace->s_list.event_list,
                       xbt_dynar_length(powerTrace->s_list.event_list) - 1, &val);
     if (val.delta == 0) {
       empty_trace = tmgr_empty_trace_new();
-       p_powerEvent =
+      p_powerEvent =
         tmgr_history_add_trace(history, empty_trace,
         tmgr_history_add_trace(history, empty_trace,
-                               p_availTrace->m_lastTime, 0, this);
+                               p_availTrace->m_lastTime, 0, static_cast<ResourcePtr>(this));
     }
   }
 };
 
     }
   }
 };
 
+CpuTi::~CpuTi(){
+delete p_availTrace;
+xbt_swag_free(p_actionSet);
+}
+
 void CpuTi::updateState(tmgr_trace_event_t event_type,
                         double value, double date)
 {
   void *_action;
   CpuTiActionPtr action;
 
 void CpuTi::updateState(tmgr_trace_event_t event_type,
                         double value, double date)
 {
   void *_action;
   CpuTiActionPtr action;
 
-  surf_watched_hosts();
-
   if (event_type == p_powerEvent) {
     tmgr_trace_t power_trace;
     CpuTiTgmrPtr trace;
     s_tmgr_event_t val;
 
   if (event_type == p_powerEvent) {
     tmgr_trace_t power_trace;
     CpuTiTgmrPtr trace;
     s_tmgr_event_t val;
 
-    XBT_DEBUG("Finish trace date: %lf value %lf date %lf", surf_get_clock(),
+    XBT_DEBUG("Finish trace date: %f value %lf date %f", surf_get_clock(),
            value, date);
     /* update remaining of actions and put in modified cpu swag */
     updateRemainingAmount(date);
            value, date);
     /* update remaining of actions and put in modified cpu swag */
     updateRemainingAmount(date);
@@ -613,7 +642,7 @@ void CpuTi::updateState(tmgr_trace_event_t event_type,
     m_powerScale = val.value;
 
     trace = new CpuTiTgmr(TRACE_FIXED, val.value);
     m_powerScale = val.value;
 
     trace = new CpuTiTgmr(TRACE_FIXED, val.value);
-    XBT_DEBUG("value %lf", val.value);
+    XBT_DEBUG("value %f", val.value);
 
     p_availTrace = trace;
 
 
     p_availTrace = trace;
 
@@ -621,14 +650,16 @@ void CpuTi::updateState(tmgr_trace_event_t event_type,
       p_powerEvent = NULL;
 
   } else if (event_type == p_stateEvent) {
       p_powerEvent = NULL;
 
   } else if (event_type == p_stateEvent) {
-    if (value > 0)
+    if (value > 0) {
+      if(p_stateCurrent == SURF_RESOURCE_OFF)
+        xbt_dynar_push_as(host_that_restart, char*, (char *)m_name);
       p_stateCurrent = SURF_RESOURCE_ON;
       p_stateCurrent = SURF_RESOURCE_ON;
-    else {
+    else {
       p_stateCurrent = SURF_RESOURCE_OFF;
 
       /* put all action running on cpu to failed */
       xbt_swag_foreach(_action, p_actionSet) {
       p_stateCurrent = SURF_RESOURCE_OFF;
 
       /* put all action running on cpu to failed */
       xbt_swag_foreach(_action, p_actionSet) {
-       action = (CpuTiActionPtr) _action;
+       action = static_cast<CpuTiActionPtr>(_action);
         if (action->getState() == SURF_ACTION_RUNNING
          || action->getState() == SURF_ACTION_READY
          || action->getState() == SURF_ACTION_NOT_IN_THE_SYSTEM) {
         if (action->getState() == SURF_ACTION_RUNNING
          || action->getState() == SURF_ACTION_READY
          || action->getState() == SURF_ACTION_NOT_IN_THE_SYSTEM) {
@@ -663,10 +694,10 @@ void CpuTi::updateActionFinishDate(double now)
 updateRemainingAmount(now);
 
   xbt_swag_foreach(_action, p_actionSet) {
 updateRemainingAmount(now);
 
   xbt_swag_foreach(_action, p_actionSet) {
-    action = (CpuTiActionPtr) _action;
+    action = static_cast<CpuTiActionPtr>(_action);
     /* action not running, skip it */
     if (action->p_stateSet !=
     /* action not running, skip it */
     if (action->p_stateSet !=
-        surf_cpu_model->p_runningActionSet)
+        surf_cpu_model_pm->p_runningActionSet)
       continue;
 
     /* bogus priority, skip it */
       continue;
 
     /* bogus priority, skip it */
@@ -682,11 +713,11 @@ updateRemainingAmount(now);
   m_sumPriority = sum_priority;
 
   xbt_swag_foreach(_action, p_actionSet) {
   m_sumPriority = sum_priority;
 
   xbt_swag_foreach(_action, p_actionSet) {
-    action = (CpuTiActionPtr) _action;
+    action = static_cast<CpuTiActionPtr>(_action);
     min_finish = -1;
     /* action not running, skip it */
     if (action->p_stateSet !=
     min_finish = -1;
     /* action not running, skip it */
     if (action->p_stateSet !=
-        surf_cpu_model->p_runningActionSet)
+        surf_cpu_model_pm->p_runningActionSet)
       continue;
 
     /* verify if the action is really running on cpu */
       continue;
 
     /* verify if the action is really running on cpu */
@@ -722,7 +753,7 @@ updateRemainingAmount(now);
       xbt_heap_push(cpu_ti_action_heap, action, min_finish);
 
     XBT_DEBUG
       xbt_heap_push(cpu_ti_action_heap, action, min_finish);
 
     XBT_DEBUG
-        ("Update finish time: Cpu(%s) Action: %p, Start Time: %lf Finish Time: %lf Max duration %lf",
+        ("Update finish time: Cpu(%s) Action: %p, Start Time: %f Finish Time: %f Max duration %f",
          m_name, action, action->m_start,
          action->m_finish,
          action->m_maxDuration);
          m_name, action, action->m_start,
          action->m_finish,
          action->m_maxDuration);
@@ -731,11 +762,6 @@ updateRemainingAmount(now);
   xbt_swag_remove(this, cpu_ti_modified_cpu);
 }
 
   xbt_swag_remove(this, cpu_ti_modified_cpu);
 }
 
-CpuTiModelPtr CpuTi::getModel()
-{
-  return static_cast<CpuTiModelPtr>(p_model);
-}; 
-
 bool CpuTi::isUsed()
 {
   return xbt_swag_size(p_actionSet);
 bool CpuTi::isUsed()
 {
   return xbt_swag_size(p_actionSet);
@@ -766,11 +792,11 @@ void CpuTi::updateRemainingAmount(double now)
 
 /* calcule the surface */
   area_total = p_availTrace->integrate(m_lastUpdate, now) * m_powerPeak;
 
 /* calcule the surface */
   area_total = p_availTrace->integrate(m_lastUpdate, now) * m_powerPeak;
-  XBT_DEBUG("Flops total: %lf, Last update %lf", area_total,
+  XBT_DEBUG("Flops total: %f, Last update %f", area_total,
          m_lastUpdate);
 
   xbt_swag_foreach(_action, p_actionSet) {
          m_lastUpdate);
 
   xbt_swag_foreach(_action, p_actionSet) {
-    action = (CpuTiActionPtr) _action;
+    action = static_cast<CpuTiActionPtr>(_action);
     /* action not running, skip it */
     if (action->p_stateSet !=
         getModel()->p_runningActionSet)
     /* action not running, skip it */
     if (action->p_stateSet !=
         getModel()->p_runningActionSet)
@@ -797,7 +823,7 @@ void CpuTi::updateRemainingAmount(double now)
     double_update(&(action->m_remains),
                   area_total / (m_sumPriority *
                                 action->m_priority));
     double_update(&(action->m_remains),
                   area_total / (m_sumPriority *
                                 action->m_priority));
-    XBT_DEBUG("Update remaining action(%p) remaining %lf", action,
+    XBT_DEBUG("Update remaining action(%p) remaining %f", action,
            action->m_remains);
   }
   m_lastUpdate = now;
            action->m_remains);
   }
   m_lastUpdate = now;
@@ -805,13 +831,13 @@ void CpuTi::updateRemainingAmount(double now)
 
 CpuActionPtr CpuTi::execute(double size)
 {
 
 CpuActionPtr CpuTi::execute(double size)
 {
-  return execute(size);
+  return _execute(size);
 }
 
 CpuTiActionPtr CpuTi::_execute(double size)
 {
   XBT_IN("(%s,%g)", m_name, size);
 }
 
 CpuTiActionPtr CpuTi::_execute(double size)
 {
   XBT_IN("(%s,%g)", m_name, size);
-  CpuTiActionPtr action = new CpuTiAction((CpuTiModelPtr) p_model, size, p_stateCurrent != SURF_RESOURCE_ON);
+  CpuTiActionPtr action = new CpuTiAction(static_cast<CpuTiModelPtr>(p_model), size, p_stateCurrent != SURF_RESOURCE_ON);
 
   action->p_cpu = this;
   action->m_indexHeap = -1;
 
   action->p_cpu = this;
   action->m_indexHeap = -1;
@@ -821,7 +847,7 @@ CpuTiActionPtr CpuTi::_execute(double size)
   xbt_swag_insert(action, p_actionSet);
 
   action->m_suspended = 0;        /* Should be useless because of the
   xbt_swag_insert(action, p_actionSet);
 
   action->m_suspended = 0;        /* Should be useless because of the
-                                   calloc but it seems to help valgrind... */
+              ยป                     calloc but it seems to help valgrind... */
 
   XBT_OUT();
   return action;
 
   XBT_OUT();
   return action;
@@ -868,7 +894,7 @@ void CpuTiAction::updateIndexHeap(int i)
 void CpuTiAction::setState(e_surf_action_state_t state)
 {
   Action::setState(state);
 void CpuTiAction::setState(e_surf_action_state_t state)
 {
   Action::setState(state);
-  xbt_swag_insert(surf_cpu_resource_priv(p_cpu), cpu_ti_modified_cpu);
+  xbt_swag_insert(p_cpu, cpu_ti_modified_cpu);
 }
 
 int CpuTiAction::unref()
 }
 
 int CpuTiAction::unref()
@@ -877,10 +903,10 @@ int CpuTiAction::unref()
   if (!m_refcount) {
     xbt_swag_remove(static_cast<ActionPtr>(this), p_stateSet);
     /* remove from action_set */
   if (!m_refcount) {
     xbt_swag_remove(static_cast<ActionPtr>(this), p_stateSet);
     /* remove from action_set */
-    xbt_swag_remove(this, ((CpuTiPtr)surf_cpu_resource_priv(p_cpu))->p_actionSet);
+    xbt_swag_remove(this, p_cpu->p_actionSet);
     /* remove from heap */
     xbt_heap_remove(cpu_ti_action_heap, this->m_indexHeap);
     /* remove from heap */
     xbt_heap_remove(cpu_ti_action_heap, this->m_indexHeap);
-    xbt_swag_insert(surf_cpu_resource_priv(p_cpu), cpu_ti_modified_cpu);
+    xbt_swag_insert(p_cpu, cpu_ti_modified_cpu);
     delete this;
     return 1;
   }
     delete this;
     return 1;
   }
@@ -891,7 +917,7 @@ void CpuTiAction::cancel()
 {
   this->setState(SURF_ACTION_FAILED);
   xbt_heap_remove(cpu_ti_action_heap, this->m_indexHeap);
 {
   this->setState(SURF_ACTION_FAILED);
   xbt_heap_remove(cpu_ti_action_heap, this->m_indexHeap);
-  xbt_swag_insert(surf_cpu_resource_priv(p_cpu), cpu_ti_modified_cpu);
+  xbt_swag_insert(p_cpu, cpu_ti_modified_cpu);
   return;
 }
 
   return;
 }
 
@@ -906,7 +932,7 @@ void CpuTiAction::suspend()
   if (m_suspended != 2) {
     m_suspended = 1;
     xbt_heap_remove(cpu_ti_action_heap, m_indexHeap);
   if (m_suspended != 2) {
     m_suspended = 1;
     xbt_heap_remove(cpu_ti_action_heap, m_indexHeap);
-    xbt_swag_insert(surf_cpu_resource_priv(p_cpu), cpu_ti_modified_cpu);
+    xbt_swag_insert(p_cpu, cpu_ti_modified_cpu);
   }
   XBT_OUT();
 }
   }
   XBT_OUT();
 }
@@ -916,7 +942,7 @@ void CpuTiAction::resume()
   XBT_IN("(%p)", this);
   if (m_suspended != 2) {
     m_suspended = 0;
   XBT_IN("(%p)", this);
   if (m_suspended != 2) {
     m_suspended = 0;
-    xbt_swag_insert(surf_cpu_resource_priv(p_cpu), cpu_ti_modified_cpu);
+    xbt_swag_insert(p_cpu, cpu_ti_modified_cpu);
   }
   XBT_OUT();
 }
   }
   XBT_OUT();
 }
@@ -956,21 +982,17 @@ void CpuTiAction::setPriority(double priority)
 {
   XBT_IN("(%p,%g)", this, priority);
   m_priority = priority;
 {
   XBT_IN("(%p,%g)", this, priority);
   m_priority = priority;
-  xbt_swag_insert(surf_cpu_resource_priv(p_cpu), cpu_ti_modified_cpu);
+  xbt_swag_insert(p_cpu, cpu_ti_modified_cpu);
   XBT_OUT();
 }
 
 double CpuTiAction::getRemains()
 {
   XBT_IN("(%p)", this);
   XBT_OUT();
 }
 
 double CpuTiAction::getRemains()
 {
   XBT_IN("(%p)", this);
-  ((CpuTiPtr)p_cpu)->updateRemainingAmount(surf_get_clock());
+  p_cpu->updateRemainingAmount(surf_get_clock());
   XBT_OUT();
   return m_remains;
 }
 
   XBT_OUT();
   return m_remains;
 }
 
-static void check() {
-  CpuTiActionPtr cupAction = new CpuTiAction(NULL, 0, true);
-}
-
 #endif /* SURF_MODEL_CPUTI_H_ */
 
 #endif /* SURF_MODEL_CPUTI_H_ */