From 73e319cfebc9c33fe3305f68b06eb594ff42f9ed Mon Sep 17 00:00:00 2001 From: Bruno Donassolo Date: Thu, 4 Mar 2021 15:52:10 +0100 Subject: [PATCH] surf_disk_model: remove it. - Add disk_model to NetZone as done for network and cpu models - Add create_disk method in NetZone too: keep interface uniform --- include/simgrid/kernel/routing/NetZoneImpl.hpp | 5 +++++ src/kernel/resource/DiskImpl.cpp | 4 +--- src/kernel/resource/DiskImpl.hpp | 2 -- src/kernel/routing/NetZoneImpl.cpp | 10 ++++++++++ src/s4u/s4u_Host.cpp | 4 +++- src/surf/disk_s19.cpp | 5 ++++- src/surf/sg_platf.cpp | 3 ++- 7 files changed, 25 insertions(+), 8 deletions(-) diff --git a/include/simgrid/kernel/routing/NetZoneImpl.hpp b/include/simgrid/kernel/routing/NetZoneImpl.hpp index c9b6ea92fb..eed458f362 100644 --- a/include/simgrid/kernel/routing/NetZoneImpl.hpp +++ b/include/simgrid/kernel/routing/NetZoneImpl.hpp @@ -73,6 +73,7 @@ class XBT_PUBLIC NetZoneImpl : public xbt::PropertyHolder { resource::NetworkModel* network_model_; resource::CpuModel* cpu_model_vm_; resource::CpuModel* cpu_model_pm_; + resource::DiskModel* disk_model_; protected: explicit NetZoneImpl(NetZoneImpl* father, const std::string& name, resource::NetworkModel* network_model); @@ -110,6 +111,8 @@ public: resource::CpuModel* get_cpu_vm_model() const { return cpu_model_vm_; } /** @brief Retrieves the CPU model for physical machines associated to this NetZone */ resource::CpuModel* get_cpu_pm_model() const { return cpu_model_pm_; } + /** @brief Retrieves the disk model associated to this NetZone */ + resource::DiskModel* get_disk_model() const { return disk_model_; } const s4u::NetZone* get_iface() const { return &piface_; } s4u::NetZone* get_iface() { return &piface_; } @@ -129,6 +132,8 @@ public: /** @brief Make a host within that NetZone */ s4u::Host* create_host(const std::string& name, const std::vector& speed_per_pstate, int core_amount); + /** @brief Create a disk with the disk model from this NetZone */ + s4u::Disk* create_disk(const std::string& name, double read_bandwidth, double write_bandwidth); /** @brief Make a link within that NetZone */ virtual s4u::Link* create_link(const std::string& name, const std::vector& bandwidths, s4u::Link::SharingPolicy policy); diff --git a/src/kernel/resource/DiskImpl.cpp b/src/kernel/resource/DiskImpl.cpp index 75222290da..3388bdf60b 100644 --- a/src/kernel/resource/DiskImpl.cpp +++ b/src/kernel/resource/DiskImpl.cpp @@ -11,8 +11,6 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(res_disk, ker_resource, "Disk resources, fuelling I/O activities"); -simgrid::kernel::resource::DiskModel* surf_disk_model = nullptr; - namespace simgrid { namespace kernel { namespace resource { @@ -28,7 +26,6 @@ DiskModel::DiskModel() : Model(Model::UpdateAlgo::FULL) DiskModel::~DiskModel() { - surf_disk_model = nullptr; } /************ @@ -101,6 +98,7 @@ void DiskImpl::turn_off() void DiskImpl::seal() { + xbt_assert(this->get_model(), "Cannot seal Disk (%s) without setting the model first", this->get_cname()); lmm::System* maxmin_system = get_model()->get_maxmin_system(); this->set_read_constraint(maxmin_system->constraint_new(this, read_bw_)) ->set_write_constraint(maxmin_system->constraint_new(this, write_bw_)) diff --git a/src/kernel/resource/DiskImpl.hpp b/src/kernel/resource/DiskImpl.hpp index 8418916143..c7bdd533b5 100644 --- a/src/kernel/resource/DiskImpl.hpp +++ b/src/kernel/resource/DiskImpl.hpp @@ -20,8 +20,6 @@ * Model * *********/ -XBT_PUBLIC_DATA simgrid::kernel::resource::DiskModel* surf_disk_model; - namespace simgrid { namespace kernel { namespace resource { diff --git a/src/kernel/routing/NetZoneImpl.cpp b/src/kernel/routing/NetZoneImpl.cpp index da9e717214..b9046bef9b 100644 --- a/src/kernel/routing/NetZoneImpl.cpp +++ b/src/kernel/routing/NetZoneImpl.cpp @@ -7,6 +7,7 @@ #include "simgrid/kernel/routing/NetPoint.hpp" #include "simgrid/s4u/Engine.hpp" #include "simgrid/s4u/Host.hpp" +#include "src/kernel/resource/DiskImpl.hpp" #include "src/surf/cpu_interface.hpp" #include "src/surf/network_interface.hpp" #include "src/surf/xml/platf_private.hpp" @@ -31,6 +32,8 @@ NetZoneImpl::NetZoneImpl(NetZoneImpl* father, const std::string& name, resource: } cpu_model_pm_ = static_cast( models_by_type[simgrid::kernel::resource::Model::Type::CPU_PM][0]); + disk_model_ = static_cast( + models_by_type[simgrid::kernel::resource::Model::Type::DISK][0]); XBT_DEBUG("NetZone '%s' created with the id '%u'", get_cname(), netpoint_->id()); } @@ -71,6 +74,13 @@ int NetZoneImpl::get_host_count() const return count; } +s4u::Disk* NetZoneImpl::create_disk(const std::string& name, double read_bandwidth, double write_bandwidth) +{ + auto* l = disk_model_->create_disk(name, read_bandwidth, write_bandwidth); + + return l->get_iface(); +} + s4u::Link* NetZoneImpl::create_link(const std::string& name, const std::vector& bandwidths, s4u::Link::SharingPolicy policy) { diff --git a/src/s4u/s4u_Host.cpp b/src/s4u/s4u_Host.cpp index 8350971740..b9e8c8b506 100644 --- a/src/s4u/s4u_Host.cpp +++ b/src/s4u/s4u_Host.cpp @@ -275,7 +275,9 @@ std::vector Host::get_disks() const Disk* Host::create_disk(const std::string& name, double read_bandwidth, double write_bandwidth) { - return surf_disk_model->create_disk(name, read_bandwidth, write_bandwidth)->set_host(this)->get_iface(); + auto disk = + this->get_netpoint()->get_englobing_zone()->get_disk_model()->create_disk(name, read_bandwidth, write_bandwidth); + return disk->set_host(this)->get_iface(); } void Host::add_disk(const Disk* disk) diff --git a/src/surf/disk_s19.cpp b/src/surf/disk_s19.cpp index 0b12cab6e1..c1e4bde901 100644 --- a/src/surf/disk_s19.cpp +++ b/src/surf/disk_s19.cpp @@ -19,7 +19,10 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(res_disk); void surf_disk_model_init_default() { - surf_disk_model = new simgrid::kernel::resource::DiskS19Model(); + /* 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::kernel::resource::DiskS19Model(); } namespace simgrid { diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 9dbd579b5c..6d9188d630 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -331,7 +331,8 @@ void sg_platf_new_cabinet(const simgrid::kernel::routing::CabinetCreationArgs* c simgrid::kernel::resource::DiskImpl* sg_platf_new_disk(const simgrid::kernel::routing::DiskCreationArgs* disk) { - simgrid::kernel::resource::DiskImpl* pimpl = surf_disk_model->create_disk(disk->id, disk->read_bw, disk->write_bw); + simgrid::kernel::resource::DiskImpl* pimpl = + routing_get_current()->create_disk(disk->id, disk->read_bw, disk->write_bw)->get_impl(); if (disk->properties) { pimpl->set_properties(*disk->properties); -- 2.20.1