X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/1e2bdd3b231b3a1df3b910c800c1e5e9224d41fc..fedb0ec6497d5d21ee4eab39c686fc0cdebcfc9a:/src/plugins/vm/VirtualMachineImpl.cpp diff --git a/src/plugins/vm/VirtualMachineImpl.cpp b/src/plugins/vm/VirtualMachineImpl.cpp index b01ab0a7e4..412cbd13a2 100644 --- a/src/plugins/vm/VirtualMachineImpl.cpp +++ b/src/plugins/vm/VirtualMachineImpl.cpp @@ -6,6 +6,8 @@ #include "src/plugins/vm/VirtualMachineImpl.hpp" #include "simgrid/s4u/VirtualMachine.hpp" +#include "src/simix/ActorImpl.hpp" +#include "src/simix/smx_host_private.h" #include @@ -13,26 +15,26 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_vm, surf, "Logging specific to the SURF VM module"); -simgrid::surf::VMModel* surf_vm_model = nullptr; +simgrid::vm::VMModel* surf_vm_model = nullptr; void surf_vm_model_init_HL13() { if (surf_cpu_model_vm) { - surf_vm_model = new simgrid::surf::VMModel(); + surf_vm_model = new simgrid::vm::VMModel(); all_existing_models->push_back(surf_vm_model); } } namespace simgrid { -namespace surf { +namespace vm { /************* * Callbacks * *************/ -simgrid::xbt::signal onVmCreation; -simgrid::xbt::signal onVmDestruction; -simgrid::xbt::signal onVmStateChange; +simgrid::xbt::signal onVmCreation; +simgrid::xbt::signal onVmDestruction; +simgrid::xbt::signal onVmStateChange; /********* * Model * @@ -73,12 +75,11 @@ double VMModel::nextOccuringEvent(double now) /* iterate for all virtual machines */ for (s4u::VirtualMachine* ws_vm : VirtualMachineImpl::allVms_) { - Cpu* cpu = ws_vm->pimpl_cpu; + surf::Cpu* cpu = ws_vm->pimpl_cpu; xbt_assert(cpu, "cpu-less host"); double solved_value = ws_vm->pimpl_vm_->action_->getVariable()->value; - XBT_DEBUG("assign %f to vm %s @ pm %s", solved_value, ws_vm->name().c_str(), - ws_vm->pimpl_vm_->getPm()->name().c_str()); + XBT_DEBUG("assign %f to vm %s @ pm %s", solved_value, ws_vm->cname(), ws_vm->pimpl_vm_->getPm()->cname()); // TODO: check lmm_update_constraint_bound() works fine instead of the below manual substitution. // cpu_cas01->constraint->bound = solved_value; @@ -111,7 +112,7 @@ VirtualMachineImpl::VirtualMachineImpl(simgrid::s4u::VirtualMachine* piface, sim /* Initialize the VM parameters */ params_.ramsize = 0; - XBT_VERB("Create VM(%s)@PM(%s)", piface->name().c_str(), hostPM_->name().c_str()); + XBT_VERB("Create VM(%s)@PM(%s)", piface->cname(), hostPM_->cname()); } extern "C" int @@ -153,30 +154,96 @@ void VirtualMachineImpl::setState(e_surf_vm_state_t state) { vmState_ = state; } -void VirtualMachineImpl::suspend() +void VirtualMachineImpl::suspend(smx_actor_t issuer) { + if (isMigrating) + THROWF(vm_error, 0, "Cannot suspend VM '%s': it is migrating", piface_->cname()); + if (getState() != SURF_VM_STATE_RUNNING) + THROWF(vm_error, 0, "Cannot suspend VM %s: it is not running.", piface_->cname()); + if (issuer->host == piface_) + THROWF(vm_error, 0, "Actor %s cannot suspend the VM %s in which it runs", issuer->cname(), piface_->cname()); + + xbt_swag_t process_list = piface_->extension()->process_list; + XBT_DEBUG("suspend VM(%s), where %d processes exist", piface_->cname(), xbt_swag_size(process_list)); + action_->suspend(); + + smx_actor_t smx_process, smx_process_safe; + xbt_swag_foreach_safe(smx_process, smx_process_safe, process_list) { + XBT_DEBUG("suspend %s", smx_process->name.c_str()); + SIMIX_process_suspend(smx_process, issuer); + } + + XBT_DEBUG("suspend all processes on the VM done done"); + vmState_ = SURF_VM_STATE_SUSPENDED; } void VirtualMachineImpl::resume() { + if (getState() != SURF_VM_STATE_SUSPENDED) + THROWF(vm_error, 0, "Cannot resume VM %s: it was not suspended", piface_->cname()); + + xbt_swag_t process_list = piface_->extension()->process_list; + XBT_DEBUG("Resume VM %s, containing %d processes.", piface_->cname(), xbt_swag_size(process_list)); + action_->resume(); + + smx_actor_t smx_process, smx_process_safe; + xbt_swag_foreach_safe(smx_process, smx_process_safe, process_list) { + XBT_DEBUG("resume %s", smx_process->cname()); + SIMIX_process_resume(smx_process); + } + vmState_ = SURF_VM_STATE_RUNNING; } -void VirtualMachineImpl::save() +/** + * @brief Function to save a VM. + * This function is the same as vm_suspend, but the state of the VM is saved to the disk, and not preserved in memory. + * We can later restore it again. + * + * @param issuer the process requesting this operation + */ +void VirtualMachineImpl::save(smx_actor_t issuer) { + if (isMigrating) + THROWF(vm_error, 0, "Cannot save VM %s: it is migrating.", piface_->cname()); + + if (getState() != SURF_VM_STATE_RUNNING) + THROWF(vm_error, 0, "Cannot save VM %s: it is not running.", piface_->cname()); + + xbt_swag_t process_list = piface_->extension()->process_list; + XBT_DEBUG("Save VM %s, where %d processes exist", piface_->cname(), xbt_swag_size(process_list)); + vmState_ = SURF_VM_STATE_SAVING; action_->suspend(); vmState_ = SURF_VM_STATE_SAVED; + + smx_actor_t smx_process, smx_process_safe; + xbt_swag_foreach_safe(smx_process, smx_process_safe, process_list) { + XBT_DEBUG("suspend %s", smx_process->cname()); + SIMIX_process_suspend(smx_process, issuer); + } } void VirtualMachineImpl::restore() { + if (getState() != SURF_VM_STATE_SAVED) + THROWF(vm_error, 0, "Cannot restore VM %s: it was not saved", piface_->cname()); + + xbt_swag_t process_list = piface_->extension()->process_list; + XBT_DEBUG("Restore VM %s, where %d processes exist", piface_->cname(), xbt_swag_size(process_list)); + vmState_ = SURF_VM_STATE_RESTORING; action_->resume(); vmState_ = SURF_VM_STATE_RUNNING; + + smx_actor_t smx_process, smx_process_safe; + xbt_swag_foreach_safe(smx_process, smx_process_safe, process_list) { + XBT_DEBUG("resume %s", smx_process->cname()); + SIMIX_process_resume(smx_process); + } } /** @brief returns the physical machine on which the VM is running **/ @@ -185,24 +252,27 @@ s4u::Host* VirtualMachineImpl::getPm() return hostPM_; } -/* Update the physical host of the given VM */ -void VirtualMachineImpl::migrate(s4u::Host* host_dest) +/** @brief Change the physical host on which the given VM is running + * + * This is an instantaneous migration. + */ +void VirtualMachineImpl::setPm(s4u::Host* destination) { - const char* vm_name = piface_->name().c_str(); - const char* pm_name_src = hostPM_->name().c_str(); - const char* pm_name_dst = host_dest->name().c_str(); + const char* vm_name = piface_->cname(); + const char* pm_name_src = hostPM_->cname(); + const char* pm_name_dst = destination->cname(); /* update net_elm with that of the destination physical host */ - piface_->pimpl_netcard = host_dest->pimpl_netcard; + piface_->pimpl_netcard = destination->pimpl_netcard; - hostPM_ = host_dest; + hostPM_ = destination; /* Update vcpu's action for the new pm */ /* create a cpu action bound to the pm model at the destination. */ - CpuAction* new_cpu_action = static_cast(host_dest->pimpl_cpu->execution_start(0)); + surf::CpuAction* new_cpu_action = static_cast(destination->pimpl_cpu->execution_start(0)); - Action::State state = action_->getState(); - if (state != Action::State::done) + surf::Action::State state = action_->getState(); + if (state != surf::Action::State::done) XBT_CRITICAL("FIXME: may need a proper handling, %d", static_cast(state)); if (action_->getRemainsNoUpdate() > 0) XBT_CRITICAL("FIXME: need copy the state(?), %f", action_->getRemainsNoUpdate());