1 /* Copyright (c) 2013-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 "disk_s19.hpp"
7 #include "simgrid/kernel/routing/NetPoint.hpp"
8 #include "simgrid/s4u/Engine.hpp"
9 #include "simgrid/s4u/Host.hpp"
10 #include "src/kernel/lmm/maxmin.hpp"
11 #include "src/surf/xml/platf.hpp"
12 #include "surf/surf.hpp"
14 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(res_disk);
20 void surf_disk_model_init_default()
22 surf_disk_model = new simgrid::kernel::resource::DiskS19Model();
29 DiskS19Model::DiskS19Model()
31 all_existing_models.push_back(this);
34 DiskImpl* DiskS19Model::createDisk(const std::string& id, double read_bw, double write_bw)
36 XBT_DEBUG("SURF disk create resource\n\t\tid '%s'\n\t\tread_bw '%f'\n", id.c_str(), read_bw);
38 return new DiskS19(this, id, read_bw, write_bw);
41 double DiskS19Model::next_occurring_event(double now)
43 return DiskModel::next_occurring_event_full(now);
46 void DiskS19Model::update_actions_state(double /*now*/, double delta)
48 for (auto it = std::begin(*get_started_action_set()); it != std::end(*get_started_action_set());) {
50 ++it; // increment iterator here since the following calls to action.finish() may invalidate it
51 action.update_remains(rint(action.get_variable()->get_value() * delta));
52 action.update_max_duration(delta);
54 if (((action.get_remains_no_update() <= 0) && (action.get_variable()->get_penalty() > 0)) ||
55 ((action.get_max_duration() != NO_MAX_DURATION) && (action.get_max_duration() <= 0))) {
56 action.finish(Action::State::FINISHED);
65 DiskS19::DiskS19(DiskModel* model, const std::string& name, double read_bw, double write_bw)
68 lmm::System* maxmin_system = model->get_maxmin_system();
69 this->set_read_bandwidth(read_bw)
70 ->set_write_bandwidth(write_bw)
71 ->set_read_constraint(maxmin_system->constraint_new(this, read_bw))
72 ->set_write_constraint(maxmin_system->constraint_new(this, write_bw))
75 ->set_constraint(maxmin_system->constraint_new(this, std::max(read_bw, write_bw)));
76 XBT_DEBUG("Create resource with read_bw '%f' write_bw '%f'", read_bw, write_bw);
80 DiskAction* DiskS19::io_start(sg_size_t size, s4u::Io::OpType type)
82 return new DiskS19Action(get_model(), static_cast<double>(size), not is_on(), this, type);
85 DiskAction* DiskS19::read(sg_size_t size)
87 return new DiskS19Action(get_model(), static_cast<double>(size), not is_on(), this, s4u::Io::OpType::READ);
90 DiskAction* DiskS19::write(sg_size_t size)
92 return new DiskS19Action(get_model(), static_cast<double>(size), not is_on(), this, s4u::Io::OpType::WRITE);
99 DiskS19Action::DiskS19Action(Model* model, double cost, bool failed, DiskImpl* disk, s4u::Io::OpType type)
100 : DiskAction(model, cost, failed, model->get_maxmin_system()->variable_new(this, 1.0, -1.0, 3), disk, type)
102 XBT_IN("(%s,%g", disk->get_cname(), cost);
104 // Must be less than the max bandwidth for all actions
105 model->get_maxmin_system()->expand(disk->get_constraint(), get_variable(), 1.0);
107 case s4u::Io::OpType::READ:
108 model->get_maxmin_system()->expand(disk->get_read_constraint(), get_variable(), 1.0);
110 case s4u::Io::OpType::WRITE:
111 model->get_maxmin_system()->expand(disk->get_write_constraint(), get_variable(), 1.0);
119 void DiskS19Action::cancel()
121 set_state(Action::State::FAILED);
124 void DiskS19Action::suspend()
126 XBT_IN("(%p)", this);
128 get_model()->get_maxmin_system()->update_variable_penalty(get_variable(), 0.0);
129 set_suspend_state(Action::SuspendStates::SUSPENDED);
134 void DiskS19Action::resume()
139 void DiskS19Action::set_max_duration(double /*duration*/)
144 void DiskS19Action::set_sharing_penalty(double)
148 void DiskS19Action::update_remains_lazy(double /*now*/)
152 } // namespace resource
153 } // namespace kernel
154 } // namespace simgrid