Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add boolean state to resources and protect set_core_count
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Fri, 5 Mar 2021 11:31:01 +0000 (12:31 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Fri, 5 Mar 2021 11:31:01 +0000 (12:31 +0100)
include/simgrid/kernel/resource/Resource.hpp
src/kernel/resource/DiskImpl.cpp
src/surf/cpu_interface.cpp
src/surf/cpu_interface.hpp
src/surf/network_interface.cpp

index 5751b34..9be92f6 100644 (file)
@@ -25,6 +25,7 @@ namespace resource {
 class XBT_PUBLIC Resource {
   std::string name_ = "unnamed";
   bool is_on_       = true;
+  bool sealed_      = false;
 
 protected:
   struct Metric {
@@ -37,6 +38,7 @@ protected:
 public:
   Resource(const std::string& name) : name_(name){};
   virtual ~Resource() = default;
+  virtual void seal() { sealed_ = true; }
 
   /** @brief Get the name of the current Resource */
   const std::string& get_name() const { return name_; }
@@ -53,6 +55,8 @@ public:
 
   /** @brief Check if the current Resource is active */
   virtual bool is_on() const { return is_on_; }
+  virtual bool is_sealed() const { return sealed_; }
+
   /** @brief Turn on the current Resource */
   virtual void turn_on() { is_on_ = true; }
   /** @brief Turn off the current Resource */
index 5a6e1b6..d8eeae5 100644 (file)
@@ -106,6 +106,7 @@ void DiskImpl::seal()
       ->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;
index 823c219..a15bc1f 100644 (file)
@@ -96,6 +96,7 @@ void Cpu::on_speed_change()
 
 Cpu* Cpu::set_core_count(int core_count)
 {
+  xbt_assert(not is_sealed(), "Core count cannot be changed once CPU has been sealed");
   xbt_assert(core_count > 0, "Host %s must have at least one core, not 0.", piface_->get_cname());
   core_count_ = core_count;
   return this;
@@ -113,6 +114,11 @@ void Cpu::set_speed_profile(kernel::profile::Profile* profile)
   speed_.event = profile->schedule(&profile::future_evt_set, this);
 }
 
+void Cpu::seal()
+{
+  Resource::seal();
+}
+
 /**********
  * Action *
  **********/
index 22f07b5..b71f146 100644 (file)
@@ -75,6 +75,8 @@ public:
   Cpu* set_core_count(int core_count);
   virtual int get_core_count();
 
+  void seal();
+
   /** @brief Get a forecast of the speed (in flops/s) if the load were as provided.
    *
    * The provided load should encompasses both the application's activities and the external load that come from a
index 7a8aa54..23a464a 100644 (file)
@@ -153,12 +153,14 @@ void LinkImpl::turn_off()
     }
   }
 }
+
 void LinkImpl::seal()
 {
   this->set_model(surf_network_model);
-
+  Resource::seal();
   simgrid::s4u::Link::on_creation(*get_iface());
 }
+
 void LinkImpl::on_bandwidth_change() const
 {
   s4u::Link::on_bandwidth_change(this->piface_);