From aa5a7febd33d50d8457f71c35f11c39bef0b64e4 Mon Sep 17 00:00:00 2001 From: Gabriel Corona Date: Tue, 24 Nov 2015 11:27:18 +0100 Subject: [PATCH] [surf] Change CPU initialization - 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 | 6 ++++-- src/surf/cpu_interface.cpp | 25 ++++++++++++++++++------- src/surf/cpu_interface.hpp | 9 ++++++++- src/surf/cpu_ti.cpp | 7 ++++--- src/surf/host_ptask_L07.cpp | 6 +++--- src/surf/surf_interface.cpp | 11 ++++++++--- src/surf/surf_interface.hpp | 3 +++ 7 files changed, 48 insertions(+), 19 deletions(-) diff --git a/src/surf/cpu_cas01.cpp b/src/surf/cpu_cas01.cpp index fde93bca20..4d9ae260da 100644 --- a/src/surf/cpu_cas01.cpp +++ b/src/surf/cpu_cas01.cpp @@ -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); diff --git a/src/surf/cpu_interface.cpp b/src/surf/cpu_interface.cpp index 585f48c947..ed245c8f88 100644 --- a/src/surf/cpu_interface.cpp +++ b/src/surf/cpu_interface.cpp @@ -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){ diff --git a/src/surf/cpu_interface.hpp b/src/surf/cpu_interface.hpp index 40e3659708..1228859ec6 100644 --- a/src/surf/cpu_interface.hpp +++ b/src/surf/cpu_interface.hpp @@ -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); diff --git a/src/surf/cpu_ti.cpp b/src/surf/cpu_ti.cpp index fba3eac780..9052b30819 100644 --- a/src/surf/cpu_ti.cpp +++ b/src/surf/cpu_ti.cpp @@ -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; diff --git a/src/surf/host_ptask_L07.cpp b/src/surf/host_ptask_L07.cpp index 2114c977cd..2f1006a9bb 100644 --- a/src/surf/host_ptask_L07.cpp +++ b/src/surf/host_ptask_L07.cpp @@ -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); } diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index 178b7b1431..b10a5042cc 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -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) diff --git a/src/surf/surf_interface.hpp b/src/surf/surf_interface.hpp index de1665d759..e3281ca00c 100644 --- a/src/surf/surf_interface.hpp +++ b/src/surf/surf_interface.hpp @@ -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 * -- 2.20.1