Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ns3: no need for 2 postparse callbacks
[simgrid.git] / src / surf / cpu_ti.cpp
index 2cc517e..4e7b6e6 100644 (file)
@@ -414,21 +414,9 @@ CpuTiModel::~CpuTiModel()
   xbt_heap_free(tiActionHeap_);
 }
 
-Cpu *CpuTiModel::createCpu(simgrid::s4u::Host *host,
-                         xbt_dynar_t speedPeak,
-                         int pstate,
-                           double speedScale,
-                           tmgr_trace_t speedTrace,
-                           int core,
-                           int initiallyOn,
-                           tmgr_trace_t stateTrace)
-{
-  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?");
-  CpuTi *cpu = new CpuTi(this, host, speedPeak, pstate, speedScale, speedTrace,
-               core, initiallyOn, stateTrace);
-  return cpu;
+Cpu *CpuTiModel::createCpu(simgrid::s4u::Host *host, xbt_dynar_t speedPerPstate, int core)
+{
+  return new CpuTi(this, host, speedPerPstate, core);
 }
 
 double CpuTiModel::next_occuring_event(double now)
@@ -461,7 +449,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());
   }
@@ -470,62 +458,45 @@ void CpuTiModel::updateActionsState(double now, double /*delta*/)
 /************
  * Resource *
  ************/
-CpuTi::CpuTi(CpuTiModel *model, simgrid::s4u::Host *host, xbt_dynar_t speedPeak,
-        int pstate, double speedScale, tmgr_trace_t speedTrace, int core,
-        int initiallyOn, tmgr_trace_t stateTrace)
-  : Cpu(model, host, NULL, pstate, core, 0, speedScale, initiallyOn)
+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");
-  m_core = core;
-
-  p_speed.scale = speedScale;
-  availTrace_ = new CpuTiTgmr(speedTrace, speedScale);
+  coresAmount_ = core;
 
   actionSet_ = new ActionTiList();
 
-  xbt_dynar_get_cpy(speedPeak, 0, &p_speed.peak);
-  XBT_DEBUG("CPU create: peak=%f", p_speed.peak);
-
-  if (stateTrace)
-    p_stateEvent = future_evt_set->add_trace(stateTrace, 0.0, this);
+  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) {
-      p_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::set_speed_trace(tmgr_trace_t trace)
+void CpuTi::setSpeedTrace(tmgr_trace_t trace)
 {
-  if (availTrace_)
-    delete availTrace_;
+  if (speedIntegratedTrace_)
+    delete speedIntegratedTrace_;
 
-  availTrace_ = new CpuTiTgmr(trace, p_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) {
     s_tmgr_event_t val;
     xbt_dynar_get_cpy(trace->event_list, xbt_dynar_length(trace->event_list) - 1, &val);
     if (val.delta == 0)
-      p_speed.event = future_evt_set->add_trace(tmgr_empty_trace_new(), 0.0, this);
+      speed_.event = future_evt_set->add_trace(tmgr_empty_trace_new(), 0.0, this);
   }
 }
 
 void CpuTi::apply_event(tmgr_trace_iterator_t event, double value)
 {
-  if (event == p_speed.event) {
+  if (event == speed_.event) {
     tmgr_trace_t speedTrace;
     CpuTiTgmr *trace;
     s_tmgr_event_t val;
@@ -536,19 +507,19 @@ 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_;
-    p_speed.scale = val.value;
+    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(&p_speed.event);
+    tmgr_trace_event_unref(&speed_.event);
 
-  } else if (event == p_stateEvent) {
+  } else if (event == stateEvent_) {
     if (value > 0) {
       if(isOff())
         xbt_dynar_push_as(host_that_restart, char*, (char *)getName());
@@ -562,11 +533,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_);
@@ -576,7 +547,7 @@ void CpuTi::apply_event(tmgr_trace_iterator_t event, double value)
         }
       }
     }
-    tmgr_trace_event_unref(&p_stateEvent);
+    tmgr_trace_event_unref(&stateEvent_);
 
   } else {
     xbt_die("Unknown event!\n");
@@ -624,9 +595,9 @@ void CpuTi::updateActionsFinishTime(double now)
           (action->getRemains()) * sum_priority *
            action->getPriority();
 
-      total_area /= p_speed.peak;
+      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)
@@ -666,7 +637,7 @@ bool CpuTi::isUsed()
 
 double CpuTi::getAvailableSpeed()
 {
-  p_speed.scale = availTrace_->getPowerScale(surf_get_clock());
+  speed_.scale = speedIntegratedTrace_->getPowerScale(surf_get_clock());
   return Cpu::getAvailableSpeed();
 }
 
@@ -679,7 +650,7 @@ void CpuTi::updateRemainingAmount(double now)
     return;
 
   /* compute the integration area */
-  double area_total = availTrace_->integrate(lastUpdate_, now) * p_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) {
@@ -777,7 +748,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);
@@ -803,7 +774,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;