Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Close #105
[simgrid.git] / src / plugins / vm / s4u_VirtualMachine.cpp
index 3ee05b2..848098e 100644 (file)
@@ -3,19 +3,23 @@
 /* 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. */
 
+#include "simgrid/s4u/Actor.hpp"
 #include "src/instr/instr_private.hpp"
 #include "src/plugins/vm/VirtualMachineImpl.hpp"
 #include "src/plugins/vm/VmHostExt.hpp"
 #include "src/simix/smx_host_private.hpp"
 #include "src/surf/cpu_cas01.hpp"
+#include <src/plugins/vm/VmLiveMigration.hpp>
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_vm, "S4U virtual machines");
 
+simgrid::xbt::signal<void(simgrid::s4u::VirtualMachine*)> simgrid::s4u::VirtualMachine::onVmShutdown;
+
 namespace simgrid {
 namespace s4u {
 
 VirtualMachine::VirtualMachine(const char* name, s4u::Host* pm, int coreAmount)
-    : VirtualMachine(name, pm, coreAmount, 0)
+    : VirtualMachine(name, pm, coreAmount, 1024)
 {
 }
 
@@ -37,8 +41,10 @@ VirtualMachine::VirtualMachine(const char* name, s4u::Host* pm, int coreAmount,
   extension_set<simgrid::simix::Host>(new simgrid::simix::Host());
 
   if (TRACE_msg_vm_is_enabled()) {
-    container_t host_container = simgrid::instr::Container::byName(pm->getName());
-    new simgrid::instr::Container(name, "MSG_VM", host_container);
+    container_t host_container = instr::Container::byName(pm->getName());
+    new instr::Container(name, "MSG_VM", host_container);
+    instr::Container::byName(getName())->getState("MSG_VM_STATE")->addEntityValue("start", "0 0 1");   // start is blue
+    instr::Container::byName(getName())->getState("MSG_VM_STATE")->addEntityValue("suspend", "1 0 0"); // suspend is red
   }
 }
 
@@ -58,10 +64,19 @@ VirtualMachine::~VirtualMachine()
 
   /* Don't free these things twice: they are the ones of my physical host */
   pimpl_netpoint = nullptr;
+
+  if (TRACE_msg_vm_is_enabled()) {
+    container_t container = simgrid::instr::Container::byName(getName());
+    container->removeFromParent();
+    delete container;
+  }
 }
 
 void VirtualMachine::start()
 {
+  if (TRACE_msg_vm_is_enabled())
+    simgrid::instr::Container::byName(getName())->getState("MSG_VM_STATE")->pushEvent("start");
+
   simgrid::simix::kernelImmediate([this]() {
     simgrid::vm::VmHostExt::ensureVmExtInstalled();
 
@@ -77,8 +92,8 @@ void VirtualMachine::start()
       /* 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::s4u::VirtualMachine* const& ws_vm : simgrid::vm::VirtualMachineImpl::allVms_)
-        if (pm == ws_vm->pimpl_vm_->getPm())
-          total_ramsize_of_vms += ws_vm->pimpl_vm_->getRamsize();
+        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).",
@@ -90,24 +105,41 @@ void VirtualMachine::start()
 
     this->pimpl_vm_->setState(SURF_VM_STATE_RUNNING);
   });
+
+  if (TRACE_msg_vm_is_enabled())
+    simgrid::instr::Container::byName(getName())->getState("MSG_VM_STATE")->popEvent();
 }
 
 void VirtualMachine::suspend()
 {
   smx_actor_t issuer = SIMIX_process_self();
   simgrid::simix::kernelImmediate([this, issuer]() { pimpl_vm_->suspend(issuer); });
+  if (TRACE_msg_vm_is_enabled())
+    simgrid::instr::Container::byName(getName())->getState("MSG_VM_STATE")->pushEvent("suspend");
   XBT_DEBUG("vm_suspend done");
 }
 
 void VirtualMachine::resume()
 {
   pimpl_vm_->resume();
+  if (TRACE_msg_vm_is_enabled())
+    simgrid::instr::Container::byName(getName())->getState("MSG_VM_STATE")->popEvent();
 }
 
 void VirtualMachine::shutdown()
 {
   smx_actor_t issuer = SIMIX_process_self();
   simgrid::simix::kernelImmediate([this, issuer]() { pimpl_vm_->shutdown(issuer); });
+  onVmShutdown(this);
+}
+
+void VirtualMachine::destroy()
+{
+  /* First, terminate all processes on the VM if necessary */
+  shutdown();
+
+  /* Then, destroy the VM object */
+  Host::destroy();
 }
 
 bool VirtualMachine::isMigrating()
@@ -120,9 +152,14 @@ simgrid::s4u::Host* VirtualMachine::getPm()
   return pimpl_vm_->getPm();
 }
 
+void VirtualMachine::setPm(simgrid::s4u::Host* pm)
+{
+  simgrid::simix::kernelImmediate([this, pm]() { pimpl_vm_->setPm(pm); });
+}
+
 e_surf_vm_state_t VirtualMachine::getState()
 {
-  return pimpl_vm_->getState();
+  return simgrid::simix::kernelImmediate([this]() { return pimpl_vm_->getState(); });
 }
 
 size_t VirtualMachine::getRamsize()
@@ -164,17 +201,6 @@ void VirtualMachine::setBound(double bound)
 {
   simgrid::simix::kernelImmediate([this, bound]() { pimpl_vm_->setBound(bound); });
 }
-/** @brief Retrieve a copy of the parameters of that VM/PM
- *  @details The ramsize and overcommit fields are used on the PM too */
-void VirtualMachine::getParameters(vm_params_t params)
-{
-  pimpl_vm_->getParams(params);
-}
-/** @brief Sets the params of that VM/PM */
-void VirtualMachine::setParameters(vm_params_t params)
-{
-  simgrid::simix::kernelImmediate([this, params] { pimpl_vm_->setParams(params); });
-}
 
 } // namespace simgrid
 } // namespace s4u