Logo AND Algorithmique Numérique Distribuée

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