2004-09-26 17:43:35 +00:00
|
|
|
/*
|
2005-11-05 19:57:48 +00:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
2011-06-23 20:38:02 +00:00
|
|
|
* Copyright (c) 2004-2011 The University of Tennessee and The University
|
2005-11-05 19:57:48 +00:00
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2004-11-28 20:09:25 +00:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
2005-03-24 12:43:37 +00:00
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2008-07-25 15:23:23 +00:00
|
|
|
* Copyright (c) 2008 Institut National de Recherche en Informatique
|
|
|
|
* et Automatique. All rights reserved.
|
2012-04-06 14:23:13 +00:00
|
|
|
* Copyright (c) 2011 Los Alamos National Security, LLC.
|
|
|
|
* All rights reserved.
|
2004-11-22 01:38:40 +00:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
2004-09-26 17:43:35 +00:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
*
|
|
|
|
* Interface for waitpid / async notification of child death with the
|
|
|
|
* libevent runtime system.
|
|
|
|
*/
|
2005-03-14 20:57:21 +00:00
|
|
|
#ifndef ORTE_WAIT_H
|
|
|
|
#define ORTE_WAIT_H
|
2004-09-26 17:43:35 +00:00
|
|
|
|
2005-03-14 20:57:21 +00:00
|
|
|
#include "orte_config.h"
|
2004-09-26 17:43:35 +00:00
|
|
|
|
2004-10-20 01:03:09 +00:00
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
2004-09-26 17:43:35 +00:00
|
|
|
#include <sys/types.h>
|
2004-10-20 01:03:09 +00:00
|
|
|
#endif
|
2012-06-11 19:59:53 +00:00
|
|
|
#if HAVE_TIME_H
|
|
|
|
#include <time.h>
|
|
|
|
#endif
|
|
|
|
#if HAVE_SYS_TIME_H
|
2008-02-28 01:57:57 +00:00
|
|
|
#include <sys/time.h>
|
2006-08-23 03:32:36 +00:00
|
|
|
#endif
|
|
|
|
|
2008-02-28 19:58:32 +00:00
|
|
|
#include "opal/dss/dss.h"
|
2009-03-17 22:37:15 +00:00
|
|
|
#include "opal/util/output.h"
|
2008-08-05 15:09:29 +00:00
|
|
|
#include "opal/sys/atomic.h"
|
Update libevent to the 2.0 series, currently at 2.0.7rc. We will update to their final release when it becomes available. Currently known errors exist in unused portions of the libevent code. This revision passes the IBM test suite on a Linux machine and on a standalone Mac.
This is a fairly intrusive change, but outside of the moving of opal/event to opal/mca/event, the only changes involved (a) changing all calls to opal_event functions to reflect the new framework instead, and (b) ensuring that all opal_event_t objects are properly constructed since they are now true opal_objects.
Note: Shiqing has just returned from vacation and has not yet had a chance to complete the Windows integration. Thus, this commit almost certainly breaks Windows support on the trunk. However, I want this to have a chance to soak for as long as possible before I become less available a week from today (going to be at a class for 5 days, and thus will only be sparingly available) so we can find and fix any problems.
Biggest change is moving the libevent code from opal/event to a new opal/mca/event framework. This was done to make it much easier to update libevent in the future. New versions can be inserted as a new component and tested in parallel with the current version until validated, then we can remove the earlier version if we so choose. This is a statically built framework ala installdirs, so only one component will build at a time. There is no selection logic - the sole compiled component simply loads its function pointers into the opal_event struct.
I have gone thru the code base and converted all the libevent calls I could find. However, I cannot compile nor test every environment. It is therefore quite likely that errors remain in the system. Please keep an eye open for two things:
1. compile-time errors: these will be obvious as calls to the old functions (e.g., opal_evtimer_new) must be replaced by the new framework APIs (e.g., opal_event.evtimer_new)
2. run-time errors: these will likely show up as segfaults due to missing constructors on opal_event_t objects. It appears that it became a typical practice for people to "init" an opal_event_t by simply using memset to zero it out. This will no longer work - you must either OBJ_NEW or OBJ_CONSTRUCT an opal_event_t. I tried to catch these cases, but may have missed some. Believe me, you'll know when you hit it.
There is also the issue of the new libevent "no recursion" behavior. As I described on a recent email, we will have to discuss this and figure out what, if anything, we need to do.
This commit was SVN r23925.
2010-10-24 18:35:54 +00:00
|
|
|
#include "opal/mca/event/event.h"
|
2012-06-11 19:59:53 +00:00
|
|
|
#include "opal/runtime/opal_progress.h"
|
2008-02-28 01:57:57 +00:00
|
|
|
|
2009-04-29 01:32:14 +00:00
|
|
|
#include "orte/types.h"
|
2008-02-28 19:58:32 +00:00
|
|
|
#include "orte/mca/rml/rml_types.h"
|
2010-10-26 02:41:42 +00:00
|
|
|
#include "opal/runtime/opal_progress.h"
|
2008-02-28 01:57:57 +00:00
|
|
|
|
|
|
|
BEGIN_C_DECLS
|
|
|
|
|
2004-09-26 17:43:35 +00:00
|
|
|
/** typedef for callback function used in \c ompi_rte_wait_cb */
|
2005-03-14 20:57:21 +00:00
|
|
|
typedef void (*orte_wait_fn_t)(pid_t wpid, int status, void *data);
|
2004-09-26 17:43:35 +00:00
|
|
|
|
2008-07-25 15:23:23 +00:00
|
|
|
/**
|
|
|
|
* Disable / re-Enable SIGCHLD handler
|
|
|
|
*
|
|
|
|
* These functions have to be used after orte_wait_init was called.
|
|
|
|
*/
|
|
|
|
|
|
|
|
ORTE_DECLSPEC void orte_wait_enable(void);
|
|
|
|
ORTE_DECLSPEC void orte_wait_disable(void);
|
|
|
|
|
2004-09-26 17:43:35 +00:00
|
|
|
/**
|
|
|
|
* Wait for process terminiation
|
|
|
|
*
|
2005-03-14 20:57:21 +00:00
|
|
|
* Similar to \c waitpid, \c orte_waitpid utilizes the run-time
|
2004-09-26 17:43:35 +00:00
|
|
|
* event library for process terminiation notification. The \c
|
|
|
|
* WUNTRACED option is not supported, but the \c WNOHANG option is
|
|
|
|
* supported.
|
|
|
|
*
|
|
|
|
* \note A \c wpid value of \c -1 is not currently supported and will
|
|
|
|
* return an error.
|
|
|
|
*/
|
2006-08-23 03:32:36 +00:00
|
|
|
ORTE_DECLSPEC pid_t orte_waitpid(pid_t wpid, int *status, int options);
|
2004-09-26 17:43:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register a callback for process termination
|
|
|
|
*
|
|
|
|
* Register a callback for notification when \c wpid causes a SIGCHLD.
|
|
|
|
* \c waitpid() will have already been called on the process at this
|
|
|
|
* time.
|
|
|
|
*
|
|
|
|
* If a thread is already blocked in \c ompi_rte_waitpid for \c wpid,
|
2006-02-12 01:33:29 +00:00
|
|
|
* this function will return \c ORTE_ERR_EXISTS. It is illegal for
|
2005-03-18 03:43:59 +00:00
|
|
|
* multiple callbacks to be registered for a single \c wpid
|
|
|
|
* (OMPI_EXISTS will be returned in this case).
|
2004-09-26 17:43:35 +00:00
|
|
|
*
|
|
|
|
* \warning It is not legal for \c wpid to be -1 when registering a
|
|
|
|
* callback.
|
|
|
|
*/
|
2006-08-23 03:32:36 +00:00
|
|
|
ORTE_DECLSPEC int orte_wait_cb(pid_t wpid, orte_wait_fn_t callback, void *data);
|
2004-09-26 17:43:35 +00:00
|
|
|
|
2006-08-23 03:32:36 +00:00
|
|
|
ORTE_DECLSPEC int orte_wait_cb_cancel(pid_t wpid);
|
2004-10-26 22:11:03 +00:00
|
|
|
|
2006-08-23 03:32:36 +00:00
|
|
|
ORTE_DECLSPEC int orte_wait_cb_disable(void);
|
2004-10-26 22:11:03 +00:00
|
|
|
|
2006-08-23 03:32:36 +00:00
|
|
|
ORTE_DECLSPEC int orte_wait_cb_enable(void);
|
2004-09-26 17:43:35 +00:00
|
|
|
|
2012-04-06 14:23:13 +00:00
|
|
|
/* define an object for timer events */
|
2008-02-28 19:58:32 +00:00
|
|
|
typedef struct {
|
|
|
|
opal_object_t super;
|
2012-04-06 14:23:13 +00:00
|
|
|
struct timeval tv;
|
Fix a potential, albeit perhaps esoteric, race condition that can occur for fast HNP's, slow orteds, and fast apps. Under those conditions, it is possible for the orted to be caught in its original send of contact info back to the HNP, and thus for the progress stack never to recover back to a high level. In those circumstances, the orted can "hang" when trying to exit.
Add a new function to opal_progress that tells us our recursion depth to support that solution.
Yes, I know this sounds picky, but good ol' Jeff managed to make it happen by driving his cluster near to death...
Also ensure that we declare "failed" for the daemon job when daemons fail instead of the application job. This is important so that orte knows that it cannot use xcast to tell daemons to "exit", nor should it expect all daemons to respond. Otherwise, it is possible to hang.
After lots of testing, decide to default (again) to slurm detecting failed orteds. This proved necessary to avoid rather annoying hangs that were difficult to recover from. There are conditions where slurm will fail to launch all daemons (slurm folks are working on it), and yet again, good ol' Jeff managed to find both of them.
Thanks you Jeff! :-/
This commit was SVN r18611.
2008-06-06 19:36:27 +00:00
|
|
|
opal_event_t *ev;
|
2012-04-06 14:23:13 +00:00
|
|
|
void *payload;
|
|
|
|
} orte_timer_t;
|
|
|
|
OBJ_CLASS_DECLARATION(orte_timer_t);
|
2008-02-28 01:57:57 +00:00
|
|
|
|
2012-06-11 19:59:53 +00:00
|
|
|
/* In a few places, we need to barrier until something happens
|
|
|
|
* that changes a flag to indicate we can release - e.g., waiting
|
|
|
|
* for a specific message to arrive. If no progress thread is running,
|
|
|
|
* we cycle across opal_progress - however, if a progress thread
|
|
|
|
* is active, then we need to just nanosleep to avoid cross-thread
|
|
|
|
* confusion
|
|
|
|
*/
|
|
|
|
#if ORTE_ENABLE_PROGRESS_THREADS
|
2012-11-15 15:54:38 +00:00
|
|
|
#define ORTE_WAIT_FOR_COMPLETION(flg) \
|
|
|
|
do { \
|
|
|
|
opal_output_verbose(1, orte_progress_thread_debug, \
|
|
|
|
"%s waiting on progress thread at %s:%d", \
|
|
|
|
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), \
|
|
|
|
__FILE__, __LINE__); \
|
|
|
|
while ((flg)) { \
|
|
|
|
/* provide a very short quiet period so we \
|
|
|
|
* don't hammer the cpu while \
|
|
|
|
*/ \
|
|
|
|
struct timespec tp = {0, 100}; \
|
|
|
|
nanosleep(&tp, NULL); \
|
|
|
|
} \
|
2012-06-11 19:59:53 +00:00
|
|
|
}while(0);
|
2012-11-15 15:54:38 +00:00
|
|
|
|
|
|
|
|
2012-06-11 19:59:53 +00:00
|
|
|
#else
|
2012-11-15 15:54:38 +00:00
|
|
|
#define ORTE_WAIT_FOR_COMPLETION(flg) \
|
|
|
|
do { \
|
|
|
|
opal_output_verbose(1, orte_progress_thread_debug, \
|
|
|
|
"%s looping opal_progress at %s:%d", \
|
|
|
|
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), \
|
|
|
|
__FILE__, __LINE__); \
|
|
|
|
while ((flg)) { \
|
|
|
|
opal_progress(); \
|
|
|
|
} \
|
2012-06-11 19:59:53 +00:00
|
|
|
}while(0);
|
|
|
|
#endif
|
|
|
|
|
2008-02-28 01:57:57 +00:00
|
|
|
/**
|
|
|
|
* In a number of places within the code, we want to setup a timer
|
|
|
|
* to detect when some procedure failed to complete. For example,
|
|
|
|
* when we launch the daemons, we frequently have no way to directly
|
|
|
|
* detect that a daemon failed to launch. Setting a timer allows us
|
|
|
|
* to automatically fail out of the launch if we don't hear from a
|
|
|
|
* daemon in some specified time window.
|
|
|
|
*
|
|
|
|
* Computing the amount of time to wait takes a few lines of code, but
|
|
|
|
* this macro encapsulates those lines along with the timer event
|
|
|
|
* definition just as a convenience. It also centralizes the
|
|
|
|
* necessary checks to ensure that the microsecond field is always
|
|
|
|
* less than 1M since some systems care about that, and to ensure
|
|
|
|
* that the computed wait time doesn't exceed the desired max
|
|
|
|
* wait
|
2012-04-06 14:23:13 +00:00
|
|
|
*
|
|
|
|
* NOTE: the callback function is responsible for releasing the timer
|
|
|
|
* event back to the event pool!
|
2008-02-28 01:57:57 +00:00
|
|
|
*/
|
2012-04-06 14:23:13 +00:00
|
|
|
#define ORTE_DETECT_TIMEOUT(n, deltat, maxwait, cbfunc, cbd) \
|
2008-10-16 14:21:37 +00:00
|
|
|
do { \
|
2012-04-06 14:23:13 +00:00
|
|
|
orte_timer_t *tmp; \
|
2008-10-16 14:21:37 +00:00
|
|
|
int timeout; \
|
2012-04-06 14:23:13 +00:00
|
|
|
tmp = OBJ_NEW(orte_timer_t); \
|
|
|
|
tmp->payload = (cbd); \
|
|
|
|
opal_event_evtimer_set(orte_event_base, \
|
|
|
|
tmp->ev, (cbfunc), tmp); \
|
|
|
|
opal_event_set_priority(tmp->ev, ORTE_ERROR_PRI); \
|
2008-10-16 14:21:37 +00:00
|
|
|
timeout = (deltat) * (n); \
|
|
|
|
if ((maxwait) > 0 && timeout > (maxwait)) { \
|
|
|
|
timeout = (maxwait); \
|
|
|
|
} \
|
2012-04-06 14:23:13 +00:00
|
|
|
tmp->tv.tv_sec = timeout/1000000; \
|
|
|
|
tmp->tv.tv_usec = timeout%1000000; \
|
2008-10-16 14:21:37 +00:00
|
|
|
OPAL_OUTPUT_VERBOSE((1, orte_debug_output, \
|
|
|
|
"defining timeout: %ld sec %ld usec at %s:%d", \
|
2012-04-06 14:23:13 +00:00
|
|
|
(long)tmp->tv.tv_sec, (long)tmp->tv.tv_usec, \
|
2008-10-16 14:21:37 +00:00
|
|
|
__FILE__, __LINE__)); \
|
2012-04-06 14:23:13 +00:00
|
|
|
opal_event_evtimer_add(tmp->ev, &tmp->tv); \
|
2008-11-14 20:22:36 +00:00
|
|
|
}while(0); \
|
2008-02-28 01:57:57 +00:00
|
|
|
|
2008-03-05 13:51:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* There are places in the code where we just want to periodically
|
|
|
|
* wakeup to do something, and then go back to sleep again. Setting
|
|
|
|
* a timer allows us to do this
|
2012-04-06 14:23:13 +00:00
|
|
|
*
|
|
|
|
* NOTE: the callback function is responsible for releasing the timer
|
|
|
|
* event back to the event pool when done! Otherwise, the finalize
|
|
|
|
* function will take care of it.
|
2008-03-05 13:51:32 +00:00
|
|
|
*/
|
2012-04-06 14:23:13 +00:00
|
|
|
#define ORTE_TIMER_EVENT(sec, usec, cbfunc, pri) \
|
2008-12-10 20:40:47 +00:00
|
|
|
do { \
|
2012-04-06 14:23:13 +00:00
|
|
|
orte_timer_t *tm; \
|
|
|
|
tm = OBJ_NEW(orte_timer_t); \
|
|
|
|
opal_event_evtimer_set(orte_event_base, \
|
|
|
|
tm->ev, (cbfunc), tm); \
|
|
|
|
opal_event_set_priority(tm->ev, (pri)); \
|
|
|
|
tm->tv.tv_sec = (sec) + (usec)/1000000; \
|
|
|
|
tm->tv.tv_usec = (usec) % 1000000; \
|
2008-12-10 20:40:47 +00:00
|
|
|
OPAL_OUTPUT_VERBOSE((1, orte_debug_output, \
|
2012-04-06 14:23:13 +00:00
|
|
|
"defining timer event: %ld sec %ld usec at %s:%d", \
|
|
|
|
(long)tm->tv.tv_sec, (long)tm->tv.tv_usec, \
|
|
|
|
__FILE__, __LINE__)); \
|
|
|
|
opal_event_evtimer_add(tm->ev, &tm->tv); \
|
2008-12-10 20:40:47 +00:00
|
|
|
}while(0); \
|
2008-03-05 13:51:32 +00:00
|
|
|
|
|
|
|
|
2004-09-26 17:43:35 +00:00
|
|
|
/**
|
|
|
|
* \internal
|
|
|
|
*
|
|
|
|
* Initialize the wait system (allocate mutexes, etc.)
|
|
|
|
*/
|
2006-08-23 03:32:36 +00:00
|
|
|
ORTE_DECLSPEC int orte_wait_init(void);
|
2004-09-26 17:43:35 +00:00
|
|
|
|
2005-03-14 20:57:21 +00:00
|
|
|
/**
|
|
|
|
* Kill all processes we are waiting on.
|
|
|
|
*/
|
2006-08-23 03:32:36 +00:00
|
|
|
ORTE_DECLSPEC int orte_wait_kill(int sig);
|
2004-09-26 17:43:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \internal
|
|
|
|
*
|
|
|
|
* Finalize the wait system (deallocate mutexes, etc.)
|
|
|
|
*/
|
2006-08-23 03:32:36 +00:00
|
|
|
ORTE_DECLSPEC int orte_wait_finalize(void);
|
|
|
|
|
2008-02-28 01:57:57 +00:00
|
|
|
END_C_DECLS
|
2004-09-26 17:43:35 +00:00
|
|
|
|
2005-03-14 20:57:21 +00:00
|
|
|
#endif /* #ifndef ORTE_WAIT_H */
|