From: Martin Quinson Date: Tue, 15 Nov 2011 01:35:50 +0000 (+0100) Subject: kill the now useless 'cleanup' parameter of routing_get_route_and_latency X-Git-Tag: exp_20120216~279 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/85b02668e44e45559b9fc8474cbb81c7e6b3ae74?ds=sidebyside kill the now useless 'cleanup' parameter of routing_get_route_and_latency Instead, if route == NULL we won't bother collecting the route, so freeing is useless. If *route == NULL, we create a short-lived dynar (equivalent to the result of having cleanup=1 previously else, we fill that route without messing with it --- diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index f1a883221d..fe9b4f38d5 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -176,7 +176,7 @@ typedef struct surf_network_model_extension_public { surf_action_t(*communicate) (const char *src_name, const char *dst_name, double size, double rate); - xbt_dynar_t(*get_route) (const char *src_name, const char *dst_name); + xbt_dynar_t(*get_route) (const char *src_name, const char *dst_name); //FIXME: kill field? That is done by the routing nowadays double (*get_link_bandwidth) (const void *link); double (*get_link_latency) (const void *link); int (*link_shared) (const void *link); @@ -208,6 +208,7 @@ typedef struct surf_workstation_model_extension_public { surf_action_t(*communicate) (void *workstation_src, /**< Execute a communication amount between two workstations */ void *workstation_dst, double size, double max_rate); + // FIXME: kill next field, which duplicates the routing xbt_dynar_t(*get_route) (void *workstation_src, void *workstation_dst); /**< Get the list of links between two ws */ surf_action_t(*execute_parallel_task) (int workstation_nb, /**< Execute a parallel task on several workstations */ diff --git a/src/instr/instr_interface.c b/src/instr/instr_interface.c index b0ac44e0a9..7a27800d57 100644 --- a/src/instr/instr_interface.c +++ b/src/instr/instr_interface.c @@ -138,8 +138,8 @@ static void instr_user_srcdst_variable(double time, double value, InstrUserVariable what) { - xbt_dynar_t route; - routing_get_route_and_latency (src, dst, &route,NULL,1); + xbt_dynar_t route=NULL; + routing_get_route_and_latency (src, dst, &route,NULL); unsigned int i; void *link; xbt_dynar_foreach (route, i, link) { diff --git a/src/instr/instr_routing.c b/src/instr/instr_routing.c index f009b2a38f..6c0528ff5b 100644 --- a/src/instr/instr_routing.c +++ b/src/instr/instr_routing.c @@ -113,7 +113,7 @@ static void recursiveGraphExtraction (AS_t rc, container_t container, xbt_dict_t xbt_ex_t e; TRY { - routing_get_route_and_latency(child1_name, child2_name, &route, NULL, 1); + routing_get_route_and_latency(child1_name, child2_name, &route, NULL); } CATCH(e) { xbt_ex_free(e); } @@ -421,9 +421,9 @@ static void recursiveXBTGraphExtraction (xbt_graph_t graph, xbt_dict_t nodes, xb (child2->kind == INSTR_HOST || child2->kind == INSTR_ROUTER) && strcmp (child1_name, child2_name) != 0){ - // FIXME factorize route creation once possible - xbt_dynar_t route; - routing_get_route_and_latency (child1_name, child2_name,&route,NULL,1); + // FIXME factorize route creation with else branch below (once possible) + xbt_dynar_t route=NULL; + routing_get_route_and_latency (child1_name, child2_name,&route,NULL); if (TRACE_onelink_only()){ if (xbt_dynar_length (route) > 1) continue; } diff --git a/src/surf/network.c b/src/surf/network.c index 8753f1a421..9abdaf3ab9 100644 --- a/src/surf/network.c +++ b/src/surf/network.c @@ -413,8 +413,8 @@ static void net_update_actions_state(double now, double delta) } #ifdef HAVE_TRACING if (TRACE_is_enabled()) { - xbt_dynar_t route; - routing_get_route_and_latency(action->src_name, action->dst_name,&route,NULL,1); + xbt_dynar_t route=NULL; + routing_get_route_and_latency(action->src_name, action->dst_name,&route,NULL); link_CM02_t link; unsigned int i; xbt_dynar_foreach(route, i, link) { @@ -585,12 +585,13 @@ static surf_action_t net_communicate(const char *src_name, xbt_dynar_t back_route = NULL; int constraints_per_variable = 0; - xbt_dynar_t route; - // I need to have the forward and backward routes at the same time, so I don't ask the routing to cleanup the route right away for me - routing_get_route_and_latency(src_name, dst_name, &route, &latency, 0); + xbt_dynar_t route = xbt_dynar_new(sizeof(void*),NULL); + // I need to have the forward and backward routes at the same time, so allocate "route". That way, the routing wont clean it up + routing_get_route_and_latency(src_name, dst_name, &route, &latency); if (sg_network_fullduplex == 1) { - routing_get_route_and_latency(dst_name, src_name, &back_route,NULL,1); + // FIXME: fill route directly + routing_get_route_and_latency(dst_name, src_name, &back_route,NULL); } /* LARGE PLATFORMS HACK: @@ -723,8 +724,8 @@ static surf_action_t net_communicate(const char *src_name, static xbt_dynar_t net_get_route(const char *src, const char *dst) { - xbt_dynar_t route; - routing_get_route_and_latency(src, dst,&route, NULL,1); + xbt_dynar_t route=NULL; + routing_get_route_and_latency(src, dst,&route, NULL); return route; } diff --git a/src/surf/network_im.c b/src/surf/network_im.c index a8c6e7f668..9b4ef5b4ab 100644 --- a/src/surf/network_im.c +++ b/src/surf/network_im.c @@ -605,13 +605,13 @@ 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 with 0 as last argument to preserve it - xbt_dynar_t route; - routing_get_route_and_latency(src_name, dst_name,&route,NULL,0); + // 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) { - routing_get_route_and_latency(dst_name, src_name, &back_route, NULL,1); + routing_get_route_and_latency(dst_name, src_name, &back_route, NULL); } /* LARGE PLATFORMS HACK: @@ -748,8 +748,8 @@ static surf_action_t im_net_communicate(const char *src_name, static xbt_dynar_t im_net_get_route(const char *src, const char *dst) { - xbt_dynar_t route; - routing_get_route_and_latency(src, dst,&route,NULL,1); + xbt_dynar_t route=NULL; + routing_get_route_and_latency(src, dst,&route,NULL); return route; } diff --git a/src/surf/surf_private.h b/src/surf/surf_private.h index fc8e8dc40a..b527e5c48f 100644 --- a/src/surf/surf_private.h +++ b/src/surf/surf_private.h @@ -173,10 +173,11 @@ XBT_PUBLIC(void) routing_model_create(size_t size_of_link, void *loopback); XBT_PUBLIC(void) routing_exit(void); XBT_PUBLIC(void) routing_register_callbacks(void); XBT_PUBLIC(void) generic_free_route(route_t route); // FIXME rename to routing_route_free + // FIXME: make previous function private to routing again? -XBT_PUBLIC(void) routing_get_route_and_latency(const char *src, const char *dst, //FIXME too much functions avail? - xbt_dynar_t * route, double *latency, int cleanup); +XBT_PUBLIC(void) routing_get_route_and_latency(const char *src, const char *dst, + xbt_dynar_t * route, double *latency); /** * Resource protected methods diff --git a/src/surf/surf_routing.c b/src/surf/surf_routing.c index 5f3e5685f9..65539ef0b7 100644 --- a/src/surf/surf_routing.c +++ b/src/surf/surf_routing.c @@ -478,7 +478,7 @@ static void elements_father(const char *src, const char *dst, * * \param src the source host name * \param dst the destination host name - * \param *e_route the route where the links are stored + * \param *route the route where the links are stored. * \param *latency the latency, if needed * * This function is called by "get_route" and "get_latency". It allows to walk @@ -631,26 +631,29 @@ static void _get_route_and_latency(const char *src, const char *dst, * * \param src the source host name * \param dst the destination host name - * \param route where to store the list of links (or NULL if you are not interested in it) + * \param route where to store the list of links. If route=NULL, we don't care about the route. + * If *route=NULL, create a short lived dynar. Else, fill the provided dynar * \param latency where to store the latency experienced on the path (or NULL if not interested) - * \param cleanup boolean whether the dynar should be automatically destroyed or not * * walk through the routing components tree and find a route between hosts * by calling the differents "get_route" functions in each routing component. */ void routing_get_route_and_latency(const char *src, const char *dst, - xbt_dynar_t * route, double *latency, int cleanup) + xbt_dynar_t * route, double *latency) { static xbt_dynar_t last_route = NULL; + int need_cleanup = route && !(*route); + + if (need_cleanup) { + xbt_dynar_free(&last_route); + last_route = *route = xbt_dynar_new(global_routing->size_of_link,NULL); + } _get_route_and_latency(src, dst, route, latency); + xbt_assert(!route || *route, "no route between \"%s\" and \"%s\"", src, dst); xbt_assert(!latency || *latency >= 0.0, - "latency error on route between \"%s\" and \"%s\"", src, dst); - if (route) { - xbt_dynar_free(&last_route); - last_route = cleanup ? *route : NULL; - } + "negative latency on route between \"%s\" and \"%s\"", src, dst); } static xbt_dynar_t recursive_get_onelink_routes(AS_t rc) diff --git a/src/surf/surf_routing_dijkstra.c b/src/surf/surf_routing_dijkstra.c index b77cfaf337..2c65d60bbe 100644 --- a/src/surf/surf_routing_dijkstra.c +++ b/src/surf/surf_routing_dijkstra.c @@ -360,8 +360,8 @@ static void dijkstra_get_route(AS_t asg, if (asg->hierarchy == SURF_ROUTING_RECURSIVE && v != dst_node_id && strcmp(gw_dst, prev_gw_src)) { - xbt_dynar_t e_route_as_to_as; - routing_get_route_and_latency(gw_dst, prev_gw_src,&e_route_as_to_as,NULL,1); + xbt_dynar_t e_route_as_to_as=NULL; + routing_get_route_and_latency(gw_dst, prev_gw_src,&e_route_as_to_as,NULL); xbt_assert(e_route_as_to_as, "no route between \"%s\" and \"%s\"", gw_dst, prev_gw_src); links = e_route_as_to_as; diff --git a/src/surf/surf_routing_floyd.c b/src/surf/surf_routing_floyd.c index cd869e9367..a17aabcfdd 100644 --- a/src/surf/surf_routing_floyd.c +++ b/src/surf/surf_routing_floyd.c @@ -108,8 +108,8 @@ static void floyd_get_route(AS_t asg, const char *src, const char *dst, route_t if (asg->hierarchy == SURF_ROUTING_RECURSIVE && !first && strcmp(gw_dst, prev_gw_src)) { - xbt_dynar_t e_route_as_to_as; - routing_get_route_and_latency(gw_dst, prev_gw_src,&e_route_as_to_as,NULL,1); + xbt_dynar_t e_route_as_to_as=NULL; + routing_get_route_and_latency(gw_dst, prev_gw_src,&e_route_as_to_as,NULL); xbt_assert(e_route_as_to_as, "no route between \"%s\" and \"%s\"", gw_dst, prev_gw_src); links = e_route_as_to_as; diff --git a/src/surf/workstation_ptask_L07.c b/src/surf/workstation_ptask_L07.c index 714590bab1..ce71a99b5d 100644 --- a/src/surf/workstation_ptask_L07.c +++ b/src/surf/workstation_ptask_L07.c @@ -81,11 +81,11 @@ static void ptask_update_action_bound(surf_action_workstation_L07_t action) for (i = 0; i < workstation_nb; i++) { for (j = 0; j < workstation_nb; j++) { - xbt_dynar_t route; + xbt_dynar_t route=NULL; routing_get_route_and_latency(surf_resource_name (action->workstation_list[i]), surf_resource_name(action->workstation_list[j]), - &route, NULL,1); + &route, NULL); // FIXME do we really need to recompute the latency here? double lat = 0.0; @@ -462,11 +462,11 @@ static surf_action_t ptask_execute_parallel_task(int workstation_nb, for (i = 0; i < workstation_nb; i++) { for (j = 0; j < workstation_nb; j++) { link_L07_t link; - xbt_dynar_t route; + xbt_dynar_t route=NULL; routing_get_route_and_latency( surf_resource_name(workstation_list[i]), surf_resource_name(workstation_list[j]), - &route,NULL,1); // FIXME: do we want to recompute the latency? + &route,NULL); // FIXME: do we want to recompute the latency? double lat = 0.0; if (communication_amount[i * workstation_nb + j] > 0) @@ -516,11 +516,11 @@ static surf_action_t ptask_execute_parallel_task(int workstation_nb, for (i = 0; i < workstation_nb; i++) { for (j = 0; j < workstation_nb; j++) { link_L07_t link; - xbt_dynar_t route; + xbt_dynar_t route=NULL; routing_get_route_and_latency( surf_resource_name(workstation_list[i]), surf_resource_name(workstation_list[j]), - &route,NULL,1); + &route,NULL); if (communication_amount[i * workstation_nb + j] == 0.0) continue; @@ -591,10 +591,10 @@ static surf_action_t ptask_action_sleep(void *cpu, double duration) static xbt_dynar_t ptask_get_route(void *src, void *dst) // FIXME: kill that callback kind? { - xbt_dynar_t route; + xbt_dynar_t route=NULL; routing_get_route_and_latency( surf_resource_name(src), surf_resource_name(dst), - &route,NULL,1); + &route,NULL); return route; } diff --git a/teshsuite/simdag/platforms/flatifier.c b/teshsuite/simdag/platforms/flatifier.c index 7e7bb7ffed..1f1c663b11 100644 --- a/teshsuite/simdag/platforms/flatifier.c +++ b/teshsuite/simdag/platforms/flatifier.c @@ -136,8 +136,8 @@ int main(int argc, char **argv) printf(" \n " ,src ,dst); - xbt_dynar_t route; - routing_get_route_and_latency(src,dst,&route,NULL,1); + xbt_dynar_t route=NULL; + routing_get_route_and_latency(src,dst,&route,NULL); for(i=0;i\n " ,src ,dst); - xbt_dynar_t route; - routing_get_route_and_latency(src,dst,&route,NULL,1); + xbt_dynar_t route=NULL; + routing_get_route_and_latency(src,dst,&route,NULL); for(i=0;i\n " ,src ,dst); - xbt_dynar_t route; - routing_get_route_and_latency(src,dst,&route,NULL,1); + xbt_dynar_t route=NULL; + routing_get_route_and_latency(src,dst,&route,NULL); for(i=0;i\n " ,src, dst); - xbt_dynar_t route; - routing_get_route_and_latency(src,dst,&route, NULL,1); + xbt_dynar_t route=NULL; + routing_get_route_and_latency(src,dst,&route, NULL); for(i=0;i