Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
694972bc7d295b219245a03e4de25f597dd5b0cf
[simgrid.git] / src / kernel / resource / DiskImpl.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 #include "simgrid/kernel/resource/Action.hpp"
7 #include "simgrid/kernel/resource/Model.hpp"
8 #include "simgrid/kernel/resource/Resource.hpp"
9 #include "simgrid/s4u/Disk.hpp"
10 #include "simgrid/s4u/Io.hpp"
11 #include "src/surf/surf_interface.hpp"
12 #include <xbt/PropertyHolder.hpp>
13
14 #include <map>
15
16 #ifndef DISK_INTERFACE_HPP_
17 #define DISK_INTERFACE_HPP_
18
19 /*********
20  * Model *
21  *********/
22
23 namespace simgrid {
24 namespace kernel {
25 namespace resource {
26 /***********
27  * Classes *
28  ***********/
29
30 class DiskAction;
31
32 /*********
33  * Model *
34  *********/
35 class DiskModel : public Model {
36 public:
37   explicit DiskModel(const std::string& name);
38   DiskModel(const DiskModel&) = delete;
39   DiskModel& operator=(const DiskModel&) = delete;
40
41   virtual DiskImpl* create_disk(const std::string& name, double read_bandwidth, double write_bandwidth) = 0;
42
43   virtual DiskAction* io_start(const DiskImpl* disk, sg_size_t size, s4u::Io::OpType type) = 0;
44 };
45
46 /************
47  * Resource *
48  ************/
49 class DiskImpl : public Resource_T<DiskImpl>, public xbt::PropertyHolder {
50   s4u::Disk piface_;
51   s4u::Host* host_                   = nullptr;
52   lmm::Constraint* constraint_write_ = nullptr; /* Constraint for maximum write bandwidth*/
53   lmm::Constraint* constraint_read_  = nullptr; /* Constraint for maximum read bandwidth*/
54
55 protected:
56   ~DiskImpl() override = default; // Disallow direct deletion. Call destroy() instead.
57
58 public:
59   Metric read_bw_  = {0.0, 0, nullptr};
60   Metric write_bw_ = {0.0, 0, nullptr};
61
62   explicit DiskImpl(const std::string& name, double read_bandwidth, double write_bandwidth);
63   DiskImpl(const DiskImpl&) = delete;
64   DiskImpl& operator=(const DiskImpl&) = delete;
65
66   /** @brief Public interface */
67   const s4u::Disk* get_iface() const { return &piface_; }
68   s4u::Disk* get_iface() { return &piface_; }
69   DiskImpl* set_host(s4u::Host* host);
70   s4u::Host* get_host() const { return host_; }
71
72   virtual void set_read_bandwidth(double read_bw) = 0;
73   double get_read_bandwidth() const { return read_bw_.peak * read_bw_.scale; }
74
75   virtual void set_write_bandwidth(double write_bw) = 0;
76   double get_write_bandwidth() const { return write_bw_.peak * write_bw_.scale; }
77
78   DiskImpl* set_read_constraint(lmm::Constraint* constraint_read);
79   lmm::Constraint* get_read_constraint() const { return constraint_read_; }
80
81   DiskImpl* set_write_constraint(lmm::Constraint* constraint_write);
82   lmm::Constraint* get_write_constraint() const { return constraint_write_; }
83
84   DiskImpl* set_read_bandwidth_profile(profile::Profile* profile);
85   DiskImpl* set_write_bandwidth_profile(profile::Profile* profile);
86
87   /** @brief Check if the Disk is used (if an action currently uses its resources) */
88   bool is_used() const override;
89   void turn_on() override;
90   void turn_off() override;
91
92   void seal() override;
93   void destroy(); // Must be called instead of the destructor
94 };
95
96 /**********
97  * Action *
98  **********/
99
100 class DiskAction : public Action {
101 public:
102   static xbt::signal<void(DiskAction const&, Action::State, Action::State)> on_state_change;
103
104   using Action::Action;
105   void set_state(simgrid::kernel::resource::Action::State state) override;
106
107   double sharing_penalty_ = {};
108 };
109
110 } // namespace resource
111 } // namespace kernel
112 } // namespace simgrid
113 #endif /* DISK_INTERFACE_HPP_ */