From: SUTER Frederic Date: Sat, 30 Oct 2021 10:48:54 +0000 (+0200) Subject: add user friendly wrapper to set priorities on I/Os X-Git-Tag: v3.30~286 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/0222476e8bed5bf150cdedad39b97424d8d39d21 add user friendly wrapper to set priorities on I/Os --- diff --git a/examples/cpp/io-priority/s4u-io-priority.cpp b/examples/cpp/io-priority/s4u-io-priority.cpp index 1c8f4785ec..5c03a19b20 100644 --- a/examples/cpp/io-priority/s4u-io-priority.cpp +++ b/examples/cpp/io-priority/s4u-io-priority.cpp @@ -29,7 +29,7 @@ static void privileged_writer() * Since the priority is 2, it writes twice as fast as a regular one. * * 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(); + disk_list.front()->write(4000000, 2); XBT_INFO("First write done."); /* Note that the timings printed when running this example are a bit misleading, because the uneven sharing only last diff --git a/include/simgrid/s4u/Disk.hpp b/include/simgrid/s4u/Disk.hpp index 68740d13e8..736476367e 100644 --- a/include/simgrid/s4u/Disk.hpp +++ b/include/simgrid/s4u/Disk.hpp @@ -84,9 +84,11 @@ public: IoPtr read_async(sg_size_t size) const; sg_size_t read(sg_size_t size) const; + sg_size_t read(sg_size_t size, double priority) const; IoPtr write_async(sg_size_t size) const; sg_size_t write(sg_size_t size) const; + sg_size_t write(sg_size_t size, double priority) const; /** @brief Policy for sharing the disk among activities */ enum class SharingPolicy { NONLINEAR = 1, LINEAR = 0 }; diff --git a/src/bindings/python/simgrid_python.cpp b/src/bindings/python/simgrid_python.cpp index 7b5efdb41e..7530f38fc9 100644 --- a/src/bindings/python/simgrid_python.cpp +++ b/src/bindings/python/simgrid_python.cpp @@ -284,8 +284,10 @@ PYBIND11_MODULE(simgrid, m) /* Class Disk */ py::class_> disk(m, "Disk", "Simulated disk"); - disk.def("read", &simgrid::s4u::Disk::read, py::call_guard(), "Read data from disk") - .def("write", &simgrid::s4u::Disk::write, py::call_guard(), "Write data in disk") + disk.def("read", py::overload_cast(&simgrid::s4u::Disk::read, py::const_), + py::call_guard(), "Read data from disk", py::arg("size"), py::arg("priority") = 1) + .def("write", py::overload_cast(&simgrid::s4u::Disk::write, py::const_), + py::call_guard(), "Write data in disk", py::arg("size"), py::arg("priority") = 1) .def("read_async", &simgrid::s4u::Disk::read_async, py::call_guard(), "Non-blocking read data from disk") .def("write_async", &simgrid::s4u::Disk::write_async, py::call_guard(), diff --git a/src/s4u/s4u_Disk.cpp b/src/s4u/s4u_Disk.cpp index c64af72c22..5793eb5b0f 100644 --- a/src/s4u/s4u_Disk.cpp +++ b/src/s4u/s4u_Disk.cpp @@ -126,6 +126,15 @@ sg_size_t Disk::read(sg_size_t size) const return IoPtr(io_init(size, Io::OpType::READ))->vetoable_start()->wait()->get_performed_ioops(); } +sg_size_t Disk::read(sg_size_t size, double priority) const +{ + return IoPtr(io_init(size, Io::OpType::READ)) + ->set_priority(priority) + ->vetoable_start() + ->wait() + ->get_performed_ioops(); +} + IoPtr Disk::write_async(sg_size_t size) const { return IoPtr(io_init(size, Io::OpType::WRITE)->vetoable_start()); @@ -136,6 +145,15 @@ sg_size_t Disk::write(sg_size_t size) const return IoPtr(io_init(size, Io::OpType::WRITE))->vetoable_start()->wait()->get_performed_ioops(); } +sg_size_t Disk::write(sg_size_t size, double priority) const +{ + return IoPtr(io_init(size, Io::OpType::WRITE)) + ->set_priority(priority) + ->vetoable_start() + ->wait() + ->get_performed_ioops(); +} + Disk* Disk::set_sharing_policy(Disk::Operation op, Disk::SharingPolicy policy, const NonLinearResourceCb& cb) { kernel::actor::simcall([this, op, policy, &cb] { pimpl_->set_sharing_policy(op, policy, cb); });