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);
* 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;
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();
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();
/************
* 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)
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()),
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())),
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;
}
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 *
**********/
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;
* 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
*/
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();
**/
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};
};
* 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);
} 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 */
************/
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;
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;
} 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 {