Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Kill a VM-related function out of HostImpl
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 20 Nov 2016 18:35:50 +0000 (19:35 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Sun, 20 Nov 2016 18:35:50 +0000 (19:35 +0100)
src/plugins/vm/VirtualMachineImpl.cpp
src/plugins/vm/VirtualMachineImpl.hpp
src/simix/smx_vm.cpp
src/surf/HostImpl.cpp
src/surf/HostImpl.hpp

index 5b03ca6..51e42ef 100644 (file)
@@ -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);
index 0a25e54..b13f3e7 100644 (file)
@@ -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);
index 359286a..080cf30 100644 (file)
@@ -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<simgrid::s4u::VirtualMachine*>(vm)->pimpl_vm_->getPm();
 
-  int pm_overcommit = 0;
+  simgrid::vm::VmHostExt::ensureVmExtInstalled();
   if (pm->extension<simgrid::vm::VmHostExt>() == nullptr)
     pm->extension_set(new simgrid::vm::VmHostExt());
+
   long pm_ramsize = pm->extension<simgrid::vm::VmHostExt>()->ramsize;
+  int pm_overcommit = pm->extension<simgrid::vm::VmHostExt>()->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;
   }
 
index 52dcdbc..c24abb7 100644 (file)
@@ -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;
-    }
     }
     }
index 7692601..44858a6 100644 (file)
@@ -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_; }
 };
 }