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 "storage_n11.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"
13 #include "xbt/parse_units.hpp"
15 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_storage);
20 extern std::map<std::string, simgrid::kernel::resource::StorageType*, std::less<>> storage_types;
22 void check_disk_attachment()
24 for (auto const& s : simgrid::s4u::Engine::get_instance()->get_all_storages()) {
25 const simgrid::kernel::routing::NetPoint* host_elm =
26 simgrid::s4u::Engine::get_instance()->netpoint_by_name_or_null(s->get_impl()->get_host());
28 surf_parse_error(std::string("Unable to attach storage ") + s->get_cname() + ": host " +
29 s->get_impl()->get_host() + " does not exist.");
31 s->set_host(simgrid::s4u::Host::by_name(s->get_impl()->get_host()));
39 void surf_storage_model_init_default()
41 surf_storage_model = new simgrid::kernel::resource::StorageN11Model();
48 StorageN11Model::StorageN11Model()
50 all_existing_models.push_back(this);
53 StorageImpl* StorageN11Model::createStorage(std::string& filename, int lineno, const std::string& id,
54 const std::string& type_id, const std::string& content_name,
55 const std::string& attach)
57 const StorageType* storage_type = storage_types.at(type_id);
59 double Bread = xbt_parse_get_bandwidth(filename, lineno, storage_type->model_properties->at("Bread").c_str(),
60 "property Bread, storage", type_id);
61 double Bwrite = xbt_parse_get_bandwidth(filename, lineno, storage_type->model_properties->at("Bwrite").c_str(),
62 "property Bwrite, storage", type_id);
64 XBT_DEBUG("SURF storage create resource\n\t\tid '%s'\n\t\ttype '%s'\n\t\tBread '%f'\n", id.c_str(), type_id.c_str(),
67 return new StorageN11(this, id, get_maxmin_system(), Bread, Bwrite, type_id, content_name, storage_type->size,
71 double StorageN11Model::next_occurring_event(double now)
73 return StorageModel::next_occurring_event_full(now);
76 void StorageN11Model::update_actions_state(double /*now*/, double delta)
78 for (auto it = std::begin(*get_started_action_set()); it != std::end(*get_started_action_set());) {
80 ++it; // increment iterator here since the following calls to action.finish() may invalidate it
81 action.update_remains(rint(action.get_variable()->get_value() * delta));
82 action.update_max_duration(delta);
84 if (((action.get_remains_no_update() <= 0) && (action.get_variable()->get_penalty() > 0)) ||
85 ((action.get_max_duration() != NO_MAX_DURATION) && (action.get_max_duration() <= 0))) {
86 action.finish(Action::State::FINISHED);
95 StorageN11::StorageN11(StorageModel* model, const std::string& name, lmm::System* maxminSystem, double bread,
96 double bwrite, const std::string& type_id, const std::string& content_name, sg_size_t size,
97 const std::string& attach)
98 : StorageImpl(model, name, maxminSystem, bread, bwrite, type_id, content_name, size, attach)
100 XBT_DEBUG("Create resource with Bread '%f' Bwrite '%f' and Size '%llu'", bread, bwrite, size);
101 s4u::Storage::on_creation(*get_iface());
104 StorageAction* StorageN11::io_start(sg_size_t size, s4u::Io::OpType type)
106 return new StorageN11Action(get_model(), static_cast<double>(size), not is_on(), this, type);
109 StorageAction* StorageN11::read(sg_size_t size)
111 return new StorageN11Action(get_model(), static_cast<double>(size), not is_on(), this, s4u::Io::OpType::READ);
114 StorageAction* StorageN11::write(sg_size_t size)
116 return new StorageN11Action(get_model(), static_cast<double>(size), not is_on(), this, s4u::Io::OpType::WRITE);
123 StorageN11Action::StorageN11Action(Model* model, double cost, bool failed, StorageImpl* storage, s4u::Io::OpType type)
124 : StorageAction(model, cost, failed, model->get_maxmin_system()->variable_new(this, 1.0, -1.0, 3), storage, type)
126 XBT_IN("(%s,%g", storage->get_cname(), cost);
128 // Must be less than the max bandwidth for all actions
129 model->get_maxmin_system()->expand(storage->get_constraint(), get_variable(), 1.0);
131 case s4u::Io::OpType::READ:
132 model->get_maxmin_system()->expand(storage->get_read_constraint(), get_variable(), 1.0);
134 case s4u::Io::OpType::WRITE:
135 model->get_maxmin_system()->expand(storage->get_write_constraint(), get_variable(), 1.0);
143 void StorageN11Action::cancel()
145 set_state(Action::State::FAILED);
148 void StorageN11Action::suspend()
150 XBT_IN("(%p)", this);
152 get_model()->get_maxmin_system()->update_variable_penalty(get_variable(), 0.0);
153 set_suspend_state(Action::SuspendStates::SUSPENDED);
158 void StorageN11Action::resume()
163 void StorageN11Action::set_max_duration(double /*duration*/)
168 void StorageN11Action::set_sharing_penalty(double)
172 void StorageN11Action::update_remains_lazy(double /*now*/)
176 } // namespace resource
177 } // namespace kernel
178 } // namespace simgrid