From de722196965b37f6b0f2b7b85d9cfbe9ba339832 Mon Sep 17 00:00:00 2001 From: Noah Evans Date: Mon, 4 Feb 2019 20:20:37 -0700 Subject: [PATCH 01/17] Add threads framework Add a framework to support different types of threading models including user space thread packages such as Qthreads and argobot: https://github.com/pmodels/argobots https://github.com/Qthreads/qthreads The default threading model is pthreads. Alternate thread models are specificed at configure time using the --with-threads=X option. The framework is static. The theading model to use is selected at Open MPI configure/build time. Signed-off-by: Noah Evans --- configure.ac | 2 +- opal/Makefile.am | 1 - opal/mca/event/event.h | 2 + opal/mca/event/external/external.h | 3 - opal/mca/event/libevent2022/libevent2022.h | 3 - opal/mca/threads/Makefile.am | 39 ++++ opal/mca/threads/base/Makefile.am | 24 +++ opal/mca/threads/base/base.h | 45 ++++ opal/mca/threads/base/owner.txt | 7 + opal/mca/threads/base/threads_base_null.h | 47 +++++ opal/mca/threads/base/threads_base_open.c | 45 ++++ opal/mca/threads/condition.h | 145 +++++++++++++ opal/mca/threads/configure.m4 | 55 +++++ opal/mca/threads/mutex.h | 196 ++++++++++++++++++ opal/mca/threads/pthreads/Makefile.am | 28 +++ opal/mca/threads/pthreads/configure.m4 | 65 ++++++ .../threads/pthreads}/mutex_unix.h | 18 +- opal/mca/threads/pthreads/owner.txt | 7 + opal/mca/threads/pthreads/threads_base_null.h | 62 ++++++ opal/mca/threads/pthreads/threads_pthreads.h | 1 + .../pthreads/threads_pthreads_component.c | 53 +++++ .../pthreads/threads_pthreads_condition.c} | 2 +- .../pthreads/threads_pthreads_module.c} | 90 ++++---- .../threads/pthreads/threads_pthreads_mutex.c | 63 ++++++ .../pthreads/threads_pthreads_wait_sync.c} | 2 +- opal/mca/threads/qthreads/Makefile.am | 27 +++ opal/mca/threads/qthreads/configure.m4 | 61 ++++++ opal/mca/threads/qthreads/owner.txt | 7 + opal/mca/threads/qthreads/threads_base_null.h | 62 ++++++ .../threads/qthreads/threads_base_null.htmp | 62 ++++++ opal/mca/threads/qthreads/threads_qthreads.h | 96 +++++++++ .../threads/qthreads/threads_qthreads.htmp | 96 +++++++++ .../qthreads/threads_qthreads_component.c | 53 +++++ .../qthreads/threads_qthreads_condition.c | 38 ++++ .../qthreads/threads_qthreads_module.c | 123 +++++++++++ .../qthreads/threads_qthreads_mutex.c} | 2 +- opal/mca/threads/thread.h | 96 +++++++++ opal/mca/threads/thread_usage.h | 192 +++++++++++++++++ opal/mca/threads/threads.h | 145 +++++++++++++ opal/mca/threads/tsd.h | 178 ++++++++++++++++ opal/mca/threads/wait_sync.h | 128 ++++++++++++ opal/runtime/opal_params.c | 4 + opal/threads/Makefile.am | 39 ---- opal/threads/condition.h | 119 +---------- opal/threads/mutex.h | 163 +-------------- opal/threads/threads.h | 114 +--------- opal/threads/tsd.h | 162 +-------------- opal/threads/wait_sync.h | 107 +--------- opal/tools/wrappers/Makefile.am | 3 +- 49 files changed, 2315 insertions(+), 767 deletions(-) create mode 100644 opal/mca/threads/Makefile.am create mode 100644 opal/mca/threads/base/Makefile.am create mode 100644 opal/mca/threads/base/base.h create mode 100644 opal/mca/threads/base/owner.txt create mode 100644 opal/mca/threads/base/threads_base_null.h create mode 100644 opal/mca/threads/base/threads_base_open.c create mode 100644 opal/mca/threads/condition.h create mode 100644 opal/mca/threads/configure.m4 create mode 100644 opal/mca/threads/mutex.h create mode 100644 opal/mca/threads/pthreads/Makefile.am create mode 100644 opal/mca/threads/pthreads/configure.m4 rename opal/{threads => mca/threads/pthreads}/mutex_unix.h (91%) create mode 100644 opal/mca/threads/pthreads/owner.txt create mode 100644 opal/mca/threads/pthreads/threads_base_null.h create mode 100644 opal/mca/threads/pthreads/threads_pthreads.h create mode 100644 opal/mca/threads/pthreads/threads_pthreads_component.c rename opal/{threads/condition.c => mca/threads/pthreads/threads_pthreads_condition.c} (96%) rename opal/{threads/thread.c => mca/threads/pthreads/threads_pthreads_module.c} (80%) create mode 100644 opal/mca/threads/pthreads/threads_pthreads_mutex.c rename opal/{threads/wait_sync.c => mca/threads/pthreads/threads_pthreads_wait_sync.c} (98%) create mode 100644 opal/mca/threads/qthreads/Makefile.am create mode 100644 opal/mca/threads/qthreads/configure.m4 create mode 100644 opal/mca/threads/qthreads/owner.txt create mode 100644 opal/mca/threads/qthreads/threads_base_null.h create mode 100644 opal/mca/threads/qthreads/threads_base_null.htmp create mode 100644 opal/mca/threads/qthreads/threads_qthreads.h create mode 100644 opal/mca/threads/qthreads/threads_qthreads.htmp create mode 100644 opal/mca/threads/qthreads/threads_qthreads_component.c create mode 100644 opal/mca/threads/qthreads/threads_qthreads_condition.c create mode 100644 opal/mca/threads/qthreads/threads_qthreads_module.c rename opal/{threads/mutex.c => mca/threads/qthreads/threads_qthreads_mutex.c} (98%) create mode 100644 opal/mca/threads/thread.h create mode 100644 opal/mca/threads/thread_usage.h create mode 100644 opal/mca/threads/threads.h create mode 100644 opal/mca/threads/tsd.h create mode 100644 opal/mca/threads/wait_sync.h delete mode 100644 opal/threads/Makefile.am diff --git a/configure.ac b/configure.ac index 7a3030dee6c..df0a8c92152 100644 --- a/configure.ac +++ b/configure.ac @@ -972,7 +972,7 @@ OPAL_CHECK_BROKEN_QSORT # # Check out what thread support we have # -OPAL_CONFIG_THREADS +#OPAL_CONFIG_THREADS CFLAGS="$CFLAGS $THREAD_CFLAGS" CPPFLAGS="$CPPFLAGS $THREAD_CPPFLAGS" diff --git a/opal/Makefile.am b/opal/Makefile.am index b657794eabc..de2588716ed 100644 --- a/opal/Makefile.am +++ b/opal/Makefile.am @@ -71,7 +71,6 @@ endif include class/Makefile.am include memoryhooks/Makefile.am include runtime/Makefile.am -include threads/Makefile.am include mca/Makefile.am include tools/Makefile.am include dss/Makefile.am diff --git a/opal/mca/event/event.h b/opal/mca/event/event.h index b0958b64e09..65f8f69e054 100644 --- a/opal/mca/event/event.h +++ b/opal/mca/event/event.h @@ -48,6 +48,8 @@ BEGIN_C_DECLS #define OPAL_TIMEOUT_DEFAULT {1, 0} +OPAL_DECLSPEC void opal_event_use_threads(void); + /** * Structure for event components. */ diff --git a/opal/mca/event/external/external.h b/opal/mca/event/external/external.h index 00378f684fe..6fe67feeeab 100644 --- a/opal/mca/event/external/external.h +++ b/opal/mca/event/external/external.h @@ -71,9 +71,6 @@ OPAL_DECLSPEC int opal_event_finalize(void); #define opal_event_set_priority(x, n) event_priority_set((x), (n)) -/* thread support APIs */ -#define opal_event_use_threads() evthread_use_pthreads() - /* Basic event APIs */ #define opal_event_enable_debug_mode() event_enable_debug_mode() diff --git a/opal/mca/event/libevent2022/libevent2022.h b/opal/mca/event/libevent2022/libevent2022.h index de3443539f0..73961785475 100644 --- a/opal/mca/event/libevent2022/libevent2022.h +++ b/opal/mca/event/libevent2022/libevent2022.h @@ -102,9 +102,6 @@ OPAL_DECLSPEC int opal_event_finalize(void); #define opal_event_set_priority(x, n) event_priority_set((x), (n)) -/* thread support APIs */ -#define opal_event_use_threads() evthread_use_pthreads() - /* Basic event APIs */ #define opal_event_enable_debug_mode() event_enable_debug_mode() diff --git a/opal/mca/threads/Makefile.am b/opal/mca/threads/Makefile.am new file mode 100644 index 00000000000..a2164a34c5a --- /dev/null +++ b/opal/mca/threads/Makefile.am @@ -0,0 +1,39 @@ +# +# 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. +# Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, +# University of Stuttgart. All rights reserved. +# Copyright (c) 2004-2005 The Regents of the University of California. +# All rights reserved. +# Copyright (c) 2010 Cisco Systems, Inc. All rights reserved. +# $COPYRIGHT$ +# +# Additional copyrights may follow +# +# $HEADER$ +# + +# main library setup +noinst_LTLIBRARIES = libmca_threads.la +libmca_threads_la_SOURCES = + +# local files +headers = threads.h +nodist_headers = +libmca_threads_la_SOURCES += $(headers) + +# Conditionally install the header files +if WANT_INSTALL_HEADERS +opaldir = $(opalincludedir)/$(subdir) +nobase_opal_HEADERS = $(headers) +nobase_nodist_opal_HEADERS = $(nodist_headers) +endif + +include base/Makefile.am + +distclean-local: + rm -f base/static-components.h diff --git a/opal/mca/threads/base/Makefile.am b/opal/mca/threads/base/Makefile.am new file mode 100644 index 00000000000..cbaa77d35a8 --- /dev/null +++ b/opal/mca/threads/base/Makefile.am @@ -0,0 +1,24 @@ +# +# 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. +# Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, +# University of Stuttgart. All rights reserved. +# Copyright (c) 2004-2005 The Regents of the University of California. +# All rights reserved. +# $COPYRIGHT$ +# +# Additional copyrights may follow +# +# $HEADER$ +# + +headers += \ + base/base.h \ + base/threads_base_null.h + +libmca_threads_la_SOURCES += \ + base/threads_base_open.c diff --git a/opal/mca/threads/base/base.h b/opal/mca/threads/base/base.h new file mode 100644 index 00000000000..5043a3d66b2 --- /dev/null +++ b/opal/mca/threads/base/base.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana + * University Research and Technology + * Corporation. All rights reserved. + * Copyright (c) 2004-2014 The University of Tennessee and The University + * of Tennessee Research Foundation. All rights + * reserved. + * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, + * University of Stuttgart. All rights reserved. + * Copyright (c) 2004-2005 The Regents of the University of California. + * All rights reserved. + * Copyright (c) 2014 Cisco Systems, Inc. All rights reserved. + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + * + */ + +#ifndef OPAL_THREADS_BASE_H +#define OPAL_THREADS_BASE_H + +#include "opal_config.h" +#include "opal/mca/base/mca_base_framework.h" +#include "opal/mca/threads/threads.h" + + +/* + * Global functions for MCA overall threads open and close + */ + +BEGIN_C_DECLS + +/** + * Framework structure declaration + */ +OPAL_DECLSPEC extern mca_base_framework_t opal_threads_base_framework; + +END_C_DECLS + +/* include implementation to call */ +#include MCA_threads_IMPLEMENTATION_HEADER + +#endif /* OPAL_BASE_THREADS_H */ diff --git a/opal/mca/threads/base/owner.txt b/opal/mca/threads/base/owner.txt new file mode 100644 index 00000000000..340dd610b4f --- /dev/null +++ b/opal/mca/threads/base/owner.txt @@ -0,0 +1,7 @@ +# +# owner/status file +# owner: institution that is responsible for this package +# status: e.g. active, maintenance, unmaintained +# +owner: SNL +status: maintenance diff --git a/opal/mca/threads/base/threads_base_null.h b/opal/mca/threads/base/threads_base_null.h new file mode 100644 index 00000000000..2731787a3f3 --- /dev/null +++ b/opal/mca/threads/base/threads_base_null.h @@ -0,0 +1,47 @@ +/* + * 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. + * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, + * University of Stuttgart. All rights reserved. + * Copyright (c) 2004-2005 The Regents of the University of California. + * All rights reserved. + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + +#ifndef OPAL_MCA_TIMER_BASE_TIMER_BASE_NULL_H +#define OPAL_MCA_TIMER_BASE_TIMER_BASE_NULL_H + +int opal_condition_t_class; +int opal_mutex_t_class; +int opal_recursive_mutex_t_class; + +int opal_thread_join(opal_thread_t *t, void **thr_return) { + return 0; +} + +void opal_thread_set_main() { + return 0; +} +int opal_thread_start(opal_thread_t *t) { + return 0; +} +int *opal_thread_t_class = NULL; + +int opal_tsd_key_create(opal_tsd_key_t *key, opal_tsd_destructor_t destructor) +{ + return 0; +} +int opal_uses_threads = 0; +int opal_tsd_keys_destruct() +{ + return 0; +} +#endif diff --git a/opal/mca/threads/base/threads_base_open.c b/opal/mca/threads/base/threads_base_open.c new file mode 100644 index 00000000000..33502790133 --- /dev/null +++ b/opal/mca/threads/base/threads_base_open.c @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana + * University Research and Technology + * Corporation. All rights reserved. + * Copyright (c) 2004-2014 The University of Tennessee and The University + * of Tennessee Research Foundation. All rights + * reserved. + * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, + * University of Stuttgart. All rights reserved. + * Copyright (c) 2004-2005 The Regents of the University of California. + * All rights reserved. + * Copyright (c) 2014 Cisco Systems, Inc. All rights reserved. + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + + +#include "opal_config.h" + +#include "opal/constants.h" +#include "opal/mca/threads/base/base.h" + + +/* + * The following file was created by configure. It contains extern + * statements and the definition of an array of pointers to each + * component's public mca_base_component_t struct. + */ +#include "opal/mca/threads/base/static-components.h" + +static int mca_threads_base_register(mca_base_register_flag_t flags) +{ + // Do I need to register anything here? + return OPAL_SUCCESS; +} + +/* + * Globals + */ +/* Use default register/open/close functions */ +MCA_BASE_FRAMEWORK_DECLARE(opal, threads, "OPAL OS threads", mca_threads_base_register, NULL, NULL, + mca_threads_base_static_components, 0); diff --git a/opal/mca/threads/condition.h b/opal/mca/threads/condition.h new file mode 100644 index 00000000000..b054b011e45 --- /dev/null +++ b/opal/mca/threads/condition.h @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2004-2007 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. + * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, + * University of Stuttgart. All rights reserved. + * Copyright (c) 2004-2005 The Regents of the University of California. + * All rights reserved. + * Copyright (c) 2007 Los Alamos National Security, LLC. All rights + * reserved. + * Copyright (c) 2015 Research Organization for Information Science + * and Technology (RIST). All rights reserved. + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ +#ifndef OPAL_MCA_CONDITION_SPINLOCK_H +#define OPAL_MCA_CONDITION_SPINLOCK_H + +#include "opal_config.h" +#ifdef HAVE_SYS_TIME_H +#include +#endif +#include +#include + +#include "opal/threads/mutex.h" +#include "opal/runtime/opal_progress.h" + +#include "opal/runtime/opal_cr.h" + +BEGIN_C_DECLS + +/* + * Combine pthread support w/ polled progress to allow run-time selection + * of threading vs. non-threading progress. + */ + +struct opal_condition_t { + opal_object_t super; + volatile int c_waiting; + volatile int c_signaled; +}; +typedef struct opal_condition_t opal_condition_t; + +OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_condition_t); + + +static inline int opal_condition_wait(opal_condition_t *c, opal_mutex_t *m) +{ + int rc = 0; + c->c_waiting++; + + if (opal_using_threads()) { + if (c->c_signaled) { + c->c_waiting--; + opal_mutex_unlock(m); + opal_progress(); + OPAL_CR_TEST_CHECKPOINT_READY_STALL(); + opal_mutex_lock(m); + return 0; + } + while (c->c_signaled == 0) { + opal_mutex_unlock(m); + opal_progress(); + OPAL_CR_TEST_CHECKPOINT_READY_STALL(); + opal_mutex_lock(m); + } + } else { + while (c->c_signaled == 0) { + opal_progress(); + OPAL_CR_TEST_CHECKPOINT_READY_STALL(); + } + } + + c->c_signaled--; + c->c_waiting--; + return rc; +} + +static inline int opal_condition_timedwait(opal_condition_t *c, + opal_mutex_t *m, + const struct timespec *abstime) +{ + struct timeval tv; + struct timeval absolute; + int rc = 0; + + c->c_waiting++; + if (opal_using_threads()) { + absolute.tv_sec = abstime->tv_sec; + absolute.tv_usec = abstime->tv_nsec / 1000; + gettimeofday(&tv,NULL); + if (c->c_signaled == 0) { + do { + opal_mutex_unlock(m); + opal_progress(); + gettimeofday(&tv,NULL); + opal_mutex_lock(m); + } while (c->c_signaled == 0 && + (tv.tv_sec <= absolute.tv_sec || + (tv.tv_sec == absolute.tv_sec && tv.tv_usec < absolute.tv_usec))); + } + } else { + absolute.tv_sec = abstime->tv_sec; + absolute.tv_usec = abstime->tv_nsec / 1000; + gettimeofday(&tv,NULL); + if (c->c_signaled == 0) { + do { + opal_progress(); + gettimeofday(&tv,NULL); + } while (c->c_signaled == 0 && + (tv.tv_sec <= absolute.tv_sec || + (tv.tv_sec == absolute.tv_sec && tv.tv_usec < absolute.tv_usec))); + } + } + + if (c->c_signaled != 0) c->c_signaled--; + c->c_waiting--; + return rc; +} + +static inline int opal_condition_signal(opal_condition_t *c) +{ + if (c->c_waiting) { + c->c_signaled++; + } + return 0; +} + +static inline int opal_condition_broadcast(opal_condition_t *c) +{ + c->c_signaled = c->c_waiting; + return 0; +} + +END_C_DECLS + +#endif // OPAL_MCA_CONDITION_SPINLOCK_H + diff --git a/opal/mca/threads/configure.m4 b/opal/mca/threads/configure.m4 new file mode 100644 index 00000000000..14911994c8b --- /dev/null +++ b/opal/mca/threads/configure.m4 @@ -0,0 +1,55 @@ +dnl -*- shell-script -*- +dnl +dnl Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana +dnl University Research and Technology +dnl Corporation. All rights reserved. +dnl Copyright (c) 2004-2005 The University of Tennessee and The University +dnl of Tennessee Research Foundation. All rights +dnl reserved. +dnl Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, +dnl University of Stuttgart. All rights reserved. +dnl Copyright (c) 2004-2005 The Regents of the University of California. +dnl All rights reserved. +dnl Copyright (c) 2010 Cisco Systems, Inc. All rights reserved. +dnl $COPYRIGHT$ +dnl +dnl Additional copyrights may follow +dnl +dnl $HEADER$ +dnl + +dnl we only want one :) +m4_define(MCA_opal_threads_CONFIGURE_MODE, STOP_AT_FIRST) + +AC_DEFINE_UNQUOTED([OPAL_ENABLE_MULTI_THREADS], [1], + [Whether we should enable thread support within the OPAL code base]) +AC_DEFUN([MCA_opal_threads_CONFIG],[ + threads_base_include= + + # All components look at this value + AC_ARG_WITH([threads], + [AC_HELP_STRING([--with-threads=TYPE], + [Build high resolution threads component TYPE])]) + + # first, compile all the components + MCA_CONFIGURE_FRAMEWORK($1, $2, 1) + + # someone should have set this... + if test "$threads_base_include" = "" ; then + threads_base_include="base/threads_base_null.h" + fi + + if test "$mutex_base_include" = "" ; then +# mutex_base_include="base/mutex_base_null.h" + mutex_base_include="pthreads/mutex_unix.h" + fi + AC_DEFINE_UNQUOTED([MCA_threads_IMPLEMENTATION_HEADER], + ["opal/mca/threads/$threads_base_include"], + [Header to include for threads implementation]) + + AC_DEFINE_UNQUOTED([MCA_mutex_IMPLEMENTATION_HEADER], + ["opal/mca/threads/$mutex_base_include"], + [Header to include for mutex implementation]) +]) + + diff --git a/opal/mca/threads/mutex.h b/opal/mca/threads/mutex.h new file mode 100644 index 00000000000..4d8401674a7 --- /dev/null +++ b/opal/mca/threads/mutex.h @@ -0,0 +1,196 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ +/* + * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana + * University Research and Technology + * Corporation. All rights reserved. + * Copyright (c) 2004-2016 The University of Tennessee and The University + * of Tennessee Research Foundation. All rights + * reserved. + * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, + * University of Stuttgart. All rights reserved. + * Copyright (c) 2004-2005 The Regents of the University of California. + * All rights reserved. + * Copyright (c) 2007 Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2007-2016 Los Alamos National Security, LLC. All rights + * reserved. + * Copyright (c) 2007 Voltaire. All rights reserved. + * Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved. + * + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + +#ifndef OPAL_MCA_MUTEX_H +#define OPAL_MCA_MUTEX_H 1 + +#include "opal_config.h" + +#include MCA_mutex_IMPLEMENTATION_HEADER + +BEGIN_C_DECLS + +/** + * @file: + * + * Mutual exclusion functions. + * + * Functions for locking of critical sections. + */ + +/** + * Opaque mutex object + */ +typedef struct opal_mutex_t opal_mutex_t; +typedef struct opal_mutex_t opal_recursive_mutex_t; + +OBJ_CLASS_DECLARATION(opal_mutex_t); +OBJ_CLASS_DECLARATION(opal_recursive_mutex_t); + + +/** + * Try to acquire a mutex. + * + * @param mutex Address of the mutex. + * @return 0 if the mutex was acquired, 1 otherwise. + */ +static inline int opal_mutex_trylock(opal_mutex_t *mutex); + + +/** + * Acquire a mutex. + * + * @param mutex Address of the mutex. + */ +static inline void opal_mutex_lock(opal_mutex_t *mutex); + + +/** + * Release a mutex. + * + * @param mutex Address of the mutex. + */ +static inline void opal_mutex_unlock(opal_mutex_t *mutex); + + +/** + * Try to acquire a mutex using atomic operations. + * + * @param mutex Address of the mutex. + * @return 0 if the mutex was acquired, 1 otherwise. + */ +static inline int opal_mutex_atomic_trylock(opal_mutex_t *mutex); + + +/** + * Acquire a mutex using atomic operations. + * + * @param mutex Address of the mutex. + */ +static inline void opal_mutex_atomic_lock(opal_mutex_t *mutex); + + +/** + * Release a mutex using atomic operations. + * + * @param mutex Address of the mutex. + */ +static inline void opal_mutex_atomic_unlock(opal_mutex_t *mutex); + +END_C_DECLS + +#include MCA_mutex_IMPLEMENTATION_HEADER + +BEGIN_C_DECLS + +/** + * Lock a mutex if opal_using_threads() says that multiple threads may + * be active in the process. + * + * @param mutex Pointer to a opal_mutex_t to lock. + * + * If there is a possibility that multiple threads are running in the + * process (as determined by opal_using_threads()), this function will + * block waiting to lock the mutex. + * + * If there is no possibility that multiple threads are running in the + * process, return immediately. + */ +#define OPAL_THREAD_LOCK(mutex) \ + do { \ + if (OPAL_UNLIKELY(opal_using_threads())) { \ + opal_mutex_lock(mutex); \ + } \ + } while (0) + + +/** + * Try to lock a mutex if opal_using_threads() says that multiple + * threads may be active in the process. + * + * @param mutex Pointer to a opal_mutex_t to trylock + * + * If there is a possibility that multiple threads are running in the + * process (as determined by opal_using_threads()), this function will + * trylock the mutex. + * + * If there is no possibility that multiple threads are running in the + * process, return immediately without modifying the mutex. + * + * Returns 0 if mutex was locked, non-zero otherwise. + */ +#define OPAL_THREAD_TRYLOCK(mutex) \ + (OPAL_UNLIKELY(opal_using_threads()) ? opal_mutex_trylock(mutex) : 0) + +/** + * Unlock a mutex if opal_using_threads() says that multiple threads + * may be active in the process. + * + * @param mutex Pointer to a opal_mutex_t to unlock. + * + * If there is a possibility that multiple threads are running in the + * process (as determined by opal_using_threads()), this function will + * unlock the mutex. + * + * If there is no possibility that multiple threads are running in the + * process, return immediately without modifying the mutex. + */ +#define OPAL_THREAD_UNLOCK(mutex) \ + do { \ + if (OPAL_UNLIKELY(opal_using_threads())) { \ + opal_mutex_unlock(mutex); \ + } \ + } while (0) + + +/** + * Lock a mutex if opal_using_threads() says that multiple threads may + * be active in the process for the duration of the specified action. + * + * @param mutex Pointer to a opal_mutex_t to lock. + * @param action A scope over which the lock is held. + * + * If there is a possibility that multiple threads are running in the + * process (as determined by opal_using_threads()), this function will + * acquire the lock before invoking the specified action and release + * it on return. + * + * If there is no possibility that multiple threads are running in the + * process, invoke the action without acquiring the lock. + */ +#define OPAL_THREAD_SCOPED_LOCK(mutex, action) \ + do { \ + if(OPAL_UNLIKELY(opal_using_threads())) { \ + opal_mutex_lock(mutex); \ + action; \ + opal_mutex_unlock(mutex); \ + } else { \ + action; \ + } \ + } while (0) + +END_C_DECLS + +#endif /* OPAL_MCA_MUTEX_H */ diff --git a/opal/mca/threads/pthreads/Makefile.am b/opal/mca/threads/pthreads/Makefile.am new file mode 100644 index 00000000000..41d7fb90e72 --- /dev/null +++ b/opal/mca/threads/pthreads/Makefile.am @@ -0,0 +1,28 @@ +# +# 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. +# Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, +# University of Stuttgart. All rights reserved. +# Copyright (c) 2004-2005 The Regents of the University of California. +# All rights reserved. +# Copyright (c) 2008 Cisco Systems, Inc. All rights reserved. +# $COPYRIGHT$ +# +# Additional copyrights may follow +# +# $HEADER$ +# + +noinst_LTLIBRARIES = libmca_threads_pthreads.la + +libmca_threads_pthreads_la_SOURCES = \ + threads_pthreads.h \ + threads_pthreads_component.c \ + threads_pthreads_mutex.c \ + threads_pthreads_condition.c \ + threads_pthreads_wait_sync.c \ + threads_pthreads_module.c diff --git a/opal/mca/threads/pthreads/configure.m4 b/opal/mca/threads/pthreads/configure.m4 new file mode 100644 index 00000000000..2fc3f4a1883 --- /dev/null +++ b/opal/mca/threads/pthreads/configure.m4 @@ -0,0 +1,65 @@ +# -*- shell-script -*- +# +# 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. +# Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, +# University of Stuttgart. All rights reserved. +# Copyright (c) 2004-2005 The Regents of the University of California. +# All rights reserved. +# Copyright (c) 2010 Cisco Systems, Inc. All rights reserved. +# Copyright (c) 2015 Research Organization for Information Science +# and Technology (RIST). All rights reserved. +# $COPYRIGHT$ +# +# Additional copyrights may follow +# +# $HEADER$ +# +AC_DEFUN([MCA_opal_threads_pthreads_PRIORITY], [30]) + +AC_DEFUN([MCA_opal_threads_pthreads_COMPILE_MODE], [ + AC_MSG_CHECKING([for MCA component $2:$3 compile mode]) + $4="static" + AC_MSG_RESULT([$$4]) +]) + +AC_DEFUN([MCA_opal_threads_pthreads_POST_CONFIG],[ + AS_IF([test "$1" = "1"], [threads_base_include="pthreads/threads_pthreads.h"]) +])dnl + +AC_DEFUN([MCA_opal_mutex_pthreads_POST_CONFIG],[ + AS_IF([test "$1" = "1"], [mutex_base_include="pthreads/mutex_unix.h"]) +])dnl + +# MCA_threads_pthreads_CONFIG(action-if-can-compile, +# [action-if-cant-compile]) +# ------------------------------------------------ +AC_DEFUN([MCA_opal_threads_pthreads_CONFIG],[ + AC_CONFIG_FILES([opal/mca/threads/pthreads/Makefile]) + + AS_IF([test "$with_threads" = "pthreads"], + [threads_pthreads_happy="yes" + threads_pthreads_should_use=1], + [threads_pthreads_should_use=0 + AS_IF([test "$with_threads" = ""], + [threads_pthreads_happy="yes"], + [threads_pthreads_happy="no"])]) + + AS_IF([test "$threads_pthreads_happy" = "yes"], + [AC_CHECK_HEADERS([mach/mach_time.h]) + AC_CHECK_FUNC([mach_absolute_time], + [threads_pthreads_happy="yes"], + [threads_pthreads_happy="no"])]) + + AS_IF([test "$threads_pthreads_happy" = "no" && \ + test "$threads_pthreads_should_use" = "1"], + [AC_MSG_ERROR([pthreads threads requested but not available. Aborting.])]) + + AS_IF([test "$threads_pthreads_happy" = "yes"], + [$1], + [$2]) +]) diff --git a/opal/threads/mutex_unix.h b/opal/mca/threads/pthreads/mutex_unix.h similarity index 91% rename from opal/threads/mutex_unix.h rename to opal/mca/threads/pthreads/mutex_unix.h index 1cafdedd4e1..56802473590 100644 --- a/opal/threads/mutex_unix.h +++ b/opal/mca/threads/pthreads/mutex_unix.h @@ -116,7 +116,7 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_recursive_mutex_t); * ************************************************************************/ -static inline int opal_mutex_trylock(opal_mutex_t *m) +static inline int opal_mutex_trylock(struct opal_mutex_t *m) { #if OPAL_ENABLE_DEBUG int ret = pthread_mutex_trylock(&m->m_lock_pthread); @@ -131,7 +131,7 @@ static inline int opal_mutex_trylock(opal_mutex_t *m) #endif } -static inline void opal_mutex_lock(opal_mutex_t *m) +static inline void opal_mutex_lock(struct opal_mutex_t *m) { #if OPAL_ENABLE_DEBUG int ret = pthread_mutex_lock(&m->m_lock_pthread); @@ -145,7 +145,7 @@ static inline void opal_mutex_lock(opal_mutex_t *m) #endif } -static inline void opal_mutex_unlock(opal_mutex_t *m) +static inline void opal_mutex_unlock(struct opal_mutex_t *m) { #if OPAL_ENABLE_DEBUG int ret = pthread_mutex_unlock(&m->m_lock_pthread); @@ -171,17 +171,17 @@ static inline void opal_mutex_unlock(opal_mutex_t *m) * Spin Locks ************************************************************************/ -static inline int opal_mutex_atomic_trylock(opal_mutex_t *m) +static inline int opal_mutex_atomic_trylock(struct opal_mutex_t *m) { return opal_atomic_trylock(&m->m_lock_atomic); } -static inline void opal_mutex_atomic_lock(opal_mutex_t *m) +static inline void opal_mutex_atomic_lock(struct opal_mutex_t *m) { opal_atomic_lock(&m->m_lock_atomic); } -static inline void opal_mutex_atomic_unlock(opal_mutex_t *m) +static inline void opal_mutex_atomic_unlock(struct opal_mutex_t *m) { opal_atomic_unlock(&m->m_lock_atomic); } @@ -192,17 +192,17 @@ static inline void opal_mutex_atomic_unlock(opal_mutex_t *m) * Standard locking ************************************************************************/ -static inline int opal_mutex_atomic_trylock(opal_mutex_t *m) +static inline int opal_mutex_atomic_trylock(struct opal_mutex_t *m) { return opal_mutex_trylock(m); } -static inline void opal_mutex_atomic_lock(opal_mutex_t *m) +static inline void opal_mutex_atomic_lock(struct opal_mutex_t *m) { opal_mutex_lock(m); } -static inline void opal_mutex_atomic_unlock(opal_mutex_t *m) +static inline void opal_mutex_atomic_unlock(struct opal_mutex_t *m) { opal_mutex_unlock(m); } diff --git a/opal/mca/threads/pthreads/owner.txt b/opal/mca/threads/pthreads/owner.txt new file mode 100644 index 00000000000..199577ac8cf --- /dev/null +++ b/opal/mca/threads/pthreads/owner.txt @@ -0,0 +1,7 @@ +# +# owner/status file +# owner: institution that is responsible for this package +# status: e.g. active, maintenance, unmaintained +# +owner: SNL +status: unmaintained diff --git a/opal/mca/threads/pthreads/threads_base_null.h b/opal/mca/threads/pthreads/threads_base_null.h new file mode 100644 index 00000000000..8c662351281 --- /dev/null +++ b/opal/mca/threads/pthreads/threads_base_null.h @@ -0,0 +1,62 @@ +/* + * 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. + * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, + * University of Stuttgart. All rights reserved. + * Copyright (c) 2004-2005 The Regents of the University of California. + * All rights reserved. + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + +#ifndef OPAL_MCA_TIMER_BASE_TIMER_BASE_NULL_H +#define OPAL_MCA_TIMER_BASE_TIMER_BASE_NULL_H + +opal_class_t opal_condition_t_class; +opal_class_t opal_mutex_t_class; +opal_class_t opal_recursive_mutex_t_class; + +opal_thread_t *opal_thread_get_self(void) { + return NULL; +} + +bool opal_thread_self_compare(opal_thread_t *t) { + return 0; +} + +int sync_wait_mt(void *p) { + return 0; +} + +int opal_thread_join(opal_thread_t *t, void **thr_return) { + return 0; +} + +void opal_thread_set_main() { +} + +int opal_thread_start(opal_thread_t *t) { + return 0; +} +opal_class_t opal_thread_t_class; + +typedef int opal_tsd_key_t; +typedef int opal_tsd_destructor_t; + +int opal_tsd_key_create(opal_tsd_key_t *key, opal_tsd_destructor_t destructor) +{ + return 0; +} +bool opal_uses_threads = 0; +int opal_tsd_keys_destruct() +{ + return 0; +} +#endif diff --git a/opal/mca/threads/pthreads/threads_pthreads.h b/opal/mca/threads/pthreads/threads_pthreads.h new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/opal/mca/threads/pthreads/threads_pthreads.h @@ -0,0 +1 @@ + diff --git a/opal/mca/threads/pthreads/threads_pthreads_component.c b/opal/mca/threads/pthreads/threads_pthreads_component.c new file mode 100644 index 00000000000..2441a74a228 --- /dev/null +++ b/opal/mca/threads/pthreads/threads_pthreads_component.c @@ -0,0 +1,53 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ +/* + * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana + * University Research and Technology + * Corporation. All rights reserved. + * Copyright (c) 2004-2014 The University of Tennessee and The University + * of Tennessee Research Foundation. All rights + * reserved. + * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, + * University of Stuttgart. All rights reserved. + * Copyright (c) 2004-2005 The Regents of the University of California. + * All rights reserved. + * Copyright (c) 2007-2015 Los Alamos National Security, LLC. All rights + * reserved. + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + +#include "opal_config.h" + +#include "opal/mca/threads/thread.h" +#include "opal/mca/threads/threads.h" +#include "opal/mca/threads/pthreads/threads_pthreads.h" +#include "opal/constants.h" + +static int opal_threads_pthreads_open(void); + +const opal_threads_base_component_2_0_0_t mca_threads_pthreads_component = { + /* First, the mca_component_t struct containing meta information + about the component itself */ + .threadsc_version = { + OPAL_THREADS_BASE_VERSION_2_0_0, + + /* Component name and version */ + .mca_component_name = "pthreads", + MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, + OPAL_RELEASE_VERSION), + + .mca_open_component = opal_threads_pthreads_open, + }, + .threadsc_data = { + /* The component is checkpoint ready */ + MCA_BASE_METADATA_PARAM_CHECKPOINT + }, +}; + +int opal_threads_pthreads_open(void) +{ + return OPAL_SUCCESS; +} diff --git a/opal/threads/condition.c b/opal/mca/threads/pthreads/threads_pthreads_condition.c similarity index 96% rename from opal/threads/condition.c rename to opal/mca/threads/pthreads/threads_pthreads_condition.c index 7745d316544..bdc8a67f214 100644 --- a/opal/threads/condition.c +++ b/opal/mca/threads/pthreads/threads_pthreads_condition.c @@ -18,7 +18,7 @@ #include "opal_config.h" -#include "opal/threads/condition.h" +#include "opal/mca/threads/condition.h" static void opal_condition_construct(opal_condition_t *c) diff --git a/opal/threads/thread.c b/opal/mca/threads/pthreads/threads_pthreads_module.c similarity index 80% rename from opal/threads/thread.c rename to opal/mca/threads/pthreads/threads_pthreads_module.c index 2d67fa2d693..60d88a0191e 100644 --- a/opal/threads/thread.c +++ b/opal/mca/threads/pthreads/threads_pthreads_module.c @@ -9,41 +9,30 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. - * Copyright (c) 2010 Cisco Systems, Inc. All rights reserved. - * Copyright (c) 2015-2017 Research Organization for Information Science - * and Technology (RIST). All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow * * $HEADER$ */ +#include -#include "opal_config.h" - -#include "opal/threads/threads.h" -#include "opal/threads/tsd.h" #include "opal/constants.h" - -bool opal_debug_threads = false; - -static void opal_thread_construct(opal_thread_t *t); - -static pthread_t opal_main_thread; +#include "opal/util/sys_limits.h" +#include "opal/util/output.h" +#include "opal/prefetch.h" +#include "opal/mca/threads/threads.h" +#include "opal/mca/threads/tsd.h" struct opal_tsd_key_value { opal_tsd_key_t key; opal_tsd_destructor_t destructor; }; -static struct opal_tsd_key_value *opal_tsd_key_values = NULL; +static pthread_t opal_main_thread; +struct opal_tsd_key_value *opal_tsd_key_values = NULL; static int opal_tsd_key_values_count = 0; -OBJ_CLASS_INSTANCE(opal_thread_t, - opal_object_t, - opal_thread_construct, NULL); - - /* * Constructor */ @@ -53,50 +42,55 @@ static void opal_thread_construct(opal_thread_t *t) t->t_handle = (pthread_t) -1; } -int opal_thread_start(opal_thread_t *t) -{ - int rc; +OBJ_CLASS_INSTANCE(opal_thread_t, + opal_object_t, + opal_thread_construct, NULL); + - if (OPAL_ENABLE_DEBUG) { - if (NULL == t->t_run || t->t_handle != (pthread_t) -1) { - return OPAL_ERR_BAD_PARAM; - } - } - rc = pthread_create(&t->t_handle, NULL, (void*(*)(void*)) t->t_run, t); +opal_thread_t *opal_thread_get_self(void) +{ + opal_thread_t *t = OBJ_NEW(opal_thread_t); + t->t_handle = pthread_self(); + return t; +} - return (rc == 0) ? OPAL_SUCCESS : OPAL_ERROR; +bool opal_thread_self_compare(opal_thread_t *t) +{ + return t->t_handle == pthread_self(); } +int sync_wait_mt(void *p) { + return 0; +} -int opal_thread_join(opal_thread_t *t, void **thr_return) -{ +int opal_thread_join(opal_thread_t *t, void **thr_return) { int rc = pthread_join(t->t_handle, thr_return); t->t_handle = (pthread_t) -1; return (rc == 0) ? OPAL_SUCCESS : OPAL_ERROR; } - -bool opal_thread_self_compare(opal_thread_t *t) -{ - return t->t_handle == pthread_self(); +void opal_thread_set_main() { + opal_main_thread = pthread_self(); } +int opal_thread_start(opal_thread_t *t) { + int rc; -opal_thread_t *opal_thread_get_self(void) -{ - opal_thread_t *t = OBJ_NEW(opal_thread_t); - t->t_handle = pthread_self(); - return t; -} + if (OPAL_ENABLE_DEBUG) { + if (NULL == t->t_run || t->t_handle != (pthread_t) -1) { + return OPAL_ERR_BAD_PARAM; + } + } -void opal_thread_kill(opal_thread_t *t, int sig) -{ - pthread_kill(t->t_handle, sig); + rc = pthread_create(&t->t_handle, NULL, (void*(*)(void*)) t->t_run, t); + + return (rc == 0) ? OPAL_SUCCESS : OPAL_ERROR; } -int opal_tsd_key_create(opal_tsd_key_t *key, - opal_tsd_destructor_t destructor) +opal_class_t opal_thread_t_class; + +int opal_tsd_key_create(opal_tsd_key_t *key, opal_tsd_destructor_t destructor) { int rc; rc = pthread_key_create(key, destructor); @@ -128,6 +122,6 @@ int opal_tsd_keys_destruct() return OPAL_SUCCESS; } -void opal_thread_set_main() { - opal_main_thread = pthread_self(); +void opal_event_use_threads(void) { + evthread_use_pthreads(); } diff --git a/opal/mca/threads/pthreads/threads_pthreads_mutex.c b/opal/mca/threads/pthreads/threads_pthreads_mutex.c new file mode 100644 index 00000000000..68e26383256 --- /dev/null +++ b/opal/mca/threads/pthreads/threads_pthreads_mutex.c @@ -0,0 +1,63 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ +/* + * 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. + * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, + * University of Stuttgart. All rights reserved. + * Copyright (c) 2004-2005 The Regents of the University of California. + * All rights reserved. + * Copyright (c) 2007-2016 Los Alamos National Security, LLC. All rights + * reserved. + * Copyright (c) 2015 Research Organization for Information Science + * and Technology (RIST). All rights reserved. + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + +#include "opal_config.h" + +#include +#include + +#include "opal/mca/threads/mutex.h" +//#include "opal/mca/threads/pthreads/mutex_unix.h" + + +OBJ_CLASS_INSTANCE(opal_mutex_t, + opal_object_t, + NULL, + NULL); +OBJ_CLASS_INSTANCE(opal_recursive_mutex_t, + opal_object_t, + NULL, + NULL); + +/* + * Wait and see if some upper layer wants to use threads, if support + * exists. + */ +bool opal_uses_threads = false; + +struct opal_pthread_mutex_t { + opal_object_t super; + + pthread_mutex_t m_lock_pthread; + +#if OPAL_ENABLE_DEBUG + int m_lock_debug; + const char *m_lock_file; + int m_lock_line; +#endif + + opal_atomic_lock_t m_lock_atomic; +}; +typedef struct opal_pthread_mutex_t opal_pthread_mutex_t; +typedef struct opal_pthread_mutex_t opal_pthread_recursive_mutex_t; + diff --git a/opal/threads/wait_sync.c b/opal/mca/threads/pthreads/threads_pthreads_wait_sync.c similarity index 98% rename from opal/threads/wait_sync.c rename to opal/mca/threads/pthreads/threads_pthreads_wait_sync.c index 1f73f7c8ad4..8f128adab6c 100644 --- a/opal/threads/wait_sync.c +++ b/opal/mca/threads/pthreads/threads_pthreads_wait_sync.c @@ -12,7 +12,7 @@ * * $HEADER$ */ -#include "wait_sync.h" +#include "opal/mca/threads/wait_sync.h" static opal_mutex_t wait_sync_lock = OPAL_MUTEX_STATIC_INIT; static ompi_wait_sync_t* wait_sync_list = NULL; diff --git a/opal/mca/threads/qthreads/Makefile.am b/opal/mca/threads/qthreads/Makefile.am new file mode 100644 index 00000000000..d9a893a880f --- /dev/null +++ b/opal/mca/threads/qthreads/Makefile.am @@ -0,0 +1,27 @@ +# +# 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. +# Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, +# University of Stuttgart. All rights reserved. +# Copyright (c) 2004-2005 The Regents of the University of California. +# All rights reserved. +# Copyright (c) 2008 Cisco Systems, Inc. All rights reserved. +# $COPYRIGHT$ +# +# Additional copyrights may follow +# +# $HEADER$ +# + +noinst_LTLIBRARIES = libmca_threads_qthreads.la + +libmca_threads_qthreads_la_SOURCES = \ + threads_qthreads.h \ + threads_qthreads_component.c \ + threads_qthreads_mutex.c \ + threads_qthreads_condition.c \ + threads_qthreads_module.c diff --git a/opal/mca/threads/qthreads/configure.m4 b/opal/mca/threads/qthreads/configure.m4 new file mode 100644 index 00000000000..08ffca8ced2 --- /dev/null +++ b/opal/mca/threads/qthreads/configure.m4 @@ -0,0 +1,61 @@ +# -*- shell-script -*- +# +# 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. +# Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, +# University of Stuttgart. All rights reserved. +# Copyright (c) 2004-2005 The Regents of the University of California. +# All rights reserved. +# Copyright (c) 2010 Cisco Systems, Inc. All rights reserved. +# Copyright (c) 2015 Research Organization for Information Science +# and Technology (RIST). All rights reserved. +# $COPYRIGHT$ +# +# Additional copyrights may follow +# +# $HEADER$ +# +AC_DEFUN([MCA_opal_threads_qthreads_PRIORITY], [30]) + +AC_DEFUN([MCA_opal_threads_qthreads_COMPILE_MODE], [ + AC_MSG_CHECKING([for MCA component $2:$3 compile mode]) + $4="static" + AC_MSG_RESULT([$$4]) +]) + +AC_DEFUN([MCA_opal_threads_qthreads_POST_CONFIG],[ + AS_IF([test "$1" = "1"], [threads_base_include="qthreads/threads_qthreads.h"]) +])dnl + +# MCA_threads_qthreads_CONFIG(action-if-can-compile, +# [action-if-cant-compile]) +# ------------------------------------------------ +AC_DEFUN([MCA_opal_threads_qthreads_CONFIG],[ + AC_CONFIG_FILES([opal/mca/threads/qthreads/Makefile]) + + AS_IF([test "$with_threads" = "qthreads"], + [threads_qthreads_happy="yes" + threads_qthreads_should_use=1], + [threads_qthreads_should_use=0 + AS_IF([test "$with_threads" = ""], + [threads_qthreads_happy="yes"], + [threads_qthreads_happy="no"])]) + + AS_IF([test "$threads_qthreads_happy" = "yes"], + [AC_CHECK_HEADERS([mach/mach_time.h]) + AC_CHECK_FUNC([mach_absolute_time], + [threads_qthreads_happy="yes"], + [threads_qthreads_happy="no"])]) + + AS_IF([test "$threads_qthreads_happy" = "no" && \ + test "$threads_qthreads_should_use" = "1"], + [AC_MSG_ERROR([qthreads threads requested but not available. Aborting.])]) + + AS_IF([test "$threads_qthreads_happy" = "yes"], + [$1], + [$2]) +]) diff --git a/opal/mca/threads/qthreads/owner.txt b/opal/mca/threads/qthreads/owner.txt new file mode 100644 index 00000000000..199577ac8cf --- /dev/null +++ b/opal/mca/threads/qthreads/owner.txt @@ -0,0 +1,7 @@ +# +# owner/status file +# owner: institution that is responsible for this package +# status: e.g. active, maintenance, unmaintained +# +owner: SNL +status: unmaintained diff --git a/opal/mca/threads/qthreads/threads_base_null.h b/opal/mca/threads/qthreads/threads_base_null.h new file mode 100644 index 00000000000..8c662351281 --- /dev/null +++ b/opal/mca/threads/qthreads/threads_base_null.h @@ -0,0 +1,62 @@ +/* + * 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. + * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, + * University of Stuttgart. All rights reserved. + * Copyright (c) 2004-2005 The Regents of the University of California. + * All rights reserved. + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + +#ifndef OPAL_MCA_TIMER_BASE_TIMER_BASE_NULL_H +#define OPAL_MCA_TIMER_BASE_TIMER_BASE_NULL_H + +opal_class_t opal_condition_t_class; +opal_class_t opal_mutex_t_class; +opal_class_t opal_recursive_mutex_t_class; + +opal_thread_t *opal_thread_get_self(void) { + return NULL; +} + +bool opal_thread_self_compare(opal_thread_t *t) { + return 0; +} + +int sync_wait_mt(void *p) { + return 0; +} + +int opal_thread_join(opal_thread_t *t, void **thr_return) { + return 0; +} + +void opal_thread_set_main() { +} + +int opal_thread_start(opal_thread_t *t) { + return 0; +} +opal_class_t opal_thread_t_class; + +typedef int opal_tsd_key_t; +typedef int opal_tsd_destructor_t; + +int opal_tsd_key_create(opal_tsd_key_t *key, opal_tsd_destructor_t destructor) +{ + return 0; +} +bool opal_uses_threads = 0; +int opal_tsd_keys_destruct() +{ + return 0; +} +#endif diff --git a/opal/mca/threads/qthreads/threads_base_null.htmp b/opal/mca/threads/qthreads/threads_base_null.htmp new file mode 100644 index 00000000000..8c662351281 --- /dev/null +++ b/opal/mca/threads/qthreads/threads_base_null.htmp @@ -0,0 +1,62 @@ +/* + * 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. + * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, + * University of Stuttgart. All rights reserved. + * Copyright (c) 2004-2005 The Regents of the University of California. + * All rights reserved. + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + +#ifndef OPAL_MCA_TIMER_BASE_TIMER_BASE_NULL_H +#define OPAL_MCA_TIMER_BASE_TIMER_BASE_NULL_H + +opal_class_t opal_condition_t_class; +opal_class_t opal_mutex_t_class; +opal_class_t opal_recursive_mutex_t_class; + +opal_thread_t *opal_thread_get_self(void) { + return NULL; +} + +bool opal_thread_self_compare(opal_thread_t *t) { + return 0; +} + +int sync_wait_mt(void *p) { + return 0; +} + +int opal_thread_join(opal_thread_t *t, void **thr_return) { + return 0; +} + +void opal_thread_set_main() { +} + +int opal_thread_start(opal_thread_t *t) { + return 0; +} +opal_class_t opal_thread_t_class; + +typedef int opal_tsd_key_t; +typedef int opal_tsd_destructor_t; + +int opal_tsd_key_create(opal_tsd_key_t *key, opal_tsd_destructor_t destructor) +{ + return 0; +} +bool opal_uses_threads = 0; +int opal_tsd_keys_destruct() +{ + return 0; +} +#endif diff --git a/opal/mca/threads/qthreads/threads_qthreads.h b/opal/mca/threads/qthreads/threads_qthreads.h new file mode 100644 index 00000000000..f1ab4c81c0f --- /dev/null +++ b/opal/mca/threads/qthreads/threads_qthreads.h @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana + * University Research and Technology + * Corporation. All rights reserved. + * Copyright (c) 2004-2014 The University of Tennessee and The University + * of Tennessee Research Foundation. All rights + * reserved. + * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, + * University of Stuttgart. All rights reserved. + * Copyright (c) 2004-2005 The Regents of the University of California. + * All rights reserved. + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + +#ifndef OPAL_MCA_TIMER_DARWIN_TIMER_DARWIN_H +#define OPAL_MCA_TIMER_DARWIN_TIMER_DARWIN_H + +#include "opal_config.h" +#include + +typedef uint64_t opal_threadss_t; + +/* frequency in mhz */ +OPAL_DECLSPEC extern opal_threadss_t opal_threadss_darwin_freq; +OPAL_DECLSPEC extern mach_timebase_info_data_t opal_threadss_darwin_info; +OPAL_DECLSPEC extern opal_threadss_t opal_threadss_darwin_bias; + +/** + * Use the pragmatic solution proposed at + * http://stackoverflow.com/questions/23378063/how-can-i-use-mach-absolute-time-without-overflowing/23378064#23378064 + */ +static inline opal_threadss_t +opal_threadss_base_get_cycles(void) +{ + uint64_t now = mach_absolute_time(); + + if( opal_threadss_darwin_info.denom == 0 ) { + (void)mach_timebase_info(&opal_threadss_darwin_info); + if( opal_threadss_darwin_info.denom > 1024 ) { + double frac = (double)opal_threadss_darwin_info.numer/opal_threadss_darwin_info.denom; + opal_threadss_darwin_info.denom = 1024; + opal_threadss_darwin_info.numer = opal_threadss_darwin_info.denom * frac + 0.5; + } + opal_threadss_darwin_bias = now; + } + /* this is basically a wrapper around the "right" assembly to convert + the tick counter off the PowerPC Time Base into nanos. */ + return (now - opal_threadss_darwin_bias) * opal_threadss_darwin_info.numer / opal_threadss_darwin_info.denom; +} + + +static inline opal_threadss_t +opal_threadss_base_get_usec(void) +{ + /* freq is in Hz, so this gives usec */ + return opal_threadss_base_get_cycles() / 1000; +} + + +static inline opal_threadss_t +opal_threadss_base_get_freq(void) +{ + return opal_threadss_darwin_freq; +} + +typedef pthread_key_t opal_tsd_key_t; + +static inline int +opal_tsd_key_delete(opal_tsd_key_t key) +{ + return pthread_key_delete(key); +} + +static inline int +opal_tsd_setspecific(opal_tsd_key_t key, void *value) +{ + return pthread_setspecific(key, value); +} + +static inline int +opal_tsd_getspecific(opal_tsd_key_t key, void **valuep) +{ + *valuep = pthread_getspecific(key); + return OPAL_SUCCESS; +} + +#define OPAL_TIMER_CYCLE_NATIVE 0 +#define OPAL_TIMER_CYCLE_SUPPORTED 1 +#define OPAL_TIMER_USEC_NATIVE 1 +#define OPAL_TIMER_USEC_SUPPORTED 1 + +#endif diff --git a/opal/mca/threads/qthreads/threads_qthreads.htmp b/opal/mca/threads/qthreads/threads_qthreads.htmp new file mode 100644 index 00000000000..f1ab4c81c0f --- /dev/null +++ b/opal/mca/threads/qthreads/threads_qthreads.htmp @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana + * University Research and Technology + * Corporation. All rights reserved. + * Copyright (c) 2004-2014 The University of Tennessee and The University + * of Tennessee Research Foundation. All rights + * reserved. + * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, + * University of Stuttgart. All rights reserved. + * Copyright (c) 2004-2005 The Regents of the University of California. + * All rights reserved. + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + +#ifndef OPAL_MCA_TIMER_DARWIN_TIMER_DARWIN_H +#define OPAL_MCA_TIMER_DARWIN_TIMER_DARWIN_H + +#include "opal_config.h" +#include + +typedef uint64_t opal_threadss_t; + +/* frequency in mhz */ +OPAL_DECLSPEC extern opal_threadss_t opal_threadss_darwin_freq; +OPAL_DECLSPEC extern mach_timebase_info_data_t opal_threadss_darwin_info; +OPAL_DECLSPEC extern opal_threadss_t opal_threadss_darwin_bias; + +/** + * Use the pragmatic solution proposed at + * http://stackoverflow.com/questions/23378063/how-can-i-use-mach-absolute-time-without-overflowing/23378064#23378064 + */ +static inline opal_threadss_t +opal_threadss_base_get_cycles(void) +{ + uint64_t now = mach_absolute_time(); + + if( opal_threadss_darwin_info.denom == 0 ) { + (void)mach_timebase_info(&opal_threadss_darwin_info); + if( opal_threadss_darwin_info.denom > 1024 ) { + double frac = (double)opal_threadss_darwin_info.numer/opal_threadss_darwin_info.denom; + opal_threadss_darwin_info.denom = 1024; + opal_threadss_darwin_info.numer = opal_threadss_darwin_info.denom * frac + 0.5; + } + opal_threadss_darwin_bias = now; + } + /* this is basically a wrapper around the "right" assembly to convert + the tick counter off the PowerPC Time Base into nanos. */ + return (now - opal_threadss_darwin_bias) * opal_threadss_darwin_info.numer / opal_threadss_darwin_info.denom; +} + + +static inline opal_threadss_t +opal_threadss_base_get_usec(void) +{ + /* freq is in Hz, so this gives usec */ + return opal_threadss_base_get_cycles() / 1000; +} + + +static inline opal_threadss_t +opal_threadss_base_get_freq(void) +{ + return opal_threadss_darwin_freq; +} + +typedef pthread_key_t opal_tsd_key_t; + +static inline int +opal_tsd_key_delete(opal_tsd_key_t key) +{ + return pthread_key_delete(key); +} + +static inline int +opal_tsd_setspecific(opal_tsd_key_t key, void *value) +{ + return pthread_setspecific(key, value); +} + +static inline int +opal_tsd_getspecific(opal_tsd_key_t key, void **valuep) +{ + *valuep = pthread_getspecific(key); + return OPAL_SUCCESS; +} + +#define OPAL_TIMER_CYCLE_NATIVE 0 +#define OPAL_TIMER_CYCLE_SUPPORTED 1 +#define OPAL_TIMER_USEC_NATIVE 1 +#define OPAL_TIMER_USEC_SUPPORTED 1 + +#endif diff --git a/opal/mca/threads/qthreads/threads_qthreads_component.c b/opal/mca/threads/qthreads/threads_qthreads_component.c new file mode 100644 index 00000000000..aef0a009d1f --- /dev/null +++ b/opal/mca/threads/qthreads/threads_qthreads_component.c @@ -0,0 +1,53 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ +/* + * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana + * University Research and Technology + * Corporation. All rights reserved. + * Copyright (c) 2004-2014 The University of Tennessee and The University + * of Tennessee Research Foundation. All rights + * reserved. + * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, + * University of Stuttgart. All rights reserved. + * Copyright (c) 2004-2005 The Regents of the University of California. + * All rights reserved. + * Copyright (c) 2007-2015 Los Alamos National Security, LLC. All rights + * reserved. + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + +#include "opal_config.h" + +#include "opal/mca/threads/thread.h" +#include "opal/mca/threads/threads.h" +#include "opal/mca/threads/qthreads/threads_qthreads.h" +#include "opal/constants.h" + +static int opal_threads_qthreads_open(void); + +const opal_threads_base_component_2_0_0_t mca_threads_qthreads_component = { + /* First, the mca_component_t struct containing meta information + about the component itself */ + .threadsc_version = { + OPAL_THREADS_BASE_VERSION_2_0_0, + + /* Component name and version */ + .mca_component_name = "qthreads", + MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, + OPAL_RELEASE_VERSION), + + .mca_open_component = opal_threads_qthreads_open, + }, + .threadsc_data = { + /* The component is checkpoint ready */ + MCA_BASE_METADATA_PARAM_CHECKPOINT + }, +}; + +int opal_threads_qthreads_open(void) +{ + return OPAL_SUCCESS; +} diff --git a/opal/mca/threads/qthreads/threads_qthreads_condition.c b/opal/mca/threads/qthreads/threads_qthreads_condition.c new file mode 100644 index 00000000000..bdc8a67f214 --- /dev/null +++ b/opal/mca/threads/qthreads/threads_qthreads_condition.c @@ -0,0 +1,38 @@ +/* + * 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. + * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, + * University of Stuttgart. All rights reserved. + * Copyright (c) 2004-2005 The Regents of the University of California. + * All rights reserved. + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + +#include "opal_config.h" + +#include "opal/mca/threads/condition.h" + + +static void opal_condition_construct(opal_condition_t *c) +{ + c->c_waiting = 0; + c->c_signaled = 0; +} + + +static void opal_condition_destruct(opal_condition_t *c) +{ +} + +OBJ_CLASS_INSTANCE(opal_condition_t, + opal_object_t, + opal_condition_construct, + opal_condition_destruct); diff --git a/opal/mca/threads/qthreads/threads_qthreads_module.c b/opal/mca/threads/qthreads/threads_qthreads_module.c new file mode 100644 index 00000000000..554ef07a1b8 --- /dev/null +++ b/opal/mca/threads/qthreads/threads_qthreads_module.c @@ -0,0 +1,123 @@ +/* + * 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. + * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, + * University of Stuttgart. All rights reserved. + * Copyright (c) 2004-2005 The Regents of the University of California. + * All rights reserved. + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ +#include + +#include "opal/constants.h" +#include "opal/util/sys_limits.h" +#include "opal/util/output.h" +#include "opal/prefetch.h" +#include "opal/mca/threads/threads.h" +#include "opal/mca/threads/tsd.h" + +struct opal_tsd_key_value { + opal_tsd_key_t key; + opal_tsd_destructor_t destructor; +}; + +static pthread_t opal_main_thread; +struct opal_tsd_key_value *opal_tsd_key_values = NULL; +static int opal_tsd_key_values_count = 0; + +/* + * Constructor + */ +static void opal_thread_construct(opal_thread_t *t) +{ + t->t_run = 0; + t->t_handle = (pthread_t) -1; +} + +OBJ_CLASS_INSTANCE(opal_thread_t, + opal_object_t, + opal_thread_construct, NULL); + + + +opal_thread_t *opal_thread_get_self(void) +{ + opal_thread_t *t = OBJ_NEW(opal_thread_t); + t->t_handle = pthread_self(); + return t; +} + +bool opal_thread_self_compare(opal_thread_t *t) +{ + return t->t_handle == pthread_self(); +} + +int sync_wait_mt(void *p) { + return 0; +} + +int opal_thread_join(opal_thread_t *t, void **thr_return) { + int rc = pthread_join(t->t_handle, thr_return); + t->t_handle = (pthread_t) -1; + return (rc == 0) ? OPAL_SUCCESS : OPAL_ERROR; +} + +void opal_thread_set_main() { + opal_main_thread = pthread_self(); +} + +int opal_thread_start(opal_thread_t *t) { + int rc; + + if (OPAL_ENABLE_DEBUG) { + if (NULL == t->t_run || t->t_handle != (pthread_t) -1) { + return OPAL_ERR_BAD_PARAM; + } + } + + rc = pthread_create(&t->t_handle, NULL, (void*(*)(void*)) t->t_run, t); + + return (rc == 0) ? OPAL_SUCCESS : OPAL_ERROR; +} + +opal_class_t opal_thread_t_class; + +int opal_tsd_key_create(opal_tsd_key_t *key, opal_tsd_destructor_t destructor) +{ + int rc; + rc = pthread_key_create(key, destructor); + if ((0 == rc) && (pthread_self() == opal_main_thread)) { + opal_tsd_key_values = (struct opal_tsd_key_value *)realloc(opal_tsd_key_values, (opal_tsd_key_values_count+1) * sizeof(struct opal_tsd_key_value)); + opal_tsd_key_values[opal_tsd_key_values_count].key = *key; + opal_tsd_key_values[opal_tsd_key_values_count].destructor = destructor; + opal_tsd_key_values_count ++; + } + return rc; +} + +int opal_tsd_keys_destruct() +{ + int i; + void * ptr; + for (i=0; i + *
  • OPAL_THREADS_CYCLE_NATIVE
    Whether + * opal_threads_base_get_cycle() is implemented directly or computed + * from some other data (such as a high res threads)
  • + *
  • OPAL_THREADS_CYCLE_SUPPORTED
    Whether + * opal_threads_base_get_cycle() is supported on the current + * platform.
  • + *
  • OPAL_THREADS_USEC_SUPPORTED
    Whether + * opal_threads_base_get_usec() is supported on the current + * platform or implemented on top of gettimeofday(), which + * may be unsuitable for some uses. + * + * + * The cycle count may not be the cycle count of the CPU itself, if + * there is another sufficiently close counter with better behavior + * characteristics (like the Time Base counter on many Power/PowerPC + * platforms). The function opal_threads_base_get_freq() returns the + * frequency of the cycle counter in use, *NOT* the frequency of the + * main CPU. + * + * Unless otherwise noted, no attempt is made to cope with the the + * differences in counters on SMP machines. If your process switches + * CPUs, your threads results may change. + * + * Build time priorities are allocated as follows: + * + * - 0 gettimeofday() wrapper + * - 10 Assembly threadss with bad frequency search (Linux) + * - 20 NIC software stack (QSNet, Myrinet?) + * - 30 Operating systems with native interfaces + */ + +#ifndef OPAL_MCA_THREADS_THREADS_H +#define OPAL_MCA_THREADS_THREADS_H + +#include "opal_config.h" + +#include "opal/mca/mca.h" +#include "opal/mca/base/base.h" + + +/** + * Structure for threads components. + */ +struct opal_threads_base_component_2_0_0_t { + /** MCA base component */ + mca_base_component_t threadsc_version; + /** MCA base data */ + mca_base_component_data_t threadsc_data; +}; +/** + * Convenience typedef + */ +typedef struct opal_threads_base_component_2_0_0_t opal_threads_base_component_2_0_0_t; + +/* + * Macro for use in components that are of type threads + */ +#define OPAL_THREADS_BASE_VERSION_2_0_0 \ + OPAL_MCA_BASE_VERSION_2_1_0("threads", 2, 0, 0) + +#endif /* OPAL_MCA_THREADS_THREADS_H */ diff --git a/opal/mca/threads/thread_usage.h b/opal/mca/threads/thread_usage.h new file mode 100644 index 00000000000..2f8e8945b3d --- /dev/null +++ b/opal/mca/threads/thread_usage.h @@ -0,0 +1,192 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ +/* + * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana + * University Research and Technology + * Corporation. All rights reserved. + * Copyright (c) 2004-2007 The University of Tennessee and The University + * of Tennessee Research Foundation. All rights + * reserved. + * Copyright (c) 2004-2006 High Performance Computing Center Stuttgart, + * University of Stuttgart. All rights reserved. + * Copyright (c) 2004-2005 The Regents of the University of California. + * All rights reserved. + * Copyright (c) 2007-2014 Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2014-2016 Research Organization for Information Science + * and Technology (RIST). All rights reserved. + * Copyright (c) 2015-2016 Los Alamos National Security, LLC. All rights + * reserved. + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + +/* Should this go in mca/threads/base? */ +#if !defined(OPAL_MCA_THREAD_USAGE_H) +#define OPAL_MCA_THREAD_USAGE_H + +#include "opal_config.h" + +#include "opal/sys/atomic.h" +#include "opal/prefetch.h" + +OPAL_DECLSPEC extern bool opal_uses_threads; + +/** + * Check and see if the process is using multiple threads. + * + * @retval true If the process may have more than one thread. + * @retval false If the process only has a single thread. + * + * The value that this function returns is influenced by: + * + * - how MPI_INIT or MPI_INIT_THREAD was invoked, + * - what the final MPI thread level was determined to be, + * - whether the OMPI or MPI libraries are multi-threaded + * + * MPI_INIT and MPI_INIT_THREAD (specifically, back-end OMPI startup + * functions) invoke opal_set_using_threads() to influence the value of + * this function, depending on their situation. Some examples: + * + * - if MPI_INIT is invoked, and the ompi components in use are + * single-threaded, this value will be false. + * + * - if MPI_INIT_THREAD is invoked with MPI_THREAD_MULTIPLE, we have + * thread support, and the final thread level is determined to be + * MPI_THREAD_MULTIPLE, this value will be true. + * + * - if the process is a single-threaded OMPI executable (e.g., mpicc), + * this value will be false. + * + * Hence, this function will return false if there is guaranteed to + * only be one thread in the process. If there is even the + * possibility that we may have multiple threads, true will be + * returned. + */ +#define opal_using_threads() opal_uses_threads + +/** + * Set whether the process is using multiple threads or not. + * + * @param have Boolean indicating whether the process is using + * multiple threads or not. + * + * @retval opal_using_threads The new return value from + * opal_using_threads(). + * + * This function is used to influence the return value of + * opal_using_threads(). If configure detected that we have thread + * support, the return value of future invocations of + * opal_using_threads() will be the parameter's value. If configure + * detected that we have no thread support, then the retuen from + * opal_using_threads() will always be false. + */ +static inline bool opal_set_using_threads(bool have) +{ + opal_uses_threads = have; + return opal_using_threads(); +} + + +/** + * Use an atomic operation for increment/decrement if opal_using_threads() + * indicates that threads are in use by the application or library. + */ + +#define OPAL_THREAD_DEFINE_ATOMIC_ADD(type, suffix) \ +static inline type opal_thread_add_ ## suffix (volatile type *addr, type delta) \ +{ \ + if (OPAL_UNLIKELY(opal_using_threads())) { \ + return opal_atomic_add_ ## suffix (addr, delta); \ + } \ + \ + return (*addr += delta); \ +} + +#define OPAL_THREAD_DEFINE_ATOMIC_SUB(type, suffix) \ +static inline type opal_thread_sub_ ## suffix (volatile type *addr, type delta) \ +{ \ + if (OPAL_UNLIKELY(opal_using_threads())) { \ + return opal_atomic_sub_ ## suffix (addr, delta); \ + } \ + \ + return (*addr -= delta); \ +} + +#define OPAL_THREAD_DEFINE_ATOMIC_CMPSET(type, addr_type, suffix) \ +static inline bool opal_thread_cmpset_bool_ ## suffix (volatile addr_type *addr, type compare, type value) \ +{ \ + if (OPAL_UNLIKELY(opal_using_threads())) { \ + return opal_atomic_cmpset_ ## suffix ((volatile type *) addr, compare, value); \ + } \ + \ + if ((type) *addr == compare) { \ + ((type *) addr)[0] = value; \ + return true; \ + } \ + \ + return false; \ +} + +#define OPAL_THREAD_DEFINE_ATOMIC_SWAP(type, addr_type, suffix) \ +static inline type opal_thread_swap_ ## suffix (volatile addr_type *ptr, type newvalue) \ +{ \ + if (opal_using_threads ()) { \ + return opal_atomic_swap_ ## suffix ((volatile type *) ptr, newvalue); \ + } \ + \ + type old = ((type *) ptr)[0]; \ + ((type *) ptr)[0] = newvalue; \ + \ + return old; \ +} + +OPAL_THREAD_DEFINE_ATOMIC_ADD(int32_t, 32) +OPAL_THREAD_DEFINE_ATOMIC_ADD(size_t, size_t) +OPAL_THREAD_DEFINE_ATOMIC_SUB(size_t, size_t) +OPAL_THREAD_DEFINE_ATOMIC_CMPSET(int32_t, int32_t, 32) +OPAL_THREAD_DEFINE_ATOMIC_CMPSET(void *, intptr_t, ptr) +OPAL_THREAD_DEFINE_ATOMIC_SWAP(int32_t, int32_t, 32) +OPAL_THREAD_DEFINE_ATOMIC_SWAP(void *, intptr_t, ptr) + +#define OPAL_THREAD_ADD32 opal_thread_add_32 +#define OPAL_ATOMIC_ADD32 opal_thread_add_32 + +#define OPAL_THREAD_ADD_SIZE_T opal_thread_add_size_t +#define OPAL_ATOMIC_ADD_SIZE_T opal_thread_add_size_t + +#define OPAL_THREAD_SUB_SIZE_T opal_thread_sub_size_t +#define OPAL_ATOMIC_SUB_SIZE_T opal_thread_sub_size_t + +#define OPAL_THREAD_CMPSET_32 opal_thread_cmpset_bool_32 +#define OPAL_ATOMIC_CMPSET_32 opal_thread_cmpset_bool_32 + +#define OPAL_THREAD_CMPSET_PTR(x, y, z) opal_thread_cmpset_bool_ptr ((volatile intptr_t *) x, (void *) y, (void *) z) +#define OPAL_ATOMIC_CMPSET_PTR OPAL_THREAD_CMPSET_PTR + +#define OPAL_THREAD_SWAP_32 opal_thread_swap_32 +#define OPAL_ATOMIC_SWAP_32 opal_thread_swap_32 + +#define OPAL_THREAD_SWAP_PTR(x, y) opal_thread_swap_ptr ((volatile intptr_t *) x, (void *) y) +#define OPAL_ATOMIC_SWAP_PTR OPAL_THREAD_SWAP_PTR + +/* define 64-bit macros is 64-bit atomic math is available */ +#if OPAL_HAVE_ATOMIC_MATH_64 + +OPAL_THREAD_DEFINE_ATOMIC_ADD(int64_t, 64) +OPAL_THREAD_DEFINE_ATOMIC_CMPSET(int64_t, int64_t, 64) +OPAL_THREAD_DEFINE_ATOMIC_SWAP(int64_t, int64_t, 64) + +#define OPAL_THREAD_ADD64 opal_thread_add_64 +#define OPAL_ATOMIC_ADD64 opal_thread_add_64 + +#define OPAL_THREAD_CMPSET_64 opal_thread_cmpset_bool_64 +#define OPAL_ATOMIC_CMPSET_64 opal_thread_cmpset_bool_64 + +#define OPAL_THREAD_SWAP_64 opal_thread_swap_64 +#define OPAL_ATOMIC_SWAP_64 opal_thread_swap_64 + +#endif + +#endif /* !defined(OPAL_MCA_THREAD_USAGE_H) */ diff --git a/opal/mca/threads/threads.h b/opal/mca/threads/threads.h new file mode 100644 index 00000000000..6055ee3840a --- /dev/null +++ b/opal/mca/threads/threads.h @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana + * University Research and Technology + * Corporation. All rights reserved. + * Copyright (c) 2004-2006 The University of Tennessee and The University + * of Tennessee Research Foundation. All rights + * reserved. + * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, + * University of Stuttgart. All rights reserved. + * Copyright (c) 2004-2005 The Regents of the University of California. + * All rights reserved. + * Copyright (c) 2010 Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015-2017 Research Organization for Information Science + * and Technology (RIST). All rights reserved. + * Copyright (c) 2017 Intel, Inc. All rights reserved. + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + +#ifndef OPAL_MCA_THREAD_H +#define OPAL_MCA_THREAD_H 1 + +#include "opal_config.h" + +#include +#include + +#include "opal/class/opal_object.h" +#if OPAL_ENABLE_DEBUG +#include "opal/util/output.h" +#endif + +#include "mutex.h" +#include "condition.h" + +BEGIN_C_DECLS + +typedef void *(*opal_thread_fn_t) (opal_object_t *); + +#define OPAL_THREAD_CANCELLED ((void*)1); + +struct opal_thread_t { + opal_object_t super; + opal_thread_fn_t t_run; + void* t_arg; + pthread_t t_handle; +}; + +typedef struct opal_thread_t opal_thread_t; + +OBJ_CLASS_DECLARATION(opal_thread_t); + +#if OPAL_ENABLE_DEBUG +OPAL_DECLSPEC extern bool opal_debug_threads; +#endif + + +OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_thread_t); + +#if OPAL_ENABLE_DEBUG +#define OPAL_ACQUIRE_THREAD(lck, cnd, act) \ + do { \ + OPAL_THREAD_LOCK((lck)); \ + if (opal_debug_threads) { \ + opal_output(0, "Waiting for thread %s:%d", \ + __FILE__, __LINE__); \ + } \ + while (*(act)) { \ + opal_condition_wait((cnd), (lck)); \ + } \ + if (opal_debug_threads) { \ + opal_output(0, "Thread obtained %s:%d", \ + __FILE__, __LINE__); \ + } \ + *(act) = true; \ + } while(0); +#else +#define OPAL_ACQUIRE_THREAD(lck, cnd, act) \ + do { \ + OPAL_THREAD_LOCK((lck)); \ + while (*(act)) { \ + opal_condition_wait((cnd), (lck)); \ + } \ + *(act) = true; \ + } while(0); +#endif + + +#if OPAL_ENABLE_DEBUG +#define OPAL_RELEASE_THREAD(lck, cnd, act) \ + do { \ + if (opal_debug_threads) { \ + opal_output(0, "Releasing thread %s:%d", \ + __FILE__, __LINE__); \ + } \ + *(act) = false; \ + opal_condition_broadcast((cnd)); \ + OPAL_THREAD_UNLOCK((lck)); \ + } while(0); +#else +#define OPAL_RELEASE_THREAD(lck, cnd, act) \ + do { \ + *(act) = false; \ + opal_condition_broadcast((cnd)); \ + OPAL_THREAD_UNLOCK((lck)); \ + } while(0); +#endif + + +#define OPAL_WAKEUP_THREAD(cnd, act) \ + do { \ + *(act) = false; \ + opal_condition_broadcast((cnd)); \ + } while(0); + +/* provide a macro for forward-proofing the shifting + * of objects between libevent threads - at some point, we + * may revamp that threading model */ + +/* post an object to another thread - for now, we + * only have a memory barrier */ +#define OPAL_POST_OBJECT(o) opal_atomic_wmb() + +/* acquire an object from another thread - for now, + * we only have a memory barrier */ +#define OPAL_ACQUIRE_OBJECT(o) opal_atomic_rmb() + + + +OPAL_DECLSPEC int opal_thread_start(opal_thread_t *); +OPAL_DECLSPEC int opal_thread_join(opal_thread_t *, void **thread_return); +OPAL_DECLSPEC bool opal_thread_self_compare(opal_thread_t*); +OPAL_DECLSPEC opal_thread_t *opal_thread_get_self(void); +OPAL_DECLSPEC void opal_thread_kill(opal_thread_t *, int sig); +OPAL_DECLSPEC void opal_thread_set_main(void); +OPAL_DECLSPEC void opal_event_use_threads(void); + + +END_C_DECLS + +#endif /* OPAL_MCA_THREAD_H */ diff --git a/opal/mca/threads/tsd.h b/opal/mca/threads/tsd.h new file mode 100644 index 00000000000..51623978522 --- /dev/null +++ b/opal/mca/threads/tsd.h @@ -0,0 +1,178 @@ +/* + * Copyright (c) 2007-2013 Los Alamos National Security, LLC. All rights + * reserved. + * Copyright (c) 2008 Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2015-2017 Research Organization for Information Science + * and Technology (RIST). All rights reserved. + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + + +#ifndef OPAL_MCA_THREADS_TSD_H +#define OPAL_MCA_THREADS_TSD_H + +#include "opal_config.h" + +#include + +#include "opal/constants.h" + +BEGIN_C_DECLS + +/** + * @file + * + * Thread Specific Datastore Interface + * + * Functions for providing thread-specific datastore capabilities. + */ + + +/** + * Prototype for callback when tsd data is being destroyed + */ +typedef void (*opal_tsd_destructor_t)(void *value); + +#if defined(DOXYGEN) + +/** + * Typedef for thread-specific data key + */ +typedef void* opal_tsd_key_t; + + +/** + * Delete a thread-specific data key + * + * Delete a thread-specific data key previously returned by + * opal_tsd_key_create(). The destructor associated with the key is + * not fired in any thread and memory cleanup is the responsibility of + * the caller. + * + * @note Unlike pthread_key_delete, this function should not be called + * from within a destructor. It can not be universally supported at + * this time. + * + * @param key[in] The key for accessing thread-specific data + * + * @retval OPAL_SUCCESS Success + * @retval EINVAL Invalid key + */ +OPAL_DECLSPEC int opal_tsd_key_delete(opal_tsd_key_t key); + + +/** + * Set a thread-specific data value + * + * Associates value with key in the current thread. The value for the + * key in other threads is not changed. Different threads may assign + * different values to the same key. + * + * @note This function should not be called within + * opal_tsd_key_delete(). + * + * @param key[in] Thread specific data key to modify + * @param value[in] Value to associate with key + * + * @retval OPAL_SUCCESS Success + * @retval ENOMEM Insufficient memory exists to associate the + * value with the key + * @retval EINVAL Invalid key + */ +OPAL_DECLSPEC int opal_tsd_setspecific(opal_tsd_key_t key, void *value); + + +/** + * Get a thread-specific data value + * + * Get the data associated with the given key, as set by + * opal_tsd_setspecific(). If opal_tsd_setspecific() hasn't been + * called in the current thread with the given key, NULL is returned + * in valuep. + * + * @param key[in] Thread specific data key to modify + * @param value[out] Value to associate with key + * + * @retval OPAL_SUCCESS Success + * @retval ENOMEM Insufficient memory exists to associate the + * value with the key + * @retval EINVAL Invalid key + */ +OPAL_DECLSPEC int opal_tsd_getspecific(opal_tsd_key_t key, void **valuep); + +#else + +typedef pthread_key_t opal_tsd_key_t; + +static inline int +opal_tsd_key_delete(opal_tsd_key_t key) +{ + return pthread_key_delete(key); +} + +static inline int +opal_tsd_setspecific(opal_tsd_key_t key, void *value) +{ + return pthread_setspecific(key, value); +} + +static inline int +opal_tsd_getspecific(opal_tsd_key_t key, void **valuep) +{ + *valuep = pthread_getspecific(key); + return OPAL_SUCCESS; +} + +#endif + +/** + * Create thread-specific data key + * + * Create a thread-specific data key visible to all threads in the + * current process. The returned key is valid in all threads, + * although the values bound to the key by opal_tsd_setspecific() are + * allocated on a per-thread basis and persist for the life of the + * calling thread. + * + * Upon key creation, the value NULL is associated with the new key in + * all active threads. When a new thread is created, the value NULL + * is associated with all defined keys in the new thread. + * + * The destructor parameter may be NULL. At thread exit, if + * destructor is non-NULL AND the thread has a non-NULL value + * associated with the key, the function is called with the current + * value as its argument. + * + * @param key[out] The key for accessing thread-specific data + * @param destructor[in] Cleanup function to call when a thread exits + * + * @retval OPAL_SUCCESS Success + * @retval EAGAIN The system lacked the necessary resource to + * create another thread specific data key + * @retval ENOMEM Insufficient memory exists to create the key + */ +OPAL_DECLSPEC int opal_tsd_key_create(opal_tsd_key_t *key, + opal_tsd_destructor_t destructor); + + +/** + * Destruct all thread-specific data keys + * + * Destruct all thread-specific data keys and invoke the destructor + * + * This should only be invoked in the main thread. + * This is made necessary since destructors are not invoked on the + * keys of the main thread, since there is no such thing as + * pthread_join(main_thread) + * + * @retval OPAL_SUCCESS Success + */ +OPAL_DECLSPEC int opal_tsd_keys_destruct(void); + +END_C_DECLS + +#endif /* OPAL_MCA_THREADS_TSD_H */ diff --git a/opal/mca/threads/wait_sync.h b/opal/mca/threads/wait_sync.h new file mode 100644 index 00000000000..5159a2b2a1d --- /dev/null +++ b/opal/mca/threads/wait_sync.h @@ -0,0 +1,128 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ +/* + * Copyright (c) 2014-2016 The University of Tennessee and The University + * of Tennessee Research Foundation. All rights + * reserved. + * Copyright (c) 2016 Los Alamos National Security, LLC. All rights + * reserved. + * Copyright (c) 2016 Mellanox Technologies. All rights reserved. + * Copyright (c) 2016 Research Organization for Information Science + * and Technology (RIST). All rights reserved. + * Copyright (c) 2017 IBM Corporation. All rights reserved. + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + +#if !defined(OPAL_MCA_THREADS_WAIT_SYNC_H) +#define OPAL_MCA_THREADS_WAIT_SYNC_H + +#include "opal/sys/atomic.h" +#include "opal/threads/condition.h" +//#include + +BEGIN_C_DECLS + +extern int opal_max_thread_in_progress; + +typedef struct ompi_wait_sync_t { + opal_atomic_int32_t count; + int32_t status; + pthread_cond_t condition; + pthread_mutex_t lock; + struct ompi_wait_sync_t *next; + struct ompi_wait_sync_t *prev; + volatile bool signaling; +} ompi_wait_sync_t; + +#define REQUEST_PENDING (void*)0L +#define REQUEST_COMPLETED (void*)1L + +#define SYNC_WAIT(sync) (opal_using_threads() ? ompi_sync_wait_mt (sync) : sync_wait_st (sync)) + +/* The loop in release handles a race condition between the signaling + * thread and the destruction of the condition variable. The signaling + * member will be set to false after the final signaling thread has + * finished operating on the sync object. This is done to avoid + * extra atomics in the signalling function and keep it as fast + * as possible. Note that the race window is small so spinning here + * is more optimal than sleeping since this macro is called in + * the critical path. */ +#define WAIT_SYNC_RELEASE(sync) \ + if (opal_using_threads()) { \ + while ((sync)->signaling) { \ + continue; \ + } \ + pthread_cond_destroy(&(sync)->condition); \ + pthread_mutex_destroy(&(sync)->lock); \ + } + +#define WAIT_SYNC_RELEASE_NOWAIT(sync) \ + if (opal_using_threads()) { \ + pthread_cond_destroy(&(sync)->condition); \ + pthread_mutex_destroy(&(sync)->lock); \ + } + + +#define WAIT_SYNC_SIGNAL(sync) \ + if (opal_using_threads()) { \ + pthread_mutex_lock(&(sync->lock)); \ + pthread_cond_signal(&sync->condition); \ + pthread_mutex_unlock(&(sync->lock)); \ + sync->signaling = false; \ + } + +#define WAIT_SYNC_SIGNALLED(sync){ \ + (sync)->signaling = false; \ +} + +OPAL_DECLSPEC int ompi_sync_wait_mt(ompi_wait_sync_t *sync); +static inline int sync_wait_st (ompi_wait_sync_t *sync) +{ + while (sync->count > 0) { + opal_progress(); + } + + return sync->status; +} + + +#define WAIT_SYNC_INIT(sync,c) \ + do { \ + (sync)->count = (c); \ + (sync)->next = NULL; \ + (sync)->prev = NULL; \ + (sync)->status = 0; \ + (sync)->signaling = (0 != (c)); \ + if (opal_using_threads()) { \ + pthread_cond_init (&(sync)->condition, NULL); \ + pthread_mutex_init (&(sync)->lock, NULL); \ + } \ + } while(0) + +/** + * Update the status of the synchronization primitive. If an error is + * reported the synchronization is completed and the signal + * triggered. The status of the synchronization will be reported to + * the waiting threads. + */ +static inline void wait_sync_update(ompi_wait_sync_t *sync, int updates, int status) +{ + if( OPAL_LIKELY(OPAL_SUCCESS == status) ) { + if( 0 != (OPAL_THREAD_ADD_FETCH32(&sync->count, -updates)) ) { + return; + } + } else { + /* this is an error path so just use the atomic */ + sync->status = OPAL_ERROR; + opal_atomic_wmb (); + opal_atomic_swap_32 (&sync->count, 0); + } + WAIT_SYNC_SIGNAL(sync); +} + +END_C_DECLS + +#endif /* defined(OPAL_MCA_THREADS_WAIT_SYNC_H) */ diff --git a/opal/runtime/opal_params.c b/opal/runtime/opal_params.c index 2897b64737f..485a8ce325b 100644 --- a/opal/runtime/opal_params.c +++ b/opal/runtime/opal_params.c @@ -61,6 +61,10 @@ char *opal_timing_output = NULL; bool opal_timing_overhead = true; #endif +#if OPAL_ENABLE_DEBUG +bool opal_debug_threads; +#endif + bool opal_built_with_cuda_support = OPAL_INT_TO_BOOL(OPAL_CUDA_SUPPORT); bool opal_cuda_support = false; bool opal_warn_on_missing_libcuda = true; diff --git a/opal/threads/Makefile.am b/opal/threads/Makefile.am deleted file mode 100644 index a4a084038ca..00000000000 --- a/opal/threads/Makefile.am +++ /dev/null @@ -1,39 +0,0 @@ -# -*- makefile -*- -# -# Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana -# University Research and Technology -# Corporation. All rights reserved. -# Copyright (c) 2004-2016 The University of Tennessee and The University -# of Tennessee Research Foundation. All rights -# reserved. -# Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, -# University of Stuttgart. All rights reserved. -# Copyright (c) 2004-2005 The Regents of the University of California. -# All rights reserved. -# Copyright (c) 2014 Cisco Systems, Inc. All rights reserved. -# Copyright (c) 2015 Research Organization for Information Science -# and Technology (RIST). All rights reserved. -# $COPYRIGHT$ -# -# Additional copyrights may follow -# -# $HEADER$ -# - -# This makefile.am does not stand on its own - it is included from opal/Makefile.am - -# Source code files -headers += \ - threads/condition.h \ - threads/mutex.h \ - threads/mutex_unix.h \ - threads/threads.h \ - threads/tsd.h \ - threads/wait_sync.h \ - threads/thread_usage.h - -lib@OPAL_LIB_PREFIX@open_pal_la_SOURCES += \ - threads/condition.c \ - threads/mutex.c \ - threads/thread.c \ - threads/wait_sync.c diff --git a/opal/threads/condition.h b/opal/threads/condition.h index 4c61fd64ac9..47eef598f8e 100644 --- a/opal/threads/condition.h +++ b/opal/threads/condition.h @@ -22,124 +22,7 @@ #ifndef OPAL_CONDITION_SPINLOCK_H #define OPAL_CONDITION_SPINLOCK_H -#include "opal_config.h" -#ifdef HAVE_SYS_TIME_H -#include -#endif -#include -#include - -#include "opal/threads/mutex.h" -#include "opal/runtime/opal_progress.h" - -#include "opal/runtime/opal_cr.h" - -BEGIN_C_DECLS - -/* - * Combine pthread support w/ polled progress to allow run-time selection - * of threading vs. non-threading progress. - */ - -struct opal_condition_t { - opal_object_t super; - volatile int c_waiting; - volatile int c_signaled; -}; -typedef struct opal_condition_t opal_condition_t; - -OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_condition_t); - - -static inline int opal_condition_wait(opal_condition_t *c, opal_mutex_t *m) -{ - int rc = 0; - c->c_waiting++; - - if (opal_using_threads()) { - if (c->c_signaled) { - c->c_waiting--; - opal_mutex_unlock(m); - opal_progress(); - OPAL_CR_TEST_CHECKPOINT_READY_STALL(); - opal_mutex_lock(m); - return 0; - } - while (c->c_signaled == 0) { - opal_mutex_unlock(m); - opal_progress(); - OPAL_CR_TEST_CHECKPOINT_READY_STALL(); - opal_mutex_lock(m); - } - } else { - while (c->c_signaled == 0) { - opal_progress(); - OPAL_CR_TEST_CHECKPOINT_READY_STALL(); - } - } - - c->c_signaled--; - c->c_waiting--; - return rc; -} - -static inline int opal_condition_timedwait(opal_condition_t *c, - opal_mutex_t *m, - const struct timespec *abstime) -{ - struct timeval tv; - struct timeval absolute; - int rc = 0; - - c->c_waiting++; - if (opal_using_threads()) { - absolute.tv_sec = abstime->tv_sec; - absolute.tv_usec = abstime->tv_nsec / 1000; - gettimeofday(&tv,NULL); - if (c->c_signaled == 0) { - do { - opal_mutex_unlock(m); - opal_progress(); - gettimeofday(&tv,NULL); - opal_mutex_lock(m); - } while (c->c_signaled == 0 && - (tv.tv_sec <= absolute.tv_sec || - (tv.tv_sec == absolute.tv_sec && tv.tv_usec < absolute.tv_usec))); - } - } else { - absolute.tv_sec = abstime->tv_sec; - absolute.tv_usec = abstime->tv_nsec / 1000; - gettimeofday(&tv,NULL); - if (c->c_signaled == 0) { - do { - opal_progress(); - gettimeofday(&tv,NULL); - } while (c->c_signaled == 0 && - (tv.tv_sec <= absolute.tv_sec || - (tv.tv_sec == absolute.tv_sec && tv.tv_usec < absolute.tv_usec))); - } - } - - if (c->c_signaled != 0) c->c_signaled--; - c->c_waiting--; - return rc; -} - -static inline int opal_condition_signal(opal_condition_t *c) -{ - if (c->c_waiting) { - c->c_signaled++; - } - return 0; -} - -static inline int opal_condition_broadcast(opal_condition_t *c) -{ - c->c_signaled = c->c_waiting; - return 0; -} - -END_C_DECLS +#include "opal/mca/threads/condition.h" #endif diff --git a/opal/threads/mutex.h b/opal/threads/mutex.h index 694c23d988a..79067829ca1 100644 --- a/opal/threads/mutex.h +++ b/opal/threads/mutex.h @@ -26,167 +26,6 @@ #ifndef OPAL_MUTEX_H #define OPAL_MUTEX_H 1 -#include "opal_config.h" - -#include "opal/threads/thread_usage.h" - -BEGIN_C_DECLS - -/** - * @file: - * - * Mutual exclusion functions. - * - * Functions for locking of critical sections. - */ - -/** - * Opaque mutex object - */ -typedef struct opal_mutex_t opal_mutex_t; -typedef struct opal_mutex_t opal_recursive_mutex_t; - -/** - * Try to acquire a mutex. - * - * @param mutex Address of the mutex. - * @return 0 if the mutex was acquired, 1 otherwise. - */ -static inline int opal_mutex_trylock(opal_mutex_t *mutex); - - -/** - * Acquire a mutex. - * - * @param mutex Address of the mutex. - */ -static inline void opal_mutex_lock(opal_mutex_t *mutex); - - -/** - * Release a mutex. - * - * @param mutex Address of the mutex. - */ -static inline void opal_mutex_unlock(opal_mutex_t *mutex); - - -/** - * Try to acquire a mutex using atomic operations. - * - * @param mutex Address of the mutex. - * @return 0 if the mutex was acquired, 1 otherwise. - */ -static inline int opal_mutex_atomic_trylock(opal_mutex_t *mutex); - - -/** - * Acquire a mutex using atomic operations. - * - * @param mutex Address of the mutex. - */ -static inline void opal_mutex_atomic_lock(opal_mutex_t *mutex); - - -/** - * Release a mutex using atomic operations. - * - * @param mutex Address of the mutex. - */ -static inline void opal_mutex_atomic_unlock(opal_mutex_t *mutex); - -END_C_DECLS - -#include "mutex_unix.h" - -BEGIN_C_DECLS - -/** - * Lock a mutex if opal_using_threads() says that multiple threads may - * be active in the process. - * - * @param mutex Pointer to a opal_mutex_t to lock. - * - * If there is a possibility that multiple threads are running in the - * process (as determined by opal_using_threads()), this function will - * block waiting to lock the mutex. - * - * If there is no possibility that multiple threads are running in the - * process, return immediately. - */ -#define OPAL_THREAD_LOCK(mutex) \ - do { \ - if (OPAL_UNLIKELY(opal_using_threads())) { \ - opal_mutex_lock(mutex); \ - } \ - } while (0) - - -/** - * Try to lock a mutex if opal_using_threads() says that multiple - * threads may be active in the process. - * - * @param mutex Pointer to a opal_mutex_t to trylock - * - * If there is a possibility that multiple threads are running in the - * process (as determined by opal_using_threads()), this function will - * trylock the mutex. - * - * If there is no possibility that multiple threads are running in the - * process, return immediately without modifying the mutex. - * - * Returns 0 if mutex was locked, non-zero otherwise. - */ -#define OPAL_THREAD_TRYLOCK(mutex) \ - (OPAL_UNLIKELY(opal_using_threads()) ? opal_mutex_trylock(mutex) : 0) - -/** - * Unlock a mutex if opal_using_threads() says that multiple threads - * may be active in the process. - * - * @param mutex Pointer to a opal_mutex_t to unlock. - * - * If there is a possibility that multiple threads are running in the - * process (as determined by opal_using_threads()), this function will - * unlock the mutex. - * - * If there is no possibility that multiple threads are running in the - * process, return immediately without modifying the mutex. - */ -#define OPAL_THREAD_UNLOCK(mutex) \ - do { \ - if (OPAL_UNLIKELY(opal_using_threads())) { \ - opal_mutex_unlock(mutex); \ - } \ - } while (0) - - -/** - * Lock a mutex if opal_using_threads() says that multiple threads may - * be active in the process for the duration of the specified action. - * - * @param mutex Pointer to a opal_mutex_t to lock. - * @param action A scope over which the lock is held. - * - * If there is a possibility that multiple threads are running in the - * process (as determined by opal_using_threads()), this function will - * acquire the lock before invoking the specified action and release - * it on return. - * - * If there is no possibility that multiple threads are running in the - * process, invoke the action without acquiring the lock. - */ -#define OPAL_THREAD_SCOPED_LOCK(mutex, action) \ - do { \ - if(OPAL_UNLIKELY(opal_using_threads())) { \ - opal_mutex_lock(mutex); \ - action; \ - opal_mutex_unlock(mutex); \ - } else { \ - action; \ - } \ - } while (0) - -END_C_DECLS +#include "opal/mca/threads/mutex.h" #endif /* OPAL_MUTEX_H */ diff --git a/opal/threads/threads.h b/opal/threads/threads.h index 661d6b00ee0..ba7fcb081c0 100644 --- a/opal/threads/threads.h +++ b/opal/threads/threads.h @@ -24,118 +24,6 @@ #ifndef OPAL_THREAD_H #define OPAL_THREAD_H 1 -#include "opal_config.h" - -#include -#include - -#include "opal/class/opal_object.h" -#if OPAL_ENABLE_DEBUG -#include "opal/util/output.h" -#endif - -#include "mutex.h" -#include "condition.h" - -BEGIN_C_DECLS - -typedef void *(*opal_thread_fn_t) (opal_object_t *); - -#define OPAL_THREAD_CANCELLED ((void*)1); - -struct opal_thread_t { - opal_object_t super; - opal_thread_fn_t t_run; - void* t_arg; - pthread_t t_handle; -}; - -typedef struct opal_thread_t opal_thread_t; - -#if OPAL_ENABLE_DEBUG -OPAL_DECLSPEC extern bool opal_debug_threads; -#endif - - -OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_thread_t); - -#if OPAL_ENABLE_DEBUG -#define OPAL_ACQUIRE_THREAD(lck, cnd, act) \ - do { \ - OPAL_THREAD_LOCK((lck)); \ - if (opal_debug_threads) { \ - opal_output(0, "Waiting for thread %s:%d", \ - __FILE__, __LINE__); \ - } \ - while (*(act)) { \ - opal_condition_wait((cnd), (lck)); \ - } \ - if (opal_debug_threads) { \ - opal_output(0, "Thread obtained %s:%d", \ - __FILE__, __LINE__); \ - } \ - *(act) = true; \ - } while(0); -#else -#define OPAL_ACQUIRE_THREAD(lck, cnd, act) \ - do { \ - OPAL_THREAD_LOCK((lck)); \ - while (*(act)) { \ - opal_condition_wait((cnd), (lck)); \ - } \ - *(act) = true; \ - } while(0); -#endif - - -#if OPAL_ENABLE_DEBUG -#define OPAL_RELEASE_THREAD(lck, cnd, act) \ - do { \ - if (opal_debug_threads) { \ - opal_output(0, "Releasing thread %s:%d", \ - __FILE__, __LINE__); \ - } \ - *(act) = false; \ - opal_condition_broadcast((cnd)); \ - OPAL_THREAD_UNLOCK((lck)); \ - } while(0); -#else -#define OPAL_RELEASE_THREAD(lck, cnd, act) \ - do { \ - *(act) = false; \ - opal_condition_broadcast((cnd)); \ - OPAL_THREAD_UNLOCK((lck)); \ - } while(0); -#endif - - -#define OPAL_WAKEUP_THREAD(cnd, act) \ - do { \ - *(act) = false; \ - opal_condition_broadcast((cnd)); \ - } while(0); - -/* provide a macro for forward-proofing the shifting - * of objects between libevent threads - at some point, we - * may revamp that threading model */ - -/* post an object to another thread - for now, we - * only have a memory barrier */ -#define OPAL_POST_OBJECT(o) opal_atomic_wmb() - -/* acquire an object from another thread - for now, - * we only have a memory barrier */ -#define OPAL_ACQUIRE_OBJECT(o) opal_atomic_rmb() - - - -OPAL_DECLSPEC int opal_thread_start(opal_thread_t *); -OPAL_DECLSPEC int opal_thread_join(opal_thread_t *, void **thread_return); -OPAL_DECLSPEC bool opal_thread_self_compare(opal_thread_t*); -OPAL_DECLSPEC opal_thread_t *opal_thread_get_self(void); -OPAL_DECLSPEC void opal_thread_kill(opal_thread_t *, int sig); -OPAL_DECLSPEC void opal_thread_set_main(void); - -END_C_DECLS +#include "opal/mca/threads/threads.h" #endif /* OPAL_THREAD_H */ diff --git a/opal/threads/tsd.h b/opal/threads/tsd.h index e49c08dd96e..e059f15fca1 100644 --- a/opal/threads/tsd.h +++ b/opal/threads/tsd.h @@ -15,164 +15,6 @@ #ifndef OPAL_THREADS_TSD_H #define OPAL_THREADS_TSD_H -#include "opal_config.h" +#include "opal/mca/threads/tsd.h" -#include - -#include "opal/constants.h" - -BEGIN_C_DECLS - -/** - * @file - * - * Thread Specific Datastore Interface - * - * Functions for providing thread-specific datastore capabilities. - */ - - -/** - * Prototype for callback when tsd data is being destroyed - */ -typedef void (*opal_tsd_destructor_t)(void *value); - -#if defined(DOXYGEN) - -/** - * Typedef for thread-specific data key - */ -typedef void* opal_tsd_key_t; - - -/** - * Delete a thread-specific data key - * - * Delete a thread-specific data key previously returned by - * opal_tsd_key_create(). The destructor associated with the key is - * not fired in any thread and memory cleanup is the responsibility of - * the caller. - * - * @note Unlike pthread_key_delete, this function should not be called - * from within a destructor. It can not be universally supported at - * this time. - * - * @param key[in] The key for accessing thread-specific data - * - * @retval OPAL_SUCCESS Success - * @retval EINVAL Invalid key - */ -OPAL_DECLSPEC int opal_tsd_key_delete(opal_tsd_key_t key); - - -/** - * Set a thread-specific data value - * - * Associates value with key in the current thread. The value for the - * key in other threads is not changed. Different threads may assign - * different values to the same key. - * - * @note This function should not be called within - * opal_tsd_key_delete(). - * - * @param key[in] Thread specific data key to modify - * @param value[in] Value to associate with key - * - * @retval OPAL_SUCCESS Success - * @retval ENOMEM Insufficient memory exists to associate the - * value with the key - * @retval EINVAL Invalid key - */ -OPAL_DECLSPEC int opal_tsd_setspecific(opal_tsd_key_t key, void *value); - - -/** - * Get a thread-specific data value - * - * Get the data associated with the given key, as set by - * opal_tsd_setspecific(). If opal_tsd_setspecific() hasn't been - * called in the current thread with the given key, NULL is returned - * in valuep. - * - * @param key[in] Thread specific data key to modify - * @param value[out] Value to associate with key - * - * @retval OPAL_SUCCESS Success - * @retval ENOMEM Insufficient memory exists to associate the - * value with the key - * @retval EINVAL Invalid key - */ -OPAL_DECLSPEC int opal_tsd_getspecific(opal_tsd_key_t key, void **valuep); - -#else - -typedef pthread_key_t opal_tsd_key_t; - -static inline int -opal_tsd_key_delete(opal_tsd_key_t key) -{ - return pthread_key_delete(key); -} - -static inline int -opal_tsd_setspecific(opal_tsd_key_t key, void *value) -{ - return pthread_setspecific(key, value); -} - -static inline int -opal_tsd_getspecific(opal_tsd_key_t key, void **valuep) -{ - *valuep = pthread_getspecific(key); - return OPAL_SUCCESS; -} - -#endif - -/** - * Create thread-specific data key - * - * Create a thread-specific data key visible to all threads in the - * current process. The returned key is valid in all threads, - * although the values bound to the key by opal_tsd_setspecific() are - * allocated on a per-thread basis and persist for the life of the - * calling thread. - * - * Upon key creation, the value NULL is associated with the new key in - * all active threads. When a new thread is created, the value NULL - * is associated with all defined keys in the new thread. - * - * The destructor parameter may be NULL. At thread exit, if - * destructor is non-NULL AND the thread has a non-NULL value - * associated with the key, the function is called with the current - * value as its argument. - * - * @param key[out] The key for accessing thread-specific data - * @param destructor[in] Cleanup function to call when a thread exits - * - * @retval OPAL_SUCCESS Success - * @retval EAGAIN The system lacked the necessary resource to - * create another thread specific data key - * @retval ENOMEM Insufficient memory exists to create the key - */ -OPAL_DECLSPEC int opal_tsd_key_create(opal_tsd_key_t *key, - opal_tsd_destructor_t destructor); - - -/** - * Destruct all thread-specific data keys - * - * Destruct all thread-specific data keys and invoke the destructor - * - * This should only be invoked in the main thread. - * This is made necessary since destructors are not invoked on the - * keys of the main thread, since there is no such thing as - * pthread_join(main_thread) - * - * @retval OPAL_SUCCESS Success - */ -OPAL_DECLSPEC int opal_tsd_keys_destruct(void); - -END_C_DECLS - -#endif /* OPAL_MTHREADS_TSD_H */ +#endif /* OPAL_THREADS_TSD_H */ diff --git a/opal/threads/wait_sync.h b/opal/threads/wait_sync.h index 3e6c8f1949f..496ebed4f9c 100644 --- a/opal/threads/wait_sync.h +++ b/opal/threads/wait_sync.h @@ -8,7 +8,6 @@ * Copyright (c) 2016 Mellanox Technologies. All rights reserved. * Copyright (c) 2016 Research Organization for Information Science * and Technology (RIST). All rights reserved. - * Copyright (c) 2017 IBM Corporation. All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -19,110 +18,6 @@ #if !defined(OPAL_THREADS_WAIT_SYNC_H) #define OPAL_THREADS_WAIT_SYNC_H -#include "opal/sys/atomic.h" -#include "opal/threads/condition.h" -#include - -BEGIN_C_DECLS - -extern int opal_max_thread_in_progress; - -typedef struct ompi_wait_sync_t { - opal_atomic_int32_t count; - int32_t status; - pthread_cond_t condition; - pthread_mutex_t lock; - struct ompi_wait_sync_t *next; - struct ompi_wait_sync_t *prev; - volatile bool signaling; -} ompi_wait_sync_t; - -#define REQUEST_PENDING (void*)0L -#define REQUEST_COMPLETED (void*)1L - -#define SYNC_WAIT(sync) (opal_using_threads() ? ompi_sync_wait_mt (sync) : sync_wait_st (sync)) - -/* The loop in release handles a race condition between the signaling - * thread and the destruction of the condition variable. The signaling - * member will be set to false after the final signaling thread has - * finished operating on the sync object. This is done to avoid - * extra atomics in the signalling function and keep it as fast - * as possible. Note that the race window is small so spinning here - * is more optimal than sleeping since this macro is called in - * the critical path. */ -#define WAIT_SYNC_RELEASE(sync) \ - if (opal_using_threads()) { \ - while ((sync)->signaling) { \ - continue; \ - } \ - pthread_cond_destroy(&(sync)->condition); \ - pthread_mutex_destroy(&(sync)->lock); \ - } - -#define WAIT_SYNC_RELEASE_NOWAIT(sync) \ - if (opal_using_threads()) { \ - pthread_cond_destroy(&(sync)->condition); \ - pthread_mutex_destroy(&(sync)->lock); \ - } - - -#define WAIT_SYNC_SIGNAL(sync) \ - if (opal_using_threads()) { \ - pthread_mutex_lock(&(sync->lock)); \ - pthread_cond_signal(&sync->condition); \ - pthread_mutex_unlock(&(sync->lock)); \ - sync->signaling = false; \ - } - -#define WAIT_SYNC_SIGNALLED(sync){ \ - (sync)->signaling = false; \ -} - -OPAL_DECLSPEC int ompi_sync_wait_mt(ompi_wait_sync_t *sync); -static inline int sync_wait_st (ompi_wait_sync_t *sync) -{ - while (sync->count > 0) { - opal_progress(); - } - - return sync->status; -} - - -#define WAIT_SYNC_INIT(sync,c) \ - do { \ - (sync)->count = (c); \ - (sync)->next = NULL; \ - (sync)->prev = NULL; \ - (sync)->status = 0; \ - (sync)->signaling = (0 != (c)); \ - if (opal_using_threads()) { \ - pthread_cond_init (&(sync)->condition, NULL); \ - pthread_mutex_init (&(sync)->lock, NULL); \ - } \ - } while(0) - -/** - * Update the status of the synchronization primitive. If an error is - * reported the synchronization is completed and the signal - * triggered. The status of the synchronization will be reported to - * the waiting threads. - */ -static inline void wait_sync_update(ompi_wait_sync_t *sync, int updates, int status) -{ - if( OPAL_LIKELY(OPAL_SUCCESS == status) ) { - if( 0 != (OPAL_THREAD_ADD_FETCH32(&sync->count, -updates)) ) { - return; - } - } else { - /* this is an error path so just use the atomic */ - sync->status = OPAL_ERROR; - opal_atomic_wmb (); - opal_atomic_swap_32 (&sync->count, 0); - } - WAIT_SYNC_SIGNAL(sync); -} - -END_C_DECLS +#include "opal/mca/threads/wait_sync.h" #endif /* defined(OPAL_THREADS_WAIT_SYNC_H) */ diff --git a/opal/tools/wrappers/Makefile.am b/opal/tools/wrappers/Makefile.am index 53850b28bb7..e4812e7a3f3 100644 --- a/opal/tools/wrappers/Makefile.am +++ b/opal/tools/wrappers/Makefile.am @@ -62,7 +62,8 @@ endif # OPAL_INSTALL_BINARIES endif # OPAL_WANT_SCRIPT_WRAPPER_COMPILERS opal_wrapper_SOURCES = opal_wrapper.c -opal_wrapper_LDADD = $(top_builddir)/opal/lib@OPAL_LIB_PREFIX@open-pal.la +# XXX(nevans) I need to fix this, compile or runtime for the threading library? +opal_wrapper_LDADD = $(top_builddir)/opal/lib@OPAL_LIB_PREFIX@open-pal.la $(top_builddir)/opal/mca/threads/pthreads/libmca_threads_pthreads.la # Ensure that the man pages are rebuilt if the opal_config.h file # changes; a "good enough" way to know if configure was run again (and From 0f6541b7cf0f99b26222e3d4bc9ee694f4870ea4 Mon Sep 17 00:00:00 2001 From: Howard Pritchard Date: Tue, 5 Feb 2019 10:40:45 -0700 Subject: [PATCH 02/17] threads: improve pthreads comp configury use the OPAL_CONFIG_POSIX_THREADS macro Signed-off-by: Howard Pritchard --- opal/mca/threads/Makefile.am | 1 + opal/mca/threads/base/Makefile.am | 4 +++- opal/mca/threads/base/base.h | 2 ++ opal/mca/threads/base/threads_base_null.h | 13 ++++++++++--- opal/mca/threads/base/threads_base_open.c | 2 ++ opal/mca/threads/condition.h | 2 ++ opal/mca/threads/configure.m4 | 1 + opal/mca/threads/mutex.h | 1 + opal/mca/threads/pthreads/Makefile.am | 1 + opal/mca/threads/pthreads/configure.m4 | 8 ++++---- opal/mca/threads/pthreads/mutex_unix.h | 2 ++ opal/mca/threads/pthreads/threads_pthreads.h | 1 - .../threads/pthreads/threads_pthreads_component.c | 2 ++ .../threads/pthreads/threads_pthreads_condition.c | 2 ++ opal/mca/threads/pthreads/threads_pthreads_mutex.c | 2 ++ .../threads/pthreads/threads_pthreads_wait_sync.c | 2 ++ opal/mca/threads/thread.h | 2 ++ opal/mca/threads/thread_usage.h | 1 + opal/mca/threads/threads.h | 1 + opal/mca/threads/tsd.h | 2 ++ opal/mca/threads/wait_sync.h | 1 + 21 files changed, 44 insertions(+), 9 deletions(-) delete mode 100644 opal/mca/threads/pthreads/threads_pthreads.h diff --git a/opal/mca/threads/Makefile.am b/opal/mca/threads/Makefile.am index a2164a34c5a..7e7e65173b5 100644 --- a/opal/mca/threads/Makefile.am +++ b/opal/mca/threads/Makefile.am @@ -10,6 +10,7 @@ # Copyright (c) 2004-2005 The Regents of the University of California. # All rights reserved. # Copyright (c) 2010 Cisco Systems, Inc. All rights reserved. +# Copyright (c) 2019 Sandia National Laboratories. All rights reserved. # $COPYRIGHT$ # # Additional copyrights may follow diff --git a/opal/mca/threads/base/Makefile.am b/opal/mca/threads/base/Makefile.am index cbaa77d35a8..1d7f2c74fb1 100644 --- a/opal/mca/threads/base/Makefile.am +++ b/opal/mca/threads/base/Makefile.am @@ -9,6 +9,8 @@ # University of Stuttgart. All rights reserved. # Copyright (c) 2004-2005 The Regents of the University of California. # All rights reserved. +# Copyright (c) 2019 Sandia National Laboratories. All rights reserved. +# # $COPYRIGHT$ # # Additional copyrights may follow @@ -18,7 +20,7 @@ headers += \ base/base.h \ - base/threads_base_null.h + base/threads_base_null.h libmca_threads_la_SOURCES += \ base/threads_base_open.c diff --git a/opal/mca/threads/base/base.h b/opal/mca/threads/base/base.h index 5043a3d66b2..3af4d834a71 100644 --- a/opal/mca/threads/base/base.h +++ b/opal/mca/threads/base/base.h @@ -10,6 +10,8 @@ * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. * Copyright (c) 2014 Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. + * * $COPYRIGHT$ * * Additional copyrights may follow diff --git a/opal/mca/threads/base/threads_base_null.h b/opal/mca/threads/base/threads_base_null.h index 2731787a3f3..41002423466 100644 --- a/opal/mca/threads/base/threads_base_null.h +++ b/opal/mca/threads/base/threads_base_null.h @@ -9,6 +9,7 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. + * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -23,23 +24,29 @@ int opal_condition_t_class; int opal_mutex_t_class; int opal_recursive_mutex_t_class; -int opal_thread_join(opal_thread_t *t, void **thr_return) { +int opal_thread_join(opal_thread_t *t, void **thr_return) +{ return 0; } -void opal_thread_set_main() { +void opal_thread_set_main() +{ return 0; } -int opal_thread_start(opal_thread_t *t) { +int opal_thread_start(opal_thread_t *t) +{ return 0; } + int *opal_thread_t_class = NULL; int opal_tsd_key_create(opal_tsd_key_t *key, opal_tsd_destructor_t destructor) { return 0; } + int opal_uses_threads = 0; + int opal_tsd_keys_destruct() { return 0; diff --git a/opal/mca/threads/base/threads_base_open.c b/opal/mca/threads/base/threads_base_open.c index 33502790133..1e15851cec5 100644 --- a/opal/mca/threads/base/threads_base_open.c +++ b/opal/mca/threads/base/threads_base_open.c @@ -10,6 +10,8 @@ * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. * Copyright (c) 2014 Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. + * * $COPYRIGHT$ * * Additional copyrights may follow diff --git a/opal/mca/threads/condition.h b/opal/mca/threads/condition.h index b054b011e45..3456bde692a 100644 --- a/opal/mca/threads/condition.h +++ b/opal/mca/threads/condition.h @@ -13,6 +13,8 @@ * reserved. * Copyright (c) 2015 Research Organization for Information Science * and Technology (RIST). All rights reserved. + * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. + * * $COPYRIGHT$ * * Additional copyrights may follow diff --git a/opal/mca/threads/configure.m4 b/opal/mca/threads/configure.m4 index 14911994c8b..29d586e3be8 100644 --- a/opal/mca/threads/configure.m4 +++ b/opal/mca/threads/configure.m4 @@ -11,6 +11,7 @@ dnl University of Stuttgart. All rights reserved. dnl Copyright (c) 2004-2005 The Regents of the University of California. dnl All rights reserved. dnl Copyright (c) 2010 Cisco Systems, Inc. All rights reserved. +dnl Copyright (c) 2019 Sandia National Laboratories. All rights reserved. dnl $COPYRIGHT$ dnl dnl Additional copyrights may follow diff --git a/opal/mca/threads/mutex.h b/opal/mca/threads/mutex.h index 4d8401674a7..ff87bcbe9f3 100644 --- a/opal/mca/threads/mutex.h +++ b/opal/mca/threads/mutex.h @@ -15,6 +15,7 @@ * reserved. * Copyright (c) 2007 Voltaire. All rights reserved. * Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. * * $COPYRIGHT$ * diff --git a/opal/mca/threads/pthreads/Makefile.am b/opal/mca/threads/pthreads/Makefile.am index 41d7fb90e72..7cd56b60242 100644 --- a/opal/mca/threads/pthreads/Makefile.am +++ b/opal/mca/threads/pthreads/Makefile.am @@ -10,6 +10,7 @@ # Copyright (c) 2004-2005 The Regents of the University of California. # All rights reserved. # Copyright (c) 2008 Cisco Systems, Inc. All rights reserved. +# Copyright (c) 2019 Sandia National Laboratories. All rights reserved. # $COPYRIGHT$ # # Additional copyrights may follow diff --git a/opal/mca/threads/pthreads/configure.m4 b/opal/mca/threads/pthreads/configure.m4 index 2fc3f4a1883..023faac62ad 100644 --- a/opal/mca/threads/pthreads/configure.m4 +++ b/opal/mca/threads/pthreads/configure.m4 @@ -13,6 +13,8 @@ # Copyright (c) 2010 Cisco Systems, Inc. All rights reserved. # Copyright (c) 2015 Research Organization for Information Science # and Technology (RIST). All rights reserved. +# Copyright (c) 2019 Sandia National Laboratories. All rights reserved. +# Copyright (c) 2019 Triad National Security, LLC. All rights # $COPYRIGHT$ # # Additional copyrights may follow @@ -50,10 +52,8 @@ AC_DEFUN([MCA_opal_threads_pthreads_CONFIG],[ [threads_pthreads_happy="no"])]) AS_IF([test "$threads_pthreads_happy" = "yes"], - [AC_CHECK_HEADERS([mach/mach_time.h]) - AC_CHECK_FUNC([mach_absolute_time], - [threads_pthreads_happy="yes"], - [threads_pthreads_happy="no"])]) + [OPAL_CONFIG_POSIX_THREADS([threads_pthreads_happy="yes"], + [threads_pthreads_happy="no"])]) AS_IF([test "$threads_pthreads_happy" = "no" && \ test "$threads_pthreads_should_use" = "1"], diff --git a/opal/mca/threads/pthreads/mutex_unix.h b/opal/mca/threads/pthreads/mutex_unix.h index 56802473590..59d4cff48db 100644 --- a/opal/mca/threads/pthreads/mutex_unix.h +++ b/opal/mca/threads/pthreads/mutex_unix.h @@ -14,6 +14,8 @@ * reserved. * Copyright (c) 2015-2016 Research Organization for Information Science * and Technology (RIST). All rights reserved. + * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. + * * $COPYRIGHT$ * * Additional copyrights may follow diff --git a/opal/mca/threads/pthreads/threads_pthreads.h b/opal/mca/threads/pthreads/threads_pthreads.h deleted file mode 100644 index 8b137891791..00000000000 --- a/opal/mca/threads/pthreads/threads_pthreads.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/opal/mca/threads/pthreads/threads_pthreads_component.c b/opal/mca/threads/pthreads/threads_pthreads_component.c index 2441a74a228..2f8f963ba03 100644 --- a/opal/mca/threads/pthreads/threads_pthreads_component.c +++ b/opal/mca/threads/pthreads/threads_pthreads_component.c @@ -12,6 +12,8 @@ * All rights reserved. * Copyright (c) 2007-2015 Los Alamos National Security, LLC. All rights * reserved. + * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. + * * $COPYRIGHT$ * * Additional copyrights may follow diff --git a/opal/mca/threads/pthreads/threads_pthreads_condition.c b/opal/mca/threads/pthreads/threads_pthreads_condition.c index bdc8a67f214..6e7c2868569 100644 --- a/opal/mca/threads/pthreads/threads_pthreads_condition.c +++ b/opal/mca/threads/pthreads/threads_pthreads_condition.c @@ -9,6 +9,8 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. + * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. + * * $COPYRIGHT$ * * Additional copyrights may follow diff --git a/opal/mca/threads/pthreads/threads_pthreads_mutex.c b/opal/mca/threads/pthreads/threads_pthreads_mutex.c index 68e26383256..32b721c76e3 100644 --- a/opal/mca/threads/pthreads/threads_pthreads_mutex.c +++ b/opal/mca/threads/pthreads/threads_pthreads_mutex.c @@ -14,6 +14,8 @@ * reserved. * Copyright (c) 2015 Research Organization for Information Science * and Technology (RIST). All rights reserved. + * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. + * * $COPYRIGHT$ * * Additional copyrights may follow diff --git a/opal/mca/threads/pthreads/threads_pthreads_wait_sync.c b/opal/mca/threads/pthreads/threads_pthreads_wait_sync.c index 8f128adab6c..21a8943c5d7 100644 --- a/opal/mca/threads/pthreads/threads_pthreads_wait_sync.c +++ b/opal/mca/threads/pthreads/threads_pthreads_wait_sync.c @@ -6,6 +6,8 @@ * Copyright (c) 2016 Los Alamos National Security, LLC. All rights * reserved. * Copyright (c) 2017 IBM Corporation. All rights reserved. + * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. + * * $COPYRIGHT$ * * Additional copyrights may follow diff --git a/opal/mca/threads/thread.h b/opal/mca/threads/thread.h index 932cde3cfff..4740d08b60c 100644 --- a/opal/mca/threads/thread.h +++ b/opal/mca/threads/thread.h @@ -12,6 +12,8 @@ * All rights reserved. * Copyright (c) 2015 Los Alamos National Security, LLC. All rights * reserved. + * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. + * * $COPYRIGHT$ * * Additional copyrights may follow diff --git a/opal/mca/threads/thread_usage.h b/opal/mca/threads/thread_usage.h index 2f8e8945b3d..c9542d863bf 100644 --- a/opal/mca/threads/thread_usage.h +++ b/opal/mca/threads/thread_usage.h @@ -15,6 +15,7 @@ * and Technology (RIST). All rights reserved. * Copyright (c) 2015-2016 Los Alamos National Security, LLC. All rights * reserved. + * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow diff --git a/opal/mca/threads/threads.h b/opal/mca/threads/threads.h index 6055ee3840a..5f63b677498 100644 --- a/opal/mca/threads/threads.h +++ b/opal/mca/threads/threads.h @@ -14,6 +14,7 @@ * Copyright (c) 2015-2017 Research Organization for Information Science * and Technology (RIST). All rights reserved. * Copyright (c) 2017 Intel, Inc. All rights reserved. + * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow diff --git a/opal/mca/threads/tsd.h b/opal/mca/threads/tsd.h index 51623978522..a9ff4d06684 100644 --- a/opal/mca/threads/tsd.h +++ b/opal/mca/threads/tsd.h @@ -4,6 +4,8 @@ * Copyright (c) 2008 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2015-2017 Research Organization for Information Science * and Technology (RIST). All rights reserved. + * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. + * * $COPYRIGHT$ * * Additional copyrights may follow diff --git a/opal/mca/threads/wait_sync.h b/opal/mca/threads/wait_sync.h index 5159a2b2a1d..316ef5a394a 100644 --- a/opal/mca/threads/wait_sync.h +++ b/opal/mca/threads/wait_sync.h @@ -9,6 +9,7 @@ * Copyright (c) 2016 Research Organization for Information Science * and Technology (RIST). All rights reserved. * Copyright (c) 2017 IBM Corporation. All rights reserved. + * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow From ca2f98edb7c466485a4f54f213d0130d7dc89b27 Mon Sep 17 00:00:00 2001 From: Noah Evans Date: Tue, 5 Feb 2019 13:25:00 -0700 Subject: [PATCH 03/17] fix thread_usage.h Signed-off-by: Noah Evans --- opal/mca/threads/base/Makefile.am | 3 +- opal/mca/threads/base/threads_base_null.h | 54 ---- opal/mca/threads/configure.m4 | 6 - opal/mca/threads/mutex.h | 17 +- opal/mca/threads/pthreads/mutex_unix.h | 18 +- opal/mca/threads/pthreads/threads_base_null.h | 62 ----- .../pthreads/threads_pthreads_module.c | 4 - opal/mca/threads/qthreads/threads_base_null.h | 62 ----- .../threads/qthreads/threads_base_null.htmp | 62 ----- opal/mca/threads/thread_usage.h | 158 ++++++++--- opal/runtime/opal_init.c | 3 +- opal/threads/thread_usage.h | 261 +----------------- 12 files changed, 147 insertions(+), 563 deletions(-) delete mode 100644 opal/mca/threads/base/threads_base_null.h delete mode 100644 opal/mca/threads/pthreads/threads_base_null.h delete mode 100644 opal/mca/threads/qthreads/threads_base_null.h delete mode 100644 opal/mca/threads/qthreads/threads_base_null.htmp diff --git a/opal/mca/threads/base/Makefile.am b/opal/mca/threads/base/Makefile.am index 1d7f2c74fb1..d0e6710ce01 100644 --- a/opal/mca/threads/base/Makefile.am +++ b/opal/mca/threads/base/Makefile.am @@ -19,8 +19,7 @@ # headers += \ - base/base.h \ - base/threads_base_null.h + base/base.h libmca_threads_la_SOURCES += \ base/threads_base_open.c diff --git a/opal/mca/threads/base/threads_base_null.h b/opal/mca/threads/base/threads_base_null.h deleted file mode 100644 index 41002423466..00000000000 --- a/opal/mca/threads/base/threads_base_null.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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. - * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, - * University of Stuttgart. All rights reserved. - * Copyright (c) 2004-2005 The Regents of the University of California. - * All rights reserved. - * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. - * $COPYRIGHT$ - * - * Additional copyrights may follow - * - * $HEADER$ - */ - -#ifndef OPAL_MCA_TIMER_BASE_TIMER_BASE_NULL_H -#define OPAL_MCA_TIMER_BASE_TIMER_BASE_NULL_H - -int opal_condition_t_class; -int opal_mutex_t_class; -int opal_recursive_mutex_t_class; - -int opal_thread_join(opal_thread_t *t, void **thr_return) -{ - return 0; -} - -void opal_thread_set_main() -{ - return 0; -} -int opal_thread_start(opal_thread_t *t) -{ - return 0; -} - -int *opal_thread_t_class = NULL; - -int opal_tsd_key_create(opal_tsd_key_t *key, opal_tsd_destructor_t destructor) -{ - return 0; -} - -int opal_uses_threads = 0; - -int opal_tsd_keys_destruct() -{ - return 0; -} -#endif diff --git a/opal/mca/threads/configure.m4 b/opal/mca/threads/configure.m4 index 29d586e3be8..d051dbb8b43 100644 --- a/opal/mca/threads/configure.m4 +++ b/opal/mca/threads/configure.m4 @@ -35,13 +35,7 @@ AC_DEFUN([MCA_opal_threads_CONFIG],[ # first, compile all the components MCA_CONFIGURE_FRAMEWORK($1, $2, 1) - # someone should have set this... - if test "$threads_base_include" = "" ; then - threads_base_include="base/threads_base_null.h" - fi - if test "$mutex_base_include" = "" ; then -# mutex_base_include="base/mutex_base_null.h" mutex_base_include="pthreads/mutex_unix.h" fi AC_DEFINE_UNQUOTED([MCA_threads_IMPLEMENTATION_HEADER], diff --git a/opal/mca/threads/mutex.h b/opal/mca/threads/mutex.h index ff87bcbe9f3..e28265941d4 100644 --- a/opal/mca/threads/mutex.h +++ b/opal/mca/threads/mutex.h @@ -29,24 +29,26 @@ #include "opal_config.h" -#include MCA_mutex_IMPLEMENTATION_HEADER - -BEGIN_C_DECLS - /** - * @file: +* @file: * * Mutual exclusion functions. * * Functions for locking of critical sections. */ + /** * Opaque mutex object */ + typedef struct opal_mutex_t opal_mutex_t; typedef struct opal_mutex_t opal_recursive_mutex_t; +BEGIN_C_DECLS +#include MCA_mutex_IMPLEMENTATION_HEADER +END_C_DECLS + OBJ_CLASS_DECLARATION(opal_mutex_t); OBJ_CLASS_DECLARATION(opal_recursive_mutex_t); @@ -100,11 +102,6 @@ static inline void opal_mutex_atomic_lock(opal_mutex_t *mutex); */ static inline void opal_mutex_atomic_unlock(opal_mutex_t *mutex); -END_C_DECLS - -#include MCA_mutex_IMPLEMENTATION_HEADER - -BEGIN_C_DECLS /** * Lock a mutex if opal_using_threads() says that multiple threads may diff --git a/opal/mca/threads/pthreads/mutex_unix.h b/opal/mca/threads/pthreads/mutex_unix.h index 59d4cff48db..9d5f0bfa213 100644 --- a/opal/mca/threads/pthreads/mutex_unix.h +++ b/opal/mca/threads/pthreads/mutex_unix.h @@ -118,7 +118,7 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_recursive_mutex_t); * ************************************************************************/ -static inline int opal_mutex_trylock(struct opal_mutex_t *m) +static inline int opal_mutex_trylock(opal_mutex_t *m) { #if OPAL_ENABLE_DEBUG int ret = pthread_mutex_trylock(&m->m_lock_pthread); @@ -133,7 +133,7 @@ static inline int opal_mutex_trylock(struct opal_mutex_t *m) #endif } -static inline void opal_mutex_lock(struct opal_mutex_t *m) +static inline void opal_mutex_lock(opal_mutex_t *m) { #if OPAL_ENABLE_DEBUG int ret = pthread_mutex_lock(&m->m_lock_pthread); @@ -147,7 +147,7 @@ static inline void opal_mutex_lock(struct opal_mutex_t *m) #endif } -static inline void opal_mutex_unlock(struct opal_mutex_t *m) +static inline void opal_mutex_unlock(opal_mutex_t *m) { #if OPAL_ENABLE_DEBUG int ret = pthread_mutex_unlock(&m->m_lock_pthread); @@ -173,17 +173,17 @@ static inline void opal_mutex_unlock(struct opal_mutex_t *m) * Spin Locks ************************************************************************/ -static inline int opal_mutex_atomic_trylock(struct opal_mutex_t *m) +static inline int opal_mutex_atomic_trylock(opal_mutex_t *m) { return opal_atomic_trylock(&m->m_lock_atomic); } -static inline void opal_mutex_atomic_lock(struct opal_mutex_t *m) +static inline void opal_mutex_atomic_lock(opal_mutex_t *m) { opal_atomic_lock(&m->m_lock_atomic); } -static inline void opal_mutex_atomic_unlock(struct opal_mutex_t *m) +static inline void opal_mutex_atomic_unlock(opal_mutex_t *m) { opal_atomic_unlock(&m->m_lock_atomic); } @@ -194,17 +194,17 @@ static inline void opal_mutex_atomic_unlock(struct opal_mutex_t *m) * Standard locking ************************************************************************/ -static inline int opal_mutex_atomic_trylock(struct opal_mutex_t *m) +static inline int opal_mutex_atomic_trylock(opal_mutex_t *m) { return opal_mutex_trylock(m); } -static inline void opal_mutex_atomic_lock(struct opal_mutex_t *m) +static inline void opal_mutex_atomic_lock(opal_mutex_t *m) { opal_mutex_lock(m); } -static inline void opal_mutex_atomic_unlock(struct opal_mutex_t *m) +static inline void opal_mutex_atomic_unlock(opal_mutex_t *m) { opal_mutex_unlock(m); } diff --git a/opal/mca/threads/pthreads/threads_base_null.h b/opal/mca/threads/pthreads/threads_base_null.h deleted file mode 100644 index 8c662351281..00000000000 --- a/opal/mca/threads/pthreads/threads_base_null.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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. - * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, - * University of Stuttgart. All rights reserved. - * Copyright (c) 2004-2005 The Regents of the University of California. - * All rights reserved. - * $COPYRIGHT$ - * - * Additional copyrights may follow - * - * $HEADER$ - */ - -#ifndef OPAL_MCA_TIMER_BASE_TIMER_BASE_NULL_H -#define OPAL_MCA_TIMER_BASE_TIMER_BASE_NULL_H - -opal_class_t opal_condition_t_class; -opal_class_t opal_mutex_t_class; -opal_class_t opal_recursive_mutex_t_class; - -opal_thread_t *opal_thread_get_self(void) { - return NULL; -} - -bool opal_thread_self_compare(opal_thread_t *t) { - return 0; -} - -int sync_wait_mt(void *p) { - return 0; -} - -int opal_thread_join(opal_thread_t *t, void **thr_return) { - return 0; -} - -void opal_thread_set_main() { -} - -int opal_thread_start(opal_thread_t *t) { - return 0; -} -opal_class_t opal_thread_t_class; - -typedef int opal_tsd_key_t; -typedef int opal_tsd_destructor_t; - -int opal_tsd_key_create(opal_tsd_key_t *key, opal_tsd_destructor_t destructor) -{ - return 0; -} -bool opal_uses_threads = 0; -int opal_tsd_keys_destruct() -{ - return 0; -} -#endif diff --git a/opal/mca/threads/pthreads/threads_pthreads_module.c b/opal/mca/threads/pthreads/threads_pthreads_module.c index 60d88a0191e..7d2ae55965a 100644 --- a/opal/mca/threads/pthreads/threads_pthreads_module.c +++ b/opal/mca/threads/pthreads/threads_pthreads_module.c @@ -60,10 +60,6 @@ bool opal_thread_self_compare(opal_thread_t *t) return t->t_handle == pthread_self(); } -int sync_wait_mt(void *p) { - return 0; -} - int opal_thread_join(opal_thread_t *t, void **thr_return) { int rc = pthread_join(t->t_handle, thr_return); t->t_handle = (pthread_t) -1; diff --git a/opal/mca/threads/qthreads/threads_base_null.h b/opal/mca/threads/qthreads/threads_base_null.h deleted file mode 100644 index 8c662351281..00000000000 --- a/opal/mca/threads/qthreads/threads_base_null.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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. - * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, - * University of Stuttgart. All rights reserved. - * Copyright (c) 2004-2005 The Regents of the University of California. - * All rights reserved. - * $COPYRIGHT$ - * - * Additional copyrights may follow - * - * $HEADER$ - */ - -#ifndef OPAL_MCA_TIMER_BASE_TIMER_BASE_NULL_H -#define OPAL_MCA_TIMER_BASE_TIMER_BASE_NULL_H - -opal_class_t opal_condition_t_class; -opal_class_t opal_mutex_t_class; -opal_class_t opal_recursive_mutex_t_class; - -opal_thread_t *opal_thread_get_self(void) { - return NULL; -} - -bool opal_thread_self_compare(opal_thread_t *t) { - return 0; -} - -int sync_wait_mt(void *p) { - return 0; -} - -int opal_thread_join(opal_thread_t *t, void **thr_return) { - return 0; -} - -void opal_thread_set_main() { -} - -int opal_thread_start(opal_thread_t *t) { - return 0; -} -opal_class_t opal_thread_t_class; - -typedef int opal_tsd_key_t; -typedef int opal_tsd_destructor_t; - -int opal_tsd_key_create(opal_tsd_key_t *key, opal_tsd_destructor_t destructor) -{ - return 0; -} -bool opal_uses_threads = 0; -int opal_tsd_keys_destruct() -{ - return 0; -} -#endif diff --git a/opal/mca/threads/qthreads/threads_base_null.htmp b/opal/mca/threads/qthreads/threads_base_null.htmp deleted file mode 100644 index 8c662351281..00000000000 --- a/opal/mca/threads/qthreads/threads_base_null.htmp +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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. - * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, - * University of Stuttgart. All rights reserved. - * Copyright (c) 2004-2005 The Regents of the University of California. - * All rights reserved. - * $COPYRIGHT$ - * - * Additional copyrights may follow - * - * $HEADER$ - */ - -#ifndef OPAL_MCA_TIMER_BASE_TIMER_BASE_NULL_H -#define OPAL_MCA_TIMER_BASE_TIMER_BASE_NULL_H - -opal_class_t opal_condition_t_class; -opal_class_t opal_mutex_t_class; -opal_class_t opal_recursive_mutex_t_class; - -opal_thread_t *opal_thread_get_self(void) { - return NULL; -} - -bool opal_thread_self_compare(opal_thread_t *t) { - return 0; -} - -int sync_wait_mt(void *p) { - return 0; -} - -int opal_thread_join(opal_thread_t *t, void **thr_return) { - return 0; -} - -void opal_thread_set_main() { -} - -int opal_thread_start(opal_thread_t *t) { - return 0; -} -opal_class_t opal_thread_t_class; - -typedef int opal_tsd_key_t; -typedef int opal_tsd_destructor_t; - -int opal_tsd_key_create(opal_tsd_key_t *key, opal_tsd_destructor_t destructor) -{ - return 0; -} -bool opal_uses_threads = 0; -int opal_tsd_keys_destruct() -{ - return 0; -} -#endif diff --git a/opal/mca/threads/thread_usage.h b/opal/mca/threads/thread_usage.h index c9542d863bf..92e0031a751 100644 --- a/opal/mca/threads/thread_usage.h +++ b/opal/mca/threads/thread_usage.h @@ -13,9 +13,9 @@ * Copyright (c) 2007-2014 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2014-2016 Research Organization for Information Science * and Technology (RIST). All rights reserved. - * Copyright (c) 2015-2016 Los Alamos National Security, LLC. All rights + * Copyright (c) 2015-2018 Los Alamos National Security, LLC. All rights * reserved. - * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. + * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -23,7 +23,6 @@ * $HEADER$ */ -/* Should this go in mca/threads/base? */ #if !defined(OPAL_MCA_THREAD_USAGE_H) #define OPAL_MCA_THREAD_USAGE_H @@ -95,46 +94,50 @@ static inline bool opal_set_using_threads(bool have) * indicates that threads are in use by the application or library. */ -#define OPAL_THREAD_DEFINE_ATOMIC_ADD(type, suffix) \ -static inline type opal_thread_add_ ## suffix (volatile type *addr, type delta) \ +#define OPAL_THREAD_DEFINE_ATOMIC_OP(type, name, operator, suffix) \ +static inline type opal_thread_ ## name ## _fetch_ ## suffix (opal_atomic_ ## type *addr, type delta) \ { \ if (OPAL_UNLIKELY(opal_using_threads())) { \ - return opal_atomic_add_ ## suffix (addr, delta); \ + return opal_atomic_ ## name ## _fetch_ ## suffix (addr, delta); \ } \ \ - return (*addr += delta); \ -} - -#define OPAL_THREAD_DEFINE_ATOMIC_SUB(type, suffix) \ -static inline type opal_thread_sub_ ## suffix (volatile type *addr, type delta) \ + *addr = *addr operator delta; \ + return *addr; \ +} \ + \ +static inline type opal_thread_fetch_ ## name ## _ ## suffix (opal_atomic_ ## type *addr, type delta) \ { \ if (OPAL_UNLIKELY(opal_using_threads())) { \ - return opal_atomic_sub_ ## suffix (addr, delta); \ + return opal_atomic_fetch_ ## name ## _ ## suffix (addr, delta); \ } \ \ - return (*addr -= delta); \ + type old = *addr; \ + *addr = old operator delta; \ + return old; \ } -#define OPAL_THREAD_DEFINE_ATOMIC_CMPSET(type, addr_type, suffix) \ -static inline bool opal_thread_cmpset_bool_ ## suffix (volatile addr_type *addr, type compare, type value) \ +#define OPAL_THREAD_DEFINE_ATOMIC_COMPARE_EXCHANGE(type, addr_type, suffix) \ +static inline bool opal_thread_compare_exchange_strong_ ## suffix (opal_atomic_ ## addr_type *addr, type *compare, type value) \ { \ if (OPAL_UNLIKELY(opal_using_threads())) { \ - return opal_atomic_cmpset_ ## suffix ((volatile type *) addr, compare, value); \ + return opal_atomic_compare_exchange_strong_ ## suffix (addr, (addr_type *) compare, (addr_type) value); \ } \ \ - if ((type) *addr == compare) { \ + if ((type) *addr == *compare) { \ ((type *) addr)[0] = value; \ return true; \ } \ \ + *compare = ((type *) addr)[0]; \ + \ return false; \ } #define OPAL_THREAD_DEFINE_ATOMIC_SWAP(type, addr_type, suffix) \ -static inline type opal_thread_swap_ ## suffix (volatile addr_type *ptr, type newvalue) \ +static inline type opal_thread_swap_ ## suffix (opal_atomic_ ## addr_type *ptr, type newvalue) \ { \ if (opal_using_threads ()) { \ - return opal_atomic_swap_ ## suffix ((volatile type *) ptr, newvalue); \ + return (type) opal_atomic_swap_ ## suffix (ptr, (addr_type) newvalue); \ } \ \ type old = ((type *) ptr)[0]; \ @@ -143,51 +146,122 @@ static inline type opal_thread_swap_ ## suffix (volatile addr_type *ptr, type ne return old; \ } -OPAL_THREAD_DEFINE_ATOMIC_ADD(int32_t, 32) -OPAL_THREAD_DEFINE_ATOMIC_ADD(size_t, size_t) -OPAL_THREAD_DEFINE_ATOMIC_SUB(size_t, size_t) -OPAL_THREAD_DEFINE_ATOMIC_CMPSET(int32_t, int32_t, 32) -OPAL_THREAD_DEFINE_ATOMIC_CMPSET(void *, intptr_t, ptr) +OPAL_THREAD_DEFINE_ATOMIC_OP(int32_t, add, +, 32) +OPAL_THREAD_DEFINE_ATOMIC_OP(size_t, add, +, size_t) +OPAL_THREAD_DEFINE_ATOMIC_OP(int32_t, and, &, 32) +OPAL_THREAD_DEFINE_ATOMIC_OP(int32_t, or, |, 32) +OPAL_THREAD_DEFINE_ATOMIC_OP(int32_t, xor, ^, 32) +OPAL_THREAD_DEFINE_ATOMIC_OP(int32_t, sub, -, 32) +OPAL_THREAD_DEFINE_ATOMIC_OP(size_t, sub, -, size_t) + +OPAL_THREAD_DEFINE_ATOMIC_COMPARE_EXCHANGE(int32_t, int32_t, 32) +OPAL_THREAD_DEFINE_ATOMIC_COMPARE_EXCHANGE(intptr_t, intptr_t, ptr) OPAL_THREAD_DEFINE_ATOMIC_SWAP(int32_t, int32_t, 32) -OPAL_THREAD_DEFINE_ATOMIC_SWAP(void *, intptr_t, ptr) +OPAL_THREAD_DEFINE_ATOMIC_SWAP(intptr_t, intptr_t, ptr) + +#define OPAL_THREAD_ADD_FETCH32 opal_thread_add_fetch_32 +#define OPAL_ATOMIC_ADD_FETCH32 opal_thread_add_fetch_32 + +#define OPAL_THREAD_AND_FETCH32 opal_thread_and_fetch_32 +#define OPAL_ATOMIC_AND_FETCH32 opal_thread_and_fetch_32 + +#define OPAL_THREAD_OR_FETCH32 opal_thread_or_fetch_32 +#define OPAL_ATOMIC_OR_FETCH32 opal_thread_or_fetch_32 + +#define OPAL_THREAD_XOR_FETCH32 opal_thread_xor_fetch_32 +#define OPAL_ATOMIC_XOR_FETCH32 opal_thread_xor_fetch_32 + +#define OPAL_THREAD_ADD_FETCH_SIZE_T opal_thread_add_fetch_size_t +#define OPAL_ATOMIC_ADD_FETCH_SIZE_T opal_thread_add_fetch_size_t + +#define OPAL_THREAD_SUB_FETCH_SIZE_T opal_thread_sub_fetch_size_t +#define OPAL_ATOMIC_SUB_FETCH_SIZE_T opal_thread_sub_fetch_size_t + +#define OPAL_THREAD_FETCH_ADD32 opal_thread_fetch_add_32 +#define OPAL_ATOMIC_FETCH_ADD32 opal_thread_fetch_add_32 -#define OPAL_THREAD_ADD32 opal_thread_add_32 -#define OPAL_ATOMIC_ADD32 opal_thread_add_32 +#define OPAL_THREAD_FETCH_AND32 opal_thread_fetch_and_32 +#define OPAL_ATOMIC_FETCH_AND32 opal_thread_fetch_and_32 -#define OPAL_THREAD_ADD_SIZE_T opal_thread_add_size_t -#define OPAL_ATOMIC_ADD_SIZE_T opal_thread_add_size_t +#define OPAL_THREAD_FETCH_OR32 opal_thread_fetch_or_32 +#define OPAL_ATOMIC_FETCH_OR32 opal_thread_fetch_or_32 -#define OPAL_THREAD_SUB_SIZE_T opal_thread_sub_size_t -#define OPAL_ATOMIC_SUB_SIZE_T opal_thread_sub_size_t +#define OPAL_THREAD_FETCH_XOR32 opal_thread_fetch_xor_32 +#define OPAL_ATOMIC_FETCH_XOR32 opal_thread_fetch_xor_32 -#define OPAL_THREAD_CMPSET_32 opal_thread_cmpset_bool_32 -#define OPAL_ATOMIC_CMPSET_32 opal_thread_cmpset_bool_32 +#define OPAL_THREAD_FETCH_ADD_SIZE_T opal_thread_fetch_add_size_t +#define OPAL_ATOMIC_FETCH_ADD_SIZE_T opal_thread_fetch_add_size_t -#define OPAL_THREAD_CMPSET_PTR(x, y, z) opal_thread_cmpset_bool_ptr ((volatile intptr_t *) x, (void *) y, (void *) z) -#define OPAL_ATOMIC_CMPSET_PTR OPAL_THREAD_CMPSET_PTR +#define OPAL_THREAD_FETCH_SUB_SIZE_T opal_thread_fetch_sub_size_t +#define OPAL_ATOMIC_FETCH_SUB_SIZE_T opal_thread_fetch_sub_size_t + +#define OPAL_THREAD_COMPARE_EXCHANGE_STRONG_32 opal_thread_compare_exchange_strong_32 +#define OPAL_ATOMIC_COMPARE_EXCHANGE_STRONG_32 opal_thread_compare_exchange_strong_32 + +#define OPAL_THREAD_COMPARE_EXCHANGE_STRONG_PTR(x, y, z) opal_thread_compare_exchange_strong_ptr ((opal_atomic_intptr_t *) x, (intptr_t *) y, (intptr_t) z) +#define OPAL_ATOMIC_COMPARE_EXCHANGE_STRONG_PTR OPAL_THREAD_COMPARE_EXCHANGE_STRONG_PTR #define OPAL_THREAD_SWAP_32 opal_thread_swap_32 #define OPAL_ATOMIC_SWAP_32 opal_thread_swap_32 -#define OPAL_THREAD_SWAP_PTR(x, y) opal_thread_swap_ptr ((volatile intptr_t *) x, (void *) y) +#define OPAL_THREAD_SWAP_PTR(x, y) opal_thread_swap_ptr ((opal_atomic_intptr_t *) x, (intptr_t) y) #define OPAL_ATOMIC_SWAP_PTR OPAL_THREAD_SWAP_PTR /* define 64-bit macros is 64-bit atomic math is available */ #if OPAL_HAVE_ATOMIC_MATH_64 -OPAL_THREAD_DEFINE_ATOMIC_ADD(int64_t, 64) -OPAL_THREAD_DEFINE_ATOMIC_CMPSET(int64_t, int64_t, 64) +OPAL_THREAD_DEFINE_ATOMIC_OP(int64_t, add, +, 64) +OPAL_THREAD_DEFINE_ATOMIC_OP(int64_t, and, &, 64) +OPAL_THREAD_DEFINE_ATOMIC_OP(int64_t, or, |, 64) +OPAL_THREAD_DEFINE_ATOMIC_OP(int64_t, xor, ^, 64) +OPAL_THREAD_DEFINE_ATOMIC_OP(int64_t, sub, -, 64) +OPAL_THREAD_DEFINE_ATOMIC_COMPARE_EXCHANGE(int64_t, int64_t, 64) OPAL_THREAD_DEFINE_ATOMIC_SWAP(int64_t, int64_t, 64) -#define OPAL_THREAD_ADD64 opal_thread_add_64 -#define OPAL_ATOMIC_ADD64 opal_thread_add_64 +#define OPAL_THREAD_ADD_FETCH64 opal_thread_add_fetch_64 +#define OPAL_ATOMIC_ADD_FETCH64 opal_thread_add_fetch_64 + +#define OPAL_THREAD_AND_FETCH64 opal_thread_and_fetch_64 +#define OPAL_ATOMIC_AND_FETCH64 opal_thread_and_fetch_64 + +#define OPAL_THREAD_OR_FETCH64 opal_thread_or_fetch_64 +#define OPAL_ATOMIC_OR_FETCH64 opal_thread_or_fetch_64 + +#define OPAL_THREAD_XOR_FETCH64 opal_thread_xor_fetch_64 +#define OPAL_ATOMIC_XOR_FETCH64 opal_thread_xor_fetch_64 + +#define OPAL_THREAD_FETCH_ADD64 opal_thread_fetch_add_64 +#define OPAL_ATOMIC_FETCH_ADD64 opal_thread_fetch_add_64 -#define OPAL_THREAD_CMPSET_64 opal_thread_cmpset_bool_64 -#define OPAL_ATOMIC_CMPSET_64 opal_thread_cmpset_bool_64 +#define OPAL_THREAD_FETCH_AND64 opal_thread_fetch_and_64 +#define OPAL_ATOMIC_FETCH_AND64 opal_thread_fetch_and_64 + +#define OPAL_THREAD_FETCH_OR64 opal_thread_fetch_or_64 +#define OPAL_ATOMIC_FETCH_OR64 opal_thread_fetch_or_64 + +#define OPAL_THREAD_FETCH_XOR64 opal_thread_fetch_xor_64 +#define OPAL_ATOMIC_FETCH_XOR64 opal_thread_fetch_xor_64 + +#define OPAL_THREAD_COMPARE_EXCHANGE_STRONG_64 opal_thread_compare_exchange_strong_64 +#define OPAL_ATOMIC_COMPARE_EXCHANGE_STRONG_64 opal_thread_compare_exchange_strong_64 #define OPAL_THREAD_SWAP_64 opal_thread_swap_64 #define OPAL_ATOMIC_SWAP_64 opal_thread_swap_64 #endif +/* thread local storage */ +#if OPAL_C_HAVE__THREAD_LOCAL +#define opal_thread_local _Thread_local +#define OPAL_HAVE_THREAD_LOCAL 1 + +#elif OPAL_C_HAVE___THREAD /* OPAL_C_HAVE__THREAD_LOCAL */ +#define opal_thread_local __thread +#define OPAL_HAVE_THREAD_LOCAL 1 +#endif /* OPAL_C_HAVE___THREAD */ + +#if !defined(OPAL_HAVE_THREAD_LOCAL) +#define OPAL_HAVE_THREAD_LOCAL 0 +#endif /* !defined(OPAL_HAVE_THREAD_LOCAL) */ + #endif /* !defined(OPAL_MCA_THREAD_USAGE_H) */ diff --git a/opal/runtime/opal_init.c b/opal/runtime/opal_init.c index 2db5b441165..7673a4137f5 100644 --- a/opal/runtime/opal_init.c +++ b/opal/runtime/opal_init.c @@ -70,6 +70,7 @@ #include "opal/runtime/opal_progress.h" #include "opal/mca/event/base/base.h" +#include "opal/mca/threads/base/base.h" #include "opal/mca/backtrace/base/base.h" #include "opal/constants.h" @@ -520,7 +521,7 @@ opal_init_util(int* pargc, char*** pargv) * versions of memcpy correctly configured. */ static mca_base_framework_t *opal_init_frameworks[] = { - &opal_hwloc_base_framework, &opal_memcpy_base_framework, &opal_memchecker_base_framework, + &opal_hwloc_base_framework, &opal_memcpy_base_framework, &opal_threads_base_framework, &opal_memchecker_base_framework, &opal_backtrace_base_framework, &opal_timer_base_framework, &opal_event_base_framework, &opal_shmem_base_framework, &opal_reachable_base_framework, &opal_compress_base_framework, NULL, diff --git a/opal/threads/thread_usage.h b/opal/threads/thread_usage.h index 8ce65362c1c..7d71bcb6d04 100644 --- a/opal/threads/thread_usage.h +++ b/opal/threads/thread_usage.h @@ -1,266 +1,29 @@ -/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ /* * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana * University Research and Technology * Corporation. All rights reserved. - * Copyright (c) 2004-2007 The University of Tennessee and The University + * Copyright (c) 2004-2006 The University of Tennessee and The University * of Tennessee Research Foundation. All rights * reserved. - * Copyright (c) 2004-2006 High Performance Computing Center Stuttgart, + * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. - * Copyright (c) 2007-2014 Cisco Systems, Inc. All rights reserved. - * Copyright (c) 2014-2016 Research Organization for Information Science + * Copyright (c) 2010 Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015-2017 Research Organization for Information Science * and Technology (RIST). All rights reserved. - * Copyright (c) 2015-2018 Los Alamos National Security, LLC. All rights - * reserved. + * Copyright (c) 2017 Intel, Inc. All rights reserved. * $COPYRIGHT$ - * - * Additional copyrights may follow - * - * $HEADER$ - */ - -#if !defined(OPAL_THREAD_USAGE_H) -#define OPAL_THREAD_USAGE_H - -#include "opal_config.h" - -#include "opal/sys/atomic.h" -#include "opal/prefetch.h" - -OPAL_DECLSPEC extern bool opal_uses_threads; - -/** - * Check and see if the process is using multiple threads. - * - * @retval true If the process may have more than one thread. - * @retval false If the process only has a single thread. - * - * The value that this function returns is influenced by: - * - * - how MPI_INIT or MPI_INIT_THREAD was invoked, - * - what the final MPI thread level was determined to be, - * - whether the OMPI or MPI libraries are multi-threaded - * - * MPI_INIT and MPI_INIT_THREAD (specifically, back-end OMPI startup - * functions) invoke opal_set_using_threads() to influence the value of - * this function, depending on their situation. Some examples: - * - * - if MPI_INIT is invoked, and the ompi components in use are - * single-threaded, this value will be false. - * - * - if MPI_INIT_THREAD is invoked with MPI_THREAD_MULTIPLE, we have - * thread support, and the final thread level is determined to be - * MPI_THREAD_MULTIPLE, this value will be true. * - * - if the process is a single-threaded OMPI executable (e.g., mpicc), - * this value will be false. - * - * Hence, this function will return false if there is guaranteed to - * only be one thread in the process. If there is even the - * possibility that we may have multiple threads, true will be - * returned. - */ -#define opal_using_threads() opal_uses_threads - -/** - * Set whether the process is using multiple threads or not. - * - * @param have Boolean indicating whether the process is using - * multiple threads or not. - * - * @retval opal_using_threads The new return value from - * opal_using_threads(). + * Additional copyrights may follow * - * This function is used to influence the return value of - * opal_using_threads(). If configure detected that we have thread - * support, the return value of future invocations of - * opal_using_threads() will be the parameter's value. If configure - * detected that we have no thread support, then the retuen from - * opal_using_threads() will always be false. - */ -static inline bool opal_set_using_threads(bool have) -{ - opal_uses_threads = have; - return opal_using_threads(); -} - - -/** - * Use an atomic operation for increment/decrement if opal_using_threads() - * indicates that threads are in use by the application or library. + * $HEADER$ */ -#define OPAL_THREAD_DEFINE_ATOMIC_OP(type, name, operator, suffix) \ -static inline type opal_thread_ ## name ## _fetch_ ## suffix (opal_atomic_ ## type *addr, type delta) \ -{ \ - if (OPAL_UNLIKELY(opal_using_threads())) { \ - return opal_atomic_ ## name ## _fetch_ ## suffix (addr, delta); \ - } \ - \ - *addr = *addr operator delta; \ - return *addr; \ -} \ - \ -static inline type opal_thread_fetch_ ## name ## _ ## suffix (opal_atomic_ ## type *addr, type delta) \ -{ \ - if (OPAL_UNLIKELY(opal_using_threads())) { \ - return opal_atomic_fetch_ ## name ## _ ## suffix (addr, delta); \ - } \ - \ - type old = *addr; \ - *addr = old operator delta; \ - return old; \ -} - -#define OPAL_THREAD_DEFINE_ATOMIC_COMPARE_EXCHANGE(type, addr_type, suffix) \ -static inline bool opal_thread_compare_exchange_strong_ ## suffix (opal_atomic_ ## addr_type *addr, type *compare, type value) \ -{ \ - if (OPAL_UNLIKELY(opal_using_threads())) { \ - return opal_atomic_compare_exchange_strong_ ## suffix (addr, (addr_type *) compare, (addr_type) value); \ - } \ - \ - if ((type) *addr == *compare) { \ - ((type *) addr)[0] = value; \ - return true; \ - } \ - \ - *compare = ((type *) addr)[0]; \ - \ - return false; \ -} - -#define OPAL_THREAD_DEFINE_ATOMIC_SWAP(type, addr_type, suffix) \ -static inline type opal_thread_swap_ ## suffix (opal_atomic_ ## addr_type *ptr, type newvalue) \ -{ \ - if (opal_using_threads ()) { \ - return (type) opal_atomic_swap_ ## suffix (ptr, (addr_type) newvalue); \ - } \ - \ - type old = ((type *) ptr)[0]; \ - ((type *) ptr)[0] = newvalue; \ - \ - return old; \ -} - -OPAL_THREAD_DEFINE_ATOMIC_OP(int32_t, add, +, 32) -OPAL_THREAD_DEFINE_ATOMIC_OP(size_t, add, +, size_t) -OPAL_THREAD_DEFINE_ATOMIC_OP(int32_t, and, &, 32) -OPAL_THREAD_DEFINE_ATOMIC_OP(int32_t, or, |, 32) -OPAL_THREAD_DEFINE_ATOMIC_OP(int32_t, xor, ^, 32) -OPAL_THREAD_DEFINE_ATOMIC_OP(int32_t, sub, -, 32) -OPAL_THREAD_DEFINE_ATOMIC_OP(size_t, sub, -, size_t) - -OPAL_THREAD_DEFINE_ATOMIC_COMPARE_EXCHANGE(int32_t, int32_t, 32) -OPAL_THREAD_DEFINE_ATOMIC_COMPARE_EXCHANGE(intptr_t, intptr_t, ptr) -OPAL_THREAD_DEFINE_ATOMIC_SWAP(int32_t, int32_t, 32) -OPAL_THREAD_DEFINE_ATOMIC_SWAP(intptr_t, intptr_t, ptr) - -#define OPAL_THREAD_ADD_FETCH32 opal_thread_add_fetch_32 -#define OPAL_ATOMIC_ADD_FETCH32 opal_thread_add_fetch_32 - -#define OPAL_THREAD_AND_FETCH32 opal_thread_and_fetch_32 -#define OPAL_ATOMIC_AND_FETCH32 opal_thread_and_fetch_32 - -#define OPAL_THREAD_OR_FETCH32 opal_thread_or_fetch_32 -#define OPAL_ATOMIC_OR_FETCH32 opal_thread_or_fetch_32 - -#define OPAL_THREAD_XOR_FETCH32 opal_thread_xor_fetch_32 -#define OPAL_ATOMIC_XOR_FETCH32 opal_thread_xor_fetch_32 - -#define OPAL_THREAD_ADD_FETCH_SIZE_T opal_thread_add_fetch_size_t -#define OPAL_ATOMIC_ADD_FETCH_SIZE_T opal_thread_add_fetch_size_t - -#define OPAL_THREAD_SUB_FETCH_SIZE_T opal_thread_sub_fetch_size_t -#define OPAL_ATOMIC_SUB_FETCH_SIZE_T opal_thread_sub_fetch_size_t - -#define OPAL_THREAD_FETCH_ADD32 opal_thread_fetch_add_32 -#define OPAL_ATOMIC_FETCH_ADD32 opal_thread_fetch_add_32 - -#define OPAL_THREAD_FETCH_AND32 opal_thread_fetch_and_32 -#define OPAL_ATOMIC_FETCH_AND32 opal_thread_fetch_and_32 - -#define OPAL_THREAD_FETCH_OR32 opal_thread_fetch_or_32 -#define OPAL_ATOMIC_FETCH_OR32 opal_thread_fetch_or_32 - -#define OPAL_THREAD_FETCH_XOR32 opal_thread_fetch_xor_32 -#define OPAL_ATOMIC_FETCH_XOR32 opal_thread_fetch_xor_32 - -#define OPAL_THREAD_FETCH_ADD_SIZE_T opal_thread_fetch_add_size_t -#define OPAL_ATOMIC_FETCH_ADD_SIZE_T opal_thread_fetch_add_size_t - -#define OPAL_THREAD_FETCH_SUB_SIZE_T opal_thread_fetch_sub_size_t -#define OPAL_ATOMIC_FETCH_SUB_SIZE_T opal_thread_fetch_sub_size_t - -#define OPAL_THREAD_COMPARE_EXCHANGE_STRONG_32 opal_thread_compare_exchange_strong_32 -#define OPAL_ATOMIC_COMPARE_EXCHANGE_STRONG_32 opal_thread_compare_exchange_strong_32 - -#define OPAL_THREAD_COMPARE_EXCHANGE_STRONG_PTR(x, y, z) opal_thread_compare_exchange_strong_ptr ((opal_atomic_intptr_t *) x, (intptr_t *) y, (intptr_t) z) -#define OPAL_ATOMIC_COMPARE_EXCHANGE_STRONG_PTR OPAL_THREAD_COMPARE_EXCHANGE_STRONG_PTR - -#define OPAL_THREAD_SWAP_32 opal_thread_swap_32 -#define OPAL_ATOMIC_SWAP_32 opal_thread_swap_32 - -#define OPAL_THREAD_SWAP_PTR(x, y) opal_thread_swap_ptr ((opal_atomic_intptr_t *) x, (intptr_t) y) -#define OPAL_ATOMIC_SWAP_PTR OPAL_THREAD_SWAP_PTR - -/* define 64-bit macros is 64-bit atomic math is available */ -#if OPAL_HAVE_ATOMIC_MATH_64 - -OPAL_THREAD_DEFINE_ATOMIC_OP(int64_t, add, +, 64) -OPAL_THREAD_DEFINE_ATOMIC_OP(int64_t, and, &, 64) -OPAL_THREAD_DEFINE_ATOMIC_OP(int64_t, or, |, 64) -OPAL_THREAD_DEFINE_ATOMIC_OP(int64_t, xor, ^, 64) -OPAL_THREAD_DEFINE_ATOMIC_OP(int64_t, sub, -, 64) -OPAL_THREAD_DEFINE_ATOMIC_COMPARE_EXCHANGE(int64_t, int64_t, 64) -OPAL_THREAD_DEFINE_ATOMIC_SWAP(int64_t, int64_t, 64) - -#define OPAL_THREAD_ADD_FETCH64 opal_thread_add_fetch_64 -#define OPAL_ATOMIC_ADD_FETCH64 opal_thread_add_fetch_64 - -#define OPAL_THREAD_AND_FETCH64 opal_thread_and_fetch_64 -#define OPAL_ATOMIC_AND_FETCH64 opal_thread_and_fetch_64 - -#define OPAL_THREAD_OR_FETCH64 opal_thread_or_fetch_64 -#define OPAL_ATOMIC_OR_FETCH64 opal_thread_or_fetch_64 - -#define OPAL_THREAD_XOR_FETCH64 opal_thread_xor_fetch_64 -#define OPAL_ATOMIC_XOR_FETCH64 opal_thread_xor_fetch_64 - -#define OPAL_THREAD_FETCH_ADD64 opal_thread_fetch_add_64 -#define OPAL_ATOMIC_FETCH_ADD64 opal_thread_fetch_add_64 - -#define OPAL_THREAD_FETCH_AND64 opal_thread_fetch_and_64 -#define OPAL_ATOMIC_FETCH_AND64 opal_thread_fetch_and_64 - -#define OPAL_THREAD_FETCH_OR64 opal_thread_fetch_or_64 -#define OPAL_ATOMIC_FETCH_OR64 opal_thread_fetch_or_64 - -#define OPAL_THREAD_FETCH_XOR64 opal_thread_fetch_xor_64 -#define OPAL_ATOMIC_FETCH_XOR64 opal_thread_fetch_xor_64 - -#define OPAL_THREAD_COMPARE_EXCHANGE_STRONG_64 opal_thread_compare_exchange_strong_64 -#define OPAL_ATOMIC_COMPARE_EXCHANGE_STRONG_64 opal_thread_compare_exchange_strong_64 - -#define OPAL_THREAD_SWAP_64 opal_thread_swap_64 -#define OPAL_ATOMIC_SWAP_64 opal_thread_swap_64 - -#endif - -/* thread local storage */ -#if OPAL_C_HAVE__THREAD_LOCAL -#define opal_thread_local _Thread_local -#define OPAL_HAVE_THREAD_LOCAL 1 - -#elif OPAL_C_HAVE___THREAD /* OPAL_C_HAVE__THREAD_LOCAL */ -#define opal_thread_local __thread -#define OPAL_HAVE_THREAD_LOCAL 1 -#endif /* OPAL_C_HAVE___THREAD */ +#ifndef OPAL_THREAD_USAGE_H +#define OPAL_THREAD_USAGE_H 1 -#if !defined(OPAL_HAVE_THREAD_LOCAL) -#define OPAL_HAVE_THREAD_LOCAL 0 -#endif /* !defined(OPAL_HAVE_THREAD_LOCAL) */ +#include "opal/mca/threads/thread_usage.h" -#endif /* !defined(OPAL_THREAD_USAGE_H) */ +#endif /* OPAL_THREAD_USAGE_H */ From 8e99c68f58488bdc75c7e34d80e3d8776915eebc Mon Sep 17 00:00:00 2001 From: Shintaro Iwasaki Date: Wed, 6 Feb 2019 16:14:19 -0600 Subject: [PATCH 04/17] mca/threads: fix Pthreads mutex implementation. Signed-off-by: Shintaro Iwasaki --- opal/mca/pmix/base/base.h | 14 +-- opal/mca/threads/configure.m4 | 24 +++-- opal/mca/threads/mutex.h | 5 +- opal/mca/threads/pthreads/Makefile.am | 9 +- opal/mca/threads/pthreads/configure.m4 | 12 ++- .../pthreads/threads_pthreads_component.c | 1 - .../threads/pthreads/threads_pthreads_mutex.c | 53 ++++++++-- ...{mutex_unix.h => threads_pthreads_mutex.h} | 14 ++- .../pthreads/threads_pthreads_threads.h | 15 +++ .../threads/pthreads/threads_pthreads_tsd.h | 29 ++++++ .../pthreads/threads_pthreads_wait_sync.h | 77 +++++++++++++++ .../threads/qthreads/threads_qthreads.htmp | 96 ------------------- opal/mca/threads/threads.h | 11 +-- opal/mca/threads/tsd.h | 21 +--- opal/mca/threads/wait_sync.h | 73 +------------- opal/mca/timer/linux/timer_linux_component.c | 1 + orte/util/threads.h | 14 +-- 17 files changed, 228 insertions(+), 241 deletions(-) rename opal/mca/threads/pthreads/{mutex_unix.h => threads_pthreads_mutex.h} (91%) create mode 100644 opal/mca/threads/pthreads/threads_pthreads_threads.h create mode 100644 opal/mca/threads/pthreads/threads_pthreads_tsd.h create mode 100644 opal/mca/threads/pthreads/threads_pthreads_wait_sync.h delete mode 100644 opal/mca/threads/qthreads/threads_qthreads.htmp diff --git a/opal/mca/pmix/base/base.h b/opal/mca/pmix/base/base.h index 83365891070..277e598cf30 100644 --- a/opal/mca/pmix/base/base.h +++ b/opal/mca/pmix/base/base.h @@ -55,11 +55,11 @@ OPAL_DECLSPEC int opal_pmix_base_exchange(opal_value_t *info, OPAL_DECLSPEC void opal_pmix_base_set_evbase(opal_event_base_t *evbase); -#define opal_pmix_condition_wait(a,b) pthread_cond_wait(a, &(b)->m_lock_pthread) -typedef pthread_cond_t opal_pmix_condition_t; -#define opal_pmix_condition_broadcast(a) pthread_cond_broadcast(a) -#define opal_pmix_condition_signal(a) pthread_cond_signal(a) -#define OPAL_PMIX_CONDITION_STATIC_INIT PTHREAD_COND_INITIALIZER +#define opal_pmix_condition_wait(a,b) opal_cond_wait(a, b) +typedef opal_cond_t opal_pmix_condition_t; +#define opal_pmix_condition_broadcast(a) opal_cond_broadcast(a) +#define opal_pmix_condition_signal(a) opal_cond_signal(a) +#define OPAL_PMIX_CONDITION_STATIC_INIT OPAL_CONDITION_STATIC_INIT typedef struct { opal_mutex_t mutex; @@ -81,7 +81,7 @@ extern opal_pmix_base_t opal_pmix_base; #define OPAL_PMIX_CONSTRUCT_LOCK(l) \ do { \ OBJ_CONSTRUCT(&(l)->mutex, opal_mutex_t); \ - pthread_cond_init(&(l)->cond, NULL); \ + opal_cond_init(&(l)->cond); \ (l)->active = true; \ OPAL_POST_OBJECT((l)); \ } while(0) @@ -90,7 +90,7 @@ extern opal_pmix_base_t opal_pmix_base; do { \ OPAL_ACQUIRE_OBJECT((l)); \ OBJ_DESTRUCT(&(l)->mutex); \ - pthread_cond_destroy(&(l)->cond); \ + opal_cond_destroy(&(l)->cond); \ } while(0) diff --git a/opal/mca/threads/configure.m4 b/opal/mca/threads/configure.m4 index d051dbb8b43..dd10a05edf8 100644 --- a/opal/mca/threads/configure.m4 +++ b/opal/mca/threads/configure.m4 @@ -25,19 +25,23 @@ m4_define(MCA_opal_threads_CONFIGURE_MODE, STOP_AT_FIRST) AC_DEFINE_UNQUOTED([OPAL_ENABLE_MULTI_THREADS], [1], [Whether we should enable thread support within the OPAL code base]) AC_DEFUN([MCA_opal_threads_CONFIG],[ - threads_base_include= - # All components look at this value AC_ARG_WITH([threads], [AC_HELP_STRING([--with-threads=TYPE], - [Build high resolution threads component TYPE])]) + [Build high resolution threads component TYPE])], + [], + [with_threads=pthreads]) + + thread_type=$with_threads # first, compile all the components MCA_CONFIGURE_FRAMEWORK($1, $2, 1) - if test "$mutex_base_include" = "" ; then - mutex_base_include="pthreads/mutex_unix.h" - fi + threads_base_include="${thread_type}/threads_${thread_type}_threads.h" + mutex_base_include="${thread_type}/threads_${thread_type}_mutex.h" + tsd_base_include="${thread_type}/threads_${thread_type}_tsd.h" + wait_sync_base_include="${thread_type}/threads_${thread_type}_wait_sync.h" + AC_DEFINE_UNQUOTED([MCA_threads_IMPLEMENTATION_HEADER], ["opal/mca/threads/$threads_base_include"], [Header to include for threads implementation]) @@ -45,6 +49,12 @@ AC_DEFUN([MCA_opal_threads_CONFIG],[ AC_DEFINE_UNQUOTED([MCA_mutex_IMPLEMENTATION_HEADER], ["opal/mca/threads/$mutex_base_include"], [Header to include for mutex implementation]) -]) + AC_DEFINE_UNQUOTED([MCA_tsd_IMPLEMENTATION_HEADER], + ["opal/mca/threads/$tsd_base_include"], + [Header to include for tsd implementation]) + AC_DEFINE_UNQUOTED([MCA_wait_sync_IMPLEMENTATION_HEADER], + ["opal/mca/threads/$wait_sync_base_include"], + [Header to include for wait_sync implementation]) +]) diff --git a/opal/mca/threads/mutex.h b/opal/mca/threads/mutex.h index e28265941d4..d0228c98dfb 100644 --- a/opal/mca/threads/mutex.h +++ b/opal/mca/threads/mutex.h @@ -29,6 +29,8 @@ #include "opal_config.h" +BEGIN_C_DECLS + /** * @file: * @@ -37,7 +39,6 @@ * Functions for locking of critical sections. */ - /** * Opaque mutex object */ @@ -45,9 +46,7 @@ typedef struct opal_mutex_t opal_mutex_t; typedef struct opal_mutex_t opal_recursive_mutex_t; -BEGIN_C_DECLS #include MCA_mutex_IMPLEMENTATION_HEADER -END_C_DECLS OBJ_CLASS_DECLARATION(opal_mutex_t); OBJ_CLASS_DECLARATION(opal_recursive_mutex_t); diff --git a/opal/mca/threads/pthreads/Makefile.am b/opal/mca/threads/pthreads/Makefile.am index 7cd56b60242..833950d5e17 100644 --- a/opal/mca/threads/pthreads/Makefile.am +++ b/opal/mca/threads/pthreads/Makefile.am @@ -21,9 +21,12 @@ noinst_LTLIBRARIES = libmca_threads_pthreads.la libmca_threads_pthreads_la_SOURCES = \ - threads_pthreads.h \ threads_pthreads_component.c \ - threads_pthreads_mutex.c \ threads_pthreads_condition.c \ + threads_pthreads_module.c \ + threads_pthreads_mutex.c \ + threads_pthreads_mutex.h \ + threads_pthreads_threads.h \ + threads_pthreads_tsd.h \ threads_pthreads_wait_sync.c \ - threads_pthreads_module.c + threads_pthreads_wait_sync.h diff --git a/opal/mca/threads/pthreads/configure.m4 b/opal/mca/threads/pthreads/configure.m4 index 023faac62ad..cb66096e492 100644 --- a/opal/mca/threads/pthreads/configure.m4 +++ b/opal/mca/threads/pthreads/configure.m4 @@ -30,11 +30,19 @@ AC_DEFUN([MCA_opal_threads_pthreads_COMPILE_MODE], [ ]) AC_DEFUN([MCA_opal_threads_pthreads_POST_CONFIG],[ - AS_IF([test "$1" = "1"], [threads_base_include="pthreads/threads_pthreads.h"]) + AS_IF([test "$1" = "1"], [threads_base_include="pthreads/threads_pthreads_threads.h"]) ])dnl AC_DEFUN([MCA_opal_mutex_pthreads_POST_CONFIG],[ - AS_IF([test "$1" = "1"], [mutex_base_include="pthreads/mutex_unix.h"]) + AS_IF([test "$1" = "1"], [mutex_base_include="pthreads/threads_pthreads_mutex.h"]) +])dnl + +AC_DEFUN([MCA_opal_tsd_pthreads_POST_CONFIG],[ + AS_IF([test "$1" = "1"], [threads_base_include="pthreads/threads_pthreads_tsd.h"]) +])dnl + +AC_DEFUN([MCA_opal_wait_sync_pthreads_POST_CONFIG],[ + AS_IF([test "$1" = "1"], [mutex_base_include="pthreads/threads_pthreads_wait_sync.h"]) ])dnl # MCA_threads_pthreads_CONFIG(action-if-can-compile, diff --git a/opal/mca/threads/pthreads/threads_pthreads_component.c b/opal/mca/threads/pthreads/threads_pthreads_component.c index 2f8f963ba03..938497c02d1 100644 --- a/opal/mca/threads/pthreads/threads_pthreads_component.c +++ b/opal/mca/threads/pthreads/threads_pthreads_component.c @@ -25,7 +25,6 @@ #include "opal/mca/threads/thread.h" #include "opal/mca/threads/threads.h" -#include "opal/mca/threads/pthreads/threads_pthreads.h" #include "opal/constants.h" static int opal_threads_pthreads_open(void); diff --git a/opal/mca/threads/pthreads/threads_pthreads_mutex.c b/opal/mca/threads/pthreads/threads_pthreads_mutex.c index 32b721c76e3..35ca43a2494 100644 --- a/opal/mca/threads/pthreads/threads_pthreads_mutex.c +++ b/opal/mca/threads/pthreads/threads_pthreads_mutex.c @@ -31,16 +31,6 @@ #include "opal/mca/threads/mutex.h" //#include "opal/mca/threads/pthreads/mutex_unix.h" - -OBJ_CLASS_INSTANCE(opal_mutex_t, - opal_object_t, - NULL, - NULL); -OBJ_CLASS_INSTANCE(opal_recursive_mutex_t, - opal_object_t, - NULL, - NULL); - /* * Wait and see if some upper layer wants to use threads, if support * exists. @@ -63,3 +53,46 @@ struct opal_pthread_mutex_t { typedef struct opal_pthread_mutex_t opal_pthread_mutex_t; typedef struct opal_pthread_mutex_t opal_pthread_recursive_mutex_t; +static void mca_threads_pthreads_mutex_constructor(opal_mutex_t *p_mutex) { + pthread_mutex_init(&p_mutex->m_lock_pthread, NULL); +#if OPAL_ENABLE_DEBUG + p_mutex->m_lock_debug = 0; + p_mutex->m_lock_file = NULL; + p_mutex->m_lock_line = 0; +#endif + opal_atomic_lock_init(&p_mutex->m_lock_atomic, 0); +} + +static void mca_threads_pthreads_mutex_desctructor(opal_mutex_t *p_mutex) { + pthread_mutex_destroy(&p_mutex->m_lock_pthread); +} + +static void mca_threads_pthreads_recursive_mutex_constructor + (opal_recursive_mutex_t *p_mutex) { + pthread_mutexattr_t mutex_attr; + pthread_mutexattr_init(&mutex_attr); + pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE); + pthread_mutex_init(&p_mutex->m_lock_pthread, &mutex_attr); + pthread_mutexattr_destroy(&mutex_attr); +#if OPAL_ENABLE_DEBUG + p_mutex->m_lock_debug = 0; + p_mutex->m_lock_file = NULL; + p_mutex->m_lock_line = 0; +#endif + opal_atomic_lock_init(&p_mutex->m_lock_atomic, 0); +} + +static void mca_threads_pthreads_recursive_mutex_desctructor + (opal_recursive_mutex_t *p_mutex) { + pthread_mutex_destroy(&p_mutex->m_lock_pthread); +} + +OBJ_CLASS_INSTANCE(opal_mutex_t, + opal_object_t, + mca_threads_pthreads_mutex_constructor, + mca_threads_pthreads_mutex_desctructor); + +OBJ_CLASS_INSTANCE(opal_recursive_mutex_t, + opal_object_t, + mca_threads_pthreads_recursive_mutex_constructor, + mca_threads_pthreads_recursive_mutex_desctructor); diff --git a/opal/mca/threads/pthreads/mutex_unix.h b/opal/mca/threads/pthreads/threads_pthreads_mutex.h similarity index 91% rename from opal/mca/threads/pthreads/mutex_unix.h rename to opal/mca/threads/pthreads/threads_pthreads_mutex.h index 9d5f0bfa213..3f8d082c4b4 100644 --- a/opal/mca/threads/pthreads/mutex_unix.h +++ b/opal/mca/threads/pthreads/threads_pthreads_mutex.h @@ -23,8 +23,8 @@ * $HEADER$ */ -#ifndef OPAL_MUTEX_UNIX_H -#define OPAL_MUTEX_UNIX_H 1 +#ifndef OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_MUTEX_H +#define OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_MUTEX_H 1 /** * @file: @@ -211,6 +211,14 @@ static inline void opal_mutex_atomic_unlock(opal_mutex_t *m) #endif +typedef pthread_cond_t opal_cond_t; +#define OPAL_CONDITION_STATIC_INIT PTHREAD_COND_INITIALIZER +#define opal_cond_init(a) pthread_cond_init(a, NULL) +#define opal_cond_wait(a,b) pthread_cond_wait(a, &(b)->m_lock_pthread) +#define opal_cond_broadcast(a) pthread_cond_broadcast(a) +#define opal_cond_signal(a) pthread_cond_signal(a) +#define opal_cond_destroy(a) pthread_cond_destroy(a) + END_C_DECLS -#endif /* OPAL_MUTEX_UNIX_H */ +#endif /* OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_MUTEX_H */ diff --git a/opal/mca/threads/pthreads/threads_pthreads_threads.h b/opal/mca/threads/pthreads/threads_pthreads_threads.h new file mode 100644 index 00000000000..ed0166e4dab --- /dev/null +++ b/opal/mca/threads/pthreads/threads_pthreads_threads.h @@ -0,0 +1,15 @@ + +#ifndef OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_THREADS_H +#define OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_THREADS_H 1 + +#include +#include + +struct opal_thread_t { + opal_object_t super; + opal_thread_fn_t t_run; + void* t_arg; + pthread_t t_handle; +}; + +#endif /* OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_THREADS_H */ diff --git a/opal/mca/threads/pthreads/threads_pthreads_tsd.h b/opal/mca/threads/pthreads/threads_pthreads_tsd.h new file mode 100644 index 00000000000..f3696f7df3d --- /dev/null +++ b/opal/mca/threads/pthreads/threads_pthreads_tsd.h @@ -0,0 +1,29 @@ + +#ifndef OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_TSD_H +#define OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_TSD_H 1 + +#include +#include + +typedef pthread_key_t opal_tsd_key_t; + +static inline int +opal_tsd_key_delete(opal_tsd_key_t key) +{ + return pthread_key_delete(key); +} + +static inline int +opal_tsd_setspecific(opal_tsd_key_t key, void *value) +{ + return pthread_setspecific(key, value); +} + +static inline int +opal_tsd_getspecific(opal_tsd_key_t key, void **valuep) +{ + *valuep = pthread_getspecific(key); + return OPAL_SUCCESS; +} + +#endif /* OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_TSD_H */ diff --git a/opal/mca/threads/pthreads/threads_pthreads_wait_sync.h b/opal/mca/threads/pthreads/threads_pthreads_wait_sync.h new file mode 100644 index 00000000000..0b43a51fd62 --- /dev/null +++ b/opal/mca/threads/pthreads/threads_pthreads_wait_sync.h @@ -0,0 +1,77 @@ + +#ifndef OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_WAIT_SYNC_H +#define OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_WAIT_SYNC_H 1 + +typedef struct ompi_wait_sync_t { + opal_atomic_int32_t count; + int32_t status; + pthread_cond_t condition; + pthread_mutex_t lock; + struct ompi_wait_sync_t *next; + struct ompi_wait_sync_t *prev; + volatile bool signaling; +} ompi_wait_sync_t; + +#define SYNC_WAIT(sync) (opal_using_threads() ? ompi_sync_wait_mt (sync) : sync_wait_st (sync)) + +/* The loop in release handles a race condition between the signaling + * thread and the destruction of the condition variable. The signaling + * member will be set to false after the final signaling thread has + * finished operating on the sync object. This is done to avoid + * extra atomics in the signalling function and keep it as fast + * as possible. Note that the race window is small so spinning here + * is more optimal than sleeping since this macro is called in + * the critical path. */ +#define WAIT_SYNC_RELEASE(sync) \ + if (opal_using_threads()) { \ + while ((sync)->signaling) { \ + continue; \ + } \ + pthread_cond_destroy(&(sync)->condition); \ + pthread_mutex_destroy(&(sync)->lock); \ + } + +#define WAIT_SYNC_RELEASE_NOWAIT(sync) \ + if (opal_using_threads()) { \ + pthread_cond_destroy(&(sync)->condition); \ + pthread_mutex_destroy(&(sync)->lock); \ + } + + +#define WAIT_SYNC_SIGNAL(sync) \ + if (opal_using_threads()) { \ + pthread_mutex_lock(&(sync->lock)); \ + pthread_cond_signal(&sync->condition); \ + pthread_mutex_unlock(&(sync->lock)); \ + sync->signaling = false; \ + } + +#define WAIT_SYNC_SIGNALLED(sync){ \ + (sync)->signaling = false; \ +} + +OPAL_DECLSPEC int ompi_sync_wait_mt(ompi_wait_sync_t *sync); +static inline int sync_wait_st (ompi_wait_sync_t *sync) +{ + while (sync->count > 0) { + opal_progress(); + } + + return sync->status; +} + + +#define WAIT_SYNC_INIT(sync,c) \ + do { \ + (sync)->count = (c); \ + (sync)->next = NULL; \ + (sync)->prev = NULL; \ + (sync)->status = 0; \ + (sync)->signaling = (0 != (c)); \ + if (opal_using_threads()) { \ + pthread_cond_init (&(sync)->condition, NULL); \ + pthread_mutex_init (&(sync)->lock, NULL); \ + } \ + } while(0) + +#endif /* OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_WAIT_SYNC_H */ diff --git a/opal/mca/threads/qthreads/threads_qthreads.htmp b/opal/mca/threads/qthreads/threads_qthreads.htmp deleted file mode 100644 index f1ab4c81c0f..00000000000 --- a/opal/mca/threads/qthreads/threads_qthreads.htmp +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana - * University Research and Technology - * Corporation. All rights reserved. - * Copyright (c) 2004-2014 The University of Tennessee and The University - * of Tennessee Research Foundation. All rights - * reserved. - * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, - * University of Stuttgart. All rights reserved. - * Copyright (c) 2004-2005 The Regents of the University of California. - * All rights reserved. - * $COPYRIGHT$ - * - * Additional copyrights may follow - * - * $HEADER$ - */ - -#ifndef OPAL_MCA_TIMER_DARWIN_TIMER_DARWIN_H -#define OPAL_MCA_TIMER_DARWIN_TIMER_DARWIN_H - -#include "opal_config.h" -#include - -typedef uint64_t opal_threadss_t; - -/* frequency in mhz */ -OPAL_DECLSPEC extern opal_threadss_t opal_threadss_darwin_freq; -OPAL_DECLSPEC extern mach_timebase_info_data_t opal_threadss_darwin_info; -OPAL_DECLSPEC extern opal_threadss_t opal_threadss_darwin_bias; - -/** - * Use the pragmatic solution proposed at - * http://stackoverflow.com/questions/23378063/how-can-i-use-mach-absolute-time-without-overflowing/23378064#23378064 - */ -static inline opal_threadss_t -opal_threadss_base_get_cycles(void) -{ - uint64_t now = mach_absolute_time(); - - if( opal_threadss_darwin_info.denom == 0 ) { - (void)mach_timebase_info(&opal_threadss_darwin_info); - if( opal_threadss_darwin_info.denom > 1024 ) { - double frac = (double)opal_threadss_darwin_info.numer/opal_threadss_darwin_info.denom; - opal_threadss_darwin_info.denom = 1024; - opal_threadss_darwin_info.numer = opal_threadss_darwin_info.denom * frac + 0.5; - } - opal_threadss_darwin_bias = now; - } - /* this is basically a wrapper around the "right" assembly to convert - the tick counter off the PowerPC Time Base into nanos. */ - return (now - opal_threadss_darwin_bias) * opal_threadss_darwin_info.numer / opal_threadss_darwin_info.denom; -} - - -static inline opal_threadss_t -opal_threadss_base_get_usec(void) -{ - /* freq is in Hz, so this gives usec */ - return opal_threadss_base_get_cycles() / 1000; -} - - -static inline opal_threadss_t -opal_threadss_base_get_freq(void) -{ - return opal_threadss_darwin_freq; -} - -typedef pthread_key_t opal_tsd_key_t; - -static inline int -opal_tsd_key_delete(opal_tsd_key_t key) -{ - return pthread_key_delete(key); -} - -static inline int -opal_tsd_setspecific(opal_tsd_key_t key, void *value) -{ - return pthread_setspecific(key, value); -} - -static inline int -opal_tsd_getspecific(opal_tsd_key_t key, void **valuep) -{ - *valuep = pthread_getspecific(key); - return OPAL_SUCCESS; -} - -#define OPAL_TIMER_CYCLE_NATIVE 0 -#define OPAL_TIMER_CYCLE_SUPPORTED 1 -#define OPAL_TIMER_USEC_NATIVE 1 -#define OPAL_TIMER_USEC_SUPPORTED 1 - -#endif diff --git a/opal/mca/threads/threads.h b/opal/mca/threads/threads.h index 5f63b677498..c69de3f774d 100644 --- a/opal/mca/threads/threads.h +++ b/opal/mca/threads/threads.h @@ -27,9 +27,6 @@ #include "opal_config.h" -#include -#include - #include "opal/class/opal_object.h" #if OPAL_ENABLE_DEBUG #include "opal/util/output.h" @@ -44,12 +41,7 @@ typedef void *(*opal_thread_fn_t) (opal_object_t *); #define OPAL_THREAD_CANCELLED ((void*)1); -struct opal_thread_t { - opal_object_t super; - opal_thread_fn_t t_run; - void* t_arg; - pthread_t t_handle; -}; +#include MCA_threads_IMPLEMENTATION_HEADER typedef struct opal_thread_t opal_thread_t; @@ -140,7 +132,6 @@ OPAL_DECLSPEC void opal_thread_kill(opal_thread_t *, int sig); OPAL_DECLSPEC void opal_thread_set_main(void); OPAL_DECLSPEC void opal_event_use_threads(void); - END_C_DECLS #endif /* OPAL_MCA_THREAD_H */ diff --git a/opal/mca/threads/tsd.h b/opal/mca/threads/tsd.h index a9ff4d06684..5f5a7ffd625 100644 --- a/opal/mca/threads/tsd.h +++ b/opal/mca/threads/tsd.h @@ -108,26 +108,7 @@ OPAL_DECLSPEC int opal_tsd_getspecific(opal_tsd_key_t key, void **valuep); #else -typedef pthread_key_t opal_tsd_key_t; - -static inline int -opal_tsd_key_delete(opal_tsd_key_t key) -{ - return pthread_key_delete(key); -} - -static inline int -opal_tsd_setspecific(opal_tsd_key_t key, void *value) -{ - return pthread_setspecific(key, value); -} - -static inline int -opal_tsd_getspecific(opal_tsd_key_t key, void **valuep) -{ - *valuep = pthread_getspecific(key); - return OPAL_SUCCESS; -} +#include MCA_tsd_IMPLEMENTATION_HEADER #endif diff --git a/opal/mca/threads/wait_sync.h b/opal/mca/threads/wait_sync.h index 316ef5a394a..4dc9f9ecb07 100644 --- a/opal/mca/threads/wait_sync.h +++ b/opal/mca/threads/wait_sync.h @@ -22,87 +22,16 @@ #include "opal/sys/atomic.h" #include "opal/threads/condition.h" -//#include BEGIN_C_DECLS extern int opal_max_thread_in_progress; -typedef struct ompi_wait_sync_t { - opal_atomic_int32_t count; - int32_t status; - pthread_cond_t condition; - pthread_mutex_t lock; - struct ompi_wait_sync_t *next; - struct ompi_wait_sync_t *prev; - volatile bool signaling; -} ompi_wait_sync_t; +#include MCA_wait_sync_IMPLEMENTATION_HEADER #define REQUEST_PENDING (void*)0L #define REQUEST_COMPLETED (void*)1L -#define SYNC_WAIT(sync) (opal_using_threads() ? ompi_sync_wait_mt (sync) : sync_wait_st (sync)) - -/* The loop in release handles a race condition between the signaling - * thread and the destruction of the condition variable. The signaling - * member will be set to false after the final signaling thread has - * finished operating on the sync object. This is done to avoid - * extra atomics in the signalling function and keep it as fast - * as possible. Note that the race window is small so spinning here - * is more optimal than sleeping since this macro is called in - * the critical path. */ -#define WAIT_SYNC_RELEASE(sync) \ - if (opal_using_threads()) { \ - while ((sync)->signaling) { \ - continue; \ - } \ - pthread_cond_destroy(&(sync)->condition); \ - pthread_mutex_destroy(&(sync)->lock); \ - } - -#define WAIT_SYNC_RELEASE_NOWAIT(sync) \ - if (opal_using_threads()) { \ - pthread_cond_destroy(&(sync)->condition); \ - pthread_mutex_destroy(&(sync)->lock); \ - } - - -#define WAIT_SYNC_SIGNAL(sync) \ - if (opal_using_threads()) { \ - pthread_mutex_lock(&(sync->lock)); \ - pthread_cond_signal(&sync->condition); \ - pthread_mutex_unlock(&(sync->lock)); \ - sync->signaling = false; \ - } - -#define WAIT_SYNC_SIGNALLED(sync){ \ - (sync)->signaling = false; \ -} - -OPAL_DECLSPEC int ompi_sync_wait_mt(ompi_wait_sync_t *sync); -static inline int sync_wait_st (ompi_wait_sync_t *sync) -{ - while (sync->count > 0) { - opal_progress(); - } - - return sync->status; -} - - -#define WAIT_SYNC_INIT(sync,c) \ - do { \ - (sync)->count = (c); \ - (sync)->next = NULL; \ - (sync)->prev = NULL; \ - (sync)->status = 0; \ - (sync)->signaling = (0 != (c)); \ - if (opal_using_threads()) { \ - pthread_cond_init (&(sync)->condition, NULL); \ - pthread_mutex_init (&(sync)->lock, NULL); \ - } \ - } while(0) - /** * Update the status of the synchronization primitive. If an error is * reported the synchronization is completed and the signal diff --git a/opal/mca/timer/linux/timer_linux_component.c b/opal/mca/timer/linux/timer_linux_component.c index c5b664afbeb..0eb03baac04 100644 --- a/opal/mca/timer/linux/timer_linux_component.c +++ b/opal/mca/timer/linux/timer_linux_component.c @@ -26,6 +26,7 @@ #include "opal_config.h" #include +#include #include "opal/mca/timer/timer.h" #include "opal/mca/timer/base/base.h" diff --git a/orte/util/threads.h b/orte/util/threads.h index 5bd1be82b5b..d5f9c9c3369 100644 --- a/orte/util/threads.h +++ b/orte/util/threads.h @@ -27,11 +27,11 @@ * we only have a memory barrier */ #define ORTE_ACQUIRE_OBJECT(o) opal_atomic_rmb() -#define orte_condition_wait(a,b) pthread_cond_wait(a, &(b)->m_lock_pthread) -typedef pthread_cond_t orte_condition_t; -#define orte_condition_broadcast(a) pthread_cond_broadcast(a) -#define orte_condition_signal(a) pthread_cond_signal(a) -#define ORTE_CONDITION_STATIC_INIT PTHREAD_COND_INITIALIZER +#define orte_condition_wait(a,b) opal_cond_wait(a,b) +typedef opal_cond_t orte_condition_t; +#define orte_condition_broadcast(a) opal_cond_broadcast(a) +#define orte_condition_signal(a) opal_cond_signal(a) +#define ORTE_CONDITION_STATIC_INIT OPAL_COND_INITIALIZER /* define a threadshift macro */ #define ORTE_THREADSHIFT(x, eb, f, p) \ @@ -51,14 +51,14 @@ typedef struct { #define ORTE_CONSTRUCT_LOCK(l) \ do { \ OBJ_CONSTRUCT(&(l)->mutex, opal_mutex_t); \ - pthread_cond_init(&(l)->cond, NULL); \ + opal_cond_init(&(l)->cond); \ (l)->active = true; \ } while(0) #define ORTE_DESTRUCT_LOCK(l) \ do { \ OBJ_DESTRUCT(&(l)->mutex); \ - pthread_cond_destroy(&(l)->cond); \ + opal_cond_destroy(&(l)->cond); \ } while(0) From 0a25a79f1ad1ca7949da79a446a95232b746bda2 Mon Sep 17 00:00:00 2001 From: Howard Pritchard Date: Thu, 7 Feb 2019 10:54:56 -0700 Subject: [PATCH 05/17] threads: remove workaround for mpi wrappers remove workaround introduced into the wrappers Makefile. This can be done due to the configury refactor. rework the threads framework configury to move a good chunk of setup to the top config directory to make sure thread package specific compile/link args are defined early in the configure process. Signed-off-by: Howard Pritchard --- config/opal_config_argobots.m4 | 35 +++++++++++ config/opal_config_pthreads.m4 | 72 +++++++++++----------- config/opal_config_qthreads.m4 | 45 ++++++++++++++ config/opal_config_threads.m4 | 85 +++++++++++++++++++------- configure.ac | 2 +- opal/mca/threads/configure.m4 | 11 +--- opal/mca/threads/pthreads/configure.m4 | 23 ++----- opal/mca/threads/qthreads/configure.m4 | 20 +----- opal/tools/wrappers/Makefile.am | 3 +- 9 files changed, 190 insertions(+), 106 deletions(-) create mode 100644 config/opal_config_argobots.m4 create mode 100644 config/opal_config_qthreads.m4 diff --git a/config/opal_config_argobots.m4 b/config/opal_config_argobots.m4 new file mode 100644 index 00000000000..d3cb817395b --- /dev/null +++ b/config/opal_config_argobots.m4 @@ -0,0 +1,35 @@ +dnl +dnl Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana +dnl University Research and Technology +dnl Corporation. All rights reserved. +dnl Copyright (c) 2004-2005 The University of Tennessee and The University +dnl of Tennessee Research Foundation. All rights +dnl reserved. +dnl Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, +dnl University of Stuttgart. All rights reserved. +dnl Copyright (c) 2004-2005 The Regents of the University of California. +dnl All rights reserved. +dnl Copyright (c) 2012 Cisco Systems, Inc. All rights reserved. +dnl Copyright (c) 2014 Intel, Inc. All rights reserved. +dnl Copyright (c) 2014-2016 Research Organization for Information Science +dnl and Technology (RIST). All rights reserved. +dnl $COPYRIGHT$ +dnl +dnl Additional copyrights may follow +dnl +dnl $HEADER$ +dnl +dnl OPAL_CONFIG_ARGOBOT_THREADS() +dnl +dnl Configure argobot threads, setting the following variables (but +dnl not calling AC_SUBST on them). + +#******************************************************************** +# +# TODO: work in progress +# +#******************************************************************** +AC_DEFUN([OPAL_CONFIG_ARGOBOT_THREADS],[ + AC_REQUIRE([AC_PROG_GREP]) + [$2] +])dnl diff --git a/config/opal_config_pthreads.m4 b/config/opal_config_pthreads.m4 index b2d9c7aaece..de040436a9d 100644 --- a/config/opal_config_pthreads.m4 +++ b/config/opal_config_pthreads.m4 @@ -281,11 +281,11 @@ if test "$opal_pthread_c_success" = "0"; then opal_pthread_c_success=0) AC_LANG_POP(C) if test "$opal_pthread_c_success" = "1"; then - PTHREAD_CFLAGS="$pf" + TPKG_CFLAGS="$pf" AC_MSG_RESULT([yes]) break else - PTHREAD_CFLAGS= + TPKG_CFLAGS= CFLAGS="$orig_CFLAGS" AC_MSG_RESULT([no]) fi @@ -307,11 +307,11 @@ if test "$opal_pthread_cxx_success" = "0"; then opal_pthread_cxx_success=0) AC_LANG_POP(C++) if test "$opal_pthread_cxx_success" = "1"; then - PTHREAD_CXXFLAGS="$pf" + TPKG_CXXFLAGS="$pf" AC_MSG_RESULT([yes]) break else - PTHREAD_CXXFLAGS= + TPKG_CXXFLAGS= CXXFLAGS="$orig_CXXFLAGS" AC_MSG_RESULT([no]) fi @@ -335,11 +335,11 @@ if test "$opal_pthread_fortran_success" = "0" && \ opal_pthread_fortran_success=0) AC_LANG_POP(C) if test "$opal_pthread_fortran_success" = "1"; then - PTHREAD_FCFLAGS="$pf" + TPKG_FCFLAGS="$pf" AC_MSG_RESULT([yes]) break else - PTHREAD_FCFLAGS= + TPKG_FCFLAGS= FCFLAGS="$orig_FCFLAGS" AC_MSG_RESULT([no]) fi @@ -406,14 +406,14 @@ if test "$opal_pthread_c_success" = "0"; then case "${host_cpu}-${host-_os}" in *-aix* | *-freebsd*) if test "`echo $CPPFLAGS | $GREP 'D_THREAD_SAFE'`" = ""; then - PTHREAD_CPPFLAGS="-D_THREAD_SAFE" - CPPFLAGS="$CPPFLAGS $PTHREAD_CPPFLAGS" + TPKG_CPPFLAGS="-D_THREAD_SAFE" + CPPFLAGS="$CPPFLAGS $TPKG_CPPFLAGS" fi ;; *) if test "`echo $CPPFLAGS | $GREP 'D_REENTRANT'`" = ""; then - PTHREAD_CPPFLAGS="-D_REENTRANT" - CPPFLAGS="$CPPFLAGS $PTHREAD_CPPFLAGS" + TPKG_CPPFLAGS="-D_REENTRANT" + CPPFLAGS="$CPPFLAGS $TPKG_CPPFLAGS" fi ;; esac @@ -423,10 +423,10 @@ if test "$opal_pthread_c_success" = "0"; then opal_pthread_c_success=0) AC_LANG_POP(C) if test "$opal_pthread_c_success" = "1"; then - PTHREAD_LIBS="$pl" + TPKG_LIBS="$pl" AC_MSG_RESULT([yes]) else - PTHREAD_CPPFLAGS= + TPKG_CPPFLAGS= CPPFLAGS="$orig_CPPFLAGS" LIBS="$orig_LIBS" AC_MSG_RESULT([no]) @@ -441,23 +441,23 @@ AC_DEFUN([OPAL_INTL_POSIX_THREADS_LIBS_CXX],[ # C++ compiler # if test "$opal_pthread_cxx_success" = "0"; then - if test ! "$opal_pthread_c_success" = "0" && test ! "$PTHREAD_LIBS" = "" ; then - AC_MSG_CHECKING([if C++ compiler and POSIX threads work with $PTHREAD_LIBS]) + if test ! "$opal_pthread_c_success" = "0" && test ! "$TPKG_LIBS" = "" ; then + AC_MSG_CHECKING([if C++ compiler and POSIX threads work with $TPKG_LIBS]) case "${host_cpu}-${host-_os}" in *-aix* | *-freebsd*) if test "`echo $CXXCPPFLAGS | $GREP 'D_THREAD_SAFE'`" = ""; then - PTHREAD_CXXCPPFLAGS="-D_THREAD_SAFE" - CXXCPPFLAGS="$CXXCPPFLAGS $PTHREAD_CXXCPPFLAGS" + TPKG_CXXCPPFLAGS="-D_THREAD_SAFE" + CXXCPPFLAGS="$CXXCPPFLAGS $TPKG_CXXCPPFLAGS" fi ;; *) if test "`echo $CXXCPPFLAGS | $GREP 'D_REENTRANT'`" = ""; then - PTHREAD_CXXCPPFLAGS="-D_REENTRANT" - CXXCPPFLAGS="$CXXCPPFLAGS $PTHREAD_CXXCPPFLAGS" + TPKG_CXXCPPFLAGS="-D_REENTRANT" + CXXCPPFLAGS="$CXXCPPFLAGS $TPKG_CXXCPPFLAGS" fi ;; esac - LIBS="$orig_LIBS $PTHREAD_LIBS" + LIBS="$orig_LIBS $TPKG_LIBS" AC_LANG_PUSH(C++) OPAL_INTL_PTHREAD_TRY_LINK(opal_pthread_cxx_success=1, opal_pthread_cxx_success=0) @@ -476,14 +476,14 @@ if test "$opal_pthread_cxx_success" = "0"; then case "${host_cpu}-${host-_os}" in *-aix* | *-freebsd*) if test "`echo $CXXCPPFLAGS | $GREP 'D_THREAD_SAFE'`" = ""; then - PTHREAD_CXXCPPFLAGS="-D_THREAD_SAFE" - CXXCPPFLAGS="$CXXCPPFLAGS $PTHREAD_CXXCPPFLAGS" + TPKG_CXXCPPFLAGS="-D_THREAD_SAFE" + CXXCPPFLAGS="$CXXCPPFLAGS $TPKG_CXXCPPFLAGS" fi ;; *) if test "`echo $CXXCPPFLAGS | $GREP 'D_REENTRANT'`" = ""; then - PTHREAD_CXXCPPFLAGS="-D_REENTRANT" - CXXCPPFLAGS="$CXXCPPFLAGS $PTHREAD_CXXCPPFLAGS" + TPKG_CXXCPPFLAGS="-D_REENTRANT" + CXXCPPFLAGS="$CXXCPPFLAGS $TPKG_CXXCPPFLAGS" fi ;; esac @@ -493,10 +493,10 @@ if test "$opal_pthread_cxx_success" = "0"; then opal_pthread_cxx_success=0) AC_LANG_POP(C++) if test "$opal_pthread_cxx_success" = "1"; then - PTHREAD_LIBS="$pl" + TPKG_LIBS="$pl" AC_MSG_RESULT([yes]) else - PTHREAD_CXXCPPFLAGS= + TPKG_CXXCPPFLAGS= CXXCPPFLAGS="$orig_CXXCPPFLAGS" LIBS="$orig_LIBS" AC_MSG_RESULT([no]) @@ -514,9 +514,9 @@ AC_DEFUN([OPAL_INTL_POSIX_THREADS_LIBS_FC],[ if test "$opal_pthread_fortran_success" = "0" && \ test "$OMPI_TRY_FORTRAN_BINDINGS" -gt "$OMPI_FORTRAN_NO_BINDINGS" && \ test $ompi_fortran_happy -eq 1; then - if test ! "$opal_pthread_c_success" = "0" && test ! "$PTHREAD_LIBS" = "" ; then - AC_MSG_CHECKING([if Fortran compiler and POSIX threads work with $PTHREAD_LIBS]) - LIBS="$orig_LIBS $PTHREAD_LIBS" + if test ! "$opal_pthread_c_success" = "0" && test ! "$TPKG_LIBS" = "" ; then + AC_MSG_CHECKING([if Fortran compiler and POSIX threads work with $TPKG_LIBS]) + LIBS="$orig_LIBS $TPKG_LIBS" AC_LANG_PUSH(C) OPAL_INTL_PTHREAD_TRY_LINK_FORTRAN(opal_pthread_fortran_success=1, opal_pthread_fortran_success=0) @@ -537,7 +537,7 @@ if test "$opal_pthread_fortran_success" = "0" && \ opal_pthread_fortran_success=0) AC_LANG_POP(C) if test "$opal_pthread_fortran_success" = "1"; then - PTHREAD_LIBS="$pl" + TPKG_LIBS="$pl" AC_MSG_RESULT([yes]) break else @@ -600,13 +600,13 @@ orig_CXXCPPFLAGS="$CXXCPPFLAGS" orig_LDFLAGS="$LDFLAGS" orig_LIBS="$LIBS" -PTHREAD_CFLAGS= -PTHREAD_FCFLAGS= -PTHREAD_CXXFLAGS= -PTHREAD_CPPFLAGS= -PTHREAD_CXXCPPFLAGS= -PTHREAD_LDFLAGS= -PTHREAD_LIBS= +TPKG_CFLAGS= +TPKG_FCFLAGS= +TPKG_CXXFLAGS= +TPKG_CPPFLAGS= +TPKG_CXXCPPFLAGS= +TPKG_LDFLAGS= +TPKG_LIBS= # Try with the basics, mam. OPAL_INTL_POSIX_THREADS_PLAIN diff --git a/config/opal_config_qthreads.m4 b/config/opal_config_qthreads.m4 new file mode 100644 index 00000000000..08c0fd729a9 --- /dev/null +++ b/config/opal_config_qthreads.m4 @@ -0,0 +1,45 @@ +dnl +dnl Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana +dnl University Research and Technology +dnl Corporation. All rights reserved. +dnl Copyright (c) 2004-2005 The University of Tennessee and The University +dnl of Tennessee Research Foundation. All rights +dnl reserved. +dnl Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, +dnl University of Stuttgart. All rights reserved. +dnl Copyright (c) 2004-2005 The Regents of the University of California. +dnl All rights reserved. +dnl Copyright (c) 2012 Cisco Systems, Inc. All rights reserved. +dnl Copyright (c) 2014 Intel, Inc. All rights reserved. +dnl Copyright (c) 2014-2016 Research Organization for Information Science +dnl and Technology (RIST). All rights reserved. +dnl Copyright (c) 2019 Sandia National Laboratories. All rights reserved. +dnl Copyright (c) 2019 Triad National Security, LLC. All rights. +dnl $COPYRIGHT$ +dnl +dnl Additional copyrights may follow +dnl +dnl $HEADER$ +dnl +dnl OPAL_CONFIG_QTHREADS() +dnl +dnl Configure argobot threads, setting the following variables (but +dnl not calling AC_SUBST on them). + +#******************************************************************** +# +# TODO: undoubtedly need some better check than this +# +#******************************************************************** +AC_DEFUN([OPAL_CONFIG_QTHREADS],[ + + AC_CHECK_HEADERS([mach/mach_time.h], + [AC_CHECK_FUNC([mach_absolute_time], + [threads_qthreads_happy="yes"], + [threads_qthreads_happy="no"])], + [threads_qthreads_happy="no"]) + + AS_IF([test "$threads_qthreads_happy" = "yes"], + [$1], + [$2]) +])dnl diff --git a/config/opal_config_threads.m4 b/config/opal_config_threads.m4 index d136cccf86b..299a50a41da 100644 --- a/config/opal_config_threads.m4 +++ b/config/opal_config_threads.m4 @@ -14,6 +14,7 @@ dnl Copyright (c) 2009-2011 Oak Ridge National Labs. All rights reserved. dnl Copyright (c) 2014 Intel, Inc. All rights reserved dnl Copyright (c) 2015 Research Organization for Information Science dnl and Technology (RIST). All rights reserved. +dnl Copyright (c) 2019 Triad National Security, LLC. All rights. dnl $COPYRIGHT$ dnl dnl Additional copyrights may follow @@ -34,36 +35,74 @@ AC_DEFUN([OPAL_CONFIG_THREADS],[ # # -# Check we have POSIX threads +# First see what kind of threads we are going to use # -OPAL_CONFIG_POSIX_THREADS(HAVE_POSIX_THREADS=1, HAVE_POSIX_THREADS=0) -AC_MSG_CHECKING([for working POSIX threads package]) -if test "$HAVE_POSIX_THREADS" = "1" ; then - AC_MSG_RESULT([yes]) -else - AC_MSG_RESULT([no]) -fi -export HAVE_POSIX_THREADS + +AC_ARG_WITH([threads], + [AC_HELP_STRING([--with-threads=TYPE], + [Specify thread TYPE to use. default:pthreads. Other options are qthreads and argobots.])]) + +# +# Check we for the thread package requested, or posix +# + +thread_type_found= + +# +# check for posix threads +# +AS_IF([test -z "$with_threads" || test "$with_threads" = "pthreads" || test "$with_threads" = "yes"], + [OPAL_CONFIG_POSIX_THREADS(HAVE_THREAD_PKG=1, HAVE_THREAD_PKG=0) + AC_MSG_CHECKING([for working POSIX threads package]) + AS_IF([test "$HAVE_THREAD_PKG" = "1"], + [AC_MSG_RESULT([yes]) + thread_type_found="pthreads"], + [AC_MSG_RESULT([no])])], + []) + +# +# see if argobots is called for +# +AS_IF([test -z "$thread_type_found" && test "$with_threads" = argobots"], + [OPAL_CONFIG_ARGOBOT_THREADS(HAVE_THREAD_PKG=1, HAVE_THREAD_PKG=0) + AC_MSG_CHECKING([for working ARGOBOTS threads package]) + AS_IF([test "$HAVE_THREAD_PKG" = "1"], + [AC_MSG_RESULT([yes]) + thread_type_found="argobots"], + [AC_MSG_RESULT([no])])], + []) + +AS_IF([test -z "$thread_type_found" && test "$with_threads" = qthreads"], + [OPAL_CONFIG_QTHREADS(HAVE_THREAD_PKG=1, HAVE_THREAD_PKG=0) + AC_MSG_CHECKING([for working Qthreads package]) + AS_IF([test "$HAVE_THREAD_PKG" = "1"], + [AC_MSG_RESULT([yes]) + thread_type_found="qthreads"], + [AC_MSG_RESULT([no])])], + []) # -# Ask what threading we want (allow posix right now) +# Bail if we didn't find any thread package # -if test "$HAVE_POSIX_THREADS" = "0"; then - AC_MSG_WARN(["*** POSIX threads are not"]) - AC_MSG_WARN(["*** available on your system "]) - AC_MSG_ERROR(["*** Can not continue"]) -fi +AS_IF([test -z "$thread_type_found"], + [AC_MSG_WARN([*** no thread package $with_threads]) + AC_MSG_WARN([*** available on your system]) + AC_MSG_ERROR([*** Can not continue])]) -THREAD_CFLAGS="$PTHREAD_CFLAGS" -THREAD_FCFLAGS="$PTHREAD_FCFLAGS" -THREAD_CXXFLAGS="$PTHREAD_CXXFLAGS" -THREAD_CPPFLAGS="$PTHREAD_CPPFLAGS" -THREAD_CXXCPPFLAGS="$PTHREAD_CXXCPPFLAGS" -THREAD_LDFLAGS="$PTHREAD_LDFLAGS" -THREAD_LIBS="$PTHREAD_LIBS" +THREAD_CFLAGS="$TPKG_CFLAGS" +THREAD_FCFLAGS="$TPKG_FCFLAGS" +THREAD_CXXFLAGS="$TPKG_CXXFLAGS" +THREAD_CPPFLAGS="$TPKG_CPPFLAGS" +THREAD_CXXCPPFLAGS="$TPKG_CXXCPPFLAGS" +THREAD_LDFLAGS="$TPKG_LDFLAGS" +THREAD_LIBS="$TPKG_LIBS" +HAVE_THREAD_PKG_TYPE="$thread_type_found" +export HAVE_THREAD_PKG_TYPE -OPAL_CHECK_PTHREAD_PIDS +AS_IF([test "$thread_type_found" = "pthreads"], + [OPAL_CHECK_PTHREAD_PIDS],[]) +OPAL_SUMMARY_ADD([[Miscellaneous]],[[Threading Package]],[opal_threads], [$thread_type_found]) ])dnl diff --git a/configure.ac b/configure.ac index df0a8c92152..7a3030dee6c 100644 --- a/configure.ac +++ b/configure.ac @@ -972,7 +972,7 @@ OPAL_CHECK_BROKEN_QSORT # # Check out what thread support we have # -#OPAL_CONFIG_THREADS +OPAL_CONFIG_THREADS CFLAGS="$CFLAGS $THREAD_CFLAGS" CPPFLAGS="$CPPFLAGS $THREAD_CPPFLAGS" diff --git a/opal/mca/threads/configure.m4 b/opal/mca/threads/configure.m4 index dd10a05edf8..b35ce36a3b2 100644 --- a/opal/mca/threads/configure.m4 +++ b/opal/mca/threads/configure.m4 @@ -25,14 +25,9 @@ m4_define(MCA_opal_threads_CONFIGURE_MODE, STOP_AT_FIRST) AC_DEFINE_UNQUOTED([OPAL_ENABLE_MULTI_THREADS], [1], [Whether we should enable thread support within the OPAL code base]) AC_DEFUN([MCA_opal_threads_CONFIG],[ - # All components look at this value - AC_ARG_WITH([threads], - [AC_HELP_STRING([--with-threads=TYPE], - [Build high resolution threads component TYPE])], - [], - [with_threads=pthreads]) - - thread_type=$with_threads + thread_type=$HAVE_THREAD_PKG_TYPE + threads_base_include= + mutex_base_include= # first, compile all the components MCA_CONFIGURE_FRAMEWORK($1, $2, 1) diff --git a/opal/mca/threads/pthreads/configure.m4 b/opal/mca/threads/pthreads/configure.m4 index cb66096e492..f0ca42683ce 100644 --- a/opal/mca/threads/pthreads/configure.m4 +++ b/opal/mca/threads/pthreads/configure.m4 @@ -35,14 +35,17 @@ AC_DEFUN([MCA_opal_threads_pthreads_POST_CONFIG],[ AC_DEFUN([MCA_opal_mutex_pthreads_POST_CONFIG],[ AS_IF([test "$1" = "1"], [mutex_base_include="pthreads/threads_pthreads_mutex.h"]) + AC_MSG_CHECKING([mutex_base_include = $mutex_base_include]) ])dnl AC_DEFUN([MCA_opal_tsd_pthreads_POST_CONFIG],[ AS_IF([test "$1" = "1"], [threads_base_include="pthreads/threads_pthreads_tsd.h"]) + AC_MSG_CHECKING([threads_base_include = $threads_base_include]) ])dnl AC_DEFUN([MCA_opal_wait_sync_pthreads_POST_CONFIG],[ - AS_IF([test "$1" = "1"], [mutex_base_include="pthreads/threads_pthreads_wait_sync.h"]) + AS_IF([test "$1" = "1"], [wait_sync_base_include="pthreads/threads_pthreads_wait_sync.h"]) + AC_MSG_CHECKING([wait_sync_includenclude = $wait_sync_base_include]) ])dnl # MCA_threads_pthreads_CONFIG(action-if-can-compile, @@ -51,23 +54,9 @@ AC_DEFUN([MCA_opal_wait_sync_pthreads_POST_CONFIG],[ AC_DEFUN([MCA_opal_threads_pthreads_CONFIG],[ AC_CONFIG_FILES([opal/mca/threads/pthreads/Makefile]) - AS_IF([test "$with_threads" = "pthreads"], - [threads_pthreads_happy="yes" - threads_pthreads_should_use=1], - [threads_pthreads_should_use=0 - AS_IF([test "$with_threads" = ""], - [threads_pthreads_happy="yes"], - [threads_pthreads_happy="no"])]) + AC_MSG_CHECKING([HAVE_THREAD_PKG_TYPE = $HAVE_THREAD_PKG_TYPE]) - AS_IF([test "$threads_pthreads_happy" = "yes"], - [OPAL_CONFIG_POSIX_THREADS([threads_pthreads_happy="yes"], - [threads_pthreads_happy="no"])]) - - AS_IF([test "$threads_pthreads_happy" = "no" && \ - test "$threads_pthreads_should_use" = "1"], - [AC_MSG_ERROR([pthreads threads requested but not available. Aborting.])]) - - AS_IF([test "$threads_pthreads_happy" = "yes"], + AS_IF([test "$HAVE_THREAD_PKG_TYPE" = "pthreads"], [$1], [$2]) ]) diff --git a/opal/mca/threads/qthreads/configure.m4 b/opal/mca/threads/qthreads/configure.m4 index 08ffca8ced2..be32cf87911 100644 --- a/opal/mca/threads/qthreads/configure.m4 +++ b/opal/mca/threads/qthreads/configure.m4 @@ -37,25 +37,7 @@ AC_DEFUN([MCA_opal_threads_qthreads_POST_CONFIG],[ AC_DEFUN([MCA_opal_threads_qthreads_CONFIG],[ AC_CONFIG_FILES([opal/mca/threads/qthreads/Makefile]) - AS_IF([test "$with_threads" = "qthreads"], - [threads_qthreads_happy="yes" - threads_qthreads_should_use=1], - [threads_qthreads_should_use=0 - AS_IF([test "$with_threads" = ""], - [threads_qthreads_happy="yes"], - [threads_qthreads_happy="no"])]) - - AS_IF([test "$threads_qthreads_happy" = "yes"], - [AC_CHECK_HEADERS([mach/mach_time.h]) - AC_CHECK_FUNC([mach_absolute_time], - [threads_qthreads_happy="yes"], - [threads_qthreads_happy="no"])]) - - AS_IF([test "$threads_qthreads_happy" = "no" && \ - test "$threads_qthreads_should_use" = "1"], - [AC_MSG_ERROR([qthreads threads requested but not available. Aborting.])]) - - AS_IF([test "$threads_qthreads_happy" = "yes"], + AS_IF([test "$HAVE_THREAD_PKG_TYPE" = "qthreads"], [$1], [$2]) ]) diff --git a/opal/tools/wrappers/Makefile.am b/opal/tools/wrappers/Makefile.am index e4812e7a3f3..53850b28bb7 100644 --- a/opal/tools/wrappers/Makefile.am +++ b/opal/tools/wrappers/Makefile.am @@ -62,8 +62,7 @@ endif # OPAL_INSTALL_BINARIES endif # OPAL_WANT_SCRIPT_WRAPPER_COMPILERS opal_wrapper_SOURCES = opal_wrapper.c -# XXX(nevans) I need to fix this, compile or runtime for the threading library? -opal_wrapper_LDADD = $(top_builddir)/opal/lib@OPAL_LIB_PREFIX@open-pal.la $(top_builddir)/opal/mca/threads/pthreads/libmca_threads_pthreads.la +opal_wrapper_LDADD = $(top_builddir)/opal/lib@OPAL_LIB_PREFIX@open-pal.la # Ensure that the man pages are rebuilt if the opal_config.h file # changes; a "good enough" way to know if configure was run again (and From 3f6b63647c2093ebc030099c35095cb015d65551 Mon Sep 17 00:00:00 2001 From: Shintaro Iwasaki Date: Wed, 13 Feb 2019 17:15:24 -0600 Subject: [PATCH 06/17] mca/threads: implement Argobots threading layer config: fix thread configury - Add double quotations - Change Argobot to Argobots config: implement Argobots check If the poll time is too long, MPI hangs. This quick fix just sets it to 0, but it is not good for the Pthreads version. Need to find a good way to abstract it. Note that even 1 (= 1 millisecond) causes disastrous performance degradation. Signed-off-by: Shintaro Iwasaki --- config/opal_config_argobots.m4 | 22 +- config/opal_config_threads.m4 | 6 +- opal/mca/event/libevent2022/libevent/poll.c | 3 + opal/mca/threads/argobots/Makefile.am | 34 ++ opal/mca/threads/argobots/configure.m4 | 62 ++++ opal/mca/threads/argobots/owner.txt | 7 + opal/mca/threads/argobots/threads_argobots.h | 12 + .../argobots/threads_argobots_component.c | 57 ++++ .../argobots/threads_argobots_condition.c | 40 +++ .../threads/argobots/threads_argobots_event.c | 136 ++++++++ .../argobots/threads_argobots_module.c | 143 ++++++++ .../threads/argobots/threads_argobots_mutex.c | 86 +++++ .../threads/argobots/threads_argobots_mutex.h | 311 ++++++++++++++++++ .../argobots/threads_argobots_threads.h | 16 + .../threads/argobots/threads_argobots_tsd.h | 32 ++ .../argobots/threads_argobots_wait_sync.c | 112 +++++++ .../argobots/threads_argobots_wait_sync.h | 87 +++++ test/asm/Makefile.am | 13 +- test/class/Makefile.am | 6 +- test/class/opal_fifo.c | 1 + test/class/opal_lifo.c | 1 + 21 files changed, 1166 insertions(+), 21 deletions(-) create mode 100644 opal/mca/threads/argobots/Makefile.am create mode 100644 opal/mca/threads/argobots/configure.m4 create mode 100644 opal/mca/threads/argobots/owner.txt create mode 100644 opal/mca/threads/argobots/threads_argobots.h create mode 100644 opal/mca/threads/argobots/threads_argobots_component.c create mode 100644 opal/mca/threads/argobots/threads_argobots_condition.c create mode 100644 opal/mca/threads/argobots/threads_argobots_event.c create mode 100644 opal/mca/threads/argobots/threads_argobots_module.c create mode 100644 opal/mca/threads/argobots/threads_argobots_mutex.c create mode 100644 opal/mca/threads/argobots/threads_argobots_mutex.h create mode 100644 opal/mca/threads/argobots/threads_argobots_threads.h create mode 100644 opal/mca/threads/argobots/threads_argobots_tsd.h create mode 100644 opal/mca/threads/argobots/threads_argobots_wait_sync.c create mode 100644 opal/mca/threads/argobots/threads_argobots_wait_sync.h diff --git a/config/opal_config_argobots.m4 b/config/opal_config_argobots.m4 index d3cb817395b..c158adf0a50 100644 --- a/config/opal_config_argobots.m4 +++ b/config/opal_config_argobots.m4 @@ -19,17 +19,19 @@ dnl Additional copyrights may follow dnl dnl $HEADER$ dnl -dnl OPAL_CONFIG_ARGOBOT_THREADS() +dnl OPAL_CONFIG_ARGOBOTS_THREADS() dnl -dnl Configure argobot threads, setting the following variables (but +dnl Configure Argobots threads, setting the following variables (but dnl not calling AC_SUBST on them). -#******************************************************************** -# -# TODO: work in progress -# -#******************************************************************** -AC_DEFUN([OPAL_CONFIG_ARGOBOT_THREADS],[ - AC_REQUIRE([AC_PROG_GREP]) - [$2] +AC_DEFUN([OPAL_CONFIG_ARGOBOTS_THREADS],[ + AC_CHECK_HEADERS([abt.h], + [AC_CHECK_LIB([abt],[ABT_init], + [threads_argobots_happy="yes"], + [threads_argobots_happy="no"])], + [threads_argobots_happy="no"]) + + AS_IF([test "$threads_argobots_happy" = "yes"], + [$1], + [$2]) ])dnl diff --git a/config/opal_config_threads.m4 b/config/opal_config_threads.m4 index 299a50a41da..9aead21cbd5 100644 --- a/config/opal_config_threads.m4 +++ b/config/opal_config_threads.m4 @@ -63,8 +63,8 @@ AS_IF([test -z "$with_threads" || test "$with_threads" = "pthreads" || test "$wi # # see if argobots is called for # -AS_IF([test -z "$thread_type_found" && test "$with_threads" = argobots"], - [OPAL_CONFIG_ARGOBOT_THREADS(HAVE_THREAD_PKG=1, HAVE_THREAD_PKG=0) +AS_IF([test -z "$thread_type_found" && test "$with_threads" = "argobots"], + [OPAL_CONFIG_ARGOBOTS_THREADS(HAVE_THREAD_PKG=1, HAVE_THREAD_PKG=0) AC_MSG_CHECKING([for working ARGOBOTS threads package]) AS_IF([test "$HAVE_THREAD_PKG" = "1"], [AC_MSG_RESULT([yes]) @@ -72,7 +72,7 @@ AS_IF([test -z "$thread_type_found" && test "$with_threads" = argobots"], [AC_MSG_RESULT([no])])], []) -AS_IF([test -z "$thread_type_found" && test "$with_threads" = qthreads"], +AS_IF([test -z "$thread_type_found" && test "$with_threads" = "qthreads"], [OPAL_CONFIG_QTHREADS(HAVE_THREAD_PKG=1, HAVE_THREAD_PKG=0) AC_MSG_CHECKING([for working Qthreads package]) AS_IF([test "$HAVE_THREAD_PKG" = "1"], diff --git a/opal/mca/event/libevent2022/libevent/poll.c b/opal/mca/event/libevent2022/libevent/poll.c index 04d311bb676..47beb50e081 100644 --- a/opal/mca/event/libevent2022/libevent/poll.c +++ b/opal/mca/event/libevent2022/libevent/poll.c @@ -162,6 +162,9 @@ poll_dispatch(struct event_base *base, struct timeval *tv) EVBASE_RELEASE_LOCK(base, th_base_lock); + if (msec > 0) { + msec = 0; + } res = poll(event_set, nfds, msec); EVBASE_ACQUIRE_LOCK(base, th_base_lock); diff --git a/opal/mca/threads/argobots/Makefile.am b/opal/mca/threads/argobots/Makefile.am new file mode 100644 index 00000000000..ffec87a40d3 --- /dev/null +++ b/opal/mca/threads/argobots/Makefile.am @@ -0,0 +1,34 @@ +# +# 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. +# Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, +# University of Stuttgart. All rights reserved. +# Copyright (c) 2004-2005 The Regents of the University of California. +# All rights reserved. +# Copyright (c) 2008 Cisco Systems, Inc. All rights reserved. +# Copyright (c) 2019 Sandia National Laboratories. All rights reserved. +# $COPYRIGHT$ +# +# Additional copyrights may follow +# +# $HEADER$ +# + +noinst_LTLIBRARIES = libmca_threads_argobots.la + +libmca_threads_argobots_la_SOURCES = \ + threads_argobots.h \ + threads_argobots_component.c \ + threads_argobots_condition.c \ + threads_argobots_event.c \ + threads_argobots_module.c \ + threads_argobots_mutex.c \ + threads_argobots_mutex.h \ + threads_argobots_threads.h \ + threads_argobots_tsd.h \ + threads_argobots_wait_sync.c \ + threads_argobots_wait_sync.h diff --git a/opal/mca/threads/argobots/configure.m4 b/opal/mca/threads/argobots/configure.m4 new file mode 100644 index 00000000000..26d327ac143 --- /dev/null +++ b/opal/mca/threads/argobots/configure.m4 @@ -0,0 +1,62 @@ +# -*- shell-script -*- +# +# 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. +# Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, +# University of Stuttgart. All rights reserved. +# Copyright (c) 2004-2005 The Regents of the University of California. +# All rights reserved. +# Copyright (c) 2010 Cisco Systems, Inc. All rights reserved. +# Copyright (c) 2015 Research Organization for Information Science +# and Technology (RIST). All rights reserved. +# Copyright (c) 2019 Sandia National Laboratories. All rights reserved. +# Copyright (c) 2019 Triad National Security, LLC. All rights +# $COPYRIGHT$ +# +# Additional copyrights may follow +# +# $HEADER$ +# +AC_DEFUN([MCA_opal_threads_argobots_PRIORITY], [30]) + +AC_DEFUN([MCA_opal_threads_argobots_COMPILE_MODE], [ + AC_MSG_CHECKING([for MCA component $2:$3 compile mode]) + $4="static" + AC_MSG_RESULT([$$4]) +]) + +AC_DEFUN([MCA_opal_threads_argobots_POST_CONFIG],[ + AS_IF([test "$1" = "1"], [threads_base_include="argobots/threads_argobots_threads.h"]) +])dnl + +AC_DEFUN([MCA_opal_mutex_argobots_POST_CONFIG],[ + AS_IF([test "$1" = "1"], [mutex_base_include="argobots/threads_argobots_mutex.h"]) + AC_MSG_CHECKING([mutex_base_include = $mutex_base_include]) +])dnl + +AC_DEFUN([MCA_opal_tsd_argobots_POST_CONFIG],[ + AS_IF([test "$1" = "1"], [threads_base_include="argobots/threads_argobots_tsd.h"]) + AC_MSG_CHECKING([threads_base_include = $threads_base_include]) +])dnl + +AC_DEFUN([MCA_opal_wait_sync_argobots_POST_CONFIG],[ + AS_IF([test "$1" = "1"], [wait_sync_base_include="argobots/threads_argobots_wait_sync.h"]) + AC_MSG_CHECKING([wait_sync_base_include = $wait_sync_base_include]) +])dnl + +# MCA_threads_argobots_CONFIG(action-if-can-compile, +# [action-if-cant-compile]) +# ------------------------------------------------ +AC_DEFUN([MCA_opal_threads_argobots_CONFIG],[ + AC_CONFIG_FILES([opal/mca/threads/argobots/Makefile]) + + AC_MSG_CHECKING([HAVE_THREAD_PKG_TYPE = $HAVE_THREAD_PKG_TYPE]) + + AS_IF([test "$HAVE_THREAD_PKG_TYPE" = "argobots"], + [$1], + [$2]) +]) diff --git a/opal/mca/threads/argobots/owner.txt b/opal/mca/threads/argobots/owner.txt new file mode 100644 index 00000000000..199577ac8cf --- /dev/null +++ b/opal/mca/threads/argobots/owner.txt @@ -0,0 +1,7 @@ +# +# owner/status file +# owner: institution that is responsible for this package +# status: e.g. active, maintenance, unmaintained +# +owner: SNL +status: unmaintained diff --git a/opal/mca/threads/argobots/threads_argobots.h b/opal/mca/threads/argobots/threads_argobots.h new file mode 100644 index 00000000000..133fa81582a --- /dev/null +++ b/opal/mca/threads/argobots/threads_argobots.h @@ -0,0 +1,12 @@ + +#ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_H +#define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_H 1 + +#include + +static inline void ensure_init_argobots(void) { + if (ABT_initialized() != 0) + ABT_init(0, 0); +} + +#endif /* OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_H */ diff --git a/opal/mca/threads/argobots/threads_argobots_component.c b/opal/mca/threads/argobots/threads_argobots_component.c new file mode 100644 index 00000000000..248473a2e27 --- /dev/null +++ b/opal/mca/threads/argobots/threads_argobots_component.c @@ -0,0 +1,57 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ +/* + * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana + * University Research and Technology + * Corporation. All rights reserved. + * Copyright (c) 2004-2014 The University of Tennessee and The University + * of Tennessee Research Foundation. All rights + * reserved. + * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, + * University of Stuttgart. All rights reserved. + * Copyright (c) 2004-2005 The Regents of the University of California. + * All rights reserved. + * Copyright (c) 2007-2015 Los Alamos National Security, LLC. All rights + * reserved. + * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. + * + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + +#include "opal_config.h" + +#include "opal/mca/threads/argobots/threads_argobots.h" +#include "opal/mca/threads/thread.h" +#include "opal/mca/threads/threads.h" +#include "opal/constants.h" +#include + +static int opal_threads_argobots_open(void); + +const opal_threads_base_component_2_0_0_t mca_threads_argobots_component = { + /* First, the mca_component_t struct containing meta information + about the component itself */ + .threadsc_version = { + OPAL_THREADS_BASE_VERSION_2_0_0, + + /* Component name and version */ + .mca_component_name = "argobots", + MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, + OPAL_RELEASE_VERSION), + + .mca_open_component = opal_threads_argobots_open, + }, + .threadsc_data = { + /* The component is checkpoint ready */ + MCA_BASE_METADATA_PARAM_CHECKPOINT + }, +}; + +int opal_threads_argobots_open(void) +{ + ensure_init_argobots(); + return OPAL_SUCCESS; +} diff --git a/opal/mca/threads/argobots/threads_argobots_condition.c b/opal/mca/threads/argobots/threads_argobots_condition.c new file mode 100644 index 00000000000..6e7c2868569 --- /dev/null +++ b/opal/mca/threads/argobots/threads_argobots_condition.c @@ -0,0 +1,40 @@ +/* + * 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. + * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, + * University of Stuttgart. All rights reserved. + * Copyright (c) 2004-2005 The Regents of the University of California. + * All rights reserved. + * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. + * + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + +#include "opal_config.h" + +#include "opal/mca/threads/condition.h" + + +static void opal_condition_construct(opal_condition_t *c) +{ + c->c_waiting = 0; + c->c_signaled = 0; +} + + +static void opal_condition_destruct(opal_condition_t *c) +{ +} + +OBJ_CLASS_INSTANCE(opal_condition_t, + opal_object_t, + opal_condition_construct, + opal_condition_destruct); diff --git a/opal/mca/threads/argobots/threads_argobots_event.c b/opal/mca/threads/argobots/threads_argobots_event.c new file mode 100644 index 00000000000..98830d27891 --- /dev/null +++ b/opal/mca/threads/argobots/threads_argobots_event.c @@ -0,0 +1,136 @@ + +#include "opal/mca/threads/threads.h" +#include "opal/mca/threads/argobots/threads_argobots.h" +#include "opal/mca/event/libevent2022/libevent/include/event2/thread.h" +#include "opal/mca/event/libevent2022/libevent/include/event2/event-config.h" +#include "opal/mca/event/libevent2022/libevent/include/event2/util.h" + +#include + +static void * +evthread_argobots_lock_alloc(unsigned locktype) +{ + ABT_mutex lock; + if (locktype & EVTHREAD_LOCKTYPE_RECURSIVE) { + ABT_mutex_attr abt_mutex_attr; + ABT_mutex_attr_create(&abt_mutex_attr); + ABT_mutex_attr_set_recursive(abt_mutex_attr, ABT_TRUE); + ABT_mutex_create_with_attr(abt_mutex_attr, &lock); + ABT_mutex_attr_free(&abt_mutex_attr); + } else { + ABT_mutex_create(&lock); + } + return lock; +} + +static void +evthread_argobots_lock_free(void *_lock, unsigned locktype) +{ + ABT_mutex lock = _lock; + ABT_mutex_free(&lock); +} + +static int +evthread_argobots_lock(unsigned mode, void *_lock) +{ + int ret; + ABT_mutex lock = _lock; + if (mode & EVTHREAD_TRY) { + ret = ABT_mutex_trylock(lock); + } else { + ret = ABT_mutex_lock(lock); + } + return ret; +} + +static int +evthread_argobots_unlock(unsigned mode, void *_lock) +{ + ABT_mutex lock = _lock; + int ret = ABT_mutex_unlock(lock); + /* This yield is necessary to avoid taking a lock consecutively. */ + ABT_thread_yield(); + return ret; +} + +static unsigned long +evthread_argobots_get_id(void) +{ + ABT_thread thr; + ABT_thread_self(&thr); + return (unsigned long)((intptr_t)thr); +} + +static void * +evthread_argobots_cond_alloc(unsigned condflags) +{ + ABT_cond cond; + ABT_cond_create(&cond); + return cond; +} + +static void +evthread_argobots_cond_free(void *_cond) +{ + ABT_cond cond = _cond; + ABT_cond_free(&cond); +} + +static int +evthread_argobots_cond_signal(void *_cond, int broadcast) +{ + ABT_cond cond = _cond; + int r; + if (broadcast) + r = ABT_cond_broadcast(cond); + else + r = ABT_cond_signal(cond); + return r ? -1 : 0; +} + +static int +evthread_argobots_cond_wait(void *_cond, void *_lock, const struct timeval *tv) +{ + int r; + ABT_cond cond = _cond; + ABT_mutex lock = _lock; + + if (tv) { + struct timeval now, abstime; + struct timespec ts; + evutil_gettimeofday(&now, NULL); + evutil_timeradd(&now, tv, &abstime); + ts.tv_sec = abstime.tv_sec; + ts.tv_nsec = abstime.tv_usec*1000; + r = ABT_cond_timedwait(cond, lock, &ts); + if (r != 0) + return 1; + else + return 0; + } else { + r = ABT_cond_wait(cond, lock); + return r ? -1 : 0; + } +} + +void opal_event_use_threads(void) { + struct evthread_lock_callbacks cbs = { + EVTHREAD_LOCK_API_VERSION, + EVTHREAD_LOCKTYPE_RECURSIVE, + evthread_argobots_lock_alloc, + evthread_argobots_lock_free, + evthread_argobots_lock, + evthread_argobots_unlock + }; + struct evthread_condition_callbacks cond_cbs = { + EVTHREAD_CONDITION_API_VERSION, + evthread_argobots_cond_alloc, + evthread_argobots_cond_free, + evthread_argobots_cond_signal, + evthread_argobots_cond_wait + }; + ensure_init_argobots(); + evthread_set_lock_callbacks(&cbs); + evthread_set_condition_callbacks(&cond_cbs); + evthread_set_id_callback(evthread_argobots_get_id); +} diff --git a/opal/mca/threads/argobots/threads_argobots_module.c b/opal/mca/threads/argobots/threads_argobots_module.c new file mode 100644 index 00000000000..8587ab0e3e1 --- /dev/null +++ b/opal/mca/threads/argobots/threads_argobots_module.c @@ -0,0 +1,143 @@ +/* + * 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. + * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, + * University of Stuttgart. All rights reserved. + * Copyright (c) 2004-2005 The Regents of the University of California. + * All rights reserved. + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ +#include + +#include "opal/mca/threads/argobots/threads_argobots.h" +#include "opal/constants.h" +#include "opal/util/sys_limits.h" +#include "opal/util/output.h" +#include "opal/prefetch.h" +#include "opal/mca/threads/threads.h" +#include "opal/mca/threads/tsd.h" + +#include + +struct opal_tsd_key_value { + opal_tsd_key_t key; + opal_tsd_destructor_t destructor; +}; + +static ABT_thread opal_main_thread; +struct opal_tsd_key_value *opal_tsd_key_values = NULL; +static int opal_tsd_key_values_count = 0; + +/* + * Constructor + */ +static void opal_thread_construct(opal_thread_t *t) +{ + t->t_run = 0; + t->t_handle = ABT_THREAD_NULL; +} + +OBJ_CLASS_INSTANCE(opal_thread_t, + opal_object_t, + opal_thread_construct, NULL); + +static inline ABT_thread opal_thread_get_argobots_self(void) { + ABT_thread self; + ABT_thread_self(&self); + return self; +} + +static void opal_thread_argobots_wrapper(void *arg) { + opal_thread_t *t = (opal_thread_t *) arg; + t->t_ret = ((void*(*)(void*)) t->t_run)(t); +} + +opal_thread_t *opal_thread_get_self(void) +{ + ensure_init_argobots(); + opal_thread_t *t = OBJ_NEW(opal_thread_t); + t->t_handle = opal_thread_get_argobots_self(); + return t; +} + +bool opal_thread_self_compare(opal_thread_t *t) +{ + ensure_init_argobots(); + return t->t_handle == opal_thread_get_argobots_self(); +} + +int opal_thread_join(opal_thread_t *t, void **thr_return) { + ensure_init_argobots(); + int rc = ABT_thread_free(&t->t_handle); + if (thr_return) + *thr_return = t->t_ret; + t->t_handle = ABT_THREAD_NULL; + return (rc == 0) ? OPAL_SUCCESS : OPAL_ERROR; +} + +void opal_thread_set_main() { + ensure_init_argobots(); + opal_main_thread = opal_thread_get_argobots_self(); +} + +int opal_thread_start(opal_thread_t *t) { + ensure_init_argobots(); + int rc; + if (OPAL_ENABLE_DEBUG) { + if (NULL == t->t_run || t->t_handle != ABT_THREAD_NULL) { + return OPAL_ERR_BAD_PARAM; + } + } + + ABT_xstream self_xstream; + ABT_xstream_self(&self_xstream); + rc = ABT_thread_create_on_xstream(self_xstream, + opal_thread_argobots_wrapper, t, + ABT_THREAD_ATTR_NULL, &t->t_handle); + + return (rc == 0) ? OPAL_SUCCESS : OPAL_ERROR; +} + +opal_class_t opal_thread_t_class; + +int opal_tsd_key_create(opal_tsd_key_t *key, opal_tsd_destructor_t destructor) +{ + ensure_init_argobots(); + int rc; + rc = ABT_key_create(destructor, key); + if ((0 == rc) && (opal_thread_get_argobots_self() == opal_main_thread)) { + opal_tsd_key_values = (struct opal_tsd_key_value *)realloc(opal_tsd_key_values, (opal_tsd_key_values_count+1) * sizeof(struct opal_tsd_key_value)); + opal_tsd_key_values[opal_tsd_key_values_count].key = *key; + opal_tsd_key_values[opal_tsd_key_values_count].destructor = destructor; + opal_tsd_key_values_count ++; + } + return rc; +} + +int opal_tsd_keys_destruct() +{ + ensure_init_argobots(); + int i; + void * ptr; + for (i=0; i +#include + +#include "opal/mca/threads/mutex.h" +#include "opal/mca/threads/argobots/threads_argobots_mutex.h" + +/* + * Wait and see if some upper layer wants to use threads, if support + * exists. + */ +bool opal_uses_threads = false; + +static void mca_threads_argobots_mutex_constructor(opal_mutex_t *p_mutex) { + ensure_init_argobots(); + p_mutex->m_lock_argobots = OPAL_ABT_MUTEX_NULL; + p_mutex->m_recursive = 0; +#if OPAL_ENABLE_DEBUG + p_mutex->m_lock_debug = 0; + p_mutex->m_lock_file = NULL; + p_mutex->m_lock_line = 0; +#endif + opal_atomic_lock_init(&p_mutex->m_lock_atomic, 0); +} + +static void mca_threads_argobots_mutex_desctructor(opal_mutex_t *p_mutex) { + ensure_init_argobots(); + if (p_mutex->m_lock_argobots != OPAL_ABT_MUTEX_NULL) + ABT_mutex_free(&p_mutex->m_lock_argobots); +} + +static void mca_threads_argobots_recursive_mutex_constructor + (opal_recursive_mutex_t *p_mutex) { + ensure_init_argobots(); + p_mutex->m_lock_argobots = OPAL_ABT_MUTEX_NULL; + p_mutex->m_recursive = 1; +#if OPAL_ENABLE_DEBUG + p_mutex->m_lock_debug = 0; + p_mutex->m_lock_file = NULL; + p_mutex->m_lock_line = 0; +#endif + opal_atomic_lock_init(&p_mutex->m_lock_atomic, 0); +} + +static void mca_threads_argobots_recursive_mutex_desctructor + (opal_recursive_mutex_t *p_mutex) { + ensure_init_argobots(); + if (p_mutex->m_lock_argobots != OPAL_ABT_MUTEX_NULL) + ABT_mutex_free(&p_mutex->m_lock_argobots); +} + +OBJ_CLASS_INSTANCE(opal_mutex_t, + opal_object_t, + mca_threads_argobots_mutex_constructor, + mca_threads_argobots_mutex_desctructor); +OBJ_CLASS_INSTANCE(opal_recursive_mutex_t, + opal_object_t, + mca_threads_argobots_recursive_mutex_constructor, + mca_threads_argobots_recursive_mutex_desctructor); diff --git a/opal/mca/threads/argobots/threads_argobots_mutex.h b/opal/mca/threads/argobots/threads_argobots_mutex.h new file mode 100644 index 00000000000..72da868f0a6 --- /dev/null +++ b/opal/mca/threads/argobots/threads_argobots_mutex.h @@ -0,0 +1,311 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ +/* + * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana + * University Research and Technology + * Corporation. All rights reserved. + * Copyright (c) 2004-2006 The University of Tennessee and The University + * of Tennessee Research Foundation. All rights + * reserved. + * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, + * University of Stuttgart. All rights reserved. + * Copyright (c) 2004-2005 The Regents of the University of California. + * All rights reserved. + * Copyright (c) 2007-2018 Los Alamos National Security, LLC. All rights + * reserved. + * Copyright (c) 2015-2016 Research Organization for Information Science + * and Technology (RIST). All rights reserved. + * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. + * + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + +#ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_MUTEX_H +#define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_MUTEX_H 1 + +/** + * @file: + * + * Mutual exclusion functions: Unix implementation. + * + * Functions for locking of critical sections. + * + * On unix, use Argobots or our own atomic operations as + * available. + */ + +#include "opal/mca/threads/argobots/threads_argobots.h" +#include "opal_config.h" + +#include +#include + +#include "opal/class/opal_object.h" +#include "opal/sys/atomic.h" + +#include + +BEGIN_C_DECLS + +/* Don't use ABT_MUTEX_NULL, since it might be not NULL. */ +#define OPAL_ABT_MUTEX_NULL 0 + +struct opal_mutex_t { + opal_object_t super; + + ABT_mutex m_lock_argobots; + int m_recursive; + +#if OPAL_ENABLE_DEBUG + int m_lock_debug; + const char *m_lock_file; + int m_lock_line; +#endif + + opal_atomic_lock_t m_lock_atomic; +}; + +typedef struct opal_argobots_mutex_t opal_pthread_mutex_t; +typedef struct opal_argobots_mutex_t opal_pthread_recursive_mutex_t; + +OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_mutex_t); +OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_recursive_mutex_t); + +#if OPAL_ENABLE_DEBUG +#define OPAL_MUTEX_STATIC_INIT \ + { \ + .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), \ + .m_lock_argobots = OPAL_ABT_MUTEX_NULL, \ + .m_recursive = 0, \ + .m_lock_debug = 0, \ + .m_lock_file = NULL, \ + .m_lock_line = 0, \ + .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \ + } +#else +#define OPAL_MUTEX_STATIC_INIT \ + { \ + .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), \ + .m_lock_argobots = OPAL_ABT_MUTEX_NULL, \ + .m_recursive = 0, \ + .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \ + } +#endif + +#if defined(OPAL_PTHREAD_RECURSIVE_MUTEX_INITIALIZER) + +#if OPAL_ENABLE_DEBUG +#define OPAL_RECURSIVE_MUTEX_STATIC_INIT \ + { \ + .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), \ + .m_lock_argobots = OPAL_ABT_MUTEX_NULL, \ + .m_recursive = 1, \ + .m_lock_debug = 0, \ + .m_lock_file = NULL, \ + .m_lock_line = 0, \ + .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \ + } +#else +#define OPAL_RECURSIVE_MUTEX_STATIC_INIT \ + { \ + .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), \ + .m_lock_argobots = OPAL_ABT_MUTEX_NULL, \ + .m_recursive = 1, \ + .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \ + } +#endif + +#endif + +/************************************************************************ + * + * mutex operations (non-atomic versions) + * + ************************************************************************/ + +static inline void opal_mutex_create(struct opal_mutex_t *m) { + while (m->m_lock_argobots == OPAL_ABT_MUTEX_NULL) { + ABT_mutex abt_mutex; + if (m->m_recursive) { + ABT_mutex_attr abt_mutex_attr; + ABT_mutex_attr_create(&abt_mutex_attr); + ABT_mutex_attr_set_recursive(abt_mutex_attr, ABT_TRUE); + ABT_mutex_create_with_attr(abt_mutex_attr, &abt_mutex); + ABT_mutex_attr_free(&abt_mutex_attr); + } else { + ABT_mutex_create(&abt_mutex); + } + void *null_ptr = OPAL_ABT_MUTEX_NULL; + if (opal_atomic_compare_exchange_strong_ptr( + (intptr_t *)&m->m_lock_argobots, (intptr_t *)&null_ptr, + (intptr_t)abt_mutex)) { + /* mutex is successfully created and substituted. */ + return; + } + ABT_mutex_free(&abt_mutex); + } +} + +static inline int opal_mutex_trylock(opal_mutex_t *m) +{ + ensure_init_argobots(); + if (m->m_lock_argobots == OPAL_ABT_MUTEX_NULL) + opal_mutex_create(m); +#if OPAL_ENABLE_DEBUG + int ret = ABT_mutex_trylock(m->m_lock_argobots); + if (ret != 0) { + errno = ret; + perror("opal_mutex_trylock()"); + abort(); + } + return ret; +#else + return ABT_mutex_trylock(m->m_lock_argobots); +#endif +} + +static inline void opal_mutex_lock(opal_mutex_t *m) +{ + ensure_init_argobots(); + if (m->m_lock_argobots == OPAL_ABT_MUTEX_NULL) + opal_mutex_create(m); +#if OPAL_ENABLE_DEBUG + int ret = ABT_mutex_lock(m->m_lock_argobots); + if (ret != 0) { + errno = ret; + perror("opal_mutex_lock()"); + abort(); + } +#else + ABT_mutex_lock(m->m_lock_argobots); +#endif +} + +static inline void opal_mutex_unlock(opal_mutex_t *m) +{ + ensure_init_argobots(); + if (m->m_lock_argobots == OPAL_ABT_MUTEX_NULL) + opal_mutex_create(m); +#if OPAL_ENABLE_DEBUG + int ret = ABT_mutex_unlock(m->m_lock_argobots); + if (ret != 0) { + errno = ret; + perror("opal_mutex_unlock"); + abort(); + } +#else + ABT_mutex_unlock(m->m_lock_argobots); +#endif + /* For fairness of locking. */ + ABT_thread_yield(); +} + +/************************************************************************ + * + * mutex operations (atomic versions) + * + ************************************************************************/ + +#if OPAL_HAVE_ATOMIC_SPINLOCKS + +/************************************************************************ + * Spin Locks + ************************************************************************/ + +static inline int opal_mutex_atomic_trylock(opal_mutex_t *m) +{ + return opal_atomic_trylock(&m->m_lock_atomic); +} + +static inline void opal_mutex_atomic_lock(opal_mutex_t *m) +{ + opal_atomic_lock(&m->m_lock_atomic); +} + +static inline void opal_mutex_atomic_unlock(opal_mutex_t *m) +{ + opal_atomic_unlock(&m->m_lock_atomic); +} + +#else + +/************************************************************************ + * Standard locking + ************************************************************************/ + +static inline int opal_mutex_atomic_trylock(opal_mutex_t *m) +{ + return opal_mutex_trylock(m); +} + +static inline void opal_mutex_atomic_lock(opal_mutex_t *m) +{ + opal_mutex_lock(m); +} + +static inline void opal_mutex_atomic_unlock(opal_mutex_t *m) +{ + opal_mutex_unlock(m); +} + +#endif + +#define OPAL_ABT_COND_NULL NULL +typedef ABT_cond opal_cond_t; +#define OPAL_CONDITION_STATIC_INIT OPAL_ABT_COND_NULL + +static inline void opal_cond_create(opal_cond_t *cond) { + ensure_init_argobots(); + while (*cond == OPAL_ABT_COND_NULL) { + ABT_cond new_cond; + ABT_cond_create(&new_cond); + void *null_ptr = OPAL_ABT_COND_NULL; + if (opal_atomic_compare_exchange_strong_ptr((intptr_t *)cond, + (intptr_t *)&null_ptr, + (intptr_t)new_cond)) { + /* cond is successfully created and substituted. */ + return; + } + ABT_cond_free(&new_cond); + } +} + +static inline int opal_cond_init(opal_cond_t *cond) { + *cond = OPAL_ABT_COND_NULL; + return 0; +} + +static inline int opal_cond_wait(opal_cond_t *cond, opal_mutex_t *lock) { + ensure_init_argobots(); + if (*cond == OPAL_ABT_COND_NULL) + opal_cond_create(cond); + return ABT_cond_wait(*cond, lock->m_lock_argobots); +} + +static inline int opal_cond_broadcast(opal_cond_t *cond) { + ensure_init_argobots(); + if (*cond == OPAL_ABT_COND_NULL) + opal_cond_create(cond); + return ABT_cond_broadcast(*cond); +} + +static inline int opal_cond_signal(opal_cond_t *cond) { + ensure_init_argobots(); + if (*cond == OPAL_ABT_COND_NULL) + opal_cond_create(cond); + return ABT_cond_signal(*cond); +} + +static inline int opal_cond_destroy(opal_cond_t *cond) { + ensure_init_argobots(); + if (*cond != OPAL_ABT_COND_NULL) + ABT_cond_free(cond); + return 0; +} + +END_C_DECLS + +#endif /* OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_MUTEX_H */ diff --git a/opal/mca/threads/argobots/threads_argobots_threads.h b/opal/mca/threads/argobots/threads_argobots_threads.h new file mode 100644 index 00000000000..5a7d7a772c7 --- /dev/null +++ b/opal/mca/threads/argobots/threads_argobots_threads.h @@ -0,0 +1,16 @@ + +#ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_THREADS_H +#define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_THREADS_H 1 + +#include +#include + +struct opal_thread_t { + opal_object_t super; + opal_thread_fn_t t_run; + void* t_arg; + ABT_thread t_handle; + void* t_ret; +}; + +#endif /* OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_THREADS_H */ diff --git a/opal/mca/threads/argobots/threads_argobots_tsd.h b/opal/mca/threads/argobots/threads_argobots_tsd.h new file mode 100644 index 00000000000..290adadfde3 --- /dev/null +++ b/opal/mca/threads/argobots/threads_argobots_tsd.h @@ -0,0 +1,32 @@ + +#ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_TSD_H +#define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_TSD_H 1 + +#include "opal/mca/threads/argobots/threads_argobots.h" +#include + +typedef ABT_key opal_tsd_key_t; + +static inline int +opal_tsd_key_delete(opal_tsd_key_t key) +{ + ensure_init_argobots(); + return ABT_key_free(&key); +} + +static inline int +opal_tsd_setspecific(opal_tsd_key_t key, void *value) +{ + ensure_init_argobots(); + return ABT_key_set(key, value); +} + +static inline int +opal_tsd_getspecific(opal_tsd_key_t key, void **valuep) +{ + ensure_init_argobots(); + ABT_key_get(key, valuep); + return OPAL_SUCCESS; +} + +#endif /* OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_TSD_H */ diff --git a/opal/mca/threads/argobots/threads_argobots_wait_sync.c b/opal/mca/threads/argobots/threads_argobots_wait_sync.c new file mode 100644 index 00000000000..dddb7eafbf7 --- /dev/null +++ b/opal/mca/threads/argobots/threads_argobots_wait_sync.c @@ -0,0 +1,112 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ +/* + * Copyright (c) 2014-2016 The University of Tennessee and The University + * of Tennessee Research Foundation. All rights + * reserved. + * Copyright (c) 2016 Los Alamos National Security, LLC. All rights + * reserved. + * Copyright (c) 2017 IBM Corporation. All rights reserved. + * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. + * + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ +#include "opal/mca/threads/argobots/threads_argobots.h" +#include "opal/mca/threads/wait_sync.h" + +static opal_mutex_t wait_sync_lock = OPAL_MUTEX_STATIC_INIT; +static ompi_wait_sync_t* wait_sync_list = NULL; + +static opal_atomic_int32_t num_thread_in_progress = 0; + +#define WAIT_SYNC_PASS_OWNERSHIP(who) \ + do { \ + ensure_init_argobots(); \ + ABT_mutex_lock((who)->lock); \ + ABT_cond_signal((who)->condition ); \ + ABT_mutex_unlock((who)->lock); \ + } while(0) + +int ompi_sync_wait_mt(ompi_wait_sync_t *sync) +{ + ensure_init_argobots(); + /* Don't stop if the waiting synchronization is completed. We avoid the + * race condition around the release of the synchronization using the + * signaling field. + */ + if(sync->count <= 0) + return (0 == sync->status) ? OPAL_SUCCESS : OPAL_ERROR; + + /* lock so nobody can signal us during the list updating */ + ABT_mutex_lock(sync->lock); + + /* Now that we hold the lock make sure another thread has not already + * call cond_signal. + */ + if(sync->count <= 0) { + ABT_mutex_unlock(sync->lock); + return (0 == sync->status) ? OPAL_SUCCESS : OPAL_ERROR; + } + + /* Insert sync on the list of pending synchronization constructs */ + OPAL_THREAD_LOCK(&wait_sync_lock); + if( NULL == wait_sync_list ) { + sync->next = sync->prev = sync; + wait_sync_list = sync; + } else { + sync->prev = wait_sync_list->prev; + sync->prev->next = sync; + sync->next = wait_sync_list; + wait_sync_list->prev = sync; + } + OPAL_THREAD_UNLOCK(&wait_sync_lock); + + /** + * If we are not responsible for progresing, go silent until something worth noticing happen: + * - this thread has been promoted to take care of the progress + * - our sync has been triggered. + */ + check_status: + if( sync != wait_sync_list && num_thread_in_progress >= opal_max_thread_in_progress) { + ABT_cond_wait(sync->condition, sync->lock); + + /** + * At this point either the sync was completed in which case + * we should remove it from the wait list, or/and I was + * promoted as the progress manager. + */ + + if( sync->count <= 0 ) { /* Completed? */ + ABT_mutex_unlock(sync->lock); + goto i_am_done; + } + /* either promoted, or spurious wakeup ! */ + goto check_status; + } + ABT_mutex_unlock(sync->lock); + + OPAL_THREAD_ADD_FETCH32(&num_thread_in_progress, 1); + while(sync->count > 0) { /* progress till completion */ + opal_progress(); /* don't progress with the sync lock locked or you'll deadlock */ + ABT_thread_yield(); + } + OPAL_THREAD_ADD_FETCH32(&num_thread_in_progress, -1); + + i_am_done: + /* My sync is now complete. Trim the list: remove self, wake next */ + OPAL_THREAD_LOCK(&wait_sync_lock); + sync->prev->next = sync->next; + sync->next->prev = sync->prev; + /* In case I am the progress manager, pass the duties on */ + if( sync == wait_sync_list ) { + wait_sync_list = (sync == sync->next) ? NULL : sync->next; + if( NULL != wait_sync_list ) + WAIT_SYNC_PASS_OWNERSHIP(wait_sync_list); + } + OPAL_THREAD_UNLOCK(&wait_sync_lock); + + return (0 == sync->status) ? OPAL_SUCCESS : OPAL_ERROR; +} diff --git a/opal/mca/threads/argobots/threads_argobots_wait_sync.h b/opal/mca/threads/argobots/threads_argobots_wait_sync.h new file mode 100644 index 00000000000..dbe443db550 --- /dev/null +++ b/opal/mca/threads/argobots/threads_argobots_wait_sync.h @@ -0,0 +1,87 @@ + +#ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_WAIT_SYNC_H +#define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_WAIT_SYNC_H 1 + +#include "opal/mca/threads/argobots/threads_argobots.h" +#include + +typedef struct ompi_wait_sync_t { + opal_atomic_int32_t count; + int32_t status; + ABT_cond condition; + ABT_mutex lock; + struct ompi_wait_sync_t *next; + struct ompi_wait_sync_t *prev; + volatile bool signaling; +} ompi_wait_sync_t; + +#define SYNC_WAIT(sync) (opal_using_threads() ? ompi_sync_wait_mt (sync) : sync_wait_st (sync)) + +/* The loop in release handles a race condition between the signaling + * thread and the destruction of the condition variable. The signaling + * member will be set to false after the final signaling thread has + * finished operating on the sync object. This is done to avoid + * extra atomics in the signalling function and keep it as fast + * as possible. Note that the race window is small so spinning here + * is more optimal than sleeping since this macro is called in + * the critical path. */ +#define WAIT_SYNC_RELEASE(sync) \ + if (opal_using_threads()) { \ + ensure_init_argobots(); \ + while ((sync)->signaling) { \ + ABT_thread_yield(); \ + continue; \ + } \ + ABT_cond_free(&(sync)->condition); \ + ABT_mutex_free(&(sync)->lock); \ + } + +#define WAIT_SYNC_RELEASE_NOWAIT(sync) \ + if (opal_using_threads()) { \ + ensure_init_argobots(); \ + ABT_cond_free(&(sync)->condition); \ + ABT_mutex_free(&(sync)->lock); \ + } + + +#define WAIT_SYNC_SIGNAL(sync) \ + if (opal_using_threads()) { \ + ensure_init_argobots(); \ + ABT_mutex_lock(sync->lock); \ + ABT_cond_signal(sync->condition); \ + ABT_mutex_unlock(sync->lock); \ + sync->signaling = false; \ + } + +#define WAIT_SYNC_SIGNALLED(sync){ \ + (sync)->signaling = false; \ +} + +OPAL_DECLSPEC int ompi_sync_wait_mt(ompi_wait_sync_t *sync); +static inline int sync_wait_st (ompi_wait_sync_t *sync) +{ + ensure_init_argobots(); + while (sync->count > 0) { + opal_progress(); + ABT_thread_yield(); + } + + return sync->status; +} + + +#define WAIT_SYNC_INIT(sync,c) \ + do { \ + (sync)->count = (c); \ + (sync)->next = NULL; \ + (sync)->prev = NULL; \ + (sync)->status = 0; \ + (sync)->signaling = (0 != (c)); \ + if (opal_using_threads()) { \ + ensure_init_argobots(); \ + ABT_cond_create (&(sync)->condition); \ + ABT_mutex_create (&(sync)->lock); \ + } \ + } while(0) + +#endif /* OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_WAIT_SYNC_H */ diff --git a/test/asm/Makefile.am b/test/asm/Makefile.am index 17f222bbd9d..61bc008caa1 100644 --- a/test/asm/Makefile.am +++ b/test/asm/Makefile.am @@ -43,39 +43,40 @@ atomic_barrier_noinline.c: ln -s $(top_srcdir)/test/asm/atomic_barrier.c atomic_barrier_noinline.c atomic_barrier_noinline_SOURCES = atomic_barrier_noinline.c atomic_barrier_noinline_CFLAGS = $(AM_CFLAGS) -DOMPI_DISABLE_INLINE_ASM +atomic_barrier_noinline_LDADD = $(libs) -lpthread ###################################################################### atomic_spinlock_SOURCES = atomic_spinlock.c -atomic_spinlock_LDADD = $(libs) +atomic_spinlock_LDADD = $(libs) -lpthread atomic_spinlock_noinline.c: ln -s $(top_srcdir)/test/asm/atomic_spinlock.c atomic_spinlock_noinline.c atomic_spinlock_noinline_SOURCES = atomic_spinlock_noinline.c atomic_spinlock_noinline_CFLAGS = $(AM_CFLAGS) -DOMPI_DISABLE_INLINE_ASM -atomic_spinlock_noinline_LDADD = $(libs) +atomic_spinlock_noinline_LDADD = $(libs) -lpthread ###################################################################### atomic_math_SOURCES = atomic_math.c -atomic_math_LDADD = $(libs) +atomic_math_LDADD = $(libs) -lpthread atomic_math_noinline.c: ln -s $(top_srcdir)/test/asm/atomic_math.c atomic_math_noinline.c atomic_math_noinline_SOURCES = atomic_math_noinline.c atomic_math_noinline_CFLAGS = $(AM_CFLAGS) -DOMPI_DISABLE_INLINE_ASM -atomic_math_noinline_LDADD = $(libs) +atomic_math_noinline_LDADD = $(libs) -lpthread ###################################################################### atomic_cmpset_SOURCES = atomic_cmpset.c -atomic_cmpset_LDADD = $(libs) +atomic_cmpset_LDADD = $(libs) -lpthread atomic_cmpset_noinline.c: ln -s $(top_srcdir)/test/asm/atomic_cmpset.c atomic_cmpset_noinline.c atomic_cmpset_noinline_SOURCES = atomic_cmpset_noinline.c atomic_cmpset_noinline_CFLAGS = $(AM_CFLAGS) -DOMPI_DISABLE_INLINE_ASM -atomic_cmpset_noinline_LDADD = $(libs) +atomic_cmpset_noinline_LDADD = $(libs) -lpthread ###################################################################### diff --git a/test/class/Makefile.am b/test/class/Makefile.am index 4dc7daf24cc..46f1c584ac9 100644 --- a/test/class/Makefile.am +++ b/test/class/Makefile.am @@ -92,13 +92,15 @@ ompi_rb_tree_DEPENDENCIES = $(ompi_rb_tree_LDADD) opal_lifo_SOURCES = opal_lifo.c opal_lifo_LDADD = \ $(top_builddir)/opal/lib@OPAL_LIB_PREFIX@open-pal.la \ - $(top_builddir)/test/support/libsupport.a + $(top_builddir)/test/support/libsupport.a \ + -lpthread opal_lifo_DEPENDENCIES = $(opal_lifo_LDADD) opal_fifo_SOURCES = opal_fifo.c opal_fifo_LDADD = \ $(top_builddir)/opal/lib@OPAL_LIB_PREFIX@open-pal.la \ - $(top_builddir)/test/support/libsupport.a + $(top_builddir)/test/support/libsupport.a \ + -lpthread opal_fifo_DEPENDENCIES = $(opal_fifo_LDADD) clean-local: diff --git a/test/class/opal_fifo.c b/test/class/opal_fifo.c index 122524a8d9f..400bfd55222 100644 --- a/test/class/opal_fifo.c +++ b/test/class/opal_fifo.c @@ -18,6 +18,7 @@ #include "opal/runtime/opal.h" #include "opal/constants.h" +#include #include #include #include diff --git a/test/class/opal_lifo.c b/test/class/opal_lifo.c index 521bb4e5d97..7997065b6d0 100644 --- a/test/class/opal_lifo.c +++ b/test/class/opal_lifo.c @@ -20,6 +20,7 @@ #include #include #include +#include #include From 6cdb2df8c0a4bec204a02fd7ba8943535ec4fca1 Mon Sep 17 00:00:00 2001 From: Howard Pritchard Date: Fri, 21 Jun 2019 09:21:31 -0600 Subject: [PATCH 07/17] address some feedback from PR review Signed-off-by: Howard Pritchard --- .../argobots/threads_argobots_component.c | 4 +- .../threads/argobots/threads_argobots_event.c | 140 +++++++++--------- opal/mca/threads/base/base.h | 2 +- opal/mca/threads/base/threads_base_open.c | 1 - opal/mca/threads/condition.h | 10 +- opal/mca/threads/configure.m4 | 8 +- opal/mca/threads/mutex.h | 8 +- .../pthreads/threads_pthreads_component.c | 4 +- .../threads/pthreads/threads_pthreads_mutex.c | 1 - .../qthreads/threads_qthreads_component.c | 4 +- .../qthreads/threads_qthreads_module.c | 3 +- opal/mca/threads/thread.h | 52 +------ opal/mca/threads/threads.h | 2 +- opal/mca/threads/tsd.h | 2 +- opal/mca/threads/wait_sync.h | 2 +- 15 files changed, 99 insertions(+), 144 deletions(-) diff --git a/opal/mca/threads/argobots/threads_argobots_component.c b/opal/mca/threads/argobots/threads_argobots_component.c index 248473a2e27..b72b0bca859 100644 --- a/opal/mca/threads/argobots/threads_argobots_component.c +++ b/opal/mca/threads/argobots/threads_argobots_component.c @@ -31,11 +31,11 @@ static int opal_threads_argobots_open(void); -const opal_threads_base_component_2_0_0_t mca_threads_argobots_component = { +const opal_threads_base_component_1_0_0_t mca_threads_argobots_component = { /* First, the mca_component_t struct containing meta information about the component itself */ .threadsc_version = { - OPAL_THREADS_BASE_VERSION_2_0_0, + OPAL_THREADS_BASE_VERSION_1_0_0, /* Component name and version */ .mca_component_name = "argobots", diff --git a/opal/mca/threads/argobots/threads_argobots_event.c b/opal/mca/threads/argobots/threads_argobots_event.c index 98830d27891..c9c9fd98baf 100644 --- a/opal/mca/threads/argobots/threads_argobots_event.c +++ b/opal/mca/threads/argobots/threads_argobots_event.c @@ -11,7 +11,7 @@ static void * evthread_argobots_lock_alloc(unsigned locktype) { ABT_mutex lock; - if (locktype & EVTHREAD_LOCKTYPE_RECURSIVE) { + if (locktype & EVTHREAD_LOCKTYPE_RECURSIVE) { ABT_mutex_attr abt_mutex_attr; ABT_mutex_attr_create(&abt_mutex_attr); ABT_mutex_attr_set_recursive(abt_mutex_attr, ABT_TRUE); @@ -20,117 +20,117 @@ evthread_argobots_lock_alloc(unsigned locktype) } else { ABT_mutex_create(&lock); } - return lock; + return lock; } static void evthread_argobots_lock_free(void *_lock, unsigned locktype) { - ABT_mutex lock = _lock; - ABT_mutex_free(&lock); + ABT_mutex lock = _lock; + ABT_mutex_free(&lock); } static int evthread_argobots_lock(unsigned mode, void *_lock) { - int ret; - ABT_mutex lock = _lock; - if (mode & EVTHREAD_TRY) { - ret = ABT_mutex_trylock(lock); - } else { - ret = ABT_mutex_lock(lock); - } - return ret; + int ret; + ABT_mutex lock = _lock; + if (mode & EVTHREAD_TRY) { + ret = ABT_mutex_trylock(lock); + } else { + ret = ABT_mutex_lock(lock); + } + return ret; } static int evthread_argobots_unlock(unsigned mode, void *_lock) { - ABT_mutex lock = _lock; - int ret = ABT_mutex_unlock(lock); - /* This yield is necessary to avoid taking a lock consecutively. */ - ABT_thread_yield(); - return ret; + ABT_mutex lock = _lock; + int ret = ABT_mutex_unlock(lock); + /* This yield is necessary to avoid taking a lock consecutively. */ + ABT_thread_yield(); + return ret; } static unsigned long evthread_argobots_get_id(void) { - ABT_thread thr; - ABT_thread_self(&thr); - return (unsigned long)((intptr_t)thr); + ABT_thread thr; + ABT_thread_self(&thr); + return (unsigned long)((intptr_t)thr); } static void * evthread_argobots_cond_alloc(unsigned condflags) { - ABT_cond cond; - ABT_cond_create(&cond); - return cond; + ABT_cond cond; + ABT_cond_create(&cond); + return cond; } static void evthread_argobots_cond_free(void *_cond) { - ABT_cond cond = _cond; - ABT_cond_free(&cond); + ABT_cond cond = _cond; + ABT_cond_free(&cond); } static int evthread_argobots_cond_signal(void *_cond, int broadcast) { - ABT_cond cond = _cond; - int r; - if (broadcast) - r = ABT_cond_broadcast(cond); - else - r = ABT_cond_signal(cond); - return r ? -1 : 0; + ABT_cond cond = _cond; + int r; + if (broadcast) + r = ABT_cond_broadcast(cond); + else + r = ABT_cond_signal(cond); + return r ? -1 : 0; } static int evthread_argobots_cond_wait(void *_cond, void *_lock, const struct timeval *tv) { - int r; - ABT_cond cond = _cond; - ABT_mutex lock = _lock; + int r; + ABT_cond cond = _cond; + ABT_mutex lock = _lock; - if (tv) { - struct timeval now, abstime; - struct timespec ts; - evutil_gettimeofday(&now, NULL); - evutil_timeradd(&now, tv, &abstime); - ts.tv_sec = abstime.tv_sec; - ts.tv_nsec = abstime.tv_usec*1000; - r = ABT_cond_timedwait(cond, lock, &ts); - if (r != 0) - return 1; - else - return 0; - } else { - r = ABT_cond_wait(cond, lock); - return r ? -1 : 0; - } + if (tv) { + struct timeval now, abstime; + struct timespec ts; + evutil_gettimeofday(&now, NULL); + evutil_timeradd(&now, tv, &abstime); + ts.tv_sec = abstime.tv_sec; + ts.tv_nsec = abstime.tv_usec*1000; + r = ABT_cond_timedwait(cond, lock, &ts); + if (r != 0) + return 1; + else + return 0; + } else { + r = ABT_cond_wait(cond, lock); + return r ? -1 : 0; + } } void opal_event_use_threads(void) { - struct evthread_lock_callbacks cbs = { - EVTHREAD_LOCK_API_VERSION, - EVTHREAD_LOCKTYPE_RECURSIVE, - evthread_argobots_lock_alloc, - evthread_argobots_lock_free, - evthread_argobots_lock, - evthread_argobots_unlock - }; - struct evthread_condition_callbacks cond_cbs = { - EVTHREAD_CONDITION_API_VERSION, - evthread_argobots_cond_alloc, - evthread_argobots_cond_free, - evthread_argobots_cond_signal, - evthread_argobots_cond_wait - }; - ensure_init_argobots(); - evthread_set_lock_callbacks(&cbs); - evthread_set_condition_callbacks(&cond_cbs); - evthread_set_id_callback(evthread_argobots_get_id); + struct evthread_lock_callbacks cbs = { + EVTHREAD_LOCK_API_VERSION, + EVTHREAD_LOCKTYPE_RECURSIVE, + evthread_argobots_lock_alloc, + evthread_argobots_lock_free, + evthread_argobots_lock, + evthread_argobots_unlock + }; + struct evthread_condition_callbacks cond_cbs = { + EVTHREAD_CONDITION_API_VERSION, + evthread_argobots_cond_alloc, + evthread_argobots_cond_free, + evthread_argobots_cond_signal, + evthread_argobots_cond_wait + }; + ensure_init_argobots(); + evthread_set_lock_callbacks(&cbs); + evthread_set_condition_callbacks(&cond_cbs); + evthread_set_id_callback(evthread_argobots_get_id); } diff --git a/opal/mca/threads/base/base.h b/opal/mca/threads/base/base.h index 3af4d834a71..f407a1784c2 100644 --- a/opal/mca/threads/base/base.h +++ b/opal/mca/threads/base/base.h @@ -42,6 +42,6 @@ OPAL_DECLSPEC extern mca_base_framework_t opal_threads_base_framework; END_C_DECLS /* include implementation to call */ -#include MCA_threads_IMPLEMENTATION_HEADER +#include MCA_threads_base_include_HEADER #endif /* OPAL_BASE_THREADS_H */ diff --git a/opal/mca/threads/base/threads_base_open.c b/opal/mca/threads/base/threads_base_open.c index 1e15851cec5..4b497280a34 100644 --- a/opal/mca/threads/base/threads_base_open.c +++ b/opal/mca/threads/base/threads_base_open.c @@ -35,7 +35,6 @@ static int mca_threads_base_register(mca_base_register_flag_t flags) { - // Do I need to register anything here? return OPAL_SUCCESS; } diff --git a/opal/mca/threads/condition.h b/opal/mca/threads/condition.h index 3456bde692a..0100231b92a 100644 --- a/opal/mca/threads/condition.h +++ b/opal/mca/threads/condition.h @@ -14,6 +14,9 @@ * Copyright (c) 2015 Research Organization for Information Science * and Technology (RIST). All rights reserved. * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. + * Copyright (c) 2019 Triad National Security, LLC. All rights + * reserved. + * * * $COPYRIGHT$ * @@ -21,8 +24,8 @@ * * $HEADER$ */ -#ifndef OPAL_MCA_CONDITION_SPINLOCK_H -#define OPAL_MCA_CONDITION_SPINLOCK_H +#ifndef OPAL_MCA_THREADS_CONDITION_H +#define OPAL_MCA_THREADS_CONDITION_H #include "opal_config.h" #ifdef HAVE_SYS_TIME_H @@ -143,5 +146,4 @@ static inline int opal_condition_broadcast(opal_condition_t *c) END_C_DECLS -#endif // OPAL_MCA_CONDITION_SPINLOCK_H - +#endif // OPAL_MCA_THREADS_CONDITION_H diff --git a/opal/mca/threads/configure.m4 b/opal/mca/threads/configure.m4 index b35ce36a3b2..e9e08c4f38f 100644 --- a/opal/mca/threads/configure.m4 +++ b/opal/mca/threads/configure.m4 @@ -37,19 +37,19 @@ AC_DEFUN([MCA_opal_threads_CONFIG],[ tsd_base_include="${thread_type}/threads_${thread_type}_tsd.h" wait_sync_base_include="${thread_type}/threads_${thread_type}_wait_sync.h" - AC_DEFINE_UNQUOTED([MCA_threads_IMPLEMENTATION_HEADER], + AC_DEFINE_UNQUOTED([MCA_threads_base_include_HEADER], ["opal/mca/threads/$threads_base_include"], [Header to include for threads implementation]) - AC_DEFINE_UNQUOTED([MCA_mutex_IMPLEMENTATION_HEADER], + AC_DEFINE_UNQUOTED([MCA_threads_mutex_base_include_HEADER], ["opal/mca/threads/$mutex_base_include"], [Header to include for mutex implementation]) - AC_DEFINE_UNQUOTED([MCA_tsd_IMPLEMENTATION_HEADER], + AC_DEFINE_UNQUOTED([MCA_threads_tsd_base_include_HEADER], ["opal/mca/threads/$tsd_base_include"], [Header to include for tsd implementation]) - AC_DEFINE_UNQUOTED([MCA_wait_sync_IMPLEMENTATION_HEADER], + AC_DEFINE_UNQUOTED([MCA_threads_wait_sync_base_include_HEADER], ["opal/mca/threads/$wait_sync_base_include"], [Header to include for wait_sync implementation]) ]) diff --git a/opal/mca/threads/mutex.h b/opal/mca/threads/mutex.h index d0228c98dfb..35a5812d20a 100644 --- a/opal/mca/threads/mutex.h +++ b/opal/mca/threads/mutex.h @@ -24,8 +24,8 @@ * $HEADER$ */ -#ifndef OPAL_MCA_MUTEX_H -#define OPAL_MCA_MUTEX_H 1 +#ifndef OPAL_MCA_THREADS_MUTEX_H +#define OPAL_MCA_THREADS_MUTEX_H 1 #include "opal_config.h" @@ -46,7 +46,7 @@ BEGIN_C_DECLS typedef struct opal_mutex_t opal_mutex_t; typedef struct opal_mutex_t opal_recursive_mutex_t; -#include MCA_mutex_IMPLEMENTATION_HEADER +#include MCA_threads_mutex_base_include_HEADER OBJ_CLASS_DECLARATION(opal_mutex_t); OBJ_CLASS_DECLARATION(opal_recursive_mutex_t); @@ -190,4 +190,4 @@ static inline void opal_mutex_atomic_unlock(opal_mutex_t *mutex); END_C_DECLS -#endif /* OPAL_MCA_MUTEX_H */ +#endif /* OPAL_MCA_THREADS_MUTEX_H */ diff --git a/opal/mca/threads/pthreads/threads_pthreads_component.c b/opal/mca/threads/pthreads/threads_pthreads_component.c index 938497c02d1..85339d1381c 100644 --- a/opal/mca/threads/pthreads/threads_pthreads_component.c +++ b/opal/mca/threads/pthreads/threads_pthreads_component.c @@ -29,11 +29,11 @@ static int opal_threads_pthreads_open(void); -const opal_threads_base_component_2_0_0_t mca_threads_pthreads_component = { +const opal_threads_base_component_1_0_0_t mca_threads_pthreads_component = { /* First, the mca_component_t struct containing meta information about the component itself */ .threadsc_version = { - OPAL_THREADS_BASE_VERSION_2_0_0, + OPAL_THREADS_BASE_VERSION_1_0_0, /* Component name and version */ .mca_component_name = "pthreads", diff --git a/opal/mca/threads/pthreads/threads_pthreads_mutex.c b/opal/mca/threads/pthreads/threads_pthreads_mutex.c index 35ca43a2494..b4e73fbd24c 100644 --- a/opal/mca/threads/pthreads/threads_pthreads_mutex.c +++ b/opal/mca/threads/pthreads/threads_pthreads_mutex.c @@ -29,7 +29,6 @@ #include #include "opal/mca/threads/mutex.h" -//#include "opal/mca/threads/pthreads/mutex_unix.h" /* * Wait and see if some upper layer wants to use threads, if support diff --git a/opal/mca/threads/qthreads/threads_qthreads_component.c b/opal/mca/threads/qthreads/threads_qthreads_component.c index aef0a009d1f..d8be5d0e7fd 100644 --- a/opal/mca/threads/qthreads/threads_qthreads_component.c +++ b/opal/mca/threads/qthreads/threads_qthreads_component.c @@ -28,11 +28,11 @@ static int opal_threads_qthreads_open(void); -const opal_threads_base_component_2_0_0_t mca_threads_qthreads_component = { +const opal_threads_base_component_1_0_0_t mca_threads_qthreads_component = { /* First, the mca_component_t struct containing meta information about the component itself */ .threadsc_version = { - OPAL_THREADS_BASE_VERSION_2_0_0, + OPAL_THREADS_BASE_VERSION_1_0_0, /* Component name and version */ .mca_component_name = "qthreads", diff --git a/opal/mca/threads/qthreads/threads_qthreads_module.c b/opal/mca/threads/qthreads/threads_qthreads_module.c index 554ef07a1b8..393948c2ef3 100644 --- a/opal/mca/threads/qthreads/threads_qthreads_module.c +++ b/opal/mca/threads/qthreads/threads_qthreads_module.c @@ -45,7 +45,6 @@ static void opal_thread_construct(opal_thread_t *t) OBJ_CLASS_INSTANCE(opal_thread_t, opal_object_t, opal_thread_construct, NULL); - opal_thread_t *opal_thread_get_self(void) @@ -61,7 +60,7 @@ bool opal_thread_self_compare(opal_thread_t *t) } int sync_wait_mt(void *p) { - return 0; + return 0; } int opal_thread_join(opal_thread_t *t, void **thr_return) { diff --git a/opal/mca/threads/thread.h b/opal/mca/threads/thread.h index 4740d08b60c..9bf106a6dc7 100644 --- a/opal/mca/threads/thread.h +++ b/opal/mca/threads/thread.h @@ -21,50 +21,6 @@ * $HEADER$ */ -/** - * @file - * - * High resolution threads / cycle counter - * - * High resolution threads / cycle counter interface. This interface is - * intended to hide the system-dependent nature of threadss that provide - * higher resolution and lower calling cost than gettimeofday(). - * Unlike most component interfaces, there should only ever be one - * component available to be built on a particular platform. - * Therefore, a number of #defines are available to determine how well - * the platform supports high resolution threadss: - * - *
      - *
    • OPAL_THREADS_CYCLE_NATIVE
      Whether - * opal_threads_base_get_cycle() is implemented directly or computed - * from some other data (such as a high res threads)
    • - *
    • OPAL_THREADS_CYCLE_SUPPORTED
      Whether - * opal_threads_base_get_cycle() is supported on the current - * platform.
    • - *
    • OPAL_THREADS_USEC_SUPPORTED
      Whether - * opal_threads_base_get_usec() is supported on the current - * platform or implemented on top of gettimeofday(), which - * may be unsuitable for some uses. - *
    - * - * The cycle count may not be the cycle count of the CPU itself, if - * there is another sufficiently close counter with better behavior - * characteristics (like the Time Base counter on many Power/PowerPC - * platforms). The function opal_threads_base_get_freq() returns the - * frequency of the cycle counter in use, *NOT* the frequency of the - * main CPU. - * - * Unless otherwise noted, no attempt is made to cope with the the - * differences in counters on SMP machines. If your process switches - * CPUs, your threads results may change. - * - * Build time priorities are allocated as follows: - * - * - 0 gettimeofday() wrapper - * - 10 Assembly threadss with bad frequency search (Linux) - * - 20 NIC software stack (QSNet, Myrinet?) - * - 30 Operating systems with native interfaces - */ #ifndef OPAL_MCA_THREADS_THREADS_H #define OPAL_MCA_THREADS_THREADS_H @@ -78,7 +34,7 @@ /** * Structure for threads components. */ -struct opal_threads_base_component_2_0_0_t { +struct opal_threads_base_component_1_0_0_t { /** MCA base component */ mca_base_component_t threadsc_version; /** MCA base data */ @@ -87,12 +43,12 @@ struct opal_threads_base_component_2_0_0_t { /** * Convenience typedef */ -typedef struct opal_threads_base_component_2_0_0_t opal_threads_base_component_2_0_0_t; +typedef struct opal_threads_base_component_1_0_0_t opal_threads_base_component_1_0_0_t; /* * Macro for use in components that are of type threads */ -#define OPAL_THREADS_BASE_VERSION_2_0_0 \ - OPAL_MCA_BASE_VERSION_2_1_0("threads", 2, 0, 0) +#define OPAL_THREADS_BASE_VERSION_1_0_0 \ + OPAL_MCA_BASE_VERSION_2_1_0("threads", 1, 0, 0) #endif /* OPAL_MCA_THREADS_THREADS_H */ diff --git a/opal/mca/threads/threads.h b/opal/mca/threads/threads.h index c69de3f774d..b7378e4db61 100644 --- a/opal/mca/threads/threads.h +++ b/opal/mca/threads/threads.h @@ -41,7 +41,7 @@ typedef void *(*opal_thread_fn_t) (opal_object_t *); #define OPAL_THREAD_CANCELLED ((void*)1); -#include MCA_threads_IMPLEMENTATION_HEADER +#include MCA_threads_base_include_HEADER typedef struct opal_thread_t opal_thread_t; diff --git a/opal/mca/threads/tsd.h b/opal/mca/threads/tsd.h index 5f5a7ffd625..83950da1913 100644 --- a/opal/mca/threads/tsd.h +++ b/opal/mca/threads/tsd.h @@ -108,7 +108,7 @@ OPAL_DECLSPEC int opal_tsd_getspecific(opal_tsd_key_t key, void **valuep); #else -#include MCA_tsd_IMPLEMENTATION_HEADER +#include MCA_threads_tsd_base_include_HEADER #endif diff --git a/opal/mca/threads/wait_sync.h b/opal/mca/threads/wait_sync.h index 4dc9f9ecb07..96c9fe90b8c 100644 --- a/opal/mca/threads/wait_sync.h +++ b/opal/mca/threads/wait_sync.h @@ -27,7 +27,7 @@ BEGIN_C_DECLS extern int opal_max_thread_in_progress; -#include MCA_wait_sync_IMPLEMENTATION_HEADER +#include MCA_threads_wait_sync_base_include_HEADER #define REQUEST_PENDING (void*)0L #define REQUEST_COMPLETED (void*)1L From 837e6702c8e774e8454b757701b7bf3a1eaa569a Mon Sep 17 00:00:00 2001 From: Howard Pritchard Date: Fri, 21 Jun 2019 10:31:38 -0600 Subject: [PATCH 08/17] minor configury change Signed-off-by: Howard Pritchard --- opal/mca/threads/argobots/configure.m4 | 2 -- opal/mca/threads/pthreads/configure.m4 | 2 -- 2 files changed, 4 deletions(-) diff --git a/opal/mca/threads/argobots/configure.m4 b/opal/mca/threads/argobots/configure.m4 index 26d327ac143..22bc1f1e962 100644 --- a/opal/mca/threads/argobots/configure.m4 +++ b/opal/mca/threads/argobots/configure.m4 @@ -54,8 +54,6 @@ AC_DEFUN([MCA_opal_wait_sync_argobots_POST_CONFIG],[ AC_DEFUN([MCA_opal_threads_argobots_CONFIG],[ AC_CONFIG_FILES([opal/mca/threads/argobots/Makefile]) - AC_MSG_CHECKING([HAVE_THREAD_PKG_TYPE = $HAVE_THREAD_PKG_TYPE]) - AS_IF([test "$HAVE_THREAD_PKG_TYPE" = "argobots"], [$1], [$2]) diff --git a/opal/mca/threads/pthreads/configure.m4 b/opal/mca/threads/pthreads/configure.m4 index f0ca42683ce..7ec32e36c9f 100644 --- a/opal/mca/threads/pthreads/configure.m4 +++ b/opal/mca/threads/pthreads/configure.m4 @@ -54,8 +54,6 @@ AC_DEFUN([MCA_opal_wait_sync_pthreads_POST_CONFIG],[ AC_DEFUN([MCA_opal_threads_pthreads_CONFIG],[ AC_CONFIG_FILES([opal/mca/threads/pthreads/Makefile]) - AC_MSG_CHECKING([HAVE_THREAD_PKG_TYPE = $HAVE_THREAD_PKG_TYPE]) - AS_IF([test "$HAVE_THREAD_PKG_TYPE" = "pthreads"], [$1], [$2]) From d6a90a568ae2e94e5f12090c88729da7ff7f3b4a Mon Sep 17 00:00:00 2001 From: Howard Pritchard Date: Fri, 21 Jun 2019 10:51:13 -0600 Subject: [PATCH 09/17] undo messing inside libevent We can't make changes to external packages that we happen to embed in Open MPI. If changes need to be made to the external package, they should be made in that package itself. Signed-off-by: Howard Pritchard --- opal/mca/event/libevent2022/libevent/poll.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/opal/mca/event/libevent2022/libevent/poll.c b/opal/mca/event/libevent2022/libevent/poll.c index 47beb50e081..04d311bb676 100644 --- a/opal/mca/event/libevent2022/libevent/poll.c +++ b/opal/mca/event/libevent2022/libevent/poll.c @@ -162,9 +162,6 @@ poll_dispatch(struct event_base *base, struct timeval *tv) EVBASE_RELEASE_LOCK(base, th_base_lock); - if (msec > 0) { - msec = 0; - } res = poll(event_set, nfds, msec); EVBASE_ACQUIRE_LOCK(base, th_base_lock); From 76851a44da844a9a206badda589a96d109a252b0 Mon Sep 17 00:00:00 2001 From: Howard Pritchard Date: Fri, 21 Jun 2019 13:38:15 -0600 Subject: [PATCH 10/17] remove opal/threads include files Signed-off-by: Howard Pritchard --- ompi/attribute/attribute.c | 2 +- ompi/communicator/comm.c | 2 +- ompi/communicator/communicator.h | 2 +- ompi/file/file.h | 2 +- ompi/info/info.h | 2 +- ompi/mca/common/monitoring/monitoring_prof.c | 2 +- ompi/mca/common/ompio/common_ompio.h | 2 +- ompi/mca/io/ompio/io_ompio.h | 2 +- ompi/mca/io/ompio/io_ompio_component.c | 2 +- ompi/mca/io/ompio/io_ompio_module.c | 2 +- ompi/mca/io/romio321/src/io_romio321.h | 2 +- .../io/romio321/src/io_romio321_component.c | 2 +- ompi/mca/osc/pt2pt/osc_pt2pt.h | 2 +- ompi/mca/osc/pt2pt/osc_pt2pt_active_target.c | 2 +- ompi/mca/osc/pt2pt/osc_pt2pt_passive_target.c | 2 +- ompi/mca/osc/pt2pt/osc_pt2pt_sync.h | 2 +- ompi/mca/osc/rdma/osc_rdma.h | 2 +- ompi/mca/osc/rdma/osc_rdma_active_target.c | 2 +- ompi/mca/osc/rdma/osc_rdma_component.c | 2 +- ompi/mca/osc/rdma/osc_rdma_sync.h | 2 +- ompi/mca/pml/base/pml_base_bsend.c | 4 +-- ompi/mca/pml/ob1/pml_ob1_comm.h | 2 +- ompi/mca/pml/ob1/pml_ob1_recvfrag.c | 2 +- ompi/mca/rte/orte/rte_orte.h | 2 +- ompi/mca/rte/orte/rte_orte_component.c | 2 +- ompi/mca/rte/orte/rte_orte_module.c | 2 +- ompi/mca/rte/pmix/rte_pmix.h | 2 +- ompi/mca/rte/pmix/rte_pmix_component.c | 2 +- ompi/mca/rte/pmix/rte_pmix_module.c | 4 +-- ompi/mpi/c/comm_get_name.c | 2 +- ompi/mpi/c/is_thread_main.c | 2 +- ompi/proc/proc.c | 2 +- ompi/request/request.h | 4 +-- ompi/runtime/mpiruntime.h | 2 +- ompi/runtime/ompi_mpi_init.c | 2 +- opal/class/opal_fifo.h | 2 +- opal/class/opal_free_list.h | 2 +- opal/class/opal_lifo.h | 2 +- opal/class/opal_list.h | 2 +- opal/class/opal_object.h | 2 +- opal/class/opal_pointer_array.h | 2 +- opal/class/opal_ring_buffer.h | 2 +- opal/class/opal_tree.h | 2 +- opal/mca/allocator/basic/allocator_basic.h | 2 +- .../allocator/bucket/allocator_bucket_alloc.h | 2 +- opal/mca/btl/ofi/btl_ofi_rdma.h | 2 +- opal/mca/btl/tcp/btl_tcp_component.c | 2 +- opal/mca/btl/uct/btl_uct.h | 2 +- opal/mca/btl/usnic/btl_usnic_cagent.c | 2 +- opal/mca/btl/usnic/btl_usnic_cclient.c | 2 +- opal/mca/btl/vader/btl_vader_component.c | 2 +- opal/mca/common/ucx/common_ucx_wpool.h | 2 +- opal/mca/event/libevent2022/libevent2022.h | 4 +-- .../event/libevent2022/libevent2022_module.c | 4 +-- opal/mca/hwloc/base/hwloc_base_frame.c | 2 +- opal/mca/hwloc/base/hwloc_base_util.c | 2 +- opal/mca/mpool/base/mpool_base_alloc.c | 2 +- opal/mca/patcher/linux/patcher_linux.h | 2 +- opal/mca/pmix/base/base.h | 2 +- opal/mca/pmix/base/pmix_base_frame.c | 2 +- opal/mca/pmix/ext2x/ext2x.c | 2 +- opal/mca/pmix/ext2x/ext2x_client.c | 2 +- opal/mca/pmix/ext2x/ext2x_server_north.c | 2 +- opal/mca/pmix/ext2x/ext2x_server_south.c | 2 +- opal/mca/pmix/ext3x/ext3x.c | 2 +- opal/mca/pmix/ext3x/ext3x_client.c | 2 +- opal/mca/pmix/ext3x/ext3x_server_north.c | 2 +- opal/mca/pmix/ext3x/ext3x_server_south.c | 2 +- opal/mca/pmix/pmix4x/pmix4x.c | 2 +- opal/mca/pmix/pmix4x/pmix4x_client.c | 2 +- opal/mca/pmix/pmix4x/pmix4x_local.c | 2 +- opal/mca/pmix/pmix4x/pmix4x_server_north.c | 2 +- opal/mca/pmix/pmix4x/pmix4x_server_south.c | 2 +- opal/mca/rcache/rcache.h | 2 +- opal/mca/threads/condition.h | 2 +- opal/mca/threads/qthreads/threads_qthreads.h | 8 +++-- opal/mca/threads/wait_sync.h | 2 +- opal/runtime/opal_cr.c | 4 +-- opal/runtime/opal_finalize.c | 2 +- opal/runtime/opal_init.c | 4 +-- opal/runtime/opal_params.c | 4 +-- opal/runtime/opal_progress.h | 2 +- opal/runtime/opal_progress_threads.c | 2 +- opal/threads/condition.h | 28 ----------------- opal/threads/mutex.h | 31 ------------------- opal/threads/thread_usage.h | 29 ----------------- opal/threads/threads.h | 29 ----------------- opal/threads/tsd.h | 20 ------------ opal/threads/wait_sync.h | 23 -------------- opal/util/cmd_line.c | 2 +- opal/util/cmd_line.h | 2 +- opal/util/info.h | 2 +- opal/util/info_subscriber.h | 2 +- opal/util/keyval_parse.c | 2 +- opal/util/net.c | 2 +- opal/util/output.c | 2 +- orte/mca/plm/base/plm_base_receive.c | 2 +- orte/mca/plm/rsh/plm_rsh.h | 2 +- orte/mca/rmaps/base/rmaps_base_binding.c | 2 +- orte/mca/rmaps/base/rmaps_base_print_fns.c | 2 +- orte/mca/rmaps/base/rmaps_base_ranking.c | 2 +- orte/mca/rmaps/base/rmaps_base_support_fns.c | 2 +- orte/mca/sstore/central/sstore_central_app.c | 4 +-- .../sstore/central/sstore_central_global.c | 4 +-- .../mca/sstore/central/sstore_central_local.c | 4 +-- .../sstore/central/sstore_central_module.c | 4 +-- orte/mca/sstore/stage/sstore_stage_app.c | 4 +-- orte/mca/sstore/stage/sstore_stage_global.c | 4 +-- orte/mca/sstore/stage/sstore_stage_local.c | 4 +-- orte/mca/sstore/stage/sstore_stage_module.c | 4 +-- orte/runtime/orte_globals.c | 2 +- orte/runtime/orte_globals.h | 2 +- orte/runtime/orte_init.c | 2 +- orte/runtime/orte_wait.c | 4 +-- orte/test/system/event-threads.c | 2 +- orte/test/system/evthread-test.c | 2 +- orte/util/comm/comm.c | 2 +- orte/util/name_fns.c | 2 +- orte/util/threads.h | 2 +- oshmem/mca/memheap/buddy/memheap_buddy.h | 2 +- .../mca/memheap/ptmalloc/memheap_ptmalloc.h | 2 +- oshmem/proc/proc.c | 2 +- oshmem/request/request.h | 2 +- oshmem/runtime/oshmem_shmem_init.c | 2 +- test/threads/opal_condition.c | 4 +-- test/threads/opal_thread.c | 2 +- 126 files changed, 142 insertions(+), 300 deletions(-) delete mode 100644 opal/threads/condition.h delete mode 100644 opal/threads/mutex.h delete mode 100644 opal/threads/thread_usage.h delete mode 100644 opal/threads/threads.h delete mode 100644 opal/threads/tsd.h delete mode 100644 opal/threads/wait_sync.h diff --git a/ompi/attribute/attribute.c b/ompi/attribute/attribute.c index b3f5eda4568..c731069728d 100644 --- a/ompi/attribute/attribute.c +++ b/ompi/attribute/attribute.c @@ -232,7 +232,7 @@ #include "ompi_config.h" #include "opal/class/opal_bitmap.h" -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" #include "opal/sys/atomic.h" #include "ompi/attribute/attribute.h" diff --git a/ompi/communicator/comm.c b/ompi/communicator/comm.c index 50b19ee98d5..de46901cbba 100644 --- a/ompi/communicator/comm.c +++ b/ompi/communicator/comm.c @@ -41,7 +41,7 @@ #include "opal/util/string_copy.h" #include "ompi/proc/proc.h" -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" #include "opal/util/bit_ops.h" #include "opal/util/output.h" #include "ompi/mca/topo/topo.h" diff --git a/ompi/communicator/communicator.h b/ompi/communicator/communicator.h index 6adedd7a4a0..87a148dfd72 100644 --- a/ompi/communicator/communicator.h +++ b/ompi/communicator/communicator.h @@ -36,7 +36,7 @@ #include "opal/class/opal_hash_table.h" #include "opal/util/info_subscriber.h" #include "ompi/errhandler/errhandler.h" -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" #include "ompi/communicator/comm_request.h" #include "mpi.h" diff --git a/ompi/file/file.h b/ompi/file/file.h index 8e3fbb85a3d..bb50903ae5d 100644 --- a/ompi/file/file.h +++ b/ompi/file/file.h @@ -30,7 +30,7 @@ #include "mpi.h" #include "opal/class/opal_list.h" #include "ompi/errhandler/errhandler.h" -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" #include "opal/util/info_subscriber.h" #include "ompi/mca/io/io.h" diff --git a/ompi/info/info.h b/ompi/info/info.h index 6e9466bc7c0..4128fb91890 100644 --- a/ompi/info/info.h +++ b/ompi/info/info.h @@ -32,7 +32,7 @@ #include "opal/util/info.h" #include "opal/class/opal_list.h" #include "opal/class/opal_pointer_array.h" -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" #include "opal/mca/base/mca_base_var_enum.h" diff --git a/ompi/mca/common/monitoring/monitoring_prof.c b/ompi/mca/common/monitoring/monitoring_prof.c index a4ea139c679..1dcc0ca916c 100644 --- a/ompi/mca/common/monitoring/monitoring_prof.c +++ b/ompi/mca/common/monitoring/monitoring_prof.c @@ -58,7 +58,7 @@ writing 4x4 matrix to monitoring_avg.mat #define OMPI_COMPILING_FORTRAN_WRAPPERS 1 #endif -#include "opal/threads/thread_usage.h" +#include "opal/mca/threads/thread_usage.h" #include "ompi/include/mpi.h" #include "ompi/mpi/fortran/base/constants.h" diff --git a/ompi/mca/common/ompio/common_ompio.h b/ompi/mca/common/ompio/common_ompio.h index 68e11b51545..3d92bdd6861 100644 --- a/ompi/mca/common/ompio/common_ompio.h +++ b/ompi/mca/common/ompio/common_ompio.h @@ -29,7 +29,7 @@ #include "mpi.h" #include "opal/class/opal_list.h" #include "ompi/errhandler/errhandler.h" -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" #include "ompi/file/file.h" #include "ompi/mca/io/io.h" #include "ompi/mca/fs/fs.h" diff --git a/ompi/mca/io/ompio/io_ompio.h b/ompi/mca/io/ompio/io_ompio.h index 218c8a4ada5..4c019240892 100644 --- a/ompi/mca/io/ompio/io_ompio.h +++ b/ompi/mca/io/ompio/io_ompio.h @@ -29,7 +29,7 @@ #include "mpi.h" #include "opal/class/opal_list.h" #include "ompi/errhandler/errhandler.h" -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" #include "ompi/file/file.h" #include "ompi/mca/io/io.h" #include "ompi/mca/fs/fs.h" diff --git a/ompi/mca/io/ompio/io_ompio_component.c b/ompi/mca/io/ompio/io_ompio_component.c index d2ac847973b..ac0844f9c5e 100644 --- a/ompi/mca/io/ompio/io_ompio_component.c +++ b/ompi/mca/io/ompio/io_ompio_component.c @@ -28,7 +28,7 @@ #include "mpi.h" #include "opal/class/opal_list.h" -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" #include "opal/mca/base/base.h" #include "ompi/mca/io/io.h" #include "ompi/mca/fs/base/base.h" diff --git a/ompi/mca/io/ompio/io_ompio_module.c b/ompi/mca/io/ompio/io_ompio_module.c index 109b99c82ef..0dea57f2a08 100644 --- a/ompi/mca/io/ompio/io_ompio_module.c +++ b/ompi/mca/io/ompio/io_ompio_module.c @@ -20,7 +20,7 @@ #include "ompi_config.h" #include "mpi.h" -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" #include "ompi/mca/io/io.h" #include "io_ompio.h" diff --git a/ompi/mca/io/romio321/src/io_romio321.h b/ompi/mca/io/romio321/src/io_romio321.h index b1c14b2d8c3..ee6a6bc97ab 100644 --- a/ompi/mca/io/romio321/src/io_romio321.h +++ b/ompi/mca/io/romio321/src/io_romio321.h @@ -24,7 +24,7 @@ #define MCA_IO_ROMIO321_H #include "ompi_config.h" -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" #include "ompi/request/request.h" #include "ompi/file/file.h" #include "ompi/mca/io/io.h" diff --git a/ompi/mca/io/romio321/src/io_romio321_component.c b/ompi/mca/io/romio321/src/io_romio321_component.c index e3dbbcf3919..2f1b50a822f 100644 --- a/ompi/mca/io/romio321/src/io_romio321_component.c +++ b/ompi/mca/io/romio321/src/io_romio321_component.c @@ -27,7 +27,7 @@ #include "mpi.h" #include "opal/class/opal_list.h" -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" #include "opal/mca/base/base.h" #include "ompi/mca/io/io.h" #include "io_romio321.h" diff --git a/ompi/mca/osc/pt2pt/osc_pt2pt.h b/ompi/mca/osc/pt2pt/osc_pt2pt.h index 85bad738462..1d1412831bd 100644 --- a/ompi/mca/osc/pt2pt/osc_pt2pt.h +++ b/ompi/mca/osc/pt2pt/osc_pt2pt.h @@ -30,7 +30,7 @@ #include "opal/class/opal_list.h" #include "opal/class/opal_free_list.h" #include "opal/class/opal_hash_table.h" -#include "opal/threads/threads.h" +#include "opal/mca/threads/threads.h" #include "opal/util/output.h" #include "ompi/win/win.h" diff --git a/ompi/mca/osc/pt2pt/osc_pt2pt_active_target.c b/ompi/mca/osc/pt2pt/osc_pt2pt_active_target.c index 59831842bc9..ab04c697ed5 100644 --- a/ompi/mca/osc/pt2pt/osc_pt2pt_active_target.c +++ b/ompi/mca/osc/pt2pt/osc_pt2pt_active_target.c @@ -33,7 +33,7 @@ #include "mpi.h" #include "opal/runtime/opal_progress.h" -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" #include "ompi/communicator/communicator.h" #include "ompi/mca/osc/base/base.h" diff --git a/ompi/mca/osc/pt2pt/osc_pt2pt_passive_target.c b/ompi/mca/osc/pt2pt/osc_pt2pt_passive_target.c index 59b585337c0..0cafe109c3a 100644 --- a/ompi/mca/osc/pt2pt/osc_pt2pt_passive_target.c +++ b/ompi/mca/osc/pt2pt/osc_pt2pt_passive_target.c @@ -31,7 +31,7 @@ #include "mpi.h" #include "opal/runtime/opal_progress.h" -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" #include "ompi/communicator/communicator.h" #include "ompi/mca/osc/base/base.h" #include "opal/include/opal_stdint.h" diff --git a/ompi/mca/osc/pt2pt/osc_pt2pt_sync.h b/ompi/mca/osc/pt2pt/osc_pt2pt_sync.h index cf5da61bf88..98d8a084d04 100644 --- a/ompi/mca/osc/pt2pt/osc_pt2pt_sync.h +++ b/ompi/mca/osc/pt2pt/osc_pt2pt_sync.h @@ -14,7 +14,7 @@ #include "ompi_config.h" #include "opal/class/opal_free_list.h" -#include "opal/threads/threads.h" +#include "opal/mca/threads/threads.h" enum ompi_osc_pt2pt_sync_type_t { /** default value */ diff --git a/ompi/mca/osc/rdma/osc_rdma.h b/ompi/mca/osc/rdma/osc_rdma.h index 095c9ff5a2c..4ea7667ed50 100644 --- a/ompi/mca/osc/rdma/osc_rdma.h +++ b/ompi/mca/osc/rdma/osc_rdma.h @@ -26,7 +26,7 @@ #include "ompi_config.h" #include "opal/class/opal_free_list.h" #include "opal/class/opal_hash_table.h" -#include "opal/threads/threads.h" +#include "opal/mca/threads/threads.h" #include "opal/util/output.h" #include "opal/mca/shmem/shmem.h" diff --git a/ompi/mca/osc/rdma/osc_rdma_active_target.c b/ompi/mca/osc/rdma/osc_rdma_active_target.c index 80c31fc00b3..f6cf6bb2820 100644 --- a/ompi/mca/osc/rdma/osc_rdma_active_target.c +++ b/ompi/mca/osc/rdma/osc_rdma_active_target.c @@ -31,7 +31,7 @@ #include "osc_rdma_active_target.h" #include "mpi.h" -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" #include "ompi/communicator/communicator.h" #include "ompi/mca/osc/base/base.h" diff --git a/ompi/mca/osc/rdma/osc_rdma_component.c b/ompi/mca/osc/rdma/osc_rdma_component.c index 830e12f99f5..1d96e7d6127 100644 --- a/ompi/mca/osc/rdma/osc_rdma_component.c +++ b/ompi/mca/osc/rdma/osc_rdma_component.c @@ -41,7 +41,7 @@ #include "osc_rdma_dynamic.h" #include "osc_rdma_accumulate.h" -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" #include "opal/util/arch.h" #include "opal/util/argv.h" #include "opal/util/printf.h" diff --git a/ompi/mca/osc/rdma/osc_rdma_sync.h b/ompi/mca/osc/rdma/osc_rdma_sync.h index ce0daa5db94..31bf5bc3295 100644 --- a/ompi/mca/osc/rdma/osc_rdma_sync.h +++ b/ompi/mca/osc/rdma/osc_rdma_sync.h @@ -14,7 +14,7 @@ #include "osc_rdma_types.h" #include "opal/class/opal_object.h" -#include "opal/threads/threads.h" +#include "opal/mca/threads/threads.h" /** * @brief synchronization types diff --git a/ompi/mca/pml/base/pml_base_bsend.c b/ompi/mca/pml/base/pml_base_bsend.c index 4da15522b8b..3826253e2ae 100644 --- a/ompi/mca/pml/base/pml_base_bsend.c +++ b/ompi/mca/pml/base/pml_base_bsend.c @@ -24,8 +24,8 @@ */ #include "ompi_config.h" -#include "opal/threads/mutex.h" -#include "opal/threads/condition.h" +#include "opal/mca/threads/mutex.h" +#include "opal/mca/threads/condition.h" #include "ompi/datatype/ompi_datatype.h" #include "opal/mca/allocator/base/base.h" #include "opal/mca/allocator/allocator.h" diff --git a/ompi/mca/pml/ob1/pml_ob1_comm.h b/ompi/mca/pml/ob1/pml_ob1_comm.h index 780c9a44fc7..8e48a48e969 100644 --- a/ompi/mca/pml/ob1/pml_ob1_comm.h +++ b/ompi/mca/pml/ob1/pml_ob1_comm.h @@ -26,7 +26,7 @@ #ifndef MCA_PML_OB1_COMM_H #define MCA_PML_OB1_COMM_H -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" #include "opal/class/opal_list.h" #include "ompi/proc/proc.h" #include "ompi/communicator/communicator.h" diff --git a/ompi/mca/pml/ob1/pml_ob1_recvfrag.c b/ompi/mca/pml/ob1/pml_ob1_recvfrag.c index b61649ad2a5..7652cf317fd 100644 --- a/ompi/mca/pml/ob1/pml_ob1_recvfrag.c +++ b/ompi/mca/pml/ob1/pml_ob1_recvfrag.c @@ -33,7 +33,7 @@ #include "ompi_config.h" #include "opal/class/opal_list.h" -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" #include "opal/prefetch.h" #include "ompi/constants.h" diff --git a/ompi/mca/rte/orte/rte_orte.h b/ompi/mca/rte/orte/rte_orte.h index 665cdd9e7bc..c191fe6cabd 100644 --- a/ompi/mca/rte/orte/rte_orte.h +++ b/ompi/mca/rte/orte/rte_orte.h @@ -26,7 +26,7 @@ struct opal_proc_t; -#include "opal/threads/threads.h" +#include "opal/mca/threads/threads.h" #include "orte/types.h" #include "orte/mca/errmgr/errmgr.h" diff --git a/ompi/mca/rte/orte/rte_orte_component.c b/ompi/mca/rte/orte/rte_orte_component.c index 50e49935bd7..48460b55035 100644 --- a/ompi/mca/rte/orte/rte_orte_component.c +++ b/ompi/mca/rte/orte/rte_orte_component.c @@ -21,7 +21,7 @@ #include "ompi_config.h" #include "ompi/constants.h" -#include "opal/threads/threads.h" +#include "opal/mca/threads/threads.h" #include "opal/class/opal_list.h" #include "orte/mca/rml/rml.h" diff --git a/ompi/mca/rte/orte/rte_orte_module.c b/ompi/mca/rte/orte/rte_orte_module.c index 046b6d2532e..c25b6d05f71 100644 --- a/ompi/mca/rte/orte/rte_orte_module.c +++ b/ompi/mca/rte/orte/rte_orte_module.c @@ -22,7 +22,7 @@ #include "opal/util/opal_getcwd.h" #include "opal/util/printf.h" #include "opal/mca/pmix/pmix.h" -#include "opal/threads/threads.h" +#include "opal/mca/threads/threads.h" #include "opal/class/opal_list.h" #include "opal/dss/dss.h" diff --git a/ompi/mca/rte/pmix/rte_pmix.h b/ompi/mca/rte/pmix/rte_pmix.h index fd39621d5f3..ceda68d6dcb 100644 --- a/ompi/mca/rte/pmix/rte_pmix.h +++ b/ompi/mca/rte/pmix/rte_pmix.h @@ -35,7 +35,7 @@ struct opal_proc_t; -#include "opal/threads/threads.h" +#include "opal/mca/threads/threads.h" #include "opal/util/proc.h" #include "opal/mca/hwloc/hwloc-internal.h" #include "opal/mca/pmix/pmix.h" diff --git a/ompi/mca/rte/pmix/rte_pmix_component.c b/ompi/mca/rte/pmix/rte_pmix_component.c index a54c0b0ab0a..f19ee183106 100644 --- a/ompi/mca/rte/pmix/rte_pmix_component.c +++ b/ompi/mca/rte/pmix/rte_pmix_component.c @@ -21,7 +21,7 @@ #include "ompi_config.h" #include "ompi/constants.h" -#include "opal/threads/threads.h" +#include "opal/mca/threads/threads.h" #include "opal/class/opal_list.h" #include "ompi/mca/rte/rte.h" diff --git a/ompi/mca/rte/pmix/rte_pmix_module.c b/ompi/mca/rte/pmix/rte_pmix_module.c index e876e9895fa..a734971c2a6 100644 --- a/ompi/mca/rte/pmix/rte_pmix_module.c +++ b/ompi/mca/rte/pmix/rte_pmix_module.c @@ -46,8 +46,8 @@ #include "opal/util/string_copy.h" #include "opal/mca/hwloc/base/base.h" #include "opal/mca/pmix/base/base.h" -#include "opal/threads/threads.h" -#include "opal/threads/tsd.h" +#include "opal/mca/threads/threads.h" +#include "opal/mca/threads/tsd.h" #include "opal/class/opal_list.h" #include "opal/dss/dss.h" diff --git a/ompi/mpi/c/comm_get_name.c b/ompi/mpi/c/comm_get_name.c index c4904f13bf5..f7a0ce43d8a 100644 --- a/ompi/mpi/c/comm_get_name.c +++ b/ompi/mpi/c/comm_get_name.c @@ -23,7 +23,7 @@ #include -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" #include "opal/util/string_copy.h" #include "ompi/mpi/c/bindings.h" diff --git a/ompi/mpi/c/is_thread_main.c b/ompi/mpi/c/is_thread_main.c index 1be65a19194..3dead8d09d8 100644 --- a/ompi/mpi/c/is_thread_main.c +++ b/ompi/mpi/c/is_thread_main.c @@ -25,7 +25,7 @@ #include "ompi/communicator/communicator.h" #include "ompi/errhandler/errhandler.h" #include "ompi/runtime/mpiruntime.h" -#include "opal/threads/threads.h" +#include "opal/mca/threads/threads.h" #if OMPI_BUILD_MPI_PROFILING #if OPAL_HAVE_WEAK_SYMBOLS diff --git a/ompi/proc/proc.c b/ompi/proc/proc.c index 5b712bf25e1..8666201be7c 100644 --- a/ompi/proc/proc.c +++ b/ompi/proc/proc.c @@ -32,7 +32,7 @@ #include "ompi/constants.h" #include "opal/datatype/opal_convertor.h" -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" #include "opal/dss/dss.h" #include "opal/util/arch.h" #include "opal/util/show_help.h" diff --git a/ompi/request/request.h b/ompi/request/request.h index 6460fbe4faf..4b0c28c4e6e 100644 --- a/ompi/request/request.h +++ b/ompi/request/request.h @@ -35,8 +35,8 @@ #include "mpi.h" #include "opal/class/opal_free_list.h" #include "opal/class/opal_pointer_array.h" -#include "opal/threads/condition.h" -#include "opal/threads/wait_sync.h" +#include "opal/mca/threads/condition.h" +#include "opal/mca/threads/wait_sync.h" #include "ompi/constants.h" BEGIN_C_DECLS diff --git a/ompi/runtime/mpiruntime.h b/ompi/runtime/mpiruntime.h index f311de538f5..81c9741c2e2 100644 --- a/ompi/runtime/mpiruntime.h +++ b/ompi/runtime/mpiruntime.h @@ -36,7 +36,7 @@ #include "opal/class/opal_list.h" #include "opal/class/opal_hash_table.h" -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" BEGIN_C_DECLS diff --git a/ompi/runtime/ompi_mpi_init.c b/ompi/runtime/ompi_mpi_init.c index ec980487240..bf9c0eae93f 100644 --- a/ompi/runtime/ompi_mpi_init.c +++ b/ompi/runtime/ompi_mpi_init.c @@ -46,7 +46,7 @@ #include "opal/mca/base/base.h" #include "opal/mca/hwloc/base/base.h" #include "opal/runtime/opal_progress.h" -#include "opal/threads/threads.h" +#include "opal/mca/threads/threads.h" #include "opal/util/arch.h" #include "opal/util/argv.h" #include "opal/util/output.h" diff --git a/opal/class/opal_fifo.h b/opal/class/opal_fifo.h index ebb3a0e7d8e..89b90329383 100644 --- a/opal/class/opal_fifo.h +++ b/opal/class/opal_fifo.h @@ -28,7 +28,7 @@ #include "opal/class/opal_lifo.h" #include "opal/sys/atomic.h" -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" BEGIN_C_DECLS diff --git a/opal/class/opal_free_list.h b/opal/class/opal_free_list.h index b7fd1920219..ddc383fb912 100644 --- a/opal/class/opal_free_list.h +++ b/opal/class/opal_free_list.h @@ -27,7 +27,7 @@ #include "opal_config.h" #include "opal/class/opal_lifo.h" #include "opal/prefetch.h" -#include "opal/threads/condition.h" +#include "opal/mca/threads/condition.h" #include "opal/constants.h" #include "opal/runtime/opal.h" diff --git a/opal/class/opal_lifo.h b/opal/class/opal_lifo.h index 4d07ef6ccda..99b90be10a2 100644 --- a/opal/class/opal_lifo.h +++ b/opal/class/opal_lifo.h @@ -31,7 +31,7 @@ #include "opal/class/opal_list.h" #include "opal/sys/atomic.h" -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" BEGIN_C_DECLS diff --git a/opal/class/opal_list.h b/opal/class/opal_list.h index f9f1f00ab26..4ec07fc6e7f 100644 --- a/opal/class/opal_list.h +++ b/opal/class/opal_list.h @@ -75,7 +75,7 @@ #if OPAL_ENABLE_DEBUG /* Need atomics for debugging (reference counting) */ #include "opal/sys/atomic.h" -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" #endif BEGIN_C_DECLS diff --git a/opal/class/opal_object.h b/opal/class/opal_object.h index 4d3380f0da0..0f693fa1a9b 100644 --- a/opal/class/opal_object.h +++ b/opal/class/opal_object.h @@ -123,7 +123,7 @@ #include #include -#include "opal/threads/thread_usage.h" +#include "opal/mca/threads/thread_usage.h" BEGIN_C_DECLS diff --git a/opal/class/opal_pointer_array.h b/opal/class/opal_pointer_array.h index 5900243b043..ec6a883f5e4 100644 --- a/opal/class/opal_pointer_array.h +++ b/opal/class/opal_pointer_array.h @@ -31,7 +31,7 @@ #include "opal_config.h" -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" #include "opal/class/opal_object.h" #include "opal/prefetch.h" diff --git a/opal/class/opal_ring_buffer.h b/opal/class/opal_ring_buffer.h index 7a841b3bbcb..ed607709dfd 100644 --- a/opal/class/opal_ring_buffer.h +++ b/opal/class/opal_ring_buffer.h @@ -26,7 +26,7 @@ #include "opal_config.h" -#include "opal/threads/threads.h" +#include "opal/mca/threads/threads.h" #include "opal/class/opal_object.h" #include "opal/util/output.h" diff --git a/opal/class/opal_tree.h b/opal/class/opal_tree.h index e73d0a48d9c..c80c52d18af 100644 --- a/opal/class/opal_tree.h +++ b/opal/class/opal_tree.h @@ -67,7 +67,7 @@ #if OPAL_ENABLE_DEBUG /* Need atomics for debugging (reference counting) */ #include "opal/sys/atomic.h" -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" #endif BEGIN_C_DECLS diff --git a/opal/mca/allocator/basic/allocator_basic.h b/opal/mca/allocator/basic/allocator_basic.h index aa257457dbc..4766a994c8d 100644 --- a/opal/mca/allocator/basic/allocator_basic.h +++ b/opal/mca/allocator/basic/allocator_basic.h @@ -29,7 +29,7 @@ #include "opal_config.h" #include #include -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" #include "opal/class/opal_free_list.h" #include "opal/mca/allocator/allocator.h" diff --git a/opal/mca/allocator/bucket/allocator_bucket_alloc.h b/opal/mca/allocator/bucket/allocator_bucket_alloc.h index fe0b66e881e..103b611d7b4 100644 --- a/opal/mca/allocator/bucket/allocator_bucket_alloc.h +++ b/opal/mca/allocator/bucket/allocator_bucket_alloc.h @@ -29,7 +29,7 @@ #include "opal_config.h" #include #include -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" #include "opal/mca/allocator/allocator.h" BEGIN_C_DECLS diff --git a/opal/mca/btl/ofi/btl_ofi_rdma.h b/opal/mca/btl/ofi/btl_ofi_rdma.h index a9ad34c147d..b4e1965081e 100644 --- a/opal/mca/btl/ofi/btl_ofi_rdma.h +++ b/opal/mca/btl/ofi/btl_ofi_rdma.h @@ -14,7 +14,7 @@ #ifndef BTL_OFI_RDMA_H #define BTL_OFI_RDMA_H -#include "opal/threads/thread_usage.h" +#include "opal/mca/threads/thread_usage.h" #include "btl_ofi.h" #include "btl_ofi_endpoint.h" diff --git a/opal/mca/btl/tcp/btl_tcp_component.c b/opal/mca/btl/tcp/btl_tcp_component.c index d86d9a57a7a..297ecba6c73 100644 --- a/opal/mca/btl/tcp/btl_tcp_component.c +++ b/opal/mca/btl/tcp/btl_tcp_component.c @@ -76,7 +76,7 @@ #include "opal/mca/mpool/base/base.h" #include "opal/mca/btl/base/btl_base_error.h" #include "opal/mca/pmix/pmix.h" -#include "opal/threads/threads.h" +#include "opal/mca/threads/threads.h" #include "opal/constants.h" #include "opal/mca/btl/btl.h" diff --git a/opal/mca/btl/uct/btl_uct.h b/opal/mca/btl/uct/btl_uct.h index 38756794430..0adbf9474e8 100644 --- a/opal/mca/btl/uct/btl_uct.h +++ b/opal/mca/btl/uct/btl_uct.h @@ -37,7 +37,7 @@ #include "opal/class/opal_fifo.h" #include "opal/class/opal_hash_table.h" #include "opal/mca/pmix/pmix.h" -#include "opal/threads/tsd.h" +#include "opal/mca/threads/tsd.h" #include #include "btl_uct_types.h" diff --git a/opal/mca/btl/usnic/btl_usnic_cagent.c b/opal/mca/btl/usnic/btl_usnic_cagent.c index b265d37f352..ff17600a96c 100644 --- a/opal/mca/btl/usnic/btl_usnic_cagent.c +++ b/opal/mca/btl/usnic/btl_usnic_cagent.c @@ -22,7 +22,7 @@ #endif #include "opal_stdint.h" -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" #include "opal/mca/event/event.h" #include "opal/util/show_help.h" #include "opal/types.h" diff --git a/opal/mca/btl/usnic/btl_usnic_cclient.c b/opal/mca/btl/usnic/btl_usnic_cclient.c index d1498d92249..cca6157dea1 100644 --- a/opal/mca/btl/usnic/btl_usnic_cclient.c +++ b/opal/mca/btl/usnic/btl_usnic_cclient.c @@ -25,7 +25,7 @@ #include #include "opal_stdint.h" -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" #include "opal/mca/event/event.h" #include "opal/util/output.h" #include "opal/util/fd.h" diff --git a/opal/mca/btl/vader/btl_vader_component.c b/opal/mca/btl/vader/btl_vader_component.c index 2a773ceed25..4eb85b4d78b 100644 --- a/opal/mca/btl/vader/btl_vader_component.c +++ b/opal/mca/btl/vader/btl_vader_component.c @@ -32,7 +32,7 @@ #include "opal/util/output.h" #include "opal/util/show_help.h" #include "opal/util/printf.h" -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" #include "opal/mca/btl/base/btl_base_error.h" #include "btl_vader.h" diff --git a/opal/mca/common/ucx/common_ucx_wpool.h b/opal/mca/common/ucx/common_ucx_wpool.h index 59c40c9d437..af1c47398cb 100644 --- a/opal/mca/common/ucx/common_ucx_wpool.h +++ b/opal/mca/common/ucx/common_ucx_wpool.h @@ -15,7 +15,7 @@ #include "opal/runtime/opal_progress.h" #include "opal/include/opal/constants.h" #include "opal/class/opal_list.h" -#include "opal/threads/tsd.h" +#include "opal/mca/threads/tsd.h" BEGIN_C_DECLS diff --git a/opal/mca/event/libevent2022/libevent2022.h b/opal/mca/event/libevent2022/libevent2022.h index 73961785475..3b8834d0fb2 100644 --- a/opal/mca/event/libevent2022/libevent2022.h +++ b/opal/mca/event/libevent2022/libevent2022.h @@ -48,8 +48,8 @@ #include #include "opal/class/opal_object.h" -#include "opal/threads/mutex.h" -#include "opal/threads/threads.h" +#include "opal/mca/threads/mutex.h" +#include "opal/mca/threads/threads.h" #include "opal/util/output.h" #include "opal/constants.h" #include "opal/util/argv.h" diff --git a/opal/mca/event/libevent2022/libevent2022_module.c b/opal/mca/event/libevent2022/libevent2022_module.c index b36f4d4f985..68bf898c161 100644 --- a/opal/mca/event/libevent2022/libevent2022_module.c +++ b/opal/mca/event/libevent2022/libevent2022_module.c @@ -53,8 +53,8 @@ #include #include "opal/class/opal_object.h" -#include "opal/threads/mutex.h" -#include "opal/threads/threads.h" +#include "opal/mca/threads/mutex.h" +#include "opal/mca/threads/threads.h" #include "opal/util/output.h" #include "opal/util/argv.h" #include "opal/util/fd.h" diff --git a/opal/mca/hwloc/base/hwloc_base_frame.c b/opal/mca/hwloc/base/hwloc_base_frame.c index da48d4833ec..6ab3895be5b 100644 --- a/opal/mca/hwloc/base/hwloc_base_frame.c +++ b/opal/mca/hwloc/base/hwloc_base_frame.c @@ -20,7 +20,7 @@ #include "opal/util/show_help.h" #include "opal/mca/mca.h" #include "opal/mca/base/base.h" -#include "opal/threads/tsd.h" +#include "opal/mca/threads/tsd.h" #include "opal/mca/hwloc/hwloc-internal.h" #include "opal/mca/hwloc/base/base.h" diff --git a/opal/mca/hwloc/base/hwloc_base_util.c b/opal/mca/hwloc/base/hwloc_base_util.c index 5817090320a..6a45eeab764 100644 --- a/opal/mca/hwloc/base/hwloc_base_util.c +++ b/opal/mca/hwloc/base/hwloc_base_util.c @@ -54,7 +54,7 @@ #include "opal/util/os_dirpath.h" #include "opal/util/show_help.h" #include "opal/util/printf.h" -#include "opal/threads/tsd.h" +#include "opal/mca/threads/tsd.h" #include "opal/mca/pmix/pmix.h" #include "opal/mca/hwloc/hwloc-internal.h" diff --git a/opal/mca/mpool/base/mpool_base_alloc.c b/opal/mca/mpool/base/mpool_base_alloc.c index 1c4f87a9a91..ea5de261b78 100644 --- a/opal/mca/mpool/base/mpool_base_alloc.c +++ b/opal/mca/mpool/base/mpool_base_alloc.c @@ -29,7 +29,7 @@ #include "opal/mca/mpool/mpool.h" #include "base.h" #include "mpool_base_tree.h" -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" #include "opal/util/info.h" diff --git a/opal/mca/patcher/linux/patcher_linux.h b/opal/mca/patcher/linux/patcher_linux.h index de4e85b35da..1d7b041b74f 100644 --- a/opal/mca/patcher/linux/patcher_linux.h +++ b/opal/mca/patcher/linux/patcher_linux.h @@ -18,7 +18,7 @@ #include "opal/mca/patcher/patcher.h" #include "opal/class/opal_list.h" -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" struct mca_patcher_linux_patch_got_t { opal_list_item_t super; diff --git a/opal/mca/pmix/base/base.h b/opal/mca/pmix/base/base.h index 277e598cf30..54a98c1cd6c 100644 --- a/opal/mca/pmix/base/base.h +++ b/opal/mca/pmix/base/base.h @@ -14,7 +14,7 @@ #include "opal_config.h" #include "opal/types.h" -#include "opal/threads/threads.h" +#include "opal/mca/threads/threads.h" #include "opal/mca/mca.h" #include "opal/mca/base/mca_base_framework.h" diff --git a/opal/mca/pmix/base/pmix_base_frame.c b/opal/mca/pmix/base/pmix_base_frame.c index e06d18c0e36..bf42e7c21ea 100644 --- a/opal/mca/pmix/base/pmix_base_frame.c +++ b/opal/mca/pmix/base/pmix_base_frame.c @@ -13,7 +13,7 @@ #include "opal/constants.h" #include "opal/mca/mca.h" -#include "opal/threads/thread_usage.h" +#include "opal/mca/threads/thread_usage.h" #include "opal/util/argv.h" #include "opal/util/output.h" #include "opal/mca/base/base.h" diff --git a/opal/mca/pmix/ext2x/ext2x.c b/opal/mca/pmix/ext2x/ext2x.c index ce8324978f4..905c1bbdbdd 100644 --- a/opal/mca/pmix/ext2x/ext2x.c +++ b/opal/mca/pmix/ext2x/ext2x.c @@ -31,7 +31,7 @@ #include "opal/mca/hwloc/base/base.h" #include "opal/runtime/opal.h" #include "opal/runtime/opal_progress_threads.h" -#include "opal/threads/threads.h" +#include "opal/mca/threads/threads.h" #include "opal/util/argv.h" #include "opal/util/error.h" #include "opal/util/opal_environ.h" diff --git a/opal/mca/pmix/ext2x/ext2x_client.c b/opal/mca/pmix/ext2x/ext2x_client.c index 8e01e7a1ac7..91a74c4ca34 100644 --- a/opal/mca/pmix/ext2x/ext2x_client.c +++ b/opal/mca/pmix/ext2x/ext2x_client.c @@ -30,7 +30,7 @@ #endif #include "opal/hash_string.h" -#include "opal/threads/threads.h" +#include "opal/mca/threads/threads.h" #include "opal/util/argv.h" #include "opal/util/opal_environ.h" #include "opal/util/proc.h" diff --git a/opal/mca/pmix/ext2x/ext2x_server_north.c b/opal/mca/pmix/ext2x/ext2x_server_north.c index be406eb6bf7..1203b3d3f89 100644 --- a/opal/mca/pmix/ext2x/ext2x_server_north.c +++ b/opal/mca/pmix/ext2x/ext2x_server_north.c @@ -29,7 +29,7 @@ #include "opal/mca/hwloc/base/base.h" #include "opal/runtime/opal.h" #include "opal/runtime/opal_progress_threads.h" -#include "opal/threads/threads.h" +#include "opal/mca/threads/threads.h" #include "opal/util/argv.h" #include "opal/util/error.h" #include "opal/util/output.h" diff --git a/opal/mca/pmix/ext2x/ext2x_server_south.c b/opal/mca/pmix/ext2x/ext2x_server_south.c index 45228394ac7..479f44d805d 100644 --- a/opal/mca/pmix/ext2x/ext2x_server_south.c +++ b/opal/mca/pmix/ext2x/ext2x_server_south.c @@ -35,7 +35,7 @@ #include "opal/mca/hwloc/base/base.h" #include "opal/runtime/opal.h" #include "opal/runtime/opal_progress_threads.h" -#include "opal/threads/threads.h" +#include "opal/mca/threads/threads.h" #include "opal/util/argv.h" #include "opal/util/error.h" #include "opal/util/output.h" diff --git a/opal/mca/pmix/ext3x/ext3x.c b/opal/mca/pmix/ext3x/ext3x.c index d59b393f4a3..abed19fc1ed 100644 --- a/opal/mca/pmix/ext3x/ext3x.c +++ b/opal/mca/pmix/ext3x/ext3x.c @@ -34,7 +34,7 @@ #include "opal/mca/hwloc/base/base.h" #include "opal/runtime/opal.h" #include "opal/runtime/opal_progress_threads.h" -#include "opal/threads/threads.h" +#include "opal/mca/threads/threads.h" #include "opal/util/argv.h" #include "opal/util/error.h" #include "opal/util/opal_environ.h" diff --git a/opal/mca/pmix/ext3x/ext3x_client.c b/opal/mca/pmix/ext3x/ext3x_client.c index 617f20936b7..c95569ba4fd 100644 --- a/opal/mca/pmix/ext3x/ext3x_client.c +++ b/opal/mca/pmix/ext3x/ext3x_client.c @@ -31,7 +31,7 @@ #endif #include "opal/hash_string.h" -#include "opal/threads/threads.h" +#include "opal/mca/threads/threads.h" #include "opal/util/argv.h" #include "opal/util/opal_environ.h" #include "opal/util/proc.h" diff --git a/opal/mca/pmix/ext3x/ext3x_server_north.c b/opal/mca/pmix/ext3x/ext3x_server_north.c index c22e8862a46..ed0041fb1d3 100644 --- a/opal/mca/pmix/ext3x/ext3x_server_north.c +++ b/opal/mca/pmix/ext3x/ext3x_server_north.c @@ -29,7 +29,7 @@ #include "opal/mca/hwloc/base/base.h" #include "opal/runtime/opal.h" #include "opal/runtime/opal_progress_threads.h" -#include "opal/threads/threads.h" +#include "opal/mca/threads/threads.h" #include "opal/util/argv.h" #include "opal/util/error.h" #include "opal/util/output.h" diff --git a/opal/mca/pmix/ext3x/ext3x_server_south.c b/opal/mca/pmix/ext3x/ext3x_server_south.c index 2991aca6c2d..fecd6a8a8c7 100644 --- a/opal/mca/pmix/ext3x/ext3x_server_south.c +++ b/opal/mca/pmix/ext3x/ext3x_server_south.c @@ -36,7 +36,7 @@ #include "opal/mca/hwloc/base/base.h" #include "opal/runtime/opal.h" #include "opal/runtime/opal_progress_threads.h" -#include "opal/threads/threads.h" +#include "opal/mca/threads/threads.h" #include "opal/util/argv.h" #include "opal/util/error.h" #include "opal/util/output.h" diff --git a/opal/mca/pmix/pmix4x/pmix4x.c b/opal/mca/pmix/pmix4x/pmix4x.c index cd38aeeba64..1f82f25e084 100644 --- a/opal/mca/pmix/pmix4x/pmix4x.c +++ b/opal/mca/pmix/pmix4x/pmix4x.c @@ -34,7 +34,7 @@ #include "opal/mca/hwloc/base/base.h" #include "opal/runtime/opal.h" #include "opal/runtime/opal_progress_threads.h" -#include "opal/threads/threads.h" +#include "opal/mca/threads/threads.h" #include "opal/util/argv.h" #include "opal/util/error.h" #include "opal/util/opal_environ.h" diff --git a/opal/mca/pmix/pmix4x/pmix4x_client.c b/opal/mca/pmix/pmix4x/pmix4x_client.c index d7ea3f6bb1c..2273bc34818 100644 --- a/opal/mca/pmix/pmix4x/pmix4x_client.c +++ b/opal/mca/pmix/pmix4x/pmix4x_client.c @@ -31,7 +31,7 @@ #endif #include "opal/hash_string.h" -#include "opal/threads/threads.h" +#include "opal/mca/threads/threads.h" #include "opal/util/argv.h" #include "opal/util/opal_environ.h" #include "opal/util/proc.h" diff --git a/opal/mca/pmix/pmix4x/pmix4x_local.c b/opal/mca/pmix/pmix4x/pmix4x_local.c index 2665d4b1c09..f98b08da02c 100644 --- a/opal/mca/pmix/pmix4x/pmix4x_local.c +++ b/opal/mca/pmix/pmix4x/pmix4x_local.c @@ -31,7 +31,7 @@ #include "opal/mca/hwloc/base/base.h" #include "opal/runtime/opal.h" #include "opal/runtime/opal_progress_threads.h" -#include "opal/threads/threads.h" +#include "opal/mca/threads/threads.h" #include "opal/util/argv.h" #include "opal/util/error.h" #include "opal/util/opal_environ.h" diff --git a/opal/mca/pmix/pmix4x/pmix4x_server_north.c b/opal/mca/pmix/pmix4x/pmix4x_server_north.c index ea941149ef6..d8ff9470921 100644 --- a/opal/mca/pmix/pmix4x/pmix4x_server_north.c +++ b/opal/mca/pmix/pmix4x/pmix4x_server_north.c @@ -29,7 +29,7 @@ #include "opal/mca/hwloc/base/base.h" #include "opal/runtime/opal.h" #include "opal/runtime/opal_progress_threads.h" -#include "opal/threads/threads.h" +#include "opal/mca/threads/threads.h" #include "opal/util/argv.h" #include "opal/util/error.h" #include "opal/util/output.h" diff --git a/opal/mca/pmix/pmix4x/pmix4x_server_south.c b/opal/mca/pmix/pmix4x/pmix4x_server_south.c index 9102af45b00..cceec8252aa 100644 --- a/opal/mca/pmix/pmix4x/pmix4x_server_south.c +++ b/opal/mca/pmix/pmix4x/pmix4x_server_south.c @@ -36,7 +36,7 @@ #include "opal/mca/hwloc/base/base.h" #include "opal/runtime/opal.h" #include "opal/runtime/opal_progress_threads.h" -#include "opal/threads/threads.h" +#include "opal/mca/threads/threads.h" #include "opal/util/argv.h" #include "opal/util/error.h" #include "opal/util/output.h" diff --git a/opal/mca/rcache/rcache.h b/opal/mca/rcache/rcache.h index f95fa1a5972..ed68deca7ac 100644 --- a/opal/mca/rcache/rcache.h +++ b/opal/mca/rcache/rcache.h @@ -27,7 +27,7 @@ #define MCA_RCACHE_H #include "opal/mca/mca.h" #include "opal/mca/mpool/mpool.h" -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" /* forward-declaration of rcache module structure */ diff --git a/opal/mca/threads/condition.h b/opal/mca/threads/condition.h index 0100231b92a..d5533a20d84 100644 --- a/opal/mca/threads/condition.h +++ b/opal/mca/threads/condition.h @@ -34,7 +34,7 @@ #include #include -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" #include "opal/runtime/opal_progress.h" #include "opal/runtime/opal_cr.h" diff --git a/opal/mca/threads/qthreads/threads_qthreads.h b/opal/mca/threads/qthreads/threads_qthreads.h index f1ab4c81c0f..67a5adbcf44 100644 --- a/opal/mca/threads/qthreads/threads_qthreads.h +++ b/opal/mca/threads/qthreads/threads_qthreads.h @@ -9,6 +9,8 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. + * Copyright (c) 2019 Triad National Security, LLC. All rights + * reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -16,8 +18,8 @@ * $HEADER$ */ -#ifndef OPAL_MCA_TIMER_DARWIN_TIMER_DARWIN_H -#define OPAL_MCA_TIMER_DARWIN_TIMER_DARWIN_H +#ifndef OPAL_MCA_THREADS_DARWIN_TIMER_DARWIN_H +#define OPAL_MCA_THREADS_DARWIN_TIMER_DARWIN_H #include "opal_config.h" #include @@ -93,4 +95,4 @@ opal_tsd_getspecific(opal_tsd_key_t key, void **valuep) #define OPAL_TIMER_USEC_NATIVE 1 #define OPAL_TIMER_USEC_SUPPORTED 1 -#endif +#endif /* OPAL_MCA_THREADS_DARWIN_TIMER_DARWIN_H */ diff --git a/opal/mca/threads/wait_sync.h b/opal/mca/threads/wait_sync.h index 96c9fe90b8c..0b5f421c75f 100644 --- a/opal/mca/threads/wait_sync.h +++ b/opal/mca/threads/wait_sync.h @@ -21,7 +21,7 @@ #define OPAL_MCA_THREADS_WAIT_SYNC_H #include "opal/sys/atomic.h" -#include "opal/threads/condition.h" +#include "opal/mca/threads/condition.h" BEGIN_C_DECLS diff --git a/opal/runtime/opal_cr.c b/opal/runtime/opal_cr.c index 11f938edd98..33b94434b8e 100644 --- a/opal/runtime/opal_cr.c +++ b/opal/runtime/opal_cr.c @@ -69,8 +69,8 @@ #include "opal/mca/memory/base/base.h" #include "opal/mca/timer/base/base.h" -#include "opal/threads/mutex.h" -#include "opal/threads/threads.h" +#include "opal/mca/threads/mutex.h" +#include "opal/mca/threads/threads.h" #include "opal/mca/crs/base/base.h" /****************** diff --git a/opal/runtime/opal_finalize.c b/opal/runtime/opal_finalize.c index 7c7e37c310a..33138b453a6 100644 --- a/opal/runtime/opal_finalize.c +++ b/opal/runtime/opal_finalize.c @@ -39,7 +39,7 @@ #include "opal/memoryhooks/memory.h" #include "opal/runtime/opal.h" #include "opal/constants.h" -#include "opal/threads/tsd.h" +#include "opal/mca/threads/tsd.h" #include "opal/runtime/opal_cr.h" #include "opal/runtime/opal_progress.h" diff --git a/opal/runtime/opal_init.c b/opal/runtime/opal_init.c index 7673a4137f5..da93168d676 100644 --- a/opal/runtime/opal_init.c +++ b/opal/runtime/opal_init.c @@ -62,8 +62,8 @@ #include "opal/dss/dss.h" #include "opal/mca/shmem/base/base.h" #include "opal/mca/compress/base/base.h" -#include "opal/threads/threads.h" -#include "opal/threads/tsd.h" +#include "opal/mca/threads/threads.h" +#include "opal/mca/threads/tsd.h" #include "opal/runtime/opal_cr.h" #include "opal/mca/crs/base/base.h" diff --git a/opal/runtime/opal_params.c b/opal/runtime/opal_params.c index 485a8ce325b..f6c9faf5d17 100644 --- a/opal/runtime/opal_params.c +++ b/opal/runtime/opal_params.c @@ -39,8 +39,8 @@ #include "opal/runtime/opal.h" #include "opal/datatype/opal_datatype.h" #include "opal/mca/base/mca_base_var.h" -#include "opal/threads/mutex.h" -#include "opal/threads/threads.h" +#include "opal/mca/threads/mutex.h" +#include "opal/mca/threads/threads.h" #include "opal/mca/shmem/base/base.h" #include "opal/mca/base/mca_base_var.h" #include "opal/runtime/opal_params.h" diff --git a/opal/runtime/opal_progress.h b/opal/runtime/opal_progress.h index 1d25905569d..13bb9ead954 100644 --- a/opal/runtime/opal_progress.h +++ b/opal/runtime/opal_progress.h @@ -33,7 +33,7 @@ BEGIN_C_DECLS #include "opal_config.h" -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" #include "opal/runtime/opal.h" /** diff --git a/opal/runtime/opal_progress_threads.c b/opal/runtime/opal_progress_threads.c index 4c53fa35b67..a675405dc53 100644 --- a/opal/runtime/opal_progress_threads.c +++ b/opal/runtime/opal_progress_threads.c @@ -17,7 +17,7 @@ #include "opal/class/opal_list.h" #include "opal/mca/event/event.h" -#include "opal/threads/threads.h" +#include "opal/mca/threads/threads.h" #include "opal/util/error.h" #include "opal/util/fd.h" diff --git a/opal/threads/condition.h b/opal/threads/condition.h deleted file mode 100644 index 47eef598f8e..00000000000 --- a/opal/threads/condition.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2004-2007 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. - * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, - * University of Stuttgart. All rights reserved. - * Copyright (c) 2004-2005 The Regents of the University of California. - * All rights reserved. - * Copyright (c) 2007 Los Alamos National Security, LLC. All rights - * reserved. - * Copyright (c) 2015 Research Organization for Information Science - * and Technology (RIST). All rights reserved. - * $COPYRIGHT$ - * - * Additional copyrights may follow - * - * $HEADER$ - */ -#ifndef OPAL_CONDITION_SPINLOCK_H -#define OPAL_CONDITION_SPINLOCK_H - -#include "opal/mca/threads/condition.h" - -#endif - diff --git a/opal/threads/mutex.h b/opal/threads/mutex.h deleted file mode 100644 index 79067829ca1..00000000000 --- a/opal/threads/mutex.h +++ /dev/null @@ -1,31 +0,0 @@ -/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ -/* - * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana - * University Research and Technology - * Corporation. All rights reserved. - * Copyright (c) 2004-2016 The University of Tennessee and The University - * of Tennessee Research Foundation. All rights - * reserved. - * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, - * University of Stuttgart. All rights reserved. - * Copyright (c) 2004-2005 The Regents of the University of California. - * All rights reserved. - * Copyright (c) 2007 Cisco Systems, Inc. All rights reserved. - * Copyright (c) 2007-2016 Los Alamos National Security, LLC. All rights - * reserved. - * Copyright (c) 2007 Voltaire. All rights reserved. - * Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved. - * - * $COPYRIGHT$ - * - * Additional copyrights may follow - * - * $HEADER$ - */ - -#ifndef OPAL_MUTEX_H -#define OPAL_MUTEX_H 1 - -#include "opal/mca/threads/mutex.h" - -#endif /* OPAL_MUTEX_H */ diff --git a/opal/threads/thread_usage.h b/opal/threads/thread_usage.h deleted file mode 100644 index 7d71bcb6d04..00000000000 --- a/opal/threads/thread_usage.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana - * University Research and Technology - * Corporation. All rights reserved. - * Copyright (c) 2004-2006 The University of Tennessee and The University - * of Tennessee Research Foundation. All rights - * reserved. - * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, - * University of Stuttgart. All rights reserved. - * Copyright (c) 2004-2005 The Regents of the University of California. - * All rights reserved. - * Copyright (c) 2010 Cisco Systems, Inc. All rights reserved. - * Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2015-2017 Research Organization for Information Science - * and Technology (RIST). All rights reserved. - * Copyright (c) 2017 Intel, Inc. All rights reserved. - * $COPYRIGHT$ - * - * Additional copyrights may follow - * - * $HEADER$ - */ - -#ifndef OPAL_THREAD_USAGE_H -#define OPAL_THREAD_USAGE_H 1 - -#include "opal/mca/threads/thread_usage.h" - -#endif /* OPAL_THREAD_USAGE_H */ diff --git a/opal/threads/threads.h b/opal/threads/threads.h deleted file mode 100644 index ba7fcb081c0..00000000000 --- a/opal/threads/threads.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana - * University Research and Technology - * Corporation. All rights reserved. - * Copyright (c) 2004-2006 The University of Tennessee and The University - * of Tennessee Research Foundation. All rights - * reserved. - * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, - * University of Stuttgart. All rights reserved. - * Copyright (c) 2004-2005 The Regents of the University of California. - * All rights reserved. - * Copyright (c) 2010 Cisco Systems, Inc. All rights reserved. - * Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2015-2017 Research Organization for Information Science - * and Technology (RIST). All rights reserved. - * Copyright (c) 2017 Intel, Inc. All rights reserved. - * $COPYRIGHT$ - * - * Additional copyrights may follow - * - * $HEADER$ - */ - -#ifndef OPAL_THREAD_H -#define OPAL_THREAD_H 1 - -#include "opal/mca/threads/threads.h" - -#endif /* OPAL_THREAD_H */ diff --git a/opal/threads/tsd.h b/opal/threads/tsd.h deleted file mode 100644 index e059f15fca1..00000000000 --- a/opal/threads/tsd.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2007-2013 Los Alamos National Security, LLC. All rights - * reserved. - * Copyright (c) 2008 Cisco Systems, Inc. All rights reserved. - * Copyright (c) 2015-2017 Research Organization for Information Science - * and Technology (RIST). All rights reserved. - * $COPYRIGHT$ - * - * Additional copyrights may follow - * - * $HEADER$ - */ - - -#ifndef OPAL_THREADS_TSD_H -#define OPAL_THREADS_TSD_H - -#include "opal/mca/threads/tsd.h" - -#endif /* OPAL_THREADS_TSD_H */ diff --git a/opal/threads/wait_sync.h b/opal/threads/wait_sync.h deleted file mode 100644 index 496ebed4f9c..00000000000 --- a/opal/threads/wait_sync.h +++ /dev/null @@ -1,23 +0,0 @@ -/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ -/* - * Copyright (c) 2014-2016 The University of Tennessee and The University - * of Tennessee Research Foundation. All rights - * reserved. - * Copyright (c) 2016 Los Alamos National Security, LLC. All rights - * reserved. - * Copyright (c) 2016 Mellanox Technologies. All rights reserved. - * Copyright (c) 2016 Research Organization for Information Science - * and Technology (RIST). All rights reserved. - * $COPYRIGHT$ - * - * Additional copyrights may follow - * - * $HEADER$ - */ - -#if !defined(OPAL_THREADS_WAIT_SYNC_H) -#define OPAL_THREADS_WAIT_SYNC_H - -#include "opal/mca/threads/wait_sync.h" - -#endif /* defined(OPAL_THREADS_WAIT_SYNC_H) */ diff --git a/opal/util/cmd_line.c b/opal/util/cmd_line.c index f17263ac3c0..2da39dd3cc1 100644 --- a/opal/util/cmd_line.c +++ b/opal/util/cmd_line.c @@ -32,7 +32,7 @@ #include "opal/class/opal_object.h" #include "opal/class/opal_list.h" -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" #include "opal/util/argv.h" #include "opal/util/cmd_line.h" #include "opal/util/output.h" diff --git a/opal/util/cmd_line.h b/opal/util/cmd_line.h index 546e49200b9..9c49bc25360 100644 --- a/opal/util/cmd_line.h +++ b/opal/util/cmd_line.h @@ -120,7 +120,7 @@ #include "opal/class/opal_object.h" #include "opal/class/opal_list.h" -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" BEGIN_C_DECLS /** diff --git a/opal/util/info.h b/opal/util/info.h index 8f8cc686686..bbab7c35ab9 100644 --- a/opal/util/info.h +++ b/opal/util/info.h @@ -29,7 +29,7 @@ #include "opal/class/opal_list.h" #include "opal/class/opal_pointer_array.h" -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" #include "opal/mca/base/mca_base_var_enum.h" /** diff --git a/opal/util/info_subscriber.h b/opal/util/info_subscriber.h index c676ab0338e..c7ce58f95d7 100644 --- a/opal/util/info_subscriber.h +++ b/opal/util/info_subscriber.h @@ -30,7 +30,7 @@ #include "opal/class/opal_list.h" #include "opal/class/opal_pointer_array.h" #include "opal/class/opal_hash_table.h" -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" #include "opal/util/info.h" #include "opal/mca/base/mca_base_var_enum.h" diff --git a/opal/util/keyval_parse.c b/opal/util/keyval_parse.c index 212773f0e43..fe947131b63 100644 --- a/opal/util/keyval_parse.c +++ b/opal/util/keyval_parse.c @@ -29,7 +29,7 @@ #include "opal/util/keyval/keyval_lex.h" #include "opal/util/output.h" #include "opal/util/string_copy.h" -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" #include #include diff --git a/opal/util/net.c b/opal/util/net.c index 2ec734aee0b..3f14d524b89 100644 --- a/opal/util/net.c +++ b/opal/util/net.c @@ -69,7 +69,7 @@ #include "opal/util/argv.h" #include "opal/util/show_help.h" #include "opal/constants.h" -#include "opal/threads/tsd.h" +#include "opal/mca/threads/tsd.h" #include "opal/runtime/opal_params.h" /* this function doesn't depend on sockaddr_h */ diff --git a/opal/util/output.c b/opal/util/output.c index 46638674045..69a85bf9ee3 100644 --- a/opal/util/output.c +++ b/opal/util/output.c @@ -48,7 +48,7 @@ #include "opal/util/output.h" #include "opal/util/string_copy.h" #include "opal/util/printf.h" -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" #include "opal/constants.h" #include "opal/mca/pmix/pmix.h" diff --git a/orte/mca/plm/base/plm_base_receive.c b/orte/mca/plm/base/plm_base_receive.c index c95f203bc78..b1553a61fe2 100644 --- a/orte/mca/plm/base/plm_base_receive.c +++ b/orte/mca/plm/base/plm_base_receive.c @@ -37,7 +37,7 @@ #include "orte/mca/mca.h" #include "opal/dss/dss.h" -#include "opal/threads/threads.h" +#include "opal/mca/threads/threads.h" #include "opal/util/argv.h" #include "opal/util/opal_environ.h" diff --git a/orte/mca/plm/rsh/plm_rsh.h b/orte/mca/plm/rsh/plm_rsh.h index 7cad6d1221f..315bc40469f 100644 --- a/orte/mca/plm/rsh/plm_rsh.h +++ b/orte/mca/plm/rsh/plm_rsh.h @@ -35,7 +35,7 @@ #endif #include -#include "opal/threads/condition.h" +#include "opal/mca/threads/condition.h" #include "orte/mca/mca.h" #include "orte/mca/plm/plm.h" diff --git a/orte/mca/rmaps/base/rmaps_base_binding.c b/orte/mca/rmaps/base/rmaps_base_binding.c index 0715a1fe2d8..773aee5ef74 100644 --- a/orte/mca/rmaps/base/rmaps_base_binding.c +++ b/orte/mca/rmaps/base/rmaps_base_binding.c @@ -37,7 +37,7 @@ #include "orte/mca/mca.h" #include "opal/mca/base/base.h" #include "opal/mca/hwloc/base/base.h" -#include "opal/threads/tsd.h" +#include "opal/mca/threads/tsd.h" #include "orte/types.h" #include "orte/util/show_help.h" diff --git a/orte/mca/rmaps/base/rmaps_base_print_fns.c b/orte/mca/rmaps/base/rmaps_base_print_fns.c index 7899ebe342f..cc077e49e04 100644 --- a/orte/mca/rmaps/base/rmaps_base_print_fns.c +++ b/orte/mca/rmaps/base/rmaps_base_print_fns.c @@ -32,7 +32,7 @@ #include "orte/mca/mca.h" #include "opal/mca/base/base.h" #include "opal/mca/hwloc/base/base.h" -#include "opal/threads/tsd.h" +#include "opal/mca/threads/tsd.h" #include "orte/types.h" #include "orte/util/show_help.h" diff --git a/orte/mca/rmaps/base/rmaps_base_ranking.c b/orte/mca/rmaps/base/rmaps_base_ranking.c index e4f67d9f4d5..c80f81925d7 100644 --- a/orte/mca/rmaps/base/rmaps_base_ranking.c +++ b/orte/mca/rmaps/base/rmaps_base_ranking.c @@ -35,7 +35,7 @@ #include "orte/mca/mca.h" #include "opal/mca/base/base.h" #include "opal/mca/hwloc/base/base.h" -#include "opal/threads/tsd.h" +#include "opal/mca/threads/tsd.h" #include "orte/types.h" #include "orte/util/show_help.h" diff --git a/orte/mca/rmaps/base/rmaps_base_support_fns.c b/orte/mca/rmaps/base/rmaps_base_support_fns.c index 31cc85507e6..cd367799458 100644 --- a/orte/mca/rmaps/base/rmaps_base_support_fns.c +++ b/orte/mca/rmaps/base/rmaps_base_support_fns.c @@ -36,7 +36,7 @@ #include "orte/mca/mca.h" #include "opal/mca/base/base.h" #include "opal/mca/hwloc/base/base.h" -#include "opal/threads/tsd.h" +#include "opal/mca/threads/tsd.h" #include "orte/types.h" #include "orte/util/show_help.h" diff --git a/orte/mca/sstore/central/sstore_central_app.c b/orte/mca/sstore/central/sstore_central_app.c index 8ab1244bdc5..c1388141032 100644 --- a/orte/mca/sstore/central/sstore_central_app.c +++ b/orte/mca/sstore/central/sstore_central_app.c @@ -38,8 +38,8 @@ #include "opal/util/basename.h" #include "opal/util/os_dirpath.h" -#include "opal/threads/mutex.h" -#include "opal/threads/condition.h" +#include "opal/mca/threads/mutex.h" +#include "opal/mca/threads/condition.h" #include "orte/util/name_fns.h" #include "orte/util/proc_info.h" diff --git a/orte/mca/sstore/central/sstore_central_global.c b/orte/mca/sstore/central/sstore_central_global.c index aa361860a3b..f2a6a8bc920 100644 --- a/orte/mca/sstore/central/sstore_central_global.c +++ b/orte/mca/sstore/central/sstore_central_global.c @@ -40,8 +40,8 @@ #include "opal/util/basename.h" #include "opal/util/os_dirpath.h" -#include "opal/threads/mutex.h" -#include "opal/threads/condition.h" +#include "opal/mca/threads/mutex.h" +#include "opal/mca/threads/condition.h" #include "orte/util/name_fns.h" #include "orte/util/proc_info.h" diff --git a/orte/mca/sstore/central/sstore_central_local.c b/orte/mca/sstore/central/sstore_central_local.c index 0ed0f9d2b46..c60a4398f65 100644 --- a/orte/mca/sstore/central/sstore_central_local.c +++ b/orte/mca/sstore/central/sstore_central_local.c @@ -39,8 +39,8 @@ #include "opal/util/opal_environ.h" #include "opal/util/basename.h" -#include "opal/threads/mutex.h" -#include "opal/threads/condition.h" +#include "opal/mca/threads/mutex.h" +#include "opal/mca/threads/condition.h" #include "orte/util/name_fns.h" #include "orte/util/proc_info.h" diff --git a/orte/mca/sstore/central/sstore_central_module.c b/orte/mca/sstore/central/sstore_central_module.c index 7c02196632f..e3f2d3e8f4c 100644 --- a/orte/mca/sstore/central/sstore_central_module.c +++ b/orte/mca/sstore/central/sstore_central_module.c @@ -35,8 +35,8 @@ #include "opal/util/opal_environ.h" #include "opal/util/basename.h" -#include "opal/threads/mutex.h" -#include "opal/threads/condition.h" +#include "opal/mca/threads/mutex.h" +#include "opal/mca/threads/condition.h" #include "orte/util/name_fns.h" #include "orte/util/proc_info.h" diff --git a/orte/mca/sstore/stage/sstore_stage_app.c b/orte/mca/sstore/stage/sstore_stage_app.c index ce5ea401530..7ba3f257177 100644 --- a/orte/mca/sstore/stage/sstore_stage_app.c +++ b/orte/mca/sstore/stage/sstore_stage_app.c @@ -38,8 +38,8 @@ #include "opal/util/basename.h" #include "opal/util/os_dirpath.h" -#include "opal/threads/mutex.h" -#include "opal/threads/condition.h" +#include "opal/mca/threads/mutex.h" +#include "opal/mca/threads/condition.h" #include "orte/util/name_fns.h" #include "orte/util/proc_info.h" diff --git a/orte/mca/sstore/stage/sstore_stage_global.c b/orte/mca/sstore/stage/sstore_stage_global.c index 8379b4e9a57..a38127738a9 100644 --- a/orte/mca/sstore/stage/sstore_stage_global.c +++ b/orte/mca/sstore/stage/sstore_stage_global.c @@ -41,8 +41,8 @@ #include "opal/util/os_dirpath.h" #include "opal/util/opal_getcwd.h" -#include "opal/threads/mutex.h" -#include "opal/threads/condition.h" +#include "opal/mca/threads/mutex.h" +#include "opal/mca/threads/condition.h" #include "orte/util/show_help.h" #include "orte/util/name_fns.h" diff --git a/orte/mca/sstore/stage/sstore_stage_local.c b/orte/mca/sstore/stage/sstore_stage_local.c index c93943e3d69..998386c6597 100644 --- a/orte/mca/sstore/stage/sstore_stage_local.c +++ b/orte/mca/sstore/stage/sstore_stage_local.c @@ -45,8 +45,8 @@ #include "opal/mca/compress/compress.h" #include "opal/mca/compress/base/base.h" -#include "opal/threads/mutex.h" -#include "opal/threads/condition.h" +#include "opal/mca/threads/mutex.h" +#include "opal/mca/threads/condition.h" #include "orte/util/name_fns.h" #include "orte/util/proc_info.h" diff --git a/orte/mca/sstore/stage/sstore_stage_module.c b/orte/mca/sstore/stage/sstore_stage_module.c index 7a03e88b093..c69182bba27 100644 --- a/orte/mca/sstore/stage/sstore_stage_module.c +++ b/orte/mca/sstore/stage/sstore_stage_module.c @@ -35,8 +35,8 @@ #include "opal/util/opal_environ.h" #include "opal/util/basename.h" -#include "opal/threads/mutex.h" -#include "opal/threads/condition.h" +#include "opal/mca/threads/mutex.h" +#include "opal/mca/threads/condition.h" #include "orte/util/name_fns.h" #include "orte/util/proc_info.h" diff --git a/orte/runtime/orte_globals.c b/orte/runtime/orte_globals.c index abd2bfb3862..ebac4081461 100644 --- a/orte/runtime/orte_globals.c +++ b/orte/runtime/orte_globals.c @@ -40,7 +40,7 @@ #include "opal/class/opal_pointer_array.h" #include "opal/class/opal_value_array.h" #include "opal/dss/dss.h" -#include "opal/threads/threads.h" +#include "opal/mca/threads/threads.h" #include "orte/mca/errmgr/errmgr.h" #include "orte/mca/rml/rml.h" diff --git a/orte/runtime/orte_globals.h b/orte/runtime/orte_globals.h index 9abe705a47d..687b32bebae 100644 --- a/orte/runtime/orte_globals.h +++ b/orte/runtime/orte_globals.h @@ -44,7 +44,7 @@ #include "opal/class/opal_pointer_array.h" #include "opal/class/opal_value_array.h" #include "opal/class/opal_ring_buffer.h" -#include "opal/threads/threads.h" +#include "opal/mca/threads/threads.h" #include "opal/mca/event/event.h" #include "opal/mca/hwloc/hwloc-internal.h" #include "opal/mca/hwloc/base/base.h" diff --git a/orte/runtime/orte_init.c b/orte/runtime/orte_init.c index a14891cc9ae..2c4b6fb7e6e 100644 --- a/orte/runtime/orte_init.c +++ b/orte/runtime/orte_init.c @@ -40,7 +40,7 @@ #include "opal/util/proc.h" #include "opal/util/timings.h" #include "opal/runtime/opal.h" -#include "opal/threads/threads.h" +#include "opal/mca/threads/threads.h" #include "orte/util/show_help.h" #include "orte/mca/ess/base/base.h" diff --git a/orte/runtime/orte_wait.c b/orte/runtime/orte_wait.c index bed373d615c..be5163ef4c0 100644 --- a/orte/runtime/orte_wait.c +++ b/orte/runtime/orte_wait.c @@ -53,8 +53,8 @@ #include "opal/util/output.h" #include "opal/class/opal_list.h" #include "opal/mca/event/event.h" -#include "opal/threads/mutex.h" -#include "opal/threads/condition.h" +#include "opal/mca/threads/mutex.h" +#include "opal/mca/threads/condition.h" #include "opal/sys/atomic.h" #include "orte/constants.h" diff --git a/orte/test/system/event-threads.c b/orte/test/system/event-threads.c index cdd012d1a78..fd6ed9fc3fd 100644 --- a/orte/test/system/event-threads.c +++ b/orte/test/system/event-threads.c @@ -11,7 +11,7 @@ #include #include "opal/util/fd.h" -#include "opal/threads/threads.h" +#include "opal/mca/threads/threads.h" #include "opal/runtime/opal.h" #include "opal/mca/event/event.h" diff --git a/orte/test/system/evthread-test.c b/orte/test/system/evthread-test.c index 58c464679d7..c85c7c4c35b 100644 --- a/orte/test/system/evthread-test.c +++ b/orte/test/system/evthread-test.c @@ -11,7 +11,7 @@ #endif #include -#include "opal/threads/threads.h" +#include "opal/mca/threads/threads.h" #include "opal/runtime/opal.h" #include "opal/mca/event/event.h" diff --git a/orte/util/comm/comm.c b/orte/util/comm/comm.c index 6f2fba50aa1..b848ed68528 100644 --- a/orte/util/comm/comm.c +++ b/orte/util/comm/comm.c @@ -26,7 +26,7 @@ #include #include "opal/util/output.h" -#include "opal/threads/tsd.h" +#include "opal/mca/threads/tsd.h" #include "opal/mca/event/event.h" #include "opal/mca/pmix/pmix.h" #include "opal/runtime/opal_progress.h" diff --git a/orte/util/name_fns.c b/orte/util/name_fns.c index 7d5cd876d91..f684ab07edf 100644 --- a/orte/util/name_fns.c +++ b/orte/util/name_fns.c @@ -29,7 +29,7 @@ #include "opal/util/printf.h" #include "opal/util/string_copy.h" -#include "opal/threads/tsd.h" +#include "opal/mca/threads/tsd.h" #include "orte/mca/errmgr/errmgr.h" diff --git a/orte/util/threads.h b/orte/util/threads.h index d5f9c9c3369..08c6c66ab7e 100644 --- a/orte/util/threads.h +++ b/orte/util/threads.h @@ -13,7 +13,7 @@ #include "orte_config.h" #include "opal/sys/atomic.h" -#include "opal/threads/threads.h" +#include "opal/mca/threads/threads.h" /* provide macros for forward-proofing the shifting * of objects between threads - at some point, we diff --git a/oshmem/mca/memheap/buddy/memheap_buddy.h b/oshmem/mca/memheap/buddy/memheap_buddy.h index ab7e16b4b3c..246e598453f 100644 --- a/oshmem/mca/memheap/buddy/memheap_buddy.h +++ b/oshmem/mca/memheap/buddy/memheap_buddy.h @@ -17,7 +17,7 @@ #include "oshmem_config.h" #include "oshmem/mca/mca.h" #include "opal/class/opal_list.h" -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" #include "oshmem/mca/memheap/memheap.h" #include "oshmem/mca/memheap/base/base.h" #include "oshmem/mca/spml/spml.h" diff --git a/oshmem/mca/memheap/ptmalloc/memheap_ptmalloc.h b/oshmem/mca/memheap/ptmalloc/memheap_ptmalloc.h index dba1ed55f7d..9f1a95959a8 100644 --- a/oshmem/mca/memheap/ptmalloc/memheap_ptmalloc.h +++ b/oshmem/mca/memheap/ptmalloc/memheap_ptmalloc.h @@ -17,7 +17,7 @@ #include "oshmem_config.h" #include "oshmem/mca/mca.h" #include "opal/class/opal_list.h" -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" #include "oshmem/mca/memheap/memheap.h" #include "oshmem/mca/memheap/base/base.h" #include "oshmem/mca/spml/spml.h" diff --git a/oshmem/proc/proc.c b/oshmem/proc/proc.c index 23cbbc685c5..509f04941cc 100644 --- a/oshmem/proc/proc.c +++ b/oshmem/proc/proc.c @@ -24,7 +24,7 @@ #endif #include "opal/datatype/opal_convertor.h" -#include "opal/threads/mutex.h" +#include "opal/mca/threads/mutex.h" #include "opal/dss/dss.h" #include "opal/util/arch.h" #include "opal/class/opal_list.h" diff --git a/oshmem/request/request.h b/oshmem/request/request.h index 8d90bd922cf..97c6c2630ee 100644 --- a/oshmem/request/request.h +++ b/oshmem/request/request.h @@ -24,7 +24,7 @@ #include "opal/class/opal_free_list.h" #include "opal/class/opal_pointer_array.h" -#include "opal/threads/condition.h" +#include "opal/mca/threads/condition.h" BEGIN_C_DECLS diff --git a/oshmem/runtime/oshmem_shmem_init.c b/oshmem/runtime/oshmem_shmem_init.c index 696c7518b55..d430c05ef1b 100644 --- a/oshmem/runtime/oshmem_shmem_init.c +++ b/oshmem/runtime/oshmem_shmem_init.c @@ -27,7 +27,7 @@ #include "opal/class/opal_list.h" #include "opal/mca/base/base.h" #include "opal/runtime/opal_progress.h" -#include "opal/threads/threads.h" +#include "opal/mca/threads/threads.h" #include "opal/util/argv.h" #include "opal/util/output.h" #include "opal/util/error.h" diff --git a/test/threads/opal_condition.c b/test/threads/opal_condition.c index e163dcb83e4..cacb3acc5f1 100644 --- a/test/threads/opal_condition.c +++ b/test/threads/opal_condition.c @@ -25,8 +25,8 @@ #include "support.h" #include "opal/runtime/opal.h" #include "opal/constants.h" -#include "opal/threads/threads.h" -#include "opal/threads/condition.h" +#include "opal/mca/threads/threads.h" +#include "opal/mca/threads/condition.h" #include "opal/sys/atomic.h" static opal_mutex_t mutex; diff --git a/test/threads/opal_thread.c b/test/threads/opal_thread.c index e795190c5a1..f7f66130d8d 100644 --- a/test/threads/opal_thread.c +++ b/test/threads/opal_thread.c @@ -15,7 +15,7 @@ #include "support.h" #include "opal/constants.h" -#include "opal/threads/threads.h" +#include "opal/mca/threads/threads.h" #include "opal/sys/atomic.h" From 730e0b78a39d5958c2b833b59d4cd79bfbc0d969 Mon Sep 17 00:00:00 2001 From: Howard Pritchard Date: Fri, 21 Jun 2019 16:10:05 -0600 Subject: [PATCH 11/17] mca/threads: move configure functions out of top level config folder and in to relevant m4 files in the threads framework Signed-off-by: Howard Pritchard --- config/opal_config_argobots.m4 | 37 -- config/opal_config_pthreads.m4 | 676 ------------------------- config/opal_config_qthreads.m4 | 45 -- config/opal_config_threads.m4 | 108 ---- opal/mca/threads/argobots/configure.m4 | 13 + opal/mca/threads/configure.m4 | 85 ++++ opal/mca/threads/pthreads/configure.m4 | 653 ++++++++++++++++++++++++ opal/mca/threads/qthreads/configure.m4 | 19 + 8 files changed, 770 insertions(+), 866 deletions(-) delete mode 100644 config/opal_config_argobots.m4 delete mode 100644 config/opal_config_pthreads.m4 delete mode 100644 config/opal_config_qthreads.m4 delete mode 100644 config/opal_config_threads.m4 diff --git a/config/opal_config_argobots.m4 b/config/opal_config_argobots.m4 deleted file mode 100644 index c158adf0a50..00000000000 --- a/config/opal_config_argobots.m4 +++ /dev/null @@ -1,37 +0,0 @@ -dnl -dnl Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana -dnl University Research and Technology -dnl Corporation. All rights reserved. -dnl Copyright (c) 2004-2005 The University of Tennessee and The University -dnl of Tennessee Research Foundation. All rights -dnl reserved. -dnl Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, -dnl University of Stuttgart. All rights reserved. -dnl Copyright (c) 2004-2005 The Regents of the University of California. -dnl All rights reserved. -dnl Copyright (c) 2012 Cisco Systems, Inc. All rights reserved. -dnl Copyright (c) 2014 Intel, Inc. All rights reserved. -dnl Copyright (c) 2014-2016 Research Organization for Information Science -dnl and Technology (RIST). All rights reserved. -dnl $COPYRIGHT$ -dnl -dnl Additional copyrights may follow -dnl -dnl $HEADER$ -dnl -dnl OPAL_CONFIG_ARGOBOTS_THREADS() -dnl -dnl Configure Argobots threads, setting the following variables (but -dnl not calling AC_SUBST on them). - -AC_DEFUN([OPAL_CONFIG_ARGOBOTS_THREADS],[ - AC_CHECK_HEADERS([abt.h], - [AC_CHECK_LIB([abt],[ABT_init], - [threads_argobots_happy="yes"], - [threads_argobots_happy="no"])], - [threads_argobots_happy="no"]) - - AS_IF([test "$threads_argobots_happy" = "yes"], - [$1], - [$2]) -])dnl diff --git a/config/opal_config_pthreads.m4 b/config/opal_config_pthreads.m4 deleted file mode 100644 index de040436a9d..00000000000 --- a/config/opal_config_pthreads.m4 +++ /dev/null @@ -1,676 +0,0 @@ -dnl -dnl Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana -dnl University Research and Technology -dnl Corporation. All rights reserved. -dnl Copyright (c) 2004-2005 The University of Tennessee and The University -dnl of Tennessee Research Foundation. All rights -dnl reserved. -dnl Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, -dnl University of Stuttgart. All rights reserved. -dnl Copyright (c) 2004-2005 The Regents of the University of California. -dnl All rights reserved. -dnl Copyright (c) 2012 Cisco Systems, Inc. All rights reserved. -dnl Copyright (c) 2014 Intel, Inc. All rights reserved. -dnl Copyright (c) 2014-2016 Research Organization for Information Science -dnl and Technology (RIST). All rights reserved. -dnl $COPYRIGHT$ -dnl -dnl Additional copyrights may follow -dnl -dnl $HEADER$ -dnl -dnl OPAL_CONFIG_POSIX_THREADS() -dnl -dnl Configure posix threads, setting the following variables (but -dnl not calling AC_SUBST on them). - -# ******************************************************************** -# -# Internal macros - do not call from outside OPAL_CONFIG_POSIX_THREADS -# -# ******************************************************************** - - -AC_DEFUN([OPAL_INTL_PTHREAD_TRY_LINK], [ -# BEGIN: OPAL_INTL_PTHREAD_TRY_LINK -# -# Make sure that we can run a small application in C or C++, which -# ever is the current language. Do make sure that C or C++ is the -# current language. -# -# As long as this is not being run.... -# pthread_t may be anything from an int to a struct -- init with self-tid. -# - AC_LINK_IFELSE([AC_LANG_SOURCE([[ -#include - -int i = 3; -pthread_t me, newthread; - -void cleanup_routine(void *foo); -void *thread_main(void *foo); - -void cleanup_routine(void *foo) { i = 4; } -void *thread_main(void *foo) { i = 2; return (void*) &i; } - -int main(int argc, char* argv[]) -{ - pthread_attr_t attr; - - me = pthread_self(); - pthread_atfork(NULL, NULL, NULL); - pthread_attr_init(&attr); - pthread_cleanup_push(cleanup_routine, 0); - pthread_create(&newthread, &attr, thread_main, 0); - pthread_join(newthread, 0); - pthread_cleanup_pop(0); - - return 0; -}]])], - [$1], [$2]) -# END: OPAL_INTL_PTHREAD_TRY_LINK -])dnl - - -AC_DEFUN([OPAL_INTL_PTHREAD_TRY_LINK_FORTRAN], [ -# BEGIN: OPAL_INTL_PTHREAD_TRY_LINK_FORTRAN -# -# Make sure that we can run a small application in Fortran, with -# pthreads living in a C object file - -# Fortran module -cat > conftestf.f < conftest.c < -#include -#include -$opal_conftest_h - -#ifdef __cplusplus -extern "C" { -#endif -int i = 3; -pthread_t me, newthread; - -void cleanup_routine(void *foo); -void *thread_main(void *foo); -void pthreadtest_f(void); - -void cleanup_routine(void *foo) { i = 4; } -void *thread_main(void *foo) { i = 2; return (void*) &i; } - -void pthreadtest_f(void) -{ - pthread_attr_t attr; - - me = pthread_self(); - pthread_atfork(NULL, NULL, NULL); - pthread_attr_init(&attr); - pthread_cleanup_push(cleanup_routine, 0); - pthread_create(&newthread, &attr, thread_main, 0); - pthread_join(newthread, 0); - pthread_cleanup_pop(0); -} - -void pthreadtest(void) -{ pthreadtest_f(); } - -void pthreadtest_(void) -{ pthreadtest_f(); } - -void pthreadtest__(void) -{ pthreadtest_f(); } - -void PTHREADTEST(void) -{ pthreadtest_f(); } - -#ifdef __cplusplus -} -#endif -EOF - -# Try the compile -OPAL_LOG_COMMAND( - [$CC $CFLAGS -I. -c conftest.c], - OPAL_LOG_COMMAND( - [$FC $FCFLAGS conftestf.f conftest.o -o conftest $LDFLAGS $LIBS], - [HAPPY=1], - [HAPPY=0]), - [HAPPY=0]) - -if test "$HAPPY" = "1"; then - $1 -else - OPAL_LOG_MSG([here is the C program:], 1) - OPAL_LOG_FILE([conftest.c]) - if test -f conftest.h; then - OPAL_LOG_MSG([here is contest.h:], 1) - OPAL_LOG_FILE([conftest.h]) - fi - OPAL_LOG_MSG([here is the fortran program:], 1) - OPAL_LOG_FILE([conftestf.f]) - $2 -fi - -unset HAPPY opal_conftest_h -rm -rf conftest* -# END: OPAL_INTL_PTHREAD_TRY_LINK_FORTRAN -])dnl - - -# ******************************************************************** -# -# Try to compile thread support without any special flags -# -# ******************************************************************** -AC_DEFUN([OPAL_INTL_POSIX_THREADS_PLAIN_C], [ -# -# C compiler -# -if test "$opal_pthread_c_success" = "0"; then - AC_MSG_CHECKING([if C compiler and POSIX threads work as is]) - - AC_LANG_PUSH(C) - OPAL_INTL_PTHREAD_TRY_LINK(opal_pthread_c_success=1, - opal_pthread_c_success=0) - AC_LANG_POP(C) - if test "$opal_pthread_c_success" = "1"; then - AC_MSG_RESULT([yes]) - else - AC_MSG_RESULT([no]) - fi -fi -])dnl - - -AC_DEFUN([OPAL_INTL_POSIX_THREADS_PLAIN_CXX], [ -# -# C++ compiler -# -if test "$opal_pthread_cxx_success" = "0"; then - AC_MSG_CHECKING([if C++ compiler and POSIX threads work as is]) - - AC_LANG_PUSH(C++) - OPAL_INTL_PTHREAD_TRY_LINK(opal_pthread_cxx_success=1, - opal_pthread_cxx_success=0) - AC_LANG_POP(C++) - if test "$opal_pthread_cxx_success" = "1"; then - AC_MSG_RESULT([yes]) - else - AC_MSG_RESULT([no]) - fi -fi -])dnl - - -AC_DEFUN([OPAL_INTL_POSIX_THREADS_PLAIN_FC], [ -# -# Fortran compiler -# -if test "$opal_pthread_fortran_success" = "0" && \ - test "$OMPI_TRY_FORTRAN_BINDINGS" -gt "$OMPI_FORTRAN_NO_BINDINGS" && \ - test $ompi_fortran_happy -eq 1; then - AC_MSG_CHECKING([if Fortran compiler and POSIX threads work as is]) - - AC_LANG_PUSH(C) - OPAL_INTL_PTHREAD_TRY_LINK_FORTRAN(opal_pthread_fortran_success=1, - opal_pthread_fortran_success=0) - AC_LANG_POP(C) - if test "$opal_pthread_fortran_success" = "1"; then - AC_MSG_RESULT([yes]) - else - AC_MSG_RESULT([no]) - fi -fi -])dnl - - -AC_DEFUN([OPAL_INTL_POSIX_THREADS_PLAIN], [ -# BEGIN: OPAL_INTL_POSIX_THREADS_PLAIN -# -# Check if can compile without any special flags -# we throw -D_REENTRANT or -D_THREAD_SAFE in here, just in -# case. Some systems (OS X, for example) generally don't need -# the defines, but then will on one system header here or there -# why take chances? -# - -# Only run C++ and Fortran if those compilers already configured -AC_PROVIDE_IFELSE([AC_PROG_CC], - [OPAL_INTL_POSIX_THREADS_PLAIN_C], - [opal_pthread_c_success=1]) - -AC_PROVIDE_IFELSE([AC_PROG_CXX], - [OPAL_INTL_POSIX_THREADS_PLAIN_CXX], - [opal_pthread_cxx_success=1]) - -AC_PROVIDE_IFELSE([AC_PROG_FC], - [OPAL_INTL_POSIX_THREADS_PLAIN_FC], - [opal_pthread_fortran_success=1]) - -# End: OPAL_INTL_POSIX_THREADS_PLAIN -])dnl - - -# ******************************************************************** -# -# Try to compile thread support with special compiler flags -# -# ******************************************************************** -AC_DEFUN([OPAL_INTL_POSIX_THREADS_SPECIAL_FLAGS_C], [ -# -# C compiler -# -if test "$opal_pthread_c_success" = "0"; then - for pf in $pflags; do - AC_MSG_CHECKING([if C compiler and POSIX threads work with $pf]) - CFLAGS="$orig_CFLAGS $pf" - AC_LANG_PUSH(C) - OPAL_INTL_PTHREAD_TRY_LINK(opal_pthread_c_success=1, - opal_pthread_c_success=0) - AC_LANG_POP(C) - if test "$opal_pthread_c_success" = "1"; then - TPKG_CFLAGS="$pf" - AC_MSG_RESULT([yes]) - break - else - TPKG_CFLAGS= - CFLAGS="$orig_CFLAGS" - AC_MSG_RESULT([no]) - fi - done -fi -]) - - -AC_DEFUN([OPAL_INTL_POSIX_THREADS_SPECIAL_FLAGS_CXX], [ -# -# C++ compiler -# -if test "$opal_pthread_cxx_success" = "0"; then - for pf in $pflags; do - AC_MSG_CHECKING([if C++ compiler and POSIX threads work with $pf]) - CXXFLAGS="$orig_CXXFLAGS $pf" - AC_LANG_PUSH(C++) - OPAL_INTL_PTHREAD_TRY_LINK(opal_pthread_cxx_success=1, - opal_pthread_cxx_success=0) - AC_LANG_POP(C++) - if test "$opal_pthread_cxx_success" = "1"; then - TPKG_CXXFLAGS="$pf" - AC_MSG_RESULT([yes]) - break - else - TPKG_CXXFLAGS= - CXXFLAGS="$orig_CXXFLAGS" - AC_MSG_RESULT([no]) - fi - done -fi -]) - - -AC_DEFUN([OPAL_INTL_POSIX_THREADS_SPECIAL_FLAGS_FC], [ -# -# Fortran compiler -# -if test "$opal_pthread_fortran_success" = "0" && \ - test "$OMPI_TRY_FORTRAN_BINDINGS" -gt "$OMPI_FORTRAN_NO_BINDINGS" && \ - test $ompi_fortran_happy -eq 1; then - for pf in $pflags; do - AC_MSG_CHECKING([if Fortran compiler and POSIX threads work with $pf]) - FCFLAGS="$orig_FCFLAGS $pf" - AC_LANG_PUSH(C) - OPAL_INTL_PTHREAD_TRY_LINK_FORTRAN(opal_pthread_fortran_success=1, - opal_pthread_fortran_success=0) - AC_LANG_POP(C) - if test "$opal_pthread_fortran_success" = "1"; then - TPKG_FCFLAGS="$pf" - AC_MSG_RESULT([yes]) - break - else - TPKG_FCFLAGS= - FCFLAGS="$orig_FCFLAGS" - AC_MSG_RESULT([no]) - fi - done -fi -]) - - -AC_DEFUN([OPAL_INTL_POSIX_THREADS_SPECIAL_FLAGS],[ -# Begin: OPAL_INTL_POSIX_THREADS_SPECIAL_FLAGS -# -# If above didn't work, try some super-special compiler flags -# that get evaluated to the "right" things. -# -# -Kthread: -# -kthread: FreeBSD kernel threads -# -pthread: Modern GCC (most all platforms) -# -pthreads: GCC on solaris -# -mthreads: -# -mt: Solaris native compilers / HP-UX aCC -# -# Put -mt before -mthreads because HP-UX aCC will properly compile -# with -mthreads (reading as -mt), but emit a warning about unknown -# flags hreads. Stupid compilers. - -case "${host_cpu}-${host_os}" in - *solaris*) - pflags="-pthread -pthreads -mt" - ;; - *) - pflags="-Kthread -kthread -pthread -pthreads -mt -mthreads" - ;; -esac - -# Only run C++ and Fortran if those compilers already configured -AC_PROVIDE_IFELSE([AC_PROG_CC], - [OPAL_INTL_POSIX_THREADS_SPECIAL_FLAGS_C], - [opal_pthread_c_success=1]) - -AC_PROVIDE_IFELSE([AC_PROG_CXX], - [OPAL_INTL_POSIX_THREADS_SPECIAL_FLAGS_CXX], - [opal_pthread_cxx_success=1]) - -AC_PROVIDE_IFELSE([AC_PROG_FC], - [OPAL_INTL_POSIX_THREADS_SPECIAL_FLAGS_FC], - [opal_pthread_fortran_success=1]) - -# End: OPAL_INTL_POSIX_THREADS_SPECIAL_FLAGS -])dnl - - -# ******************************************************************** -# -# Try to compile thread support with extra libs -# -# ******************************************************************** -AC_DEFUN([OPAL_INTL_POSIX_THREADS_LIBS_C],[ -# -# C compiler -# -if test "$opal_pthread_c_success" = "0"; then - for pl in $plibs; do - AC_MSG_CHECKING([if C compiler and POSIX threads work with $pl]) - case "${host_cpu}-${host-_os}" in - *-aix* | *-freebsd*) - if test "`echo $CPPFLAGS | $GREP 'D_THREAD_SAFE'`" = ""; then - TPKG_CPPFLAGS="-D_THREAD_SAFE" - CPPFLAGS="$CPPFLAGS $TPKG_CPPFLAGS" - fi - ;; - *) - if test "`echo $CPPFLAGS | $GREP 'D_REENTRANT'`" = ""; then - TPKG_CPPFLAGS="-D_REENTRANT" - CPPFLAGS="$CPPFLAGS $TPKG_CPPFLAGS" - fi - ;; - esac - LIBS="$orig_LIBS $pl" - AC_LANG_PUSH(C) - OPAL_INTL_PTHREAD_TRY_LINK(opal_pthread_c_success=1, - opal_pthread_c_success=0) - AC_LANG_POP(C) - if test "$opal_pthread_c_success" = "1"; then - TPKG_LIBS="$pl" - AC_MSG_RESULT([yes]) - else - TPKG_CPPFLAGS= - CPPFLAGS="$orig_CPPFLAGS" - LIBS="$orig_LIBS" - AC_MSG_RESULT([no]) - fi - done -fi -])dnl - - -AC_DEFUN([OPAL_INTL_POSIX_THREADS_LIBS_CXX],[ -# -# C++ compiler -# -if test "$opal_pthread_cxx_success" = "0"; then - if test ! "$opal_pthread_c_success" = "0" && test ! "$TPKG_LIBS" = "" ; then - AC_MSG_CHECKING([if C++ compiler and POSIX threads work with $TPKG_LIBS]) - case "${host_cpu}-${host-_os}" in - *-aix* | *-freebsd*) - if test "`echo $CXXCPPFLAGS | $GREP 'D_THREAD_SAFE'`" = ""; then - TPKG_CXXCPPFLAGS="-D_THREAD_SAFE" - CXXCPPFLAGS="$CXXCPPFLAGS $TPKG_CXXCPPFLAGS" - fi - ;; - *) - if test "`echo $CXXCPPFLAGS | $GREP 'D_REENTRANT'`" = ""; then - TPKG_CXXCPPFLAGS="-D_REENTRANT" - CXXCPPFLAGS="$CXXCPPFLAGS $TPKG_CXXCPPFLAGS" - fi - ;; - esac - LIBS="$orig_LIBS $TPKG_LIBS" - AC_LANG_PUSH(C++) - OPAL_INTL_PTHREAD_TRY_LINK(opal_pthread_cxx_success=1, - opal_pthread_cxx_success=0) - AC_LANG_POP(C++) - if test "$opal_pthread_cxx_success" = "1"; then - AC_MSG_RESULT([yes]) - else - CXXCPPFLAGS="$orig_CXXCPPFLAGS" - LIBS="$orig_LIBS" - AC_MSG_RESULT([no]) - AC_MSG_ERROR([Can not find working threads configuration. aborting]) - fi - else - for pl in $plibs; do - AC_MSG_CHECKING([if C++ compiler and POSIX threads work with $pl]) - case "${host_cpu}-${host-_os}" in - *-aix* | *-freebsd*) - if test "`echo $CXXCPPFLAGS | $GREP 'D_THREAD_SAFE'`" = ""; then - TPKG_CXXCPPFLAGS="-D_THREAD_SAFE" - CXXCPPFLAGS="$CXXCPPFLAGS $TPKG_CXXCPPFLAGS" - fi - ;; - *) - if test "`echo $CXXCPPFLAGS | $GREP 'D_REENTRANT'`" = ""; then - TPKG_CXXCPPFLAGS="-D_REENTRANT" - CXXCPPFLAGS="$CXXCPPFLAGS $TPKG_CXXCPPFLAGS" - fi - ;; - esac - LIBS="$orig_LIBS $pl" - AC_LANG_PUSH(C++) - OPAL_INTL_PTHREAD_TRY_LINK(opal_pthread_cxx_success=1, - opal_pthread_cxx_success=0) - AC_LANG_POP(C++) - if test "$opal_pthread_cxx_success" = "1"; then - TPKG_LIBS="$pl" - AC_MSG_RESULT([yes]) - else - TPKG_CXXCPPFLAGS= - CXXCPPFLAGS="$orig_CXXCPPFLAGS" - LIBS="$orig_LIBS" - AC_MSG_RESULT([no]) - fi - done - fi -fi -])dnl - - -AC_DEFUN([OPAL_INTL_POSIX_THREADS_LIBS_FC],[ -# -# Fortran compiler -# -if test "$opal_pthread_fortran_success" = "0" && \ - test "$OMPI_TRY_FORTRAN_BINDINGS" -gt "$OMPI_FORTRAN_NO_BINDINGS" && \ - test $ompi_fortran_happy -eq 1; then - if test ! "$opal_pthread_c_success" = "0" && test ! "$TPKG_LIBS" = "" ; then - AC_MSG_CHECKING([if Fortran compiler and POSIX threads work with $TPKG_LIBS]) - LIBS="$orig_LIBS $TPKG_LIBS" - AC_LANG_PUSH(C) - OPAL_INTL_PTHREAD_TRY_LINK_FORTRAN(opal_pthread_fortran_success=1, - opal_pthread_fortran_success=0) - AC_LANG_POP(C) - if test "$opal_pthread_fortran_success" = "1"; then - AC_MSG_RESULT([yes]) - else - LIBS="$orig_LIBS" - AC_MSG_RESULT([no]) - AC_MSG_ERROR([Can not find working threads configuration. aborting]) - fi - else - for pl in $plibs; do - AC_MSG_CHECKING([if Fortran compiler and POSIX threads work with $pl]) - LIBS="$orig_LIBS $pl" - AC_LANG_PUSH(C) - OPAL_INTL_PTHREAD_TRY_LINK_FORTRAN(opal_pthread_fortran_success=1, - opal_pthread_fortran_success=0) - AC_LANG_POP(C) - if test "$opal_pthread_fortran_success" = "1"; then - TPKG_LIBS="$pl" - AC_MSG_RESULT([yes]) - break - else - LIBS="$orig_LIBS" - AC_MSG_RESULT([no]) - fi - done - fi -fi -])dnl - - -AC_DEFUN([OPAL_INTL_POSIX_THREADS_LIBS],[ -# Begin: OPAL_INTL_POSIX_THREADS_LIBS -# -# if we can't find a super-special compiler flags, try some libraries. -# we throw -D_REENTRANT or -D_THREAD_SAFE in here, just in case. Some -# systems (OS X, for example) generally don't need the defines, but -# then will on one system header here or there why take chances? -# -# libpthreads: AIX - must check before libpthread -# liblthread: LinuxThreads on FreeBSD -# libpthread: The usual place (like we can define usual!) -plibs="-lpthreads -llthread -lpthread" - -# Only run C++ and Fortran if those compilers already configured -AC_PROVIDE_IFELSE([AC_PROG_CC], - [OPAL_INTL_POSIX_THREADS_LIBS_C], - [opal_pthread_c_success=1]) - -AC_PROVIDE_IFELSE([AC_PROG_CXX], - [OPAL_INTL_POSIX_THREADS_LIBS_CXX], - [opal_pthread_cxx_success=1]) - -AC_PROVIDE_IFELSE([AC_PROG_FC], - [OPAL_INTL_POSIX_THREADS_LIBS_FC], - [opal_pthread_fortran_success=1]) - -# End: OPAL_INTL_POSIX_THREADS_LIBS] -)dnl - - -#******************************************************************** -# -# External macro (aka, the real thing) -# -#******************************************************************** -AC_DEFUN([OPAL_CONFIG_POSIX_THREADS],[ - AC_REQUIRE([AC_PROG_GREP]) - -opal_pthread_c_success=0 -opal_pthread_fortran_success=0 -opal_pthread_cxx_success=0 - -orig_CFLAGS="$CFLAGS" -orig_FCFLAGS="$FCFLAGS" -orig_CXXFLAGS="$CXXFLAGS" -orig_CPPFLAGS="$CPPFLAGS" -orig_CXXCPPFLAGS="$CXXCPPFLAGS" -orig_LDFLAGS="$LDFLAGS" -orig_LIBS="$LIBS" - -TPKG_CFLAGS= -TPKG_FCFLAGS= -TPKG_CXXFLAGS= -TPKG_CPPFLAGS= -TPKG_CXXCPPFLAGS= -TPKG_LDFLAGS= -TPKG_LIBS= - -# Try with the basics, mam. -OPAL_INTL_POSIX_THREADS_PLAIN - -# Try the super-special compiler flags. -OPAL_INTL_POSIX_THREADS_SPECIAL_FLAGS - -# Try the normal linking methods (that's no fun) -OPAL_INTL_POSIX_THREADS_LIBS - -# -# check to see if we can create shared memory mutexes and conditions -# -AC_CHECK_FUNCS([pthread_mutexattr_setpshared pthread_condattr_setpshared]) - -# -# check to see if we can set error checking mutexes -# - -# LinuxThreads -AC_MSG_CHECKING([for PTHREAD_MUTEX_ERRORCHECK_NP]) -AC_LINK_IFELSE( - [AC_LANG_PROGRAM( - [[#include ]], - [[pthread_mutexattr_settype(NULL, PTHREAD_MUTEX_ERRORCHECK_NP);]])], - [result="yes" defval=1], [result="no" defval=0]) -AC_MSG_RESULT([$result]) -AC_DEFINE_UNQUOTED([OPAL_HAVE_PTHREAD_MUTEX_ERRORCHECK_NP], [$defval], - [If PTHREADS implementation supports PTHREAD_MUTEX_ERRORCHECK_NP]) - -# Mac OS X -AC_MSG_CHECKING([for PTHREAD_MUTEX_ERRORCHECK]) -AC_LINK_IFELSE( - [AC_LANG_PROGRAM( - [[#include ]], - [[pthread_mutexattr_settype(NULL, PTHREAD_MUTEX_ERRORCHECK);]])], - [result="yes" defval=1], [result="no" defval=0]) -AC_MSG_RESULT([$result]) -AC_DEFINE_UNQUOTED([OPAL_HAVE_PTHREAD_MUTEX_ERRORCHECK], [$defval], - [If PTHREADS implementation supports PTHREAD_MUTEX_ERRORCHECK]) - -CFLAGS="$orig_CFLAGS" -FCFLAGS="$orig_FCFLAGS" -CXXFLAGS="$orig_CXXFLAGS" -CPPFLAGS="$orig_CPPFLAGS" -CXXCPPFLAGS="$orig_CXXCPPFLAGS" -LDFLAGS="$orig_LDFLAGS" -LIBS="$orig_LIBS" - -if test "$OMPI_TRY_FORTRAN_BINDINGS" = "$OMPI_FORTRAN_NO_BINDINGS" || \ - test $ompi_fortran_happy -ne 1; then - opal_pthread_fortran_success=1 -fi - -if test "$opal_pthread_c_success" = "1" && \ - test "$opal_pthread_cxx_success" = "1" && \ - test "$opal_pthread_fortran_success" = "1"; then - internal_useless=1 - $1 -else - internal_useless=1 - $2 -fi - -unset opal_pthread_c_success opal_pthread_fortran_success opal_pthread_cxx_success -unset internal_useless -])dnl diff --git a/config/opal_config_qthreads.m4 b/config/opal_config_qthreads.m4 deleted file mode 100644 index 08c0fd729a9..00000000000 --- a/config/opal_config_qthreads.m4 +++ /dev/null @@ -1,45 +0,0 @@ -dnl -dnl Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana -dnl University Research and Technology -dnl Corporation. All rights reserved. -dnl Copyright (c) 2004-2005 The University of Tennessee and The University -dnl of Tennessee Research Foundation. All rights -dnl reserved. -dnl Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, -dnl University of Stuttgart. All rights reserved. -dnl Copyright (c) 2004-2005 The Regents of the University of California. -dnl All rights reserved. -dnl Copyright (c) 2012 Cisco Systems, Inc. All rights reserved. -dnl Copyright (c) 2014 Intel, Inc. All rights reserved. -dnl Copyright (c) 2014-2016 Research Organization for Information Science -dnl and Technology (RIST). All rights reserved. -dnl Copyright (c) 2019 Sandia National Laboratories. All rights reserved. -dnl Copyright (c) 2019 Triad National Security, LLC. All rights. -dnl $COPYRIGHT$ -dnl -dnl Additional copyrights may follow -dnl -dnl $HEADER$ -dnl -dnl OPAL_CONFIG_QTHREADS() -dnl -dnl Configure argobot threads, setting the following variables (but -dnl not calling AC_SUBST on them). - -#******************************************************************** -# -# TODO: undoubtedly need some better check than this -# -#******************************************************************** -AC_DEFUN([OPAL_CONFIG_QTHREADS],[ - - AC_CHECK_HEADERS([mach/mach_time.h], - [AC_CHECK_FUNC([mach_absolute_time], - [threads_qthreads_happy="yes"], - [threads_qthreads_happy="no"])], - [threads_qthreads_happy="no"]) - - AS_IF([test "$threads_qthreads_happy" = "yes"], - [$1], - [$2]) -])dnl diff --git a/config/opal_config_threads.m4 b/config/opal_config_threads.m4 deleted file mode 100644 index 9aead21cbd5..00000000000 --- a/config/opal_config_threads.m4 +++ /dev/null @@ -1,108 +0,0 @@ -dnl -dnl Copyright (c) 2004-2010 The Trustees of Indiana University and Indiana -dnl University Research and Technology -dnl Corporation. All rights reserved. -dnl Copyright (c) 2004-2005 The University of Tennessee and The University -dnl of Tennessee Research Foundation. All rights -dnl reserved. -dnl Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, -dnl University of Stuttgart. All rights reserved. -dnl Copyright (c) 2004-2005 The Regents of the University of California. -dnl All rights reserved. -dnl Copyright (c) 2010 Cisco Systems, Inc. All rights reserved. -dnl Copyright (c) 2009-2011 Oak Ridge National Labs. All rights reserved. -dnl Copyright (c) 2014 Intel, Inc. All rights reserved -dnl Copyright (c) 2015 Research Organization for Information Science -dnl and Technology (RIST). All rights reserved. -dnl Copyright (c) 2019 Triad National Security, LLC. All rights. -dnl $COPYRIGHT$ -dnl -dnl Additional copyrights may follow -dnl -dnl $HEADER$ -dnl - -AC_DEFUN([OPAL_CONFIG_THREADS],[ -# -# Arguments: none -# -# Dependencies: None -# -# Modifies: -# none - see called tests -# -# configure threads -# - -# -# First see what kind of threads we are going to use -# - -AC_ARG_WITH([threads], - [AC_HELP_STRING([--with-threads=TYPE], - [Specify thread TYPE to use. default:pthreads. Other options are qthreads and argobots.])]) - -# -# Check we for the thread package requested, or posix -# - -thread_type_found= - -# -# check for posix threads -# -AS_IF([test -z "$with_threads" || test "$with_threads" = "pthreads" || test "$with_threads" = "yes"], - [OPAL_CONFIG_POSIX_THREADS(HAVE_THREAD_PKG=1, HAVE_THREAD_PKG=0) - AC_MSG_CHECKING([for working POSIX threads package]) - AS_IF([test "$HAVE_THREAD_PKG" = "1"], - [AC_MSG_RESULT([yes]) - thread_type_found="pthreads"], - [AC_MSG_RESULT([no])])], - []) - -# -# see if argobots is called for -# -AS_IF([test -z "$thread_type_found" && test "$with_threads" = "argobots"], - [OPAL_CONFIG_ARGOBOTS_THREADS(HAVE_THREAD_PKG=1, HAVE_THREAD_PKG=0) - AC_MSG_CHECKING([for working ARGOBOTS threads package]) - AS_IF([test "$HAVE_THREAD_PKG" = "1"], - [AC_MSG_RESULT([yes]) - thread_type_found="argobots"], - [AC_MSG_RESULT([no])])], - []) - -AS_IF([test -z "$thread_type_found" && test "$with_threads" = "qthreads"], - [OPAL_CONFIG_QTHREADS(HAVE_THREAD_PKG=1, HAVE_THREAD_PKG=0) - AC_MSG_CHECKING([for working Qthreads package]) - AS_IF([test "$HAVE_THREAD_PKG" = "1"], - [AC_MSG_RESULT([yes]) - thread_type_found="qthreads"], - [AC_MSG_RESULT([no])])], - []) - -# -# Bail if we didn't find any thread package -# - -AS_IF([test -z "$thread_type_found"], - [AC_MSG_WARN([*** no thread package $with_threads]) - AC_MSG_WARN([*** available on your system]) - AC_MSG_ERROR([*** Can not continue])]) - -THREAD_CFLAGS="$TPKG_CFLAGS" -THREAD_FCFLAGS="$TPKG_FCFLAGS" -THREAD_CXXFLAGS="$TPKG_CXXFLAGS" -THREAD_CPPFLAGS="$TPKG_CPPFLAGS" -THREAD_CXXCPPFLAGS="$TPKG_CXXCPPFLAGS" -THREAD_LDFLAGS="$TPKG_LDFLAGS" -THREAD_LIBS="$TPKG_LIBS" -HAVE_THREAD_PKG_TYPE="$thread_type_found" -export HAVE_THREAD_PKG_TYPE - -AS_IF([test "$thread_type_found" = "pthreads"], - [OPAL_CHECK_PTHREAD_PIDS],[]) - -OPAL_SUMMARY_ADD([[Miscellaneous]],[[Threading Package]],[opal_threads], [$thread_type_found]) -])dnl - diff --git a/opal/mca/threads/argobots/configure.m4 b/opal/mca/threads/argobots/configure.m4 index 22bc1f1e962..d23ce8c3b5a 100644 --- a/opal/mca/threads/argobots/configure.m4 +++ b/opal/mca/threads/argobots/configure.m4 @@ -21,6 +21,19 @@ # # $HEADER$ # + +AC_DEFUN([OPAL_CONFIG_ARGOBOTS_THREADS],[ + AC_CHECK_HEADERS([abt.h], + [AC_CHECK_LIB([abt],[ABT_init], + [threads_argobots_happy="yes"], + [threads_argobots_happy="no"])], + [threads_argobots_happy="no"]) + + AS_IF([test "$threads_argobots_happy" = "yes"], + [$1], + [$2]) +])dnl + AC_DEFUN([MCA_opal_threads_argobots_PRIORITY], [30]) AC_DEFUN([MCA_opal_threads_argobots_COMPILE_MODE], [ diff --git a/opal/mca/threads/configure.m4 b/opal/mca/threads/configure.m4 index e9e08c4f38f..b3635c4dc20 100644 --- a/opal/mca/threads/configure.m4 +++ b/opal/mca/threads/configure.m4 @@ -19,6 +19,91 @@ dnl dnl $HEADER$ dnl + +AC_DEFUN([OPAL_CONFIG_THREADS],[ +# +# Arguments: none +# +# Dependencies: None +# +# Modifies: +# none - see called tests +# +# configure threads +# + +# +# First see what kind of threads we are going to use +# + +AC_ARG_WITH([threads], + [AC_HELP_STRING([--with-threads=TYPE], + [Specify thread TYPE to use. default:pthreads. Other options are qthreads and argobots.])]) + +# +# Check we for the thread package requested, or posix +# + +thread_type_found= + +# +# check for posix threads +# +AS_IF([test -z "$with_threads" || test "$with_threads" = "pthreads" || test "$with_threads" = "yes"], + [OPAL_CONFIG_POSIX_THREADS(HAVE_THREAD_PKG=1, HAVE_THREAD_PKG=0) + AC_MSG_CHECKING([for working POSIX threads package]) + AS_IF([test "$HAVE_THREAD_PKG" = "1"], + [AC_MSG_RESULT([yes]) + thread_type_found="pthreads"], + [AC_MSG_RESULT([no])])], + []) + +# +# see if argobots is called for +# +AS_IF([test -z "$thread_type_found" && test "$with_threads" = "argobots"], + [OPAL_CONFIG_ARGOBOTS_THREADS(HAVE_THREAD_PKG=1, HAVE_THREAD_PKG=0) + AC_MSG_CHECKING([for working ARGOBOTS threads package]) + AS_IF([test "$HAVE_THREAD_PKG" = "1"], + [AC_MSG_RESULT([yes]) + thread_type_found="argobots"], + [AC_MSG_RESULT([no])])], + []) + +AS_IF([test -z "$thread_type_found" && test "$with_threads" = "qthreads"], + [OPAL_CONFIG_QTHREADS(HAVE_THREAD_PKG=1, HAVE_THREAD_PKG=0) + AC_MSG_CHECKING([for working Qthreads package]) + AS_IF([test "$HAVE_THREAD_PKG" = "1"], + [AC_MSG_RESULT([yes]) + thread_type_found="qthreads"], + [AC_MSG_RESULT([no])])], + []) + +# +# Bail if we didn't find any thread package +# + +AS_IF([test -z "$thread_type_found"], + [AC_MSG_WARN([*** no thread package $with_threads]) + AC_MSG_WARN([*** available on your system]) + AC_MSG_ERROR([*** Can not continue])]) + +THREAD_CFLAGS="$TPKG_CFLAGS" +THREAD_FCFLAGS="$TPKG_FCFLAGS" +THREAD_CXXFLAGS="$TPKG_CXXFLAGS" +THREAD_CPPFLAGS="$TPKG_CPPFLAGS" +THREAD_CXXCPPFLAGS="$TPKG_CXXCPPFLAGS" +THREAD_LDFLAGS="$TPKG_LDFLAGS" +THREAD_LIBS="$TPKG_LIBS" +HAVE_THREAD_PKG_TYPE="$thread_type_found" +export HAVE_THREAD_PKG_TYPE + +AS_IF([test "$thread_type_found" = "pthreads"], + [OPAL_CHECK_PTHREAD_PIDS],[]) + +OPAL_SUMMARY_ADD([[Miscellaneous]],[[Threading Package]],[opal_threads], [$thread_type_found]) +])dnl + dnl we only want one :) m4_define(MCA_opal_threads_CONFIGURE_MODE, STOP_AT_FIRST) diff --git a/opal/mca/threads/pthreads/configure.m4 b/opal/mca/threads/pthreads/configure.m4 index 7ec32e36c9f..7b50a4e82fd 100644 --- a/opal/mca/threads/pthreads/configure.m4 +++ b/opal/mca/threads/pthreads/configure.m4 @@ -21,6 +21,658 @@ # # $HEADER$ # + +# ******************************************************************** +# +# Internal macros - do not call from outside OPAL_CONFIG_POSIX_THREADS +# +# ******************************************************************** + + +AC_DEFUN([OPAL_INTL_PTHREAD_TRY_LINK], [ +# BEGIN: OPAL_INTL_PTHREAD_TRY_LINK +# +# Make sure that we can run a small application in C or C++, which +# ever is the current language. Do make sure that C or C++ is the +# current language. +# +# As long as this is not being run.... +# pthread_t may be anything from an int to a struct -- init with self-tid. +# + AC_LINK_IFELSE([AC_LANG_SOURCE([[ +#include + +int i = 3; +pthread_t me, newthread; + +void cleanup_routine(void *foo); +void *thread_main(void *foo); + +void cleanup_routine(void *foo) { i = 4; } +void *thread_main(void *foo) { i = 2; return (void*) &i; } + +int main(int argc, char* argv[]) +{ + pthread_attr_t attr; + + me = pthread_self(); + pthread_atfork(NULL, NULL, NULL); + pthread_attr_init(&attr); + pthread_cleanup_push(cleanup_routine, 0); + pthread_create(&newthread, &attr, thread_main, 0); + pthread_join(newthread, 0); + pthread_cleanup_pop(0); + + return 0; +}]])], + [$1], [$2]) +# END: OPAL_INTL_PTHREAD_TRY_LINK +])dnl + + +AC_DEFUN([OPAL_INTL_PTHREAD_TRY_LINK_FORTRAN], [ +# BEGIN: OPAL_INTL_PTHREAD_TRY_LINK_FORTRAN +# +# Make sure that we can run a small application in Fortran, with +# pthreads living in a C object file + +# Fortran module +cat > conftestf.f < conftest.c < +#include +#include +$opal_conftest_h + +#ifdef __cplusplus +extern "C" { +#endif +int i = 3; +pthread_t me, newthread; + +void cleanup_routine(void *foo); +void *thread_main(void *foo); +void pthreadtest_f(void); + +void cleanup_routine(void *foo) { i = 4; } +void *thread_main(void *foo) { i = 2; return (void*) &i; } + +void pthreadtest_f(void) +{ + pthread_attr_t attr; + + me = pthread_self(); + pthread_atfork(NULL, NULL, NULL); + pthread_attr_init(&attr); + pthread_cleanup_push(cleanup_routine, 0); + pthread_create(&newthread, &attr, thread_main, 0); + pthread_join(newthread, 0); + pthread_cleanup_pop(0); +} + +void pthreadtest(void) +{ pthreadtest_f(); } + +void pthreadtest_(void) +{ pthreadtest_f(); } + +void pthreadtest__(void) +{ pthreadtest_f(); } + +void PTHREADTEST(void) +{ pthreadtest_f(); } + +#ifdef __cplusplus +} +#endif +EOF + +# Try the compile +OPAL_LOG_COMMAND( + [$CC $CFLAGS -I. -c conftest.c], + OPAL_LOG_COMMAND( + [$FC $FCFLAGS conftestf.f conftest.o -o conftest $LDFLAGS $LIBS], + [HAPPY=1], + [HAPPY=0]), + [HAPPY=0]) + +if test "$HAPPY" = "1"; then + $1 +else + OPAL_LOG_MSG([here is the C program:], 1) + OPAL_LOG_FILE([conftest.c]) + if test -f conftest.h; then + OPAL_LOG_MSG([here is contest.h:], 1) + OPAL_LOG_FILE([conftest.h]) + fi + OPAL_LOG_MSG([here is the fortran program:], 1) + OPAL_LOG_FILE([conftestf.f]) + $2 +fi + +unset HAPPY opal_conftest_h +rm -rf conftest* +# END: OPAL_INTL_PTHREAD_TRY_LINK_FORTRAN +])dnl + + +# ******************************************************************** +# +# Try to compile thread support without any special flags +# +# ******************************************************************** +AC_DEFUN([OPAL_INTL_POSIX_THREADS_PLAIN_C], [ +# +# C compiler +# +if test "$opal_pthread_c_success" = "0"; then + AC_MSG_CHECKING([if C compiler and POSIX threads work as is]) + + AC_LANG_PUSH(C) + OPAL_INTL_PTHREAD_TRY_LINK(opal_pthread_c_success=1, + opal_pthread_c_success=0) + AC_LANG_POP(C) + if test "$opal_pthread_c_success" = "1"; then + AC_MSG_RESULT([yes]) + else + AC_MSG_RESULT([no]) + fi +fi +])dnl + + +AC_DEFUN([OPAL_INTL_POSIX_THREADS_PLAIN_CXX], [ +# +# C++ compiler +# +if test "$opal_pthread_cxx_success" = "0"; then + AC_MSG_CHECKING([if C++ compiler and POSIX threads work as is]) + + AC_LANG_PUSH(C++) + OPAL_INTL_PTHREAD_TRY_LINK(opal_pthread_cxx_success=1, + opal_pthread_cxx_success=0) + AC_LANG_POP(C++) + if test "$opal_pthread_cxx_success" = "1"; then + AC_MSG_RESULT([yes]) + else + AC_MSG_RESULT([no]) + fi +fi +])dnl + + +AC_DEFUN([OPAL_INTL_POSIX_THREADS_PLAIN_FC], [ +# +# Fortran compiler +# +if test "$opal_pthread_fortran_success" = "0" && \ + test "$OMPI_TRY_FORTRAN_BINDINGS" -gt "$OMPI_FORTRAN_NO_BINDINGS" && \ + test $ompi_fortran_happy -eq 1; then + AC_MSG_CHECKING([if Fortran compiler and POSIX threads work as is]) + + AC_LANG_PUSH(C) + OPAL_INTL_PTHREAD_TRY_LINK_FORTRAN(opal_pthread_fortran_success=1, + opal_pthread_fortran_success=0) + AC_LANG_POP(C) + if test "$opal_pthread_fortran_success" = "1"; then + AC_MSG_RESULT([yes]) + else + AC_MSG_RESULT([no]) + fi +fi +])dnl + + +AC_DEFUN([OPAL_INTL_POSIX_THREADS_PLAIN], [ +# BEGIN: OPAL_INTL_POSIX_THREADS_PLAIN +# +# Check if can compile without any special flags +# we throw -D_REENTRANT or -D_THREAD_SAFE in here, just in +# case. Some systems (OS X, for example) generally don't need +# the defines, but then will on one system header here or there +# why take chances? +# + +# Only run C++ and Fortran if those compilers already configured +AC_PROVIDE_IFELSE([AC_PROG_CC], + [OPAL_INTL_POSIX_THREADS_PLAIN_C], + [opal_pthread_c_success=1]) + +AC_PROVIDE_IFELSE([AC_PROG_CXX], + [OPAL_INTL_POSIX_THREADS_PLAIN_CXX], + [opal_pthread_cxx_success=1]) + +AC_PROVIDE_IFELSE([AC_PROG_FC], + [OPAL_INTL_POSIX_THREADS_PLAIN_FC], + [opal_pthread_fortran_success=1]) + +# End: OPAL_INTL_POSIX_THREADS_PLAIN +])dnl + + +# ******************************************************************** +# +# Try to compile thread support with special compiler flags +# +# ******************************************************************** +AC_DEFUN([OPAL_INTL_POSIX_THREADS_SPECIAL_FLAGS_C], [ +# +# C compiler +# +if test "$opal_pthread_c_success" = "0"; then + for pf in $pflags; do + AC_MSG_CHECKING([if C compiler and POSIX threads work with $pf]) + CFLAGS="$orig_CFLAGS $pf" + AC_LANG_PUSH(C) + OPAL_INTL_PTHREAD_TRY_LINK(opal_pthread_c_success=1, + opal_pthread_c_success=0) + AC_LANG_POP(C) + if test "$opal_pthread_c_success" = "1"; then + TPKG_CFLAGS="$pf" + AC_MSG_RESULT([yes]) + break + else + TPKG_CFLAGS= + CFLAGS="$orig_CFLAGS" + AC_MSG_RESULT([no]) + fi + done +fi +]) + + +AC_DEFUN([OPAL_INTL_POSIX_THREADS_SPECIAL_FLAGS_CXX], [ +# +# C++ compiler +# +if test "$opal_pthread_cxx_success" = "0"; then + for pf in $pflags; do + AC_MSG_CHECKING([if C++ compiler and POSIX threads work with $pf]) + CXXFLAGS="$orig_CXXFLAGS $pf" + AC_LANG_PUSH(C++) + OPAL_INTL_PTHREAD_TRY_LINK(opal_pthread_cxx_success=1, + opal_pthread_cxx_success=0) + AC_LANG_POP(C++) + if test "$opal_pthread_cxx_success" = "1"; then + TPKG_CXXFLAGS="$pf" + AC_MSG_RESULT([yes]) + break + else + TPKG_CXXFLAGS= + CXXFLAGS="$orig_CXXFLAGS" + AC_MSG_RESULT([no]) + fi + done +fi +]) + + +AC_DEFUN([OPAL_INTL_POSIX_THREADS_SPECIAL_FLAGS_FC], [ +# +# Fortran compiler +# +if test "$opal_pthread_fortran_success" = "0" && \ + test "$OMPI_TRY_FORTRAN_BINDINGS" -gt "$OMPI_FORTRAN_NO_BINDINGS" && \ + test $ompi_fortran_happy -eq 1; then + for pf in $pflags; do + AC_MSG_CHECKING([if Fortran compiler and POSIX threads work with $pf]) + FCFLAGS="$orig_FCFLAGS $pf" + AC_LANG_PUSH(C) + OPAL_INTL_PTHREAD_TRY_LINK_FORTRAN(opal_pthread_fortran_success=1, + opal_pthread_fortran_success=0) + AC_LANG_POP(C) + if test "$opal_pthread_fortran_success" = "1"; then + TPKG_FCFLAGS="$pf" + AC_MSG_RESULT([yes]) + break + else + TPKG_FCFLAGS= + FCFLAGS="$orig_FCFLAGS" + AC_MSG_RESULT([no]) + fi + done +fi +]) + + +AC_DEFUN([OPAL_INTL_POSIX_THREADS_SPECIAL_FLAGS],[ +# Begin: OPAL_INTL_POSIX_THREADS_SPECIAL_FLAGS +# +# If above didn't work, try some super-special compiler flags +# that get evaluated to the "right" things. +# +# -Kthread: +# -kthread: FreeBSD kernel threads +# -pthread: Modern GCC (most all platforms) +# -pthreads: GCC on solaris +# -mthreads: +# -mt: Solaris native compilers / HP-UX aCC +# +# Put -mt before -mthreads because HP-UX aCC will properly compile +# with -mthreads (reading as -mt), but emit a warning about unknown +# flags hreads. Stupid compilers. + +case "${host_cpu}-${host_os}" in + *solaris*) + pflags="-pthread -pthreads -mt" + ;; + *) + pflags="-Kthread -kthread -pthread -pthreads -mt -mthreads" + ;; +esac + +# Only run C++ and Fortran if those compilers already configured +AC_PROVIDE_IFELSE([AC_PROG_CC], + [OPAL_INTL_POSIX_THREADS_SPECIAL_FLAGS_C], + [opal_pthread_c_success=1]) + +AC_PROVIDE_IFELSE([AC_PROG_CXX], + [OPAL_INTL_POSIX_THREADS_SPECIAL_FLAGS_CXX], + [opal_pthread_cxx_success=1]) + +AC_PROVIDE_IFELSE([AC_PROG_FC], + [OPAL_INTL_POSIX_THREADS_SPECIAL_FLAGS_FC], + [opal_pthread_fortran_success=1]) + +# End: OPAL_INTL_POSIX_THREADS_SPECIAL_FLAGS +])dnl + + +# ******************************************************************** +# +# Try to compile thread support with extra libs +# +# ******************************************************************** +AC_DEFUN([OPAL_INTL_POSIX_THREADS_LIBS_C],[ +# +# C compiler +# +if test "$opal_pthread_c_success" = "0"; then + for pl in $plibs; do + AC_MSG_CHECKING([if C compiler and POSIX threads work with $pl]) + case "${host_cpu}-${host-_os}" in + *-aix* | *-freebsd*) + if test "`echo $CPPFLAGS | $GREP 'D_THREAD_SAFE'`" = ""; then + TPKG_CPPFLAGS="-D_THREAD_SAFE" + CPPFLAGS="$CPPFLAGS $TPKG_CPPFLAGS" + fi + ;; + *) + if test "`echo $CPPFLAGS | $GREP 'D_REENTRANT'`" = ""; then + TPKG_CPPFLAGS="-D_REENTRANT" + CPPFLAGS="$CPPFLAGS $TPKG_CPPFLAGS" + fi + ;; + esac + LIBS="$orig_LIBS $pl" + AC_LANG_PUSH(C) + OPAL_INTL_PTHREAD_TRY_LINK(opal_pthread_c_success=1, + opal_pthread_c_success=0) + AC_LANG_POP(C) + if test "$opal_pthread_c_success" = "1"; then + TPKG_LIBS="$pl" + AC_MSG_RESULT([yes]) + else + TPKG_CPPFLAGS= + CPPFLAGS="$orig_CPPFLAGS" + LIBS="$orig_LIBS" + AC_MSG_RESULT([no]) + fi + done +fi +])dnl + + +AC_DEFUN([OPAL_INTL_POSIX_THREADS_LIBS_CXX],[ +# +# C++ compiler +# +if test "$opal_pthread_cxx_success" = "0"; then + if test ! "$opal_pthread_c_success" = "0" && test ! "$TPKG_LIBS" = "" ; then + AC_MSG_CHECKING([if C++ compiler and POSIX threads work with $TPKG_LIBS]) + case "${host_cpu}-${host-_os}" in + *-aix* | *-freebsd*) + if test "`echo $CXXCPPFLAGS | $GREP 'D_THREAD_SAFE'`" = ""; then + TPKG_CXXCPPFLAGS="-D_THREAD_SAFE" + CXXCPPFLAGS="$CXXCPPFLAGS $TPKG_CXXCPPFLAGS" + fi + ;; + *) + if test "`echo $CXXCPPFLAGS | $GREP 'D_REENTRANT'`" = ""; then + TPKG_CXXCPPFLAGS="-D_REENTRANT" + CXXCPPFLAGS="$CXXCPPFLAGS $TPKG_CXXCPPFLAGS" + fi + ;; + esac + LIBS="$orig_LIBS $TPKG_LIBS" + AC_LANG_PUSH(C++) + OPAL_INTL_PTHREAD_TRY_LINK(opal_pthread_cxx_success=1, + opal_pthread_cxx_success=0) + AC_LANG_POP(C++) + if test "$opal_pthread_cxx_success" = "1"; then + AC_MSG_RESULT([yes]) + else + CXXCPPFLAGS="$orig_CXXCPPFLAGS" + LIBS="$orig_LIBS" + AC_MSG_RESULT([no]) + AC_MSG_ERROR([Can not find working threads configuration. aborting]) + fi + else + for pl in $plibs; do + AC_MSG_CHECKING([if C++ compiler and POSIX threads work with $pl]) + case "${host_cpu}-${host-_os}" in + *-aix* | *-freebsd*) + if test "`echo $CXXCPPFLAGS | $GREP 'D_THREAD_SAFE'`" = ""; then + TPKG_CXXCPPFLAGS="-D_THREAD_SAFE" + CXXCPPFLAGS="$CXXCPPFLAGS $TPKG_CXXCPPFLAGS" + fi + ;; + *) + if test "`echo $CXXCPPFLAGS | $GREP 'D_REENTRANT'`" = ""; then + TPKG_CXXCPPFLAGS="-D_REENTRANT" + CXXCPPFLAGS="$CXXCPPFLAGS $TPKG_CXXCPPFLAGS" + fi + ;; + esac + LIBS="$orig_LIBS $pl" + AC_LANG_PUSH(C++) + OPAL_INTL_PTHREAD_TRY_LINK(opal_pthread_cxx_success=1, + opal_pthread_cxx_success=0) + AC_LANG_POP(C++) + if test "$opal_pthread_cxx_success" = "1"; then + TPKG_LIBS="$pl" + AC_MSG_RESULT([yes]) + else + TPKG_CXXCPPFLAGS= + CXXCPPFLAGS="$orig_CXXCPPFLAGS" + LIBS="$orig_LIBS" + AC_MSG_RESULT([no]) + fi + done + fi +fi +])dnl + + +AC_DEFUN([OPAL_INTL_POSIX_THREADS_LIBS_FC],[ +# +# Fortran compiler +# +if test "$opal_pthread_fortran_success" = "0" && \ + test "$OMPI_TRY_FORTRAN_BINDINGS" -gt "$OMPI_FORTRAN_NO_BINDINGS" && \ + test $ompi_fortran_happy -eq 1; then + if test ! "$opal_pthread_c_success" = "0" && test ! "$TPKG_LIBS" = "" ; then + AC_MSG_CHECKING([if Fortran compiler and POSIX threads work with $TPKG_LIBS]) + LIBS="$orig_LIBS $TPKG_LIBS" + AC_LANG_PUSH(C) + OPAL_INTL_PTHREAD_TRY_LINK_FORTRAN(opal_pthread_fortran_success=1, + opal_pthread_fortran_success=0) + AC_LANG_POP(C) + if test "$opal_pthread_fortran_success" = "1"; then + AC_MSG_RESULT([yes]) + else + LIBS="$orig_LIBS" + AC_MSG_RESULT([no]) + AC_MSG_ERROR([Can not find working threads configuration. aborting]) + fi + else + for pl in $plibs; do + AC_MSG_CHECKING([if Fortran compiler and POSIX threads work with $pl]) + LIBS="$orig_LIBS $pl" + AC_LANG_PUSH(C) + OPAL_INTL_PTHREAD_TRY_LINK_FORTRAN(opal_pthread_fortran_success=1, + opal_pthread_fortran_success=0) + AC_LANG_POP(C) + if test "$opal_pthread_fortran_success" = "1"; then + TPKG_LIBS="$pl" + AC_MSG_RESULT([yes]) + break + else + LIBS="$orig_LIBS" + AC_MSG_RESULT([no]) + fi + done + fi +fi +])dnl + + +AC_DEFUN([OPAL_INTL_POSIX_THREADS_LIBS],[ +# Begin: OPAL_INTL_POSIX_THREADS_LIBS +# +# if we can't find a super-special compiler flags, try some libraries. +# we throw -D_REENTRANT or -D_THREAD_SAFE in here, just in case. Some +# systems (OS X, for example) generally don't need the defines, but +# then will on one system header here or there why take chances? +# +# libpthreads: AIX - must check before libpthread +# liblthread: LinuxThreads on FreeBSD +# libpthread: The usual place (like we can define usual!) +plibs="-lpthreads -llthread -lpthread" + +# Only run C++ and Fortran if those compilers already configured +AC_PROVIDE_IFELSE([AC_PROG_CC], + [OPAL_INTL_POSIX_THREADS_LIBS_C], + [opal_pthread_c_success=1]) + +AC_PROVIDE_IFELSE([AC_PROG_CXX], + [OPAL_INTL_POSIX_THREADS_LIBS_CXX], + [opal_pthread_cxx_success=1]) + +AC_PROVIDE_IFELSE([AC_PROG_FC], + [OPAL_INTL_POSIX_THREADS_LIBS_FC], + [opal_pthread_fortran_success=1]) + +# End: OPAL_INTL_POSIX_THREADS_LIBS] +)dnl + + +#******************************************************************** +# +# External macro (aka, the real thing) +# +#******************************************************************** +AC_DEFUN([OPAL_CONFIG_POSIX_THREADS],[ + AC_REQUIRE([AC_PROG_GREP]) + +opal_pthread_c_success=0 +opal_pthread_fortran_success=0 +opal_pthread_cxx_success=0 + +orig_CFLAGS="$CFLAGS" +orig_FCFLAGS="$FCFLAGS" +orig_CXXFLAGS="$CXXFLAGS" +orig_CPPFLAGS="$CPPFLAGS" +orig_CXXCPPFLAGS="$CXXCPPFLAGS" +orig_LDFLAGS="$LDFLAGS" +orig_LIBS="$LIBS" + +TPKG_CFLAGS= +TPKG_FCFLAGS= +TPKG_CXXFLAGS= +TPKG_CPPFLAGS= +TPKG_CXXCPPFLAGS= +TPKG_LDFLAGS= +TPKG_LIBS= + +# Try with the basics, mam. +OPAL_INTL_POSIX_THREADS_PLAIN + +# Try the super-special compiler flags. +OPAL_INTL_POSIX_THREADS_SPECIAL_FLAGS + +# Try the normal linking methods (that's no fun) +OPAL_INTL_POSIX_THREADS_LIBS + +# +# check to see if we can create shared memory mutexes and conditions +# +AC_CHECK_FUNCS([pthread_mutexattr_setpshared pthread_condattr_setpshared]) + +# +# check to see if we can set error checking mutexes +# + +# LinuxThreads +AC_MSG_CHECKING([for PTHREAD_MUTEX_ERRORCHECK_NP]) +AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[#include ]], + [[pthread_mutexattr_settype(NULL, PTHREAD_MUTEX_ERRORCHECK_NP);]])], + [result="yes" defval=1], [result="no" defval=0]) +AC_MSG_RESULT([$result]) +AC_DEFINE_UNQUOTED([OPAL_HAVE_PTHREAD_MUTEX_ERRORCHECK_NP], [$defval], + [If PTHREADS implementation supports PTHREAD_MUTEX_ERRORCHECK_NP]) + +# Mac OS X +AC_MSG_CHECKING([for PTHREAD_MUTEX_ERRORCHECK]) +AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[#include ]], + [[pthread_mutexattr_settype(NULL, PTHREAD_MUTEX_ERRORCHECK);]])], + [result="yes" defval=1], [result="no" defval=0]) +AC_MSG_RESULT([$result]) +AC_DEFINE_UNQUOTED([OPAL_HAVE_PTHREAD_MUTEX_ERRORCHECK], [$defval], + [If PTHREADS implementation supports PTHREAD_MUTEX_ERRORCHECK]) + +CFLAGS="$orig_CFLAGS" +FCFLAGS="$orig_FCFLAGS" +CXXFLAGS="$orig_CXXFLAGS" +CPPFLAGS="$orig_CPPFLAGS" +CXXCPPFLAGS="$orig_CXXCPPFLAGS" +LDFLAGS="$orig_LDFLAGS" +LIBS="$orig_LIBS" + +if test "$OMPI_TRY_FORTRAN_BINDINGS" = "$OMPI_FORTRAN_NO_BINDINGS" || \ + test $ompi_fortran_happy -ne 1; then + opal_pthread_fortran_success=1 +fi + +if test "$opal_pthread_c_success" = "1" && \ + test "$opal_pthread_cxx_success" = "1" && \ + test "$opal_pthread_fortran_success" = "1"; then + internal_useless=1 + $1 +else + internal_useless=1 + $2 +fi + +unset opal_pthread_c_success opal_pthread_fortran_success opal_pthread_cxx_success +unset internal_useless +])dnl + AC_DEFUN([MCA_opal_threads_pthreads_PRIORITY], [30]) AC_DEFUN([MCA_opal_threads_pthreads_COMPILE_MODE], [ @@ -58,3 +710,4 @@ AC_DEFUN([MCA_opal_threads_pthreads_CONFIG],[ [$1], [$2]) ]) + diff --git a/opal/mca/threads/qthreads/configure.m4 b/opal/mca/threads/qthreads/configure.m4 index be32cf87911..4c060111d7a 100644 --- a/opal/mca/threads/qthreads/configure.m4 +++ b/opal/mca/threads/qthreads/configure.m4 @@ -19,6 +19,25 @@ # # $HEADER$ # + +#******************************************************************** +# +# TODO: undoubtedly need some better check than this +# +#******************************************************************** +AC_DEFUN([OPAL_CONFIG_QTHREADS],[ + + AC_CHECK_HEADERS([mach/mach_time.h], + [AC_CHECK_FUNC([mach_absolute_time], + [threads_qthreads_happy="yes"], + [threads_qthreads_happy="no"])], + [threads_qthreads_happy="no"]) + + AS_IF([test "$threads_qthreads_happy" = "yes"], + [$1], + [$2]) +])dnl + AC_DEFUN([MCA_opal_threads_qthreads_PRIORITY], [30]) AC_DEFUN([MCA_opal_threads_qthreads_COMPILE_MODE], [ From 00f789b9647ea55b2db39c13a8fe2f520d1207dd Mon Sep 17 00:00:00 2001 From: Howard Pritchard Date: Mon, 24 Jun 2019 12:59:02 -0600 Subject: [PATCH 12/17] blow away unneeded header file Signed-off-by: Howard Pritchard --- opal/mca/threads/qthreads/Makefile.am | 1 - opal/mca/threads/qthreads/threads_qthreads.h | 98 ------------------- .../qthreads/threads_qthreads_component.c | 1 - 3 files changed, 100 deletions(-) delete mode 100644 opal/mca/threads/qthreads/threads_qthreads.h diff --git a/opal/mca/threads/qthreads/Makefile.am b/opal/mca/threads/qthreads/Makefile.am index d9a893a880f..9412c63e53c 100644 --- a/opal/mca/threads/qthreads/Makefile.am +++ b/opal/mca/threads/qthreads/Makefile.am @@ -20,7 +20,6 @@ noinst_LTLIBRARIES = libmca_threads_qthreads.la libmca_threads_qthreads_la_SOURCES = \ - threads_qthreads.h \ threads_qthreads_component.c \ threads_qthreads_mutex.c \ threads_qthreads_condition.c \ diff --git a/opal/mca/threads/qthreads/threads_qthreads.h b/opal/mca/threads/qthreads/threads_qthreads.h deleted file mode 100644 index 67a5adbcf44..00000000000 --- a/opal/mca/threads/qthreads/threads_qthreads.h +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana - * University Research and Technology - * Corporation. All rights reserved. - * Copyright (c) 2004-2014 The University of Tennessee and The University - * of Tennessee Research Foundation. All rights - * reserved. - * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, - * University of Stuttgart. All rights reserved. - * Copyright (c) 2004-2005 The Regents of the University of California. - * All rights reserved. - * Copyright (c) 2019 Triad National Security, LLC. All rights - * reserved. - * $COPYRIGHT$ - * - * Additional copyrights may follow - * - * $HEADER$ - */ - -#ifndef OPAL_MCA_THREADS_DARWIN_TIMER_DARWIN_H -#define OPAL_MCA_THREADS_DARWIN_TIMER_DARWIN_H - -#include "opal_config.h" -#include - -typedef uint64_t opal_threadss_t; - -/* frequency in mhz */ -OPAL_DECLSPEC extern opal_threadss_t opal_threadss_darwin_freq; -OPAL_DECLSPEC extern mach_timebase_info_data_t opal_threadss_darwin_info; -OPAL_DECLSPEC extern opal_threadss_t opal_threadss_darwin_bias; - -/** - * Use the pragmatic solution proposed at - * http://stackoverflow.com/questions/23378063/how-can-i-use-mach-absolute-time-without-overflowing/23378064#23378064 - */ -static inline opal_threadss_t -opal_threadss_base_get_cycles(void) -{ - uint64_t now = mach_absolute_time(); - - if( opal_threadss_darwin_info.denom == 0 ) { - (void)mach_timebase_info(&opal_threadss_darwin_info); - if( opal_threadss_darwin_info.denom > 1024 ) { - double frac = (double)opal_threadss_darwin_info.numer/opal_threadss_darwin_info.denom; - opal_threadss_darwin_info.denom = 1024; - opal_threadss_darwin_info.numer = opal_threadss_darwin_info.denom * frac + 0.5; - } - opal_threadss_darwin_bias = now; - } - /* this is basically a wrapper around the "right" assembly to convert - the tick counter off the PowerPC Time Base into nanos. */ - return (now - opal_threadss_darwin_bias) * opal_threadss_darwin_info.numer / opal_threadss_darwin_info.denom; -} - - -static inline opal_threadss_t -opal_threadss_base_get_usec(void) -{ - /* freq is in Hz, so this gives usec */ - return opal_threadss_base_get_cycles() / 1000; -} - - -static inline opal_threadss_t -opal_threadss_base_get_freq(void) -{ - return opal_threadss_darwin_freq; -} - -typedef pthread_key_t opal_tsd_key_t; - -static inline int -opal_tsd_key_delete(opal_tsd_key_t key) -{ - return pthread_key_delete(key); -} - -static inline int -opal_tsd_setspecific(opal_tsd_key_t key, void *value) -{ - return pthread_setspecific(key, value); -} - -static inline int -opal_tsd_getspecific(opal_tsd_key_t key, void **valuep) -{ - *valuep = pthread_getspecific(key); - return OPAL_SUCCESS; -} - -#define OPAL_TIMER_CYCLE_NATIVE 0 -#define OPAL_TIMER_CYCLE_SUPPORTED 1 -#define OPAL_TIMER_USEC_NATIVE 1 -#define OPAL_TIMER_USEC_SUPPORTED 1 - -#endif /* OPAL_MCA_THREADS_DARWIN_TIMER_DARWIN_H */ diff --git a/opal/mca/threads/qthreads/threads_qthreads_component.c b/opal/mca/threads/qthreads/threads_qthreads_component.c index d8be5d0e7fd..72009c2c4c4 100644 --- a/opal/mca/threads/qthreads/threads_qthreads_component.c +++ b/opal/mca/threads/qthreads/threads_qthreads_component.c @@ -23,7 +23,6 @@ #include "opal/mca/threads/thread.h" #include "opal/mca/threads/threads.h" -#include "opal/mca/threads/qthreads/threads_qthreads.h" #include "opal/constants.h" static int opal_threads_qthreads_open(void); From 252637bf4d9cf0ba4b64784a56b0a45a60ba546e Mon Sep 17 00:00:00 2001 From: Howard Pritchard Date: Tue, 8 Oct 2019 11:54:20 -0700 Subject: [PATCH 13/17] address some feedback from PR reviews Signed-off-by: Howard Pritchard --- opal/mca/threads/README | 43 ++++++++++++++ opal/mca/threads/argobots/owner.txt | 2 +- opal/mca/threads/argobots/threads_argobots.h | 24 ++++++++ .../threads/argobots/threads_argobots_event.c | 10 ++++ .../argobots/threads_argobots_module.c | 4 +- .../threads/argobots/threads_argobots_mutex.c | 5 +- .../threads/argobots/threads_argobots_mutex.h | 37 ++++-------- .../argobots/threads_argobots_threads.h | 24 ++++++++ .../threads/argobots/threads_argobots_tsd.h | 25 +++++++++ .../argobots/threads_argobots_wait_sync.h | 25 +++++++++ opal/mca/threads/pthreads/configure.m4 | 1 + opal/mca/threads/pthreads/owner.txt | 2 +- .../pthreads/threads_pthreads_module.c | 12 +++- .../pthreads/threads_pthreads_threads.h | 25 +++++++++ .../threads/pthreads/threads_pthreads_tsd.h | 25 +++++++++ .../pthreads/threads_pthreads_wait_sync.h | 25 +++++++++ opal/mca/threads/qthreads/Makefile.am | 2 + opal/mca/threads/qthreads/configure.m4 | 5 -- opal/mca/threads/qthreads/owner.txt | 2 +- .../qthreads/threads_qthreads_component.c | 9 +++ .../qthreads/threads_qthreads_condition.c | 7 +++ .../qthreads/threads_qthreads_module.c | 56 +++++++------------ opal/runtime/opal_init.c | 2 +- 23 files changed, 293 insertions(+), 79 deletions(-) create mode 100644 opal/mca/threads/README diff --git a/opal/mca/threads/README b/opal/mca/threads/README new file mode 100644 index 00000000000..f09509a604f --- /dev/null +++ b/opal/mca/threads/README @@ -0,0 +1,43 @@ + +MCA THREADING FRAMEWORKS: +------------------------- +This MCA framework makes it possible to integrate new threading frameworks with the OpenMPI runtime. + +BACKGROUND +---------- +There has been a lot of interest in integrating alternative threading models, in particular lightweight threading models with MPI implementations. Open MPI's modular component architecture seems like an ideal architecture for this sort of integration (in fact it was, Open MPI used to support Solaris and Windows threads). + +Recently there has been interest in integrating MPI with lightweight tasking layers, which led to work reviving and modernizing the old modular threading code but with an emphasis on integrating lightweight threading models. + +SELECTING A THREADING MODEL +--------------------------- + +The threading model is chosen via the configure option --with-threads=. This will choose a compile time threading model as well as compiling the relevant MCA. + +IMPLEMENTATION +-------------- +The MCA for threading libraries is implemented in two places, once as a set of .h files in mca/threads//threads__{threads,mutex,tsd}.h which are defined inline to the main thread implementation and also as an mca component that is loaded at runtime. + +For performance reasons, in particular synchonization overhead, it is not possible to implement a threading model as a traditional MCA. This means --at least in the short term-- that threading models are chosen at compile time rather than runtime options, using mechanisms similar to OpenMPI's libevent integration. + +The .h files are meant to be run on the fast path containing inline synchonization functions (threads__mutex.h, thread local storage (threads__tsd.h) and the opal_thread structure (threads__thread.h). + +The rest of the threading implementation follows the normal MCA model: + +* threads__component.c describes the version of the module and specifies the module open behavior (the threading model initialization goes here). + +* threads__condition.c defines an instance of opal_condition_t which is used by condition.h to define Open MPI specific condition variables. + +* threads__event.c defines an interface to Open MPI's libevent hooks. It allows the threading module to use threading model specific memory allocation and synchronization structures with Open MPI's libevent integration. + +* threads__module.c defines the interface to opal's thread handle. It provides ways of comparing threads, getting the value of a thread via its handle and the implementation of thread local storage. + +* threads__mutex.c provides a slow path interface to creating and destroying mutices dynamically via mca allocation. They can also be defined statically using the .h fast path interface. + +* threads__wait_sync.c provides condition variable like waiting capability that ensures MPI progress while it waits. + +TODO +---- +Libevent integration with lightweight threading models is a work in progress. The current Open MPI libevent library assumes preemption and does not yield by default. Lightweight threading libraries typically require tasks to be cooperative and to voluntarily yield after some time. + +Open MPI itself needs to be altered to use a common yielding model instead of usleep(3). diff --git a/opal/mca/threads/argobots/owner.txt b/opal/mca/threads/argobots/owner.txt index 199577ac8cf..1cd89be1e87 100644 --- a/opal/mca/threads/argobots/owner.txt +++ b/opal/mca/threads/argobots/owner.txt @@ -4,4 +4,4 @@ # status: e.g. active, maintenance, unmaintained # owner: SNL -status: unmaintained +status: active diff --git a/opal/mca/threads/argobots/threads_argobots.h b/opal/mca/threads/argobots/threads_argobots.h index 133fa81582a..5dfa18647cb 100644 --- a/opal/mca/threads/argobots/threads_argobots.h +++ b/opal/mca/threads/argobots/threads_argobots.h @@ -1,3 +1,27 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ +/* + * 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. + * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, + * University of Stuttgart. All rights reserved. + * Copyright (c) 2004-2005 The Regents of the University of California. + * All rights reserved. + * Copyright (c) 2007-2016 Los Alamos National Security, LLC. All rights + * reserved. + * Copyright (c) 2015 Research Organization for Information Science + * and Technology (RIST). All rights reserved. + * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. + * + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ #ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_H #define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_H 1 diff --git a/opal/mca/threads/argobots/threads_argobots_event.c b/opal/mca/threads/argobots/threads_argobots_event.c index c9c9fd98baf..7f3dc5df99f 100644 --- a/opal/mca/threads/argobots/threads_argobots_event.c +++ b/opal/mca/threads/argobots/threads_argobots_event.c @@ -1,3 +1,13 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ +/* + * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. + * + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ #include "opal/mca/threads/threads.h" #include "opal/mca/threads/argobots/threads_argobots.h" diff --git a/opal/mca/threads/argobots/threads_argobots_module.c b/opal/mca/threads/argobots/threads_argobots_module.c index 8587ab0e3e1..5dc95348808 100644 --- a/opal/mca/threads/argobots/threads_argobots_module.c +++ b/opal/mca/threads/argobots/threads_argobots_module.c @@ -9,6 +9,8 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. + * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. + * * $COPYRIGHT$ * * Additional copyrights may follow @@ -122,7 +124,7 @@ int opal_tsd_key_create(opal_tsd_key_t *key, opal_tsd_destructor_t destructor) return rc; } -int opal_tsd_keys_destruct() +int opal_tsd_keys_destruct(void) { ensure_init_argobots(); int i; diff --git a/opal/mca/threads/argobots/threads_argobots_mutex.c b/opal/mca/threads/argobots/threads_argobots_mutex.c index d93bb00ce01..159184ee815 100644 --- a/opal/mca/threads/argobots/threads_argobots_mutex.c +++ b/opal/mca/threads/argobots/threads_argobots_mutex.c @@ -27,7 +27,6 @@ #include "opal_config.h" #include -#include #include "opal/mca/threads/mutex.h" #include "opal/mca/threads/argobots/threads_argobots_mutex.h" @@ -52,7 +51,7 @@ static void mca_threads_argobots_mutex_constructor(opal_mutex_t *p_mutex) { static void mca_threads_argobots_mutex_desctructor(opal_mutex_t *p_mutex) { ensure_init_argobots(); - if (p_mutex->m_lock_argobots != OPAL_ABT_MUTEX_NULL) + if (OPAL_ABT_MUTX_NULL != p_mutex->m_lock_argobots) ABT_mutex_free(&p_mutex->m_lock_argobots); } @@ -72,7 +71,7 @@ static void mca_threads_argobots_recursive_mutex_constructor static void mca_threads_argobots_recursive_mutex_desctructor (opal_recursive_mutex_t *p_mutex) { ensure_init_argobots(); - if (p_mutex->m_lock_argobots != OPAL_ABT_MUTEX_NULL) + if (OPAL_ABT_MUTEX_NULL != p_mutex->m_lock_argobots) ABT_mutex_free(&p_mutex->m_lock_argobots); } diff --git a/opal/mca/threads/argobots/threads_argobots_mutex.h b/opal/mca/threads/argobots/threads_argobots_mutex.h index 72da868f0a6..e0c41f5398d 100644 --- a/opal/mca/threads/argobots/threads_argobots_mutex.h +++ b/opal/mca/threads/argobots/threads_argobots_mutex.h @@ -68,8 +68,7 @@ struct opal_mutex_t { opal_atomic_lock_t m_lock_atomic; }; -typedef struct opal_argobots_mutex_t opal_pthread_mutex_t; -typedef struct opal_argobots_mutex_t opal_pthread_recursive_mutex_t; +typedef struct opal_argobots_mutex_t int; OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_mutex_t); OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_recursive_mutex_t); @@ -95,29 +94,13 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_recursive_mutex_t); } #endif -#if defined(OPAL_PTHREAD_RECURSIVE_MUTEX_INITIALIZER) - -#if OPAL_ENABLE_DEBUG #define OPAL_RECURSIVE_MUTEX_STATIC_INIT \ { \ .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), \ .m_lock_argobots = OPAL_ABT_MUTEX_NULL, \ .m_recursive = 1, \ - .m_lock_debug = 0, \ - .m_lock_file = NULL, \ - .m_lock_line = 0, \ .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \ } -#else -#define OPAL_RECURSIVE_MUTEX_STATIC_INIT \ - { \ - .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), \ - .m_lock_argobots = OPAL_ABT_MUTEX_NULL, \ - .m_recursive = 1, \ - .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \ - } -#endif - #endif /************************************************************************ @@ -127,7 +110,7 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_recursive_mutex_t); ************************************************************************/ static inline void opal_mutex_create(struct opal_mutex_t *m) { - while (m->m_lock_argobots == OPAL_ABT_MUTEX_NULL) { + while (OPAL_ABT_MUTEX_NULL == m->m_lock_argobots) { ABT_mutex abt_mutex; if (m->m_recursive) { ABT_mutex_attr abt_mutex_attr; @@ -152,7 +135,7 @@ static inline void opal_mutex_create(struct opal_mutex_t *m) { static inline int opal_mutex_trylock(opal_mutex_t *m) { ensure_init_argobots(); - if (m->m_lock_argobots == OPAL_ABT_MUTEX_NULL) + if (OPAL_ABT_MUTEX_NULL == m->m_lock_argobots) opal_mutex_create(m); #if OPAL_ENABLE_DEBUG int ret = ABT_mutex_trylock(m->m_lock_argobots); @@ -170,7 +153,7 @@ static inline int opal_mutex_trylock(opal_mutex_t *m) static inline void opal_mutex_lock(opal_mutex_t *m) { ensure_init_argobots(); - if (m->m_lock_argobots == OPAL_ABT_MUTEX_NULL) + if (OPAL_ABT_MUTEX_NULL == m->m_lock_argobots) opal_mutex_create(m); #if OPAL_ENABLE_DEBUG int ret = ABT_mutex_lock(m->m_lock_argobots); @@ -187,7 +170,7 @@ static inline void opal_mutex_lock(opal_mutex_t *m) static inline void opal_mutex_unlock(opal_mutex_t *m) { ensure_init_argobots(); - if (m->m_lock_argobots == OPAL_ABT_MUTEX_NULL) + if (OPAL_ABT_MUTEX_NULL == m->m_lock_argobots) opal_mutex_create(m); #if OPAL_ENABLE_DEBUG int ret = ABT_mutex_unlock(m->m_lock_argobots); @@ -259,7 +242,7 @@ typedef ABT_cond opal_cond_t; static inline void opal_cond_create(opal_cond_t *cond) { ensure_init_argobots(); - while (*cond == OPAL_ABT_COND_NULL) { + while (OPAL_ABT_COND_NULL == *cond) { ABT_cond new_cond; ABT_cond_create(&new_cond); void *null_ptr = OPAL_ABT_COND_NULL; @@ -280,28 +263,28 @@ static inline int opal_cond_init(opal_cond_t *cond) { static inline int opal_cond_wait(opal_cond_t *cond, opal_mutex_t *lock) { ensure_init_argobots(); - if (*cond == OPAL_ABT_COND_NULL) + if (OPAL_ABT_COND_NULL == *cond) opal_cond_create(cond); return ABT_cond_wait(*cond, lock->m_lock_argobots); } static inline int opal_cond_broadcast(opal_cond_t *cond) { ensure_init_argobots(); - if (*cond == OPAL_ABT_COND_NULL) + if (OPAL_ABT_COND_NULL == *cond) opal_cond_create(cond); return ABT_cond_broadcast(*cond); } static inline int opal_cond_signal(opal_cond_t *cond) { ensure_init_argobots(); - if (*cond == OPAL_ABT_COND_NULL) + if (OPAL_ABT_COND_NULL == *cond) opal_cond_create(cond); return ABT_cond_signal(*cond); } static inline int opal_cond_destroy(opal_cond_t *cond) { ensure_init_argobots(); - if (*cond != OPAL_ABT_COND_NULL) + if (OPAL_ABT_COND_NULL != *cond) ABT_cond_free(cond); return 0; } diff --git a/opal/mca/threads/argobots/threads_argobots_threads.h b/opal/mca/threads/argobots/threads_argobots_threads.h index 5a7d7a772c7..78e09767fb2 100644 --- a/opal/mca/threads/argobots/threads_argobots_threads.h +++ b/opal/mca/threads/argobots/threads_argobots_threads.h @@ -1,3 +1,27 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ +/* + * 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. + * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, + * University of Stuttgart. All rights reserved. + * Copyright (c) 2004-2005 The Regents of the University of California. + * All rights reserved. + * Copyright (c) 2007-2016 Los Alamos National Security, LLC. All rights + * reserved. + * Copyright (c) 2015 Research Organization for Information Science + * and Technology (RIST). All rights reserved. + * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. + * + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ #ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_THREADS_H #define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_THREADS_H 1 diff --git a/opal/mca/threads/argobots/threads_argobots_tsd.h b/opal/mca/threads/argobots/threads_argobots_tsd.h index 290adadfde3..7582724db8a 100644 --- a/opal/mca/threads/argobots/threads_argobots_tsd.h +++ b/opal/mca/threads/argobots/threads_argobots_tsd.h @@ -1,3 +1,28 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ +/* + * 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. + * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, + * University of Stuttgart. All rights reserved. + * Copyright (c) 2004-2005 The Regents of the University of California. + * All rights reserved. + * Copyright (c) 2007-2016 Los Alamos National Security, LLC. All rights + * reserved. + * Copyright (c) 2015 Research Organization for Information Science + * and Technology (RIST). All rights reserved. + * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. + * + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + #ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_TSD_H #define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_TSD_H 1 diff --git a/opal/mca/threads/argobots/threads_argobots_wait_sync.h b/opal/mca/threads/argobots/threads_argobots_wait_sync.h index dbe443db550..b9d5041294f 100644 --- a/opal/mca/threads/argobots/threads_argobots_wait_sync.h +++ b/opal/mca/threads/argobots/threads_argobots_wait_sync.h @@ -1,3 +1,28 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ +/* + * 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. + * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, + * University of Stuttgart. All rights reserved. + * Copyright (c) 2004-2005 The Regents of the University of California. + * All rights reserved. + * Copyright (c) 2007-2016 Los Alamos National Security, LLC. All rights + * reserved. + * Copyright (c) 2015 Research Organization for Information Science + * and Technology (RIST). All rights reserved. + * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. + * + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + #ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_WAIT_SYNC_H #define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_WAIT_SYNC_H 1 diff --git a/opal/mca/threads/pthreads/configure.m4 b/opal/mca/threads/pthreads/configure.m4 index 7b50a4e82fd..63bedf6da5f 100644 --- a/opal/mca/threads/pthreads/configure.m4 +++ b/opal/mca/threads/pthreads/configure.m4 @@ -15,6 +15,7 @@ # and Technology (RIST). All rights reserved. # Copyright (c) 2019 Sandia National Laboratories. All rights reserved. # Copyright (c) 2019 Triad National Security, LLC. All rights +# reserved. # $COPYRIGHT$ # # Additional copyrights may follow diff --git a/opal/mca/threads/pthreads/owner.txt b/opal/mca/threads/pthreads/owner.txt index 199577ac8cf..1cd89be1e87 100644 --- a/opal/mca/threads/pthreads/owner.txt +++ b/opal/mca/threads/pthreads/owner.txt @@ -4,4 +4,4 @@ # status: e.g. active, maintenance, unmaintained # owner: SNL -status: unmaintained +status: active diff --git a/opal/mca/threads/pthreads/threads_pthreads_module.c b/opal/mca/threads/pthreads/threads_pthreads_module.c index 7d2ae55965a..a6a7483122e 100644 --- a/opal/mca/threads/pthreads/threads_pthreads_module.c +++ b/opal/mca/threads/pthreads/threads_pthreads_module.c @@ -1,20 +1,28 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ /* * 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 + * Copyright (c) 2004-2006 The University of Tennessee and The University * of Tennessee Research Foundation. All rights * reserved. * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. + * Copyright (c) 2007-2018 Los Alamos National Security, LLC. All rights + * reserved. + * Copyright (c) 2015-2016 Research Organization for Information Science + * and Technology (RIST). All rights reserved. + * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. + * * $COPYRIGHT$ * * Additional copyrights may follow * * $HEADER$ */ + #include #include "opal/constants.h" @@ -99,7 +107,7 @@ int opal_tsd_key_create(opal_tsd_key_t *key, opal_tsd_destructor_t destructor) return rc; } -int opal_tsd_keys_destruct() +int opal_tsd_keys_destruct(void) { int i; void * ptr; diff --git a/opal/mca/threads/pthreads/threads_pthreads_threads.h b/opal/mca/threads/pthreads/threads_pthreads_threads.h index ed0166e4dab..45e5e8f87ed 100644 --- a/opal/mca/threads/pthreads/threads_pthreads_threads.h +++ b/opal/mca/threads/pthreads/threads_pthreads_threads.h @@ -1,3 +1,28 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ +/* + * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana + * University Research and Technology + * Corporation. All rights reserved. + * Copyright (c) 2004-2006 The University of Tennessee and The University + * of Tennessee Research Foundation. All rights + * reserved. + * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, + * University of Stuttgart. All rights reserved. + * Copyright (c) 2004-2005 The Regents of the University of California. + * All rights reserved. + * Copyright (c) 2007-2018 Los Alamos National Security, LLC. All rights + * reserved. + * Copyright (c) 2015-2016 Research Organization for Information Science + * and Technology (RIST). All rights reserved. + * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. + * + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + #ifndef OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_THREADS_H #define OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_THREADS_H 1 diff --git a/opal/mca/threads/pthreads/threads_pthreads_tsd.h b/opal/mca/threads/pthreads/threads_pthreads_tsd.h index f3696f7df3d..001d20aa042 100644 --- a/opal/mca/threads/pthreads/threads_pthreads_tsd.h +++ b/opal/mca/threads/pthreads/threads_pthreads_tsd.h @@ -1,3 +1,28 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ +/* + * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana + * University Research and Technology + * Corporation. All rights reserved. + * Copyright (c) 2004-2006 The University of Tennessee and The University + * of Tennessee Research Foundation. All rights + * reserved. + * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, + * University of Stuttgart. All rights reserved. + * Copyright (c) 2004-2005 The Regents of the University of California. + * All rights reserved. + * Copyright (c) 2007-2018 Los Alamos National Security, LLC. All rights + * reserved. + * Copyright (c) 2015-2016 Research Organization for Information Science + * and Technology (RIST). All rights reserved. + * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. + * + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + #ifndef OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_TSD_H #define OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_TSD_H 1 diff --git a/opal/mca/threads/pthreads/threads_pthreads_wait_sync.h b/opal/mca/threads/pthreads/threads_pthreads_wait_sync.h index 0b43a51fd62..26a1a3927f4 100644 --- a/opal/mca/threads/pthreads/threads_pthreads_wait_sync.h +++ b/opal/mca/threads/pthreads/threads_pthreads_wait_sync.h @@ -1,3 +1,28 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ +/* + * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana + * University Research and Technology + * Corporation. All rights reserved. + * Copyright (c) 2004-2006 The University of Tennessee and The University + * of Tennessee Research Foundation. All rights + * reserved. + * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, + * University of Stuttgart. All rights reserved. + * Copyright (c) 2004-2005 The Regents of the University of California. + * All rights reserved. + * Copyright (c) 2007-2018 Los Alamos National Security, LLC. All rights + * reserved. + * Copyright (c) 2015-2016 Research Organization for Information Science + * and Technology (RIST). All rights reserved. + * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. + * + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + #ifndef OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_WAIT_SYNC_H #define OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_WAIT_SYNC_H 1 diff --git a/opal/mca/threads/qthreads/Makefile.am b/opal/mca/threads/qthreads/Makefile.am index 9412c63e53c..cc0bc2e0aba 100644 --- a/opal/mca/threads/qthreads/Makefile.am +++ b/opal/mca/threads/qthreads/Makefile.am @@ -10,6 +10,8 @@ # Copyright (c) 2004-2005 The Regents of the University of California. # All rights reserved. # Copyright (c) 2008 Cisco Systems, Inc. All rights reserved. +# Copyright (c) 2019 Sandia National Laboratories. All rights reserved. +# # $COPYRIGHT$ # # Additional copyrights may follow diff --git a/opal/mca/threads/qthreads/configure.m4 b/opal/mca/threads/qthreads/configure.m4 index 4c060111d7a..801235fc6cd 100644 --- a/opal/mca/threads/qthreads/configure.m4 +++ b/opal/mca/threads/qthreads/configure.m4 @@ -20,11 +20,6 @@ # $HEADER$ # -#******************************************************************** -# -# TODO: undoubtedly need some better check than this -# -#******************************************************************** AC_DEFUN([OPAL_CONFIG_QTHREADS],[ AC_CHECK_HEADERS([mach/mach_time.h], diff --git a/opal/mca/threads/qthreads/owner.txt b/opal/mca/threads/qthreads/owner.txt index 199577ac8cf..1cd89be1e87 100644 --- a/opal/mca/threads/qthreads/owner.txt +++ b/opal/mca/threads/qthreads/owner.txt @@ -4,4 +4,4 @@ # status: e.g. active, maintenance, unmaintained # owner: SNL -status: unmaintained +status: active diff --git a/opal/mca/threads/qthreads/threads_qthreads_component.c b/opal/mca/threads/qthreads/threads_qthreads_component.c index 72009c2c4c4..86cff6bd762 100644 --- a/opal/mca/threads/qthreads/threads_qthreads_component.c +++ b/opal/mca/threads/qthreads/threads_qthreads_component.c @@ -12,6 +12,15 @@ * All rights reserved. * Copyright (c) 2007-2015 Los Alamos National Security, LLC. All rights * reserved. + * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. + * + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + * $COPYRIGHT$ * * Additional copyrights may follow diff --git a/opal/mca/threads/qthreads/threads_qthreads_condition.c b/opal/mca/threads/qthreads/threads_qthreads_condition.c index bdc8a67f214..f2b8bab4af8 100644 --- a/opal/mca/threads/qthreads/threads_qthreads_condition.c +++ b/opal/mca/threads/qthreads/threads_qthreads_condition.c @@ -1,3 +1,4 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ /* * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana * University Research and Technology @@ -9,6 +10,12 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. + * Copyright (c) 2007-2016 Los Alamos National Security, LLC. All rights + * reserved. + * Copyright (c) 2015 Research Organization for Information Science + * and Technology (RIST). All rights reserved. + * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. + * * $COPYRIGHT$ * * Additional copyrights may follow diff --git a/opal/mca/threads/qthreads/threads_qthreads_module.c b/opal/mca/threads/qthreads/threads_qthreads_module.c index 393948c2ef3..4649447f304 100644 --- a/opal/mca/threads/qthreads/threads_qthreads_module.c +++ b/opal/mca/threads/qthreads/threads_qthreads_module.c @@ -9,12 +9,15 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. + * Copyright (c) 2019 Triad National Security, LLC. All rights + * reserved. * $COPYRIGHT$ * * Additional copyrights may follow * * $HEADER$ */ + #include #include "opal/constants.h" @@ -29,7 +32,7 @@ struct opal_tsd_key_value { opal_tsd_destructor_t destructor; }; -static pthread_t opal_main_thread; +static int opal_main_thread; struct opal_tsd_key_value *opal_tsd_key_values = NULL; static int opal_tsd_key_values_count = 0; @@ -38,8 +41,6 @@ static int opal_tsd_key_values_count = 0; */ static void opal_thread_construct(opal_thread_t *t) { - t->t_run = 0; - t->t_handle = (pthread_t) -1; } OBJ_CLASS_INSTANCE(opal_thread_t, @@ -49,60 +50,41 @@ OBJ_CLASS_INSTANCE(opal_thread_t, opal_thread_t *opal_thread_get_self(void) { - opal_thread_t *t = OBJ_NEW(opal_thread_t); - t->t_handle = pthread_self(); - return t; + return NULL; } bool opal_thread_self_compare(opal_thread_t *t) { - return t->t_handle == pthread_self(); + return OPAL_ERROR; } -int sync_wait_mt(void *p) { - return 0; +int sync_wait_mt(void *p) +{ + return OPAL_ERROR; } -int opal_thread_join(opal_thread_t *t, void **thr_return) { - int rc = pthread_join(t->t_handle, thr_return); - t->t_handle = (pthread_t) -1; - return (rc == 0) ? OPAL_SUCCESS : OPAL_ERROR; +int opal_thread_join(opal_thread_t *t, void **thr_return) +{ + return OPAL_ERROR; } -void opal_thread_set_main() { - opal_main_thread = pthread_self(); +void opal_thread_set_main() +{ } -int opal_thread_start(opal_thread_t *t) { - int rc; - - if (OPAL_ENABLE_DEBUG) { - if (NULL == t->t_run || t->t_handle != (pthread_t) -1) { - return OPAL_ERR_BAD_PARAM; - } - } - - rc = pthread_create(&t->t_handle, NULL, (void*(*)(void*)) t->t_run, t); - - return (rc == 0) ? OPAL_SUCCESS : OPAL_ERROR; +int opal_thread_start(opal_thread_t *t) +{ + return OPAL_ERR_NOT_IMPLEMENTED; } opal_class_t opal_thread_t_class; int opal_tsd_key_create(opal_tsd_key_t *key, opal_tsd_destructor_t destructor) { - int rc; - rc = pthread_key_create(key, destructor); - if ((0 == rc) && (pthread_self() == opal_main_thread)) { - opal_tsd_key_values = (struct opal_tsd_key_value *)realloc(opal_tsd_key_values, (opal_tsd_key_values_count+1) * sizeof(struct opal_tsd_key_value)); - opal_tsd_key_values[opal_tsd_key_values_count].key = *key; - opal_tsd_key_values[opal_tsd_key_values_count].destructor = destructor; - opal_tsd_key_values_count ++; - } - return rc; + return OPAL_ERR_NOT_IMPLEMENTED; } -int opal_tsd_keys_destruct() +int opal_tsd_keys_destruct(void) { int i; void * ptr; diff --git a/opal/runtime/opal_init.c b/opal/runtime/opal_init.c index da93168d676..8b59eb53405 100644 --- a/opal/runtime/opal_init.c +++ b/opal/runtime/opal_init.c @@ -521,7 +521,7 @@ opal_init_util(int* pargc, char*** pargv) * versions of memcpy correctly configured. */ static mca_base_framework_t *opal_init_frameworks[] = { - &opal_hwloc_base_framework, &opal_memcpy_base_framework, &opal_threads_base_framework, &opal_memchecker_base_framework, + &opal_threads_base_framework, &opal_hwloc_base_framework, &opal_memcpy_base_framework, &opal_memchecker_base_framework, &opal_backtrace_base_framework, &opal_timer_base_framework, &opal_event_base_framework, &opal_shmem_base_framework, &opal_reachable_base_framework, &opal_compress_base_framework, NULL, From 80503e5ab1b3be2ca7db1b9081af92a12a8fd9ce Mon Sep 17 00:00:00 2001 From: Howard Pritchard Date: Fri, 11 Oct 2019 14:58:36 -0600 Subject: [PATCH 14/17] initial rework of threads mca configury Signed-off-by: Howard Pritchard --- opal/mca/threads/configure.m4 | 140 ---------------------------------- 1 file changed, 140 deletions(-) delete mode 100644 opal/mca/threads/configure.m4 diff --git a/opal/mca/threads/configure.m4 b/opal/mca/threads/configure.m4 deleted file mode 100644 index b3635c4dc20..00000000000 --- a/opal/mca/threads/configure.m4 +++ /dev/null @@ -1,140 +0,0 @@ -dnl -*- shell-script -*- -dnl -dnl Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana -dnl University Research and Technology -dnl Corporation. All rights reserved. -dnl Copyright (c) 2004-2005 The University of Tennessee and The University -dnl of Tennessee Research Foundation. All rights -dnl reserved. -dnl Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, -dnl University of Stuttgart. All rights reserved. -dnl Copyright (c) 2004-2005 The Regents of the University of California. -dnl All rights reserved. -dnl Copyright (c) 2010 Cisco Systems, Inc. All rights reserved. -dnl Copyright (c) 2019 Sandia National Laboratories. All rights reserved. -dnl $COPYRIGHT$ -dnl -dnl Additional copyrights may follow -dnl -dnl $HEADER$ -dnl - - -AC_DEFUN([OPAL_CONFIG_THREADS],[ -# -# Arguments: none -# -# Dependencies: None -# -# Modifies: -# none - see called tests -# -# configure threads -# - -# -# First see what kind of threads we are going to use -# - -AC_ARG_WITH([threads], - [AC_HELP_STRING([--with-threads=TYPE], - [Specify thread TYPE to use. default:pthreads. Other options are qthreads and argobots.])]) - -# -# Check we for the thread package requested, or posix -# - -thread_type_found= - -# -# check for posix threads -# -AS_IF([test -z "$with_threads" || test "$with_threads" = "pthreads" || test "$with_threads" = "yes"], - [OPAL_CONFIG_POSIX_THREADS(HAVE_THREAD_PKG=1, HAVE_THREAD_PKG=0) - AC_MSG_CHECKING([for working POSIX threads package]) - AS_IF([test "$HAVE_THREAD_PKG" = "1"], - [AC_MSG_RESULT([yes]) - thread_type_found="pthreads"], - [AC_MSG_RESULT([no])])], - []) - -# -# see if argobots is called for -# -AS_IF([test -z "$thread_type_found" && test "$with_threads" = "argobots"], - [OPAL_CONFIG_ARGOBOTS_THREADS(HAVE_THREAD_PKG=1, HAVE_THREAD_PKG=0) - AC_MSG_CHECKING([for working ARGOBOTS threads package]) - AS_IF([test "$HAVE_THREAD_PKG" = "1"], - [AC_MSG_RESULT([yes]) - thread_type_found="argobots"], - [AC_MSG_RESULT([no])])], - []) - -AS_IF([test -z "$thread_type_found" && test "$with_threads" = "qthreads"], - [OPAL_CONFIG_QTHREADS(HAVE_THREAD_PKG=1, HAVE_THREAD_PKG=0) - AC_MSG_CHECKING([for working Qthreads package]) - AS_IF([test "$HAVE_THREAD_PKG" = "1"], - [AC_MSG_RESULT([yes]) - thread_type_found="qthreads"], - [AC_MSG_RESULT([no])])], - []) - -# -# Bail if we didn't find any thread package -# - -AS_IF([test -z "$thread_type_found"], - [AC_MSG_WARN([*** no thread package $with_threads]) - AC_MSG_WARN([*** available on your system]) - AC_MSG_ERROR([*** Can not continue])]) - -THREAD_CFLAGS="$TPKG_CFLAGS" -THREAD_FCFLAGS="$TPKG_FCFLAGS" -THREAD_CXXFLAGS="$TPKG_CXXFLAGS" -THREAD_CPPFLAGS="$TPKG_CPPFLAGS" -THREAD_CXXCPPFLAGS="$TPKG_CXXCPPFLAGS" -THREAD_LDFLAGS="$TPKG_LDFLAGS" -THREAD_LIBS="$TPKG_LIBS" -HAVE_THREAD_PKG_TYPE="$thread_type_found" -export HAVE_THREAD_PKG_TYPE - -AS_IF([test "$thread_type_found" = "pthreads"], - [OPAL_CHECK_PTHREAD_PIDS],[]) - -OPAL_SUMMARY_ADD([[Miscellaneous]],[[Threading Package]],[opal_threads], [$thread_type_found]) -])dnl - -dnl we only want one :) -m4_define(MCA_opal_threads_CONFIGURE_MODE, STOP_AT_FIRST) - -AC_DEFINE_UNQUOTED([OPAL_ENABLE_MULTI_THREADS], [1], - [Whether we should enable thread support within the OPAL code base]) -AC_DEFUN([MCA_opal_threads_CONFIG],[ - thread_type=$HAVE_THREAD_PKG_TYPE - threads_base_include= - mutex_base_include= - - # first, compile all the components - MCA_CONFIGURE_FRAMEWORK($1, $2, 1) - - threads_base_include="${thread_type}/threads_${thread_type}_threads.h" - mutex_base_include="${thread_type}/threads_${thread_type}_mutex.h" - tsd_base_include="${thread_type}/threads_${thread_type}_tsd.h" - wait_sync_base_include="${thread_type}/threads_${thread_type}_wait_sync.h" - - AC_DEFINE_UNQUOTED([MCA_threads_base_include_HEADER], - ["opal/mca/threads/$threads_base_include"], - [Header to include for threads implementation]) - - AC_DEFINE_UNQUOTED([MCA_threads_mutex_base_include_HEADER], - ["opal/mca/threads/$mutex_base_include"], - [Header to include for mutex implementation]) - - AC_DEFINE_UNQUOTED([MCA_threads_tsd_base_include_HEADER], - ["opal/mca/threads/$tsd_base_include"], - [Header to include for tsd implementation]) - - AC_DEFINE_UNQUOTED([MCA_threads_wait_sync_base_include_HEADER], - ["opal/mca/threads/$wait_sync_base_include"], - [Header to include for wait_sync implementation]) -]) From cbf5ba0dd43b8b9b137d7c1fb863c2e531893b35 Mon Sep 17 00:00:00 2001 From: Shintaro Iwasaki Date: Thu, 31 Oct 2019 14:46:37 -0500 Subject: [PATCH 15/17] /opal/mca/threads: clean up Signed-off-by: Shintaro Iwasaki --- opal/mca/threads/argobots/threads_argobots.h | 12 +- .../argobots/threads_argobots_component.c | 4 +- .../argobots/threads_argobots_condition.c | 3 +- .../threads/argobots/threads_argobots_event.c | 45 +++--- .../argobots/threads_argobots_module.c | 57 +++++--- .../threads/argobots/threads_argobots_mutex.c | 26 ++-- .../threads/argobots/threads_argobots_mutex.h | 77 +++++----- .../argobots/threads_argobots_threads.h | 8 +- .../threads/argobots/threads_argobots_tsd.h | 19 ++- .../argobots/threads_argobots_wait_sync.c | 38 ++--- .../argobots/threads_argobots_wait_sync.h | 28 ++-- opal/mca/threads/base/base.h | 9 +- opal/mca/threads/base/threads_base_open.c | 8 +- opal/mca/threads/condition.h | 40 +++--- opal/mca/threads/mutex.h | 48 +++---- .../pthreads/threads_pthreads_component.c | 2 +- .../pthreads/threads_pthreads_condition.c | 1 + .../pthreads/threads_pthreads_module.c | 40 +++--- .../threads/pthreads/threads_pthreads_mutex.c | 12 +- .../threads/pthreads/threads_pthreads_mutex.h | 20 +-- .../pthreads/threads_pthreads_threads.h | 6 +- .../threads/pthreads/threads_pthreads_tsd.h | 13 +- .../pthreads/threads_pthreads_wait_sync.c | 44 +++--- .../pthreads/threads_pthreads_wait_sync.h | 22 +-- .../qthreads/threads_qthreads_component.c | 9 +- .../qthreads/threads_qthreads_module.c | 25 +--- .../threads/qthreads/threads_qthreads_mutex.c | 47 +----- opal/mca/threads/thread.h | 9 +- opal/mca/threads/thread_usage.h | 135 ++++++++++-------- opal/mca/threads/threads.h | 24 ++-- opal/mca/threads/tsd.h | 3 +- opal/mca/threads/wait_sync.h | 20 +-- 32 files changed, 425 insertions(+), 429 deletions(-) diff --git a/opal/mca/threads/argobots/threads_argobots.h b/opal/mca/threads/argobots/threads_argobots.h index 5dfa18647cb..75f80cb301d 100644 --- a/opal/mca/threads/argobots/threads_argobots.h +++ b/opal/mca/threads/argobots/threads_argobots.h @@ -23,14 +23,16 @@ * $HEADER$ */ -#ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_H -#define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_H 1 +#ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_H +#define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_H #include -static inline void ensure_init_argobots(void) { - if (ABT_initialized() != 0) - ABT_init(0, 0); +static inline void opal_threads_argobots_ensure_init(void) +{ + if (ABT_initialized() != 0) { + ABT_init(0, 0); + } } #endif /* OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_H */ diff --git a/opal/mca/threads/argobots/threads_argobots_component.c b/opal/mca/threads/argobots/threads_argobots_component.c index b72b0bca859..6d3fd0a519c 100644 --- a/opal/mca/threads/argobots/threads_argobots_component.c +++ b/opal/mca/threads/argobots/threads_argobots_component.c @@ -33,7 +33,7 @@ static int opal_threads_argobots_open(void); const opal_threads_base_component_1_0_0_t mca_threads_argobots_component = { /* First, the mca_component_t struct containing meta information - about the component itself */ + * about the component itself */ .threadsc_version = { OPAL_THREADS_BASE_VERSION_1_0_0, @@ -52,6 +52,6 @@ const opal_threads_base_component_1_0_0_t mca_threads_argobots_component = { int opal_threads_argobots_open(void) { - ensure_init_argobots(); + opal_threads_argobots_ensure_init(); return OPAL_SUCCESS; } diff --git a/opal/mca/threads/argobots/threads_argobots_condition.c b/opal/mca/threads/argobots/threads_argobots_condition.c index 6e7c2868569..56b11cf9526 100644 --- a/opal/mca/threads/argobots/threads_argobots_condition.c +++ b/opal/mca/threads/argobots/threads_argobots_condition.c @@ -1,3 +1,4 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ /* * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana * University Research and Technology @@ -22,14 +23,12 @@ #include "opal/mca/threads/condition.h" - static void opal_condition_construct(opal_condition_t *c) { c->c_waiting = 0; c->c_signaled = 0; } - static void opal_condition_destruct(opal_condition_t *c) { } diff --git a/opal/mca/threads/argobots/threads_argobots_event.c b/opal/mca/threads/argobots/threads_argobots_event.c index 7f3dc5df99f..c9ad79476b8 100644 --- a/opal/mca/threads/argobots/threads_argobots_event.c +++ b/opal/mca/threads/argobots/threads_argobots_event.c @@ -17,8 +17,7 @@ #include -static void * -evthread_argobots_lock_alloc(unsigned locktype) +static void *evthread_argobots_lock_alloc(unsigned locktype) { ABT_mutex lock; if (locktype & EVTHREAD_LOCKTYPE_RECURSIVE) { @@ -33,15 +32,13 @@ evthread_argobots_lock_alloc(unsigned locktype) return lock; } -static void -evthread_argobots_lock_free(void *_lock, unsigned locktype) +static void evthread_argobots_lock_free(void *_lock, unsigned locktype) { ABT_mutex lock = _lock; ABT_mutex_free(&lock); } -static int -evthread_argobots_lock(unsigned mode, void *_lock) +static int evthread_argobots_lock(unsigned mode, void *_lock) { int ret; ABT_mutex lock = _lock; @@ -53,8 +50,7 @@ evthread_argobots_lock(unsigned mode, void *_lock) return ret; } -static int -evthread_argobots_unlock(unsigned mode, void *_lock) +static int evthread_argobots_unlock(unsigned mode, void *_lock) { ABT_mutex lock = _lock; int ret = ABT_mutex_unlock(lock); @@ -63,43 +59,40 @@ evthread_argobots_unlock(unsigned mode, void *_lock) return ret; } -static unsigned long -evthread_argobots_get_id(void) +static unsigned long evthread_argobots_get_id(void) { ABT_thread thr; ABT_thread_self(&thr); return (unsigned long)((intptr_t)thr); } -static void * -evthread_argobots_cond_alloc(unsigned condflags) +static void *evthread_argobots_cond_alloc(unsigned condflags) { ABT_cond cond; ABT_cond_create(&cond); return cond; } -static void -evthread_argobots_cond_free(void *_cond) +static void evthread_argobots_cond_free(void *_cond) { ABT_cond cond = _cond; ABT_cond_free(&cond); } -static int -evthread_argobots_cond_signal(void *_cond, int broadcast) +static int evthread_argobots_cond_signal(void *_cond, int broadcast) { ABT_cond cond = _cond; int r; - if (broadcast) + if (broadcast) { r = ABT_cond_broadcast(cond); - else + } else { r = ABT_cond_signal(cond); + } return r ? -1 : 0; } -static int -evthread_argobots_cond_wait(void *_cond, void *_lock, const struct timeval *tv) +static int evthread_argobots_cond_wait(void *_cond, void *_lock, + const struct timeval *tv) { int r; ABT_cond cond = _cond; @@ -111,19 +104,21 @@ evthread_argobots_cond_wait(void *_cond, void *_lock, const struct timeval *tv) evutil_gettimeofday(&now, NULL); evutil_timeradd(&now, tv, &abstime); ts.tv_sec = abstime.tv_sec; - ts.tv_nsec = abstime.tv_usec*1000; + ts.tv_nsec = abstime.tv_usec * 1000; r = ABT_cond_timedwait(cond, lock, &ts); - if (r != 0) + if (r != 0) { return 1; - else + } else { return 0; + } } else { r = ABT_cond_wait(cond, lock); return r ? -1 : 0; } } -void opal_event_use_threads(void) { +void opal_event_use_threads(void) +{ struct evthread_lock_callbacks cbs = { EVTHREAD_LOCK_API_VERSION, EVTHREAD_LOCKTYPE_RECURSIVE, @@ -139,7 +134,7 @@ void opal_event_use_threads(void) { evthread_argobots_cond_signal, evthread_argobots_cond_wait }; - ensure_init_argobots(); + opal_threads_argobots_ensure_init(); evthread_set_lock_callbacks(&cbs); evthread_set_condition_callbacks(&cond_cbs); evthread_set_id_callback(evthread_argobots_get_id); diff --git a/opal/mca/threads/argobots/threads_argobots_module.c b/opal/mca/threads/argobots/threads_argobots_module.c index 5dc95348808..464e3a25b7d 100644 --- a/opal/mca/threads/argobots/threads_argobots_module.c +++ b/opal/mca/threads/argobots/threads_argobots_module.c @@ -1,3 +1,4 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ /* * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana * University Research and Technology @@ -17,6 +18,7 @@ * * $HEADER$ */ + #include #include "opal/mca/threads/argobots/threads_argobots.h" @@ -51,20 +53,22 @@ OBJ_CLASS_INSTANCE(opal_thread_t, opal_object_t, opal_thread_construct, NULL); -static inline ABT_thread opal_thread_get_argobots_self(void) { +static inline ABT_thread opal_thread_get_argobots_self(void) +{ ABT_thread self; ABT_thread_self(&self); return self; } -static void opal_thread_argobots_wrapper(void *arg) { - opal_thread_t *t = (opal_thread_t *) arg; - t->t_ret = ((void*(*)(void*)) t->t_run)(t); +static void opal_thread_argobots_wrapper(void *arg) +{ + opal_thread_t *t = (opal_thread_t *)arg; + t->t_ret = ((void *(*)(void *))t->t_run)(t); } opal_thread_t *opal_thread_get_self(void) { - ensure_init_argobots(); + opal_threads_argobots_ensure_init(); opal_thread_t *t = OBJ_NEW(opal_thread_t); t->t_handle = opal_thread_get_argobots_self(); return t; @@ -72,26 +76,30 @@ opal_thread_t *opal_thread_get_self(void) bool opal_thread_self_compare(opal_thread_t *t) { - ensure_init_argobots(); - return t->t_handle == opal_thread_get_argobots_self(); + opal_threads_argobots_ensure_init(); + return opal_thread_get_argobots_self() == t->t_handle; } -int opal_thread_join(opal_thread_t *t, void **thr_return) { - ensure_init_argobots(); +int opal_thread_join(opal_thread_t *t, void **thr_return) +{ + opal_threads_argobots_ensure_init(); int rc = ABT_thread_free(&t->t_handle); - if (thr_return) + if (thr_return) { *thr_return = t->t_ret; + } t->t_handle = ABT_THREAD_NULL; - return (rc == 0) ? OPAL_SUCCESS : OPAL_ERROR; + return (0 == rc) ? OPAL_SUCCESS : OPAL_ERROR; } -void opal_thread_set_main() { - ensure_init_argobots(); +void opal_thread_set_main() +{ + opal_threads_argobots_ensure_init(); opal_main_thread = opal_thread_get_argobots_self(); } -int opal_thread_start(opal_thread_t *t) { - ensure_init_argobots(); +int opal_thread_start(opal_thread_t *t) +{ + opal_threads_argobots_ensure_init(); int rc; if (OPAL_ENABLE_DEBUG) { if (NULL == t->t_run || t->t_handle != ABT_THREAD_NULL) { @@ -105,32 +113,35 @@ int opal_thread_start(opal_thread_t *t) { opal_thread_argobots_wrapper, t, ABT_THREAD_ATTR_NULL, &t->t_handle); - return (rc == 0) ? OPAL_SUCCESS : OPAL_ERROR; + return (0 == rc) ? OPAL_SUCCESS : OPAL_ERROR; } opal_class_t opal_thread_t_class; int opal_tsd_key_create(opal_tsd_key_t *key, opal_tsd_destructor_t destructor) { - ensure_init_argobots(); + opal_threads_argobots_ensure_init(); int rc; rc = ABT_key_create(destructor, key); if ((0 == rc) && (opal_thread_get_argobots_self() == opal_main_thread)) { - opal_tsd_key_values = (struct opal_tsd_key_value *)realloc(opal_tsd_key_values, (opal_tsd_key_values_count+1) * sizeof(struct opal_tsd_key_value)); + opal_tsd_key_values = (struct opal_tsd_key_value *) + realloc(opal_tsd_key_values, (opal_tsd_key_values_count + 1) * + sizeof(struct opal_tsd_key_value)); opal_tsd_key_values[opal_tsd_key_values_count].key = *key; opal_tsd_key_values[opal_tsd_key_values_count].destructor = destructor; - opal_tsd_key_values_count ++; + opal_tsd_key_values_count++; } return rc; } int opal_tsd_keys_destruct(void) { - ensure_init_argobots(); + opal_threads_argobots_ensure_init(); int i; - void * ptr; - for (i=0; im_lock_argobots = OPAL_ABT_MUTEX_NULL; p_mutex->m_recursive = 0; #if OPAL_ENABLE_DEBUG @@ -49,15 +50,18 @@ static void mca_threads_argobots_mutex_constructor(opal_mutex_t *p_mutex) { opal_atomic_lock_init(&p_mutex->m_lock_atomic, 0); } -static void mca_threads_argobots_mutex_desctructor(opal_mutex_t *p_mutex) { - ensure_init_argobots(); - if (OPAL_ABT_MUTX_NULL != p_mutex->m_lock_argobots) +static void mca_threads_argobots_mutex_desctructor(opal_mutex_t *p_mutex) +{ + opal_threads_argobots_ensure_init(); + if (OPAL_ABT_MUTEX_NULL != p_mutex->m_lock_argobots) { ABT_mutex_free(&p_mutex->m_lock_argobots); + } } static void mca_threads_argobots_recursive_mutex_constructor - (opal_recursive_mutex_t *p_mutex) { - ensure_init_argobots(); + (opal_recursive_mutex_t *p_mutex) +{ + opal_threads_argobots_ensure_init(); p_mutex->m_lock_argobots = OPAL_ABT_MUTEX_NULL; p_mutex->m_recursive = 1; #if OPAL_ENABLE_DEBUG @@ -69,10 +73,12 @@ static void mca_threads_argobots_recursive_mutex_constructor } static void mca_threads_argobots_recursive_mutex_desctructor - (opal_recursive_mutex_t *p_mutex) { - ensure_init_argobots(); - if (OPAL_ABT_MUTEX_NULL != p_mutex->m_lock_argobots) + (opal_recursive_mutex_t *p_mutex) +{ + opal_threads_argobots_ensure_init(); + if (OPAL_ABT_MUTEX_NULL != p_mutex->m_lock_argobots) { ABT_mutex_free(&p_mutex->m_lock_argobots); + } } OBJ_CLASS_INSTANCE(opal_mutex_t, diff --git a/opal/mca/threads/argobots/threads_argobots_mutex.h b/opal/mca/threads/argobots/threads_argobots_mutex.h index e0c41f5398d..e9d26a06750 100644 --- a/opal/mca/threads/argobots/threads_argobots_mutex.h +++ b/opal/mca/threads/argobots/threads_argobots_mutex.h @@ -15,7 +15,7 @@ * Copyright (c) 2015-2016 Research Organization for Information Science * and Technology (RIST). All rights reserved. * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. - * + * * $COPYRIGHT$ * * Additional copyrights may follow @@ -23,19 +23,8 @@ * $HEADER$ */ -#ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_MUTEX_H -#define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_MUTEX_H 1 - -/** - * @file: - * - * Mutual exclusion functions: Unix implementation. - * - * Functions for locking of critical sections. - * - * On unix, use Argobots or our own atomic operations as - * available. - */ +#ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_MUTEX_H +#define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_MUTEX_H #include "opal/mca/threads/argobots/threads_argobots.h" #include "opal_config.h" @@ -109,7 +98,8 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_recursive_mutex_t); * ************************************************************************/ -static inline void opal_mutex_create(struct opal_mutex_t *m) { +static inline void opal_mutex_create(struct opal_mutex_t *m) +{ while (OPAL_ABT_MUTEX_NULL == m->m_lock_argobots) { ABT_mutex abt_mutex; if (m->m_recursive) { @@ -134,9 +124,10 @@ static inline void opal_mutex_create(struct opal_mutex_t *m) { static inline int opal_mutex_trylock(opal_mutex_t *m) { - ensure_init_argobots(); - if (OPAL_ABT_MUTEX_NULL == m->m_lock_argobots) + opal_threads_argobots_ensure_init(); + if (OPAL_ABT_MUTEX_NULL == m->m_lock_argobots) { opal_mutex_create(m); + } #if OPAL_ENABLE_DEBUG int ret = ABT_mutex_trylock(m->m_lock_argobots); if (ret != 0) { @@ -152,9 +143,10 @@ static inline int opal_mutex_trylock(opal_mutex_t *m) static inline void opal_mutex_lock(opal_mutex_t *m) { - ensure_init_argobots(); - if (OPAL_ABT_MUTEX_NULL == m->m_lock_argobots) + opal_threads_argobots_ensure_init(); + if (OPAL_ABT_MUTEX_NULL == m->m_lock_argobots) { opal_mutex_create(m); + } #if OPAL_ENABLE_DEBUG int ret = ABT_mutex_lock(m->m_lock_argobots); if (ret != 0) { @@ -169,9 +161,10 @@ static inline void opal_mutex_lock(opal_mutex_t *m) static inline void opal_mutex_unlock(opal_mutex_t *m) { - ensure_init_argobots(); - if (OPAL_ABT_MUTEX_NULL == m->m_lock_argobots) + opal_threads_argobots_ensure_init(); + if (OPAL_ABT_MUTEX_NULL == m->m_lock_argobots) { opal_mutex_create(m); + } #if OPAL_ENABLE_DEBUG int ret = ABT_mutex_unlock(m->m_lock_argobots); if (ret != 0) { @@ -240,8 +233,9 @@ static inline void opal_mutex_atomic_unlock(opal_mutex_t *m) typedef ABT_cond opal_cond_t; #define OPAL_CONDITION_STATIC_INIT OPAL_ABT_COND_NULL -static inline void opal_cond_create(opal_cond_t *cond) { - ensure_init_argobots(); +static inline void opal_cond_create(opal_cond_t *cond) +{ + opal_threads_argobots_ensure_init(); while (OPAL_ABT_COND_NULL == *cond) { ABT_cond new_cond; ABT_cond_create(&new_cond); @@ -256,39 +250,48 @@ static inline void opal_cond_create(opal_cond_t *cond) { } } -static inline int opal_cond_init(opal_cond_t *cond) { +static inline int opal_cond_init(opal_cond_t *cond) +{ *cond = OPAL_ABT_COND_NULL; return 0; } -static inline int opal_cond_wait(opal_cond_t *cond, opal_mutex_t *lock) { - ensure_init_argobots(); - if (OPAL_ABT_COND_NULL == *cond) +static inline int opal_cond_wait(opal_cond_t *cond, opal_mutex_t *lock) +{ + opal_threads_argobots_ensure_init(); + if (OPAL_ABT_COND_NULL == *cond) { opal_cond_create(cond); + } return ABT_cond_wait(*cond, lock->m_lock_argobots); } -static inline int opal_cond_broadcast(opal_cond_t *cond) { - ensure_init_argobots(); - if (OPAL_ABT_COND_NULL == *cond) +static inline int opal_cond_broadcast(opal_cond_t *cond) +{ + opal_threads_argobots_ensure_init(); + if (OPAL_ABT_COND_NULL == *cond) { opal_cond_create(cond); + } return ABT_cond_broadcast(*cond); } -static inline int opal_cond_signal(opal_cond_t *cond) { - ensure_init_argobots(); - if (OPAL_ABT_COND_NULL == *cond) +static inline int opal_cond_signal(opal_cond_t *cond) +{ + opal_threads_argobots_ensure_init(); + if (OPAL_ABT_COND_NULL == *cond) { opal_cond_create(cond); + } return ABT_cond_signal(*cond); } -static inline int opal_cond_destroy(opal_cond_t *cond) { - ensure_init_argobots(); - if (OPAL_ABT_COND_NULL != *cond) +static inline int opal_cond_destroy(opal_cond_t *cond) +{ + opal_threads_argobots_ensure_init(); + if (OPAL_ABT_COND_NULL != * cond) { ABT_cond_free(cond); + } return 0; } END_C_DECLS -#endif /* OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_MUTEX_H */ +#endif /* OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_MUTEX_H */ diff --git a/opal/mca/threads/argobots/threads_argobots_threads.h b/opal/mca/threads/argobots/threads_argobots_threads.h index 78e09767fb2..5d85369fa98 100644 --- a/opal/mca/threads/argobots/threads_argobots_threads.h +++ b/opal/mca/threads/argobots/threads_argobots_threads.h @@ -23,8 +23,8 @@ * $HEADER$ */ -#ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_THREADS_H -#define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_THREADS_H 1 +#ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_THREADS_H +#define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_THREADS_H #include #include @@ -32,9 +32,9 @@ struct opal_thread_t { opal_object_t super; opal_thread_fn_t t_run; - void* t_arg; + void *t_arg; ABT_thread t_handle; - void* t_ret; + void *t_ret; }; #endif /* OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_THREADS_H */ diff --git a/opal/mca/threads/argobots/threads_argobots_tsd.h b/opal/mca/threads/argobots/threads_argobots_tsd.h index 7582724db8a..6385d9b2c47 100644 --- a/opal/mca/threads/argobots/threads_argobots_tsd.h +++ b/opal/mca/threads/argobots/threads_argobots_tsd.h @@ -24,32 +24,29 @@ */ -#ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_TSD_H -#define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_TSD_H 1 +#ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_TSD_H +#define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_TSD_H #include "opal/mca/threads/argobots/threads_argobots.h" #include typedef ABT_key opal_tsd_key_t; -static inline int -opal_tsd_key_delete(opal_tsd_key_t key) +static inline int opal_tsd_key_delete(opal_tsd_key_t key) { - ensure_init_argobots(); + opal_threads_argobots_ensure_init(); return ABT_key_free(&key); } -static inline int -opal_tsd_setspecific(opal_tsd_key_t key, void *value) +static inline int opal_tsd_setspecific(opal_tsd_key_t key, void *value) { - ensure_init_argobots(); + opal_threads_argobots_ensure_init(); return ABT_key_set(key, value); } -static inline int -opal_tsd_getspecific(opal_tsd_key_t key, void **valuep) +static inline int opal_tsd_getspecific(opal_tsd_key_t key, void **valuep) { - ensure_init_argobots(); + opal_threads_argobots_ensure_init(); ABT_key_get(key, valuep); return OPAL_SUCCESS; } diff --git a/opal/mca/threads/argobots/threads_argobots_wait_sync.c b/opal/mca/threads/argobots/threads_argobots_wait_sync.c index dddb7eafbf7..e11e1fc3a74 100644 --- a/opal/mca/threads/argobots/threads_argobots_wait_sync.c +++ b/opal/mca/threads/argobots/threads_argobots_wait_sync.c @@ -14,31 +14,33 @@ * * $HEADER$ */ + #include "opal/mca/threads/argobots/threads_argobots.h" #include "opal/mca/threads/wait_sync.h" static opal_mutex_t wait_sync_lock = OPAL_MUTEX_STATIC_INIT; -static ompi_wait_sync_t* wait_sync_list = NULL; +static ompi_wait_sync_t *wait_sync_list = NULL; static opal_atomic_int32_t num_thread_in_progress = 0; #define WAIT_SYNC_PASS_OWNERSHIP(who) \ do { \ - ensure_init_argobots(); \ + opal_threads_argobots_ensure_init(); \ ABT_mutex_lock((who)->lock); \ ABT_cond_signal((who)->condition ); \ ABT_mutex_unlock((who)->lock); \ - } while(0) + } while (0) int ompi_sync_wait_mt(ompi_wait_sync_t *sync) { - ensure_init_argobots(); + opal_threads_argobots_ensure_init(); /* Don't stop if the waiting synchronization is completed. We avoid the * race condition around the release of the synchronization using the * signaling field. */ - if(sync->count <= 0) + if (sync->count <= 0) { return (0 == sync->status) ? OPAL_SUCCESS : OPAL_ERROR; + } /* lock so nobody can signal us during the list updating */ ABT_mutex_lock(sync->lock); @@ -46,14 +48,14 @@ int ompi_sync_wait_mt(ompi_wait_sync_t *sync) /* Now that we hold the lock make sure another thread has not already * call cond_signal. */ - if(sync->count <= 0) { + if (sync->count <= 0) { ABT_mutex_unlock(sync->lock); return (0 == sync->status) ? OPAL_SUCCESS : OPAL_ERROR; } /* Insert sync on the list of pending synchronization constructs */ OPAL_THREAD_LOCK(&wait_sync_lock); - if( NULL == wait_sync_list ) { + if (NULL == wait_sync_list) { sync->next = sync->prev = sync; wait_sync_list = sync; } else { @@ -65,12 +67,14 @@ int ompi_sync_wait_mt(ompi_wait_sync_t *sync) OPAL_THREAD_UNLOCK(&wait_sync_lock); /** - * If we are not responsible for progresing, go silent until something worth noticing happen: + * If we are not responsible for progressing, go silent until something + * worth noticing happen: * - this thread has been promoted to take care of the progress * - our sync has been triggered. */ - check_status: - if( sync != wait_sync_list && num_thread_in_progress >= opal_max_thread_in_progress) { + check_status: + if (sync != wait_sync_list && + num_thread_in_progress >= opal_max_thread_in_progress) { ABT_cond_wait(sync->condition, sync->lock); /** @@ -79,7 +83,7 @@ int ompi_sync_wait_mt(ompi_wait_sync_t *sync) * promoted as the progress manager. */ - if( sync->count <= 0 ) { /* Completed? */ + if (sync->count <= 0) { /* Completed? */ ABT_mutex_unlock(sync->lock); goto i_am_done; } @@ -89,22 +93,24 @@ int ompi_sync_wait_mt(ompi_wait_sync_t *sync) ABT_mutex_unlock(sync->lock); OPAL_THREAD_ADD_FETCH32(&num_thread_in_progress, 1); - while(sync->count > 0) { /* progress till completion */ - opal_progress(); /* don't progress with the sync lock locked or you'll deadlock */ + while (sync->count > 0) { /* progress till completion */ + /* don't progress with the sync lock locked or you'll deadlock */ + opal_progress(); ABT_thread_yield(); } OPAL_THREAD_ADD_FETCH32(&num_thread_in_progress, -1); - i_am_done: + i_am_done: /* My sync is now complete. Trim the list: remove self, wake next */ OPAL_THREAD_LOCK(&wait_sync_lock); sync->prev->next = sync->next; sync->next->prev = sync->prev; /* In case I am the progress manager, pass the duties on */ - if( sync == wait_sync_list ) { + if (sync == wait_sync_list) { wait_sync_list = (sync == sync->next) ? NULL : sync->next; - if( NULL != wait_sync_list ) + if (NULL != wait_sync_list) { WAIT_SYNC_PASS_OWNERSHIP(wait_sync_list); + } } OPAL_THREAD_UNLOCK(&wait_sync_lock); diff --git a/opal/mca/threads/argobots/threads_argobots_wait_sync.h b/opal/mca/threads/argobots/threads_argobots_wait_sync.h index b9d5041294f..dfb66e76cb5 100644 --- a/opal/mca/threads/argobots/threads_argobots_wait_sync.h +++ b/opal/mca/threads/argobots/threads_argobots_wait_sync.h @@ -23,9 +23,8 @@ * $HEADER$ */ - -#ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_WAIT_SYNC_H -#define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_WAIT_SYNC_H 1 +#ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_WAIT_SYNC_H +#define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_WAIT_SYNC_H #include "opal/mca/threads/argobots/threads_argobots.h" #include @@ -40,7 +39,8 @@ typedef struct ompi_wait_sync_t { volatile bool signaling; } ompi_wait_sync_t; -#define SYNC_WAIT(sync) (opal_using_threads() ? ompi_sync_wait_mt (sync) : sync_wait_st (sync)) +#define SYNC_WAIT(sync) \ + (opal_using_threads() ? ompi_sync_wait_mt (sync) : sync_wait_st (sync)) /* The loop in release handles a race condition between the signaling * thread and the destruction of the condition variable. The signaling @@ -52,7 +52,7 @@ typedef struct ompi_wait_sync_t { * the critical path. */ #define WAIT_SYNC_RELEASE(sync) \ if (opal_using_threads()) { \ - ensure_init_argobots(); \ + opal_threads_argobots_ensure_init(); \ while ((sync)->signaling) { \ ABT_thread_yield(); \ continue; \ @@ -63,7 +63,7 @@ typedef struct ompi_wait_sync_t { #define WAIT_SYNC_RELEASE_NOWAIT(sync) \ if (opal_using_threads()) { \ - ensure_init_argobots(); \ + opal_threads_argobots_ensure_init(); \ ABT_cond_free(&(sync)->condition); \ ABT_mutex_free(&(sync)->lock); \ } @@ -71,26 +71,26 @@ typedef struct ompi_wait_sync_t { #define WAIT_SYNC_SIGNAL(sync) \ if (opal_using_threads()) { \ - ensure_init_argobots(); \ + opal_threads_argobots_ensure_init(); \ ABT_mutex_lock(sync->lock); \ ABT_cond_signal(sync->condition); \ ABT_mutex_unlock(sync->lock); \ sync->signaling = false; \ } -#define WAIT_SYNC_SIGNALLED(sync){ \ +#define WAIT_SYNC_SIGNALLED(sync) \ + { \ (sync)->signaling = false; \ -} + } OPAL_DECLSPEC int ompi_sync_wait_mt(ompi_wait_sync_t *sync); -static inline int sync_wait_st (ompi_wait_sync_t *sync) +static inline int sync_wait_st(ompi_wait_sync_t *sync) { - ensure_init_argobots(); + opal_threads_argobots_ensure_init(); while (sync->count > 0) { opal_progress(); ABT_thread_yield(); } - return sync->status; } @@ -103,10 +103,10 @@ static inline int sync_wait_st (ompi_wait_sync_t *sync) (sync)->status = 0; \ (sync)->signaling = (0 != (c)); \ if (opal_using_threads()) { \ - ensure_init_argobots(); \ + opal_threads_argobots_ensure_init(); \ ABT_cond_create (&(sync)->condition); \ ABT_mutex_create (&(sync)->lock); \ } \ - } while(0) + } while (0) #endif /* OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_WAIT_SYNC_H */ diff --git a/opal/mca/threads/base/base.h b/opal/mca/threads/base/base.h index f407a1784c2..dd774005068 100644 --- a/opal/mca/threads/base/base.h +++ b/opal/mca/threads/base/base.h @@ -1,3 +1,4 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ /* * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana * University Research and Technology @@ -9,7 +10,7 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. - * Copyright (c) 2014 Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2014 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. * * $COPYRIGHT$ @@ -20,8 +21,8 @@ * */ -#ifndef OPAL_THREADS_BASE_H -#define OPAL_THREADS_BASE_H +#ifndef OPAL_MCA_THREADS_BASE_BASE_H +#define OPAL_MCA_THREADS_BASE_BASE_H #include "opal_config.h" #include "opal/mca/base/mca_base_framework.h" @@ -44,4 +45,4 @@ END_C_DECLS /* include implementation to call */ #include MCA_threads_base_include_HEADER -#endif /* OPAL_BASE_THREADS_H */ +#endif /* OPAL_MCA_THREADS_BASE_BASE_H */ diff --git a/opal/mca/threads/base/threads_base_open.c b/opal/mca/threads/base/threads_base_open.c index 4b497280a34..25fb95b28ce 100644 --- a/opal/mca/threads/base/threads_base_open.c +++ b/opal/mca/threads/base/threads_base_open.c @@ -1,3 +1,4 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ /* * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana * University Research and Technology @@ -9,7 +10,7 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. - * Copyright (c) 2014 Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2014 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. * * $COPYRIGHT$ @@ -19,13 +20,11 @@ * $HEADER$ */ - #include "opal_config.h" #include "opal/constants.h" #include "opal/mca/threads/base/base.h" - /* * The following file was created by configure. It contains extern * statements and the definition of an array of pointers to each @@ -42,5 +41,6 @@ static int mca_threads_base_register(mca_base_register_flag_t flags) * Globals */ /* Use default register/open/close functions */ -MCA_BASE_FRAMEWORK_DECLARE(opal, threads, "OPAL OS threads", mca_threads_base_register, NULL, NULL, +MCA_BASE_FRAMEWORK_DECLARE(opal, threads, "OPAL OS threads", + mca_threads_base_register, NULL, NULL, mca_threads_base_static_components, 0); diff --git a/opal/mca/threads/condition.h b/opal/mca/threads/condition.h index d5533a20d84..65b15978642 100644 --- a/opal/mca/threads/condition.h +++ b/opal/mca/threads/condition.h @@ -1,3 +1,4 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ /* * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana * University Research and Technology @@ -17,13 +18,13 @@ * Copyright (c) 2019 Triad National Security, LLC. All rights * reserved. * - * * $COPYRIGHT$ * * Additional copyrights may follow * * $HEADER$ */ + #ifndef OPAL_MCA_THREADS_CONDITION_H #define OPAL_MCA_THREADS_CONDITION_H @@ -70,14 +71,14 @@ static inline int opal_condition_wait(opal_condition_t *c, opal_mutex_t *m) opal_mutex_lock(m); return 0; } - while (c->c_signaled == 0) { + while (0 == c->c_signaled) { opal_mutex_unlock(m); opal_progress(); OPAL_CR_TEST_CHECKPOINT_READY_STALL(); opal_mutex_lock(m); } } else { - while (c->c_signaled == 0) { + while (0 == c->c_signaled) { opal_progress(); OPAL_CR_TEST_CHECKPOINT_READY_STALL(); } @@ -88,8 +89,7 @@ static inline int opal_condition_wait(opal_condition_t *c, opal_mutex_t *m) return rc; } -static inline int opal_condition_timedwait(opal_condition_t *c, - opal_mutex_t *m, +static inline int opal_condition_timedwait(opal_condition_t *c, opal_mutex_t *m, const struct timespec *abstime) { struct timeval tv; @@ -100,32 +100,34 @@ static inline int opal_condition_timedwait(opal_condition_t *c, if (opal_using_threads()) { absolute.tv_sec = abstime->tv_sec; absolute.tv_usec = abstime->tv_nsec / 1000; - gettimeofday(&tv,NULL); - if (c->c_signaled == 0) { + gettimeofday(&tv, NULL); + if (0 == c->c_signaled) { do { opal_mutex_unlock(m); opal_progress(); - gettimeofday(&tv,NULL); + gettimeofday(&tv, NULL); opal_mutex_lock(m); - } while (c->c_signaled == 0 && - (tv.tv_sec <= absolute.tv_sec || - (tv.tv_sec == absolute.tv_sec && tv.tv_usec < absolute.tv_usec))); + } while (0 == c->c_signaled && (tv.tv_sec <= absolute.tv_sec || + (tv.tv_sec == absolute.tv_sec && + tv.tv_usec < absolute.tv_usec))); } } else { absolute.tv_sec = abstime->tv_sec; absolute.tv_usec = abstime->tv_nsec / 1000; - gettimeofday(&tv,NULL); - if (c->c_signaled == 0) { + gettimeofday(&tv, NULL); + if (0 == c->c_signaled) { do { opal_progress(); - gettimeofday(&tv,NULL); - } while (c->c_signaled == 0 && - (tv.tv_sec <= absolute.tv_sec || - (tv.tv_sec == absolute.tv_sec && tv.tv_usec < absolute.tv_usec))); + gettimeofday(&tv, NULL); + } while (0 == c->c_signaled && (tv.tv_sec <= absolute.tv_sec || + (tv.tv_sec == absolute.tv_sec && + tv.tv_usec < absolute.tv_usec))); } } - if (c->c_signaled != 0) c->c_signaled--; + if (0 != c->c_signaled) { + c->c_signaled--; + } c->c_waiting--; return rc; } @@ -146,4 +148,4 @@ static inline int opal_condition_broadcast(opal_condition_t *c) END_C_DECLS -#endif // OPAL_MCA_THREADS_CONDITION_H +#endif /* OPAL_MCA_THREADS_CONDITION_H */ diff --git a/opal/mca/threads/mutex.h b/opal/mca/threads/mutex.h index 35a5812d20a..a81e94cb6e8 100644 --- a/opal/mca/threads/mutex.h +++ b/opal/mca/threads/mutex.h @@ -24,15 +24,15 @@ * $HEADER$ */ -#ifndef OPAL_MCA_THREADS_MUTEX_H -#define OPAL_MCA_THREADS_MUTEX_H 1 +#ifndef OPAL_MCA_THREADS_MUTEX_H +#define OPAL_MCA_THREADS_MUTEX_H #include "opal_config.h" BEGIN_C_DECLS /** -* @file: + * @file: * * Mutual exclusion functions. * @@ -115,11 +115,11 @@ static inline void opal_mutex_atomic_unlock(opal_mutex_t *mutex); * If there is no possibility that multiple threads are running in the * process, return immediately. */ -#define OPAL_THREAD_LOCK(mutex) \ - do { \ - if (OPAL_UNLIKELY(opal_using_threads())) { \ - opal_mutex_lock(mutex); \ - } \ +#define OPAL_THREAD_LOCK(mutex) \ + do { \ + if (OPAL_UNLIKELY(opal_using_threads())) { \ + opal_mutex_lock(mutex); \ + } \ } while (0) @@ -138,7 +138,7 @@ static inline void opal_mutex_atomic_unlock(opal_mutex_t *mutex); * * Returns 0 if mutex was locked, non-zero otherwise. */ -#define OPAL_THREAD_TRYLOCK(mutex) \ +#define OPAL_THREAD_TRYLOCK(mutex) \ (OPAL_UNLIKELY(opal_using_threads()) ? opal_mutex_trylock(mutex) : 0) /** @@ -154,11 +154,11 @@ static inline void opal_mutex_atomic_unlock(opal_mutex_t *mutex); * If there is no possibility that multiple threads are running in the * process, return immediately without modifying the mutex. */ -#define OPAL_THREAD_UNLOCK(mutex) \ - do { \ - if (OPAL_UNLIKELY(opal_using_threads())) { \ - opal_mutex_unlock(mutex); \ - } \ +#define OPAL_THREAD_UNLOCK(mutex) \ + do { \ + if (OPAL_UNLIKELY(opal_using_threads())) { \ + opal_mutex_unlock(mutex); \ + } \ } while (0) @@ -177,17 +177,17 @@ static inline void opal_mutex_atomic_unlock(opal_mutex_t *mutex); * If there is no possibility that multiple threads are running in the * process, invoke the action without acquiring the lock. */ -#define OPAL_THREAD_SCOPED_LOCK(mutex, action) \ - do { \ - if(OPAL_UNLIKELY(opal_using_threads())) { \ - opal_mutex_lock(mutex); \ - action; \ - opal_mutex_unlock(mutex); \ - } else { \ - action; \ - } \ +#define OPAL_THREAD_SCOPED_LOCK(mutex, action) \ + do { \ + if (OPAL_UNLIKELY(opal_using_threads())) { \ + opal_mutex_lock(mutex); \ + action; \ + opal_mutex_unlock(mutex); \ + } else { \ + action; \ + } \ } while (0) END_C_DECLS -#endif /* OPAL_MCA_THREADS_MUTEX_H */ +#endif /* OPAL_MCA_THREADS_MUTEX_H */ diff --git a/opal/mca/threads/pthreads/threads_pthreads_component.c b/opal/mca/threads/pthreads/threads_pthreads_component.c index 85339d1381c..fcd00368831 100644 --- a/opal/mca/threads/pthreads/threads_pthreads_component.c +++ b/opal/mca/threads/pthreads/threads_pthreads_component.c @@ -31,7 +31,7 @@ static int opal_threads_pthreads_open(void); const opal_threads_base_component_1_0_0_t mca_threads_pthreads_component = { /* First, the mca_component_t struct containing meta information - about the component itself */ + * about the component itself */ .threadsc_version = { OPAL_THREADS_BASE_VERSION_1_0_0, diff --git a/opal/mca/threads/pthreads/threads_pthreads_condition.c b/opal/mca/threads/pthreads/threads_pthreads_condition.c index 6e7c2868569..9af788d9241 100644 --- a/opal/mca/threads/pthreads/threads_pthreads_condition.c +++ b/opal/mca/threads/pthreads/threads_pthreads_condition.c @@ -1,3 +1,4 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ /* * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana * University Research and Technology diff --git a/opal/mca/threads/pthreads/threads_pthreads_module.c b/opal/mca/threads/pthreads/threads_pthreads_module.c index a6a7483122e..819eb27ab80 100644 --- a/opal/mca/threads/pthreads/threads_pthreads_module.c +++ b/opal/mca/threads/pthreads/threads_pthreads_module.c @@ -47,13 +47,12 @@ static int opal_tsd_key_values_count = 0; static void opal_thread_construct(opal_thread_t *t) { t->t_run = 0; - t->t_handle = (pthread_t) -1; + t->t_handle = (pthread_t)-1; } OBJ_CLASS_INSTANCE(opal_thread_t, opal_object_t, opal_thread_construct, NULL); - opal_thread_t *opal_thread_get_self(void) @@ -65,31 +64,34 @@ opal_thread_t *opal_thread_get_self(void) bool opal_thread_self_compare(opal_thread_t *t) { - return t->t_handle == pthread_self(); + return pthread_self() == t->t_handle; } -int opal_thread_join(opal_thread_t *t, void **thr_return) { +int opal_thread_join(opal_thread_t *t, void **thr_return) +{ int rc = pthread_join(t->t_handle, thr_return); - t->t_handle = (pthread_t) -1; - return (rc == 0) ? OPAL_SUCCESS : OPAL_ERROR; + t->t_handle = (pthread_t)-1; + return (0 == rc) ? OPAL_SUCCESS : OPAL_ERROR; } -void opal_thread_set_main() { +void opal_thread_set_main(void) +{ opal_main_thread = pthread_self(); } -int opal_thread_start(opal_thread_t *t) { +int opal_thread_start(opal_thread_t *t) +{ int rc; if (OPAL_ENABLE_DEBUG) { - if (NULL == t->t_run || t->t_handle != (pthread_t) -1) { + if (NULL == t->t_run || t->t_handle != (pthread_t)-1) { return OPAL_ERR_BAD_PARAM; } } - rc = pthread_create(&t->t_handle, NULL, (void*(*)(void*)) t->t_run, t); + rc = pthread_create(&t->t_handle, NULL, (void *(*)(void *))t->t_run, t); - return (rc == 0) ? OPAL_SUCCESS : OPAL_ERROR; + return (0 == rc) ? OPAL_SUCCESS : OPAL_ERROR; } opal_class_t opal_thread_t_class; @@ -99,10 +101,12 @@ int opal_tsd_key_create(opal_tsd_key_t *key, opal_tsd_destructor_t destructor) int rc; rc = pthread_key_create(key, destructor); if ((0 == rc) && (pthread_self() == opal_main_thread)) { - opal_tsd_key_values = (struct opal_tsd_key_value *)realloc(opal_tsd_key_values, (opal_tsd_key_values_count+1) * sizeof(struct opal_tsd_key_value)); + opal_tsd_key_values = (struct opal_tsd_key_value *) + realloc(opal_tsd_key_values, (opal_tsd_key_values_count + 1) * + sizeof(struct opal_tsd_key_value)); opal_tsd_key_values[opal_tsd_key_values_count].key = *key; opal_tsd_key_values[opal_tsd_key_values_count].destructor = destructor; - opal_tsd_key_values_count ++; + opal_tsd_key_values_count++; } return rc; } @@ -110,9 +114,10 @@ int opal_tsd_key_create(opal_tsd_key_t *key, opal_tsd_destructor_t destructor) int opal_tsd_keys_destruct(void) { int i; - void * ptr; - for (i=0; im_lock_pthread, NULL); #if OPAL_ENABLE_DEBUG p_mutex->m_lock_debug = 0; @@ -62,12 +63,14 @@ static void mca_threads_pthreads_mutex_constructor(opal_mutex_t *p_mutex) { opal_atomic_lock_init(&p_mutex->m_lock_atomic, 0); } -static void mca_threads_pthreads_mutex_desctructor(opal_mutex_t *p_mutex) { +static void mca_threads_pthreads_mutex_desctructor(opal_mutex_t *p_mutex) +{ pthread_mutex_destroy(&p_mutex->m_lock_pthread); } static void mca_threads_pthreads_recursive_mutex_constructor - (opal_recursive_mutex_t *p_mutex) { + (opal_recursive_mutex_t *p_mutex) +{ pthread_mutexattr_t mutex_attr; pthread_mutexattr_init(&mutex_attr); pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE); @@ -82,7 +85,8 @@ static void mca_threads_pthreads_recursive_mutex_constructor } static void mca_threads_pthreads_recursive_mutex_desctructor - (opal_recursive_mutex_t *p_mutex) { + (opal_recursive_mutex_t *p_mutex) +{ pthread_mutex_destroy(&p_mutex->m_lock_pthread); } diff --git a/opal/mca/threads/pthreads/threads_pthreads_mutex.h b/opal/mca/threads/pthreads/threads_pthreads_mutex.h index 3f8d082c4b4..e42e6ddc900 100644 --- a/opal/mca/threads/pthreads/threads_pthreads_mutex.h +++ b/opal/mca/threads/pthreads/threads_pthreads_mutex.h @@ -15,7 +15,7 @@ * Copyright (c) 2015-2016 Research Organization for Information Science * and Technology (RIST). All rights reserved. * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. - * + * * $COPYRIGHT$ * * Additional copyrights may follow @@ -23,8 +23,8 @@ * $HEADER$ */ -#ifndef OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_MUTEX_H -#define OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_MUTEX_H 1 +#ifndef OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_MUTEX_H +#define OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_MUTEX_H /** * @file: @@ -65,9 +65,11 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_mutex_t); OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_recursive_mutex_t); #if defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP) -#define OPAL_PTHREAD_RECURSIVE_MUTEX_INITIALIZER PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP +#define OPAL_PTHREAD_RECURSIVE_MUTEX_INITIALIZER \ + PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP #elif defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER) -#define OPAL_PTHREAD_RECURSIVE_MUTEX_INITIALIZER PTHREAD_RECURSIVE_MUTEX_INITIALIZER +#define OPAL_PTHREAD_RECURSIVE_MUTEX_INITIALIZER \ + PTHREAD_RECURSIVE_MUTEX_INITIALIZER #endif #if OPAL_ENABLE_DEBUG @@ -122,7 +124,7 @@ static inline int opal_mutex_trylock(opal_mutex_t *m) { #if OPAL_ENABLE_DEBUG int ret = pthread_mutex_trylock(&m->m_lock_pthread); - if (ret == EDEADLK) { + if (EDEADLK == ret) { errno = ret; perror("opal_mutex_trylock()"); abort(); @@ -137,7 +139,7 @@ static inline void opal_mutex_lock(opal_mutex_t *m) { #if OPAL_ENABLE_DEBUG int ret = pthread_mutex_lock(&m->m_lock_pthread); - if (ret == EDEADLK) { + if (EDEADLK == ret) { errno = ret; perror("opal_mutex_lock()"); abort(); @@ -151,7 +153,7 @@ static inline void opal_mutex_unlock(opal_mutex_t *m) { #if OPAL_ENABLE_DEBUG int ret = pthread_mutex_unlock(&m->m_lock_pthread); - if (ret == EPERM) { + if (EPERM == ret) { errno = ret; perror("opal_mutex_unlock"); abort(); @@ -221,4 +223,4 @@ typedef pthread_cond_t opal_cond_t; END_C_DECLS -#endif /* OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_MUTEX_H */ +#endif /* OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_MUTEX_H */ diff --git a/opal/mca/threads/pthreads/threads_pthreads_threads.h b/opal/mca/threads/pthreads/threads_pthreads_threads.h index 45e5e8f87ed..27ad13e8e1d 100644 --- a/opal/mca/threads/pthreads/threads_pthreads_threads.h +++ b/opal/mca/threads/pthreads/threads_pthreads_threads.h @@ -24,8 +24,8 @@ */ -#ifndef OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_THREADS_H -#define OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_THREADS_H 1 +#ifndef OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_THREADS_H +#define OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_THREADS_H #include #include @@ -33,7 +33,7 @@ struct opal_thread_t { opal_object_t super; opal_thread_fn_t t_run; - void* t_arg; + void *t_arg; pthread_t t_handle; }; diff --git a/opal/mca/threads/pthreads/threads_pthreads_tsd.h b/opal/mca/threads/pthreads/threads_pthreads_tsd.h index 001d20aa042..2d1955eea7f 100644 --- a/opal/mca/threads/pthreads/threads_pthreads_tsd.h +++ b/opal/mca/threads/pthreads/threads_pthreads_tsd.h @@ -24,28 +24,25 @@ */ -#ifndef OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_TSD_H -#define OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_TSD_H 1 +#ifndef OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_TSD_H +#define OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_TSD_H #include #include typedef pthread_key_t opal_tsd_key_t; -static inline int -opal_tsd_key_delete(opal_tsd_key_t key) +static inline int opal_tsd_key_delete(opal_tsd_key_t key) { return pthread_key_delete(key); } -static inline int -opal_tsd_setspecific(opal_tsd_key_t key, void *value) +static inline int opal_tsd_setspecific(opal_tsd_key_t key, void *value) { return pthread_setspecific(key, value); } -static inline int -opal_tsd_getspecific(opal_tsd_key_t key, void **valuep) +static inline int opal_tsd_getspecific(opal_tsd_key_t key, void **valuep) { *valuep = pthread_getspecific(key); return OPAL_SUCCESS; diff --git a/opal/mca/threads/pthreads/threads_pthreads_wait_sync.c b/opal/mca/threads/pthreads/threads_pthreads_wait_sync.c index 21a8943c5d7..622efdfe1df 100644 --- a/opal/mca/threads/pthreads/threads_pthreads_wait_sync.c +++ b/opal/mca/threads/pthreads/threads_pthreads_wait_sync.c @@ -14,19 +14,20 @@ * * $HEADER$ */ + #include "opal/mca/threads/wait_sync.h" static opal_mutex_t wait_sync_lock = OPAL_MUTEX_STATIC_INIT; -static ompi_wait_sync_t* wait_sync_list = NULL; +static ompi_wait_sync_t *wait_sync_list = NULL; static opal_atomic_int32_t num_thread_in_progress = 0; -#define WAIT_SYNC_PASS_OWNERSHIP(who) \ - do { \ - pthread_mutex_lock( &(who)->lock); \ - pthread_cond_signal( &(who)->condition ); \ - pthread_mutex_unlock( &(who)->lock); \ - } while(0) +#define WAIT_SYNC_PASS_OWNERSHIP(who) \ + do { \ + pthread_mutex_lock(&(who)->lock); \ + pthread_cond_signal(&(who)->condition); \ + pthread_mutex_unlock(&(who)->lock); \ + } while (0) int ompi_sync_wait_mt(ompi_wait_sync_t *sync) { @@ -34,8 +35,9 @@ int ompi_sync_wait_mt(ompi_wait_sync_t *sync) * race condition around the release of the synchronization using the * signaling field. */ - if(sync->count <= 0) + if (sync->count <= 0) { return (0 == sync->status) ? OPAL_SUCCESS : OPAL_ERROR; + } /* lock so nobody can signal us during the list updating */ pthread_mutex_lock(&sync->lock); @@ -43,14 +45,14 @@ int ompi_sync_wait_mt(ompi_wait_sync_t *sync) /* Now that we hold the lock make sure another thread has not already * call cond_signal. */ - if(sync->count <= 0) { + if (sync->count <= 0) { pthread_mutex_unlock(&sync->lock); return (0 == sync->status) ? OPAL_SUCCESS : OPAL_ERROR; } /* Insert sync on the list of pending synchronization constructs */ OPAL_THREAD_LOCK(&wait_sync_lock); - if( NULL == wait_sync_list ) { + if (NULL == wait_sync_list) { sync->next = sync->prev = sync; wait_sync_list = sync; } else { @@ -62,12 +64,14 @@ int ompi_sync_wait_mt(ompi_wait_sync_t *sync) OPAL_THREAD_UNLOCK(&wait_sync_lock); /** - * If we are not responsible for progresing, go silent until something worth noticing happen: + * If we are not responsible for progressing, go silent until something + * worth noticing happen: * - this thread has been promoted to take care of the progress * - our sync has been triggered. */ - check_status: - if( sync != wait_sync_list && num_thread_in_progress >= opal_max_thread_in_progress) { + check_status: + if (sync != wait_sync_list && + num_thread_in_progress >= opal_max_thread_in_progress) { pthread_cond_wait(&sync->condition, &sync->lock); /** @@ -76,7 +80,7 @@ int ompi_sync_wait_mt(ompi_wait_sync_t *sync) * promoted as the progress manager. */ - if( sync->count <= 0 ) { /* Completed? */ + if (sync->count <= 0) { /* Completed? */ pthread_mutex_unlock(&sync->lock); goto i_am_done; } @@ -86,21 +90,23 @@ int ompi_sync_wait_mt(ompi_wait_sync_t *sync) pthread_mutex_unlock(&sync->lock); OPAL_THREAD_ADD_FETCH32(&num_thread_in_progress, 1); - while(sync->count > 0) { /* progress till completion */ - opal_progress(); /* don't progress with the sync lock locked or you'll deadlock */ + while (sync->count > 0) { /* progress till completion */ + /* don't progress with the sync lock locked or you'll deadlock */ + opal_progress(); } OPAL_THREAD_ADD_FETCH32(&num_thread_in_progress, -1); - i_am_done: + i_am_done: /* My sync is now complete. Trim the list: remove self, wake next */ OPAL_THREAD_LOCK(&wait_sync_lock); sync->prev->next = sync->next; sync->next->prev = sync->prev; /* In case I am the progress manager, pass the duties on */ - if( sync == wait_sync_list ) { + if (sync == wait_sync_list) { wait_sync_list = (sync == sync->next) ? NULL : sync->next; - if( NULL != wait_sync_list ) + if (NULL != wait_sync_list) { WAIT_SYNC_PASS_OWNERSHIP(wait_sync_list); + } } OPAL_THREAD_UNLOCK(&wait_sync_lock); diff --git a/opal/mca/threads/pthreads/threads_pthreads_wait_sync.h b/opal/mca/threads/pthreads/threads_pthreads_wait_sync.h index 26a1a3927f4..d34b9fcd3c7 100644 --- a/opal/mca/threads/pthreads/threads_pthreads_wait_sync.h +++ b/opal/mca/threads/pthreads/threads_pthreads_wait_sync.h @@ -24,8 +24,8 @@ */ -#ifndef OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_WAIT_SYNC_H -#define OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_WAIT_SYNC_H 1 +#ifndef OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_WAIT_SYNC_H +#define OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_WAIT_SYNC_H typedef struct ompi_wait_sync_t { opal_atomic_int32_t count; @@ -37,7 +37,8 @@ typedef struct ompi_wait_sync_t { volatile bool signaling; } ompi_wait_sync_t; -#define SYNC_WAIT(sync) (opal_using_threads() ? ompi_sync_wait_mt (sync) : sync_wait_st (sync)) +#define SYNC_WAIT(sync) \ + (opal_using_threads() ? ompi_sync_wait_mt(sync) : sync_wait_st(sync)) /* The loop in release handles a race condition between the signaling * thread and the destruction of the condition variable. The signaling @@ -71,21 +72,20 @@ typedef struct ompi_wait_sync_t { sync->signaling = false; \ } -#define WAIT_SYNC_SIGNALLED(sync){ \ +#define WAIT_SYNC_SIGNALLED(sync) \ + { \ (sync)->signaling = false; \ -} + } OPAL_DECLSPEC int ompi_sync_wait_mt(ompi_wait_sync_t *sync); -static inline int sync_wait_st (ompi_wait_sync_t *sync) +static inline int sync_wait_st(ompi_wait_sync_t *sync) { while (sync->count > 0) { opal_progress(); } - return sync->status; } - #define WAIT_SYNC_INIT(sync,c) \ do { \ (sync)->count = (c); \ @@ -94,9 +94,9 @@ static inline int sync_wait_st (ompi_wait_sync_t *sync) (sync)->status = 0; \ (sync)->signaling = (0 != (c)); \ if (opal_using_threads()) { \ - pthread_cond_init (&(sync)->condition, NULL); \ - pthread_mutex_init (&(sync)->lock, NULL); \ + pthread_cond_init(&(sync)->condition, NULL); \ + pthread_mutex_init(&(sync)->lock, NULL); \ } \ - } while(0) + } while (0) #endif /* OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_WAIT_SYNC_H */ diff --git a/opal/mca/threads/qthreads/threads_qthreads_component.c b/opal/mca/threads/qthreads/threads_qthreads_component.c index 86cff6bd762..bae4cc18983 100644 --- a/opal/mca/threads/qthreads/threads_qthreads_component.c +++ b/opal/mca/threads/qthreads/threads_qthreads_component.c @@ -21,13 +21,6 @@ * $HEADER$ */ - * $COPYRIGHT$ - * - * Additional copyrights may follow - * - * $HEADER$ - */ - #include "opal_config.h" #include "opal/mca/threads/thread.h" @@ -38,7 +31,7 @@ static int opal_threads_qthreads_open(void); const opal_threads_base_component_1_0_0_t mca_threads_qthreads_component = { /* First, the mca_component_t struct containing meta information - about the component itself */ + * about the component itself */ .threadsc_version = { OPAL_THREADS_BASE_VERSION_1_0_0, diff --git a/opal/mca/threads/qthreads/threads_qthreads_module.c b/opal/mca/threads/qthreads/threads_qthreads_module.c index 4649447f304..392a73638af 100644 --- a/opal/mca/threads/qthreads/threads_qthreads_module.c +++ b/opal/mca/threads/qthreads/threads_qthreads_module.c @@ -1,3 +1,4 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ /* * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana * University Research and Technology @@ -58,21 +59,21 @@ bool opal_thread_self_compare(opal_thread_t *t) return OPAL_ERROR; } -int sync_wait_mt(void *p) +int sync_wait_mt(void *p) { return OPAL_ERROR; } -int opal_thread_join(opal_thread_t *t, void **thr_return) +int opal_thread_join(opal_thread_t *t, void **thr_return) { return OPAL_ERROR; } -void opal_thread_set_main() +void opal_thread_set_main(void) { } -int opal_thread_start(opal_thread_t *t) +int opal_thread_start(opal_thread_t *t) { return OPAL_ERR_NOT_IMPLEMENTED; } @@ -86,19 +87,5 @@ int opal_tsd_key_create(opal_tsd_key_t *key, opal_tsd_destructor_t destructor) int opal_tsd_keys_destruct(void) { - int i; - void * ptr; - for (i=0; im_lock_pthread, &attr); - pthread_mutexattr_destroy(&attr); - - m->m_lock_debug = 0; - m->m_lock_file = NULL; - m->m_lock_line = 0; -#else - - /* Without debugging, choose the fastest available mutexes */ - pthread_mutex_init(&m->m_lock_pthread, NULL); - -#endif /* OPAL_ENABLE_DEBUG */ - -#if OPAL_HAVE_ATOMIC_SPINLOCKS - opal_atomic_lock_init( &m->m_lock_atomic, OPAL_ATOMIC_LOCK_UNLOCKED ); -#endif } static void opal_mutex_destruct(opal_mutex_t *m) { - pthread_mutex_destroy(&m->m_lock_pthread); } OBJ_CLASS_INSTANCE(opal_mutex_t, @@ -74,23 +48,6 @@ OBJ_CLASS_INSTANCE(opal_mutex_t, static void opal_recursive_mutex_construct(opal_recursive_mutex_t *m) { - pthread_mutexattr_t attr; - pthread_mutexattr_init(&attr); - -#if OPAL_ENABLE_DEBUG - m->m_lock_debug = 0; - m->m_lock_file = NULL; - m->m_lock_line = 0; -#endif - - pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); - - pthread_mutex_init(&m->m_lock_pthread, &attr); - pthread_mutexattr_destroy(&attr); - -#if OPAL_HAVE_ATOMIC_SPINLOCKS - opal_atomic_lock_init( &m->m_lock_atomic, OPAL_ATOMIC_LOCK_UNLOCKED ); -#endif } OBJ_CLASS_INSTANCE(opal_recursive_mutex_t, diff --git a/opal/mca/threads/thread.h b/opal/mca/threads/thread.h index 9bf106a6dc7..9be62eddb96 100644 --- a/opal/mca/threads/thread.h +++ b/opal/mca/threads/thread.h @@ -22,8 +22,8 @@ */ -#ifndef OPAL_MCA_THREADS_THREADS_H -#define OPAL_MCA_THREADS_THREADS_H +#ifndef OPAL_MCA_THREADS_THREAD_H +#define OPAL_MCA_THREADS_THREAD_H #include "opal_config.h" @@ -43,7 +43,8 @@ struct opal_threads_base_component_1_0_0_t { /** * Convenience typedef */ -typedef struct opal_threads_base_component_1_0_0_t opal_threads_base_component_1_0_0_t; +typedef struct opal_threads_base_component_1_0_0_t + opal_threads_base_component_1_0_0_t; /* * Macro for use in components that are of type threads @@ -51,4 +52,4 @@ typedef struct opal_threads_base_component_1_0_0_t opal_threads_base_component_1 #define OPAL_THREADS_BASE_VERSION_1_0_0 \ OPAL_MCA_BASE_VERSION_2_1_0("threads", 1, 0, 0) -#endif /* OPAL_MCA_THREADS_THREADS_H */ +#endif /* OPAL_MCA_THREADS_THREAD_H */ diff --git a/opal/mca/threads/thread_usage.h b/opal/mca/threads/thread_usage.h index 92e0031a751..8c2ec8291d1 100644 --- a/opal/mca/threads/thread_usage.h +++ b/opal/mca/threads/thread_usage.h @@ -6,7 +6,7 @@ * Copyright (c) 2004-2007 The University of Tennessee and The University * of Tennessee Research Foundation. All rights * reserved. - * Copyright (c) 2004-2006 High Performance Computing Center Stuttgart, + * Copyright (c) 2004-2006 High Performance Computing Center Stuttgart, * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. @@ -16,15 +16,16 @@ * Copyright (c) 2015-2018 Los Alamos National Security, LLC. All rights * reserved. * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. + * * $COPYRIGHT$ - * + * * Additional copyrights may follow - * + * * $HEADER$ */ -#if !defined(OPAL_MCA_THREAD_USAGE_H) -#define OPAL_MCA_THREAD_USAGE_H +#ifndef OPAL_MCA_THREADS_THREAD_USAGE_H +#define OPAL_MCA_THREADS_THREAD_USAGE_H #include "opal_config.h" @@ -64,7 +65,7 @@ OPAL_DECLSPEC extern bool opal_uses_threads; * possibility that we may have multiple threads, true will be * returned. */ -#define opal_using_threads() opal_uses_threads +#define opal_using_threads() opal_uses_threads /** * Set whether the process is using multiple threads or not. @@ -94,56 +95,62 @@ static inline bool opal_set_using_threads(bool have) * indicates that threads are in use by the application or library. */ -#define OPAL_THREAD_DEFINE_ATOMIC_OP(type, name, operator, suffix) \ -static inline type opal_thread_ ## name ## _fetch_ ## suffix (opal_atomic_ ## type *addr, type delta) \ -{ \ - if (OPAL_UNLIKELY(opal_using_threads())) { \ - return opal_atomic_ ## name ## _fetch_ ## suffix (addr, delta); \ - } \ - \ - *addr = *addr operator delta; \ - return *addr; \ -} \ - \ -static inline type opal_thread_fetch_ ## name ## _ ## suffix (opal_atomic_ ## type *addr, type delta) \ -{ \ - if (OPAL_UNLIKELY(opal_using_threads())) { \ - return opal_atomic_fetch_ ## name ## _ ## suffix (addr, delta); \ - } \ - \ - type old = *addr; \ - *addr = old operator delta; \ - return old; \ +#define OPAL_THREAD_DEFINE_ATOMIC_OP(type, name, operator, suffix) \ +static inline type opal_thread_ ## name ## _fetch_ ## suffix \ + (opal_atomic_ ## type *addr, type delta) \ +{ \ + if (OPAL_UNLIKELY(opal_using_threads())) { \ + return opal_atomic_ ## name ## _fetch_ ## suffix (addr, delta); \ + } \ + \ + *addr = *addr operator delta; \ + return *addr; \ +} \ + \ +static inline type opal_thread_fetch_ ## name ## _ ## suffix \ + (opal_atomic_ ## type *addr, type delta) \ +{ \ + if (OPAL_UNLIKELY(opal_using_threads())) { \ + return opal_atomic_fetch_ ## name ## _ ## suffix (addr, delta); \ + } \ + \ + type old = *addr; \ + *addr = old operator delta; \ + return old; \ } -#define OPAL_THREAD_DEFINE_ATOMIC_COMPARE_EXCHANGE(type, addr_type, suffix) \ -static inline bool opal_thread_compare_exchange_strong_ ## suffix (opal_atomic_ ## addr_type *addr, type *compare, type value) \ -{ \ - if (OPAL_UNLIKELY(opal_using_threads())) { \ - return opal_atomic_compare_exchange_strong_ ## suffix (addr, (addr_type *) compare, (addr_type) value); \ - } \ - \ - if ((type) *addr == *compare) { \ - ((type *) addr)[0] = value; \ - return true; \ - } \ - \ - *compare = ((type *) addr)[0]; \ - \ - return false; \ +#define OPAL_THREAD_DEFINE_ATOMIC_COMPARE_EXCHANGE(type, addr_type, suffix) \ +static inline bool opal_thread_compare_exchange_strong_ ## suffix \ + (opal_atomic_ ## addr_type *addr, type *compare, type value) \ +{ \ + if (OPAL_UNLIKELY(opal_using_threads())) { \ + return opal_atomic_compare_exchange_strong_ ## suffix \ + (addr, (addr_type *)compare, (addr_type)value); \ + } \ + \ + if ((type) *addr == *compare) { \ + ((type *)addr)[0] = value; \ + return true; \ + } \ + \ + *compare = ((type *)addr)[0]; \ + \ + return false; \ } -#define OPAL_THREAD_DEFINE_ATOMIC_SWAP(type, addr_type, suffix) \ -static inline type opal_thread_swap_ ## suffix (opal_atomic_ ## addr_type *ptr, type newvalue) \ -{ \ - if (opal_using_threads ()) { \ - return (type) opal_atomic_swap_ ## suffix (ptr, (addr_type) newvalue); \ - } \ - \ - type old = ((type *) ptr)[0]; \ - ((type *) ptr)[0] = newvalue; \ - \ - return old; \ +#define OPAL_THREAD_DEFINE_ATOMIC_SWAP(type, addr_type, suffix) \ +static inline type opal_thread_swap_ ## suffix \ + (opal_atomic_ ## addr_type *ptr, type newvalue) \ +{ \ + if (opal_using_threads ()) { \ + return (type) opal_atomic_swap_ ## suffix \ + (ptr, (addr_type) newvalue); \ + } \ + \ + type old = ((type *)ptr)[0]; \ + ((type *)ptr)[0] = newvalue; \ + \ + return old; \ } OPAL_THREAD_DEFINE_ATOMIC_OP(int32_t, add, +, 32) @@ -195,16 +202,22 @@ OPAL_THREAD_DEFINE_ATOMIC_SWAP(intptr_t, intptr_t, ptr) #define OPAL_THREAD_FETCH_SUB_SIZE_T opal_thread_fetch_sub_size_t #define OPAL_ATOMIC_FETCH_SUB_SIZE_T opal_thread_fetch_sub_size_t -#define OPAL_THREAD_COMPARE_EXCHANGE_STRONG_32 opal_thread_compare_exchange_strong_32 -#define OPAL_ATOMIC_COMPARE_EXCHANGE_STRONG_32 opal_thread_compare_exchange_strong_32 +#define OPAL_THREAD_COMPARE_EXCHANGE_STRONG_32 \ + opal_thread_compare_exchange_strong_32 +#define OPAL_ATOMIC_COMPARE_EXCHANGE_STRONG_32 \ + opal_thread_compare_exchange_strong_32 -#define OPAL_THREAD_COMPARE_EXCHANGE_STRONG_PTR(x, y, z) opal_thread_compare_exchange_strong_ptr ((opal_atomic_intptr_t *) x, (intptr_t *) y, (intptr_t) z) -#define OPAL_ATOMIC_COMPARE_EXCHANGE_STRONG_PTR OPAL_THREAD_COMPARE_EXCHANGE_STRONG_PTR +#define OPAL_THREAD_COMPARE_EXCHANGE_STRONG_PTR(x, y, z) \ + opal_thread_compare_exchange_strong_ptr ((opal_atomic_intptr_t *) x, \ + (intptr_t *) y, (intptr_t) z) +#define OPAL_ATOMIC_COMPARE_EXCHANGE_STRONG_PTR \ + OPAL_THREAD_COMPARE_EXCHANGE_STRONG_PTR #define OPAL_THREAD_SWAP_32 opal_thread_swap_32 #define OPAL_ATOMIC_SWAP_32 opal_thread_swap_32 -#define OPAL_THREAD_SWAP_PTR(x, y) opal_thread_swap_ptr ((opal_atomic_intptr_t *) x, (intptr_t) y) +#define OPAL_THREAD_SWAP_PTR(x, y) \ + opal_thread_swap_ptr ((opal_atomic_intptr_t *) x, (intptr_t) y) #define OPAL_ATOMIC_SWAP_PTR OPAL_THREAD_SWAP_PTR /* define 64-bit macros is 64-bit atomic math is available */ @@ -242,8 +255,10 @@ OPAL_THREAD_DEFINE_ATOMIC_SWAP(int64_t, int64_t, 64) #define OPAL_THREAD_FETCH_XOR64 opal_thread_fetch_xor_64 #define OPAL_ATOMIC_FETCH_XOR64 opal_thread_fetch_xor_64 -#define OPAL_THREAD_COMPARE_EXCHANGE_STRONG_64 opal_thread_compare_exchange_strong_64 -#define OPAL_ATOMIC_COMPARE_EXCHANGE_STRONG_64 opal_thread_compare_exchange_strong_64 +#define OPAL_THREAD_COMPARE_EXCHANGE_STRONG_64 \ + opal_thread_compare_exchange_strong_64 +#define OPAL_ATOMIC_COMPARE_EXCHANGE_STRONG_64 \ + opal_thread_compare_exchange_strong_64 #define OPAL_THREAD_SWAP_64 opal_thread_swap_64 #define OPAL_ATOMIC_SWAP_64 opal_thread_swap_64 @@ -264,4 +279,4 @@ OPAL_THREAD_DEFINE_ATOMIC_SWAP(int64_t, int64_t, 64) #define OPAL_HAVE_THREAD_LOCAL 0 #endif /* !defined(OPAL_HAVE_THREAD_LOCAL) */ -#endif /* !defined(OPAL_MCA_THREAD_USAGE_H) */ +#endif /* OPAL_MCA_THREADS_THREAD_USAGE_H */ diff --git a/opal/mca/threads/threads.h b/opal/mca/threads/threads.h index b7378e4db61..bcbfa88197d 100644 --- a/opal/mca/threads/threads.h +++ b/opal/mca/threads/threads.h @@ -1,3 +1,4 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ /* * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana * University Research and Technology @@ -15,6 +16,7 @@ * and Technology (RIST). All rights reserved. * Copyright (c) 2017 Intel, Inc. All rights reserved. * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. + * * $COPYRIGHT$ * * Additional copyrights may follow @@ -22,8 +24,8 @@ * $HEADER$ */ -#ifndef OPAL_MCA_THREAD_H -#define OPAL_MCA_THREAD_H 1 +#ifndef OPAL_MCA_THREADS_THREADS_H +#define OPAL_MCA_THREADS_THREADS_H #include "opal_config.h" @@ -37,9 +39,9 @@ BEGIN_C_DECLS -typedef void *(*opal_thread_fn_t) (opal_object_t *); +typedef void *(*opal_thread_fn_t)(opal_object_t *); -#define OPAL_THREAD_CANCELLED ((void*)1); +#define OPAL_THREAD_CANCELLED ((void *)1); #include MCA_threads_base_include_HEADER @@ -70,7 +72,7 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_thread_t); __FILE__, __LINE__); \ } \ *(act) = true; \ - } while(0); + } while (0); #else #define OPAL_ACQUIRE_THREAD(lck, cnd, act) \ do { \ @@ -79,7 +81,7 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_thread_t); opal_condition_wait((cnd), (lck)); \ } \ *(act) = true; \ - } while(0); + } while (0); #endif @@ -93,14 +95,14 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_thread_t); *(act) = false; \ opal_condition_broadcast((cnd)); \ OPAL_THREAD_UNLOCK((lck)); \ - } while(0); + } while (0); #else #define OPAL_RELEASE_THREAD(lck, cnd, act) \ do { \ *(act) = false; \ opal_condition_broadcast((cnd)); \ OPAL_THREAD_UNLOCK((lck)); \ - } while(0); + } while (0); #endif @@ -108,7 +110,7 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_thread_t); do { \ *(act) = false; \ opal_condition_broadcast((cnd)); \ - } while(0); + } while (0); /* provide a macro for forward-proofing the shifting * of objects between libevent threads - at some point, we @@ -126,7 +128,7 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_thread_t); OPAL_DECLSPEC int opal_thread_start(opal_thread_t *); OPAL_DECLSPEC int opal_thread_join(opal_thread_t *, void **thread_return); -OPAL_DECLSPEC bool opal_thread_self_compare(opal_thread_t*); +OPAL_DECLSPEC bool opal_thread_self_compare(opal_thread_t *); OPAL_DECLSPEC opal_thread_t *opal_thread_get_self(void); OPAL_DECLSPEC void opal_thread_kill(opal_thread_t *, int sig); OPAL_DECLSPEC void opal_thread_set_main(void); @@ -134,4 +136,4 @@ OPAL_DECLSPEC void opal_event_use_threads(void); END_C_DECLS -#endif /* OPAL_MCA_THREAD_H */ +#endif /* OPAL_MCA_THREADS_THREADS_H */ diff --git a/opal/mca/threads/tsd.h b/opal/mca/threads/tsd.h index 83950da1913..f05d0747a96 100644 --- a/opal/mca/threads/tsd.h +++ b/opal/mca/threads/tsd.h @@ -1,3 +1,4 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ /* * Copyright (c) 2007-2013 Los Alamos National Security, LLC. All rights * reserved. @@ -44,7 +45,7 @@ typedef void (*opal_tsd_destructor_t)(void *value); /** * Typedef for thread-specific data key */ -typedef void* opal_tsd_key_t; +typedef void *opal_tsd_key_t; /** diff --git a/opal/mca/threads/wait_sync.h b/opal/mca/threads/wait_sync.h index 0b5f421c75f..c600a3d0e95 100644 --- a/opal/mca/threads/wait_sync.h +++ b/opal/mca/threads/wait_sync.h @@ -10,6 +10,7 @@ * and Technology (RIST). All rights reserved. * Copyright (c) 2017 IBM Corporation. All rights reserved. * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. + * * $COPYRIGHT$ * * Additional copyrights may follow @@ -17,7 +18,7 @@ * $HEADER$ */ -#if !defined(OPAL_MCA_THREADS_WAIT_SYNC_H) +#ifndef OPAL_MCA_THREADS_WAIT_SYNC_H #define OPAL_MCA_THREADS_WAIT_SYNC_H #include "opal/sys/atomic.h" @@ -29,8 +30,8 @@ extern int opal_max_thread_in_progress; #include MCA_threads_wait_sync_base_include_HEADER -#define REQUEST_PENDING (void*)0L -#define REQUEST_COMPLETED (void*)1L +#define REQUEST_PENDING (void *)0L +#define REQUEST_COMPLETED (void *)1L /** * Update the status of the synchronization primitive. If an error is @@ -38,21 +39,22 @@ extern int opal_max_thread_in_progress; * triggered. The status of the synchronization will be reported to * the waiting threads. */ -static inline void wait_sync_update(ompi_wait_sync_t *sync, int updates, int status) +static inline void wait_sync_update(ompi_wait_sync_t *sync, int updates, + int status) { - if( OPAL_LIKELY(OPAL_SUCCESS == status) ) { - if( 0 != (OPAL_THREAD_ADD_FETCH32(&sync->count, -updates)) ) { + if (OPAL_LIKELY(OPAL_SUCCESS == status)) { + if (0 != (OPAL_THREAD_ADD_FETCH32(&sync->count, -updates))) { return; } } else { /* this is an error path so just use the atomic */ sync->status = OPAL_ERROR; - opal_atomic_wmb (); - opal_atomic_swap_32 (&sync->count, 0); + opal_atomic_wmb(); + opal_atomic_swap_32(&sync->count, 0); } WAIT_SYNC_SIGNAL(sync); } END_C_DECLS -#endif /* defined(OPAL_MCA_THREADS_WAIT_SYNC_H) */ +#endif /* OPAL_MCA_THREADS_WAIT_SYNC_H */ From 6fe3237d083f7eb9e1f41365d696b296ede903ee Mon Sep 17 00:00:00 2001 From: Howard Pritchard Date: Wed, 4 Dec 2019 13:38:08 -0700 Subject: [PATCH 16/17] update threads MCA framework configury It now works more like the ompi/mca/rte configury, modulo some edge items that are special for threading package linking, etc. Signed-off-by: Howard Pritchard --- configure.ac | 28 +++++------- opal/mca/threads/argobots/configure.m4 | 42 ++++++++++-------- opal/mca/threads/configure.m4 | 60 ++++++++++++++++++++++++++ opal/mca/threads/pthreads/configure.m4 | 49 +++++++++++++-------- opal/mca/threads/qthreads/configure.m4 | 31 +++++++++++-- 5 files changed, 155 insertions(+), 55 deletions(-) create mode 100644 opal/mca/threads/configure.m4 diff --git a/configure.ac b/configure.ac index 7a3030dee6c..eea28daf773 100644 --- a/configure.ac +++ b/configure.ac @@ -26,6 +26,8 @@ # Copyright (c) 2018 Amazon.com, Inc. or its affiliates. # All Rights reserved. # Copyright (c) 2018 FUJITSU LIMITED. All rights reserved. +# Copyright (c) 2019 Triad National Security, LLC. All rights +# reserved. # $COPYRIGHT$ # # Additional copyrights may follow @@ -969,24 +971,6 @@ OPAL_CHECK_BROKEN_QSORT # all: type of getsockopt optlen # all: type of recvfrom optlen -# -# Check out what thread support we have -# -OPAL_CONFIG_THREADS - -CFLAGS="$CFLAGS $THREAD_CFLAGS" -CPPFLAGS="$CPPFLAGS $THREAD_CPPFLAGS" -CXXFLAGS="$CXXFLAGS $THREAD_CXXFLAGS" -CXXCPPFLAGS="$CXXCPPFLAGS $THREAD_CXXCPPFLAGS" -LDFLAGS="$LDFLAGS $THREAD_LDFLAGS" -LIBS="$LIBS $THREAD_LIBS" - -OPAL_WRAPPER_FLAGS_ADD([CFLAGS], [$THREAD_CFLAGS]) -OPAL_WRAPPER_FLAGS_ADD([CXXFLAGS], [$THREAD_CXXFLAGS]) -OPAL_WRAPPER_FLAGS_ADD([FCFLAGS], [$THREAD_FCFLAGS]) -OPAL_WRAPPER_FLAGS_ADD([LDFLAGS], [$THREAD_LDFLAGS]) -# no need to update WRAPPER_EXTRA_LIBS - we'll get it from LT later - # # What is the local equivalent of "ln -s" # @@ -1144,6 +1128,14 @@ AC_MSG_RESULT([$opal_subdir_args]) OPAL_MCA +# +# Now that we know how to support threads with wrappers, update +# +OPAL_WRAPPER_FLAGS_ADD([CFLAGS], [$THREAD_CFLAGS]) +OPAL_WRAPPER_FLAGS_ADD([CXXFLAGS], [$THREAD_CXXFLAGS]) +OPAL_WRAPPER_FLAGS_ADD([FCFLAGS], [$THREAD_FCFLAGS]) +OPAL_WRAPPER_FLAGS_ADD([LDFLAGS], [$THREAD_LDFLAGS]) + m4_ifdef([project_ompi], [OMPI_REQUIRE_ENDPOINT_TAG_FINI]) # Last minute disable of OpenSHMEM if we didn't find any oshmem SPMLs diff --git a/opal/mca/threads/argobots/configure.m4 b/opal/mca/threads/argobots/configure.m4 index d23ce8c3b5a..1702bc307e0 100644 --- a/opal/mca/threads/argobots/configure.m4 +++ b/opal/mca/threads/argobots/configure.m4 @@ -15,6 +15,7 @@ # and Technology (RIST). All rights reserved. # Copyright (c) 2019 Sandia National Laboratories. All rights reserved. # Copyright (c) 2019 Triad National Security, LLC. All rights +# Reserved. # $COPYRIGHT$ # # Additional copyrights may follow @@ -34,6 +35,7 @@ AC_DEFUN([OPAL_CONFIG_ARGOBOTS_THREADS],[ [$2]) ])dnl + AC_DEFUN([MCA_opal_threads_argobots_PRIORITY], [30]) AC_DEFUN([MCA_opal_threads_argobots_COMPILE_MODE], [ @@ -42,23 +44,24 @@ AC_DEFUN([MCA_opal_threads_argobots_COMPILE_MODE], [ AC_MSG_RESULT([$$4]) ]) +# If component was selected, $1 will be 1 and we should set the base header AC_DEFUN([MCA_opal_threads_argobots_POST_CONFIG],[ - AS_IF([test "$1" = "1"], [threads_base_include="argobots/threads_argobots_threads.h"]) -])dnl - -AC_DEFUN([MCA_opal_mutex_argobots_POST_CONFIG],[ - AS_IF([test "$1" = "1"], [mutex_base_include="argobots/threads_argobots_mutex.h"]) - AC_MSG_CHECKING([mutex_base_include = $mutex_base_include]) -])dnl + AS_IF([test "$1" = "1"], + [opal_thread_type_found="argobots" + AC_DEFINE_UNQUOTED([MCA_threads_base_include_HEADER], + ["opal/mca/threads/argobots/threads_argobots_threads.h"], + [Header to include for threads implementation]) + AC_DEFINE_UNQUOTED([MCA_threads_mutex_base_include_HEADER], + ["opal/mca/threads/argobots/threads_argobots_mutex.h"], + [Header to include for mutex implementation]) + AC_DEFINE_UNQUOTED([MCA_threads_tsd_base_include_HEADER], + ["opal/mca/threads/argobots/threads_argobots_tsd.h"], + [Header to include for tsd implementation]) + AC_DEFINE_UNQUOTED([MCA_threads_wait_sync_base_include_HEADER], + ["opal/mca/threads/argobots/threads_argobots_wait_sync.h"], + [Header to include for wait_sync implementation]) + ]) -AC_DEFUN([MCA_opal_tsd_argobots_POST_CONFIG],[ - AS_IF([test "$1" = "1"], [threads_base_include="argobots/threads_argobots_tsd.h"]) - AC_MSG_CHECKING([threads_base_include = $threads_base_include]) -])dnl - -AC_DEFUN([MCA_opal_wait_sync_argobots_POST_CONFIG],[ - AS_IF([test "$1" = "1"], [wait_sync_base_include="argobots/threads_argobots_wait_sync.h"]) - AC_MSG_CHECKING([wait_sync_base_include = $wait_sync_base_include]) ])dnl # MCA_threads_argobots_CONFIG(action-if-can-compile, @@ -67,7 +70,12 @@ AC_DEFUN([MCA_opal_wait_sync_argobots_POST_CONFIG],[ AC_DEFUN([MCA_opal_threads_argobots_CONFIG],[ AC_CONFIG_FILES([opal/mca/threads/argobots/Makefile]) - AS_IF([test "$HAVE_THREAD_PKG_TYPE" = "argobots"], - [$1], + AS_IF([test "$with_threads" = "argobots"], + [OPAL_CONFIG_ARGOBOTS_THREADS([argobots_threads_works=1], [argobots_threads_works=0])], + [argobots_threads_works=0]) + + AS_IF([test "$argobots_threads_works" = "1"], + [$1 + opal_thread_type_found="argobots"], [$2]) ]) diff --git a/opal/mca/threads/configure.m4 b/opal/mca/threads/configure.m4 new file mode 100644 index 00000000000..dfe24cccd00 --- /dev/null +++ b/opal/mca/threads/configure.m4 @@ -0,0 +1,60 @@ +dnl -*- shell-script -*- +dnl +dnl Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana +dnl University Research and Technology +dnl Corporation. All rights reserved. +dnl Copyright (c) 2004-2005 The University of Tennessee and The University +dnl of Tennessee Research Foundation. All rights +dnl reserved. +dnl Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, +dnl University of Stuttgart. All rights reserved. +dnl Copyright (c) 2004-2005 The Regents of the University of California. +dnl All rights reserved. +dnl Copyright (c) 2010 Cisco Systems, Inc. All rights reserved. +dnl Copyright (c) 2019 Sandia National Laboratories. All rights reserved. +dnl Copyright (c) 2019 Triad National Security, LLC. All rights +dnl reserved. +dnl +dnl $COPYRIGHT$ +dnl +dnl Additional copyrights may follow +dnl +dnl $HEADER$ +dnl + +dnl we only want one :) +m4_define(MCA_opal_threads_CONFIGURE_MODE, STOP_AT_FIRST) + +AC_DEFUN([MCA_opal_threads_CONFIG],[ +# +# Arguments: none +# +# Dependencies: None +# +# Modifies: +# none - see called tests +# +# configure threads +# + +# +# First see what kind of threads we are going to use +# + +AC_ARG_WITH([threads], + [AC_HELP_STRING([--with-threads=TYPE], + [Specify thread TYPE to use. default:pthreads. Other options are qthreads and argobots.])]) + +# +# Configure components +# + +MCA_CONFIGURE_FRAMEWORK($1, $2, 1) + +AS_IF([test x"$opal_thread_type_found" = x""], + [AC_MSG_ERROR([Did not find a suitable threads component])]) + +AC_MSG_RESULT([Found thread type $opal_thread_type_found]) + +OPAL_SUMMARY_ADD([[Miscellaneous]],[[Threading Package]],[], [$opal_thread_type_found]) +])dnl diff --git a/opal/mca/threads/pthreads/configure.m4 b/opal/mca/threads/pthreads/configure.m4 index 63bedf6da5f..cb4345c3eed 100644 --- a/opal/mca/threads/pthreads/configure.m4 +++ b/opal/mca/threads/pthreads/configure.m4 @@ -664,9 +664,11 @@ if test "$opal_pthread_c_success" = "1" && \ test "$opal_pthread_cxx_success" = "1" && \ test "$opal_pthread_fortran_success" = "1"; then internal_useless=1 +AC_MSG_RESULT("looks like posix threads work") $1 else internal_useless=1 +AC_MSG_RESULT("looks like posix threads don't work") $2 fi @@ -682,23 +684,31 @@ AC_DEFUN([MCA_opal_threads_pthreads_COMPILE_MODE], [ AC_MSG_RESULT([$$4]) ]) -AC_DEFUN([MCA_opal_threads_pthreads_POST_CONFIG],[ - AS_IF([test "$1" = "1"], [threads_base_include="pthreads/threads_pthreads_threads.h"]) -])dnl - -AC_DEFUN([MCA_opal_mutex_pthreads_POST_CONFIG],[ - AS_IF([test "$1" = "1"], [mutex_base_include="pthreads/threads_pthreads_mutex.h"]) - AC_MSG_CHECKING([mutex_base_include = $mutex_base_include]) -])dnl -AC_DEFUN([MCA_opal_tsd_pthreads_POST_CONFIG],[ - AS_IF([test "$1" = "1"], [threads_base_include="pthreads/threads_pthreads_tsd.h"]) - AC_MSG_CHECKING([threads_base_include = $threads_base_include]) -])dnl - -AC_DEFUN([MCA_opal_wait_sync_pthreads_POST_CONFIG],[ - AS_IF([test "$1" = "1"], [wait_sync_base_include="pthreads/threads_pthreads_wait_sync.h"]) - AC_MSG_CHECKING([wait_sync_includenclude = $wait_sync_base_include]) +# If component was selected, $1 will be 1 and we should set the base header +AC_DEFUN([MCA_opal_threads_pthreads_POST_CONFIG],[ + AS_IF([test "$1" = "1"], + [opal_thread_type_found="pthreads" + AC_DEFINE_UNQUOTED([MCA_threads_base_include_HEADER], + ["opal/mca/threads/pthreads/threads_pthreads_threads.h"], + [Header to include for threads implementation]) + AC_DEFINE_UNQUOTED([MCA_threads_mutex_base_include_HEADER], + ["opal/mca/threads/pthreads/threads_pthreads_mutex.h"], + [Header to include for mutex implementation]) + AC_DEFINE_UNQUOTED([MCA_threads_tsd_base_include_HEADER], + ["opal/mca/threads/pthreads/threads_pthreads_tsd.h"], + [Header to include for tsd implementation]) + AC_DEFINE_UNQUOTED([MCA_threads_wait_sync_base_include_HEADER], + ["opal/mca/threads/pthreads/threads_pthreads_wait_sync.h"], + [Header to include for wait_sync implementation]) + THREAD_CFLAGS="$TPKG_CFLAGS" + THREAD_FCFLAGS="$TPKG_FCFLAGS" + THREAD_CXXFLAGS="$TPKG_CXXFLAGS" + THREAD_CPPFLAGS="$TPKG_CPPFLAGS" + THREAD_CXXCPPFLAGS="$TPKG_CXXCPPFLAGS" + THREAD_LDFLAGS="$TPKG_LDFLAGS" + THREAD_LIBS="$TPKG_LIBS" + ]) ])dnl # MCA_threads_pthreads_CONFIG(action-if-can-compile, @@ -707,8 +717,13 @@ AC_DEFUN([MCA_opal_wait_sync_pthreads_POST_CONFIG],[ AC_DEFUN([MCA_opal_threads_pthreads_CONFIG],[ AC_CONFIG_FILES([opal/mca/threads/pthreads/Makefile]) - AS_IF([test "$HAVE_THREAD_PKG_TYPE" = "pthreads"], + AS_IF([test -z "$with_threads" || test "$with_threads" = "pthreads" || test "$with_threads" = "yes"], + [OPAL_CONFIG_POSIX_THREADS([posix_threads_works=1],[posix_threads_works=0])], + [posix_threads_works=0]) + + AS_IF([test "$posix_threads_works" = "1"], [$1], [$2]) + AC_MSG_RESULT("posix_threads_works = $posix_threads_works") ]) diff --git a/opal/mca/threads/qthreads/configure.m4 b/opal/mca/threads/qthreads/configure.m4 index 801235fc6cd..cd9923ad23b 100644 --- a/opal/mca/threads/qthreads/configure.m4 +++ b/opal/mca/threads/qthreads/configure.m4 @@ -13,6 +13,9 @@ # Copyright (c) 2010 Cisco Systems, Inc. All rights reserved. # Copyright (c) 2015 Research Organization for Information Science # and Technology (RIST). All rights reserved. +# Copyright (c) 2019 Triad National Security, LLC. All rights +# reserved. +# # $COPYRIGHT$ # # Additional copyrights may follow @@ -41,17 +44,39 @@ AC_DEFUN([MCA_opal_threads_qthreads_COMPILE_MODE], [ AC_MSG_RESULT([$$4]) ]) +# If component was selected, $1 will be 1 and we should set the base header AC_DEFUN([MCA_opal_threads_qthreads_POST_CONFIG],[ - AS_IF([test "$1" = "1"], [threads_base_include="qthreads/threads_qthreads.h"]) + AS_IF([test "$1" = "1"], + [opal_thread_type_found="qthreads" + AC_DEFINE_UNQUOTED([MCA_threads_base_include_HEADER], + ["opal/mca/threads/qthreads/threads_qthreads.h"], + [Header to include for threads implementation]) + AC_DEFINE_UNQUOTED([MCA_threads_mutex_base_include_HEADER], + ["opal/mca/threads/qthreads/threads_qthreads_mutex.h"], + [Header to include for mutex implementation]) + AC_DEFINE_UNQUOTED([MCA_threads_tsd_base_include_HEADER], + ["opal/mca/threads/qthreads/threads_qthreads_tsd.h"], + [Header to include for tsd implementation]) + AC_DEFINE_UNQUOTED([MCA_threads_wait_sync_base_include_HEADER], + ["opal/mca/threads/qthreads/threads_qthreads_wait_sync.h"], + [Header to include for wait_sync implementation]) + ]) + ])dnl + # MCA_threads_qthreads_CONFIG(action-if-can-compile, # [action-if-cant-compile]) # ------------------------------------------------ AC_DEFUN([MCA_opal_threads_qthreads_CONFIG],[ AC_CONFIG_FILES([opal/mca/threads/qthreads/Makefile]) - AS_IF([test "$HAVE_THREAD_PKG_TYPE" = "qthreads"], - [$1], + AS_IF([test "$with_threads" = "qthreads"], + [OPAL_CONFIG_QTHREADS([qthreads_works=1],[qthreads_works=0])], + [qthreads_works=0]) + + AS_IF([test "$qthreads_works" = "1"], + [$1 + opal_thread_type_found="qthreads"], [$2]) ]) From 505d459330822a00807ee25891ec2c024ef9c725 Mon Sep 17 00:00:00 2001 From: Noah Evans Date: Tue, 24 Dec 2019 07:52:00 +0900 Subject: [PATCH 17/17] qthreads module --- opal/mca/threads/mutex.h | 2 +- opal/mca/threads/qthreads/configure.m4 | 7 +- opal/mca/threads/qthreads/threads_qthreads.h | 36 +++ .../qthreads/threads_qthreads_module.c | 1 + .../threads/qthreads/threads_qthreads_mutex.h | 245 ++++++++++++++++++ .../qthreads/threads_qthreads_threads.h | 40 +++ .../threads/qthreads/threads_qthreads_tsd.h | 55 ++++ .../qthreads/threads_qthreads_wait_sync.h | 112 ++++++++ opal/mca/threads/tsd.h | 2 +- 9 files changed, 494 insertions(+), 6 deletions(-) create mode 100644 opal/mca/threads/qthreads/threads_qthreads.h create mode 100644 opal/mca/threads/qthreads/threads_qthreads_mutex.h create mode 100644 opal/mca/threads/qthreads/threads_qthreads_threads.h create mode 100644 opal/mca/threads/qthreads/threads_qthreads_tsd.h create mode 100644 opal/mca/threads/qthreads/threads_qthreads_wait_sync.h diff --git a/opal/mca/threads/mutex.h b/opal/mca/threads/mutex.h index a81e94cb6e8..598219b24e0 100644 --- a/opal/mca/threads/mutex.h +++ b/opal/mca/threads/mutex.h @@ -46,7 +46,7 @@ BEGIN_C_DECLS typedef struct opal_mutex_t opal_mutex_t; typedef struct opal_mutex_t opal_recursive_mutex_t; -#include MCA_threads_mutex_base_include_HEADER +#include "opal/mca/threads/qthreads/threads_qthreads_mutex.h" OBJ_CLASS_DECLARATION(opal_mutex_t); OBJ_CLASS_DECLARATION(opal_recursive_mutex_t); diff --git a/opal/mca/threads/qthreads/configure.m4 b/opal/mca/threads/qthreads/configure.m4 index cd9923ad23b..7248ad4d708 100644 --- a/opal/mca/threads/qthreads/configure.m4 +++ b/opal/mca/threads/qthreads/configure.m4 @@ -25,8 +25,8 @@ AC_DEFUN([OPAL_CONFIG_QTHREADS],[ - AC_CHECK_HEADERS([mach/mach_time.h], - [AC_CHECK_FUNC([mach_absolute_time], + AC_CHECK_HEADERS([qthread/qthread.h], + [AC_CHECK_LIB([qthread],[qthread_initialize], [threads_qthreads_happy="yes"], [threads_qthreads_happy="no"])], [threads_qthreads_happy="no"]) @@ -49,7 +49,7 @@ AC_DEFUN([MCA_opal_threads_qthreads_POST_CONFIG],[ AS_IF([test "$1" = "1"], [opal_thread_type_found="qthreads" AC_DEFINE_UNQUOTED([MCA_threads_base_include_HEADER], - ["opal/mca/threads/qthreads/threads_qthreads.h"], + ["opal/mca/threads/qthreads/threads_qthreads_threads.h"], [Header to include for threads implementation]) AC_DEFINE_UNQUOTED([MCA_threads_mutex_base_include_HEADER], ["opal/mca/threads/qthreads/threads_qthreads_mutex.h"], @@ -61,7 +61,6 @@ AC_DEFUN([MCA_opal_threads_qthreads_POST_CONFIG],[ ["opal/mca/threads/qthreads/threads_qthreads_wait_sync.h"], [Header to include for wait_sync implementation]) ]) - ])dnl diff --git a/opal/mca/threads/qthreads/threads_qthreads.h b/opal/mca/threads/qthreads/threads_qthreads.h new file mode 100644 index 00000000000..202758d65a6 --- /dev/null +++ b/opal/mca/threads/qthreads/threads_qthreads.h @@ -0,0 +1,36 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ +/* + * 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. + * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, + * University of Stuttgart. All rights reserved. + * Copyright (c) 2004-2005 The Regents of the University of California. + * All rights reserved. + * Copyright (c) 2007-2016 Los Alamos National Security, LLC. All rights + * reserved. + * Copyright (c) 2015 Research Organization for Information Science + * and Technology (RIST). All rights reserved. + * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. + * + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + +#ifndef OPAL_MCA_THREADS_QTHREADS_THREADS_QTHREADS_H +#define OPAL_MCA_THREADS_QTHREADS_THREADS_QTHREADS_H 1 + +#include + +static inline void ensure_init_qthreads(void) { + if (qthread_initialize() != 0) + qthread_initialize(); +} + +#endif /* OPAL_MCA_THREADS_QTHREADS_THREADS_QTHREADS_H */ diff --git a/opal/mca/threads/qthreads/threads_qthreads_module.c b/opal/mca/threads/qthreads/threads_qthreads_module.c index 392a73638af..a057660f91b 100644 --- a/opal/mca/threads/qthreads/threads_qthreads_module.c +++ b/opal/mca/threads/qthreads/threads_qthreads_module.c @@ -21,6 +21,7 @@ #include +#include "opal/mca/threads/qthreads/threads_qthreads.h" #include "opal/constants.h" #include "opal/util/sys_limits.h" #include "opal/util/output.h" diff --git a/opal/mca/threads/qthreads/threads_qthreads_mutex.h b/opal/mca/threads/qthreads/threads_qthreads_mutex.h new file mode 100644 index 00000000000..2ba56f3d8d1 --- /dev/null +++ b/opal/mca/threads/qthreads/threads_qthreads_mutex.h @@ -0,0 +1,245 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ +/* + * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana + * University Research and Technology + * Corporation. All rights reserved. + * Copyright (c) 2004-2006 The University of Tennessee and The University + * of Tennessee Research Foundation. All rights + * reserved. + * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, + * University of Stuttgart. All rights reserved. + * Copyright (c) 2004-2005 The Regents of the University of California. + * All rights reserved. + * Copyright (c) 2007-2018 Los Alamos National Security, LLC. All rights + * reserved. + * Copyright (c) 2015-2016 Research Organization for Information Science + * and Technology (RIST). All rights reserved. + * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. + * + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + +#ifndef OPAL_MCA_THREADS_QTHREADS_THREADS_QTHREADS_MUTEX_H +#define OPAL_MCA_THREADS_QTHREADS_THREADS_QTHREADS_MUTEX_H 1 + +/** + * @file: + * + * Mutual exclusion functions: Unix implementation. + * + * Functions for locking of critical sections. + * + * On unix, use Argobots or our own atomic operations as + * available. + */ + +#include "opal/mca/threads/qthreads/threads_qthreads.h" +#include "opal_config.h" + +#include +#include + +#include "opal/class/opal_object.h" +#include "opal/sys/atomic.h" + +#include + +BEGIN_C_DECLS + +struct opal_mutex_t { + opal_object_t super; + + aligned_t m_lock_qthreads; + int m_recursive; + +#if OPAL_ENABLE_DEBUG + int m_lock_debug; + const char *m_lock_file; + int m_lock_line; +#endif + + opal_atomic_lock_t m_lock_atomic; +}; + +typedef aligned_t opal_qthreads_mutex_t; + +OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_mutex_t); +OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_recursive_mutex_t); + +#if OPAL_ENABLE_DEBUG +#define OPAL_MUTEX_STATIC_INIT \ + { \ + .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), \ + .m_lock_qthreads = 0, \ + .m_recursive = 0, \ + .m_lock_debug = 0, \ + .m_lock_file = NULL, \ + .m_lock_line = 0, \ + .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \ + } +#else +#define OPAL_MUTEX_STATIC_INIT \ + { \ + .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), \ + .m_lock_qthreads = 0, \ + .m_recursive = 0, \ + .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \ + } +#endif + +#define OPAL_RECURSIVE_MUTEX_STATIC_INIT \ + { \ + .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), \ + .m_lock_qthreads = 0, \ + .m_recursive = 1, \ + .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \ + } +#endif + +/************************************************************************ + * + * mutex operations (non-atomic versions) + * + ************************************************************************/ + +static inline void opal_mutex_create(struct opal_mutex_t *m) { +} + +static inline int opal_mutex_trylock(opal_mutex_t *m) +{ + ensure_init_qthreads(); + +#if OPAL_ENABLE_DEBUG + int ret = qthread_readFE_nb(NULL, &m->m_lock_qthreads); + if (ret != 0) { + errno = ret; + perror("opal_mutex_trylock()"); + abort(); + } + return ret; +#else + return qthread_readFE_nb(NULL, &m->m_lock_qthreads); +#endif +} + +static inline void opal_mutex_lock(opal_mutex_t *m) +{ + ensure_init_qthreads(); +#if OPAL_ENABLE_DEBUG + int ret = qthread_lock(&m->m_lock_qthreads); + if (ret != 0) { + errno = ret; + perror("opal_mutex_lock()"); + abort(); + } +#else + qthread_lock(&m->m_lock_qthreads); +#endif +} + +static inline void opal_mutex_unlock(opal_mutex_t *m) +{ + ensure_init_qthreads(); + +#if OPAL_ENABLE_DEBUG + int ret = qthread_unlock(&m->m_lock_qthreads); + if (ret != 0) { + errno = ret; + perror("opal_mutex_unlock"); + abort(); + } +#else + qthread_unlock(&m->m_lock_qthreads); +#endif + /* For fairness of locking. */ + qthread_yield(); +} + +/************************************************************************ + * + * mutex operations (atomic versions) + * + ************************************************************************/ + +#if OPAL_HAVE_ATOMIC_SPINLOCKS + +/************************************************************************ + * Spin Locks + ************************************************************************/ + +static inline int opal_mutex_atomic_trylock(opal_mutex_t *m) +{ + return opal_atomic_trylock(&m->m_lock_atomic); +} + +static inline void opal_mutex_atomic_lock(opal_mutex_t *m) +{ + opal_atomic_lock(&m->m_lock_atomic); +} + +static inline void opal_mutex_atomic_unlock(opal_mutex_t *m) +{ + opal_atomic_unlock(&m->m_lock_atomic); +} + +#else + +/************************************************************************ + * Standard locking + ************************************************************************/ + +static inline int opal_mutex_atomic_trylock(opal_mutex_t *m) +{ + return opal_mutex_trylock(m); +} + +static inline void opal_mutex_atomic_lock(opal_mutex_t *m) +{ + opal_mutex_lock(m); +} + +static inline void opal_mutex_atomic_unlock(opal_mutex_t *m) +{ + opal_mutex_unlock(m); +} + +#endif + +typedef aligned_t* opal_cond_t; +#define OPAL_CONDITION_STATIC_INIT 0 + +static inline void opal_cond_create(opal_cond_t *cond) { + ensure_init_qthreads(); +} + +static inline int opal_cond_init(opal_cond_t *cond) { + return 0; +} + +static inline int opal_cond_wait(opal_cond_t *cond, opal_mutex_t *lock) { + ensure_init_qthreads(); + return qthread_readFE(*cond, &lock->m_lock_qthreads); +} + +static inline int opal_cond_broadcast(opal_cond_t *cond) { + ensure_init_qthreads(); + return qthread_fill(*cond); +} + +static inline int opal_cond_signal(opal_cond_t *cond) { + ensure_init_qthreads(); + return qthread_fill(*cond); +} + +static inline int opal_cond_destroy(opal_cond_t *cond) { + ensure_init_qthreads(); + return 0; +} + +END_C_DECLS + +//#endif /* OPAL_MCA_THREADS_QTHREADS_THREADS_QTHREADS_MUTEX_H */ diff --git a/opal/mca/threads/qthreads/threads_qthreads_threads.h b/opal/mca/threads/qthreads/threads_qthreads_threads.h new file mode 100644 index 00000000000..1c0d225a472 --- /dev/null +++ b/opal/mca/threads/qthreads/threads_qthreads_threads.h @@ -0,0 +1,40 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ +/* + * 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. + * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, + * University of Stuttgart. All rights reserved. + * Copyright (c) 2004-2005 The Regents of the University of California. + * All rights reserved. + * Copyright (c) 2007-2016 Los Alamos National Security, LLC. All rights + * reserved. + * Copyright (c) 2015 Research Organization for Information Science + * and Technology (RIST). All rights reserved. + * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. + * + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + +#ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_THREADS_H +#define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_THREADS_H 1 + +#include +#include + +struct opal_thread_t { + opal_object_t super; + opal_thread_fn_t t_run; + void* t_arg; + unsigned* t_handle; + void* t_ret; +}; + +#endif /* OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_THREADS_H */ diff --git a/opal/mca/threads/qthreads/threads_qthreads_tsd.h b/opal/mca/threads/qthreads/threads_qthreads_tsd.h new file mode 100644 index 00000000000..956d4f3a70b --- /dev/null +++ b/opal/mca/threads/qthreads/threads_qthreads_tsd.h @@ -0,0 +1,55 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ +/* + * 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. + * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, + * University of Stuttgart. All rights reserved. + * Copyright (c) 2004-2005 The Regents of the University of California. + * All rights reserved. + * Copyright (c) 2007-2016 Los Alamos National Security, LLC. All rights + * reserved. + * Copyright (c) 2015 Research Organization for Information Science + * and Technology (RIST). All rights reserved. + * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. + * + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + + +#ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_TSD_H +#define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_TSD_H 1 + +#include "opal/mca/threads/qthreads/threads_qthreads.h" +#include +#include + +typedef qthread_key_t opal_tsd_key_t; + +static inline int +opal_tsd_key_delete(opal_tsd_key_t key) +{ + return qthread_key_delete(&key); +} + +static inline int +opal_tsd_setspecific(opal_tsd_key_t key, void *value) +{ + return qthread_setspecific(key, value); +} + +static inline int +opal_tsd_getspecific(opal_tsd_key_t key, void **valuep) +{ + qthread_getspecific(key); + return OPAL_SUCCESS; +} + +#endif /* OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_TSD_H */ diff --git a/opal/mca/threads/qthreads/threads_qthreads_wait_sync.h b/opal/mca/threads/qthreads/threads_qthreads_wait_sync.h new file mode 100644 index 00000000000..b9d5041294f --- /dev/null +++ b/opal/mca/threads/qthreads/threads_qthreads_wait_sync.h @@ -0,0 +1,112 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ +/* + * 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. + * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, + * University of Stuttgart. All rights reserved. + * Copyright (c) 2004-2005 The Regents of the University of California. + * All rights reserved. + * Copyright (c) 2007-2016 Los Alamos National Security, LLC. All rights + * reserved. + * Copyright (c) 2015 Research Organization for Information Science + * and Technology (RIST). All rights reserved. + * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. + * + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + + +#ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_WAIT_SYNC_H +#define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_WAIT_SYNC_H 1 + +#include "opal/mca/threads/argobots/threads_argobots.h" +#include + +typedef struct ompi_wait_sync_t { + opal_atomic_int32_t count; + int32_t status; + ABT_cond condition; + ABT_mutex lock; + struct ompi_wait_sync_t *next; + struct ompi_wait_sync_t *prev; + volatile bool signaling; +} ompi_wait_sync_t; + +#define SYNC_WAIT(sync) (opal_using_threads() ? ompi_sync_wait_mt (sync) : sync_wait_st (sync)) + +/* The loop in release handles a race condition between the signaling + * thread and the destruction of the condition variable. The signaling + * member will be set to false after the final signaling thread has + * finished operating on the sync object. This is done to avoid + * extra atomics in the signalling function and keep it as fast + * as possible. Note that the race window is small so spinning here + * is more optimal than sleeping since this macro is called in + * the critical path. */ +#define WAIT_SYNC_RELEASE(sync) \ + if (opal_using_threads()) { \ + ensure_init_argobots(); \ + while ((sync)->signaling) { \ + ABT_thread_yield(); \ + continue; \ + } \ + ABT_cond_free(&(sync)->condition); \ + ABT_mutex_free(&(sync)->lock); \ + } + +#define WAIT_SYNC_RELEASE_NOWAIT(sync) \ + if (opal_using_threads()) { \ + ensure_init_argobots(); \ + ABT_cond_free(&(sync)->condition); \ + ABT_mutex_free(&(sync)->lock); \ + } + + +#define WAIT_SYNC_SIGNAL(sync) \ + if (opal_using_threads()) { \ + ensure_init_argobots(); \ + ABT_mutex_lock(sync->lock); \ + ABT_cond_signal(sync->condition); \ + ABT_mutex_unlock(sync->lock); \ + sync->signaling = false; \ + } + +#define WAIT_SYNC_SIGNALLED(sync){ \ + (sync)->signaling = false; \ +} + +OPAL_DECLSPEC int ompi_sync_wait_mt(ompi_wait_sync_t *sync); +static inline int sync_wait_st (ompi_wait_sync_t *sync) +{ + ensure_init_argobots(); + while (sync->count > 0) { + opal_progress(); + ABT_thread_yield(); + } + + return sync->status; +} + + +#define WAIT_SYNC_INIT(sync,c) \ + do { \ + (sync)->count = (c); \ + (sync)->next = NULL; \ + (sync)->prev = NULL; \ + (sync)->status = 0; \ + (sync)->signaling = (0 != (c)); \ + if (opal_using_threads()) { \ + ensure_init_argobots(); \ + ABT_cond_create (&(sync)->condition); \ + ABT_mutex_create (&(sync)->lock); \ + } \ + } while(0) + +#endif /* OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_WAIT_SYNC_H */ diff --git a/opal/mca/threads/tsd.h b/opal/mca/threads/tsd.h index f05d0747a96..032def83ad6 100644 --- a/opal/mca/threads/tsd.h +++ b/opal/mca/threads/tsd.h @@ -109,7 +109,7 @@ OPAL_DECLSPEC int opal_tsd_getspecific(opal_tsd_key_t key, void **valuep); #else -#include MCA_threads_tsd_base_include_HEADER +#include "opal/mca/threads/qthreads/threads_qthreads_tsd.h" #endif