Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make the energy plugin usable with ptask (but not DVFS) (fix #27)
[simgrid.git] / src / surf / cpu_cas01.cpp
index f24f51f..014f9da 100644 (file)
@@ -27,18 +27,21 @@ void surf_cpu_model_init_Cas01()
     return;
   }
 
-  surf_cpu_model_pm = new CpuCas01Model();
-  surf_cpu_model_vm  = new CpuCas01Model();
+  surf_cpu_model_pm = new simgrid::surf::CpuCas01Model();
+  surf_cpu_model_vm  = new simgrid::surf::CpuCas01Model();
 
-  sg_platf_postparse_add_cb(cpu_add_traces);
+  sg_platf_postparse_add_cb(simgrid::surf::cpu_add_traces);
 
-  Model *model_pm = surf_cpu_model_pm;
-  Model *model_vm = surf_cpu_model_vm;
+  simgrid::surf::Model *model_pm = surf_cpu_model_pm;
+  simgrid::surf::Model *model_vm = surf_cpu_model_vm;
   xbt_dynar_push(all_existing_models, &model_pm);
   xbt_dynar_push(all_existing_models, &model_vm);
 }
 
-CpuCas01Model::CpuCas01Model() : CpuModel()
+namespace simgrid {
+namespace surf {
+
+CpuCas01Model::CpuCas01Model() : simgrid::surf::CpuModel()
 {
   char *optim = xbt_cfg_get_string(_sg_cfg_set, "cpu/optim");
   int select = xbt_cfg_get_boolean(_sg_cfg_set, "cpu/maxmin_selective_update");
@@ -96,21 +99,16 @@ CpuCas01Model::~CpuCas01Model()
   delete p_cpuRunningActionSetThatDoesNotNeedBeingChecked;
 }
 
-Cpu *CpuCas01Model::createCpu(const char *name, xbt_dynar_t speedPeak,
+Cpu *CpuCas01Model::createCpu(simgrid::Host *host, xbt_dynar_t speedPeak,
                                  int pstate, double speedScale,
                           tmgr_trace_t speedTrace, int core,
                           e_surf_resource_state_t state_initial,
-                          tmgr_trace_t state_trace,
-                          xbt_dict_t cpu_properties)
+                          tmgr_trace_t state_trace)
 {
-  Cpu *cpu = NULL;
-  sg_host_t host = sg_host_by_name(name);
   xbt_assert(xbt_dynar_getfirst_as(speedPeak, double) > 0.0,
       "Speed has to be >0.0. Did you forget to specify the mandatory power attribute?");
   xbt_assert(core > 0, "Invalid number of cores %d. Must be larger than 0", core);
-
-  cpu = new CpuCas01(this, name, speedPeak, pstate, speedScale, speedTrace, core, state_initial, state_trace, cpu_properties);
-  sg_host_surfcpu_register(host, cpu);
+  Cpu *cpu = new CpuCas01(this, host, speedPeak, pstate, speedScale, speedTrace, core, state_initial, state_trace);
   return cpu;
 }
 
@@ -154,26 +152,16 @@ void CpuCas01Model::addTraces()
 /************
  * Resource *
  ************/
-CpuCas01::CpuCas01(CpuCas01Model *model, const char *name, xbt_dynar_t speedPeak,
+CpuCas01::CpuCas01(CpuCas01Model *model, simgrid::Host *host, xbt_dynar_t speedPeak,
                          int pstate, double speedScale, tmgr_trace_t speedTrace, int core,
-                         e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace,
-                         xbt_dict_t properties)
-: Cpu(model, name, properties,
-         lmm_constraint_new(model->getMaxminSystem(), this, core * speedScale * xbt_dynar_get_as(speedPeak, pstate, double)),
-         core, xbt_dynar_get_as(speedPeak, pstate, double), speedScale,
+                         e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace)
+: Cpu(model, host,
+       lmm_constraint_new(model->getMaxminSystem(), this, core * speedScale * xbt_dynar_get_as(speedPeak, pstate, double)),
+       speedPeak, pstate,
+       core, xbt_dynar_get_as(speedPeak, pstate, double), speedScale,
     stateInitial) {
   p_speedEvent = NULL;
 
-  // Copy the power peak array:
-  p_speedPeakList = xbt_dynar_new(sizeof(double), nullptr);
-  unsigned long n = xbt_dynar_length(speedPeak);
-  for (unsigned long i = 0; i != n; ++i) {
-    double value = xbt_dynar_get_as(speedPeak, i, double);
-    xbt_dynar_push(p_speedPeakList, &value);
-  }
-
-  m_pstate = pstate;
-
   XBT_DEBUG("CPU create: peak=%f, pstate=%d", m_speedPeak, m_pstate);
 
   m_core = core;
@@ -184,7 +172,8 @@ CpuCas01::CpuCas01(CpuCas01Model *model, const char *name, xbt_dynar_t speedPeak
     p_stateEvent = tmgr_history_add_trace(history, stateTrace, 0.0, 0, this);
 }
 
-CpuCas01::~CpuCas01(){
+CpuCas01::~CpuCas01()
+{
   if (getModel() == surf_cpu_model_pm)
     xbt_dynar_free(&p_speedPeakList);
 }
@@ -203,11 +192,6 @@ xbt_dynar_t CpuCas01::getSpeedPeakList(){
   return p_speedPeakList;
 }
 
-int CpuCas01::getPState()
-{
-  return m_pstate;
-}
-
 bool CpuCas01::isUsed()
 {
   return lmm_constraint_used(getModel()->getMaxminSystem(), getConstraint());
@@ -324,34 +308,6 @@ double CpuCas01::getCurrentPowerPeak()
   return m_speedPeak;
 }
 
-double CpuCas01::getPowerPeakAt(int pstate_index)
-{
-  xbt_dynar_t plist = p_speedPeakList;
-  xbt_assert((pstate_index <= (int)xbt_dynar_length(plist)), "Invalid parameters (pstate index out of bounds)");
-
-  return xbt_dynar_get_as(plist, pstate_index, double);
-}
-
-int CpuCas01::getNbPstates()
-{
-  return xbt_dynar_length(p_speedPeakList);
-}
-
-void CpuCas01::setPstate(int pstate_index)
-{
-  xbt_dynar_t plist = p_speedPeakList;
-  xbt_assert((pstate_index <= (int)xbt_dynar_length(plist)), "Invalid parameters (pstate index out of bounds)");
-
-  double new_pstate = xbt_dynar_get_as(plist, pstate_index, double);
-  m_pstate = pstate_index;
-  m_speedPeak = new_pstate;
-}
-
-int CpuCas01::getPstate()
-{
-  return m_pstate;
-}
-
 /**********
  * Action *
  **********/
@@ -369,3 +325,6 @@ CpuCas01Action::CpuCas01Action(Model *model, double cost, bool failed, double sp
   }
   lmm_expand(model->getMaxminSystem(), constraint, getVariable(), 1.0);
 }
+
+}
+}