From: Paul Bédaride Date: Wed, 30 Jan 2013 15:18:07 +0000 (+0100) Subject: Make MSG use SIMIX pids X-Git-Tag: v3_9_90~594 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/1625ecc60d22425fe2fdbd1d6d6cc9c69142de64 Make MSG use SIMIX pids --- diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index 46763d42b4..c53fd4e43e 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -342,7 +342,7 @@ XBT_PUBLIC(void) simcall_process_create(smx_process_t *process, int auto_restart); XBT_PUBLIC(void) simcall_process_kill(smx_process_t process); -XBT_PUBLIC(void) simcall_process_killall(void); +XBT_PUBLIC(void) simcall_process_killall(int reset_pid); /* Process handling */ XBT_PUBLIC(void) simcall_process_cleanup(smx_process_t process); diff --git a/src/msg/msg_global.c b/src/msg/msg_global.c index f40bf21962..3a3ad8ce9a 100644 --- a/src/msg/msg_global.c +++ b/src/msg/msg_global.c @@ -46,7 +46,6 @@ void MSG_init_nocheck(int *argc, char **argv) { #ifdef MSG_USE_DEPRECATED msg_global->max_channel = 0; #endif - msg_global->PID = 1; msg_global->sent_msg = 0; msg_global->task_copy_callback = NULL; msg_global->process_data_cleanup = NULL; @@ -152,14 +151,12 @@ void MSG_config(const char *key, const char *value){ */ int MSG_process_killall(int reset_PIDs) { - simcall_process_killall(); + simcall_process_killall(reset_PIDs); - if (reset_PIDs > 0) { - msg_global->PID = reset_PIDs; + if (reset_PIDs > 0) msg_global->session++; - } - return msg_global->PID; + return 0; } diff --git a/src/msg/msg_private.h b/src/msg/msg_private.h index b7801c9f70..cbc10c8df3 100644 --- a/src/msg/msg_private.h +++ b/src/msg/msg_private.h @@ -58,8 +58,6 @@ typedef struct simdata_gpu_task { typedef struct simdata_process { msg_host_t m_host; /* the host on which the process is running */ - int PID; /* used for debugging purposes */ - int PPID; /* The parent PID */ msg_host_t put_host; /* used for debugging purposes */ #ifdef MSG_USE_DEPRECATED m_channel_t put_channel; /* used for debugging purposes */ @@ -112,7 +110,6 @@ typedef struct MSG_Global { #ifdef MSG_USE_DEPRECATED int max_channel; #endif - int PID; int session; 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); diff --git a/src/msg/msg_process.c b/src/msg/msg_process.c index cf7ce52b6a..097cfaa4a5 100644 --- a/src/msg/msg_process.c +++ b/src/msg/msg_process.c @@ -162,7 +162,6 @@ msg_process_t MSG_process_create_with_environment(const char *name, msg_process_t process; /* Simulator data for MSG */ - simdata->PID = msg_global->PID++; simdata->waiting_action = NULL; simdata->waiting_task = NULL; simdata->m_host = host; @@ -171,23 +170,17 @@ msg_process_t MSG_process_create_with_environment(const char *name, simdata->data = data; simdata->last_errno = MSG_OK; - if (SIMIX_process_self()) { - simdata->PPID = MSG_process_get_PID(MSG_process_self()); - } else { - simdata->PPID = -1; - } - -#ifdef HAVE_TRACING - TRACE_msg_process_create(name, simdata->PID, simdata->m_host); -#endif /* Let's create the process: SIMIX may decide to start it right now, * even before returning the flow control to us */ simcall_process_create(&process, name, code, simdata, sg_host_name(host), -1, argc, argv, properties,0); + #ifdef HAVE_TRACING + TRACE_msg_process_create(name, simcall_process_get_PID(process), simdata->m_host); + #endif + if (!process) { /* Undo everything we have just changed */ - msg_global->PID--; xbt_free(simdata); return NULL; } @@ -344,10 +337,7 @@ int MSG_process_get_PID(msg_process_t process) if (process == NULL) { return 0; } - - simdata_process_t simdata = simcall_process_get_data(process); - - return simdata != NULL ? simdata->PID : 0; + return simcall_process_get_PID(process); } /** \ingroup m_process_management @@ -361,9 +351,7 @@ int MSG_process_get_PPID(msg_process_t process) { xbt_assert(process != NULL, "Invalid parameter"); - simdata_process_t simdata = simcall_process_get_data(process); - - return simdata->PPID; + return simcall_process_get_PPID(process); } /** \ingroup m_process_management diff --git a/src/simix/smx_global.c b/src/simix/smx_global.c index 6c0623cb71..7cd414d13e 100644 --- a/src/simix/smx_global.c +++ b/src/simix/smx_global.c @@ -124,7 +124,7 @@ static void SIMIX_clean(void) #endif /* Kill everyone (except maestro) */ - SIMIX_process_killall(simix_global->maestro_process); + SIMIX_process_killall(simix_global->maestro_process, 1); /* Exit the SIMIX network module */ SIMIX_network_exit(); diff --git a/src/simix/smx_process.c b/src/simix/smx_process.c index 6172807a78..ff48a3537e 100644 --- a/src/simix/smx_process.c +++ b/src/simix/smx_process.c @@ -144,6 +144,12 @@ void SIMIX_create_maestro_process() maestro->context = SIMIX_context_new(NULL, 0, NULL, NULL, maestro); maestro->simcall.issuer = maestro; + if (SIMIX_process_self()) { + maestro->ppid = SIMIX_process_get_PID(SIMIX_process_self()); + } else { + maestro->ppid = -1; + } + simix_global->maestro_process = maestro; return; } @@ -249,6 +255,12 @@ void SIMIX_process_create(smx_process_t *process, (*process)->comms = xbt_fifo_new(); (*process)->simcall.issuer = *process; + if (SIMIX_process_self()) { + (*process)->ppid = SIMIX_process_get_PID(SIMIX_process_self()); + } else { + (*process)->ppid = -1; + } + /* Process data for auto-restart */ (*process)->auto_restart = auto_restart; (*process)->code = code; @@ -370,14 +382,14 @@ void SIMIX_process_kill(smx_process_t process, smx_process_t issuer) { } -void SIMIX_pre_process_killall(smx_simcall_t simcall) { - SIMIX_process_killall(simcall->issuer); +void SIMIX_pre_process_killall(smx_simcall_t simcall, int reset_pid) { + SIMIX_process_killall(simcall->issuer, reset_pid); } /** * \brief Kills all running processes. * \param issuer this one will not be killed */ -void SIMIX_process_killall(smx_process_t issuer) +void SIMIX_process_killall(smx_process_t issuer, int reset_pid) { smx_process_t p = NULL; @@ -387,6 +399,9 @@ void SIMIX_process_killall(smx_process_t issuer) } } + if (reset_pid > 0) + simix_process_maxpid = reset_pid; + SIMIX_context_runall(); SIMIX_process_empty_trash(); @@ -538,6 +553,28 @@ int SIMIX_process_count(void) return xbt_swag_size(simix_global->process_list); } +int SIMIX_pre_process_get_PID(smx_simcall_t simcall, smx_process_t self){ + return SIMIX_process_get_PID(self); +} + +int SIMIX_process_get_PID(smx_process_t self){ + if (self == NULL) + return 0; + else + return self->pid; +} + +int SIMIX_pre_process_get_PPID(smx_simcall_t simcall, smx_process_t self){ + return SIMIX_process_get_PPID(self); +} + +int SIMIX_process_get_PPID(smx_process_t self){ + if (self == NULL) + return 0; + else + return self->ppid; +} + void* SIMIX_pre_process_self_get_data(smx_simcall_t simcall, smx_process_t self){ return SIMIX_process_self_get_data(self); } diff --git a/src/simix/smx_process_private.h b/src/simix/smx_process_private.h index 414d8b1e2f..de9b038c6a 100644 --- a/src/simix/smx_process_private.h +++ b/src/simix/smx_process_private.h @@ -36,6 +36,7 @@ typedef struct s_smx_process { s_xbt_swag_hookup_t destroy_hookup; unsigned long pid; + unsigned long ppid; 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 (uctx/raw/thread) that executes the user function */ @@ -72,7 +73,7 @@ void SIMIX_process_create(smx_process_t *process, int auto_restart); void SIMIX_process_runall(void); void SIMIX_process_kill(smx_process_t process, smx_process_t issuer); -void SIMIX_process_killall(smx_process_t issuer); +void SIMIX_process_killall(smx_process_t issuer, int reset_pid); smx_process_t SIMIX_process_create_from_wrapper(smx_process_arg_t args); void SIMIX_create_maestro_process(void); void SIMIX_process_stop(smx_process_t arg); @@ -88,6 +89,7 @@ void SIMIX_process_change_host(smx_process_t process, void SIMIX_pre_process_suspend(smx_simcall_t simcall, smx_process_t process); smx_action_t SIMIX_process_suspend(smx_process_t process, smx_process_t issuer); void SIMIX_process_resume(smx_process_t process, smx_process_t issuer); +int SIMIX_process_get_PID(smx_process_t self); void* SIMIX_process_get_data(smx_process_t process); void SIMIX_process_set_data(smx_process_t process, void *data); smx_host_t SIMIX_process_get_host(smx_process_t process); @@ -111,11 +113,12 @@ void SIMIX_pre_process_create(smx_simcall_t simcall, smx_process_t *process, const char *hostname, double kill_time, int argc, char **argv, xbt_dict_t properties, int auto_restart); void SIMIX_pre_process_kill(smx_simcall_t simcall, smx_process_t process); -void SIMIX_pre_process_killall(smx_simcall_t simcall); +void SIMIX_pre_process_killall(smx_simcall_t simcall, int reset_pid); void SIMIX_pre_process_cleanup(smx_simcall_t simcall, smx_process_t process); void SIMIX_pre_process_resume(smx_simcall_t simcall, smx_process_t process); int SIMIX_pre_process_count(smx_simcall_t simcall); void* SIMIX_pre_process_self_get_data(smx_simcall_t simcall, smx_process_t process); +int SIMIX_pre_process_get_PID(smx_simcall_t simcall, smx_process_t self); void* SIMIX_pre_process_get_data(smx_simcall_t simcall, smx_process_t process); void SIMIX_pre_process_set_data(smx_simcall_t simcall, smx_process_t process, void *data); diff --git a/src/simix/smx_smurf_private.h b/src/simix/smx_smurf_private.h index a418dd0908..aaa090fb28 100644 --- a/src/simix/smx_smurf_private.h +++ b/src/simix/smx_smurf_private.h @@ -276,12 +276,14 @@ ACTION(SIMCALL_HOST_EXECUTION_SET_PRIORITY, host_execution_set_priority, WITH_AN ACTION(SIMCALL_HOST_EXECUTION_WAIT, host_execution_wait, WITHOUT_ANSWER, TINT(result), TSPEC(execution, smx_action_t)) sep \ ACTION(SIMCALL_PROCESS_CREATE, process_create, WITH_ANSWER, TVOID(result), TSPEC(process, smx_process_t*), TSTRING(name), TSPEC(code, xbt_main_func_t), TPTR(data), TSTRING(hostname), TDOUBLE(kill_time), TINT(argc), TSPEC(argv, char**), TSPEC(properties, xbt_dict_t), TINT(auto_restart)) sep \ ACTION(SIMCALL_PROCESS_KILL, process_kill, WITH_ANSWER, TVOID(result), TSPEC(process, smx_process_t)) sep \ -ACTION(SIMCALL_PROCESS_KILLALL, process_killall, WITH_ANSWER, TVOID(result)) sep \ +ACTION(SIMCALL_PROCESS_KILLALL, process_killall, WITH_ANSWER, TVOID(result), TINT(reset_pid)) sep \ ACTION(SIMCALL_PROCESS_CLEANUP, process_cleanup, WITH_ANSWER, TVOID(result), TSPEC(process, smx_process_t)) sep \ ACTION(SIMCALL_PROCESS_CHANGE_HOST, process_change_host, WITH_ANSWER, TVOID(result), TSPEC(process, smx_process_t), TSPEC(dest, smx_host_t)) sep \ ACTION(SIMCALL_PROCESS_SUSPEND, process_suspend, WITHOUT_ANSWER, TVOID(result), TSPEC(process, smx_process_t)) sep \ ACTION(SIMCALL_PROCESS_RESUME, process_resume, WITH_ANSWER, TVOID(result), TSPEC(process, smx_process_t)) sep \ ACTION(SIMCALL_PROCESS_COUNT, process_count, WITH_ANSWER, TINT(result)) sep \ +ACTION(SIMCALL_PROCESS_GET_PID, process_get_PID, WITH_ANSWER, TINT(result), TSPEC(process, smx_process_t)) sep \ +ACTION(SIMCALL_PROCESS_GET_PPID, process_get_PPID, WITH_ANSWER, TINT(result), TSPEC(process, smx_process_t)) sep \ ACTION(SIMCALL_PROCESS_GET_DATA, process_get_data, WITH_ANSWER, TPTR(result), TSPEC(process, smx_process_t)) sep \ ACTION(SIMCALL_PROCESS_SET_DATA, process_set_data, WITH_ANSWER, TVOID(result), TSPEC(process, smx_process_t), TPTR(data)) sep \ ACTION(SIMCALL_PROCESS_GET_HOST, process_get_host, WITH_ANSWER, TSPEC(result, smx_host_t), TSPEC(process, smx_process_t)) sep \ diff --git a/src/simix/smx_user.c b/src/simix/smx_user.c index 15fca99e57..b9099f5877 100644 --- a/src/simix/smx_user.c +++ b/src/simix/smx_user.c @@ -323,9 +323,9 @@ void simcall_process_kill(smx_process_t process) * \ingroup simix_process_management * \brief Kills all SIMIX processes. */ -void simcall_process_killall(void) +void simcall_process_killall(int reset_pid) { - simcall_BODY_process_killall(); + simcall_BODY_process_killall(reset_pid); } /** @@ -393,6 +393,38 @@ int simcall_process_count(void) return simcall_BODY_process_count(); } +/** + * \ingroup simix_process_management + * \brief Return the PID of a #smx_process_t. + * \param process a SIMIX process + * \return the PID of this process + */ +int simcall_process_get_PID(smx_process_t process) +{ + if (process == SIMIX_process_self()) { + /* avoid a simcall if this function is called by the process itself */ + return SIMIX_process_get_PID(process); + } + + return simcall_BODY_process_get_PID(process); +} + +/** + * \ingroup simix_process_management + * \brief Return the parent PID of a #smx_process_t. + * \param process a SIMIX process + * \return the PID of this process parenrt + */ +int simcall_process_get_PPID(smx_process_t process) +{ + if (process == SIMIX_process_self()) { + /* avoid a simcall if this function is called by the process itself */ + return SIMIX_process_get_PPID(process); + } + + return simcall_BODY_process_get_PPID(process); +} + /** * \ingroup simix_process_management * \brief Return the user data of a #smx_process_t. diff --git a/teshsuite/msg/pid.tesh b/teshsuite/msg/pid.tesh index c91fedf15d..04b6943b93 100644 --- a/teshsuite/msg/pid.tesh +++ b/teshsuite/msg/pid.tesh @@ -1,4 +1,3 @@ -! output sort $ msg/pid ${srcdir:=.}/msg/pid.xml 0 "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" > [ 0.000000] (1:sendpid@toto) Sending pid of "1". > [ 0.000000] (2:sendpid@toto) Sending pid of "2". @@ -14,15 +13,15 @@ $ msg/pid ${srcdir:=.}/msg/pid.xml 0 "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" > [ 0.003247] (3:sendpid@toto) Process "3" killed. $ msg/pid ${srcdir:=.}/msg/pid.xml 2 "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" -> [ 0.000000] (10:sendpid@toto) Sending pid of "2". -> [ 0.000000] (11:sendpid@toto) Sending pid of "3". -> [ 0.000000] (12:sendpid@toto) Sending pid of "4". -> [ 0.001082] (13:killall@toto) Killing process "2". -> [ 0.001082] (1:sendpid@toto) Send of pid "2" done. -> [ 0.001082] (1:sendpid@toto) Process "2" killed. -> [ 0.002165] (2:sendpid@toto) Send of pid "3" done. -> [ 0.002165] (4:killall@toto) Killing process "3". -> [ 0.002165] (2:sendpid@toto) Process "3" killed. -> [ 0.003247] (3:sendpid@toto) Send of pid "4" done. -> [ 0.003247] (4:killall@toto) Killing process "4". -> [ 0.003247] (3:sendpid@toto) Process "4" killed. +> [ 0.000000] (2:sendpid@toto) Sending pid of "2". +> [ 0.000000] (3:sendpid@toto) Sending pid of "3". +> [ 0.000000] (4:sendpid@toto) Sending pid of "4". +> [ 0.001082] (5:killall@toto) Killing process "2". +> [ 0.001082] (2:sendpid@toto) Send of pid "2" done. +> [ 0.001082] (2:sendpid@toto) Process "2" killed. +> [ 0.002165] (3:sendpid@toto) Send of pid "3" done. +> [ 0.002165] (5:killall@toto) Killing process "3". +> [ 0.002165] (3:sendpid@toto) Process "3" killed. +> [ 0.003247] (4:sendpid@toto) Send of pid "4" done. +> [ 0.003247] (5:killall@toto) Killing process "4". +> [ 0.003247] (4:sendpid@toto) Process "4" killed.