Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
working implementation of storage on disks
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Tue, 3 Sep 2019 12:15:53 +0000 (14:15 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Tue, 3 Sep 2019 12:15:53 +0000 (14:15 +0200)
+ add a s4u::Disk
+ modify a lot of things to make it working
+ add a small example to test read/write

25 files changed:
MANIFEST.in
examples/platforms/hosts_with_disks.xml
examples/s4u/CMakeLists.txt
examples/s4u/io-disk-raw/s4u-io-disk-raw.cpp [new file with mode: 0644]
examples/s4u/io-disk-raw/s4u-io-disk-raw.tesh [new file with mode: 0644]
include/simgrid/forward.h
include/simgrid/s4u.hpp
include/simgrid/s4u/Disk.hpp [new file with mode: 0644]
include/simgrid/s4u/Engine.hpp
include/simgrid/s4u/Host.hpp
include/simgrid/s4u/Io.hpp
src/kernel/EngineImpl.hpp
src/kernel/activity/IoImpl.cpp
src/kernel/activity/IoImpl.hpp
src/kernel/resource/DiskImpl.cpp
src/kernel/resource/DiskImpl.hpp
src/s4u/s4u_Disk.cpp [new file with mode: 0644]
src/s4u/s4u_Engine.cpp
src/s4u/s4u_Host.cpp
src/s4u/s4u_Io.cpp
src/surf/HostImpl.cpp
src/surf/HostImpl.hpp
src/surf/disk_s19.cpp
src/surf/host_clm03.cpp
tools/cmake/DefinePackages.cmake

index 165ccda..5a4621f 100644 (file)
@@ -1946,6 +1946,7 @@ include include/simgrid/s4u/Actor.hpp
 include include/simgrid/s4u/Barrier.hpp
 include include/simgrid/s4u/Comm.hpp
 include include/simgrid/s4u/ConditionVariable.hpp
 include include/simgrid/s4u/Barrier.hpp
 include include/simgrid/s4u/Comm.hpp
 include include/simgrid/s4u/ConditionVariable.hpp
+include include/simgrid/s4u/Disk.hpp
 include include/simgrid/s4u/Engine.hpp
 include include/simgrid/s4u/Exec.hpp
 include include/simgrid/s4u/Host.hpp
 include include/simgrid/s4u/Engine.hpp
 include include/simgrid/s4u/Exec.hpp
 include include/simgrid/s4u/Host.hpp
@@ -2276,6 +2277,7 @@ include src/s4u/s4u_Actor.cpp
 include src/s4u/s4u_Barrier.cpp
 include src/s4u/s4u_Comm.cpp
 include src/s4u/s4u_ConditionVariable.cpp
 include src/s4u/s4u_Barrier.cpp
 include src/s4u/s4u_Comm.cpp
 include src/s4u/s4u_ConditionVariable.cpp
+include src/s4u/s4u_Disk.cpp
 include src/s4u/s4u_Engine.cpp
 include src/s4u/s4u_Exec.cpp
 include src/s4u/s4u_Host.cpp
 include src/s4u/s4u_Engine.cpp
 include src/s4u/s4u_Exec.cpp
 include src/s4u/s4u_Host.cpp
index d543c25..b59a8d1 100644 (file)
@@ -3,13 +3,13 @@
 <platform version="4.1">
   <zone id="AS0" routing="Full">
     <host id="bob" speed="1Gf">
 <platform version="4.1">
   <zone id="AS0" routing="Full">
     <host id="bob" speed="1Gf">
-      <disk id="Disk1" read_bw="100MBps" write_bw="30MBps">
+      <disk id="Disk1" read_bw="100MBps" write_bw="40MBps">
         <prop id="size" value="500GiB"/>
       </disk>
     </host>
 
     <host id="alice" speed="1Gf">
         <prop id="size" value="500GiB"/>
       </disk>
     </host>
 
     <host id="alice" speed="1Gf">
-      <disk id="Disk2" read_bw="200MBps" write_bw="60MBps"/>
+      <disk id="Disk2" read_bw="200MBps" write_bw="80MBps"/>
     </host>
 
     <link id="link1" bandwidth="125MBps" latency="150us" />
     </host>
 
     <link id="link1" bandwidth="125MBps" latency="150us" />
index e6d1930..5672278 100644 (file)
@@ -10,7 +10,7 @@ foreach (example actor-create actor-daemon actor-exiting actor-join actor-kill
                  energy-exec energy-boot energy-link energy-vm
                  engine-filtering
                  exec-async exec-basic exec-dvfs exec-ptask exec-remote exec-waitany
                  energy-exec energy-boot energy-link energy-vm
                  engine-filtering
                  exec-async exec-basic exec-dvfs exec-ptask exec-remote exec-waitany
-                 io-async io-file-system io-file-remote io-storage-raw
+                 io-async io-file-system io-file-remote io-storage-raw io-disk-raw
                  platform-failures platform-profile platform-properties
                  plugin-hostload
                  replay-comm replay-storage
                  platform-failures platform-profile platform-properties
                  plugin-hostload
                  replay-comm replay-storage
diff --git a/examples/s4u/io-disk-raw/s4u-io-disk-raw.cpp b/examples/s4u/io-disk-raw/s4u-io-disk-raw.cpp
new file mode 100644 (file)
index 0000000..a490816
--- /dev/null
@@ -0,0 +1,57 @@
+/* Copyright (c) 2017-2019. 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"
+#include <string>
+#include <unordered_map>
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(disk, "Messages specific for this simulation");
+
+static void host()
+{
+  /* - Display information on the disks mounted by the current host */
+  XBT_INFO("*** Storage info on %s ***", simgrid::s4u::Host::current()->get_cname());
+
+  /* - Retrieve all mount points of current host */
+  std::vector<simgrid::s4u::Disk*> const& disk_list = simgrid::s4u::Host::current()->get_disks();
+
+  /* - For each disk mounted on host, display disk name and mount point */
+  for (auto disk : disk_list)
+    XBT_INFO("Disk name: %s", disk->get_cname());
+
+  /* - Write 400,000 bytes on Disk4 */
+  simgrid::s4u::Disk* disk = simgrid::s4u::Disk::by_name("Disk1");
+  sg_size_t write          = disk->write(400000);
+  XBT_INFO("Wrote %llu bytes on '%s'", write, disk->get_cname());
+
+  /*  - Now read 200,000 bytes */
+  sg_size_t read = disk->read(200000);
+  XBT_INFO("Read %llu bytes on '%s'", read, disk->get_cname());
+
+  /* - Attach some user data to disk1 */
+  XBT_INFO("*** Get/set data for storage element: Disk1 ***");
+
+  std::string* data = static_cast<std::string*>(disk->get_data());
+
+  XBT_INFO("Get storage data: '%s'", data ? data->c_str() : "No user data");
+
+  disk->set_data(new std::string("Some user data"));
+  data = static_cast<std::string*>(disk->get_data());
+  XBT_INFO("Set and get data: '%s'", data->c_str());
+  delete data;
+}
+
+int main(int argc, char** argv)
+{
+  simgrid::s4u::Engine e(&argc, argv);
+  e.load_platform(argv[1]);
+
+  simgrid::s4u::Actor::create("", simgrid::s4u::Host::by_name("bob"), host);
+
+  e.run();
+  XBT_INFO("Simulated time: %g", simgrid::s4u::Engine::get_clock());
+
+  return 0;
+}
diff --git a/examples/s4u/io-disk-raw/s4u-io-disk-raw.tesh b/examples/s4u/io-disk-raw/s4u-io-disk-raw.tesh
new file mode 100644 (file)
index 0000000..a1967ac
--- /dev/null
@@ -0,0 +1,11 @@
+#!/usr/bin/env tesh
+
+$ ${bindir}/s4u-io-disk-raw ${platfdir}/hosts_with_disks.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+> [  0.000000] (1:@bob) *** Storage info on bob ***
+> [  0.000000] (1:@bob) Disk name: Disk1
+> [  0.010000] (1:@bob) Wrote 400000 bytes on 'Disk1'
+> [  0.012000] (1:@bob) Read 200000 bytes on 'Disk1'
+> [  0.012000] (1:@bob) *** Get/set data for storage element: Disk1 ***
+> [  0.012000] (1:@bob) Get storage data: 'No user data'
+> [  0.012000] (1:@bob) Set and get data: 'Some user data'
+> [  0.012000] (0:maestro@) Simulated time: 0.012
index 8405699..8ce7d7b 100644 (file)
@@ -81,6 +81,7 @@ typedef boost::intrusive_ptr<Semaphore> SemaphorePtr;
 XBT_PUBLIC void intrusive_ptr_release(Semaphore* m);
 XBT_PUBLIC void intrusive_ptr_add_ref(Semaphore* m);
 
 XBT_PUBLIC void intrusive_ptr_release(Semaphore* m);
 XBT_PUBLIC void intrusive_ptr_add_ref(Semaphore* m);
 
+class Disk;
 class Storage;
 } // namespace s4u
 
 class Storage;
 } // namespace s4u
 
@@ -185,6 +186,7 @@ typedef simgrid::s4u::File s4u_File;
 typedef simgrid::s4u::ConditionVariable s4u_ConditionVariable;
 typedef simgrid::s4u::Mutex s4u_Mutex;
 typedef simgrid::s4u::Semaphore s4u_Semaphore;
 typedef simgrid::s4u::ConditionVariable s4u_ConditionVariable;
 typedef simgrid::s4u::Mutex s4u_Mutex;
 typedef simgrid::s4u::Semaphore s4u_Semaphore;
+typedef simgrid::s4u::Disk s4u_Disk;
 typedef simgrid::s4u::Storage s4u_Storage;
 typedef simgrid::s4u::NetZone s4u_NetZone;
 typedef simgrid::s4u::VirtualMachine s4u_VM;
 typedef simgrid::s4u::Storage s4u_Storage;
 typedef simgrid::s4u::NetZone s4u_NetZone;
 typedef simgrid::s4u::VirtualMachine s4u_VM;
@@ -207,6 +209,7 @@ typedef struct s4u_File s4u_File;
 typedef struct s4u_ConditionVariable s4u_ConditionVariable;
 typedef struct s4u_Mutex s4u_Mutex;
 typedef struct s4u_Semaphore s4u_Semaphore;
 typedef struct s4u_ConditionVariable s4u_ConditionVariable;
 typedef struct s4u_Mutex s4u_Mutex;
 typedef struct s4u_Semaphore s4u_Semaphore;
+typedef struct s4u_Disk s4u_Disk;
 typedef struct s4u_Storage s4u_Storage;
 typedef struct s4u_NetZone s4u_NetZone;
 typedef struct s4u_VM s4u_VM;
 typedef struct s4u_Storage s4u_Storage;
 typedef struct s4u_NetZone s4u_NetZone;
 typedef struct s4u_VM s4u_VM;
@@ -228,6 +231,7 @@ typedef s4u_Semaphore* sg_sem_t;
 typedef s4u_NetZone* sg_netzone_t;
 typedef s4u_Host* sg_host_t;
 typedef s4u_Link* sg_link_t;
 typedef s4u_NetZone* sg_netzone_t;
 typedef s4u_Host* sg_host_t;
 typedef s4u_Link* sg_link_t;
+typedef s4u_Disk* sg_disk_t;
 typedef s4u_Storage* sg_storage_t;
 typedef s4u_File* sg_file_t;
 typedef s4u_VM* sg_vm_t;
 typedef s4u_Storage* sg_storage_t;
 typedef s4u_File* sg_file_t;
 typedef s4u_VM* sg_vm_t;
index dcbc463..7dc4005 100644 (file)
@@ -13,6 +13,7 @@
 #include <simgrid/s4u/Barrier.hpp>
 #include <simgrid/s4u/Comm.hpp>
 #include <simgrid/s4u/ConditionVariable.hpp>
 #include <simgrid/s4u/Barrier.hpp>
 #include <simgrid/s4u/Comm.hpp>
 #include <simgrid/s4u/ConditionVariable.hpp>
+#include <simgrid/s4u/Disk.hpp>
 #include <simgrid/s4u/Engine.hpp>
 #include <simgrid/s4u/Exec.hpp>
 #include <simgrid/s4u/Host.hpp>
 #include <simgrid/s4u/Engine.hpp>
 #include <simgrid/s4u/Exec.hpp>
 #include <simgrid/s4u/Host.hpp>
diff --git a/include/simgrid/s4u/Disk.hpp b/include/simgrid/s4u/Disk.hpp
new file mode 100644 (file)
index 0000000..29ea07d
--- /dev/null
@@ -0,0 +1,85 @@
+/* Copyright (c) 2019. 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 INCLUDE_SIMGRID_S4U_DISK_HPP_
+#define INCLUDE_SIMGRID_S4U_DISK_HPP_
+
+#include <simgrid/forward.h>
+#include <simgrid/s4u/Io.hpp>
+#include <xbt/Extendable.hpp>
+#include <xbt/base.h>
+#include <xbt/signal.hpp>
+
+#include <map>
+#include <string>
+#include <unordered_map>
+
+namespace simgrid {
+namespace s4u {
+
+/** Disk represent the disk resources associated to a host
+ *
+ * By default, SimGrid does not keep track of the actual data being written but
+ * only computes the time taken by the corresponding data movement.
+ */
+
+class XBT_PUBLIC Disk : public xbt::Extendable<Disk> {
+  friend Engine;
+  friend Io;
+  friend kernel::resource::DiskImpl;
+
+public:
+  explicit Disk(const std::string& name, kernel::resource::DiskImpl* pimpl);
+
+protected:
+  virtual ~Disk() = default;
+
+public:
+  /** @brief Callback signal fired when a new Storage is created */
+  static xbt::signal<void(Disk&)> on_creation;
+  /** @brief Callback signal fired when a Storage is destroyed */
+  static xbt::signal<void(Disk const&)> on_destruction;
+  /** @brief Callback signal fired when a Storage's state changes */
+  static xbt::signal<void(Disk const&)> on_state_change;
+
+  /** Retrieve a Storage by its name. It must exist in the platform file */
+  static Disk* by_name(const std::string& name);
+  static Disk* by_name_or_null(const std::string& name);
+
+  /** @brief Retrieves the name of that storage as a C++ string */
+  std::string const& get_name() const { return name_; }
+  /** @brief Retrieves the name of that storage as a C string */
+  const char* get_cname() const { return name_.c_str(); }
+
+  Host* get_host() { return attached_to_; };
+  void set_host(Host* host) { attached_to_ = host; }
+
+  const std::unordered_map<std::string, std::string>* get_properties() const;
+  const char* get_property(const std::string& key) const;
+  void set_property(const std::string&, const std::string& value);
+
+  void set_data(void* data) { userdata_ = data; }
+  void* get_data() { return userdata_; }
+
+  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);
+  kernel::resource::DiskImpl* get_impl() const { return pimpl_; }
+
+private:
+  Host* attached_to_ = nullptr;
+  kernel::resource::DiskImpl* const pimpl_;
+  std::string name_;
+  void* userdata_ = nullptr;
+};
+
+} // namespace s4u
+} // namespace simgrid
+
+#endif /* INCLUDE_SIMGRID_S4U_DISK_HPP_ */
index 941b7cd..acca2fb 100644 (file)
@@ -87,6 +87,7 @@ protected:
 #ifndef DOXYGEN
   friend Host;
   friend Link;
 #ifndef DOXYGEN
   friend Host;
   friend Link;
+  friend Disk;
   friend Storage;
   friend kernel::routing::NetPoint;
   friend kernel::routing::NetZoneImpl;
   friend Storage;
   friend kernel::routing::NetPoint;
   friend kernel::routing::NetZoneImpl;
@@ -95,6 +96,8 @@ protected:
   void host_unregister(const std::string& name);
   void link_register(const std::string& name, Link* link);
   void link_unregister(const std::string& name);
   void host_unregister(const std::string& name);
   void link_register(const std::string& name, Link* link);
   void link_unregister(const std::string& name);
+  void disk_register(const std::string& name, Disk* storage);
+  void disk_unregister(const std::string& name);
   void storage_register(const std::string& name, Storage* storage);
   void storage_unregister(const std::string& name);
   void netpoint_register(simgrid::kernel::routing::NetPoint* card);
   void storage_register(const std::string& name, Storage* storage);
   void storage_unregister(const std::string& name);
   void netpoint_register(simgrid::kernel::routing::NetPoint* card);
@@ -119,6 +122,9 @@ public:
   std::vector<ActorPtr> get_all_actors();
   std::vector<ActorPtr> get_filtered_actors(const std::function<bool(ActorPtr)>& filter);
 
   std::vector<ActorPtr> get_all_actors();
   std::vector<ActorPtr> get_filtered_actors(const std::function<bool(ActorPtr)>& filter);
 
+  Disk* disk_by_name(const std::string& name);
+  Disk* disk_by_name_or_null(const std::string& name);
+
   size_t get_storage_count();
   std::vector<Storage*> get_all_storages();
   Storage* storage_by_name(const std::string& name);
   size_t get_storage_count();
   std::vector<Storage*> get_all_storages();
   Storage* storage_by_name(const std::string& name);
index 7702d6b..16c5ffe 100644 (file)
@@ -115,6 +115,7 @@ public:
   void set_pstate(int pstate_index);
   int get_pstate() const;
 
   void set_pstate(int pstate_index);
   int get_pstate() const;
 
+  std::vector<Disk*> get_disks() const;
   std::vector<const char*> get_attached_storages() const;
 
   /** Get an associative list [mount point]->[Storage] of all local mount points.
   std::vector<const char*> get_attached_storages() const;
 
   /** Get an associative list [mount point]->[Storage] of all local mount points.
index d486b34..73593ab 100644 (file)
@@ -26,17 +26,20 @@ public:
 
 private:
   Storage* storage_ = nullptr;
 
 private:
   Storage* storage_ = nullptr;
+  Disk* disk_       = nullptr;
   sg_size_t size_   = 0;
   OpType type_      = OpType::READ;
   std::string name_ = "";
   std::atomic_int_fast32_t refcount_{0};
 
   explicit Io(sg_storage_t storage, sg_size_t size, OpType type);
   sg_size_t size_   = 0;
   OpType type_      = OpType::READ;
   std::string name_ = "";
   std::atomic_int_fast32_t refcount_{0};
 
   explicit Io(sg_storage_t storage, sg_size_t size, OpType type);
+  explicit Io(sg_disk_t disk, sg_size_t size, OpType type);
 
 public:
 #ifndef DOXYGEN
   friend XBT_PUBLIC void intrusive_ptr_release(simgrid::s4u::Io* i);
   friend XBT_PUBLIC void intrusive_ptr_add_ref(simgrid::s4u::Io* i);
 
 public:
 #ifndef DOXYGEN
   friend XBT_PUBLIC void intrusive_ptr_release(simgrid::s4u::Io* i);
   friend XBT_PUBLIC void intrusive_ptr_add_ref(simgrid::s4u::Io* i);
+  friend Disk;    // Factory of IOs
   friend Storage; // Factory of IOs
 #endif
 
   friend Storage; // Factory of IOs
 #endif
 
index f824149..2a197f5 100644 (file)
@@ -15,6 +15,7 @@ namespace kernel {
 class EngineImpl {
   std::map<std::string, s4u::Host*> hosts_;
   std::map<std::string, s4u::Link*> links_;
 class EngineImpl {
   std::map<std::string, s4u::Host*> hosts_;
   std::map<std::string, s4u::Link*> links_;
+  std::map<std::string, s4u::Disk*> disks_;
   std::map<std::string, s4u::Storage*> storages_;
   std::unordered_map<std::string, routing::NetPoint*> netpoints_;
   friend s4u::Engine;
   std::map<std::string, s4u::Storage*> storages_;
   std::unordered_map<std::string, routing::NetPoint*> netpoints_;
   friend s4u::Engine;
index 6022c2d..63f5381 100644 (file)
@@ -7,6 +7,7 @@
 #include "simgrid/Exception.hpp"
 #include "simgrid/kernel/resource/Action.hpp"
 #include "simgrid/s4u/Host.hpp"
 #include "simgrid/Exception.hpp"
 #include "simgrid/kernel/resource/Action.hpp"
 #include "simgrid/s4u/Host.hpp"
+#include "src/kernel/resource/DiskImpl.hpp"
 #include "src/mc/mc_replay.hpp"
 #include "src/simix/smx_private.hpp"
 #include "src/surf/StorageImpl.hpp"
 #include "src/mc/mc_replay.hpp"
 #include "src/simix/smx_private.hpp"
 #include "src/surf/StorageImpl.hpp"
@@ -44,6 +45,12 @@ IoImpl& IoImpl::set_size(sg_size_t size)
   return *this;
 }
 
   return *this;
 }
 
+IoImpl& IoImpl::set_disk(resource::DiskImpl* disk)
+{
+  disk_ = disk;
+  return *this;
+}
+
 IoImpl& IoImpl::set_storage(resource::StorageImpl* storage)
 {
   storage_ = storage;
 IoImpl& IoImpl::set_storage(resource::StorageImpl* storage)
 {
   storage_ = storage;
@@ -53,7 +60,10 @@ IoImpl& IoImpl::set_storage(resource::StorageImpl* storage)
 IoImpl* IoImpl::start()
 {
   state_       = SIMIX_RUNNING;
 IoImpl* IoImpl::start()
 {
   state_       = SIMIX_RUNNING;
-  surf_action_ = storage_->io_start(size_, type_);
+  if (storage_)
+    surf_action_ = storage_->io_start(size_, type_);
+  else
+    surf_action_ = disk_->io_start(size_, type_);
   surf_action_->set_activity(this);
 
   XBT_DEBUG("Create IO synchro %p %s", this, get_cname());
   surf_action_->set_activity(this);
 
   XBT_DEBUG("Create IO synchro %p %s", this, get_cname());
@@ -66,7 +76,7 @@ void IoImpl::post()
 {
   performed_ioops_ = surf_action_->get_cost();
   if (surf_action_->get_state() == resource::Action::State::FAILED) {
 {
   performed_ioops_ = surf_action_->get_cost();
   if (surf_action_->get_state() == resource::Action::State::FAILED) {
-    if (storage_ && not storage_->is_on())
+    if ((storage_ && not storage_->is_on()) || (disk_ && not disk_->is_on()))
       state_ = SIMIX_FAILED;
     else
       state_ = SIMIX_CANCELED;
       state_ = SIMIX_FAILED;
     else
       state_ = SIMIX_CANCELED;
index 2ab4ff7..8d8f04c 100644 (file)
@@ -16,6 +16,7 @@ namespace activity {
 
 class XBT_PUBLIC IoImpl : public ActivityImpl_T<IoImpl> {
   resource::StorageImpl* storage_ = nullptr;
 
 class XBT_PUBLIC IoImpl : public ActivityImpl_T<IoImpl> {
   resource::StorageImpl* storage_ = nullptr;
+  resource::DiskImpl* disk_       = nullptr;
   sg_size_t size_                 = 0;
   s4u::Io::OpType type_           = s4u::Io::OpType::READ;
   sg_size_t performed_ioops_      = 0;
   sg_size_t size_                 = 0;
   s4u::Io::OpType type_           = s4u::Io::OpType::READ;
   sg_size_t performed_ioops_      = 0;
@@ -24,6 +25,7 @@ public:
   IoImpl& set_size(sg_size_t size);
   IoImpl& set_type(s4u::Io::OpType type);
   IoImpl& set_storage(resource::StorageImpl* storage);
   IoImpl& set_size(sg_size_t size);
   IoImpl& set_type(s4u::Io::OpType type);
   IoImpl& set_storage(resource::StorageImpl* storage);
+  IoImpl& set_disk(resource::DiskImpl* disk);
 
   sg_size_t get_performed_ioops() { return performed_ioops_; }
 
 
   sg_size_t get_performed_ioops() { return performed_ioops_; }
 
index 5f2a72c..f2877f2 100644 (file)
@@ -37,8 +37,7 @@ DiskModel::~DiskModel()
 
 DiskImpl::DiskImpl(kernel::resource::Model* model, const std::string& name, kernel::lmm::System* maxminSystem,
                    double read_bw, double write_bw)
 
 DiskImpl::DiskImpl(kernel::resource::Model* model, const std::string& name, kernel::lmm::System* maxminSystem,
                    double read_bw, double write_bw)
-    : Resource(model, name, maxminSystem->constraint_new(this, std::max(read_bw, write_bw)))
-// FIXME    , piface_(name, this)
+    : Resource(model, name, maxminSystem->constraint_new(this, std::max(read_bw, write_bw))), piface_(name, this)
 {
   DiskImpl::turn_on();
   XBT_DEBUG("Create resource with read_bw '%f' write_bw '%f'", read_bw, write_bw);
 {
   DiskImpl::turn_on();
   XBT_DEBUG("Create resource with read_bw '%f' write_bw '%f'", read_bw, write_bw);
@@ -59,7 +58,7 @@ void DiskImpl::destroy()
 {
   if (not currently_destroying_) {
     currently_destroying_ = true;
 {
   if (not currently_destroying_) {
     currently_destroying_ = true;
-    // FIXME s4u::Storage::on_destruction(this->piface_);
+    s4u::Disk::on_destruction(this->piface_);
     delete this;
   }
 }
     delete this;
   }
 }
@@ -78,14 +77,14 @@ void DiskImpl::turn_on()
 {
   if (not is_on()) {
     Resource::turn_on();
 {
   if (not is_on()) {
     Resource::turn_on();
-    // FIXME s4u::Storage::on_state_change(this->piface_);
+    s4u::Disk::on_state_change(this->piface_);
   }
 }
 void DiskImpl::turn_off()
 {
   if (is_on()) {
     Resource::turn_off();
   }
 }
 void DiskImpl::turn_off()
 {
   if (is_on()) {
     Resource::turn_off();
-    // FIXME s4u::Storage::on_state_change(this->piface_);
+    s4u::Disk::on_state_change(this->piface_);
   }
 }
 
   }
 }
 
index 8645dd0..dde80f5 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/kernel/resource/Action.hpp"
 #include "simgrid/kernel/resource/Model.hpp"
 #include "simgrid/kernel/resource/Resource.hpp"
+#include "simgrid/s4u/Disk.hpp"
 #include "simgrid/s4u/Io.hpp"
 #include "src/surf/PropertyHolder.hpp"
 #include "src/surf/surf_interface.hpp"
 #include "simgrid/s4u/Io.hpp"
 #include "src/surf/PropertyHolder.hpp"
 #include "src/surf/surf_interface.hpp"
@@ -57,7 +58,7 @@ public:
   ~DiskImpl() override;
 
   /** @brief Public interface */
   ~DiskImpl() override;
 
   /** @brief Public interface */
-  // FIXME s4u::Storage piface_;
+  s4u::Disk piface_;
 
   /** @brief Check if the Storage is used (if an action currently uses its resources) */
   bool is_used() override;
 
   /** @brief Check if the Storage is used (if an action currently uses its resources) */
   bool is_used() override;
diff --git a/src/s4u/s4u_Disk.cpp b/src/s4u/s4u_Disk.cpp
new file mode 100644 (file)
index 0000000..b543f94
--- /dev/null
@@ -0,0 +1,80 @@
+/* Copyright (c) 2019. 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/Disk.hpp"
+#include "simgrid/s4u/Engine.hpp"
+#include "simgrid/s4u/Host.hpp"
+#include "simgrid/s4u/Io.hpp"
+#include "src/kernel/resource/DiskImpl.hpp"
+
+namespace simgrid {
+namespace xbt {
+template class Extendable<s4u::Disk>;
+} // namespace xbt
+
+namespace s4u {
+
+xbt::signal<void(Disk&)> Disk::on_creation;
+xbt::signal<void(Disk const&)> Disk::on_destruction;
+xbt::signal<void(Disk const&)> Disk::on_state_change;
+
+Disk::Disk(const std::string& name, kernel::resource::DiskImpl* pimpl) : pimpl_(pimpl), name_(name)
+{
+  Engine::get_instance()->disk_register(name_, this);
+}
+
+Disk* Disk::by_name(const std::string& name)
+{
+  return Engine::get_instance()->disk_by_name(name);
+}
+
+Disk* Disk::by_name_or_null(const std::string& name)
+{
+  return Engine::get_instance()->disk_by_name_or_null(name);
+}
+
+const std::unordered_map<std::string, std::string>* Disk::get_properties() const
+{
+  return pimpl_->get_properties();
+}
+
+const char* Disk::get_property(const std::string& key) const
+{
+  return this->pimpl_->get_property(key);
+}
+
+void Disk::set_property(const std::string& key, const std::string& value)
+{
+  kernel::actor::simcall([this, &key, &value] { this->pimpl_->set_property(key, value); });
+}
+
+IoPtr Disk::io_init(sg_size_t size, Io::OpType type)
+{
+  return IoPtr(new Io(this, size, type));
+}
+
+IoPtr Disk::read_async(sg_size_t size)
+{
+  return IoPtr(io_init(size, Io::OpType::READ))->start();
+}
+
+sg_size_t Disk::read(sg_size_t size)
+{
+  return IoPtr(io_init(size, Io::OpType::READ))->start()->wait()->get_performed_ioops();
+}
+
+IoPtr Disk::write_async(sg_size_t size)
+{
+
+  return IoPtr(io_init(size, Io::OpType::WRITE)->start());
+}
+
+sg_size_t Disk::write(sg_size_t size)
+{
+  return IoPtr(io_init(size, Io::OpType::WRITE))->start()->wait()->get_performed_ioops();
+}
+
+} // namespace s4u
+} // namespace simgrid
index 64cb7f6..c92bdaa 100644 (file)
@@ -8,6 +8,7 @@
 #include "mc/mc.h"
 #include "simgrid/kernel/routing/NetPoint.hpp"
 #include "simgrid/kernel/routing/NetZoneImpl.hpp"
 #include "mc/mc.h"
 #include "simgrid/kernel/routing/NetPoint.hpp"
 #include "simgrid/kernel/routing/NetZoneImpl.hpp"
+#include "simgrid/s4u/Disk.hpp"
 #include "simgrid/s4u/Engine.hpp"
 #include "simgrid/s4u/Host.hpp"
 #include "simgrid/s4u/Mailbox.hpp"
 #include "simgrid/s4u/Engine.hpp"
 #include "simgrid/s4u/Host.hpp"
 #include "simgrid/s4u/Mailbox.hpp"
@@ -210,6 +211,25 @@ std::vector<Storage*> Engine::get_all_storages()
   return res;
 }
 
   return res;
 }
 
+/** @brief Find a disk from its name.
+ *
+ *  @throw std::invalid_argument if the searched disk does not exist.
+ */
+Disk* Engine::disk_by_name(const std::string& name)
+{
+  if (pimpl->disks_.find(name) == pimpl->disks_.end())
+    throw std::invalid_argument(std::string("Disk not found: ") + name);
+
+  return pimpl->disks_.at(name);
+}
+
+/** @brief Find a disk from its name (or nullptr if that disk does not exist) */
+Disk* Engine::disk_by_name_or_null(const std::string& name)
+{
+  auto disk = pimpl->disks_.find(name);
+  return disk == pimpl->disks_.end() ? nullptr : disk->second;
+}
+
 /** @brief Find a storage from its name.
  *
  *  @throw std::invalid_argument if the searched storage does not exist.
 /** @brief Find a storage from its name.
  *
  *  @throw std::invalid_argument if the searched storage does not exist.
@@ -239,6 +259,16 @@ void Engine::storage_unregister(const std::string& name)
   pimpl->storages_.erase(name);
 }
 
   pimpl->storages_.erase(name);
 }
 
+void Engine::disk_register(const std::string& name, Disk* disk)
+{
+  pimpl->disks_[name] = disk;
+}
+
+void Engine::disk_unregister(const std::string& name)
+{
+  pimpl->disks_.erase(name);
+}
+
 /** @brief Returns the amount of links in the platform */
 size_t Engine::get_link_count()
 {
 /** @brief Returns the amount of links in the platform */
 size_t Engine::get_link_count()
 {
index 29eb24b..02698af 100644 (file)
@@ -284,6 +284,10 @@ int Host::get_pstate() const
   return this->pimpl_cpu->get_pstate();
 }
 
   return this->pimpl_cpu->get_pstate();
 }
 
+std::vector<Disk*> Host::get_disks() const
+{
+  return kernel::actor::simcall([this] { return this->pimpl_->get_disks(); });
+}
 /**
  * @ingroup simix_storage_management
  * @brief Returns the list of storages attached to a host.
 /**
  * @ingroup simix_storage_management
  * @brief Returns the list of storages attached to a host.
index 924dfec..4cf33bc 100644 (file)
@@ -3,6 +3,7 @@
 /* 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. */
 
 /* 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/Disk.hpp"
 #include "simgrid/s4u/Io.hpp"
 #include "simgrid/s4u/Storage.hpp"
 #include "src/kernel/activity/IoImpl.hpp"
 #include "simgrid/s4u/Io.hpp"
 #include "simgrid/s4u/Storage.hpp"
 #include "src/kernel/activity/IoImpl.hpp"
@@ -13,6 +14,12 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_io, s4u_activity, "S4U asynchronous IOs");
 namespace simgrid {
 namespace s4u {
 
 namespace simgrid {
 namespace s4u {
 
+Io::Io(sg_disk_t disk, sg_size_t size, OpType type) : disk_(disk), size_(size), type_(type)
+{
+  Activity::set_remaining(size_);
+  pimpl_ = kernel::activity::IoImplPtr(new kernel::activity::IoImpl());
+}
+
 Io::Io(sg_storage_t storage, sg_size_t size, OpType type) : storage_(storage), size_(size), type_(type)
 {
   Activity::set_remaining(size_);
 Io::Io(sg_storage_t storage, sg_size_t size, OpType type) : storage_(storage), size_(size), type_(type)
 {
   Activity::set_remaining(size_);
@@ -22,12 +29,21 @@ Io::Io(sg_storage_t storage, sg_size_t size, OpType type) : storage_(storage), s
 Io* Io::start()
 {
   kernel::actor::simcall([this] {
 Io* Io::start()
 {
   kernel::actor::simcall([this] {
-    (*boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_))
-        .set_name(name_)
-        .set_storage(storage_->get_impl())
-        .set_size(size_)
-        .set_type(type_)
-        .start();
+    if (storage_) {
+      (*boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_))
+          .set_name(name_)
+          .set_storage(storage_->get_impl())
+          .set_size(size_)
+          .set_type(type_)
+          .start();
+    } else {
+      (*boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_))
+          .set_name(name_)
+          .set_disk(disk_->get_impl())
+          .set_size(size_)
+          .set_type(type_)
+          .start();
+    }
   });
   state_ = State::STARTED;
   return this;
   });
   state_ = State::STARTED;
   return this;
index e598461..a749282 100644 (file)
@@ -147,6 +147,15 @@ size_t HostImpl::get_actor_count()
 {
   return process_list_.size();
 }
 {
   return process_list_.size();
 }
+
+std::vector<s4u::Disk*> HostImpl::get_disks()
+{
+  std::vector<s4u::Disk*> disks;
+  for (auto const& d : disks_)
+    disks.push_back(&d->piface_);
+  return disks;
+}
+
 std::vector<const char*> HostImpl::get_attached_storages()
 {
   std::vector<const char*> storages;
 std::vector<const char*> HostImpl::get_attached_storages()
 {
   std::vector<const char*> storages;
index b5f4d5c..daf3841 100644 (file)
@@ -7,6 +7,7 @@
 #define SURF_HOST_INTERFACE_HPP_
 
 #include "src/kernel/actor/ActorImpl.hpp"
 #define SURF_HOST_INTERFACE_HPP_
 
 #include "src/kernel/actor/ActorImpl.hpp"
+#include "src/kernel/resource/DiskImpl.hpp"
 #include "src/surf/PropertyHolder.hpp"
 #include "src/surf/StorageImpl.hpp"
 #include "src/surf/cpu_interface.hpp"
 #include "src/surf/PropertyHolder.hpp"
 #include "src/surf/StorageImpl.hpp"
 #include "src/surf/cpu_interface.hpp"
@@ -47,6 +48,7 @@ public:
   explicit HostImpl(s4u::Host* host);
   virtual ~HostImpl();
 
   explicit HostImpl(s4u::Host* host);
   virtual ~HostImpl();
 
+  std::vector<s4u::Disk*> get_disks();
   /** @brief Get the vector of storages (by names) attached to the Host */
   virtual std::vector<const char*> get_attached_storages();
 
   /** @brief Get the vector of storages (by names) attached to the Host */
   virtual std::vector<const char*> get_attached_storages();
 
index 160279a..c873094 100644 (file)
@@ -66,7 +66,7 @@ DiskS19::DiskS19(DiskModel* model, const std::string& name, lmm::System* maxminS
     : DiskImpl(model, name, maxminSystem, read_bw, write_bw)
 {
   XBT_DEBUG("Create resource with read_bw '%f' write_bw '%f'", read_bw, write_bw);
     : DiskImpl(model, name, maxminSystem, read_bw, write_bw)
 {
   XBT_DEBUG("Create resource with read_bw '%f' write_bw '%f'", read_bw, write_bw);
-  // FIXME s4u::Storage::on_creation(this->piface_);
+  s4u::Disk::on_creation(this->piface_);
 }
 
 DiskAction* DiskS19::io_start(sg_size_t size, s4u::Io::OpType type)
 }
 
 DiskAction* DiskS19::io_start(sg_size_t size, s4u::Io::OpType type)
index 7aa840b..955e6b8 100644 (file)
@@ -36,17 +36,19 @@ double HostCLM03Model::next_occuring_event(double now)
   double min_by_net =
       surf_network_model->next_occuring_event_is_idempotent() ? surf_network_model->next_occuring_event(now) : -1;
   double min_by_sto = surf_storage_model->next_occuring_event(now);
   double min_by_net =
       surf_network_model->next_occuring_event_is_idempotent() ? surf_network_model->next_occuring_event(now) : -1;
   double min_by_sto = surf_storage_model->next_occuring_event(now);
+  double min_by_dsk = surf_disk_model->next_occuring_event(now);
 
 
-  XBT_DEBUG("model %p, %s min_by_cpu %f, %s min_by_net %f, %s min_by_sto %f",
-      this, typeid(surf_cpu_model_pm).name(), min_by_cpu,
-      typeid(surf_network_model).name(), min_by_net,
-      typeid(surf_storage_model).name(), min_by_sto);
+  XBT_DEBUG("model %p, %s min_by_cpu %f, %s min_by_net %f, %s min_by_sto %f, %s min_by_dsk %f", this,
+            typeid(surf_cpu_model_pm).name(), min_by_cpu, typeid(surf_network_model).name(), min_by_net,
+            typeid(surf_storage_model).name(), min_by_sto, typeid(surf_disk_model).name(), min_by_dsk);
 
   double res = min_by_cpu;
   if (res < 0 || (min_by_net >= 0.0 && min_by_net < res))
     res = min_by_net;
   if (res < 0 || (min_by_sto >= 0.0 && min_by_sto < res))
     res = min_by_sto;
 
   double res = min_by_cpu;
   if (res < 0 || (min_by_net >= 0.0 && min_by_net < res))
     res = min_by_net;
   if (res < 0 || (min_by_sto >= 0.0 && min_by_sto < res))
     res = min_by_sto;
+  if (res < 0 || (min_by_dsk >= 0.0 && min_by_dsk < res))
+    res = min_by_dsk;
   return res;
 }
 
   return res;
 }
 
index 7ebc788..6b18fd1 100644 (file)
@@ -442,6 +442,7 @@ set(S4U_SRC
   src/s4u/s4u_Barrier.cpp
   src/s4u/s4u_ConditionVariable.cpp
   src/s4u/s4u_Comm.cpp
   src/s4u/s4u_Barrier.cpp
   src/s4u/s4u_ConditionVariable.cpp
   src/s4u/s4u_Comm.cpp
+  src/s4u/s4u_Disk.cpp
   src/s4u/s4u_Engine.cpp
   src/s4u/s4u_Exec.cpp
   src/s4u/s4u_Host.cpp
   src/s4u/s4u_Engine.cpp
   src/s4u/s4u_Exec.cpp
   src/s4u/s4u_Host.cpp
@@ -711,6 +712,7 @@ set(headers_to_install
   include/simgrid/s4u/Barrier.hpp
   include/simgrid/s4u/Comm.hpp
   include/simgrid/s4u/ConditionVariable.hpp
   include/simgrid/s4u/Barrier.hpp
   include/simgrid/s4u/Comm.hpp
   include/simgrid/s4u/ConditionVariable.hpp
+  include/simgrid/s4u/Disk.hpp
   include/simgrid/s4u/Engine.hpp
   include/simgrid/s4u/Exec.hpp
   include/simgrid/s4u/Host.hpp
   include/simgrid/s4u/Engine.hpp
   include/simgrid/s4u/Exec.hpp
   include/simgrid/s4u/Host.hpp