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:
private:
xbt::string name_{"noname"};
- kernel::routing::NetPoint* pimpl_netpoint_ = nullptr;
+ kernel::routing::NetPoint* pimpl_netpoint_ = nullptr;
public:
#ifndef DOXYGEN
/* 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"
#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>
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)
{
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;
}
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())),
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();
*/
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
*