Logo AND Algorithmique Numérique Distribuée

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