#include <xbt/ex.hpp>
#include "src/plugins/vm/VirtualMachineImpl.hpp"
+#include "src/plugins/vm/VmHostExt.hpp"
#include <simgrid/s4u/VirtualMachine.hpp>
#include <simgrid/s4u/host.hpp>
#include "xbt/log.h"
#include "simgrid/host.h"
+#include "src/simix/smx_host_private.h" /* don't ask me why the VM functions are in there (FIXME:KILLME) */
+
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_vm, msg, "Cloud-oriented parts of the MSG API");
static_cast<simgrid::s4u::VirtualMachine*>(vm)->parameters(params);
}
-/** \ingroup msg_vm_management
- * \brief Finds a msg_vm_t using its name.
- *
- * This is a name directory service
- * \param name the name of a vm.
- * \return the corresponding vm
- *
- * Please note that a VM is a specific host. Hence, you should give a different name for each VM/PM.
- */
-msg_vm_t MSG_vm_get_by_name(const char *name)
-{
- return MSG_host_by_name(name);
-}
-
-/** \ingroup m_vm_management
- *
- * \brief Return the name of the #msg_host_t.
- *
- * This functions checks whether \a host is a valid pointer or not and return its name.
- */
-const char *MSG_vm_get_name(msg_vm_t vm)
-{
- return MSG_host_get_name(vm);
-}
-
/* **** Check state of a VM **** */
static inline int __MSG_vm_is_state(msg_vm_t vm, e_surf_vm_state_t state)
{
- return simcall_vm_get_state(vm) == state;
+ return static_cast<simgrid::s4u::VirtualMachine*>(vm)->pimpl_vm_->getState() == state;
}
/** @brief Returns whether the given VM has just created, not running.
msg_vm_t MSG_vm_create(msg_host_t pm, const char *name, int ncpus, int ramsize, int net_cap, char *disk_path,
int disksize, int mig_netspeed, int dp_intensity)
{
- /* For the moment, intensity_rate is the percentage against the migration
- * bandwidth */
+ simgrid::vm::VmHostExt::ensureVmExtInstalled();
+
+ /* For the moment, intensity_rate is the percentage against the migration bandwidth */
double host_speed = MSG_host_get_speed(pm);
double update_speed = ((double)dp_intensity/100) * mig_netspeed;
*
* A VM is treated as a host. The name of the VM must be unique among all hosts.
*/
-msg_vm_t MSG_vm_create_core(msg_host_t ind_pm, const char *name)
+msg_vm_t MSG_vm_create_core(msg_host_t pm, const char* name)
{
- /* make sure the VM of the same name does not exit */
- {
- simgrid::s4u::Host* ind_host_tmp = sg_host_by_name(name);
- if (ind_host_tmp != nullptr && sg_host_simix(ind_host_tmp) != nullptr) {
- XBT_ERROR("host %s already exits", name);
- return nullptr;
- }
- }
-
- /* Note: ind_vm and vm_workstation point to the same elm object. */
- /* Ask the SIMIX layer to create the surf vm resource */
- sg_host_t ind_vm_workstation = simcall_vm_create(name, ind_pm);
-
- msg_vm_t ind_vm = (msg_vm_t) __MSG_host_create(ind_vm_workstation);
+ xbt_assert(sg_host_by_name(name) == nullptr,
+ "Cannot create a VM named %s: this name is already used by an host or a VM", name);
- XBT_DEBUG("A new VM (%s) has been created", name);
-
- TRACE_msg_vm_create(name, ind_pm);
-
- return ind_vm;
+ return new simgrid::s4u::VirtualMachine(name, pm);
}
/** @brief Destroy a VM. Destroy the VM object from the simulation.
void MSG_vm_destroy(msg_vm_t vm)
{
if (MSG_vm_is_migrating(vm))
- THROWF(vm_error, 0, "VM(%s) is migrating", sg_host_get_name(vm));
+ THROWF(vm_error, 0, "VM(%s) is migrating", vm->name().c_str());
/* First, terminate all processes on the VM if necessary */
if (MSG_vm_is_running(vm))
- simcall_vm_shutdown(vm);
+ MSG_vm_shutdown(vm);
- if (!MSG_vm_is_created(vm)) {
- XBT_CRITICAL("shutdown the given VM before destroying it");
- DIE_IMPOSSIBLE;
- }
+ xbt_assert(MSG_vm_is_created(vm), "shutdown the given VM before destroying it");
/* Then, destroy the VM object */
- simcall_vm_destroy(vm);
-
- TRACE_msg_vm_end(vm);
+ simgrid::simix::kernelImmediate([vm]() {
+ vm->destroy();
+ });
+
+ if (TRACE_msg_vm_is_enabled()) {
+ container_t container = PJ_container_get(vm->name().c_str());
+ PJ_container_remove_from_parent(container);
+ PJ_container_free(container);
+ }
}
/** @brief Start a vm (i.e., boot the guest operating system)
{
simcall_vm_start(vm);
- TRACE_msg_vm_start(vm);
+ if (TRACE_msg_vm_is_enabled()) {
+ container_t vm_container = PJ_container_get(vm->name().c_str());
+ type_t type = PJ_type_get("MSG_VM_STATE", vm_container->type);
+ val_t value = PJ_value_get_or_new("start", "0 0 1", type); // start is blue
+ new_pajePushState(MSG_get_clock(), vm_container, type, value);
+ }
}
/** @brief Immediately kills all processes within the given VM. Any memory that they allocated will be leaked.
*/
void MSG_vm_shutdown(msg_vm_t vm)
{
- /* msg_vm_t equals to msg_host_t */
simcall_vm_shutdown(vm);
-
- // TRACE_msg_vm_(vm);
+ MSG_process_sleep(0.); // Make sure that the processes in the VM are killed in this scheduling round before processing
+ // (eg with the VM destroy)
}
/* We have two mailboxes. mbox is used to transfer migration data between source and destination PMs. mbox_ctl is used
msg_host_t src_pm = ms->src_pm;
msg_host_t dst_pm = ms->dst_pm;
- // TODO: we have an issue, if the DST node is turning off during the three next calls, then the VM is in an
- // inconsistent
- // state. I should check with Takahiro in order to make this portion of code atomic
- //
- // /* Update the vm location */
- // simcall_vm_migrate(vm, dst_pm);
- //
- // /* Resume the VM */
- // simcall_vm_resume(vm);
- //
- simcall_vm_migratefrom_resumeto(vm, src_pm, dst_pm);
+ // Make sure that we cannot get interrupted between the migrate and the resume to not end in an inconsistent state
+ simgrid::simix::kernelImmediate([vm, src_pm, dst_pm]() {
+ /* Update the vm location */
+ /* precopy migration makes the VM temporally paused */
+ xbt_assert(static_cast<simgrid::s4u::VirtualMachine*>(vm)->pimpl_vm_->getState() == SURF_VM_STATE_SUSPENDED);
+
+ /* jump to vm_ws_xigrate(). this will update the vm location. */
+ static_cast<simgrid::s4u::VirtualMachine*>(vm)->pimpl_vm_->migrate(dst_pm);
+
+ /* Resume the VM */
+ SIMIX_vm_resume(vm);
+ });
{
// Now the VM is running on the new host (the migration is completed) (even if the SRC crash)
- static_cast<simgrid::surf::VirtualMachineImpl*>(vm->pimpl_)->isMigrating = false;
+ vm->pimpl_vm_->isMigrating = false;
XBT_DEBUG("VM(%s) moved from PM(%s) to PM(%s)", sg_host_get_name(ms->vm), sg_host_get_name(ms->src_pm),
sg_host_get_name(ms->dst_pm));
- TRACE_msg_vm_change_host(ms->vm, ms->src_pm, ms->dst_pm);
+
+ if (TRACE_msg_vm_is_enabled()) {
+ static long long int counter = 0;
+ char key[INSTR_DEFAULT_STR_SIZE];
+ snprintf(key, INSTR_DEFAULT_STR_SIZE, "%lld", counter++);
+
+ // start link
+ container_t msg = PJ_container_get(vm->name().c_str());
+ type_t type = PJ_type_get("MSG_VM_LINK", PJ_type_get_root());
+ new_pajeStartLink(MSG_get_clock(), PJ_container_get_root(), type, msg, "M", key);
+
+ // destroy existing container of this vm
+ container_t existing_container = PJ_container_get(vm->name().c_str());
+ PJ_container_remove_from_parent(existing_container);
+ PJ_container_free(existing_container);
+
+ // create new container on the new_host location
+ PJ_container_new(vm->name().c_str(), INSTR_MSG_VM, PJ_container_get(sg_host_get_name(ms->dst_pm)));
+
+ // end link
+ msg = PJ_container_get(vm->name().c_str());
+ type = PJ_type_get("MSG_VM_LINK", PJ_type_get_root());
+ new_pajeEndLink(MSG_get_clock(), PJ_container_get_root(), type, msg, "M", key);
+ }
}
// Inform the SRC that the migration has been correctly performed
{
static void start_dirty_page_tracking(msg_vm_t vm)
{
- simgrid::surf::VirtualMachineImpl* pimpl = static_cast<simgrid::surf::VirtualMachineImpl*>(vm->pimpl_);
- pimpl->dp_enabled = 1;
+ static_cast<simgrid::s4u::VirtualMachine*>(vm)->pimpl_vm_->dp_enabled = 1;
reset_dirty_pages(vm);
}
static void stop_dirty_page_tracking(msg_vm_t vm)
{
- simgrid::surf::VirtualMachineImpl* pimpl = static_cast<simgrid::surf::VirtualMachineImpl*>(vm->pimpl_);
- pimpl->dp_enabled = 0;
+ static_cast<simgrid::s4u::VirtualMachine*>(vm)->pimpl_vm_->dp_enabled = 0;
}
static double get_computed(char *key, msg_vm_t vm, dirty_page_t dp, double remaining, double clock)
static double lookup_computed_flop_counts(msg_vm_t vm, int stage_for_fancy_debug, int stage2_round_for_fancy_debug)
{
- simgrid::surf::VirtualMachineImpl* pimpl = static_cast<simgrid::surf::VirtualMachineImpl*>(vm->pimpl_);
+ simgrid::surf::VirtualMachineImpl* pimpl = static_cast<simgrid::s4u::VirtualMachine*>(vm)->pimpl_vm_;
double total = 0;
char *key = nullptr;
XBT_DEBUG("vm_suspend done");
- TRACE_msg_vm_suspend(vm);
+ if (TRACE_msg_vm_is_enabled()) {
+ container_t vm_container = PJ_container_get(vm->name().c_str());
+ type_t type = PJ_type_get("MSG_VM_STATE", vm_container->type);
+ val_t value = PJ_value_get_or_new("suspend", "1 0 0", type); // suspend is red
+ new_pajePushState(MSG_get_clock(), vm_container, type, value);
+ }
}
/** @brief Resume the execution of the VM. All processes on the VM run again.
{
simcall_vm_resume(vm);
- TRACE_msg_vm_resume(vm);
+ if (TRACE_msg_vm_is_enabled()) {
+ container_t vm_container = PJ_container_get(vm->name().c_str());
+ type_t type = PJ_type_get("MSG_VM_STATE", vm_container->type);
+ new_pajePopState(MSG_get_clock(), vm_container, type);
+ }
}
THROWF(vm_error, 0, "VM(%s) is migrating", sg_host_get_name(vm));
simcall_vm_save(vm);
- TRACE_msg_vm_save(vm);
+
+ if (TRACE_msg_vm_is_enabled()) {
+ container_t vm_container = PJ_container_get(vm->name().c_str());
+ type_t type = PJ_type_get("MSG_VM_STATE", vm_container->type);
+ val_t value = PJ_value_get_or_new("save", "0 1 0", type); // save is green
+ new_pajePushState(MSG_get_clock(), vm_container, type, value);
+ }
}
/** @brief Restore the execution of the VM. All processes on the VM run again.
{
simcall_vm_restore(vm);
- TRACE_msg_vm_restore(vm);
+ if (TRACE_msg_vm_is_enabled()) {
+ container_t vm_container = PJ_container_get(vm->name().c_str());
+ type_t type = PJ_type_get("MSG_VM_STATE", vm_container->type);
+ new_pajePopState(MSG_get_clock(), vm_container, type);
+ }
}
/** @brief Get the physical host of a given VM.