Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
start implementing what is behind the new <disk> tag
[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/Io.hpp"
10 #include "src/surf/PropertyHolder.hpp"
11 #include "src/surf/surf_interface.hpp"
12
13 #include <map>
14
15 #ifndef DISK_INTERFACE_HPP_
16 #define DISK_INTERFACE_HPP_
17
18 /*********
19  * Model *
20  *********/
21
22 XBT_PUBLIC_DATA simgrid::kernel::resource::DiskModel* surf_disk_model;
23
24 namespace simgrid {
25 namespace kernel {
26 namespace resource {
27 /***********
28  * Classes *
29  ***********/
30
31 class DiskAction;
32
33 /*********
34  * Model *
35  *********/
36 class DiskModel : public kernel::resource::Model {
37 public:
38   DiskModel();
39   DiskModel(const DiskModel&) = delete;
40   DiskModel& operator=(const DiskModel&) = delete;
41   ~DiskModel();
42
43   virtual DiskImpl* createDisk(const std::string& id, double read_bw, double write_bw) = 0;
44 };
45
46 /************
47  * Resource *
48  ************/
49 class DiskImpl : public Resource, public surf::PropertyHolder {
50   bool currently_destroying_ = false;
51
52 public:
53   DiskImpl(Model* model, const std::string& name, kernel::lmm::System* maxmin_system, double read_bw, double bwrite_bw);
54   DiskImpl(const DiskImpl&) = delete;
55   DiskImpl& operator=(const DiskImpl&) = delete;
56
57   ~DiskImpl() override;
58
59   /** @brief Public interface */
60   // FIXME s4u::Storage piface_;
61
62   /** @brief Check if the Storage is used (if an action currently uses its resources) */
63   bool is_used() override;
64
65   void apply_event(profile::Event* event, double value) override;
66
67   void turn_on() override;
68   void turn_off() override;
69
70   void destroy(); // Must be called instead of the destructor
71   virtual DiskAction* io_start(sg_size_t size, s4u::Io::OpType type) = 0;
72   virtual DiskAction* read(sg_size_t size)                           = 0;
73   virtual DiskAction* write(sg_size_t size)                          = 0;
74
75   lmm::Constraint* constraint_write_; /* Constraint for maximum write bandwidth*/
76   lmm::Constraint* constraint_read_;  /* Constraint for maximum write bandwidth*/
77 };
78
79 /**********
80  * Action *
81  **********/
82
83 class DiskAction : public Action {
84 public:
85   static xbt::signal<void(DiskAction const&, Action::State, Action::State)> on_state_change;
86
87   DiskAction(Model* model, double cost, bool failed, DiskImpl* disk, s4u::Io::OpType type)
88       : Action(model, cost, failed), type_(type), disk_(disk){};
89
90   /**
91    * @brief diskAction constructor
92    *
93    * @param model The StorageModel associated to this DiskAction
94    * @param cost The cost of this DiskAction in bytes
95    * @param failed [description]
96    * @param var The lmm variable associated to this DiskAction if it is part of a LMM component
97    * @param storage The Storage associated to this DiskAction
98    * @param type [description]
99    */
100   DiskAction(kernel::resource::Model* model, double cost, bool failed, kernel::lmm::Variable* var, DiskImpl* disk,
101              s4u::Io::OpType type)
102       : Action(model, cost, failed, var), type_(type), disk_(disk){};
103
104   void set_state(simgrid::kernel::resource::Action::State state) override;
105
106   s4u::Io::OpType type_;
107   DiskImpl* disk_;
108 };
109
110 } // namespace resource
111 } // namespace kernel
112 } // namespace simgrid
113 #endif /* DISK_INTERFACE_HPP_ */