From 795d95bd3584056b40e441e4ca9b935fb0dc7d32 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Mon, 9 Dec 2019 11:52:58 +0100 Subject: [PATCH] give access to disk's read and write (nomimal) bandwidth values --- examples/s4u/io-disk-raw/s4u-io-disk-raw.cpp | 3 ++- examples/s4u/io-disk-raw/s4u-io-disk-raw.tesh | 4 ++-- include/simgrid/s4u/Disk.hpp | 14 ++++++-------- src/kernel/resource/DiskImpl.cpp | 7 +++++-- src/kernel/resource/DiskImpl.hpp | 5 +++++ src/s4u/s4u_Disk.cpp | 10 ++++++++++ 6 files changed, 30 insertions(+), 13 deletions(-) diff --git a/examples/s4u/io-disk-raw/s4u-io-disk-raw.cpp b/examples/s4u/io-disk-raw/s4u-io-disk-raw.cpp index fadd0d827b..d51781a432 100644 --- a/examples/s4u/io-disk-raw/s4u-io-disk-raw.cpp +++ b/examples/s4u/io-disk-raw/s4u-io-disk-raw.cpp @@ -19,7 +19,8 @@ static void host() /* - For each disk mounted on host, display disk name and mount point */ for (auto disk : disk_list) - XBT_INFO("Disk name: %s", disk->get_cname()); + XBT_INFO("Disk name: %s (read: %.0f B/s -- write: %.0f B/s ", disk->get_cname(), disk->get_read_bandwidth(), + disk->get_write_bandwidth()); /* - Write 400,000 bytes on Disk1 */ simgrid::s4u::Disk* disk = disk_list.front(); diff --git a/examples/s4u/io-disk-raw/s4u-io-disk-raw.tesh b/examples/s4u/io-disk-raw/s4u-io-disk-raw.tesh index 1dcba40532..f2eadab4d3 100644 --- a/examples/s4u/io-disk-raw/s4u-io-disk-raw.tesh +++ b/examples/s4u/io-disk-raw/s4u-io-disk-raw.tesh @@ -8,8 +8,8 @@ $ ${bindir}/s4u-io-disk-raw ${platfdir}/hosts_with_disks.xml "--log=root.fmt:[%1 > [ 0.000000] (0:maestro@) *** carl properties **** > [ 0.000000] (0:maestro@) remote_disk -> /scratch:Disk1:bob > [ 0.000000] (1:@bob) *** Storage info on bob *** -> [ 0.000000] (1:@bob) Disk name: Disk1 -> [ 0.000000] (1:@bob) Disk name: Disk2 +> [ 0.000000] (1:@bob) Disk name: Disk1 (read: 100000000 B/s -- write: 40000000 B/s +> [ 0.000000] (1:@bob) Disk name: Disk2 (read: 200000000 B/s -- write: 80000000 B/s > [ 0.010000] (1:@bob) Wrote 400000 bytes on 'Disk1' > [ 0.012000] (1:@bob) Read 200000 bytes on 'Disk1' > [ 0.012000] (1:@bob) *** Get/set data for storage element: Disk1 *** diff --git a/include/simgrid/s4u/Disk.hpp b/include/simgrid/s4u/Disk.hpp index 106da72666..78c411564d 100644 --- a/include/simgrid/s4u/Disk.hpp +++ b/include/simgrid/s4u/Disk.hpp @@ -26,17 +26,18 @@ namespace s4u { */ class XBT_PUBLIC Disk : public xbt::Extendable { + kernel::resource::DiskImpl* const pimpl_; + std::string name_; friend Engine; friend Io; friend kernel::resource::DiskImpl; -public: - explicit Disk(const std::string& name, kernel::resource::DiskImpl* pimpl) : pimpl_(pimpl), name_(name) {} - protected: virtual ~Disk() = default; public: + explicit Disk(const std::string& name, kernel::resource::DiskImpl* pimpl) : pimpl_(pimpl), name_(name) {} + /** @brief Callback signal fired when a new Disk is created */ static xbt::signal on_creation; /** @brief Callback signal fired when a Disk is destroyed */ @@ -48,7 +49,8 @@ public: std::string const& get_name() const { return name_; } /** @brief Retrieves the name of that disk as a C string */ const char* get_cname() const { return name_.c_str(); } - + double get_read_bandwidth() const; + double get_write_bandwidth(); const std::unordered_map* get_properties() const; const char* get_property(const std::string& key) const; void set_property(const std::string&, const std::string& value); @@ -62,10 +64,6 @@ public: IoPtr write_async(sg_size_t size); sg_size_t write(sg_size_t size); kernel::resource::DiskImpl* get_impl() const { return pimpl_; } - -private: - kernel::resource::DiskImpl* const pimpl_; - std::string name_; }; } // namespace s4u diff --git a/src/kernel/resource/DiskImpl.cpp b/src/kernel/resource/DiskImpl.cpp index 7c759a78fa..18c7035ce3 100644 --- a/src/kernel/resource/DiskImpl.cpp +++ b/src/kernel/resource/DiskImpl.cpp @@ -37,10 +37,13 @@ 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) + : Resource(model, name, maxminSystem->constraint_new(this, std::max(read_bw, write_bw))) + , piface_(name, this) + , read_bw_(read_bw) + , write_bw_(write_bw) { DiskImpl::turn_on(); - XBT_DEBUG("Create resource with read_bw '%f' write_bw '%f'", read_bw, write_bw); + 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); } diff --git a/src/kernel/resource/DiskImpl.hpp b/src/kernel/resource/DiskImpl.hpp index c25b0a2771..269a3607d8 100644 --- a/src/kernel/resource/DiskImpl.hpp +++ b/src/kernel/resource/DiskImpl.hpp @@ -51,6 +51,8 @@ class DiskImpl : public Resource, public surf::PropertyHolder { bool currently_destroying_ = false; s4u::Host* host_ = nullptr; s4u::Disk piface_; + double read_bw_; + double write_bw_; public: DiskImpl(Model* model, const std::string& name, kernel::lmm::System* maxmin_system, double read_bw, double bwrite_bw); @@ -61,6 +63,9 @@ public: /** @brief Public interface */ s4u::Disk* get_iface() { return &piface_; } + double get_read_bandwidth() { return read_bw_; } + double get_write_bandwidth() { return write_bw_; } + /** @brief Check if the Storage is used (if an action currently uses its resources) */ bool is_used() override; diff --git a/src/s4u/s4u_Disk.cpp b/src/s4u/s4u_Disk.cpp index 562e7423b2..153a65c5e4 100644 --- a/src/s4u/s4u_Disk.cpp +++ b/src/s4u/s4u_Disk.cpp @@ -20,6 +20,16 @@ xbt::signal Disk::on_creation; xbt::signal Disk::on_destruction; xbt::signal Disk::on_state_change; +double Disk::get_read_bandwidth() const +{ + return this->pimpl_->get_read_bandwidth(); +} + +double Disk::get_write_bandwidth() +{ + return pimpl_->get_write_bandwidth(); +} + Host* Disk::get_host() { return pimpl_->get_host(); -- 2.20.1