2004-09-26 21:43:35 +04:00
|
|
|
/*
|
2005-11-05 22:57:48 +03:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
2008-07-25 19:23:23 +04:00
|
|
|
* Copyright (c) 2004-2008 The University of Tennessee and The University
|
2005-11-05 22:57:48 +03:00
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2015-06-24 06:59:57 +03:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
2004-11-28 23:09:25 +03:00
|
|
|
* University of Stuttgart. All rights reserved.
|
2005-03-24 15:43:37 +03:00
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2013-02-28 21:31:47 +04:00
|
|
|
* Copyright (c) 2007-2013 Los Alamos National Security, LLC. All rights
|
2015-06-24 06:59:57 +03:00
|
|
|
* reserved.
|
2008-07-25 19:23:23 +04:00
|
|
|
* Copyright (c) 2008 Institut National de Recherche en Informatique
|
|
|
|
* et Automatique. All rights reserved.
|
2017-06-06 01:22:28 +03:00
|
|
|
* Copyright (c) 2014-2017 Intel, Inc. All rights reserved.
|
2004-11-22 04:38:40 +03:00
|
|
|
* $COPYRIGHT$
|
2015-06-24 06:59:57 +03:00
|
|
|
*
|
2004-11-22 04:38:40 +03:00
|
|
|
* Additional copyrights may follow
|
2015-06-24 06:59:57 +03:00
|
|
|
*
|
2004-09-26 21:43:35 +04:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2006-02-12 04:33:29 +03:00
|
|
|
#include "orte_config.h"
|
2008-02-28 04:57:57 +03:00
|
|
|
|
2009-03-13 05:10:32 +03:00
|
|
|
#include <string.h>
|
2004-09-26 21:43:35 +04:00
|
|
|
#include <assert.h>
|
2008-02-28 04:57:57 +03:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_QUEUE_H
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#endif
|
2004-09-26 21:43:35 +04:00
|
|
|
#include <errno.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#ifdef HAVE_SYS_TIME_H
|
2004-09-26 21:43:35 +04:00
|
|
|
#include <sys/time.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
2004-09-26 21:43:35 +04:00
|
|
|
#include <sys/types.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
2008-02-28 04:57:57 +03:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdlib.h>
|
2004-09-29 22:40:46 +04:00
|
|
|
#include <signal.h>
|
2008-02-28 04:57:57 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/stat.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#ifdef HAVE_SYS_WAIT_H
|
2004-09-26 21:43:35 +04:00
|
|
|
#include <sys/wait.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
2004-09-26 21:43:35 +04:00
|
|
|
|
2008-02-28 22:58:32 +03:00
|
|
|
#include "opal/dss/dss_types.h"
|
2005-07-03 20:06:07 +04:00
|
|
|
#include "opal/class/opal_object.h"
|
2009-02-14 05:26:12 +03:00
|
|
|
#include "opal/util/output.h"
|
2005-07-03 20:22:16 +04:00
|
|
|
#include "opal/class/opal_list.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 22:35:54 +04:00
|
|
|
#include "opal/mca/event/event.h"
|
2005-07-04 02:45:48 +04:00
|
|
|
#include "opal/threads/mutex.h"
|
|
|
|
#include "opal/threads/condition.h"
|
2008-08-05 19:09:29 +04:00
|
|
|
#include "opal/sys/atomic.h"
|
2008-02-28 04:57:57 +03:00
|
|
|
|
2009-03-13 05:10:32 +03:00
|
|
|
#include "orte/constants.h"
|
2008-02-28 04:57:57 +03:00
|
|
|
#include "orte/mca/errmgr/errmgr.h"
|
|
|
|
#include "orte/util/name_fns.h"
|
2017-06-06 01:22:28 +03:00
|
|
|
#include "orte/util/threads.h"
|
2008-02-28 04:57:57 +03:00
|
|
|
#include "orte/runtime/orte_globals.h"
|
|
|
|
|
2005-08-15 22:25:35 +04:00
|
|
|
#include "orte/runtime/orte_wait.h"
|
2004-09-26 21:43:35 +04:00
|
|
|
|
2014-06-17 21:57:51 +04:00
|
|
|
/* Timer Object Declaration */
|
2012-04-06 18:23:13 +04:00
|
|
|
static void timer_const(orte_timer_t *tm)
|
2008-02-28 22:58:32 +03:00
|
|
|
{
|
2012-04-06 18:23:13 +04:00
|
|
|
tm->ev = opal_event_alloc();
|
|
|
|
tm->payload = NULL;
|
2008-02-28 22:58:32 +03:00
|
|
|
}
|
2012-04-06 18:23:13 +04:00
|
|
|
static void timer_dest(orte_timer_t *tm)
|
2008-02-28 22:58:32 +03:00
|
|
|
{
|
2012-04-06 18:23:13 +04:00
|
|
|
opal_event_free(tm->ev);
|
2008-08-06 13:42:48 +04:00
|
|
|
}
|
2012-04-06 18:23:13 +04:00
|
|
|
OBJ_CLASS_INSTANCE(orte_timer_t,
|
2008-02-28 22:58:32 +03:00
|
|
|
opal_object_t,
|
2012-04-06 18:23:13 +04:00
|
|
|
timer_const,
|
|
|
|
timer_dest);
|
2008-12-10 23:40:47 +03:00
|
|
|
|
2017-11-25 00:29:02 +03:00
|
|
|
|
2014-06-17 21:57:51 +04:00
|
|
|
static void wccon(orte_wait_tracker_t *p)
|
2004-09-26 21:43:35 +04:00
|
|
|
{
|
2014-06-17 21:57:51 +04:00
|
|
|
p->child = NULL;
|
|
|
|
p->cbfunc = NULL;
|
|
|
|
p->cbdata = NULL;
|
2004-09-26 21:43:35 +04:00
|
|
|
}
|
2014-06-17 21:57:51 +04:00
|
|
|
static void wcdes(orte_wait_tracker_t *p)
|
2004-09-26 21:43:35 +04:00
|
|
|
{
|
2014-06-17 21:57:51 +04:00
|
|
|
if (NULL != p->child) {
|
|
|
|
OBJ_RELEASE(p->child);
|
|
|
|
}
|
2004-09-26 21:43:35 +04:00
|
|
|
}
|
2017-11-25 00:29:02 +03:00
|
|
|
OBJ_CLASS_INSTANCE(orte_wait_tracker_t,
|
|
|
|
opal_list_item_t,
|
|
|
|
wccon, wcdes);
|
2004-09-26 21:43:35 +04:00
|
|
|
|
2014-06-17 21:57:51 +04:00
|
|
|
/* Local Variables */
|
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 22:35:54 +04:00
|
|
|
static opal_event_t handler;
|
2014-06-17 21:57:51 +04:00
|
|
|
static opal_list_t pending_cbs;
|
|
|
|
|
|
|
|
/* Local Function Prototypes */
|
|
|
|
static void wait_signal_callback(int fd, short event, void *arg);
|
2004-09-26 21:43:35 +04:00
|
|
|
|
2014-06-17 21:57:51 +04:00
|
|
|
/* Interface Functions */
|
2004-09-26 21:43:35 +04:00
|
|
|
|
2014-06-17 21:57:51 +04:00
|
|
|
void orte_wait_disable(void)
|
2008-07-25 19:23:23 +04:00
|
|
|
{
|
2010-10-28 19:22:46 +04:00
|
|
|
opal_event_del(&handler);
|
2008-07-25 19:23:23 +04:00
|
|
|
}
|
|
|
|
|
2014-06-17 21:57:51 +04:00
|
|
|
void orte_wait_enable(void)
|
2008-07-25 19:23:23 +04:00
|
|
|
{
|
2010-10-28 19:22:46 +04:00
|
|
|
opal_event_add(&handler, NULL);
|
2008-07-25 19:23:23 +04:00
|
|
|
}
|
|
|
|
|
2014-06-17 21:57:51 +04:00
|
|
|
int orte_wait_init(void)
|
2004-09-26 21:43:35 +04:00
|
|
|
{
|
2014-06-17 21:57:51 +04:00
|
|
|
OBJ_CONSTRUCT(&pending_cbs, opal_list_t);
|
2004-09-26 21:43:35 +04:00
|
|
|
|
2012-04-06 18:23:13 +04:00
|
|
|
opal_event_set(orte_event_base,
|
2010-10-26 06:41:42 +04:00
|
|
|
&handler, SIGCHLD, OPAL_EV_SIGNAL|OPAL_EV_PERSIST,
|
2014-06-17 21:57:51 +04:00
|
|
|
wait_signal_callback,
|
2005-03-14 23:57:21 +03:00
|
|
|
&handler);
|
2012-04-06 18:23:13 +04:00
|
|
|
opal_event_set_priority(&handler, ORTE_SYS_PRI);
|
2005-03-14 23:57:21 +03:00
|
|
|
|
2010-10-28 19:22:46 +04:00
|
|
|
opal_event_add(&handler, NULL);
|
2005-08-15 22:25:35 +04:00
|
|
|
return ORTE_SUCCESS;
|
2004-09-26 21:43:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-17 21:57:51 +04:00
|
|
|
int orte_wait_finalize(void)
|
2004-09-26 21:43:35 +04:00
|
|
|
{
|
2010-10-28 19:22:46 +04:00
|
|
|
opal_event_del(&handler);
|
2004-09-26 21:43:35 +04:00
|
|
|
|
2014-06-17 21:57:51 +04:00
|
|
|
/* clear out the pending cbs */
|
|
|
|
OPAL_LIST_DESTRUCT(&pending_cbs);
|
2004-09-26 21:43:35 +04:00
|
|
|
|
2005-08-15 22:25:35 +04:00
|
|
|
return ORTE_SUCCESS;
|
2004-09-26 21:43:35 +04:00
|
|
|
}
|
|
|
|
|
2015-10-24 07:02:31 +03:00
|
|
|
/* this function *must* always be called from
|
|
|
|
* within an event in the orte_event_base */
|
2017-11-25 00:29:02 +03:00
|
|
|
void orte_wait_cb(orte_proc_t *child, orte_wait_cbfunc_t callback,
|
|
|
|
opal_event_base_t *evb, void *data)
|
2005-03-14 23:57:21 +03:00
|
|
|
{
|
2014-06-17 21:57:51 +04:00
|
|
|
orte_wait_tracker_t *t2;
|
|
|
|
|
2015-10-24 07:02:31 +03:00
|
|
|
if (NULL == child || NULL == callback) {
|
|
|
|
/* bozo protection */
|
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_BAD_PARAM);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-17 21:57:51 +04:00
|
|
|
/* see if this proc is still alive */
|
2015-10-24 07:02:31 +03:00
|
|
|
if (!ORTE_FLAG_TEST(child, ORTE_PROC_FLAG_ALIVE)) {
|
2017-11-25 00:29:02 +03:00
|
|
|
if (NULL != callback) {
|
|
|
|
/* already heard this proc is dead, so just do the callback */
|
|
|
|
t2 = OBJ_NEW(orte_wait_tracker_t);
|
|
|
|
OBJ_RETAIN(child); // protect against race conditions
|
|
|
|
t2->child = child;
|
|
|
|
t2->evb = evb;
|
|
|
|
t2->cbfunc = callback;
|
|
|
|
t2->cbdata = data;
|
|
|
|
opal_event_set(t2->evb, &t2->ev, -1,
|
|
|
|
OPAL_EV_WRITE, t2->cbfunc, t2);
|
|
|
|
opal_event_set_priority(&t2->ev, ORTE_MSG_PRI);
|
|
|
|
opal_event_active(&t2->ev, OPAL_EV_WRITE, 1);
|
|
|
|
}
|
2015-10-24 07:02:31 +03:00
|
|
|
return;
|
2004-09-26 21:43:35 +04:00
|
|
|
}
|
|
|
|
|
2014-06-17 22:46:40 +04:00
|
|
|
/* we just override any existing registration */
|
2014-06-17 21:57:51 +04:00
|
|
|
OPAL_LIST_FOREACH(t2, &pending_cbs, orte_wait_tracker_t) {
|
2015-10-24 07:02:31 +03:00
|
|
|
if (t2->child == child) {
|
|
|
|
t2->cbfunc = callback;
|
|
|
|
t2->cbdata = data;
|
2014-06-17 21:57:51 +04:00
|
|
|
return;
|
2004-10-27 02:11:03 +04:00
|
|
|
}
|
2004-09-26 21:43:35 +04:00
|
|
|
}
|
2014-06-17 21:57:51 +04:00
|
|
|
/* get here if this is a new registration */
|
2015-10-24 07:02:31 +03:00
|
|
|
t2 = OBJ_NEW(orte_wait_tracker_t);
|
2014-06-17 21:57:51 +04:00
|
|
|
OBJ_RETAIN(child); // protect against race conditions
|
2015-10-24 07:02:31 +03:00
|
|
|
t2->child = child;
|
2017-11-25 00:29:02 +03:00
|
|
|
t2->evb = evb;
|
2015-10-24 07:02:31 +03:00
|
|
|
t2->cbfunc = callback;
|
|
|
|
t2->cbdata = data;
|
|
|
|
opal_list_append(&pending_cbs, &t2->super);
|
2004-10-27 02:11:03 +04:00
|
|
|
}
|
|
|
|
|
2014-06-17 21:57:51 +04:00
|
|
|
static void cancel_callback(int fd, short args, void *cbdata)
|
2004-09-26 21:43:35 +04:00
|
|
|
{
|
2014-06-17 21:57:51 +04:00
|
|
|
orte_wait_tracker_t *trk = (orte_wait_tracker_t*)cbdata;
|
|
|
|
orte_wait_tracker_t *t2;
|
|
|
|
|
2017-06-06 01:22:28 +03:00
|
|
|
ORTE_ACQUIRE_OBJECT(trk);
|
|
|
|
|
2014-06-17 21:57:51 +04:00
|
|
|
OPAL_LIST_FOREACH(t2, &pending_cbs, orte_wait_tracker_t) {
|
|
|
|
if (t2->child == trk->child) {
|
|
|
|
opal_list_remove_item(&pending_cbs, &t2->super);
|
|
|
|
OBJ_RELEASE(t2);
|
|
|
|
OBJ_RELEASE(trk);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2004-09-26 21:43:35 +04:00
|
|
|
|
2014-06-17 21:57:51 +04:00
|
|
|
OBJ_RELEASE(trk);
|
2004-09-26 21:43:35 +04:00
|
|
|
}
|
|
|
|
|
2014-06-17 21:57:51 +04:00
|
|
|
void orte_wait_cb_cancel(orte_proc_t *child)
|
2004-09-26 21:43:35 +04:00
|
|
|
{
|
2014-06-17 21:57:51 +04:00
|
|
|
orte_wait_tracker_t *trk;
|
2004-09-26 21:43:35 +04:00
|
|
|
|
2014-06-17 21:57:51 +04:00
|
|
|
if (NULL == child) {
|
|
|
|
/* bozo protection */
|
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_BAD_PARAM);
|
|
|
|
return;
|
2004-09-26 21:43:35 +04:00
|
|
|
}
|
|
|
|
|
2014-06-17 21:57:51 +04:00
|
|
|
/* push this into the event library for handling */
|
|
|
|
trk = OBJ_NEW(orte_wait_tracker_t);
|
|
|
|
OBJ_RETAIN(child); // protect against race conditions
|
|
|
|
trk->child = child;
|
2017-06-06 01:22:28 +03:00
|
|
|
ORTE_THREADSHIFT(trk, orte_event_base, cancel_callback, ORTE_SYS_PRI);
|
2004-09-26 21:43:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-17 21:57:51 +04:00
|
|
|
/* callback from the event library whenever a SIGCHLD is received */
|
|
|
|
static void wait_signal_callback(int fd, short event, void *arg)
|
2004-09-26 21:43:35 +04:00
|
|
|
{
|
2014-06-17 21:57:51 +04:00
|
|
|
opal_event_t *signal = (opal_event_t*) arg;
|
|
|
|
int status;
|
|
|
|
pid_t pid;
|
|
|
|
orte_wait_tracker_t *t2;
|
2004-09-26 21:43:35 +04:00
|
|
|
|
2017-06-06 01:22:28 +03:00
|
|
|
ORTE_ACQUIRE_OBJECT(signal);
|
|
|
|
|
2014-06-17 21:57:51 +04:00
|
|
|
if (SIGCHLD != OPAL_EVENT_SIGNAL(signal)) {
|
|
|
|
return;
|
2004-09-26 21:43:35 +04:00
|
|
|
}
|
|
|
|
|
2014-06-17 22:46:40 +04:00
|
|
|
/* we can have multiple children leave but only get one
|
|
|
|
* sigchild callback, so reap all the waitpids until we
|
|
|
|
* don't get anything valid back */
|
|
|
|
while (1) {
|
|
|
|
pid = waitpid(-1, &status, WNOHANG);
|
|
|
|
if (-1 == pid && EINTR == errno) {
|
|
|
|
/* try it again */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* if we got garbage, then nothing we can do */
|
|
|
|
if (pid <= 0) {
|
2014-06-17 21:57:51 +04:00
|
|
|
return;
|
|
|
|
}
|
2015-06-24 06:59:57 +03:00
|
|
|
|
2014-06-17 22:46:40 +04:00
|
|
|
/* we are already in an event, so it is safe to access the list */
|
|
|
|
OPAL_LIST_FOREACH(t2, &pending_cbs, orte_wait_tracker_t) {
|
|
|
|
if (pid == t2->child->pid) {
|
|
|
|
/* found it! */
|
|
|
|
t2->child->exit_code = status;
|
2017-11-25 00:29:02 +03:00
|
|
|
opal_list_remove_item(&pending_cbs, &t2->super);
|
2014-06-17 22:46:40 +04:00
|
|
|
if (NULL != t2->cbfunc) {
|
2017-11-25 00:29:02 +03:00
|
|
|
opal_event_set(t2->evb, &t2->ev, -1,
|
|
|
|
OPAL_EV_WRITE, t2->cbfunc, t2);
|
|
|
|
opal_event_set_priority(&t2->ev, ORTE_MSG_PRI);
|
|
|
|
opal_event_active(&t2->ev, OPAL_EV_WRITE, 1);
|
|
|
|
} else {
|
|
|
|
OBJ_RELEASE(t2);
|
2014-06-17 22:46:40 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-09-26 21:43:35 +04:00
|
|
|
}
|
2007-01-18 02:16:52 +03:00
|
|
|
}
|