Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
The exception associated to each process was relocated from the
authorcristianrosa <cristianrosa@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 18 Aug 2009 14:01:09 +0000 (14:01 +0000)
committercristianrosa <cristianrosa@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 18 Aug 2009 14:01:09 +0000 (14:01 +0000)
context to the simix process that contains it. This is both faster and
simpler because the initialization code was factorized and exception
fetching uses one dereference less.

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

examples/msg/masterslave/masterslave_failure.tesh
src/simix/private.h
src/simix/smx_context.c
src/simix/smx_context_java.c
src/simix/smx_context_sysv.c
src/simix/smx_context_thread.c
src/simix/smx_global.c
src/simix/smx_process.c
src/simix/smx_synchro.c

index 6179c8d..65e6c78 100644 (file)
@@ -3,7 +3,7 @@
 p Testing a simple master/slave example application handling failures
 
 $ masterslave/masterslave_failure$EXEEXT ${srcdir:=.}/small_platform_with_failures.xml ${srcdir:=.}/masterslave/deployment_masterslave.xml --cfg:path=${srcdir}
-> [0.000000] simix/smx_process.c:92: [simix_process/WARNING] Cannot launch process 'slave' on failed host 'Fafard'
+> [0.000000] simix/smx_process.c:100: [simix_process/WARNING] Cannot launch process 'slave' on failed host 'Fafard'
 > [Tremblay:master:(1) 0.000000] [msg_test/INFO] Got 5 slave(s) :
 > [Tremblay:master:(1) 0.000000] [msg_test/INFO] Jupiter
 > [Tremblay:master:(1) 0.000000] [msg_test/INFO] Fafard
index 4de05ad..210e01d 100644 (file)
@@ -17,6 +17,7 @@
 #include "xbt/dict.h"
 #include "xbt/config.h"
 #include "xbt/function_types.h"
+#include "xbt/ex_interface.h"
 
 /******************************** Datatypes ***********************************/
 
@@ -65,6 +66,7 @@ extern SIMIX_Global_t simix_global;
        char *name;              /**< @brief process name if any */
        smx_host_t smx_host;     /* the host on which the process is running */
        smx_context_t context;   /* the context that executes the scheduler function */
+       ex_ctx_t *exception;
        int blocked : 1;
        int suspended : 1;
        int iwannadie : 1;
@@ -87,9 +89,13 @@ typedef struct s_smx_process_arg {
   xbt_dict_t properties;
 } s_smx_process_arg_t, *smx_process_arg_t;
 
+void SIMIX_create_maestro_process(void);
 void SIMIX_process_empty_trash(void);
-void __SIMIX_process_schedule(smx_process_t process);
-void __SIMIX_process_yield(void);
+void SIMIX_process_schedule(smx_process_t process);
+void SIMIX_process_yield(void);
+ex_ctx_t *SIMIX_process_get_exception(void);
+void SIMIX_process_exception_terminate(xbt_ex_t * e);
+
 
 /*************************** Mutex and Conditional ****************************/
 
@@ -140,7 +146,6 @@ void __SIMIX_host_destroy(void *host);
 void __SIMIX_cond_wait(smx_cond_t cond);
 void __SIMIX_cond_display_actions(smx_cond_t cond);
 void __SIMIX_action_display_conditions(smx_action_t action);
-void __SIMIX_create_maestro_process(void);
 
 /******************************** Context *************************************/
 
@@ -157,7 +162,6 @@ void SIMIX_context_mod_exit(void);
 /* each context type must contain this macro at its begining -- OOP in C :/ */
 #define SMX_CTX_BASE_T \
   s_xbt_swag_hookup_t hookup; \
-  ex_ctx_t *exception; \
   xbt_main_func_t code; \
   int argc; \
   char **argv; \
index 8683547..006c478 100644 (file)
@@ -80,7 +80,7 @@ int SIMIX_context_select_factory(const char *name)
   /* init the desired factory */
   SIMIX_context_init_factory_by_name(&simix_global->context_factory, name);
 
-  __SIMIX_create_maestro_process ();
+  SIMIX_create_maestro_process ();
   
   return 0;
 }
index 47af4c4..bf64e54 100644 (file)
@@ -9,18 +9,11 @@
 
 
 #include "xbt/function_types.h"
-#include "xbt/ex_interface.h"
 #include "private.h"
 #include "smx_context_java.h"
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(jmsg, "MSG for Java(TM)");
 
-/* callback: context fetching */
-static ex_ctx_t *xbt_ctx_java_ex_ctx(void);
-
-/* callback: termination */
-static void xbt_ctx_java_ex_terminate(xbt_ex_t * e);
-
 static smx_context_t
 smx_ctx_java_factory_create_context(xbt_main_func_t code, int argc, char** argv, 
                                     void_f_pvoid_t cleanup_func, void* cleanup_arg);
@@ -38,26 +31,8 @@ static void smx_ctx_java_suspend(smx_context_t context);
 static void
   smx_ctx_java_resume(smx_context_t old_context, smx_context_t new_context);
 
-
-/* callback: context fetching */
-static ex_ctx_t *xbt_ctx_java_ex_ctx(void)
-{
-  return simix_global->current_process->context->exception;
-}
-
-/* callback: termination */
-static void xbt_ctx_java_ex_terminate(xbt_ex_t * e)
-{
-  xbt_ex_display(e);
-  abort();
-}
-
 void SIMIX_ctx_java_factory_init(smx_context_factory_t * factory)
 {
-  /* context exception handlers */
-  __xbt_ex_ctx = xbt_ctx_java_ex_ctx;
-  __xbt_ex_terminate = xbt_ctx_java_ex_terminate;
-
   /* instantiate the context factory */
   *factory = xbt_new0(s_smx_context_factory_t, 1);
 
@@ -76,11 +51,6 @@ static int smx_ctx_java_factory_finalize(smx_context_factory_t * factory)
 {
   free(*factory);
   *factory = NULL;
-
-  /* Restore the default exception setup */
-  __xbt_ex_ctx = &__xbt_ex_ctx_default;
-  __xbt_ex_terminate = &__xbt_ex_terminate_default;
-
   return 0;
 }
 
@@ -90,9 +60,6 @@ smx_ctx_java_factory_create_context(xbt_main_func_t code, int argc, char** argv,
 {
   smx_ctx_java_t context = xbt_new0(s_smx_ctx_java_t, 1);
 
-  context->exception = xbt_new(ex_ctx_t, 1);
-  XBT_CTX_INITIALIZE(context->exception);
-
   /* If the user provided a function for the process then use it
      otherwise is the context for maestro */
   if(code){
@@ -120,9 +87,6 @@ static void smx_ctx_java_free(smx_context_t context)
         jprocess_join(jprocess, get_current_thread_env());
     }
 
-    if (ctx_java->exception)
-      free(ctx_java->exception);
-
     free(context);
     context = NULL;
   }
index 3baf8f2..7ad1d98 100644 (file)
@@ -7,7 +7,6 @@
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
-#include "xbt/ex_interface.h"
 #include "private.h"
 #include "context_sysv_config.h"        /* loads context system definitions */
 #include "portable.h"
@@ -32,13 +31,6 @@ typedef struct s_smx_ctx_sysv {
 #endif                          
 } s_smx_ctx_sysv_t, *smx_ctx_sysv_t;
 
-
-/* callback: context fetching */
-static ex_ctx_t *xbt_jcontext_ex_ctx(void);
-
-/* callback: termination */
-static void xbt_jcontext_ex_terminate(xbt_ex_t *e);
-
 static smx_context_t 
 smx_ctx_sysv_factory_create_context(xbt_main_func_t code, int argc, char** argv, 
                                     void_f_pvoid_t cleanup_func, void* cleanup_arg);
@@ -58,20 +50,6 @@ static void
 
 static void smx_ctx_sysv_wrapper(void);
 
-/* callback: context fetching */
-static ex_ctx_t *xbt_ctx_sysv_ex_ctx(void)
-{
-  /*FIXME: the factory should access simix level datastructures! */
-  return simix_global->current_process->context->exception;
-}
-
-/* callback: termination */
-static void xbt_ctx_sysv_ex_terminate(xbt_ex_t * e)
-{
-  xbt_ex_display(e);
-  abort();
-}
-
 void SIMIX_ctx_sysv_factory_init(smx_context_factory_t *factory)
 {
   *factory = xbt_new0(s_smx_context_factory_t, 1);
@@ -84,21 +62,12 @@ void SIMIX_ctx_sysv_factory_init(smx_context_factory_t *factory)
   (*factory)->suspend = smx_ctx_sysv_suspend;
   (*factory)->resume = smx_ctx_sysv_resume;
   (*factory)->name = "smx_sysv_context_factory";
-
-  /* context exception handlers */
-  __xbt_ex_ctx = xbt_ctx_sysv_ex_ctx;
-  __xbt_ex_terminate = xbt_ctx_sysv_ex_terminate;
 }
 
 static int smx_ctx_sysv_factory_finalize(smx_context_factory_t * factory)
 {
   free(*factory);
   *factory = NULL;
-
-  /* Restore the default exception setup */
-  __xbt_ex_ctx = &__xbt_ex_ctx_default;
-  __xbt_ex_terminate = &__xbt_ex_terminate_default;
-
   return 0;
 }
 
@@ -107,9 +76,6 @@ smx_ctx_sysv_factory_create_context(xbt_main_func_t code, int argc, char** argv,
                                     void_f_pvoid_t cleanup_func, void* cleanup_arg)
 {
   smx_ctx_sysv_t context = xbt_new0(s_smx_ctx_sysv_t, 1);
-
-  context->exception = xbt_new(ex_ctx_t, 1);
-  XBT_CTX_INITIALIZE(context->exception);
   
   /* If the user provided a function for the process then use it
      otherwise is the context for maestro */
@@ -149,9 +115,6 @@ static void smx_ctx_sysv_free(smx_context_t pcontext)
   smx_ctx_sysv_t context = (smx_ctx_sysv_t)pcontext;   
   if (context){
 
-    if (context->exception)
-      free(context->exception);
-
 #ifdef HAVE_VALGRIND_VALGRIND_H
     VALGRIND_STACK_DEREGISTER(((smx_ctx_sysv_t) context)->valgrind_stack_id);
 #endif /* HAVE_VALGRIND_VALGRIND_H */
index 7f6c139..6ffe157 100644 (file)
@@ -45,9 +45,6 @@ static void *smx_ctx_thread_wrapper(void *param);
 
 void SIMIX_ctx_thread_factory_init(smx_context_factory_t * factory)
 {
-  /* Initialize the thread portability layer 
-  xbt_os_thread_mod_init();*/
-  
   *factory = xbt_new0(s_smx_context_factory_t, 1);
 
   (*factory)->create_context = smx_ctx_thread_factory_create_context;
@@ -62,8 +59,6 @@ void SIMIX_ctx_thread_factory_init(smx_context_factory_t * factory)
 
 static int smx_ctx_thread_factory_finalize(smx_context_factory_t * factory)
 {
-  /* Stop the thread portability layer 
-  xbt_os_thread_mod_exit();*/
   free(*factory);
   *factory = NULL;
   return 0;
index 5a3ed08..2adc9cb 100644 (file)
@@ -77,7 +77,12 @@ void SIMIX_global_init(int *argc, char **argv)
     simix_global->cleanup_process_function = SIMIX_process_cleanup;
 
     SIMIX_context_mod_init();
-    __SIMIX_create_maestro_process();
+    SIMIX_create_maestro_process();
+
+    /* context exception handlers */
+    __xbt_ex_ctx = SIMIX_process_get_exception;
+    __xbt_ex_terminate = SIMIX_process_exception_terminate;
+
 
     /* Prepare to display some more info when dying on Ctrl-C pressing */
     signal(SIGINT, inthandler);
@@ -236,14 +241,20 @@ void SIMIX_clean(void)
 
   /* Let's free maestro now */
   SIMIX_context_free(simix_global->maestro_process->context);
-  free(simix_global->maestro_process);  
+  xbt_free(simix_global->maestro_process->exception);
+  xbt_free(simix_global->maestro_process);  
   simix_global->maestro_process = NULL;
+
+  /* Restore the default exception setup */
+  __xbt_ex_ctx = &__xbt_ex_ctx_default;
+  __xbt_ex_terminate = &__xbt_ex_terminate_default;
   
   /* Finish context module and SURF */
   SIMIX_context_mod_exit();
+
   surf_exit();
 
-  free(simix_global);
+  xbt_free(simix_global);
   simix_global = NULL;
 
   return;
@@ -293,7 +304,7 @@ double SIMIX_solve(xbt_fifo_t actions_done, xbt_fifo_t actions_failed)
 
   while ((process = xbt_swag_extract(simix_global->process_to_run))) {
     DEBUG2("Scheduling %s on %s", process->name, process->smx_host->name);
-    __SIMIX_process_schedule(process);
+    SIMIX_process_schedule(process);
   }
 
   {
index f90dcdb..32f2537 100644 (file)
@@ -37,6 +37,11 @@ void SIMIX_process_empty_trash(void)
 
   while ((process = xbt_swag_extract(simix_global->process_to_destroy))){
     SIMIX_context_free(process->context);
+
+    /* Free the exception allocated at creation time */
+    if (process->exception)
+      free(process->exception);
+
     free(process->name);
     process->name = NULL;
     free(process);
@@ -46,7 +51,7 @@ void SIMIX_process_empty_trash(void)
 /**
  * \brief Creates and runs the maestro process
  */
-void __SIMIX_create_maestro_process()
+void SIMIX_create_maestro_process()
 {
   smx_process_t process = NULL;
   process = xbt_new0(s_smx_process_t, 1);
@@ -54,6 +59,9 @@ void __SIMIX_create_maestro_process()
   /* Process data */
   process->name = (char *)"";
 
+  process->exception = xbt_new(ex_ctx_t, 1);
+  XBT_CTX_INITIALIZE(process->exception);
+  
   /* Create a dummy context for maestro */
   process->context = SIMIX_context_new(NULL, 0, NULL, NULL, NULL);
 
@@ -102,13 +110,15 @@ smx_process_t SIMIX_process_create(const char *name,
   process->mutex = NULL;
   process->cond = NULL;
   process->iwannadie = 0;
-
+  process->data = data;
+  
   VERB1("Create context %s", process->name);
   process->context = SIMIX_context_new(code, argc, argv, 
                                        simix_global->cleanup_process_function,
                                        process);
-  
-  process->data = data;
+
+  process->exception = xbt_new(ex_ctx_t, 1);
+  XBT_CTX_INITIALIZE(process->exception);
 
   /* Add properties */
   process->properties = properties;
@@ -152,7 +162,7 @@ void SIMIX_process_kill(smx_process_t process)
   if (process == SIMIX_process_self())
     SIMIX_context_stop(process->context);
   else
-    __SIMIX_process_schedule(process);
+    SIMIX_process_schedule(process);
   
 }
 
@@ -380,7 +390,7 @@ int SIMIX_process_count()
  * Only the processes can call this function, giving back the control
  * to the maestro
  */
-void __SIMIX_process_yield(void)
+void SIMIX_process_yield(void)
 {
   DEBUG1("Yield process '%s'", simix_global->current_process->name);
   xbt_assert0((simix_global->current_process != simix_global->maestro_process),
@@ -392,7 +402,7 @@ void __SIMIX_process_yield(void)
     SIMIX_context_stop(simix_global->current_process->context);
 }
 
-void __SIMIX_process_schedule(smx_process_t new_process)
+void SIMIX_process_schedule(smx_process_t new_process)
 {
   DEBUG1("Scheduling context: '%s'", new_process->name);
 
@@ -408,3 +418,18 @@ void __SIMIX_process_schedule(smx_process_t new_process)
   /* restore the current process to the previously saved process */
   simix_global->current_process = old_process;
 }
+
+/* callback: context fetching */
+ex_ctx_t *SIMIX_process_get_exception(void)
+{
+  return simix_global->current_process->exception;
+}
+
+/* callback: termination */
+void SIMIX_process_exception_terminate(xbt_ex_t * e)
+{
+  xbt_ex_display(e);
+  abort();
+}
+
+
index cabc1f4..dbebbcb 100644 (file)
@@ -51,12 +51,12 @@ void SIMIX_mutex_lock(smx_mutex_t mutex)
     xbt_swag_insert(self, mutex->sleeping);
     self->mutex = mutex;
     /* wait for some process make the unlock and wake up me from mutex->sleeping */
-    __SIMIX_process_yield();
+    SIMIX_process_yield();
     self->mutex = NULL;
 
     /* verify if the process was suspended */
     while (self->suspended) {
-      __SIMIX_process_yield();
+      SIMIX_process_yield();
     }
 
     mutex->refcount = 1;
@@ -213,10 +213,10 @@ void __SIMIX_cond_wait(smx_cond_t cond)
 
   self->cond = cond;
   xbt_swag_insert(self, cond->sleeping);
-  __SIMIX_process_yield();
+  SIMIX_process_yield();
   self->cond = NULL;
   while (self->suspended) {
-    __SIMIX_process_yield();
+    SIMIX_process_yield();
   }
   return;