Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
try to reduce the amount of warnings in StarPU compilation
[simgrid.git] / src / msg / msg_vm.cpp
1 /* Copyright (c) 2012-2017. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 /* TODO:
8  * 1. add the support of trace
9  * 2. use parallel tasks to simulate CPU overhead and remove the experimental code generating micro computation tasks
10  */
11
12 #include <xbt/ex.hpp>
13
14 #include "simgrid/plugins/live_migration.h"
15 #include "src/instr/instr_private.hpp"
16 #include "src/plugins/vm/VirtualMachineImpl.hpp"
17
18 #include "simgrid/host.h"
19 #include "simgrid/simix.hpp"
20 #include "xbt/string.hpp"
21
22 extern "C" {
23
24 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_vm, msg, "Cloud-oriented parts of the MSG API");
25
26 const char* MSG_vm_get_name(msg_vm_t vm)
27 {
28   return vm->getCname();
29 }
30
31 /** @brief Get the physical host of a given VM.
32  *  @ingroup msg_VMs
33  */
34 msg_host_t MSG_vm_get_pm(msg_vm_t vm)
35 {
36   return vm->getPm();
37 }
38
39 void MSG_vm_set_ramsize(msg_vm_t vm, size_t size)
40 {
41   vm->setRamsize(size);
42 }
43
44 size_t MSG_vm_get_ramsize(msg_vm_t vm)
45 {
46   return vm->getRamsize();
47 }
48
49 void MSG_vm_set_bound(msg_vm_t vm, double bound)
50 {
51   vm->setBound(bound);
52 }
53
54 /** @brief Returns whether the given VM has just created, not running.
55  *  @ingroup msg_VMs
56  */
57 int MSG_vm_is_created(msg_vm_t vm)
58 {
59   return vm->getState() == SURF_VM_STATE_CREATED;
60 }
61
62 /** @brief Returns whether the given VM is currently running
63  *  @ingroup msg_VMs
64  */
65 int MSG_vm_is_running(msg_vm_t vm)
66 {
67   return vm->getState() == SURF_VM_STATE_RUNNING;
68 }
69
70 /** @brief Returns whether the given VM is currently suspended, not running.
71  *  @ingroup msg_VMs
72  */
73 int MSG_vm_is_suspended(msg_vm_t vm)
74 {
75   return vm->getState() == SURF_VM_STATE_SUSPENDED;
76 }
77
78 /* **** ******** MSG vm actions ********* **** */
79 /** @brief Create a new VM object with the default parameters
80  *  @ingroup msg_VMs*
81  *
82  * A VM is treated as a host. The name of the VM must be unique among all hosts.
83  */
84 msg_vm_t MSG_vm_create_core(msg_host_t pm, const char* name)
85 {
86   return MSG_vm_create_multicore(pm, name, 1);
87 }
88 /** @brief Create a new VM object with the default parameters, but with a specified amount of cores
89  *  @ingroup msg_VMs*
90  *
91  * A VM is treated as a host. The name of the VM must be unique among all hosts.
92  */
93 msg_vm_t MSG_vm_create_multicore(msg_host_t pm, const char* name, int coreAmount)
94 {
95   xbt_assert(sg_host_by_name(name) == nullptr,
96              "Cannot create a VM named %s: this name is already used by an host or a VM", name);
97
98   return new simgrid::s4u::VirtualMachine(name, pm, coreAmount);
99 }
100
101 /** @brief Start a vm (i.e., boot the guest operating system)
102  *  @ingroup msg_VMs
103  *
104  *  If the VM cannot be started (because of memory over-provisioning), an exception is generated.
105  */
106 void MSG_vm_start(msg_vm_t vm)
107 {
108   vm->start();
109 }
110
111 /** @brief Immediately suspend the execution of all processes within the given VM.
112  *  @ingroup msg_VMs
113  *
114  * This function stops the execution of the VM. All the processes on this VM
115  * will pause. The state of the VM is preserved. We can later resume it again.
116  *
117  * No suspension cost occurs.
118  */
119 void MSG_vm_suspend(msg_vm_t vm)
120 {
121   vm->suspend();
122 }
123
124 /** @brief Resume the execution of the VM. All processes on the VM run again.
125  *  @ingroup msg_VMs
126  *
127  * No resume cost occurs.
128  */
129 void MSG_vm_resume(msg_vm_t vm)
130 {
131   vm->resume();
132 }
133
134 /** @brief Immediately kills all processes within the given VM.
135  *  @ingroup msg_VMs
136  *
137  * Any memory that they allocated will be leaked, unless you used #MSG_process_on_exit().
138  *
139  * No extra delay occurs. If you want to simulate this too, you want to use a #MSG_process_sleep().
140  */
141 void MSG_vm_shutdown(msg_vm_t vm)
142 {
143   vm->shutdown();
144 }
145
146 /* Deprecated. Please use MSG_vm_create_migratable() instead */
147 msg_vm_t MSG_vm_create(msg_host_t ind_pm, const char* name, int coreAmount, int ramsize, int mig_netspeed,
148                        int dp_intensity)
149 {
150   return sg_vm_create_migratable(ind_pm, name, coreAmount, ramsize, mig_netspeed, dp_intensity);
151 }
152
153 /** @brief Destroy a VM. Destroy the VM object from the simulation.
154  *  @ingroup msg_VMs
155  */
156 void MSG_vm_destroy(msg_vm_t vm)
157 {
158   vm->destroy();
159 }
160 }