p Testing a simple master/slave example application handling failures
$ masterslave/masterslave_failure$EXEEXT small_platform_with_failures.xml masterslave/deployment_masterslave.xml
-> [0.000000] simix/smx_process.c:92: [simix_process/WARNING] Cannot launch process 'slave' on failed host 'Fafard'
+> [0.000000] simix/smx_process.c:91: [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
typedef smx_context_t (*smx_pfn_context_factory_create_context_t)
(xbt_main_func_t, int, char**, void_f_pvoid_t, void*);
-/* function used to create the context for the maestro process */
-typedef smx_context_t (*smx_pfn_context_factory_create_maestro_context_t) (void);
-
/* this function finalize the specified context factory */
typedef int (*smx_pfn_context_factory_finalize_t) (smx_context_factory_t*);
/* interface of the context factories */
typedef struct s_smx_context_factory {
- smx_pfn_context_factory_create_maestro_context_t create_maestro_context;
smx_pfn_context_factory_create_context_t create_context;
smx_pfn_context_factory_finalize_t finalize;
smx_pfn_context_free_t free;
* iwannadie == 1, and call SIMIX_context_stop(same than first case afterward)
*/
-/**
- * \brief creates the context for the maestro process
- */
-static inline smx_context_t SIMIX_context_create_maestro()
-{
- return (*(simix_global->context_factory->create_maestro_context)) ();
-}
-
/**
* \brief creates a new context for a user level process
* \param code a main function
if (simix_global->context_factory) {
smx_pfn_context_factory_finalize_t finalize_factory;
- /* if there are living processes then kill them (except maestro) */
- if(simix_global->process_list != NULL)
- SIMIX_process_killall();
+ /* Check that there are no living process or to destroy */
+ xbt_assert0((simix_global->process_list == NULL),
+ "There are living process!");
+
+ xbt_assert0((simix_global->process_to_destroy == NULL),
+ "There are process to destroy!");
+
+ xbt_assert0((simix_global->maestro_process == NULL),
+ "The maestro process is alive!");
/* finalize the context factory */
finalize_factory = simix_global->context_factory->finalize;
/**
* This function is used to change the context factory.
- * Warning: it destroy all the existing contexts
+ * Warning: it destroy all the existing processes (even for maestro), and it
+ * will create a new maestro process using the new context factory.
*/
int SIMIX_context_select_factory(const char *name)
{
- /* if a factory is already instantiated (SIMIX_context_mod_init() was called) */
+ /* if a context factory is already instantiated and it is different from the
+ newly selected one, then kill all the processes, exit the context module
+ and initialize the new factory.
+ */
if (simix_global->context_factory != NULL) {
- /* if the desired factory is different of the current factory, call SIMIX_context_mod_exit() */
- if (strcmp(simix_global->context_factory->name, name))
+ if (strcmp(simix_global->context_factory->name, name)){
+
+ SIMIX_process_killall();
+
+ /* kill maestro process */
+ SIMIX_context_free(simix_global->maestro_process->context);
+ free(simix_global->maestro_process);
+ simix_global->maestro_process = NULL;
+
SIMIX_context_mod_exit();
+ }
else
/* the same context factory is requested return directly */
return 0;
}
- /* get the desired factory */
+ /* init the desired factory */
SIMIX_context_init_factory_by_name(&simix_global->context_factory, name);
- /* maestro process specialisation */
- simix_global->maestro_process->context = SIMIX_context_create_maestro ();
-
- /* the current process is the process of the maestro */
- simix_global->current_process = simix_global->maestro_process;
-
- /* the current context doesn't want to die */
- simix_global->current_process->iwannadie = 0;
-
- /* insert the current context in the list of the contexts in use */
- xbt_swag_insert(simix_global->current_process, simix_global->process_list);
-
+ __SIMIX_create_maestro_process ();
+
return 0;
}
smx_ctx_java_factory_create_context(xbt_main_func_t code, int argc, char** argv,
void_f_pvoid_t cleanup_func, void* cleanup_arg);
-static smx_context_t smx_ctx_java_factory_create_maestro_context(void);
-
static int smx_ctx_java_factory_finalize(smx_context_factory_t * factory);
static void smx_ctx_java_free(smx_context_t context);
(*factory)->create_context = smx_ctx_java_factory_create_context;
(*factory)->finalize = smx_ctx_java_factory_finalize;
- (*factory)->create_maestro_context = smx_ctx_java_factory_create_maestro_context;
(*factory)->free = smx_ctx_java_free;
(*factory)->start = smx_ctx_java_start;
(*factory)->stop = smx_ctx_java_stop;
(*factory)->name = "ctx_java_factory";
}
-static smx_context_t smx_ctx_java_factory_create_maestro_context(void)
-{
- 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);
-
- return (smx_context_t) context;
-}
-
static int smx_ctx_java_factory_finalize(smx_context_factory_t * factory)
{
/*FIXME: free(maestro_context->exception);*/
{
smx_ctx_java_t context = xbt_new0(s_smx_ctx_java_t, 1);
- context->cleanup_func = cleanup_func;
- context->cleanup_arg = cleanup_arg;
context->exception = xbt_new(ex_ctx_t, 1);
XBT_CTX_INITIALIZE(context->exception);
- context->jprocess = (jobject) code;
- context->jenv = get_current_thread_env();
+ /* If the user provided a function for the process then use it
+ otherwise is the context for maestro */
+ if(code){
+ context->cleanup_func = cleanup_func;
+ context->cleanup_arg = cleanup_arg;
+ context->jprocess = (jobject) code;
+ context->jenv = get_current_thread_env();
+ }
+
return (smx_context_t) context;
}
static int smx_ctx_sysv_factory_finalize(smx_context_factory_t *factory);
-static smx_context_t smx_ctx_sysv_factory_create_maestro_context(void);
-
static void smx_ctx_sysv_free(smx_context_t context);
static void smx_ctx_sysv_start(smx_context_t context);
(*factory)->create_context = smx_ctx_sysv_factory_create_context;
(*factory)->finalize = smx_ctx_sysv_factory_finalize;
- (*factory)->create_maestro_context = smx_ctx_sysv_factory_create_maestro_context;
(*factory)->free = smx_ctx_sysv_free;
(*factory)->start = smx_ctx_sysv_start;
(*factory)->stop = smx_ctx_sysv_stop;
__xbt_ex_terminate = xbt_ctx_sysv_ex_terminate;
}
-static smx_context_t smx_ctx_sysv_factory_create_maestro_context()
-{
- 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);
-
- return (smx_context_t)context;
-}
-
static int smx_ctx_sysv_factory_finalize(smx_context_factory_t * factory)
{
/*FIXME free(maestro_context->exception);*/
{
smx_ctx_sysv_t context = xbt_new0(s_smx_ctx_sysv_t, 1);
- context->code = code;
+ 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){
+ context->code = code;
+
+ xbt_assert2(getcontext(&(context->uc)) == 0,
+ "Error in context saving: %d (%s)", errno, strerror(errno));
+
+ context->uc.uc_link = NULL;
+
+ context->uc.uc_stack.ss_sp =
+ pth_skaddr_makecontext(context->stack, STACK_SIZE);
+
+ context->uc.uc_stack.ss_size =
+ pth_sksize_makecontext(context->stack, STACK_SIZE);
- xbt_assert2(getcontext(&(context->uc)) == 0,
- "Error in context saving: %d (%s)", errno, strerror(errno));
- context->uc.uc_link = NULL;
- context->uc.uc_stack.ss_sp =
- pth_skaddr_makecontext(context->stack, STACK_SIZE);
- context->uc.uc_stack.ss_size =
- pth_sksize_makecontext(context->stack, STACK_SIZE);
#ifdef HAVE_VALGRIND_VALGRIND_H
- context->valgrind_stack_id =
- VALGRIND_STACK_REGISTER(context->uc.uc_stack.ss_sp,
- ((char *) context->uc.uc_stack.ss_sp) +
- context->uc.uc_stack.ss_size);
+ context->valgrind_stack_id =
+ VALGRIND_STACK_REGISTER(context->uc.uc_stack.ss_sp,
+ ((char *) context->uc.uc_stack.ss_sp) +
+ context->uc.uc_stack.ss_size);
#endif /* HAVE_VALGRIND_VALGRIND_H */
- context->exception = xbt_new(ex_ctx_t, 1);
- XBT_CTX_INITIALIZE(context->exception);
- context->argc = argc;
- context->argv = argv;
- context->cleanup_func = cleanup_func;
- context->cleanup_arg = cleanup_arg;
+ context->argc = argc;
+ context->argv = argv;
+ context->cleanup_func = cleanup_func;
+ context->cleanup_arg = cleanup_arg;
+ }
+
return (smx_context_t)context;
}
#include "portable.h" /* loads context system definitions */
#include "xbt/swag.h"
#include "xbt/xbt_os_thread.h"
+#include "xbt_modinter.h" /* prototype of os thread module's init/exit in XBT */
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context);
smx_ctx_thread_factory_create_context(xbt_main_func_t code, int argc, char** argv,
void_f_pvoid_t cleanup_func, void* cleanup_arg);
-static smx_context_t smx_ctx_thread_factory_create_master_context(void);
-
static int smx_ctx_thread_factory_finalize(smx_context_factory_t * factory);
static void smx_ctx_thread_free(smx_context_t context);
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;
(*factory)->finalize = smx_ctx_thread_factory_finalize;
- (*factory)->create_maestro_context = smx_ctx_thread_factory_create_master_context;
(*factory)->free = smx_ctx_thread_free;
(*factory)->start = smx_ctx_thread_start;
(*factory)->stop = smx_ctx_thread_stop;
(*factory)->name = "ctx_thread_factory";
}
-static smx_context_t smx_ctx_thread_factory_create_master_context(void)
-{
- return (smx_context_t) xbt_new0(s_smx_ctx_thread_t, 1);
-}
-
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;
{
smx_ctx_thread_t context = xbt_new0(s_smx_ctx_thread_t, 1);
- context->code = code;
- context->argc = argc;
- context->argv = argv;
- context->cleanup_func = cleanup_func;
- context->cleanup_arg = cleanup_arg;
- context->begin = xbt_os_sem_init(0);
- context->end = xbt_os_sem_init(0);
-
+ /* If the user provided a function for the process then use it
+ otherwise is the context for maestro */
+ if(code){
+ context->code = code;
+ context->argc = argc;
+ context->argv = argv;
+ context->cleanup_func = cleanup_func;
+ context->cleanup_arg = cleanup_arg;
+ context->begin = xbt_os_sem_init(0);
+ context->end = xbt_os_sem_init(0);
+ }
+
return (smx_context_t)context;
}
/**
* \brief Kill all running process
- *
+ * Only maestro can kill everyone :)
*/
void SIMIX_process_killall()
{
smx_process_t p = NULL;
- smx_process_t self = SIMIX_process_self();
+ xbt_assert0((simix_global->current_process == simix_global->maestro_process),
+ "You are not supposed to run this function here!");
- while ((p = xbt_swag_extract(simix_global->process_list))) {
- if (p != self)
- SIMIX_process_kill(p);
- }
+ while ((p = xbt_swag_extract(simix_global->process_list)))
+ SIMIX_process_kill(p);
SIMIX_process_empty_trash();
- if (self != simix_global->maestro_process) {
- __SIMIX_process_yield();
- }
-
return;
}
xbt_swag_free(simix_global->process_to_destroy);
xbt_swag_free(simix_global->process_list);
simix_global->process_list = NULL;
+ simix_global->process_to_destroy = NULL;
xbt_dict_free(&(simix_global->registered_functions));
xbt_dict_free(&(simix_global->host));
/* Let's free maestro now */
SIMIX_context_free(simix_global->maestro_process->context);
free(simix_global->maestro_process);
-
+ simix_global->maestro_process = NULL;
+
/* Finish context module and SURF */
SIMIX_context_mod_exit();
surf_exit();
/* Process data */
process->name = (char *)"";
- /* Create the right context type */
- process->context = SIMIX_context_create_maestro();
+ /* Create a dummy context for maestro */
+ process->context = SIMIX_context_new(NULL, 0, NULL, NULL, NULL);
/* Set it as the maestro process */
simix_global->maestro_process = process;
xbt_die
("No pthread in SG when compiled against the ucontext (xbt_os_cond_destroy)");
}
-#endif
-
-
-/*#ifndef HAVE_JAVA
-#include "xbt/xbt_context_private.h"
-void xbt_ctx_java_factory_init(xbt_context_factory_t * factory)
-{
-}
-#endif*/
+#endif
\ No newline at end of file