1 /* Copyright (c) 2012-2017. The SimGrid Team.
2 * All rights reserved. */
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. */
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
14 #include "simgrid/plugins/live_migration.h"
15 #include "src/instr/instr_private.hpp"
16 #include "src/plugins/vm/VirtualMachineImpl.hpp"
18 #include "simgrid/host.h"
19 #include "simgrid/simix.hpp"
20 #include "xbt/string.hpp"
24 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_vm, msg, "Cloud-oriented parts of the MSG API");
26 const char* MSG_vm_get_name(msg_vm_t vm)
28 return vm->getCname();
31 /** @brief Get the physical host of a given VM.
34 msg_host_t MSG_vm_get_pm(msg_vm_t vm)
39 void MSG_vm_set_ramsize(msg_vm_t vm, size_t size)
44 size_t MSG_vm_get_ramsize(msg_vm_t vm)
46 return vm->getRamsize();
49 void MSG_vm_set_bound(msg_vm_t vm, double bound)
54 /** @brief Returns whether the given VM has just created, not running.
57 int MSG_vm_is_created(msg_vm_t vm)
59 return vm->getState() == SURF_VM_STATE_CREATED;
62 /** @brief Returns whether the given VM is currently running
65 int MSG_vm_is_running(msg_vm_t vm)
67 return vm->getState() == SURF_VM_STATE_RUNNING;
70 /** @brief Returns whether the given VM is currently suspended, not running.
73 int MSG_vm_is_suspended(msg_vm_t vm)
75 return vm->getState() == SURF_VM_STATE_SUSPENDED;
78 /* **** ******** MSG vm actions ********* **** */
79 /** @brief Create a new VM object with the default parameters
82 * A VM is treated as a host. The name of the VM must be unique among all hosts.
84 msg_vm_t MSG_vm_create_core(msg_host_t pm, const char* name)
86 return MSG_vm_create_multicore(pm, name, 1);
88 /** @brief Create a new VM object with the default parameters, but with a specified amount of cores
91 * A VM is treated as a host. The name of the VM must be unique among all hosts.
93 msg_vm_t MSG_vm_create_multicore(msg_host_t pm, const char* name, int coreAmount)
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);
98 return new simgrid::s4u::VirtualMachine(name, pm, coreAmount);
101 /** @brief Start a vm (i.e., boot the guest operating system)
104 * If the VM cannot be started (because of memory over-provisioning), an exception is generated.
106 void MSG_vm_start(msg_vm_t vm)
111 /** @brief Immediately suspend the execution of all processes within the given VM.
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.
117 * No suspension cost occurs.
119 void MSG_vm_suspend(msg_vm_t vm)
124 /** @brief Resume the execution of the VM. All processes on the VM run again.
127 * No resume cost occurs.
129 void MSG_vm_resume(msg_vm_t vm)
134 /** @brief Immediately kills all processes within the given VM.
137 * Any memory that they allocated will be leaked, unless you used #MSG_process_on_exit().
139 * No extra delay occurs. If you want to simulate this too, you want to use a #MSG_process_sleep().
141 void MSG_vm_shutdown(msg_vm_t vm)
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,
150 return sg_vm_create_migratable(ind_pm, name, coreAmount, ramsize, mig_netspeed, dp_intensity);
153 /** @brief Destroy a VM. Destroy the VM object from the simulation.
156 void MSG_vm_destroy(msg_vm_t vm)