From: Frederic Suter Date: Thu, 11 Jan 2018 12:40:24 +0000 (+0100) Subject: Messing up with VM X-Git-Tag: v3.19~367 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/55ff61a313ebbe8195ca80dcb61697b47f59d98f Messing up with VM - move VM tracing to S4U - move last functions related to migration to the plugin - MSG_vm_create is now MSG_vm_create_migratable and tagged as DEPRECATED (will be removed in 3.21) - Assume that the live migration plugin is always loaded in JAVA (because all VMs are create with MSG_vm_create there) - add a proper destroy function to S4U VMs (shutdown first, then destroy) - pimpl_vm_ is now private (with getImpl() as accessor) - and use the user level interface as much as possible Conclusion: The MSG_vm interface is now just a dummy wrapper on the S4U interface and live migration is fully isolated in a plugin. Only the is_migrating bool remains in VirtualMachineImpl, but is not (and should not be) accessed or modified from outside the plugin. We can live with that. --- diff --git a/examples/java/cloud/masterworker/Main.java b/examples/java/cloud/masterworker/Main.java index 8406958c28..5623ffa5e2 100644 --- a/examples/java/cloud/masterworker/Main.java +++ b/examples/java/cloud/masterworker/Main.java @@ -22,7 +22,6 @@ class Main { public static void main(String[] args) { Msg.init(args); - Msg.liveMigrationInit(); String platfFile = "../../examples/platforms/small_platform.xml"; if (args.length >= 1) diff --git a/examples/java/cloud/migration/Main.java b/examples/java/cloud/migration/Main.java index 191b2a170b..72675087af 100644 --- a/examples/java/cloud/migration/Main.java +++ b/examples/java/cloud/migration/Main.java @@ -26,7 +26,6 @@ public class Main { public static void main(String[] args) throws MsgException { Msg.init(args); - Msg.liveMigrationInit(); if (args.length < 1) { Msg.info("Usage : Main platform_file.xml"); System.exit(1); diff --git a/examples/s4u/cloud-migration/s4u-cloud-migration.tesh b/examples/s4u/cloud-migration/s4u-cloud-migration.tesh index acc2db7248..f18aa46a11 100644 --- a/examples/s4u/cloud-migration/s4u-cloud-migration.tesh +++ b/examples/s4u/cloud-migration/s4u-cloud-migration.tesh @@ -4,9 +4,9 @@ $ $SG_TEST_EXENV ${bindir:=.}/s4u-cloud-migration ${platfdir}/small_platform.xml > [132.765801] (1:master_@Fafard) Test: Migrate a VM with 100 Mbytes RAM > [146.111793] (1:master_@Fafard) VM0 migrated: Fafard->Tremblay in 13.346 s > [146.111793] (1:master_@Fafard) Test: Migrate two VMs at once from PM0 to PM1 -> [411.566271] (8:mig_wrk@Fafard) VM1 migrated: Fafard->Tremblay in 265.454 s +> [411.566271] (7:mig_wrk@Fafard) VM1 migrated: Fafard->Tremblay in 265.454 s > [411.566271] (6:mig_wrk@Fafard) VM0 migrated: Fafard->Tremblay in 265.454 s > [10146.111793] (1:master_@Fafard) Test: Migrate two VMs at once to different PMs -> [10362.620589] (14:mig_wrk@Fafard) VM1 migrated: Fafard->Bourassa in 216.509 s +> [10362.620589] (13:mig_wrk@Fafard) VM1 migrated: Fafard->Bourassa in 216.509 s > [10411.547334] (12:mig_wrk@Fafard) VM0 migrated: Fafard->Tremblay in 265.436 s > [20146.111793] (0:maestro@) Bye (simulation time 20146.1) diff --git a/include/simgrid/msg.h b/include/simgrid/msg.h index 7da4c7f431..da53555456 100644 --- a/include/simgrid/msg.h +++ b/include/simgrid/msg.h @@ -8,6 +8,7 @@ #include "simgrid/forward.h" #include "simgrid/host.h" +#include "simgrid/plugins/live_migration.h" #include "xbt/base.h" #include "xbt/dict.h" @@ -406,7 +407,6 @@ 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_migrating(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); @@ -416,8 +416,13 @@ 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_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_ATTRIB_DEPRECATED_v321("Use MSG_vm_create_migratable() from the live migration plugin: " + "v3.21 will drop MSG_vm_create() completely.") static 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); +} XBT_PUBLIC(void) MSG_vm_destroy(msg_vm_t vm); diff --git a/include/simgrid/plugins/live_migration.h b/include/simgrid/plugins/live_migration.h index 24425cc81f..99665ba2ef 100644 --- a/include/simgrid/plugins/live_migration.h +++ b/include/simgrid/plugins/live_migration.h @@ -25,8 +25,17 @@ XBT_PUBLIC(sg_size_t) sg_vm_get_working_set_memory(sg_vm_t vm); XBT_PUBLIC(void) sg_vm_set_migration_speed(sg_vm_t vm, double speed); XBT_PUBLIC(double) sg_vm_get_migration_speed(sg_vm_t vm); XBT_PUBLIC(double) sg_vm_get_max_downtime(sg_vm_t vm); +XBT_PUBLIC(int) sg_vm_is_migrating(sg_vm_t vm); +XBT_PUBLIC(sg_vm_t) +sg_vm_create_migratable(sg_host_t pm, const char* name, int coreAmount, int ramsize, int mig_netspeed, + int dp_intensity); #define MSG_vm_live_migration_plugin_init() sg_vm_live_migration_plugin_init() + +#define MSG_vm_create_migratable(pm, name, coreAmount, ramsize, mig_netspeed, dp_intensity) \ + sg_vm_create_migratable(pm, name, coreAmount, ramsize, mig_netspeed, dp_intensity) + +#define MSG_vm_is_migrating(vm) sg_vm_is_migrating(vm) #define MSG_vm_migrate(vm, dst_pm) sg_vm_migrate(vm, dst_pm) SG_END_DECL() diff --git a/include/simgrid/s4u/VirtualMachine.hpp b/include/simgrid/s4u/VirtualMachine.hpp index de4ebd8027..c4cca14c27 100644 --- a/include/simgrid/s4u/VirtualMachine.hpp +++ b/include/simgrid/s4u/VirtualMachine.hpp @@ -20,6 +20,7 @@ namespace simgrid { namespace vm { class VirtualMachineImpl; }; + namespace s4u { /** @ingroup s4u_api @@ -32,6 +33,8 @@ namespace s4u { */ XBT_PUBLIC_CLASS VirtualMachine : public s4u::Host { + simgrid::vm::VirtualMachineImpl* pimpl_vm_ = nullptr; + virtual ~VirtualMachine(); public: explicit VirtualMachine(const char* name, s4u::Host* hostPm, int coreAmount); @@ -41,13 +44,12 @@ public: VirtualMachine(VirtualMachine const&) = delete; VirtualMachine& operator=(VirtualMachine const&) = delete; -private: - virtual ~VirtualMachine(); -public: + simgrid::vm::VirtualMachineImpl* getImpl() { return pimpl_vm_; } void start(); void suspend(); void resume(); void shutdown(); + void destroy(); bool isMigrating(); @@ -58,11 +60,8 @@ public: void setBound(double bound); e_surf_vm_state_t getState(); - - /* FIXME: protect me */ - simgrid::vm::VirtualMachineImpl* pimpl_vm_ = nullptr; }; } } // namespace simgrid::s4u -#endif /* SIMGRID_S4U_HOST_HPP */ +#endif diff --git a/src/bindings/java/jmsg.cpp b/src/bindings/java/jmsg.cpp index acdd302571..78b7dfe590 100644 --- a/src/bindings/java/jmsg.cpp +++ b/src/bindings/java/jmsg.cpp @@ -118,6 +118,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, j argv[argc] = nullptr; MSG_init(&argc, argv); + sg_vm_live_migration_plugin_init(); JAVA_HOST_LEVEL = simgrid::s4u::Host::extension_create(nullptr); @@ -239,11 +240,6 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_energyInit() { sg_host_energy_plugin_init(); } -JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_liveMigrationInit() -{ - sg_vm_live_migration_plugin_init(); -} - JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_fileSystemInit() { sg_storage_file_system_init(); diff --git a/src/bindings/java/jmsg_vm.cpp b/src/bindings/java/jmsg_vm.cpp index f108bf2c16..25256f7b49 100644 --- a/src/bindings/java/jmsg_vm.cpp +++ b/src/bindings/java/jmsg_vm.cpp @@ -73,8 +73,8 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_VM_create(JNIEnv* env, jobject jVm, msg_host_t host = jhost_get_native(env, jHost); const char* name = env->GetStringUTFChars(jname, 0); - msg_vm_t vm = MSG_vm_create(host, name, static_cast(coreAmount), static_cast(jramsize), - static_cast(jmig_netspeed), static_cast(jdp_intensity)); + msg_vm_t vm = MSG_vm_create_migratable(host, name, static_cast(coreAmount), static_cast(jramsize), + static_cast(jmig_netspeed), static_cast(jdp_intensity)); env->ReleaseStringUTFChars(jname, name); jvm_bind(env, jVm, vm); diff --git a/src/bindings/java/org/simgrid/msg/Msg.java b/src/bindings/java/org/simgrid/msg/Msg.java index 86a14b4846..cc1cb7d0ba 100644 --- a/src/bindings/java/org/simgrid/msg/Msg.java +++ b/src/bindings/java/org/simgrid/msg/Msg.java @@ -41,7 +41,6 @@ public final class Msg { /** Tell the kernel that you want to use the energy plugin */ public static final native void energyInit(); public static final native void fileSystemInit(); - public static final native void liveMigrationInit(); /** Run the MSG simulation. * diff --git a/src/msg/msg_vm.cpp b/src/msg/msg_vm.cpp index ce2030b122..a49828172f 100644 --- a/src/msg/msg_vm.cpp +++ b/src/msg/msg_vm.cpp @@ -14,7 +14,6 @@ #include "simgrid/plugins/live_migration.h" #include "src/instr/instr_private.hpp" #include "src/plugins/vm/VirtualMachineImpl.hpp" -#include "src/plugins/vm/VmHostExt.hpp" #include "simgrid/host.h" #include "simgrid/simix.hpp" @@ -41,27 +40,23 @@ 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(); } -/* **** Check state of a VM **** */ void MSG_vm_set_bound(msg_vm_t vm, double bound) { vm->setBound(bound); } -static inline int __MSG_vm_is_state(msg_vm_t vm, e_surf_vm_state_t state) -{ - return vm->pimpl_vm_ != nullptr && vm->getState() == state; -} /** @brief Returns whether the given VM has just created, not running. * @ingroup msg_VMs */ int MSG_vm_is_created(msg_vm_t vm) { - return __MSG_vm_is_state(vm, SURF_VM_STATE_CREATED); + return vm->getState() == SURF_VM_STATE_CREATED; } /** @brief Returns whether the given VM is currently running @@ -69,15 +64,7 @@ int MSG_vm_is_created(msg_vm_t vm) */ int MSG_vm_is_running(msg_vm_t vm) { - return __MSG_vm_is_state(vm, SURF_VM_STATE_RUNNING); -} - -/** @brief Returns whether the given VM is currently migrating - * @ingroup msg_VMs - */ -int MSG_vm_is_migrating(msg_vm_t vm) -{ - return vm->isMigrating(); + return vm->getState() == SURF_VM_STATE_RUNNING; } /** @brief Returns whether the given VM is currently suspended, not running. @@ -85,40 +72,10 @@ int MSG_vm_is_migrating(msg_vm_t vm) */ int MSG_vm_is_suspended(msg_vm_t vm) { - return __MSG_vm_is_state(vm, SURF_VM_STATE_SUSPENDED); + return vm->getState() == SURF_VM_STATE_SUSPENDED; } /* **** ******** MSG vm actions ********* **** */ -/** @brief Create a new VM with specified parameters. - * @ingroup msg_VMs* - * @param pm Physical machine that will host the VM - * @param name Must be unique - * @param coreAmount Must be >= 1 - * @param ramsize [TODO] - * @param mig_netspeed Amount of Mbyte/s allocated to the migration (cannot be larger than net_cap). Use 0 if unsure. - * @param dp_intensity Dirty page percentage according to migNetSpeed, [0-100]. Use 0 if unsure. - */ -msg_vm_t MSG_vm_create(msg_host_t pm, const char* name, int coreAmount, int ramsize, int mig_netspeed, int dp_intensity) -{ - simgrid::vm::VmHostExt::ensureVmExtInstalled(); - - /* For the moment, intensity_rate is the percentage against the migration bandwidth */ - - msg_vm_t vm = new simgrid::s4u::VirtualMachine(name, pm, coreAmount, static_cast(ramsize) * 1024 * 1024); - if (not sg_vm_is_migratable(vm)) { - if (mig_netspeed != 0 || dp_intensity != 0) - XBT_WARN("The live migration is not enabled. dp_intensity and mig_netspeed can't be used"); - } else { - sg_vm_set_dirty_page_intensity(vm, dp_intensity / 100.0); - sg_vm_set_working_set_memory(vm, vm->getRamsize() * 0.9); // assume working set memory is 90% of ramsize - sg_vm_set_migration_speed(vm, mig_netspeed * 1024 * 1024.0); - - XBT_DEBUG("migspeed : %f intensity mem : %d", mig_netspeed * 1024 * 1024.0, dp_intensity); - } - - return vm; -} - /** @brief Create a new VM object with the default parameters * @ingroup msg_VMs* * @@ -126,11 +83,7 @@ msg_vm_t MSG_vm_create(msg_host_t pm, const char* name, int coreAmount, int rams */ msg_vm_t MSG_vm_create_core(msg_host_t pm, const char* name) { - 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); - - msg_vm_t vm = new simgrid::s4u::VirtualMachine(name, pm, 1); - return vm; + 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* @@ -142,8 +95,7 @@ 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); - msg_vm_t vm = new simgrid::s4u::VirtualMachine(name, pm, coreAmount); - return vm; + return new simgrid::s4u::VirtualMachine(name, pm, coreAmount); } /** @brief Start a vm (i.e., boot the guest operating system) @@ -154,11 +106,6 @@ msg_vm_t MSG_vm_create_multicore(msg_host_t pm, const char* name, int coreAmount void MSG_vm_start(msg_vm_t vm) { vm->start(); - if (TRACE_msg_vm_is_enabled()) { - simgrid::instr::StateType* state = simgrid::instr::Container::byName(vm->getName())->getState("MSG_VM_STATE"); - state->addEntityValue("start", "0 0 1"); // start is blue - state->pushEvent("start"); - } } /** @brief Immediately suspend the execution of all processes within the given VM. @@ -172,11 +119,6 @@ void MSG_vm_start(msg_vm_t vm) void MSG_vm_suspend(msg_vm_t vm) { vm->suspend(); - if (TRACE_msg_vm_is_enabled()) { - simgrid::instr::StateType* state = simgrid::instr::Container::byName(vm->getName())->getState("MSG_VM_STATE"); - state->addEntityValue("suspend", "1 0 0"); // suspend is red - state->pushEvent("suspend"); - } } /** @brief Resume the execution of the VM. All processes on the VM run again. @@ -187,8 +129,6 @@ void MSG_vm_suspend(msg_vm_t vm) void MSG_vm_resume(msg_vm_t vm) { vm->resume(); - if (TRACE_msg_vm_is_enabled()) - simgrid::instr::Container::byName(vm->getName())->getState("MSG_VM_STATE")->popEvent(); } /** @brief Immediately kills all processes within the given VM. @@ -208,20 +148,6 @@ void MSG_vm_shutdown(msg_vm_t vm) */ void MSG_vm_destroy(msg_vm_t vm) { - if (vm->isMigrating()) - THROWF(vm_error, 0, "Cannot destroy VM '%s', which is migrating.", vm->getCname()); - - /* First, terminate all processes on the VM if necessary */ - vm->shutdown(); - - /* Then, destroy the VM object */ vm->destroy(); - - if (TRACE_msg_vm_is_enabled()) { - container_t container = simgrid::instr::Container::byName(vm->getName()); - container->removeFromParent(); - delete container; - } } - } diff --git a/src/plugins/vm/VirtualMachineImpl.cpp b/src/plugins/vm/VirtualMachineImpl.cpp index 4367a9b74c..f4c0dd642c 100644 --- a/src/plugins/vm/VirtualMachineImpl.cpp +++ b/src/plugins/vm/VirtualMachineImpl.cpp @@ -54,7 +54,7 @@ static void hostStateChange(s4u::Host& host) if (vm->getPm() == &host) trash.push_back(vm); for (s4u::VirtualMachine* vm : trash) - vm->pimpl_vm_->shutdown(SIMIX_process_self()); + vm->shutdown(); } } VMModel::VMModel() @@ -93,9 +93,9 @@ double VMModel::nextOccuringEvent(double now) surf::Cpu* cpu = ws_vm->pimpl_cpu; xbt_assert(cpu, "cpu-less host"); - double solved_value = ws_vm->pimpl_vm_->action_->getVariable()->get_value(); // this is X1 in comment above, what + double solved_value = ws_vm->getImpl()->action_->getVariable()->get_value(); // this is X1 in comment above, what // this VM got in the sharing on the PM - XBT_DEBUG("assign %f to vm %s @ pm %s", solved_value, ws_vm->getCname(), ws_vm->pimpl_vm_->getPm()->getCname()); + XBT_DEBUG("assign %f to vm %s @ pm %s", solved_value, ws_vm->getCname(), ws_vm->getPm()->getCname()); xbt_assert(cpu->model() == surf_cpu_model_vm); lmm_system_t vcpu_system = cpu->model()->getMaxminSystem(); diff --git a/src/plugins/vm/VmLiveMigration.cpp b/src/plugins/vm/VmLiveMigration.cpp index f0ec4ec59e..ba9cee4d94 100644 --- a/src/plugins/vm/VmLiveMigration.cpp +++ b/src/plugins/vm/VmLiveMigration.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -45,7 +46,7 @@ void MigrationRx::operator()() vm_->resume(); // Now the VM is running on the new host (the migration is completed) (even if the SRC crash) - vm_->pimpl_vm_->isMigrating = false; + vm_->getImpl()->isMigrating = false; XBT_DEBUG("VM(%s) moved from PM(%s) to PM(%s)", vm_->getCname(), src_pm_->getCname(), dst_pm_->getCname()); if (TRACE_msg_vm_is_enabled()) { @@ -280,6 +281,28 @@ void MigrationTx::operator()() } SG_BEGIN_DECL() +simgrid::s4u::VirtualMachine* sg_vm_create_migratable(simgrid::s4u::Host* pm, const char* name, int coreAmount, + int ramsize, int mig_netspeed, int dp_intensity) +{ + simgrid::vm::VmHostExt::ensureVmExtInstalled(); + + /* For the moment, intensity_rate is the percentage against the migration bandwidth */ + + msg_vm_t vm = new simgrid::s4u::VirtualMachine(name, pm, coreAmount, static_cast(ramsize) * 1024 * 1024); + sg_vm_set_dirty_page_intensity(vm, dp_intensity / 100.0); + sg_vm_set_working_set_memory(vm, vm->getRamsize() * 0.9); // assume working set memory is 90% of ramsize + sg_vm_set_migration_speed(vm, mig_netspeed * 1024 * 1024.0); + + XBT_DEBUG("migspeed : %f intensity mem : %d", mig_netspeed * 1024 * 1024.0, dp_intensity); + + return vm; +} + +int sg_vm_is_migrating(simgrid::s4u::VirtualMachine* vm) +{ + return vm->isMigrating(); +} + void sg_vm_migrate(simgrid::s4u::VirtualMachine* vm, simgrid::s4u::Host* dst_pm) { simgrid::s4u::Host* src_pm = vm->getPm(); @@ -293,7 +316,7 @@ void sg_vm_migrate(simgrid::s4u::VirtualMachine* vm, simgrid::s4u::Host* dst_pm) if (vm->isMigrating()) THROWF(vm_error, 0, "Cannot migrate VM '%s' that is already migrating.", vm->getCname()); - vm->pimpl_vm_->isMigrating = true; + vm->getImpl()->isMigrating = true; std::string rx_name = std::string("__pr_mig_rx:") + vm->getCname() + "(" + src_pm->getCname() + "-" + dst_pm->getCname() + ")"; @@ -314,6 +337,6 @@ void sg_vm_migrate(simgrid::s4u::VirtualMachine* vm, simgrid::s4u::Host* dst_pm) tx->join(); rx->join(); - vm->pimpl_vm_->isMigrating = false; + vm->getImpl()->isMigrating = false; } } diff --git a/src/plugins/vm/s4u_VirtualMachine.cpp b/src/plugins/vm/s4u_VirtualMachine.cpp index 403a647e92..3ca10336ca 100644 --- a/src/plugins/vm/s4u_VirtualMachine.cpp +++ b/src/plugins/vm/s4u_VirtualMachine.cpp @@ -17,7 +17,7 @@ namespace simgrid { namespace s4u { VirtualMachine::VirtualMachine(const char* name, s4u::Host* pm, int coreAmount) - : VirtualMachine(name, pm, coreAmount, 0) + : VirtualMachine(name, pm, coreAmount, 1024) { } @@ -39,8 +39,10 @@ VirtualMachine::VirtualMachine(const char* name, s4u::Host* pm, int coreAmount, extension_set(new simgrid::simix::Host()); if (TRACE_msg_vm_is_enabled()) { - container_t host_container = simgrid::instr::Container::byName(pm->getName()); - new simgrid::instr::Container(name, "MSG_VM", host_container); + container_t host_container = instr::Container::byName(pm->getName()); + new instr::Container(name, "MSG_VM", host_container); + instr::Container::byName(getName())->getState("MSG_VM_STATE")->addEntityValue("start", "0 0 1"); // start is blue + instr::Container::byName(getName())->getState("MSG_VM_STATE")->addEntityValue("suspend", "1 0 0"); // suspend is red } } @@ -60,10 +62,19 @@ VirtualMachine::~VirtualMachine() /* Don't free these things twice: they are the ones of my physical host */ pimpl_netpoint = nullptr; + + if (TRACE_msg_vm_is_enabled()) { + container_t container = simgrid::instr::Container::byName(getName()); + container->removeFromParent(); + delete container; + } } void VirtualMachine::start() { + if (TRACE_msg_vm_is_enabled()) + simgrid::instr::Container::byName(getName())->getState("MSG_VM_STATE")->pushEvent("start"); + simgrid::simix::kernelImmediate([this]() { simgrid::vm::VmHostExt::ensureVmExtInstalled(); @@ -79,8 +90,8 @@ void VirtualMachine::start() /* Retrieve the memory occupied by the VMs on that host. Yep, we have to traverse all VMs of all hosts for that */ long total_ramsize_of_vms = 0; for (simgrid::s4u::VirtualMachine* const& ws_vm : simgrid::vm::VirtualMachineImpl::allVms_) - if (pm == ws_vm->pimpl_vm_->getPm()) - total_ramsize_of_vms += ws_vm->pimpl_vm_->getRamsize(); + if (pm == ws_vm->getPm()) + total_ramsize_of_vms += ws_vm->getRamsize(); if (vm_ramsize > pm_ramsize - total_ramsize_of_vms) { XBT_WARN("cannnot start %s@%s due to memory shortage: vm_ramsize %ld, free %ld, pm_ramsize %ld (bytes).", @@ -92,18 +103,25 @@ void VirtualMachine::start() this->pimpl_vm_->setState(SURF_VM_STATE_RUNNING); }); + + if (TRACE_msg_vm_is_enabled()) + simgrid::instr::Container::byName(getName())->getState("MSG_VM_STATE")->popEvent(); } void VirtualMachine::suspend() { smx_actor_t issuer = SIMIX_process_self(); simgrid::simix::kernelImmediate([this, issuer]() { pimpl_vm_->suspend(issuer); }); + if (TRACE_msg_vm_is_enabled()) + simgrid::instr::Container::byName(getName())->getState("MSG_VM_STATE")->pushEvent("suspend"); XBT_DEBUG("vm_suspend done"); } void VirtualMachine::resume() { pimpl_vm_->resume(); + if (TRACE_msg_vm_is_enabled()) + simgrid::instr::Container::byName(getName())->getState("MSG_VM_STATE")->popEvent(); } void VirtualMachine::shutdown() @@ -112,6 +130,18 @@ void VirtualMachine::shutdown() simgrid::simix::kernelImmediate([this, issuer]() { pimpl_vm_->shutdown(issuer); }); } +void VirtualMachine::destroy() +{ + if (isMigrating()) + THROWF(vm_error, 0, "Cannot destroy VM '%s', which is migrating.", getCname()); + + /* First, terminate all processes on the VM if necessary */ + shutdown(); + + /* Then, destroy the VM object */ + Host::destroy(); +} + bool VirtualMachine::isMigrating() { return pimpl_vm_ && pimpl_vm_->isMigrating; @@ -129,7 +159,7 @@ void VirtualMachine::setPm(simgrid::s4u::Host* pm) e_surf_vm_state_t VirtualMachine::getState() { - return pimpl_vm_->getState(); + return simgrid::simix::kernelImmediate([this]() { return pimpl_vm_->getState(); }); } size_t VirtualMachine::getRamsize() diff --git a/src/surf/HostImpl.cpp b/src/surf/HostImpl.cpp index 2a24cc68e8..36bff707f3 100644 --- a/src/surf/HostImpl.cpp +++ b/src/surf/HostImpl.cpp @@ -21,10 +21,9 @@ namespace surf { * Model * *********/ -/* Each VM has a dummy CPU action on the PM layer. This CPU action works as the - * constraint (capacity) of the VM in the PM layer. If the VM does not have any - * active task, the dummy CPU action must be deactivated, so that the VM does - * not get any CPU share in the PM layer. */ +/* Each VM has a dummy CPU action on the PM layer. This CPU action works as the constraint (capacity) of the VM in the + * PM layer. If the VM does not have any active task, the dummy CPU action must be deactivated, so that the VM does not + * get any CPU share in the PM layer. */ void HostModel::ignoreEmptyVmInPmLMM() { /* iterate for all virtual machines */ @@ -33,13 +32,13 @@ void HostModel::ignoreEmptyVmInPmLMM() int active_tasks = cpu->constraint()->get_variable_amount(); /* The impact of the VM over its PM is the min between its vCPU amount and the amount of tasks it contains */ - int impact = std::min(active_tasks, ws_vm->pimpl_vm_->coreAmount()); + int impact = std::min(active_tasks, ws_vm->getImpl()->coreAmount()); XBT_DEBUG("set the weight of the dummy CPU action of VM%p on PM to %d (#tasks: %d)", ws_vm, impact, active_tasks); if (impact > 0) - ws_vm->pimpl_vm_->action_->setSharingWeight(1. / impact); + ws_vm->getImpl()->action_->setSharingWeight(1. / impact); else - ws_vm->pimpl_vm_->action_->setSharingWeight(0.); + ws_vm->getImpl()->action_->setSharingWeight(0.); } } diff --git a/src/surf/plugins/dirty_page_tracking.cpp b/src/surf/plugins/dirty_page_tracking.cpp index e75cb111de..6c3710bc77 100644 --- a/src/surf/plugins/dirty_page_tracking.cpp +++ b/src/surf/plugins/dirty_page_tracking.cpp @@ -79,10 +79,10 @@ static void onExecCreation(simgrid::kernel::activity::ExecImplPtr exec) if (vm == nullptr) return; - if (vm->pimpl_vm_->extension()->isTracking()) { - vm->pimpl_vm_->extension()->track(exec, exec->remains()); + if (vm->getImpl()->extension()->isTracking()) { + vm->getImpl()->extension()->track(exec, exec->remains()); } else { - vm->pimpl_vm_->extension()->track(exec, 0.0); + vm->getImpl()->extension()->track(exec, 0.0); } } @@ -94,12 +94,12 @@ static void onExecCompletion(simgrid::kernel::activity::ExecImplPtr exec) /* If we are in the middle of dirty page tracking, we record how much computation has been done until now, and keep * the information for the lookup_() function that will called soon. */ - if (vm->pimpl_vm_->extension()->isTracking()) { + if (vm->getImpl()->extension()->isTracking()) { double delta = - vm->pimpl_vm_->extension()->getStoredRemains(exec) - exec->remains(); - vm->pimpl_vm_->extension()->updateDirtyPageCount(delta); + vm->getImpl()->extension()->getStoredRemains(exec) - exec->remains(); + vm->getImpl()->extension()->updateDirtyPageCount(delta); } - vm->pimpl_vm_->extension()->untrack(exec); + vm->getImpl()->extension()->untrack(exec); } SG_BEGIN_DECL() @@ -115,59 +115,54 @@ void sg_vm_live_migration_plugin_init() } } -int sg_vm_is_migratable(sg_vm_t vm) -{ - return simgrid::vm::VmDirtyPageTrackingExt::EXTENSION_ID.valid(); -} - void sg_vm_start_dirty_page_tracking(sg_vm_t vm) { - vm->pimpl_vm_->extension()->startTracking(); + vm->getImpl()->extension()->startTracking(); } void sg_vm_stop_dirty_page_tracking(sg_vm_t vm) { - vm->pimpl_vm_->extension()->stopTracking(); + vm->getImpl()->extension()->stopTracking(); } double sg_vm_lookup_computed_flops(sg_vm_t vm) { - return vm->pimpl_vm_->extension()->computedFlopsLookup(); + return vm->getImpl()->extension()->computedFlopsLookup(); } void sg_vm_set_dirty_page_intensity(sg_vm_t vm, double intensity) { - vm->pimpl_vm_->extension()->setIntensity(intensity); + vm->getImpl()->extension()->setIntensity(intensity); } double sg_vm_get_dirty_page_intensity(sg_vm_t vm) { - return vm->pimpl_vm_->extension()->getIntensity(); + return vm->getImpl()->extension()->getIntensity(); } void sg_vm_set_working_set_memory(sg_vm_t vm, sg_size_t size) { - vm->pimpl_vm_->extension()->setWorkingSetMemory(size); + vm->getImpl()->extension()->setWorkingSetMemory(size); } sg_size_t sg_vm_get_working_set_memory(sg_vm_t vm) { - return vm->pimpl_vm_->extension()->getWorkingSetMemory(); + return vm->getImpl()->extension()->getWorkingSetMemory(); } void sg_vm_set_migration_speed(sg_vm_t vm, double speed) { - vm->pimpl_vm_->extension()->setMigrationSpeed(speed); + vm->getImpl()->extension()->setMigrationSpeed(speed); } double sg_vm_get_migration_speed(sg_vm_t vm) { - return vm->pimpl_vm_->extension()->getMigrationSpeed(); + return vm->getImpl()->extension()->getMigrationSpeed(); } double sg_vm_get_max_downtime(sg_vm_t vm) { - return vm->pimpl_vm_->extension()->getMaxDowntime(); + return vm->getImpl()->extension()->getMaxDowntime(); } SG_END_DECL() diff --git a/src/surf/plugins/host_energy.cpp b/src/surf/plugins/host_energy.cpp index fbd887a48a..2a0947f494 100644 --- a/src/surf/plugins/host_energy.cpp +++ b/src/surf/plugins/host_energy.cpp @@ -385,7 +385,7 @@ static void onActionStateChange(simgrid::surf::CpuAction* action, simgrid::surf: // If it's a VM, take the corresponding PM simgrid::s4u::VirtualMachine* vm = dynamic_cast(host); if (vm) // If it's a VM, take the corresponding PM - host = vm->pimpl_vm_->getPm(); + host = vm->getPm(); // Get the host_energy extension for the relevant host HostEnergy* host_energy = host->extension(); diff --git a/teshsuite/msg/cloud-migration/cloud-migration.tesh b/teshsuite/msg/cloud-migration/cloud-migration.tesh index 6f32cff5da..124b61a9c7 100644 --- a/teshsuite/msg/cloud-migration/cloud-migration.tesh +++ b/teshsuite/msg/cloud-migration/cloud-migration.tesh @@ -4,9 +4,9 @@ $ $SG_TEST_EXENV ${bindir:=.}/cloud-migration ${platfdir}/small_platform.xml --l > [132.765801] (1:master_@Fafard) Test: Migrate a VM with 100 Mbytes RAM > [146.111793] (1:master_@Fafard) VM0 migrated: Fafard->Tremblay in 13.346 s > [146.111793] (1:master_@Fafard) Test: Migrate two VMs at once from PM0 to PM1 -> [411.566271] (9:mig_wrk@Fafard) VM1 migrated: Fafard->Tremblay in 265.454 s +> [411.566271] (8:mig_wrk@Fafard) VM1 migrated: Fafard->Tremblay in 265.454 s > [411.566271] (6:mig_wrk@Fafard) VM0 migrated: Fafard->Tremblay in 265.454 s > [10146.111793] (1:master_@Fafard) Test: Migrate two VMs at once to different PMs -> [10362.620589] (15:mig_wrk@Fafard) VM1 migrated: Fafard->Bourassa in 216.509 s +> [10362.620589] (14:mig_wrk@Fafard) VM1 migrated: Fafard->Bourassa in 216.509 s > [10411.547334] (12:mig_wrk@Fafard) VM0 migrated: Fafard->Tremblay in 265.436 s > [20146.111793] (0:maestro@) Bye (simulation time 20146.1)