For that, I reset the physical fields of the CPU (speed_, pstate_ and
speed_per_pstate_) to the ones of the new physical host during the
migration.
Maybe we should change only the speed_, and prevent the use of pstate
things in VM?
Another approach for this commit could be to make Host::get_speed()
and friend virtual, and to override them in the VM to use the values
of the underlying physical CPU (ie, of get_pm()->pimple_cpu) instead
of the one of the VM's VCPU, but I fear to still use the wrong speed
in some cases, in particular when a new execution in created onto the
VCPU.
This forbids speed_per_pstate_ to be 'const', since we reset it for
VCPUs on VM migration. Another approach could have been to destroy and
re-create the VCPU on migration, but I'd have to update the LMM to
point the Execs to the newly created resource, which seems
troublesome.
/* update net_elm with that of the destination physical host */
piface_->set_netpoint(destination->get_netpoint());
+ /* Adapt the speed, pstate and other physical characteristics to the one of our new physical CPU */
+ piface_->pimpl_cpu->reset_vcpu(destination->pimpl_cpu);
+
physical_host_ = destination;
/* Update vcpu's action for the new pm */
xbt_assert(speed_.scale > 0, "Speed of host %s must be >0", host->get_cname());
}
+void Cpu::reset_vcpu(Cpu* that)
+{
+ this->pstate_ = that->pstate_;
+ this->speed_ = that->speed_;
+ this->speed_per_pstate_.clear();
+ 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();
class XBT_PUBLIC Cpu : public Resource {
int core_count_ = 1;
s4u::Host* host_;
- int pstate_ = 0; /*< Current pstate (index in the speed_per_pstate_)*/
- const std::vector<double> speed_per_pstate_; /*< List of supported CPU capacities (pstate related) */
+ 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 Take speed changes (either load or max) into account */
virtual void on_speed_change();
+ /** Reset most characteristics of this CPU to the one of that CPU.
+ *
+ * Used to reset a VCPU when its VM migrates to another host, so it only resets the fields that should be in this
+ *case.
+ **/
+ virtual void reset_vcpu(Cpu* that);
+
public:
/** @brief Get the available speed ratio, between 0 and 1.
*