2004-11-22 03:37:56 +03: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.
|
|
|
|
* Copyright (c) 2004-2005 The University of Tennessee and The University
|
|
|
|
* 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.
|
2006-11-22 05:06:52 +03:00
|
|
|
* Copyright (c) 2006 Los Alamos National Security, LLC. All rights
|
|
|
|
* reserved.
|
|
|
|
*
|
2004-11-22 04:38:40 +03:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
2004-11-22 03:37:56 +03:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
2006-02-12 04:33:29 +03:00
|
|
|
#include "opal_config.h"
|
2005-03-14 23:57:21 +03:00
|
|
|
|
2005-01-20 03:03:23 +03:00
|
|
|
#ifdef HAVE_SCHED_H
|
2004-12-07 18:39:57 +03:00
|
|
|
#include <sched.h>
|
2005-01-20 03:03:23 +03:00
|
|
|
#endif
|
2005-03-14 23:57:21 +03:00
|
|
|
|
2005-07-04 01:57:43 +04:00
|
|
|
#include "opal/runtime/opal_progress.h"
|
2005-07-04 03:09:55 +04:00
|
|
|
#include "opal/event/event.h"
|
2005-08-13 00:46:25 +04:00
|
|
|
#include "opal/mca/base/mca_base_param.h"
|
2006-02-12 04:33:29 +03:00
|
|
|
#include "opal/constants.h"
|
2005-08-18 09:34:22 +04:00
|
|
|
#include "opal/mca/timer/base/base.h"
|
2006-11-22 15:20:08 +03:00
|
|
|
#include "opal/util/output.h"
|
2005-08-18 09:34:22 +04:00
|
|
|
|
|
|
|
#define OPAL_PROGRESS_USE_TIMERS (OPAL_TIMER_CYCLE_SUPPORTED || OPAL_TIMER_USEC_SUPPORTED)
|
2004-12-12 18:29:29 +03:00
|
|
|
|
2005-04-21 18:58:25 +04:00
|
|
|
/*
|
|
|
|
* default parameters
|
|
|
|
*/
|
2006-08-02 02:23:57 +04:00
|
|
|
static int opal_progress_event_flag = OPAL_EVLOOP_ONELOOP;
|
2006-03-02 03:39:07 +03:00
|
|
|
volatile int32_t opal_progress_thread_count = 0;
|
|
|
|
int opal_progress_spin_count = 10000;
|
|
|
|
|
|
|
|
|
2005-04-21 18:58:25 +04:00
|
|
|
/*
|
|
|
|
* Local variables
|
|
|
|
*/
|
2005-03-29 01:02:02 +04:00
|
|
|
#if OMPI_HAVE_THREAD_SUPPORT
|
2005-07-04 01:38:51 +04:00
|
|
|
static opal_atomic_lock_t progress_lock;
|
2005-03-29 01:02:02 +04:00
|
|
|
#endif /* OMPI_HAVE_THREAD_SUPPORT */
|
2005-03-30 05:40:26 +04:00
|
|
|
|
2005-04-21 18:58:25 +04:00
|
|
|
/* callbacks to progress */
|
2005-07-04 01:57:43 +04:00
|
|
|
static opal_progress_callback_t *callbacks = NULL;
|
2005-03-14 23:57:21 +03:00
|
|
|
static size_t callbacks_len = 0;
|
|
|
|
static size_t callbacks_size = 0;
|
2004-12-12 18:29:29 +03:00
|
|
|
|
2005-04-21 18:58:25 +04:00
|
|
|
/* do we want to call sched_yield() if nothing happened */
|
2005-03-30 05:40:26 +04:00
|
|
|
static int call_yield = 1;
|
|
|
|
|
2005-08-18 09:34:22 +04:00
|
|
|
#if OPAL_PROGRESS_USE_TIMERS
|
|
|
|
static opal_timer_t event_progress_last_time = 0;
|
|
|
|
static opal_timer_t event_progress_delta = 0;
|
|
|
|
#else
|
2005-04-21 18:58:25 +04:00
|
|
|
/* current count down until we tick the event library */
|
2005-08-12 20:08:44 +04:00
|
|
|
static int32_t event_progress_counter = 0;
|
2005-04-21 18:58:25 +04:00
|
|
|
/* reset value for counter when it hits 0 */
|
2005-08-18 09:34:22 +04:00
|
|
|
static int32_t event_progress_delta = 0;
|
|
|
|
#endif
|
2005-04-21 18:58:25 +04:00
|
|
|
/* users of the event library from MPI cause the tick rate to
|
|
|
|
be every time */
|
2006-11-22 05:06:52 +03:00
|
|
|
static int32_t num_event_users = 0;
|
|
|
|
|
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 23:36:27 +04:00
|
|
|
/* How deep are we in opal_progress recursion? */
|
|
|
|
#if OMPI_HAVE_THREAD_SUPPORT
|
|
|
|
volatile
|
|
|
|
#endif
|
|
|
|
uint32_t opal_progress_recursion_depth_counter = 0;
|
|
|
|
|
2006-11-22 05:06:52 +03:00
|
|
|
#if OMPI_ENABLE_DEBUG
|
|
|
|
static int debug_output = -1;
|
|
|
|
#endif
|
2005-03-30 05:40:26 +04:00
|
|
|
|
2008-06-06 19:54:40 +04:00
|
|
|
/**
|
|
|
|
* Fake callback used for threading purpose when one thread
|
|
|
|
* progesses callbacks while another unregister somes. The root
|
|
|
|
* of the problem is that we allow modifications of the callback
|
|
|
|
* array directly from the callbacks themselves. Now if
|
|
|
|
* writing a pointer is atomic, we should not have any more
|
|
|
|
* problems.
|
|
|
|
*/
|
|
|
|
static int fake_cb(void) { return 0; };
|
2005-03-30 05:40:26 +04:00
|
|
|
|
2005-04-14 22:55:53 +04:00
|
|
|
/* init the progress engine - called from orte_init */
|
2005-02-16 20:42:07 +03:00
|
|
|
int
|
2005-07-04 01:57:43 +04:00
|
|
|
opal_progress_init(void)
|
2005-02-16 20:42:07 +03:00
|
|
|
{
|
2007-01-08 20:20:09 +03:00
|
|
|
#if OMPI_ENABLE_DEBUG
|
2006-11-22 05:06:52 +03:00
|
|
|
int param, value;
|
2007-01-08 20:20:09 +03:00
|
|
|
#endif
|
2006-11-22 05:06:52 +03:00
|
|
|
|
2005-03-30 05:40:26 +04:00
|
|
|
/* reentrant issues */
|
2005-03-29 01:02:02 +04:00
|
|
|
#if OMPI_HAVE_THREAD_SUPPORT
|
2005-07-04 01:38:51 +04:00
|
|
|
opal_atomic_init(&progress_lock, OPAL_ATOMIC_UNLOCKED);
|
2005-03-29 01:02:02 +04:00
|
|
|
#endif /* OMPI_HAVE_THREAD_SUPPORT */
|
2005-03-30 05:40:26 +04:00
|
|
|
|
|
|
|
/* set the event tick rate */
|
2006-11-22 05:06:52 +03:00
|
|
|
opal_progress_set_event_poll_rate(10000);
|
2005-03-30 05:40:26 +04:00
|
|
|
|
2006-11-22 05:06:52 +03:00
|
|
|
#if OMPI_ENABLE_DEBUG
|
|
|
|
param = mca_base_param_find("opal", NULL, "progress_debug");
|
|
|
|
mca_base_param_lookup_int(param, &value);
|
|
|
|
if (value) {
|
|
|
|
debug_output = opal_output_open(NULL);
|
2005-03-30 05:40:26 +04:00
|
|
|
}
|
2005-08-18 09:34:22 +04:00
|
|
|
#endif
|
2005-03-30 05:40:26 +04:00
|
|
|
|
2007-02-05 22:38:54 +03:00
|
|
|
OPAL_OUTPUT((debug_output, "progress: initialized event flag to: %x",
|
|
|
|
opal_progress_event_flag));
|
|
|
|
OPAL_OUTPUT((debug_output, "progress: initialized yield_when_idle to: %s",
|
|
|
|
call_yield == 0 ? "false" : "true"));
|
|
|
|
OPAL_OUTPUT((debug_output, "progress: initialized num users to: %d",
|
|
|
|
num_event_users));
|
|
|
|
OPAL_OUTPUT((debug_output, "progress: initialized poll rate to: %ld",
|
|
|
|
(long) event_progress_delta));
|
|
|
|
|
2006-02-12 04:33:29 +03:00
|
|
|
return OPAL_SUCCESS;
|
2005-03-30 05:40:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2005-07-04 01:57:43 +04:00
|
|
|
opal_progress_finalize(void)
|
2005-03-30 05:40:26 +04:00
|
|
|
{
|
|
|
|
/* free memory associated with the callbacks */
|
|
|
|
#if OMPI_HAVE_THREAD_SUPPORT
|
2005-07-04 01:38:51 +04:00
|
|
|
opal_atomic_lock(&progress_lock);
|
2005-03-30 05:40:26 +04:00
|
|
|
#endif
|
|
|
|
|
2006-11-22 05:06:52 +03:00
|
|
|
callbacks_len = 0;
|
|
|
|
callbacks_size = 0;
|
2005-03-30 22:03:08 +04:00
|
|
|
if (NULL != callbacks) {
|
|
|
|
free(callbacks);
|
|
|
|
callbacks = NULL;
|
|
|
|
}
|
2005-03-30 05:40:26 +04:00
|
|
|
|
|
|
|
#if OMPI_HAVE_THREAD_SUPPORT
|
2005-07-04 01:38:51 +04:00
|
|
|
opal_atomic_unlock(&progress_lock);
|
2005-03-30 05:40:26 +04:00
|
|
|
#endif
|
|
|
|
|
2006-02-12 04:33:29 +03:00
|
|
|
return OPAL_SUCCESS;
|
2005-02-16 20:42:07 +03:00
|
|
|
}
|
|
|
|
|
2005-03-30 05:40:26 +04:00
|
|
|
|
2005-04-05 21:58:43 +04:00
|
|
|
/*
|
|
|
|
* Progress the event library and any functions that have registered to
|
|
|
|
* be called. We don't propogate errors from the progress functions,
|
|
|
|
* so no action is taken if they return failures. The functions are
|
|
|
|
* expected to return the number of events progressed, to determine
|
|
|
|
* whether or not we should call sched_yield() during MPI progress.
|
|
|
|
* This is only losely tracked, as an error return can cause the number
|
|
|
|
* of progressed events to appear lower than it actually is. We don't
|
|
|
|
* care, as the cost of that happening is far outweighed by the cost
|
2005-08-12 20:21:17 +04:00
|
|
|
* of the if checks (they were resulting in bad pipe stalling behavior)
|
2005-04-05 21:58:43 +04:00
|
|
|
*/
|
2005-03-30 05:40:26 +04:00
|
|
|
void
|
2005-07-04 01:57:43 +04:00
|
|
|
opal_progress(void)
|
2004-04-06 20:32:40 +04:00
|
|
|
{
|
2005-03-14 23:57:21 +03:00
|
|
|
size_t i;
|
2005-04-05 21:58:43 +04:00
|
|
|
int events = 0;
|
2006-02-16 19:08:12 +03:00
|
|
|
|
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 23:36:27 +04:00
|
|
|
#if OMPI_HAVE_THREAD_SUPPORT
|
|
|
|
opal_atomic_add(&opal_progress_recursion_depth_counter, 1);
|
|
|
|
#else
|
|
|
|
++opal_progress_recursion_depth_counter;
|
|
|
|
#endif
|
2006-02-16 19:08:12 +03:00
|
|
|
if( opal_progress_event_flag != 0 ) {
|
|
|
|
#if (OMPI_ENABLE_PROGRESS_THREADS == 0) && OPAL_HAVE_WORKING_EVENTOPS
|
2005-08-18 09:34:22 +04:00
|
|
|
#if OPAL_PROGRESS_USE_TIMERS
|
|
|
|
#if OPAL_TIMER_USEC_NATIVE
|
2007-07-24 23:10:19 +04:00
|
|
|
opal_timer_t now = opal_timer_base_get_usec();
|
2005-08-18 09:34:22 +04:00
|
|
|
#else
|
2007-07-24 23:10:19 +04:00
|
|
|
opal_timer_t now = opal_timer_base_get_cycles();
|
2006-02-16 19:08:12 +03:00
|
|
|
#endif /* OPAL_TIMER_USEC_NATIVE */
|
2005-08-18 09:34:22 +04:00
|
|
|
/* trip the event library if we've reached our tick rate and we are
|
|
|
|
enabled */
|
2006-02-16 19:08:12 +03:00
|
|
|
if (now - event_progress_last_time > event_progress_delta ) {
|
2006-11-22 05:06:52 +03:00
|
|
|
event_progress_last_time = (num_event_users > 0) ?
|
2006-02-16 19:08:12 +03:00
|
|
|
now - event_progress_delta : now;
|
2005-08-18 09:34:22 +04:00
|
|
|
|
2006-02-16 19:08:12 +03:00
|
|
|
events += opal_event_loop(opal_progress_event_flag);
|
|
|
|
}
|
2005-08-18 09:34:22 +04:00
|
|
|
|
|
|
|
#else /* OPAL_PROGRESS_USE_TIMERS */
|
2005-03-30 05:40:26 +04:00
|
|
|
/* trip the event library if we've reached our tick rate and we are
|
|
|
|
enabled */
|
2006-02-16 19:08:12 +03:00
|
|
|
if (OPAL_THREAD_ADD32(&event_progress_counter, -1) <= 0 ) {
|
|
|
|
event_progress_counter =
|
2006-11-22 05:06:52 +03:00
|
|
|
(num_event_users > 0) ? 0 : event_progress_delta;
|
2006-02-16 19:08:12 +03:00
|
|
|
events += opal_event_loop(opal_progress_event_flag);
|
|
|
|
}
|
2005-08-18 09:34:22 +04:00
|
|
|
#endif /* OPAL_PROGRESS_USE_TIMERS */
|
|
|
|
|
2005-08-12 20:21:17 +04:00
|
|
|
#endif /* OMPI_ENABLE_PROGRESS_THREADS == 0 && OPAL_HAVE_WORKING_EVENTOPS */
|
2006-02-16 19:08:12 +03:00
|
|
|
}
|
2005-08-18 09:34:22 +04:00
|
|
|
|
2005-03-30 05:40:26 +04:00
|
|
|
/* progress all registered callbacks */
|
2005-03-14 23:57:21 +03:00
|
|
|
for (i = 0 ; i < callbacks_len ; ++i) {
|
2006-02-16 19:08:12 +03:00
|
|
|
events += (callbacks[i])();
|
2005-03-14 23:57:21 +03:00
|
|
|
}
|
|
|
|
|
2006-08-24 18:02:26 +04:00
|
|
|
#if defined(__WINDOWS__) || defined(HAVE_SCHED_YIELD)
|
2005-06-13 23:32:52 +04:00
|
|
|
if (call_yield && events <= 0) {
|
2005-04-21 18:58:25 +04:00
|
|
|
/* If there is nothing to do - yield the processor - otherwise
|
2005-03-30 05:40:26 +04:00
|
|
|
* we could consume the processor for the entire time slice. If
|
|
|
|
* the processor is oversubscribed - this will result in a best-case
|
|
|
|
* latency equivalent to the time-slice.
|
|
|
|
*/
|
2006-08-22 00:08:51 +04:00
|
|
|
#if defined(__WINDOWS__)
|
|
|
|
SwitchToThread();
|
|
|
|
#else
|
2005-03-29 01:03:24 +04:00
|
|
|
sched_yield();
|
2006-08-22 00:08:51 +04:00
|
|
|
#endif /* defined(__WINDOWS__) */
|
2004-12-12 18:29:29 +03:00
|
|
|
}
|
2006-08-24 18:06:01 +04:00
|
|
|
#endif /* defined(__WINDOWS__) || defined(HAVE_SCHED_YIELD) */
|
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 23:36:27 +04:00
|
|
|
#if OMPI_HAVE_THREAD_SUPPORT
|
|
|
|
opal_atomic_add(&opal_progress_recursion_depth_counter, -1);
|
|
|
|
#else
|
|
|
|
--opal_progress_recursion_depth_counter;
|
|
|
|
#endif
|
2004-04-06 20:32:40 +04:00
|
|
|
}
|
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
|
2006-11-22 05:06:52 +03:00
|
|
|
int
|
|
|
|
opal_progress_set_event_flag(int flag)
|
|
|
|
{
|
|
|
|
int tmp = opal_progress_event_flag;
|
|
|
|
opal_progress_event_flag = flag;
|
2007-02-05 22:38:54 +03:00
|
|
|
|
|
|
|
OPAL_OUTPUT((debug_output, "progress: set_event_flag setting to %d", flag));
|
|
|
|
|
2006-11-22 05:06:52 +03:00
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
opal_progress_event_users_increment(void)
|
|
|
|
{
|
|
|
|
int32_t val;
|
|
|
|
val = opal_atomic_add_32(&num_event_users, 1);
|
|
|
|
|
2007-02-05 22:38:54 +03:00
|
|
|
OPAL_OUTPUT((debug_output, "progress: event_users_increment setting count to %d", val));
|
2006-11-22 05:06:52 +03:00
|
|
|
|
|
|
|
#if OPAL_PROGRESS_USE_TIMERS
|
|
|
|
/* force an update next round (we'll be past the delta) */
|
|
|
|
event_progress_last_time -= event_progress_delta;
|
|
|
|
#else
|
|
|
|
/* always reset the tick rate - can't hurt */
|
|
|
|
event_progress_counter = 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
opal_progress_event_users_decrement(void)
|
|
|
|
{
|
|
|
|
int32_t val;
|
|
|
|
val = opal_atomic_sub_32(&num_event_users, 1);
|
|
|
|
|
2007-02-05 22:38:54 +03:00
|
|
|
OPAL_OUTPUT((debug_output, "progress: event_users_decrement setting count to %d", val));
|
2006-11-22 05:06:52 +03:00
|
|
|
|
|
|
|
#if !OPAL_PROGRESS_USE_TIMERS
|
|
|
|
/* start now in delaying if it's easy */
|
|
|
|
if (val >= 0) {
|
|
|
|
event_progress_counter = event_progress_delta;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
opal_progress_set_yield_when_idle(bool yieldopt)
|
|
|
|
{
|
|
|
|
bool tmp = (call_yield == 0) ? false : true;
|
|
|
|
call_yield = (yieldopt) ? 1 : 0;
|
|
|
|
|
2007-02-07 17:22:37 +03:00
|
|
|
OPAL_OUTPUT((debug_output, "progress: progress_set_yield_when_idle to %s",
|
|
|
|
call_yield == 0 ? "false" : "true"));
|
2006-11-22 05:06:52 +03:00
|
|
|
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
opal_progress_set_event_poll_rate(int polltime)
|
|
|
|
{
|
2007-02-05 22:38:54 +03:00
|
|
|
OPAL_OUTPUT((debug_output, "progress: progress_set_event_poll_rate(%d)", polltime));
|
2006-11-22 05:06:52 +03:00
|
|
|
|
|
|
|
#if OPAL_PROGRESS_USE_TIMERS
|
|
|
|
event_progress_delta = 0;
|
|
|
|
# if OPAL_TIMER_USEC_NATIVE
|
|
|
|
event_progress_last_time = opal_timer_base_get_usec();
|
|
|
|
# else
|
|
|
|
event_progress_last_time = opal_timer_base_get_cycles();
|
|
|
|
# endif
|
|
|
|
#else
|
|
|
|
event_progress_counter = event_progress_delta = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (polltime == 0) {
|
|
|
|
#if OPAL_PROGRESS_USE_TIMERS
|
|
|
|
/* user specified as never tick - tick once per minute */
|
|
|
|
event_progress_delta = 60 * 1000000;
|
|
|
|
#else
|
|
|
|
/* user specified as never tick - don't count often */
|
|
|
|
event_progress_delta = INT_MAX;
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
#if OPAL_PROGRESS_USE_TIMERS
|
|
|
|
event_progress_delta = polltime;
|
|
|
|
#else
|
|
|
|
/* subtract one so that we can do post-fix subtraction
|
|
|
|
in the inner loop and go faster */
|
|
|
|
event_progress_delta = polltime - 1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#if OPAL_PROGRESS_USE_TIMERS && !OPAL_TIMER_USEC_NATIVE
|
|
|
|
/* going to use cycles for counter. Adjust specified usec into cycles */
|
|
|
|
event_progress_delta = event_progress_delta * opal_timer_base_get_freq() / 1000000;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
int
|
2005-07-04 01:57:43 +04:00
|
|
|
opal_progress_register(opal_progress_callback_t cb)
|
2005-03-14 23:57:21 +03:00
|
|
|
{
|
2008-06-06 19:54:40 +04:00
|
|
|
int ret = OPAL_SUCCESS, index;
|
2005-03-30 05:40:26 +04:00
|
|
|
|
|
|
|
#if OMPI_HAVE_THREAD_SUPPORT
|
2005-07-04 01:38:51 +04:00
|
|
|
opal_atomic_lock(&progress_lock);
|
2005-03-30 05:40:26 +04:00
|
|
|
#endif
|
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
/* see if we need to allocate more space */
|
|
|
|
if (callbacks_len + 1 > callbacks_size) {
|
2005-07-04 01:57:43 +04:00
|
|
|
opal_progress_callback_t *tmp;
|
2006-08-22 00:08:51 +04:00
|
|
|
tmp = (opal_progress_callback_t*)realloc(callbacks, sizeof(opal_progress_callback_t) * (callbacks_size + 4));
|
2005-03-30 05:40:26 +04:00
|
|
|
if (tmp == NULL) {
|
2006-02-12 04:33:29 +03:00
|
|
|
ret = OPAL_ERR_TEMP_OUT_OF_RESOURCE;
|
2005-03-30 05:40:26 +04:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2008-06-06 19:54:40 +04:00
|
|
|
/* registering fake callbacks to fill callbacks[] */
|
|
|
|
for( index = callbacks_len + 1 ; index < callbacks_size + 4 ; index++) {
|
|
|
|
tmp[index] = &fake_cb;
|
|
|
|
}
|
2005-03-14 23:57:21 +03:00
|
|
|
|
|
|
|
callbacks = tmp;
|
|
|
|
callbacks_size += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
callbacks[callbacks_len++] = cb;
|
|
|
|
|
2005-03-30 05:40:26 +04:00
|
|
|
cleanup:
|
|
|
|
|
|
|
|
#if OMPI_HAVE_THREAD_SUPPORT
|
2005-07-04 01:38:51 +04:00
|
|
|
opal_atomic_unlock(&progress_lock);
|
2005-03-30 05:40:26 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return ret;
|
2005-03-14 23:57:21 +03:00
|
|
|
}
|
2005-03-18 06:43:59 +03:00
|
|
|
|
|
|
|
int
|
2005-07-04 01:57:43 +04:00
|
|
|
opal_progress_unregister(opal_progress_callback_t cb)
|
2005-03-18 06:43:59 +03:00
|
|
|
{
|
|
|
|
size_t i;
|
2006-02-12 04:33:29 +03:00
|
|
|
int ret = OPAL_ERR_NOT_FOUND;
|
2005-03-30 05:40:26 +04:00
|
|
|
|
|
|
|
#if OMPI_HAVE_THREAD_SUPPORT
|
2005-07-04 01:38:51 +04:00
|
|
|
opal_atomic_lock(&progress_lock);
|
2005-03-30 05:40:26 +04:00
|
|
|
#endif
|
2005-03-18 06:43:59 +03:00
|
|
|
|
|
|
|
for (i = 0 ; i < callbacks_len ; ++i) {
|
|
|
|
if (cb == callbacks[i]) {
|
2008-06-06 19:54:40 +04:00
|
|
|
callbacks[i] = &fake_cb;
|
2006-02-12 04:33:29 +03:00
|
|
|
ret = OPAL_SUCCESS;
|
2005-04-05 21:58:43 +04:00
|
|
|
break;
|
2005-03-18 06:43:59 +03:00
|
|
|
}
|
|
|
|
}
|
2005-04-05 21:58:43 +04:00
|
|
|
|
2005-04-15 00:10:27 +04:00
|
|
|
/* If we found the function we're unregistering: If callbacks_len
|
|
|
|
is 0, we're not goig to do anything interesting anyway, so
|
|
|
|
skip. If callbacks_len is 1, it will soon be 0, so no need to
|
|
|
|
do any repacking. size_t can be unsigned, so 0 - 1 is bad for
|
|
|
|
a loop condition :). */
|
2006-02-12 04:33:29 +03:00
|
|
|
if (OPAL_SUCCESS == ret) {
|
2005-04-15 00:10:27 +04:00
|
|
|
if (callbacks_len > 1 ) {
|
|
|
|
/* now tightly pack the array */
|
|
|
|
for ( ; i < callbacks_len - 1 ; ++i) {
|
|
|
|
callbacks[i] = callbacks[i + 1];
|
|
|
|
}
|
2005-04-07 00:17:45 +04:00
|
|
|
}
|
2008-06-06 19:54:40 +04:00
|
|
|
callbacks[callbacks_len - 1] = &fake_cb;
|
2005-04-15 00:10:27 +04:00
|
|
|
callbacks_len--;
|
2005-04-05 21:58:43 +04:00
|
|
|
}
|
2005-03-30 05:40:26 +04:00
|
|
|
|
|
|
|
#if OMPI_HAVE_THREAD_SUPPORT
|
2005-07-04 01:38:51 +04:00
|
|
|
opal_atomic_unlock(&progress_lock);
|
2005-03-30 05:40:26 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return ret;
|
2005-03-18 06:43:59 +03:00
|
|
|
}
|