Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
CpuCas01: set updateAlgo as initializer
[simgrid.git] / src / surf / cpu_ti.cpp
index 6cf864c..c04b25a 100644 (file)
@@ -336,7 +336,7 @@ Cpu *CpuTiModel::createCpu(simgrid::s4u::Host *host, std::vector<double>* speedP
   return new CpuTi(this, host, speedPerPstate, core);
 }
 
-double CpuTiModel::nextOccuringEvent(double now)
+double CpuTiModel::next_occuring_event(double now)
 {
   double min_action_duration = -1;
 
@@ -356,14 +356,12 @@ double CpuTiModel::nextOccuringEvent(double now)
   return min_action_duration;
 }
 
-void CpuTiModel::updateActionsState(double now, double /*delta*/)
+void CpuTiModel::update_actions_state(double now, double /*delta*/)
 {
   while (not actionHeapIsEmpty() && actionHeapTopDate() <= now) {
     CpuTiAction* action = static_cast<CpuTiAction*>(actionHeapPop());
     XBT_DEBUG("Action %p: finish", action);
     action->finish(kernel::resource::Action::State::done);
-    /* set the remains to 0 due to precision problems when updating the remaining amount */
-    action->set_remains(0);
     /* update remaining amount of all actions */
     action->cpu_->updateRemainingAmount(surf_get_clock());
   }
@@ -375,8 +373,7 @@ void CpuTiModel::updateActionsState(double now, double /*delta*/)
 CpuTi::CpuTi(CpuTiModel *model, simgrid::s4u::Host *host, std::vector<double> *speedPerPstate, int core)
   : Cpu(model, host, speedPerPstate, core)
 {
-  xbt_assert(core==1,"Multi-core not handled by this model yet");
-  coresAmount_ = core;
+  xbt_assert(core == 1, "Multi-core not handled by this model yet");
 
   speed_.peak = speedPerPstate->front();
   XBT_DEBUG("CPU create: peak=%f", speed_.peak);
@@ -444,7 +441,7 @@ void CpuTi::apply_event(tmgr_trace_event_t event, double value)
             action.get_state() == kernel::resource::Action::State::not_in_the_system) {
           action.set_finish_time(date);
           action.set_state(kernel::resource::Action::State::failed);
-          action.heapRemove(model()->getActionHeap());
+          action.heapRemove();
         }
       }
     }
@@ -465,7 +462,7 @@ void CpuTi::updateActionsFinishTime(double now)
 
   for (CpuTiAction const& action : actionSet_) {
     /* action not running, skip it */
-    if (action.get_state_set() != surf_cpu_model_pm->getRunningActionSet())
+    if (action.get_state_set() != surf_cpu_model_pm->get_running_action_set())
       continue;
 
     /* bogus priority, skip it */
@@ -483,7 +480,7 @@ void CpuTi::updateActionsFinishTime(double now)
   for (CpuTiAction& action : actionSet_) {
     double min_finish = -1;
     /* action not running, skip it */
-    if (action.get_state_set() != surf_cpu_model_pm->getRunningActionSet())
+    if (action.get_state_set() != surf_cpu_model_pm->get_running_action_set())
       continue;
 
     /* verify if the action is really running on cpu */
@@ -496,10 +493,10 @@ void CpuTi::updateActionsFinishTime(double now)
       action.set_finish_time(speedIntegratedTrace_->solve(now, total_area));
       /* verify which event will happen before (max_duration or finish time) */
       if (action.get_max_duration() > NO_MAX_DURATION &&
-          action.get_start_time() + action.get_max_duration() < action.getFinishTime())
+          action.get_start_time() + action.get_max_duration() < action.get_finish_time())
         min_finish = action.get_start_time() + action.get_max_duration();
       else
-        min_finish = action.getFinishTime();
+        min_finish = action.get_finish_time();
     } else {
       /* put the max duration time on heap */
       if (action.get_max_duration() > NO_MAX_DURATION)
@@ -507,12 +504,12 @@ void CpuTi::updateActionsFinishTime(double now)
     }
     /* add in action heap */
     if (min_finish > NO_MAX_DURATION)
-      action.heapUpdate(model()->getActionHeap(), min_finish, kernel::resource::Action::Type::NOTSET);
+      action.heapUpdate(min_finish, kernel::resource::Action::Type::NOTSET);
     else
-      action.heapRemove(model()->getActionHeap());
+      action.heapRemove();
 
     XBT_DEBUG("Update finish time: Cpu(%s) Action: %p, Start Time: %f Finish Time: %f Max duration %f", getCname(),
-              &action, action.get_start_time(), action.getFinishTime(), action.get_max_duration());
+              &action, action.get_start_time(), action.get_finish_time(), action.get_max_duration());
   }
   /* remove from modified cpu */
   modified(false);
@@ -542,7 +539,7 @@ void CpuTi::updateRemainingAmount(double now)
   XBT_DEBUG("Flops total: %f, Last update %f", area_total, lastUpdate_);
   for (CpuTiAction& action : actionSet_) {
     /* action not running, skip it */
-    if (action.get_state_set() != model()->getRunningActionSet())
+    if (action.get_state_set() != model()->get_running_action_set())
       continue;
 
     /* bogus priority, skip it */
@@ -558,7 +555,7 @@ void CpuTi::updateRemainingAmount(double now)
       continue;
 
     /* skip action that are finishing now */
-    if (action.getFinishTime() >= 0 && action.getFinishTime() <= now)
+    if (action.get_finish_time() >= 0 && action.get_finish_time() <= now)
       continue;
 
     /* update remaining */
@@ -625,35 +622,26 @@ CpuTiAction::CpuTiAction(CpuTiModel *model_, double cost, bool failed, CpuTi *cp
 {
   cpu_->modified(true);
 }
-
-void CpuTiAction::set_state(Action::State state)
+CpuTiAction::~CpuTiAction()
 {
-  CpuAction::set_state(state);
+  /* remove from action_set */
+  if (action_ti_hook.is_linked())
+    simgrid::xbt::intrusive_erase(cpu_->actionSet_, *this);
+  /* remove from heap */
+  heapRemove();
   cpu_->modified(true);
 }
 
-int CpuTiAction::unref()
+void CpuTiAction::set_state(Action::State state)
 {
-  refcount_--;
-  if (not refcount_) {
-    if (state_set_hook_.is_linked())
-      simgrid::xbt::intrusive_erase(*get_state_set(), *this);
-    /* remove from action_set */
-    if (action_ti_hook.is_linked())
-      simgrid::xbt::intrusive_erase(cpu_->actionSet_, *this);
-    /* remove from heap */
-    heapRemove(get_model()->getActionHeap());
-    cpu_->modified(true);
-    delete this;
-    return 1;
-  }
-  return 0;
+  CpuAction::set_state(state);
+  cpu_->modified(true);
 }
 
 void CpuTiAction::cancel()
 {
   this->set_state(Action::State::failed);
-  heapRemove(get_model()->getActionHeap());
+  heapRemove();
   cpu_->modified(true);
 }
 
@@ -662,7 +650,7 @@ void CpuTiAction::suspend()
   XBT_IN("(%p)", this);
   if (suspended_ != Action::SuspendStates::sleeping) {
     suspended_ = Action::SuspendStates::suspended;
-    heapRemove(get_model()->getActionHeap());
+    heapRemove();
     cpu_->modified(true);
   }
   XBT_OUT();
@@ -687,13 +675,13 @@ void CpuTiAction::set_max_duration(double duration)
   Action::set_max_duration(duration);
 
   if (duration >= 0)
-    min_finish = (get_start_time() + get_max_duration()) < getFinishTime() ? (get_start_time() + get_max_duration())
-                                                                           : getFinishTime();
+    min_finish = (get_start_time() + get_max_duration()) < get_finish_time() ? (get_start_time() + get_max_duration())
+                                                                             : get_finish_time();
   else
-    min_finish = getFinishTime();
+    min_finish = get_finish_time();
 
   /* add in action heap */
-  heapUpdate(get_model()->getActionHeap(), min_finish, Action::Type::NOTSET);
+  heapUpdate(min_finish, Action::Type::NOTSET);
 
   XBT_OUT();
 }