Logo AND Algorithmique Numérique Distribuée

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