From 46b3f69b83f27f9958a26e19b21ce4be64914d71 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Wed, 12 Aug 2020 01:37:39 +0200 Subject: [PATCH] Make sure that VM::get_speed() returns the correct value after a migration 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 | 3 +++ src/surf/cpu_interface.cpp | 8 ++++++++ src/surf/cpu_interface.hpp | 13 +++++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/plugins/vm/VirtualMachineImpl.cpp b/src/plugins/vm/VirtualMachineImpl.cpp index 80f1689d51..1bb1944a84 100644 --- a/src/plugins/vm/VirtualMachineImpl.cpp +++ b/src/plugins/vm/VirtualMachineImpl.cpp @@ -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 */ diff --git a/src/surf/cpu_interface.cpp b/src/surf/cpu_interface.cpp index f85cce4b9f..6cbbe10fcc 100644 --- a/src/surf/cpu_interface.cpp +++ b/src/surf/cpu_interface.cpp @@ -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(); diff --git a/src/surf/cpu_interface.hpp b/src/surf/cpu_interface.hpp index 1e77a39467..0215897243 100644 --- a/src/surf/cpu_interface.hpp +++ b/src/surf/cpu_interface.hpp @@ -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 speed_per_pstate_; /*< List of supported CPU capacities (pstate related) */ + int pstate_ = 0; /*< Current pstate (index in the speed_per_pstate_)*/ + std::vector 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. * -- 2.20.1