Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix a leak in XML parsing
[simgrid.git] / src / surf / cpu_ti.cpp
index 0bf0d25..8cde051 100644 (file)
@@ -68,7 +68,6 @@ CpuTiTgmr::~CpuTiTgmr()
 * Wrapper around surf_cpu_integrate_trace_simple() to get
 * the cyclic effect.
 *
-* \param trace Trace structure.
 * \param a      Begin of interval
 * \param b      End of interval
 * \return the integrate value. -1 if an error occurs.
@@ -253,7 +252,6 @@ double CpuTiTgmr::solveSomewhatSimple(double a, double amount)
 /**
  * \brief Auxiliary function to solve integral.
  *  It returns the date when the requested amount of flops is available
- * \param trace    Trace structure
  * \param a        Initial point
  * \param amount  Amount of flops
  * \return The date when amount is available.
@@ -280,7 +278,6 @@ double CpuTiTrace::solveSimple(double a, double amount)
 * \brief Auxiliary function to update the CPU speed scale.
 *
 *  This function uses the trace structure to return the speed scale at the determined time a.
-* \param trace    Trace structure to search the updated speed scale
 * \param a        Time
 * \return CPU speed scale
 */
@@ -302,7 +299,6 @@ double CpuTiTgmr::getPowerScale(double a)
 *
 * \param  speedTrace    CPU availability trace
 * \param  value          Percentage of CPU speed available (useful to fixed tracing)
-* \param  spacing        Initial spacing
 * \return  Integration trace structure
 */
 CpuTiTgmr::CpuTiTgmr(tmgr_trace_t speedTrace, double value)
@@ -414,15 +410,9 @@ CpuTiModel::~CpuTiModel()
   xbt_heap_free(tiActionHeap_);
 }
 
-Cpu *CpuTiModel::createCpu(simgrid::s4u::Host *host,
-    xbt_dynar_t speedPeak,
-    tmgr_trace_t speedTrace,
-    int core)
+Cpu *CpuTiModel::createCpu(simgrid::s4u::Host *host, xbt_dynar_t speedPerPstate, int core)
 {
-  xbt_assert(core==1,"Multi-core not handled with this model yet");
-  xbt_assert(xbt_dynar_getfirst_as(speedPeak, double) > 0.0,
-      "Speed has to be >0.0. Did you forget to specify the mandatory speed attribute?");
-  return new CpuTi(this, host, speedPeak, speedTrace, core);
+  return new CpuTi(this, host, speedPerPstate, core);
 }
 
 double CpuTiModel::next_occuring_event(double now)
@@ -455,7 +445,7 @@ void CpuTiModel::updateActionsState(double now, double /*delta*/)
     action->finish();
     /* set the remains to 0 due to precision problems when updating the remaining amount */
     action->setRemains(0);
-    action->setState(SURF_ACTION_DONE);
+    action->setState(Action::State::done);
     /* update remaining amount of all actions */
     action->cpu_->updateRemainingAmount(surf_get_clock());
   }
@@ -464,41 +454,32 @@ void CpuTiModel::updateActionsState(double now, double /*delta*/)
 /************
  * Resource *
  ************/
-CpuTi::CpuTi(CpuTiModel *model, simgrid::s4u::Host *host, xbt_dynar_t speedPeak,
-        tmgr_trace_t speedTrace, int core)
-  : Cpu(model, host, NULL, core, 0)
+CpuTi::CpuTi(CpuTiModel *model, simgrid::s4u::Host *host, xbt_dynar_t speedPerPstate, int core)
+  : Cpu(model, host, speedPerPstate, core)
 {
   xbt_assert(core==1,"Multi-core not handled by this model yet");
   coresAmount_ = core;
 
-  availTrace_ = new CpuTiTgmr(speedTrace, 1/*scale*/);
-
   actionSet_ = new ActionTiList();
 
-  xbt_dynar_get_cpy(speedPeak, 0, &speed_.peak);
+  xbt_dynar_get_cpy(speedPerPstate, 0, &speed_.peak);
   XBT_DEBUG("CPU create: peak=%f", speed_.peak);
 
-  if (speedTrace && xbt_dynar_length(speedTrace->event_list) > 1) {
-    s_tmgr_event_t val;
-    // add a fake trace event if periodicity == 0
-    xbt_dynar_get_cpy(speedTrace->event_list,  xbt_dynar_length(speedTrace->event_list) - 1, &val);
-    if (val.delta == 0)
-      speed_.event = future_evt_set->add_trace(tmgr_empty_trace_new(), availTrace_->lastTime_, this);
-  }
+  speedIntegratedTrace_ = new CpuTiTgmr(NULL, 1/*scale*/);
 }
 
 CpuTi::~CpuTi()
 {
   modified(false);
-  delete availTrace_;
+  delete speedIntegratedTrace_;
   delete actionSet_;
 }
 void CpuTi::setSpeedTrace(tmgr_trace_t trace)
 {
-  if (availTrace_)
-    delete availTrace_;
+  if (speedIntegratedTrace_)
+    delete speedIntegratedTrace_;
 
-  availTrace_ = new CpuTiTgmr(trace, speed_.scale);
+  speedIntegratedTrace_ = new CpuTiTgmr(trace, speed_.scale);
 
   /* add a fake trace event if periodicity == 0 */
   if (trace && xbt_dynar_length(trace->event_list) > 1) {
@@ -522,15 +503,15 @@ void CpuTi::apply_event(tmgr_trace_iterator_t event, double value)
 
     modified(true);
 
-    speedTrace = availTrace_->speedTrace_;
+    speedTrace = speedIntegratedTrace_->speedTrace_;
     xbt_dynar_get_cpy(speedTrace->event_list, xbt_dynar_length(speedTrace->event_list) - 1, &val);
-    delete availTrace_;
+    delete speedIntegratedTrace_;
     speed_.scale = val.value;
 
     trace = new CpuTiTgmr(TRACE_FIXED, val.value);
     XBT_DEBUG("value %f", val.value);
 
-    availTrace_ = trace;
+    speedIntegratedTrace_ = trace;
 
     tmgr_trace_event_unref(&speed_.event);
 
@@ -548,11 +529,11 @@ void CpuTi::apply_event(tmgr_trace_iterator_t event, double value)
           ; it != itend ; ++it) {
 
         CpuTiAction *action = &*it;
-        if (action->getState() == SURF_ACTION_RUNNING
-         || action->getState() == SURF_ACTION_READY
-         || action->getState() == SURF_ACTION_NOT_IN_THE_SYSTEM) {
+        if (action->getState() == Action::State::running
+         || action->getState() == Action::State::ready
+         || action->getState() == Action::State::not_in_the_system) {
           action->setFinishTime(date);
-          action->setState(SURF_ACTION_FAILED);
+          action->setState(Action::State::failed);
           if (action->indexHeap_ >= 0) {
             CpuTiAction *heap_act = (CpuTiAction*)
                 xbt_heap_remove(static_cast<CpuTiModel*>(getModel())->tiActionHeap_, action->indexHeap_);
@@ -612,13 +593,13 @@ void CpuTi::updateActionsFinishTime(double now)
 
       total_area /= speed_.peak;
 
-      action->setFinishTime(availTrace_->solve(now, total_area));
+      action->setFinishTime(speedIntegratedTrace_->solve(now, total_area));
       /* verify which event will happen before (max_duration or finish time) */
       if (action->getMaxDuration() != NO_MAX_DURATION &&
-          action->getStartTime() + action->getMaxDuration() < action->m_finish)
+          action->getStartTime() + action->getMaxDuration() < action->finishTime_)
         min_finish = action->getStartTime() + action->getMaxDuration();
       else
-        min_finish = action->m_finish;
+        min_finish = action->finishTime_;
     } else {
       /* put the max duration time on heap */
       if (action->getMaxDuration() != NO_MAX_DURATION)
@@ -638,7 +619,7 @@ void CpuTi::updateActionsFinishTime(double now)
     XBT_DEBUG
         ("Update finish time: Cpu(%s) Action: %p, Start Time: %f Finish Time: %f Max duration %f",
          getName(), action, action->getStartTime(),
-         action->m_finish,
+         action->finishTime_,
          action->getMaxDuration());
   }
   /* remove from modified cpu */
@@ -652,7 +633,7 @@ bool CpuTi::isUsed()
 
 double CpuTi::getAvailableSpeed()
 {
-  speed_.scale = availTrace_->getPowerScale(surf_get_clock());
+  speed_.scale = speedIntegratedTrace_->getPowerScale(surf_get_clock());
   return Cpu::getAvailableSpeed();
 }
 
@@ -665,7 +646,7 @@ void CpuTi::updateRemainingAmount(double now)
     return;
 
   /* compute the integration area */
-  double area_total = availTrace_->integrate(lastUpdate_, now) * speed_.peak;
+  double area_total = speedIntegratedTrace_->integrate(lastUpdate_, now) * speed_.peak;
   XBT_DEBUG("Flops total: %f, Last update %f", area_total, lastUpdate_);
 
   for(ActionTiList::iterator it(actionSet_->begin()), itend(actionSet_->end()) ; it != itend ; ++it) {
@@ -687,12 +668,12 @@ void CpuTi::updateRemainingAmount(double now)
       continue;
 
     /* skip action that are finishing now */
-    if (action->m_finish >= 0 && action->m_finish <= now)
+    if (action->finishTime_ >= 0 && action->finishTime_ <= now)
       continue;
 
     /* update remaining */
     action->updateRemains(area_total / (sumPriority_ * action->getPriority()));
-    XBT_DEBUG("Update remaining action(%p) remaining %f", action, action->m_remains);
+    XBT_DEBUG("Update remaining action(%p) remaining %f", action, action->remains_);
   }
   lastUpdate_ = now;
 }
@@ -717,13 +698,13 @@ CpuAction *CpuTi::sleep(double duration)
   XBT_IN("(%s,%g)", getName(), duration);
   CpuTiAction *action = new CpuTiAction(static_cast<CpuTiModel*>(getModel()), 1.0, isOff(), this);
 
-  action->m_maxDuration = duration;
+  action->maxDuration_ = duration;
   action->suspended_ = 2;
   if (duration == NO_MAX_DURATION) {
    /* Move to the *end* of the corresponding action set. This convention
       is used to speed up update_resource_state  */
   action->getStateSet()->erase(action->getStateSet()->iterator_to(*action));
-    action->p_stateSet = static_cast<CpuTiModel*>(getModel())->runningActionSetThatDoesNotNeedBeingChecked_;
+    action->stateSet_ = static_cast<CpuTiModel*>(getModel())->runningActionSetThatDoesNotNeedBeingChecked_;
     action->getStateSet()->push_back(*action);
   }
 
@@ -763,7 +744,7 @@ void CpuTiAction::updateIndexHeap(int i)
   indexHeap_ = i;
 }
 
-void CpuTiAction::setState(e_surf_action_state_t state)
+void CpuTiAction::setState(Action::State state)
 {
   CpuAction::setState(state);
   cpu_->modified(true);
@@ -771,8 +752,8 @@ void CpuTiAction::setState(e_surf_action_state_t state)
 
 int CpuTiAction::unref()
 {
-  m_refcount--;
-  if (!m_refcount) {
+  refcount_--;
+  if (!refcount_) {
     if (action_hook.is_linked())
       getStateSet()->erase(getStateSet()->iterator_to(*this));
     /* remove from action_set */
@@ -789,7 +770,7 @@ int CpuTiAction::unref()
 
 void CpuTiAction::cancel()
 {
-  this->setState(SURF_ACTION_FAILED);
+  this->setState(Action::State::failed);
   xbt_heap_remove(getModel()->getActionHeap(), this->indexHeap_);
   cpu_->modified(true);
   return;
@@ -822,7 +803,7 @@ void CpuTiAction::setMaxDuration(double duration)
 
   XBT_IN("(%p,%g)", this, duration);
 
-  m_maxDuration = duration;
+  maxDuration_ = duration;
 
   if (duration >= 0)
     min_finish = (getStartTime() + getMaxDuration()) < getFinishTime() ?
@@ -845,7 +826,7 @@ void CpuTiAction::setMaxDuration(double duration)
 void CpuTiAction::setPriority(double priority)
 {
   XBT_IN("(%p,%g)", this, priority);
-  m_priority = priority;
+  priority_ = priority;
   cpu_->modified(true);
   XBT_OUT();
 }
@@ -855,7 +836,7 @@ double CpuTiAction::getRemains()
   XBT_IN("(%p)", this);
   cpu_->updateRemainingAmount(surf_get_clock());
   XBT_OUT();
-  return m_remains;
+  return remains_;
 }
 
 }