Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use const& for std::string parameter (sonar, again).
[simgrid.git] / src / kernel / resource / DiskImpl.cpp
index f2877f2..f44e3ff 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2019. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2019-2021. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -9,9 +9,7 @@
 #include "src/kernel/EngineImpl.hpp"
 #include "src/kernel/lmm/maxmin.hpp"
 
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(disk_kernel, surf, "Logging specific to the disk kernel resource");
-
-simgrid::kernel::resource::DiskModel* surf_disk_model = nullptr;
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(res_disk, ker_resource, "Disk resources, fuelling I/O activities");
 
 namespace simgrid {
 namespace kernel {
@@ -21,33 +19,42 @@ namespace resource {
  * Model *
  *********/
 
-DiskModel::DiskModel() : Model(Model::UpdateAlgo::FULL)
-{
-  set_maxmin_system(new simgrid::kernel::lmm::System(true /* selective update */));
-}
-
-DiskModel::~DiskModel()
+DiskModel::DiskModel(const std::string& name) : Model(name)
 {
-  surf_disk_model = nullptr;
+  set_maxmin_system(new lmm::System(true /* selective update */));
 }
 
 /************
  * Resource *
  ************/
+DiskImpl* DiskImpl::set_host(s4u::Host* host)
+{
+  host_ = host;
+  return this;
+}
 
-DiskImpl::DiskImpl(kernel::resource::Model* model, const std::string& name, kernel::lmm::System* maxminSystem,
-                   double read_bw, double write_bw)
-    : Resource(model, name, maxminSystem->constraint_new(this, std::max(read_bw, write_bw))), piface_(name, this)
+DiskImpl* DiskImpl::set_read_bandwidth(double read_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()
+DiskImpl* DiskImpl::set_write_bandwidth(double write_bw)
 {
-  xbt_assert(currently_destroying_, "Don't delete Disks directly. Call destroy() instead.");
+  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
@@ -56,14 +63,11 @@ DiskImpl::~DiskImpl()
  */
 void DiskImpl::destroy()
 {
-  if (not currently_destroying_) {
-    currently_destroying_ = true;
-    s4u::Disk::on_destruction(this->piface_);
-    delete this;
-  }
+  s4u::Disk::on_destruction(this->piface_);
+  delete this;
 }
 
-bool DiskImpl::is_used()
+bool DiskImpl::is_used() const
 {
   THROW_UNIMPLEMENTED;
 }
@@ -88,8 +92,18 @@ void DiskImpl::turn_off()
   }
 }
 
-xbt::signal<void(DiskAction const&, kernel::resource::Action::State, kernel::resource::Action::State)>
-    DiskAction::on_state_change;
+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_))
+      ->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_);
+  Resource::seal();
+  turn_on();
+}
+xbt::signal<void(DiskAction const&, Action::State, Action::State)> DiskAction::on_state_change;
 
 /**********
  * Action *