From a89587facecc0a7ac72c72243fedf75638374d2a Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Tue, 1 Oct 2013 15:15:24 +0200 Subject: [PATCH] Try to exit in a more valgrind friendly manner when help is requested. --- src/include/simgrid/sg_config.h | 1 + src/instr/instr_config.c | 1 + src/simdag/sd_global.c | 5 +++++ src/simgrid/sg_config.c | 24 ++++++++++++++---------- src/simix/smx_global.c | 9 ++++++++- 5 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/include/simgrid/sg_config.h b/src/include/simgrid/sg_config.h index d0e93c449d..e4142a9e1a 100644 --- a/src/include/simgrid/sg_config.h +++ b/src/include/simgrid/sg_config.h @@ -11,6 +11,7 @@ /*******************************************/ XBT_PUBLIC_DATA(xbt_cfg_t) _sg_cfg_set; XBT_PUBLIC_DATA(int) _sg_cfg_init_status; +XBT_PUBLIC_DATA(int) _sg_cfg_exit_asap; XBT_PUBLIC(int) sg_cfg_get_int(const char* name); XBT_PUBLIC(double) sg_cfg_get_double(const char* name); XBT_PUBLIC(char*) sg_cfg_get_string(const char* name); diff --git a/src/instr/instr_config.c b/src/instr/instr_config.c index 3339f1a452..3ef4c714e7 100644 --- a/src/instr/instr_config.c +++ b/src/instr/instr_config.c @@ -181,6 +181,7 @@ int TRACE_end() XBT_DEBUG("Tracing is off"); XBT_DEBUG("Tracing system is shutdown"); } + xbt_dynar_free(&TRACE_start_functions); /* useful when exiting early */ xbt_dynar_free(&TRACE_end_functions); return retval; } diff --git a/src/simdag/sd_global.c b/src/simdag/sd_global.c index 21b640d8f9..54feb2d027 100644 --- a/src/simdag/sd_global.c +++ b/src/simdag/sd_global.c @@ -96,6 +96,11 @@ void SD_init(int *argc, char **argv) SD_HOST_LEVEL = xbt_lib_add_level(host_lib,__SD_workstation_destroy); SD_LINK_LEVEL = xbt_lib_add_level(link_lib,__SD_link_destroy); SD_STORAGE_LEVEL = xbt_lib_add_level(storage_lib,__SD_storage_destroy); + + if (_sg_cfg_exit_asap) { + SD_exit(); + exit(0); + } } /** \brief set a configuration variable diff --git a/src/simgrid/sg_config.c b/src/simgrid/sg_config.c index 34e5b43f32..5365b6408d 100644 --- a/src/simgrid/sg_config.c +++ b/src/simgrid/sg_config.c @@ -35,6 +35,12 @@ xbt_cfg_t _sg_cfg_set = NULL; */ int _sg_cfg_init_status = 0; +/* instruct the upper layer (simix or simdag) to exit as soon as possible + */ +int _sg_cfg_exit_asap = 0; + +#define sg_cfg_exit_early() do { _sg_cfg_exit_asap = 1; return; } while (0) + /* Parse the command line, looking for options */ static void sg_config_cmd_line(int *argc, char **argv) { @@ -96,10 +102,8 @@ static void sg_config_cmd_line(int *argc, char **argv) argv[j] = NULL; *argc = j; } - if (shall_exit) { - _sg_cfg_init_status = 1; // get everything cleanly cleaned on exit - exit(0); - } + if (shall_exit) + sg_cfg_exit_early(); } /* callback of the workstation/model variable */ @@ -114,7 +118,7 @@ static void _sg_cfg_cb__workstation_model(const char *name, int pos) if (!strcmp(val, "help")) { model_help("workstation", surf_workstation_model_description); - exit(0); + sg_cfg_exit_early(); } /* Make sure that the model exists */ @@ -133,7 +137,7 @@ static void _sg_cfg_cb__cpu_model(const char *name, int pos) if (!strcmp(val, "help")) { model_help("CPU", surf_cpu_model_description); - exit(0); + sg_cfg_exit_early(); } /* New Module missing */ @@ -152,7 +156,7 @@ static void _sg_cfg_cb__optimization_mode(const char *name, int pos) if (!strcmp(val, "help")) { model_help("optimization", surf_optimization_mode_description); - exit(0); + sg_cfg_exit_early(); } /* New Module missing */ @@ -171,7 +175,7 @@ static void _sg_cfg_cb__storage_mode(const char *name, int pos) if (!strcmp(val, "help")) { model_help("storage", surf_storage_model_description); - exit(0); + sg_cfg_exit_early(); } /* New Module missing */ @@ -190,7 +194,7 @@ static void _sg_cfg_cb__network_model(const char *name, int pos) if (!strcmp(val, "help")) { model_help("network", surf_network_model_description); - exit(0); + sg_cfg_exit_early(); } /* New Module missing */ @@ -243,7 +247,7 @@ static void _sg_cfg_cb__coll(const char *category, if (!strcmp(val, "help")) { coll_help(category, table); - exit(0); + sg_cfg_exit_early(); } /* New Module missing */ diff --git a/src/simix/smx_global.c b/src/simix/smx_global.c index 8915337575..bfed0bafe9 100644 --- a/src/simix/smx_global.c +++ b/src/simix/smx_global.c @@ -110,7 +110,11 @@ void SIMIX_global_init(int *argc, char **argv) SIMIX_HOST_LEVEL = xbt_lib_add_level(host_lib,SIMIX_host_destroy); - if(sg_cfg_get_boolean("clean_atexit")) atexit(SIMIX_clean); + if (sg_cfg_get_boolean("clean_atexit")) + atexit(SIMIX_clean); + + if (_sg_cfg_exit_asap) + exit(0); } /** @@ -121,6 +125,9 @@ void SIMIX_global_init(int *argc, char **argv) */ static void SIMIX_clean(void) { +#ifdef HAVE_TRACING + TRACE_end(); +#endif #ifdef TIME_BENCH_PER_SR smx_ctx_raw_new_sr(); #endif -- 2.20.1