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 link_CM02_im_t im_net_link_new(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_link_new(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_link_new(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_link_new(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_create_resource(char *name,
248 tmgr_trace_t bw_trace,
250 tmgr_trace_t lat_trace,
251 e_surf_resource_state_t
253 tmgr_trace_t state_trace,
254 e_surf_link_sharing_policy_t policy,
255 xbt_dict_t properties)
257 im_net_link_new(name, bw_initial, bw_trace,
258 lat_initial, lat_trace, state_initial, state_trace,
259 policy, xbt_dict_new());
262 static void im_net_add_traces(void)
264 xbt_dict_cursor_t cursor = NULL;
265 char *trace_name, *elm;
267 static int called = 0;
272 /* connect all traces relative to network */
273 xbt_dict_foreach(trace_connect_list_link_avail, cursor, trace_name, elm) {
274 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
275 link_CM02_im_t link =
276 xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL);
278 xbt_assert(link, "Cannot connect trace %s to link %s: link undefined",
281 "Cannot connect trace %s to link %s: trace undefined",
284 link->lmm_resource.state_event =
285 tmgr_history_add_trace(history, trace, 0.0, 0, link);
288 xbt_dict_foreach(trace_connect_list_bandwidth, cursor, trace_name, elm) {
289 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
290 link_CM02_im_t link =
291 xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL);
293 xbt_assert(link, "Cannot connect trace %s to link %s: link undefined",
296 "Cannot connect trace %s to link %s: trace undefined",
299 link->lmm_resource.power.event =
300 tmgr_history_add_trace(history, trace, 0.0, 0, link);
303 xbt_dict_foreach(trace_connect_list_latency, cursor, trace_name, elm) {
304 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
305 link_CM02_im_t link =
306 xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL);
308 xbt_assert(link, "Cannot connect trace %s to link %s: link undefined",
311 "Cannot connect trace %s to link %s: trace undefined",
314 link->lat_event = tmgr_history_add_trace(history, trace, 0.0, 0, link);
318 static void im_net_define_callbacks(const char *file)
320 /* Figuring out the network links */
321 surfxml_add_callback(STag_surfxml_link_cb_list, &im_net_parse_link_init);
322 surfxml_add_callback(ETag_surfxml_platform_cb_list, &im_net_add_traces);
325 static int im_net_resource_used(void *resource_id)
327 return lmm_constraint_used(network_im_maxmin_system,
328 ((surf_resource_lmm_t)
329 resource_id)->constraint);
332 static int im_net_action_unref(surf_action_t action)
335 if (!action->refcount) {
336 xbt_swag_remove(action, action->state_set);
337 if (((surf_action_network_CM02_im_t) action)->variable){
338 lmm_variable_free(network_im_maxmin_system,
339 ((surf_action_network_CM02_im_t) action)->variable);
341 // remove action from the heap
342 heap_remove((surf_action_network_CM02_im_t) action);
344 xbt_swag_remove(action, im_net_modified_set);
346 xbt_free(((surf_action_network_CM02_im_t) action)->src_name);
347 xbt_free(((surf_action_network_CM02_im_t) action)->dst_name);
348 if (action->category)
349 xbt_free(action->category);
351 surf_action_free(&action);
359 static void im_net_action_cancel(surf_action_t action)
361 surf_network_model->action_state_set(action, SURF_ACTION_FAILED);
363 xbt_swag_remove(action, im_net_modified_set);
364 // remove action from the heap
365 heap_remove((surf_action_network_CM02_im_t) action);
368 void im_net_action_recycle(surf_action_t action)
373 #ifdef HAVE_LATENCY_BOUND_TRACKING
374 int im_net_get_link_latency_limited(surf_action_t action)
376 return action->latency_limited;
380 double im_net_action_get_remains(surf_action_t action)
382 /* update remains before return it */
383 update_action_remaining(surf_get_clock());
384 return action->remains;
387 static void update_action_remaining(double now){
388 surf_action_network_CM02_im_t action = NULL;
391 xbt_swag_foreach(action, im_net_modified_set) {
393 if(action->suspended != 0){
397 delta = now - action->last_update;
399 double_update(&(action->generic_action.remains),
400 lmm_variable_getvalue(action->variable) * delta);
402 if (action->generic_action.max_duration != NO_MAX_DURATION)
403 double_update(&(action->generic_action.max_duration), delta);
405 if ((action->generic_action.remains <= 0) &&
406 (lmm_get_variable_weight(action->variable) > 0)) {
407 action->generic_action.finish = surf_get_clock();
408 surf_network_model->action_state_set((surf_action_t) action,
411 } else if ((action->generic_action.max_duration != NO_MAX_DURATION)
412 && (action->generic_action.max_duration <= 0)) {
413 action->generic_action.finish = surf_get_clock();
414 surf_network_model->action_state_set((surf_action_t) action,
419 action->last_update = now;
423 static double im_net_share_resources(double now)
425 surf_action_network_CM02_im_t action = NULL;
429 XBT_DEBUG("Before share resources, the size of modified actions set is %d", xbt_swag_size(im_net_modified_set));
430 update_action_remaining(now);
432 lmm_solve(network_im_maxmin_system);
434 XBT_DEBUG("After share resources, The size of modified actions set is %d", xbt_swag_size(im_net_modified_set));
436 xbt_swag_foreach(action, im_net_modified_set) {
437 if (GENERIC_ACTION(action).state_set != surf_network_model->states.running_action_set){
441 /* bogus priority, skip it */
442 if (GENERIC_ACTION(action).priority <= 0){
447 value = lmm_variable_getvalue(action->variable);
449 if (GENERIC_ACTION(action).remains > 0) {
450 value = GENERIC_ACTION(action).remains / value;
458 if ((GENERIC_ACTION(action).max_duration != NO_MAX_DURATION)
460 || GENERIC_ACTION(action).start +
461 GENERIC_ACTION(action).max_duration < min)){
462 min = GENERIC_ACTION(action).start +
463 GENERIC_ACTION(action).max_duration;
466 XBT_DEBUG("Action(%p) Start %lf Finish %lf Max_duration %lf", action,
467 GENERIC_ACTION(action).start, now + value,
468 GENERIC_ACTION(action).max_duration);
472 if (action->index_heap >= 0) {
473 heap_remove((surf_action_network_CM02_im_t) action);
477 heap_insert((surf_action_network_CM02_im_t) action, min, NORMAL);
478 XBT_DEBUG("Insert at heap action(%p) min %lf now %lf", action, min, now);
482 //hereafter must have already the min value for this resource model
483 if(xbt_heap_size(im_net_action_heap) > 0 ){
484 min = xbt_heap_maxkey(im_net_action_heap) - now ;
489 XBT_DEBUG("The minimum with the HEAP %lf", min);
495 static void im_net_update_actions_state(double now, double delta)
497 surf_action_network_CM02_im_t action = NULL;
499 while ((xbt_heap_size(im_net_action_heap) > 0)
500 && (double_equals(xbt_heap_maxkey(im_net_action_heap), now))) {
501 action = xbt_heap_pop(im_net_action_heap);
502 XBT_DEBUG("Action %p: finish", action);
503 GENERIC_ACTION(action).finish = surf_get_clock();
505 // if I am wearing a latency heat
506 if( action->hat == LATENCY){
507 lmm_update_variable_weight(network_im_maxmin_system, action->variable,
510 action->last_update = surf_get_clock();
512 XBT_DEBUG("Action (%p) is not limited by latency anymore", action);
513 #ifdef HAVE_LATENCY_BOUND_TRACKING
514 GENERIC_ACTION(action).latency_limited = 0;
517 // if I am wearing a max_duration or normal hat
518 }else if( action->hat == MAX_DURATION || action->hat == NORMAL ){
519 // no need to communicate anymore
520 // assume that flows that reached max_duration have remaining of 0
521 GENERIC_ACTION(action).remains = 0;
522 action->generic_action.finish = surf_get_clock();
523 surf_network_model->action_state_set((surf_action_t) action,
531 static void im_net_update_resource_state(void *id,
532 tmgr_trace_event_t event_type,
533 double value, double date)
535 link_CM02_im_t nw_link = id;
536 /* printf("[" "%lg" "] Asking to update network card \"%s\" with value " */
537 /* "%lg" " for event %p\n", surf_get_clock(), nw_link->name, */
538 /* value, event_type); */
540 if (event_type == nw_link->lmm_resource.power.event) {
542 sg_weight_S_parameter / value - sg_weight_S_parameter /
543 (nw_link->lmm_resource.power.peak *
544 nw_link->lmm_resource.power.scale);
545 lmm_variable_t var = NULL;
546 lmm_element_t elem = NULL;
547 surf_action_network_CM02_im_t action = NULL;
549 nw_link->lmm_resource.power.peak = value;
550 lmm_update_constraint_bound(network_im_maxmin_system,
551 nw_link->lmm_resource.constraint,
552 sg_bandwidth_factor *
553 (nw_link->lmm_resource.power.peak *
554 nw_link->lmm_resource.power.scale));
556 TRACE_surf_link_set_bandwidth(date, (char *)(((nw_link->lmm_resource).generic_resource).name),
557 sg_bandwidth_factor *
558 (nw_link->lmm_resource.power.peak *
559 nw_link->lmm_resource.power.scale));
561 if (sg_weight_S_parameter > 0) {
562 while ((var = lmm_get_var_from_cnst
563 (network_im_maxmin_system, nw_link->lmm_resource.constraint,
565 action = lmm_variable_id(var);
566 action->weight += delta;
567 if (!(action->suspended))
568 lmm_update_variable_weight(network_im_maxmin_system,
569 action->variable, action->weight);
572 if (tmgr_trace_event_free(event_type))
573 nw_link->lmm_resource.power.event = NULL;
574 } else if (event_type == nw_link->lat_event) {
575 double delta = value - nw_link->lat_current;
576 lmm_variable_t var = NULL;
577 lmm_element_t elem = NULL;
578 surf_action_network_CM02_im_t action = NULL;
580 nw_link->lat_current = value;
581 while ((var = lmm_get_var_from_cnst
582 (network_im_maxmin_system, nw_link->lmm_resource.constraint,
584 action = lmm_variable_id(var);
585 action->lat_current += delta;
586 action->weight += delta;
587 if (action->rate < 0)
588 lmm_update_variable_bound(network_im_maxmin_system, action->variable,
589 sg_tcp_gamma / (2.0 *
590 action->lat_current));
592 lmm_update_variable_bound(network_im_maxmin_system, action->variable,
594 sg_tcp_gamma / (2.0 *
595 action->lat_current)));
597 if (action->rate < sg_tcp_gamma / (2.0 * action->lat_current)) {
598 XBT_INFO("Flow is limited BYBANDWIDTH");
600 XBT_INFO("Flow is limited BYLATENCY, latency of flow is %f",
601 action->lat_current);
604 if (!(action->suspended))
605 lmm_update_variable_weight(network_im_maxmin_system, action->variable,
609 if (tmgr_trace_event_free(event_type))
610 nw_link->lat_event = NULL;
611 } else if (event_type == nw_link->lmm_resource.state_event) {
613 nw_link->lmm_resource.state_current = SURF_RESOURCE_ON;
615 lmm_constraint_t cnst = nw_link->lmm_resource.constraint;
616 lmm_variable_t var = NULL;
617 lmm_element_t elem = NULL;
619 nw_link->lmm_resource.state_current = SURF_RESOURCE_OFF;
620 while ((var = lmm_get_var_from_cnst
621 (network_im_maxmin_system, cnst, &elem))) {
622 surf_action_t action = lmm_variable_id(var);
624 if (surf_action_state_get(action) == SURF_ACTION_RUNNING ||
625 surf_action_state_get(action) == SURF_ACTION_READY) {
626 action->finish = date;
627 surf_network_model->action_state_set(action, SURF_ACTION_FAILED);
631 if (tmgr_trace_event_free(event_type))
632 nw_link->lmm_resource.state_event = NULL;
634 XBT_CRITICAL("Unknown event ! \n");
638 XBT_DEBUG("There were a resource state event, need to update actions related to the constraint (%p)", nw_link->lmm_resource.constraint);
643 static surf_action_t im_net_communicate(const char *src_name,
644 const char *dst_name, double size,
650 surf_action_network_CM02_im_t action = NULL;
651 double bandwidth_bound;
652 /* LARGE PLATFORMS HACK:
653 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
654 Use the cluster_id for ->id */
656 xbt_dynar_t back_route = NULL;
657 int constraints_per_variable = 0;
658 // I will need this route for some time so let's call get_route_no_cleanup
659 xbt_dynar_t route = global_routing->get_route_no_cleanup(src_name, dst_name);
662 if (sg_network_fullduplex == 1) {
663 back_route = global_routing->get_route(dst_name, src_name);
666 /* LARGE PLATFORMS HACK:
667 total_route_size = route_size + src->link_nb + dst->nb */
669 XBT_IN("(%s,%s,%g,%g)", src_name, dst_name, size, rate);
670 /* LARGE PLATFORMS HACK:
671 assert on total_route_size */
672 xbt_assert(xbt_dynar_length(route),
673 "You're trying to send data from %s to %s but there is no connection between these two hosts.",
676 xbt_dynar_foreach(route, i, link) {
677 if (link->lmm_resource.state_current == SURF_RESOURCE_OFF) {
683 surf_action_new(sizeof(s_surf_action_network_CM02_im_t), size,
684 surf_network_model, failed);
687 #ifdef HAVE_LATENCY_BOUND_TRACKING
688 (action->generic_action).latency_limited = 0;
691 xbt_swag_insert(action, action->generic_action.state_set);
693 action->index_heap = -1;
694 action->latency = 0.0;
695 action->weight = 0.0;
696 action->last_update = surf_get_clock();
698 bandwidth_bound = -1.0;
699 xbt_dynar_foreach(route, i, link) {
700 action->latency += link->lat_current;
703 sg_weight_S_parameter /
704 (link->lmm_resource.power.peak * link->lmm_resource.power.scale);
705 if (bandwidth_bound < 0.0)
707 (*im_bandwidth_factor_callback) (size) *
708 (link->lmm_resource.power.peak * link->lmm_resource.power.scale);
712 (*im_bandwidth_factor_callback) (size) *
713 (link->lmm_resource.power.peak *
714 link->lmm_resource.power.scale));
716 /* LARGE PLATFORMS HACK:
717 Add src->link and dst->link latencies */
718 action->lat_current = action->latency;
719 action->latency *= (*im_latency_factor_callback) (size);
721 (*im_bandwidth_constraint_callback) (action->rate, bandwidth_bound,
724 /* LARGE PLATFORMS HACK:
725 lmm_variable_new(..., total_route_size) */
726 if (back_route != NULL) {
727 constraints_per_variable =
728 xbt_dynar_length(route) + xbt_dynar_length(back_route);
730 constraints_per_variable = xbt_dynar_length(route);
733 if (action->latency > 0){
735 lmm_variable_new(network_im_maxmin_system, action, 0.0, -1.0,
736 constraints_per_variable);
737 // add to the heap the event when the latency is payed
738 XBT_DEBUG("Added action (%p) one latency event at date %f", action, action->latency + action->last_update);
739 heap_insert(action, action->latency + action->last_update, LATENCY);
740 #ifdef HAVE_LATENCY_BOUND_TRACKING
741 (action->generic_action).latency_limited = 1;
746 lmm_variable_new(network_im_maxmin_system, action, 1.0, -1.0,
747 constraints_per_variable);
749 if (action->rate < 0) {
750 if (action->lat_current > 0)
751 lmm_update_variable_bound(network_im_maxmin_system, action->variable,
752 sg_tcp_gamma / (2.0 *
753 action->lat_current));
755 lmm_update_variable_bound(network_im_maxmin_system, action->variable,
758 if (action->lat_current > 0)
759 lmm_update_variable_bound(network_im_maxmin_system, action->variable,
761 sg_tcp_gamma / (2.0 *
762 action->lat_current)));
764 lmm_update_variable_bound(network_im_maxmin_system, action->variable,
768 xbt_dynar_foreach(route, i, link) {
769 lmm_expand(network_im_maxmin_system, link->lmm_resource.constraint,
770 action->variable, 1.0);
773 if (sg_network_fullduplex == 1) {
774 XBT_DEBUG("Fullduplex active adding backward flow using 5%c", '%');
775 xbt_dynar_foreach(back_route, i, link) {
776 lmm_expand(network_im_maxmin_system, link->lmm_resource.constraint,
777 action->variable, .05);
781 /* LARGE PLATFORMS HACK:
782 expand also with src->link and dst->link */
784 if (TRACE_is_enabled()) {
785 action->src_name = xbt_strdup(src_name);
786 action->dst_name = xbt_strdup(dst_name);
788 action->src_name = action->dst_name = NULL;
792 xbt_dynar_free(&route);
795 return (surf_action_t) action;
798 static xbt_dynar_t im_net_get_route(const char *src, const char *dst)
800 return global_routing->get_route(src, dst);
803 static double im_net_get_link_bandwidth(const void *link)
805 surf_resource_lmm_t lmm = (surf_resource_lmm_t) link;
806 return lmm->power.peak * lmm->power.scale;
809 static double im_net_get_link_latency(const void *link)
811 return ((link_CM02_im_t) link)->lat_current;
814 static int im_net_link_shared(const void *link)
817 lmm_constraint_is_shared(((surf_resource_lmm_t) link)->constraint);
820 static void im_net_action_suspend(surf_action_t action)
822 ((surf_action_network_CM02_im_t) action)->suspended = 1;
823 lmm_update_variable_weight(network_im_maxmin_system,
824 ((surf_action_network_CM02_im_t)
825 action)->variable, 0.0);
827 // remove action from the heap
828 heap_remove((surf_action_network_CM02_im_t) action);
831 static void im_net_action_resume(surf_action_t action)
833 if (((surf_action_network_CM02_im_t) action)->suspended) {
834 lmm_update_variable_weight(network_im_maxmin_system,
835 ((surf_action_network_CM02_im_t)
837 ((surf_action_network_CM02_im_t)
839 ((surf_action_network_CM02_im_t) action)->suspended = 0;
840 // remove action from the heap
841 heap_remove((surf_action_network_CM02_im_t) action);
845 static int im_net_action_is_suspended(surf_action_t action)
847 return ((surf_action_network_CM02_im_t) action)->suspended;
850 void im_net_action_set_max_duration(surf_action_t action, double duration)
852 action->max_duration = duration;
853 // remove action from the heap
854 heap_remove((surf_action_network_CM02_im_t) action);
858 static void im_net_finalize(void)
860 surf_model_exit(surf_network_model);
861 surf_network_model = NULL;
863 global_routing->finalize();
865 lmm_system_free(network_im_maxmin_system);
866 network_im_maxmin_system = NULL;
868 xbt_heap_free(im_net_action_heap);
869 xbt_swag_free(im_net_modified_set);
873 static void im_surf_network_model_init_internal(void)
875 s_surf_action_network_CM02_im_t comm;
876 XBT_INFO("You are using the UNSAFE lazy management optimization, I hope you know what you are doing.");
877 XBT_INFO("====> For now this optimization is only available for LV08_im network model.");
879 surf_network_model = surf_model_init();
881 surf_network_model->name = "network";
882 surf_network_model->action_unref = im_net_action_unref;
883 surf_network_model->action_cancel = im_net_action_cancel;
884 surf_network_model->action_recycle = im_net_action_recycle;
885 surf_network_model->get_remains = im_net_action_get_remains;
886 #ifdef HAVE_LATENCY_BOUND_TRACKING
887 surf_network_model->get_latency_limited = im_net_get_link_latency_limited;
890 surf_network_model->model_private->resource_used = im_net_resource_used;
891 surf_network_model->model_private->share_resources = im_net_share_resources;
892 surf_network_model->model_private->update_actions_state =
893 im_net_update_actions_state;
894 surf_network_model->model_private->update_resource_state =
895 im_net_update_resource_state;
896 surf_network_model->model_private->finalize = im_net_finalize;
898 surf_network_model->suspend = im_net_action_suspend;
899 surf_network_model->resume = im_net_action_resume;
900 surf_network_model->is_suspended = im_net_action_is_suspended;
901 surf_cpu_model->set_max_duration = im_net_action_set_max_duration;
903 surf_network_model->extension.network.communicate = im_net_communicate;
904 surf_network_model->extension.network.get_route = im_net_get_route;
905 surf_network_model->extension.network.get_link_bandwidth =
906 im_net_get_link_bandwidth;
907 surf_network_model->extension.network.get_link_latency =
908 im_net_get_link_latency;
909 surf_network_model->extension.network.link_shared = im_net_link_shared;
910 surf_network_model->extension.network.add_traces = im_net_add_traces;
911 surf_network_model->extension.network.create_resource =
912 im_net_create_resource;
915 if (!network_im_maxmin_system){
916 sg_maxmin_selective_update = 1;
917 network_im_maxmin_system = lmm_system_new();
919 im_net_action_heap = xbt_heap_new(8,NULL);
921 xbt_heap_set_update_callback(im_net_action_heap, im_net_action_update_index_heap);
923 routing_model_create(sizeof(link_CM02_im_t), im_net_link_new(xbt_strdup("__loopback__"),
924 498000000, NULL, 0.000015, NULL,
925 SURF_RESOURCE_ON, NULL,
926 SURF_LINK_FATPIPE, NULL),
927 im_net_get_link_latency);
928 im_net_modified_set =
929 xbt_swag_new(xbt_swag_offset(comm, action_list_hookup));
930 keep_track = im_net_modified_set;
935 /************************************************************************/
936 /* New model based on optimizations discussed during this thesis */
937 /************************************************************************/
938 void im_surf_network_model_init_LegrandVelho(const char *filename)
941 if (surf_network_model)
943 im_surf_network_model_init_internal();
944 im_net_define_callbacks(filename);
945 xbt_dynar_push(model_list, &surf_network_model);
946 network_im_solve = lmm_solve;
948 xbt_cfg_setdefault_double(_surf_cfg_set, "network/latency_factor", 10.4);
949 xbt_cfg_setdefault_double(_surf_cfg_set, "network/bandwidth_factor",
951 xbt_cfg_setdefault_double(_surf_cfg_set, "network/weight_S", 8775);
953 update_model_description(surf_network_model_description,
954 "LV08_im", surf_network_model);