Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make sure that VM::get_speed() returns the correct value after a migration
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Tue, 11 Aug 2020 23:37:39 +0000 (01:37 +0200)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Wed, 12 Aug 2020 08:51:54 +0000 (10:51 +0200)
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.

src/plugins/vm/VirtualMachineImpl.cpp
src/surf/cpu_interface.cpp
src/surf/cpu_interface.hpp

index 80f1689..1bb1944 100644 (file)
@@ -290,6 +290,9 @@ void VirtualMachineImpl::set_physical_host(s4u::Host* destination)
   /* 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 */
index f85cce4..6cbbe10 100644 (file)
@@ -72,6 +72,14 @@ Cpu::Cpu(Model* model, s4u::Host* host, lmm::Constraint* constraint, const std::
   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();
index 1e77a39..0215897 100644 (file)
@@ -56,8 +56,10 @@ class CpuAction;
 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:
   /**
@@ -128,6 +130,13 @@ protected:
   /** @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.
    *