From b4b2e66a3e8b0f5e84729c3d57a3cfd17a894bd5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Baptiste=20Herv=C3=A9?= Date: Fri, 3 Aug 2012 14:00:49 +0200 Subject: [PATCH 1/1] Platform generation can now be used with MSG Some stuff had to be done by SIMIX and MSG right after the XML platform parsing. It is now done by callbacks, registered in SURF at initialization. So that stuff is also done when you create a random platform with the generator. Add some ugly code to avoid the deletion of these registered callbacks before the parsing. --- src/msg/msg_environment.c | 6 ++++-- src/msg/msg_global.c | 2 ++ src/msg/msg_private.h | 2 ++ src/simix/smx_environment.c | 12 ++++++++---- src/simix/smx_global.c | 5 +++++ src/simix/smx_private.h | 3 +++ src/surf/platf_generator.c | 1 - src/surf/sg_platf.c | 5 +++++ src/surf/surfxml_parseplatf.c | 2 +- 9 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/msg/msg_environment.c b/src/msg/msg_environment.c index 5814f78189..eb889cbe3d 100644 --- a/src/msg/msg_environment.c +++ b/src/msg/msg_environment.c @@ -34,12 +34,14 @@ */ void MSG_create_environment(const char *file) { + SIMIX_create_environment(file); +} + +void MSG_post_create_environment(void) { xbt_lib_cursor_t cursor; void **data; char *name; - SIMIX_create_environment(file); - /* Initialize MSG hosts */ xbt_lib_foreach(host_lib, cursor, name, data) { if(data[SIMIX_HOST_LEVEL]) diff --git a/src/msg/msg_global.c b/src/msg/msg_global.c index 16f3507a33..dc424fc00b 100644 --- a/src/msg/msg_global.c +++ b/src/msg/msg_global.c @@ -59,6 +59,8 @@ void MSG_init_nocheck(int *argc, char **argv) { SIMIX_function_register_process_create(MSG_process_create_from_SIMIX); SIMIX_function_register_process_cleanup(MSG_process_cleanup_from_SIMIX); + + sg_platf_postparse_add_cb(MSG_post_create_environment); } #ifdef HAVE_TRACING TRACE_start(); diff --git a/src/msg/msg_private.h b/src/msg/msg_private.h index 97af923ebf..6c9544580a 100644 --- a/src/msg/msg_private.h +++ b/src/msg/msg_private.h @@ -153,5 +153,7 @@ void MSG_comm_copy_data_from_SIMIX(smx_action_t comm, void* buff, size_t buff_si void _MSG_action_init(void); void _MSG_action_exit(void); +void MSG_post_create_environment(void); + SG_END_DECL() #endif diff --git a/src/simix/smx_environment.c b/src/simix/smx_environment.c index 76c1e32e94..dd4709a949 100644 --- a/src/simix/smx_environment.c +++ b/src/simix/smx_environment.c @@ -33,10 +33,6 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_environment, simix, */ void SIMIX_create_environment(const char *file) { - xbt_lib_cursor_t cursor = NULL; - char *name = NULL; - void **workstation = NULL; - double start, end; start = xbt_os_time(); @@ -44,6 +40,14 @@ void SIMIX_create_environment(const char *file) end = xbt_os_time(); XBT_DEBUG("PARSE TIME: %lg", (end - start)); +} + +void SIMIX_post_create_environment(void) { + + void **workstation = NULL; + xbt_lib_cursor_t cursor = NULL; + char *name = NULL; + xbt_lib_foreach(host_lib, cursor, name, workstation) { if(workstation[SURF_WKS_LEVEL]) SIMIX_host_create(name, workstation[SURF_WKS_LEVEL], NULL); diff --git a/src/simix/smx_global.c b/src/simix/smx_global.c index db0f05141d..57020ba970 100644 --- a/src/simix/smx_global.c +++ b/src/simix/smx_global.c @@ -95,6 +95,11 @@ void SIMIX_global_init(int *argc, char **argv) /* Prepare to display some more info when dying on Ctrl-C pressing */ signal(SIGINT, inthandler); + + /* register a function to be called by SURF after the environment creation */ + sg_platf_init(); + sg_platf_postparse_add_cb(SIMIX_post_create_environment); + } if (!simix_timers) { simix_timers = xbt_heap_new(8, &free); diff --git a/src/simix/smx_private.h b/src/simix/smx_private.h index 8dcf056d79..88bd7b7661 100644 --- a/src/simix/smx_private.h +++ b/src/simix/smx_private.h @@ -309,4 +309,7 @@ static XBT_INLINE void* SIMIX_context_get_data(smx_context_t context) } XBT_PUBLIC(int) SIMIX_process_get_maxpid(void); + +void SIMIX_post_create_environment(void); + #endif diff --git a/src/surf/platf_generator.c b/src/surf/platf_generator.c index 895e9f8dc2..0726ae8e7e 100644 --- a/src/surf/platf_generator.c +++ b/src/surf/platf_generator.c @@ -383,7 +383,6 @@ void platf_generate(void) { nodes = xbt_graph_get_nodes(platform_graph); - sg_platf_init(); sg_platf_begin(); surf_parse_init_callbacks(); routing_register_callbacks(); diff --git a/src/surf/sg_platf.c b/src/surf/sg_platf.c index 874a00004d..0e4060fbb6 100644 --- a/src/surf/sg_platf.c +++ b/src/surf/sg_platf.c @@ -35,6 +35,11 @@ static RngStream sg_platf_rng_stream = NULL; /** Module management function: creates all internal data structures */ void sg_platf_init(void) { + + //FIXME : Ugly, but useful... + if(sg_platf_host_cb_list) + return; //Already initialized, so do nothing... + sg_platf_host_cb_list = xbt_dynar_new(sizeof(sg_platf_host_cb_t), NULL); sg_platf_host_link_cb_list = xbt_dynar_new(sizeof(sg_platf_host_link_cb_t), NULL); sg_platf_router_cb_list = xbt_dynar_new(sizeof(sg_platf_host_cb_t), NULL); diff --git a/src/surf/surfxml_parseplatf.c b/src/surf/surfxml_parseplatf.c index 9555060ffe..631c6de1b3 100644 --- a/src/surf/surfxml_parseplatf.c +++ b/src/surf/surfxml_parseplatf.c @@ -134,7 +134,7 @@ void parse_platform_file(const char *file) { int parse_status; - surf_parse_reset_callbacks(); + surf_parse_init_callbacks(); /* Register classical callbacks */ surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties); -- 2.20.1