Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add the Storage::read_async and Storage::write_async methods
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Wed, 8 Aug 2018 07:17:37 +0000 (09:17 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Wed, 8 Aug 2018 08:31:59 +0000 (10:31 +0200)
also add the corresponding io-async example

ChangeLog
examples/s4u/CMakeLists.txt
examples/s4u/io-async/s4u-io-async.cpp [new file with mode: 0644]
examples/s4u/io-async/s4u-io-async.tesh [new file with mode: 0644]
include/simgrid/s4u/Storage.hpp
src/s4u/s4u_Storage.cpp

index f556726..39946e8 100644 (file)
--- 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
index 785bef9..c8a987e 100644 (file)
@@ -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 (file)
index 0000000..7b40346
--- /dev/null
@@ -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 (file)
index 0000000..3a32add
--- /dev/null
@@ -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
index 956a664..b807c7f 100644 (file)
@@ -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_; }
 
index aba158e..b1e3e71 100644 (file)
@@ -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);