Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
see what can be done with method chaining in disk creation
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 25 Feb 2021 09:38:07 +0000 (10:38 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 25 Feb 2021 09:38:07 +0000 (10:38 +0100)
src/kernel/resource/DiskImpl.cpp
src/kernel/resource/DiskImpl.hpp
src/surf/disk_s19.cpp
src/surf/disk_s19.hpp
src/surf/sg_platf.cpp

index e765fed..8907216 100644 (file)
@@ -35,17 +35,28 @@ DiskModel::~DiskModel()
  * Resource *
  ************/
 
-DiskImpl::DiskImpl(kernel::resource::Model* model, const std::string& name, kernel::lmm::System* maxminSystem,
-                   double read_bw, double write_bw)
-    : piface_(name, this)
-    , read_bw_(read_bw)
-    , write_bw_(write_bw)
+DiskImpl* DiskImpl::set_read_bandwidth(double read_bw)
 {
-  this->set_name(name)->set_model(model)->set_constraint(maxminSystem->constraint_new(this, std::max(read_bw, write_bw)));
-  DiskImpl::turn_on();
-  XBT_DEBUG("Create resource with read_bw '%f' write_bw '%f'", read_bw_, write_bw_);
-  constraint_read_  = maxminSystem->constraint_new(this, read_bw);
-  constraint_write_ = maxminSystem->constraint_new(this, write_bw);
+  read_bw_ = read_bw;
+  return this;
+}
+
+DiskImpl* DiskImpl::set_write_bandwidth(double write_bw)
+{
+  write_bw_ = write_bw;
+  return this;
+}
+
+DiskImpl* DiskImpl::set_read_constraint(lmm::Constraint* constraint_read)
+{
+  constraint_read_  = constraint_read;
+  return this;
+}
+
+DiskImpl* DiskImpl::set_write_constraint(lmm::Constraint* constraint_write)
+{
+  constraint_write_  = constraint_write;
+  return this;
 }
 
 /** @brief Fire the required callbacks and destroy the object
index 2a2d85d..1d80d65 100644 (file)
@@ -50,16 +50,16 @@ public:
 class DiskImpl : public Resource, public xbt::PropertyHolder {
   s4u::Host* host_           = nullptr;
   s4u::Disk piface_;
-  double read_bw_;
-  double write_bw_;
-  lmm::Constraint* constraint_write_; /* Constraint for maximum write bandwidth*/
-  lmm::Constraint* constraint_read_;  /* Constraint for maximum read bandwidth*/
+  double read_bw_ = -1.0;
+  double write_bw_ = 1.0;
+  lmm::Constraint* constraint_write_ = nullptr; /* Constraint for maximum write bandwidth*/
+  lmm::Constraint* constraint_read_ = nullptr;  /* Constraint for maximum read bandwidth*/
 
 protected:
   ~DiskImpl() override = default; // Disallow direct deletion. Call destroy() instead.
 
 public:
-  DiskImpl(Model* model, const std::string& name, kernel::lmm::System* maxmin_system, double read_bw, double bwrite_bw);
+  DiskImpl(const std::string& name) : piface_(name, this){}
   DiskImpl(const DiskImpl&) = delete;
   DiskImpl& operator=(const DiskImpl&) = delete;
 
@@ -69,9 +69,13 @@ public:
   s4u::Host* get_host() const { return host_; }
   void set_host(s4u::Host* host) { host_ = host; }
 
+  DiskImpl* set_read_bandwidth(double read_bw);
+  DiskImpl* set_write_bandwidth(double write_bw);
   double get_read_bandwidth() const { return read_bw_; }
   double get_write_bandwidth() const { return write_bw_; }
+  DiskImpl* set_read_constraint(lmm::Constraint* constraint_read);
   lmm::Constraint* get_read_constraint() const { return constraint_read_; }
+  DiskImpl* set_write_constraint(lmm::Constraint* constraint_write);
   lmm::Constraint* get_write_constraint() const { return constraint_write_; }
 
   /** @brief Check if the Disk is used (if an action currently uses its resources) */
index 80fe78b..1066e62 100644 (file)
@@ -35,7 +35,7 @@ DiskImpl* DiskS19Model::createDisk(const std::string& id, double read_bw, double
 {
   XBT_DEBUG("SURF disk create resource\n\t\tid '%s'\n\t\tread_bw '%f'\n", id.c_str(), read_bw);
 
-  return new DiskS19(this, id, get_maxmin_system(), read_bw, write_bw);
+  return new DiskS19(this, id, read_bw, write_bw);
 }
 
 double DiskS19Model::next_occurring_event(double now)
@@ -62,10 +62,19 @@ void DiskS19Model::update_actions_state(double /*now*/, double delta)
  * Resource *
  ************/
 
-DiskS19::DiskS19(DiskModel* model, const std::string& name, lmm::System* maxminSystem, double read_bw, double write_bw)
-    : DiskImpl(model, name, maxminSystem, read_bw, write_bw)
-{
+DiskS19::DiskS19(DiskModel* model, const std::string& name, double read_bw, double write_bw)
+    : DiskImpl(name)
+{
+  lmm::System* maxmin_system = model->get_maxmin_system();
+  this->set_read_bandwidth(read_bw)
+      ->set_write_bandwidth(write_bw)
+      ->set_read_constraint(maxmin_system->constraint_new(this, read_bw))
+      ->set_write_constraint(maxmin_system->constraint_new(this, write_bw))
+      ->set_name(name)
+      ->set_model(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);
+  DiskImpl::turn_on();
 }
 
 DiskAction* DiskS19::io_start(sg_size_t size, s4u::Io::OpType type)
index a46ffce..8f8213a 100644 (file)
@@ -40,8 +40,7 @@ public:
 
 class DiskS19 : public DiskImpl {
 public:
-  DiskS19(DiskModel* model, const std::string& name, kernel::lmm::System* maxminSystem, double read_bw,
-          double write_bw);
+  DiskS19(DiskModel* model, const std::string& name, double read_bw, double write_bw);
   DiskAction* io_start(sg_size_t size, s4u::Io::OpType type) override;
   DiskAction* read(sg_size_t size) override;
   DiskAction* write(sg_size_t size) override;
index 3c6cbc9..5e01a57 100644 (file)
@@ -324,6 +324,7 @@ 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* d = surf_disk_model->createDisk(disk->id, disk->read_bw, disk->write_bw);
   if (disk->properties) {
     d->set_properties(*disk->properties);