From a4c95b1dede3a4652f67577b76d844123cb8223a Mon Sep 17 00:00:00 2001 From: SUTER Frederic Date: Fri, 29 Oct 2021 16:58:54 +0200 Subject: [PATCH] add the capacity the update the priority of an I/O during its execution --- MANIFEST.in | 4 +-- examples/cpp/CMakeLists.txt | 2 +- examples/cpp/io-basic/s4u-io-basic.tesh | 5 ---- .../s4u-io-priority.cpp} | 29 +++++++++++++++++-- examples/cpp/io-priority/s4u-io-priority.tesh | 8 +++++ include/simgrid/s4u/Io.hpp | 2 ++ src/kernel/activity/IoImpl.cpp | 7 +++++ src/kernel/activity/IoImpl.hpp | 2 ++ src/kernel/lmm/maxmin.cpp | 4 ++- src/kernel/resource/Action.cpp | 1 - src/s4u/s4u_Io.cpp | 8 +++++ 11 files changed, 60 insertions(+), 12 deletions(-) delete mode 100644 examples/cpp/io-basic/s4u-io-basic.tesh rename examples/cpp/{io-basic/s4u-io-basic.cpp => io-priority/s4u-io-priority.cpp} (59%) create mode 100644 examples/cpp/io-priority/s4u-io-priority.tesh diff --git a/MANIFEST.in b/MANIFEST.in index d88dde2439..db4e029408 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -260,8 +260,6 @@ include examples/cpp/exec-waitfor/s4u-exec-waitfor.cpp include examples/cpp/exec-waitfor/s4u-exec-waitfor.tesh include examples/cpp/io-async/s4u-io-async.cpp include examples/cpp/io-async/s4u-io-async.tesh -include examples/cpp/io-basic/s4u-io-basic.cpp -include examples/cpp/io-basic/s4u-io-basic.tesh include examples/cpp/io-degradation/s4u-io-degradation.cpp include examples/cpp/io-degradation/s4u-io-degradation.tesh include examples/cpp/io-dependent/s4u-io-dependent.cpp @@ -273,6 +271,8 @@ include examples/cpp/io-file-remote/s4u-io-file-remote.tesh include examples/cpp/io-file-remote/s4u-io-file-remote_d.xml include examples/cpp/io-file-system/s4u-io-file-system.cpp include examples/cpp/io-file-system/s4u-io-file-system.tesh +include examples/cpp/io-priority/s4u-io-priority.cpp +include examples/cpp/io-priority/s4u-io-priority.tesh include examples/cpp/maestro-set/s4u-maestro-set.cpp include examples/cpp/maestro-set/s4u-maestro-set.tesh include examples/cpp/mc-bugged1-liveness/promela_bugged1_liveness diff --git a/examples/cpp/CMakeLists.txt b/examples/cpp/CMakeLists.txt index c111550f75..a09d9cf2a5 100644 --- a/examples/cpp/CMakeLists.txt +++ b/examples/cpp/CMakeLists.txt @@ -74,7 +74,7 @@ foreach (example actor-create actor-daemon actor-exiting actor-join actor-kill maestro-set mc-bugged1 mc-bugged2 mc-electric-fence mc-failing-assert network-wifi - io-async io-basic io-degradation io-file-system io-file-remote io-disk-raw io-dependent + io-async io-priority io-degradation io-file-system io-file-remote io-disk-raw io-dependent platform-failures platform-profile platform-properties plugin-host-load plugin-link-load plugin-prodcons replay-comm replay-io diff --git a/examples/cpp/io-basic/s4u-io-basic.tesh b/examples/cpp/io-basic/s4u-io-basic.tesh deleted file mode 100644 index 4fd0f1cdd4..0000000000 --- a/examples/cpp/io-basic/s4u-io-basic.tesh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env tesh - -$ ${bindir:=.}/s4u-io-basic ${platfdir}/hosts_with_disks.xml -> [bob:privileged_writer:(2) 0.150000] [s4u_test/INFO] Done. -> [bob:writer:(1) 0.200000] [s4u_test/INFO] Done. diff --git a/examples/cpp/io-basic/s4u-io-basic.cpp b/examples/cpp/io-priority/s4u-io-priority.cpp similarity index 59% rename from examples/cpp/io-basic/s4u-io-basic.cpp rename to examples/cpp/io-priority/s4u-io-priority.cpp index 77e1213ca3..1c8f4785ec 100644 --- a/examples/cpp/io-basic/s4u-io-basic.cpp +++ b/examples/cpp/io-priority/s4u-io-priority.cpp @@ -13,7 +13,10 @@ static void writer() std::vector const& disk_list = simgrid::s4u::Host::current()->get_disks(); /* - Write 4,000,000 bytes on Disk1 */ disk_list.front()->write(4000000); - XBT_INFO("Done."); + XBT_INFO("First write done."); + /* - Write 4,000,000 bytes on Disk1 again */ + disk_list.front()->write(4000000); + XBT_INFO("Second write done."); } static void privileged_writer() @@ -27,11 +30,33 @@ static void privileged_writer() * * So instead of a half/half sharing between the two, we get a 1/3 vs. 2/3 sharing. */ disk_list.front()->io_init(4000000, simgrid::s4u::Io::OpType::WRITE)->set_priority(2)->wait(); - XBT_INFO("Done."); + XBT_INFO("First write done."); /* Note that the timings printed when running this example are a bit misleading, because the uneven sharing only last * until the privileged actor ends. After this point, the unprivileged one gets 100% of the disk and finishes quite * quickly. */ + + /* Resynchronize actors before second write */ + simgrid::s4u::this_actor::sleep_for(0.05); + + /* - Write 4,000,000 bytes on Disk1 again and this time : + * - Start the I/O operation asynchronously to get an IoPtr + * - Let the actor sleep while half of the data is written + * - Double its priority + * - Wait for the end of the I/O operation + * + * Writing the second half of the data with a higher priority, and thus 2/3 of the bandwidth takes 0.075s. + * In the meantime, the regular writer has only 1/3 of the bandwidth and thus only writes 1MB. After the completion + * of the I/O initiated by the privileged writer, the regular writer has the full bandwidth available and only needs + * 0.025s to write the last MB. + */ + + simgrid::s4u::IoPtr io = disk_list.front()->write_async(4000000); + simgrid::s4u::this_actor::sleep_for(0.1); + XBT_INFO("Increase priority for the priviledged writer (%.0f bytes remaining to write)", io->get_remaining()); + io->update_priority(2); + io->wait(); + XBT_INFO("Second write done."); } int main(int argc, char* argv[]) diff --git a/examples/cpp/io-priority/s4u-io-priority.tesh b/examples/cpp/io-priority/s4u-io-priority.tesh new file mode 100644 index 0000000000..3a9b3e6f99 --- /dev/null +++ b/examples/cpp/io-priority/s4u-io-priority.tesh @@ -0,0 +1,8 @@ +#!/usr/bin/env tesh + +$ ${bindir:=.}/s4u-io-priority ${platfdir}/hosts_with_disks.xml +> [bob:privileged_writer:(2) 0.150000] [s4u_test/INFO] First write done. +> [bob:writer:(1) 0.200000] [s4u_test/INFO] First write done. +> [bob:privileged_writer:(2) 0.300000] [s4u_test/INFO] Increase priority for the priviledged writer (2000000 bytes remaining to write) +> [bob:privileged_writer:(2) 0.375000] [s4u_test/INFO] Second write done. +> [bob:writer:(1) 0.400000] [s4u_test/INFO] Second write done. diff --git a/include/simgrid/s4u/Io.hpp b/include/simgrid/s4u/Io.hpp index 14abc92604..2f596869dc 100644 --- a/include/simgrid/s4u/Io.hpp +++ b/include/simgrid/s4u/Io.hpp @@ -50,6 +50,8 @@ public: IoPtr set_size(sg_size_t size); IoPtr set_op_type(OpType type); + IoPtr update_priority(double priority); + bool is_assigned() const override; }; diff --git a/src/kernel/activity/IoImpl.cpp b/src/kernel/activity/IoImpl.cpp index a714e97b62..4038c62365 100644 --- a/src/kernel/activity/IoImpl.cpp +++ b/src/kernel/activity/IoImpl.cpp @@ -34,6 +34,13 @@ IoImpl& IoImpl::set_sharing_penalty(double sharing_penalty) return *this; } +IoImpl& IoImpl::update_sharing_penalty(double sharing_penalty) +{ + sharing_penalty_ = sharing_penalty; + surf_action_->set_sharing_penalty(sharing_penalty); + return *this; +} + IoImpl& IoImpl::set_timeout(double timeout) { const s4u::Host* host = get_disk()->get_host(); diff --git a/src/kernel/activity/IoImpl.hpp b/src/kernel/activity/IoImpl.hpp index 2c2ab5b323..d3b84fd561 100644 --- a/src/kernel/activity/IoImpl.hpp +++ b/src/kernel/activity/IoImpl.hpp @@ -32,6 +32,8 @@ public: IoImpl& set_type(s4u::Io::OpType type); IoImpl& set_disk(resource::DiskImpl* disk); + IoImpl& update_sharing_penalty(double sharing_penalty); + sg_size_t get_performed_ioops() const { return performed_ioops_; } resource::DiskImpl* get_disk() const { return disk_; } diff --git a/src/kernel/lmm/maxmin.cpp b/src/kernel/lmm/maxmin.cpp index fba53b32ad..a7514dead9 100644 --- a/src/kernel/lmm/maxmin.cpp +++ b/src/kernel/lmm/maxmin.cpp @@ -823,7 +823,7 @@ void System::update_variable_penalty(Variable* var, double penalty) bool enabling_var = (penalty > 0 && var->sharing_penalty_ <= 0); bool disabling_var = (penalty <= 0 && var->sharing_penalty_ > 0); - XBT_IN("(sys=%p, var=%p, penalty=%f)", this, var, penalty); + XBT_IN("(sys=%p, var=%p, var->sharing_penalty = %f, penalty=%f)", this, var, var->sharing_penalty_, penalty); modified_ = true; @@ -843,6 +843,8 @@ void System::update_variable_penalty(Variable* var, double penalty) disable_var(var); } else { var->sharing_penalty_ = penalty; + if (not var->cnsts_.empty()) + update_modified_set(var->cnsts_[0].constraint); } check_concurrency(); diff --git a/src/kernel/resource/Action.cpp b/src/kernel/resource/Action.cpp index 825578bb99..06ef1456f1 100644 --- a/src/kernel/resource/Action.cpp +++ b/src/kernel/resource/Action.cpp @@ -129,7 +129,6 @@ void Action::set_sharing_penalty(double sharing_penalty) XBT_IN("(%p,%g)", this, sharing_penalty); sharing_penalty_ = sharing_penalty; model_->get_maxmin_system()->update_variable_penalty(get_variable(), sharing_penalty); - if (model_->is_update_lazy()) model_->get_action_heap().remove(this); XBT_OUT(); diff --git a/src/s4u/s4u_Io.cpp b/src/s4u/s4u_Io.cpp index 4906e79a16..ea8960be41 100644 --- a/src/s4u/s4u_Io.cpp +++ b/src/s4u/s4u_Io.cpp @@ -105,6 +105,14 @@ IoPtr Io::set_op_type(OpType type) return this; } +IoPtr Io::update_priority(double priority) +{ + kernel::actor::simcall([this, priority] { + boost::static_pointer_cast(pimpl_)->update_sharing_penalty(1. / priority); + }); + return this; +} + /** @brief Returns the amount of flops that remain to be done */ double Io::get_remaining() const { -- 2.20.1