From 1e2bdd3b231b3a1df3b910c800c1e5e9224d41fc Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Mon, 21 Nov 2016 08:22:08 +0100 Subject: [PATCH] store the VMs by their interface, not by their implementation --- src/plugins/vm/VirtualMachineImpl.cpp | 18 +++++++++--------- src/plugins/vm/VirtualMachineImpl.hpp | 4 ++-- src/simix/smx_vm.cpp | 6 +++--- src/surf/HostImpl.cpp | 8 ++++---- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/plugins/vm/VirtualMachineImpl.cpp b/src/plugins/vm/VirtualMachineImpl.cpp index 931e00c1ab..b01ab0a7e4 100644 --- a/src/plugins/vm/VirtualMachineImpl.cpp +++ b/src/plugins/vm/VirtualMachineImpl.cpp @@ -38,7 +38,7 @@ simgrid::xbt::signal onVmStateChange; * Model * *********/ -std::deque VirtualMachineImpl::allVms_; +std::deque VirtualMachineImpl::allVms_; /* In the real world, processes on the guest operating system will be somewhat degraded due to virtualization overhead. * The total CPU share these processes get is smaller than that of the VM process gets on a host operating system. */ @@ -72,13 +72,13 @@ double VMModel::nextOccuringEvent(double now) **/ /* iterate for all virtual machines */ - for (VirtualMachineImpl* ws_vm : VirtualMachineImpl::allVms_) { - Cpu* cpu = ws_vm->piface_->pimpl_cpu; + for (s4u::VirtualMachine* ws_vm : VirtualMachineImpl::allVms_) { + Cpu* cpu = ws_vm->pimpl_cpu; xbt_assert(cpu, "cpu-less host"); - double solved_value = ws_vm->action_->getVariable()->value; - XBT_DEBUG("assign %f to vm %s @ pm %s", solved_value, ws_vm->piface_->name().c_str(), - ws_vm->getPm()->name().c_str()); + double solved_value = ws_vm->pimpl_vm_->action_->getVariable()->value; + XBT_DEBUG("assign %f to vm %s @ pm %s", solved_value, ws_vm->name().c_str(), + ws_vm->pimpl_vm_->getPm()->name().c_str()); // TODO: check lmm_update_constraint_bound() works fine instead of the below manual substitution. // cpu_cas01->constraint->bound = solved_value; @@ -98,11 +98,11 @@ double VMModel::nextOccuringEvent(double now) * Resource * ************/ -VirtualMachineImpl::VirtualMachineImpl(simgrid::s4u::Host* piface, simgrid::s4u::Host* host_PM) +VirtualMachineImpl::VirtualMachineImpl(simgrid::s4u::VirtualMachine* piface, simgrid::s4u::Host* host_PM) : HostImpl(piface, nullptr /*storage*/), hostPM_(host_PM) { /* Register this VM to the list of all VMs */ - allVms_.push_back(this); + allVms_.push_back(piface); /* We create cpu_action corresponding to a VM process on the host operating system. */ /* FIXME: TODO: we have to periodically input GUESTOS_NOISE to the system? how ? */ @@ -120,7 +120,7 @@ extern "C" int VirtualMachineImpl::~VirtualMachineImpl() { onVmDestruction(this); - allVms_.erase(find(allVms_.begin(), allVms_.end(), this)); + allVms_.erase(find(allVms_.begin(), allVms_.end(), piface_)); /* dirty page tracking */ unsigned int size = xbt_dict_size(dp_objs); diff --git a/src/plugins/vm/VirtualMachineImpl.hpp b/src/plugins/vm/VirtualMachineImpl.hpp index 06d413e311..353f9a9074 100644 --- a/src/plugins/vm/VirtualMachineImpl.hpp +++ b/src/plugins/vm/VirtualMachineImpl.hpp @@ -57,7 +57,7 @@ extern XBT_PRIVATE simgrid::xbt::signal allVms_; + static std::deque allVms_; bool isMigrating = false; diff --git a/src/simix/smx_vm.cpp b/src/simix/smx_vm.cpp index e11f0777d4..429bd5cd45 100644 --- a/src/simix/smx_vm.cpp +++ b/src/simix/smx_vm.cpp @@ -40,9 +40,9 @@ void SIMIX_vm_start(sg_host_t vm) if (pm_ramsize && !pm_overcommit) { /* Only verify that we don't overcommit on need */ /* Retrieve the memory occupied by the VMs on that host. Yep, we have to traverse all VMs of all hosts for that */ long total_ramsize_of_vms = 0; - for (simgrid::surf::VirtualMachineImpl* ws_vm : simgrid::surf::VirtualMachineImpl::allVms_) - if (pm == ws_vm->getPm()) - total_ramsize_of_vms += ws_vm->getRamsize(); + for (simgrid::s4u::VirtualMachine* ws_vm : simgrid::surf::VirtualMachineImpl::allVms_) + if (pm == ws_vm->pimpl_vm_->getPm()) + total_ramsize_of_vms += ws_vm->pimpl_vm_->getRamsize(); if (vm_ramsize > pm_ramsize - total_ramsize_of_vms) { XBT_WARN("cannnot start %s@%s due to memory shortage: vm_ramsize %ld, free %ld, pm_ramsize %ld (bytes).", diff --git a/src/surf/HostImpl.cpp b/src/surf/HostImpl.cpp index c24abb7d01..bda7540fb7 100644 --- a/src/surf/HostImpl.cpp +++ b/src/surf/HostImpl.cpp @@ -35,9 +35,9 @@ namespace surf { void HostModel::adjustWeightOfDummyCpuActions() { /* iterate for all virtual machines */ - for (VirtualMachineImpl* ws_vm : VirtualMachineImpl::allVms_) { + for (s4u::VirtualMachine* ws_vm : VirtualMachineImpl::allVms_) { - Cpu* cpu = ws_vm->piface_->pimpl_cpu; + Cpu* cpu = ws_vm->pimpl_cpu; int is_active = lmm_constraint_used(cpu->getModel()->getMaxminSystem(), cpu->getConstraint()); @@ -47,13 +47,13 @@ void HostModel::adjustWeightOfDummyCpuActions() /* FIXME: we should use lmm_update_variable_weight() ? */ /* FIXME: If we assign 1.05 and 0.05, the system makes apparently wrong values. */ - ws_vm->action_->setPriority(1); + ws_vm->pimpl_vm_->action_->setPriority(1); } else { /* no task exits on this VM */ XBT_DEBUG("set the weight of the dummy CPU action on PM to 0"); - ws_vm->action_->setPriority(0); + ws_vm->pimpl_vm_->action_->setPriority(0); } } } -- 2.20.1