From 4736926935eb52f1e561715d2fa5a3fc4144a188 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Wed, 23 Dec 2015 02:34:44 +0100 Subject: [PATCH 1/1] simplify how cpus are plugged into hosts at creation --- src/surf/cpu_cas01.cpp | 8 ++++---- src/surf/cpu_cas01.hpp | 4 ++-- src/surf/cpu_interface.cpp | 30 ++++++++++++------------------ src/surf/cpu_interface.hpp | 18 ++++++++---------- src/surf/cpu_ti.cpp | 8 ++++---- src/surf/cpu_ti.hpp | 4 ++-- src/surf/host_ptask_L07.cpp | 8 ++++---- src/surf/host_ptask_L07.hpp | 4 ++-- src/surf/sg_platf.cpp | 3 +-- src/surf/vm_hl13.cpp | 3 +-- 10 files changed, 40 insertions(+), 50 deletions(-) diff --git a/src/surf/cpu_cas01.cpp b/src/surf/cpu_cas01.cpp index 1535c15e67..c767a73002 100644 --- a/src/surf/cpu_cas01.cpp +++ b/src/surf/cpu_cas01.cpp @@ -99,7 +99,7 @@ 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, @@ -108,7 +108,7 @@ Cpu *CpuCas01Model::createCpu(const char *name, xbt_dynar_t speedPeak, 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, name, speedPeak, pstate, speedScale, speedTrace, core, state_initial, state_trace); + Cpu *cpu = new CpuCas01(this, host, speedPeak, pstate, speedScale, speedTrace, core, state_initial, state_trace); return cpu; } @@ -152,10 +152,10 @@ 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) -: Cpu(model, name, +: Cpu(model, host, lmm_constraint_new(model->getMaxminSystem(), this, core * speedScale * xbt_dynar_get_as(speedPeak, pstate, double)), core, xbt_dynar_get_as(speedPeak, pstate, double), speedScale, stateInitial) { diff --git a/src/surf/cpu_cas01.hpp b/src/surf/cpu_cas01.hpp index 8d53c81c39..66dd3f7072 100644 --- a/src/surf/cpu_cas01.hpp +++ b/src/surf/cpu_cas01.hpp @@ -31,7 +31,7 @@ public: double (CpuCas01Model::*shareResources)(double now); void (CpuCas01Model::*updateActionsState)(double now, double delta); - Cpu *createCpu(const char *name, xbt_dynar_t speedPeak, int pstate, + Cpu *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, @@ -47,7 +47,7 @@ public: class CpuCas01 : public Cpu { public: - CpuCas01(CpuCas01Model *model, const char *name, xbt_dynar_t speedPeak, + 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) ; ~CpuCas01(); diff --git a/src/surf/cpu_interface.cpp b/src/surf/cpu_interface.cpp index 10334fa25f..78785a9e18 100644 --- a/src/surf/cpu_interface.cpp +++ b/src/surf/cpu_interface.cpp @@ -143,26 +143,28 @@ Cpu::Cpu() } -Cpu::Cpu(Model *model, const char *name, +Cpu::Cpu(Model *model, simgrid::Host *host, int core, double speedPeak, double speedScale, e_surf_resource_state_t stateInitial) - : Resource(model, name, stateInitial) + : Resource(model, host->getName().c_str(), stateInitial) , m_core(core) , m_speedPeak(speedPeak) , m_speedScale(speedScale) + , m_host(host) { } -Cpu::Cpu(Model *model, const char *name, +Cpu::Cpu(Model *model, simgrid::Host *host, lmm_constraint_t constraint, int core, double speedPeak, double speedScale, e_surf_resource_state_t stateInitial) - : Resource(model, name, constraint, stateInitial) + : Resource(model, host->getName().c_str(), constraint, stateInitial) , m_core(core) , m_speedPeak(speedPeak) , m_speedScale(speedScale) + , m_host(host) { - /* At now, we assume that a VM does not have a multicore CPU. */ + /* Currently, we assume that a VM does not have a multicore CPU. */ if (core > 1) xbt_assert(model == surf_cpu_model_pm); @@ -173,20 +175,20 @@ Cpu::Cpu(Model *model, const char *name, int i; for (i = 0; i < core; i++) { /* just for a unique id, never used as a string. */ - p_constraintCoreId[i] = bprintf("%s:%i", name, i); + p_constraintCoreId[i] = bprintf("%s:%i", host->getName().c_str(), i); p_constraintCore[i] = lmm_constraint_new(model->getMaxminSystem(), p_constraintCoreId[i], m_speedScale * m_speedPeak); } } } -Cpu::Cpu(Model *model, const char *name, +Cpu::Cpu(Model *model, simgrid::Host *host, lmm_constraint_t constraint, int core, double speedPeak, double speedScale) -: Cpu(model, name, constraint, core, speedPeak, speedScale, SURF_RESOURCE_ON) +: Cpu(model, host, constraint, core, speedPeak, speedScale, SURF_RESOURCE_ON) {} -Cpu::Cpu(Model *model, const char *name, +Cpu::Cpu(Model *model, simgrid::Host *host, int core, double speedPeak, double speedScale) -: Cpu(model, name, core, speedPeak, speedScale, SURF_RESOURCE_ON) +: Cpu(model, host, core, speedPeak, speedScale, SURF_RESOURCE_ON) {} Cpu::~Cpu() @@ -222,14 +224,6 @@ int Cpu::getCore() return m_core; } -void Cpu::plug(simgrid::Host* host) -{ - if (this->m_host != nullptr) - xbt_die("Already plugged into host %s", host->getName().c_str()); - host->extension_set(this); - this->m_host = host; -} - /********** * Action * **********/ diff --git a/src/surf/cpu_interface.hpp b/src/surf/cpu_interface.hpp index 12a8e00d41..4f1b156247 100644 --- a/src/surf/cpu_interface.hpp +++ b/src/surf/cpu_interface.hpp @@ -53,7 +53,7 @@ public: * @param state_initial [TODO] * @param state_trace [TODO] */ - virtual Cpu *createCpu(const char *name, xbt_dynar_t speedPeak, + virtual Cpu *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, @@ -82,14 +82,14 @@ public: * @brief Cpu constructor * * @param model The CpuModel associated to this Cpu - * @param name The name of the Cpu + * @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 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 stateInitial whether it is created running or crashed */ - Cpu(simgrid::surf::Model *model, const char *name, + Cpu(simgrid::surf::Model *model, simgrid::Host *host, lmm_constraint_t constraint, int core, double speedPeak, double speedScale, e_surf_resource_state_t stateInitial); @@ -97,19 +97,19 @@ public: * @brief Cpu constructor * * @param model The CpuModel associated to this Cpu - * @param name The name of the Cpu + * @param host The host in which this Cpu should be plugged * @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 stateInitial whether it is created running or crashed */ - Cpu(simgrid::surf::Model *model, const char *name, + Cpu(simgrid::surf::Model *model, simgrid::Host *host, int core, double speedPeak, double speedScale, e_surf_resource_state_t stateInitial); - Cpu(simgrid::surf::Model *model, const char *name, + Cpu(simgrid::surf::Model *model, simgrid::Host *host, lmm_constraint_t constraint, int core, double speedPeak, double speedScale); - Cpu(simgrid::surf::Model *model, const char *name, + Cpu(simgrid::surf::Model *model, simgrid::Host *host, int core, double speedPeak, double speedScale); ~Cpu(); @@ -148,8 +148,6 @@ public: virtual void setPstate(int pstate_index)=0; virtual int getPstate()=0; - void plug(simgrid::Host* host); - void addTraces(void); simgrid::Host* getHost() { return m_host; } @@ -157,7 +155,7 @@ 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::Host* m_host = nullptr; + simgrid::Host* m_host; /* Note (hypervisor): */ lmm_constraint_t *p_constraintCore=NULL; diff --git a/src/surf/cpu_ti.cpp b/src/surf/cpu_ti.cpp index 90447fb0e3..a72268a2f6 100644 --- a/src/surf/cpu_ti.cpp +++ b/src/surf/cpu_ti.cpp @@ -435,7 +435,7 @@ CpuTiModel::~CpuTiModel() xbt_heap_free(p_tiActionHeap); } -Cpu *CpuTiModel::createCpu(const char *name, +Cpu *CpuTiModel::createCpu(simgrid::Host *host, xbt_dynar_t speedPeak, int pstate, double speedScale, @@ -447,7 +447,7 @@ Cpu *CpuTiModel::createCpu(const char *name, 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, name, speedPeak, pstate, speedScale, speedTrace, + CpuTi *cpu = new CpuTi(this, host, speedPeak, pstate, speedScale, speedTrace, core, stateInitial, stateTrace); return cpu; } @@ -548,10 +548,10 @@ void CpuTiModel::addTraces() /************ * Resource * ************/ -CpuTi::CpuTi(CpuTiModel *model, const char *name, xbt_dynar_t speedPeak, +CpuTi::CpuTi(CpuTiModel *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) - : Cpu(model, name, core, 0, speedScale, stateInitial) + : Cpu(model, host, core, 0, speedScale, stateInitial) { p_speedEvent = NULL; m_speedScale = speedScale; diff --git a/src/surf/cpu_ti.hpp b/src/surf/cpu_ti.hpp index f95c819812..06b10dfaf8 100644 --- a/src/surf/cpu_ti.hpp +++ b/src/surf/cpu_ti.hpp @@ -115,7 +115,7 @@ typedef boost::intrusive::list< class CpuTi : public Cpu { public: CpuTi() {}; - CpuTi(CpuTiModel *model, const char *name, xbt_dynar_t speedPeak, + CpuTi(CpuTiModel *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) ; ~CpuTi(); @@ -160,7 +160,7 @@ class CpuTiModel : public CpuModel { public: CpuTiModel(); ~CpuTiModel(); - Cpu *createCpu(const char *name, xbt_dynar_t speedPeak, + Cpu *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, diff --git a/src/surf/host_ptask_L07.cpp b/src/surf/host_ptask_L07.cpp index 9ac974c7a5..700aa0c44f 100644 --- a/src/surf/host_ptask_L07.cpp +++ b/src/surf/host_ptask_L07.cpp @@ -289,14 +289,14 @@ Action *NetworkL07Model::communicate(RoutingEdge *src, RoutingEdge *dst, return res; } -Cpu *CpuL07Model::createCpu(const char *name, xbt_dynar_t powerPeak, +Cpu *CpuL07Model::createCpu(simgrid::Host *host, xbt_dynar_t powerPeak, int pstate, double power_scale, tmgr_trace_t power_trace, int core, e_surf_resource_state_t state_initial, tmgr_trace_t state_trace) { double power_initial = xbt_dynar_get_as(powerPeak, pstate, double); - CpuL07 *cpu = new CpuL07(this, name, power_initial, power_scale, power_trace, + CpuL07 *cpu = new CpuL07(this, host, power_initial, power_scale, power_trace, core, state_initial, state_trace); return cpu; } @@ -387,10 +387,10 @@ void HostL07Model::addTraces() /************ * Resource * ************/ -CpuL07::CpuL07(CpuL07Model *model, const char* name, +CpuL07::CpuL07(CpuL07Model *model, simgrid::Host *host, double speedInitial, double speedScale, tmgr_trace_t speedTrace, int core, e_surf_resource_state_t state_initial, tmgr_trace_t state_trace) - : Cpu(model, name, lmm_constraint_new(ptask_maxmin_system, this, speedInitial * speedScale), + : Cpu(model, host, lmm_constraint_new(ptask_maxmin_system, this, speedInitial * speedScale), core, speedInitial, speedScale, state_initial) { xbt_assert(m_speedScale > 0, "Power has to be >0"); diff --git a/src/surf/host_ptask_L07.hpp b/src/surf/host_ptask_L07.hpp index b69b496863..5b8c107209 100644 --- a/src/surf/host_ptask_L07.hpp +++ b/src/surf/host_ptask_L07.hpp @@ -58,7 +58,7 @@ public: CpuL07Model(HostL07Model *hmodel) : CpuModel() {p_hostModel = hmodel;}; ~CpuL07Model() {surf_cpu_model_pm = NULL;}; - Cpu *createCpu(const char *name, xbt_dynar_t speedPeak, + Cpu *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, @@ -98,7 +98,7 @@ class CpuL07 : public Cpu { tmgr_trace_event_t p_stateEvent; tmgr_trace_event_t p_speedEvent; public: - CpuL07(CpuL07Model *model, const char* name, + CpuL07(CpuL07Model *model, simgrid::Host *host, double power_scale, double power_initial, tmgr_trace_t power_trace, int core, e_surf_resource_state_t state_initial, tmgr_trace_t state_trace); ~CpuL07(); diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index b1896426e4..208484b51b 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -62,7 +62,7 @@ void sg_platf_new_host(sg_platf_host_cbarg_t host) sg_host_t h = simgrid::Host::by_name_or_create(host->id); simgrid::surf::Cpu *cpu = surf_cpu_model_pm->createCpu( - host->id, + h, host->speed_peak, host->pstate, host->speed_scale, @@ -70,7 +70,6 @@ void sg_platf_new_host(sg_platf_host_cbarg_t host) host->core_amount, host->initial_state, host->state_trace); - cpu->plug(h); surf_host_model->createHost(host->id, net, cpu, host->properties)->attach(h); if (TRACE_is_enabled() && TRACE_needs_platform()) sg_instr_new_host(host); diff --git a/src/surf/vm_hl13.cpp b/src/surf/vm_hl13.cpp index 19d008dc94..89cbef1622 100644 --- a/src/surf/vm_hl13.cpp +++ b/src/surf/vm_hl13.cpp @@ -186,7 +186,7 @@ VMHL13::VMHL13(VMModel *model, const char* name, xbt_dict_t props, sg_host_t hos // Roughly, create a vcpu resource by using the values of the sub_cpu one. CpuCas01 *sub_cpu = static_cast(sg_host_surfcpu(host_PM)); - p_cpu = surf_cpu_model_vm->createCpu(name, // name + p_cpu = surf_cpu_model_vm->createCpu(host, // the machine hosting the VM sub_cpu->getSpeedPeakList(), // host->power_peak, sub_cpu->getPState(), 1, // host->power_scale, @@ -194,7 +194,6 @@ VMHL13::VMHL13(VMModel *model, const char* name, xbt_dict_t props, sg_host_t hos 1, // host->core_amount, SURF_RESOURCE_ON, // host->initial_state, NULL); // host->state_trace, - p_cpu->plug(host); /* 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