Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
declare an Io::OpType enum class
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 2 Aug 2018 07:41:42 +0000 (09:41 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 2 Aug 2018 22:00:13 +0000 (00:00 +0200)
include/simgrid/s4u/Io.hpp
include/simgrid/simix.h
src/s4u/s4u_Io.cpp
src/simix/libsmx.cpp
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

index 6e3df22..1625419 100644 (file)
@@ -21,6 +21,7 @@ public:
   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;
@@ -29,10 +30,13 @@ public:
   Activity* cancel() override;
 
   double get_remaining() override;
+  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
 }
index 2d65ccb..4f5047b 100644 (file)
@@ -286,9 +286,6 @@ 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   **********************************/
-#ifdef __cplusplus
-XBT_PUBLIC smx_activity_t simcall_io_start(std::string name, sg_size_t size, sg_storage_t storage);
-#endif
 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);
 /************************** MC simcalls   **********************************/
index 4dfbfa2..2f6d6ed 100644 (file)
@@ -6,6 +6,7 @@
 #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");
@@ -15,7 +16,7 @@ namespace s4u {
 
 Activity* Io::start()
 {
-  pimpl_ = simcall_io_start("", size_, storage_);
+  pimpl_ = simix::simcall([this] { return SIMIX_io_start(name_, size_, storage_, type_); });
   state_ = State::STARTED;
   return this;
 }
@@ -66,6 +67,13 @@ double Io::get_remaining()
       [this]() { return boost::static_pointer_cast<simgrid::kernel::activity::IoImpl>(pimpl_)->get_remaining(); });
 }
 
+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;
+}
+
 // double Io::get_remaining_ratio()
 //{
 //  return simgrid::simix::simcall([this]() {
index 0ec3f39..447032f 100644 (file)
@@ -468,14 +468,6 @@ int simcall_sem_acquire_timeout(smx_sem_t sem, double timeout)
   return simcall_BODY_sem_acquire_timeout(sem, timeout);
 }
 
-smx_activity_t simcall_io_start(std::string name, sg_size_t size, simgrid::s4u::Storage* storage)
-{
-  /* checking for infinite values */
-  xbt_assert(std::isfinite(size), "size is not finite!");
-
-  return simgrid::simix::simcall([name, size, storage] { return SIMIX_io_start(name, size, storage); });
-}
-
 sg_size_t simcall_storage_read(surf_storage_t st, sg_size_t size)
 {
   return simcall_BODY_storage_read(st, size);
index 4a0cb7e..c76819e 100644 (file)
@@ -4,6 +4,7 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "simgrid/s4u/Host.hpp"
+#include "simgrid/s4u/Io.hpp"
 #include "xbt/ex.hpp"
 
 #include "smx_private.hpp"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_io, simix, "Logging specific to SIMIX (io)");
 
-simgrid::kernel::activity::IoImplPtr SIMIX_io_start(std::string name, sg_size_t size, sg_storage_t storage)
+simgrid::kernel::activity::IoImplPtr SIMIX_io_start(std::string name, sg_size_t size, sg_storage_t storage,
+                                                    simgrid::s4u::Io::OpType type)
 {
   /* set surf's action */
-  // FIXME
-  simgrid::kernel::resource::Action* surf_action =
-      storage->get_impl()->io_start(size, (simgrid::surf::e_surf_action_storage_type_t)0);
+  simgrid::kernel::resource::Action* surf_action = storage->get_impl()->io_start(size, type);
 
   simgrid::kernel::activity::IoImplPtr io =
       simgrid::kernel::activity::IoImplPtr(new simgrid::kernel::activity::IoImpl(name, surf_action, storage));
index dc62c72..ee9db60 100644 (file)
@@ -9,8 +9,10 @@
 #include <xbt/base.h>
 
 #include "popping_private.hpp"
+#include "simgrid/s4u/Io.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);
+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);
 
index 6d47c15..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"
@@ -27,11 +28,6 @@ class StorageAction;
 /** @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 */
-};
-
 /*************
  * Callbacks *
  *************/
@@ -88,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, e_surf_action_storage_type_t type) = 0;
+  virtual simgrid::kernel::resource::Action* io_start(sg_size_t size, s4u::Io::OpType type) = 0;
   /**
    * @brief Read a file
    *
@@ -141,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){};
 
   /**
@@ -156,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 74ff08a..9c9b487 100644 (file)
@@ -99,19 +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, e_surf_action_storage_type_t type)
+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);
 }
 
 /**********
@@ -119,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);
@@ -127,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 4886507..3931f75 100644 (file)
@@ -43,7 +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, e_surf_action_storage_type_t type);
+  StorageAction* io_start(sg_size_t size, s4u::Io::OpType type);
   StorageAction* read(sg_size_t size);
   StorageAction* write(sg_size_t size);
 };
@@ -55,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;