Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
please sonar
[simgrid.git] / src / kernel / resource / DiskImpl.hpp
1 /* Copyright (c) 2019-2020. 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 XBT_PUBLIC_DATA simgrid::kernel::resource::DiskModel* surf_disk_model;
24
25 namespace simgrid {
26 namespace kernel {
27 namespace resource {
28 /***********
29  * Classes *
30  ***********/
31
32 class DiskAction;
33
34 /*********
35  * Model *
36  *********/
37 class DiskModel : public Model {
38 public:
39   DiskModel();
40   DiskModel(const DiskModel&) = delete;
41   DiskModel& operator=(const DiskModel&) = delete;
42   ~DiskModel();
43
44   virtual DiskImpl* createDisk(const std::string& id, double read_bw, double write_bw) = 0;
45 };
46
47 /************
48  * Resource *
49  ************/
50 class DiskImpl : public Resource, public xbt::PropertyHolder {
51   bool currently_destroying_ = false;
52   s4u::Host* host_           = nullptr;
53   s4u::Disk piface_;
54   double read_bw_;
55   double write_bw_;
56   lmm::Constraint* constraint_write_; /* Constraint for maximum write bandwidth*/
57   lmm::Constraint* constraint_read_;  /* Constraint for maximum write bandwidth*/
58
59 public:
60   DiskImpl(Model* model, const std::string& name, kernel::lmm::System* maxmin_system, double read_bw, double bwrite_bw);
61   DiskImpl(const DiskImpl&) = delete;
62   DiskImpl& operator=(const DiskImpl&) = delete;
63
64   ~DiskImpl() override;
65
66   /** @brief Public interface */
67   s4u::Disk* get_iface() { return &piface_; }
68   s4u::Host* get_host() const { return host_; }
69   void set_host(s4u::Host* host) { host_ = host; }
70
71   double get_read_bandwidth() { return read_bw_; }
72   double get_write_bandwidth() { return write_bw_; }
73   lmm::Constraint* get_read_constraint() const { return constraint_read_; }
74   lmm::Constraint* get_write_constraint() const { return constraint_write_; }
75
76   /** @brief Check if the Storage is used (if an action currently uses its resources) */
77   bool is_used() override;
78   void apply_event(profile::Event* event, double value) override;
79   void turn_on() override;
80   void turn_off() override;
81
82   void destroy(); // Must be called instead of the destructor
83   virtual DiskAction* io_start(sg_size_t size, s4u::Io::OpType type) = 0;
84   virtual DiskAction* read(sg_size_t size)                           = 0;
85   virtual DiskAction* write(sg_size_t size)                          = 0;
86 };
87
88 /**********
89  * Action *
90  **********/
91
92 class DiskAction : public Action {
93 public:
94   static xbt::signal<void(DiskAction const&, Action::State, Action::State)> on_state_change;
95
96   DiskAction(Model* model, double cost, bool failed, DiskImpl* disk, s4u::Io::OpType type)
97       : Action(model, cost, failed), type_(type), disk_(disk){};
98
99   /**
100    * @brief diskAction constructor
101    *
102    * @param model The StorageModel associated to this DiskAction
103    * @param cost The cost of this DiskAction in bytes
104    * @param failed [description]
105    * @param var The lmm variable associated to this DiskAction if it is part of a LMM component
106    * @param storage The Storage associated to this DiskAction
107    * @param type [description]
108    */
109   DiskAction(kernel::resource::Model* model, double cost, bool failed, kernel::lmm::Variable* var, DiskImpl* disk,
110              s4u::Io::OpType type)
111       : Action(model, cost, failed, var), type_(type), disk_(disk){};
112
113   void set_state(simgrid::kernel::resource::Action::State state) override;
114
115   s4u::Io::OpType type_;
116   DiskImpl* disk_;
117 };
118
119 } // namespace resource
120 } // namespace kernel
121 } // namespace simgrid
122 #endif /* DISK_INTERFACE_HPP_ */