From: Martin Quinson Date: Sun, 20 Nov 2016 18:35:50 +0000 (+0100) Subject: Kill a VM-related function out of HostImpl X-Git-Tag: v3_14~165 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/20fc29c9161b5d8356c192fc2ddd031f7fe1fe76 Kill a VM-related function out of HostImpl --- diff --git a/src/plugins/vm/VirtualMachineImpl.cpp b/src/plugins/vm/VirtualMachineImpl.cpp index 5b03ca6fa5..51e42efd6d 100644 --- a/src/plugins/vm/VirtualMachineImpl.cpp +++ b/src/plugins/vm/VirtualMachineImpl.cpp @@ -241,6 +241,11 @@ void VirtualMachineImpl::migrate(s4u::Host* host_dest) XBT_DEBUG("migrate VM(%s): change PM (%s to %s)", vm_name, pm_name_src, pm_name_dst); } +sg_size_t VirtualMachineImpl::getRamsize() +{ + return params_.ramsize; +} + void VirtualMachineImpl::setBound(double bound) { action_->setBound(bound); diff --git a/src/plugins/vm/VirtualMachineImpl.hpp b/src/plugins/vm/VirtualMachineImpl.hpp index 0a25e54fed..b13f3e7450 100644 --- a/src/plugins/vm/VirtualMachineImpl.hpp +++ b/src/plugins/vm/VirtualMachineImpl.hpp @@ -78,6 +78,8 @@ public: /** @brief Get the physical machine hosting the VM */ s4u::Host* getPm(); + sg_size_t getRamsize(); + virtual void setBound(double bound); void getParams(vm_params_t params); diff --git a/src/simix/smx_vm.cpp b/src/simix/smx_vm.cpp index 359286a48a..080cf30b7a 100644 --- a/src/simix/smx_vm.cpp +++ b/src/simix/smx_vm.cpp @@ -27,14 +27,14 @@ static long host_get_ramsize(sg_host_t vm, int *overcommit) /* **** start a VM **** */ static int __can_be_started(sg_host_t vm) { - simgrid::vm::VmHostExt::ensureVmExtInstalled(); - sg_host_t pm = static_cast(vm)->pimpl_vm_->getPm(); - int pm_overcommit = 0; + simgrid::vm::VmHostExt::ensureVmExtInstalled(); if (pm->extension() == nullptr) pm->extension_set(new simgrid::vm::VmHostExt()); + long pm_ramsize = pm->extension()->ramsize; + int pm_overcommit = pm->extension()->overcommit; long vm_ramsize = host_get_ramsize(vm, nullptr); if (!pm_ramsize) { @@ -47,22 +47,16 @@ static int __can_be_started(sg_host_t vm) return 1; } + /* 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; - xbt_dynar_t dyn_vms = pm->pimpl_->getVms(); - { - unsigned int cursor = 0; - sg_host_t another_vm; - xbt_dynar_foreach(dyn_vms, cursor, another_vm) { - long another_vm_ramsize = host_get_ramsize(vm, nullptr); - total_ramsize_of_vms += another_vm_ramsize; - } - } + for (simgrid::surf::VirtualMachineImpl* ws_vm : simgrid::surf::VirtualMachineImpl::allVms_) + if (pm == ws_vm->getPm()) + total_ramsize_of_vms += ws_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).", sg_host_get_name(vm), sg_host_get_name(pm), vm_ramsize, pm_ramsize - total_ramsize_of_vms, pm_ramsize); - xbt_dynar_free(&dyn_vms); return 0; } diff --git a/src/surf/HostImpl.cpp b/src/surf/HostImpl.cpp index 52dcdbcba8..c24abb7d01 100644 --- a/src/surf/HostImpl.cpp +++ b/src/surf/HostImpl.cpp @@ -318,16 +318,5 @@ xbt_dynar_t HostImpl::getAttachedStorageList() } } - xbt_dynar_t HostImpl::getVms() - { - xbt_dynar_t dyn = xbt_dynar_new(sizeof(simgrid::surf::VirtualMachineImpl*), nullptr); - - for (VirtualMachineImpl* ws_vm : VirtualMachineImpl::allVms_) { - if (this == ws_vm->getPm()->pimpl_) - xbt_dynar_push(dyn, &ws_vm); - } - - return dyn; - } } } diff --git a/src/surf/HostImpl.hpp b/src/surf/HostImpl.hpp index 76926014b3..44858a6415 100644 --- a/src/surf/HostImpl.hpp +++ b/src/surf/HostImpl.hpp @@ -1,5 +1,4 @@ -/* Copyright (c) 2004-2015. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2004-2016. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -179,9 +178,6 @@ public: xbt_dynar_t storage_ = nullptr; simgrid::s4u::Host* piface_ = nullptr; - /** @brief Get the list of virtual machines on the current Host */ - xbt_dynar_t getVms(); - simgrid::s4u::Host* getHost() { return piface_; } }; }