Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Change way Resources are created: Empty ctor and setters
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 25 Feb 2021 08:25:11 +0000 (09:25 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 25 Feb 2021 08:25:11 +0000 (09:25 +0100)
include/simgrid/kernel/resource/Resource.hpp
src/kernel/resource/DiskImpl.cpp
src/kernel/resource/Resource.cpp
src/kernel/resource/profile/Profile_test.cpp
src/surf/cpu_interface.cpp
src/surf/network_interface.cpp

index fc8d09a..526237b 100644 (file)
@@ -22,11 +22,11 @@ namespace resource {
  * @details This is the ancestor class of every resources in SimGrid, such as links, CPU or disk
  */
 class XBT_PUBLIC Resource {
-  std::string name_;
-  Model* model_;
-  bool is_on_ = true;
+  std::string name_ = "unnamed";
+  Model* model_     = nullptr;
+  bool is_on_       = true;
 
-  lmm::Constraint* const constraint_;
+  lmm::Constraint* constraint_ = nullptr;
 
 protected:
   struct Metric {
@@ -37,27 +37,22 @@ protected:
   profile::Event* state_event_ = nullptr;
 
 public:
-  /**
-   * @brief Constructor of LMM Resources
-   *
-   * @param model Model associated to this Resource
-   * @param name The name of the Resource
-   * @param constraint The lmm constraint associated to this Resource if it is part of a LMM component
-   */
-  Resource(Model* model, const std::string& name, lmm::Constraint* constraint)
-      : name_(name), model_(model), constraint_(constraint)
-  {
-  }
-
+  Resource() = default;
   virtual ~Resource() = default;
 
   /** @brief Get the Model of the current Resource */
   Model* get_model() const { return model_; }
+  Resource* set_model(Model* model);
 
   /** @brief Get the name of the current Resource */
   const std::string& get_name() const { return name_; }
   /** @brief Get the name of the current Resource */
   const char* get_cname() const { return name_.c_str(); }
+  Resource* set_name(const std::string& name);
+
+  /** @brief Get the lmm constraint associated to this Resource if it is part of a LMM component (or null if none) */
+  lmm::Constraint* get_constraint() const { return constraint_; }
+  Resource* set_constraint(lmm::Constraint* constraint);
 
   bool operator==(const Resource& other) const { return name_ == other.name_; }
 
@@ -81,8 +76,6 @@ public:
   /** @brief setup the profile file with states events (ON or OFF). The profile must contain boolean values. */
   virtual void set_state_profile(profile::Profile* profile);
 
-  /** @brief Get the lmm constraint associated to this Resource if it is part of a LMM component (or null if none) */
-  lmm::Constraint* get_constraint() const { return constraint_; }
 };
 } // namespace resource
 } // namespace kernel
index f9d1b3a..e765fed 100644 (file)
@@ -37,11 +37,11 @@ DiskModel::~DiskModel()
 
 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)
+    : piface_(name, this)
     , read_bw_(read_bw)
     , write_bw_(write_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);
index 581d6c7..590db09 100644 (file)
@@ -13,6 +13,24 @@ namespace simgrid {
 namespace kernel {
 namespace resource {
 
+Resource* Resource::set_name(const std::string& name)
+{
+  name_ = name;
+  return this;
+}
+
+Resource* Resource::set_model(Model* model)
+{
+  model_ = model;
+  return this;
+}
+
+Resource* Resource::set_constraint(lmm::Constraint* constraint)
+{
+  constraint_ = constraint;
+  return this;
+}
+
 double Resource::get_load() const
 {
   return constraint_->get_usage();
index 5776a1e..283de0f 100644 (file)
@@ -24,7 +24,7 @@ class MockedResource : public simgrid::kernel::resource::Resource {
 public:
   static double the_date;
 
-  explicit MockedResource() : simgrid::kernel::resource::Resource(nullptr, "fake", nullptr) {}
+  explicit MockedResource() { this->set_name("fake"); }
   void apply_event(simgrid::kernel::profile::Event* event, double value) override
   {
     XBT_VERB("t=%.1f: Change value to %lg (idx: %u)", the_date, value, event->idx);
index e60ece1..c826944 100644 (file)
@@ -58,11 +58,12 @@ Cpu::Cpu(Model* model, s4u::Host* host, const std::vector<double>& speed_per_pst
 
 Cpu::Cpu(Model* model, s4u::Host* host, lmm::Constraint* constraint, const std::vector<double>& speed_per_pstate,
          int core)
-    : Resource(model, host->get_cname(), constraint)
-    , core_count_(core)
+    : core_count_(core)
     , host_(host)
     , speed_per_pstate_(speed_per_pstate)
 {
+  this->set_name(host->get_cname())->set_model(model)->set_constraint(constraint);
+
   xbt_assert(core > 0, "Host %s must have at least one core, not 0.", host->get_cname());
 
   speed_.peak     = speed_per_pstate_.front();
index c2f2caa..15e75ad 100644 (file)
@@ -74,8 +74,9 @@ double NetworkModel::next_occurring_event_full(double now)
  ************/
 
 LinkImpl::LinkImpl(NetworkModel* model, const std::string& name, lmm::Constraint* constraint)
-    : Resource(model, name, constraint), piface_(this)
+    : piface_(this)
 {
+  this->set_name(name)->set_model(model)->set_constraint(constraint);
   if (name != "__loopback__")
     xbt_assert(not s4u::Link::by_name_or_null(name), "Link '%s' declared several times in the platform.", name.c_str());