1 /* Copyright (c) 2013-2018. 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 "StorageImpl.hpp"
7 #include "simgrid/s4u/Engine.hpp"
8 #include "src/kernel/EngineImpl.hpp"
9 #include "src/kernel/lmm/maxmin.hpp"
10 #include "surf_private.hpp"
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_storage, surf, "Logging specific to the SURF storage module");
14 simgrid::surf::StorageModel* surf_storage_model = nullptr;
23 simgrid::xbt::signal<void(StorageImpl*)> storageCreatedCallbacks;
24 simgrid::xbt::signal<void(StorageImpl*)> storageDestructedCallbacks;
25 simgrid::xbt::signal<void(StorageImpl*, int, int)> storageStateChangedCallbacks; // signature: wasOn, isOn
26 simgrid::xbt::signal<void(StorageAction*, kernel::resource::Action::State, kernel::resource::Action::State)>
27 storageActionStateChangedCallbacks;
33 StorageModel::StorageModel() : Model()
35 maxminSystem_ = new simgrid::kernel::lmm::System(true /* lazy update */);
38 StorageModel::~StorageModel()
40 surf_storage_model = nullptr;
47 StorageImpl::StorageImpl(kernel::resource::Model* model, std::string name, lmm_system_t maxminSystem, double bread,
48 double bwrite, std::string type_id, std::string content_name, sg_size_t size,
50 : Resource(model, name.c_str(), maxminSystem->constraint_new(this, std::max(bread, bwrite)))
53 , content_name(content_name)
57 StorageImpl::turnOn();
58 XBT_DEBUG("Create resource with Bread '%f' Bwrite '%f' and Size '%llu'", bread, bwrite, size);
59 constraintRead_ = maxminSystem->constraint_new(this, bread);
60 constraintWrite_ = maxminSystem->constraint_new(this, bwrite);
63 StorageImpl::~StorageImpl()
65 storageDestructedCallbacks(this);
68 bool StorageImpl::isUsed()
74 void StorageImpl::apply_event(tmgr_trace_event_t /*event*/, double /*value*/)
79 void StorageImpl::turnOn()
83 storageStateChangedCallbacks(this, 0, 1);
86 void StorageImpl::turnOff()
90 storageStateChangedCallbacks(this, 1, 0);
97 void StorageAction::setState(Action::State state)
99 Action::State old = getState();
100 Action::setState(state);
101 storageActionStateChangedCallbacks(this, old, state);