3 * Network with improved management of tasks, IM (Improved Management).
4 * Uses a heap to store actions so that the share_resources is faster.
5 * This model automatically sets the selective update flag to 1 and is
6 * highly dependent on the maxmin lmm module.
9 /* Copyright (c) 2009, 2010, 2011. The SimGrid Team.
10 * All rights reserved. */
12 /* This program is free software; you can redistribute it and/or modify it
13 * under the terms of the license (GNU LGPL) which comes with this package. */
15 #include "network_private.h"
19 #include "surf_private.h"
21 #include "maxmin_private.h"
22 #include "surf/surfxml_parse_values.h"
23 #include "surf/surf_resource.h"
24 #include "surf/surf_resource_lmm.h"
27 #define GENERIC_ACTION(action) action->generic_action
30 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_network, surf,
31 "Logging specific to the SURF network module");
33 surf_model_t surf_network_model = NULL;
34 static lmm_system_t network_maxmin_system = NULL;
35 static void (*network_solve) (lmm_system_t) = NULL;
37 double sg_sender_gap = 0.0;
38 double sg_latency_factor = 1.0; /* default value; can be set by model or from command line */
39 double sg_bandwidth_factor = 1.0; /* default value; can be set by model or from command line */
40 double sg_weight_S_parameter = 0.0; /* default value; can be set by model or from command line */
42 double sg_tcp_gamma = 0.0;
43 int sg_network_crosstraffic = 0;
45 xbt_dict_t gap_lookup = NULL;
47 e_UM_t network_update_mechanism = UM_UNDEFINED;
48 static int selective_update = 0;
50 static int net_action_is_suspended(surf_action_t action);
51 static void net_update_actions_state(double now, double delta);
52 static void update_action_remaining(double now);
54 static xbt_swag_t net_modified_set = NULL;
55 static xbt_heap_t net_action_heap = NULL;
56 xbt_swag_t keep_track = NULL;
57 extern int sg_maxmin_selective_update;
60 static void gap_append(double size, const link_CM02_t link, surf_action_network_CM02_t action);
61 static void gap_unknown(surf_action_network_CM02_t action);
62 static void gap_remove(surf_action_network_CM02_t action);
65 /* added to manage the communication action's heap */
66 static void net_action_update_index_heap(void *action, int i)
68 ((surf_action_network_CM02_t) action)->index_heap = i;
71 /* insert action on heap using a given key and a hat (heap_action_type)
72 * a hat can be of three types for communications:
74 * NORMAL = this is a normal heap entry stating the date to finish transmitting
75 * LATENCY = this is a heap entry to warn us when the latency is payed
76 * MAX_DURATION =this is a heap entry to warn us when the max_duration limit is reached
78 static void heap_insert(surf_action_network_CM02_t action, double key, enum heap_action_type hat){
80 xbt_heap_push(net_action_heap, action, key);
83 static void heap_remove(surf_action_network_CM02_t action){
85 if(((surf_action_network_CM02_t) action)->index_heap >= 0){
86 xbt_heap_remove(net_action_heap,action->index_heap);
90 /******************************************************************************/
91 /* Factors callbacks */
92 /******************************************************************************/
93 static double constant_latency_factor(double size)
95 return sg_latency_factor;
98 static double constant_bandwidth_factor(double size)
100 return sg_bandwidth_factor;
103 static double constant_bandwidth_constraint(double rate, double bound,
110 /**********************/
112 /**********************/
113 static double smpi_latency_factor(double size)
115 /* 1 B <= size <= 1 KiB */
116 if (size <= 1024.0) {
120 /* 2 KiB <= size <= 32 KiB */
121 if (size <= 32768.0) {
125 /* 64 KiB <= size <= 4 MiB */
129 static double smpi_bandwidth_factor(double size)
131 /* 1 B <= size <= 1 KiB */
132 if (size <= 1024.0) {
136 /* 2 KiB <= size <= 32 KiB */
137 if (size <= 32768.0) {
141 /* 64 KiB <= size <= 4 MiB */
145 static double smpi_bandwidth_constraint(double rate, double bound,
148 return rate < 0 ? bound : min(bound, rate * smpi_bandwidth_factor(size));
151 static double (*latency_factor_callback) (double) =
152 &constant_latency_factor;
153 static double (*bandwidth_factor_callback) (double) =
154 &constant_bandwidth_factor;
155 static double (*bandwidth_constraint_callback) (double, double, double) =
156 &constant_bandwidth_constraint;
159 static void* net_create_resource(const char *name,
161 tmgr_trace_t bw_trace,
163 tmgr_trace_t lat_trace,
164 e_surf_resource_state_t
166 tmgr_trace_t state_trace,
167 e_surf_link_sharing_policy_t
168 policy, xbt_dict_t properties)
170 link_CM02_t nw_link = (link_CM02_t)
171 surf_resource_lmm_new(sizeof(s_link_CM02_t),
172 surf_network_model, name, properties,
173 network_maxmin_system,
174 sg_bandwidth_factor * bw_initial,
176 state_initial, state_trace,
177 bw_initial, bw_trace);
179 xbt_assert(!xbt_lib_get_or_null(link_lib, name, SURF_LINK_LEVEL),
180 "Link '%s' declared several times in the platform file.",
183 nw_link->lat_current = lat_initial;
186 tmgr_history_add_trace(history, lat_trace, 0.0, 0, nw_link);
188 if (policy == SURF_LINK_FATPIPE)
189 lmm_constraint_shared(nw_link->lmm_resource.constraint);
191 xbt_lib_set(link_lib, name, SURF_LINK_LEVEL, nw_link);
196 static void net_parse_link_init(sg_platf_link_cbarg_t link)
198 if(link->policy == SURF_LINK_FULLDUPLEX){
200 link_id = bprintf("%s_UP", link->id);
201 net_create_resource(link_id,
203 link->bandwidth_trace,
211 link_id = bprintf("%s_DOWN", link->id);
212 net_create_resource(link_id,
214 link->bandwidth_trace,
224 net_create_resource(link->id,
226 link->bandwidth_trace,
236 static void net_add_traces(void)
238 xbt_dict_cursor_t cursor = NULL;
239 char *trace_name, *elm;
241 static int called = 0;
246 /* connect all traces relative to network */
247 xbt_dict_foreach(trace_connect_list_link_avail, cursor, trace_name, elm) {
248 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
250 xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL);
252 xbt_assert(link, "Cannot connect trace %s to link %s: link undefined",
255 "Cannot connect trace %s to link %s: trace undefined",
258 link->lmm_resource.state_event =
259 tmgr_history_add_trace(history, trace, 0.0, 0, link);
262 xbt_dict_foreach(trace_connect_list_bandwidth, cursor, trace_name, elm) {
263 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
265 xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL);
267 xbt_assert(link, "Cannot connect trace %s to link %s: link undefined",
270 "Cannot connect trace %s to link %s: trace undefined",
273 link->lmm_resource.power.event =
274 tmgr_history_add_trace(history, trace, 0.0, 0, link);
277 xbt_dict_foreach(trace_connect_list_latency, cursor, trace_name, elm) {
278 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
280 xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL);
282 xbt_assert(link, "Cannot connect trace %s to link %s: link undefined",
285 "Cannot connect trace %s to link %s: trace undefined",
288 link->lat_event = tmgr_history_add_trace(history, trace, 0.0, 0, link);
292 static void net_define_callbacks(void)
294 /* Figuring out the network links */
295 sg_platf_link_add_cb(net_parse_link_init);
296 sg_platf_postparse_add_cb(net_add_traces);
299 static int net_resource_used(void *resource_id)
301 return lmm_constraint_used(network_maxmin_system,
302 ((surf_resource_lmm_t)
303 resource_id)->constraint);
306 static int net_action_unref(surf_action_t action)
309 if (!action->refcount) {
310 xbt_swag_remove(action, action->state_set);
311 if (((surf_action_network_CM02_t) action)->variable){
312 lmm_variable_free(network_maxmin_system,
313 ((surf_action_network_CM02_t) action)->variable);
315 if(network_update_mechanism == UM_LAZY){// remove action from the heap
316 heap_remove((surf_action_network_CM02_t) action);
317 xbt_swag_remove(action, net_modified_set);
320 xbt_free(((surf_action_network_CM02_t) action)->src_name);
321 xbt_free(((surf_action_network_CM02_t) action)->dst_name);
322 xbt_free(action->category);
324 surf_action_free(&action);
332 static void net_action_cancel(surf_action_t action)
334 surf_network_model->action_state_set(action, SURF_ACTION_FAILED);
335 if(network_update_mechanism == UM_LAZY){// remove action from the heap
336 xbt_swag_remove(action, net_modified_set);
337 heap_remove((surf_action_network_CM02_t) action);
341 void net_action_recycle(surf_action_t action)
346 #ifdef HAVE_LATENCY_BOUND_TRACKING
347 static int net_get_link_latency_limited(surf_action_t action)
349 return action->latency_limited;
353 double net_action_get_remains(surf_action_t action)
355 if(network_update_mechanism == UM_LAZY)/* update remains before return it */
356 update_action_remaining(surf_get_clock());
357 return action->remains;
360 static void update_action_remaining(double now){
361 surf_action_network_CM02_t action = NULL;
364 xbt_swag_foreach(action, net_modified_set) {
366 if(action->suspended != 0){
370 delta = now - action->last_update;
372 double_update(&(action->generic_action.remains),
373 lmm_variable_getvalue(action->variable) * delta);
375 if (action->generic_action.max_duration != NO_MAX_DURATION)
376 double_update(&(action->generic_action.max_duration), delta);
378 if ((action->generic_action.remains <= 0) &&
379 (lmm_get_variable_weight(action->variable) > 0)) {
380 action->generic_action.finish = surf_get_clock();
381 surf_network_model->action_state_set((surf_action_t) action,
384 } else if ((action->generic_action.max_duration != NO_MAX_DURATION)
385 && (action->generic_action.max_duration <= 0)) {
386 action->generic_action.finish = surf_get_clock();
387 surf_network_model->action_state_set((surf_action_t) action,
392 action->last_update = now;
396 static double net_share_resources_full(double now)
398 s_surf_action_network_CM02_t s_action;
399 surf_action_network_CM02_t action = NULL;
400 xbt_swag_t running_actions =
401 surf_network_model->states.running_action_set;
404 min = generic_maxmin_share_resources(running_actions,
405 xbt_swag_offset(s_action,
407 network_maxmin_system,
410 #define VARIABLE(action) (*((lmm_variable_t*)(((char *) (action)) + xbt_swag_offset(s_action, variable) )))
412 xbt_swag_foreach(action, running_actions) {
413 #ifdef HAVE_LATENCY_BOUND_TRACKING
414 if (lmm_is_variable_limited_by_latency(action->variable)) {
415 (action->generic_action).latency_limited = 1;
417 (action->generic_action).latency_limited = 0;
420 if (action->latency > 0) {
422 min = action->latency;
423 else if (action->latency < min)
424 min = action->latency;
428 XBT_DEBUG("Min of share resources %f", min);
433 static double net_share_resources_lazy(double now)
435 surf_action_network_CM02_t action = NULL;
439 XBT_DEBUG("Before share resources, the size of modified actions set is %d", xbt_swag_size(net_modified_set));
440 update_action_remaining(now);
442 keep_track = net_modified_set;
443 lmm_solve(network_maxmin_system);
446 XBT_DEBUG("After share resources, The size of modified actions set is %d", xbt_swag_size(net_modified_set));
448 xbt_swag_foreach(action, net_modified_set) {
449 if (GENERIC_ACTION(action).state_set != surf_network_model->states.running_action_set){
453 /* bogus priority, skip it */
454 if (GENERIC_ACTION(action).priority <= 0){
459 value = lmm_variable_getvalue(action->variable);
461 if (GENERIC_ACTION(action).remains > 0) {
462 value = GENERIC_ACTION(action).remains / value;
470 if ((GENERIC_ACTION(action).max_duration != NO_MAX_DURATION)
472 || GENERIC_ACTION(action).start +
473 GENERIC_ACTION(action).max_duration < min)){
474 min = GENERIC_ACTION(action).start +
475 GENERIC_ACTION(action).max_duration;
478 XBT_DEBUG("Action(%p) Start %lf Finish %lf Max_duration %lf", action,
479 GENERIC_ACTION(action).start, now + value,
480 GENERIC_ACTION(action).max_duration);
484 if (action->index_heap >= 0) {
485 heap_remove((surf_action_network_CM02_t) action);
489 heap_insert((surf_action_network_CM02_t) action, min, NORMAL);
490 XBT_DEBUG("Insert at heap action(%p) min %lf now %lf", action, min, now);
494 //hereafter must have already the min value for this resource model
495 if(xbt_heap_size(net_action_heap) > 0 ){
496 min = xbt_heap_maxkey(net_action_heap) - now ;
501 XBT_DEBUG("The minimum with the HEAP %lf", min);
507 static void net_update_actions_state_full(double now, double delta)
510 surf_action_network_CM02_t action = NULL;
511 surf_action_network_CM02_t next_action = NULL;
512 xbt_swag_t running_actions =
513 surf_network_model->states.running_action_set;
515 xbt_swag_t failed_actions =
516 surf_network_model->states.failed_action_set;
519 xbt_swag_foreach_safe(action, next_action, running_actions) {
521 if (action->latency > 0) {
522 if (action->latency > deltap) {
523 double_update(&(action->latency), deltap);
526 double_update(&(deltap), action->latency);
527 action->latency = 0.0;
529 if ((action->latency == 0.0) && !(action->suspended))
530 lmm_update_variable_weight(network_maxmin_system, action->variable,
534 if (TRACE_is_enabled()) {
535 xbt_dynar_t route=NULL;
536 routing_get_route_and_latency(action->src_name, action->dst_name,&route,NULL);
539 xbt_dynar_foreach(route, i, link) {
540 TRACE_surf_link_set_utilization(link->lmm_resource.generic_resource.name,
541 action->generic_action.data,
542 (surf_action_t) action,
543 lmm_variable_getvalue
544 (action->variable), now - delta,
549 if(!lmm_get_number_of_cnst_from_var(network_maxmin_system, action->variable)) {
550 /* There is actually no link used, hence an infinite bandwidth.
551 * This happens often when using models like vivaldi.
552 * In such case, just make sure that the action completes immediately.
554 double_update(&(action->generic_action.remains),
555 action->generic_action.remains);
557 double_update(&(action->generic_action.remains),
558 lmm_variable_getvalue(action->variable) * deltap);
559 if (action->generic_action.max_duration != NO_MAX_DURATION)
560 double_update(&(action->generic_action.max_duration), delta);
562 if ((action->generic_action.remains <= 0) &&
563 (lmm_get_variable_weight(action->variable) > 0)) {
564 action->generic_action.finish = surf_get_clock();
565 surf_network_model->action_state_set((surf_action_t) action,
570 } else if ((action->generic_action.max_duration != NO_MAX_DURATION)
571 && (action->generic_action.max_duration <= 0)) {
572 action->generic_action.finish = surf_get_clock();
573 surf_network_model->action_state_set((surf_action_t) action,
584 static void net_update_actions_state_lazy(double now, double delta)
586 surf_action_network_CM02_t action = NULL;
588 while ((xbt_heap_size(net_action_heap) > 0)
589 && (double_equals(xbt_heap_maxkey(net_action_heap), now))) {
590 action = xbt_heap_pop(net_action_heap);
591 XBT_DEBUG("Action %p: finish", action);
592 GENERIC_ACTION(action).finish = surf_get_clock();
594 // if I am wearing a latency heat
595 if( action->hat == LATENCY){
596 lmm_update_variable_weight(network_maxmin_system, action->variable,
599 action->last_update = surf_get_clock();
601 XBT_DEBUG("Action (%p) is not limited by latency anymore", action);
602 #ifdef HAVE_LATENCY_BOUND_TRACKING
603 GENERIC_ACTION(action).latency_limited = 0;
606 // if I am wearing a max_duration or normal hat
607 }else if( action->hat == MAX_DURATION || action->hat == NORMAL ){
608 // no need to communicate anymore
609 // assume that flows that reached max_duration have remaining of 0
610 GENERIC_ACTION(action).remains = 0;
611 action->generic_action.finish = surf_get_clock();
612 surf_network_model->action_state_set((surf_action_t) action,
620 static void net_update_resource_state(void *id,
621 tmgr_trace_event_t event_type,
622 double value, double date)
624 link_CM02_t nw_link = id;
625 /* printf("[" "%lg" "] Asking to update network card \"%s\" with value " */
626 /* "%lg" " for event %p\n", surf_get_clock(), nw_link->name, */
627 /* value, event_type); */
629 if (event_type == nw_link->lmm_resource.power.event) {
631 sg_weight_S_parameter / value - sg_weight_S_parameter /
632 (nw_link->lmm_resource.power.peak *
633 nw_link->lmm_resource.power.scale);
634 lmm_variable_t var = NULL;
635 lmm_element_t elem = NULL;
636 surf_action_network_CM02_t action = NULL;
638 nw_link->lmm_resource.power.peak = value;
639 lmm_update_constraint_bound(network_maxmin_system,
640 nw_link->lmm_resource.constraint,
641 sg_bandwidth_factor *
642 (nw_link->lmm_resource.power.peak *
643 nw_link->lmm_resource.power.scale));
645 TRACE_surf_link_set_bandwidth(date, (char *)(((nw_link->lmm_resource).generic_resource).name),
646 sg_bandwidth_factor *
647 (nw_link->lmm_resource.power.peak *
648 nw_link->lmm_resource.power.scale));
650 if (sg_weight_S_parameter > 0) {
651 while ((var = lmm_get_var_from_cnst
652 (network_maxmin_system, nw_link->lmm_resource.constraint,
654 action = lmm_variable_id(var);
655 action->weight += delta;
656 if (!(action->suspended))
657 lmm_update_variable_weight(network_maxmin_system,
658 action->variable, action->weight);
661 if (tmgr_trace_event_free(event_type))
662 nw_link->lmm_resource.power.event = NULL;
663 } else if (event_type == nw_link->lat_event) {
664 double delta = value - nw_link->lat_current;
665 lmm_variable_t var = NULL;
666 lmm_element_t elem = NULL;
667 surf_action_network_CM02_t action = NULL;
669 nw_link->lat_current = value;
670 while ((var = lmm_get_var_from_cnst
671 (network_maxmin_system, nw_link->lmm_resource.constraint,
673 action = lmm_variable_id(var);
674 action->lat_current += delta;
675 action->weight += delta;
676 if (action->rate < 0)
677 lmm_update_variable_bound(network_maxmin_system, action->variable,
678 sg_tcp_gamma / (2.0 *
679 action->lat_current));
681 lmm_update_variable_bound(network_maxmin_system, action->variable,
683 sg_tcp_gamma / (2.0 *
684 action->lat_current)));
686 if (action->rate < sg_tcp_gamma / (2.0 * action->lat_current)) {
687 XBT_INFO("Flow is limited BYBANDWIDTH");
689 XBT_INFO("Flow is limited BYLATENCY, latency of flow is %f",
690 action->lat_current);
693 if (!(action->suspended))
694 lmm_update_variable_weight(network_maxmin_system, action->variable,
698 if (tmgr_trace_event_free(event_type))
699 nw_link->lat_event = NULL;
700 } else if (event_type == nw_link->lmm_resource.state_event) {
702 nw_link->lmm_resource.state_current = SURF_RESOURCE_ON;
704 lmm_constraint_t cnst = nw_link->lmm_resource.constraint;
705 lmm_variable_t var = NULL;
706 lmm_element_t elem = NULL;
708 nw_link->lmm_resource.state_current = SURF_RESOURCE_OFF;
709 while ((var = lmm_get_var_from_cnst
710 (network_maxmin_system, cnst, &elem))) {
711 surf_action_t action = lmm_variable_id(var);
713 if (surf_action_state_get(action) == SURF_ACTION_RUNNING ||
714 surf_action_state_get(action) == SURF_ACTION_READY) {
715 action->finish = date;
716 surf_network_model->action_state_set(action, SURF_ACTION_FAILED);
720 if (tmgr_trace_event_free(event_type))
721 nw_link->lmm_resource.state_event = NULL;
723 XBT_CRITICAL("Unknown event ! \n");
727 XBT_DEBUG("There were a resource state event, need to update actions related to the constraint (%p)", nw_link->lmm_resource.constraint);
732 static surf_action_t net_communicate(const char *src_name,
733 const char *dst_name, double size,
739 surf_action_network_CM02_t action = NULL;
740 double bandwidth_bound;
742 /* LARGE PLATFORMS HACK:
743 Add a link_CM02_t *link and a int link_nb to network_card_CM02_t. It will represent local links for this node
744 Use the cluster_id for ->id */
746 xbt_dynar_t back_route = NULL;
747 int constraints_per_variable = 0;
748 // I need to have the forward and backward routes at the same time, so allocate "route". That way, the routing wont clean it up
749 xbt_dynar_t route=xbt_dynar_new(global_routing->size_of_link,NULL);
750 routing_get_route_and_latency(src_name, dst_name, &route, &latency);
752 if (sg_network_crosstraffic == 1) {
753 // FIXME: fill route directly (unclear: check with blame who put the FIXME)
754 routing_get_route_and_latency(dst_name, src_name, &back_route,NULL);
757 /* LARGE PLATFORMS HACK:
758 total_route_size = route_size + src->link_nb + dst->nb */
760 XBT_IN("(%s,%s,%g,%g)", src_name, dst_name, size, rate);
761 /* LARGE PLATFORMS HACK:
762 assert on total_route_size */
763 xbt_assert(!xbt_dynar_is_empty(route) || latency,
764 "You're trying to send data from %s to %s but there is no connection at all between these two hosts.",
767 xbt_dynar_foreach(route, i, link) {
768 if (link->lmm_resource.state_current == SURF_RESOURCE_OFF) {
773 if (sg_network_crosstraffic == 1) {
774 xbt_dynar_foreach(back_route, i, link) {
775 if (link->lmm_resource.state_current == SURF_RESOURCE_OFF) {
783 surf_action_new(sizeof(s_surf_action_network_CM02_t), size,
784 surf_network_model, failed);
785 #ifdef HAVE_LATENCY_BOUND_TRACKING
786 (action->generic_action).latency_limited = 0;
788 action->weight = action->latency = latency;
790 xbt_swag_insert(action, action->generic_action.state_set);
792 if(network_update_mechanism == UM_LAZY){
793 action->index_heap = -1;
794 action->latency = 0.0;
795 action->weight = 0.0;
796 action->last_update = surf_get_clock();
799 bandwidth_bound = -1.0;
800 xbt_dynar_foreach(route, i, link) {
802 sg_weight_S_parameter /
803 (link->lmm_resource.power.peak * link->lmm_resource.power.scale);
804 if (bandwidth_bound < 0.0)
806 bandwidth_factor_callback(size) *
807 (link->lmm_resource.power.peak * link->lmm_resource.power.scale);
811 bandwidth_factor_callback(size) *
812 (link->lmm_resource.power.peak *
813 link->lmm_resource.power.scale));
815 /* LARGE PLATFORMS HACK:
816 Add src->link and dst->link latencies */
817 action->lat_current = action->latency;
818 action->latency *= latency_factor_callback(size);
820 bandwidth_constraint_callback(action->rate, bandwidth_bound,
823 if(!xbt_dynar_is_empty(route)) {
824 link = *(link_CM02_t*)xbt_dynar_get_ptr(route, 0);
825 gap_append(size, link, action);
826 XBT_DEBUG("Comm %p: %s -> %s gap=%f (lat=%f)",
827 action, src_name, dst_name, action->sender.gap, action->latency);
833 /* LARGE PLATFORMS HACK:
834 lmm_variable_new(..., total_route_size) */
835 if (back_route != NULL) {
836 constraints_per_variable =
837 xbt_dynar_length(route) + xbt_dynar_length(back_route);
839 constraints_per_variable = xbt_dynar_length(route);
842 if (action->latency > 0){
844 lmm_variable_new(network_maxmin_system, action, 0.0, -1.0,
845 constraints_per_variable);
846 if(network_update_mechanism == UM_LAZY){
847 // add to the heap the event when the latency is payed
848 XBT_DEBUG("Added action (%p) one latency event at date %f", action, action->latency + action->last_update);
849 heap_insert(action, action->latency + action->last_update, LATENCY);
851 #ifdef HAVE_LATENCY_BOUND_TRACKING
852 (action->generic_action).latency_limited = 1;
857 lmm_variable_new(network_maxmin_system, action, 1.0, -1.0,
858 constraints_per_variable);
860 if (action->rate < 0) {
861 if (action->lat_current > 0)
862 lmm_update_variable_bound(network_maxmin_system, action->variable,
863 sg_tcp_gamma / (2.0 *
864 action->lat_current));
866 lmm_update_variable_bound(network_maxmin_system, action->variable,
869 if (action->lat_current > 0)
870 lmm_update_variable_bound(network_maxmin_system, action->variable,
872 sg_tcp_gamma / (2.0 *
873 action->lat_current)));
875 lmm_update_variable_bound(network_maxmin_system, action->variable,
879 xbt_dynar_foreach(route, i, link) {
880 lmm_expand(network_maxmin_system, link->lmm_resource.constraint,
881 action->variable, 1.0);
884 if (sg_network_crosstraffic == 1) {
885 XBT_DEBUG("Fullduplex active adding backward flow using 5%c", '%');
886 xbt_dynar_foreach(back_route, i, link) {
887 lmm_expand(network_maxmin_system, link->lmm_resource.constraint,
888 action->variable, .05);
892 /* LARGE PLATFORMS HACK:
893 expand also with src->link and dst->link */
895 if (TRACE_is_enabled()) {
896 action->src_name = xbt_strdup(src_name);
897 action->dst_name = xbt_strdup(dst_name);
899 action->src_name = action->dst_name = NULL;
903 xbt_dynar_free(&route);
906 return (surf_action_t) action;
909 static xbt_dynar_t net_get_route(const char *src, const char *dst)
911 xbt_dynar_t route=NULL;
912 routing_get_route_and_latency(src, dst,&route,NULL);
916 static double net_get_link_bandwidth(const void *link)
918 surf_resource_lmm_t lmm = (surf_resource_lmm_t) link;
919 return lmm->power.peak * lmm->power.scale;
922 static double net_get_link_latency(const void *link)
924 return ((link_CM02_t) link)->lat_current;
927 static int net_link_shared(const void *link)
930 lmm_constraint_is_shared(((surf_resource_lmm_t) link)->constraint);
933 static void net_action_suspend(surf_action_t action)
935 ((surf_action_network_CM02_t) action)->suspended = 1;
936 lmm_update_variable_weight(network_maxmin_system,
937 ((surf_action_network_CM02_t)
938 action)->variable, 0.0);
940 if(network_update_mechanism == UM_LAZY)// remove action from the heap
941 heap_remove((surf_action_network_CM02_t) action);
944 static void net_action_resume(surf_action_t action)
946 if (((surf_action_network_CM02_t) action)->suspended) {
947 lmm_update_variable_weight(network_maxmin_system,
948 ((surf_action_network_CM02_t)
950 ((surf_action_network_CM02_t)
952 ((surf_action_network_CM02_t) action)->suspended = 0;
953 if(network_update_mechanism == UM_LAZY)// remove action from the heap
954 heap_remove((surf_action_network_CM02_t) action);
958 static int net_action_is_suspended(surf_action_t action)
960 return ((surf_action_network_CM02_t) action)->suspended;
963 void net_action_set_max_duration(surf_action_t action, double duration)
965 action->max_duration = duration;
966 if(network_update_mechanism == UM_LAZY)// remove action from the heap
967 heap_remove((surf_action_network_CM02_t) action);
971 static void net_action_set_category(surf_action_t action, const char *category)
973 action->category = xbt_strdup (category);
977 static void net_finalize(void)
979 surf_model_exit(surf_network_model);
980 surf_network_model = NULL;
982 lmm_system_free(network_maxmin_system);
983 network_maxmin_system = NULL;
985 if(network_update_mechanism == UM_LAZY){
986 xbt_heap_free(net_action_heap);
987 xbt_swag_free(net_modified_set);
992 static void gap_append(double size, const link_CM02_t link, surf_action_network_CM02_t action) {
993 const char* src = link->lmm_resource.generic_resource.name;
995 surf_action_network_CM02_t last_action;
998 if(sg_sender_gap > 0.0) {
1000 gap_lookup = xbt_dict_new();
1002 fifo = (xbt_fifo_t)xbt_dict_get_or_null(gap_lookup, src);
1003 action->sender.gap = 0.0;
1004 if(fifo && xbt_fifo_size(fifo) > 0) {
1005 /* Compute gap from last send */
1006 last_action = (surf_action_network_CM02_t)xbt_fifo_get_item_content(xbt_fifo_get_last_item(fifo));
1007 bw = net_get_link_bandwidth(link);
1008 action->sender.gap = last_action->sender.gap + max(sg_sender_gap, last_action->sender.size / bw);
1009 action->latency += action->sender.gap;
1011 /* Append action as last send */
1012 action->sender.link_name = link->lmm_resource.generic_resource.name;
1013 fifo = (xbt_fifo_t)xbt_dict_get_or_null(gap_lookup, action->sender.link_name);
1015 fifo = xbt_fifo_new();
1016 xbt_dict_set(gap_lookup, action->sender.link_name, fifo, NULL);
1018 action->sender.fifo_item = xbt_fifo_push(fifo, action);
1019 action->sender.size = size;
1023 static void gap_unknown(surf_action_network_CM02_t action) {
1024 action->sender.gap = 0.0;
1025 action->sender.link_name = NULL;
1026 action->sender.fifo_item = NULL;
1027 action->sender.size = 0.0;
1030 static void gap_remove(surf_action_network_CM02_t action) {
1034 if(sg_sender_gap > 0.0 && action->sender.link_name && action->sender.fifo_item) {
1035 fifo = (xbt_fifo_t)xbt_dict_get_or_null(gap_lookup, action->sender.link_name);
1036 xbt_fifo_remove_item(fifo, action->sender.fifo_item);
1037 size = xbt_fifo_size(fifo);
1039 xbt_fifo_free(fifo);
1040 xbt_dict_remove(gap_lookup, action->sender.link_name);
1041 size = xbt_dict_length(gap_lookup);
1043 xbt_dict_free(&gap_lookup);
1050 static void surf_network_model_init_internal(void)
1052 s_surf_action_network_CM02_t comm;
1053 surf_network_model = surf_model_init();
1055 surf_network_model->name = "network";
1056 surf_network_model->action_unref = net_action_unref;
1057 surf_network_model->action_cancel = net_action_cancel;
1058 surf_network_model->action_recycle = net_action_recycle;
1059 surf_network_model->get_remains = net_action_get_remains;
1060 #ifdef HAVE_LATENCY_BOUND_TRACKING
1061 surf_network_model->get_latency_limited = net_get_link_latency_limited;
1064 surf_network_model->model_private->resource_used = net_resource_used;
1065 if(network_update_mechanism == UM_LAZY) {
1066 surf_network_model->model_private->share_resources = net_share_resources_lazy;
1067 surf_network_model->model_private->update_actions_state = net_update_actions_state_lazy;
1068 } else if(network_update_mechanism == UM_FULL) {
1069 surf_network_model->model_private->share_resources = net_share_resources_full;
1070 surf_network_model->model_private->update_actions_state = net_update_actions_state_full;
1073 surf_network_model->model_private->update_resource_state =
1074 net_update_resource_state;
1075 surf_network_model->model_private->finalize = net_finalize;
1077 surf_network_model->suspend = net_action_suspend;
1078 surf_network_model->resume = net_action_resume;
1079 surf_network_model->is_suspended = net_action_is_suspended;
1080 surf_cpu_model->set_max_duration = net_action_set_max_duration;
1082 surf_network_model->extension.network.communicate = net_communicate;
1083 surf_network_model->extension.network.get_route = net_get_route;
1084 surf_network_model->extension.network.get_link_bandwidth =
1085 net_get_link_bandwidth;
1086 surf_network_model->extension.network.get_link_latency =
1087 net_get_link_latency;
1088 surf_network_model->extension.network.link_shared = net_link_shared;
1089 surf_network_model->extension.network.add_traces = net_add_traces;
1090 surf_network_model->extension.network.create_resource =
1091 net_create_resource;
1093 if (!network_maxmin_system)
1094 network_maxmin_system = lmm_system_new(selective_update);
1096 routing_model_create(sizeof(link_CM02_t),
1097 net_create_resource("__loopback__",
1098 498000000, NULL, 0.000015, NULL,
1099 SURF_RESOURCE_ON, NULL,
1100 SURF_LINK_FATPIPE, NULL));
1102 if(network_update_mechanism == UM_LAZY){
1103 net_action_heap = xbt_heap_new(8,NULL);
1104 xbt_heap_set_update_callback(net_action_heap, net_action_update_index_heap);
1106 xbt_swag_new(xbt_swag_offset(comm, action_list_hookup));
1110 static void set_update_mechanism(void) {
1111 char *optim = xbt_cfg_get_string(_surf_cfg_set, "network/optim");
1112 int select = xbt_cfg_get_int(_surf_cfg_set, "network/maxmin_selective_update");
1114 if(!strcmp(optim,"Full")) {
1115 network_update_mechanism = UM_FULL;
1116 selective_update = select;
1117 } else if (!strcmp(optim,"Lazy")) {
1118 network_update_mechanism = UM_LAZY;
1119 selective_update = 1;
1120 xbt_assert((select==1) || (xbt_cfg_is_default_value(_surf_cfg_set,"network/maxmin_selective_update")),
1121 "Disabling selective update while using the lazy update mechanism is dumb!");
1123 xbt_die("Unsupported optimization (%s) for this model",optim);
1127 /************************************************************************/
1128 /* New model based on LV08 and experimental results of MPI ping-pongs */
1129 /************************************************************************/
1130 /* @Inproceedings{smpi_ipdps, */
1131 /* author={Pierre-Nicolas Clauss and Mark Stillwell and Stéphane Genaud and Frédéric Suter and Henri Casanova and Martin Quinson}, */
1132 /* title={Single Node On-Line Simulation of {MPI} Applications with SMPI}, */
1133 /* booktitle={25th IEEE International Parallel and Distributed Processing Symposium (IPDPS'11)}, */
1134 /* address={Anchorage (Alaska) USA}, */
1138 void surf_network_model_init_SMPI(void)
1141 if (surf_network_model)
1143 set_update_mechanism();
1145 surf_network_model_init_internal();
1146 latency_factor_callback = &smpi_latency_factor;
1147 bandwidth_factor_callback = &smpi_bandwidth_factor;
1148 bandwidth_constraint_callback = &smpi_bandwidth_constraint;
1149 net_define_callbacks();
1150 xbt_dynar_push(model_list, &surf_network_model);
1151 network_solve = lmm_solve;
1153 xbt_cfg_setdefault_double(_surf_cfg_set, "network/sender_gap", 10e-6);
1154 xbt_cfg_setdefault_double(_surf_cfg_set, "network/weight_S", 8775);
1157 /************************************************************************/
1158 /* New model based on optimizations discussed during Pedro Velho's thesis*/
1159 /************************************************************************/
1160 /* @techreport{VELHO:2011:HAL-00646896:1, */
1161 /* url = {http://hal.inria.fr/hal-00646896/en/}, */
1162 /* title = {{Flow-level network models: have we reached the limits?}}, */
1163 /* author = {Velho, Pedro and Schnorr, Lucas and Casanova, Henri and Legrand, Arnaud}, */
1164 /* type = {Rapport de recherche}, */
1165 /* institution = {INRIA}, */
1166 /* number = {RR-7821}, */
1167 /* year = {2011}, */
1169 /* pdf = {http://hal.inria.fr/hal-00646896/PDF/rr-validity.pdf}, */
1171 void surf_network_model_init_LegrandVelho(void)
1173 char *model = xbt_cfg_get_string(_surf_cfg_set, "network/model");
1175 if (surf_network_model)
1178 if(!strcmp(model,"LV08_fullupdate")) {
1179 XBT_WARN("[*Deprecated*. Use --cfg=network/model:LV08 with option --cfg=network/optim:Full instead.]");
1181 set_update_mechanism();
1183 surf_network_model_init_internal();
1184 net_define_callbacks();
1185 xbt_dynar_push(model_list, &surf_network_model);
1186 network_solve = lmm_solve;
1188 xbt_cfg_setdefault_double(_surf_cfg_set, "network/latency_factor", 10.4); // 13.01 when callibration is done without phase effects
1189 xbt_cfg_setdefault_double(_surf_cfg_set, "network/bandwidth_factor",0.92);// 0.97 when callibration is done without phase effects
1190 xbt_cfg_setdefault_double(_surf_cfg_set, "network/weight_S", 8775); // 20537 when callibration is done without phase effects
1193 /***************************************************************************/
1194 /* The nice TCP sharing model designed by Loris Marchal and Henri Casanova */
1195 /***************************************************************************/
1196 /* @TechReport{ rr-lip2002-40, */
1197 /* author = {Henri Casanova and Loris Marchal}, */
1198 /* institution = {LIP}, */
1199 /* title = {A Network Model for Simulation of Grid Application}, */
1200 /* number = {2002-40}, */
1201 /* month = {oct}, */
1204 void surf_network_model_init_CM02(void)
1207 if (surf_network_model)
1210 set_update_mechanism();
1211 surf_network_model_init_internal();
1212 net_define_callbacks();
1213 xbt_dynar_push(model_list, &surf_network_model);
1214 network_solve = lmm_solve;
1216 xbt_cfg_setdefault_double(_surf_cfg_set, "network/latency_factor", 1.0);
1217 xbt_cfg_setdefault_double(_surf_cfg_set, "network/bandwidth_factor", 1.0);
1218 xbt_cfg_setdefault_double(_surf_cfg_set, "network/weight_S", 0.0);
1221 /***************************************************************************/
1222 /* The models from Steven H. Low */
1223 /***************************************************************************/
1224 /* @article{Low03, */
1225 /* author={Steven H. Low}, */
1226 /* title={A Duality Model of {TCP} and Queue Management Algorithms}, */
1228 /* journal={{IEEE/ACM} Transactions on Networking}, */
1229 /* volume={11}, number={4}, */
1231 void surf_network_model_init_Reno(void)
1233 if (surf_network_model)
1236 set_update_mechanism();
1237 surf_network_model_init_internal();
1238 net_define_callbacks();
1240 xbt_dynar_push(model_list, &surf_network_model);
1241 lmm_set_default_protocol_function(func_reno_f, func_reno_fp,
1243 network_solve = lagrange_solve;
1245 xbt_cfg_setdefault_double(_surf_cfg_set, "network/latency_factor", 10.4);
1246 xbt_cfg_setdefault_double(_surf_cfg_set, "network/bandwidth_factor",
1248 xbt_cfg_setdefault_double(_surf_cfg_set, "network/weight_S", 8775);
1252 void surf_network_model_init_Reno2(void)
1254 if (surf_network_model)
1257 set_update_mechanism();
1258 surf_network_model_init_internal();
1259 net_define_callbacks();
1261 xbt_dynar_push(model_list, &surf_network_model);
1262 lmm_set_default_protocol_function(func_reno2_f, func_reno2_fp,
1264 network_solve = lagrange_solve;
1266 xbt_cfg_setdefault_double(_surf_cfg_set, "network/latency_factor", 10.4);
1267 xbt_cfg_setdefault_double(_surf_cfg_set, "network/bandwidth_factor",
1269 xbt_cfg_setdefault_double(_surf_cfg_set, "network/weight_S_parameter",
1273 void surf_network_model_init_Vegas(void)
1275 if (surf_network_model)
1278 set_update_mechanism();
1279 surf_network_model_init_internal();
1280 net_define_callbacks();
1282 xbt_dynar_push(model_list, &surf_network_model);
1283 lmm_set_default_protocol_function(func_vegas_f, func_vegas_fp,
1285 network_solve = lagrange_solve;
1287 xbt_cfg_setdefault_double(_surf_cfg_set, "network/latency_factor", 10.4);
1288 xbt_cfg_setdefault_double(_surf_cfg_set, "network/bandwidth_factor",
1290 xbt_cfg_setdefault_double(_surf_cfg_set, "network/weight_S", 8775);