1 /* Copyright (c) 2013-2017. 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/s4u/Engine.hpp"
8 #include "src/kernel/routing/NetPoint.hpp"
9 #include "surf/maxmin.hpp"
10 #include <cmath> /*ceil*/
12 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_storage);
17 extern std::map<std::string, simgrid::surf::StorageType*> storage_types;
19 static void check_disk_attachment()
21 for (auto const& s : *simgrid::surf::StorageImpl::storagesMap()) {
22 simgrid::kernel::routing::NetPoint* host_elm = sg_netpoint_by_name_or_null(s.second->getHost().c_str());
24 surf_parse_error(std::string("Unable to attach storage ") + s.second->getCname() + ": host " +
25 s.second->getHost() + " does not exist.");
27 s.second->piface_.attached_to_ = sg_host_by_name(s.second->getHost().c_str());
31 void storage_register_callbacks()
33 simgrid::s4u::onPlatformCreated.connect(check_disk_attachment);
34 instr_routing_define_callbacks();
41 void surf_storage_model_init_default()
43 surf_storage_model = new simgrid::surf::StorageN11Model();
44 all_existing_models->push_back(surf_storage_model);
50 StorageImpl* StorageN11Model::createStorage(std::string id, std::string type_id, std::string content_name,
53 StorageType* storage_type = storage_types.at(type_id);
55 double Bread = surf_parse_get_bandwidth(storage_type->model_properties->at("Bread").c_str(),
56 "property Bread, storage", type_id.c_str());
57 double Bwrite = surf_parse_get_bandwidth(storage_type->model_properties->at("Bwrite").c_str(),
58 "property Bwrite, storage", type_id.c_str());
60 StorageImpl* storage =
61 new StorageN11(this, id, maxminSystem_, Bread, Bwrite, type_id, content_name, storage_type->size, attach);
62 storageCreatedCallbacks(storage);
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 p_storageList.push_back(storage);
72 double StorageN11Model::nextOccuringEvent(double now)
74 return StorageModel::nextOccuringEventFull(now);
77 void StorageN11Model::updateActionsState(double /*now*/, double delta)
79 for (auto it = std::begin(*getRunningActionSet()); it != std::end(*getRunningActionSet());) {
80 StorageAction& action = static_cast<StorageAction&>(*it);
81 ++it; // increment iterator here since the following calls to action.finish() may invalidate it
82 action.updateRemains(lrint(action.getVariable()->get_value() * delta));
84 if (action.getMaxDuration() > NO_MAX_DURATION)
85 action.updateMaxDuration(delta);
87 if (((action.getRemainsNoUpdate() <= 0) && (action.getVariable()->get_weight() > 0)) ||
88 ((action.getMaxDuration() > NO_MAX_DURATION) && (action.getMaxDuration() <= 0))) {
89 action.finish(Action::State::done);
98 StorageN11::StorageN11(StorageModel* model, std::string name, lmm_system_t maxminSystem, double bread, double bwrite,
99 std::string type_id, std::string content_name, sg_size_t size, std::string attach)
100 : StorageImpl(model, name, maxminSystem, bread, bwrite, type_id, content_name, size, attach)
102 XBT_DEBUG("Create resource with Bread '%f' Bwrite '%f' and Size '%llu'", bread, bwrite, size);
103 simgrid::s4u::Storage::onCreation(this->piface_);
106 StorageAction* StorageN11::read(sg_size_t size)
108 return new StorageN11Action(model(), size, isOff(), this, READ);
111 StorageAction* StorageN11::write(sg_size_t size)
113 return new StorageN11Action(model(), size, isOff(), this, WRITE);
120 StorageN11Action::StorageN11Action(Model* model, double cost, bool failed, StorageImpl* storage,
121 e_surf_action_storage_type_t type)
122 : StorageAction(model, cost, failed, model->getMaxminSystem()->variable_new(this, 1.0, -1.0, 3), storage, type)
124 XBT_IN("(%s,%g", storage->getCname(), cost);
126 // Must be less than the max bandwidth for all actions
127 model->getMaxminSystem()->expand(storage->constraint(), getVariable(), 1.0);
130 model->getMaxminSystem()->expand(storage->constraintRead_, getVariable(), 1.0);
133 model->getMaxminSystem()->expand(storage->constraintWrite_, getVariable(), 1.0);
141 int StorageN11Action::unref()
145 if (action_hook.is_linked())
146 stateSet_->erase(stateSet_->iterator_to(*this));
148 getModel()->getMaxminSystem()->variable_free(getVariable());
149 xbt_free(getCategory());
156 void StorageN11Action::cancel()
158 setState(Action::State::failed);
161 void StorageN11Action::suspend()
163 XBT_IN("(%p)", this);
164 if (suspended_ != 2) {
165 getModel()->getMaxminSystem()->update_variable_weight(getVariable(), 0.0);
171 void StorageN11Action::resume()
176 bool StorageN11Action::isSuspended()
178 return suspended_ == 1;
181 void StorageN11Action::setMaxDuration(double /*duration*/)
186 void StorageN11Action::setSharingWeight(double /*priority*/)