From: Martin Quinson Date: Tue, 8 Nov 2011 15:00:57 +0000 (+0100) Subject: integrate the peer creation in sg_platf properly X-Git-Tag: exp_20120216~419 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/b9c9ef88e5a31a819e1f197b563974705e6d6805 integrate the peer creation in sg_platf properly --- diff --git a/include/simgrid/platf.h b/include/simgrid/platf.h index e17d1b28f9..ec702b43e1 100644 --- a/include/simgrid/platf.h +++ b/include/simgrid/platf.h @@ -68,6 +68,18 @@ typedef struct { xbt_dict_t properties; } s_sg_platf_link_cbarg_t, *sg_platf_link_cbarg_t; +typedef struct s_surf_parsing_peer_arg *sg_platf_peer_cbarg_t; +typedef struct s_surf_parsing_peer_arg { + const char* id; + double power; + double bw_in; + double bw_out; + double lat; + const char* coord; + tmgr_trace_t availability_trace; + tmgr_trace_t state_trace; +} s_surf_parsing_peer_arg_t; + XBT_PUBLIC(void) sg_platf_open(void); // Start a new platform XBT_PUBLIC(void) sg_platf_close(void); // Finish the creation of the platform @@ -78,6 +90,7 @@ XBT_PUBLIC(void) sg_platf_new_AS_close(void); // That XBT_PUBLIC(void) sg_platf_new_host (sg_platf_host_cbarg_t host); // Add an host to the currently described AS XBT_PUBLIC(void) sg_platf_new_router(sg_platf_router_cbarg_t router); // Add a router to the currently described AS XBT_PUBLIC(void) sg_platf_new_link (sg_platf_link_cbarg_t link); // Add a link to the currently described AS +XBT_PUBLIC(void) sg_platf_new_peer(sg_platf_peer_cbarg_t peer); // Add a peer to the currently described AS #endif /* SG_PLATF_H */ diff --git a/src/include/simgrid/platf_interface.h b/src/include/simgrid/platf_interface.h index 69f3286bcf..4afc6ed1ea 100644 --- a/src/include/simgrid/platf_interface.h +++ b/src/include/simgrid/platf_interface.h @@ -20,10 +20,12 @@ void sg_platf_exit(void); typedef void (*sg_platf_host_cb_t)(sg_platf_host_cbarg_t); typedef void (*sg_platf_router_cb_t)(sg_platf_router_cbarg_t); typedef void (*sg_platf_link_cb_t)(sg_platf_link_cbarg_t); +typedef void (*sg_platf_peer_cb_t)(sg_platf_peer_cbarg_t); void sg_platf_host_add_cb(sg_platf_host_cb_t); void sg_platf_router_add_cb(sg_platf_router_cb_t); void sg_platf_link_add_cb(sg_platf_link_cb_t); +void sg_platf_peer_add_cb(sg_platf_peer_cb_t fct); void sg_platf_postparse_add_cb(void_f_void_t fct); diff --git a/src/include/surf/surfxml_parse_values.h b/src/include/surf/surfxml_parse_values.h index bbd97c7dfb..5cc5762c9e 100644 --- a/src/include/surf/surfxml_parse_values.h +++ b/src/include/surf/surfxml_parse_values.h @@ -7,17 +7,6 @@ #ifndef SURFXML_PARSE_VALUES_H_ #define SURFXML_PARSE_VALUES_H_ -typedef struct s_surf_parsing_peer_arg *surf_parsing_peer_arg_t; -typedef struct s_surf_parsing_peer_arg { - const char* id; - double power; - double bw_in; - double bw_out; - double lat; - const char* coord; - tmgr_trace_t availability_trace; - tmgr_trace_t state_trace; -} s_surf_parsing_peer_arg_t; typedef struct s_surf_parsing_cluster_arg *surf_parsing_cluster_arg_t; typedef struct s_surf_parsing_cluster_arg { @@ -46,6 +35,5 @@ typedef struct s_surf_parsing_link_up_down { extern surf_parsing_cluster_arg_t struct_cluster; -extern surf_parsing_peer_arg_t struct_peer; #endif /* SURFXML_PARSE_VALUES_H_ */ diff --git a/src/surf/sg_platf.c b/src/surf/sg_platf.c index c111a400c8..f19336a855 100644 --- a/src/surf/sg_platf.c +++ b/src/surf/sg_platf.c @@ -14,6 +14,7 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_parse); xbt_dynar_t sg_platf_host_cb_list = NULL; // of sg_platf_host_cb_t xbt_dynar_t sg_platf_link_cb_list = NULL; // of sg_platf_link_cb_t xbt_dynar_t sg_platf_router_cb_list = NULL; // of sg_platf_router_cb_t +xbt_dynar_t sg_platf_peer_cb_list = NULL; // of sg_platf_peer_cb_t xbt_dynar_t sg_platf_postparse_cb_list = NULL; // of void_f_void_t /** Module management function: creates all internal data structures */ @@ -21,6 +22,7 @@ void sg_platf_init(void) { sg_platf_host_cb_list = xbt_dynar_new(sizeof(sg_platf_host_cb_t), NULL); sg_platf_router_cb_list = xbt_dynar_new(sizeof(sg_platf_host_cb_t), NULL); sg_platf_link_cb_list = xbt_dynar_new(sizeof(sg_platf_host_cb_t), NULL); + sg_platf_peer_cb_list = xbt_dynar_new(sizeof(sg_platf_peer_cb_t), NULL); sg_platf_postparse_cb_list = xbt_dynar_new(sizeof(sg_platf_link_cb_t),NULL); } /** Module management function: frees all internal data structures */ @@ -28,6 +30,7 @@ void sg_platf_exit(void) { xbt_dynar_free(&sg_platf_host_cb_list); xbt_dynar_free(&sg_platf_router_cb_list); xbt_dynar_free(&sg_platf_postparse_cb_list); + xbt_dynar_free(&sg_platf_peer_cb_list); } void sg_platf_new_host(sg_platf_host_cbarg_t h){ @@ -51,6 +54,13 @@ void sg_platf_new_link(sg_platf_link_cbarg_t link){ (*fun) (link); } } +void sg_platf_new_peer(sg_platf_peer_cbarg_t peer){ + unsigned int iterator; + sg_platf_peer_cb_t fun; + xbt_dynar_foreach(sg_platf_link_cb_list, iterator, fun) { + (*fun) (peer); + } +} void sg_platf_open() { /* Do nothing: just for symmetry of user code */ } @@ -72,6 +82,9 @@ void sg_platf_link_add_cb(sg_platf_link_cb_t fct) { void sg_platf_router_add_cb(sg_platf_router_cb_t fct) { xbt_dynar_push(sg_platf_router_cb_list, &fct); } +void sg_platf_peer_add_cb(sg_platf_peer_cb_t fct) { + xbt_dynar_push(sg_platf_peer_cb_list, &fct); +} void sg_platf_postparse_add_cb(void_f_void_t fct) { xbt_dynar_push(sg_platf_postparse_cb_list, &fct); } diff --git a/src/surf/surf_routing.c b/src/surf/surf_routing.c index 9f6f2e2411..cb103a7a2b 100644 --- a/src/surf/surf_routing.c +++ b/src/surf/surf_routing.c @@ -51,7 +51,7 @@ xbt_dict_t cluster_host_link = NULL; /* for tag cluster */ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route, surf, "Routing part of surf"); -static void routing_parse_Speer(void); /* peer bypass */ +static void routing_parse_Speer(sg_platf_peer_cbarg_t peer); /* peer bypass */ static void routing_parse_Srandom(void); /* random bypass */ static char* replace_random_parameter(char * chaine); @@ -897,9 +897,7 @@ void routing_model_create(size_t size_of_links, void *loopback, double_f_cpvoid_ surfxml_add_callback(STag_surfxml_cluster_cb_list, &routing_parse_Scluster); - surfxml_add_callback(STag_surfxml_peer_cb_list, - &routing_parse_Speer); - + sg_platf_peer_add_cb(routing_parse_Speer); // FIXME: inline in the sg_platf_new_peer instead sg_platf_postparse_add_cb(clean_routing_after_parse); #ifdef HAVE_TRACING @@ -1704,7 +1702,7 @@ static void clean_routing_after_parse(void) xbt_dict_free(&patterns); } -static void routing_parse_Speer(void) +static void routing_parse_Speer(sg_platf_peer_cbarg_t peer) { static int AX_ptr = 0; char *host_id = NULL; @@ -1717,51 +1715,51 @@ static void routing_parse_Speer(void) surfxml_bufferstack_push(1); - XBT_DEBUG("", struct_peer->id); - sg_platf_new_AS_open(struct_peer->id, "Full"); + XBT_DEBUG("", peer->id); + sg_platf_new_AS_open(peer->id, "Full"); XBT_DEBUG(" "); - host_id = HOST_PEER(struct_peer->id); - router_id = ROUTER_PEER(struct_peer->id); - link_id_up = LINK_UP_PEER(struct_peer->id); - link_id_down = LINK_DOWN_PEER(struct_peer->id); + host_id = HOST_PEER(peer->id); + router_id = ROUTER_PEER(peer->id); + link_id_up = LINK_UP_PEER(peer->id); + link_id_down = LINK_DOWN_PEER(peer->id); - link_router = bprintf("%s_link_router", struct_peer->id); - link_backbone = bprintf("%s_backbone", struct_peer->id); + link_router = bprintf("%s_link_router", peer->id); + link_backbone = bprintf("%s_backbone", peer->id); - XBT_DEBUG("", host_id, struct_peer->power); + XBT_DEBUG("", host_id, peer->power); s_sg_platf_host_cbarg_t host; memset(&host,0,sizeof(host)); host.initial_state = SURF_RESOURCE_ON; host.id = host_id; - host.power_peak = struct_peer->power; + host.power_peak = peer->power; host.power_scale = 1.0; - host.power_trace = struct_peer->availability_trace; - host.state_trace = struct_peer->state_trace; + host.power_trace = peer->availability_trace; + host.state_trace = peer->state_trace; host.core_amount = 1; sg_platf_new_host(&host); - XBT_DEBUG("", router_id, struct_peer->coord); + XBT_DEBUG("", router_id, peer->coord); s_sg_platf_router_cbarg_t router; memset(&router,0,sizeof(router)); router.id = router_id; - router.coord = struct_peer->coord; + router.coord = peer->coord; sg_platf_new_router(&router); - XBT_DEBUG("", link_id_up, struct_peer->bw_in, struct_peer->lat); + XBT_DEBUG("", link_id_up, peer->bw_in, peer->lat); s_sg_platf_link_cbarg_t link; memset(&link,0,sizeof(link)); link.state = SURF_RESOURCE_ON; link.policy = SURF_LINK_SHARED; link.id = link_id_up; - link.bandwidth = struct_peer->bw_in; - link.latency = struct_peer->lat; + link.bandwidth = peer->bw_in; + link.latency = peer->lat; sg_platf_new_link(&link); // FIXME: dealing with full duplex is not the role of this piece of code, I'd say [Mt] // Instead, it should be created fullduplex, and the models will do what's needed in this case - XBT_DEBUG("", link_id_down, struct_peer->bw_out, struct_peer->lat); + XBT_DEBUG("", link_id_down, peer->bw_out, peer->lat); link.id = link_id_down; sg_platf_new_link(&link); diff --git a/src/surf/surfxml_parse.c b/src/surf/surfxml_parse.c index 756f83752f..9235b3cecd 100644 --- a/src/surf/surfxml_parse.c +++ b/src/surf/surfxml_parse.c @@ -337,20 +337,22 @@ void ETag_surfxml_cluster(void){ } void STag_surfxml_peer(void){ - struct_peer = xbt_new0(s_surf_parsing_peer_arg_t, 1); - struct_peer->id = A_surfxml_peer_id; - struct_peer->power = surf_parse_get_double(A_surfxml_peer_power); - struct_peer->bw_in = surf_parse_get_double(A_surfxml_peer_bw_in); - struct_peer->bw_out = surf_parse_get_double(A_surfxml_peer_bw_out); - struct_peer->lat = surf_parse_get_double(A_surfxml_peer_lat); - struct_peer->coord = A_surfxml_peer_coordinates; - struct_peer->availability_trace = tmgr_trace_new(A_surfxml_peer_availability_file); - struct_peer->state_trace = tmgr_trace_new(A_surfxml_peer_state_file); + s_surf_parsing_peer_arg_t peer; + memset(&peer,0,sizeof(peer)); + peer.id = A_surfxml_peer_id; + peer.power = surf_parse_get_double(A_surfxml_peer_power); + peer.bw_in = surf_parse_get_double(A_surfxml_peer_bw_in); + peer.bw_out = surf_parse_get_double(A_surfxml_peer_bw_out); + peer.lat = surf_parse_get_double(A_surfxml_peer_lat); + peer.coord = A_surfxml_peer_coordinates; + peer.availability_trace = tmgr_trace_new(A_surfxml_peer_availability_file); + peer.state_trace = tmgr_trace_new(A_surfxml_peer_state_file); + surfxml_call_cb_functions(STag_surfxml_peer_cb_list); + sg_platf_new_peer(&peer); } void ETag_surfxml_peer(void){ - surfxml_call_cb_functions(ETag_surfxml_peer_cb_list); - xbt_free(struct_peer); + /* nothing to do here */ } void STag_surfxml_link(void){ s_sg_platf_link_cbarg_t link; diff --git a/src/surf/surfxml_parseplatf.c b/src/surf/surfxml_parseplatf.c index 4445475156..f1d0d4bd46 100644 --- a/src/surf/surfxml_parseplatf.c +++ b/src/surf/surfxml_parseplatf.c @@ -54,7 +54,6 @@ void surfxml_bufferstack_pop(int new) */ surf_parsing_cluster_arg_t struct_cluster = NULL; -surf_parsing_peer_arg_t struct_peer = NULL; /* * Trace related stuff