From 18da6183cb7f52a959005356cee3e1388d533a14 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Tue, 27 Oct 2015 19:10:58 +0100 Subject: [PATCH 1/1] [surf] tiny cleanups around the virtual machines - rename the file vm_interface.[ch] into virtual_machine.[ch] - rename the type VM into VirtualMachine - have the VirtualMachine constructor register the VM to the host lib - it was in Model13::CreateVM, that can now be emptied and soon killed - other VM models won't forget to do so --- src/surf/host_clm03.cpp | 2 +- src/surf/host_interface.cpp | 8 ++++---- src/surf/surf_c_bindings.cpp | 10 +++++----- src/surf/surf_interface.cpp | 2 +- .../{vm_interface.cpp => virtual_machine.cpp} | 19 ++++++++++-------- .../{vm_interface.hpp => virtual_machine.hpp} | 20 +++++++++---------- src/surf/vm_hl13.cpp | 19 ++++++------------ src/surf/vm_hl13.hpp | 6 +++--- tools/cmake/DefinePackages.cmake | 4 ++-- 9 files changed, 43 insertions(+), 47 deletions(-) rename src/surf/{vm_interface.cpp => virtual_machine.cpp} (74%) rename src/surf/{vm_interface.hpp => virtual_machine.hpp} (81%) diff --git a/src/surf/host_clm03.cpp b/src/surf/host_clm03.cpp index 79127599f9..e4d4957ff3 100644 --- a/src/surf/host_clm03.cpp +++ b/src/surf/host_clm03.cpp @@ -8,7 +8,7 @@ #include "cpu_cas01.hpp" #include "simgrid/sg_config.h" -#include "vm_interface.hpp" +#include "virtual_machine.hpp" XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_host); diff --git a/src/surf/host_interface.cpp b/src/surf/host_interface.cpp index 4c5dbca191..025df7c46d 100644 --- a/src/surf/host_interface.cpp +++ b/src/surf/host_interface.cpp @@ -11,7 +11,7 @@ #include "simgrid/sg_config.h" #include "network_interface.hpp" -#include "vm_interface.hpp" +#include "virtual_machine.hpp" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_host, surf, "Logging specific to the SURF host module"); @@ -50,7 +50,7 @@ void HostModel::adjustWeightOfDummyCpuActions() VMModel::ws_vms.begin(); iter != VMModel::ws_vms.end(); ++iter) { - VM *ws_vm = &*iter; + VirtualMachine *ws_vm = &*iter; CpuCas01 *cpu_cas01 = static_cast(ws_vm->p_cpu); xbt_assert(cpu_cas01, "cpu-less host"); @@ -322,14 +322,14 @@ int Host::fileMove(surf_file_t fd, const char* fullpath){ xbt_dynar_t Host::getVms() { - xbt_dynar_t dyn = xbt_dynar_new(sizeof(VM*), NULL); + xbt_dynar_t dyn = xbt_dynar_new(sizeof(VirtualMachine*), NULL); /* iterate for all virtual machines */ for (VMModel::vm_list_t::iterator iter = VMModel::ws_vms.begin(); iter != VMModel::ws_vms.end(); ++iter) { - VM *ws_vm = &*iter; + VirtualMachine *ws_vm = &*iter; if (this == ws_vm->p_subWs) xbt_dynar_push(dyn, &ws_vm); } diff --git a/src/surf/surf_c_bindings.cpp b/src/surf/surf_c_bindings.cpp index dabe0c2cfd..032280eb77 100644 --- a/src/surf/surf_c_bindings.cpp +++ b/src/surf/surf_c_bindings.cpp @@ -10,7 +10,7 @@ #include "surf_routing_cluster.hpp" #include "src/instr/instr_private.h" #include "plugins/energy.hpp" -#include "vm_interface.hpp" +#include "virtual_machine.hpp" XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_kernel); @@ -22,8 +22,8 @@ static Host *get_casted_host(surf_resource_t resource){ return static_cast(surf_host_resource_priv(resource)); } -static VM *get_casted_vm(surf_resource_t resource){ - return static_cast(surf_host_resource_priv(resource)); +static VirtualMachine *get_casted_vm(surf_resource_t resource){ + return static_cast(surf_host_resource_priv(resource)); } extern double NOW; @@ -374,7 +374,7 @@ xbt_dynar_t surf_host_get_vms(surf_resource_t host){ xbt_dynar_t vms = get_casted_host(host)->getVms(); xbt_dynar_t vms_ = xbt_dynar_new(sizeof(sg_host_t), NULL); unsigned int cpt; - VM *vm; + VirtualMachine *vm; xbt_dynar_foreach(vms, cpt, vm) { sg_host_t vm_ = xbt_lib_get_elm_or_null(host_lib, vm->getName()); xbt_dynar_push(vms_, &vm_); @@ -393,7 +393,7 @@ void surf_host_set_params(surf_resource_t host, vm_params_t params){ void surf_vm_destroy(surf_resource_t resource){ /* Before clearing the entries in host_lib, we have to pick up resources. */ - VM *vm = get_casted_vm(resource); + VirtualMachine *vm = get_casted_vm(resource); char* name = xbt_dict_get_elm_key(resource); /* We deregister objects from host_lib, without invoking the freeing callback * of each level. diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index 54788a7348..1bcf4a2187 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -13,7 +13,7 @@ #include "surf_routing.hpp" #include "simgrid/sg_config.h" #include "mc/mc.h" -#include "vm_interface.hpp" +#include "virtual_machine.hpp" XBT_LOG_NEW_CATEGORY(surf, "All SURF categories"); XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_kernel, surf, diff --git a/src/surf/vm_interface.cpp b/src/surf/virtual_machine.cpp similarity index 74% rename from src/surf/vm_interface.cpp rename to src/surf/virtual_machine.cpp index b50057f507..8f38911272 100644 --- a/src/surf/vm_interface.cpp +++ b/src/surf/virtual_machine.cpp @@ -5,7 +5,7 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "cpu_cas01.hpp" -#include "vm_interface.hpp" +#include "virtual_machine.hpp" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_vm, surf, "Logging specific to the SURF VM module"); @@ -16,9 +16,9 @@ VMModel *surf_vm_model = NULL; * Callbacks * *************/ -surf_callback(void, VM*) VMCreatedCallbacks; -surf_callback(void, VM*) VMDestructedCallbacks; -surf_callback(void, VM*) VMStateChangedCallbacks; +surf_callback(void, VirtualMachine*) VMCreatedCallbacks; +surf_callback(void, VirtualMachine*) VMDestructedCallbacks; +surf_callback(void, VirtualMachine*) VMStateChangedCallbacks; /********* * Model * @@ -30,11 +30,14 @@ VMModel::vm_list_t VMModel::ws_vms; * Resource * ************/ -VM::VM(Model *model, const char *name, xbt_dict_t props, +VirtualMachine::VirtualMachine(Model *model, const char *name, xbt_dict_t props, RoutingEdge *netElm, Cpu *cpu) : Host(model, name, props, NULL, netElm, cpu) { VMModel::ws_vms.push_back(*this); + + xbt_lib_set(host_lib, name, SURF_HOST_LEVEL, this); + surf_callback_emit(VMCreatedCallbacks, this); } @@ -42,13 +45,13 @@ VM::VM(Model *model, const char *name, xbt_dict_t props, * A physical host does not disappear in the current SimGrid code, but a VM may * disappear during a simulation. */ -VM::~VM() +VirtualMachine::~VirtualMachine() { surf_callback_emit(VMDestructedCallbacks, this); VMModel::ws_vms.erase(VMModel::vm_list_t::s_iterator_to(*this)); } -void VM::setState(e_surf_resource_state_t state){ +void VirtualMachine::setState(e_surf_resource_state_t state){ Resource::setState(state); surf_callback_emit(VMStateChangedCallbacks, this); } @@ -57,7 +60,7 @@ void VM::setState(e_surf_resource_state_t state){ * A surf level object will be useless in the upper layer. Returning the * dict_elm of the host. **/ -surf_resource_t VM::getPm() +surf_resource_t VirtualMachine::getPm() { return xbt_lib_get_elm_or_null(host_lib, p_subWs->getName()); } diff --git a/src/surf/vm_interface.hpp b/src/surf/virtual_machine.hpp similarity index 81% rename from src/surf/vm_interface.hpp rename to src/surf/virtual_machine.hpp index 961a04e864..ebc420b7a3 100644 --- a/src/surf/vm_interface.hpp +++ b/src/surf/virtual_machine.hpp @@ -19,7 +19,7 @@ ***********/ class XBT_PRIVATE VMModel; -class XBT_PRIVATE VM; +class XBT_PRIVATE VirtualMachine; /************* * Callbacks * @@ -28,17 +28,17 @@ class XBT_PRIVATE VM; /** @ingroup SURF_callbacks * @brief Callbacks fired after VM creation. Signature: `void(VM*)` */ -extern XBT_PRIVATE surf_callback(void, VM*) VMCreatedCallbacks; +extern XBT_PRIVATE surf_callback(void, VirtualMachine*) VMCreatedCallbacks; /** @ingroup SURF_callbacks * @brief Callbacks fired after VM destruction. Signature: `void(VM*)` */ -extern XBT_PRIVATE surf_callback(void, VM*) VMDestructedCallbacks; +extern XBT_PRIVATE surf_callback(void, VirtualMachine*) VMDestructedCallbacks; /** @ingroup SURF_callbacks * @brief Callbacks after VM State changes. Signature: `void(VMAction*)` */ -extern XBT_PRIVATE surf_callback(void, VM*) VMStateChangedCallbacks; +extern XBT_PRIVATE surf_callback(void, VirtualMachine*) VMStateChangedCallbacks; /************ * Resource * @@ -48,7 +48,7 @@ extern XBT_PRIVATE surf_callback(void, VM*) VMStateChangedCallbacks; * @brief SURF VM interface class * @details A VM represent a virtual machine */ -class VM : public Host { +class VirtualMachine : public Host { public: /** * @brief Constructor @@ -59,11 +59,11 @@ public: * @param netElm The RoutingEdge associated to this VM * @param cpu The Cpu associated to this VM */ - VM(Model *model, const char *name, xbt_dict_t props, + VirtualMachine(Model *model, const char *name, xbt_dict_t props, RoutingEdge *netElm, Cpu *cpu); /** @brief Destructor */ - ~VM(); + ~VirtualMachine(); void setState(e_surf_resource_state_t state); @@ -117,12 +117,12 @@ public: * @param host_PM The real machine hosting the VM * */ - virtual VM *createVM(const char *name, surf_resource_t host_PM)=0; + virtual VirtualMachine *createVM(const char *name, surf_resource_t host_PM)=0; void adjustWeightOfDummyCpuActions() {}; typedef boost::intrusive::member_hook< - VM, boost::intrusive::list_member_hook<>, &VM::vm_hook> VmOptions; - typedef boost::intrusive::list > vm_list_t; + VirtualMachine, boost::intrusive::list_member_hook<>, &VirtualMachine::vm_hook> VmOptions; + typedef boost::intrusive::list > vm_list_t; static vm_list_t ws_vms; }; diff --git a/src/surf/vm_hl13.cpp b/src/surf/vm_hl13.cpp index bafa0447c7..768c7ac52a 100644 --- a/src/surf/vm_hl13.cpp +++ b/src/surf/vm_hl13.cpp @@ -30,16 +30,8 @@ void VMHL13Model::updateActionsState(double /*now*/, double /*delta*/) {} /* ind means ''indirect'' that this is a reference on the whole dict_elm * structure (i.e not on the surf_resource_private infos) */ -VM *VMHL13Model::createVM(const char *name, surf_resource_t host_PM) -{ - VMHL13 *ws = new VMHL13(this, name, NULL, host_PM); - - xbt_lib_set(host_lib, name, SURF_HOST_LEVEL, ws); - - /* TODO: - * - check how network requests are scheduled between distinct processes competing for the same card. - */ - return ws; +VirtualMachine *VMHL13Model::createVM(const char *name, surf_resource_t host_PM) { + return new VMHL13(this, name, NULL, host_PM); } static inline double get_solved_value(CpuAction *cpu_action) @@ -56,7 +48,7 @@ const double virt_overhead = 1; double VMHL13Model::shareResources(double now) { - /* TODO: udpate action's cost with the total cost of processes on the VM. */ + /* TODO: update action's cost with the total cost of processes on the VM. */ /* 0. Make sure that we already calculated the resource share at the physical @@ -103,7 +95,7 @@ double VMHL13Model::shareResources(double now) VMModel::ws_vms.begin(); iter != VMModel::ws_vms.end(); ++iter) { - VM *ws_vm = &*iter; + VirtualMachine *ws_vm = &*iter; Cpu *cpu = ws_vm->p_cpu; xbt_assert(cpu, "cpu-less host"); @@ -211,7 +203,7 @@ Action *VMHL13Model::executeParallelTask(int host_nb, VMHL13::VMHL13(VMModel *model, const char* name, xbt_dict_t props, surf_resource_t host_PM) - : VM(model, name, props, NULL, NULL) + : VirtualMachine(model, name, props, NULL, NULL) { Host *sub_ws = static_cast(surf_host_resource_priv(host_PM)); @@ -253,6 +245,7 @@ VMHL13::VMHL13(VMModel *model, const char* name, xbt_dict_t props, p_action = sub_cpu->execute(0); XBT_INFO("Create VM(%s)@PM(%s) with %ld mounted disks", name, sub_ws->getName(), xbt_dynar_length(p_storage)); + } /* diff --git a/src/surf/vm_hl13.hpp b/src/surf/vm_hl13.hpp index 311c0f8266..894d7429de 100644 --- a/src/surf/vm_hl13.hpp +++ b/src/surf/vm_hl13.hpp @@ -7,7 +7,7 @@ #include "xbt/base.h" #include "host_clm03.hpp" -#include "vm_interface.hpp" +#include "virtual_machine.hpp" #ifndef SURF_VM_HPP_ #define SURF_VM_HPP_ @@ -30,7 +30,7 @@ public: VMHL13Model(); ~VMHL13Model(){}; - VM *createVM(const char *name, surf_resource_t host_PM); + VirtualMachine *createVM(const char *name, surf_resource_t host_PM); double shareResources(double now); void adjustWeightOfDummyCpuActions() {}; Action *executeParallelTask(int host_nb, @@ -45,7 +45,7 @@ public: * Resource * ************/ -class VMHL13 : public VM { +class VMHL13 : public VirtualMachine { public: VMHL13(VMModel *model, const char* name, xbt_dict_t props, surf_resource_t host_PM); ~VMHL13(); diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index 4be343f1b1..360eb6c7aa 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -83,7 +83,7 @@ set(EXTRA_DIST src/surf/surfxml_parse.c src/surf/trace_mgr_private.h src/surf/vm_hl13.hpp - src/surf/vm_interface.hpp + src/surf/virtual_machine.hpp src/surf/host_clm03.hpp src/surf/host_interface.hpp src/surf/host_ptask_L07.hpp @@ -337,7 +337,7 @@ set(SURF_SRC src/surf/surfxml_parseplatf.c src/surf/trace_mgr.c src/surf/vm_hl13.cpp - src/surf/vm_interface.cpp + src/surf/virtual_machine.cpp src/surf/host_clm03.cpp src/surf/host_interface.cpp src/surf/host_ptask_L07.cpp -- 2.20.1