X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/773715423764e9f35aacb24b982b6b43598bd40e..5f9b13c6302e914a514168da8ff54818c0ee6787:/src/surf/network_cm02.cpp diff --git a/src/surf/network_cm02.cpp b/src/surf/network_cm02.cpp index 8e824113f1..db6d3ab00e 100644 --- a/src/surf/network_cm02.cpp +++ b/src/surf/network_cm02.cpp @@ -1,6 +1,15 @@ +/* Copyright (c) 2013-2015. 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 + #include "network_cm02.hpp" -#include "maxmin_private.h" +#include "maxmin_private.hpp" #include "simgrid/sg_config.h" +#include "src/surf/platform.hpp" XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network); @@ -16,99 +25,10 @@ int sg_network_crosstraffic = 0; * CallBacks * *************/ -static void net_parse_link_init(sg_platf_link_cbarg_t link){ - if (link->policy == SURF_LINK_FULLDUPLEX) { - char *link_id; - link_id = bprintf("%s_UP", link->id); - surf_network_model->createResource(link_id, - link->bandwidth, - link->bandwidth_trace, - link->latency, - link->latency_trace, - link->state, - link->state_trace, link->policy, link->properties); - xbt_free(link_id); - link_id = bprintf("%s_DOWN", link->id); - surf_network_model->createResource(link_id, - link->bandwidth, - link->bandwidth_trace, - link->latency, - link->latency_trace, - link->state, - link->state_trace, link->policy, link->properties); - xbt_free(link_id); - } else { - surf_network_model->createResource(link->id, - link->bandwidth, - link->bandwidth_trace, - link->latency, - link->latency_trace, - link->state, - link->state_trace, link->policy, link->properties); - } -} - -static void net_add_traces(void){ - 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); - NetworkCm02LinkLmmPtr link = dynamic_cast( - static_cast( - xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL))); - - 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 = tmgr_history_add_trace(history, trace, 0.0, 0, static_cast(link)); - } - - xbt_dict_foreach(trace_connect_list_bandwidth, cursor, trace_name, elm) { - tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name); - NetworkCm02LinkLmmPtr link = dynamic_cast( - static_cast( - xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL))); - - 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_power.event = tmgr_history_add_trace(history, trace, 0.0, 0, static_cast(link)); - } - - xbt_dict_foreach(trace_connect_list_latency, cursor, trace_name, elm) { - tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name); - NetworkCm02LinkLmmPtr link = dynamic_cast( - static_cast( - xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL))); - - 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 = tmgr_history_add_trace(history, trace, 0.0, 0, static_cast(link)); - } -} - void net_define_callbacks(void) { /* Figuring out the network links */ - sg_platf_link_add_cb(net_parse_link_init); - sg_platf_postparse_add_cb(net_add_traces); + simgrid::surf::on_link.connect(netlink_parse_init); } /********* @@ -134,10 +54,10 @@ void surf_network_model_init_LegrandVelho(void) if (surf_network_model) return; - surf_network_model = new NetworkCm02Model(); + surf_network_model = new simgrid::surf::NetworkCm02Model(); net_define_callbacks(); - ModelPtr model = static_cast(surf_network_model); - xbt_dynar_push(model_list, &model); + simgrid::surf::Model *model = surf_network_model; + xbt_dynar_push(all_existing_models, &model); xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor", 13.01); @@ -163,14 +83,12 @@ void surf_network_model_init_CM02(void) if (surf_network_model) return; - surf_network_model = new NetworkCm02Model(); + surf_network_model = new simgrid::surf::NetworkCm02Model(); + xbt_dynar_push(all_existing_models, &surf_network_model); net_define_callbacks(); - ModelPtr model = static_cast(surf_network_model); - xbt_dynar_push(model_list, &model); 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/bandwidth_factor", 1.0); xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S", 0.0); } @@ -189,17 +107,14 @@ void surf_network_model_init_Reno(void) if (surf_network_model) return; - surf_network_model = new NetworkCm02Model(); + surf_network_model = new simgrid::surf::NetworkCm02Model(); + xbt_dynar_push(all_existing_models, &surf_network_model); net_define_callbacks(); - ModelPtr model = static_cast(surf_network_model); - xbt_dynar_push(model_list, &model); - lmm_set_default_protocol_function(func_reno_f, func_reno_fp, - func_reno_fpi); + lmm_set_default_protocol_function(func_reno_f, func_reno_fp, func_reno_fpi); surf_network_model->f_networkSolve = lagrange_solve; 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/bandwidth_factor", 0.92); xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S", 8775); } @@ -209,19 +124,15 @@ void surf_network_model_init_Reno2(void) if (surf_network_model) return; - surf_network_model = new NetworkCm02Model(); + surf_network_model = new simgrid::surf::NetworkCm02Model(); + xbt_dynar_push(all_existing_models, &surf_network_model); net_define_callbacks(); - ModelPtr model = static_cast(surf_network_model); - xbt_dynar_push(model_list, &model); - lmm_set_default_protocol_function(func_reno2_f, func_reno2_fp, - func_reno2_fpi); + lmm_set_default_protocol_function(func_reno2_f, func_reno2_fp, func_reno2_fpi); surf_network_model->f_networkSolve = lagrange_solve; 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_parameter", - 8775); + xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor", 0.92); + xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S", 8775); } void surf_network_model_init_Vegas(void) @@ -229,24 +140,23 @@ void surf_network_model_init_Vegas(void) if (surf_network_model) return; - surf_network_model = new NetworkCm02Model(); + surf_network_model = new simgrid::surf::NetworkCm02Model(); + xbt_dynar_push(all_existing_models, &surf_network_model); net_define_callbacks(); - ModelPtr model = static_cast(surf_network_model); - xbt_dynar_push(model_list, &model); - lmm_set_default_protocol_function(func_vegas_f, func_vegas_fp, - func_vegas_fpi); + lmm_set_default_protocol_function(func_vegas_f, func_vegas_fp, func_vegas_fpi); surf_network_model->f_networkSolve = lagrange_solve; 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/bandwidth_factor", 0.92); xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S", 8775); } -void NetworkCm02Model::initialize() -{ - ActionLmmPtr comm = NULL; +namespace simgrid { +namespace surf { +NetworkCm02Model::NetworkCm02Model() + :NetworkModel() +{ char *optim = xbt_cfg_get_string(_sg_cfg_set, "network/optim"); int select = xbt_cfg_get_boolean(_sg_cfg_set, "network/maxmin_selective_update"); @@ -257,103 +167,89 @@ void NetworkCm02Model::initialize() } 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")), + 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); + p_maxminSystem = lmm_system_new(m_selectiveUpdate); - const char* lb_name = "__loopback__"; - routing_model_create(static_cast(createResource(lb_name, - 498000000, NULL, 0.000015, NULL, - SURF_RESOURCE_ON, NULL, - SURF_LINK_FATPIPE, NULL))); + 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 = xbt_swag_new(xbt_swag_offset(*comm, p_actionListHookup)); - p_maxminSystem->keep_track = p_modifiedSet; + 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; } - - m_haveGap = false; } -NetworkLinkPtr NetworkCm02Model::createResource(const char *name, +Link* NetworkCm02Model::createLink(const char *name, double bw_initial, tmgr_trace_t bw_trace, double lat_initial, tmgr_trace_t lat_trace, - e_surf_resource_state_t state_initial, + int initiallyOn, tmgr_trace_t state_trace, e_surf_link_sharing_policy_t policy, xbt_dict_t properties) { - xbt_assert(!xbt_lib_get_or_null(link_lib, name, SURF_LINK_LEVEL), - "Link '%s' declared several times in the platform file.", + xbt_assert(NULL == Link::byName(name), + "Link '%s' declared several times in the platform", name); - NetworkCm02LinkLmmPtr nw_link = - new NetworkCm02LinkLmm(this, name, properties, p_maxminSystem, sg_bandwidth_factor * bw_initial, history, - state_initial, state_trace, bw_initial, bw_trace, lat_initial, lat_trace, policy); - - - xbt_lib_set(link_lib, name, SURF_LINK_LEVEL, static_cast(nw_link)); - XBT_DEBUG("Create link '%s'",name); - - return nw_link; + Link* link = new NetworkCm02Link(this, name, properties, p_maxminSystem, sg_bandwidth_factor * bw_initial, + initiallyOn, state_trace, bw_initial, bw_trace, lat_initial, lat_trace, policy); + Link::onCreation(link); + return link; } void NetworkCm02Model::updateActionsStateLazy(double now, double /*delta*/) { - NetworkCm02ActionLmmPtr action; + NetworkCm02Action *action; while ((xbt_heap_size(p_actionHeap) > 0) - && (double_equals(xbt_heap_maxkey(p_actionHeap), now))) { - action = (NetworkCm02ActionLmmPtr) xbt_heap_pop(p_actionHeap); + && (double_equals(xbt_heap_maxkey(p_actionHeap), now, sg_surf_precision))) { + action = static_cast (xbt_heap_pop(p_actionHeap)); XBT_DEBUG("Something happened to action %p", action); -#ifdef HAVE_TRACING if (TRACE_is_enabled()) { - int n = lmm_get_number_of_cnst_from_var(p_maxminSystem, action->p_variable); + 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->p_variable, + action->getVariable(), i); - NetworkCm02LinkLmmPtr link = static_cast(lmm_constraint_id(constraint)); - TRACE_surf_link_set_utilization(link->m_name, - action->p_category, - (lmm_variable_getvalue(action->p_variable)* + NetworkCm02Link *link = static_cast(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->p_variable, + action->getVariable(), i)), - action->m_lastUpdate, - now - action->m_lastUpdate); + action->getLastUpdate(), + now - action->getLastUpdate()); } } -#endif // if I am wearing a latency hat - if (action->m_hat == LATENCY) { + if (action->getHat() == LATENCY) { XBT_DEBUG("Latency paid for action %p. Activating", action); - lmm_update_variable_weight(p_maxminSystem, action->p_variable, action->m_weight); + lmm_update_variable_weight(p_maxminSystem, action->getVariable(), action->m_weight); action->heapRemove(p_actionHeap); - action->m_lastUpdate = surf_get_clock(); + action->refreshLastUpdate(); // if I am wearing a max_duration or normal hat - } else if (action->m_hat == MAX_DURATION || - action->m_hat == NORMAL) { + } 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 - action->m_finish = surf_get_clock(); XBT_DEBUG("Action %p finished", action); - action->m_remains = 0; - action->m_finish = surf_get_clock(); + action->setRemains(0); + action->finish(); action->setState(SURF_ACTION_DONE); action->heapRemove(p_actionHeap); @@ -363,54 +259,124 @@ void NetworkCm02Model::updateActionsStateLazy(double now, double /*delta*/) return; } -ActionPtr NetworkCm02Model::communicate(RoutingEdgePtr src, RoutingEdgePtr dst, + +void NetworkCm02Model::updateActionsStateFull(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 (&*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(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()); + } + } + 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()); + } + 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(); + } + } + return; +} + +Action *NetworkCm02Model::communicate(NetCard *src, NetCard *dst, double size, double rate) { unsigned int i; void *_link; - NetworkCm02LinkLmmPtr link; + NetworkCm02Link *link; int failed = 0; - NetworkCm02ActionLmmPtr action = NULL; + 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(RoutingEdgePtr), NULL); + xbt_dynar_t route = xbt_dynar_new(sizeof(NetCard*), NULL); - XBT_IN("(%s,%s,%g,%g)", src->p_name, dst->p_name, size, rate); + XBT_IN("(%s,%s,%g,%g)", src->getName(), dst->getName(), size, rate); routing_platf->getRouteAndLatency(src, dst, &route, &latency); xbt_assert(!xbt_dynar_is_empty(route) || latency, - "You're trying to send data from %s to %s but there is no connection at all between these two hosts.", - src->p_name, dst->p_name); + "You're trying to send data from %s to %s but there is no connecting path between these two hosts.", + src->getName(), dst->getName()); xbt_dynar_foreach(route, i, _link) { - link = dynamic_cast(static_cast(_link)); - if (link->p_stateCurrent == SURF_RESOURCE_OFF) { + link = static_cast(_link); + if (link->isOff()) { failed = 1; break; } } if (sg_network_crosstraffic == 1) { - routing_platf->getRouteAndLatency(dst, src, &back_route, NULL); + routing_platf->getRouteAndLatency(dst, src, &back_route, NULL); xbt_dynar_foreach(back_route, i, _link) { - link = dynamic_cast(static_cast(_link)); - if (link->p_stateCurrent == SURF_RESOURCE_OFF) { + link = static_cast(_link); + if (link->isOff()) { failed = 1; break; } } } - action = new NetworkCm02ActionLmm(this, size, failed); + action = new NetworkCm02Action(this, size, failed); #ifdef HAVE_LATENCY_BOUND_TRACKING action->m_latencyLimited = 0; #endif action->m_weight = action->m_latency = latency; - //FIXME:REMOVxbt_swag_insert(action, action->p_stateSet); action->m_rate = rate; if (p_updateMechanism == UM_LAZY) { action->m_indexHeap = -1; @@ -420,17 +386,15 @@ ActionPtr NetworkCm02Model::communicate(RoutingEdgePtr src, RoutingEdgePtr dst, bandwidth_bound = -1.0; if (sg_weight_S_parameter > 0) { xbt_dynar_foreach(route, i, _link) { - link = dynamic_cast(static_cast(_link)); - action->m_weight += - sg_weight_S_parameter / - (link->p_power.peak * link->p_power.scale); + link = static_cast(_link); + action->m_weight += sg_weight_S_parameter / link->getBandwidth(); } } xbt_dynar_foreach(route, i, _link) { - link = dynamic_cast(static_cast(_link)); - double bb = bandwidthFactor(size) * (link->p_power.peak * link->p_power.scale); + link = static_cast(_link); + double bb = bandwidthFactor(size) * link->getBandwidth(); bandwidth_bound = - (bandwidth_bound < 0.0) ? bb : min(bandwidth_bound, bb); + (bandwidth_bound < 0.0) ? bb : std::min(bandwidth_bound, bb); } action->m_latCurrent = action->m_latency; @@ -440,11 +404,10 @@ ActionPtr NetworkCm02Model::communicate(RoutingEdgePtr src, RoutingEdgePtr dst, 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 = *(NetworkCm02LinkLmmPtr *) xbt_dynar_get_ptr(route, 0); - link = dynamic_cast(*static_cast(xbt_dynar_get_ptr(route, 0))); + link = *static_cast(xbt_dynar_get_ptr(route, 0)); gapAppend(size, link, action); XBT_DEBUG("Comm %p: %s -> %s gap=%f (lat=%f)", - action, src->p_name, dst->p_name, action->m_senderGap, + action, src->getName(), dst->getName(), action->m_senderGap, action->m_latency); } @@ -465,158 +428,169 @@ ActionPtr NetworkCm02Model::communicate(RoutingEdgePtr src, RoutingEdgePtr dst, action->p_variable = lmm_variable_new(p_maxminSystem, action, 1.0, -1.0, constraints_per_variable); if (action->m_rate < 0) { - lmm_update_variable_bound(p_maxminSystem, action->p_variable, (action->m_latCurrent > 0) ? sg_tcp_gamma / (2.0 * action->m_latCurrent) : -1.0); + lmm_update_variable_bound(p_maxminSystem, action->getVariable(), (action->m_latCurrent > 0) ? sg_tcp_gamma / (2.0 * action->m_latCurrent) : -1.0); } else { - lmm_update_variable_bound(p_maxminSystem, action->p_variable, (action->m_latCurrent > 0) ? min(action->m_rate, sg_tcp_gamma / (2.0 * action->m_latCurrent)) : action->m_rate); + 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); } xbt_dynar_foreach(route, i, _link) { - link = dynamic_cast(static_cast(_link)); - lmm_expand(p_maxminSystem, link->p_constraint, action->p_variable, 1.0); + link = static_cast(_link); + lmm_expand(p_maxminSystem, link->getConstraint(), action->getVariable(), 1.0); } if (sg_network_crosstraffic == 1) { XBT_DEBUG("Fullduplex active adding backward flow using 5%%"); xbt_dynar_foreach(back_route, i, _link) { - link = dynamic_cast(static_cast(_link)); - lmm_expand(p_maxminSystem, link->p_constraint, action->p_variable, .05); + link = static_cast(_link); + lmm_expand(p_maxminSystem, link->getConstraint(), action->getVariable(), .05); } + lmm_variable_concurrency_share_set(action->getVariable(),2); } xbt_dynar_free(&route); XBT_OUT(); + networkCommunicateCallbacks(action, src, dst, size, rate); return action; } - - /************ * Resource * ************/ -NetworkCm02LinkLmm::NetworkCm02LinkLmm(NetworkCm02ModelPtr model, const char *name, xbt_dict_t props, - lmm_system_t system, - double constraint_value, - tmgr_history_t history, - e_surf_resource_state_t state_init, - tmgr_trace_t state_trace, - double metric_peak, - tmgr_trace_t metric_trace, - double lat_initial, - tmgr_trace_t lat_trace, - e_surf_link_sharing_policy_t policy) -: Resource(model, name, props), - NetworkLinkLmm(system, constraint_value, history, state_init, state_trace, metric_peak, metric_trace) +NetworkCm02Link::NetworkCm02Link(NetworkCm02Model *model, const char *name, xbt_dict_t props, + lmm_system_t system, + double constraint_value, + 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), state_trace) { - m_latCurrent = lat_initial; + if (initiallyOn) + turnOn(); + else + turnOff(); + + m_bandwidth.scale = 1.0; + m_bandwidth.peak = bw_peak; + if (bw_trace) + m_bandwidth.event = future_evt_set->add_trace(bw_trace, 0.0, this); + else + m_bandwidth.event = NULL; + + m_latency.scale = 1.0; + m_latency.peak = lat_initial; if (lat_trace) - p_latEvent = tmgr_history_add_trace(history, lat_trace, 0.0, 0, static_cast(this)); + m_latency.event = future_evt_set->add_trace(lat_trace, 0.0, this); if (policy == SURF_LINK_FATPIPE) - lmm_constraint_shared(p_constraint); + lmm_constraint_shared(getConstraint()); } -void NetworkCm02LinkLmm::updateState(tmgr_trace_event_t event_type, - double value, double date) +void NetworkCm02Link::apply_event(tmgr_trace_iterator_t triggered, double value) { - /* printf("[" "%g" "] Asking to update network card \"%s\" with value " */ - /* "%g" " for event %p\n", surf_get_clock(), nw_link->name, */ - /* value, event_type); */ - - if (event_type == p_power.event) { - double delta = - sg_weight_S_parameter / value - sg_weight_S_parameter / - (p_power.peak * p_power.scale); - lmm_variable_t var = NULL; - lmm_element_t elem = NULL; - NetworkCm02ActionLmmPtr action = NULL; - - p_power.peak = value; - lmm_update_constraint_bound(p_model->p_maxminSystem, - p_constraint, - sg_bandwidth_factor * - (p_power.peak * p_power.scale)); -#ifdef HAVE_TRACING - TRACE_surf_link_set_bandwidth(date, m_name, sg_bandwidth_factor * p_power.peak * p_power.scale); -#endif - if (sg_weight_S_parameter > 0) { - while ((var = lmm_get_var_from_cnst(p_model->p_maxminSystem, p_constraint, &elem))) { - action = (NetworkCm02ActionLmmPtr) lmm_variable_id(var); - action->m_weight += delta; - if (!action->m_suspended) - lmm_update_variable_weight(p_model->p_maxminSystem, action->p_variable, action->m_weight); - } - } - if (tmgr_trace_event_free(event_type)) - p_power.event = NULL; - } else if (event_type == p_latEvent) { - double delta = value - m_latCurrent; - lmm_variable_t var = NULL; - lmm_element_t elem = NULL; - NetworkCm02ActionLmmPtr action = NULL; - - m_latCurrent = value; - while ((var = lmm_get_var_from_cnst(p_model->p_maxminSystem, p_constraint, &elem))) { - action = (NetworkCm02ActionLmmPtr) lmm_variable_id(var); - action->m_latCurrent += delta; - action->m_weight += delta; - if (action->m_rate < 0) - lmm_update_variable_bound(p_model->p_maxminSystem, action->p_variable, sg_tcp_gamma / (2.0 * action->m_latCurrent)); - else { - lmm_update_variable_bound(p_model->p_maxminSystem, action->p_variable, - min(action->m_rate, sg_tcp_gamma / (2.0 * action->m_latCurrent))); - - if (action->m_rate < sg_tcp_gamma / (2.0 * action->m_latCurrent)) { - XBT_INFO("Flow is limited BYBANDWIDTH"); - } else { - XBT_INFO("Flow is limited BYLATENCY, latency of flow is %f", - action->m_latCurrent); - } - } - if (!action->m_suspended) - lmm_update_variable_weight(p_model->p_maxminSystem, action->p_variable, action->m_weight); - } - if (tmgr_trace_event_free(event_type)) - p_latEvent = NULL; - } else if (event_type == p_stateEvent) { + /* Find out which of my iterators was triggered, and react accordingly */ + if (triggered == m_bandwidth.event) { + updateBandwidth(value); + tmgr_trace_event_unref(&m_bandwidth.event); + + } else if (triggered == m_latency.event) { + updateLatency(value); + tmgr_trace_event_unref(&m_latency.event); + + } else if (triggered == m_stateEvent) { if (value > 0) - p_stateCurrent = SURF_RESOURCE_ON; + turnOn(); else { - lmm_constraint_t cnst = p_constraint; lmm_variable_t var = NULL; lmm_element_t elem = NULL; + double now = surf_get_clock(); - p_stateCurrent = SURF_RESOURCE_OFF; - while ((var = lmm_get_var_from_cnst(p_model->p_maxminSystem, cnst, &elem))) { - ActionPtr action = (ActionPtr) lmm_variable_id(var); + turnOff(); + while ((var = lmm_get_var_from_cnst(getModel()->getMaxminSystem(), getConstraint(), &elem))) { + Action *action = static_cast( lmm_variable_id(var) ); if (action->getState() == SURF_ACTION_RUNNING || action->getState() == SURF_ACTION_READY) { - action->m_finish = date; + action->setFinishTime(now); action->setState(SURF_ACTION_FAILED); } } } - if (tmgr_trace_event_free(event_type)) - p_stateEvent = NULL; + tmgr_trace_event_unref(&m_stateEvent); } else { - XBT_CRITICAL("Unknown event ! \n"); - xbt_abort(); + xbt_die("Unknown event!\n"); } XBT_DEBUG - ("There were a resource state event, need to update actions related to the constraint (%p)", - p_constraint); - return; + ("There was a resource state event, need to update actions related to the constraint (%p)", + getConstraint()); +} + +void NetworkCm02Link::updateBandwidth(double value) { + double delta = sg_weight_S_parameter / value - sg_weight_S_parameter / + (m_bandwidth.peak * m_bandwidth.scale); + lmm_variable_t var = NULL; + lmm_element_t elem = NULL; + lmm_element_t nextelem = NULL; + int numelem = 0; + + NetworkCm02Action *action = NULL; + + m_bandwidth.peak = value; + lmm_update_constraint_bound(getModel()->getMaxminSystem(), + getConstraint(), + sg_bandwidth_factor * + (m_bandwidth.peak * m_bandwidth.scale)); + TRACE_surf_link_set_bandwidth(surf_get_clock(), getName(), sg_bandwidth_factor * m_bandwidth.peak * m_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); + } + } +} + +void NetworkCm02Link::updateLatency(double value){ + double delta = value - m_latency.peak; + lmm_variable_t var = NULL; + lmm_element_t elem = NULL; + lmm_element_t nextelem = NULL; + int numelem = 0; + NetworkCm02Action *action = NULL; + + m_latency.peak = 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)); + else { + lmm_update_variable_bound(getModel()->getMaxminSystem(), action->getVariable(), + std::min(action->m_rate, sg_tcp_gamma / (2.0 * action->m_latCurrent))); + + if (action->m_rate < sg_tcp_gamma / (2.0 * action->m_latCurrent)) { + XBT_INFO("Flow is limited BYBANDWIDTH"); + } else { + XBT_INFO("Flow is limited BYLATENCY, latency of flow is %f", + action->m_latCurrent); + } + } + if (!action->isSuspended()) + lmm_update_variable_weight(getModel()->getMaxminSystem(), action->getVariable(), action->m_weight); + } } /********** * Action * **********/ -void NetworkCm02ActionLmm::updateRemainingLazy(double now) +void NetworkCm02Action::updateRemainingLazy(double now) { double delta = 0.0; @@ -626,33 +600,31 @@ void NetworkCm02ActionLmm::updateRemainingLazy(double now) delta = now - m_lastUpdate; if (m_remains > 0) { - XBT_DEBUG("Updating action(%p): remains was %lf, last_update was: %lf", this, m_remains, m_lastUpdate); - double_update(&(m_remains), m_lastValue * delta); + 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); - XBT_DEBUG("Updating action(%p): remains is now %lf", this, m_remains); + XBT_DEBUG("Updating action(%p): remains is now %f", this, m_remains); } if (m_maxDuration != NO_MAX_DURATION) - double_update(&m_maxDuration, delta); + double_update(&m_maxDuration, delta, sg_surf_precision); if (m_remains <= 0 && - (lmm_get_variable_weight(p_variable) > 0)) { - m_finish = surf_get_clock(); + (lmm_get_variable_weight(getVariable()) > 0)) { + finish(); setState(SURF_ACTION_DONE); - heapRemove(p_model->p_actionHeap); + heapRemove(getModel()->getActionHeap()); } else if (((m_maxDuration != NO_MAX_DURATION) && (m_maxDuration <= 0))) { - m_finish = surf_get_clock(); + finish(); setState(SURF_ACTION_DONE); - heapRemove(p_model->p_actionHeap); + heapRemove(getModel()->getActionHeap()); } m_lastUpdate = now; - m_lastValue = lmm_variable_getvalue(p_variable); -} -void NetworkCm02ActionLmm::recycle() -{ - return; + m_lastValue = lmm_variable_getvalue(getVariable()); } +} +}