Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Disk: Non-linear contraints
[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   const std::unordered_map<std::string, std::string>* get_properties() const;
61   const char* get_property(const std::string& key) const;
62   Disk* set_property(const std::string&, const std::string& value);
63   Disk* set_properties(const std::unordered_map<std::string, std::string>& properties);
64
65   Disk* set_host(Host* host);
66   Host* get_host() const;
67
68   Disk* set_state_profile(kernel::profile::Profile* profile);
69   Disk* set_read_bandwidth_profile(kernel::profile::Profile* profile);
70   Disk* set_write_bandwidth_profile(kernel::profile::Profile* profile);
71
72   IoPtr io_init(sg_size_t size, s4u::Io::OpType type) const;
73
74   IoPtr read_async(sg_size_t size) const;
75   sg_size_t read(sg_size_t size) const;
76
77   IoPtr write_async(sg_size_t size) const;
78   sg_size_t write(sg_size_t size) const;
79
80   /** @brief Policy for sharing the disk among activities */
81   enum class SharingPolicy { NONLINEAR = 1, LINEAR = 0 };
82   enum class Operation { READ = 2, WRITE = 1, READWRITE = 0 };
83
84   /**
85    * @brief Describes how the disk is shared between activities for each operation
86    *
87    * Disks have different bandwidths for read and write operations. This method
88    * allows you to set different sharing policies for each operation:
89    * - Read: resource sharing for read operation
90    * - Write: resource sharing for write
91    * - ReadWrite: global sharing for read and write operations
92    *
93    * @param op Operation type
94    * @param policy Sharing policy
95    * @param cb Callback for NONLINEAR policies
96    */
97   Disk* set_sharing_policy(Operation op, SharingPolicy policy, const s4u::NonLinearResourceCb& cb = {});
98   SharingPolicy get_sharing_policy(Operation op) const;
99
100   Disk* seal();
101
102   /* The signals */
103   /** @brief Callback signal fired when a new Disk is created */
104   static xbt::signal<void(Disk&)> on_creation;
105   /** @brief Callback signal fired when a Disk is destroyed */
106   static xbt::signal<void(Disk const&)> on_destruction;
107   /** @brief Callback signal fired when a Disk's state changes */
108   static xbt::signal<void(Disk const&)> on_state_change;
109 };
110
111 } // namespace s4u
112 } // namespace simgrid
113
114 #endif /* INCLUDE_SIMGRID_S4U_DISK_HPP_ */