Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add a flag --cfg=simix/context to choose the context factory: ucontext,
authorthiery <thiery@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 15 Dec 2010 13:15:11 +0000 (13:15 +0000)
committerthiery <thiery@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 15 Dec 2010 13:15:11 +0000 (13:15 +0000)
thread or raw

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@9245 48e7efb5-ca39-0410-a469-dd3cf9ba447f

examples/msg/actions/actions.c
include/simix/context.h
src/simix/smx_context.c
src/simix/smx_context_raw.c
src/simix/smx_context_sysv.c
src/simix/smx_context_thread.c
src/simix/smx_smurf.c
src/surf/surf_config.c

index f14ebeb..aec65c7 100644 (file)
@@ -11,8 +11,8 @@
 #include "xbt.h"                /* calloc, printf */
 #include "simgrid_config.h"     /* getline */
 #include "instr/instr_private.h"
 #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");
 
 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;
 
 {
   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) {
   /* Check the given arguments */
   MSG_global_init(&argc, argv);
   if (argc < 3) {
index 475ffbc..6c62065 100644 (file)
@@ -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;
 
 /* *********************** */
 smx_context_t smx_current_context;
 
 /* *********************** */
index 857c049..8821246 100644 (file)
@@ -15,7 +15,8 @@
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_context, simix,
                                 "Context switching mecanism");
 
 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.
 
 /** 
  * 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) {
 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);
   }
     finalize_factory = simix_global->context_factory->finalize;
     (*finalize_factory) (&simix_global->context_factory);
   }
+  xbt_free(smx_context_factory_name);
 }
 }
index 38a2473..afb3cc8 100644 (file)
@@ -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";
 
   (*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;
 #ifdef CONTEXT_THREADS  /* To use parallel ucontexts a thread pool is needed */
     parmap = xbt_parmap_new(2);
     (*factory)->runall = smx_ctx_raw_runall_parallel;
index eab0b57..5c30df5 100644 (file)
@@ -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";
 
   (*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;
 #ifdef CONTEXT_THREADS /* To use parallel ucontexts a thread pool is needed */
     parmap = xbt_parmap_new(2);
     (*factory)->runall = smx_ctx_sysv_runall_parallel;
index 6038730..ddd4deb 100644 (file)
@@ -16,6 +16,8 @@
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context);
 
 
 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) */
 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;
 
   (*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;
     (*factory)->runall = smx_ctx_thread_runall_parallel;
   else
     (*factory)->runall = smx_ctx_thread_runall_serial;
index 475b3fb..0e287f6 100644 (file)
@@ -34,13 +34,13 @@ void SIMIX_request_push()
   if (issuer != simix_global->maestro_process){
     issuer->request.issuer = issuer;
 
   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));
       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,
       xbt_os_mutex_release(sync_req_positions);
 
     DEBUG3("Yield process '%s' on request of type %s (%d)", issuer->name,
index e0b90da..f691bfb 100644 (file)
@@ -9,13 +9,13 @@
 #include "xbt/config.h"
 #include "xbt/str.h"
 #include "surf/surf_private.h"
 #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;
 
 
 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)
 {
 /* 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();
 }
 
   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)
 {
 
 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,
 }
 
 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); */
 
        _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",
     /* parallel contexts */
     default_value_int = 0;
     xbt_cfg_register(&_surf_cfg_set, "parallel-contexts",