Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cosmetics in the changelog and NEWS file [skip-ci]
[simgrid.git] / include / simgrid / s4u / Disk.hpp
1 /* Copyright (c) 2019-2021. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #ifndef INCLUDE_SIMGRID_S4U_DISK_HPP_
7 #define INCLUDE_SIMGRID_S4U_DISK_HPP_
8
9 #include <simgrid/disk.h>
10 #include <simgrid/forward.h>
11 #include <simgrid/s4u/Io.hpp>
12 #include <xbt/Extendable.hpp>
13 #include <xbt/base.h>
14 #include <xbt/signal.hpp>
15
16 #include <map>
17 #include <string>
18 #include <unordered_map>
19
20 namespace simgrid {
21
22 extern template class XBT_PUBLIC xbt::Extendable<s4u::Disk>;
23
24 namespace s4u {
25
26 /** Disk represent the disk resources associated to a host
27  *
28  * By default, SimGrid does not keep track of the actual data being written but
29  * only computes the time taken by the corresponding data movement.
30  */
31
32 class XBT_PUBLIC Disk : public xbt::Extendable<Disk> {
33 #ifndef DOXYGEN
34   friend Engine;
35   friend Io;
36   friend kernel::resource::DiskImpl;
37 #endif
38
39   explicit Disk(kernel::resource::DiskImpl* pimpl) : pimpl_(pimpl) {}
40   virtual ~Disk() = default;
41
42   // The private implementation, that never changes
43   kernel::resource::DiskImpl* const pimpl_;
44
45 public:
46 #ifndef DOXYGEN
47   kernel::resource::DiskImpl* get_impl() const { return pimpl_; }
48 #endif
49
50   std::string const& get_name() const;
51   /** @brief Retrieves the name of that disk as a C string */
52   const char* get_cname() const;
53
54   Disk* set_read_bandwidth(double read_bw);
55   double get_read_bandwidth() const;
56
57   Disk* set_write_bandwidth(double write_bw);
58   double get_write_bandwidth() const;
59
60   /**
61    * @brief Set limit for read/write operations.
62    *
63    * This determines the limit for read and write operation in the same disk.
64    * Usually, it's configured to max(read_bw, write_bw).
65    * You can change this behavior using this method
66    *
67    * @param bw New bandwidth for the disk
68    */
69   Disk* set_readwrite_bandwidth(double bw);
70
71   const std::unordered_map<std::string, std::string>* get_properties() const;
72   const char* get_property(const std::string& key) const;
73   Disk* set_property(const std::string&, const std::string& value);
74   Disk* set_properties(const std::unordered_map<std::string, std::string>& properties);
75
76   Disk* set_host(Host* host);
77   Host* get_host() const;
78
79   Disk* set_state_profile(kernel::profile::Profile* profile);
80   Disk* set_read_bandwidth_profile(kernel::profile::Profile* profile);
81   Disk* set_write_bandwidth_profile(kernel::profile::Profile* profile);
82
83   IoPtr io_init(sg_size_t size, s4u::Io::OpType type) const;
84
85   IoPtr read_async(sg_size_t size) const;
86   sg_size_t read(sg_size_t size) const;
87
88   IoPtr write_async(sg_size_t size) const;
89   sg_size_t write(sg_size_t size) const;
90
91   /** @brief Policy for sharing the disk among activities */
92   enum class SharingPolicy { NONLINEAR = 1, LINEAR = 0 };
93   enum class Operation { READ = 2, WRITE = 1, READWRITE = 0 };
94
95   /**
96    * @brief Describes how the disk is shared between activities for each operation
97    *
98    * Disks have different bandwidths for read and write operations, that can have different policies:
99    * - Read: resource sharing for read operation
100    * - Write: resource sharing for write
101    * - ReadWrite: global sharing for read and write operations
102    *
103    * Note that the NONLINEAR callback is in the critical path of the solver, so it should be fast.
104    *
105    * @param op Operation type
106    * @param policy Sharing policy
107    * @param cb Callback for NONLINEAR policies
108    */
109   Disk* set_sharing_policy(Operation op, SharingPolicy policy, const s4u::NonLinearResourceCb& cb = {});
110   SharingPolicy get_sharing_policy(Operation op) const;
111   /**
112    * @brief Callback to set IO factors
113    *
114    * This callback offers a flexible way to create variability in I/O operations
115    *
116    * @param size I/O operation size in bytes
117    * @param op I/O operation type: read or write
118    * @return Multiply factor
119    */
120   using IoFactorCb = double(sg_size_t size, Io::OpType op);
121   /** @brief Configure the factor callback */
122   Disk* set_factor_cb(const std::function<IoFactorCb>& cb);
123
124   Disk* seal();
125
126   /* The signals */
127   /** @brief Callback signal fired when a new Disk is created */
128   static xbt::signal<void(Disk&)> on_creation;
129   /** @brief Callback signal fired when a Disk is destroyed */
130   static xbt::signal<void(Disk const&)> on_destruction;
131   /** @brief Callback signal fired when a Disk's state changes */
132   static xbt::signal<void(Disk const&)> on_state_change;
133 };
134
135 } // namespace s4u
136 } // namespace simgrid
137
138 #endif /* INCLUDE_SIMGRID_S4U_DISK_HPP_ */