Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add option to msg to debug multiple use of task
authorPaul Bédaride <paul.bedaride@gmail.com>
Thu, 17 Apr 2014 15:40:31 +0000 (17:40 +0200)
committerPaul Bédaride <paul.bedaride@gmail.com>
Thu, 17 Apr 2014 15:40:53 +0000 (17:40 +0200)
src/msg/msg_global.c
src/msg/msg_gos.c
src/msg/msg_mailbox.c
src/msg/msg_private.h

index 52d88d8..f00a073 100644 (file)
@@ -25,6 +25,11 @@ static void MSG_exit(void);
 
 /********************************* MSG **************************************/
 
+static void _sg_cfg_cb_msg_multiple_backtraces(const char *name, int pos)
+{
+  msg_global->multiple_backtraces = xbt_cfg_get_boolean(_sg_cfg_set, name);
+}
+
 /**
  * \ingroup msg_simulation
  * \brief Initialize MSG with less verifications
@@ -39,10 +44,15 @@ void MSG_init_nocheck(int *argc, char **argv) {
   xbt_getpid = MSG_process_self_PID;
   if (!msg_global) {
 
-    SIMIX_global_init(argc, argv);
-    
     msg_global = xbt_new0(s_MSG_Global_t, 1);
 
+    xbt_cfg_register(&_sg_cfg_set, "msg/multiple_backtraces",
+                     "Keep the severals backtraces",
+                     xbt_cfgelm_boolean, 1, 1, _sg_cfg_cb_msg_multiple_backtraces, NULL);
+    xbt_cfg_setdefault_boolean(_sg_cfg_set, "msg/multiple_backtraces", "no");
+
+    SIMIX_global_init(argc, argv);
+
 #ifdef MSG_USE_DEPRECATED
     msg_global->max_channel = 0;
 #endif
@@ -58,7 +68,7 @@ void MSG_init_nocheck(int *argc, char **argv) {
 
     sg_platf_postparse_add_cb(MSG_post_create_environment);
   }
-  
+
   if(MC_is_active()){
     /* Ignore total amount of messages sent during the simulation for heap comparison */
     MC_ignore_heap(&(msg_global->sent_msg), sizeof(msg_global->sent_msg));
index dbf0eac..de83be3 100644 (file)
@@ -58,7 +58,7 @@ msg_error_t MSG_parallel_task_execute(msg_task_t task)
 
   xbt_assert((!simdata->compute) && (task->simdata->isused == 0),
              "This task is executed somewhere else. Go fix your code! %d",
-             task->simdata->isused);
+             task->simdata->isused!=NULL);
 
   XBT_DEBUG("Computing on %s", MSG_process_get_name(MSG_process_self()));
 
@@ -71,8 +71,10 @@ msg_error_t MSG_parallel_task_execute(msg_task_t task)
 
 
   TRY {
-
-    simdata->isused=1;
+    if (msg_global->multiple_backtraces)
+      MSG_BT(simdata->isused, "Using Backtrace");
+    else
+      simdata->isused = (void*)1;
 
     if (simdata->host_nb > 0) {
       simdata->compute = simcall_host_parallel_execute(task->name,
@@ -405,10 +407,20 @@ msg_comm_t MSG_task_isend_internal(msg_task_t task, const char *alias,
   t_simdata->sender = process;
   t_simdata->source = ((simdata_process_t) SIMIX_process_self_get_data(process))->m_host;
 
-  xbt_assert(t_simdata->isused == 0,
-              "This task is still being used somewhere else. You cannot send it now. Go fix your code!");
+  if (t_simdata->isused != 0) {
+    if (msg_global->multiple_backtraces){
+      XBT_ERROR("This task is already used in there:");
+      xbt_backtrace_display(t_simdata->isused);
+      THROWF(unknown_error, 0, "And you try to reuse it from here. You cannot send it now. Go fix your code!");
+    } else {
+      THROWF(unknown_error, 0, "This task is still being used somewhere else. You cannot send it now. Go fix your code! (use --cfg=msg/multiple_backtraces:on to get the backtrace of the other process)");
+    }
+  }
 
-  t_simdata->isused = 1;
+  if (msg_global->multiple_backtraces)
+    MSG_BT(t_simdata->isused, "Using Backtrace");
+  else
+    t_simdata->isused = (void*)1;
   t_simdata->comm = NULL;
   msg_global->sent_msg++;
 
index b8b63a2..7e5e577 100644 (file)
@@ -58,13 +58,13 @@ msg_mailbox_t MSG_mailbox_get_by_alias(const char *alias)
 /** \ingroup msg_mailbox_management
  * \brief Set the mailbox to receive in asynchronous mode
  *
- * All messages sent to this mailbox will be transferred to 
- * the receiver without waiting for the receive call. 
+ * All messages sent to this mailbox will be transferred to
+ * the receiver without waiting for the receive call.
  * The receive call will still be necessary to use the received data.
- * If there is a need to receive some messages asynchronously, and some not, 
+ * If there is a need to receive some messages asynchronously, and some not,
  * two different mailboxes should be used.
  *
- * \param alias The name of the mailbox 
+ * \param alias The name of the mailbox
  */
 void MSG_mailbox_set_async(const char *alias){
   msg_mailbox_t mailbox = MSG_mailbox_get_by_alias(alias);
@@ -180,10 +180,20 @@ MSG_mailbox_put_with_timeout(msg_mailbox_t mailbox, msg_task_t task,
   t_simdata->sender = process;
   t_simdata->source = ((simdata_process_t) SIMIX_process_self_get_data(process))->m_host;
 
-  xbt_assert(t_simdata->isused == 0,
-              "This task is still being used somewhere else. You cannot send it now. Go fix your code!");
+  if (t_simdata->isused != 0) {
+    if (msg_global->multiple_backtraces){
+      XBT_ERROR("This task is already used in there:");
+      xbt_backtrace_display(t_simdata->isused);
+      THROWF(unknown_error, 0, "And you try to reuse it from here. You cannot send it now. Go fix your code!");
+    } else {
+      THROWF(unknown_error, 0, "This task is still being used somewhere else. You cannot send it now. Go fix your code! (use --cfg=msg/multiple_backtraces:on to get the backtrace of the other process)");
+    }
+  }
 
-  t_simdata->isused=1;
+  if (msg_global->multiple_backtraces)
+    MSG_BT(t_simdata->isused, "Using Backtrace");
+  else
+    t_simdata->isused = (void*)1;
   t_simdata->comm = NULL;
   msg_global->sent_msg++;
 
index 5644882..480d01e 100644 (file)
@@ -22,6 +22,22 @@ SG_BEGIN_DECL()
 
 /********************************* Task **************************************/
 
+
+#define MSG_BT(ptr, m)                              \
+  do {xbt_ex_t *_xbt_ex_t = xbt_new0(xbt_ex_t, 1); \
+  /* build the exception */                                             \
+  _xbt_ex_t->msg      = (bprintf(m));                                 \
+  _xbt_ex_t->category = (xbt_errcat_t)(0);                   \
+  _xbt_ex_t->value    = (0);                                 \
+  _xbt_ex_t->procname = (char*)xbt_procname();               \
+  _xbt_ex_t->pid      = xbt_getpid();                        \
+  _xbt_ex_t->file     = (char*)__FILE__;                     \
+  _xbt_ex_t->line     = __LINE__;                            \
+  _xbt_ex_t->func     = (char*)_XBT_FUNCTION;                \
+  _xbt_ex_t->bt_strings = NULL;                              \
+  xbt_backtrace_current(_xbt_ex_t); \
+  ptr = _xbt_ex_t; } while(0)
+
 typedef struct simdata_task {
   smx_action_t compute;         /* SIMIX modeling of computation */
   smx_action_t comm;            /* SIMIX modeling of communication */
@@ -37,7 +53,7 @@ typedef struct simdata_task {
   /* CPU affinity database of this task */
   xbt_dict_t affinity_mask_db; /* smx_host_t host => unsigned long mask */
 
-  int isused;  /* Indicates whether the task is used in SIMIX currently */
+  void *isused;  /* Indicates whether the task is used in SIMIX currently */
   int host_nb;                  /* ==0 if sequential task; parallel task if not */
   /*******  Parallel Tasks Only !!!! *******/
   smx_host_t *host_list;
@@ -114,6 +130,7 @@ typedef struct MSG_Global {
   int max_channel;
 #endif
   int session;
+  int multiple_backtraces;
   unsigned long int sent_msg;   /* Total amount of messages sent during the simulation */
   void (*task_copy_callback) (msg_task_t task, msg_process_t src, msg_process_t dst);
   void_f_pvoid_t process_data_cleanup;