Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Also cleanup the network/weight-S parameter
[simgrid.git] / src / kernel / resource / NetworkModel.cpp
1 /* Copyright (c) 2013-2022. 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 <simgrid/s4u/Engine.hpp>
7
8 #include "simgrid/sg_config.hpp"
9 #include "src/kernel/resource/NetworkModel.hpp"
10 #include "src/kernel/resource/profile/Profile.hpp"
11 #include "src/surf/surf_interface.hpp"
12
13 #include <numeric>
14
15 #ifndef NETWORK_INTERFACE_CPP_
16 #define NETWORK_INTERFACE_CPP_
17
18 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(res_network, ker_resource, "Network resources, that fuel communications");
19
20 /*********
21  * Model *
22  *********/
23
24 namespace simgrid::kernel::resource {
25 double NetworkModel::cfg_latency_factor   = 1.0; // default value
26 double NetworkModel::cfg_bandwidth_factor = 1.0; // default value
27
28 /** @brief Command-line option 'network/TCP-gamma' -- see @ref options_model_network_gamma */
29 config::Flag<double> NetworkModel::cfg_tcp_gamma(
30     "network/TCP-gamma",
31     "Size of the biggest TCP window (cat /proc/sys/net/ipv4/tcp_[rw]mem for recv/send window; "
32     "Use the last given value, which is the max window size)",
33     4194304.0);
34
35 /** @brief Command-line option 'network/crosstraffic' -- see @ref options_model_network_crosstraffic */
36 config::Flag<bool> NetworkModel::cfg_crosstraffic(
37     "network/crosstraffic",
38     "Activate the interferences between uploads and downloads for fluid max-min models (LV08, CM02)", "yes");
39
40 config::Flag<double> NetworkModel::cfg_weight_S_parameter(
41     "network/weight-S",
42     "Correction factor to apply to the weight of competing streams (default value set by network model)", 0.0);
43
44 NetworkModel::~NetworkModel() = default;
45
46 double NetworkModel::next_occurring_event_full(double now)
47 {
48   double minRes = Model::next_occurring_event_full(now);
49
50   for (Action const& action : *get_started_action_set()) {
51     const auto& net_action = static_cast<const NetworkAction&>(action);
52     if (net_action.latency_ > 0)
53       minRes = (minRes < 0) ? net_action.latency_ : std::min(minRes, net_action.latency_);
54   }
55
56   XBT_DEBUG("Min of share resources %f", minRes);
57
58   return minRes;
59 }
60
61 /**********
62  * Action *
63  **********/
64
65 void NetworkAction::set_state(Action::State state)
66 {
67   Action::State previous = get_state();
68   if (previous != state) { // Trigger only if the state changed
69     Action::set_state(state);
70     s4u::Link::on_communication_state_change(*this, previous);
71   }
72 }
73
74 /** @brief returns a list of all Links that this action is using */
75 std::list<StandardLinkImpl*> NetworkAction::get_links() const
76 {
77   std::list<StandardLinkImpl*> retlist;
78   int llen = get_variable()->get_number_of_constraint();
79
80   for (int i = 0; i < llen; i++) {
81     /* Beware of composite actions: ptasks put links and cpus together */
82     if (auto* link = dynamic_cast<StandardLinkImpl*>(get_variable()->get_constraint(i)->get_id()))
83       retlist.push_back(link);
84   }
85
86   return retlist;
87 }
88
89 static void add_latency(const std::vector<StandardLinkImpl*>& links, double* latency)
90 {
91   if (latency)
92     *latency = std::accumulate(begin(links), end(links), *latency,
93                                [](double lat, const auto* link) { return lat + link->get_latency(); });
94 }
95
96 void add_link_latency(std::vector<StandardLinkImpl*>& result, StandardLinkImpl* link, double* latency)
97 {
98   result.push_back(link);
99   if (latency)
100     *latency += link->get_latency();
101 }
102
103 void add_link_latency(std::vector<StandardLinkImpl*>& result, const std::vector<StandardLinkImpl*>& links,
104                       double* latency)
105 {
106   result.insert(result.end(), begin(links), end(links));
107   add_latency(links, latency);
108 }
109
110 void insert_link_latency(std::vector<StandardLinkImpl*>& result, const std::vector<StandardLinkImpl*>& links,
111                          double* latency)
112 {
113   result.insert(result.begin(), rbegin(links), rend(links));
114   add_latency(links, latency);
115 }
116
117 } // namespace simgrid::kernel::resource
118
119 #endif /* NETWORK_INTERFACE_CPP_ */