From cf454dfcf7c27e86e15af1a45c58dbb7a76e43c8 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Fri, 5 Mar 2021 12:31:01 +0100 Subject: [PATCH] add boolean state to resources and protect set_core_count --- include/simgrid/kernel/resource/Resource.hpp | 4 ++++ src/kernel/resource/DiskImpl.cpp | 1 + src/surf/cpu_interface.cpp | 6 ++++++ src/surf/cpu_interface.hpp | 2 ++ src/surf/network_interface.cpp | 4 +++- 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/simgrid/kernel/resource/Resource.hpp b/include/simgrid/kernel/resource/Resource.hpp index 5751b3435b..9be92f6bfe 100644 --- a/include/simgrid/kernel/resource/Resource.hpp +++ b/include/simgrid/kernel/resource/Resource.hpp @@ -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 */ diff --git a/src/kernel/resource/DiskImpl.cpp b/src/kernel/resource/DiskImpl.cpp index 5a6e1b6e62..d8eeae5c04 100644 --- a/src/kernel/resource/DiskImpl.cpp +++ b/src/kernel/resource/DiskImpl.cpp @@ -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 DiskAction::on_state_change; diff --git a/src/surf/cpu_interface.cpp b/src/surf/cpu_interface.cpp index 823c219724..a15bc1faab 100644 --- a/src/surf/cpu_interface.cpp +++ b/src/surf/cpu_interface.cpp @@ -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 * **********/ diff --git a/src/surf/cpu_interface.hpp b/src/surf/cpu_interface.hpp index 22f07b5e6a..b71f146f37 100644 --- a/src/surf/cpu_interface.hpp +++ b/src/surf/cpu_interface.hpp @@ -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 diff --git a/src/surf/network_interface.cpp b/src/surf/network_interface.cpp index 7a8aa5404a..23a464aa33 100644 --- a/src/surf/network_interface.cpp +++ b/src/surf/network_interface.cpp @@ -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_); -- 2.20.1