-/* Copyright (c) 2013-2015. The SimGrid Team.
- * All rights reserved. */
+/* Copyright (c) 2013-2018. 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. */
-#include <algorithm>
-
#include "network_cm02.hpp"
-#include "maxmin_private.hpp"
-#include "simgrid/sg_config.h"
-#include "src/surf/platform.hpp"
+#include "simgrid/s4u/Host.hpp"
+#include "simgrid/sg_config.hpp"
+#include "src/instr/instr_private.hpp" // TRACE_is_enabled(). FIXME: remove by subscribing tracing to the surf signals
+#include "src/surf/surf_interface.hpp"
+#include "surf/surf.hpp"
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network);
-double sg_sender_gap = 0.0;
double sg_latency_factor = 1.0; /* default value; can be set by model or from command line */
double sg_bandwidth_factor = 1.0; /* default value; can be set by model or from command line */
double sg_weight_S_parameter = 0.0; /* default value; can be set by model or from command line */
-double sg_tcp_gamma = 0.0;
-int sg_network_crosstraffic = 0;
-
-/*************
- * CallBacks *
- *************/
-
-void net_define_callbacks(void)
-{
- /* Figuring out the network links */
- simgrid::surf::on_link.connect(netlink_parse_init);
- simgrid::surf::on_postparse.connect([]() {
- surf_network_model->addTraces();
- });
-}
-
-/*********
- * Model *
- *********/
-
/************************************************************************/
/* New model based on optimizations discussed during Pedro Velho's thesis*/
/************************************************************************/
/* month = Nov, */
/* pdf = {http://hal.inria.fr/hal-00646896/PDF/rr-validity.pdf}, */
/* } */
-void surf_network_model_init_LegrandVelho(void)
+void surf_network_model_init_LegrandVelho()
{
if (surf_network_model)
return;
- surf_network_model = new simgrid::surf::NetworkCm02Model();
- net_define_callbacks();
- simgrid::surf::Model *model = surf_network_model;
- xbt_dynar_push(all_existing_models, &model);
+ surf_network_model = new simgrid::kernel::resource::NetworkCm02Model();
+ all_existing_models->push_back(surf_network_model);
- xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor",
- 13.01);
- xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor",
- 0.97);
- xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S", 20537);
+ xbt_cfg_setdefault_double("network/latency-factor", 13.01);
+ xbt_cfg_setdefault_double("network/bandwidth-factor", 0.97);
+ xbt_cfg_setdefault_double("network/weight-S", 20537);
}
/***************************************************************************/
/* month = {oct}, */
/* year = {2002} */
/* } */
-void surf_network_model_init_CM02(void)
+void surf_network_model_init_CM02()
{
if (surf_network_model)
return;
- surf_network_model = new simgrid::surf::NetworkCm02Model();
- xbt_dynar_push(all_existing_models, &surf_network_model);
- net_define_callbacks();
+ xbt_cfg_setdefault_double("network/latency-factor", 1.0);
+ xbt_cfg_setdefault_double("network/bandwidth-factor", 1.0);
+ xbt_cfg_setdefault_double("network/weight-S", 0.0);
- xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor", 1.0);
- xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor", 1.0);
- xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S", 0.0);
+ surf_network_model = new simgrid::kernel::resource::NetworkCm02Model();
+ all_existing_models->push_back(surf_network_model);
}
/***************************************************************************/
/* journal={{IEEE/ACM} Transactions on Networking}, */
/* volume={11}, number={4}, */
/* } */
-void surf_network_model_init_Reno(void)
+void surf_network_model_init_Reno()
{
if (surf_network_model)
return;
- surf_network_model = new simgrid::surf::NetworkCm02Model();
- xbt_dynar_push(all_existing_models, &surf_network_model);
- net_define_callbacks();
- lmm_set_default_protocol_function(func_reno_f, func_reno_fp, func_reno_fpi);
- surf_network_model->f_networkSolve = lagrange_solve;
+ using namespace simgrid::kernel;
+ lmm::Lagrange::set_default_protocol_function(lmm::func_reno_f, lmm::func_reno_fp, lmm::func_reno_fpi);
+
+ xbt_cfg_setdefault_double("network/latency-factor", 13.01);
+ xbt_cfg_setdefault_double("network/bandwidth-factor", 0.97);
+ xbt_cfg_setdefault_double("network/weight-S", 20537);
- xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor", 10.4);
- xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor", 0.92);
- xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S", 8775);
+ surf_network_model = new simgrid::kernel::resource::NetworkCm02Model(&simgrid::kernel::lmm::make_new_lagrange_system);
+ all_existing_models->push_back(surf_network_model);
}
-void surf_network_model_init_Reno2(void)
+void surf_network_model_init_Reno2()
{
if (surf_network_model)
return;
- surf_network_model = new simgrid::surf::NetworkCm02Model();
- xbt_dynar_push(all_existing_models, &surf_network_model);
- net_define_callbacks();
- lmm_set_default_protocol_function(func_reno2_f, func_reno2_fp, func_reno2_fpi);
- surf_network_model->f_networkSolve = lagrange_solve;
+ using namespace simgrid::kernel;
+ lmm::Lagrange::set_default_protocol_function(lmm::func_reno2_f, lmm::func_reno2_fp, lmm::func_reno2_fpi);
- xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor", 10.4);
- xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor", 0.92);
- xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S", 8775);
+ xbt_cfg_setdefault_double("network/latency-factor", 13.01);
+ xbt_cfg_setdefault_double("network/bandwidth-factor", 0.97);
+ xbt_cfg_setdefault_double("network/weight-S", 20537);
+
+ surf_network_model = new simgrid::kernel::resource::NetworkCm02Model(&simgrid::kernel::lmm::make_new_lagrange_system);
+ all_existing_models->push_back(surf_network_model);
}
-void surf_network_model_init_Vegas(void)
+void surf_network_model_init_Vegas()
{
if (surf_network_model)
return;
- surf_network_model = new simgrid::surf::NetworkCm02Model();
- xbt_dynar_push(all_existing_models, &surf_network_model);
- net_define_callbacks();
- lmm_set_default_protocol_function(func_vegas_f, func_vegas_fp, func_vegas_fpi);
- surf_network_model->f_networkSolve = lagrange_solve;
+ using namespace simgrid::kernel;
+ lmm::Lagrange::set_default_protocol_function(lmm::func_vegas_f, lmm::func_vegas_fp, lmm::func_vegas_fpi);
+
+ xbt_cfg_setdefault_double("network/latency-factor", 13.01);
+ xbt_cfg_setdefault_double("network/bandwidth-factor", 0.97);
+ xbt_cfg_setdefault_double("network/weight-S", 20537);
- xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor", 10.4);
- xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor", 0.92);
- xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S", 8775);
+ surf_network_model = new simgrid::kernel::resource::NetworkCm02Model(&simgrid::kernel::lmm::make_new_lagrange_system);
+ all_existing_models->push_back(surf_network_model);
}
namespace simgrid {
-namespace surf {
+namespace kernel {
+namespace resource {
-NetworkCm02Model::NetworkCm02Model()
- :NetworkModel()
+NetworkCm02Model::NetworkCm02Model(kernel::lmm::System* (*make_new_lmm_system)(bool))
+ : NetworkModel(xbt_cfg_get_string("network/optim") == "Full" ? Model::UpdateAlgo::Full : Model::UpdateAlgo::Lazy)
{
- char *optim = xbt_cfg_get_string(_sg_cfg_set, "network/optim");
- int select =
- xbt_cfg_get_boolean(_sg_cfg_set, "network/maxmin_selective_update");
-
- if (!strcmp(optim, "Full")) {
- p_updateMechanism = UM_FULL;
- m_selectiveUpdate = select;
- } else if (!strcmp(optim, "Lazy")) {
- p_updateMechanism = UM_LAZY;
- m_selectiveUpdate = 1;
- xbt_assert((select == 1)
- ||
- (xbt_cfg_is_default_value
- (_sg_cfg_set, "network/maxmin_selective_update")),
- "Disabling selective update while using the lazy update mechanism is dumb!");
- } else {
- xbt_die("Unsupported optimization (%s) for this model", optim);
- }
-
- if (!p_maxminSystem)
- p_maxminSystem = lmm_system_new(m_selectiveUpdate);
+ std::string optim = xbt_cfg_get_string("network/optim");
+ bool select = xbt_cfg_get_boolean("network/maxmin-selective-update");
- routing_model_create(createLink("__loopback__",
- 498000000, NULL, 0.000015, NULL,
- 1 /*SURF_RESOURCE_ON*/, NULL,
- SURF_LINK_FATPIPE, NULL));
-
- if (p_updateMechanism == UM_LAZY) {
- p_actionHeap = xbt_heap_new(8, NULL);
- xbt_heap_set_update_callback(p_actionHeap, surf_action_lmm_update_index_heap);
- p_modifiedSet = new ActionLmmList();
- p_maxminSystem->keep_track = p_modifiedSet;
+ if (optim == "Lazy") {
+ xbt_assert(select || xbt_cfg_is_default_value("network/maxmin-selective-update"),
+ "You cannot disable network selective update when using the lazy update mechanism");
+ select = true;
}
+
+ set_maxmin_system(make_new_lmm_system(select));
+ loopback_ = NetworkCm02Model::createLink("__loopback__", 498000000, 0.000015, s4u::Link::SharingPolicy::FATPIPE);
}
-Link* NetworkCm02Model::createLink(const char *name,
- double bw_initial,
- tmgr_trace_t bw_trace,
- double lat_initial,
- tmgr_trace_t lat_trace,
- int initiallyOn,
- tmgr_trace_t state_trace,
- e_surf_link_sharing_policy_t policy,
- xbt_dict_t properties)
+LinkImpl* NetworkCm02Model::createLink(const std::string& name, double bandwidth, double latency,
+ s4u::Link::SharingPolicy policy)
{
- xbt_assert(NULL == Link::byName(name),
- "Link '%s' declared several times in the platform",
- name);
-
- Link* link = new NetworkCm02Link(this, name, properties, p_maxminSystem, sg_bandwidth_factor * bw_initial, future_evt_set,
- initiallyOn, state_trace, bw_initial, bw_trace, lat_initial, lat_trace, policy);
- Link::onCreation(link);
- return link;
+ return new NetworkCm02Link(this, name, bandwidth, latency, policy, get_maxmin_system());
}
-void NetworkCm02Model::updateActionsStateLazy(double now, double /*delta*/)
+void NetworkCm02Model::update_actions_state_lazy(double now, double /*delta*/)
{
- NetworkCm02Action *action;
- while ((xbt_heap_size(p_actionHeap) > 0)
- && (double_equals(xbt_heap_maxkey(p_actionHeap), now, sg_surf_precision))) {
- action = static_cast<NetworkCm02Action*> (xbt_heap_pop(p_actionHeap));
+ while (not get_action_heap().empty() && double_equals(get_action_heap().top_date(), now, sg_surf_precision)) {
+
+ NetworkCm02Action* action = static_cast<NetworkCm02Action*>(get_action_heap().pop());
XBT_DEBUG("Something happened to action %p", action);
if (TRACE_is_enabled()) {
- int n = lmm_get_number_of_cnst_from_var(p_maxminSystem, action->getVariable());
- int i;
- for (i = 0; i < n; i++){
- lmm_constraint_t constraint = lmm_get_cnst_from_var(p_maxminSystem,
- action->getVariable(),
- i);
- NetworkCm02Link *link = static_cast<NetworkCm02Link*>(lmm_constraint_id(constraint));
- TRACE_surf_link_set_utilization(link->getName(),
- action->getCategory(),
- (lmm_variable_getvalue(action->getVariable())*
- lmm_get_cnst_weight_from_var(p_maxminSystem,
- action->getVariable(),
- i)),
- action->getLastUpdate(),
- now - action->getLastUpdate());
+ int n = action->get_variable()->get_number_of_constraint();
+
+ for (int i = 0; i < n; i++){
+ kernel::lmm::Constraint* constraint = action->get_variable()->get_constraint(i);
+ NetworkCm02Link* link = static_cast<NetworkCm02Link*>(constraint->get_id());
+ double value = action->get_variable()->get_value() * action->get_variable()->get_constraint_weight(i);
+ TRACE_surf_link_set_utilization(link->get_cname(), action->get_category(), value, action->get_last_update(),
+ now - action->get_last_update());
}
}
// if I am wearing a latency hat
- if (action->getHat() == LATENCY) {
+ if (action->get_type() == ActionHeap::Type::latency) {
XBT_DEBUG("Latency paid for action %p. Activating", action);
- lmm_update_variable_weight(p_maxminSystem, action->getVariable(), action->m_weight);
- action->heapRemove(p_actionHeap);
- action->refreshLastUpdate();
-
- // if I am wearing a max_duration or normal hat
- } else if (action->getHat() == MAX_DURATION ||
- action->getHat() == NORMAL) {
- // no need to communicate anymore
- // assume that flows that reached max_duration have remaining of 0
+ get_maxmin_system()->update_variable_weight(action->get_variable(), action->weight_);
+ get_action_heap().remove(action);
+ action->set_last_update();
+
+ // if I am wearing a max_duration or normal hat
+ } else if (action->get_type() == ActionHeap::Type::max_duration || action->get_type() == ActionHeap::Type::normal) {
+ // no need to communicate anymore
+ // assume that flows that reached max_duration have remaining of 0
XBT_DEBUG("Action %p finished", action);
- action->setRemains(0);
- action->finish();
- action->setState(SURF_ACTION_DONE);
- action->heapRemove(p_actionHeap);
-
- action->gapRemove();
+ action->finish(Action::State::done);
+ get_action_heap().remove(action);
}
}
- return;
}
-
-void NetworkCm02Model::updateActionsStateFull(double now, double delta)
+void NetworkCm02Model::update_actions_state_full(double now, double delta)
{
- NetworkCm02Action *action;
- ActionList *running_actions = getRunningActionSet();
-
- for(ActionList::iterator it(running_actions->begin()), itNext=it, itend(running_actions->end())
- ; it != itend ; it=itNext) {
- ++itNext;
-
- action = static_cast<NetworkCm02Action*> (&*it);
- XBT_DEBUG("Something happened to action %p", action);
- double deltap = delta;
- if (action->m_latency > 0) {
- if (action->m_latency > deltap) {
- double_update(&(action->m_latency), deltap, sg_surf_precision);
- deltap = 0.0;
- } else {
- double_update(&(deltap), action->m_latency, sg_surf_precision);
- action->m_latency = 0.0;
- }
- if (action->m_latency == 0.0 && !(action->isSuspended()))
- lmm_update_variable_weight(p_maxminSystem, action->getVariable(),
- action->m_weight);
- }
- if (TRACE_is_enabled()) {
- int n = lmm_get_number_of_cnst_from_var(p_maxminSystem, action->getVariable());
- int i;
- for (i = 0; i < n; i++){
- lmm_constraint_t constraint = lmm_get_cnst_from_var(p_maxminSystem,
- action->getVariable(),
- i);
- NetworkCm02Link* link = static_cast<NetworkCm02Link*>(lmm_constraint_id(constraint));
- TRACE_surf_link_set_utilization(link->getName(),
- action->getCategory(),
- (lmm_variable_getvalue(action->getVariable())*
- lmm_get_cnst_weight_from_var(p_maxminSystem,
- action->getVariable(),
- i)),
- action->getLastUpdate(),
- now - action->getLastUpdate());
- }
+ for (auto it = std::begin(*get_running_action_set()); it != std::end(*get_running_action_set());) {
+ NetworkCm02Action& action = static_cast<NetworkCm02Action&>(*it);
+ ++it; // increment iterator here since the following calls to action.finish() may invalidate it
+ XBT_DEBUG("Something happened to action %p", &action);
+ double deltap = delta;
+ if (action.latency_ > 0) {
+ if (action.latency_ > deltap) {
+ double_update(&action.latency_, deltap, sg_surf_precision);
+ deltap = 0.0;
+ } else {
+ double_update(&deltap, action.latency_, sg_surf_precision);
+ action.latency_ = 0.0;
}
- if (!lmm_get_number_of_cnst_from_var
- (p_maxminSystem, action->getVariable())) {
- /* There is actually no link used, hence an infinite bandwidth.
- * This happens often when using models like vivaldi.
- * In such case, just make sure that the action completes immediately.
- */
- action->updateRemains(action->getRemains());
+ if (action.latency_ <= 0.0 && not action.is_suspended())
+ get_maxmin_system()->update_variable_weight(action.get_variable(), action.weight_);
+ }
+ if (TRACE_is_enabled()) {
+ int n = action.get_variable()->get_number_of_constraint();
+ for (int i = 0; i < n; i++) {
+ kernel::lmm::Constraint* constraint = action.get_variable()->get_constraint(i);
+ NetworkCm02Link* link = static_cast<NetworkCm02Link*>(constraint->get_id());
+ TRACE_surf_link_set_utilization(
+ link->get_cname(), action.get_category(),
+ (action.get_variable()->get_value() * action.get_variable()->get_constraint_weight(i)),
+ action.get_last_update(), now - action.get_last_update());
}
- action->updateRemains(lmm_variable_getvalue(action->getVariable()) * delta);
-
- if (action->getMaxDuration() != NO_MAX_DURATION)
- action->updateMaxDuration(delta);
-
- if ((action->getRemains() <= 0) &&
- (lmm_get_variable_weight(action->getVariable()) > 0)) {
- action->finish();
- action->setState(SURF_ACTION_DONE);
- action->gapRemove();
- } else if (((action->getMaxDuration() != NO_MAX_DURATION)
- && (action->getMaxDuration() <= 0))) {
- action->finish();
- action->setState(SURF_ACTION_DONE);
- action->gapRemove();
+ }
+ if (not action.get_variable()->get_number_of_constraint()) {
+ /* There is actually no link used, hence an infinite bandwidth. This happens often when using models like
+ * vivaldi. In such case, just make sure that the action completes immediately.
+ */
+ action.update_remains(action.get_remains());
+ }
+ action.update_remains(action.get_variable()->get_value() * delta);
+
+ if (action.get_max_duration() > NO_MAX_DURATION)
+ action.update_max_duration(delta);
+
+ if (((action.get_remains() <= 0) && (action.get_variable()->get_weight() > 0)) ||
+ ((action.get_max_duration() > NO_MAX_DURATION) && (action.get_max_duration() <= 0))) {
+ action.finish(Action::State::done);
}
}
- return;
}
-Action *NetworkCm02Model::communicate(NetCard *src, NetCard *dst,
- double size, double rate)
+Action* NetworkCm02Model::communicate(s4u::Host* src, s4u::Host* dst, double size, double rate)
{
- unsigned int i;
- void *_link;
- NetworkCm02Link *link;
int failed = 0;
- NetworkCm02Action *action = NULL;
- double bandwidth_bound;
double latency = 0.0;
- xbt_dynar_t back_route = NULL;
- int constraints_per_variable = 0;
-
- xbt_dynar_t route = xbt_dynar_new(sizeof(NetCard*), NULL);
+ std::vector<LinkImpl*> back_route;
+ std::vector<LinkImpl*> route;
- XBT_IN("(%s,%s,%g,%g)", src->getName(), dst->getName(), size, rate);
+ XBT_IN("(%s,%s,%g,%g)", src->get_cname(), dst->get_cname(), size, rate);
- routing_platf->getRouteAndLatency(src, dst, &route, &latency);
- xbt_assert(!xbt_dynar_is_empty(route) || latency,
+ src->routeTo(dst, route, &latency);
+ xbt_assert(not route.empty() || latency,
"You're trying to send data from %s to %s but there is no connecting path between these two hosts.",
- src->getName(), dst->getName());
+ src->get_cname(), dst->get_cname());
- xbt_dynar_foreach(route, i, _link) {
- link = static_cast<NetworkCm02Link*>(_link);
- if (link->isOff()) {
+ for (auto const& link : route)
+ if (link->is_off())
failed = 1;
- break;
- }
- }
- if (sg_network_crosstraffic == 1) {
- routing_platf->getRouteAndLatency(dst, src, &back_route, NULL);
- xbt_dynar_foreach(back_route, i, _link) {
- link = static_cast<NetworkCm02Link*>(_link);
- if (link->isOff()) {
+
+ if (cfg_crosstraffic == 1) {
+ dst->routeTo(src, back_route, nullptr);
+ for (auto const& link : back_route)
+ if (link->is_off())
failed = 1;
- break;
- }
- }
}
- action = new NetworkCm02Action(this, size, failed);
-
-#ifdef HAVE_LATENCY_BOUND_TRACKING
- action->m_latencyLimited = 0;
-#endif
- action->m_weight = action->m_latency = latency;
-
- action->m_rate = rate;
- if (p_updateMechanism == UM_LAZY) {
- action->m_indexHeap = -1;
- action->m_lastUpdate = surf_get_clock();
+ NetworkCm02Action *action = new NetworkCm02Action(this, size, failed);
+ action->weight_ = latency;
+ action->latency_ = latency;
+ action->rate_ = rate;
+ if (get_update_algorithm() == Model::UpdateAlgo::Lazy) {
+ action->set_last_update();
}
- bandwidth_bound = -1.0;
- if (sg_weight_S_parameter > 0) {
- xbt_dynar_foreach(route, i, _link) {
- link = static_cast<NetworkCm02Link*>(_link);
- action->m_weight += sg_weight_S_parameter / link->getBandwidth();
- }
- }
- xbt_dynar_foreach(route, i, _link) {
- link = static_cast<NetworkCm02Link*>(_link);
- double bb = bandwidthFactor(size) * link->getBandwidth();
- bandwidth_bound =
- (bandwidth_bound < 0.0) ? bb : std::min(bandwidth_bound, bb);
- }
+ double bandwidth_bound = -1.0;
+ if (sg_weight_S_parameter > 0)
+ for (auto const& link : route)
+ action->weight_ += sg_weight_S_parameter / link->bandwidth();
- action->m_latCurrent = action->m_latency;
- action->m_latency *= latencyFactor(size);
- action->m_rate = bandwidthConstraint(action->m_rate, bandwidth_bound, size);
- if (m_haveGap) {
- xbt_assert(!xbt_dynar_is_empty(route),
- "Using a model with a gap (e.g., SMPI) with a platform without links (e.g. vivaldi)!!!");
-
- link = *static_cast<NetworkCm02Link **>(xbt_dynar_get_ptr(route, 0));
- gapAppend(size, link, action);
- XBT_DEBUG("Comm %p: %s -> %s gap=%f (lat=%f)",
- action, src->getName(), dst->getName(), action->m_senderGap,
- action->m_latency);
+ for (auto const& link : route) {
+ double bb = bandwidthFactor(size) * link->bandwidth();
+ bandwidth_bound = (bandwidth_bound < 0.0) ? bb : std::min(bandwidth_bound, bb);
}
- constraints_per_variable = xbt_dynar_length(route);
- if (back_route != NULL)
- constraints_per_variable += xbt_dynar_length(back_route);
+ action->lat_current_ = action->latency_;
+ action->latency_ *= latencyFactor(size);
+ action->rate_ = bandwidthConstraint(action->rate_, bandwidth_bound, size);
+
+ int constraints_per_variable = route.size();
+ constraints_per_variable += back_route.size();
- if (action->m_latency > 0) {
- action->p_variable = lmm_variable_new(p_maxminSystem, action, 0.0, -1.0,
- constraints_per_variable);
- if (p_updateMechanism == UM_LAZY) {
+ if (action->latency_ > 0) {
+ action->set_variable(get_maxmin_system()->variable_new(action, 0.0, -1.0, constraints_per_variable));
+ if (get_update_algorithm() == Model::UpdateAlgo::Lazy) {
// add to the heap the event when the latency is payed
- XBT_DEBUG("Added action (%p) one latency event at date %f", action,
- action->m_latency + action->m_lastUpdate);
- action->heapInsert(p_actionHeap, action->m_latency + action->m_lastUpdate, xbt_dynar_is_empty(route) ? NORMAL : LATENCY);
+ double date = action->latency_ + action->get_last_update();
+ ActionHeap::Type type;
+ if (route.empty())
+ type = ActionHeap::Type::normal;
+ else
+ type = ActionHeap::Type::latency;
+
+ XBT_DEBUG("Added action (%p) one latency event at date %f", action, date);
+ get_action_heap().insert(action, date, type);
}
} else
- action->p_variable = lmm_variable_new(p_maxminSystem, action, 1.0, -1.0, constraints_per_variable);
+ action->set_variable(get_maxmin_system()->variable_new(action, 1.0, -1.0, constraints_per_variable));
- if (action->m_rate < 0) {
- lmm_update_variable_bound(p_maxminSystem, action->getVariable(), (action->m_latCurrent > 0) ? sg_tcp_gamma / (2.0 * action->m_latCurrent) : -1.0);
+ if (action->rate_ < 0) {
+ get_maxmin_system()->update_variable_bound(
+ action->get_variable(), (action->lat_current_ > 0) ? cfg_tcp_gamma / (2.0 * action->lat_current_) : -1.0);
} else {
- lmm_update_variable_bound(p_maxminSystem, action->getVariable(), (action->m_latCurrent > 0) ? std::min(action->m_rate, sg_tcp_gamma / (2.0 * action->m_latCurrent)) : action->m_rate);
+ get_maxmin_system()->update_variable_bound(
+ action->get_variable(), (action->lat_current_ > 0)
+ ? std::min(action->rate_, cfg_tcp_gamma / (2.0 * action->lat_current_))
+ : action->rate_);
}
- xbt_dynar_foreach(route, i, _link) {
- link = static_cast<NetworkCm02Link*>(_link);
- lmm_expand(p_maxminSystem, link->getConstraint(), action->getVariable(), 1.0);
- }
+ for (auto const& link : route)
+ get_maxmin_system()->expand(link->get_constraint(), action->get_variable(), 1.0);
- if (sg_network_crosstraffic == 1) {
- XBT_DEBUG("Fullduplex active adding backward flow using 5%%");
- xbt_dynar_foreach(back_route, i, _link) {
- link = static_cast<NetworkCm02Link*>(_link);
- lmm_expand(p_maxminSystem, link->getConstraint(), action->getVariable(), .05);
- }
- lmm_variable_concurrency_share_set(action->getVariable(),2);
- }
+ if (not back_route.empty()) { // cfg_crosstraffic was activated
+ XBT_DEBUG("Crosstraffic active adding backward flow using 5%%");
+ for (auto const& link : back_route)
+ get_maxmin_system()->expand(link->get_constraint(), action->get_variable(), .05);
- xbt_dynar_free(&route);
+ // Change concurrency_share here, if you want that cross-traffic is included in the SURF concurrency
+ // (You would also have to change simgrid::kernel::lmm::Element::get_concurrency())
+ // action->getVariable()->set_concurrency_share(2)
+ }
XBT_OUT();
- networkCommunicateCallbacks(action, src, dst, size, rate);
+ simgrid::s4u::Link::onCommunicate(action, src, dst);
return action;
}
-void NetworkCm02Model::addTraces(){
- xbt_dict_cursor_t cursor = NULL;
- char *trace_name, *elm;
-
- static int called = 0;
- if (called)
- return;
- called = 1;
-
- /* connect all traces relative to network */
- xbt_dict_foreach(trace_connect_list_link_avail, cursor, trace_name, elm) {
- tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
- NetworkCm02Link *link = static_cast<NetworkCm02Link*>( Link::byName(elm) );
-
- xbt_assert(link, "Cannot connect trace %s to link %s: link undefined",
- trace_name, elm);
- xbt_assert(trace,
- "Cannot connect trace %s to link %s: trace undefined",
- trace_name, elm);
-
- link->p_stateEvent = future_evt_set->add_trace(trace, 0.0, link);
- }
-
- xbt_dict_foreach(trace_connect_list_link_bw, cursor, trace_name, elm) {
- tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
- NetworkCm02Link *link = static_cast<NetworkCm02Link*>( Link::byName(elm) );
-
- xbt_assert(link, "Cannot connect trace %s to link %s: link undefined",
- trace_name, elm);
- xbt_assert(trace,
- "Cannot connect trace %s to link %s: trace undefined",
- trace_name, elm);
-
- link->p_speed.event = future_evt_set->add_trace(trace, 0.0, link);
- }
-
- xbt_dict_foreach(trace_connect_list_link_lat, cursor, trace_name, elm) {
- tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
- NetworkCm02Link *link = static_cast<NetworkCm02Link*>(Link::byName(elm));;
-
- xbt_assert(link, "Cannot connect trace %s to link %s: link undefined",
- trace_name, elm);
- xbt_assert(trace,
- "Cannot connect trace %s to link %s: trace undefined",
- trace_name, elm);
-
- link->p_latEvent = future_evt_set->add_trace(trace, 0.0, link);
- }
-}
-
/************
* Resource *
************/
-NetworkCm02Link::NetworkCm02Link(NetworkCm02Model *model, const char *name, xbt_dict_t props,
- lmm_system_t system,
- double constraint_value,
- sg_future_evt_set_t fes,
- int initiallyOn, tmgr_trace_t state_trace,
- double bw_peak, tmgr_trace_t bw_trace,
- double lat_initial, tmgr_trace_t lat_trace,
- e_surf_link_sharing_policy_t policy)
-: Link(model, name, props, lmm_constraint_new(system, this, constraint_value), fes, state_trace)
+NetworkCm02Link::NetworkCm02Link(NetworkCm02Model* model, const std::string& name, double bandwidth, double latency,
+ s4u::Link::SharingPolicy policy, kernel::lmm::System* system)
+ : LinkImpl(model, name, system->constraint_new(this, sg_bandwidth_factor * bandwidth))
{
- if (initiallyOn)
- turnOn();
- else
- turnOff();
-
- p_speed.scale = 1.0;
- p_speed.peak = bw_peak;
- if (bw_trace)
- p_speed.event = fes->add_trace(bw_trace, 0.0, this);
- else
- p_speed.event = NULL;
-
- m_latCurrent = lat_initial;
- if (lat_trace)
- p_latEvent = fes->add_trace(lat_trace, 0.0, this);
-
- if (policy == SURF_LINK_FATPIPE)
- lmm_constraint_shared(getConstraint());
-}
+ bandwidth_.scale = 1.0;
+ bandwidth_.peak = bandwidth;
+ latency_.scale = 1.0;
+ latency_.peak = latency;
+ if (policy == s4u::Link::SharingPolicy::FATPIPE)
+ get_constraint()->unshare();
-void NetworkCm02Link::updateState(tmgr_trace_iterator_t triggered,
- double value, double date)
-{
+ simgrid::s4u::Link::onCreation(this->piface_);
+}
+void NetworkCm02Link::apply_event(tmgr_trace_event_t triggered, double value)
+{
/* Find out which of my iterators was triggered, and react accordingly */
- if (triggered == p_speed.event) {
- updateBandwidth(value, date);
- tmgr_trace_event_unref(&p_speed.event);
- } else if (triggered == p_latEvent) {
- updateLatency(value, date);
- tmgr_trace_event_unref(&p_latEvent);
- } else if (triggered == p_stateEvent) {
+ if (triggered == bandwidth_.event) {
+ setBandwidth(value);
+ tmgr_trace_event_unref(&bandwidth_.event);
+
+ } else if (triggered == latency_.event) {
+ setLatency(value);
+ tmgr_trace_event_unref(&latency_.event);
+
+ } else if (triggered == stateEvent_) {
if (value > 0)
- turnOn();
+ turn_on();
else {
- lmm_variable_t var = NULL;
- lmm_element_t elem = NULL;
+ kernel::lmm::Variable* var = nullptr;
+ const kernel::lmm::Element* elem = nullptr;
+ double now = surf_get_clock();
- turnOff();
- while ((var = lmm_get_var_from_cnst(getModel()->getMaxminSystem(), getConstraint(), &elem))) {
- Action *action = static_cast<Action*>( lmm_variable_id(var) );
+ turn_off();
+ while ((var = get_constraint()->get_variable(&elem))) {
+ Action* action = static_cast<Action*>(var->get_id());
- if (action->getState() == SURF_ACTION_RUNNING ||
- action->getState() == SURF_ACTION_READY) {
- action->setFinishTime(date);
- action->setState(SURF_ACTION_FAILED);
+ if (action->get_state() == Action::State::running || action->get_state() == Action::State::ready) {
+ action->set_finish_time(now);
+ action->set_state(Action::State::failed);
}
}
}
- tmgr_trace_event_unref(&p_stateEvent);
+ tmgr_trace_event_unref(&stateEvent_);
} else {
xbt_die("Unknown event!\n");
}
- XBT_DEBUG
- ("There was a resource state event, need to update actions related to the constraint (%p)",
- getConstraint());
+ XBT_DEBUG("There was a resource state event, need to update actions related to the constraint (%p)",
+ get_constraint());
}
-void NetworkCm02Link::updateBandwidth(double value, double date){
- double delta = sg_weight_S_parameter / value - sg_weight_S_parameter /
- (p_speed.peak * p_speed.scale);
- lmm_variable_t var = NULL;
- lmm_element_t elem = NULL;
- lmm_element_t nextelem = NULL;
- int numelem = 0;
-
- NetworkCm02Action *action = NULL;
-
- p_speed.peak = value;
- lmm_update_constraint_bound(getModel()->getMaxminSystem(),
- getConstraint(),
- sg_bandwidth_factor *
- (p_speed.peak * p_speed.scale));
- TRACE_surf_link_set_bandwidth(date, getName(), sg_bandwidth_factor * p_speed.peak * p_speed.scale);
+void NetworkCm02Link::setBandwidth(double value)
+{
+ bandwidth_.peak = value;
+
+ get_model()->get_maxmin_system()->update_constraint_bound(get_constraint(),
+ sg_bandwidth_factor * (bandwidth_.peak * bandwidth_.scale));
+ TRACE_surf_link_set_bandwidth(surf_get_clock(), get_cname(),
+ sg_bandwidth_factor * bandwidth_.peak * bandwidth_.scale);
+
if (sg_weight_S_parameter > 0) {
- while ((var = lmm_get_var_from_cnst_safe(getModel()->getMaxminSystem(), getConstraint(), &elem, &nextelem, &numelem))) {
- action = (NetworkCm02Action*) lmm_variable_id(var);
- action->m_weight += delta;
- if (!action->isSuspended())
- lmm_update_variable_weight(getModel()->getMaxminSystem(), action->getVariable(), action->m_weight);
+ double delta = sg_weight_S_parameter / value - sg_weight_S_parameter / (bandwidth_.peak * bandwidth_.scale);
+
+ kernel::lmm::Variable* var;
+ const kernel::lmm::Element* elem = nullptr;
+ const kernel::lmm::Element* nextelem = nullptr;
+ int numelem = 0;
+ while ((var = get_constraint()->get_variable_safe(&elem, &nextelem, &numelem))) {
+ NetworkCm02Action* action = static_cast<NetworkCm02Action*>(var->get_id());
+ action->weight_ += delta;
+ if (not action->is_suspended())
+ get_model()->get_maxmin_system()->update_variable_weight(action->get_variable(), action->weight_);
}
}
}
-void NetworkCm02Link::updateLatency(double value, double date){
- double delta = value - m_latCurrent;
- lmm_variable_t var = NULL;
- lmm_element_t elem = NULL;
- lmm_element_t nextelem = NULL;
- int numelem = 0;
- NetworkCm02Action *action = NULL;
-
- m_latCurrent = value;
- while ((var = lmm_get_var_from_cnst_safe(getModel()->getMaxminSystem(), getConstraint(), &elem, &nextelem, &numelem))) {
- action = (NetworkCm02Action*) lmm_variable_id(var);
- action->m_latCurrent += delta;
- action->m_weight += delta;
- if (action->m_rate < 0)
- lmm_update_variable_bound(getModel()->getMaxminSystem(), action->getVariable(), sg_tcp_gamma / (2.0 * action->m_latCurrent));
+void NetworkCm02Link::setLatency(double value)
+{
+ double delta = value - latency_.peak;
+ kernel::lmm::Variable* var = nullptr;
+ const kernel::lmm::Element* elem = nullptr;
+ const kernel::lmm::Element* nextelem = nullptr;
+ int numelem = 0;
+
+ latency_.peak = value;
+
+ while ((var = get_constraint()->get_variable_safe(&elem, &nextelem, &numelem))) {
+ NetworkCm02Action* action = static_cast<NetworkCm02Action*>(var->get_id());
+ action->lat_current_ += delta;
+ action->weight_ += delta;
+ if (action->rate_ < 0)
+ get_model()->get_maxmin_system()->update_variable_bound(action->get_variable(), NetworkModel::cfg_tcp_gamma /
+ (2.0 * action->lat_current_));
else {
- lmm_update_variable_bound(getModel()->getMaxminSystem(), action->getVariable(),
- std::min(action->m_rate, sg_tcp_gamma / (2.0 * action->m_latCurrent)));
+ get_model()->get_maxmin_system()->update_variable_bound(
+ action->get_variable(), std::min(action->rate_, NetworkModel::cfg_tcp_gamma / (2.0 * action->lat_current_)));
- if (action->m_rate < sg_tcp_gamma / (2.0 * action->m_latCurrent)) {
+ if (action->rate_ < NetworkModel::cfg_tcp_gamma / (2.0 * action->lat_current_)) {
XBT_INFO("Flow is limited BYBANDWIDTH");
} else {
- XBT_INFO("Flow is limited BYLATENCY, latency of flow is %f",
- action->m_latCurrent);
+ XBT_INFO("Flow is limited BYLATENCY, latency of flow is %f", action->lat_current_);
}
}
- if (!action->isSuspended())
- lmm_update_variable_weight(getModel()->getMaxminSystem(), action->getVariable(), action->m_weight);
+ if (not action->is_suspended())
+ get_model()->get_maxmin_system()->update_variable_weight(action->get_variable(), action->weight_);
}
}
/**********
* Action *
**********/
-void NetworkCm02Action::updateRemainingLazy(double now)
-{
- double delta = 0.0;
- if (m_suspended != 0)
+void NetworkCm02Action::update_remains_lazy(double now)
+{
+ if (suspended_ != Action::SuspendStates::not_suspended)
return;
- delta = now - m_lastUpdate;
+ double delta = now - get_last_update();
+ double max_duration = get_max_duration();
- if (m_remains > 0) {
- XBT_DEBUG("Updating action(%p): remains was %f, last_update was: %f", this, m_remains, m_lastUpdate);
- double_update(&(m_remains), m_lastValue * delta, sg_maxmin_precision*sg_surf_precision);
+ if (get_remains_no_update() > 0) {
+ XBT_DEBUG("Updating action(%p): remains was %f, last_update was: %f", this, get_remains_no_update(),
+ get_last_update());
+ update_remains(get_last_value() * delta);
- XBT_DEBUG("Updating action(%p): remains is now %f", this, m_remains);
+ XBT_DEBUG("Updating action(%p): remains is now %f", this, get_remains_no_update());
}
- if (m_maxDuration != NO_MAX_DURATION)
- double_update(&m_maxDuration, delta, sg_surf_precision);
-
- if (m_remains <= 0 &&
- (lmm_get_variable_weight(getVariable()) > 0)) {
- finish();
- setState(SURF_ACTION_DONE);
+ if (max_duration > NO_MAX_DURATION) {
+ double_update(&max_duration, delta, sg_surf_precision);
+ set_max_duration(max_duration);
+ }
- heapRemove(getModel()->getActionHeap());
- } else if (((m_maxDuration != NO_MAX_DURATION)
- && (m_maxDuration <= 0))) {
- finish();
- setState(SURF_ACTION_DONE);
- heapRemove(getModel()->getActionHeap());
+ if ((get_remains_no_update() <= 0 && (get_variable()->get_weight() > 0)) ||
+ ((max_duration > NO_MAX_DURATION) && (max_duration <= 0))) {
+ finish(Action::State::done);
+ get_model()->get_action_heap().remove(this);
}
- m_lastUpdate = now;
- m_lastValue = lmm_variable_getvalue(getVariable());
+ set_last_update();
+ set_last_value(get_variable()->get_value());
}
}
}
+} // namespace simgrid