Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
make Cpu::speed a surf_metric
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 7 Feb 2016 23:39:35 +0000 (00:39 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Sun, 7 Feb 2016 23:46:46 +0000 (00:46 +0100)
src/surf/cpu_cas01.cpp
src/surf/cpu_interface.cpp
src/surf/cpu_interface.hpp
src/surf/cpu_ti.cpp
src/surf/host_ptask_L07.cpp
src/surf/plugins/energy.cpp

index e05b75e..6c8f440 100644 (file)
@@ -138,11 +138,11 @@ CpuCas01::CpuCas01(CpuCas01Model *model, simgrid::s4u::Host *host, xbt_dynar_t s
   core, xbt_dynar_get_as(speedPeak, pstate, double), speedScale,
     initiallyOn) {
 
-  XBT_DEBUG("CPU create: peak=%f, pstate=%d", m_speedPeak, m_pstate);
+  XBT_DEBUG("CPU create: peak=%f, pstate=%d", p_speed.peak, m_pstate);
 
   m_core = core;
   if (speedTrace)
-    p_speedEvent = future_evt_set->add_trace(speedTrace, 0.0, this);
+    p_speed.event = future_evt_set->add_trace(speedTrace, 0.0, this);
 
   if (stateTrace)
     p_stateEvent = future_evt_set->add_trace(stateTrace, 0.0, this);
@@ -169,33 +169,33 @@ void CpuCas01::onSpeedChange() {
   lmm_element_t elem = NULL;
 
     lmm_update_constraint_bound(getModel()->getMaxminSystem(), getConstraint(),
-                                m_core * m_speedScale * m_speedPeak);
+                                m_core * p_speed.scale * p_speed.peak);
     while ((var = lmm_get_var_from_cnst
             (getModel()->getMaxminSystem(), getConstraint(), &elem))) {
       CpuCas01Action *action = static_cast<CpuCas01Action*>(lmm_variable_id(var));
 
       lmm_update_variable_bound(getModel()->getMaxminSystem(),
                                 action->getVariable(),
-                                m_speedScale * m_speedPeak);
+                                p_speed.scale * p_speed.peak);
     }
 
   Cpu::onSpeedChange();
 }
 
-void CpuCas01::apply_event(tmgr_trace_iterator_t event_type, double value)
+void CpuCas01::apply_event(tmgr_trace_iterator_t event, double value)
 {
   lmm_variable_t var = NULL;
   lmm_element_t elem = NULL;
 
-  if (event_type == p_speedEvent) {
+  if (event == p_speed.event) {
     /* TODO (Hypervisor): do the same thing for constraint_core[i] */
     xbt_assert(m_core == 1, "FIXME: add speed scaling code also for constraint_core[i]");
 
-    m_speedScale = value;
+    p_speed.scale = value;
     onSpeedChange();
 
-    tmgr_trace_event_unref(&p_speedEvent);
-  } else if (event_type == p_stateEvent) {
+    tmgr_trace_event_unref(&p_speed.event);
+  } else if (event == p_stateEvent) {
     /* TODO (Hypervisor): do the same thing for constraint_core[i] */
     xbt_assert(m_core == 1, "FIXME: add state change code also for constraint_core[i]");
 
@@ -233,7 +233,7 @@ CpuAction *CpuCas01::execution_start(double size)
 
   XBT_IN("(%s,%g)", getName(), size);
   CpuCas01Action *action = new CpuCas01Action(getModel(), size, isOff(),
-      m_speedScale * m_speedPeak, getConstraint());
+      p_speed.scale * p_speed.peak, getConstraint());
 
   XBT_OUT();
   return action;
@@ -246,7 +246,7 @@ CpuAction *CpuCas01::sleep(double duration)
 
   XBT_IN("(%s,%g)", getName(), duration);
   CpuCas01Action *action = new CpuCas01Action(getModel(), 1.0, isOff(),
-      m_speedScale * m_speedPeak, getConstraint());
+      p_speed.scale * p_speed.peak, getConstraint());
 
 
   // FIXME: sleep variables should not consume 1.0 in lmm_expand
index 7629b04..50b4ee1 100644 (file)
@@ -141,12 +141,12 @@ Cpu::Cpu(Model *model, simgrid::s4u::Host *host, lmm_constraint_t constraint,
         double speedScale, int initiallyOn)
  : Resource(model, host->name().c_str(), constraint, initiallyOn)
  , m_core(core)
- , m_speedPeak(speedPeak)
- , m_speedScale(speedScale)
  , m_host(host)
 {
+  p_speed.peak = speedPeak;
+  p_speed.scale = speedScale;
   host->pimpl_cpu = this;
-  xbt_assert(m_speedScale > 0, "Available speed has to be >0");
+  xbt_assert(p_speed.scale > 0, "Available speed has to be >0");
 
   // Copy the power peak array:
   p_speedPeakList = xbt_dynar_new(sizeof(double), nullptr);
@@ -170,7 +170,7 @@ Cpu::Cpu(Model *model, simgrid::s4u::Host *host, lmm_constraint_t constraint,
     for (i = 0; i < core; i++) {
       /* just for a unique id, never used as a string. */
       p_constraintCoreId[i] = bprintf("%s:%i", host->name().c_str(), i);
-      p_constraintCore[i] = lmm_constraint_new(model->getMaxminSystem(), p_constraintCoreId[i], m_speedScale * m_speedPeak);
+      p_constraintCore[i] = lmm_constraint_new(model->getMaxminSystem(), p_constraintCoreId[i], p_speed.scale * p_speed.peak);
     }
   }
 }
@@ -191,7 +191,7 @@ Cpu::~Cpu()
 
 double Cpu::getCurrentPowerPeak()
 {
-  return m_speedPeak;
+  return p_speed.peak;
 }
 
 int Cpu::getNbPStates()
@@ -207,7 +207,7 @@ void Cpu::setPState(int pstate_index)
 
   double new_peak_speed = xbt_dynar_get_as(plist, pstate_index, double);
   m_pstate = pstate_index;
-  m_speedPeak = new_peak_speed;
+  p_speed.peak = new_peak_speed;
 
   onSpeedChange();
 }
@@ -227,18 +227,18 @@ double Cpu::getPowerPeakAt(int pstate_index)
 
 double Cpu::getSpeed(double load)
 {
-  return load * m_speedPeak;
+  return load * p_speed.peak;
 }
 
 double Cpu::getAvailableSpeed()
 {
 /* number between 0 and 1 */
-  return m_speedScale;
+  return p_speed.scale;
 }
 
 void Cpu::onSpeedChange() {
   TRACE_surf_host_set_speed(surf_get_clock(), getName(),
-      m_core * m_speedScale * m_speedPeak);
+      m_core * p_speed.scale * p_speed.peak);
 }
 
 
@@ -255,9 +255,9 @@ void Cpu::set_state_trace(tmgr_trace_t trace)
 }
 void Cpu::set_speed_trace(tmgr_trace_t trace)
 {
-  xbt_assert(p_speedEvent==NULL,"Cannot set a second speed trace to Host %s", m_host->name().c_str());
+  xbt_assert(p_speed.event==NULL,"Cannot set a second speed trace to Host %s", m_host->name().c_str());
 
-  p_speedEvent = future_evt_set->add_trace(trace, 0.0, this);
+  p_speed.event = future_evt_set->add_trace(trace, 0.0, this);
 }
 
 
index baa184b..91b9b40 100644 (file)
@@ -153,8 +153,6 @@ public:
 
 public:
   int m_core = 1;                /* Amount of cores */
-  double m_speedPeak;            /*< CPU speed peak, ie max value */
-  double m_speedScale;           /*< Percentage of CPU available according to the trace, in [O,1] */
   simgrid::s4u::Host* m_host;
 
   xbt_dynar_t p_speedPeakList = NULL; /*< List of supported CPU capacities (pstate related) */
@@ -167,9 +165,9 @@ public:
 public:
   void set_state_trace(tmgr_trace_t trace); /*< setup the trace file with states events (ON or OFF) */
   void set_speed_trace(tmgr_trace_t trace); /*< setup the trace file with availability events (peak speed changes due to external load) */
-protected:
+
   tmgr_trace_iterator_t p_stateEvent = nullptr;
-  tmgr_trace_iterator_t p_speedEvent = nullptr;
+  s_surf_metric_t p_speed = {1.0, 0, nullptr};
 };
 
 /**********
index 5169617..a08d080 100644 (file)
@@ -514,13 +514,13 @@ CpuTi::CpuTi(CpuTiModel *model, simgrid::s4u::Host *host, xbt_dynar_t speedPeak,
   xbt_assert(core==1,"Multi-core not handled by this model yet");
   m_core = core;
 
-  m_speedScale = speedScale;
+  p_speed.scale = speedScale;
   p_availTrace = new CpuTiTgmr(speedTrace, speedScale);
 
   p_actionSet = new ActionTiList();
 
-  xbt_dynar_get_cpy(speedPeak, 0, &m_speedPeak);
-  XBT_DEBUG("CPU create: peak=%f", m_speedPeak);
+  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);
@@ -531,7 +531,7 @@ CpuTi::CpuTi(CpuTiModel *model, simgrid::s4u::Host *host, xbt_dynar_t speedPeak,
     xbt_dynar_get_cpy(speedTrace->event_list,
                       xbt_dynar_length(speedTrace->event_list) - 1, &val);
     if (val.delta == 0) {
-      p_speedEvent =
+      p_speed.event =
           future_evt_set->add_trace(tmgr_empty_trace_new(), p_availTrace->m_lastTime, this);
     }
   }
@@ -548,24 +548,22 @@ void CpuTi::set_speed_trace(tmgr_trace_t trace)
   if (p_availTrace)
     delete p_availTrace;
 
-  p_availTrace = new CpuTiTgmr(trace, m_speedScale);
+  p_availTrace = new CpuTiTgmr(trace, p_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_speedEvent = future_evt_set->add_trace(tmgr_empty_trace_new(), 0.0, this);
-    }
+    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);
   }
 }
 
-void CpuTi::apply_event(tmgr_trace_iterator_t event_type, double value)
+void CpuTi::apply_event(tmgr_trace_iterator_t event, double value)
 {
   CpuTiAction *action;
 
-  if (event_type == p_speedEvent) {
+  if (event == p_speed.event) {
     tmgr_trace_t speedTrace;
     CpuTiTgmr *trace;
     s_tmgr_event_t val;
@@ -581,16 +579,16 @@ void CpuTi::apply_event(tmgr_trace_iterator_t event_type, double value)
                       xbt_dynar_length(speedTrace->event_list) - 1, &val);
     /* free old trace */
     delete p_availTrace;
-    m_speedScale = val.value;
+    p_speed.scale = val.value;
 
     trace = new CpuTiTgmr(TRACE_FIXED, val.value);
     XBT_DEBUG("value %f", val.value);
 
     p_availTrace = trace;
 
-    tmgr_trace_event_unref(&p_speedEvent);
+    tmgr_trace_event_unref(&p_speed.event);
 
-  } else if (event_type == p_stateEvent) {
+  } else if (event == p_stateEvent) {
     if (value > 0) {
       if(isOff())
         xbt_dynar_push_as(host_that_restart, char*, (char *)getName());
@@ -667,7 +665,7 @@ void CpuTi::updateActionsFinishTime(double now)
           (action->getRemains()) * sum_priority *
            action->getPriority();
 
-      total_area /= m_speedPeak;
+      total_area /= p_speed.peak;
 
       action->setFinishTime(p_availTrace->solve(now, total_area));
       /* verify which event will happen before (max_duration or finish time) */
@@ -709,7 +707,7 @@ bool CpuTi::isUsed()
 
 double CpuTi::getAvailableSpeed()
 {
-  m_speedScale = p_availTrace->getPowerScale(surf_get_clock());
+  p_speed.scale = p_availTrace->getPowerScale(surf_get_clock());
   return Cpu::getAvailableSpeed();
 }
 
@@ -724,7 +722,7 @@ void CpuTi::updateRemainingAmount(double now)
     return;
 
   /* compute the integration area */
-  area_total = p_availTrace->integrate(m_lastUpdate, now) * m_speedPeak;
+  area_total = p_availTrace->integrate(m_lastUpdate, now) * p_speed.peak;
   XBT_DEBUG("Flops total: %f, Last update %f", area_total,
          m_lastUpdate);
 
index a02f7b5..2280340 100644 (file)
@@ -397,7 +397,7 @@ CpuL07::CpuL07(CpuL07Model *model, simgrid::s4u::Host *host,
   p_constraint = lmm_constraint_new(model->getMaxminSystem(), this, xbt_dynar_get_as(speedPeakList,pstate,double) * speedScale);
 
   if (speedTrace)
-    p_speedEvent = future_evt_set->add_trace(speedTrace, 0.0, this);
+    p_speed.event = future_evt_set->add_trace(speedTrace, 0.0, this);
 
   if (state_trace)
     p_stateEvent = future_evt_set->add_trace(state_trace, 0.0, this);
@@ -462,14 +462,14 @@ void CpuL07::onSpeedChange() {
   lmm_variable_t var = NULL;
   lmm_element_t elem = NULL;
 
-    lmm_update_constraint_bound(getModel()->getMaxminSystem(), getConstraint(), m_speedPeak * m_speedScale);
+    lmm_update_constraint_bound(getModel()->getMaxminSystem(), getConstraint(), p_speed.peak * p_speed.scale);
     while ((var = lmm_get_var_from_cnst
             (getModel()->getMaxminSystem(), getConstraint(), &elem))) {
       Action *action = static_cast<Action*>(lmm_variable_id(var));
 
       lmm_update_variable_bound(getModel()->getMaxminSystem(),
                                 action->getVariable(),
-                                m_speedScale * m_speedPeak);
+                                p_speed.scale * p_speed.peak);
     }
 
   Cpu::onSpeedChange();
@@ -482,10 +482,10 @@ bool LinkL07::isUsed(){
 
 void CpuL07::apply_event(tmgr_trace_iterator_t triggered, double value){
   XBT_DEBUG("Updating cpu %s (%p) with value %g", getName(), this, value);
-  if (triggered == p_speedEvent) {
-    m_speedScale = value;
+  if (triggered == p_speed.event) {
+    p_speed.scale = value;
     onSpeedChange();
-    tmgr_trace_event_unref(&p_speedEvent);
+    tmgr_trace_event_unref(&p_speed.event);
   } else if (triggered == p_stateEvent) {
     if (value > 0)
       turnOn();
index c7ad3f8..02ffe37 100644 (file)
@@ -69,13 +69,13 @@ void HostEnergy::update()
   double start_time = this->last_updated;
   double finish_time = surf_get_clock();
   double cpu_load;
-  if (surf_host->p_cpu->m_speedPeak == 0)
+  if (surf_host->p_cpu->p_speed.peak == 0)
     // Some users declare a pstate of speed 0 flops (eg to model boot time).
     // We consider that the machine is then fully loaded. That's arbitrary but it avoids a NaN
     cpu_load = 1;
   else
     cpu_load = lmm_constraint_get_usage(surf_host->p_cpu->getConstraint())
-                / surf_host->p_cpu->m_speedPeak;
+                / surf_host->p_cpu->p_speed.peak;
 
   if (cpu_load > 1) // A machine with a load > 1 consumes as much as a fully loaded machine, not mores
     cpu_load = 1;
@@ -94,7 +94,7 @@ void HostEnergy::update()
   this->last_updated = finish_time;
 
   XBT_DEBUG("[update_energy of %s] period=[%.2f-%.2f]; current power peak=%.0E flop/s; consumption change: %.2f J -> %.2f J",
-      surf_host->getName(), start_time, finish_time, surf_host->p_cpu->m_speedPeak, previous_energy, energy_this_step);
+      surf_host->getName(), start_time, finish_time, surf_host->p_cpu->p_speed.peak, previous_energy, energy_this_step);
 }
 
 HostEnergy::HostEnergy(simgrid::s4u::Host *ptr) :