From 919edbcd087b9ad979957ea49c05d1453bab8e69 Mon Sep 17 00:00:00 2001 From: alegrand Date: Wed, 1 Dec 2010 15:50:05 +0000 Subject: [PATCH] Move the latency computation logic from surf models to the routing module. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@8816 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- src/surf/network.c | 3 +- src/surf/network_constant.c | 2 +- src/surf/network_vivaldi.c | 2 +- src/surf/surf_private.h | 5 +- src/surf/surf_routing.c | 158 ++++++++++++++++++++++++++++++- src/surf/workstation_ptask_L07.c | 3 +- 6 files changed, 166 insertions(+), 7 deletions(-) diff --git a/src/surf/network.c b/src/surf/network.c index 73f0a60b05..30792cfc24 100644 --- a/src/surf/network.c +++ b/src/surf/network.c @@ -773,7 +773,8 @@ static void surf_network_model_init_internal(void) net_link_new(xbt_strdup("__loopback__"), 498000000, NULL, 0.000015, NULL, SURF_RESOURCE_ON, NULL, - SURF_LINK_FATPIPE, NULL)); + SURF_LINK_FATPIPE, NULL), + (double_f_pvoid_t)net_get_link_latency); } diff --git a/src/surf/network_constant.c b/src/surf/network_constant.c index 5a0cbad452..b76ff47863 100644 --- a/src/surf/network_constant.c +++ b/src/surf/network_constant.c @@ -230,5 +230,5 @@ void surf_network_model_init_Constant(const char *filename) "Constant", surf_network_model); xbt_cfg_set_string(_surf_cfg_set, "routing", "none"); - routing_model_create(sizeof(double), NULL); + routing_model_create(sizeof(double), NULL, (double_f_pvoid_t)netcste_get_link_latency); } diff --git a/src/surf/network_vivaldi.c b/src/surf/network_vivaldi.c index bf264c87a6..085b701c84 100644 --- a/src/surf/network_vivaldi.c +++ b/src/surf/network_vivaldi.c @@ -292,5 +292,5 @@ void surf_network_model_init_Vivaldi(const char *filename) #endif xbt_cfg_set_string(_surf_cfg_set, "routing", "none"); - routing_model_create(sizeof(double), NULL); + routing_model_create(sizeof(double), NULL, (double_f_pvoid_t)netviva_get_link_latency); } diff --git a/src/surf/surf_private.h b/src/surf/surf_private.h index 9d52382fe2..fe5fbc443d 100644 --- a/src/surf/surf_private.h +++ b/src/surf/surf_private.h @@ -157,6 +157,8 @@ typedef struct s_routing_component { xbt_dict_t routing_sons; route_extended_t(*get_route) (routing_component_t rc, const char *src, const char *dst); + double(*get_latency) (routing_component_t rc, const char *src, + const char *dst); xbt_dynar_t(*get_onelink_routes) (routing_component_t rc); e_surf_network_element_type_t(*get_network_element_type) (const char *name); @@ -188,13 +190,14 @@ struct s_routing_global { xbt_dynar_t(*get_route) (const char *src, const char *dst); xbt_dynar_t(*get_route_no_cleanup) (const char *src, const char *dst); xbt_dynar_t(*get_onelink_routes) (void); + double (*get_latency) (const char *src, const char *dst); e_surf_network_element_type_t(*get_network_element_type) (const char *name); void (*finalize) (void); xbt_dynar_t last_route; }; -XBT_PUBLIC(void) routing_model_create(size_t size_of_link, void *loopback); +XBT_PUBLIC(void) routing_model_create(size_t size_of_link, void *loopback, double_f_pvoid_t get_link_latency_fun); /** * Resource protected methods diff --git a/src/surf/surf_routing.c b/src/surf/surf_routing.c index f90fe09564..f607a184cb 100644 --- a/src/surf/surf_routing.c +++ b/src/surf/surf_routing.c @@ -25,6 +25,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route, surf, "Routing part of surf"); routing_global_t global_routing = NULL; routing_component_t current_routing = NULL; model_type_t current_routing_model = NULL; +static double_f_pvoid_t get_link_latency = NULL; /* Prototypes of each model */ static void *model_full_create(void); /* create structures for full routing model */ @@ -123,6 +124,7 @@ static int surf_pointer_resource_cmp(const void *a, const void *b); /* ************************************************************************** */ /* *************** GENERIC BUSINESS METHODS (declarations) ****************** */ +static double generic_get_link_latency(routing_component_t rc, const char *src, const char *dst); static xbt_dynar_t generic_get_onelink_routes(routing_component_t rc); static route_extended_t generic_get_bypassroute(routing_component_t rc, const char *src, @@ -714,6 +716,121 @@ static route_extended_t _get_route(const char *src, const char *dst) return e_route; } +static double _get_latency(const char *src, const char *dst) +{ + + void *link; + unsigned int cpt = 0; + double latency, latency_src, latency_dst = 0.0; + + DEBUG2("Solve route \"%s\" to \"%s\"", src, dst); + + xbt_assert0(src && dst, "bad parameters for \"_get_route\" method"); + + route_extended_t e_route, e_route_cnt, e_route_src = NULL, e_route_dst = + NULL; + + xbt_dynar_t elem_father_list = elements_father(src, dst); + + routing_component_t common_father = + xbt_dynar_get_as(elem_father_list, 0, routing_component_t); + routing_component_t src_father = + xbt_dynar_get_as(elem_father_list, 1, routing_component_t); + routing_component_t dst_father = + xbt_dynar_get_as(elem_father_list, 2, routing_component_t); + + e_route = xbt_new0(s_route_extended_t, 1); + e_route->src_gateway = NULL; + e_route->dst_gateway = NULL; + e_route->generic_route.link_list = + xbt_dynar_new(global_routing->size_of_link, NULL); + + if (src_father == dst_father) { /* SURF_ROUTING_BASE */ + + if (strcmp(src, dst)) { + latency = + (*(common_father->get_latency)) (common_father, src, dst); + xbt_assert2(latency>=0, "no route between \"%s\" and \"%s\"", src, + dst); + } else latency = 0; + } else { /* SURF_ROUTING_RECURSIVE */ + route_extended_t e_route_bypass = NULL; + + if (common_father->get_bypass_route) + e_route_bypass = + (*(common_father->get_bypass_route)) (common_father, src, dst); + + xbt_assert0(!e_route_bypass,"Bypass cannot work yet with get_latency"); + + e_route_cnt = + (*(common_father->get_route)) (common_father, src_father->name, + dst_father->name); + + xbt_assert2(e_route_cnt, "no route between \"%s\" and \"%s\"", + src_father->name, dst_father->name); + + xbt_assert2((e_route_cnt->src_gateway == NULL) == + (e_route_cnt->dst_gateway == NULL), + "bad gateway for route between \"%s\" and \"%s\"", src, + dst); + latency = + (*(common_father->get_latency)) (common_father, src_father->name, + dst_father->name); + xbt_assert2(latency>=0, "no route between \"%s\" and \"%s\"", + src_father->name, dst_father->name); + + + if (src != e_route_cnt->src_gateway) { + /* + e_route_src = _get_route(src, e_route_cnt->src_gateway); + xbt_assert2(e_route_src, "no route between \"%s\" and \"%s\"", src, + e_route_cnt->src_gateway); + xbt_dynar_foreach(e_route_src->generic_route.link_list, cpt, link) { + xbt_dynar_push(e_route->generic_route.link_list, &link); + } + */ + latency_src = _get_latency(src, e_route_cnt->src_gateway); + xbt_assert2(latency_src>=0, "no route between \"%s\" and \"%s\"", src, + e_route_cnt->src_gateway); + latency += latency_src; + } + + /* + xbt_dynar_foreach(e_route_cnt->generic_route.link_list, cpt, link) { + xbt_dynar_push(e_route->generic_route.link_list, &link); + } + */ + + if (e_route_cnt->dst_gateway != dst) { + /* + e_route_dst = _get_route(e_route_cnt->dst_gateway, dst); + xbt_assert2(e_route_dst, "no route between \"%s\" and \"%s\"", + e_route_cnt->dst_gateway, dst); + xbt_dynar_foreach(e_route_dst->generic_route.link_list, cpt, link) { + xbt_dynar_push(e_route->generic_route.link_list, &link); + } + */ + latency_dst = _get_latency(e_route_cnt->dst_gateway, dst); + xbt_assert2(latency_dst>=0, "no route between \"%s\" and \"%s\"", + e_route_cnt->dst_gateway, dst); + latency += latency_dst; + } + + /* + e_route->src_gateway = xbt_strdup(e_route_cnt->src_gateway); + e_route->dst_gateway = xbt_strdup(e_route_cnt->dst_gateway); + + generic_free_extended_route(e_route_src); + generic_free_extended_route(e_route_cnt); + generic_free_extended_route(e_route_dst); + */ + } + + xbt_dynar_free(&elem_father_list); + + return latency; +} + /** * \brief Generic method: find a route between hosts * @@ -774,6 +891,25 @@ static xbt_dynar_t get_route_no_cleanup(const char *src, const char *dst) return d; } +/*Get Latency*/ +static double get_latency(const char *src, const char *dst) +{ + + double latency = -1.0; + xbt_dynar_t elem_father_list = elements_father(src, dst); + routing_component_t common_father = + xbt_dynar_get_as(elem_father_list, 0, routing_component_t); + + if (strcmp(src, dst)) + latency = _get_latency(src, dst); + else + latency = (*(common_father->get_latency)) (common_father, src, dst); + + xbt_assert2(latency>=0.0, "no route between \"%s\" and \"%s\"", src, dst); + + return latency; +} + /** * \brief Recursive function for finalize * @@ -865,7 +1001,7 @@ static e_surf_network_element_type_t get_network_element_type(const char * * Make a global routing structure and set all the parsing functions. */ -void routing_model_create(size_t size_of_links, void *loopback) +void routing_model_create(size_t size_of_links, void *loopback, double_f_pvoid_t get_link_latency_fun ) { /* config the uniq global routing */ @@ -873,6 +1009,7 @@ void routing_model_create(size_t size_of_links, void *loopback) global_routing->where_network_elements = xbt_dict_new(); global_routing->root = NULL; global_routing->get_route = get_route; + global_routing->get_latency = get_latency; global_routing->get_route_no_cleanup = get_route_no_cleanup; global_routing->get_onelink_routes = get_onelink_routes; global_routing->get_network_element_type = get_network_element_type; @@ -880,7 +1017,7 @@ void routing_model_create(size_t size_of_links, void *loopback) global_routing->loopback = loopback; global_routing->size_of_link = size_of_links; global_routing->last_route = NULL; - + get_link_latency = get_link_latency_fun; /* no current routing at moment */ current_routing = NULL; @@ -1044,6 +1181,7 @@ static void *model_full_create(void) new_component->generic_routing.set_ASroute = model_full_set_route; new_component->generic_routing.set_bypassroute = generic_set_bypassroute; new_component->generic_routing.get_route = full_get_route; + new_component->generic_routing.get_latency = generic_get_link_latency; new_component->generic_routing.get_onelink_routes = full_get_onelink_routes; new_component->generic_routing.get_bypass_route = @@ -1365,6 +1503,7 @@ static void *model_floyd_create(void) new_component->generic_routing.set_ASroute = model_floyd_set_route; new_component->generic_routing.set_bypassroute = generic_set_bypassroute; new_component->generic_routing.get_route = floyd_get_route; + new_component->generic_routing.get_latency = generic_get_link_latency; new_component->generic_routing.get_onelink_routes = floyd_get_onelink_routes; new_component->generic_routing.get_bypass_route = @@ -1983,6 +2122,7 @@ static void *model_dijkstra_both_create(int cached) new_component->generic_routing.set_ASroute = model_dijkstra_both_set_route; //TODO new_component->generic_routing.set_bypassroute = generic_set_bypassroute; new_component->generic_routing.get_route = dijkstra_get_route; + new_component->generic_routing.get_latency = generic_get_link_latency; new_component->generic_routing.get_onelink_routes = dijkstra_get_onelink_routes; new_component->generic_routing.get_bypass_route = @@ -2678,6 +2818,20 @@ static void generic_set_bypassroute(routing_component_t rc, /* ************************************************************************** */ /* *********************** GENERIC BUSINESS METHODS ************************* */ +static double generic_get_link_latency(routing_component_t rc, + const char *src, const char *dst) +{ + route_extended_t route = rc->get_route(rc,src,dst); + void * link; + unsigned int i; + double latency = 0.0; + + xbt_dynar_foreach(route->generic_route.link_list,i,link) { + latency += get_link_latency(link); + } + return latency; +} + static xbt_dynar_t generic_get_onelink_routes(routing_component_t rc) { xbt_die("\"generic_get_onelink_routes\" not implemented yet"); diff --git a/src/surf/workstation_ptask_L07.c b/src/surf/workstation_ptask_L07.c index e0ce3d4155..d1fc646c17 100644 --- a/src/surf/workstation_ptask_L07.c +++ b/src/surf/workstation_ptask_L07.c @@ -966,7 +966,8 @@ static void ptask_model_init_internal(void) ptask_link_new(xbt_strdup("__loopback__"), 498000000, NULL, 0.000015, NULL, SURF_RESOURCE_ON, NULL, - SURF_LINK_FATPIPE, NULL)); + SURF_LINK_FATPIPE, NULL), + ptask_get_link_latency); } -- 2.20.1