Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines with new year.
[simgrid.git] / src / kernel / resource / DiskImpl.cpp
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 "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(disk_kernel, surf, "Logging specific to the disk kernel resource");
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
38 DiskImpl::DiskImpl(kernel::resource::Model* model, const std::string& name, kernel::lmm::System* maxminSystem,
39                    double read_bw, double write_bw)
40     : Resource(model, name, maxminSystem->constraint_new(this, std::max(read_bw, write_bw)))
41     , piface_(name, this)
42     , read_bw_(read_bw)
43     , write_bw_(write_bw)
44 {
45   DiskImpl::turn_on();
46   XBT_DEBUG("Create resource with read_bw '%f' write_bw '%f'", read_bw_, write_bw_);
47   constraint_read_  = maxminSystem->constraint_new(this, read_bw);
48   constraint_write_ = maxminSystem->constraint_new(this, write_bw);
49 }
50
51 DiskImpl::~DiskImpl()
52 {
53   xbt_assert(currently_destroying_, "Don't delete Disks directly. Call destroy() instead.");
54 }
55
56 /** @brief Fire the required callbacks and destroy the object
57  *
58  * Don't delete directly a Disk, call d->destroy() instead.
59  */
60 void DiskImpl::destroy()
61 {
62   if (not currently_destroying_) {
63     currently_destroying_ = true;
64     s4u::Disk::on_destruction(this->piface_);
65     delete this;
66   }
67 }
68
69 bool DiskImpl::is_used()
70 {
71   THROW_UNIMPLEMENTED;
72 }
73
74 void DiskImpl::apply_event(kernel::profile::Event* /*event*/, double /*value*/)
75 {
76   THROW_UNIMPLEMENTED;
77 }
78
79 void DiskImpl::turn_on()
80 {
81   if (not is_on()) {
82     Resource::turn_on();
83     s4u::Disk::on_state_change(this->piface_);
84   }
85 }
86 void DiskImpl::turn_off()
87 {
88   if (is_on()) {
89     Resource::turn_off();
90     s4u::Disk::on_state_change(this->piface_);
91   }
92 }
93
94 xbt::signal<void(DiskAction const&, Action::State, Action::State)> DiskAction::on_state_change;
95
96 /**********
97  * Action *
98  **********/
99 void DiskAction::set_state(Action::State state)
100 {
101   Action::State old = get_state();
102   Action::set_state(state);
103   on_state_change(*this, old, state);
104 }
105 } // namespace resource
106 } // namespace kernel
107 } // namespace simgrid