2014-03-27 19:51:06 +04:00
|
|
|
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
|
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.
|
2014-03-27 19:51:06 +04:00
|
|
|
* Copyright (c) 2006-2014 Los Alamos National Security, LLC. All rights
|
2006-11-22 05:06:52 +03:00
|
|
|
* 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"
|
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"
|
2013-03-28 01:09:41 +04:00
|
|
|
#include "opal/mca/base/mca_base_var.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"
|
2013-03-28 01:09:41 +04:00
|
|
|
#include "opal/runtime/opal_params.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
|
|
|
|
2013-03-28 01:09:41 +04:00
|
|
|
#if OPAL_ENABLE_DEBUG
|
|
|
|
bool opal_progress_debug = false;
|
|
|
|
#endif
|
|
|
|
|
2005-04-21 18:58:25 +04:00
|
|
|
/*
|
|
|
|
* default parameters
|
|
|
|
*/
|
2010-10-27 00:29:22 +04:00
|
|
|
static int opal_progress_event_flag = OPAL_EVLOOP_ONCE | OPAL_EVLOOP_NONBLOCK;
|
2006-03-02 03:39:07 +03:00
|
|
|
int opal_progress_spin_count = 10000;
|
|
|
|
|
|
|
|
|
2005-04-21 18:58:25 +04:00
|
|
|
/*
|
|
|
|
* Local variables
|
|
|
|
*/
|
2005-07-04 01:38:51 +04:00
|
|
|
static opal_atomic_lock_t progress_lock;
|
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 */
|
2014-03-27 19:51:06 +04:00
|
|
|
bool opal_progress_yield_when_idle;
|
2005-03-30 05:40:26 +04:00
|
|
|
|
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;
|
|
|
|
|
2009-05-07 00:11:28 +04:00
|
|
|
#if OPAL_ENABLE_DEBUG
|
2006-11-22 05:06:52 +03:00
|
|
|
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.
|
|
|
|
*/
|
2008-06-09 16:57:41 +04:00
|
|
|
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
|
|
|
{
|
2005-03-30 05:40:26 +04:00
|
|
|
/* reentrant issues */
|
2005-07-04 01:38:51 +04:00
|
|
|
opal_atomic_init(&progress_lock, OPAL_ATOMIC_UNLOCKED);
|
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
|
|
|
|
2009-05-07 00:11:28 +04:00
|
|
|
#if OPAL_ENABLE_DEBUG
|
2013-03-28 01:09:41 +04:00
|
|
|
if (opal_progress_debug) {
|
|
|
|
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",
|
2014-03-27 19:51:06 +04:00
|
|
|
opal_progress_yield_when_idle ? "true" : "false"));
|
2007-02-05 22:38:54 +03:00
|
|
|
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 */
|
2005-07-04 01:38:51 +04:00
|
|
|
opal_atomic_lock(&progress_lock);
|
2005-03-30 05:40:26 +04:00
|
|
|
|
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
|
|
|
|
2005-07-04 01:38:51 +04:00
|
|
|
opal_atomic_unlock(&progress_lock);
|
2005-03-30 05:40:26 +04:00
|
|
|
|
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
|
|
|
|
|
|
|
if( opal_progress_event_flag != 0 ) {
|
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
|
|
|
#if 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
|
|
|
|
2010-10-28 19:22:46 +04:00
|
|
|
events += opal_event_loop(opal_event_base, opal_progress_event_flag);
|
2006-02-16 19:08:12 +03:00
|
|
|
}
|
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;
|
2010-10-28 19:22:46 +04:00
|
|
|
events += opal_event_loop(opal_event_base, opal_progress_event_flag);
|
2006-02-16 19:08:12 +03:00
|
|
|
}
|
2005-08-18 09:34:22 +04:00
|
|
|
#endif /* OPAL_PROGRESS_USE_TIMERS */
|
|
|
|
|
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
|
|
|
#endif /* 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
|
|
|
}
|
|
|
|
|
2013-02-28 21:31:47 +04:00
|
|
|
#if defined(HAVE_SCHED_YIELD)
|
2014-03-27 19:51:06 +04:00
|
|
|
if (opal_progress_yield_when_idle && 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.
|
|
|
|
*/
|
2005-03-29 01:03:24 +04:00
|
|
|
sched_yield();
|
2004-12-12 18:29:29 +03:00
|
|
|
}
|
2013-02-28 21:31:47 +04:00
|
|
|
#endif /* defined(HAVE_SCHED_YIELD) */
|
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)
|
|
|
|
{
|
2014-03-27 19:51:06 +04:00
|
|
|
bool tmp = opal_progress_yield_when_idle;
|
|
|
|
opal_progress_yield_when_idle = (yieldopt) ? 1 : 0;
|
2006-11-22 05:06:52 +03:00
|
|
|
|
2007-02-07 17:22:37 +03:00
|
|
|
OPAL_OUTPUT((debug_output, "progress: progress_set_yield_when_idle to %s",
|
2014-03-27 19:51:06 +04:00
|
|
|
opal_progress_yield_when_idle ? "true" : "false"));
|
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-09 16:57:41 +04:00
|
|
|
int ret = OPAL_SUCCESS;
|
|
|
|
size_t index;
|
2005-03-30 05:40:26 +04:00
|
|
|
|
2005-07-04 01:38:51 +04:00
|
|
|
opal_atomic_lock(&progress_lock);
|
2005-03-30 05:40:26 +04:00
|
|
|
|
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:
|
|
|
|
|
2005-07-04 01:38:51 +04:00
|
|
|
opal_atomic_unlock(&progress_lock);
|
2005-03-30 05:40:26 +04:00
|
|
|
|
|
|
|
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
|
|
|
|
2005-07-04 01:38:51 +04:00
|
|
|
opal_atomic_lock(&progress_lock);
|
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
|
|
|
|
2005-07-04 01:38:51 +04:00
|
|
|
opal_atomic_unlock(&progress_lock);
|
2005-03-30 05:40:26 +04:00
|
|
|
|
|
|
|
return ret;
|
2005-03-18 06:43:59 +03:00
|
|
|
}
|