1 /* Copyright (c) 2019-2021. The SimGrid Team. All rights reserved. */
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. */
6 #include "DiskImpl.hpp"
8 #include "simgrid/s4u/Engine.hpp"
9 #include "src/kernel/EngineImpl.hpp"
10 #include "src/kernel/lmm/maxmin.hpp"
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(res_disk, ker_resource, "Disk resources, fuelling I/O activities");
14 simgrid::kernel::resource::DiskModel* surf_disk_model = nullptr;
24 DiskModel::DiskModel() : Model(Model::UpdateAlgo::FULL)
26 set_maxmin_system(new simgrid::kernel::lmm::System(true /* selective update */));
29 DiskModel::~DiskModel()
31 surf_disk_model = nullptr;
38 DiskImpl* DiskImpl::set_read_bandwidth(double read_bw)
44 DiskImpl* DiskImpl::set_write_bandwidth(double write_bw)
50 DiskImpl* DiskImpl::set_read_constraint(lmm::Constraint* constraint_read)
52 constraint_read_ = constraint_read;
56 DiskImpl* DiskImpl::set_write_constraint(lmm::Constraint* constraint_write)
58 constraint_write_ = constraint_write;
62 /** @brief Fire the required callbacks and destroy the object
64 * Don't delete directly a Disk, call d->destroy() instead.
66 void DiskImpl::destroy()
68 s4u::Disk::on_destruction(this->piface_);
72 bool DiskImpl::is_used() const
77 void DiskImpl::apply_event(kernel::profile::Event* /*event*/, double /*value*/)
82 void DiskImpl::turn_on()
86 s4u::Disk::on_state_change(this->piface_);
89 void DiskImpl::turn_off()
93 s4u::Disk::on_state_change(this->piface_);
99 lmm::System* maxmin_system = surf_disk_model->get_maxmin_system();
100 this->set_read_constraint(maxmin_system->constraint_new(this, read_bw_))
101 ->set_write_constraint(maxmin_system->constraint_new(this, write_bw_))
102 ->set_model(surf_disk_model)
103 ->set_constraint(maxmin_system->constraint_new(this, std::max(read_bw_, write_bw_)));
104 XBT_DEBUG("Create resource with read_bw '%f' write_bw '%f'", read_bw_, write_bw_);
107 xbt::signal<void(DiskAction const&, Action::State, Action::State)> DiskAction::on_state_change;
112 void DiskAction::set_state(Action::State state)
114 Action::State old = get_state();
115 Action::set_state(state);
116 on_state_change(*this, old, state);
118 } // namespace resource
119 } // namespace kernel
120 } // namespace simgrid