From: thiery Date: Wed, 15 Dec 2010 13:15:11 +0000 (+0000) Subject: Add a flag --cfg=simix/context to choose the context factory: ucontext, X-Git-Tag: v3.6_beta2~678 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/ca219853a75e59f34961591d0abda7d9d091bd74 Add a flag --cfg=simix/context to choose the context factory: ucontext, thread or raw git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@9245 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/examples/msg/actions/actions.c b/examples/msg/actions/actions.c index f14ebeb73b..aec65c79b4 100644 --- a/examples/msg/actions/actions.c +++ b/examples/msg/actions/actions.c @@ -11,8 +11,8 @@ #include "xbt.h" /* calloc, printf */ #include "simgrid_config.h" /* getline */ #include "instr/instr_private.h" -void SIMIX_ctx_raw_factory_init(smx_context_factory_t *factory); +void SIMIX_ctx_raw_factory_init(smx_context_factory_t *factory); XBT_LOG_NEW_DEFAULT_CATEGORY(actions, "Messages specific for this msg example"); @@ -526,7 +526,8 @@ int main(int argc, char *argv[]) { MSG_error_t res = MSG_OK; - factory_initializer_to_use = SIMIX_ctx_raw_factory_init; + smx_factory_initializer_to_use = SIMIX_ctx_raw_factory_init; + /* Check the given arguments */ MSG_global_init(&argc, argv); if (argc < 3) { diff --git a/include/simix/context.h b/include/simix/context.h index 475ffbcfea..6c62065011 100644 --- a/include/simix/context.h +++ b/include/simix/context.h @@ -51,11 +51,11 @@ typedef struct s_smx_context_factory { -/*Hack: let msg load directly the right factory */ -typedef void (*SIMIX_ctx_factory_initializer_t)(smx_context_factory_t*); -extern SIMIX_ctx_factory_initializer_t factory_initializer_to_use; - -extern int _surf_parallel_contexts; +/* Hack: let msg load directly the right factory */ +typedef void (*smx_ctx_factory_initializer_t)(smx_context_factory_t*); +extern smx_ctx_factory_initializer_t smx_factory_initializer_to_use; +extern char* smx_context_factory_name; +extern int smx_parallel_contexts; smx_context_t smx_current_context; /* *********************** */ diff --git a/src/simix/smx_context.c b/src/simix/smx_context.c index 857c049502..88212467d6 100644 --- a/src/simix/smx_context.c +++ b/src/simix/smx_context.c @@ -15,7 +15,8 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_context, simix, "Context switching mecanism"); -SIMIX_ctx_factory_initializer_t factory_initializer_to_use = NULL; +char* smx_context_factory_name = NULL; /* factory name specified by --cfg=simix/context=value */ +smx_ctx_factory_initializer_t smx_factory_initializer_to_use = NULL; /** * This function is called by SIMIX_global_init() to initialize the context module. @@ -23,18 +24,26 @@ SIMIX_ctx_factory_initializer_t factory_initializer_to_use = NULL; void SIMIX_context_mod_init(void) { if (!simix_global->context_factory) { - /* select context factory to use to create the context(depends of the macro definitions) */ - if (factory_initializer_to_use) { - (*factory_initializer_to_use)(&(simix_global->context_factory)); + /* select the context factory to use to create the contexts */ + if (smx_factory_initializer_to_use) { + (*smx_factory_initializer_to_use)(&(simix_global->context_factory)); } - else { -#ifdef CONTEXT_UCONTEXT /* use ucontext */ - SIMIX_ctx_sysv_factory_init(&simix_global->context_factory); -#elif defined(CONTEXT_THREADS) /* Use os threads (either pthreads or windows ones) */ - SIMIX_ctx_thread_factory_init(&simix_global->context_factory); -#else -#error ERROR [__FILE__, line __LINE__]: no context implementation specified. -#endif + else { /* use the factory specified by --cfg=simix/ctx:value */ + if (smx_context_factory_name == NULL || !strcmp(smx_context_factory_name, "ucontext")) { + /* use ucontext */ + SIMIX_ctx_sysv_factory_init(&simix_global->context_factory); + } + else if (!strcmp(smx_context_factory_name, "thread")) { + /* use os threads (either pthreads or windows ones) */ + SIMIX_ctx_thread_factory_init(&simix_global->context_factory); + } + else if (!strcmp(smx_context_factory_name, "raw")) { + /* use raw contexts */ + SIMIX_ctx_raw_factory_init(&simix_global->context_factory); + } + else { + xbt_die("Invalid context factory specified"); + } } } } @@ -51,4 +60,5 @@ void SIMIX_context_mod_exit(void) finalize_factory = simix_global->context_factory->finalize; (*finalize_factory) (&simix_global->context_factory); } + xbt_free(smx_context_factory_name); } diff --git a/src/simix/smx_context_raw.c b/src/simix/smx_context_raw.c index 38a24734ae..afb3cc8e0f 100644 --- a/src/simix/smx_context_raw.c +++ b/src/simix/smx_context_raw.c @@ -298,7 +298,7 @@ void SIMIX_ctx_raw_factory_init(smx_context_factory_t *factory) (*factory)->suspend = smx_ctx_raw_suspend; (*factory)->name = "smx_raw_context_factory"; - if(_surf_parallel_contexts){ + if (smx_parallel_contexts) { #ifdef CONTEXT_THREADS /* To use parallel ucontexts a thread pool is needed */ parmap = xbt_parmap_new(2); (*factory)->runall = smx_ctx_raw_runall_parallel; diff --git a/src/simix/smx_context_sysv.c b/src/simix/smx_context_sysv.c index eab0b5726f..5c30df5461 100644 --- a/src/simix/smx_context_sysv.c +++ b/src/simix/smx_context_sysv.c @@ -44,7 +44,7 @@ void SIMIX_ctx_sysv_factory_init(smx_context_factory_t *factory) (*factory)->suspend = smx_ctx_sysv_suspend; (*factory)->name = "smx_sysv_context_factory"; - if(_surf_parallel_contexts){ + if (smx_parallel_contexts) { #ifdef CONTEXT_THREADS /* To use parallel ucontexts a thread pool is needed */ parmap = xbt_parmap_new(2); (*factory)->runall = smx_ctx_sysv_runall_parallel; diff --git a/src/simix/smx_context_thread.c b/src/simix/smx_context_thread.c index 6038730a41..ddd4deb48d 100644 --- a/src/simix/smx_context_thread.c +++ b/src/simix/smx_context_thread.c @@ -16,6 +16,8 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context); +int smx_parallel_contexts = 0; + typedef struct s_smx_ctx_thread { s_smx_ctx_base_t super; /* Fields of super implementation */ xbt_os_thread_t thread; /* a plain dumb thread (portable to posix or windows) */ @@ -50,7 +52,7 @@ void SIMIX_ctx_thread_factory_init(smx_context_factory_t * factory) (*factory)->stop = smx_ctx_thread_stop; (*factory)->suspend = smx_ctx_thread_suspend; - if(_surf_parallel_contexts) + if (smx_parallel_contexts) (*factory)->runall = smx_ctx_thread_runall_parallel; else (*factory)->runall = smx_ctx_thread_runall_serial; diff --git a/src/simix/smx_smurf.c b/src/simix/smx_smurf.c index 475b3fbdf9..0e287f6599 100644 --- a/src/simix/smx_smurf.c +++ b/src/simix/smx_smurf.c @@ -34,13 +34,13 @@ void SIMIX_request_push() if (issuer != simix_global->maestro_process){ issuer->request.issuer = issuer; - if (_surf_parallel_contexts) + if (smx_parallel_contexts) xbt_os_mutex_acquire(sync_req_positions); xbt_heap_push(req_todo,&issuer->request,issuer->pid); DEBUG4("Pushed request %s (%d) of %s; now %d requests waiting", SIMIX_request_name(issuer->request.call), issuer->request.call, issuer->name,xbt_heap_size(req_todo)); - if (_surf_parallel_contexts) + if (smx_parallel_contexts) xbt_os_mutex_release(sync_req_positions); DEBUG3("Yield process '%s' on request of type %s (%d)", issuer->name, diff --git a/src/surf/surf_config.c b/src/surf/surf_config.c index e0b90daa03..f691bfb67c 100644 --- a/src/surf/surf_config.c +++ b/src/surf/surf_config.c @@ -9,13 +9,13 @@ #include "xbt/config.h" #include "xbt/str.h" #include "surf/surf_private.h" +#include "simix/context.h" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_config, surf, "About the configuration of surf (and the rest of the simulation)"); xbt_cfg_t _surf_cfg_set = NULL; - /* Parse the command line, looking for options */ static void surf_config_cmd_line(int *argc, char **argv) { @@ -189,11 +189,14 @@ static void _surf_cfg_cb_model_check(const char *name, int pos) xbt_dict_preinit(); } -int _surf_parallel_contexts = 0; +static void _surf_cfg_cb_context_factory(const char *name, int pos) +{ + smx_context_factory_name = xbt_cfg_get_string(_surf_cfg_set, name); +} static void _surf_cfg_cb_parallel_contexts(const char *name, int pos) { - _surf_parallel_contexts = 1; + smx_parallel_contexts = 1; } static void _surf_cfg_cb__surf_network_fullduplex(const char *name, @@ -337,6 +340,12 @@ void surf_config_init(int *argc, char **argv) _surf_cfg_cb_model_check which sets it's value to 1 (instead of the defalut value 0) xbt_cfg_set_int(_surf_cfg_set, "model-check", default_value_int); */ + /* context factory */ + default_value = xbt_strdup("ucontext"); + xbt_cfg_register(&_surf_cfg_set, "simix/context", + "Context factory to use in SIMIX (ucontext, thread or raw)", + xbt_cfgelm_string, &default_value, 1, 1, _surf_cfg_cb_context_factory, NULL); + /* parallel contexts */ default_value_int = 0; xbt_cfg_register(&_surf_cfg_set, "parallel-contexts",