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)
193 if(struct_lnk->V_policy_initial_link == SURF_LINK_FULLDUPLEX)
195 im_net_create_resource(bprintf("%s_UP",struct_lnk->V_link_id), struct_lnk->V_link_bandwidth, struct_lnk->V_link_bandwidth_file,
196 struct_lnk->V_link_latency, struct_lnk->V_link_latency_file, struct_lnk->V_link_state, struct_lnk->V_link_state_file,
197 struct_lnk->V_policy_initial_link, xbt_dict_new());
198 im_net_create_resource(bprintf("%s_DOWN",struct_lnk->V_link_id), struct_lnk->V_link_bandwidth, struct_lnk->V_link_bandwidth_file,
199 struct_lnk->V_link_latency, struct_lnk->V_link_latency_file, struct_lnk->V_link_state, struct_lnk->V_link_state_file,
200 struct_lnk->V_policy_initial_link, xbt_dict_new());
204 im_net_create_resource(xbt_strdup(struct_lnk->V_link_id), struct_lnk->V_link_bandwidth, struct_lnk->V_link_bandwidth_file,
205 struct_lnk->V_link_latency, struct_lnk->V_link_latency_file, struct_lnk->V_link_state, struct_lnk->V_link_state_file,
206 struct_lnk->V_policy_initial_link, xbt_dict_new());
210 static void im_net_add_traces(void)
212 xbt_dict_cursor_t cursor = NULL;
213 char *trace_name, *elm;
215 static int called = 0;
220 /* connect all traces relative to network */
221 xbt_dict_foreach(trace_connect_list_link_avail, cursor, trace_name, elm) {
222 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
223 link_CM02_im_t link =
224 xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL);
226 xbt_assert(link, "Cannot connect trace %s to link %s: link undefined",
229 "Cannot connect trace %s to link %s: trace undefined",
232 link->lmm_resource.state_event =
233 tmgr_history_add_trace(history, trace, 0.0, 0, link);
236 xbt_dict_foreach(trace_connect_list_bandwidth, cursor, trace_name, elm) {
237 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
238 link_CM02_im_t link =
239 xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL);
241 xbt_assert(link, "Cannot connect trace %s to link %s: link undefined",
244 "Cannot connect trace %s to link %s: trace undefined",
247 link->lmm_resource.power.event =
248 tmgr_history_add_trace(history, trace, 0.0, 0, link);
251 xbt_dict_foreach(trace_connect_list_latency, cursor, trace_name, elm) {
252 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
253 link_CM02_im_t link =
254 xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL);
256 xbt_assert(link, "Cannot connect trace %s to link %s: link undefined",
259 "Cannot connect trace %s to link %s: trace undefined",
262 link->lat_event = tmgr_history_add_trace(history, trace, 0.0, 0, link);
266 static void im_net_define_callbacks(const char *file)
268 /* Figuring out the network links */
269 surfxml_add_callback(STag_surfxml_link_cb_list, &im_net_parse_link_init);
270 surfxml_add_callback(ETag_surfxml_platform_cb_list, &im_net_add_traces);
273 static int im_net_resource_used(void *resource_id)
275 return lmm_constraint_used(network_im_maxmin_system,
276 ((surf_resource_lmm_t)
277 resource_id)->constraint);
280 static int im_net_action_unref(surf_action_t action)
283 if (!action->refcount) {
284 xbt_swag_remove(action, action->state_set);
285 if (((surf_action_network_CM02_im_t) action)->variable){
286 lmm_variable_free(network_im_maxmin_system,
287 ((surf_action_network_CM02_im_t) action)->variable);
289 // remove action from the heap
290 heap_remove((surf_action_network_CM02_im_t) action);
292 xbt_swag_remove(action, im_net_modified_set);
294 xbt_free(((surf_action_network_CM02_im_t) action)->src_name);
295 xbt_free(((surf_action_network_CM02_im_t) action)->dst_name);
296 if (action->category)
297 xbt_free(action->category);
299 surf_action_free(&action);
307 static void im_net_action_cancel(surf_action_t action)
309 surf_network_model->action_state_set(action, SURF_ACTION_FAILED);
311 xbt_swag_remove(action, im_net_modified_set);
312 // remove action from the heap
313 heap_remove((surf_action_network_CM02_im_t) action);
316 void im_net_action_recycle(surf_action_t action)
321 #ifdef HAVE_LATENCY_BOUND_TRACKING
322 int im_net_get_link_latency_limited(surf_action_t action)
324 return action->latency_limited;
328 double im_net_action_get_remains(surf_action_t action)
330 /* update remains before return it */
331 update_action_remaining(surf_get_clock());
332 return action->remains;
335 static void update_action_remaining(double now){
336 surf_action_network_CM02_im_t action = NULL;
339 xbt_swag_foreach(action, im_net_modified_set) {
341 if(action->suspended != 0){
345 delta = now - action->last_update;
347 double_update(&(action->generic_action.remains),
348 lmm_variable_getvalue(action->variable) * delta);
350 if (action->generic_action.max_duration != NO_MAX_DURATION)
351 double_update(&(action->generic_action.max_duration), delta);
353 if ((action->generic_action.remains <= 0) &&
354 (lmm_get_variable_weight(action->variable) > 0)) {
355 action->generic_action.finish = surf_get_clock();
356 surf_network_model->action_state_set((surf_action_t) action,
359 } else if ((action->generic_action.max_duration != NO_MAX_DURATION)
360 && (action->generic_action.max_duration <= 0)) {
361 action->generic_action.finish = surf_get_clock();
362 surf_network_model->action_state_set((surf_action_t) action,
367 action->last_update = now;
371 static double im_net_share_resources(double now)
373 surf_action_network_CM02_im_t action = NULL;
377 XBT_DEBUG("Before share resources, the size of modified actions set is %d", xbt_swag_size(im_net_modified_set));
378 update_action_remaining(now);
380 keep_track = im_net_modified_set;
381 lmm_solve(network_im_maxmin_system);
384 XBT_DEBUG("After share resources, The size of modified actions set is %d", xbt_swag_size(im_net_modified_set));
386 xbt_swag_foreach(action, im_net_modified_set) {
387 if (GENERIC_ACTION(action).state_set != surf_network_model->states.running_action_set){
391 /* bogus priority, skip it */
392 if (GENERIC_ACTION(action).priority <= 0){
397 value = lmm_variable_getvalue(action->variable);
399 if (GENERIC_ACTION(action).remains > 0) {
400 value = GENERIC_ACTION(action).remains / value;
408 if ((GENERIC_ACTION(action).max_duration != NO_MAX_DURATION)
410 || GENERIC_ACTION(action).start +
411 GENERIC_ACTION(action).max_duration < min)){
412 min = GENERIC_ACTION(action).start +
413 GENERIC_ACTION(action).max_duration;
416 XBT_DEBUG("Action(%p) Start %lf Finish %lf Max_duration %lf", action,
417 GENERIC_ACTION(action).start, now + value,
418 GENERIC_ACTION(action).max_duration);
422 if (action->index_heap >= 0) {
423 heap_remove((surf_action_network_CM02_im_t) action);
427 heap_insert((surf_action_network_CM02_im_t) action, min, NORMAL);
428 XBT_DEBUG("Insert at heap action(%p) min %lf now %lf", action, min, now);
432 //hereafter must have already the min value for this resource model
433 if(xbt_heap_size(im_net_action_heap) > 0 ){
434 min = xbt_heap_maxkey(im_net_action_heap) - now ;
439 XBT_DEBUG("The minimum with the HEAP %lf", min);
445 static void im_net_update_actions_state(double now, double delta)
447 surf_action_network_CM02_im_t action = NULL;
449 while ((xbt_heap_size(im_net_action_heap) > 0)
450 && (double_equals(xbt_heap_maxkey(im_net_action_heap), now))) {
451 action = xbt_heap_pop(im_net_action_heap);
452 XBT_DEBUG("Action %p: finish", action);
453 GENERIC_ACTION(action).finish = surf_get_clock();
455 // if I am wearing a latency heat
456 if( action->hat == LATENCY){
457 lmm_update_variable_weight(network_im_maxmin_system, action->variable,
460 action->last_update = surf_get_clock();
462 XBT_DEBUG("Action (%p) is not limited by latency anymore", action);
463 #ifdef HAVE_LATENCY_BOUND_TRACKING
464 GENERIC_ACTION(action).latency_limited = 0;
467 // if I am wearing a max_duration or normal hat
468 }else if( action->hat == MAX_DURATION || action->hat == NORMAL ){
469 // no need to communicate anymore
470 // assume that flows that reached max_duration have remaining of 0
471 GENERIC_ACTION(action).remains = 0;
472 action->generic_action.finish = surf_get_clock();
473 surf_network_model->action_state_set((surf_action_t) action,
481 static void im_net_update_resource_state(void *id,
482 tmgr_trace_event_t event_type,
483 double value, double date)
485 link_CM02_im_t nw_link = id;
486 /* printf("[" "%lg" "] Asking to update network card \"%s\" with value " */
487 /* "%lg" " for event %p\n", surf_get_clock(), nw_link->name, */
488 /* value, event_type); */
490 if (event_type == nw_link->lmm_resource.power.event) {
492 sg_weight_S_parameter / value - sg_weight_S_parameter /
493 (nw_link->lmm_resource.power.peak *
494 nw_link->lmm_resource.power.scale);
495 lmm_variable_t var = NULL;
496 lmm_element_t elem = NULL;
497 surf_action_network_CM02_im_t action = NULL;
499 nw_link->lmm_resource.power.peak = value;
500 lmm_update_constraint_bound(network_im_maxmin_system,
501 nw_link->lmm_resource.constraint,
502 sg_bandwidth_factor *
503 (nw_link->lmm_resource.power.peak *
504 nw_link->lmm_resource.power.scale));
506 TRACE_surf_link_set_bandwidth(date, (char *)(((nw_link->lmm_resource).generic_resource).name),
507 sg_bandwidth_factor *
508 (nw_link->lmm_resource.power.peak *
509 nw_link->lmm_resource.power.scale));
511 if (sg_weight_S_parameter > 0) {
512 while ((var = lmm_get_var_from_cnst
513 (network_im_maxmin_system, nw_link->lmm_resource.constraint,
515 action = lmm_variable_id(var);
516 action->weight += delta;
517 if (!(action->suspended))
518 lmm_update_variable_weight(network_im_maxmin_system,
519 action->variable, action->weight);
522 if (tmgr_trace_event_free(event_type))
523 nw_link->lmm_resource.power.event = NULL;
524 } else if (event_type == nw_link->lat_event) {
525 double delta = value - nw_link->lat_current;
526 lmm_variable_t var = NULL;
527 lmm_element_t elem = NULL;
528 surf_action_network_CM02_im_t action = NULL;
530 nw_link->lat_current = value;
531 while ((var = lmm_get_var_from_cnst
532 (network_im_maxmin_system, nw_link->lmm_resource.constraint,
534 action = lmm_variable_id(var);
535 action->lat_current += delta;
536 action->weight += delta;
537 if (action->rate < 0)
538 lmm_update_variable_bound(network_im_maxmin_system, action->variable,
539 sg_tcp_gamma / (2.0 *
540 action->lat_current));
542 lmm_update_variable_bound(network_im_maxmin_system, action->variable,
544 sg_tcp_gamma / (2.0 *
545 action->lat_current)));
547 if (action->rate < sg_tcp_gamma / (2.0 * action->lat_current)) {
548 XBT_INFO("Flow is limited BYBANDWIDTH");
550 XBT_INFO("Flow is limited BYLATENCY, latency of flow is %f",
551 action->lat_current);
554 if (!(action->suspended))
555 lmm_update_variable_weight(network_im_maxmin_system, action->variable,
559 if (tmgr_trace_event_free(event_type))
560 nw_link->lat_event = NULL;
561 } else if (event_type == nw_link->lmm_resource.state_event) {
563 nw_link->lmm_resource.state_current = SURF_RESOURCE_ON;
565 lmm_constraint_t cnst = nw_link->lmm_resource.constraint;
566 lmm_variable_t var = NULL;
567 lmm_element_t elem = NULL;
569 nw_link->lmm_resource.state_current = SURF_RESOURCE_OFF;
570 while ((var = lmm_get_var_from_cnst
571 (network_im_maxmin_system, cnst, &elem))) {
572 surf_action_t action = lmm_variable_id(var);
574 if (surf_action_state_get(action) == SURF_ACTION_RUNNING ||
575 surf_action_state_get(action) == SURF_ACTION_READY) {
576 action->finish = date;
577 surf_network_model->action_state_set(action, SURF_ACTION_FAILED);
581 if (tmgr_trace_event_free(event_type))
582 nw_link->lmm_resource.state_event = NULL;
584 XBT_CRITICAL("Unknown event ! \n");
588 XBT_DEBUG("There were a resource state event, need to update actions related to the constraint (%p)", nw_link->lmm_resource.constraint);
593 static surf_action_t im_net_communicate(const char *src_name,
594 const char *dst_name, double size,
600 surf_action_network_CM02_im_t action = NULL;
601 double bandwidth_bound;
602 /* LARGE PLATFORMS HACK:
603 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
604 Use the cluster_id for ->id */
606 xbt_dynar_t back_route = NULL;
607 int constraints_per_variable = 0;
608 // I will need this route for some time so let's call get_route_no_cleanup
609 xbt_dynar_t route = global_routing->get_route_no_cleanup(src_name, dst_name);
612 if (sg_network_fullduplex == 1) {
613 back_route = global_routing->get_route(dst_name, src_name);
616 /* LARGE PLATFORMS HACK:
617 total_route_size = route_size + src->link_nb + dst->nb */
619 XBT_IN("(%s,%s,%g,%g)", src_name, dst_name, size, rate);
620 /* LARGE PLATFORMS HACK:
621 assert on total_route_size */
622 xbt_assert(xbt_dynar_length(route),
623 "You're trying to send data from %s to %s but there is no connection between these two hosts.",
626 xbt_dynar_foreach(route, i, link) {
627 if (link->lmm_resource.state_current == SURF_RESOURCE_OFF) {
633 surf_action_new(sizeof(s_surf_action_network_CM02_im_t), size,
634 surf_network_model, failed);
637 #ifdef HAVE_LATENCY_BOUND_TRACKING
638 (action->generic_action).latency_limited = 0;
641 xbt_swag_insert(action, action->generic_action.state_set);
643 action->index_heap = -1;
644 action->latency = 0.0;
645 action->weight = 0.0;
646 action->last_update = surf_get_clock();
648 bandwidth_bound = -1.0;
649 xbt_dynar_foreach(route, i, link) {
650 action->latency += link->lat_current;
653 sg_weight_S_parameter /
654 (link->lmm_resource.power.peak * link->lmm_resource.power.scale);
655 if (bandwidth_bound < 0.0)
657 (*im_bandwidth_factor_callback) (size) *
658 (link->lmm_resource.power.peak * link->lmm_resource.power.scale);
662 (*im_bandwidth_factor_callback) (size) *
663 (link->lmm_resource.power.peak *
664 link->lmm_resource.power.scale));
666 /* LARGE PLATFORMS HACK:
667 Add src->link and dst->link latencies */
668 action->lat_current = action->latency;
669 action->latency *= (*im_latency_factor_callback) (size);
671 (*im_bandwidth_constraint_callback) (action->rate, bandwidth_bound,
674 /* LARGE PLATFORMS HACK:
675 lmm_variable_new(..., total_route_size) */
676 if (back_route != NULL) {
677 constraints_per_variable =
678 xbt_dynar_length(route) + xbt_dynar_length(back_route);
680 constraints_per_variable = xbt_dynar_length(route);
683 if (action->latency > 0){
685 lmm_variable_new(network_im_maxmin_system, action, 0.0, -1.0,
686 constraints_per_variable);
687 // add to the heap the event when the latency is payed
688 XBT_DEBUG("Added action (%p) one latency event at date %f", action, action->latency + action->last_update);
689 heap_insert(action, action->latency + action->last_update, LATENCY);
690 #ifdef HAVE_LATENCY_BOUND_TRACKING
691 (action->generic_action).latency_limited = 1;
696 lmm_variable_new(network_im_maxmin_system, action, 1.0, -1.0,
697 constraints_per_variable);
699 if (action->rate < 0) {
700 if (action->lat_current > 0)
701 lmm_update_variable_bound(network_im_maxmin_system, action->variable,
702 sg_tcp_gamma / (2.0 *
703 action->lat_current));
705 lmm_update_variable_bound(network_im_maxmin_system, action->variable,
708 if (action->lat_current > 0)
709 lmm_update_variable_bound(network_im_maxmin_system, action->variable,
711 sg_tcp_gamma / (2.0 *
712 action->lat_current)));
714 lmm_update_variable_bound(network_im_maxmin_system, action->variable,
718 xbt_dynar_foreach(route, i, link) {
719 lmm_expand(network_im_maxmin_system, link->lmm_resource.constraint,
720 action->variable, 1.0);
723 if (sg_network_fullduplex == 1) {
724 XBT_DEBUG("Fullduplex active adding backward flow using 5%c", '%');
725 xbt_dynar_foreach(back_route, i, link) {
726 lmm_expand(network_im_maxmin_system, link->lmm_resource.constraint,
727 action->variable, .05);
731 /* LARGE PLATFORMS HACK:
732 expand also with src->link and dst->link */
734 if (TRACE_is_enabled()) {
735 action->src_name = xbt_strdup(src_name);
736 action->dst_name = xbt_strdup(dst_name);
738 action->src_name = action->dst_name = NULL;
742 xbt_dynar_free(&route);
745 return (surf_action_t) action;
748 static xbt_dynar_t im_net_get_route(const char *src, const char *dst)
750 return global_routing->get_route(src, dst);
753 static double im_net_get_link_bandwidth(const void *link)
755 surf_resource_lmm_t lmm = (surf_resource_lmm_t) link;
756 return lmm->power.peak * lmm->power.scale;
759 static double im_net_get_link_latency(const void *link)
761 return ((link_CM02_im_t) link)->lat_current;
764 static int im_net_link_shared(const void *link)
767 lmm_constraint_is_shared(((surf_resource_lmm_t) link)->constraint);
770 static void im_net_action_suspend(surf_action_t action)
772 ((surf_action_network_CM02_im_t) action)->suspended = 1;
773 lmm_update_variable_weight(network_im_maxmin_system,
774 ((surf_action_network_CM02_im_t)
775 action)->variable, 0.0);
777 // remove action from the heap
778 heap_remove((surf_action_network_CM02_im_t) action);
781 static void im_net_action_resume(surf_action_t action)
783 if (((surf_action_network_CM02_im_t) action)->suspended) {
784 lmm_update_variable_weight(network_im_maxmin_system,
785 ((surf_action_network_CM02_im_t)
787 ((surf_action_network_CM02_im_t)
789 ((surf_action_network_CM02_im_t) action)->suspended = 0;
790 // remove action from the heap
791 heap_remove((surf_action_network_CM02_im_t) action);
795 static int im_net_action_is_suspended(surf_action_t action)
797 return ((surf_action_network_CM02_im_t) action)->suspended;
800 void im_net_action_set_max_duration(surf_action_t action, double duration)
802 action->max_duration = duration;
803 // remove action from the heap
804 heap_remove((surf_action_network_CM02_im_t) action);
808 static void im_net_finalize(void)
810 surf_model_exit(surf_network_model);
811 surf_network_model = NULL;
813 global_routing->finalize();
815 lmm_system_free(network_im_maxmin_system);
816 network_im_maxmin_system = NULL;
818 xbt_heap_free(im_net_action_heap);
819 xbt_swag_free(im_net_modified_set);
823 static void im_surf_network_model_init_internal(void)
825 s_surf_action_network_CM02_im_t comm;
827 surf_network_model = surf_model_init();
829 surf_network_model->name = "network";
830 surf_network_model->action_unref = im_net_action_unref;
831 surf_network_model->action_cancel = im_net_action_cancel;
832 surf_network_model->action_recycle = im_net_action_recycle;
833 surf_network_model->get_remains = im_net_action_get_remains;
834 #ifdef HAVE_LATENCY_BOUND_TRACKING
835 surf_network_model->get_latency_limited = im_net_get_link_latency_limited;
838 surf_network_model->model_private->resource_used = im_net_resource_used;
839 surf_network_model->model_private->share_resources = im_net_share_resources;
840 surf_network_model->model_private->update_actions_state =
841 im_net_update_actions_state;
842 surf_network_model->model_private->update_resource_state =
843 im_net_update_resource_state;
844 surf_network_model->model_private->finalize = im_net_finalize;
846 surf_network_model->suspend = im_net_action_suspend;
847 surf_network_model->resume = im_net_action_resume;
848 surf_network_model->is_suspended = im_net_action_is_suspended;
849 surf_cpu_model->set_max_duration = im_net_action_set_max_duration;
851 surf_network_model->extension.network.communicate = im_net_communicate;
852 surf_network_model->extension.network.get_route = im_net_get_route;
853 surf_network_model->extension.network.get_link_bandwidth =
854 im_net_get_link_bandwidth;
855 surf_network_model->extension.network.get_link_latency =
856 im_net_get_link_latency;
857 surf_network_model->extension.network.link_shared = im_net_link_shared;
858 surf_network_model->extension.network.add_traces = im_net_add_traces;
859 surf_network_model->extension.network.create_resource =
860 im_net_create_resource;
863 if (!network_im_maxmin_system){
864 sg_maxmin_selective_update = 1;
865 network_im_maxmin_system = lmm_system_new();
867 im_net_action_heap = xbt_heap_new(8,NULL);
869 xbt_heap_set_update_callback(im_net_action_heap, im_net_action_update_index_heap);
871 routing_model_create(sizeof(link_CM02_im_t),
872 im_net_create_resource(xbt_strdup("__loopback__"),
873 498000000, NULL, 0.000015, NULL,
874 SURF_RESOURCE_ON, NULL,
875 SURF_LINK_FATPIPE, NULL),
876 im_net_get_link_latency);
877 im_net_modified_set =
878 xbt_swag_new(xbt_swag_offset(comm, action_list_hookup));
883 /************************************************************************/
884 /* New model based on optimizations discussed during this thesis */
885 /************************************************************************/
886 void im_surf_network_model_init_LegrandVelho(const char *filename)
889 if (surf_network_model)
891 im_surf_network_model_init_internal();
892 im_net_define_callbacks(filename);
893 xbt_dynar_push(model_list, &surf_network_model);
894 network_im_solve = lmm_solve;
896 xbt_cfg_setdefault_double(_surf_cfg_set, "network/latency_factor", 10.4);
897 xbt_cfg_setdefault_double(_surf_cfg_set, "network/bandwidth_factor",
899 xbt_cfg_setdefault_double(_surf_cfg_set, "network/weight_S", 8775);
901 update_model_description(surf_network_model_description,
902 "LV08", surf_network_model);