From: Fred Suter Date: Fri, 28 Oct 2022 11:36:22 +0000 (-0400) Subject: introduce s4u::Io::streamto X-Git-Tag: v3.34~717^2^2~8 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/7128ce31a27a36d8d666e428ea399acb3020ae9e?ds=sidebyside introduce s4u::Io::streamto --- diff --git a/include/simgrid/s4u/Io.hpp b/include/simgrid/s4u/Io.hpp index c3118c357d..81dafc905b 100644 --- a/include/simgrid/s4u/Io.hpp +++ b/include/simgrid/s4u/Io.hpp @@ -50,6 +50,13 @@ public: IoPtr set_size(sg_size_t size); IoPtr set_op_type(OpType type); + static IoPtr streamto_init(Host* from, Disk* from_disk, Host* to, Disk* to_disk); + static IoPtr streamto_async(Host* from, Disk* from_disk, Host* to, Disk* to_disk, uint64_t simulated_size_in_bytes); + static void streamto(Host* from, Disk* from_disk, Host* to, Disk* to_disk, uint64_t simulated_size_in_bytes); + + IoPtr set_source(Host* from, Disk* from_disk); + IoPtr set_destination(Host* to, Disk* to_disk); + 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 8f18e6db44..339b91a4b4 100644 --- a/src/kernel/activity/IoImpl.cpp +++ b/src/kernel/activity/IoImpl.cpp @@ -15,6 +15,7 @@ #include "src/kernel/resource/CpuImpl.hpp" #include "src/kernel/resource/DiskImpl.hpp" #include "src/mc/mc_replay.hpp" +#include "src/surf/HostImpl.hpp" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_io, kernel, "Kernel io-related synchronization"); @@ -69,13 +70,40 @@ IoImpl& IoImpl::set_disk(resource::DiskImpl* disk) return *this; } +IoImpl& IoImpl::set_host(s4u::Host* host) +{ + host_ = host; + return *this; +} + +IoImpl& IoImpl::set_dst_disk(resource::DiskImpl* disk) +{ + dst_disk_ = disk; + return *this; +} + +IoImpl& IoImpl::set_dst_host(s4u::Host* host) +{ + dst_host_ = host; + return *this; +} + IoImpl* IoImpl::start() { set_state(State::RUNNING); - surf_action_ = disk_->io_start(size_, type_); - surf_action_->set_sharing_penalty(sharing_penalty_); + if (dst_host_ == nullptr) { + XBT_DEBUG("Starting regular I/O"); + surf_action_ = disk_->io_start(size_, type_); + surf_action_->set_sharing_penalty(sharing_penalty_); + } else { + XBT_DEBUG("Starting streaming I/O"); + auto host_model = dst_host_->get_netpoint()->get_englobing_zone()->get_host_model(); + surf_action_ = host_model->io_stream(host_, disk_, dst_host_, dst_disk_, size_); + } + surf_action_->set_activity(this); set_start_time(surf_action_->get_start_time()); +#include "src/surf/HostImpl.hpp" XBT_DEBUG("Create IO synchro %p %s", this, get_cname()); diff --git a/src/kernel/activity/IoImpl.hpp b/src/kernel/activity/IoImpl.hpp index 399775bfca..d22447c61b 100644 --- a/src/kernel/activity/IoImpl.hpp +++ b/src/kernel/activity/IoImpl.hpp @@ -12,7 +12,10 @@ namespace simgrid::kernel::activity { class XBT_PUBLIC IoImpl : public ActivityImpl_T { + s4u::Host* host_ = nullptr; resource::DiskImpl* disk_ = nullptr; + s4u::Host* dst_host_ = nullptr; + resource::DiskImpl* dst_disk_ = nullptr; double sharing_penalty_ = 1.0; sg_size_t size_ = 0; s4u::Io::OpType type_ = s4u::Io::OpType::READ; @@ -27,6 +30,11 @@ public: IoImpl& set_size(sg_size_t size); IoImpl& set_type(s4u::Io::OpType type); IoImpl& set_disk(resource::DiskImpl* disk); + IoImpl& set_host(s4u::Host* host); + s4u::Host* get_host() const { return host_; } + IoImpl& set_dst_disk(resource::DiskImpl* disk); + IoImpl& set_dst_host(s4u::Host* host); + s4u::Host* get_dst_host() const { return dst_host_; } IoImpl& update_sharing_penalty(double sharing_penalty); diff --git a/src/s4u/s4u_Io.cpp b/src/s4u/s4u_Io.cpp index 906b0bee2d..134a423e7b 100644 --- a/src/s4u/s4u_Io.cpp +++ b/src/s4u/s4u_Io.cpp @@ -11,6 +11,8 @@ #include "src/kernel/actor/ActorImpl.hpp" #include "src/kernel/actor/SimcallObserver.hpp" +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_io, s4u_activity, "S4U asynchronous I/Os"); + namespace simgrid::s4u { xbt::signal Io::on_start; @@ -25,6 +27,59 @@ IoPtr Io::init() return IoPtr(static_cast(pimpl->get_iface())); } +IoPtr Io::streamto_init(Host* from, Disk* from_disk, Host* to, Disk* to_disk) +{ + auto res = Io::init()->set_source(from, from_disk)->set_destination(to, to_disk); + res->set_state(State::STARTING); + return res; +} + +IoPtr Io::streamto_async(Host* from, Disk* from_disk, Host* to, Disk* to_disk, uint64_t simulated_size_in_bytes) +{ + return Io::init()->set_size(simulated_size_in_bytes)->set_source(from, from_disk)->set_destination(to, to_disk); +} + +void Io::streamto(Host* from, Disk* from_disk, Host* to, Disk* to_disk, uint64_t simulated_size_in_bytes) +{ + streamto_async(from, from_disk, to, to_disk, simulated_size_in_bytes)->wait(); +} + +IoPtr Io::set_source(Host* from, Disk* from_disk) +{ + xbt_assert(state_ == State::INITED || state_ == State::STARTING, + "Cannot change the source of an IO stream once it's started (state: %s)", to_c_str(state_)); + kernel::actor::simcall_answered( + [this, from, from_disk] { + boost::static_pointer_cast(pimpl_)->set_host(from); + boost::static_pointer_cast(pimpl_)->set_disk(from_disk->get_impl()); + }); + // Setting 'source' may allow to start the activity, let's try + if (state_ == State::STARTING && remains_ <= 0) + XBT_DEBUG("This IO has a size of 0 byte. It cannot start yet"); + else + vetoable_start(); + + return this; +} + +IoPtr Io::set_destination(Host* to, Disk* to_disk) +{ + xbt_assert(state_ == State::INITED || state_ == State::STARTING, + "Cannot change the source of an IO stream once it's started (state: %s)", to_c_str(state_)); + kernel::actor::simcall_answered( + [this, to, to_disk] { + boost::static_pointer_cast(pimpl_)->set_dst_host(to); + boost::static_pointer_cast(pimpl_)->set_dst_disk(to_disk->get_impl()); + }); + // Setting 'destination' may allow to start the activity, let's try + if (state_ == State::STARTING && remains_ <= 0) + XBT_DEBUG("This IO has a size of 0 byte. It cannot start yet"); + else + vetoable_start(); + + return this; +} + Io* Io::start() { kernel::actor::simcall_answered( @@ -109,7 +164,11 @@ sg_size_t Io::get_performed_ioops() const bool Io::is_assigned() const { - return boost::static_pointer_cast(pimpl_)->get_disk() != nullptr; + if (boost::static_pointer_cast(pimpl_)->get_host() == nullptr) { + return boost::static_pointer_cast(pimpl_)->get_disk() != nullptr; + } else { + return boost::static_pointer_cast(pimpl_)->get_dst_host() != nullptr; + } } } // namespace simgrid::s4u