Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add boolean state to resources and protect set_core_count
[simgrid.git] / src / kernel / resource / DiskImpl.cpp
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 "DiskImpl.hpp"
7
8 #include "simgrid/s4u/Engine.hpp"
9 #include "src/kernel/EngineImpl.hpp"
10 #include "src/kernel/lmm/maxmin.hpp"
11
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(res_disk, ker_resource, "Disk resources, fuelling I/O activities");
13
14 simgrid::kernel::resource::DiskModel* surf_disk_model = nullptr;
15
16 namespace simgrid {
17 namespace kernel {
18 namespace resource {
19
20 /*********
21  * Model *
22  *********/
23
24 DiskModel::DiskModel() : Model(Model::UpdateAlgo::FULL)
25 {
26   set_maxmin_system(new simgrid::kernel::lmm::System(true /* selective update */));
27 }
28
29 DiskModel::~DiskModel()
30 {
31   surf_disk_model = nullptr;
32 }
33
34 /************
35  * Resource *
36  ************/
37 DiskImpl* DiskImpl::set_host(s4u::Host* host)
38 {
39   host_ = host;
40   return this;
41 }
42
43 DiskImpl* DiskImpl::set_read_bandwidth(double read_bw)
44 {
45   read_bw_ = read_bw;
46   return this;
47 }
48
49 DiskImpl* DiskImpl::set_write_bandwidth(double write_bw)
50 {
51   write_bw_ = write_bw;
52   return this;
53 }
54
55 DiskImpl* DiskImpl::set_read_constraint(lmm::Constraint* constraint_read)
56 {
57   constraint_read_  = constraint_read;
58   return this;
59 }
60
61 DiskImpl* DiskImpl::set_write_constraint(lmm::Constraint* constraint_write)
62 {
63   constraint_write_  = constraint_write;
64   return this;
65 }
66
67 /** @brief Fire the required callbacks and destroy the object
68  *
69  * Don't delete directly a Disk, call d->destroy() instead.
70  */
71 void DiskImpl::destroy()
72 {
73   s4u::Disk::on_destruction(this->piface_);
74   delete this;
75 }
76
77 bool DiskImpl::is_used() const
78 {
79   THROW_UNIMPLEMENTED;
80 }
81
82 void DiskImpl::apply_event(kernel::profile::Event* /*event*/, double /*value*/)
83 {
84   THROW_UNIMPLEMENTED;
85 }
86
87 void DiskImpl::turn_on()
88 {
89   if (not is_on()) {
90     Resource::turn_on();
91     s4u::Disk::on_state_change(this->piface_);
92   }
93 }
94 void DiskImpl::turn_off()
95 {
96   if (is_on()) {
97     Resource::turn_off();
98     s4u::Disk::on_state_change(this->piface_);
99   }
100 }
101
102 void DiskImpl::seal()
103 {
104   lmm::System* maxmin_system = get_model()->get_maxmin_system();
105   this->set_read_constraint(maxmin_system->constraint_new(this, read_bw_))
106       ->set_write_constraint(maxmin_system->constraint_new(this, write_bw_))
107       ->set_constraint(maxmin_system->constraint_new(this, std::max(read_bw_, write_bw_)));
108   XBT_DEBUG("Create resource with read_bw '%f' write_bw '%f'", read_bw_, write_bw_);
109   Resource::seal();
110   turn_on();
111 }
112 xbt::signal<void(DiskAction const&, Action::State, Action::State)> DiskAction::on_state_change;
113
114 /**********
115  * Action *
116  **********/
117 void DiskAction::set_state(Action::State state)
118 {
119   Action::State old = get_state();
120   Action::set_state(state);
121   on_state_change(*this, old, state);
122 }
123 } // namespace resource
124 } // namespace kernel
125 } // namespace simgrid