Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
surf_disk_model: remove it.
authorBruno Donassolo <bruno.donassolo@inria.fr>
Thu, 4 Mar 2021 14:52:10 +0000 (15:52 +0100)
committerBruno Donassolo <bruno.donassolo@inria.fr>
Tue, 9 Mar 2021 14:17:12 +0000 (15:17 +0100)
- 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
src/kernel/resource/DiskImpl.cpp
src/kernel/resource/DiskImpl.hpp
src/kernel/routing/NetZoneImpl.cpp
src/s4u/s4u_Host.cpp
src/surf/disk_s19.cpp
src/surf/sg_platf.cpp

index c9b6ea9..eed458f 100644 (file)
@@ -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<double>& 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<double>& bandwidths,
                                  s4u::Link::SharingPolicy policy);
index 7522229..3388bdf 100644 (file)
@@ -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_))
index 8418916..c7bdd53 100644 (file)
@@ -20,8 +20,6 @@
  * Model *
  *********/
 
-XBT_PUBLIC_DATA simgrid::kernel::resource::DiskModel* surf_disk_model;
-
 namespace simgrid {
 namespace kernel {
 namespace resource {
index da9e717..b9046be 100644 (file)
@@ -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<simgrid::kernel::resource::CpuModel*>(
       models_by_type[simgrid::kernel::resource::Model::Type::CPU_PM][0]);
+  disk_model_ = static_cast<simgrid::kernel::resource::DiskModel*>(
+      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<double>& bandwidths,
                                     s4u::Link::SharingPolicy policy)
 {
index 8350971..b9e8c8b 100644 (file)
@@ -275,7 +275,9 @@ std::vector<Disk*> 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)
index 0b12cab..c1e4bde 100644 (file)
@@ -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 {
index 9dbd579..6d9188d 100644 (file)
@@ -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);