From 36f55a5f2d60d4c9d96c0f7a4473dc24638cd7d1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20B=C3=A9daride?= Date: Thu, 17 Apr 2014 17:40:31 +0200 Subject: [PATCH] Add option to msg to debug multiple use of task --- src/msg/msg_global.c | 16 +++++++++++++--- src/msg/msg_gos.c | 24 ++++++++++++++++++------ src/msg/msg_mailbox.c | 24 +++++++++++++++++------- src/msg/msg_private.h | 19 ++++++++++++++++++- 4 files changed, 66 insertions(+), 17 deletions(-) diff --git a/src/msg/msg_global.c b/src/msg/msg_global.c index 52d88d8870..f00a0733cb 100644 --- a/src/msg/msg_global.c +++ b/src/msg/msg_global.c @@ -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)); diff --git a/src/msg/msg_gos.c b/src/msg/msg_gos.c index dbf0eac49c..de83be3bfc 100644 --- a/src/msg/msg_gos.c +++ b/src/msg/msg_gos.c @@ -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++; diff --git a/src/msg/msg_mailbox.c b/src/msg/msg_mailbox.c index b8b63a28d7..7e5e577098 100644 --- a/src/msg/msg_mailbox.c +++ b/src/msg/msg_mailbox.c @@ -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++; diff --git a/src/msg/msg_private.h b/src/msg/msg_private.h index 56448820b1..480d01ec22 100644 --- a/src/msg/msg_private.h +++ b/src/msg/msg_private.h @@ -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; -- 2.20.1