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. */
17 #include "surf_private.h"
19 #include "maxmin_private.h"
22 #define GENERIC_ACTION(action) action->generic_action
25 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_network_im, surf,
26 "Logging specific to the SURF network module");
29 enum heap_action_type{
36 typedef struct surf_action_network_CM02_im {
37 s_surf_action_t generic_action;
38 s_xbt_swag_hookup_t action_list_hookup;
42 lmm_variable_t variable;
44 #ifdef HAVE_LATENCY_BOUND_TRACKING
53 enum heap_action_type hat;
55 } s_surf_action_network_CM02_im_t, *surf_action_network_CM02_im_t;
58 typedef struct network_link_CM02_im {
59 s_surf_resource_lmm_t lmm_resource; /* must remain first to be added to a trace */
61 /* Using this object with the public part of
62 model does not make sense */
64 tmgr_trace_event_t lat_event;
65 } s_link_CM02_im_t, *link_CM02_im_t;
74 extern surf_model_t surf_network_model;
75 static lmm_system_t network_im_maxmin_system = NULL;
76 static void (*network_im_solve) (lmm_system_t) = NULL;
78 extern double sg_latency_factor;
79 extern double sg_bandwidth_factor;
80 extern double sg_weight_S_parameter;
82 extern double sg_tcp_gamma;
83 extern int sg_network_fullduplex;
86 static void im_net_action_recycle(surf_action_t action);
87 static int im_net_get_link_latency_limited(surf_action_t action);
88 static int im_net_action_is_suspended(surf_action_t action);
89 static double im_net_action_get_remains(surf_action_t action);
90 static void im_net_action_set_max_duration(surf_action_t action, double duration);
91 static void surf_network_model_init_CM02_im(const char *filename);
92 static void im_net_update_actions_state(double now, double delta);
93 static void update_action_remaining(double now);
95 static xbt_swag_t im_net_modified_set = NULL;
96 static xbt_heap_t im_net_action_heap = NULL;
97 xbt_swag_t keep_track = NULL;
98 extern int sg_maxmin_selective_update;
100 /* added to manage the communication action's heap */
101 static void im_net_action_update_index_heap(void *action, int i)
103 ((surf_action_network_CM02_im_t) action)->index_heap = i;
106 /* insert action on heap using a given key and a hat (heap_action_type)
107 * a hat can be of three types for communications:
109 * NORMAL = this is a normal heap entry stating the date to finish transmitting
110 * LATENCY = this is a heap entry to warn us when the latency is payed
111 * MAX_DURATION =this is a heap entry to warn us when the max_duration limit is reached
113 static void heap_insert(surf_action_network_CM02_im_t action, double key, enum heap_action_type hat){
115 xbt_heap_push(im_net_action_heap, action, key);
118 static void heap_remove(surf_action_network_CM02_im_t action){
120 if(((surf_action_network_CM02_im_t) action)->index_heap >= 0){
121 xbt_heap_remove(im_net_action_heap,action->index_heap);
125 /******************************************************************************/
126 /* Factors callbacks */
127 /******************************************************************************/
128 static double im_constant_latency_factor(double size)
130 return sg_latency_factor;
133 static double im_constant_bandwidth_factor(double size)
135 return sg_bandwidth_factor;
138 static double im_constant_bandwidth_constraint(double rate, double bound,
145 static double (*im_latency_factor_callback) (double) =
146 &im_constant_latency_factor;
147 static double (*im_bandwidth_factor_callback) (double) =
148 &im_constant_bandwidth_factor;
149 static double (*im_bandwidth_constraint_callback) (double, double, double) =
150 &im_constant_bandwidth_constraint;
153 static void* im_net_create_resource(char *name,
155 tmgr_trace_t bw_trace,
157 tmgr_trace_t lat_trace,
158 e_surf_resource_state_t
160 tmgr_trace_t state_trace,
161 e_surf_link_sharing_policy_t
162 policy, xbt_dict_t properties)
164 link_CM02_im_t nw_link = (link_CM02_im_t)
165 surf_resource_lmm_new(sizeof(s_link_CM02_im_t),
166 surf_network_model, name, properties,
167 network_im_maxmin_system,
168 sg_bandwidth_factor * bw_initial,
170 state_initial, state_trace,
171 bw_initial, bw_trace);
173 xbt_assert(!xbt_lib_get_or_null(link_lib, name, SURF_LINK_LEVEL),
174 "Link '%s' declared several times in the platform file.",
177 nw_link->lat_current = lat_initial;
180 tmgr_history_add_trace(history, lat_trace, 0.0, 0, nw_link);
182 if (policy == SURF_LINK_FATPIPE)
183 lmm_constraint_shared(nw_link->lmm_resource.constraint);
185 xbt_lib_set(link_lib, name, SURF_LINK_LEVEL, nw_link);
191 static void im_net_parse_link_init(void)
195 tmgr_trace_t bw_trace;
197 tmgr_trace_t lat_trace;
198 e_surf_resource_state_t state_initial_link = SURF_RESOURCE_ON;
199 e_surf_link_sharing_policy_t policy_initial_link = SURF_LINK_SHARED;
200 tmgr_trace_t state_trace;
201 XBT_DEBUG("link_CM02_im");
202 name_link = xbt_strdup(A_surfxml_link_id);
203 surf_parse_get_double(&bw_initial, A_surfxml_link_bandwidth);
204 bw_trace = tmgr_trace_new(A_surfxml_link_bandwidth_file);
205 surf_parse_get_double(&lat_initial, A_surfxml_link_latency);
206 lat_trace = tmgr_trace_new(A_surfxml_link_latency_file);
208 xbt_assert((A_surfxml_link_state == A_surfxml_link_state_ON)
209 || (A_surfxml_link_state ==
210 A_surfxml_link_state_OFF), "Invalid state");
211 if (A_surfxml_link_state == A_surfxml_link_state_ON)
212 state_initial_link = SURF_RESOURCE_ON;
213 else if (A_surfxml_link_state == A_surfxml_link_state_OFF)
214 state_initial_link = SURF_RESOURCE_OFF;
216 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_SHARED)
217 policy_initial_link = SURF_LINK_SHARED;
220 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FATPIPE)
221 policy_initial_link = SURF_LINK_FATPIPE;
222 else if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FULLDUPLEX)
223 policy_initial_link = SURF_LINK_FULLDUPLEX;
226 state_trace = tmgr_trace_new(A_surfxml_link_state_file);
228 if(policy_initial_link == SURF_LINK_FULLDUPLEX)
230 im_net_create_resource(bprintf("%s_UP",name_link), bw_initial, bw_trace,
231 lat_initial, lat_trace, state_initial_link, state_trace,
232 policy_initial_link, xbt_dict_new());
233 im_net_create_resource(bprintf("%s_DOWN",name_link), bw_initial, bw_trace,
234 lat_initial, lat_trace, state_initial_link, state_trace,
235 policy_initial_link, xbt_dict_new());
239 im_net_create_resource(name_link, bw_initial, bw_trace,
240 lat_initial, lat_trace, state_initial_link, state_trace,
241 policy_initial_link, xbt_dict_new());
246 static void im_net_add_traces(void)
248 xbt_dict_cursor_t cursor = NULL;
249 char *trace_name, *elm;
251 static int called = 0;
256 /* connect all traces relative to network */
257 xbt_dict_foreach(trace_connect_list_link_avail, cursor, trace_name, elm) {
258 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
259 link_CM02_im_t link =
260 xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL);
262 xbt_assert(link, "Cannot connect trace %s to link %s: link undefined",
265 "Cannot connect trace %s to link %s: trace undefined",
268 link->lmm_resource.state_event =
269 tmgr_history_add_trace(history, trace, 0.0, 0, link);
272 xbt_dict_foreach(trace_connect_list_bandwidth, cursor, trace_name, elm) {
273 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
274 link_CM02_im_t link =
275 xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL);
277 xbt_assert(link, "Cannot connect trace %s to link %s: link undefined",
280 "Cannot connect trace %s to link %s: trace undefined",
283 link->lmm_resource.power.event =
284 tmgr_history_add_trace(history, trace, 0.0, 0, link);
287 xbt_dict_foreach(trace_connect_list_latency, cursor, trace_name, elm) {
288 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
289 link_CM02_im_t link =
290 xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL);
292 xbt_assert(link, "Cannot connect trace %s to link %s: link undefined",
295 "Cannot connect trace %s to link %s: trace undefined",
298 link->lat_event = tmgr_history_add_trace(history, trace, 0.0, 0, link);
302 static void im_net_define_callbacks(const char *file)
304 /* Figuring out the network links */
305 surfxml_add_callback(STag_surfxml_link_cb_list, &im_net_parse_link_init);
306 surfxml_add_callback(ETag_surfxml_platform_cb_list, &im_net_add_traces);
309 static int im_net_resource_used(void *resource_id)
311 return lmm_constraint_used(network_im_maxmin_system,
312 ((surf_resource_lmm_t)
313 resource_id)->constraint);
316 static int im_net_action_unref(surf_action_t action)
319 if (!action->refcount) {
320 xbt_swag_remove(action, action->state_set);
321 if (((surf_action_network_CM02_im_t) action)->variable){
322 lmm_variable_free(network_im_maxmin_system,
323 ((surf_action_network_CM02_im_t) action)->variable);
325 // remove action from the heap
326 heap_remove((surf_action_network_CM02_im_t) action);
328 xbt_swag_remove(action, im_net_modified_set);
330 xbt_free(((surf_action_network_CM02_im_t) action)->src_name);
331 xbt_free(((surf_action_network_CM02_im_t) action)->dst_name);
332 if (action->category)
333 xbt_free(action->category);
335 surf_action_free(&action);
343 static void im_net_action_cancel(surf_action_t action)
345 surf_network_model->action_state_set(action, SURF_ACTION_FAILED);
347 xbt_swag_remove(action, im_net_modified_set);
348 // remove action from the heap
349 heap_remove((surf_action_network_CM02_im_t) action);
352 void im_net_action_recycle(surf_action_t action)
357 #ifdef HAVE_LATENCY_BOUND_TRACKING
358 int im_net_get_link_latency_limited(surf_action_t action)
360 return action->latency_limited;
364 double im_net_action_get_remains(surf_action_t action)
366 /* update remains before return it */
367 update_action_remaining(surf_get_clock());
368 return action->remains;
371 static void update_action_remaining(double now){
372 surf_action_network_CM02_im_t action = NULL;
375 xbt_swag_foreach(action, im_net_modified_set) {
377 if(action->suspended != 0){
381 delta = now - action->last_update;
383 double_update(&(action->generic_action.remains),
384 lmm_variable_getvalue(action->variable) * delta);
386 if (action->generic_action.max_duration != NO_MAX_DURATION)
387 double_update(&(action->generic_action.max_duration), delta);
389 if ((action->generic_action.remains <= 0) &&
390 (lmm_get_variable_weight(action->variable) > 0)) {
391 action->generic_action.finish = surf_get_clock();
392 surf_network_model->action_state_set((surf_action_t) action,
395 } else if ((action->generic_action.max_duration != NO_MAX_DURATION)
396 && (action->generic_action.max_duration <= 0)) {
397 action->generic_action.finish = surf_get_clock();
398 surf_network_model->action_state_set((surf_action_t) action,
403 action->last_update = now;
407 static double im_net_share_resources(double now)
409 surf_action_network_CM02_im_t action = NULL;
413 XBT_DEBUG("Before share resources, the size of modified actions set is %d", xbt_swag_size(im_net_modified_set));
414 update_action_remaining(now);
416 lmm_solve(network_im_maxmin_system);
418 XBT_DEBUG("After share resources, The size of modified actions set is %d", xbt_swag_size(im_net_modified_set));
420 xbt_swag_foreach(action, im_net_modified_set) {
421 if (GENERIC_ACTION(action).state_set != surf_network_model->states.running_action_set){
425 /* bogus priority, skip it */
426 if (GENERIC_ACTION(action).priority <= 0){
431 value = lmm_variable_getvalue(action->variable);
433 if (GENERIC_ACTION(action).remains > 0) {
434 value = GENERIC_ACTION(action).remains / value;
442 if ((GENERIC_ACTION(action).max_duration != NO_MAX_DURATION)
444 || GENERIC_ACTION(action).start +
445 GENERIC_ACTION(action).max_duration < min)){
446 min = GENERIC_ACTION(action).start +
447 GENERIC_ACTION(action).max_duration;
450 XBT_DEBUG("Action(%p) Start %lf Finish %lf Max_duration %lf", action,
451 GENERIC_ACTION(action).start, now + value,
452 GENERIC_ACTION(action).max_duration);
456 if (action->index_heap >= 0) {
457 heap_remove((surf_action_network_CM02_im_t) action);
461 heap_insert((surf_action_network_CM02_im_t) action, min, NORMAL);
462 XBT_DEBUG("Insert at heap action(%p) min %lf now %lf", action, min, now);
466 //hereafter must have already the min value for this resource model
467 if(xbt_heap_size(im_net_action_heap) > 0 ){
468 min = xbt_heap_maxkey(im_net_action_heap) - now ;
473 XBT_DEBUG("The minimum with the HEAP %lf", min);
479 static void im_net_update_actions_state(double now, double delta)
481 surf_action_network_CM02_im_t action = NULL;
483 while ((xbt_heap_size(im_net_action_heap) > 0)
484 && (double_equals(xbt_heap_maxkey(im_net_action_heap), now))) {
485 action = xbt_heap_pop(im_net_action_heap);
486 XBT_DEBUG("Action %p: finish", action);
487 GENERIC_ACTION(action).finish = surf_get_clock();
489 // if I am wearing a latency heat
490 if( action->hat == LATENCY){
491 lmm_update_variable_weight(network_im_maxmin_system, action->variable,
494 action->last_update = surf_get_clock();
496 XBT_DEBUG("Action (%p) is not limited by latency anymore", action);
497 #ifdef HAVE_LATENCY_BOUND_TRACKING
498 GENERIC_ACTION(action).latency_limited = 0;
501 // if I am wearing a max_duration or normal hat
502 }else if( action->hat == MAX_DURATION || action->hat == NORMAL ){
503 // no need to communicate anymore
504 // assume that flows that reached max_duration have remaining of 0
505 GENERIC_ACTION(action).remains = 0;
506 action->generic_action.finish = surf_get_clock();
507 surf_network_model->action_state_set((surf_action_t) action,
515 static void im_net_update_resource_state(void *id,
516 tmgr_trace_event_t event_type,
517 double value, double date)
519 link_CM02_im_t nw_link = id;
520 /* printf("[" "%lg" "] Asking to update network card \"%s\" with value " */
521 /* "%lg" " for event %p\n", surf_get_clock(), nw_link->name, */
522 /* value, event_type); */
524 if (event_type == nw_link->lmm_resource.power.event) {
526 sg_weight_S_parameter / value - sg_weight_S_parameter /
527 (nw_link->lmm_resource.power.peak *
528 nw_link->lmm_resource.power.scale);
529 lmm_variable_t var = NULL;
530 lmm_element_t elem = NULL;
531 surf_action_network_CM02_im_t action = NULL;
533 nw_link->lmm_resource.power.peak = value;
534 lmm_update_constraint_bound(network_im_maxmin_system,
535 nw_link->lmm_resource.constraint,
536 sg_bandwidth_factor *
537 (nw_link->lmm_resource.power.peak *
538 nw_link->lmm_resource.power.scale));
540 TRACE_surf_link_set_bandwidth(date, (char *)(((nw_link->lmm_resource).generic_resource).name),
541 sg_bandwidth_factor *
542 (nw_link->lmm_resource.power.peak *
543 nw_link->lmm_resource.power.scale));
545 if (sg_weight_S_parameter > 0) {
546 while ((var = lmm_get_var_from_cnst
547 (network_im_maxmin_system, nw_link->lmm_resource.constraint,
549 action = lmm_variable_id(var);
550 action->weight += delta;
551 if (!(action->suspended))
552 lmm_update_variable_weight(network_im_maxmin_system,
553 action->variable, action->weight);
556 if (tmgr_trace_event_free(event_type))
557 nw_link->lmm_resource.power.event = NULL;
558 } else if (event_type == nw_link->lat_event) {
559 double delta = value - nw_link->lat_current;
560 lmm_variable_t var = NULL;
561 lmm_element_t elem = NULL;
562 surf_action_network_CM02_im_t action = NULL;
564 nw_link->lat_current = value;
565 while ((var = lmm_get_var_from_cnst
566 (network_im_maxmin_system, nw_link->lmm_resource.constraint,
568 action = lmm_variable_id(var);
569 action->lat_current += delta;
570 action->weight += delta;
571 if (action->rate < 0)
572 lmm_update_variable_bound(network_im_maxmin_system, action->variable,
573 sg_tcp_gamma / (2.0 *
574 action->lat_current));
576 lmm_update_variable_bound(network_im_maxmin_system, action->variable,
578 sg_tcp_gamma / (2.0 *
579 action->lat_current)));
581 if (action->rate < sg_tcp_gamma / (2.0 * action->lat_current)) {
582 XBT_INFO("Flow is limited BYBANDWIDTH");
584 XBT_INFO("Flow is limited BYLATENCY, latency of flow is %f",
585 action->lat_current);
588 if (!(action->suspended))
589 lmm_update_variable_weight(network_im_maxmin_system, action->variable,
593 if (tmgr_trace_event_free(event_type))
594 nw_link->lat_event = NULL;
595 } else if (event_type == nw_link->lmm_resource.state_event) {
597 nw_link->lmm_resource.state_current = SURF_RESOURCE_ON;
599 lmm_constraint_t cnst = nw_link->lmm_resource.constraint;
600 lmm_variable_t var = NULL;
601 lmm_element_t elem = NULL;
603 nw_link->lmm_resource.state_current = SURF_RESOURCE_OFF;
604 while ((var = lmm_get_var_from_cnst
605 (network_im_maxmin_system, cnst, &elem))) {
606 surf_action_t action = lmm_variable_id(var);
608 if (surf_action_state_get(action) == SURF_ACTION_RUNNING ||
609 surf_action_state_get(action) == SURF_ACTION_READY) {
610 action->finish = date;
611 surf_network_model->action_state_set(action, SURF_ACTION_FAILED);
615 if (tmgr_trace_event_free(event_type))
616 nw_link->lmm_resource.state_event = NULL;
618 XBT_CRITICAL("Unknown event ! \n");
622 XBT_DEBUG("There were a resource state event, need to update actions related to the constraint (%p)", nw_link->lmm_resource.constraint);
627 static surf_action_t im_net_communicate(const char *src_name,
628 const char *dst_name, double size,
634 surf_action_network_CM02_im_t action = NULL;
635 double bandwidth_bound;
636 /* LARGE PLATFORMS HACK:
637 Add a link_CM02_im_t *link and a int link_nb to network_card_CM02_im_t. It will represent local links for this node
638 Use the cluster_id for ->id */
640 xbt_dynar_t back_route = NULL;
641 int constraints_per_variable = 0;
642 // I will need this route for some time so let's call get_route_no_cleanup
643 xbt_dynar_t route = global_routing->get_route_no_cleanup(src_name, dst_name);
646 if (sg_network_fullduplex == 1) {
647 back_route = global_routing->get_route(dst_name, src_name);
650 /* LARGE PLATFORMS HACK:
651 total_route_size = route_size + src->link_nb + dst->nb */
653 XBT_IN("(%s,%s,%g,%g)", src_name, dst_name, size, rate);
654 /* LARGE PLATFORMS HACK:
655 assert on total_route_size */
656 xbt_assert(xbt_dynar_length(route),
657 "You're trying to send data from %s to %s but there is no connection between these two hosts.",
660 xbt_dynar_foreach(route, i, link) {
661 if (link->lmm_resource.state_current == SURF_RESOURCE_OFF) {
667 surf_action_new(sizeof(s_surf_action_network_CM02_im_t), size,
668 surf_network_model, failed);
671 #ifdef HAVE_LATENCY_BOUND_TRACKING
672 (action->generic_action).latency_limited = 0;
675 xbt_swag_insert(action, action->generic_action.state_set);
677 action->index_heap = -1;
678 action->latency = 0.0;
679 action->weight = 0.0;
680 action->last_update = surf_get_clock();
682 bandwidth_bound = -1.0;
683 xbt_dynar_foreach(route, i, link) {
684 action->latency += link->lat_current;
687 sg_weight_S_parameter /
688 (link->lmm_resource.power.peak * link->lmm_resource.power.scale);
689 if (bandwidth_bound < 0.0)
691 (*im_bandwidth_factor_callback) (size) *
692 (link->lmm_resource.power.peak * link->lmm_resource.power.scale);
696 (*im_bandwidth_factor_callback) (size) *
697 (link->lmm_resource.power.peak *
698 link->lmm_resource.power.scale));
700 /* LARGE PLATFORMS HACK:
701 Add src->link and dst->link latencies */
702 action->lat_current = action->latency;
703 action->latency *= (*im_latency_factor_callback) (size);
705 (*im_bandwidth_constraint_callback) (action->rate, bandwidth_bound,
708 /* LARGE PLATFORMS HACK:
709 lmm_variable_new(..., total_route_size) */
710 if (back_route != NULL) {
711 constraints_per_variable =
712 xbt_dynar_length(route) + xbt_dynar_length(back_route);
714 constraints_per_variable = xbt_dynar_length(route);
717 if (action->latency > 0){
719 lmm_variable_new(network_im_maxmin_system, action, 0.0, -1.0,
720 constraints_per_variable);
721 // add to the heap the event when the latency is payed
722 XBT_DEBUG("Added action (%p) one latency event at date %f", action, action->latency + action->last_update);
723 heap_insert(action, action->latency + action->last_update, LATENCY);
724 #ifdef HAVE_LATENCY_BOUND_TRACKING
725 (action->generic_action).latency_limited = 1;
730 lmm_variable_new(network_im_maxmin_system, action, 1.0, -1.0,
731 constraints_per_variable);
733 if (action->rate < 0) {
734 if (action->lat_current > 0)
735 lmm_update_variable_bound(network_im_maxmin_system, action->variable,
736 sg_tcp_gamma / (2.0 *
737 action->lat_current));
739 lmm_update_variable_bound(network_im_maxmin_system, action->variable,
742 if (action->lat_current > 0)
743 lmm_update_variable_bound(network_im_maxmin_system, action->variable,
745 sg_tcp_gamma / (2.0 *
746 action->lat_current)));
748 lmm_update_variable_bound(network_im_maxmin_system, action->variable,
752 xbt_dynar_foreach(route, i, link) {
753 lmm_expand(network_im_maxmin_system, link->lmm_resource.constraint,
754 action->variable, 1.0);
757 if (sg_network_fullduplex == 1) {
758 XBT_DEBUG("Fullduplex active adding backward flow using 5%c", '%');
759 xbt_dynar_foreach(back_route, i, link) {
760 lmm_expand(network_im_maxmin_system, link->lmm_resource.constraint,
761 action->variable, .05);
765 /* LARGE PLATFORMS HACK:
766 expand also with src->link and dst->link */
768 if (TRACE_is_enabled()) {
769 action->src_name = xbt_strdup(src_name);
770 action->dst_name = xbt_strdup(dst_name);
772 action->src_name = action->dst_name = NULL;
776 xbt_dynar_free(&route);
779 return (surf_action_t) action;
782 static xbt_dynar_t im_net_get_route(const char *src, const char *dst)
784 return global_routing->get_route(src, dst);
787 static double im_net_get_link_bandwidth(const void *link)
789 surf_resource_lmm_t lmm = (surf_resource_lmm_t) link;
790 return lmm->power.peak * lmm->power.scale;
793 static double im_net_get_link_latency(const void *link)
795 return ((link_CM02_im_t) link)->lat_current;
798 static int im_net_link_shared(const void *link)
801 lmm_constraint_is_shared(((surf_resource_lmm_t) link)->constraint);
804 static void im_net_action_suspend(surf_action_t action)
806 ((surf_action_network_CM02_im_t) action)->suspended = 1;
807 lmm_update_variable_weight(network_im_maxmin_system,
808 ((surf_action_network_CM02_im_t)
809 action)->variable, 0.0);
811 // remove action from the heap
812 heap_remove((surf_action_network_CM02_im_t) action);
815 static void im_net_action_resume(surf_action_t action)
817 if (((surf_action_network_CM02_im_t) action)->suspended) {
818 lmm_update_variable_weight(network_im_maxmin_system,
819 ((surf_action_network_CM02_im_t)
821 ((surf_action_network_CM02_im_t)
823 ((surf_action_network_CM02_im_t) action)->suspended = 0;
824 // remove action from the heap
825 heap_remove((surf_action_network_CM02_im_t) action);
829 static int im_net_action_is_suspended(surf_action_t action)
831 return ((surf_action_network_CM02_im_t) action)->suspended;
834 void im_net_action_set_max_duration(surf_action_t action, double duration)
836 action->max_duration = duration;
837 // remove action from the heap
838 heap_remove((surf_action_network_CM02_im_t) action);
842 static void im_net_finalize(void)
844 surf_model_exit(surf_network_model);
845 surf_network_model = NULL;
847 global_routing->finalize();
849 lmm_system_free(network_im_maxmin_system);
850 network_im_maxmin_system = NULL;
852 xbt_heap_free(im_net_action_heap);
853 xbt_swag_free(im_net_modified_set);
857 static void im_surf_network_model_init_internal(void)
859 s_surf_action_network_CM02_im_t comm;
861 surf_network_model = surf_model_init();
863 surf_network_model->name = "network";
864 surf_network_model->action_unref = im_net_action_unref;
865 surf_network_model->action_cancel = im_net_action_cancel;
866 surf_network_model->action_recycle = im_net_action_recycle;
867 surf_network_model->get_remains = im_net_action_get_remains;
868 #ifdef HAVE_LATENCY_BOUND_TRACKING
869 surf_network_model->get_latency_limited = im_net_get_link_latency_limited;
872 surf_network_model->model_private->resource_used = im_net_resource_used;
873 surf_network_model->model_private->share_resources = im_net_share_resources;
874 surf_network_model->model_private->update_actions_state =
875 im_net_update_actions_state;
876 surf_network_model->model_private->update_resource_state =
877 im_net_update_resource_state;
878 surf_network_model->model_private->finalize = im_net_finalize;
880 surf_network_model->suspend = im_net_action_suspend;
881 surf_network_model->resume = im_net_action_resume;
882 surf_network_model->is_suspended = im_net_action_is_suspended;
883 surf_cpu_model->set_max_duration = im_net_action_set_max_duration;
885 surf_network_model->extension.network.communicate = im_net_communicate;
886 surf_network_model->extension.network.get_route = im_net_get_route;
887 surf_network_model->extension.network.get_link_bandwidth =
888 im_net_get_link_bandwidth;
889 surf_network_model->extension.network.get_link_latency =
890 im_net_get_link_latency;
891 surf_network_model->extension.network.link_shared = im_net_link_shared;
892 surf_network_model->extension.network.add_traces = im_net_add_traces;
893 surf_network_model->extension.network.create_resource =
894 im_net_create_resource;
897 if (!network_im_maxmin_system){
898 sg_maxmin_selective_update = 1;
899 network_im_maxmin_system = lmm_system_new();
901 im_net_action_heap = xbt_heap_new(8,NULL);
903 xbt_heap_set_update_callback(im_net_action_heap, im_net_action_update_index_heap);
905 routing_model_create(sizeof(link_CM02_im_t),
906 im_net_create_resource(xbt_strdup("__loopback__"),
907 498000000, NULL, 0.000015, NULL,
908 SURF_RESOURCE_ON, NULL,
909 SURF_LINK_FATPIPE, NULL),
910 im_net_get_link_latency);
911 im_net_modified_set =
912 xbt_swag_new(xbt_swag_offset(comm, action_list_hookup));
913 keep_track = im_net_modified_set;
918 /************************************************************************/
919 /* New model based on optimizations discussed during this thesis */
920 /************************************************************************/
921 void im_surf_network_model_init_LegrandVelho(const char *filename)
924 if (surf_network_model)
926 im_surf_network_model_init_internal();
927 im_net_define_callbacks(filename);
928 xbt_dynar_push(model_list, &surf_network_model);
929 network_im_solve = lmm_solve;
931 xbt_cfg_setdefault_double(_surf_cfg_set, "network/latency_factor", 10.4);
932 xbt_cfg_setdefault_double(_surf_cfg_set, "network/bandwidth_factor",
934 xbt_cfg_setdefault_double(_surf_cfg_set, "network/weight_S", 8775);
936 update_model_description(surf_network_model_description,
937 "LV08", surf_network_model);