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/lmm/maxmin.hpp"
9 #include "src/kernel/routing/NetPoint.hpp"
10 #include "xbt/utility.hpp"
11 #include <cmath> /*ceil*/
13 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_storage);
18 extern std::map<std::string, simgrid::surf::StorageType*> storage_types;
20 static void check_disk_attachment()
22 for (auto const& s : *simgrid::surf::StorageImpl::storagesMap()) {
23 simgrid::kernel::routing::NetPoint* host_elm = sg_netpoint_by_name_or_null(s.second->getHost().c_str());
25 surf_parse_error(std::string("Unable to attach storage ") + s.second->getCname() + ": host " +
26 s.second->getHost() + " does not exist.");
28 s.second->piface_.attached_to_ = sg_host_by_name(s.second->getHost().c_str());
32 void storage_register_callbacks()
34 simgrid::s4u::onPlatformCreated.connect(check_disk_attachment);
35 instr_routing_define_callbacks();
42 void surf_storage_model_init_default()
44 surf_storage_model = new simgrid::surf::StorageN11Model();
45 all_existing_models->push_back(surf_storage_model);
51 StorageImpl* StorageN11Model::createStorage(std::string id, std::string type_id, std::string content_name,
54 StorageType* storage_type = storage_types.at(type_id);
56 double Bread = surf_parse_get_bandwidth(storage_type->model_properties->at("Bread").c_str(),
57 "property Bread, storage", type_id.c_str());
58 double Bwrite = surf_parse_get_bandwidth(storage_type->model_properties->at("Bwrite").c_str(),
59 "property Bwrite, storage", type_id.c_str());
61 StorageImpl* storage =
62 new StorageN11(this, id, maxminSystem_, Bread, Bwrite, type_id, content_name, storage_type->size, attach);
63 storageCreatedCallbacks(storage);
65 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(),
68 p_storageList.push_back(storage);
73 double StorageN11Model::nextOccuringEvent(double now)
75 return StorageModel::nextOccuringEventFull(now);
78 void StorageN11Model::updateActionsState(double /*now*/, double delta)
80 for (auto it = std::begin(*getRunningActionSet()); it != std::end(*getRunningActionSet());) {
81 StorageAction& action = static_cast<StorageAction&>(*it);
82 ++it; // increment iterator here since the following calls to action.finish() may invalidate it
83 action.updateRemains(lrint(action.getVariable()->get_value() * delta));
85 if (action.getMaxDuration() > NO_MAX_DURATION)
86 action.updateMaxDuration(delta);
88 if (((action.getRemainsNoUpdate() <= 0) && (action.getVariable()->get_weight() > 0)) ||
89 ((action.getMaxDuration() > NO_MAX_DURATION) && (action.getMaxDuration() <= 0))) {
90 action.finish(Action::State::done);
99 StorageN11::StorageN11(StorageModel* model, std::string name, lmm_system_t maxminSystem, double bread, double bwrite,
100 std::string type_id, std::string content_name, sg_size_t size, std::string attach)
101 : StorageImpl(model, name, maxminSystem, bread, bwrite, type_id, content_name, size, attach)
103 XBT_DEBUG("Create resource with Bread '%f' Bwrite '%f' and Size '%llu'", bread, bwrite, size);
104 simgrid::s4u::Storage::onCreation(this->piface_);
107 StorageAction* StorageN11::read(sg_size_t size)
109 return new StorageN11Action(model(), size, isOff(), this, READ);
112 StorageAction* StorageN11::write(sg_size_t size)
114 return new StorageN11Action(model(), size, isOff(), this, WRITE);
121 StorageN11Action::StorageN11Action(Model* model, double cost, bool failed, StorageImpl* storage,
122 e_surf_action_storage_type_t type)
123 : StorageAction(model, cost, failed, model->getMaxminSystem()->variable_new(this, 1.0, -1.0, 3), storage, type)
125 XBT_IN("(%s,%g", storage->getCname(), cost);
127 // Must be less than the max bandwidth for all actions
128 model->getMaxminSystem()->expand(storage->constraint(), getVariable(), 1.0);
131 model->getMaxminSystem()->expand(storage->constraintRead_, getVariable(), 1.0);
134 model->getMaxminSystem()->expand(storage->constraintWrite_, getVariable(), 1.0);
142 int StorageN11Action::unref()
146 if (action_hook.is_linked())
147 simgrid::xbt::intrusive_erase(*stateSet_, *this);
149 getModel()->getMaxminSystem()->variable_free(getVariable());
150 xbt_free(getCategory());
157 void StorageN11Action::cancel()
159 setState(Action::State::failed);
162 void StorageN11Action::suspend()
164 XBT_IN("(%p)", this);
165 if (suspended_ != 2) {
166 getModel()->getMaxminSystem()->update_variable_weight(getVariable(), 0.0);
172 void StorageN11Action::resume()
177 bool StorageN11Action::isSuspended()
179 return suspended_ == 1;
182 void StorageN11Action::setMaxDuration(double /*duration*/)
187 void StorageN11Action::setSharingWeight(double /*priority*/)