Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
f46ee37c9a0615c631f2ad0476938eb7cda7d3e1
[simgrid.git] / src / plugins / vm / s4u_VirtualMachine.cpp
1 /* Copyright (c) 2015-2016. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "simgrid/datatypes.h"
7 #include "simgrid/s4u/VirtualMachine.hpp"
8 #include "simgrid/s4u/host.hpp"
9 #include "simgrid/simix.hpp"
10 #include "src/plugins/vm/VirtualMachineImpl.hpp"
11 #include "src/simix/smx_host_private.h"
12 #include "src/surf/HostImpl.hpp"
13 #include "xbt/asserts.h"
14 #include "src/instr/instr_private.h"
15
16 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_vm, "S4U virtual machines");
17
18 namespace simgrid {
19 namespace s4u {
20
21 VirtualMachine::VirtualMachine(const char* name, s4u::Host* pm) : Host(name)
22 {
23   XBT_DEBUG("Create VM %s", name);
24
25   pimpl_vm_ = new surf::VirtualMachineImpl(this, pm);
26   extension_set<simgrid::simix::Host>(new simgrid::simix::Host());
27
28   if (TRACE_msg_vm_is_enabled()) {
29     container_t host_container = PJ_container_get(sg_host_get_name(pm));
30     PJ_container_new(name, INSTR_MSG_VM, host_container);
31   }
32 }
33
34 VirtualMachine::~VirtualMachine()
35 {
36   onDestruction(*this);
37
38   XBT_DEBUG("destroy %s", name().c_str());
39
40   /* FIXME: this is really strange that everything fails if the next line is removed.
41    * This is as if we shared these data with the PM, which definitely should not be the case...
42    *
43    * We need to test that suspending a VM does not suspends the processes running on its PM, for example.
44    * Or we need to simplify this code enough to make it actually readable (but this sounds harder than testing)
45    */
46   extension_set<simgrid::simix::Host>(nullptr);
47
48   /* Don't free these things twice: they are the ones of my physical host */
49   pimpl_cpu     = nullptr;
50   pimpl_netcard = nullptr;
51 }
52
53 bool VirtualMachine::isMigrating()
54 {
55   return static_cast<surf::VirtualMachineImpl*>(pimpl_)->isMigrating;
56 }
57
58 /** @brief Retrieve a copy of the parameters of that VM/PM
59  *  @details The ramsize and overcommit fields are used on the PM too */
60 void VirtualMachine::parameters(vm_params_t params)
61 {
62   static_cast<surf::VirtualMachineImpl*>(pimpl_)->getParams(params);
63 }
64 /** @brief Sets the params of that VM/PM */
65 void VirtualMachine::setParameters(vm_params_t params)
66 {
67   simgrid::simix::kernelImmediate([&]() { static_cast<surf::VirtualMachineImpl*>(pimpl_)->setParams(params); });
68 }
69
70 } // namespace simgrid
71 } // namespace s4u