Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of framagit.org:simgrid/simgrid
authorMartin Quinson <martin.quinson@loria.fr>
Fri, 3 Aug 2018 21:38:32 +0000 (23:38 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Fri, 3 Aug 2018 21:38:32 +0000 (23:38 +0200)
22 files changed:
include/simgrid/forward.h
include/simgrid/s4u/Activity.hpp
include/simgrid/s4u/Io.hpp [new file with mode: 0644]
include/simgrid/s4u/Storage.hpp
include/simgrid/simix.h
src/kernel/activity/IoImpl.cpp
src/kernel/activity/IoImpl.hpp
src/s4u/s4u_Io.cpp [new file with mode: 0644]
src/s4u/s4u_Storage.cpp
src/simix/ActorImpl.cpp
src/simix/libsmx.cpp
src/simix/popping_accessors.hpp
src/simix/popping_bodies.cpp
src/simix/popping_enum.h
src/simix/popping_generated.cpp
src/simix/simcalls.in
src/simix/smx_io.cpp
src/simix/smx_io_private.hpp
src/surf/StorageImpl.hpp
src/surf/storage_n11.cpp
src/surf/storage_n11.hpp
tools/cmake/DefinePackages.cmake

index 19e0b5b..0d07099 100644 (file)
@@ -31,6 +31,10 @@ using ExecPtr = boost::intrusive_ptr<Exec>;
 XBT_PUBLIC void intrusive_ptr_release(Exec* e);
 XBT_PUBLIC void intrusive_ptr_add_ref(Exec* e);
 class Host;
+class Io;
+using IoPtr = boost::intrusive_ptr<Io>;
+XBT_PUBLIC void intrusive_ptr_release(Io* i);
+XBT_PUBLIC void intrusive_ptr_add_ref(Io* i);
 class Link;
 class Mailbox;
 using MailboxPtr = boost::intrusive_ptr<Mailbox>;
index 7e53d03..615f7bb 100644 (file)
@@ -33,6 +33,9 @@ class XBT_PUBLIC Activity {
   friend Exec;
   friend XBT_PUBLIC void intrusive_ptr_release(Exec * e);
   friend XBT_PUBLIC void intrusive_ptr_add_ref(Exec * e);
+  friend Io;
+  friend XBT_PUBLIC void intrusive_ptr_release(Io* i);
+  friend XBT_PUBLIC void intrusive_ptr_add_ref(Io* i);
 
 protected:
   Activity()  = default;
diff --git a/include/simgrid/s4u/Io.hpp b/include/simgrid/s4u/Io.hpp
new file mode 100644 (file)
index 0000000..6052171
--- /dev/null
@@ -0,0 +1,46 @@
+/* Copyright (c) 2017-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. */
+
+#ifndef SIMGRID_S4U_IO_HPP
+#define SIMGRID_S4U_IO_HPP
+
+#include <simgrid/forward.h>
+#include <simgrid/s4u/Activity.hpp>
+
+#include <atomic>
+
+namespace simgrid {
+namespace s4u {
+
+class XBT_PUBLIC Io : public Activity {
+  explicit Io(sg_size_t size) : Activity(), size_(size) {}
+public:
+  friend XBT_PUBLIC void intrusive_ptr_release(simgrid::s4u::Io* i);
+  friend XBT_PUBLIC void intrusive_ptr_add_ref(simgrid::s4u::Io* i);
+  friend Storage; // Factory of IOs
+
+  enum class OpType { READ, WRITE };
+  ~Io() = default;
+
+  Activity* start() override;
+  Activity* wait() override;
+  Activity* wait(double timeout) override;
+  Activity* cancel() override;
+
+  double get_remaining() override;
+  sg_size_t get_performed_ioops();
+  IoPtr set_io_type(OpType type);
+
+private:
+  sg_size_t size_       = 0;
+  sg_storage_t storage_ = nullptr;
+  std::string name_     = "";
+  OpType type_          = OpType::READ;
+  std::atomic_int_fast32_t refcount_{0};
+}; // class
+}
+}; // Namespace simgrid::s4u
+
+#endif /* SIMGRID_S4U_IO_HPP */
index bd6b092..1b1bb5d 100644 (file)
@@ -9,6 +9,7 @@
 #include <simgrid/forward.h>
 #include <xbt/Extendable.hpp>
 #include <xbt/base.h>
+#include <xbt/signal.hpp>
 
 #include <map>
 #include <string>
@@ -25,6 +26,7 @@ XBT_ATTRIB_DEPRECATED_v322("Please use Engine::get_all_storages()") XBT_PUBLIC v
 
 class XBT_PUBLIC Storage : public simgrid::xbt::Extendable<Storage> {
   friend s4u::Engine;
+  friend s4u::Io;
   friend simgrid::surf::StorageImpl;
 
 public:
@@ -32,7 +34,6 @@ public:
 
 protected:
   virtual ~Storage() = default;
-
 public:
   /** @brief Callback signal fired when a new Storage is created */
   static simgrid::xbt::signal<void(s4u::Storage&)> on_creation;
@@ -61,6 +62,8 @@ public:
   void set_data(void* data) { userdata_ = data; }
   void* get_data() { return userdata_; }
 
+  IoPtr io_init(sg_size_t size);
+
   sg_size_t read(sg_size_t size);
   sg_size_t write(sg_size_t size);
   surf::StorageImpl* get_impl() { return pimpl_; }
index 4f5047b..0331d6b 100644 (file)
@@ -285,9 +285,8 @@ XBT_PUBLIC void SIMIX_sem_destroy(smx_sem_t sem);
 XBT_PUBLIC void simcall_sem_acquire(smx_sem_t sem);
 XBT_PUBLIC int simcall_sem_acquire_timeout(smx_sem_t sem, double max_duration);
 
-/*****************************   Storage   **********************************/
-XBT_PUBLIC sg_size_t simcall_storage_read(surf_storage_t st, sg_size_t size);
-XBT_PUBLIC sg_size_t simcall_storage_write(surf_storage_t fd, sg_size_t size);
+/*****************************   Io   **************************************/
+XBT_PUBLIC e_smx_state_t simcall_io_wait(smx_activity_t io);
 /************************** MC simcalls   **********************************/
 XBT_PUBLIC int simcall_mc_random(int min, int max);
 
index eb61b83..d762815 100644 (file)
@@ -7,6 +7,32 @@
 #include "simgrid/kernel/resource/Action.hpp"
 #include "src/simix/smx_io_private.hpp"
 
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_io);
+
+simgrid::kernel::activity::IoImpl::IoImpl(std::string name, resource::Action* surf_action, s4u::Storage* storage)
+    : ActivityImpl(name), storage_(storage), surf_action_(surf_action)
+{
+  this->state_ = SIMIX_RUNNING;
+
+  surf_action_->set_data(this);
+
+  XBT_DEBUG("Create io %p", this);
+}
+
+simgrid::kernel::activity::IoImpl::~IoImpl()
+{
+  if (surf_action_ != nullptr)
+    surf_action_->unref();
+  XBT_DEBUG("Destroy io %p", this);
+}
+
+void simgrid::kernel::activity::IoImpl::cancel()
+{
+  XBT_VERB("This exec %p is canceled", this);
+  if (surf_action_ != nullptr)
+    surf_action_->cancel();
+}
+
 void simgrid::kernel::activity::IoImpl::suspend()
 {
   if (surf_action_ != nullptr)
@@ -19,21 +45,14 @@ void simgrid::kernel::activity::IoImpl::resume()
     surf_action_->resume();
 }
 
-void simgrid::kernel::activity::IoImpl::post()
+double simgrid::kernel::activity::IoImpl::get_remaining()
 {
-  for (smx_simcall_t const& simcall : simcalls_) {
-    switch (simcall->call) {
-      case SIMCALL_STORAGE_WRITE:
-        simcall_storage_write__set__result(simcall, surf_action_->get_cost());
-        break;
-      case SIMCALL_STORAGE_READ:
-        simcall_storage_read__set__result(simcall, surf_action_->get_cost());
-        break;
-      default:
-        break;
-    }
-  }
+  return surf_action_ ? surf_action_->get_remains() : 0;
+}
 
+void simgrid::kernel::activity::IoImpl::post()
+{
+  performed_ioops_ = surf_action_->get_cost();
   switch (surf_action_->get_state()) {
     case simgrid::kernel::resource::Action::State::FAILED:
       state_ = SIMIX_FAILED;
@@ -45,6 +64,12 @@ void simgrid::kernel::activity::IoImpl::post()
       THROW_IMPOSSIBLE;
       break;
   }
+  on_completion(this);
 
   SIMIX_io_finish(this);
 }
+/*************
+ * Callbacks *
+ *************/
+simgrid::xbt::signal<void(simgrid::kernel::activity::IoImplPtr)> simgrid::kernel::activity::IoImpl::on_creation;
+simgrid::xbt::signal<void(simgrid::kernel::activity::IoImplPtr)> simgrid::kernel::activity::IoImpl::on_completion;
index 71f1a45..59ec127 100644 (file)
@@ -15,11 +15,21 @@ namespace activity {
 
 class XBT_PUBLIC IoImpl : public ActivityImpl {
 public:
+  ~IoImpl() override;
+  explicit IoImpl(std::string name, resource::Action* surf_action, s4u::Storage* storage);
+
   void suspend() override;
   void resume() override;
   void post() override;
+  void cancel();
+  double get_remaining();
+  sg_size_t get_performed_ioops() { return performed_ioops_; }
 
+  s4u::Storage* storage_                          = nullptr;
   simgrid::kernel::resource::Action* surf_action_ = nullptr;
+  sg_size_t performed_ioops_                      = 0;
+  static simgrid::xbt::signal<void(kernel::activity::IoImplPtr)> on_creation;
+  static simgrid::xbt::signal<void(kernel::activity::IoImplPtr)> on_completion;
 };
 }
 }
diff --git a/src/s4u/s4u_Io.cpp b/src/s4u/s4u_Io.cpp
new file mode 100644 (file)
index 0000000..88d78a7
--- /dev/null
@@ -0,0 +1,78 @@
+/* Copyright (c) 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/Io.hpp"
+#include "simgrid/s4u/Storage.hpp"
+#include "src/kernel/activity/IoImpl.hpp"
+#include "src/simix/smx_io_private.hpp"
+#include "xbt/log.h"
+
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_io, s4u_activity, "S4U asynchronous IOs");
+
+namespace simgrid {
+namespace s4u {
+
+Activity* Io::start()
+{
+  set_remaining(size_);
+  pimpl_ = simix::simcall([this] { return SIMIX_io_start(name_, size_, storage_, type_); });
+  state_ = State::STARTED;
+  return this;
+}
+
+Activity* Io::cancel()
+{
+  simgrid::simix::simcall([this] { dynamic_cast<kernel::activity::IoImpl*>(pimpl_.get())->cancel(); });
+  state_ = State::CANCELED;
+  return this;
+}
+
+Activity* Io::wait()
+{
+  simcall_io_wait(pimpl_);
+  state_ = State::FINISHED;
+  return this;
+}
+
+Activity* Io::wait(double timeout)
+{
+  THROW_UNIMPLEMENTED;
+  return this;
+}
+
+/** @brief Returns the amount of flops that remain to be done */
+double Io::get_remaining()
+{
+  return simgrid::simix::simcall(
+      [this]() { return boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_)->get_remaining(); });
+}
+
+sg_size_t Io::get_performed_ioops()
+{
+  return simgrid::simix::simcall(
+      [this]() { return boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_)->get_performed_ioops(); });
+}
+
+IoPtr Io::set_io_type(OpType type)
+{
+  xbt_assert(state_ == State::INITED, "Cannot change the name of an exec after its start");
+  type_ = type;
+  return this;
+}
+
+void intrusive_ptr_release(simgrid::s4u::Io* i)
+{
+  if (i->refcount_.fetch_sub(1, std::memory_order_release) == 1) {
+    std::atomic_thread_fence(std::memory_order_acquire);
+    delete i;
+  }
+}
+
+void intrusive_ptr_add_ref(simgrid::s4u::Io* i)
+{
+  i->refcount_.fetch_add(1, std::memory_order_relaxed);
+}
+} // namespace s4u
+} // namespace simgrid
index 84319d8..d1b2aa5 100644 (file)
@@ -5,6 +5,7 @@
 
 #include "simgrid/s4u/Engine.hpp"
 #include "simgrid/s4u/Host.hpp"
+#include "simgrid/s4u/Io.hpp"
 #include "simgrid/s4u/Storage.hpp"
 #include "simgrid/storage.h"
 #include "src/surf/StorageImpl.hpp"
@@ -55,14 +56,27 @@ void Storage::set_property(std::string key, std::string value)
   simgrid::simix::simcall([this, key, value] { this->pimpl_->set_property(key, value); });
 }
 
+IoPtr Storage::io_init(sg_size_t size)
+{
+  IoPtr res     = IoPtr(new Io(size));
+  res->storage_ = this;
+  return res;
+}
+
 sg_size_t Storage::read(sg_size_t size)
 {
-  return simcall_storage_read(pimpl_, size);
+  IoPtr i = io_init(size);
+  i->set_io_type(Io::OpType::READ);
+  i->start()->wait();
+  return i->get_performed_ioops();
 }
 
 sg_size_t Storage::write(sg_size_t size)
 {
-  return simcall_storage_write(pimpl_, size);
+  IoPtr i = io_init(size);
+  i->set_io_type(Io::OpType::WRITE);
+  i->start()->wait();
+  return i->get_performed_ioops();
 }
 
 // Deprecated functions
index 6aa8dfa..c27e6d0 100644 (file)
@@ -483,7 +483,7 @@ void SIMIX_process_kill(smx_actor_t process, smx_actor_t issuer) {
       SIMIX_synchro_stop_waiting(process, &process->simcall);
 
     } else if (io != nullptr) {
-      SIMIX_io_destroy(process->waiting_synchro);
+      delete io.get();
     } else {
       xbt_die("Unknown type of activity");
     }
@@ -547,7 +547,7 @@ void SIMIX_process_throw(smx_actor_t process, xbt_errcat_t cat, int value, const
     simgrid::kernel::activity::IoImplPtr io =
         boost::dynamic_pointer_cast<simgrid::kernel::activity::IoImpl>(process->waiting_synchro);
     if (io != nullptr) {
-      SIMIX_io_destroy(process->waiting_synchro);
+      delete io.get();
     }
   }
   process->waiting_synchro = nullptr;
index 51b08fa..68badd0 100644 (file)
 #include "src/kernel/activity/CommImpl.hpp"
 #include "src/kernel/activity/ConditionVariableImpl.hpp"
 #include "src/kernel/activity/ExecImpl.hpp"
+#include "src/kernel/activity/IoImpl.hpp"
 #include "src/kernel/activity/MutexImpl.hpp"
 #include "src/mc/mc_replay.hpp"
 #include "src/plugins/vm/VirtualMachineImpl.hpp"
 #include "src/simix/smx_host_private.hpp"
+#include "src/simix/smx_io_private.hpp"
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix);
 
@@ -466,14 +468,9 @@ int simcall_sem_acquire_timeout(smx_sem_t sem, double timeout)
   return simcall_BODY_sem_acquire_timeout(sem, timeout);
 }
 
-sg_size_t simcall_storage_read(surf_storage_t st, sg_size_t size)
+e_smx_state_t simcall_io_wait(smx_activity_t io)
 {
-  return simcall_BODY_storage_read(st, size);
-}
-
-sg_size_t simcall_storage_write(surf_storage_t st, sg_size_t size)
-{
-  return simcall_BODY_storage_write(st, size);
+  return (e_smx_state_t)simcall_BODY_io_wait(io);
 }
 
 void simcall_run_kernel(std::function<void()> const& code)
index 072cf55..5b2d81f 100644 (file)
@@ -987,76 +987,29 @@ static inline void simcall_sem_acquire_timeout__set__result(smx_simcall_t simcal
   simgrid::simix::marshal<int>(simcall->result, result);
 }
 
-static inline surf_storage_t simcall_storage_read__get__st(smx_simcall_t simcall)
-{
-  return simgrid::simix::unmarshal<surf_storage_t>(simcall->args[0]);
-}
-static inline surf_storage_t simcall_storage_read__getraw__st(smx_simcall_t simcall)
-{
-  return simgrid::simix::unmarshal_raw<surf_storage_t>(simcall->args[0]);
-}
-static inline void simcall_storage_read__set__st(smx_simcall_t simcall, surf_storage_t arg)
-{
-  simgrid::simix::marshal<surf_storage_t>(simcall->args[0], arg);
-}
-static inline sg_size_t simcall_storage_read__get__size(smx_simcall_t simcall)
-{
-  return simgrid::simix::unmarshal<sg_size_t>(simcall->args[1]);
-}
-static inline sg_size_t simcall_storage_read__getraw__size(smx_simcall_t simcall)
-{
-  return simgrid::simix::unmarshal_raw<sg_size_t>(simcall->args[1]);
-}
-static inline void simcall_storage_read__set__size(smx_simcall_t simcall, sg_size_t arg)
-{
-  simgrid::simix::marshal<sg_size_t>(simcall->args[1], arg);
-}
-static inline sg_size_t simcall_storage_read__get__result(smx_simcall_t simcall)
-{
-  return simgrid::simix::unmarshal<sg_size_t>(simcall->result);
-}
-static inline sg_size_t simcall_storage_read__getraw__result(smx_simcall_t simcall)
-{
-  return simgrid::simix::unmarshal_raw<sg_size_t>(simcall->result);
-}
-static inline void simcall_storage_read__set__result(smx_simcall_t simcall, sg_size_t result)
-{
-  simgrid::simix::marshal<sg_size_t>(simcall->result, result);
-}
-
-static inline surf_storage_t simcall_storage_write__get__st(smx_simcall_t simcall)
-{
-  return simgrid::simix::unmarshal<surf_storage_t>(simcall->args[0]);
-}
-static inline surf_storage_t simcall_storage_write__getraw__st(smx_simcall_t simcall)
-{
-  return simgrid::simix::unmarshal_raw<surf_storage_t>(simcall->args[0]);
-}
-static inline void simcall_storage_write__set__st(smx_simcall_t simcall, surf_storage_t arg)
-{
-  simgrid::simix::marshal<surf_storage_t>(simcall->args[0], arg);
-}
-static inline sg_size_t simcall_storage_write__get__size(smx_simcall_t simcall)
+static inline boost::intrusive_ptr<simgrid::kernel::activity::ActivityImpl>
+simcall_io_wait__get__io(smx_simcall_t simcall)
 {
-  return simgrid::simix::unmarshal<sg_size_t>(simcall->args[1]);
+  return simgrid::simix::unmarshal<boost::intrusive_ptr<simgrid::kernel::activity::ActivityImpl>>(simcall->args[0]);
 }
-static inline sg_size_t simcall_storage_write__getraw__size(smx_simcall_t simcall)
+static inline simgrid::kernel::activity::ActivityImpl* simcall_io_wait__getraw__io(smx_simcall_t simcall)
 {
-  return simgrid::simix::unmarshal_raw<sg_size_t>(simcall->args[1]);
+  return simgrid::simix::unmarshal_raw<simgrid::kernel::activity::ActivityImpl*>(simcall->args[0]);
 }
-static inline void simcall_storage_write__set__size(smx_simcall_t simcall, sg_size_t arg)
+static inline void simcall_io_wait__set__io(smx_simcall_t simcall,
+                                            boost::intrusive_ptr<simgrid::kernel::activity::ActivityImpl> arg)
 {
-  simgrid::simix::marshal<sg_size_t>(simcall->args[1], arg);
+  simgrid::simix::marshal<boost::intrusive_ptr<simgrid::kernel::activity::ActivityImpl>>(simcall->args[0], arg);
 }
-static inline sg_size_t simcall_storage_write__get__result(smx_simcall_t simcall)
+static inline sg_size_t simcall_io_wait__get__result(smx_simcall_t simcall)
 {
   return simgrid::simix::unmarshal<sg_size_t>(simcall->result);
 }
-static inline sg_size_t simcall_storage_write__getraw__result(smx_simcall_t simcall)
+static inline sg_size_t simcall_io_wait__getraw__result(smx_simcall_t simcall)
 {
   return simgrid::simix::unmarshal_raw<sg_size_t>(simcall->result);
 }
-static inline void simcall_storage_write__set__result(smx_simcall_t simcall, sg_size_t result)
+static inline void simcall_io_wait__set__result(smx_simcall_t simcall, sg_size_t result)
 {
   simgrid::simix::marshal<sg_size_t>(simcall->result, result);
 }
@@ -1149,6 +1102,6 @@ XBT_PRIVATE void simcall_HANDLER_cond_wait(smx_simcall_t simcall, smx_cond_t con
 XBT_PRIVATE void simcall_HANDLER_cond_wait_timeout(smx_simcall_t simcall, smx_cond_t cond, smx_mutex_t mutex, double timeout);
 XBT_PRIVATE void simcall_HANDLER_sem_acquire(smx_simcall_t simcall, smx_sem_t sem);
 XBT_PRIVATE void simcall_HANDLER_sem_acquire_timeout(smx_simcall_t simcall, smx_sem_t sem, double timeout);
-XBT_PRIVATE void simcall_HANDLER_storage_read(smx_simcall_t simcall, surf_storage_t st, sg_size_t size);
-XBT_PRIVATE void simcall_HANDLER_storage_write(smx_simcall_t simcall, surf_storage_t st, sg_size_t size);
+XBT_PRIVATE void simcall_HANDLER_io_wait(smx_simcall_t simcall,
+                                         boost::intrusive_ptr<simgrid::kernel::activity::ActivityImpl> io);
 XBT_PRIVATE int simcall_HANDLER_mc_random(smx_simcall_t simcall, int min, int max);
\ No newline at end of file
index e282a76..cfdeded 100644 (file)
@@ -184,18 +184,11 @@ inline static int simcall_BODY_sem_acquire_timeout(smx_sem_t sem, double timeout
   return simcall<int, smx_sem_t, double>(SIMCALL_SEM_ACQUIRE_TIMEOUT, sem, timeout);
 }
 
-inline static sg_size_t simcall_BODY_storage_read(surf_storage_t st, sg_size_t size)
+inline static sg_size_t simcall_BODY_io_wait(boost::intrusive_ptr<simgrid::kernel::activity::ActivityImpl> io)
 {
   if (0) /* Go to that function to follow the code flow through the simcall barrier */
-    simcall_HANDLER_storage_read(&SIMIX_process_self()->simcall, st, size);
-  return simcall<sg_size_t, surf_storage_t, sg_size_t>(SIMCALL_STORAGE_READ, st, size);
-}
-
-inline static sg_size_t simcall_BODY_storage_write(surf_storage_t st, sg_size_t size)
-{
-  if (0) /* Go to that function to follow the code flow through the simcall barrier */
-    simcall_HANDLER_storage_write(&SIMIX_process_self()->simcall, st, size);
-  return simcall<sg_size_t, surf_storage_t, sg_size_t>(SIMCALL_STORAGE_WRITE, st, size);
+    simcall_HANDLER_io_wait(&SIMIX_process_self()->simcall, io);
+  return simcall<sg_size_t, boost::intrusive_ptr<simgrid::kernel::activity::ActivityImpl>>(SIMCALL_IO_WAIT, io);
 }
 
 inline static int simcall_BODY_mc_random(int min, int max)
index 7305834..0c610a7 100644 (file)
@@ -40,8 +40,7 @@ typedef enum {
   SIMCALL_COND_WAIT_TIMEOUT,
   SIMCALL_SEM_ACQUIRE,
   SIMCALL_SEM_ACQUIRE_TIMEOUT,
-  SIMCALL_STORAGE_READ,
-  SIMCALL_STORAGE_WRITE,
+  SIMCALL_IO_WAIT,
   SIMCALL_MC_RANDOM,
   SIMCALL_RUN_KERNEL,
   SIMCALL_RUN_BLOCKING,
index e8875d3..a4a8133 100644 (file)
@@ -27,33 +27,13 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_popping);
 
 /** @brief Simcalls' names (generated from src/simix/simcalls.in) */
 const char* simcall_names[] = {
-    "SIMCALL_NONE",
-    "SIMCALL_PROCESS_SUSPEND",
-    "SIMCALL_PROCESS_JOIN",
-    "SIMCALL_PROCESS_SLEEP",
-    "SIMCALL_EXECUTION_WAIT",
-    "SIMCALL_EXECUTION_TEST",
-    "SIMCALL_COMM_IPROBE",
-    "SIMCALL_COMM_SEND",
-    "SIMCALL_COMM_ISEND",
-    "SIMCALL_COMM_RECV",
-    "SIMCALL_COMM_IRECV",
-    "SIMCALL_COMM_WAITANY",
-    "SIMCALL_COMM_WAIT",
-    "SIMCALL_COMM_TEST",
-    "SIMCALL_COMM_TESTANY",
-    "SIMCALL_MUTEX_LOCK",
-    "SIMCALL_MUTEX_TRYLOCK",
-    "SIMCALL_MUTEX_UNLOCK",
-    "SIMCALL_COND_WAIT",
-    "SIMCALL_COND_WAIT_TIMEOUT",
-    "SIMCALL_SEM_ACQUIRE",
-    "SIMCALL_SEM_ACQUIRE_TIMEOUT",
-    "SIMCALL_STORAGE_READ",
-    "SIMCALL_STORAGE_WRITE",
-    "SIMCALL_MC_RANDOM",
-    "SIMCALL_RUN_KERNEL",
-    "SIMCALL_RUN_BLOCKING",
+    "SIMCALL_NONE",           "SIMCALL_PROCESS_SUSPEND",     "SIMCALL_PROCESS_JOIN", "SIMCALL_PROCESS_SLEEP",
+    "SIMCALL_EXECUTION_WAIT", "SIMCALL_EXECUTION_TEST",      "SIMCALL_COMM_IPROBE",  "SIMCALL_COMM_SEND",
+    "SIMCALL_COMM_ISEND",     "SIMCALL_COMM_RECV",           "SIMCALL_COMM_IRECV",   "SIMCALL_COMM_WAITANY",
+    "SIMCALL_COMM_WAIT",      "SIMCALL_COMM_TEST",           "SIMCALL_COMM_TESTANY", "SIMCALL_MUTEX_LOCK",
+    "SIMCALL_MUTEX_TRYLOCK",  "SIMCALL_MUTEX_UNLOCK",        "SIMCALL_COND_WAIT",    "SIMCALL_COND_WAIT_TIMEOUT",
+    "SIMCALL_SEM_ACQUIRE",    "SIMCALL_SEM_ACQUIRE_TIMEOUT", "SIMCALL_IO_WAIT",      "SIMCALL_MC_RANDOM",
+    "SIMCALL_RUN_KERNEL",     "SIMCALL_RUN_BLOCKING",
 };
 
 /** @private
@@ -158,14 +138,10 @@ case SIMCALL_SEM_ACQUIRE_TIMEOUT:
   simcall_HANDLER_sem_acquire_timeout(simcall, simgrid::simix::unmarshal<smx_sem_t>(simcall->args[0]), simgrid::simix::unmarshal<double>(simcall->args[1]));
   break;
 
-case SIMCALL_STORAGE_READ:
-  simcall_HANDLER_storage_read(simcall, simgrid::simix::unmarshal<surf_storage_t>(simcall->args[0]),
-                               simgrid::simix::unmarshal<sg_size_t>(simcall->args[1]));
-  break;
-
-case SIMCALL_STORAGE_WRITE:
-  simcall_HANDLER_storage_write(simcall, simgrid::simix::unmarshal<surf_storage_t>(simcall->args[0]),
-                                simgrid::simix::unmarshal<sg_size_t>(simcall->args[1]));
+case SIMCALL_IO_WAIT:
+  simcall_HANDLER_io_wait(
+      simcall,
+      simgrid::simix::unmarshal<boost::intrusive_ptr<simgrid::kernel::activity::ActivityImpl>>(simcall->args[0]));
   break;
 
 case SIMCALL_MC_RANDOM:
index 7c26066..dff8503 100644 (file)
@@ -62,8 +62,7 @@ int        cond_wait_timeout(smx_cond_t cond, smx_mutex_t mutex, double timeout)
 void      sem_acquire(smx_sem_t sem) [[block]];
 int       sem_acquire_timeout(smx_sem_t sem, double timeout) [[block]];
 
-sg_size_t   storage_read(surf_storage_t st, sg_size_t size) [[block]];
-sg_size_t   storage_write(surf_storage_t st, sg_size_t size) [[block]];
+sg_size_t io_wait(boost::intrusive_ptr<simgrid::kernel::activity::ActivityImpl> io) [[block]];
 
 int        mc_random(int min, int max);
 
index f210733..98d4b23 100644 (file)
@@ -3,57 +3,52 @@
 /* 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 "mc/mc.h"
 #include "simgrid/s4u/Host.hpp"
+#include "simgrid/s4u/Io.hpp"
 #include "xbt/ex.hpp"
 
 #include "smx_private.hpp"
 #include "src/kernel/activity/IoImpl.hpp"
+#include "src/mc/mc_replay.hpp"
 #include "src/simix/smx_io_private.hpp"
 #include "src/surf/StorageImpl.hpp"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_io, simix, "Logging specific to SIMIX (io)");
 
-void simcall_HANDLER_storage_read(smx_simcall_t simcall, surf_storage_t st, sg_size_t size)
+simgrid::kernel::activity::IoImplPtr SIMIX_io_start(std::string name, sg_size_t size, sg_storage_t storage,
+                                                    simgrid::s4u::Io::OpType type)
 {
-  smx_activity_t synchro = SIMIX_storage_read(st, size);
-  synchro->simcalls_.push_back(simcall);
-  simcall->issuer->waiting_synchro = synchro;
-}
+  /* set surf's action */
+  simgrid::kernel::resource::Action* surf_action = storage->get_impl()->io_start(size, type);
 
-smx_activity_t SIMIX_storage_read(surf_storage_t st, sg_size_t size)
-{
-  simgrid::kernel::activity::IoImpl* synchro = new simgrid::kernel::activity::IoImpl();
-  synchro->surf_action_                      = st->read(size);
+  simgrid::kernel::activity::IoImplPtr io =
+      simgrid::kernel::activity::IoImplPtr(new simgrid::kernel::activity::IoImpl(name, surf_action, storage));
 
-  synchro->surf_action_->set_data(synchro);
-  XBT_DEBUG("Create io synchro %p", synchro);
+  XBT_DEBUG("Create IO synchro %p %s", io.get(), name.c_str());
+  simgrid::kernel::activity::IoImpl::on_creation(io);
 
-  return synchro;
+  return io;
 }
 
-void simcall_HANDLER_storage_write(smx_simcall_t simcall, surf_storage_t st, sg_size_t size)
+void simcall_HANDLER_io_wait(smx_simcall_t simcall, smx_activity_t synchro)
 {
-  smx_activity_t synchro = SIMIX_storage_write(st, size);
+  XBT_DEBUG("Wait for execution of synchro %p, state %d", synchro.get(), (int)synchro->state_);
+
+  /* Associate this simcall to the synchro */
   synchro->simcalls_.push_back(simcall);
   simcall->issuer->waiting_synchro = synchro;
-}
 
-smx_activity_t SIMIX_storage_write(surf_storage_t st, sg_size_t size)
-{
-  simgrid::kernel::activity::IoImpl* synchro = new simgrid::kernel::activity::IoImpl();
-  synchro->surf_action_                      = st->write(size);
-  synchro->surf_action_->set_data(synchro);
-  XBT_DEBUG("Create io synchro %p", synchro);
-
-  return synchro;
-}
+  /* set surf's synchro */
+  if (MC_is_active() || MC_record_replay_is_active()) {
+    synchro->state_ = SIMIX_DONE;
+    SIMIX_io_finish(synchro);
+    return;
+  }
 
-void SIMIX_io_destroy(smx_activity_t synchro)
-{
-  simgrid::kernel::activity::IoImplPtr io = boost::static_pointer_cast<simgrid::kernel::activity::IoImpl>(synchro);
-  XBT_DEBUG("Destroy synchro %p", synchro.get());
-  if (io->surf_action_)
-    io->surf_action_->unref();
+  /* If the synchro is already finished then perform the error handling */
+  if (synchro->state_ != SIMIX_RUNNING)
+    SIMIX_io_finish(synchro);
 }
 
 void SIMIX_io_finish(smx_activity_t synchro)
@@ -80,7 +75,4 @@ void SIMIX_io_finish(smx_activity_t synchro)
     simcall->issuer->waiting_synchro = nullptr;
     SIMIX_simcall_answer(simcall);
   }
-
-  /* We no longer need it */
-  SIMIX_io_destroy(synchro);
 }
index cae0df5..42a4aa8 100644 (file)
@@ -7,14 +7,11 @@
 #define SIMIX_IO_PRIVATE_HPP
 
 #include <xbt/base.h>
+#include "simgrid/s4u/Io.hpp"
 
-#include "popping_private.hpp"
-#include "simgrid/simix.h"
+XBT_PRIVATE simgrid::kernel::activity::IoImplPtr SIMIX_io_start(std::string name, sg_size_t size, sg_storage_t storage,
+                                                                simgrid::s4u::Io::OpType type);
 
-XBT_PRIVATE smx_activity_t SIMIX_storage_read(surf_storage_t fd, sg_size_t size);
-XBT_PRIVATE smx_activity_t SIMIX_storage_write(surf_storage_t fd, sg_size_t size);
-
-XBT_PRIVATE void SIMIX_io_destroy(smx_activity_t synchro);
 XBT_PRIVATE void SIMIX_io_finish(smx_activity_t synchro);
 
 #endif
index 6f50872..183d2b0 100644 (file)
@@ -6,6 +6,7 @@
 #include "simgrid/kernel/resource/Action.hpp"
 #include "simgrid/kernel/resource/Model.hpp"
 #include "simgrid/kernel/resource/Resource.hpp"
+#include "simgrid/s4u/Io.hpp"
 #include "simgrid/s4u/Storage.hpp"
 #include "src/surf/PropertyHolder.hpp"
 #include "src/surf/trace_mgr.hpp"
@@ -24,7 +25,9 @@ namespace surf {
  ***********/
 
 class StorageAction;
-
+/** @ingroup SURF_storage_interface
+ * @brief The possible type of action for the storage component
+ */
 /*************
  * Callbacks *
  *************/
@@ -81,7 +84,7 @@ public:
   void turn_off() override;
 
   void destroy(); // Must be called instead of the destructor
-
+  virtual simgrid::kernel::resource::Action* io_start(sg_size_t size, s4u::Io::OpType type) = 0;
   /**
    * @brief Read a file
    *
@@ -117,14 +120,6 @@ private:
  * Action *
  **********/
 
-/** @ingroup SURF_storage_interface
- * @brief The possible type of action for the storage component
- */
-enum e_surf_action_storage_type_t {
-  READ = 0, /**< Read a file */
-  WRITE     /**< Write in a file */
-};
-
 /** @ingroup SURF_storage_interface
  * @brief SURF storage action interface class
  */
@@ -142,8 +137,7 @@ public:
    * @param storage The Storage associated to this StorageAction
    * @param type [description]
    */
-  StorageAction(kernel::resource::Model* model, double cost, bool failed, StorageImpl* storage,
-                e_surf_action_storage_type_t type)
+  StorageAction(kernel::resource::Model* model, double cost, bool failed, StorageImpl* storage, s4u::Io::OpType type)
       : Action(model, cost, failed), type_(type), storage_(storage){};
 
   /**
@@ -157,12 +151,12 @@ public:
  * @param type [description]
  */
   StorageAction(kernel::resource::Model* model, double cost, bool failed, kernel::lmm::Variable* var,
-                StorageImpl* storage, e_surf_action_storage_type_t type)
+                StorageImpl* storage, s4u::Io::OpType type)
       : Action(model, cost, failed, var), type_(type), storage_(storage){};
 
   void set_state(simgrid::kernel::resource::Action::State state) override;
 
-  e_surf_action_storage_type_t type_;
+  s4u::Io::OpType type_;
   StorageImpl* storage_;
 };
 
index 6a1f0db..9c9b487 100644 (file)
@@ -99,14 +99,19 @@ StorageN11::StorageN11(StorageModel* model, std::string name, kernel::lmm::Syste
   simgrid::s4u::Storage::on_creation(this->piface_);
 }
 
+StorageAction* StorageN11::io_start(sg_size_t size, s4u::Io::OpType type)
+{
+  return new StorageN11Action(get_model(), size, is_off(), this, type);
+}
+
 StorageAction* StorageN11::read(sg_size_t size)
 {
-  return new StorageN11Action(get_model(), size, is_off(), this, READ);
+  return new StorageN11Action(get_model(), size, is_off(), this, s4u::Io::OpType::READ);
 }
 
 StorageAction* StorageN11::write(sg_size_t size)
 {
-  return new StorageN11Action(get_model(), size, is_off(), this, WRITE);
+  return new StorageN11Action(get_model(), size, is_off(), this, s4u::Io::OpType::WRITE);
 }
 
 /**********
@@ -114,7 +119,7 @@ StorageAction* StorageN11::write(sg_size_t size)
  **********/
 
 StorageN11Action::StorageN11Action(kernel::resource::Model* model, double cost, bool failed, StorageImpl* storage,
-                                   e_surf_action_storage_type_t type)
+                                   s4u::Io::OpType type)
     : StorageAction(model, cost, failed, model->get_maxmin_system()->variable_new(this, 1.0, -1.0, 3), storage, type)
 {
   XBT_IN("(%s,%g", storage->get_cname(), cost);
@@ -122,14 +127,14 @@ StorageN11Action::StorageN11Action(kernel::resource::Model* model, double cost,
   // Must be less than the max bandwidth for all actions
   model->get_maxmin_system()->expand(storage->get_constraint(), get_variable(), 1.0);
   switch(type) {
-  case READ:
-    model->get_maxmin_system()->expand(storage->constraintRead_, get_variable(), 1.0);
-    break;
-  case WRITE:
-    model->get_maxmin_system()->expand(storage->constraintWrite_, get_variable(), 1.0);
-    break;
-  default:
-    THROW_UNIMPLEMENTED;
+    case s4u::Io::OpType::READ:
+      model->get_maxmin_system()->expand(storage->constraintRead_, get_variable(), 1.0);
+      break;
+    case s4u::Io::OpType::WRITE:
+      model->get_maxmin_system()->expand(storage->constraintWrite_, get_variable(), 1.0);
+      break;
+    default:
+      THROW_UNIMPLEMENTED;
   }
   XBT_OUT();
 }
index e595db3..3931f75 100644 (file)
@@ -43,6 +43,7 @@ public:
   StorageN11(StorageModel* model, std::string name, kernel::lmm::System* maxminSystem, double bread, double bwrite,
              std::string type_id, std::string content_name, sg_size_t size, std::string attach);
   virtual ~StorageN11() = default;
+  StorageAction* io_start(sg_size_t size, s4u::Io::OpType type);
   StorageAction* read(sg_size_t size);
   StorageAction* write(sg_size_t size);
 };
@@ -54,7 +55,7 @@ public:
 class StorageN11Action : public StorageAction {
 public:
   StorageN11Action(kernel::resource::Model* model, double cost, bool failed, StorageImpl* storage,
-                   e_surf_action_storage_type_t type);
+                   s4u::Io::OpType type);
   void suspend() override;
   void cancel() override;
   void resume() override;
index 5313525..c9974ce 100644 (file)
@@ -435,6 +435,7 @@ set(S4U_SRC
   src/s4u/s4u_Engine.cpp
   src/s4u/s4u_Exec.cpp
   src/s4u/s4u_Host.cpp
+  src/s4u/s4u_Io.cpp
   src/s4u/s4u_Link.cpp
   src/s4u/s4u_Mailbox.cpp
   src/s4u/s4u_Mutex.cpp
@@ -700,6 +701,7 @@ set(headers_to_install
   include/simgrid/s4u/Engine.hpp
   include/simgrid/s4u/Exec.hpp
   include/simgrid/s4u/Host.hpp
+  include/simgrid/s4u/Io.hpp
   include/simgrid/s4u/Link.hpp
   include/simgrid/s4u/Mailbox.hpp
   include/simgrid/s4u/Mutex.hpp