Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
New API: set_pstate_speed
authorBruno Donassolo <bruno.donassolo@inria.fr>
Thu, 25 Mar 2021 16:48:42 +0000 (17:48 +0100)
committerBruno Donassolo <bruno.donassolo@inria.fr>
Tue, 30 Mar 2021 11:47:14 +0000 (13:47 +0200)
Implement new API to set pstate for a host:
- Host* Host::set_pstate_speed(const std::vector<double>& speed_per_state)
- Host* Host::set_pstate_speed(const std::vector<std::string>& speed_per_state)

include/simgrid/s4u/Host.hpp
src/s4u/s4u_Host.cpp
src/surf/cpu_interface.cpp
src/surf/cpu_interface.hpp

index f4a1174..7ebb16d 100644 (file)
@@ -107,6 +107,15 @@ public:
   Host* set_state_profile(kernel::profile::Profile* p);
   Host* set_speed_profile(kernel::profile::Profile* p);
 
+  /**
+   * @brief Set the CPU's speed
+   *
+   * @param speed_per_state list of powers for this processor (default power is at index 0)
+   */
+  Host* set_pstate_speed(const std::vector<double>& speed_per_state);
+  /** @brief Set the CPU's speed (string version) */
+  Host* set_pstate_speed(const std::vector<std::string>& speed_per_state);
+
   /** @brief Get the peak computing speed in flops/s at the current pstate, NOT taking the external load into account.
    *
    *  The amount of flops per second available for computing depends on several things:
@@ -177,7 +186,7 @@ public:
 
 private:
   xbt::string name_{"noname"};
-  kernel::routing::NetPoint* pimpl_netpoint_         = nullptr;
+  kernel::routing::NetPoint* pimpl_netpoint_ = nullptr;
 
 public:
 #ifndef DOXYGEN
index 918d757..f7b9a43 100644 (file)
@@ -3,6 +3,7 @@
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
+#include "simgrid/Exception.hpp"
 #include "simgrid/host.h"
 #include "simgrid/kernel/routing/NetPoint.hpp"
 #include "simgrid/s4u/Actor.hpp"
@@ -12,6 +13,7 @@
 #include "simgrid/s4u/VirtualMachine.hpp"
 #include "src/plugins/vm/VirtualMachineImpl.hpp"
 #include "src/surf/HostImpl.hpp"
+#include "xbt/parse_units.hpp"
 
 #include <algorithm>
 #include <string>
@@ -264,6 +266,27 @@ Host* Host::set_core_count(int core_count)
   return this;
 }
 
+Host* Host::set_pstate_speed(const std::vector<double>& speed_per_state)
+{
+  kernel::actor::simcall([this, &speed_per_state] { pimpl_cpu->set_pstate_speed(speed_per_state); });
+  return this;
+}
+
+Host* Host::set_pstate_speed(const std::vector<std::string>& speed_per_state)
+{
+  std::vector<double> speed_list(speed_per_state.size());
+  for (const auto& speed_str : speed_per_state) {
+    try {
+      double speed = xbt_parse_get_speed("", 0, speed_str.c_str(), nullptr, "");
+      speed_list.push_back(speed);
+    } catch (const simgrid::ParseError& e) {
+      xbt_die("Host(%s): Impossible to set_pstate_speed, invalid speed %s", get_cname(), speed_str.c_str());
+    }
+  }
+  set_pstate_speed(speed_list);
+  return this;
+}
+
 /** @brief Set the pstate at which the host should run */
 Host* Host::set_pstate(int pstate_index)
 {
index 33d23eb..9d4b575 100644 (file)
@@ -52,7 +52,7 @@ void CpuModel::update_actions_state_full(double /*now*/, double delta)
 Cpu::Cpu(s4u::Host* host, const std::vector<double>& speed_per_pstate)
     : Resource_T(host->get_cname()), piface_(host), speed_per_pstate_(speed_per_pstate)
 {
-  speed_.scale = 1;
+  speed_.scale    = 1;
   speed_.peak     = speed_per_pstate_.front();
   host->pimpl_cpu = this;
 }
@@ -73,13 +73,21 @@ Cpu* Cpu::set_pstate(int pstate_index)
              get_cname(), pstate_index, static_cast<int>(speed_per_pstate_.size()));
 
   double new_peak_speed = speed_per_pstate_[pstate_index];
-  pstate_ = pstate_index;
-  speed_.peak = new_peak_speed;
+  pstate_               = pstate_index;
+  speed_.peak           = new_peak_speed;
 
   on_speed_change();
   return this;
 }
 
+Cpu* Cpu::set_pstate_speed(const std::vector<double>& speed_per_state)
+{
+  xbt_assert(speed_per_state.size() > 0, "CPU %s: processor speed vector cannot be empty", get_cname());
+  xbt_assert(not is_sealed(), "CPU %s: processor speed cannot be changed once CPU has been sealed", get_cname());
+  speed_per_pstate_ = speed_per_state;
+  return this;
+}
+
 double Cpu::get_pstate_peak_speed(int pstate_index) const
 {
   xbt_assert((pstate_index <= static_cast<int>(speed_per_pstate_.size())),
@@ -152,13 +160,15 @@ void CpuAction::update_remains_lazy(double now)
 
 xbt::signal<void(CpuAction const&, Action::State)> CpuAction::on_state_change;
 
-void CpuAction::suspend(){
+void CpuAction::suspend()
+{
   Action::State previous = get_state();
   on_state_change(*this, previous);
   Action::suspend();
 }
 
-void CpuAction::resume(){
+void CpuAction::resume()
+{
   Action::State previous = get_state();
   on_state_change(*this, previous);
   Action::resume();
index 5ff2d29..03dffc6 100644 (file)
@@ -105,6 +105,13 @@ public:
    */
   virtual Cpu* set_speed_profile(profile::Profile* profile);
 
+  /**
+   * @brief Set the CPU's speed
+   *
+   * @param speed_per_state list of powers for this processor (default power is at index 0)
+   */
+  Cpu* set_pstate_speed(const std::vector<double>& speed_per_state);
+
   /**
    * @brief Execute some quantity of computation
    *