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.
|
2006-08-23 07:32:36 +04:00
|
|
|
* Copyright (c) 2004-2006 The University of Tennessee and The University
|
2005-11-05 22:57:48 +03:00
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2004-11-28 23:09:25 +03:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* 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.
|
2007-06-12 20:25:26 +04:00
|
|
|
* Copyright (c) 2007 Los Alamos National Security, LLC. All rights
|
|
|
|
* reserved.
|
2004-11-22 04:38:40 +03:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
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
|
|
|
#include "orte/constants.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"
|
This commit represents a bunch of work on a Mercurial side branch. As
such, the commit message back to the master SVN repository is fairly
long.
= ORTE Job-Level Output Messages =
Add two new interfaces that should be used for all new code throughout
the ORTE and OMPI layers (we already make the search-and-replace on
the existing ORTE / OMPI layers):
* orte_output(): (and corresponding friends ORTE_OUTPUT,
orte_output_verbose, etc.) This function sends the output directly
to the HNP for processing as part of a job-specific output
channel. It supports all the same outputs as opal_output()
(syslog, file, stdout, stderr), but for stdout/stderr, the output
is sent to the HNP for processing and output. More on this below.
* orte_show_help(): This function is a drop-in-replacement for
opal_show_help(), with two differences in functionality:
1. the rendered text help message output is sent to the HNP for
display (rather than outputting directly into the process' stderr
stream)
1. the HNP detects duplicate help messages and does not display them
(so that you don't see the same error message N times, once from
each of your N MPI processes); instead, it counts "new" instances
of the help message and displays a message every ~5 seconds when
there are new ones ("I got X new copies of the help message...")
opal_show_help and opal_output still exist, but they only output in
the current process. The intent for the new orte_* functions is that
they can apply job-level intelligence to the output. As such, we
recommend that all new ORTE and OMPI code use the new orte_*
functions, not thei opal_* functions.
=== New code ===
For ORTE and OMPI programmers, here's what you need to do differently
in new code:
* Do not include opal/util/show_help.h or opal/util/output.h.
Instead, include orte/util/output.h (this one header file has
declarations for both the orte_output() series of functions and
orte_show_help()).
* Effectively s/opal_output/orte_output/gi throughout your code.
Note that orte_output_open() takes a slightly different argument
list (as a way to pass data to the filtering stream -- see below),
so you if explicitly call opal_output_open(), you'll need to
slightly adapt to the new signature of orte_output_open().
* Literally s/opal_show_help/orte_show_help/. The function signature
is identical.
=== Notes ===
* orte_output'ing to stream 0 will do similar to what
opal_output'ing did, so leaving a hard-coded "0" as the first
argument is safe.
* For systems that do not use ORTE's RML or the HNP, the effect of
orte_output_* and orte_show_help will be identical to their opal
counterparts (the additional information passed to
orte_output_open() will be lost!). Indeed, the orte_* functions
simply become trivial wrappers to their opal_* counterparts. Note
that we have not tested this; the code is simple but it is quite
possible that we mucked something up.
= Filter Framework =
Messages sent view the new orte_* functions described above and
messages output via the IOF on the HNP will now optionally be passed
through a new "filter" framework before being output to
stdout/stderr. The "filter" OPAL MCA framework is intended to allow
preprocessing to messages before they are sent to their final
destinations. The first component that was written in the filter
framework was to create an XML stream, segregating all the messages
into different XML tags, etc. This will allow 3rd party tools to read
the stdout/stderr from the HNP and be able to know exactly what each
text message is (e.g., a help message, another OMPI infrastructure
message, stdout from the user process, stderr from the user process,
etc.).
Filtering is not active by default. Filter components must be
specifically requested, such as:
{{{
$ mpirun --mca filter xml ...
}}}
There can only be one filter component active.
= New MCA Parameters =
The new functionality described above introduces two new MCA
parameters:
* '''orte_base_help_aggregate''': Defaults to 1 (true), meaning that
help messages will be aggregated, as described above. If set to 0,
all help messages will be displayed, even if they are duplicates
(i.e., the original behavior).
* '''orte_base_show_output_recursions''': An MCA parameter to help
debug one of the known issues, described below. It is likely that
this MCA parameter will disappear before v1.3 final.
= Known Issues =
* The XML filter component is not complete. The current output from
this component is preliminary and not real XML. A bit more work
needs to be done to configure.m4 search for an appropriate XML
library/link it in/use it at run time.
* There are possible recursion loops in the orte_output() and
orte_show_help() functions -- e.g., if RML send calls orte_output()
or orte_show_help(). We have some ideas how to fix these, but
figured that it was ok to commit before feature freeze with known
issues. The code currently contains sub-optimal workarounds so
that this will not be a problem, but it would be good to actually
solve the problem rather than have hackish workarounds before v1.3 final.
This commit was SVN r18434.
2008-05-14 00:00:55 +04:00
|
|
|
#include "orte/util/output.h"
|
2005-07-03 20:06:07 +04:00
|
|
|
#include "opal/class/opal_object.h"
|
2005-07-03 20:22:16 +04:00
|
|
|
#include "opal/class/opal_list.h"
|
2005-07-04 03:09:55 +04:00
|
|
|
#include "opal/event/event.h"
|
2005-07-04 02:45:48 +04:00
|
|
|
#include "opal/threads/mutex.h"
|
|
|
|
#include "opal/threads/condition.h"
|
2008-02-28 04:57:57 +03:00
|
|
|
|
|
|
|
#include "orte/mca/errmgr/errmgr.h"
|
|
|
|
#include "orte/util/name_fns.h"
|
|
|
|
#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
|
|
|
|
2008-02-28 04:57:57 +03:00
|
|
|
|
|
|
|
#ifdef HAVE_WAITPID
|
|
|
|
|
2006-08-23 07:32:36 +04:00
|
|
|
static volatile int cb_enabled = true;
|
|
|
|
static opal_mutex_t mutex;
|
|
|
|
static opal_list_t pending_pids;
|
|
|
|
static opal_list_t registered_cb;
|
|
|
|
|
2008-02-28 22:58:32 +03:00
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Wait Object Declarations
|
|
|
|
*
|
|
|
|
********************************************************************/
|
|
|
|
static void message_event_destructor(orte_message_event_t *ev)
|
|
|
|
{
|
|
|
|
OBJ_RELEASE(ev->buffer);
|
2008-02-29 23:10:31 +03:00
|
|
|
#if OMPI_ENABLE_DEBUG
|
|
|
|
ev->file = NULL;
|
|
|
|
#endif
|
2008-02-28 22:58:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void message_event_constructor(orte_message_event_t *ev)
|
|
|
|
{
|
|
|
|
ev->buffer = OBJ_NEW(opal_buffer_t);
|
|
|
|
}
|
|
|
|
OBJ_CLASS_INSTANCE(orte_message_event_t,
|
|
|
|
opal_object_t,
|
|
|
|
message_event_constructor,
|
|
|
|
message_event_destructor);
|
|
|
|
|
|
|
|
|
2004-09-26 21:43:35 +04:00
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Local Class Declarations
|
|
|
|
*
|
|
|
|
********************************************************************/
|
|
|
|
struct blk_waitpid_data_t {
|
2005-07-03 20:06:07 +04:00
|
|
|
opal_object_t super;
|
2005-07-04 02:45:48 +04:00
|
|
|
opal_condition_t *cond;
|
2004-09-26 21:43:35 +04:00
|
|
|
volatile int done;
|
|
|
|
volatile int status;
|
2004-10-27 02:11:03 +04:00
|
|
|
volatile int free;
|
2004-09-26 21:43:35 +04:00
|
|
|
};
|
|
|
|
typedef struct blk_waitpid_data_t blk_waitpid_data_t;
|
|
|
|
|
|
|
|
struct pending_pids_item_t {
|
2005-07-03 20:22:16 +04:00
|
|
|
opal_list_item_t super;
|
2004-09-26 21:43:35 +04:00
|
|
|
pid_t pid;
|
|
|
|
int status;
|
|
|
|
};
|
|
|
|
typedef struct pending_pids_item_t pending_pids_item_t;
|
|
|
|
|
|
|
|
struct registered_cb_item_t {
|
2005-07-03 20:22:16 +04:00
|
|
|
opal_list_item_t super;
|
2004-09-26 21:43:35 +04:00
|
|
|
pid_t pid;
|
2005-03-14 23:57:21 +03:00
|
|
|
orte_wait_fn_t callback;
|
2004-09-26 21:43:35 +04:00
|
|
|
void *data;
|
|
|
|
};
|
|
|
|
typedef struct registered_cb_item_t registered_cb_item_t;
|
|
|
|
|
2004-12-14 18:47:31 +03:00
|
|
|
struct waitpid_callback_data_t {
|
|
|
|
pid_t pid;
|
|
|
|
int status;
|
|
|
|
int options;
|
|
|
|
pid_t ret;
|
2005-07-04 02:45:48 +04:00
|
|
|
opal_mutex_t mutex;
|
|
|
|
opal_condition_t cond;
|
2004-12-14 18:47:31 +03:00
|
|
|
volatile bool done;
|
|
|
|
};
|
|
|
|
typedef struct waitpid_callback_data_t waitpid_callback_data_t;
|
|
|
|
|
2004-09-26 21:43:35 +04:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Local Class Definitions
|
|
|
|
*
|
|
|
|
********************************************************************/
|
|
|
|
static void
|
2005-07-03 20:06:07 +04:00
|
|
|
blk_waitpid_data_construct(opal_object_t *obj)
|
2004-09-26 21:43:35 +04:00
|
|
|
{
|
|
|
|
blk_waitpid_data_t *data = (blk_waitpid_data_t*) obj;
|
|
|
|
|
2005-07-04 02:45:48 +04:00
|
|
|
data->cond = OBJ_NEW(opal_condition_t);
|
2004-09-26 21:43:35 +04:00
|
|
|
data->done = 0;
|
|
|
|
data->status = 0;
|
2004-10-27 02:11:03 +04:00
|
|
|
data->free = 0;
|
2004-09-26 21:43:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2005-07-03 20:06:07 +04:00
|
|
|
blk_waitpid_data_destruct(opal_object_t *obj)
|
2004-09-26 21:43:35 +04:00
|
|
|
{
|
|
|
|
blk_waitpid_data_t *data = (blk_waitpid_data_t*) obj;
|
|
|
|
|
|
|
|
if (NULL != data->cond) OBJ_RELEASE(data->cond);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-03 20:06:07 +04:00
|
|
|
static OBJ_CLASS_INSTANCE(blk_waitpid_data_t, opal_object_t,
|
2004-09-26 21:43:35 +04:00
|
|
|
blk_waitpid_data_construct,
|
|
|
|
blk_waitpid_data_destruct);
|
|
|
|
|
2005-07-03 20:22:16 +04:00
|
|
|
static OBJ_CLASS_INSTANCE(pending_pids_item_t, opal_list_item_t, NULL, NULL);
|
2004-09-26 21:43:35 +04:00
|
|
|
|
2005-07-03 20:22:16 +04:00
|
|
|
static OBJ_CLASS_INSTANCE(registered_cb_item_t, opal_list_item_t, NULL, NULL);
|
2004-09-26 21:43:35 +04:00
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Local Variables
|
|
|
|
*
|
|
|
|
********************************************************************/
|
2005-07-04 03:09:55 +04:00
|
|
|
static struct opal_event handler;
|
2004-09-26 21:43:35 +04:00
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Local Function Prototypes
|
|
|
|
*
|
|
|
|
********************************************************************/
|
|
|
|
static void blk_waitpid_cb(pid_t wpid, int status, void *data);
|
|
|
|
static pending_pids_item_t* find_pending_pid(pid_t pid, bool create);
|
|
|
|
static registered_cb_item_t* find_waiting_cb(pid_t pid, bool create);
|
|
|
|
static void do_waitall(int options);
|
2004-10-27 02:11:03 +04:00
|
|
|
static void trigger_callback(registered_cb_item_t *cb,
|
|
|
|
pending_pids_item_t *pending);
|
2005-03-14 23:57:21 +03:00
|
|
|
static int register_callback(pid_t pid, orte_wait_fn_t callback,
|
2004-09-26 21:43:35 +04:00
|
|
|
void *data);
|
2004-10-27 02:11:03 +04:00
|
|
|
static int unregister_callback(pid_t pid);
|
2005-03-14 23:57:21 +03:00
|
|
|
void orte_wait_signal_callback(int fd, short event, void *arg);
|
2004-12-14 18:47:31 +03:00
|
|
|
static pid_t internal_waitpid(pid_t pid, int *status, int options);
|
2005-03-14 23:57:21 +03:00
|
|
|
#if OMPI_THREADS_HAVE_DIFFERENT_PIDS
|
2004-12-14 18:47:31 +03:00
|
|
|
static void internal_waitpid_callback(int fd, short event, void *arg);
|
|
|
|
#endif
|
2004-09-26 21:43:35 +04:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Interface Functions
|
|
|
|
*
|
|
|
|
********************************************************************/
|
|
|
|
int
|
2005-03-14 23:57:21 +03:00
|
|
|
orte_wait_init(void)
|
2004-09-26 21:43:35 +04:00
|
|
|
{
|
2005-07-04 02:45:48 +04:00
|
|
|
OBJ_CONSTRUCT(&mutex, opal_mutex_t);
|
2005-07-03 20:22:16 +04:00
|
|
|
OBJ_CONSTRUCT(&pending_pids, opal_list_t);
|
|
|
|
OBJ_CONSTRUCT(®istered_cb, opal_list_t);
|
2004-09-26 21:43:35 +04:00
|
|
|
|
2005-07-04 03:09:55 +04:00
|
|
|
opal_event_set(&handler, SIGCHLD, OPAL_EV_SIGNAL|OPAL_EV_PERSIST,
|
2005-03-14 23:57:21 +03:00
|
|
|
orte_wait_signal_callback,
|
|
|
|
&handler);
|
|
|
|
|
2005-07-04 03:09:55 +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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2005-03-14 23:57:21 +03:00
|
|
|
orte_wait_finalize(void)
|
2004-09-26 21:43:35 +04:00
|
|
|
{
|
2005-07-03 20:22:16 +04:00
|
|
|
opal_list_item_t *item;
|
2004-09-26 21:43:35 +04:00
|
|
|
|
2005-07-04 02:45:48 +04:00
|
|
|
OPAL_THREAD_LOCK(&mutex);
|
2005-07-04 03:09:55 +04:00
|
|
|
opal_event_del(&handler);
|
2004-09-26 21:43:35 +04:00
|
|
|
|
|
|
|
/* clear out the lists */
|
2005-07-03 20:22:16 +04:00
|
|
|
while (NULL != (item = opal_list_remove_first(&pending_pids))) {
|
2004-09-26 21:43:35 +04:00
|
|
|
OBJ_RELEASE(item);
|
|
|
|
}
|
2005-07-03 20:22:16 +04:00
|
|
|
while (NULL != (item = opal_list_remove_first(®istered_cb))) {
|
2004-09-26 21:43:35 +04:00
|
|
|
OBJ_RELEASE(item);
|
|
|
|
}
|
2005-07-04 02:45:48 +04:00
|
|
|
OPAL_THREAD_UNLOCK(&mutex);
|
2004-09-26 21:43:35 +04:00
|
|
|
|
|
|
|
OBJ_DESTRUCT(&mutex);
|
|
|
|
OBJ_DESTRUCT(&pending_pids);
|
|
|
|
OBJ_DESTRUCT(®istered_cb);
|
|
|
|
|
2005-08-15 22:25:35 +04:00
|
|
|
return ORTE_SUCCESS;
|
2004-09-26 21:43:35 +04:00
|
|
|
}
|
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
int
|
|
|
|
orte_wait_kill(int sig)
|
|
|
|
{
|
2005-07-03 20:22:16 +04:00
|
|
|
opal_list_item_t* item;
|
2005-03-14 23:57:21 +03:00
|
|
|
|
2005-07-04 02:45:48 +04:00
|
|
|
OPAL_THREAD_LOCK(&mutex);
|
2005-03-14 23:57:21 +03:00
|
|
|
do_waitall(0);
|
2005-07-03 20:22:16 +04:00
|
|
|
while (NULL != (item = opal_list_remove_first(®istered_cb))) {
|
2005-03-14 23:57:21 +03:00
|
|
|
registered_cb_item_t *cb = (registered_cb_item_t*)item;
|
|
|
|
pending_pids_item_t *pending = find_pending_pid(cb->pid,false);
|
|
|
|
if(NULL == pending) {
|
|
|
|
int status;
|
|
|
|
kill(cb->pid, sig);
|
|
|
|
waitpid(cb->pid,&status,0);
|
|
|
|
} else {
|
|
|
|
OBJ_RELEASE(pending);
|
|
|
|
}
|
|
|
|
OBJ_RELEASE(item);
|
|
|
|
}
|
2005-07-04 02:45:48 +04:00
|
|
|
OPAL_THREAD_UNLOCK(&mutex);
|
2005-08-15 22:25:35 +04:00
|
|
|
return ORTE_SUCCESS;
|
2005-03-14 23:57:21 +03:00
|
|
|
}
|
|
|
|
|
2004-09-26 21:43:35 +04:00
|
|
|
|
|
|
|
pid_t
|
2005-03-14 23:57:21 +03:00
|
|
|
orte_waitpid(pid_t wpid, int *status, int options)
|
2004-09-26 21:43:35 +04:00
|
|
|
{
|
|
|
|
pending_pids_item_t *pending = NULL;
|
|
|
|
blk_waitpid_data_t *data = NULL;
|
|
|
|
struct timespec spintime;
|
|
|
|
pid_t ret;
|
|
|
|
|
|
|
|
if ((wpid <= 0) || (0 != (options & WUNTRACED))) {
|
2005-08-15 22:25:35 +04:00
|
|
|
errno = ORTE_ERR_NOT_IMPLEMENTED;
|
2004-09-26 21:43:35 +04:00
|
|
|
return (pid_t) -1;
|
|
|
|
}
|
|
|
|
|
2005-07-04 02:45:48 +04:00
|
|
|
OPAL_THREAD_LOCK(&mutex);
|
2004-09-26 21:43:35 +04:00
|
|
|
|
|
|
|
do_waitall(options);
|
|
|
|
pending = find_pending_pid(wpid, false);
|
|
|
|
if (NULL != pending) {
|
|
|
|
*status = pending->status;
|
|
|
|
ret = pending->pid;
|
2005-07-03 20:22:16 +04:00
|
|
|
opal_list_remove_item(&pending_pids, (opal_list_item_t*) pending);
|
2004-09-26 21:43:35 +04:00
|
|
|
OBJ_RELEASE(pending);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0 == (options & WNOHANG)) {
|
|
|
|
/* blocking - create a blk_waitpid_data_t, register the
|
|
|
|
callback with it, and wait for the trigger. Hold mutex
|
|
|
|
until after we register so that waitpid isn't called before
|
|
|
|
the callback is registered. There is a race condition
|
|
|
|
between starting to sit in the condition_wait and the
|
|
|
|
callback being triggered, so poll for completion on the
|
2005-03-28 19:57:11 +04:00
|
|
|
event just in case. */
|
2004-09-26 21:43:35 +04:00
|
|
|
data = OBJ_NEW(blk_waitpid_data_t);
|
|
|
|
if (NULL == data) {
|
|
|
|
ret = -1;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
register_callback(wpid, blk_waitpid_cb, data);
|
|
|
|
|
|
|
|
while (0 == data->done) {
|
|
|
|
spintime.tv_sec = 0;
|
|
|
|
spintime.tv_nsec = 1 * 1000 * 1000; /* 1 milliseconds */
|
2005-07-04 02:45:48 +04:00
|
|
|
opal_condition_timedwait(data->cond,
|
2005-03-14 23:57:21 +03:00
|
|
|
&mutex,
|
2004-09-26 21:43:35 +04:00
|
|
|
&spintime);
|
2005-03-28 19:57:11 +04:00
|
|
|
|
|
|
|
/* if we have pthreads and progress threads and we are the
|
2005-07-04 02:45:48 +04:00
|
|
|
event thread, opal_condition_timedwait won't progress
|
2005-03-28 19:57:11 +04:00
|
|
|
anything, so we need to do it. */
|
|
|
|
#if OMPI_HAVE_POSIX_THREADS && OMPI_ENABLE_PROGRESS_THREADS
|
2005-07-04 02:45:48 +04:00
|
|
|
if (opal_using_threads()) {
|
|
|
|
opal_mutex_unlock(&mutex);
|
2005-07-04 03:09:55 +04:00
|
|
|
opal_event_loop(OPAL_EVLOOP_NONBLOCK);
|
2005-07-04 02:45:48 +04:00
|
|
|
opal_mutex_lock(&mutex);
|
2004-10-14 03:08:47 +04:00
|
|
|
}
|
2005-03-28 19:57:11 +04:00
|
|
|
#endif
|
2004-10-27 02:11:03 +04:00
|
|
|
do_waitall(0);
|
2004-09-26 21:43:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = wpid;
|
|
|
|
*status = data->status;
|
|
|
|
|
2005-03-28 19:57:11 +04:00
|
|
|
/* Unlock the mutex first, so as to not cause any deadlocks.
|
|
|
|
We aren't going to touch any variables that could cause
|
|
|
|
problems with thread badness, so it's ok to be here without
|
|
|
|
the thread locked. Wich is also the reason we go to done
|
|
|
|
instead of cleanup. */
|
2005-07-04 02:45:48 +04:00
|
|
|
OPAL_THREAD_UNLOCK(&mutex);
|
2005-03-28 19:57:11 +04:00
|
|
|
|
2004-10-27 02:11:03 +04:00
|
|
|
while (0 == data->free) {
|
|
|
|
/* don't free the condition variable until we are positive
|
|
|
|
that the broadcast is done being sent. Otherwise,
|
|
|
|
pthreads gets really unhappy when we pull the rug out
|
|
|
|
from under it. Yes, it's spinning. No, we won't spin
|
2005-03-28 19:57:11 +04:00
|
|
|
for long. */
|
|
|
|
|
2005-07-04 03:09:55 +04:00
|
|
|
if (!OMPI_HAVE_THREAD_SUPPORT || opal_event_progress_thread()) {
|
|
|
|
opal_event_loop(OPAL_EVLOOP_NONBLOCK);
|
2004-10-27 02:11:03 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-26 21:43:35 +04:00
|
|
|
OBJ_RELEASE(data);
|
2005-03-28 19:57:11 +04:00
|
|
|
/* see note above while loop for why we jump to done */
|
2004-10-27 02:11:03 +04:00
|
|
|
goto done;
|
2004-09-26 21:43:35 +04:00
|
|
|
|
|
|
|
} else {
|
|
|
|
/* non-blocking - return what waitpid would */
|
2004-12-14 18:47:31 +03:00
|
|
|
ret = internal_waitpid(wpid, status, options);
|
2004-09-26 21:43:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
2005-07-04 02:45:48 +04:00
|
|
|
OPAL_THREAD_UNLOCK(&mutex);
|
2004-10-27 02:11:03 +04:00
|
|
|
|
|
|
|
done:
|
2004-09-26 21:43:35 +04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2005-03-14 23:57:21 +03:00
|
|
|
orte_wait_cb(pid_t wpid, orte_wait_fn_t callback, void *data)
|
2004-09-26 21:43:35 +04:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2005-08-15 22:25:35 +04:00
|
|
|
if (wpid <= 0) return ORTE_ERR_NOT_IMPLEMENTED;
|
|
|
|
if (NULL == callback) return ORTE_ERR_BAD_PARAM;
|
2004-09-26 21:43:35 +04:00
|
|
|
|
2005-07-04 02:45:48 +04:00
|
|
|
OPAL_THREAD_LOCK(&mutex);
|
2004-09-26 21:43:35 +04:00
|
|
|
ret = register_callback(wpid, callback, data);
|
2005-03-14 23:57:21 +03:00
|
|
|
do_waitall(0);
|
2005-07-04 02:45:48 +04:00
|
|
|
OPAL_THREAD_UNLOCK(&mutex);
|
2004-09-26 21:43:35 +04:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-27 02:11:03 +04:00
|
|
|
int
|
2005-03-14 23:57:21 +03:00
|
|
|
orte_wait_cb_cancel(pid_t wpid)
|
2004-10-27 02:11:03 +04:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2005-08-15 22:25:35 +04:00
|
|
|
if (wpid <= 0) return ORTE_ERR_BAD_PARAM;
|
2004-10-27 02:11:03 +04:00
|
|
|
|
2005-07-04 02:45:48 +04:00
|
|
|
OPAL_THREAD_LOCK(&mutex);
|
2004-10-27 02:11:03 +04:00
|
|
|
do_waitall(0);
|
|
|
|
ret = unregister_callback(wpid);
|
2005-07-04 02:45:48 +04:00
|
|
|
OPAL_THREAD_UNLOCK(&mutex);
|
2004-10-27 02:11:03 +04:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* callback from the event library whenever a SIGCHLD is received */
|
2004-09-26 21:43:35 +04:00
|
|
|
void
|
2005-03-14 23:57:21 +03:00
|
|
|
orte_wait_signal_callback(int fd, short event, void *arg)
|
2004-09-26 21:43:35 +04:00
|
|
|
{
|
2005-07-04 03:09:55 +04:00
|
|
|
struct opal_event *signal = (struct opal_event*) arg;
|
2004-09-26 21:43:35 +04:00
|
|
|
|
2005-07-04 03:09:55 +04:00
|
|
|
if (SIGCHLD != OPAL_EVENT_SIGNAL(signal)) return;
|
2004-09-26 21:43:35 +04:00
|
|
|
|
2005-07-04 02:45:48 +04:00
|
|
|
OPAL_THREAD_LOCK(&mutex);
|
2004-09-26 21:43:35 +04:00
|
|
|
do_waitall(0);
|
2005-07-04 02:45:48 +04:00
|
|
|
OPAL_THREAD_UNLOCK(&mutex);
|
2004-09-26 21:43:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-27 02:11:03 +04:00
|
|
|
int
|
2005-03-14 23:57:21 +03:00
|
|
|
orte_wait_cb_disable()
|
2004-10-27 02:11:03 +04:00
|
|
|
{
|
2005-07-04 02:45:48 +04:00
|
|
|
OPAL_THREAD_LOCK(&mutex);
|
2004-10-27 02:11:03 +04:00
|
|
|
do_waitall(0);
|
|
|
|
cb_enabled = false;
|
2005-07-04 02:45:48 +04:00
|
|
|
OPAL_THREAD_UNLOCK(&mutex);
|
2004-10-27 02:11:03 +04:00
|
|
|
|
2005-08-15 22:25:35 +04:00
|
|
|
return ORTE_SUCCESS;
|
2004-10-27 02:11:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2005-03-14 23:57:21 +03:00
|
|
|
orte_wait_cb_enable()
|
2004-10-27 02:11:03 +04:00
|
|
|
{
|
2005-07-04 02:45:48 +04:00
|
|
|
OPAL_THREAD_LOCK(&mutex);
|
2004-10-27 02:11:03 +04:00
|
|
|
cb_enabled = true;
|
|
|
|
do_waitall(0);
|
2005-07-04 02:45:48 +04:00
|
|
|
OPAL_THREAD_UNLOCK(&mutex);
|
2004-10-27 02:11:03 +04:00
|
|
|
|
2005-08-15 22:25:35 +04:00
|
|
|
return ORTE_SUCCESS;
|
2004-10-27 02:11:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-28 04:57:57 +03:00
|
|
|
int orte_wait_event(opal_event_t **event, int *trig,
|
|
|
|
void (*cbfunc)(int, short, void*))
|
|
|
|
{
|
|
|
|
int p[2];
|
|
|
|
|
|
|
|
if (pipe(p) < 0) {
|
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_SYS_LIMITS_PIPES);
|
|
|
|
return ORTE_ERR_SYS_LIMITS_PIPES;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create the event */
|
|
|
|
*event = (opal_event_t*)malloc(sizeof(opal_event_t));
|
|
|
|
|
|
|
|
/* pass back the write end of the pipe */
|
|
|
|
*trig = p[1];
|
|
|
|
|
|
|
|
/* define the event to fire when someone writes to the pipe */
|
|
|
|
opal_event_set(*event, p[0], OPAL_EV_READ, cbfunc, NULL);
|
|
|
|
|
|
|
|
/* Add it to the active events, without a timeout */
|
|
|
|
opal_event_add(*event, NULL);
|
|
|
|
|
|
|
|
/* all done */
|
|
|
|
return ORTE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void orte_trigger_event(int trig)
|
|
|
|
{
|
|
|
|
int data=1;
|
|
|
|
|
|
|
|
write(trig, &data, sizeof(int));
|
|
|
|
opal_progress();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-09-26 21:43:35 +04:00
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Local Functions
|
|
|
|
*
|
|
|
|
* None of these functions should lock mutex. All but blk_waitpid_cb
|
|
|
|
* should only be called if the mutex is already locked.
|
|
|
|
*
|
|
|
|
********************************************************************/
|
|
|
|
static void
|
|
|
|
blk_waitpid_cb(pid_t wpid, int status, void *data)
|
|
|
|
{
|
|
|
|
blk_waitpid_data_t *wp_data = (blk_waitpid_data_t*) data;
|
|
|
|
|
|
|
|
wp_data->status = status;
|
|
|
|
wp_data->done = 1;
|
2005-07-04 02:45:48 +04:00
|
|
|
opal_condition_signal(wp_data->cond);
|
2004-10-27 02:11:03 +04:00
|
|
|
wp_data->free = 1;
|
2004-09-26 21:43:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* -1 will return the first available pid */
|
|
|
|
static pending_pids_item_t *
|
|
|
|
find_pending_pid(pid_t pid, bool create)
|
|
|
|
{
|
2005-07-03 20:22:16 +04:00
|
|
|
opal_list_item_t *item;
|
2004-09-26 21:43:35 +04:00
|
|
|
pending_pids_item_t *pending;
|
|
|
|
|
2005-07-03 20:22:16 +04:00
|
|
|
for (item = opal_list_get_first(&pending_pids) ;
|
|
|
|
item != opal_list_get_end(&pending_pids) ;
|
|
|
|
item = opal_list_get_next(item)) {
|
2004-09-26 21:43:35 +04:00
|
|
|
pending = (pending_pids_item_t*) item;
|
|
|
|
|
|
|
|
if (pending->pid == pid || -1 == pid) {
|
|
|
|
return pending;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (create) {
|
|
|
|
pending = OBJ_NEW(pending_pids_item_t);
|
|
|
|
if (NULL == pending) return NULL;
|
|
|
|
|
|
|
|
pending->pid = pid;
|
|
|
|
pending->status = 0;
|
2005-07-03 20:22:16 +04:00
|
|
|
opal_list_append(&pending_pids, (opal_list_item_t*) pending);
|
2004-09-26 21:43:35 +04:00
|
|
|
return pending;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* pid must be positive */
|
|
|
|
static registered_cb_item_t *
|
|
|
|
find_waiting_cb(pid_t pid, bool create)
|
|
|
|
{
|
2005-07-03 20:22:16 +04:00
|
|
|
opal_list_item_t *item = NULL;
|
2004-09-26 21:43:35 +04:00
|
|
|
registered_cb_item_t *reg_cb = NULL;
|
|
|
|
|
2005-07-03 20:22:16 +04:00
|
|
|
for (item = opal_list_get_first(®istered_cb) ;
|
|
|
|
item != opal_list_get_end(®istered_cb) ;
|
|
|
|
item = opal_list_get_next(item)) {
|
2004-09-26 21:43:35 +04:00
|
|
|
reg_cb = (registered_cb_item_t*) item;
|
|
|
|
|
|
|
|
if (reg_cb->pid == pid) {
|
|
|
|
return reg_cb;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (create) {
|
|
|
|
reg_cb = OBJ_NEW(registered_cb_item_t);
|
|
|
|
if (NULL == reg_cb) return NULL;
|
|
|
|
|
|
|
|
reg_cb->pid = pid;
|
|
|
|
reg_cb->callback = NULL;
|
|
|
|
reg_cb->data = NULL;
|
2005-07-03 20:22:16 +04:00
|
|
|
opal_list_append(®istered_cb, (opal_list_item_t*) reg_cb);
|
2004-09-26 21:43:35 +04:00
|
|
|
return reg_cb;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
do_waitall(int options)
|
|
|
|
{
|
2004-10-27 02:11:03 +04:00
|
|
|
if (!cb_enabled) return;
|
2004-09-26 21:43:35 +04:00
|
|
|
while (1) {
|
2005-03-14 23:57:21 +03:00
|
|
|
int status;
|
|
|
|
pid_t ret = internal_waitpid(-1, &status, WNOHANG);
|
|
|
|
pending_pids_item_t *pending;
|
|
|
|
registered_cb_item_t *cb;
|
|
|
|
|
2004-09-26 21:43:35 +04:00
|
|
|
if (-1 == ret && EINTR == errno) continue;
|
|
|
|
if (ret <= 0) break;
|
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
cb = find_waiting_cb(ret, false);
|
|
|
|
if (NULL == cb) {
|
|
|
|
pending = OBJ_NEW(pending_pids_item_t);
|
|
|
|
pending->pid = ret;
|
|
|
|
pending->status = status;
|
2005-07-03 20:22:16 +04:00
|
|
|
opal_list_append(&pending_pids, &pending->super);
|
2005-03-14 23:57:21 +03:00
|
|
|
} else {
|
2005-07-03 20:22:16 +04:00
|
|
|
opal_list_remove_item(®istered_cb, &cb->super);
|
2005-07-04 02:45:48 +04:00
|
|
|
OPAL_THREAD_UNLOCK(&mutex);
|
2005-03-14 23:57:21 +03:00
|
|
|
cb->callback(cb->pid, status, cb->data);
|
2005-07-04 02:45:48 +04:00
|
|
|
OPAL_THREAD_LOCK(&mutex);
|
2005-03-14 23:57:21 +03:00
|
|
|
OBJ_RELEASE(cb);
|
|
|
|
}
|
2004-09-26 21:43:35 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
trigger_callback(registered_cb_item_t *cb, pending_pids_item_t *pending)
|
|
|
|
{
|
|
|
|
assert(cb->pid == pending->pid);
|
|
|
|
|
2007-06-12 20:25:26 +04:00
|
|
|
OPAL_THREAD_UNLOCK(&mutex);
|
2004-09-26 21:43:35 +04:00
|
|
|
cb->callback(cb->pid, pending->status, cb->data);
|
2007-06-12 20:25:26 +04:00
|
|
|
OPAL_THREAD_LOCK(&mutex);
|
|
|
|
|
2005-07-03 20:22:16 +04:00
|
|
|
opal_list_remove_item(&pending_pids, (opal_list_item_t*) pending);
|
|
|
|
opal_list_remove_item(®istered_cb, (opal_list_item_t*) cb);
|
2004-09-26 21:43:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2005-03-14 23:57:21 +03:00
|
|
|
register_callback(pid_t pid, orte_wait_fn_t callback, void *data)
|
2004-09-26 21:43:35 +04:00
|
|
|
{
|
|
|
|
registered_cb_item_t *reg_cb;
|
|
|
|
pending_pids_item_t *pending;
|
|
|
|
|
|
|
|
/* register the callback */
|
|
|
|
reg_cb = find_waiting_cb(pid, true);
|
2005-08-15 22:25:35 +04:00
|
|
|
if (NULL == reg_cb) return ORTE_ERROR;
|
|
|
|
if (NULL != reg_cb->callback) return ORTE_EXISTS;
|
2004-09-26 21:43:35 +04:00
|
|
|
|
|
|
|
reg_cb->callback = callback;
|
|
|
|
reg_cb->data = data;
|
|
|
|
|
|
|
|
/* make sure we shouldn't trigger right now */
|
|
|
|
pending = find_pending_pid(pid, false);
|
|
|
|
if (NULL != pending) {
|
|
|
|
trigger_callback(reg_cb, pending);
|
|
|
|
}
|
2005-08-15 22:25:35 +04:00
|
|
|
return ORTE_SUCCESS;
|
2004-09-26 21:43:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-27 02:11:03 +04:00
|
|
|
static int
|
|
|
|
unregister_callback(pid_t pid)
|
|
|
|
{
|
|
|
|
registered_cb_item_t *reg_cb;
|
|
|
|
|
|
|
|
/* register the callback */
|
|
|
|
reg_cb = find_waiting_cb(pid, false);
|
2005-08-15 22:25:35 +04:00
|
|
|
if (NULL == reg_cb) return ORTE_ERR_BAD_PARAM;
|
2004-10-27 02:11:03 +04:00
|
|
|
|
2005-07-03 20:22:16 +04:00
|
|
|
opal_list_remove_item(®istered_cb, (opal_list_item_t*) reg_cb);
|
2004-10-27 02:11:03 +04:00
|
|
|
|
2005-08-15 22:25:35 +04:00
|
|
|
return ORTE_SUCCESS;
|
2004-10-27 02:11:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-12-14 18:47:31 +03:00
|
|
|
|
|
|
|
static pid_t
|
|
|
|
internal_waitpid(pid_t pid, int *status, int options)
|
|
|
|
{
|
2005-03-14 23:57:21 +03:00
|
|
|
#if OMPI_THREADS_HAVE_DIFFERENT_PIDS
|
2004-12-14 18:47:31 +03:00
|
|
|
waitpid_callback_data_t data;
|
|
|
|
struct timeval tv;
|
2005-07-04 03:09:55 +04:00
|
|
|
struct opal_event ev;
|
2004-12-14 18:47:31 +03:00
|
|
|
|
2005-07-04 03:09:55 +04:00
|
|
|
if (opal_event_progress_thread()) {
|
2004-12-14 18:47:31 +03:00
|
|
|
/* I already am the progress thread. no need to event me */
|
|
|
|
return waitpid(pid, status, options);
|
|
|
|
}
|
|
|
|
|
|
|
|
data.done = false;
|
|
|
|
data.pid = pid;
|
|
|
|
data.options = options;
|
2005-07-04 02:45:48 +04:00
|
|
|
OBJ_CONSTRUCT(&(data.mutex), opal_mutex_t);
|
|
|
|
OBJ_CONSTRUCT(&(data.cond), opal_condition_t);
|
2004-12-14 18:47:31 +03:00
|
|
|
|
2005-07-04 02:45:48 +04:00
|
|
|
OPAL_THREAD_LOCK(&(data.mutex));
|
2004-12-14 18:47:31 +03:00
|
|
|
|
|
|
|
tv.tv_sec = 0;
|
|
|
|
tv.tv_usec = 0;
|
|
|
|
|
2005-07-04 03:09:55 +04:00
|
|
|
opal_evtimer_set(&ev, internal_waitpid_callback, &data);
|
|
|
|
opal_evtimer_add(&ev, &tv);
|
2004-12-14 18:47:31 +03:00
|
|
|
|
|
|
|
while (data.done == false) {
|
2005-07-04 02:45:48 +04:00
|
|
|
opal_condition_wait(&(data.cond), &(data.mutex));
|
2004-12-14 18:47:31 +03:00
|
|
|
}
|
|
|
|
|
2005-07-04 02:45:48 +04:00
|
|
|
OPAL_THREAD_UNLOCK(&(data.mutex));
|
2004-12-14 18:47:31 +03:00
|
|
|
|
|
|
|
OBJ_DESTRUCT(&(data.cond));
|
|
|
|
OBJ_DESTRUCT(&(data.mutex));
|
|
|
|
|
|
|
|
*status = data.status;
|
|
|
|
return data.ret;
|
|
|
|
|
2004-10-22 20:06:05 +04:00
|
|
|
#else
|
2004-12-14 18:47:31 +03:00
|
|
|
return waitpid(pid, status, options);
|
2004-10-22 20:06:05 +04:00
|
|
|
#endif
|
2004-09-26 21:43:35 +04:00
|
|
|
}
|
2004-12-14 18:47:31 +03:00
|
|
|
|
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
#if OMPI_THREADS_HAVE_DIFFERENT_PIDS
|
2004-12-14 18:47:31 +03:00
|
|
|
static void
|
|
|
|
internal_waitpid_callback(int fd, short event, void *arg)
|
|
|
|
{
|
|
|
|
waitpid_callback_data_t *data = (waitpid_callback_data_t*) arg;
|
|
|
|
|
|
|
|
data->ret = waitpid(data->pid, &(data->status), data->options);
|
|
|
|
|
|
|
|
data->done = true;
|
2005-07-04 02:45:48 +04:00
|
|
|
opal_condition_signal(&(data->cond));
|
2004-12-14 18:47:31 +03:00
|
|
|
}
|
|
|
|
#endif
|
2005-07-14 22:05:30 +04:00
|
|
|
|
2007-01-22 08:46:30 +03:00
|
|
|
#elif defined(__WINDOWS__)
|
2005-07-14 22:05:30 +04:00
|
|
|
|
2008-03-05 15:01:37 +03:00
|
|
|
static volatile int cb_enabled = true;
|
|
|
|
static opal_mutex_t mutex;
|
|
|
|
static opal_list_t pending_pids;
|
|
|
|
static opal_list_t registered_cb;
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Wait Object Declarations
|
|
|
|
*
|
|
|
|
********************************************************************/
|
|
|
|
static void message_event_destructor(orte_message_event_t *ev)
|
|
|
|
{
|
|
|
|
OBJ_RELEASE(ev->buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void message_event_constructor(orte_message_event_t *ev)
|
|
|
|
{
|
|
|
|
ev->buffer = OBJ_NEW(opal_buffer_t);
|
|
|
|
}
|
|
|
|
OBJ_CLASS_INSTANCE(orte_message_event_t,
|
|
|
|
opal_object_t,
|
|
|
|
message_event_constructor,
|
|
|
|
message_event_destructor);
|
|
|
|
|
2006-08-23 07:32:36 +04:00
|
|
|
typedef struct {
|
|
|
|
opal_list_item_t super;
|
|
|
|
pid_t pid;
|
|
|
|
HANDLE registered_handle;
|
|
|
|
orte_wait_fn_t callback;
|
|
|
|
void *data;
|
|
|
|
int status;
|
|
|
|
} opal_process_handle_t;
|
|
|
|
|
|
|
|
static void opal_process_handle_construct( opal_object_t* obj )
|
|
|
|
{
|
|
|
|
opal_process_handle_t* handle = (opal_process_handle_t*)obj;
|
|
|
|
|
|
|
|
handle->registered_handle = INVALID_HANDLE_VALUE;
|
|
|
|
handle->pid = 0;
|
|
|
|
handle->callback = NULL;
|
|
|
|
handle->data = NULL;
|
|
|
|
}
|
|
|
|
static void opal_process_handle_destruct( opal_object_t* obj )
|
|
|
|
{
|
|
|
|
opal_process_handle_t* handle = (opal_process_handle_t*)obj;
|
|
|
|
|
|
|
|
if( INVALID_HANDLE_VALUE != handle->registered_handle ) {
|
|
|
|
if( 0 == UnregisterWait( handle->registered_handle ) ) {
|
|
|
|
int error = GetLastError();
|
|
|
|
}
|
|
|
|
if( 0 == CloseHandle( handle->registered_handle ) ) {
|
|
|
|
int error = GetLastError();
|
|
|
|
}
|
|
|
|
handle->registered_handle = INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static OBJ_CLASS_INSTANCE( opal_process_handle_t, opal_list_item_t,
|
|
|
|
opal_process_handle_construct, opal_process_handle_destruct );
|
|
|
|
|
2005-07-14 22:05:30 +04:00
|
|
|
int
|
2006-08-23 07:32:36 +04:00
|
|
|
orte_wait_init(void)
|
|
|
|
{
|
|
|
|
OBJ_CONSTRUCT(&mutex, opal_mutex_t);
|
|
|
|
OBJ_CONSTRUCT(®istered_cb, opal_list_t);
|
|
|
|
OBJ_CONSTRUCT(&pending_pids, opal_list_t);
|
2005-09-13 01:45:58 +04:00
|
|
|
return ORTE_SUCCESS;
|
2005-07-14 22:05:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
orte_wait_finalize(void)
|
|
|
|
{
|
2006-08-23 07:32:36 +04:00
|
|
|
opal_list_item_t* item;
|
|
|
|
|
|
|
|
OPAL_THREAD_LOCK(&mutex);
|
|
|
|
OPAL_THREAD_UNLOCK(&mutex);
|
|
|
|
|
|
|
|
while (NULL != (item = opal_list_remove_first(&pending_pids))) {
|
|
|
|
OBJ_RELEASE(item);
|
|
|
|
}
|
|
|
|
while (NULL != (item = opal_list_remove_first(®istered_cb))) {
|
|
|
|
OBJ_RELEASE(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
OBJ_DESTRUCT(&mutex);
|
|
|
|
OBJ_DESTRUCT(®istered_cb);
|
|
|
|
OBJ_DESTRUCT(&pending_pids);
|
|
|
|
|
2005-09-13 01:45:58 +04:00
|
|
|
return ORTE_SUCCESS;
|
2005-07-14 22:05:30 +04:00
|
|
|
}
|
|
|
|
|
2008-03-05 15:01:37 +03:00
|
|
|
void orte_trigger_event(int trig)
|
|
|
|
{
|
|
|
|
int data=1;
|
|
|
|
|
|
|
|
write(trig, &data, sizeof(int));
|
|
|
|
opal_progress();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-23 07:32:36 +04:00
|
|
|
/**
|
|
|
|
* Internal function which find a corresponding process structure
|
|
|
|
* based on the pid. If create is true and the pid does not have a
|
|
|
|
* corresponding process structure, one will be automatically
|
|
|
|
* created and attached to the end of the list.
|
|
|
|
*/
|
|
|
|
static opal_process_handle_t* opal_find_pid_in_list(opal_list_t* list, pid_t pid, bool create)
|
|
|
|
{
|
|
|
|
opal_list_item_t *item = NULL;
|
|
|
|
opal_process_handle_t *handle = NULL;
|
|
|
|
|
|
|
|
for (item = opal_list_get_first(list) ;
|
|
|
|
item != opal_list_get_end(list) ;
|
|
|
|
item = opal_list_get_next(item)) {
|
|
|
|
handle = (opal_process_handle_t*) item;
|
|
|
|
|
|
|
|
if (handle->pid == pid) {
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (create) {
|
|
|
|
handle = OBJ_NEW(opal_process_handle_t);
|
|
|
|
if (NULL == handle) return NULL;
|
|
|
|
|
|
|
|
handle->pid = pid;
|
|
|
|
handle->callback = NULL;
|
|
|
|
handle->data = NULL;
|
|
|
|
opal_list_append(list, (opal_list_item_t*)handle);
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#define find_pending_pid(PID, CREATE) opal_find_pid_in_list( &pending_pids, (PID), (CREATE) )
|
|
|
|
#define find_pending_cb(PID, CREATE) opal_find_pid_in_list( ®istered_cb, (PID), (CREATE) )
|
|
|
|
|
2005-07-14 22:05:30 +04:00
|
|
|
pid_t
|
|
|
|
orte_waitpid(pid_t wpid, int *status, int options)
|
|
|
|
{
|
2006-08-23 07:32:36 +04:00
|
|
|
opal_process_handle_t* pending;
|
|
|
|
|
|
|
|
OPAL_THREAD_LOCK(&mutex);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is the child already gone ?
|
|
|
|
*/
|
|
|
|
pending = find_pending_pid( wpid, false );
|
|
|
|
if( NULL != pending ) {
|
|
|
|
*status = pending->status;
|
|
|
|
opal_list_remove_item( &pending_pids, (opal_list_item_t*)pending );
|
|
|
|
OBJ_RELEASE(pending);
|
|
|
|
OPAL_THREAD_UNLOCK(&mutex);
|
|
|
|
return wpid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Do we have any registered callback for this particular pid ?
|
|
|
|
*/
|
|
|
|
pending = find_pending_cb( wpid, false );
|
|
|
|
if( NULL != pending ) {
|
|
|
|
opal_list_remove_item( ®istered_cb, (opal_list_item_t*)pending );
|
|
|
|
OBJ_RELEASE( pending );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* No luck so far. Wait until the process complete ...
|
|
|
|
*/
|
|
|
|
if( WAIT_OBJECT_0 == WaitForSingleObject( (HANDLE)wpid, INFINITE ) ) {
|
|
|
|
DWORD exitCode;
|
|
|
|
/* Process completed. Grab the exit value and return. */
|
|
|
|
if( 0 == GetExitCodeProcess( (HANDLE)wpid, &exitCode ) ) {
|
|
|
|
int error = GetLastError();
|
|
|
|
}
|
|
|
|
*status = (int)exitCode;
|
|
|
|
}
|
|
|
|
OPAL_THREAD_UNLOCK(&mutex);
|
|
|
|
return wpid;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void CALLBACK trigger_process_detection( void* lpParameter, BOOLEAN TimerOrWaitFired )
|
|
|
|
{
|
|
|
|
opal_process_handle_t* handle = (opal_process_handle_t*)lpParameter;
|
|
|
|
DWORD exitCode;
|
|
|
|
|
|
|
|
opal_list_remove_item( ®istered_cb, (opal_list_item_t*)handle );
|
|
|
|
/**
|
|
|
|
* As this item will never be triggered again, we can safely remove the
|
|
|
|
* registered handle.
|
|
|
|
*/
|
|
|
|
if( 0 == UnregisterWait( handle->registered_handle ) ) {
|
2007-01-25 03:19:02 +03:00
|
|
|
/**
|
|
|
|
* If any callback functions associated with the timer have not completed when
|
|
|
|
* UnregisterWait is called, UnregisterWait unregisters the wait on the callback
|
|
|
|
* functions and fails with the ERROR_IO_PENDING error code. The error code does
|
|
|
|
* not indicate that the function has failed, and the function does not need to
|
|
|
|
* be called again. If your code requires an error code to set only when the
|
|
|
|
* unregister operation has failed, call UnregisterWaitEx instead.
|
|
|
|
*/
|
2006-08-23 07:32:36 +04:00
|
|
|
int error = GetLastError();
|
|
|
|
}
|
|
|
|
handle->registered_handle = INVALID_HANDLE_VALUE;
|
|
|
|
/**
|
|
|
|
* Get the exit code of the process.
|
|
|
|
*/
|
|
|
|
if( 0 == GetExitCodeProcess( (HANDLE)handle->pid, &exitCode ) ) {
|
|
|
|
int error = GetLastError();
|
|
|
|
}
|
|
|
|
handle->status = (int)exitCode;
|
|
|
|
handle->callback(handle->pid, handle->status, handle->data);
|
|
|
|
OBJ_RELEASE( handle );
|
2005-07-14 22:05:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
orte_wait_cb(pid_t wpid, orte_wait_fn_t callback, void *data)
|
|
|
|
{
|
2006-08-23 07:32:36 +04:00
|
|
|
opal_process_handle_t* handle;
|
|
|
|
|
|
|
|
if (wpid <= 0) return ORTE_ERR_NOT_IMPLEMENTED;
|
|
|
|
if (NULL == callback) return ORTE_ERR_BAD_PARAM;
|
|
|
|
|
|
|
|
OPAL_THREAD_LOCK(&mutex);
|
|
|
|
handle = find_pending_pid(wpid, false);
|
|
|
|
if( handle != NULL ) {
|
|
|
|
opal_list_remove_item( &pending_pids, (opal_list_item_t*)handle );
|
|
|
|
OBJ_RELEASE(handle);
|
|
|
|
return ORTE_SUCCESS;
|
|
|
|
}
|
|
|
|
handle = find_pending_cb( wpid, true );
|
|
|
|
handle->pid = wpid;
|
|
|
|
handle->callback = callback;
|
|
|
|
handle->data = data;
|
|
|
|
|
2007-06-14 08:35:46 +04:00
|
|
|
if( false == RegisterWaitForSingleObject( &handle->registered_handle, (HANDLE)handle->pid,
|
|
|
|
trigger_process_detection, (void*)handle, INFINITE,
|
|
|
|
WT_EXECUTEONLYONCE | WT_EXECUTELONGFUNCTION) ) {
|
|
|
|
DWORD errcode = GetLastError();
|
|
|
|
char* localbuf = NULL;
|
|
|
|
|
|
|
|
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
|
|
|
|
NULL, errcode, 0, (LPTSTR)&localbuf, 1024, NULL );
|
This commit represents a bunch of work on a Mercurial side branch. As
such, the commit message back to the master SVN repository is fairly
long.
= ORTE Job-Level Output Messages =
Add two new interfaces that should be used for all new code throughout
the ORTE and OMPI layers (we already make the search-and-replace on
the existing ORTE / OMPI layers):
* orte_output(): (and corresponding friends ORTE_OUTPUT,
orte_output_verbose, etc.) This function sends the output directly
to the HNP for processing as part of a job-specific output
channel. It supports all the same outputs as opal_output()
(syslog, file, stdout, stderr), but for stdout/stderr, the output
is sent to the HNP for processing and output. More on this below.
* orte_show_help(): This function is a drop-in-replacement for
opal_show_help(), with two differences in functionality:
1. the rendered text help message output is sent to the HNP for
display (rather than outputting directly into the process' stderr
stream)
1. the HNP detects duplicate help messages and does not display them
(so that you don't see the same error message N times, once from
each of your N MPI processes); instead, it counts "new" instances
of the help message and displays a message every ~5 seconds when
there are new ones ("I got X new copies of the help message...")
opal_show_help and opal_output still exist, but they only output in
the current process. The intent for the new orte_* functions is that
they can apply job-level intelligence to the output. As such, we
recommend that all new ORTE and OMPI code use the new orte_*
functions, not thei opal_* functions.
=== New code ===
For ORTE and OMPI programmers, here's what you need to do differently
in new code:
* Do not include opal/util/show_help.h or opal/util/output.h.
Instead, include orte/util/output.h (this one header file has
declarations for both the orte_output() series of functions and
orte_show_help()).
* Effectively s/opal_output/orte_output/gi throughout your code.
Note that orte_output_open() takes a slightly different argument
list (as a way to pass data to the filtering stream -- see below),
so you if explicitly call opal_output_open(), you'll need to
slightly adapt to the new signature of orte_output_open().
* Literally s/opal_show_help/orte_show_help/. The function signature
is identical.
=== Notes ===
* orte_output'ing to stream 0 will do similar to what
opal_output'ing did, so leaving a hard-coded "0" as the first
argument is safe.
* For systems that do not use ORTE's RML or the HNP, the effect of
orte_output_* and orte_show_help will be identical to their opal
counterparts (the additional information passed to
orte_output_open() will be lost!). Indeed, the orte_* functions
simply become trivial wrappers to their opal_* counterparts. Note
that we have not tested this; the code is simple but it is quite
possible that we mucked something up.
= Filter Framework =
Messages sent view the new orte_* functions described above and
messages output via the IOF on the HNP will now optionally be passed
through a new "filter" framework before being output to
stdout/stderr. The "filter" OPAL MCA framework is intended to allow
preprocessing to messages before they are sent to their final
destinations. The first component that was written in the filter
framework was to create an XML stream, segregating all the messages
into different XML tags, etc. This will allow 3rd party tools to read
the stdout/stderr from the HNP and be able to know exactly what each
text message is (e.g., a help message, another OMPI infrastructure
message, stdout from the user process, stderr from the user process,
etc.).
Filtering is not active by default. Filter components must be
specifically requested, such as:
{{{
$ mpirun --mca filter xml ...
}}}
There can only be one filter component active.
= New MCA Parameters =
The new functionality described above introduces two new MCA
parameters:
* '''orte_base_help_aggregate''': Defaults to 1 (true), meaning that
help messages will be aggregated, as described above. If set to 0,
all help messages will be displayed, even if they are duplicates
(i.e., the original behavior).
* '''orte_base_show_output_recursions''': An MCA parameter to help
debug one of the known issues, described below. It is likely that
this MCA parameter will disappear before v1.3 final.
= Known Issues =
* The XML filter component is not complete. The current output from
this component is preliminary and not real XML. A bit more work
needs to be done to configure.m4 search for an appropriate XML
library/link it in/use it at run time.
* There are possible recursion loops in the orte_output() and
orte_show_help() functions -- e.g., if RML send calls orte_output()
or orte_show_help(). We have some ideas how to fix these, but
figured that it was ok to commit before feature freeze with known
issues. The code currently contains sub-optimal workarounds so
that this will not be a problem, but it would be good to actually
solve the problem rather than have hackish workarounds before v1.3 final.
This commit was SVN r18434.
2008-05-14 00:00:55 +04:00
|
|
|
orte_output( 0, "Failed to initialize the process callback for pid %lu error %s\n",
|
2007-06-14 08:35:46 +04:00
|
|
|
(unsigned long)(handle->pid), localbuf );
|
|
|
|
LocalFree( localbuf );
|
|
|
|
}
|
2006-08-23 07:32:36 +04:00
|
|
|
|
|
|
|
OPAL_THREAD_UNLOCK(&mutex);
|
|
|
|
|
|
|
|
return OPAL_SUCCESS;
|
2005-07-14 22:05:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
orte_wait_cb_cancel(pid_t wpid)
|
|
|
|
{
|
2006-08-23 07:32:36 +04:00
|
|
|
opal_process_handle_t* pending;
|
|
|
|
|
|
|
|
OPAL_THREAD_LOCK(&mutex);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Do we have any registered callback for this particular pid ?
|
|
|
|
*/
|
|
|
|
pending = find_pending_cb( wpid, false );
|
|
|
|
if( NULL != pending ) {
|
|
|
|
opal_list_remove_item( ®istered_cb, (opal_list_item_t*)pending );
|
|
|
|
OBJ_RELEASE( pending );
|
|
|
|
OPAL_THREAD_UNLOCK(&mutex);
|
|
|
|
return ORTE_SUCCESS;
|
|
|
|
}
|
|
|
|
OPAL_THREAD_UNLOCK(&mutex);
|
|
|
|
return ORTE_ERR_BAD_PARAM;
|
2005-07-14 22:05:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
orte_wait_cb_disable(void)
|
|
|
|
{
|
2006-08-23 07:32:36 +04:00
|
|
|
OPAL_THREAD_LOCK(&mutex);
|
|
|
|
cb_enabled = false;
|
|
|
|
OPAL_THREAD_UNLOCK(&mutex);
|
|
|
|
|
|
|
|
return ORTE_SUCCESS;
|
2005-07-14 22:05:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
orte_wait_cb_enable(void)
|
|
|
|
{
|
2006-08-23 07:32:36 +04:00
|
|
|
OPAL_THREAD_LOCK(&mutex);
|
|
|
|
cb_enabled = true;
|
|
|
|
OPAL_THREAD_UNLOCK(&mutex);
|
|
|
|
|
|
|
|
return ORTE_SUCCESS;
|
2005-07-14 22:05:30 +04:00
|
|
|
}
|
|
|
|
|
2008-03-05 15:01:37 +03:00
|
|
|
|
|
|
|
int orte_wait_event(opal_event_t **event, int *trig,
|
|
|
|
void (*cbfunc)(int, short, void*))
|
|
|
|
{
|
|
|
|
int p[2];
|
|
|
|
|
|
|
|
if (pipe(p) < 0) {
|
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_SYS_LIMITS_PIPES);
|
|
|
|
return ORTE_ERR_SYS_LIMITS_PIPES;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create the event */
|
|
|
|
*event = (opal_event_t*)malloc(sizeof(opal_event_t));
|
|
|
|
|
|
|
|
/* pass back the write end of the pipe */
|
|
|
|
*trig = p[1];
|
|
|
|
|
|
|
|
/* define the event to fire when someone writes to the pipe */
|
|
|
|
opal_event_set(*event, p[0], OPAL_EV_READ, cbfunc, NULL);
|
|
|
|
|
|
|
|
/* Add it to the active events, without a timeout */
|
|
|
|
opal_event_add(*event, NULL);
|
|
|
|
|
|
|
|
/* all done */
|
|
|
|
return ORTE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-14 22:05:30 +04:00
|
|
|
int
|
|
|
|
orte_wait_kill(int sig)
|
|
|
|
{
|
2006-08-23 07:32:36 +04:00
|
|
|
opal_list_item_t* item;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* First pass. For all registered processes not yet triggered, terminate the
|
|
|
|
* process. Once this first pass is done, we will try to cleanup the ressources
|
|
|
|
*/
|
|
|
|
OPAL_THREAD_LOCK(&mutex);
|
|
|
|
|
|
|
|
for (item = opal_list_get_first(®istered_cb) ;
|
|
|
|
item != opal_list_get_end(®istered_cb) ;
|
|
|
|
item = opal_list_get_next(item)) {
|
|
|
|
opal_process_handle_t* handle = (opal_process_handle_t*)item;
|
|
|
|
|
|
|
|
if( 0 == TerminateProcess( (HANDLE)handle->pid, sig ) ) {
|
|
|
|
int error = GetLastError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Give them a chance to complete the kill. */
|
|
|
|
SleepEx( 1000, TRUE );
|
|
|
|
|
|
|
|
/* And now clean all ressources. */
|
|
|
|
while (NULL != (item = opal_list_remove_first(®istered_cb))) {
|
|
|
|
OBJ_RELEASE(item);
|
|
|
|
}
|
|
|
|
while (NULL != (item = opal_list_remove_first(&pending_pids))) {
|
|
|
|
OBJ_RELEASE(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
OPAL_THREAD_UNLOCK(&mutex);
|
|
|
|
return ORTE_SUCCESS;
|
2005-07-14 22:05:30 +04:00
|
|
|
}
|
|
|
|
|
2007-01-18 02:16:52 +03:00
|
|
|
#else /* no waitpid and not windows */
|
|
|
|
|
|
|
|
int
|
|
|
|
orte_wait_init(void) {
|
|
|
|
return ORTE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
orte_wait_finalize(void)
|
|
|
|
{
|
|
|
|
return ORTE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
pid_t
|
|
|
|
orte_waitpid(pid_t wpid, int *status, int options)
|
|
|
|
{
|
|
|
|
return ORTE_ERR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
orte_wait_cb(pid_t wpid, orte_wait_fn_t callback, void *data)
|
|
|
|
{
|
|
|
|
return ORTE_ERR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
orte_wait_cb_cancel(pid_t wpid)
|
|
|
|
{
|
|
|
|
return ORTE_ERR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
orte_wait_cb_disable(void)
|
|
|
|
{
|
|
|
|
return ORTE_ERR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
orte_wait_cb_enable(void)
|
|
|
|
{
|
|
|
|
return ORTE_ERR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
2008-02-28 04:57:57 +03:00
|
|
|
void
|
|
|
|
orte_trigger_event(int trig)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
orte_wait_event(opal_event_t **event, int *trig,
|
|
|
|
void (*cbfunc)(int, short, void*))
|
|
|
|
{
|
|
|
|
return ORTE_ERR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
2007-01-18 02:16:52 +03:00
|
|
|
int
|
|
|
|
orte_wait_kill(int sig)
|
|
|
|
{
|
|
|
|
return ORTE_ERR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
2005-07-14 22:05:30 +04:00
|
|
|
#endif
|