Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[surf] Change CPU initialization
authorGabriel Corona <gabriel.corona@loria.fr>
Tue, 24 Nov 2015 10:27:18 +0000 (11:27 +0100)
committerGabriel Corona <gabriel.corona@loria.fr>
Tue, 24 Nov 2015 11:54:39 +0000 (12:54 +0100)
- Move creation callbacks out of constructor (the object is not fully
constructed in the Host constructor).

- Do not call the setState virtual method in the constructor. This
  calls the stateChanged callbacks some of which expect the
  hostCreated callbacks to have been called.

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/surf_interface.cpp
src/surf/surf_interface.hpp

index fde93bc..4d9ae26 100644 (file)
@@ -114,6 +114,8 @@ Cpu *CpuCas01Model::createCpu(const char *name, xbt_dynar_t power_peak,
   xbt_assert(core > 0, "Invalid number of cores %d. Must be larger than 0", core);
 
   cpu = new CpuCas01(this, name, power_peak, pstate, power_scale, power_trace, core, state_initial, state_trace, cpu_properties);
+  surf_callback_emit(cpuCreatedCallbacks, cpu);
+  surf_callback_emit(cpuStateChangedCallbacks, cpu, SURF_RESOURCE_ON, state_initial);
   sg_host_surfcpu_set(host, cpu);
 
   return cpu;
@@ -165,7 +167,8 @@ CpuCas01::CpuCas01(CpuCas01Model *model, const char *name, xbt_dynar_t powerPeak
                          xbt_dict_t properties)
 : Cpu(model, name, properties,
          lmm_constraint_new(model->getMaxminSystem(), this, core * powerScale * xbt_dynar_get_as(powerPeak, pstate, double)),
-         core, xbt_dynar_get_as(powerPeak, pstate, double), powerScale) {
+         core, xbt_dynar_get_as(powerPeak, pstate, double), powerScale,
+    stateInitial) {
   p_powerEvent = NULL;
   p_powerPeakList = powerPeak;
   m_pstate = pstate;
@@ -173,7 +176,6 @@ CpuCas01::CpuCas01(CpuCas01Model *model, const char *name, xbt_dynar_t powerPeak
   XBT_DEBUG("CPU create: peak=%f, pstate=%d", m_powerPeak, m_pstate);
 
   m_core = core;
-  setState(stateInitial);
   if (powerTrace)
     p_powerEvent = tmgr_history_add_trace(history, powerTrace, 0.0, 0, this);
 
index 585f48c..ed245c8 100644 (file)
@@ -143,29 +143,30 @@ void CpuModel::updateActionsStateFull(double now, double delta)
  ************/
 
 Cpu::Cpu(){
-  surf_callback_emit(cpuCreatedCallbacks, this);
 }
 
+
 Cpu::Cpu(Model *model, const char *name, xbt_dict_t props,
-                int core, double powerPeak, double powerScale)
- : Resource(model, name, props)
+         int core, double powerPeak, double powerScale,
+         e_surf_resource_state_t stateInitial)
+ : Resource(model, name, props, stateInitial)
  , m_core(core)
  , m_powerPeak(powerPeak)
  , m_powerScale(powerScale)
  , p_constraintCore(NULL)
  , p_constraintCoreId(NULL)
 {
-  surf_callback_emit(cpuCreatedCallbacks, this);
+
 }
 
 Cpu::Cpu(Model *model, const char *name, xbt_dict_t props,
-                lmm_constraint_t constraint, int core, double powerPeak, double powerScale)
- : Resource(model, name, props, constraint)
+        lmm_constraint_t constraint, int core, double powerPeak,
+        double powerScale, e_surf_resource_state_t stateInitial)
+ : Resource(model, name, props, constraint, stateInitial)
  , m_core(core)
  , m_powerPeak(powerPeak)
  , m_powerScale(powerScale)
 {
-  surf_callback_emit(cpuCreatedCallbacks, this);
   /* At now, we assume that a VM does not have a multicore CPU. */
   if (core > 1)
     xbt_assert(model == surf_cpu_model_pm);
@@ -185,6 +186,16 @@ Cpu::Cpu(Model *model, const char *name, xbt_dict_t props,
   }
 }
 
+Cpu::Cpu(Model *model, const char *name, xbt_dict_t props,
+  lmm_constraint_t constraint, int core, double powerPeak, double powerScale)
+: Cpu(model, name, props, constraint, core, powerPeak, powerScale, SURF_RESOURCE_ON)
+{}
+
+Cpu::Cpu(Model *model, const char *name, xbt_dict_t props,
+  int core, double powerPeak, double powerScale)
+: Cpu(model, name, props, core, powerPeak, powerScale, SURF_RESOURCE_ON)
+{}
+
 Cpu::~Cpu(){
   surf_callback_emit(cpuDestructedCallbacks, this);
   if (p_constraintCoreId){
index 40e3659..1228859 100644 (file)
@@ -115,7 +115,8 @@ public:
    * @param powerScale The power scale of this Cpu
    */
   Cpu(Model *model, const char *name, xbt_dict_t props,
-         lmm_constraint_t constraint, int core, double powerPeak, double powerScale);
+         lmm_constraint_t constraint, int core, double powerPeak, double powerScale,
+    e_surf_resource_state_t stateInitial);
 
   /**
    * @brief Cpu constructor
@@ -127,6 +128,12 @@ public:
    * @param powerPeak The power peak of this Cpu in [TODO]
    * @param powerScale The power scale of this Cpu in [TODO]
    */
+  Cpu(Model *model, const char *name, xbt_dict_t props,
+         int core, double powerPeak, double powerScale,
+    e_surf_resource_state_t stateInitial);
+
+  Cpu(Model *model, const char *name, xbt_dict_t props,
+         lmm_constraint_t constraint, int core, double powerPeak, double powerScale);
   Cpu(Model *model, const char *name, xbt_dict_t props,
          int core, double powerPeak, double powerScale);
 
index fba3eac..9052b30 100644 (file)
@@ -442,6 +442,8 @@ Cpu *CpuTiModel::createCpu(const char *name,
       "Power has to be >0.0. Did you forget to specify the mandatory power attribute?");
   CpuTi *cpu = new CpuTi(this, name, powerPeak, pstate, powerScale, powerTrace,
                           core, stateInitial, stateTrace, cpuProperties);
+  surf_callback_emit(cpuCreatedCallbacks, cpu);
+  surf_callback_emit(cpuStateChangedCallbacks, cpu, SURF_RESOURCE_ON, stateInitial);
   sg_host_surfcpu_set(host, cpu);
   return cpu;
 }
@@ -545,11 +547,10 @@ void CpuTiModel::addTraces()
 CpuTi::CpuTi(CpuTiModel *model, const char *name, xbt_dynar_t powerPeak,
         int pstate, double powerScale, tmgr_trace_t powerTrace, int core,
         e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace,
-       xbt_dict_t properties)
-: Cpu(model, name, properties, core, 0, powerScale)
+             xbt_dict_t properties)
+  : Cpu(model, name, properties, core, 0, powerScale, stateInitial)
 {
   p_powerEvent = NULL;
-  setState(stateInitial);
   m_powerScale = powerScale;
   m_core = core;
   tmgr_trace_t empty_trace;
index 2114c97..2f1006a 100644 (file)
@@ -327,7 +327,8 @@ Cpu *CpuL07Model::createCpu(const char *name,  xbt_dynar_t powerPeak,
   CpuL07 *cpu = new CpuL07(this, name, cpu_properties,
                                     power_initial, power_scale, power_trace,
                          core, state_initial, state_trace);
-
+  surf_callback_emit(cpuCreatedCallbacks, cpu);
+  surf_callback_emit(cpuStateChangedCallbacks, cpu, SURF_RESOURCE_ON, state_initial);
   sg_host_surfcpu_set(sg_host, cpu);
 
   return cpu;
@@ -452,7 +453,7 @@ CpuL07::CpuL07(CpuL07Model *model, const char* name, xbt_dict_t props,
                     double power_initial, double power_scale, tmgr_trace_t power_trace,
                           int core, e_surf_resource_state_t state_initial, tmgr_trace_t state_trace)
  : Cpu(model, name, props, lmm_constraint_new(ptask_maxmin_system, this, power_initial * power_scale),
-          core, power_initial, power_scale)
+          core, power_initial, power_scale, state_initial)
 {
   xbt_assert(m_powerScale > 0, "Power has to be >0");
 
@@ -461,7 +462,6 @@ CpuL07::CpuL07(CpuL07Model *model, const char* name, xbt_dict_t props,
   else
     p_powerEvent = NULL;
 
-  setState(state_initial);
   if (state_trace)
        p_stateEvent = tmgr_history_add_trace(history, state_trace, 0.0, 0, this);
 }
index 178b7b1..b10a504 100644 (file)
@@ -583,13 +583,18 @@ Resource::Resource()
 {}
 
 Resource::Resource(Model *model, const char *name, xbt_dict_t props)
-  : p_name(xbt_strdup(name)), p_properties(props), p_model(model)
-  , m_running(true), m_stateCurrent(SURF_RESOURCE_ON)
+  : Resource(model, name, props, SURF_RESOURCE_ON)
 {}
 
 Resource::Resource(Model *model, const char *name, xbt_dict_t props, lmm_constraint_t constraint)
+  : Resource(model, name, props, constraint, SURF_RESOURCE_ON)
+{}
+  
+Resource::Resource(
+  Model *model, const char *name, xbt_dict_t props,
+  lmm_constraint_t constraint, e_surf_resource_state_t stateInit)
   : p_name(xbt_strdup(name)), p_properties(props), p_model(model)
-  , m_running(true), m_stateCurrent(SURF_RESOURCE_ON), p_constraint(constraint)
+  , m_running(true), m_stateCurrent(stateInit), p_constraint(constraint)
 {}
 
 Resource::Resource(Model *model, const char *name, xbt_dict_t props, e_surf_resource_state_t stateInit)
index de1665d..e3281ca 100644 (file)
@@ -433,6 +433,9 @@ public:
    * @param constraint The lmm constraint associated to this Resource if it is part of a LMM component
    */
   Resource(Model *model, const char *name, xbt_dict_t props, lmm_constraint_t constraint);
+
+  Resource(Model *model, const char *name, xbt_dict_t props, lmm_constraint_t constraint, e_surf_resource_state_t stateInit);
+
   /**
    * @brief Resource constructor
    *