From 24cb0129bbb29b2a1400ce3ed8679ca1d58f5ede Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sun, 16 Oct 2016 16:14:06 +0200 Subject: [PATCH] code simplifications in VMs --- include/simgrid/s4u/host.hpp | 6 +++--- src/simix/smx_vm.cpp | 11 +++++------ src/surf/HostImpl.hpp | 4 ++-- src/surf/virtual_machine.cpp | 15 ++++----------- 4 files changed, 14 insertions(+), 22 deletions(-) diff --git a/include/simgrid/s4u/host.hpp b/include/simgrid/s4u/host.hpp index 3583defaa0..2eeded4cee 100644 --- a/include/simgrid/s4u/host.hpp +++ b/include/simgrid/s4u/host.hpp @@ -44,12 +44,11 @@ XBT_PUBLIC_CLASS Host : public: explicit Host(const char *name); + /** Host destruction logic */ -protected: - ~Host(); // TODO, make me private private: + ~Host(); bool currentlyDestroying_ = false; - public: void destroy(); @@ -72,6 +71,7 @@ public: void turnOff(); /** Returns if that host is currently up and running */ bool isOn(); + /** Returns if that host is currently down and offline */ bool isOff() { return !isOn(); } double speed(); diff --git a/src/simix/smx_vm.cpp b/src/simix/smx_vm.cpp index 77c24f0616..e582a31b9e 100644 --- a/src/simix/smx_vm.cpp +++ b/src/simix/smx_vm.cpp @@ -298,12 +298,11 @@ void simcall_HANDLER_vm_shutdown(smx_simcall_t simcall, sg_host_t vm) SIMIX_vm_shutdown(vm, simcall->issuer); } -extern xbt_dict_t host_list; // FIXME:killme don't dupplicate the content of s4u::Host this way - /** - * @brief Function to destroy a SIMIX VM host. - * - * @param vm the vm host to destroy (a sg_host_t) - */ +/** + * @brief Function to destroy a SIMIX VM host. + * + * @param vm the vm host to destroy (a sg_host_t) + */ void SIMIX_vm_destroy(sg_host_t vm) { /* this code basically performs a similar thing like SIMIX_host_destroy() */ diff --git a/src/surf/HostImpl.hpp b/src/surf/HostImpl.hpp index 695e0c05fc..32d94178df 100644 --- a/src/surf/HostImpl.hpp +++ b/src/surf/HostImpl.hpp @@ -223,8 +223,8 @@ public: {THROW_IMPOSSIBLE;} // FIXME: Host should not be a Resource public: - xbt_dynar_t storage_; - Cpu *cpu_; + xbt_dynar_t storage_ = nullptr; + Cpu* cpu_ = nullptr; simgrid::s4u::Host* piface_ = nullptr; /** @brief Get the list of virtual machines on the current Host */ diff --git a/src/surf/virtual_machine.cpp b/src/surf/virtual_machine.cpp index 79a112be83..794ec016c5 100644 --- a/src/surf/virtual_machine.cpp +++ b/src/surf/virtual_machine.cpp @@ -103,34 +103,27 @@ double VMModel::nextOccuringEvent(double now) * Resource * ************/ -VirtualMachine::VirtualMachine(HostModel *model, const char *name, simgrid::s4u::Host *host_PM) -: HostImpl(model, name, nullptr, nullptr, nullptr) -, hostPM_(host_PM) +VirtualMachine::VirtualMachine(HostModel* model, const char* name, simgrid::s4u::Host* host_PM) + : HostImpl(model, name, nullptr /*constraint*/, nullptr /*storage*/, nullptr /*cpu*/), hostPM_(host_PM) { /* Register this VM to the list of all VMs */ allVms_.push_back(this); piface_ = new simgrid::s4u::Host(name); piface_->extension_set(this); - /* Currently, we assume a VM has no storage. */ - storage_ = nullptr; - /* Currently, a VM uses the network resource of its physical host. In * host_lib, this network resource object is referred from two different keys. * When deregistering the reference that points the network resource object * from the VM name, we have to make sure that the system does not call the * free callback for the network resource object. The network resource object * is still used by the physical machine. */ - sg_host_t host_VM = piface_; - host_VM->pimpl_netcard = host_PM->pimpl_netcard; - - vmState_ = SURF_VM_STATE_CREATED; + piface_->pimpl_netcard = host_PM->pimpl_netcard; // //// CPU RELATED STUFF //// // 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(host_VM, sub_cpu->getSpeedPeakList(), 1 /*cores*/); + cpu_ = surf_cpu_model_vm->createCpu(piface_, sub_cpu->getSpeedPeakList(), 1 /*cores*/); if (sub_cpu->getPState() != 0) cpu_->setPState(sub_cpu->getPState()); -- 2.20.1