X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/3577c5ad9b3db70921211e8ec8fe16dfb076b6cf..6c56800bdad43cabb6c870c9163bbeea694d6692:/src/surf/network_cm02.cpp diff --git a/src/surf/network_cm02.cpp b/src/surf/network_cm02.cpp index cb1e7cfbdb..3dc1bd7d3d 100644 --- a/src/surf/network_cm02.cpp +++ b/src/surf/network_cm02.cpp @@ -12,7 +12,6 @@ #include "src/kernel/resource/profile/Event.hpp" #include "src/surf/network_wifi.hpp" #include "src/surf/surf_interface.hpp" -#include "surf/surf.hpp" #include #include @@ -40,8 +39,9 @@ double sg_weight_S_parameter = 0.0; /* default value; can be set by model or fro void surf_network_model_init_LegrandVelho() { auto net_model = std::make_shared("Network_LegrandVelho"); - simgrid::kernel::EngineImpl::get_instance()->add_model(net_model); - simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->set_network_model(net_model); + auto* engine = simgrid::kernel::EngineImpl::get_instance(); + engine->add_model(net_model); + engine->get_netzone_root()->set_network_model(net_model); simgrid::config::set_default("network/latency-factor", 13.01); simgrid::config::set_default("network/bandwidth-factor", 0.97); @@ -66,8 +66,9 @@ void surf_network_model_init_CM02() simgrid::config::set_default("network/weight-S", 0.0); auto net_model = std::make_shared("Network_CM02"); - simgrid::kernel::EngineImpl::get_instance()->add_model(net_model); - simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->set_network_model(net_model); + auto* engine = simgrid::kernel::EngineImpl::get_instance(); + engine->add_model(net_model); + engine->get_netzone_root()->set_network_model(net_model); } namespace simgrid { @@ -87,9 +88,9 @@ NetworkCm02Model::NetworkCm02Model(const std::string& name) : NetworkModel(name) } set_maxmin_system(new lmm::System(select)); - loopback_ = create_link("__loopback__", std::vector{config::get_value("network/loopback-bw")}) - ->set_sharing_policy(s4u::Link::SharingPolicy::FATPIPE) - ->set_latency(config::get_value("network/loopback-lat")); + loopback_ = create_link("__loopback__", {config::get_value("network/loopback-bw")}); + loopback_->set_sharing_policy(s4u::Link::SharingPolicy::FATPIPE, {}); + loopback_->set_latency(config::get_value("network/loopback-lat")); loopback_->seal(); } @@ -130,12 +131,16 @@ void NetworkCm02Model::set_bw_factor_cb(const std::function& cb LinkImpl* NetworkCm02Model::create_link(const std::string& name, const std::vector& bandwidths) { xbt_assert(bandwidths.size() == 1, "Non-WIFI links must use only 1 bandwidth."); - return (new NetworkCm02Link(name, bandwidths[0], get_maxmin_system()))->set_model(this); + auto link = new NetworkCm02Link(name, bandwidths[0], get_maxmin_system()); + link->set_model(this); + return link; } LinkImpl* NetworkCm02Model::create_wifi_link(const std::string& name, const std::vector& bandwidths) { - return (new NetworkWifiLink(name, bandwidths, get_maxmin_system()))->set_model(this); + auto link = new NetworkWifiLink(name, bandwidths, get_maxmin_system()); + link->set_model(this); + return link; } void NetworkCm02Model::update_actions_state_lazy(double now, double /*delta*/) @@ -187,7 +192,7 @@ void NetworkCm02Model::update_actions_state_full(double /*now*/, double delta) */ action.update_remains(action.get_remains()); } - action.update_remains(action.get_variable()->get_value() * delta); + action.update_remains(action.get_rate() * delta); if (action.get_max_duration() != NO_MAX_DURATION) action.update_max_duration(delta); @@ -200,12 +205,13 @@ void NetworkCm02Model::update_actions_state_full(double /*now*/, double delta) } void NetworkCm02Model::comm_action_expand_constraints(const s4u::Host* src, const s4u::Host* dst, - NetworkCm02Action* action, const std::vector& route, - const std::vector& back_route) + const NetworkCm02Action* action, + const std::vector& route, + const std::vector& back_route) const { /* expand route links constraints for route and back_route */ - NetworkWifiLink* src_wifi_link = nullptr; - NetworkWifiLink* dst_wifi_link = nullptr; + const NetworkWifiLink* src_wifi_link = nullptr; + const NetworkWifiLink* dst_wifi_link = nullptr; if (not route.empty() && route.front()->get_sharing_policy() == s4u::Link::SharingPolicy::WIFI) { src_wifi_link = static_cast(route.front()); } @@ -319,7 +325,8 @@ bool NetworkCm02Model::comm_get_route_info(const s4u::Host* src, const s4u::Host void NetworkCm02Model::comm_action_set_bounds(const s4u::Host* src, const s4u::Host* dst, double size, NetworkCm02Action* action, const std::vector& route, - const std::unordered_set& netzones) + const std::unordered_set& netzones, + double rate) { std::vector s4u_route; std::unordered_set s4u_netzones; @@ -336,19 +343,28 @@ void NetworkCm02Model::comm_action_set_bounds(const s4u::Host* src, const s4u::H } else { bw_factor = get_bandwidth_factor(size); } - /* get mininum bandwidth among links in the route and multiply by correct factor */ - const auto& min_bw = std::min_element( - route.begin(), route.end(), [](const auto& a, const auto& b) { return a->get_bandwidth() < b->get_bandwidth(); }); - - double bandwidth_bound = min_bw == route.end() ? -1.0 : bw_factor * (*min_bw)->get_bandwidth(); - - if (bw_constraint_cb_) { - action->set_user_bound( - bw_constraint_cb_(action->get_user_bound(), bandwidth_bound, size, src, dst, s4u_route, s4u_netzones)); - } else { - action->set_user_bound(get_bandwidth_constraint(action->get_user_bound(), bandwidth_bound, size)); + xbt_assert(bw_factor != 0, "Invalid param for comm %s -> %s. Bandwidth factor cannot be 0", src->get_cname(), + dst->get_cname()); + action->set_rate_factor(bw_factor); + + /* get mininum bandwidth among links in the route and multiply by correct factor + * ignore wi-fi links, they're not considered for bw_factors */ + double bandwidth_bound = -1.0; + for (const auto* l : route) { + if (l->get_sharing_policy() == s4u::Link::SharingPolicy::WIFI) + continue; + if (bandwidth_bound == -1.0 || l->get_bandwidth() < bandwidth_bound) + bandwidth_bound = l->get_bandwidth(); } + /* increase rate given by user considering the factor, since the actual rate will be + * modified by it */ + rate = rate / bw_factor; + /* the bandwidth is determined by the minimum between flow and user's defined rate */ + if (rate >= 0 && rate < bandwidth_bound) + bandwidth_bound = rate; + action->set_user_bound(bandwidth_bound); + action->lat_current_ = action->latency_; if (lat_factor_cb_) { action->latency_ *= lat_factor_cb_(size, src, dst, s4u_route, s4u_netzones); @@ -403,7 +419,6 @@ Action* NetworkCm02Model::communicate(s4u::Host* src, s4u::Host* dst, double siz NetworkCm02Action* action = comm_action_create(src, dst, size, route, failed); action->sharing_penalty_ = latency; action->latency_ = latency; - action->set_user_bound(rate); if (sg_weight_S_parameter > 0) { action->sharing_penalty_ = @@ -413,7 +428,7 @@ Action* NetworkCm02Model::communicate(s4u::Host* src, s4u::Host* dst, double siz } /* setting bandwidth and latency bounds considering route and configured bw/lat factors */ - comm_action_set_bounds(src, dst, size, action, route, netzones); + comm_action_set_bounds(src, dst, size, action, route, netzones, rate); /* creating the maxmin variable associated to this action */ comm_action_set_variable(action, route, back_route); @@ -422,7 +437,6 @@ Action* NetworkCm02Model::communicate(s4u::Host* src, s4u::Host* dst, double siz comm_action_expand_constraints(src, dst, action, route, back_route); XBT_OUT(); - simgrid::s4u::Link::on_communicate(*action); return action; } @@ -434,7 +448,7 @@ NetworkCm02Link::NetworkCm02Link(const std::string& name, double bandwidth, kern { bandwidth_.scale = 1.0; bandwidth_.peak = bandwidth; - this->set_constraint(system->constraint_new(this, sg_bandwidth_factor * bandwidth)); + this->set_constraint(system->constraint_new(this, bandwidth)); } void NetworkCm02Link::apply_event(kernel::profile::Event* triggered, double value) @@ -448,12 +462,12 @@ void NetworkCm02Link::apply_event(kernel::profile::Event* triggered, double valu set_latency(value); tmgr_trace_event_unref(&latency_.event); - } else if (triggered == state_event_) { + } else if (triggered == get_state_event()) { if (value > 0) turn_on(); else turn_off(); - tmgr_trace_event_unref(&state_event_); + unref_state_event(); } else { xbt_die("Unknown event!\n"); } @@ -464,19 +478,20 @@ void NetworkCm02Link::apply_event(kernel::profile::Event* triggered, double valu void NetworkCm02Link::set_bandwidth(double value) { + double old_peak = bandwidth_.peak; bandwidth_.peak = value; - get_model()->get_maxmin_system()->update_constraint_bound(get_constraint(), - sg_bandwidth_factor * (bandwidth_.peak * bandwidth_.scale)); + get_model()->get_maxmin_system()->update_constraint_bound(get_constraint(), (bandwidth_.peak * bandwidth_.scale)); LinkImpl::on_bandwidth_change(); if (sg_weight_S_parameter > 0) { - double delta = sg_weight_S_parameter / value - sg_weight_S_parameter / (bandwidth_.peak * bandwidth_.scale); + double delta = sg_weight_S_parameter / (bandwidth_.peak * bandwidth_.scale) - + sg_weight_S_parameter / (old_peak * bandwidth_.scale); const kernel::lmm::Element* elem = nullptr; const kernel::lmm::Element* nextelem = nullptr; - int numelem = 0; + size_t numelem = 0; while (const auto* var = get_constraint()->get_variable_safe(&elem, &nextelem, &numelem)) { auto* action = static_cast(var->get_id()); action->sharing_penalty_ += delta; @@ -486,14 +501,14 @@ void NetworkCm02Link::set_bandwidth(double value) } } -LinkImpl* NetworkCm02Link::set_latency(double value) +void NetworkCm02Link::set_latency(double value) { latency_check(value); double delta = value - latency_.peak; const kernel::lmm::Element* elem = nullptr; const kernel::lmm::Element* nextelem = nullptr; - int numelem = 0; + size_t numelem = 0; latency_.scale = 1.0; latency_.peak = value; @@ -511,15 +526,14 @@ LinkImpl* NetworkCm02Link::set_latency(double value) std::min(action->get_user_bound(), NetworkModel::cfg_tcp_gamma / (2.0 * action->lat_current_))); if (action->get_user_bound() < NetworkModel::cfg_tcp_gamma / (2.0 * action->lat_current_)) { - XBT_INFO("Flow is limited BYBANDWIDTH"); + XBT_DEBUG("Flow is limited BYBANDWIDTH"); } else { - XBT_INFO("Flow is limited BYLATENCY, latency of flow is %f", action->lat_current_); + XBT_DEBUG("Flow is limited BYLATENCY, latency of flow is %f", action->lat_current_); } } if (not action->is_suspended()) get_model()->get_maxmin_system()->update_variable_penalty(action->get_variable(), action->sharing_penalty_); } - return this; } /********** @@ -550,7 +564,7 @@ void NetworkCm02Action::update_remains_lazy(double now) } set_last_update(); - set_last_value(get_variable()->get_value()); + set_last_value(get_rate()); } } // namespace resource