+Cpu::Cpu(Model *model, simgrid::s4u::Host *host, std::vector<double> *speedPerPstate, int core)
+ : Cpu(model, host, nullptr/*constraint*/, speedPerPstate, core)
+{
+}
+
+Cpu::Cpu(Model* model, simgrid::s4u::Host* host, lmm_constraint_t constraint, std::vector<double>* speedPerPstate,
+ int core)
+ : Resource(model, host->getCname(), constraint), coresAmount_(core), host_(host)
+{
+ xbt_assert(core > 0, "Host %s must have at least one core, not 0.", host->getCname());
+
+ speed_.peak = speedPerPstate->front();
+ speed_.scale = 1;
+ host->pimpl_cpu = this;
+ xbt_assert(speed_.scale > 0, "Speed of host %s must be >0", host->getCname());
+
+ // Copy the power peak array:
+ for (double const& value : *speedPerPstate) {
+ speedPerPstate_.push_back(value);
+ }
+}
+
+Cpu::~Cpu() = default;
+
+int Cpu::getNbPStates()
+{
+ return speedPerPstate_.size();
+}
+
+void Cpu::setPState(int pstate_index)
+{
+ xbt_assert(pstate_index <= static_cast<int>(speedPerPstate_.size()),
+ "Invalid parameters for CPU %s (pstate %d > length of pstates %d). Please fix your platform file, or your "
+ "call to change the pstate.",
+ getCname(), pstate_index, static_cast<int>(speedPerPstate_.size()));
+
+ double new_peak_speed = speedPerPstate_[pstate_index];
+ pstate_ = pstate_index;
+ speed_.peak = new_peak_speed;
+
+ onSpeedChange();
+}
+
+int Cpu::getPState()
+{
+ return pstate_;
+}
+
+double Cpu::getPstateSpeed(int pstate_index)
+{
+ xbt_assert((pstate_index <= static_cast<int>(speedPerPstate_.size())), "Invalid parameters (pstate index out of bounds)");
+
+ return speedPerPstate_[pstate_index];
+}