From 5e00312bf86c3868d644b7806cdba0abf23664a4 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Fri, 21 Oct 2016 18:44:10 +0200 Subject: [PATCH] rename surf::VirtualMachine to surf::VirtualMachineImpl This makes room for a s4u::VirtualMachine class that should arrive soon. --- src/simix/libsmx.cpp | 11 ++- src/simix/smx_host.cpp | 12 ++-- src/simix/smx_vm.cpp | 10 +-- src/surf/HostImpl.cpp | 8 +-- ...ual_machine.cpp => VirtualMachineImpl.cpp} | 67 ++++++++++--------- ...ual_machine.hpp => VirtualMachineImpl.hpp} | 31 +++++---- src/surf/host_clm03.cpp | 2 +- src/surf/plugins/energy.cpp | 13 ++-- src/surf/surf_c_bindings.cpp | 13 ++-- src/surf/surf_interface.cpp | 18 ++--- tools/cmake/DefinePackages.cmake | 4 +- 11 files changed, 94 insertions(+), 95 deletions(-) rename src/surf/{virtual_machine.cpp => VirtualMachineImpl.cpp} (80%) rename src/surf/{virtual_machine.hpp => VirtualMachineImpl.hpp} (84%) diff --git a/src/simix/libsmx.cpp b/src/simix/libsmx.cpp index 2fa37b7215..4c4bf39c65 100644 --- a/src/simix/libsmx.cpp +++ b/src/simix/libsmx.cpp @@ -19,15 +19,14 @@ #include -#include "src/mc/mc_replay.h" +#include "mc/mc.h" #include "smx_private.h" +#include "src/kernel/activity/SynchroComm.hpp" #include "src/mc/mc_forward.hpp" -#include "xbt/ex.h" -#include "mc/mc.h" +#include "src/mc/mc_replay.h" #include "src/simix/smx_host_private.h" -#include "src/kernel/activity/SynchroComm.hpp" -#include "src/surf/virtual_machine.hpp" - +#include "src/surf/VirtualMachineImpl.hpp" +#include "xbt/ex.h" #include diff --git a/src/simix/smx_host.cpp b/src/simix/smx_host.cpp index 0f0878ad24..9147633f9f 100644 --- a/src/simix/smx_host.cpp +++ b/src/simix/smx_host.cpp @@ -4,13 +4,13 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include "smx_private.h" -#include -#include "xbt/sysdep.h" #include "mc/mc.h" +#include "smx_private.h" #include "src/mc/mc_replay.h" -#include "src/surf/virtual_machine.hpp" #include "src/surf/HostImpl.hpp" +#include "src/surf/VirtualMachineImpl.hpp" +#include "xbt/sysdep.h" +#include #include "src/kernel/activity/SynchroExec.hpp" #include "src/kernel/activity/SynchroComm.hpp" @@ -203,9 +203,9 @@ smx_activity_t SIMIX_execution_parallel_start(const char *name, int host_nb, sg_ host_list_cpy[i] = host_list[i]; /* Check that we are not mixing VMs and PMs in the parallel task */ - bool is_a_vm = (nullptr != dynamic_cast(host_list[0]->pimpl_)); + bool is_a_vm = (nullptr != dynamic_cast(host_list[0]->pimpl_)); for (int i = 1; i < host_nb; i++) { - bool tmp_is_a_vm = (nullptr != dynamic_cast(host_list[i]->pimpl_)); + bool tmp_is_a_vm = (nullptr != dynamic_cast(host_list[i]->pimpl_)); xbt_assert(is_a_vm == tmp_is_a_vm, "parallel_execute: mixing VMs and PMs is not supported (yet)."); } diff --git a/src/simix/smx_vm.cpp b/src/simix/smx_vm.cpp index 1203a519a5..002be82015 100644 --- a/src/simix/smx_vm.cpp +++ b/src/simix/smx_vm.cpp @@ -3,10 +3,10 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include "smx_private.h" #include "mc/mc.h" -#include "src/surf/virtual_machine.hpp" +#include "smx_private.h" #include "src/surf/HostImpl.hpp" +#include "src/surf/VirtualMachineImpl.hpp" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_vm, simix, "Logging specific to SIMIX Virtual Machines"); @@ -66,7 +66,7 @@ static int __can_be_started(sg_host_t vm) void SIMIX_vm_start(sg_host_t vm) { if (__can_be_started(vm)) - static_cast(vm->pimpl_)->setState(SURF_VM_STATE_RUNNING); + static_cast(vm->pimpl_)->setState(SURF_VM_STATE_RUNNING); else THROWF(vm_error, 0, "The VM %s cannot be started", vm->name().c_str()); } @@ -74,7 +74,7 @@ void SIMIX_vm_start(sg_host_t vm) e_surf_vm_state_t SIMIX_vm_get_state(sg_host_t vm) { - return static_cast(vm->pimpl_)->getState(); + return static_cast(vm->pimpl_)->getState(); } /** @@ -284,7 +284,7 @@ void SIMIX_vm_shutdown(sg_host_t vm, smx_actor_t issuer) } /* FIXME: we may have to do something at the surf layer, e.g., vcpu action */ - static_cast(vm->pimpl_)->setState(SURF_VM_STATE_CREATED); + static_cast(vm->pimpl_)->setState(SURF_VM_STATE_CREATED); } void simcall_HANDLER_vm_shutdown(smx_simcall_t simcall, sg_host_t vm) diff --git a/src/surf/HostImpl.cpp b/src/surf/HostImpl.cpp index b05ca954c3..3fd06eb932 100644 --- a/src/surf/HostImpl.cpp +++ b/src/surf/HostImpl.cpp @@ -10,8 +10,8 @@ #include "src/surf/HostImpl.hpp" #include "simgrid/sg_config.h" +#include "VirtualMachineImpl.hpp" #include "network_interface.hpp" -#include "virtual_machine.hpp" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_host, surf, "Logging specific to the SURF host module"); @@ -35,7 +35,7 @@ namespace surf { void HostModel::adjustWeightOfDummyCpuActions() { /* iterate for all virtual machines */ - for (VirtualMachine *ws_vm : VirtualMachine::allVms_) { + for (VirtualMachineImpl* ws_vm : VirtualMachineImpl::allVms_) { Cpu* cpu = ws_vm->piface_->pimpl_cpu; @@ -319,9 +319,9 @@ int HostImpl::fileMove(surf_file_t fd, const char* fullpath){ xbt_dynar_t HostImpl::getVms() { - xbt_dynar_t dyn = xbt_dynar_new(sizeof(simgrid::surf::VirtualMachine*), nullptr); + xbt_dynar_t dyn = xbt_dynar_new(sizeof(simgrid::surf::VirtualMachineImpl*), nullptr); - for (VirtualMachine *ws_vm : VirtualMachine::allVms_) { + for (VirtualMachineImpl* ws_vm : VirtualMachineImpl::allVms_) { if (this == ws_vm->getPm()->pimpl_) xbt_dynar_push(dyn, &ws_vm); } diff --git a/src/surf/virtual_machine.cpp b/src/surf/VirtualMachineImpl.cpp similarity index 80% rename from src/surf/virtual_machine.cpp rename to src/surf/VirtualMachineImpl.cpp index 3c5d9a03c3..624465e452 100644 --- a/src/surf/virtual_machine.cpp +++ b/src/surf/VirtualMachineImpl.cpp @@ -4,16 +4,18 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ +#include "VirtualMachineImpl.hpp" + #include #include "cpu_cas01.hpp" -#include "virtual_machine.hpp" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_vm, surf, "Logging specific to the SURF VM module"); -simgrid::surf::VMModel *surf_vm_model = nullptr; +simgrid::surf::VMModel* surf_vm_model = nullptr; -void surf_vm_model_init_HL13(){ +void surf_vm_model_init_HL13() +{ if (surf_cpu_model_vm) { surf_vm_model = new simgrid::surf::VMModel(); all_existing_models->push_back(surf_vm_model); @@ -23,24 +25,23 @@ void surf_vm_model_init_HL13(){ namespace simgrid { namespace surf { - /************* * 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 * *********/ -std::deque VirtualMachine::allVms_; +std::deque VirtualMachineImpl::allVms_; -s4u::Host *VMModel::createVM(const char *name, sg_host_t host_PM) +s4u::Host* VMModel::createVM(const char* name, sg_host_t host_PM) { - VirtualMachine* vm = new VirtualMachine(name, host_PM); + VirtualMachineImpl* vm = new VirtualMachineImpl(name, host_PM); return vm->piface_; } @@ -76,7 +77,7 @@ double VMModel::nextOccuringEvent(double now) **/ /* iterate for all virtual machines */ - for (VirtualMachine *ws_vm : VirtualMachine::allVms_) { + for (VirtualMachineImpl* ws_vm : VirtualMachineImpl::allVms_) { Cpu* cpu = ws_vm->piface_->pimpl_cpu; xbt_assert(cpu, "cpu-less host"); @@ -98,12 +99,11 @@ double VMModel::nextOccuringEvent(double now) return surf_cpu_model_vm->nextOccuringEvent(now); } - /************ * Resource * ************/ -VirtualMachine::VirtualMachine(const char* name, simgrid::s4u::Host* host_PM) +VirtualMachineImpl::VirtualMachineImpl(const char* name, simgrid::s4u::Host* host_PM) : HostImpl(new simgrid::s4u::Host(name), nullptr /*storage*/), hostPM_(host_PM) { /* Register this VM to the list of all VMs */ @@ -119,7 +119,7 @@ VirtualMachine::VirtualMachine(const char* name, simgrid::s4u::Host* host_PM) // //// 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); + CpuCas01* sub_cpu = dynamic_cast(host_PM->pimpl_cpu); piface_->pimpl_cpu = surf_cpu_model_vm->createCpu(piface_, sub_cpu->getSpeedPeakList(), 1 /*cores*/); if (sub_cpu->getPState() != 0) @@ -135,44 +135,45 @@ VirtualMachine::VirtualMachine(const char* name, simgrid::s4u::Host* host_PM) /* * A physical host does not disappear in the current SimGrid code, but a VM may disappear during a simulation. */ -VirtualMachine::~VirtualMachine() +VirtualMachineImpl::~VirtualMachineImpl() { onVmDestruction(this); - allVms_.erase( find(allVms_.begin(), allVms_.end(), this) ); + allVms_.erase(find(allVms_.begin(), allVms_.end(), this)); /* Free the cpu_action of the VM. */ XBT_ATTRIB_UNUSED int ret = action_->unref(); xbt_assert(ret == 1, "Bug: some resource still remains"); } -e_surf_vm_state_t VirtualMachine::getState() { +e_surf_vm_state_t VirtualMachineImpl::getState() +{ return vmState_; } -void VirtualMachine::setState(e_surf_vm_state_t state) +void VirtualMachineImpl::setState(e_surf_vm_state_t state) { vmState_ = state; } -void VirtualMachine::suspend() +void VirtualMachineImpl::suspend() { action_->suspend(); vmState_ = SURF_VM_STATE_SUSPENDED; } -void VirtualMachine::resume() +void VirtualMachineImpl::resume() { action_->resume(); vmState_ = SURF_VM_STATE_RUNNING; } -void VirtualMachine::save() +void VirtualMachineImpl::save() { vmState_ = SURF_VM_STATE_SAVING; action_->suspend(); vmState_ = SURF_VM_STATE_SAVED; } -void VirtualMachine::restore() +void VirtualMachineImpl::restore() { vmState_ = SURF_VM_STATE_RESTORING; action_->resume(); @@ -180,12 +181,13 @@ void VirtualMachine::restore() } /** @brief returns the physical machine on which the VM is running **/ -sg_host_t VirtualMachine::getPm() { +sg_host_t VirtualMachineImpl::getPm() +{ return hostPM_; } /* Update the physical host of the given VM */ -void VirtualMachine::migrate(sg_host_t host_dest) +void VirtualMachineImpl::migrate(sg_host_t host_dest) { const char* vm_name = piface_->name().c_str(); const char* pm_name_src = hostPM_->name().c_str(); @@ -211,20 +213,19 @@ void VirtualMachine::migrate(sg_host_t host_dest) 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(); - xbt_assert(ret == 1, "Bug: some resource still remains"); + XBT_ATTRIB_UNUSED int ret = action_->unref(); + xbt_assert(ret == 1, "Bug: some resource still remains"); - action_ = new_cpu_action; + action_ = new_cpu_action; - XBT_DEBUG("migrate VM(%s): change PM (%s to %s)", vm_name, pm_name_src, pm_name_dst); + XBT_DEBUG("migrate VM(%s): change PM (%s to %s)", vm_name, pm_name_src, pm_name_dst); } -void VirtualMachine::setBound(double bound){ - action_->setBound(bound); +void VirtualMachineImpl::setBound(double bound) +{ + action_->setBound(bound); } - - } } diff --git a/src/surf/virtual_machine.hpp b/src/surf/VirtualMachineImpl.hpp similarity index 84% rename from src/surf/virtual_machine.hpp rename to src/surf/VirtualMachineImpl.hpp index c3991ba86d..aa216e7706 100644 --- a/src/surf/virtual_machine.hpp +++ b/src/surf/VirtualMachineImpl.hpp @@ -4,8 +4,8 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include #include +#include #include @@ -25,7 +25,7 @@ namespace surf { ***********/ class XBT_PRIVATE VMModel; -class XBT_PRIVATE VirtualMachine; +class XBT_PRIVATE VirtualMachineImpl; /************* * Callbacks * @@ -34,17 +34,17 @@ class XBT_PRIVATE VirtualMachine; /** @ingroup SURF_callbacks * @brief Callbacks fired after VM creation. Signature: `void(VirtualMachine*)` */ -extern XBT_PRIVATE simgrid::xbt::signal onVmCreation; +extern XBT_PRIVATE simgrid::xbt::signal onVmCreation; /** @ingroup SURF_callbacks * @brief Callbacks fired after VM destruction. Signature: `void(VirtualMachine*)` */ -extern XBT_PRIVATE simgrid::xbt::signal onVmDestruction; +extern XBT_PRIVATE simgrid::xbt::signal onVmDestruction; /** @ingroup SURF_callbacks * @brief Callbacks after VM State changes. Signature: `void(VirtualMachine*)` */ -extern XBT_PRIVATE simgrid::xbt::signal onVmStateChange; +extern XBT_PRIVATE simgrid::xbt::signal onVmStateChange; /************ * Resource * @@ -54,10 +54,10 @@ extern XBT_PRIVATE simgrid::xbt::signal on * @brief SURF VM interface class * @details A VM represent a virtual machine */ -class VirtualMachine : public HostImpl { +class VirtualMachineImpl : public HostImpl { public: - VirtualMachine(const char* name, simgrid::s4u::Host* host); - ~VirtualMachine(); + VirtualMachineImpl(const char* name, simgrid::s4u::Host* host); + ~VirtualMachineImpl(); /** @brief Suspend the VM */ virtual void suspend(); @@ -80,14 +80,15 @@ public: virtual void setBound(double bound); /* The vm object of the lower layer */ - CpuAction *action_ = nullptr; + CpuAction* action_ = nullptr; + protected: - simgrid::s4u::Host *hostPM_; + simgrid::s4u::Host* hostPM_; public: e_surf_vm_state_t getState(); void setState(e_surf_vm_state_t state); - static std::deque allVms_; + static std::deque allVms_; protected: e_surf_vm_state_t vmState_ = SURF_VM_STATE_CREATED; @@ -108,14 +109,12 @@ public: * @param name The name of the new VM * @param host_PM The real machine hosting the VM */ - s4u::Host *createVM(const char *name, sg_host_t host_PM); - void adjustWeightOfDummyCpuActions() override {}; + s4u::Host* createVM(const char* name, sg_host_t host_PM); + void adjustWeightOfDummyCpuActions() override{}; double nextOccuringEvent(double now) override; - void updateActionsState(double /*now*/, double /*delta*/) override {}; - + void updateActionsState(double /*now*/, double /*delta*/) override{}; }; - } } diff --git a/src/surf/host_clm03.cpp b/src/surf/host_clm03.cpp index 72e4bd4377..a60b0bf526 100644 --- a/src/surf/host_clm03.cpp +++ b/src/surf/host_clm03.cpp @@ -10,9 +10,9 @@ #include "host_clm03.hpp" +#include "VirtualMachineImpl.hpp" #include "cpu_cas01.hpp" #include "simgrid/sg_config.h" -#include "virtual_machine.hpp" XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_host); diff --git a/src/surf/plugins/energy.cpp b/src/surf/plugins/energy.cpp index 9474751829..b76c9132a2 100644 --- a/src/surf/plugins/energy.cpp +++ b/src/surf/plugins/energy.cpp @@ -5,10 +5,9 @@ #include "simgrid/plugins/energy.h" #include "simgrid/simix.hpp" -#include "src/surf/plugins/energy.hpp" +#include "src/surf/VirtualMachineImpl.hpp" #include "src/surf/cpu_interface.hpp" -#include "src/surf/virtual_machine.hpp" - +#include "src/surf/plugins/energy.hpp" #include /** @addtogroup SURF_plugin_energy @@ -234,7 +233,7 @@ void HostEnergy::initWattsRangeList() /* **************************** events callback *************************** */ static void onCreation(simgrid::s4u::Host& host) { - if (dynamic_cast(host.pimpl_)) // Ignore virtual machines + if (dynamic_cast(host.pimpl_)) // Ignore virtual machines return; host.extension_set(new HostEnergy(&host)); } @@ -246,7 +245,7 @@ static void onActionStateChange(simgrid::surf::CpuAction *action, simgrid::surf: if(sghost == nullptr) continue; simgrid::surf::HostImpl* host = sghost->pimpl_; - simgrid::surf::VirtualMachine *vm = dynamic_cast(host); + simgrid::surf::VirtualMachineImpl* vm = dynamic_cast(host); if (vm) // If it's a VM, take the corresponding PM host = vm->getPm()->pimpl_; @@ -258,7 +257,7 @@ static void onActionStateChange(simgrid::surf::CpuAction *action, simgrid::surf: } static void onHostStateChange(simgrid::s4u::Host &host) { - if (dynamic_cast(host.pimpl_)) // Ignore virtual machines + if (dynamic_cast(host.pimpl_)) // Ignore virtual machines return; HostEnergy *host_energy = host.extension(); @@ -269,7 +268,7 @@ static void onHostStateChange(simgrid::s4u::Host &host) { static void onHostDestruction(simgrid::s4u::Host& host) { // Ignore virtual machines - if (dynamic_cast(host.pimpl_)) + if (dynamic_cast(host.pimpl_)) return; HostEnergy *host_energy = host.extension(); host_energy->update(); diff --git a/src/surf/surf_c_bindings.cpp b/src/surf/surf_c_bindings.cpp index c599164461..61257795ff 100644 --- a/src/surf/surf_c_bindings.cpp +++ b/src/surf/surf_c_bindings.cpp @@ -4,12 +4,12 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include "src/surf/HostImpl.hpp" -#include "surf_interface.hpp" +#include "VirtualMachineImpl.hpp" #include "network_interface.hpp" -#include "src/instr/instr_private.h" #include "plugins/energy.hpp" -#include "virtual_machine.hpp" +#include "src/instr/instr_private.h" +#include "src/surf/HostImpl.hpp" +#include "surf_interface.hpp" XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_kernel); @@ -21,8 +21,9 @@ static simgrid::surf::HostImpl *get_casted_host(sg_host_t host){ //FIXME: killme return host->pimpl_; } -static simgrid::surf::VirtualMachine *get_casted_vm(sg_host_t host){ - return static_cast(host->pimpl_); +static simgrid::surf::VirtualMachineImpl* get_casted_vm(sg_host_t host) +{ + return static_cast(host->pimpl_); } extern double NOW; diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index f90440d4c6..76d1f3ef51 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -4,19 +4,19 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include "src/internal_config.h" -#include "surf_private.h" #include "surf_interface.hpp" -#include "network_interface.hpp" +#include "VirtualMachineImpl.hpp" #include "cpu_interface.hpp" -#include "src/surf/HostImpl.hpp" -#include "src/simix/smx_host_private.h" -#include "surf_routing.hpp" -#include "simgrid/sg_config.h" #include "mc/mc.h" -#include "virtual_machine.hpp" -#include "src/instr/instr_private.h" // TRACE_is_enabled(). FIXME: remove by subscribing tracing to the surf signals +#include "network_interface.hpp" #include "simgrid/s4u/engine.hpp" +#include "simgrid/sg_config.h" +#include "src/instr/instr_private.h" // TRACE_is_enabled(). FIXME: remove by subscribing tracing to the surf signals +#include "src/internal_config.h" +#include "src/simix/smx_host_private.h" +#include "src/surf/HostImpl.hpp" +#include "surf_private.h" +#include "surf_routing.hpp" #include XBT_LOG_NEW_CATEGORY(surf, "All SURF categories"); diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index 6e5357ec44..73b3005dbb 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -81,7 +81,7 @@ set(EXTRA_DIST src/surf/surf_private.h src/surf/surf_routing.hpp src/surf/PropertyHolder.hpp - src/surf/virtual_machine.hpp + src/surf/VirtualMachineImpl.hpp src/surf/host_clm03.hpp src/surf/HostImpl.hpp src/surf/ptask_L07.hpp @@ -332,7 +332,7 @@ set(SURF_SRC src/surf/xml/surfxml_parseplatf.cpp src/surf/trace_mgr.hpp src/surf/trace_mgr.cpp - src/surf/virtual_machine.cpp + src/surf/VirtualMachineImpl.cpp src/surf/host_clm03.cpp src/surf/HostImpl.cpp src/surf/ptask_L07.cpp -- 2.30.2