X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/f5fd55f293d7e019e8c23e7ff76e2b3743e40cd6..868b3bf7dbd29afa8863377e4eec8305bb2433ba:/src/surf/network_im.c diff --git a/src/surf/network_im.c b/src/surf/network_im.c index 01b323af23..0073e1e727 100644 --- a/src/surf/network_im.c +++ b/src/surf/network_im.c @@ -17,6 +17,8 @@ #include "surf_private.h" #include "xbt/dict.h" #include "maxmin_private.h" +#include "surf/surf_resource_lmm.h" + #undef GENERIC_ACTION #define GENERIC_ACTION(action) action->generic_action @@ -88,7 +90,6 @@ static int im_net_get_link_latency_limited(surf_action_t action); static int im_net_action_is_suspended(surf_action_t action); static double im_net_action_get_remains(surf_action_t action); static void im_net_action_set_max_duration(surf_action_t action, double duration); -static void surf_network_model_init_CM02_im(const char *filename); static void im_net_update_actions_state(double now, double delta); static void update_action_remaining(double now); @@ -150,7 +151,7 @@ static double (*im_bandwidth_constraint_callback) (double, double, double) = &im_constant_bandwidth_constraint; -static link_CM02_im_t im_net_link_new(char *name, +static void* im_net_create_resource(const char *name, double bw_initial, tmgr_trace_t bw_trace, double lat_initial, @@ -170,8 +171,7 @@ static link_CM02_im_t im_net_link_new(char *name, state_initial, state_trace, bw_initial, bw_trace); - xbt_assert1(!xbt_dict_get_or_null - (surf_network_model->resource_set, name), + xbt_assert(!xbt_lib_get_or_null(link_lib, name, SURF_LINK_LEVEL), "Link '%s' declared several times in the platform file.", name); @@ -183,82 +183,32 @@ static link_CM02_im_t im_net_link_new(char *name, if (policy == SURF_LINK_FATPIPE) lmm_constraint_shared(nw_link->lmm_resource.constraint); - xbt_dict_set(surf_network_model->resource_set, name, nw_link, - surf_resource_free); - + xbt_lib_set(link_lib, name, SURF_LINK_LEVEL, nw_link); return nw_link; } -static void im_net_parse_link_init(void) +static void im_net_parse_link_init(sg_platf_link_cbarg_t link) { - char *name_link; - double bw_initial; - tmgr_trace_t bw_trace; - double lat_initial; - tmgr_trace_t lat_trace; - e_surf_resource_state_t state_initial_link = SURF_RESOURCE_ON; - e_surf_link_sharing_policy_t policy_initial_link = SURF_LINK_SHARED; - tmgr_trace_t state_trace; - DEBUG0("link_CM02_im"); - name_link = xbt_strdup(A_surfxml_link_id); - surf_parse_get_double(&bw_initial, A_surfxml_link_bandwidth); - bw_trace = tmgr_trace_new(A_surfxml_link_bandwidth_file); - surf_parse_get_double(&lat_initial, A_surfxml_link_latency); - lat_trace = tmgr_trace_new(A_surfxml_link_latency_file); - - xbt_assert0((A_surfxml_link_state == A_surfxml_link_state_ON) - || (A_surfxml_link_state == - A_surfxml_link_state_OFF), "Invalid state"); - if (A_surfxml_link_state == A_surfxml_link_state_ON) - state_initial_link = SURF_RESOURCE_ON; - else if (A_surfxml_link_state == A_surfxml_link_state_OFF) - state_initial_link = SURF_RESOURCE_OFF; - - if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_SHARED) - policy_initial_link = SURF_LINK_SHARED; - else - { - if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FATPIPE) - policy_initial_link = SURF_LINK_FATPIPE; - else if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FULLDUPLEX) - policy_initial_link = SURF_LINK_FULLDUPLEX; - } - - state_trace = tmgr_trace_new(A_surfxml_link_state_file); - - if(policy_initial_link == SURF_LINK_FULLDUPLEX) + if(link->policy == SURF_LINK_FULLDUPLEX) { - im_net_link_new(bprintf("%s_UP",name_link), bw_initial, bw_trace, - lat_initial, lat_trace, state_initial_link, state_trace, - policy_initial_link, xbt_dict_new()); - im_net_link_new(bprintf("%s_DOWN",name_link), bw_initial, bw_trace, - lat_initial, lat_trace, state_initial_link, state_trace, - policy_initial_link, xbt_dict_new()); + char *name = bprintf("%s_UP",link->id); + im_net_create_resource(name, link->bandwidth, link->bandwidth_trace, + link->latency, link->latency_trace, link->state, link->state_trace, + link->policy, link->properties); + xbt_free(name); + name = bprintf("%s_DOWN",link->id); + im_net_create_resource(name, link->bandwidth, link->bandwidth_trace, + link->latency, link->latency_trace, link->state, link->state_trace, + link->policy, NULL); // FIXME: We need to deep copy the properties or we won't be able to free it + xbt_free(name); } else { - im_net_link_new(name_link, bw_initial, bw_trace, - lat_initial, lat_trace, state_initial_link, state_trace, - policy_initial_link, xbt_dict_new()); + im_net_create_resource(link->id, link->bandwidth, link->bandwidth_trace, + link->latency, link->latency_trace, link->state, link->state_trace, + link->policy, link->properties); } - -} - -static void im_net_create_resource(char *name, - double bw_initial, - tmgr_trace_t bw_trace, - double lat_initial, - tmgr_trace_t lat_trace, - e_surf_resource_state_t - state_initial, - tmgr_trace_t state_trace, - e_surf_link_sharing_policy_t policy, - xbt_dict_t properties) -{ - im_net_link_new(name, bw_initial, bw_trace, - lat_initial, lat_trace, state_initial, state_trace, - policy, xbt_dict_new()); } static void im_net_add_traces(void) @@ -275,11 +225,11 @@ static void im_net_add_traces(void) xbt_dict_foreach(trace_connect_list_link_avail, cursor, trace_name, elm) { tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name); link_CM02_im_t link = - xbt_dict_get_or_null(surf_network_model->resource_set, elm); + xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL); - xbt_assert2(link, "Cannot connect trace %s to link %s: link undefined", + xbt_assert(link, "Cannot connect trace %s to link %s: link undefined", trace_name, elm); - xbt_assert2(trace, + xbt_assert(trace, "Cannot connect trace %s to link %s: trace undefined", trace_name, elm); @@ -290,11 +240,11 @@ static void im_net_add_traces(void) xbt_dict_foreach(trace_connect_list_bandwidth, cursor, trace_name, elm) { tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name); link_CM02_im_t link = - xbt_dict_get_or_null(surf_network_model->resource_set, elm); + xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL); - xbt_assert2(link, "Cannot connect trace %s to link %s: link undefined", + xbt_assert(link, "Cannot connect trace %s to link %s: link undefined", trace_name, elm); - xbt_assert2(trace, + xbt_assert(trace, "Cannot connect trace %s to link %s: trace undefined", trace_name, elm); @@ -305,11 +255,11 @@ static void im_net_add_traces(void) xbt_dict_foreach(trace_connect_list_latency, cursor, trace_name, elm) { tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name); link_CM02_im_t link = - xbt_dict_get_or_null(surf_network_model->resource_set, elm); + xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL); - xbt_assert2(link, "Cannot connect trace %s to link %s: link undefined", + xbt_assert(link, "Cannot connect trace %s to link %s: link undefined", trace_name, elm); - xbt_assert2(trace, + xbt_assert(trace, "Cannot connect trace %s to link %s: trace undefined", trace_name, elm); @@ -317,11 +267,11 @@ static void im_net_add_traces(void) } } -static void im_net_define_callbacks(const char *file) +static void im_net_define_callbacks(void) { /* Figuring out the network links */ - surfxml_add_callback(STag_surfxml_link_cb_list, &im_net_parse_link_init); - surfxml_add_callback(ETag_surfxml_platform_cb_list, &im_net_add_traces); + sg_platf_link_add_cb(im_net_parse_link_init); + sg_platf_postparse_add_cb(im_net_add_traces); } static int im_net_resource_used(void *resource_id) @@ -347,8 +297,7 @@ static int im_net_action_unref(surf_action_t action) #ifdef HAVE_TRACING xbt_free(((surf_action_network_CM02_im_t) action)->src_name); xbt_free(((surf_action_network_CM02_im_t) action)->dst_name); - if (action->category) - xbt_free(action->category); + xbt_free(action->category); #endif surf_action_free(&action); return 1; @@ -367,19 +316,19 @@ static void im_net_action_cancel(surf_action_t action) heap_remove((surf_action_network_CM02_im_t) action); } -void im_net_action_recycle(surf_action_t action) +static void im_net_action_recycle(surf_action_t action) { return; } #ifdef HAVE_LATENCY_BOUND_TRACKING -int im_net_get_link_latency_limited(surf_action_t action) +static int im_net_get_link_latency_limited(surf_action_t action) { return action->latency_limited; } #endif -double im_net_action_get_remains(surf_action_t action) +static double im_net_action_get_remains(surf_action_t action) { /* update remains before return it */ update_action_remaining(surf_get_clock()); @@ -428,12 +377,14 @@ static double im_net_share_resources(double now) double min=-1; double value; - DEBUG1("Before share resources, the size of modified actions set is %d", xbt_swag_size(im_net_modified_set)); + XBT_DEBUG("Before share resources, the size of modified actions set is %d", xbt_swag_size(im_net_modified_set)); update_action_remaining(now); + keep_track = im_net_modified_set; lmm_solve(network_im_maxmin_system); + keep_track = NULL; - DEBUG1("After share resources, The size of modified actions set is %d", xbt_swag_size(im_net_modified_set)); + XBT_DEBUG("After share resources, The size of modified actions set is %d", xbt_swag_size(im_net_modified_set)); xbt_swag_foreach(action, im_net_modified_set) { if (GENERIC_ACTION(action).state_set != surf_network_model->states.running_action_set){ @@ -465,7 +416,7 @@ static double im_net_share_resources(double now) GENERIC_ACTION(action).max_duration; } - DEBUG4("Action(%p) Start %lf Finish %lf Max_duration %lf", action, + XBT_DEBUG("Action(%p) Start %lf Finish %lf Max_duration %lf", action, GENERIC_ACTION(action).start, now + value, GENERIC_ACTION(action).max_duration); @@ -477,7 +428,7 @@ static double im_net_share_resources(double now) if (min != -1) { heap_insert((surf_action_network_CM02_im_t) action, min, NORMAL); - DEBUG3("Insert at heap action(%p) min %lf now %lf", action, min, now); + XBT_DEBUG("Insert at heap action(%p) min %lf now %lf", action, min, now); } } @@ -488,7 +439,7 @@ static double im_net_share_resources(double now) min = -1; } - DEBUG1("The minimum with the HEAP %lf", min); + XBT_DEBUG("The minimum with the HEAP %lf", min); return min; @@ -501,7 +452,7 @@ static void im_net_update_actions_state(double now, double delta) while ((xbt_heap_size(im_net_action_heap) > 0) && (double_equals(xbt_heap_maxkey(im_net_action_heap), now))) { action = xbt_heap_pop(im_net_action_heap); - DEBUG1("Action %p: finish", action); + XBT_DEBUG("Action %p: finish", action); GENERIC_ACTION(action).finish = surf_get_clock(); // if I am wearing a latency heat @@ -511,7 +462,7 @@ static void im_net_update_actions_state(double now, double delta) heap_remove(action); action->last_update = surf_get_clock(); - DEBUG1("Action (%p) is not limited by latency anymore", action); + XBT_DEBUG("Action (%p) is not limited by latency anymore", action); #ifdef HAVE_LATENCY_BOUND_TRACKING GENERIC_ACTION(action).latency_limited = 0; #endif @@ -597,9 +548,9 @@ static void im_net_update_resource_state(void *id, action->lat_current))); if (action->rate < sg_tcp_gamma / (2.0 * action->lat_current)) { - INFO0("Flow is limited BYBANDWIDTH"); + XBT_INFO("Flow is limited BYBANDWIDTH"); } else { - INFO1("Flow is limited BYLATENCY, latency of flow is %f", + XBT_INFO("Flow is limited BYLATENCY, latency of flow is %f", action->lat_current); } } @@ -633,11 +584,11 @@ static void im_net_update_resource_state(void *id, if (tmgr_trace_event_free(event_type)) nw_link->lmm_resource.state_event = NULL; } else { - CRITICAL0("Unknown event ! \n"); + XBT_CRITICAL("Unknown event ! \n"); xbt_abort(); } - DEBUG1("There were a resource state event, need to update actions related to the constraint (%p)", nw_link->lmm_resource.constraint); + XBT_DEBUG("There were a resource state event, need to update actions related to the constraint (%p)", nw_link->lmm_resource.constraint); return; } @@ -657,21 +608,22 @@ static surf_action_t im_net_communicate(const char *src_name, xbt_dynar_t back_route = NULL; int constraints_per_variable = 0; - // I will need this route for some time so let's call get_route_no_cleanup - xbt_dynar_t route = global_routing->get_route_no_cleanup(src_name, dst_name); + // I need to have the forward and backward routes at the same time, so allocate "route". That way, the routing wont clean it up + xbt_dynar_t route=xbt_dynar_new(global_routing->size_of_link,NULL); + routing_get_route_and_latency(src_name, dst_name,&route,NULL); if (sg_network_fullduplex == 1) { - back_route = global_routing->get_route(dst_name, src_name); + routing_get_route_and_latency(dst_name, src_name, &back_route, NULL); } /* LARGE PLATFORMS HACK: total_route_size = route_size + src->link_nb + dst->nb */ - XBT_IN4("(%s,%s,%g,%g)", src_name, dst_name, size, rate); + XBT_IN("(%s,%s,%g,%g)", src_name, dst_name, size, rate); /* LARGE PLATFORMS HACK: assert on total_route_size */ - xbt_assert2(xbt_dynar_length(route), + xbt_assert(xbt_dynar_length(route), "You're trying to send data from %s to %s but there is no connection between these two hosts.", src_name, dst_name); @@ -706,21 +658,21 @@ static surf_action_t im_net_communicate(const char *src_name, (link->lmm_resource.power.peak * link->lmm_resource.power.scale); if (bandwidth_bound < 0.0) bandwidth_bound = - (*im_bandwidth_factor_callback) (size) * + im_bandwidth_factor_callback(size) * (link->lmm_resource.power.peak * link->lmm_resource.power.scale); else bandwidth_bound = min(bandwidth_bound, - (*im_bandwidth_factor_callback) (size) * + im_bandwidth_factor_callback(size) * (link->lmm_resource.power.peak * link->lmm_resource.power.scale)); } /* LARGE PLATFORMS HACK: Add src->link and dst->link latencies */ action->lat_current = action->latency; - action->latency *= (*im_latency_factor_callback) (size); + action->latency *= im_latency_factor_callback(size); action->rate = - (*im_bandwidth_constraint_callback) (action->rate, bandwidth_bound, + im_bandwidth_constraint_callback(action->rate, bandwidth_bound, size); /* LARGE PLATFORMS HACK: @@ -737,7 +689,7 @@ static surf_action_t im_net_communicate(const char *src_name, lmm_variable_new(network_im_maxmin_system, action, 0.0, -1.0, constraints_per_variable); // add to the heap the event when the latency is payed - DEBUG2("Added action (%p) one latency event at date %f", action, action->latency + action->last_update); + XBT_DEBUG("Added action (%p) one latency event at date %f", action, action->latency + action->last_update); heap_insert(action, action->latency + action->last_update, LATENCY); #ifdef HAVE_LATENCY_BOUND_TRACKING (action->generic_action).latency_limited = 1; @@ -773,7 +725,7 @@ static surf_action_t im_net_communicate(const char *src_name, } if (sg_network_fullduplex == 1) { - DEBUG1("Fullduplex active adding backward flow using 5%c", '%'); + XBT_DEBUG("Fullduplex active adding backward flow using 5%c", '%'); xbt_dynar_foreach(back_route, i, link) { lmm_expand(network_im_maxmin_system, link->lmm_resource.constraint, action->variable, .05); @@ -783,22 +735,25 @@ static surf_action_t im_net_communicate(const char *src_name, /* LARGE PLATFORMS HACK: expand also with src->link and dst->link */ #ifdef HAVE_TRACING - action->src_name = xbt_new(char, strlen(src_name) + 1); - strncpy(action->src_name, src_name, strlen(src_name) + 1); - - action->dst_name = xbt_new(char, strlen(dst_name) + 1); - strncpy(action->dst_name, dst_name, strlen(dst_name) + 1); + if (TRACE_is_enabled()) { + action->src_name = xbt_strdup(src_name); + action->dst_name = xbt_strdup(dst_name); + } else { + action->src_name = action->dst_name = NULL; + } #endif xbt_dynar_free(&route); - XBT_OUT; + XBT_OUT(); return (surf_action_t) action; } static xbt_dynar_t im_net_get_route(const char *src, const char *dst) { - return global_routing->get_route(src, dst); + xbt_dynar_t route=NULL; + routing_get_route_and_latency(src, dst,&route,NULL); + return route; } static double im_net_get_link_bandwidth(const void *link) @@ -848,7 +803,7 @@ static int im_net_action_is_suspended(surf_action_t action) return ((surf_action_network_CM02_im_t) action)->suspended; } -void im_net_action_set_max_duration(surf_action_t action, double duration) +static void im_net_action_set_max_duration(surf_action_t action, double duration) { action->max_duration = duration; // remove action from the heap @@ -861,8 +816,6 @@ static void im_net_finalize(void) surf_model_exit(surf_network_model); surf_network_model = NULL; - global_routing->finalize(); - lmm_system_free(network_im_maxmin_system); network_im_maxmin_system = NULL; @@ -874,8 +827,6 @@ static void im_net_finalize(void) static void im_surf_network_model_init_internal(void) { s_surf_action_network_CM02_im_t comm; - INFO0("You are using the UNSAFE lazy management optimization, I hope you know what you are doing."); - INFO0("====> For now this optimization is only available for LV08_im network model."); surf_network_model = surf_model_init(); @@ -921,14 +872,13 @@ static void im_surf_network_model_init_internal(void) xbt_heap_set_update_callback(im_net_action_heap, im_net_action_update_index_heap); - routing_model_create(sizeof(link_CM02_im_t), im_net_link_new(xbt_strdup("__loopback__"), - 498000000, NULL, 0.000015, NULL, - SURF_RESOURCE_ON, NULL, - SURF_LINK_FATPIPE, NULL), - im_net_get_link_latency); + routing_model_create(sizeof(link_CM02_im_t), + im_net_create_resource("__loopback__", + 498000000, NULL, 0.000015, NULL, + SURF_RESOURCE_ON, NULL, + SURF_LINK_FATPIPE, NULL)); im_net_modified_set = xbt_swag_new(xbt_swag_offset(comm, action_list_hookup)); - keep_track = im_net_modified_set; } @@ -936,13 +886,13 @@ static void im_surf_network_model_init_internal(void) /************************************************************************/ /* New model based on optimizations discussed during this thesis */ /************************************************************************/ -void im_surf_network_model_init_LegrandVelho(const char *filename) +void im_surf_network_model_init_LegrandVelho(void) { if (surf_network_model) return; im_surf_network_model_init_internal(); - im_net_define_callbacks(filename); + im_net_define_callbacks(); xbt_dynar_push(model_list, &surf_network_model); network_im_solve = lmm_solve; @@ -950,9 +900,6 @@ void im_surf_network_model_init_LegrandVelho(const char *filename) xbt_cfg_setdefault_double(_surf_cfg_set, "network/bandwidth_factor", 0.92); xbt_cfg_setdefault_double(_surf_cfg_set, "network/weight_S", 8775); - - update_model_description(surf_network_model_description, - "LV08_im", surf_network_model); }