From 90559b37332c0f396c09fd1c75326cfbdbbe5dc1 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Wed, 24 Feb 2016 09:13:29 +0100 Subject: [PATCH 1/1] simplify a bit the CPU creation API pstate and initiallyOn are not passed anymore to the constructor. They default respectively to 0 and true. You can change the values after creation if you want. --- src/surf/cpu_cas01.cpp | 17 ++++++----------- src/surf/cpu_cas01.hpp | 10 +++------- src/surf/cpu_interface.cpp | 14 ++++---------- src/surf/cpu_interface.hpp | 19 +++++-------------- src/surf/cpu_ti.cpp | 21 +++++++++------------ src/surf/cpu_ti.hpp | 10 ++++------ src/surf/ptask_L07.cpp | 17 +++++++---------- src/surf/ptask_L07.hpp | 7 +++---- src/surf/sg_platf.cpp | 9 +++++++-- src/surf/vm_hl13.cpp | 4 ++-- 10 files changed, 50 insertions(+), 78 deletions(-) diff --git a/src/surf/cpu_cas01.cpp b/src/surf/cpu_cas01.cpp index 3f1ab84f94..0f52a6e215 100644 --- a/src/surf/cpu_cas01.cpp +++ b/src/surf/cpu_cas01.cpp @@ -83,15 +83,12 @@ CpuCas01Model::~CpuCas01Model() } Cpu *CpuCas01Model::createCpu(simgrid::s4u::Host *host, xbt_dynar_t speedPeak, - int pstate, double speedScale, - tmgr_trace_t speedTrace, int core, - int initiallyOn, - tmgr_trace_t state_trace) + double speedScale, tmgr_trace_t speedTrace, int core, tmgr_trace_t state_trace) { 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 *cpu = new CpuCas01(this, host, speedPeak, pstate, speedScale, speedTrace, core, initiallyOn, state_trace); + Cpu *cpu = new CpuCas01(this, host, speedPeak, speedScale, speedTrace, core, state_trace); return cpu; } @@ -104,13 +101,11 @@ double CpuCas01Model::next_occuring_event_full(double /*now*/) * Resource * ************/ CpuCas01::CpuCas01(CpuCas01Model *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) + double speedScale, tmgr_trace_t speedTrace, int core, 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, - initiallyOn) { + lmm_constraint_new(model->getMaxminSystem(), this, core * speedScale * xbt_dynar_get_as(speedPeak, 0/*pstate*/, double)), + speedPeak, core, xbt_dynar_get_as(speedPeak, 0/*pstate*/, double), speedScale) +{ XBT_DEBUG("CPU create: peak=%f, pstate=%d", p_speed.peak, m_pstate); diff --git a/src/surf/cpu_cas01.hpp b/src/surf/cpu_cas01.hpp index d2022aae48..f0f586431f 100644 --- a/src/surf/cpu_cas01.hpp +++ b/src/surf/cpu_cas01.hpp @@ -27,11 +27,8 @@ public: CpuCas01Model(); ~CpuCas01Model(); - Cpu *createCpu(simgrid::s4u::Host *host, xbt_dynar_t speedPeak, int pstate, - double speedScale, - tmgr_trace_t speedTrace, int core, - int initiallyOn, - tmgr_trace_t state_trace) override; + Cpu *createCpu(simgrid::s4u::Host *host, xbt_dynar_t speedPeak, double speedScale, + tmgr_trace_t speedTrace, int core, tmgr_trace_t state_trace) override; double next_occuring_event_full(double now) override; ActionList *p_cpuRunningActionSetThatDoesNotNeedBeingChecked; }; @@ -43,8 +40,7 @@ public: class CpuCas01 : public Cpu { public: CpuCas01(CpuCas01Model *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) ; + double speedScale, tmgr_trace_t speedTrace, int core, tmgr_trace_t stateTrace) ; ~CpuCas01(); void apply_event(tmgr_trace_iterator_t event, double value) override; CpuAction *execution_start(double size) override; diff --git a/src/surf/cpu_interface.cpp b/src/surf/cpu_interface.cpp index 50b4ee1810..c9a152e98b 100644 --- a/src/surf/cpu_interface.cpp +++ b/src/surf/cpu_interface.cpp @@ -128,18 +128,14 @@ void CpuModel::updateActionsStateFull(double now, double delta) * Resource * ************/ Cpu::Cpu(Model *model, simgrid::s4u::Host *host, - xbt_dynar_t speedPeakList, int pstate, - int core, double speedPeak, double speedScale, - int initiallyOn) - : Cpu(model, host, NULL/*constraint*/, speedPeakList, pstate, core, speedPeak, speedScale, initiallyOn) + xbt_dynar_t speedPeakList, int core, double speedPeak, double speedScale) + : Cpu(model, host, NULL/*constraint*/, speedPeakList, core, speedPeak, speedScale) { } Cpu::Cpu(Model *model, simgrid::s4u::Host *host, lmm_constraint_t constraint, - xbt_dynar_t speedPeakList, int pstate, - int core, double speedPeak, - double speedScale, int initiallyOn) - : Resource(model, host->name().c_str(), constraint, initiallyOn) + xbt_dynar_t speedPeakList, int core, double speedPeak, double speedScale) + : Resource(model, host->name().c_str(), constraint) , m_core(core) , m_host(host) { @@ -156,8 +152,6 @@ Cpu::Cpu(Model *model, simgrid::s4u::Host *host, lmm_constraint_t constraint, xbt_dynar_push(p_speedPeakList, &value); } - m_pstate = pstate; - /* Currently, we assume that a VM does not have a multicore CPU. */ if (core > 1) xbt_assert(model == surf_cpu_model_pm); diff --git a/src/surf/cpu_interface.hpp b/src/surf/cpu_interface.hpp index 6e8e71ad1c..2b02b27a03 100644 --- a/src/surf/cpu_interface.hpp +++ b/src/surf/cpu_interface.hpp @@ -44,17 +44,14 @@ public: * * @param host The host that will have this CPU * @param speedPeak The peak spead (max speed in Flops) - * @param pstate [TODO] * @param speedScale The speed scale (in [O;1] available speed from peak) * @param speedTrace Trace variations * @param core The number of core of this Cpu - * @param initiallyOn [TODO] * @param state_trace [TODO] */ virtual Cpu *createCpu(simgrid::s4u::Host *host, xbt_dynar_t speedPeak, - int pstate, double speedScale, + double speedScale, tmgr_trace_t speedTrace, int core, - int initiallyOn, tmgr_trace_t state_trace)=0; void updateActionsStateLazy(double now, double delta); @@ -79,17 +76,14 @@ public: * @param host The host in which this Cpu should be plugged * @param constraint The lmm constraint associated to this Cpu if it is part of a LMM component * @param speedPeakList [TODO] - * @param pstate [TODO] * @param core The number of core of this Cpu * @param speedPeak The speed peak of this Cpu in flops (max speed) * @param speedScale The speed scale of this Cpu in [0;1] (available amount) - * @param initiallyOn whether it is created running or crashed */ Cpu(simgrid::surf::Model *model, simgrid::s4u::Host *host, lmm_constraint_t constraint, - xbt_dynar_t speedPeakList, int pstate, - int core, double speedPeak, double speedScale, - int initiallyOn); + xbt_dynar_t speedPeakList, + int core, double speedPeak, double speedScale); /** * @brief Cpu constructor @@ -97,16 +91,13 @@ public: * @param model The CpuModel associated to this Cpu * @param host The host in which this Cpu should be plugged * @param speedPeakList [TODO] - * @param pstate * @param core The number of core of this Cpu * @param speedPeak The speed peak of this Cpu in flops (max speed) * @param speedScale The speed scale of this Cpu in [0;1] (available amount) - * @param initiallyOn whether it is created running or crashed */ Cpu(simgrid::surf::Model *model, simgrid::s4u::Host *host, - xbt_dynar_t speedPeakList, int pstate, - int core, double speedPeak, double speedScale, - int initiallyOn); + xbt_dynar_t speedPeakList, + int core, double speedPeak, double speedScale); ~Cpu(); diff --git a/src/surf/cpu_ti.cpp b/src/surf/cpu_ti.cpp index 2cc517ea42..766ed5d367 100644 --- a/src/surf/cpu_ti.cpp +++ b/src/surf/cpu_ti.cpp @@ -415,19 +415,16 @@ CpuTiModel::~CpuTiModel() } 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_dynar_t speedPeak, + double speedScale, + tmgr_trace_t speedTrace, + int core, + 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); + CpuTi *cpu = new CpuTi(this, host, speedPeak, speedScale, speedTrace, core, stateTrace); return cpu; } @@ -471,9 +468,9 @@ 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) + double speedScale, tmgr_trace_t speedTrace, int core, + tmgr_trace_t stateTrace) + : Cpu(model, host, NULL, core, 0, speedScale) { xbt_assert(core==1,"Multi-core not handled by this model yet"); m_core = core; diff --git a/src/surf/cpu_ti.hpp b/src/surf/cpu_ti.hpp index 1c5d3ecadb..c957662624 100644 --- a/src/surf/cpu_ti.hpp +++ b/src/surf/cpu_ti.hpp @@ -111,8 +111,8 @@ typedef boost::intrusive::list ActionTiList; class CpuTi : public Cpu { public: 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) ; + double speedScale, tmgr_trace_t speedTrace, int core, + tmgr_trace_t stateTrace) ; ~CpuTi(); void set_speed_trace(tmgr_trace_t trace) override; @@ -149,10 +149,8 @@ class CpuTiModel : public CpuModel { public: CpuTiModel(); ~CpuTiModel(); - Cpu *createCpu(simgrid::s4u::Host *host, xbt_dynar_t speedPeak, - int pstate, double speedScale, - tmgr_trace_t speedTrace, int core, - int initiallyOn, tmgr_trace_t state_trace) override; + Cpu *createCpu(simgrid::s4u::Host *host, xbt_dynar_t speedPeak, double speedScale, + tmgr_trace_t speedTrace, int core, tmgr_trace_t state_trace) override; double next_occuring_event(double now) override; void updateActionsState(double now, double delta) override; diff --git a/src/surf/ptask_L07.cpp b/src/surf/ptask_L07.cpp index 8754117c86..685709b9ab 100644 --- a/src/surf/ptask_L07.cpp +++ b/src/surf/ptask_L07.cpp @@ -296,13 +296,11 @@ Action *NetworkL07Model::communicate(NetCard *src, NetCard *dst, } Cpu *CpuL07Model::createCpu(simgrid::s4u::Host *host, xbt_dynar_t powerPeakList, - int pstate, double power_scale, + double power_scale, tmgr_trace_t power_trace, int core, - int initiallyOn, tmgr_trace_t state_trace) { - CpuL07 *cpu = new CpuL07(this, host, powerPeakList, pstate, power_scale, power_trace, - core, initiallyOn, state_trace); + CpuL07 *cpu = new CpuL07(this, host, powerPeakList, power_scale, power_trace, core, state_trace); return cpu; } @@ -333,13 +331,12 @@ Link* NetworkL07Model::createLink(const char *name, ************/ CpuL07::CpuL07(CpuL07Model *model, simgrid::s4u::Host *host, - xbt_dynar_t speedPeakList, int pstate, - double speedScale, tmgr_trace_t speedTrace, - int core, int initiallyOn, tmgr_trace_t state_trace) - : Cpu(model, host, speedPeakList, pstate, - core, xbt_dynar_get_as(speedPeakList,pstate,double), speedScale, initiallyOn) + xbt_dynar_t speedPeakList, + double speedScale, tmgr_trace_t speedTrace, + int core, tmgr_trace_t state_trace) + : Cpu(model, host, speedPeakList, core, xbt_dynar_get_as(speedPeakList,0,double), speedScale) { - p_constraint = lmm_constraint_new(model->getMaxminSystem(), this, xbt_dynar_get_as(speedPeakList,pstate,double) * speedScale); + p_constraint = lmm_constraint_new(model->getMaxminSystem(), this, xbt_dynar_get_as(speedPeakList,0,double) * speedScale); if (speedTrace) p_speed.event = future_evt_set->add_trace(speedTrace, 0.0, this); diff --git a/src/surf/ptask_L07.hpp b/src/surf/ptask_L07.hpp index 1476127cc2..f235b8c9b3 100644 --- a/src/surf/ptask_L07.hpp +++ b/src/surf/ptask_L07.hpp @@ -55,9 +55,8 @@ public: ~CpuL07Model(); Cpu *createCpu(simgrid::s4u::Host *host, xbt_dynar_t speedPeakList, - int pstate, double speedScale, + double speedScale, tmgr_trace_t speedTrace, int core, - int initiallyOn, tmgr_trace_t state_trace) override; HostL07Model *p_hostModel; }; @@ -88,9 +87,9 @@ public: class CpuL07 : public Cpu { public: - CpuL07(CpuL07Model *model, simgrid::s4u::Host *host, xbt_dynar_t speedPeakList, int pstate, + CpuL07(CpuL07Model *model, simgrid::s4u::Host *host, xbt_dynar_t speedPeakList, double power_scale, tmgr_trace_t power_trace, - int core, int initiallyOn, tmgr_trace_t state_trace); + int core, tmgr_trace_t state_trace); ~CpuL07(); bool isUsed() override; void apply_event(tmgr_trace_iterator_t event, double value) override; diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index a3ae7d8ca5..1b6341f0d3 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -101,11 +101,16 @@ void sg_platf_new_host(sg_platf_host_cbarg_t host) simgrid::surf::Cpu *cpu = surf_cpu_model_pm->createCpu( h, host->speed_peak, - host->pstate, host->speed_scale, host->speed_trace, host->core_amount, - host->initiallyOn, host->state_trace); + host->state_trace); surf_host_model->createHost(host->id, netcard, cpu, host->properties)->attach(h); + + if (host->pstate != 0) + cpu->setPState(host->pstate); + if (! host->initiallyOn) + cpu->turnOff(); + simgrid::s4u::Host::onCreation(*h); if (TRACE_is_enabled() && TRACE_needs_platform()) diff --git a/src/surf/vm_hl13.cpp b/src/surf/vm_hl13.cpp index 6e8450f6a2..07a646a812 100644 --- a/src/surf/vm_hl13.cpp +++ b/src/surf/vm_hl13.cpp @@ -132,12 +132,12 @@ VMHL13::VMHL13(VMModel *model, const char* name, xbt_dict_t props, sg_host_t hos p_cpu = surf_cpu_model_vm->createCpu(host_VM, // the machine hosting the VM sub_cpu->getSpeedPeakList(), // host->power_peak, - sub_cpu->getPState(), 1, // host->power_scale, NULL, // host->power_trace, 1, // host->core_amount, - 1/*ON*/, // host->initiallyOn, NULL); // host->state_trace, + if (sub_cpu->getPState() != 0) + p_cpu->setPState(sub_cpu->getPState()); /* We create cpu_action corresponding to a VM process on the host operating system. */ /* FIXME: TODO: we have to periodically input GUESTOS_NOISE to the system? how ? */ -- 2.20.1