X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/b8be0a3a0322cb22b312549b0e8af9156b221abf..5ed37babb2fa9097abe82df299c0aa259ed84d5a:/src/kernel/resource/WifiLinkImpl.cpp diff --git a/src/kernel/resource/WifiLinkImpl.cpp b/src/kernel/resource/WifiLinkImpl.cpp index afa0c00905..52e5222614 100644 --- a/src/kernel/resource/WifiLinkImpl.cpp +++ b/src/kernel/resource/WifiLinkImpl.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2019-2022. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2019-2023. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -7,12 +7,11 @@ #include "src/kernel/resource/WifiLinkImpl.hpp" #include "src/surf/surf_interface.hpp" +#include "src/kernel/activity/CommImpl.hpp" XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(res_network); -namespace simgrid { -namespace kernel { -namespace resource { +namespace simgrid::kernel::resource { /************ * Resource * @@ -24,14 +23,13 @@ WifiLinkImpl::WifiLinkImpl(const std::string& name, const std::vector& b this->set_constraint(system->constraint_new(this, 1)); for (auto bandwidth : bandwidths) bandwidths_.push_back({bandwidth, 1.0, nullptr}); + kernel::activity::CommImpl::on_start.connect(&update_bw_comm_start); + s4u::Link::on_communication_state_change_cb(&update_bw_comm_end); } void WifiLinkImpl::set_host_rate(const s4u::Host* host, int rate_level) { host_rates_[host->get_name()] = rate_level; - - // Each time we add a host, we refresh the decay model - refresh_decay_bandwidths(); } double WifiLinkImpl::get_host_rate(const s4u::Host* host) const @@ -49,7 +47,7 @@ double WifiLinkImpl::get_host_rate(const s4u::Host* host) const "Link '%s' only has %zu wifi rate levels, so the provided level %d is invalid for host '%s'.", this->get_cname(), bandwidths_.size(), rate_id, host->get_cname()); - Metric rate = use_decay_model_ ? decay_bandwidths_[rate_id] : bandwidths_[rate_id]; + Metric rate = bandwidths_[rate_id]; return rate.peak * rate.scale; } @@ -63,37 +61,87 @@ size_t WifiLinkImpl::get_host_count() const return host_rates_.size(); } -void WifiLinkImpl::refresh_decay_bandwidths() +double WifiLinkImpl::wifi_link_dynamic_sharing(const WifiLinkImpl& link, double /*capacity*/, int /*n*/) +{ + double ratio = link.get_max_ratio(); + XBT_DEBUG("New ratio value concurrency %d: %lf of link capacity on link %s", link.nb_active_flux_, ratio, link.get_name().c_str()); + return ratio; +} + +void WifiLinkImpl::inc_active_flux() +{ + xbt_assert(nb_active_flux_ >= 0, "Negative nb_active_flux should not exist"); + nb_active_flux_++; +} + +void WifiLinkImpl::dec_active_flux() { - // Compute number of STAtion on the Access Point - size_t nSTA = get_host_count(); - - std::vector new_bandwidths; - for (auto const& bandwidth : bandwidths_) { - // Instantiate decay model relatively to the actual bandwidth - double max_bw = bandwidth.peak; - double min_bw = bandwidth.peak - (wifi_max_rate_ - wifi_min_rate_); - double model_rate = bandwidth.peak - (wifi_max_rate_ - model_rate_); - - double N0 = max_bw - min_bw; - double lambda = (-log(model_rate - min_bw) + log(N0)) / model_n_; - // Since decay model start at 0 we should use (nSTA-1) - double new_peak = N0 * exp(-lambda * (nSTA - 1)) + min_bw; - new_bandwidths.push_back({new_peak, 1.0, nullptr}); + xbt_assert(nb_active_flux_ > 0, "Negative nb_active_flux should not exist"); + nb_active_flux_--; +} + +void WifiLinkImpl::update_bw_comm_start(const kernel::activity::CommImpl& comm) +{ + auto const* actionWifi = dynamic_cast(comm.surf_action_); + if (actionWifi == nullptr) + return; + + if (auto* link_src = actionWifi->get_src_link()) { + link_src->inc_active_flux(); + } + if (auto* link_dst = actionWifi->get_dst_link()) { + link_dst->inc_active_flux(); } - decay_bandwidths_ = new_bandwidths; } -bool WifiLinkImpl::toggle_decay_model() +void WifiLinkImpl::update_bw_comm_end(const simgrid::kernel::resource::NetworkAction& action, + simgrid::kernel::resource::Action::State /*state*/) { - use_decay_model_ = not use_decay_model_; - return use_decay_model_; + if (action.get_state() != kernel::resource::Action::State::FINISHED) + return; + + auto const* actionWifi = dynamic_cast(&action); + if (actionWifi == nullptr) + return; + + if (auto* link_src = actionWifi->get_src_link()) { + link_src->dec_active_flux(); + } + if (auto* link_dst = actionWifi->get_dst_link()) { + link_dst->dec_active_flux(); + } +} + +double WifiLinkImpl::get_max_ratio() const +{ + double new_peak; + if (nb_active_flux_ > conc_lim_) { + new_peak = (nb_active_flux_-conc_lim_) * co_acc_ + x0_; + XBT_DEBUG("Wi-Fi link peak=(%d-%d)*%lf+%lf=%lf", nb_active_flux_, conc_lim_, co_acc_, x0_, new_peak); + } else { + new_peak = x0_; + XBT_DEBUG("Wi-Fi link peak=%lf", x0_); + } + // should be the new maximum bandwidth ratio (comparison between max throughput without concurrency and with it) + double propCap = new_peak / x0_; + + return propCap; +} + +bool WifiLinkImpl::toggle_callback() +{ + if (not use_callback_) { + XBT_DEBUG("Activate throughput reduction mechanism"); + use_callback_ = true; + this->set_sharing_policy( + simgrid::s4u::Link::SharingPolicy::WIFI, + std::bind(&wifi_link_dynamic_sharing, std::cref(*this), std::placeholders::_1, std::placeholders::_2)); + } + return use_callback_; } void WifiLinkImpl::set_latency(double value) { xbt_assert(value == 0, "Latency cannot be set for WiFi Links."); } -} // namespace resource -} // namespace kernel -} // namespace simgrid +} // namespace simgrid::kernel::resource