X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/6ae07464eeacbd09ee8b4ff9630c78d62bfe699e..f5a24e63c4711950e12735bda603ed31fd8403a7:/src/surf/virtual_machine.cpp diff --git a/src/surf/virtual_machine.cpp b/src/surf/virtual_machine.cpp index f28f6aed57..f79808378a 100644 --- a/src/surf/virtual_machine.cpp +++ b/src/surf/virtual_machine.cpp @@ -78,7 +78,7 @@ double VMModel::nextOccuringEvent(double now) /* iterate for all virtual machines */ for (VirtualMachine *ws_vm : VirtualMachine::allVms_) { - Cpu *cpu = ws_vm->cpu_; + Cpu* cpu = ws_vm->piface_->pimpl_cpu; xbt_assert(cpu, "cpu-less host"); double solved_value = ws_vm->action_->getVariable()->value; @@ -104,7 +104,7 @@ double VMModel::nextOccuringEvent(double now) ************/ VirtualMachine::VirtualMachine(HostModel* model, const char* name, simgrid::s4u::Host* host_PM) - : HostImpl(model, name, nullptr /*constraint*/, nullptr /*storage*/, nullptr /*cpu*/), hostPM_(host_PM) + : HostImpl(model, name, nullptr /*constraint*/, nullptr /*storage*/), hostPM_(host_PM) { /* Register this VM to the list of all VMs */ allVms_.push_back(this); @@ -124,9 +124,9 @@ VirtualMachine::VirtualMachine(HostModel* model, const char* name, simgrid::s4u: // Roughly, create a vcpu resource by using the values of the sub_cpu one. CpuCas01 *sub_cpu = dynamic_cast(host_PM->pimpl_cpu); - cpu_ = surf_cpu_model_vm->createCpu(piface_, sub_cpu->getSpeedPeakList(), 1 /*cores*/); + piface_->pimpl_cpu = surf_cpu_model_vm->createCpu(piface_, sub_cpu->getSpeedPeakList(), 1 /*cores*/); if (sub_cpu->getPState() != 0) - cpu_->setPState(sub_cpu->getPState()); + piface_->pimpl_cpu->setPState(sub_cpu->getPState()); /* We create cpu_action corresponding to a VM process on the host operating system. */ /* FIXME: TODO: we have to periodically input GUESTOS_NOISE to the system? how ? */ @@ -146,29 +146,16 @@ VirtualMachine::~VirtualMachine() /* Free the cpu_action of the VM. */ XBT_ATTRIB_UNUSED int ret = action_->unref(); xbt_assert(ret == 1, "Bug: some resource still remains"); - - delete cpu_; } e_surf_vm_state_t VirtualMachine::getState() { return vmState_; } -void VirtualMachine::setState(e_surf_vm_state_t state) { +void VirtualMachine::setState(e_surf_vm_state_t state) +{ vmState_ = state; } -void VirtualMachine::turnOn() { - if (isOff()) { - Resource::turnOn(); - onVmStateChange(this); - } -} -void VirtualMachine::turnOff() { - if (isOn()) { - Resource::turnOff(); - onVmStateChange(this); - } -} void VirtualMachine::suspend() { action_->suspend(); @@ -203,31 +190,31 @@ sg_host_t VirtualMachine::getPm() { /* Update the physical host of the given VM */ void VirtualMachine::migrate(sg_host_t host_dest) { - HostImpl *surfHost_dst = host_dest->pimpl_; - const char *vm_name = getName(); - const char *pm_name_src = hostPM_->name().c_str(); - const char *pm_name_dst = surfHost_dst->getName(); - - /* update net_elm with that of the destination physical host */ - sg_host_by_name(vm_name)->pimpl_netcard = sg_host_by_name(pm_name_dst)->pimpl_netcard; - - hostPM_ = host_dest; - - /* 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)); - - Action::State state = action_->getState(); - if (state != 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()); - - /* keep the bound value of the cpu action of the VM. */ - double old_bound = action_->getBound(); - if (old_bound != 0) { - XBT_DEBUG("migrate VM(%s): set bound (%f) at %s", vm_name, old_bound, pm_name_dst); - new_cpu_action->setBound(old_bound); + HostImpl* surfHost_dst = host_dest->pimpl_; + const char* vm_name = getName(); + const char* pm_name_src = hostPM_->name().c_str(); + const char* pm_name_dst = surfHost_dst->getName(); + + /* update net_elm with that of the destination physical host */ + sg_host_by_name(vm_name)->pimpl_netcard = sg_host_by_name(pm_name_dst)->pimpl_netcard; + + hostPM_ = host_dest; + + /* 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)); + + Action::State state = action_->getState(); + if (state != 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()); + + /* keep the bound value of the cpu action of the VM. */ + double old_bound = action_->getBound(); + if (old_bound != 0) { + XBT_DEBUG("migrate VM(%s): set bound (%f) at %s", vm_name, old_bound, pm_name_dst); + new_cpu_action->setBound(old_bound); } XBT_ATTRIB_UNUSED int ret = action_->unref();