From: Frederic Suter Date: Mon, 1 Mar 2021 23:54:36 +0000 (+0100) Subject: cleanups X-Git-Tag: v3.27~275 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/4c18091c2618f718dcd672ed8391572eeb80ad99 cleanups --- diff --git a/src/plugins/host_energy.cpp b/src/plugins/host_energy.cpp index 88e243f3bf..a1033c8b06 100644 --- a/src/plugins/host_energy.cpp +++ b/src/plugins/host_energy.cpp @@ -473,7 +473,7 @@ static void on_action_state_change(simgrid::kernel::resource::CpuAction const& a simgrid::kernel::resource::Action::State /*previous*/) { for (simgrid::kernel::resource::Cpu* const& cpu : action.cpus()) { - simgrid::s4u::Host* host = cpu->get_host(); + simgrid::s4u::Host* host = cpu->get_iface(); if (host != nullptr) { // If it's a VM, take the corresponding PM const simgrid::s4u::VirtualMachine* vm = dynamic_cast(host); diff --git a/src/surf/cpu_cas01.cpp b/src/surf/cpu_cas01.cpp index 02d4abb73d..9694417a26 100644 --- a/src/surf/cpu_cas01.cpp +++ b/src/surf/cpu_cas01.cpp @@ -87,9 +87,10 @@ Cpu* CpuCas01Model::create_cpu(s4u::Host* host, const std::vector& speed * Resource * ************/ CpuCas01::CpuCas01(CpuCas01Model* model, s4u::Host* host, const std::vector& speed_per_pstate, int core) - : Cpu(model, host, model->get_maxmin_system()->constraint_new(this, core * speed_per_pstate.front()), - speed_per_pstate, core) + : Cpu(host, speed_per_pstate) { + this->set_core_count(core)->set_model(model)->set_constraint( + model->get_maxmin_system()->constraint_new(this, core * speed_per_pstate.front())); } CpuCas01::~CpuCas01() = default; @@ -133,8 +134,8 @@ void CpuCas01::apply_event(profile::Event* event, double value) if (value > 0) { if (not is_on()) { - XBT_VERB("Restart actors on host %s", get_host()->get_cname()); - get_host()->turn_on(); + XBT_VERB("Restart actors on host %s", get_iface()->get_cname()); + get_iface()->turn_on(); } } else { const lmm::Constraint* cnst = get_constraint(); @@ -142,7 +143,7 @@ void CpuCas01::apply_event(profile::Event* event, double value) const lmm::Element* elem = nullptr; double date = surf_get_clock(); - get_host()->turn_off(); + get_iface()->turn_off(); while ((var = cnst->get_variable(&elem))) { Action* action = var->get_id(); diff --git a/src/surf/cpu_interface.cpp b/src/surf/cpu_interface.cpp index cd1fa08b75..f3a5247e08 100644 --- a/src/surf/cpu_interface.cpp +++ b/src/surf/cpu_interface.cpp @@ -51,26 +51,12 @@ void CpuModel::update_actions_state_full(double /*now*/, double delta) /************ * Resource * ************/ -Cpu::Cpu(Model* model, s4u::Host* host, const std::vector& speed_per_pstate, int core) - : Cpu(model, host, nullptr /*constraint*/, speed_per_pstate, core) +Cpu::Cpu(s4u::Host* host, const std::vector& speed_per_pstate) + : Resource(host->get_cname()), piface_(host), speed_per_pstate_(speed_per_pstate) { -} - -Cpu::Cpu(Model* model, s4u::Host* host, lmm::Constraint* constraint, const std::vector& speed_per_pstate, - int core) - : Resource(host->get_cname()) - , core_count_(core) - , host_(host) - , speed_per_pstate_(speed_per_pstate) -{ - this->set_model(model)->set_constraint(constraint); - - xbt_assert(core > 0, "Host %s must have at least one core, not 0.", host->get_cname()); - - speed_.peak = speed_per_pstate_.front(); speed_.scale = 1; + speed_.peak = speed_per_pstate_.front(); host->pimpl_cpu = this; - xbt_assert(speed_.scale > 0, "Speed of host %s must be >0", host->get_cname()); } void Cpu::reset_vcpu(Cpu* that) @@ -81,11 +67,6 @@ void Cpu::reset_vcpu(Cpu* that) this->speed_per_pstate_.assign(that->speed_per_pstate_.begin(), that->speed_per_pstate_.end()); } -int Cpu::get_pstate_count() const -{ - return speed_per_pstate_.size(); -} - void Cpu::set_pstate(int pstate_index) { xbt_assert(pstate_index <= static_cast(speed_per_pstate_.size()), @@ -100,11 +81,6 @@ void Cpu::set_pstate(int pstate_index) on_speed_change(); } -int Cpu::get_pstate() const -{ - return pstate_; -} - double Cpu::get_pstate_peak_speed(int pstate_index) const { xbt_assert((pstate_index <= static_cast(speed_per_pstate_.size())), @@ -113,25 +89,14 @@ double Cpu::get_pstate_peak_speed(int pstate_index) const return speed_per_pstate_[pstate_index]; } -double Cpu::get_speed(double load) const -{ - return load * speed_.peak; -} - -double Cpu::get_speed_ratio() -{ -/* number between 0 and 1 */ - return speed_.scale; -} - void Cpu::on_speed_change() { - s4u::Host::on_speed_change(*host_); + s4u::Host::on_speed_change(*piface_); } Cpu* Cpu::set_core_count(int core_count) { - xbt_assert(core_count > 0, "Host %s must have at least one core, not 0.", host_->get_cname()); + xbt_assert(core_count > 0, "Host %s must have at least one core, not 0.", piface_->get_cname()); core_count_ = core_count; return this; } @@ -143,12 +108,11 @@ int Cpu::get_core_count() void Cpu::set_speed_profile(kernel::profile::Profile* profile) { - xbt_assert(speed_.event == nullptr, "Cannot set a second speed trace to Host %s", host_->get_cname()); + xbt_assert(speed_.event == nullptr, "Cannot set a second speed trace to Host %s", piface_->get_cname()); speed_.event = profile->schedule(&profile::future_evt_set, this); } - /********** * Action * **********/ diff --git a/src/surf/cpu_interface.hpp b/src/surf/cpu_interface.hpp index fa856e7f20..f745b5d44b 100644 --- a/src/surf/cpu_interface.hpp +++ b/src/surf/cpu_interface.hpp @@ -21,10 +21,11 @@ namespace simgrid { namespace kernel { namespace resource { -/** @ingroup SURF_cpu_interface - * @brief SURF cpu model interface class - * @details A model is an object which handle the interactions between its Resources and its Actions - */ +class CpuAction; + +/********* + * Model * + *********/ class XBT_PUBLIC CpuModel : public Model { public: using Model::Model; @@ -47,45 +48,60 @@ public: * Resource * ************/ -class CpuAction; - -/** @ingroup SURF_cpu_interface -* @brief SURF cpu resource interface class -* @details A Cpu represent a cpu associated to a host -*/ class XBT_PUBLIC Cpu : public Resource { + friend vm::VirtualMachineImpl; // Resets the VCPU + + s4u::Host* piface_; int core_count_ = 1; - s4u::Host* host_; int pstate_ = 0; /*< Current pstate (index in the speed_per_pstate_)*/ std::vector speed_per_pstate_; /*< List of supported CPU capacities (pstate related). Not 'const' because VCPU get modified on migration */ - friend simgrid::vm::VirtualMachineImpl; // Resets the VCPU public: /** * @brief Cpu constructor * - * @param model The CpuModel associated to this 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 speedPerPstate Processor speed (in flop per second) for each pstate - * @param core The number of core of this Cpu + * @param speed_per_pstate Processor speed (in flop per second) for each pstate */ - Cpu(Model* model, s4u::Host* host, lmm::Constraint* constraint, const std::vector& speed_per_pstate, - int core); + Cpu(s4u::Host* host, const std::vector& speed_per_pstate); - /** - * @brief Cpu constructor + Cpu(const Cpu&) = delete; + Cpu& operator=(const Cpu&) = delete; + + /** @brief Public interface */ + s4u::Host* get_iface() { return piface_; } + + Cpu* set_core_count(int core_count); + virtual int get_core_count(); + + /** @brief Get a forecast of the speed (in flops/s) if the load were as provided. * - * @param model The CpuModel associated to this Cpu - * @param host The host in which this Cpu should be plugged - * @param speedPerPstate Processor speed (in flop per second) for each pstate - * @param core The number of core of this Cpu + * The provided load should encompasses both the application's activities and the external load that come from a + * trace. + * + * Use a load of 1.0 to compute the amount of flops that the Cpu would deliver with one CPU-bound task. + * If you use a load of 0, this function will return 0: when nobody is using the Cpu, it delivers nothing. + * + * If you want to know the amount of flops currently delivered, use load = get_load()*get_speed_ratio() */ - Cpu(Model* model, s4u::Host* host, const std::vector& speed_per_pstate, int core); + virtual double get_speed(double load) const { return load * speed_.peak; } - Cpu(const Cpu&) = delete; - Cpu& operator=(const Cpu&) = delete; + /** @brief Get the available speed ratio, in [0:1]. This accounts for external load (see @ref set_speed_profile()). */ + virtual double get_speed_ratio() { return speed_.scale; } + + /** @brief Get the peak processor speed (in flops/s), at the specified pstate */ + virtual double get_pstate_peak_speed(int pstate_index) const; + + virtual int get_pstate_count() const { return speed_per_pstate_.size(); } + + virtual void set_pstate(int pstate_index); + virtual int get_pstate() const { return pstate_; } + + /*< @brief Setup the trace file with availability events (peak speed changes due to external load). + * Trace must contain relative values (ratio between 0 and 1) + */ + virtual void set_speed_profile(profile::Profile* profile); /** * @brief Execute some quantity of computation @@ -112,21 +128,6 @@ public: */ virtual CpuAction* sleep(double duration) = 0; - Cpu* set_core_count(int core_count); - /** @brief Get the amount of cores */ - virtual int get_core_count(); - - /** @brief Get a forecast of the speed (in flops/s) if the load were as provided. - * - * The provided load should encompasses both the application's activities and the external load that come from a trace. - * - * Use a load of 1.0 to compute the amount of flops that the Cpu would deliver with one CPU-bound task. - * If you use a load of 0, this function will return 0: when nobody is using the Cpu, it delivers nothing. - * - * If you want to know the amount of flops currently delivered, use load = get_load()*get_speed_ratio() - */ - virtual double get_speed(double load) const; - protected: /** @brief Take speed changes (either load or max) into account */ virtual void on_speed_change(); @@ -138,28 +139,6 @@ protected: **/ virtual void reset_vcpu(Cpu* that); -public: - /** @brief Get the available speed ratio, between 0 and 1. - * - * This accounts for external load (see @ref set_speed_trace()). - */ - virtual double get_speed_ratio(); - - /** @brief Get the peak processor speed (in flops/s), at the specified pstate */ - virtual double get_pstate_peak_speed(int pstate_index) const; - - virtual int get_pstate_count() const; - virtual void set_pstate(int pstate_index); - virtual int get_pstate() const; - - s4u::Host* get_host() { return host_; } - - /*< @brief Setup the trace file with availability events (peak speed changes due to external load). - * Trace must contain relative values (ratio between 0 and 1) - */ - virtual void set_speed_profile(profile::Profile* profile); - -protected: Metric speed_ = {1.0, 0, nullptr}; }; diff --git a/src/surf/cpu_ti.cpp b/src/surf/cpu_ti.cpp index 1d0e39487f..91cf686226 100644 --- a/src/surf/cpu_ti.cpp +++ b/src/surf/cpu_ti.cpp @@ -324,9 +324,10 @@ void CpuTiModel::update_actions_state(double now, double /*delta*/) * Resource * ************/ CpuTi::CpuTi(CpuTiModel* model, s4u::Host* host, const std::vector& speed_per_pstate, int core) - : Cpu(model, host, speed_per_pstate, core) + : Cpu(host, speed_per_pstate) { xbt_assert(core == 1, "Multi-core not handled by this model yet"); + this->set_model(model); speed_.peak = speed_per_pstate.front(); XBT_DEBUG("CPU create: peak=%f", speed_.peak); @@ -374,11 +375,11 @@ void CpuTi::apply_event(kernel::profile::Event* event, double value) } else if (event == state_event_) { if (value > 0) { if (not is_on()) { - XBT_VERB("Restart actors on host %s", get_host()->get_cname()); - get_host()->turn_on(); + XBT_VERB("Restart actors on host %s", get_iface()->get_cname()); + get_iface()->turn_on(); } } else { - get_host()->turn_off(); + get_iface()->turn_off(); double date = surf_get_clock(); /* put all action running on cpu to failed */ diff --git a/src/surf/ptask_L07.cpp b/src/surf/ptask_L07.cpp index d8757a07e3..4746890ac0 100644 --- a/src/surf/ptask_L07.cpp +++ b/src/surf/ptask_L07.cpp @@ -239,9 +239,10 @@ kernel::resource::LinkImpl* NetworkL07Model::create_link(const std::string& name ************/ CpuL07::CpuL07(CpuL07Model* model, simgrid::s4u::Host* host, const std::vector& speed_per_pstate, int core) - : Cpu(model, host, model->get_maxmin_system()->constraint_new(this, speed_per_pstate.front()), speed_per_pstate, - core) + : Cpu(host, speed_per_pstate) { + this->set_core_count(core)->set_model(model)->set_constraint( + model->get_maxmin_system()->constraint_new(this, speed_per_pstate.front())); } CpuL07::~CpuL07()=default; @@ -257,7 +258,7 @@ LinkL07::LinkL07(NetworkL07Model* model, const std::string& name, double bandwid kernel::resource::CpuAction* CpuL07::execution_start(double size) { - std::vector host_list = {get_host()}; + std::vector host_list = {get_iface()}; auto* flops_amount = new double[host_list.size()](); flops_amount[0] = size; @@ -315,11 +316,11 @@ void CpuL07::apply_event(kernel::profile::Event* triggered, double value) } else if (triggered == state_event_) { if (value > 0) { if (not is_on()) { - XBT_VERB("Restart actors on host %s", get_host()->get_cname()); - get_host()->turn_on(); + XBT_VERB("Restart actors on host %s", get_iface()->get_cname()); + get_iface()->turn_on(); } } else - get_host()->turn_off(); + get_iface()->turn_off(); tmgr_trace_event_unref(&state_event_); } else {