Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Kill unused function simcall_call().
[simgrid.git] / src / surf / network_interface.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 "network_interface.hpp"
7 #include "simgrid/sg_config.hpp"
8 #include "src/instr/instr_private.hpp" // TRACE_is_enabled(). FIXME: remove by subscribing tracing to the surf signals
9 #include "src/surf/surf_interface.hpp"
10 #include "surf/surf.hpp"
11
12 #ifndef NETWORK_INTERFACE_CPP_
13 #define NETWORK_INTERFACE_CPP_
14
15 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_network, surf, "Logging specific to the SURF network module");
16
17 namespace simgrid {
18 namespace kernel {
19 namespace resource {
20
21 /* List of links */
22 std::unordered_map<std::string, LinkImpl*>* LinkImpl::links = new std::unordered_map<std::string, LinkImpl*>();
23
24 LinkImpl* LinkImpl::byName(std::string name)
25 {
26   auto link = links->find(name);
27   return link == links->end() ? nullptr : link->second;
28 }
29 /** @brief Returns the amount of links in the platform */
30 int LinkImpl::linksCount()
31 {
32   return links->size();
33 }
34 void LinkImpl::linksList(std::vector<s4u::Link*>* linkList)
35 {
36   for (auto const& kv : *links) {
37     linkList->push_back(&kv.second->piface_);
38   }
39 }
40
41 /** @brief Returns a list of all existing links */
42 LinkImpl** LinkImpl::linksList()
43 {
44   LinkImpl** res = xbt_new(LinkImpl*, (int)links->size());
45   int i          = 0;
46   for (auto const& kv : *links) {
47     res[i] = kv.second;
48     i++;
49   }
50   return res;
51 }
52 /** @brief destructor of the static data */
53 void LinkImpl::linksExit()
54 {
55   for (auto const& kv : *links)
56     (kv.second)->destroy();
57   delete links;
58 }
59 }
60 }
61 } // namespace simgrid
62
63 /*********
64  * Model *
65  *********/
66
67 simgrid::kernel::resource::NetworkModel* surf_network_model = nullptr;
68
69 namespace simgrid {
70 namespace kernel {
71 namespace resource {
72
73 /** @brief Command-line option 'network/TCP-gamma' -- see \ref options_model_network_gamma */
74 simgrid::config::Flag<double> NetworkModel::cfg_tcp_gamma(
75     "network/TCP-gamma", {"network/TCP_gamma"},
76     "Size of the biggest TCP window (cat /proc/sys/net/ipv4/tcp_[rw]mem for recv/send window; "
77     "Use the last given value, which is the max window size)",
78     4194304.0);
79
80 /** @brief Command-line option 'network/crosstraffic' -- see \ref options_model_network_crosstraffic */
81 simgrid::config::Flag<bool> NetworkModel::cfg_crosstraffic(
82     "network/crosstraffic",
83     "Activate the interferences between uploads and downloads for fluid max-min models (LV08, CM02)", "yes");
84
85 NetworkModel::~NetworkModel() = default;
86
87 double NetworkModel::latencyFactor(double /*size*/)
88 {
89   return sg_latency_factor;
90 }
91
92 double NetworkModel::bandwidthFactor(double /*size*/)
93 {
94   return sg_bandwidth_factor;
95 }
96
97 double NetworkModel::bandwidthConstraint(double rate, double /*bound*/, double /*size*/)
98 {
99   return rate;
100 }
101
102 double NetworkModel::next_occuring_event_full(double now)
103 {
104   double minRes = Model::next_occuring_event_full(now);
105
106   for (Action const& action : *get_running_action_set()) {
107     const NetworkAction& net_action = static_cast<const NetworkAction&>(action);
108     if (net_action.latency_ > 0)
109       minRes = (minRes < 0) ? net_action.latency_ : std::min(minRes, net_action.latency_);
110   }
111
112   XBT_DEBUG("Min of share resources %f", minRes);
113
114   return minRes;
115 }
116
117 /************
118  * Resource *
119  ************/
120
121 LinkImpl::LinkImpl(NetworkModel* model, const std::string& name, lmm::Constraint* constraint)
122     : Resource(model, name, constraint), piface_(this)
123 {
124
125   if (name != "__loopback__")
126     xbt_assert(not LinkImpl::byName(name), "Link '%s' declared several times in the platform.", name.c_str());
127
128   latency_.scale   = 1;
129   bandwidth_.scale = 1;
130
131   links->insert({name, this});
132   XBT_DEBUG("Create link '%s'", name.c_str());
133 }
134
135 /** @brief use destroy() instead of this destructor */
136 LinkImpl::~LinkImpl()
137 {
138   xbt_assert(currentlyDestroying_, "Don't delete Links directly. Call destroy() instead.");
139 }
140 /** @brief Fire the required callbacks and destroy the object
141  *
142  * Don't delete directly a Link, call l->destroy() instead.
143  */
144 void LinkImpl::destroy()
145 {
146   if (not currentlyDestroying_) {
147     currentlyDestroying_ = true;
148     s4u::Link::on_destruction(this->piface_);
149     delete this;
150   }
151 }
152
153 bool LinkImpl::is_used()
154 {
155   return get_model()->get_maxmin_system()->constraint_used(get_constraint());
156 }
157
158 double LinkImpl::latency()
159 {
160   return latency_.peak * latency_.scale;
161 }
162
163 double LinkImpl::bandwidth()
164 {
165   return bandwidth_.peak * bandwidth_.scale;
166 }
167
168 s4u::Link::SharingPolicy LinkImpl::sharingPolicy()
169 {
170   return get_constraint()->get_sharing_policy();
171 }
172
173 void LinkImpl::turn_on()
174 {
175   if (is_off()) {
176     Resource::turn_on();
177     s4u::Link::on_state_change(this->piface_);
178   }
179 }
180 void LinkImpl::turn_off()
181 {
182   if (is_on()) {
183     Resource::turn_off();
184     s4u::Link::on_state_change(this->piface_);
185   }
186 }
187
188 void LinkImpl::on_bandwidth_change()
189 {
190   if (TRACE_categorized() || TRACE_uncategorized() || TRACE_platform())
191     instr::Container::by_name(get_cname())
192         ->get_variable("bandwidth")
193         ->set_event(surf_get_clock(), sg_bandwidth_factor * bandwidth_.scale * bandwidth_.peak);
194   s4u::Link::on_bandwidth_change(this->piface_);
195 }
196
197 void LinkImpl::setStateTrace(tmgr_trace_t trace)
198 {
199   xbt_assert(stateEvent_ == nullptr, "Cannot set a second state trace to Link %s", get_cname());
200   stateEvent_ = future_evt_set->add_trace(trace, this);
201 }
202 void LinkImpl::setBandwidthTrace(tmgr_trace_t trace)
203 {
204   xbt_assert(bandwidth_.event == nullptr, "Cannot set a second bandwidth trace to Link %s", get_cname());
205   bandwidth_.event = future_evt_set->add_trace(trace, this);
206 }
207 void LinkImpl::setLatencyTrace(tmgr_trace_t trace)
208 {
209   xbt_assert(latency_.event == nullptr, "Cannot set a second latency trace to Link %s", get_cname());
210   latency_.event = future_evt_set->add_trace(trace, this);
211 }
212
213 /**********
214  * Action *
215  **********/
216
217 void NetworkAction::set_state(Action::State state)
218 {
219   Action::set_state(state);
220   s4u::Link::on_communication_state_change(this);
221 }
222
223 /** @brief returns a list of all Links that this action is using */
224 std::list<LinkImpl*> NetworkAction::links()
225 {
226   std::list<LinkImpl*> retlist;
227   int llen = get_variable()->get_number_of_constraint();
228
229   for (int i = 0; i < llen; i++) {
230     /* Beware of composite actions: ptasks put links and cpus together */
231     // extra pb: we cannot dynamic_cast from void*...
232     Resource* resource = static_cast<Resource*>(get_variable()->get_constraint(i)->get_id());
233     LinkImpl* link     = dynamic_cast<LinkImpl*>(resource);
234     if (link != nullptr)
235       retlist.push_back(link);
236   }
237
238   return retlist;
239 }
240 }
241 } // namespace kernel
242 }
243
244 #endif /* NETWORK_INTERFACE_CPP_ */