From 3a403e463ecccd4a15bbf4aeb05c860fdd7c5db1 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Wed, 12 Apr 2023 17:43:10 +0200 Subject: [PATCH] Allow to set a concurrency limit on disks and hosts --- ChangeLog | 1 + include/simgrid/s4u/Disk.hpp | 7 +++++++ include/simgrid/s4u/Host.hpp | 8 ++++++++ src/kernel/resource/LinkImpl.hpp | 4 ---- src/kernel/resource/Resource.hpp | 11 +++++++++++ src/kernel/resource/StandardLinkImpl.cpp | 12 ------------ src/kernel/resource/StandardLinkImpl.hpp | 3 --- src/s4u/s4u_Disk.cpp | 10 ++++++++++ src/s4u/s4u_Host.cpp | 11 +++++++++++ 9 files changed, 48 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index 41bc62f20a..7cb4558527 100644 --- a/ChangeLog +++ b/ChangeLog @@ -18,6 +18,7 @@ S4U: - Full simDAG integration: Activity::start() actually starts only when all dependencies are fullfiled. If it cannot be started right away, it will start as soon as it becomes possible. + - Allow to set a concurrency limit on disks and hosts, as it was already the case for links. Kernel: - optimize an internal datastructure (use a set instead of a list for ongoing activities), diff --git a/include/simgrid/s4u/Disk.hpp b/include/simgrid/s4u/Disk.hpp index 1f8c31dce3..fcba914a0f 100644 --- a/include/simgrid/s4u/Disk.hpp +++ b/include/simgrid/s4u/Disk.hpp @@ -79,6 +79,13 @@ public: Disk* set_state_profile(kernel::profile::Profile* profile); Disk* set_read_bandwidth_profile(kernel::profile::Profile* profile); Disk* set_write_bandwidth_profile(kernel::profile::Profile* profile); + /** + * @brief Set the max amount of operations (either read or write) that can take place on this disk at the same time + * + * Use -1 to set no limit. + */ + Disk* set_concurrency_limit(int limit); + int get_concurrency_limit() const; IoPtr io_init(sg_size_t size, s4u::Io::OpType type) const; diff --git a/include/simgrid/s4u/Host.hpp b/include/simgrid/s4u/Host.hpp index b13b561ed6..df0511ad0f 100644 --- a/include/simgrid/s4u/Host.hpp +++ b/include/simgrid/s4u/Host.hpp @@ -133,6 +133,14 @@ public: Host* set_state_profile(kernel::profile::Profile* p); Host* set_speed_profile(kernel::profile::Profile* p); + /** + * @brief Set the max amount of executions that can take place on this host at the same time + * + * Use -1 to set no limit. + */ + Host* set_concurrency_limit(int limit); + int get_concurrency_limit() const; + /** @brief Convert the CPU's speed from string to double */ static std::vector convert_pstate_speed_vector(const std::vector& speed_per_state); /** diff --git a/src/kernel/resource/LinkImpl.hpp b/src/kernel/resource/LinkImpl.hpp index f7f269f212..8b6ac8af4e 100644 --- a/src/kernel/resource/LinkImpl.hpp +++ b/src/kernel/resource/LinkImpl.hpp @@ -38,10 +38,6 @@ public: /* setup the profile file with latency events (peak latency changes due to external load). * Profile must contain absolute values */ virtual void set_latency_profile(kernel::profile::Profile* profile) = 0; - /** @brief Set the concurrency limit for this link */ - virtual void set_concurrency_limit(int limit) const = 0; - /** @brief Get the concurrency limit of this link */ - virtual int get_concurrency_limit() const = 0; }; } // namespace simgrid::kernel::resource diff --git a/src/kernel/resource/Resource.hpp b/src/kernel/resource/Resource.hpp index bf67c6a42f..6c864e33b9 100644 --- a/src/kernel/resource/Resource.hpp +++ b/src/kernel/resource/Resource.hpp @@ -101,6 +101,17 @@ public: lmm::Constraint* get_constraint() const { return constraint_; } + /** @brief Set the concurrency limit for this resource */ + virtual void set_concurrency_limit(int limit) const + { + if (limit != -1) + get_constraint()->reset_concurrency_maximum(); + get_constraint()->set_concurrency_limit(limit); + } + + /** @brief Get the concurrency limit of this resource */ + virtual int get_concurrency_limit() const { return get_constraint()->get_concurrency_limit(); } + /** @brief returns the current load due to activities (in flops per second, byte per second or similar) * * The load due to external usages modeled by profile files is ignored.*/ diff --git a/src/kernel/resource/StandardLinkImpl.cpp b/src/kernel/resource/StandardLinkImpl.cpp index 9e50e7acdd..59a07d1ec0 100644 --- a/src/kernel/resource/StandardLinkImpl.cpp +++ b/src/kernel/resource/StandardLinkImpl.cpp @@ -133,16 +133,4 @@ void StandardLinkImpl::set_latency_profile(profile::Profile* profile) } } -void StandardLinkImpl::set_concurrency_limit(int limit) const -{ - if (limit != -1) { - get_constraint()->reset_concurrency_maximum(); - } - get_constraint()->set_concurrency_limit(limit); -} -int StandardLinkImpl::get_concurrency_limit() const -{ - return get_constraint()->get_concurrency_limit(); -} - } // namespace simgrid::kernel::resource diff --git a/src/kernel/resource/StandardLinkImpl.hpp b/src/kernel/resource/StandardLinkImpl.hpp index 4a10210074..d573fe127f 100644 --- a/src/kernel/resource/StandardLinkImpl.hpp +++ b/src/kernel/resource/StandardLinkImpl.hpp @@ -70,9 +70,6 @@ public: /* setup the profile file with latency events (peak latency changes due to external load). * Profile must contain absolute values */ void set_latency_profile(kernel::profile::Profile* profile) override; - - void set_concurrency_limit(int limit) const override; - int get_concurrency_limit() const override; }; } // namespace simgrid::kernel::resource diff --git a/src/s4u/s4u_Disk.cpp b/src/s4u/s4u_Disk.cpp index 9e3d59f8b3..0fa8295342 100644 --- a/src/s4u/s4u_Disk.cpp +++ b/src/s4u/s4u_Disk.cpp @@ -112,6 +112,16 @@ Disk* Disk::set_write_bandwidth_profile(kernel::profile::Profile* profile) [this, profile]() { this->pimpl_->set_write_bandwidth_profile(profile); }); return this; } +int Disk::get_concurrency_limit() const +{ + return pimpl_->get_concurrency_limit(); +} + +Disk* Disk::set_concurrency_limit(int limit) +{ + kernel::actor::simcall_object_access(pimpl_, [this, limit] { pimpl_->set_concurrency_limit(limit); }); + return this; +} IoPtr Disk::io_init(sg_size_t size, Io::OpType type) const { diff --git a/src/s4u/s4u_Host.cpp b/src/s4u/s4u_Host.cpp index ba4a844e81..af3a4ad81c 100644 --- a/src/s4u/s4u_Host.cpp +++ b/src/s4u/s4u_Host.cpp @@ -207,6 +207,17 @@ Host* Host::set_properties(const std::unordered_map& p return this; } +int Host::get_concurrency_limit() const +{ + return pimpl_cpu_->get_concurrency_limit(); +} + +Host* Host::set_concurrency_limit(int limit) +{ + kernel::actor::simcall_object_access(pimpl_cpu_, [this, limit] { pimpl_cpu_->set_concurrency_limit(limit); }); + return this; +} + /** Specify a profile turning the host on and off according to an exhaustive list or a stochastic law. * The profile must contain boolean values. */ Host* Host::set_state_profile(kernel::profile::Profile* p) -- 2.20.1