Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cleanups
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Mon, 1 Mar 2021 23:54:36 +0000 (00:54 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Tue, 2 Mar 2021 18:52:28 +0000 (19:52 +0100)
src/plugins/host_energy.cpp
src/surf/cpu_cas01.cpp
src/surf/cpu_interface.cpp
src/surf/cpu_interface.hpp
src/surf/cpu_ti.cpp
src/surf/ptask_L07.cpp

index 88e243f..a1033c8 100644 (file)
@@ -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<simgrid::s4u::VirtualMachine*>(host);
index 02d4abb..9694417 100644 (file)
@@ -87,9 +87,10 @@ Cpu* CpuCas01Model::create_cpu(s4u::Host* host, const std::vector<double>& speed
  * Resource *
  ************/
 CpuCas01::CpuCas01(CpuCas01Model* model, s4u::Host* host, const std::vector<double>& 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();
index cd1fa08..f3a5247 100644 (file)
@@ -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<double>& speed_per_pstate, int core)
-    : Cpu(model, host, nullptr /*constraint*/, speed_per_pstate, core)
+Cpu::Cpu(s4u::Host* host, const std::vector<double>& 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<double>& 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<int>(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<int>(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 *
  **********/
index fa856e7..f745b5d 100644 (file)
@@ -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<double> 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<double>& speed_per_pstate,
-      int core);
+  Cpu(s4u::Host* host, const std::vector<double>& 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<double>& 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};
 };
 
index 1d0e394..91cf686 100644 (file)
@@ -324,9 +324,10 @@ void CpuTiModel::update_actions_state(double now, double /*delta*/)
  * Resource *
  ************/
 CpuTi::CpuTi(CpuTiModel* model, s4u::Host* host, const std::vector<double>& 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 */
index d8757a0..4746890 100644 (file)
@@ -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<double>& 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<s4u::Host*> host_list = {get_host()};
+  std::vector<s4u::Host*> 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 {