Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
make Model::update_algo a constant field, set at initialization only
[simgrid.git] / src / surf / StorageImpl.cpp
1 /* Copyright (c) 2013-2018. The SimGrid Team. All rights reserved.          */
2
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. */
5
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"
11
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_storage, surf, "Logging specific to the SURF storage module");
13
14 simgrid::surf::StorageModel* surf_storage_model = nullptr;
15
16 namespace simgrid {
17 namespace surf {
18
19 /*************
20  * Callbacks *
21  *************/
22
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;
28
29 /*********
30  * Model *
31  *********/
32
33 StorageModel::StorageModel() : Model(Model::UpdateAlgo::Full)
34 {
35   set_maxmin_system(new simgrid::kernel::lmm::System(true /* selective update */));
36 }
37
38 StorageModel::~StorageModel()
39 {
40   surf_storage_model = nullptr;
41 }
42
43 /************
44  * Resource *
45  ************/
46
47 StorageImpl::StorageImpl(kernel::resource::Model* model, std::string name, kernel::lmm::System* maxminSystem,
48                          double bread, double bwrite, std::string type_id, std::string content_name, sg_size_t size,
49                          std::string attach)
50     : Resource(model, name.c_str(), maxminSystem->constraint_new(this, std::max(bread, bwrite)))
51     , piface_(name, this)
52     , typeId_(type_id)
53     , content_name(content_name)
54     , size_(size)
55     , attach_(attach)
56 {
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);
61 }
62
63 StorageImpl::~StorageImpl()
64 {
65   storageDestructedCallbacks(this);
66 }
67
68 bool StorageImpl::is_used()
69 {
70   THROW_UNIMPLEMENTED;
71   return false;
72 }
73
74 void StorageImpl::apply_event(tmgr_trace_event_t /*event*/, double /*value*/)
75 {
76   THROW_UNIMPLEMENTED;
77 }
78
79 void StorageImpl::turnOn()
80 {
81   if (isOff()) {
82     Resource::turnOn();
83     storageStateChangedCallbacks(this, 0, 1);
84   }
85 }
86 void StorageImpl::turnOff()
87 {
88   if (isOn()) {
89     Resource::turnOff();
90     storageStateChangedCallbacks(this, 1, 0);
91   }
92 }
93
94 /**********
95  * Action *
96  **********/
97 void StorageAction::set_state(Action::State state)
98 {
99   Action::State old = get_state();
100   Action::set_state(state);
101   storageActionStateChangedCallbacks(this, old, state);
102 }
103 }
104 }