From: Frederic Suter Date: Fri, 2 Mar 2018 08:39:33 +0000 (+0100) Subject: move VMs in the S4U realm for good X-Git-Tag: v3.19~159 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/e27cc1baa2d77aba6b3b736876916df5b1b35e68 move VMs in the S4U realm for good the headers in msg.h should be moved to include/simgrid/vm.h soon --- diff --git a/include/simgrid/msg.h b/include/simgrid/msg.h index 4c7e2c216d..df767ec6fa 100644 --- a/include/simgrid/msg.h +++ b/include/simgrid/msg.h @@ -377,35 +377,43 @@ XBT_PUBLIC(int) MSG_barrier_wait(msg_bar_t bar); * */ -XBT_PUBLIC(int) MSG_vm_is_created(msg_vm_t vm); -XBT_PUBLIC(int) MSG_vm_is_running(msg_vm_t vm); -XBT_PUBLIC(int) MSG_vm_is_suspended(msg_vm_t vm); - -XBT_PUBLIC(const char*) MSG_vm_get_name(msg_vm_t vm); -XBT_PUBLIC(void) MSG_vm_set_ramsize(msg_vm_t vm, size_t size); -XBT_PUBLIC(size_t) MSG_vm_get_ramsize(msg_vm_t vm); - -// TODO add VDI later -XBT_PUBLIC(msg_vm_t) MSG_vm_create_core(msg_host_t location, const char *name); -XBT_PUBLIC(msg_vm_t) MSG_vm_create_multicore(msg_host_t pm, const char* name, int coreAmount); - -XBT_ATTRIB_DEPRECATED_v322("Use MSG_vm_create_migratable() from the live migration plugin: " +XBT_PUBLIC(int) sg_vm_is_created(sg_vm_t vm); +#define MSG_vm_is_created(vm) sg_vm_is_created(vm) +XBT_PUBLIC(int) sg_vm_is_running(sg_vm_t vm); +#define MSG_vm_is_running(vm) sg_vm_is_running(vm) +XBT_PUBLIC(int) sg_vm_is_suspended(sg_vm_t vm); +#define MSG_vm_is_suspended(vm) sg_vm_is_suspended(vm) + +XBT_PUBLIC(const char*) sg_vm_get_name(sg_vm_t vm); +#define MSG_vm_get_name(vm) sg_vm_get_name(vm) +XBT_PUBLIC(void) sg_vm_set_ramsize(sg_vm_t vm, size_t size); +#define MSG_vm_set_ramsize(vm, size) sg_vm_set_ramsize(vm, size) +XBT_PUBLIC(size_t) sg_vm_get_ramsize(sg_vm_t vm); +#define MSG_vm_get_ramsize(vm) sg_vm_get_ramsize(vm) + +XBT_PUBLIC(sg_vm_t) sg_vm_create_core(sg_host_t pm, const char* name); +#define MSG_vm_create_core(vm, name) sg_vm_create_core(vm, name) +XBT_PUBLIC(sg_vm_t) sg_vm_create_multicore(sg_host_t pm, const char* name, int coreAmount); +#define MSG_vm_create_multicore(vm, name, coreAmount) sg_vm_create_multicore(vm, name, coreAmount) + +XBT_ATTRIB_DEPRECATED_v322("Use sg_vm_create_migratable() from the live migration plugin: " "v3.22 will drop MSG_vm_create() completely.") XBT_PUBLIC(msg_vm_t) MSG_vm_create(msg_host_t ind_pm, const char* name, int coreAmount, int ramsize, int mig_netspeed, int dp_intensity); -XBT_PUBLIC(void) MSG_vm_destroy(msg_vm_t vm); - -XBT_PUBLIC(void) MSG_vm_start(msg_vm_t vm); - -/* Shutdown the guest operating system. */ -XBT_PUBLIC(void) MSG_vm_shutdown(msg_vm_t vm); - -/* Suspend the execution of the VM, but keep its state on memory. */ -XBT_PUBLIC(void) MSG_vm_suspend(msg_vm_t vm); -XBT_PUBLIC(void) MSG_vm_resume(msg_vm_t vm); - -XBT_PUBLIC(msg_host_t) MSG_vm_get_pm(msg_vm_t vm); -XBT_PUBLIC(void) MSG_vm_set_bound(msg_vm_t vm, double bound); +XBT_PUBLIC(void) sg_vm_start(msg_vm_t vm); +#define MSG_vm_start(vm) sg_vm_start(vm) +XBT_PUBLIC(void) sg_vm_suspend(msg_vm_t vm); +#define MSG_vm_suspend(vm) sg_vm_suspend(vm) +XBT_PUBLIC(void) sg_vm_resume(msg_vm_t vm); +#define MSG_vm_resume(vm) sg_vm_resume(vm) +XBT_PUBLIC(void) sg_vm_shutdown(msg_vm_t vm); +#define MSG_vm_shutdown(vm) sg_vm_shutdown(vm) +XBT_PUBLIC(void) sg_vm_destroy(msg_vm_t vm); +#define MSG_vm_destroy(vm) sg_vm_destroy(vm) +XBT_PUBLIC(sg_host_t) sg_vm_get_pm(sg_vm_t vm); +#define MSG_vm_get_pm(vm) sg_vm_get_pm(vm) +XBT_PUBLIC(void) sg_vm_set_bound(sg_vm_t vm, double bound); +#define MSG_vm_set_bound(vm, bound) sg_vm_set_bound(vm, bound) #include "simgrid/instr.h" diff --git a/src/msg/msg_vm.cpp b/src/msg/msg_vm.cpp deleted file mode 100644 index 67d1e40867..0000000000 --- a/src/msg/msg_vm.cpp +++ /dev/null @@ -1,160 +0,0 @@ -/* Copyright (c) 2012-2017. The SimGrid Team. - * All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ - -/* TODO: - * 1. add the support of trace - * 2. use parallel tasks to simulate CPU overhead and remove the experimental code generating micro computation tasks - */ - -#include - -#include "simgrid/plugins/live_migration.h" -#include "src/instr/instr_private.hpp" -#include "src/plugins/vm/VirtualMachineImpl.hpp" - -#include "simgrid/host.h" -#include "simgrid/simix.hpp" -#include "xbt/string.hpp" - -extern "C" { - -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_vm, msg, "Cloud-oriented parts of the MSG API"); - -const char* MSG_vm_get_name(msg_vm_t vm) -{ - return vm->getCname(); -} - -/** @brief Get the physical host of a given VM. - * @ingroup msg_VMs - */ -msg_host_t MSG_vm_get_pm(msg_vm_t vm) -{ - return vm->getPm(); -} - -void MSG_vm_set_ramsize(msg_vm_t vm, size_t size) -{ - vm->setRamsize(size); -} - -size_t MSG_vm_get_ramsize(msg_vm_t vm) -{ - return vm->getRamsize(); -} - -void MSG_vm_set_bound(msg_vm_t vm, double bound) -{ - vm->setBound(bound); -} - -/** @brief Returns whether the given VM has just created, not running. - * @ingroup msg_VMs - */ -int MSG_vm_is_created(msg_vm_t vm) -{ - return vm->getState() == SURF_VM_STATE_CREATED; -} - -/** @brief Returns whether the given VM is currently running - * @ingroup msg_VMs - */ -int MSG_vm_is_running(msg_vm_t vm) -{ - return vm->getState() == SURF_VM_STATE_RUNNING; -} - -/** @brief Returns whether the given VM is currently suspended, not running. - * @ingroup msg_VMs - */ -int MSG_vm_is_suspended(msg_vm_t vm) -{ - return vm->getState() == SURF_VM_STATE_SUSPENDED; -} - -/* **** ******** MSG vm actions ********* **** */ -/** @brief Create a new VM object with the default parameters - * @ingroup msg_VMs* - * - * 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 pm, const char* name) -{ - return MSG_vm_create_multicore(pm, name, 1); -} -/** @brief Create a new VM object with the default parameters, but with a specified amount of cores - * @ingroup msg_VMs* - * - * A VM is treated as a host. The name of the VM must be unique among all hosts. - */ -msg_vm_t MSG_vm_create_multicore(msg_host_t pm, const char* name, int coreAmount) -{ - 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); - - return new simgrid::s4u::VirtualMachine(name, pm, coreAmount); -} - -/** @brief Start a vm (i.e., boot the guest operating system) - * @ingroup msg_VMs - * - * If the VM cannot be started (because of memory over-provisioning), an exception is generated. - */ -void MSG_vm_start(msg_vm_t vm) -{ - vm->start(); -} - -/** @brief Immediately suspend the execution of all processes within the given VM. - * @ingroup msg_VMs - * - * This function stops the execution of the VM. All the processes on this VM - * will pause. The state of the VM is preserved. We can later resume it again. - * - * No suspension cost occurs. - */ -void MSG_vm_suspend(msg_vm_t vm) -{ - vm->suspend(); -} - -/** @brief Resume the execution of the VM. All processes on the VM run again. - * @ingroup msg_VMs - * - * No resume cost occurs. - */ -void MSG_vm_resume(msg_vm_t vm) -{ - vm->resume(); -} - -/** @brief Immediately kills all processes within the given VM. - * @ingroup msg_VMs - * - * Any memory that they allocated will be leaked, unless you used #MSG_process_on_exit(). - * - * No extra delay occurs. If you want to simulate this too, you want to use a #MSG_process_sleep(). - */ -void MSG_vm_shutdown(msg_vm_t vm) -{ - vm->shutdown(); -} - -/* Deprecated. Please use MSG_vm_create_migratable() instead */ -msg_vm_t MSG_vm_create(msg_host_t ind_pm, const char* name, int coreAmount, int ramsize, int mig_netspeed, - int dp_intensity) -{ - return sg_vm_create_migratable(ind_pm, name, coreAmount, ramsize, mig_netspeed, dp_intensity); -} - -/** @brief Destroy a VM. Destroy the VM object from the simulation. - * @ingroup msg_VMs - */ -void MSG_vm_destroy(msg_vm_t vm) -{ - vm->destroy(); -} -} diff --git a/src/plugins/vm/VmLiveMigration.cpp b/src/plugins/vm/VmLiveMigration.cpp index e04f676c34..e890dd4c6d 100644 --- a/src/plugins/vm/VmLiveMigration.cpp +++ b/src/plugins/vm/VmLiveMigration.cpp @@ -307,6 +307,13 @@ void sg_vm_live_migration_plugin_init() simgrid::s4u::VirtualMachine::onVmShutdown.connect(&onVirtualMachineShutdown); } +/* Deprecated. Please use MSG_vm_create_migratable() instead */ +msg_vm_t MSG_vm_create(msg_host_t ind_pm, const char* name, int coreAmount, int ramsize, int mig_netspeed, + int dp_intensity) +{ + return sg_vm_create_migratable(ind_pm, name, coreAmount, ramsize, mig_netspeed, dp_intensity); +} + simgrid::s4u::VirtualMachine* sg_vm_create_migratable(simgrid::s4u::Host* pm, const char* name, int coreAmount, int ramsize, int mig_netspeed, int dp_intensity) { @@ -366,4 +373,5 @@ void sg_vm_migrate(simgrid::s4u::VirtualMachine* vm, simgrid::s4u::Host* dst_pm) vm->getImpl()->isMigrating = false; } -} + +SG_END_DECL() diff --git a/src/plugins/vm/s4u_VirtualMachine.cpp b/src/plugins/vm/s4u_VirtualMachine.cpp index 5688946438..ef0d95c4c5 100644 --- a/src/plugins/vm/s4u_VirtualMachine.cpp +++ b/src/plugins/vm/s4u_VirtualMachine.cpp @@ -199,3 +199,113 @@ void VirtualMachine::setBound(double bound) } // namespace simgrid } // namespace s4u + +/* **************************** Public C interface *************************** */ + +SG_BEGIN_DECL() +/** @brief Create a new VM object with the default parameters + * A VM is treated as a host. The name of the VM must be unique among all hosts. + */ +msg_vm_t sg_vm_create_core(sg_host_t pm, const char* name) +{ + return sg_vm_create_multicore(pm, name, 1); +} +/** @brief Create a new VM object with the default parameters, but with a specified amount of cores + * A VM is treated as a host. The name of the VM must be unique among all hosts. + */ +msg_vm_t sg_vm_create_multicore(sg_host_t pm, const char* name, int coreAmount) +{ + 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); + + return new simgrid::s4u::VirtualMachine(name, pm, coreAmount); +} + +const char* sg_vm_get_name(sg_vm_t vm) +{ + return vm->getCname(); +} + +/** @brief Get the physical host of a given VM. */ +sg_host_t sg_vm_get_pm(sg_vm_t vm) +{ + return vm->getPm(); +} + +void sg_vm_set_ramsize(sg_vm_t vm, size_t size) +{ + vm->setRamsize(size); +} + +size_t sg_vm_get_ramsize(sg_vm_t vm) +{ + return vm->getRamsize(); +} + +void sg_vm_set_bound(sg_vm_t vm, double bound) +{ + vm->setBound(bound); +} + +/** @brief Returns whether the given VM has just created, not running. */ +int sg_vm_is_created(sg_vm_t vm) +{ + return vm->getState() == SURF_VM_STATE_CREATED; +} + +/** @brief Returns whether the given VM is currently running */ +int sg_vm_is_running(sg_vm_t vm) +{ + return vm->getState() == SURF_VM_STATE_RUNNING; +} + +/** @brief Returns whether the given VM is currently suspended, not running. */ +int sg_vm_is_suspended(sg_vm_t vm) +{ + return vm->getState() == SURF_VM_STATE_SUSPENDED; +} + +/** @brief Start a vm (i.e., boot the guest operating system) + * If the VM cannot be started (because of memory over-provisioning), an exception is generated. + */ +void sg_vm_start(sg_vm_t vm) +{ + vm->start(); +} + +/** @brief Immediately suspend the execution of all processes within the given VM. + * + * This function stops the execution of the VM. All the processes on this VM + * will pause. The state of the VM is preserved. We can later resume it again. + * + * No suspension cost occurs. + */ +void sg_vm_suspend(sg_vm_t vm) +{ + vm->suspend(); +} + +/** @brief Resume the execution of the VM. All processes on the VM run again. + * No resume cost occurs. + */ +void sg_vm_resume(sg_vm_t vm) +{ + vm->resume(); +} + +/** @brief Immediately kills all processes within the given VM. + * Any memory that they allocated will be leaked, unless you used #MSG_process_on_exit(). + * + * No extra delay occurs. If you want to simulate this too, you want to use a #MSG_process_sleep(). + */ +void sg_vm_shutdown(sg_vm_t vm) +{ + vm->shutdown(); +} + +/** @brief Destroy a VM. Destroy the VM object from the simulation. */ +void sg_vm_destroy(sg_vm_t vm) +{ + vm->destroy(); +} +SG_END_DECL() diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index 6bba728e8b..45a4b8c2c0 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -462,7 +462,6 @@ set(MSG_SRC src/msg/msg_process.cpp src/msg/msg_synchro.cpp src/msg/msg_task.cpp - src/msg/msg_vm.cpp ) set(SIMDAG_SRC