From: Frederic Suter Date: Wed, 8 Aug 2018 07:17:37 +0000 (+0200) Subject: add the Storage::read_async and Storage::write_async methods X-Git-Tag: v3_21~266^2~13 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/9fd6cbc6c3b06f4b09e3c3339ffb3cc8a68f9bfa add the Storage::read_async and Storage::write_async methods also add the corresponding io-async example --- diff --git a/ChangeLog b/ChangeLog index f556726820..39946e8de7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,18 @@ SimGrid (3.21) NOT RELEASED (Release Target: September 23. 2018, 1:54 UTC) +S4U new features: + - s4u::Io: IOs go asynchronous as activities. This comes with new methods in the + s4u::Storage class: + - io_init(sg_size_t, s4u::Io::OpType) to create a READ or WRITE asynchronous + IO operations that can be started, waited for, or canceled as a regular + activity. + - read_async(sg_size_t) and write_async(sg_size_t) which are wrappers on + io_init() + start() + Tracing: - Rename 'power' and 'power_used' variables into 'speed' and 'speed_used' - New host variable: 'core_count' - + XBT: - Remove xbt_os_thread_specific features - Remove portability wrapper to condition variables diff --git a/examples/s4u/CMakeLists.txt b/examples/s4u/CMakeLists.txt index 785bef9347..c8a987ec4f 100644 --- a/examples/s4u/CMakeLists.txt +++ b/examples/s4u/CMakeLists.txt @@ -8,7 +8,7 @@ foreach (example actor-create actor-daemon actor-join actor-kill energy-exec energy-boot energy-link energy-vm engine-filtering exec-async exec-basic exec-dvfs exec-monitor exec-ptask exec-remote - io-file-system io-file-remote io-storage-raw + io-async io-file-system io-file-remote io-storage-raw mutex platform-failures platform-properties plugin-hostload replay-comm replay-storage @@ -103,7 +103,7 @@ foreach(example actor-create actor-daemon actor-join actor-kill engine-filtering exec-async exec-basic exec-dvfs exec-monitor exec-ptask exec-remote platform-properties plugin-hostload mutex - io-file-system io-file-remote io-storage-raw + io-async io-file-system io-file-remote io-storage-raw replay-comm replay-storage routing-get-clusters ) diff --git a/examples/s4u/io-async/s4u-io-async.cpp b/examples/s4u/io-async/s4u-io-async.cpp new file mode 100644 index 0000000000..7b40346f80 --- /dev/null +++ b/examples/s4u/io-async/s4u-io-async.cpp @@ -0,0 +1,47 @@ +/* Copyright (c) 2007-2018. The SimGrid Team. All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + +#include "simgrid/s4u.hpp" + +XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example"); + +static void test(sg_size_t size) +{ + simgrid::s4u::Storage* storage = simgrid::s4u::Storage::by_name("Disk1"); + XBT_INFO("Hello! read %llu bytes from Storage %s", size, storage->get_cname()); + + simgrid::s4u::IoPtr activity = storage->io_init(size, simgrid::s4u::Io::OpType::READ); + activity->start(); + activity->wait(); + + XBT_INFO("Goodbye now!"); +} + +static void test_cancel(sg_size_t size) +{ + simgrid::s4u::Storage* storage = simgrid::s4u::Storage::by_name("Disk2"); + XBT_INFO("Hello! write %llu bytes from Storage %s", size, storage->get_cname()); + + simgrid::s4u::IoPtr activity = storage->write_async(size); + simgrid::s4u::this_actor::sleep_for(0.5); + XBT_INFO("I changed my mind, cancel!"); + activity->cancel(); + + XBT_INFO("Goodbye now!"); +} + +int main(int argc, char* argv[]) +{ + simgrid::s4u::Engine e(&argc, argv); + e.load_platform(argv[1]); + simgrid::s4u::Actor::create("test", simgrid::s4u::Host::by_name("bob"), test, 2e7); + simgrid::s4u::Actor::create("test_cancel", simgrid::s4u::Host::by_name("alice"), test_cancel, 5e7); + + e.run(); + + XBT_INFO("Simulation time %g", e.get_clock()); + + return 0; +} diff --git a/examples/s4u/io-async/s4u-io-async.tesh b/examples/s4u/io-async/s4u-io-async.tesh new file mode 100644 index 0000000000..3a32addb26 --- /dev/null +++ b/examples/s4u/io-async/s4u-io-async.tesh @@ -0,0 +1,9 @@ +#!/usr/bin/env tesh + +$ $SG_TEST_EXENV ${bindir:=.}/s4u-io-async$EXEEXT ${platfdir}/storage/storage.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" +> [ 0.000000] (1:test@bob) Hello! read 20000000 bytes from Storage Disk1 +> [ 0.000000] (2:test_cancel@alice) Hello! write 50000000 bytes from Storage Disk2 +> [ 0.200000] (1:test@bob) Goodbye now! +> [ 0.500000] (2:test_cancel@alice) I changed my mind, cancel! +> [ 0.500000] (2:test_cancel@alice) Goodbye now! +> [ 0.500000] (0:maestro@) Simulation time 0.5 diff --git a/include/simgrid/s4u/Storage.hpp b/include/simgrid/s4u/Storage.hpp index 956a664e6d..b807c7fa3f 100644 --- a/include/simgrid/s4u/Storage.hpp +++ b/include/simgrid/s4u/Storage.hpp @@ -65,7 +65,10 @@ public: IoPtr io_init(sg_size_t size, s4u::Io::OpType type); + IoPtr read_async(sg_size_t size); sg_size_t read(sg_size_t size); + + IoPtr write_async(sg_size_t size); sg_size_t write(sg_size_t size); surf::StorageImpl* get_impl() { return pimpl_; } diff --git a/src/s4u/s4u_Storage.cpp b/src/s4u/s4u_Storage.cpp index aba158e313..b1e3e714ae 100644 --- a/src/s4u/s4u_Storage.cpp +++ b/src/s4u/s4u_Storage.cpp @@ -63,6 +63,14 @@ IoPtr Storage::io_init(sg_size_t size, Io::OpType type) return res; } +IoPtr Storage::read_async(sg_size_t size) +{ + + IoPtr res = io_init(size, Io::OpType::READ); + res->start(); + return res; +} + sg_size_t Storage::read(sg_size_t size) { IoPtr i = io_init(size, Io::OpType::READ); @@ -70,6 +78,14 @@ sg_size_t Storage::read(sg_size_t size) return i->get_performed_ioops(); } +IoPtr Storage::write_async(sg_size_t size) +{ + + IoPtr res = io_init(size, Io::OpType::WRITE); + res->start(); + return res; +} + sg_size_t Storage::write(sg_size_t size) { IoPtr i = io_init(size, Io::OpType::WRITE);