Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Some more debug output to understand the gras/empty_main bug
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 4 Jun 2008 16:04:24 +0000 (16:04 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 4 Jun 2008 16:04:24 +0000 (16:04 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@5527 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/xbt/xbt_context.c
src/xbt/xbt_context_sysv.c
src/xbt/xbt_context_thread.c

index 03ff6d1..a683fcd 100644 (file)
@@ -11,6 +11,8 @@
 #include "xbt/swag.h"
 #include "xbt_context_private.h"
 
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_context,xbt,"Context switching mecanism");
+
 /* the context associated with the current process                             */
 xbt_context_t current_context = NULL;
 
index 7a1bbbd..378bcdc 100644 (file)
 #  include <valgrind/valgrind.h>
 #endif     /* HAVE_VALGRIND_VALGRIND_H */
 
-
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(xbt_context);
 
 typedef struct s_xbt_ctx_sysv {
   XBT_CTX_BASE_T;
   ucontext_t uc;                    /* the thread that execute the code                             */
   char stack[STACK_SIZE];           /* the thread stack size                                        */
-  struct s_xbt_ctx_sysv *prev;      /* the previous thread                                              */
+  struct s_xbt_ctx_sysv *prev;      /* the previous thread                                          */
 #ifdef HAVE_VALGRIND_VALGRIND_H
   unsigned int valgrind_stack_id;   /* the valgrind stack id.      */
 #endif /* HAVE_VALGRIND_VALGRIND_H */
@@ -50,27 +50,16 @@ static int
 xbt_ctx_sysv_factory_create_maestro_context(xbt_context_t * maestro);
 
 static void xbt_ctx_sysv_free(xbt_context_t context);
-
 static void xbt_ctx_sysv_kill(xbt_context_t context);
-
 static void xbt_ctx_sysv_schedule(xbt_context_t context);
-
 static void xbt_ctx_sysv_yield(void);
-
 static void xbt_ctx_sysv_start(xbt_context_t context);
-
 static void xbt_ctx_sysv_stop(int exit_code);
-
 static void xbt_ctx_sysv_swap(xbt_context_t context);
-
 static void xbt_ctx_sysv_schedule(xbt_context_t context);
-
 static void xbt_ctx_sysv_yield(void);
-
 static void xbt_ctx_sysv_suspend(xbt_context_t context);
-
 static void xbt_ctx_sysv_resume(xbt_context_t context);
-
 static void xbt_ctx_sysv_wrapper(void);
 
 /* callback: context fetching */
@@ -108,6 +97,7 @@ xbt_ctx_sysv_factory_create_maestro_context(xbt_context_t * maestro)
 {
 
   xbt_ctx_sysv_t context = xbt_new0(s_xbt_ctx_sysv_t, 1);
+  context->name = (char*)"maestro";
 
   context->exception = xbt_new(ex_ctx_t, 1);
   XBT_CTX_INITIALIZE(context->exception);
@@ -134,6 +124,7 @@ xbt_ctx_sysv_factory_create_context(const char *name, xbt_main_func_t code,
                                     void_f_pvoid_t cleanup_func,
                                     void *cleanup_arg, int argc, char **argv)
 {
+  VERB1("Create context %s",name);
   xbt_ctx_sysv_t context = xbt_new0(s_xbt_ctx_sysv_t, 1);
 
   context->code = code;
@@ -203,6 +194,7 @@ static void xbt_ctx_sysv_free(xbt_context_t context)
 
 static void xbt_ctx_sysv_kill(xbt_context_t context)
 {
+  DEBUG2("Kill context '%s' (from '%s')",context->name,current_context->name);
   context->iwannadie = 1;
   xbt_ctx_sysv_swap(context);
 }
@@ -218,6 +210,7 @@ static void xbt_ctx_sysv_kill(xbt_context_t context)
  */
 static void xbt_ctx_sysv_schedule(xbt_context_t context)
 {
+  DEBUG1("Schedule context '%s'",context->name);
   xbt_assert0((current_context == maestro_context),
               "You are not supposed to run this function here!");
   xbt_ctx_sysv_swap(context);
@@ -233,6 +226,7 @@ static void xbt_ctx_sysv_schedule(xbt_context_t context)
  */
 static void xbt_ctx_sysv_yield(void)
 {
+  DEBUG1("Yielding context '%s'",current_context->name);
   xbt_assert0((current_context != maestro_context),
               "You are not supposed to run this function here!");
   xbt_ctx_sysv_swap(current_context);
@@ -240,11 +234,13 @@ static void xbt_ctx_sysv_yield(void)
 
 static void xbt_ctx_sysv_start(xbt_context_t context)
 {
+  DEBUG1("Start context '%s'",context->name);
   makecontext(&(((xbt_ctx_sysv_t) context)->uc), xbt_ctx_sysv_wrapper, 0);
 }
 
 static void xbt_ctx_sysv_stop(int exit_code)
 {
+  /* please no debug here: our procdata was already free'd */
   if (current_context->cleanup_func)
     ((*current_context->cleanup_func)) (current_context->cleanup_arg);
 
@@ -256,6 +252,7 @@ static void xbt_ctx_sysv_stop(int exit_code)
 
 static void xbt_ctx_sysv_swap(xbt_context_t context)
 {
+  DEBUG2("Swap context: '%s' -> '%s'",current_context->name,context->name);
   xbt_assert0(current_context, "You have to call context_init() first.");
   xbt_assert0(context, "Invalid argument");
 
@@ -281,6 +278,7 @@ static void xbt_ctx_sysv_suspend(xbt_context_t context)
 {
   int rv;
 
+  DEBUG1("Suspend context: '%s'",current_context->name);
   xbt_ctx_sysv_t prev_context = ((xbt_ctx_sysv_t) context)->prev;
 
   current_context = (xbt_context_t) (((xbt_ctx_sysv_t) context)->prev);
@@ -296,6 +294,7 @@ static void xbt_ctx_sysv_resume(xbt_context_t context)
 {
   int rv;
 
+  DEBUG2("Resume context: '%s' (from '%s')",context->name,current_context->name);
   ((xbt_ctx_sysv_t) context)->prev = (xbt_ctx_sysv_t) current_context;
 
   current_context = context;
index 8e54725..bc29e1c 100644 (file)
@@ -14,6 +14,7 @@
 #include "xbt/swag.h"
 #include "xbt/xbt_os_thread.h"
 
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(xbt_context);
 
 typedef struct s_xbt_ctx_thread {
   XBT_CTX_BASE_T;
@@ -35,29 +36,17 @@ static int
 xbt_ctx_thread_factory_create_master_context(xbt_context_t * maestro);
 
 static int xbt_ctx_thread_factory_finalize(xbt_context_factory_t * factory);
-
 static void xbt_ctx_thread_free(xbt_context_t context);
-
 static void xbt_ctx_thread_kill(xbt_context_t context);
-
 static void xbt_ctx_thread_schedule(xbt_context_t context);
-
 static void xbt_ctx_thread_yield(void);
-
 static void xbt_ctx_thread_start(xbt_context_t context);
-
 static void xbt_ctx_thread_stop(int exit_code);
-
 static void xbt_ctx_thread_swap(xbt_context_t context);
-
 static void xbt_ctx_thread_schedule(xbt_context_t context);
-
 static void xbt_ctx_thread_yield(void);
-
 static void xbt_ctx_thread_suspend(xbt_context_t context);
-
 static void xbt_ctx_thread_resume(xbt_context_t context);
-
 static void *xbt_ctx_thread_wrapper(void *param);
 
 void xbt_ctx_thread_factory_init(xbt_context_factory_t * factory)
@@ -75,6 +64,7 @@ static int
 xbt_ctx_thread_factory_create_master_context(xbt_context_t * maestro)
 {
   *maestro = (xbt_context_t) xbt_new0(s_xbt_ctx_thread_t, 1);
+  (*maestro)->name = (char*)"maestro";
   return 0;
 }
 
@@ -95,6 +85,7 @@ xbt_ctx_thread_factory_create_context(const char *name, xbt_main_func_t code,
 {
   xbt_ctx_thread_t context = xbt_new0(s_xbt_ctx_thread_t, 1);
 
+  VERB1("Create context %s",name);
   context->code = code;
   context->name = xbt_strdup(name);
   context->begin = xbt_os_sem_init(0);
@@ -148,6 +139,7 @@ static void xbt_ctx_thread_free(xbt_context_t context)
 
 static void xbt_ctx_thread_kill(xbt_context_t context)
 {
+  DEBUG1("Kill context '%s'",context->name);
   context->iwannadie = 1;
   xbt_ctx_thread_swap(context);
 }
@@ -163,6 +155,7 @@ static void xbt_ctx_thread_kill(xbt_context_t context)
  */
 static void xbt_ctx_thread_schedule(xbt_context_t context)
 {
+  DEBUG1("Schedule context '%s'",context->name);
   xbt_assert0((current_context == maestro_context),
               "You are not supposed to run this function here!");
   xbt_ctx_thread_swap(context);
@@ -178,6 +171,7 @@ static void xbt_ctx_thread_schedule(xbt_context_t context)
  */
 static void xbt_ctx_thread_yield(void)
 {
+  DEBUG1("Yield context '%s'",current_context->name);
   xbt_assert0((current_context != maestro_context),
               "You are not supposed to run this function here!");
   xbt_ctx_thread_swap(current_context);
@@ -187,6 +181,7 @@ static void xbt_ctx_thread_start(xbt_context_t context)
 {
   xbt_ctx_thread_t ctx_thread = (xbt_ctx_thread_t) context;
 
+  DEBUG1("Start context '%s'",context->name);
   /* create and start the process */
   ctx_thread->thread =
     xbt_os_thread_create(ctx_thread->name, xbt_ctx_thread_wrapper,
@@ -198,6 +193,7 @@ static void xbt_ctx_thread_start(xbt_context_t context)
 
 static void xbt_ctx_thread_stop(int exit_code)
 {
+  /* please no debug here: our procdata was already free'd */
   if (current_context->cleanup_func)
     ((*current_context->cleanup_func)) (current_context->cleanup_arg);
 
@@ -212,7 +208,8 @@ static void xbt_ctx_thread_stop(int exit_code)
 }
 
 static void xbt_ctx_thread_swap(xbt_context_t context)
-{
+{ 
+  DEBUG2("Swap context: '%s' -> '%s'",current_context->name,context->name);
   if ((current_context != maestro_context) && !context->iwannadie) {
     /* (0) it's not the scheduler and the process doesn't want to die, it just wants to yield */
 
@@ -270,6 +267,7 @@ static void *xbt_ctx_thread_wrapper(void *param)
 
 static void xbt_ctx_thread_suspend(xbt_context_t context)
 {
+  DEBUG1("Suspend context '%s'",context->name);
   /* save the current context */
   xbt_context_t self = current_context;
 
@@ -285,6 +283,7 @@ static void xbt_ctx_thread_suspend(xbt_context_t context)
 
 static void xbt_ctx_thread_resume(xbt_context_t context)
 {
+  DEBUG1("Resume context '%s'",context->name);
   /* save the current context */
   xbt_context_t self = current_context;