1 /* Copyright (c) 2017-2023. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #ifndef SIMGRID_S4U_IO_HPP
7 #define SIMGRID_S4U_IO_HPP
9 #include <simgrid/forward.h>
10 #include <simgrid/s4u/Activity.hpp>
17 /** I/O Activity, representing the asynchronous disk access.
19 * They are generated from Disk::io_init(), Disk::read() Disk::read_async(), Disk::write() and Disk::write_async().
22 class XBT_PUBLIC Io : public Activity_T<Io> {
24 friend kernel::activity::IoImpl;
25 friend kernel::EngineImpl;
28 static xbt::signal<void(Io const&)> on_start;
31 explicit Io(kernel::activity::IoImplPtr pimpl);
32 Io* do_start() override;
35 enum class OpType { READ, WRITE };
37 static void on_start_cb(const std::function<void(Io const&)>& cb) { on_start.connect(cb); }
38 void fire_this_completion() const { on_completion(*this); }
41 /*! take a vector of s4u::IoPtr and return when one of them is finished.
42 * The return value is the rank of the first finished IoPtr. */
43 static ssize_t wait_any(const std::vector<IoPtr>& ios) { return wait_any_for(ios, -1); }
44 /*! Same as wait_any, but with a timeout. If the timeout occurs, parameter last is returned.*/
45 static ssize_t wait_any_for(const std::vector<IoPtr>& ios, double timeout);
47 double get_remaining() const override;
48 sg_size_t get_performed_ioops() const;
49 IoPtr set_disk(const_sg_disk_t disk);
50 IoPtr set_priority(double priority);
51 IoPtr set_size(sg_size_t size);
52 IoPtr set_op_type(OpType type);
54 static IoPtr streamto_init(Host* from, const Disk* from_disk, Host* to, const Disk* to_disk);
55 static IoPtr streamto_async(Host* from, const Disk* from_disk, Host* to, const Disk* to_disk,
56 uint64_t simulated_size_in_bytes);
57 static void streamto(Host* from, const Disk* from_disk, Host* to, const Disk* to_disk,
58 uint64_t simulated_size_in_bytes);
60 IoPtr set_source(Host* from, const Disk* from_disk);
61 IoPtr set_destination(Host* to, const Disk* to_disk);
63 IoPtr update_priority(double priority);
65 bool is_assigned() const override;
69 } // namespace simgrid
71 #endif /* SIMGRID_S4U_IO_HPP */