Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use a reference as parameter for signal callbacks.
[simgrid.git] / src / plugins / vm / s4u_VirtualMachine.cpp
index b727465..f16253c 100644 (file)
@@ -1,13 +1,13 @@
-/* Copyright (c) 2015-2018. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2015-2019. 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. */
 
 #include "simgrid/s4u/Actor.hpp"
 #include "simgrid/vm.h"
+#include "src/include/surf/surf.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"
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_vm, "S4U virtual machines");
@@ -15,21 +15,26 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_vm, "S4U virtual machines");
 
 namespace simgrid {
 namespace s4u {
-simgrid::xbt::signal<void(VirtualMachine&)> VirtualMachine::on_start;
-simgrid::xbt::signal<void(VirtualMachine&)> VirtualMachine::on_started;
-simgrid::xbt::signal<void(VirtualMachine&)> VirtualMachine::on_shutdown;
-simgrid::xbt::signal<void(VirtualMachine&)> VirtualMachine::on_suspend;
-simgrid::xbt::signal<void(VirtualMachine&)> VirtualMachine::on_resume;
-
-VirtualMachine::VirtualMachine(const char* name, s4u::Host* physical_host, int core_amount)
+simgrid::xbt::signal<void(VirtualMachine const&)> VirtualMachine::on_start;
+simgrid::xbt::signal<void(VirtualMachine const&)> VirtualMachine::on_started;
+simgrid::xbt::signal<void(VirtualMachine const&)> VirtualMachine::on_shutdown;
+simgrid::xbt::signal<void(VirtualMachine const&)> VirtualMachine::on_suspend;
+simgrid::xbt::signal<void(VirtualMachine const&)> VirtualMachine::on_resume;
+simgrid::xbt::signal<void(VirtualMachine const&)> VirtualMachine::on_migration_start;
+simgrid::xbt::signal<void(VirtualMachine const&)> VirtualMachine::on_migration_end;
+
+VirtualMachine::VirtualMachine(const std::string& name, s4u::Host* physical_host, int core_amount)
     : VirtualMachine(name, physical_host, core_amount, 1024)
 {
 }
 
-VirtualMachine::VirtualMachine(const char* name, s4u::Host* physical_host, int core_amount, size_t ramsize)
+VirtualMachine::VirtualMachine(const std::string& name, s4u::Host* physical_host, int core_amount, size_t ramsize)
     : Host(name), pimpl_vm_(new vm::VirtualMachineImpl(this, physical_host, core_amount, ramsize))
 {
-  XBT_DEBUG("Create VM %s", name);
+  // xbt_assert(s4u::Host::by_name(name) == nullptr,
+  //           "Cannot create a VM named %s: this name is already used by a host or a VM", get_cname());
+
+  XBT_DEBUG("Create VM %s", get_cname());
 
   /* Currently, a VM uses the network resource of its physical host */
   pimpl_netpoint = physical_host->pimpl_netpoint;
@@ -39,12 +44,9 @@ VirtualMachine::VirtualMachine(const char* name, s4u::Host* physical_host, int c
   for (int i = 0; i < physical_host->get_pstate_count(); i++)
     speeds.push_back(physical_host->get_pstate_speed(i));
 
-  surf_cpu_model_vm->create_cpu(this, &speeds, physical_host->get_core_count());
+  surf_cpu_model_vm->create_cpu(this, &speeds, core_amount);
   if (physical_host->get_pstate() != 0)
     set_pstate(physical_host->get_pstate());
-
-  /* Make a process container */
-  extension_set<simgrid::simix::Host>(new simgrid::simix::Host());
 }
 
 VirtualMachine::~VirtualMachine()
@@ -53,14 +55,6 @@ VirtualMachine::~VirtualMachine()
 
   XBT_DEBUG("destroy %s", get_cname());
 
-  /* FIXME: this is really strange that everything fails if the next line is removed.
-   * This is as if we shared these data with the PM, which definitely should not be the case...
-   *
-   * We need to test that suspending a VM does not suspends the processes running on its PM, for example.
-   * Or we need to simplify this code enough to make it actually readable (but this sounds harder than testing)
-   */
-  extension_set<simgrid::simix::Host>(nullptr);
-
   /* Don't free these things twice: they are the ones of my physical host */
   pimpl_netpoint = nullptr;
 }
@@ -202,9 +196,6 @@ sg_vm_t sg_vm_create_core(sg_host_t pm, const char* name)
  */
 sg_vm_t sg_vm_create_multicore(sg_host_t pm, const char* name, int coreAmount)
 {
-  xbt_assert(sg_host_by_name(name) == nullptr,
-             "Cannot create a VM named %s: this name is already used by an host or a VM", name);
-
   return new simgrid::s4u::VirtualMachine(name, pm, coreAmount);
 }