Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
allow for programmatic creation of a disk
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Fri, 26 Feb 2021 14:59:58 +0000 (15:59 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Fri, 26 Feb 2021 15:00:28 +0000 (16:00 +0100)
include/simgrid/s4u/Disk.hpp
src/kernel/resource/DiskImpl.cpp
src/kernel/resource/DiskImpl.hpp
src/s4u/s4u_Disk.cpp
src/s4u/s4u_Host.cpp
src/surf/sg_platf.cpp

index f0542c7..93a8e3b 100644 (file)
@@ -68,6 +68,7 @@ public:
   const std::unordered_map<std::string, std::string>* get_properties() const;
   const char* get_property(const std::string& key) const;
   void set_property(const std::string&, const std::string& value);
+  Disk* set_host(Host* host);
   Host* get_host() const;
 
   IoPtr io_init(sg_size_t size, s4u::Io::OpType type);
@@ -77,6 +78,8 @@ public:
 
   IoPtr write_async(sg_size_t size);
   sg_size_t write(sg_size_t size);
+  void seal();
+
 #ifndef DOXYGEN
   kernel::resource::DiskImpl* get_impl() const { return pimpl_; }
 #endif
index 8907216..c0cfd58 100644 (file)
@@ -94,6 +94,16 @@ void DiskImpl::turn_off()
   }
 }
 
+void DiskImpl::seal()
+{
+  lmm::System* maxmin_system = surf_disk_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_))
+          ->set_model(surf_disk_model)
+          ->set_constraint(maxmin_system->constraint_new(this, std::max(read_bw_, write_bw_)));
+  XBT_DEBUG("Create resource with read_bw '%f' write_bw '%f'", read_bw_, write_bw_);
+  turn_on();
+}
 xbt::signal<void(DiskAction const&, Action::State, Action::State)> DiskAction::on_state_change;
 
 /**********
index ce9563d..b130a96 100644 (file)
@@ -87,6 +87,7 @@ public:
   void turn_on() override;
   void turn_off() override;
 
+  void seal();
   void destroy(); // Must be called instead of the destructor
   virtual DiskAction* io_start(sg_size_t size, s4u::Io::OpType type) = 0;
   virtual DiskAction* read(sg_size_t size)                           = 0;
index 937e537..e955497 100644 (file)
@@ -48,6 +48,12 @@ double Disk::get_write_bandwidth() const
   return pimpl_->get_write_bandwidth();
 }
 
+Disk* Disk::set_host(Host* host)
+{
+  pimpl_->set_host(host);
+  return this;
+}
+
 Host* Disk::get_host() const
 {
   return pimpl_->get_host();
@@ -93,6 +99,12 @@ sg_size_t Disk::write(sg_size_t size)
   return IoPtr(io_init(size, Io::OpType::WRITE))->vetoable_start()->wait()->get_performed_ioops();
 }
 
+void Disk::seal()
+{
+  kernel::actor::simcall([this]{ pimpl_->seal(); });
+  get_host()->add_disk(this);
+  Disk::on_creation(*this);
+}
 } // namespace s4u
 } // namespace simgrid
 
index b9da40c..83b0a00 100644 (file)
@@ -270,6 +270,7 @@ std::vector<Disk*> Host::get_disks() const
 Disk* Host::create_disk()
 {
   auto pimpl = surf_disk_model->create_disk();
+  pimpl->set_host(this);
   return pimpl->get_iface();
 }
 
index 0d046fb..7781238 100644 (file)
@@ -324,7 +324,6 @@ 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::lmm::System* maxmin_system = surf_disk_model->get_maxmin_system();
   simgrid::kernel::resource::DiskImpl* pimpl = surf_disk_model->create_disk();
 
   // This should be done using s4u::Disk methods and passed to the pimpl
@@ -335,18 +334,10 @@ simgrid::kernel::resource::DiskImpl* sg_platf_new_disk(const simgrid::kernel::ro
     pimpl->set_properties(*disk->properties);
     delete disk->properties;
   }
+  pimpl->get_iface()->set_name(disk->id);
 
   // This should be done in the seal() of a Disk creation
-  pimpl->set_read_constraint(maxmin_system->constraint_new(pimpl,disk->read_bw))
-      ->set_write_constraint(maxmin_system->constraint_new(pimpl, disk->write_bw))
-      ->set_model(surf_disk_model)
-      ->set_constraint(maxmin_system->constraint_new(pimpl, std::max(disk->read_bw, disk->write_bw)));
-
-  XBT_DEBUG("Create resource with read_bw '%f' write_bw '%f'", disk->read_bw, disk->write_bw);
-  pimpl->turn_on();
-
-  // Temporary hack
-  pimpl->get_iface()->set_name(disk->id);
+  pimpl->seal();
   simgrid::s4u::Disk::on_creation(*pimpl->get_iface());
   return pimpl;
 }