Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cut some useless includes
[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 "src/instr/instr_private.h"
7 #include "src/plugins/vm/VirtualMachineImpl.hpp"
8 #include "src/simix/smx_host_private.h"
9 #include "src/surf/cpu_cas01.hpp"
10
11 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_vm, "S4U virtual machines");
12
13 namespace simgrid {
14 namespace s4u {
15
16 VirtualMachine::VirtualMachine(const char* name, s4u::Host* pm) : Host(name)
17 {
18   XBT_DEBUG("Create VM %s", name);
19
20   pimpl_vm_ = new vm::VirtualMachineImpl(this, pm);
21   /* Currently, a VM uses the network resource of its physical host */
22   pimpl_netcard = pm->pimpl_netcard;
23   // Create a VCPU for this VM
24   surf::CpuCas01* sub_cpu = dynamic_cast<surf::CpuCas01*>(pm->pimpl_cpu);
25
26   pimpl_cpu = surf_cpu_model_vm->createCpu(this, sub_cpu->getSpeedPeakList(), 1 /*cores*/);
27   if (sub_cpu->getPState() != 0)
28     pimpl_cpu->setPState(sub_cpu->getPState());
29
30   /* Make a process container */
31   extension_set<simgrid::simix::Host>(new simgrid::simix::Host());
32
33   if (TRACE_msg_vm_is_enabled()) {
34     container_t host_container = PJ_container_get(pm->cname());
35     PJ_container_new(name, INSTR_MSG_VM, host_container);
36   }
37 }
38
39 VirtualMachine::~VirtualMachine()
40 {
41   onDestruction(*this);
42
43   XBT_DEBUG("destroy %s", cname());
44
45   /* FIXME: this is really strange that everything fails if the next line is removed.
46    * This is as if we shared these data with the PM, which definitely should not be the case...
47    *
48    * We need to test that suspending a VM does not suspends the processes running on its PM, for example.
49    * Or we need to simplify this code enough to make it actually readable (but this sounds harder than testing)
50    */
51   extension_set<simgrid::simix::Host>(nullptr);
52
53   /* Don't free these things twice: they are the ones of my physical host */
54   pimpl_netcard = nullptr;
55 }
56
57 bool VirtualMachine::isMigrating()
58 {
59   return pimpl_vm_->isMigrating;
60 }
61 double VirtualMachine::getRamsize()
62 {
63   return pimpl_vm_->params_.ramsize;
64 }
65 simgrid::s4u::Host* VirtualMachine::pm()
66 {
67   return pimpl_vm_->getPm();
68 }
69
70 /** @brief Retrieve a copy of the parameters of that VM/PM
71  *  @details The ramsize and overcommit fields are used on the PM too */
72 void VirtualMachine::parameters(vm_params_t params)
73 {
74   pimpl_vm_->getParams(params);
75 }
76 /** @brief Sets the params of that VM/PM */
77 void VirtualMachine::setParameters(vm_params_t params)
78 {
79   simgrid::simix::kernelImmediate([&]() { pimpl_vm_->setParams(params); });
80 }
81
82 } // namespace simgrid
83 } // namespace s4u