From f7f7d40b071a8c28f2582c39bf599e32802580eb Mon Sep 17 00:00:00 2001 From: mquinson Date: Wed, 1 Jul 2009 20:31:57 +0000 Subject: [PATCH] Extract the routing logic into its own object. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@6431 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- ChangeLog | 7 +- src/Makefile.am | 1 + src/include/surf/surf.h | 12 ++- src/surf/network.c | 157 +++---------------------------- src/surf/network_constant.c | 9 +- src/surf/network_private.h | 16 +--- src/surf/surf_private.h | 13 +++ src/surf/surf_routing.c | 149 +++++++++++++++++++++++++++++ src/surf/workstation.c | 27 +++--- src/surf/workstation_private.h | 2 +- src/surf/workstation_ptask_L07.c | 140 ++++----------------------- 11 files changed, 227 insertions(+), 306 deletions(-) create mode 100644 src/surf/surf_routing.c diff --git a/ChangeLog b/ChangeLog index 4eef32e19a..29fe81f1eb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,10 @@ SimGrid (3.3.2-svn) unstable; urgency=low MPI_Waitany, MPI_Waitall, MPI_Allreduce SURF: + * Extract the routing logic into its own object. + - Was dupplicated in network.c and workstation_LV07.c + - We may want to implement other ways of storing that info + => kill now useless network_card concept * Declare common_public as an embeeded struct to reduce redirections and mallocs * Factorize model_init/exit between models @@ -16,9 +20,6 @@ SimGrid (3.3.2-svn) unstable; urgency=low * Embeed every fields of common_public directly into s_surf_model_t * Implement a generic resource; use it as ancestor to specific ones Allows to kill duplicated code in models - The drawback is that network cards are more fat since they don't - use the model field of their ancestor. - But hell, we wont fight for 8 bytes per host, will we? TODO: integrate the properties into that ancestor * Rename model methods: action_free -> action_unref diff --git a/src/Makefile.am b/src/Makefile.am index 66155e6262..b1e72d781d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -171,6 +171,7 @@ SURF_SRC= \ surf/surf_model.c \ surf/surf_resource.c \ surf/surf_action.c \ + surf/surf_routing.c \ surf/surf_config.c \ surf/maxmin.c \ surf/fair_bottleneck.c \ diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index 5fc2982997..1cb37e5b50 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -120,6 +120,8 @@ XBT_PUBLIC(int) find_model_description(s_surf_model_description_t * table, /***************************/ /* Generic model object */ /***************************/ + typedef struct s_routing s_routing_t, *routing_t; + XBT_PUBLIC_DATA(routing_t) used_routing; /** \brief Private data available on all models * \ingroup SURF_models @@ -167,9 +169,9 @@ XBT_PUBLIC(int) find_model_description(s_surf_model_description_t * table, * Public functions specific to the network model */ typedef struct surf_network_model_extension_public { - surf_action_t(*communicate) (void *src, void *dst, double size, - double max_rate); - xbt_dynar_t (*get_route) (void *src, void *dst); + surf_action_t(*communicate) (const char *src_name,const char *dst_name,int src, int dst, double size, + double rate); + xbt_dynar_t (*get_route) (int src, int dst); double (*get_link_bandwidth) (const void *link); double (*get_link_latency) (const void *link); int (*link_shared) (const void *link); @@ -190,13 +192,13 @@ XBT_PUBLIC(int) find_model_description(s_surf_model_description_t * table, surf_action_t(*communicate) (void *workstation_src, /**< Execute a communication amount between two workstations */ void *workstation_dst, double size, double max_rate); + 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 */ void **workstation_list, double *computation_amount, double *communication_amount, double amount, double rate); - xbt_dynar_t (*get_route) (void *src, void *dst); /**< Return the network link list between two workstations */ double (*get_link_bandwidth) (const void *link); /**< Return the current bandwidth of a network link */ double (*get_link_latency) (const void *link); /**< Return the current latency of a network link */ int (*link_shared) (const void *link); @@ -611,7 +613,7 @@ XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_bandwidth; XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_latency; -XBT_PUBLIC_DATA(double) get_cpu_power(const char *power); +XBT_PUBLIC(double) get_cpu_power(const char *power); SG_END_DECL() diff --git a/src/surf/network.c b/src/surf/network.c index e388546dfb..4b828cab84 100644 --- a/src/surf/network.c +++ b/src/surf/network.c @@ -22,23 +22,10 @@ double bandwidth_factor = 1.0; /* default value */ double weight_S_parameter = 0.0; /* default value */ int card_number = 0; -int host_number = 0; -xbt_dynar_t *routing_table = NULL; -static link_CM02_t loopback = NULL; +int host_count = 0; double sg_tcp_gamma = 0.0; -static void create_routing_table(void) -{ - int i,j; - routing_table = xbt_new0(xbt_dynar_t, /*card_number * card_number */ - host_number * host_number); - for (i=0;iproperties)); @@ -91,21 +78,6 @@ static link_CM02_t link_new(char *name, return nw_link; } -static int network_card_new(const char *card_name) -{ - network_card_CM02_t card = - surf_model_resource_by_name(surf_network_model, card_name); - - if (!card) { - card = xbt_new0(s_network_card_CM02_t, 1); - card->generic_resource.name = xbt_strdup(card_name); - card->id = host_number++; - xbt_dict_set(surf_model_resource_set(surf_network_model), card_name, card, - surf_resource_free); - } - return card->id; -} - static void parse_link_init(void) { char *name_link; @@ -145,87 +117,6 @@ static void parse_link_init(void) } -static int src_id = -1; -static int dst_id = -1; - -static void parse_route_set_endpoints(void) -{ - src_id = network_card_new(A_surfxml_route_src); - dst_id = network_card_new(A_surfxml_route_dst); - route_action = A_surfxml_route_action; -} - -static void parse_route_set_route(void) -{ - char *name; - if (src_id != -1 && dst_id != -1) { - name = bprintf("%x#%x", src_id, dst_id); - manage_route(route_table, name, route_action, 0); - free(name); - } -} - -static void add_loopback(void) -{ - int i; - /* Adding loopback if needed */ - for (i = 0; i < host_number; i++) - if (!xbt_dynar_length(ROUTE(i, i))) { - if (!loopback) - loopback = link_new(xbt_strdup("__MSG_loopback__"), - 498000000, NULL, 0.000015, NULL, - SURF_LINK_ON, NULL, SURF_LINK_FATPIPE, NULL); - ROUTE(i, i) = xbt_dynar_new(sizeof(link_CM02_t),NULL); - xbt_dynar_push(ROUTE(i,i),&loopback); - } -} - -static void add_route(void) -{ - xbt_ex_t e; - int nb_link = 0; - unsigned int cpt = 0; - xbt_dict_cursor_t cursor = NULL; - char *key, *data, *end; - const char *sep = "#"; - xbt_dynar_t links, keys; - - if (routing_table == NULL) - create_routing_table(); - - xbt_dict_foreach(route_table, cursor, key, data) { - char *link_name = NULL; - nb_link = 0; - links = (xbt_dynar_t) data; - keys = xbt_str_split_str(key, sep); - - src_id = strtol(xbt_dynar_get_as(keys, 0, char *), &end, 16); - dst_id = strtol(xbt_dynar_get_as(keys, 1, char *), &end, 16); - xbt_dynar_free(&keys); - - xbt_dynar_foreach(links, cpt, link_name) { - TRY { - link_CM02_t link = xbt_dict_get(link_set, link_name); - xbt_dynar_push(ROUTE(src_id,dst_id),&link); - } - CATCH(e) { - RETHROW1("Link %s not found (dict raised this exception: %s)", link_name); - } - } - } - - int i,j; - for (i=0;iid */ - network_card_CM02_t card_src = src; - network_card_CM02_t card_dst = dst; - xbt_dynar_t route = ROUTE(card_src->id, card_dst->id); + xbt_dynar_t route = used_routing->get_route(src, dst); /* LARGE PLATFORMS HACK: total_route_size = route_size + src->link_nb + dst->nb */ unsigned int i; - XBT_IN4("(%s,%s,%g,%g)", card_src->generic_resource.name, card_dst->generic_resource.name, size, rate); + XBT_IN4("(%s,%s,%g,%g)", src_name, dst_name, size, rate); /* LARGE PLATFORMS HACK: assert on total_route_size */ xbt_assert2(xbt_dynar_length(route), - "You're trying to send data from %s to %s but there is no connection between these two cards.", - card_src->generic_resource.name, card_dst->generic_resource.name); + "You're trying to send data from %s to %s but there is no connection between these two hosts.", + src_name, dst_name); action = xbt_new0(s_surf_action_network_CM02_t, 1); @@ -567,14 +450,6 @@ static surf_action_t communicate(void *src, void *dst, double size, return (surf_action_t) action; } -/* returns an array of link_CM02_t */ -static xbt_dynar_t get_route(void *src, void *dst) -{ - network_card_CM02_t card_src = src; - network_card_CM02_t card_dst = dst; - return ROUTE(card_src->id, card_dst->id); -} - static double get_link_bandwidth(const void *link) { return ((link_CM02_t) link)->bw_current; @@ -626,26 +501,20 @@ static void action_set_max_duration(surf_action_t action, double duration) static void finalize(void) { - int i, j; - xbt_dict_free(&link_set); surf_model_exit(surf_network_model); surf_network_model = NULL; - loopback = NULL; - for (i = 0; i < host_number; i++) - for (j = 0; j < host_number; j++) - xbt_dynar_free(&ROUTE(i, j)); - free(routing_table); - routing_table = NULL; - host_number = 0; + used_routing->finalize(); + host_count = 0; lmm_system_free(network_maxmin_system); network_maxmin_system = NULL; } static void surf_network_model_init_internal(void) { + link_set = xbt_dict_new(); surf_network_model = surf_model_init(); surf_network_model->name = "network"; @@ -667,7 +536,6 @@ static void surf_network_model_init_internal(void) surf_cpu_model->set_max_duration = action_set_max_duration; surf_network_model->extension.network.communicate = communicate; - surf_network_model->extension.network.get_route = get_route; surf_network_model->extension.network.get_link_bandwidth = get_link_bandwidth; surf_network_model->extension.network.get_link_latency = get_link_latency; @@ -675,10 +543,13 @@ static void surf_network_model_init_internal(void) surf_network_model->get_properties = get_properties; - link_set = xbt_dict_new(); - if (!network_maxmin_system) network_maxmin_system = lmm_system_new(); + + routing_model_full_create(sizeof(link_CM02_t), + link_new(xbt_strdup("__loopback__"), + 498000000, NULL, 0.000015, NULL, + SURF_LINK_ON, NULL, SURF_LINK_FATPIPE, NULL)); } /************************************************************************/ diff --git a/src/surf/network_constant.c b/src/surf/network_constant.c index eba71de241..bc6f1bcb5a 100644 --- a/src/surf/network_constant.c +++ b/src/surf/network_constant.c @@ -163,14 +163,12 @@ static void update_resource_state(void *id, DIE_IMPOSSIBLE; } -static surf_action_t communicate(void *src, void *dst, double size, - double rate) +static surf_action_t communicate(const char *src_name,const char *dst_name,int src, int dst, double size, + double rate) { surf_action_network_Constant_t action = NULL; - network_card_Constant_t card_src = src; - network_card_Constant_t card_dst = dst; - XBT_IN4("(%s,%s,%g,%g)", card_src->generic_resource.name, card_dst->generic_resource.name, size, rate); + XBT_IN4("(%s,%s,%g,%g)", src_name, dst_name, size, rate); action = xbt_new0(s_surf_action_network_Constant_t, 1); @@ -279,7 +277,6 @@ static void surf_network_model_init_internal(void) surf_cpu_model->set_max_duration = action_set_max_duration; surf_network_model->extension.network.communicate = communicate; - surf_network_model->extension.network.get_route = get_route; surf_network_model->extension.network.get_link_bandwidth = get_link_bandwidth; surf_network_model->extension.network.get_link_latency = get_link_latency; diff --git a/src/surf/network_private.h b/src/surf/network_private.h index bf4c664ed0..eeac6d0a4e 100644 --- a/src/surf/network_private.h +++ b/src/surf/network_private.h @@ -28,11 +28,6 @@ typedef struct network_link_CM02 { } s_link_CM02_t, *link_CM02_t; -typedef struct network_card_CM02 { - s_surf_resource_t generic_resource; /* must remain first to allow casts */ - int id; -} s_network_card_CM02_t, *network_card_CM02_t; - typedef struct surf_action_network_CM02 { s_surf_action_t generic_action; double latency; @@ -41,13 +36,10 @@ typedef struct surf_action_network_CM02 { lmm_variable_t variable; double rate; int suspended; - network_card_CM02_t src; - network_card_CM02_t dst; +#ifdef KILLME + int src; + int dst; +#endif } s_surf_action_network_CM02_t, *surf_action_network_CM02_t; -extern int card_number; -extern xbt_dynar_t *routing_table; - -#define ROUTE(i,j) routing_table[(i)+(j)*host_number] - #endif /* _SURF_NETWORK_PRIVATE_H */ diff --git a/src/surf/surf_private.h b/src/surf/surf_private.h index 659bf9d9bb..95b0cf37d1 100644 --- a/src/surf/surf_private.h +++ b/src/surf/surf_private.h @@ -85,4 +85,17 @@ const char *__surf_get_initial_path(void); */ int __surf_is_absolute_file_path(const char *file_path); +/* + * Routing logic + */ +struct s_routing { + const char *name; + xbt_dict_t host_id; /* char* -> int* */ + + xbt_dynar_t (*get_route)(int src, int dst); + void (*finalize)(void); + int host_count; +}; +XBT_PUBLIC(routing_t) routing_model_full_create(size_t size_of_link,void *loopback); + #endif /* _SURF_SURF_PRIVATE_H */ diff --git a/src/surf/surf_routing.c b/src/surf/surf_routing.c new file mode 100644 index 0000000000..077027ad08 --- /dev/null +++ b/src/surf/surf_routing.c @@ -0,0 +1,149 @@ +/* Copyright (c) 2009 The SimGrid team. All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + +#include "surf_private.h" +#include "xbt/dynar.h" +#include "xbt/str.h" + +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route,surf,"Routing part of surf");// FIXME: connect this under windows + +typedef struct { + s_routing_t generic_routing; + xbt_dynar_t *routing_table; + void *loopback; + size_t size_of_link; +}s_routing_full_t,*routing_full_t; + +routing_t used_routing = NULL; +/* ************************************************************************** */ +/* *************************** FULL ROUTING ********************************* */ + +#define ROUTE_FULL(i,j) ((routing_full_t)used_routing)->routing_table[(i)+(j)*(used_routing)->host_count] + +/* + * Parsing + */ +static void routing_full_parse_Shost(void) { + int *val = xbt_malloc(sizeof(int)); + DEBUG2("Seen host %s (#%d)",A_surfxml_host_id,used_routing->host_count); + *val = used_routing->host_count++; + xbt_dict_set(used_routing->host_id,A_surfxml_host_id,val,xbt_free); +} +static int src_id = -1; +static int dst_id = -1; +static void routing_full_parse_Sroute_set_endpoints(void) +{ + src_id = *(int*)xbt_dict_get(used_routing->host_id,A_surfxml_route_src); + dst_id = *(int*)xbt_dict_get(used_routing->host_id,A_surfxml_route_dst); + DEBUG4("Route %s %d -> %s %d",A_surfxml_route_src,src_id,A_surfxml_route_dst,dst_id); + route_action = A_surfxml_route_action; +} +static void routing_full_parse_Eroute(void) +{ + char *name; + if (src_id != -1 && dst_id != -1) { + name = bprintf("%x#%x", src_id, dst_id); + manage_route(route_table, name, route_action, 0); + free(name); + } +} + + +static void routing_full_parse_end(void) { + routing_full_t routing = (routing_full_t) used_routing; + int nb_link = 0; + unsigned int cpt = 0; + xbt_dict_cursor_t cursor = NULL; + char *key, *data, *end; + const char *sep = "#"; + xbt_dynar_t links, keys; + char *link_name = NULL; + int i,j; + + int host_count = routing->generic_routing.host_count; + + /* Create the routing table */ + routing->routing_table = xbt_new0(xbt_dynar_t, host_count * host_count); + for (i=0;isize_of_link,NULL); + + /* Put the routes in position */ + xbt_dict_foreach(route_table, cursor, key, data) { + nb_link = 0; + links = (xbt_dynar_t) data; + keys = xbt_str_split_str(key, sep); + + src_id = strtol(xbt_dynar_get_as(keys, 0, char *), &end, 16); + dst_id = strtol(xbt_dynar_get_as(keys, 1, char *), &end, 16); + xbt_dynar_free(&keys); + + DEBUG4("Handle %d %d (from %d hosts): %ld links", + src_id,dst_id,routing->generic_routing.host_count,xbt_dynar_length(links)); + xbt_dynar_foreach(links, cpt, link_name) { + void* link = xbt_dict_get_or_null(link_set, link_name); + if (link) + xbt_dynar_push(ROUTE_FULL(src_id,dst_id),&link); + else + THROW1(mismatch_error,0,"Link %s not found", link_name); + } + } + + /* Add the loopback if needed */ + for (i = 0; i < host_count; i++) + if (!xbt_dynar_length(ROUTE_FULL(i, i))) + xbt_dynar_push(ROUTE_FULL(i,i),&routing->loopback); + + /* Shrink the dynar routes (save unused slots) */ + for (i=0;ihost_count; i++) + for (j = 0; j < used_routing->host_count; j++) + xbt_dynar_free(&ROUTE_FULL(i, j)); + free(routing->routing_table); + xbt_dict_free(&used_routing->host_id); + free(routing); + routing=NULL; + } +} + +routing_t routing_model_full_create(size_t size_of_link,void *loopback) { + /* initialize our structure */ + routing_full_t res = xbt_new0(s_routing_full_t,1); + res->generic_routing.name = "Full"; + res->generic_routing.host_count = 0; + res->generic_routing.get_route = routing_full_get_route; + res->generic_routing.finalize = routing_full_finalize; + res->size_of_link = size_of_link; + res->loopback = loopback; + + /* Set it in position */ + used_routing = (routing_t) res; + + /* Setup the parsing callbacks we need */ + used_routing->host_id = xbt_dict_new(); + surfxml_add_callback(STag_surfxml_host_cb_list, &routing_full_parse_Shost); + surfxml_add_callback(ETag_surfxml_platform_cb_list, &routing_full_parse_end); + surfxml_add_callback(STag_surfxml_route_cb_list, + &routing_full_parse_Sroute_set_endpoints); + surfxml_add_callback(ETag_surfxml_route_cb_list, &routing_full_parse_Eroute); + + return used_routing; +} diff --git a/src/surf/workstation.c b/src/surf/workstation.c index ebe0a00469..1fb839751e 100644 --- a/src/surf/workstation.c +++ b/src/surf/workstation.c @@ -18,14 +18,14 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_workstation, surf, surf_model_t surf_workstation_model = NULL; static workstation_CLM03_t workstation_new(const char *name, - void *cpu, void *card) + void *cpu, int id) { workstation_CLM03_t workstation = xbt_new0(s_workstation_CLM03_t, 1); workstation->generic_resource.model = surf_workstation_model; workstation->generic_resource.name = xbt_strdup(name); workstation->cpu = cpu; - workstation->network_card = card; + workstation->id = id; xbt_dict_set(surf_model_resource_set(surf_workstation_model), name, workstation, surf_resource_free); @@ -38,13 +38,12 @@ void create_workstations(void) xbt_dict_cursor_t cursor = NULL; char *name = NULL; void *cpu = NULL; - void *nw_card = NULL; xbt_dict_foreach(surf_model_resource_set(surf_cpu_model), cursor, name, cpu) { - nw_card = surf_model_resource_by_name(surf_network_model, name); - xbt_assert1(nw_card, "No corresponding card found for %s", name); + int *id = xbt_dict_get_or_null(used_routing->host_id,name); + xbt_assert1(id, "No host %s found in the platform file", name); - workstation_new(name, cpu, nw_card); + workstation_new(name, cpu, *id); } } @@ -185,10 +184,12 @@ static surf_action_t communicate(void *workstation_src, void *workstation_dst, double size, double rate) { + workstation_CLM03_t src = (workstation_CLM03_t) workstation_src; + workstation_CLM03_t dst = (workstation_CLM03_t) workstation_dst; return surf_network_model->extension. - network.communicate(((workstation_CLM03_t) workstation_src)->network_card, - ((workstation_CLM03_t) workstation_dst)->network_card, - size, rate); + network.communicate(surf_resource_name(src->cpu),surf_resource_name(dst->cpu), + src->id,dst->id, + size, rate); } static e_surf_cpu_state_t get_state(void *workstation) @@ -231,10 +232,8 @@ static xbt_dynar_t get_route(void *src, void *dst) { workstation_CLM03_t workstation_src = (workstation_CLM03_t) src; workstation_CLM03_t workstation_dst = (workstation_CLM03_t) dst; - return surf_network_model->extension.network.get_route(workstation_src-> - network_card, - workstation_dst-> - network_card); + return surf_network_model->extension.network.get_route(workstation_src->id, + workstation_dst->id); } static double get_link_bandwidth(const void *link) @@ -292,9 +291,9 @@ static void surf_workstation_model_init_internal(void) surf_workstation_model->get_properties = get_properties; surf_workstation_model->extension.workstation.communicate = communicate; + surf_workstation_model->extension.workstation.get_route = get_route; surf_workstation_model->extension.workstation.execute_parallel_task = execute_parallel_task; - surf_workstation_model->extension.workstation.get_route = get_route; surf_workstation_model->extension.workstation.get_link_bandwidth = get_link_bandwidth; surf_workstation_model->extension.workstation.get_link_latency = diff --git a/src/surf/workstation_private.h b/src/surf/workstation_private.h index 0eb1248e17..6aafb39cd5 100644 --- a/src/surf/workstation_private.h +++ b/src/surf/workstation_private.h @@ -13,7 +13,7 @@ typedef struct workstation_CLM03 { s_surf_resource_t generic_resource; /* Must remain first to add this to a trace */ void *cpu; - void *network_card; + int id; } s_workstation_CLM03_t, *workstation_CLM03_t; typedef struct surf_action_parallel_task_CSL05 { diff --git a/src/surf/workstation_ptask_L07.c b/src/surf/workstation_ptask_L07.c index e722a5e5c2..214f0333d6 100644 --- a/src/surf/workstation_ptask_L07.c +++ b/src/surf/workstation_ptask_L07.c @@ -66,10 +66,7 @@ typedef struct surf_action_workstation_L07 { XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_workstation); -static int nb_workstation = 0; -static xbt_dynar_t *routing_table = NULL; -#define ROUTE(i,j) routing_table[(i)+(j)*nb_workstation] -static link_L07_t loopback = NULL; +static int host_count = 0; static xbt_dict_t parallel_task_link_set = NULL; lmm_system_t ptask_maxmin_system = NULL; @@ -87,7 +84,7 @@ static void update_action_bound(surf_action_workstation_L07_t action) for (j = 0; j < workstation_nb; j++) { cpu_L07_t card_src = action->workstation_list[i]; cpu_L07_t card_dst = action->workstation_list[j]; - xbt_dynar_t route = ROUTE(card_src->id, card_dst->id); + xbt_dynar_t route = used_routing->get_route(card_src->id, card_dst->id); double lat = 0.0; if (action->communication_amount[i * workstation_nb + j] > 0) { @@ -386,8 +383,6 @@ static void update_resource_state(void *id, static void finalize(void) { - int i, j; - xbt_dict_free(&link_set); if (parallel_task_link_set != NULL) { xbt_dict_free(¶llel_task_link_set); @@ -395,13 +390,9 @@ static void finalize(void) surf_model_exit(surf_workstation_model); surf_workstation_model = NULL; + used_routing->finalize(); - for (i = 0; i < nb_workstation; i++) - for (j = 0; j < nb_workstation; j++) - xbt_dynar_free(&ROUTE(i, j)); - free(routing_table); - routing_table = NULL; - nb_workstation = 0; + host_count = 0; // FIXME: KILLME? if (ptask_maxmin_system) { lmm_system_free(ptask_maxmin_system); @@ -452,7 +443,7 @@ static surf_action_t execute_parallel_task(int workstation_nb, cpu_L07_t card_src = workstation_list[i]; cpu_L07_t card_dst = workstation_list[j]; link_L07_t link; - xbt_dynar_t route = ROUTE(card_src->id, card_dst->id); + xbt_dynar_t route = used_routing->get_route(card_src->id, card_dst->id); double lat = 0.0; if (communication_amount[i * workstation_nb + j] > 0) @@ -513,7 +504,7 @@ static surf_action_t execute_parallel_task(int workstation_nb, cpu_L07_t card_src = workstation_list[i]; cpu_L07_t card_dst = workstation_list[j]; link_L07_t link; - xbt_dynar_t route = ROUTE(card_src->id, card_dst->id); + xbt_dynar_t route = used_routing->get_route(card_src->id, card_dst->id); if (communication_amount[i * workstation_nb + j] == 0.0) continue; @@ -581,13 +572,12 @@ static surf_action_t action_sleep(void *cpu, double duration) return (surf_action_t) action; } -/* returns a dynar of link_L07_t */ static xbt_dynar_t get_route(void *src, void *dst) { - cpu_L07_t card_src = src; - cpu_L07_t card_dst = dst; + cpu_L07_t host_src = src; + cpu_L07_t host_dst = dst; - return ROUTE(card_src->id, card_dst->id); + return used_routing->get_route(host_src->id, host_dst->id); } static double get_link_bandwidth(const void *link) @@ -628,7 +618,7 @@ static cpu_L07_t cpu_new(const char *name, double power_scale, cpu->generic_resource.model = surf_workstation_model; cpu->type = SURF_WORKSTATION_RESOURCE_CPU; cpu->generic_resource.name = xbt_strdup(name); - cpu->id = nb_workstation++; + cpu->id = host_count++; cpu->power_scale = power_scale; xbt_assert0(cpu->power_scale > 0, "Power has to be >0"); @@ -656,16 +646,6 @@ static cpu_L07_t cpu_new(const char *name, double power_scale, return cpu; } -static void create_routing_table(void) -{ - int i,j; - routing_table = xbt_new0(xbt_dynar_t, /*card_number * card_number */ - nb_workstation * nb_workstation); - for (i=0;iid; - - cpu_tmp = - (cpu_L07_t) surf_model_resource_by_name(surf_workstation_model, - A_surfxml_route_dst); - xbt_assert1(cpu_tmp, "Invalid cpu %s", A_surfxml_route_dst); - if (cpu_tmp != NULL) - dst_id = cpu_tmp->id; - - route_action = A_surfxml_route_action; -} - -static void parse_route_set_route(void) -{ - char *name; - if (src_id != -1 && dst_id != -1) { - name = bprintf("%x#%x", src_id, dst_id); - manage_route(route_table, name, route_action, 0); - free(name); - } -} - -static void add_loopback(void) -{ - int i; - - /* Adding loopback if needed */ - for (i = 0; i < nb_workstation; i++) - if (!xbt_dynar_length(ROUTE(i, i))) { - if (!loopback) - loopback = link_new(xbt_strdup("__MSG_loopback__"), - 498000000, NULL, 0.000015, NULL, - SURF_LINK_ON, NULL, SURF_LINK_FATPIPE, NULL); - - xbt_dynar_push(ROUTE(i,i),&loopback); - } -} - -static void add_route(void) -{ - xbt_ex_t e; - int nb_link = 0; - unsigned int cpt = 0; - xbt_dict_cursor_t cursor = NULL; - char *key, *data, *end; - const char *sep = "#"; - xbt_dynar_t links, keys; - char *link_name = NULL; - - if (routing_table == NULL) - create_routing_table(); - - xbt_dict_foreach(route_table, cursor, key, data) { - nb_link = 0; - links = (xbt_dynar_t) data; - keys = xbt_str_split_str(key, sep); - - src_id = strtol(xbt_dynar_get_as(keys, 0, char *), &end, 16); - dst_id = strtol(xbt_dynar_get_as(keys, 1, char *), &end, 16); - xbt_dynar_free(&keys); - - xbt_dynar_foreach(links, cpt, link_name) { - TRY { - link_L07_t link = xbt_dict_get(link_set, link_name); - xbt_dynar_push(ROUTE(src_id,dst_id),&link); - } - CATCH(e) { - RETHROW1("Link %s not found (dict raised this exception: %s)", link_name); - } - } - } -} - static void add_traces(void) { xbt_dict_cursor_t cursor = NULL; @@ -933,11 +828,6 @@ static void define_callbacks(const char *file) surf_parse_reset_parser(); surfxml_add_callback(STag_surfxml_host_cb_list, &parse_cpu_init); surfxml_add_callback(STag_surfxml_link_cb_list, &parse_link_init); - surfxml_add_callback(STag_surfxml_route_cb_list, - &parse_route_set_endpoints); - surfxml_add_callback(ETag_surfxml_route_cb_list, &parse_route_set_route); - surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_route); - surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_loopback); surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_traces); } @@ -976,9 +866,9 @@ static void model_init_internal(void) surf_workstation_model->extension.workstation.get_available_speed = get_available_speed; surf_workstation_model->extension.workstation.communicate = communicate; + surf_workstation_model->extension.workstation.get_route = get_route; surf_workstation_model->extension.workstation.execute_parallel_task = execute_parallel_task; - surf_workstation_model->extension.workstation.get_route = get_route; surf_workstation_model->extension.workstation.get_link_bandwidth = get_link_bandwidth; surf_workstation_model->extension.workstation.get_link_latency = @@ -991,6 +881,12 @@ static void model_init_internal(void) if (!ptask_maxmin_system) ptask_maxmin_system = lmm_system_new(); + + routing_model_full_create(sizeof(link_L07_t), + link_new(xbt_strdup("__MSG_loopback__"), + 498000000, NULL, 0.000015, NULL, + SURF_LINK_ON, NULL, SURF_LINK_FATPIPE, NULL)); + } /**************************************/ @@ -1000,8 +896,8 @@ void surf_workstation_model_init_ptask_L07(const char *filename) { xbt_assert0(!surf_cpu_model, "CPU model type already defined"); xbt_assert0(!surf_network_model, "network model type already defined"); - model_init_internal(); define_callbacks(filename); + model_init_internal(); update_model_description(surf_workstation_model_description, "ptask_L07", surf_workstation_model); -- 2.20.1