From 77db6c9bc8fa31f2915bbc77a1da62ce5e3c8da6 Mon Sep 17 00:00:00 2001 From: Bruno Donassolo Date: Thu, 4 Mar 2021 11:41:49 +0100 Subject: [PATCH 1/1] Get rid of surf_cpu_model_vm. - Add cpu_model_vm to NetZoneImpl. By now, it gets the global pointer in models_by_type if available - Separate CPU in CPU_PM and CPU_VM. - Move next_occurring_event call to CPU_VM models to surf_solve. One step closer to centralizing the models management --- include/simgrid/kernel/resource/Model.hpp | 3 ++- include/simgrid/kernel/routing/NetZoneImpl.hpp | 2 ++ src/include/surf/surf.hpp | 5 ----- src/kernel/routing/NetZoneImpl.cpp | 4 ++++ src/plugins/vm/VirtualMachineImpl.cpp | 13 ++++++------- src/plugins/vm/VirtualMachineImpl.hpp | 2 -- src/plugins/vm/s4u_VirtualMachine.cpp | 4 +++- src/surf/cpu_cas01.cpp | 6 +++--- src/surf/cpu_interface.cpp | 2 +- src/surf/cpu_ti.cpp | 6 +++--- src/surf/sg_platf.cpp | 2 ++ src/surf/surf_c_bindings.cpp | 3 ++- 12 files changed, 28 insertions(+), 24 deletions(-) diff --git a/include/simgrid/kernel/resource/Model.hpp b/include/simgrid/kernel/resource/Model.hpp index 48e1175688..fac93ac26b 100644 --- a/include/simgrid/kernel/resource/Model.hpp +++ b/include/simgrid/kernel/resource/Model.hpp @@ -24,7 +24,8 @@ public: enum class Type { HOST, /**< Host models: see surf_host_model_description for more details */ NETWORK, /**< Network models: see surf_network_model_description for more details */ - CPU, /**< CPU models: see surf_cpu_model_description for more details */ + CPU_PM, /**< CPU model for physical machines: see surf_cpu_model_description for more details */ + CPU_VM, /**< CPU model for virtual machines: see surf_cpu_model_description for more details */ DISK, /**< Disk models: see surf_disk_model_description for more details */ VM /**< VM model */ }; diff --git a/include/simgrid/kernel/routing/NetZoneImpl.hpp b/include/simgrid/kernel/routing/NetZoneImpl.hpp index 85cf2b507e..be084222b1 100644 --- a/include/simgrid/kernel/routing/NetZoneImpl.hpp +++ b/include/simgrid/kernel/routing/NetZoneImpl.hpp @@ -71,6 +71,7 @@ class XBT_PUBLIC NetZoneImpl : public xbt::PropertyHolder { std::map, BypassRoute*> bypass_routes_; // src x dst -> route routing::NetPoint* netpoint_ = nullptr; // Our representative in the father NetZone resource::NetworkModel* network_model_; + resource::CpuModel* cpu_model_vm_; protected: explicit NetZoneImpl(NetZoneImpl* father, const std::string& name, resource::NetworkModel* network_model); @@ -103,6 +104,7 @@ public: RoutingMode hierarchy_ = RoutingMode::unset; resource::NetworkModel* get_network_model() const { return network_model_; } + resource::CpuModel* get_cpu_vm_model() const { return cpu_model_vm_; } const s4u::NetZone* get_iface() const { return &piface_; } s4u::NetZone* get_iface() { return &piface_; } unsigned int get_table_size() const { return vertices_.size(); } diff --git a/src/include/surf/surf.hpp b/src/include/surf/surf.hpp index 772465ac43..6ac26dc075 100644 --- a/src/include/surf/surf.hpp +++ b/src/include/surf/surf.hpp @@ -13,11 +13,6 @@ */ XBT_PUBLIC_DATA simgrid::kernel::resource::CpuModel* surf_cpu_model_pm; -/** @ingroup SURF_models - * @brief The CPU model object for the virtual machine layer - */ -XBT_PUBLIC_DATA simgrid::kernel::resource::CpuModel* surf_cpu_model_vm; - /** @ingroup SURF_models * @brief The host model * diff --git a/src/kernel/routing/NetZoneImpl.cpp b/src/kernel/routing/NetZoneImpl.cpp index 70bcd205e1..618f26e07b 100644 --- a/src/kernel/routing/NetZoneImpl.cpp +++ b/src/kernel/routing/NetZoneImpl.cpp @@ -25,6 +25,10 @@ NetZoneImpl::NetZoneImpl(NetZoneImpl* father, const std::string& name, resource: "Refusing to create a second NetZone called '%s'.", get_cname()); netpoint_ = new NetPoint(name_, NetPoint::Type::NetZone, father_); + if (models_by_type[simgrid::kernel::resource::Model::Type::CPU_VM].size() > 0) { + cpu_model_vm_ = static_cast( + models_by_type[simgrid::kernel::resource::Model::Type::CPU_VM][0]); + } XBT_DEBUG("NetZone '%s' created with the id '%u'", get_cname(), netpoint_->id()); } diff --git a/src/plugins/vm/VirtualMachineImpl.cpp b/src/plugins/vm/VirtualMachineImpl.cpp index 4fde708eed..4c7d7b10da 100644 --- a/src/plugins/vm/VirtualMachineImpl.cpp +++ b/src/plugins/vm/VirtualMachineImpl.cpp @@ -11,12 +11,12 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(res_vm, ker_resource, "Virtual Machines, containing actors and mobile accross hosts"); -simgrid::vm::VMModel* surf_vm_model = nullptr; - void surf_vm_model_init_HL13() { - if (surf_cpu_model_vm != nullptr) - surf_vm_model = new simgrid::vm::VMModel(); + /* FIXME[donassolo]: this smells bad, but works + * (the constructor saves its pointer in all_existing_models and models_by_type :O). + * We need a manager for these models */ + new simgrid::vm::VMModel(); } namespace simgrid { @@ -149,13 +149,12 @@ double VMModel::next_occurring_event(double now) double solved_value = ws_vm->get_impl()->get_action()->get_variable()->get_value(); XBT_DEBUG("assign %f to vm %s @ pm %s", solved_value, ws_vm->get_cname(), ws_vm->get_pm()->get_cname()); - xbt_assert(cpu->get_model() == surf_cpu_model_vm); kernel::lmm::System* vcpu_system = cpu->get_model()->get_maxmin_system(); vcpu_system->update_constraint_bound(cpu->get_constraint(), virt_overhead * solved_value); } - /* 2. Ready. Get the next occurring event */ - return surf_cpu_model_vm->next_occurring_event(now); + /* actual next occurring event is determined by VM CPU model at surf_solve */ + return -1.0; } /************ diff --git a/src/plugins/vm/VirtualMachineImpl.hpp b/src/plugins/vm/VirtualMachineImpl.hpp index a6c8206de2..899922beee 100644 --- a/src/plugins/vm/VirtualMachineImpl.hpp +++ b/src/plugins/vm/VirtualMachineImpl.hpp @@ -103,6 +103,4 @@ public: } } -XBT_PUBLIC_DATA simgrid::vm::VMModel* surf_vm_model; - #endif /* VM_INTERFACE_HPP_ */ diff --git a/src/plugins/vm/s4u_VirtualMachine.cpp b/src/plugins/vm/s4u_VirtualMachine.cpp index c8046e073f..36470645ba 100644 --- a/src/plugins/vm/s4u_VirtualMachine.cpp +++ b/src/plugins/vm/s4u_VirtualMachine.cpp @@ -4,6 +4,7 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "simgrid/Exception.hpp" +#include "simgrid/kernel/routing/NetPoint.hpp" #include "simgrid/s4u/Actor.hpp" #include "simgrid/vm.h" #include "src/include/surf/surf.hpp" @@ -41,7 +42,8 @@ VirtualMachine::VirtualMachine(const std::string& name, s4u::Host* physical_host for (int i = 0; i < physical_host->get_pstate_count(); i++) speeds.push_back(physical_host->get_pstate_speed(i)); - surf_cpu_model_vm->create_cpu(this, speeds)->set_core_count(core_amount)->seal(); + // FIXME[donassolo]: shoud this be done at the Impl class??? + physical_host->get_netpoint()->get_englobing_zone()->get_cpu_vm_model()->create_cpu(this, speeds)->set_core_count(core_amount)->seal(); if (physical_host->get_pstate() != 0) set_pstate(physical_host->get_pstate()); diff --git a/src/surf/cpu_cas01.cpp b/src/surf/cpu_cas01.cpp index 7841e71b87..3c2ee5cbfa 100644 --- a/src/surf/cpu_cas01.cpp +++ b/src/surf/cpu_cas01.cpp @@ -37,7 +37,6 @@ static simgrid::config::Flag void surf_cpu_model_init_Cas01() { xbt_assert(surf_cpu_model_pm == nullptr, "CPU model already initialized. This should not happen."); - xbt_assert(surf_cpu_model_vm == nullptr, "CPU model already initialized. This should not happen."); if (cpu_optim_opt == "TI") { simgrid::kernel::resource::CpuTiModel::create_pm_vm_models(); @@ -51,7 +50,9 @@ void surf_cpu_model_init_Cas01() algo = simgrid::kernel::resource::Model::UpdateAlgo::FULL; surf_cpu_model_pm = new simgrid::kernel::resource::CpuCas01Model(algo); - surf_cpu_model_vm = new simgrid::kernel::resource::CpuCas01Model(algo); + models_by_type[simgrid::kernel::resource::Model::Type::CPU_PM].push_back(surf_cpu_model_pm); + auto cpu_model_vm = new simgrid::kernel::resource::CpuCas01Model(algo); + models_by_type[simgrid::kernel::resource::Model::Type::CPU_VM].push_back(cpu_model_vm); } namespace simgrid { @@ -61,7 +62,6 @@ namespace resource { CpuCas01Model::CpuCas01Model(Model::UpdateAlgo algo) : CpuModel(algo) { all_existing_models.push_back(this); - models_by_type[simgrid::kernel::resource::Model::Type::CPU].push_back(this); bool select = config::get_value("cpu/maxmin-selective-update"); diff --git a/src/surf/cpu_interface.cpp b/src/surf/cpu_interface.cpp index eafa003712..f114741c7e 100644 --- a/src/surf/cpu_interface.cpp +++ b/src/surf/cpu_interface.cpp @@ -12,7 +12,6 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(res_cpu, ker_resource, "CPU resource, fueling execution activites"); simgrid::kernel::resource::CpuModel* surf_cpu_model_pm; -simgrid::kernel::resource::CpuModel* surf_cpu_model_vm; namespace simgrid { namespace kernel { @@ -57,6 +56,7 @@ Cpu::Cpu(s4u::Host* host, const std::vector& speed_per_pstate) { speed_.scale = 1; speed_.peak = speed_per_pstate_.front(); + // FIXME[donassolo]: don't set here.. everytime I take half an hour to discover where it comes host->pimpl_cpu = this; } diff --git a/src/surf/cpu_ti.cpp b/src/surf/cpu_ti.cpp index 3dca750edf..ad330fadb1 100644 --- a/src/surf/cpu_ti.cpp +++ b/src/surf/cpu_ti.cpp @@ -270,16 +270,16 @@ int CpuTiProfile::binary_search(const std::vector& array, double a) void CpuTiModel::create_pm_vm_models() { xbt_assert(surf_cpu_model_pm == nullptr, "CPU model already initialized. This should not happen."); - xbt_assert(surf_cpu_model_vm == nullptr, "CPU model already initialized. This should not happen."); surf_cpu_model_pm = new CpuTiModel(); - surf_cpu_model_vm = new CpuTiModel(); + models_by_type[simgrid::kernel::resource::Model::Type::CPU_PM].push_back(surf_cpu_model_pm); + auto cpu_model_vm = new CpuTiModel(); + models_by_type[simgrid::kernel::resource::Model::Type::CPU_VM].push_back(cpu_model_vm); } CpuTiModel::CpuTiModel() : CpuModel(Model::UpdateAlgo::FULL) { all_existing_models.push_back(this); - models_by_type[simgrid::kernel::resource::Model::Type::CPU].push_back(this); } CpuTiModel::~CpuTiModel() diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 4d91bb48d5..9dbd579b5c 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -475,6 +475,8 @@ static void surf_config_models_setup() surf_host_model_description[host_id].model_init_preparse(); XBT_DEBUG("Call vm_model_init"); + // FIXME[donassolo]: maybe remove it, find a way to create the object and leave the + // dependency with surf_cpu_model_vm explicity surf_vm_model_init_HL13(); XBT_DEBUG("Call disk_model_init"); diff --git a/src/surf/surf_c_bindings.cpp b/src/surf/surf_c_bindings.cpp index 728cdd0b9e..a47a841aad 100644 --- a/src/surf/surf_c_bindings.cpp +++ b/src/surf/surf_c_bindings.cpp @@ -80,7 +80,7 @@ double surf_solve(double max_date) // following the order it was done in HostCLM03Model->next_occurring_event XBT_DEBUG("Looking for next event in CPU models"); - surf_update_next_event(models_by_type[simgrid::kernel::resource::Model::Type::CPU], time_delta); + surf_update_next_event(models_by_type[simgrid::kernel::resource::Model::Type::CPU_PM], time_delta); XBT_DEBUG("Looking for next event in network models"); surf_update_next_event(models_by_type[simgrid::kernel::resource::Model::Type::NETWORK], time_delta); XBT_DEBUG("Looking for next event in disk models"); @@ -88,6 +88,7 @@ double surf_solve(double max_date) XBT_DEBUG("Looking for next event in virtual models"); surf_update_next_event(models_by_type[simgrid::kernel::resource::Model::Type::VM], time_delta); + surf_update_next_event(models_by_type[simgrid::kernel::resource::Model::Type::CPU_VM], time_delta); XBT_DEBUG("Min for resources (remember that NS3 don't update that value): %f", time_delta); -- 2.20.1