From 162715982376dd8a26baa7fd0e9422dbab701811 Mon Sep 17 00:00:00 2001 From: Artem Polyakov Date: Thu, 13 Jun 2019 18:24:54 -0700 Subject: [PATCH] First step towards MT support 1. Add arch directory with required atomics implementations (for ARM64, PPC and x86_64). TODO: add other architectures later. 2. Add a thread-safe list that will be used for tracking TLS objects. 3. Update Makefile.in to build thread-safe list 4. Add stubs for mpiP threads support Signed-off-by: Artem Polyakov --- Makefile.in | 1 + arch/arch.h | 92 +++++++++++++++++++++++++ arch/arch_arm64.h | 146 +++++++++++++++++++++++++++++++++++++++ arch/arch_ppc.h | 127 ++++++++++++++++++++++++++++++++++ arch/arch_x86_64.h | 111 ++++++++++++++++++++++++++++++ mpiP-threads.c | 0 mpiP-threads.h | 9 +++ mpiP-tslist.c | 167 +++++++++++++++++++++++++++++++++++++++++++++ mpiP-tslist.h | 106 ++++++++++++++++++++++++++++ 9 files changed, 759 insertions(+) create mode 100644 arch/arch.h create mode 100644 arch/arch_arm64.h create mode 100644 arch/arch_ppc.h create mode 100644 arch/arch_x86_64.h create mode 100644 mpiP-threads.c create mode 100644 mpiP-threads.h create mode 100644 mpiP-tslist.c create mode 100644 mpiP-tslist.h diff --git a/Makefile.in b/Makefile.in index d798589..a124b69 100644 --- a/Makefile.in +++ b/Makefile.in @@ -36,6 +36,7 @@ PC_LOOKUP_OBJ = $(PC_LOOKUP_FILE:.c=.o) SRCS = diag_msgs.c \ mpiP-hash.c \ mpiP-stats.c \ + mpiP-tslist.c \ glob.c \ wrappers.c \ wrappers_special.c \ diff --git a/arch/arch.h b/arch/arch.h new file mode 100644 index 0000000..52dd4b5 --- /dev/null +++ b/arch/arch.h @@ -0,0 +1,92 @@ +/* -*- C -*- + + mpiP MPI Profiler ( http://llnl.github.io/mpiP ) + + Please see COPYRIGHT AND LICENSE information at the end of this file. + + ----- + + arch.h -- architecture-specific code and definitions + + */ + +#ifndef ARCH_ATOMICS_H +#define ARCH_ATOMICS_H + +#ifdef __x86_64__ +#include "arch/arch_x86_64.h" +#elif __ppc64__ || __ppc__ +#include "arch/arch_ppc.h" +#elif __aarch64__ +#include "arch/arch_arm64.h" +#endif + +#endif // ARCH_ATOMICS_H + + +/* + + + +Copyright (c) 2019 Mellanox Technologies Ltd. +Written by Artem Polyakov +All rights reserved. + +This file is part of mpiP. For details, see http://llnl.github.io/mpiP. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +* Redistributions of source code must retain the above copyright +notice, this list of conditions and the disclaimer below. + +* Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the disclaimer (as noted below) in +the documentation and/or other materials provided with the +distribution. + +* Neither the name of the UC/LLNL nor the names of its contributors +may be used to endorse or promote products derived from this software +without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OF +THE UNIVERSITY OF CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY OR +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +Additional BSD Notice + +1. This notice is required to be provided under our contract with the +U.S. Department of Energy (DOE). This work was produced at the +University of California, Lawrence Livermore National Laboratory under +Contract No. W-7405-ENG-48 with the DOE. + +2. Neither the United States Government nor the University of +California nor any of their employees, makes any warranty, express or +implied, or assumes any liability or responsibility for the accuracy, +completeness, or usefulness of any information, apparatus, product, or +process disclosed, or represents that its use would not infringe +privately-owned rights. + +3. Also, reference herein to any specific commercial products, +process, or services by trade name, trademark, manufacturer or +otherwise does not necessarily constitute or imply its endorsement, +recommendation, or favoring by the United States Government or the +University of California. The views and opinions of authors expressed +herein do not necessarily state or reflect those of the United States +Government or the University of California, and shall not be used for +advertising or product endorsement purposes. + + + +*/ diff --git a/arch/arch_arm64.h b/arch/arch_arm64.h new file mode 100644 index 0000000..00d62f2 --- /dev/null +++ b/arch/arch_arm64.h @@ -0,0 +1,146 @@ +/* -*- C -*- + + mpiP MPI Profiler ( http://llnl.github.io/mpiP ) + + Please see COPYRIGHT AND LICENSE information at the end of this file. + + ----- + + arch.h -- code and definitions specific to ARM64 architecture + + */ + +#ifndef ARCH_ARM64_H +#define ARCH_ARM64_H + +#define MB() __asm__ __volatile__ ("dmb sy" : : : "memory") +#define RMB() __asm__ __volatile__ ("dmb ld" : : : "memory") +#define WMB() __asm__ __volatile__ ("dmb st" : : : "memory") + +static inline void opal_atomic_wmb (void) +{ + WMB(); +} + +static inline void opal_atomic_isync (void) +{ + __asm__ __volatile__ ("isb"); +} + +static inline int64_t _mpiP_atomic_swap_ldst(int64_t *addr, int64_t newval) +{ + int64_t ret; + int tmp; + + __asm__ __volatile__ ("1: ldaxr %0, [%2] \n" + " stlxr %w1, %3, [%2] \n" + " cbnz %w1, 1b \n" + : "=&r" (ret), "=&r" (tmp) + : "r" (addr), "r" (newval) + : "cc", "memory"); + + return ret; +} + +static inline int64_t _mpiP_atomic_swap_lse(int64_t *addr, int64_t newval) +{ + int64_t ret; + int tmp; + + __asm__ __volatile__ ("swpl %2, %0, [%1]\n" + : "=&r" (ret) + : "r" (addr), "r" (newval) + : "cc", "memory"); + return ret; +} + +/* TODO: Detect the support for LSE extentions */ +static inline int64_t mpiP_atomic_swap(int64_t *addr, int64_t newval) +{ + return _mpiP_atomic_swap_lse(addr, newval); +} + +#endif + + +/* + + + +This code was derived from Open MPI OPAL layer. + +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 IBM Corporation. All rights reserved. +Copyright (c) 2010 ARM ltd. All rights reserved. +Copyright (c) 2016-2018 Los Alamos National Security, LLC. All rights + reserved. +Copyright (c) 2019 Mellanox Technologies Ltd. All rights reserved. + +This file is part of mpiP. For details, see http://llnl.github.io/mpiP. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +* Redistributions of source code must retain the above copyright +notice, this list of conditions and the disclaimer below. + +* Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the disclaimer (as noted below) in +the documentation and/or other materials provided with the +distribution. + +* Neither the name of the UC/LLNL nor the names of its contributors +may be used to endorse or promote products derived from this software +without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OF +THE UNIVERSITY OF CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY OR +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +Additional BSD Notice + +1. This notice is required to be provided under our contract with the +U.S. Department of Energy (DOE). This work was produced at the +University of California, Lawrence Livermore National Laboratory under +Contract No. W-7405-ENG-48 with the DOE. + +2. Neither the United States Government nor the University of +California nor any of their employees, makes any warranty, express or +implied, or assumes any liability or responsibility for the accuracy, +completeness, or usefulness of any information, apparatus, product, or +process disclosed, or represents that its use would not infringe +privately-owned rights. + +3. Also, reference herein to any specific commercial products, +process, or services by trade name, trademark, manufacturer or +otherwise does not necessarily constitute or imply its endorsement, +recommendation, or favoring by the United States Government or the +University of California. The views and opinions of authors expressed +herein do not necessarily state or reflect those of the United States +Government or the University of California, and shall not be used for +advertising or product endorsement purposes. + + + +*/ + diff --git a/arch/arch_ppc.h b/arch/arch_ppc.h new file mode 100644 index 0000000..f46550d --- /dev/null +++ b/arch/arch_ppc.h @@ -0,0 +1,127 @@ +/* -*- C -*- + + mpiP MPI Profiler ( http://llnl.github.io/mpiP ) + + Please see COPYRIGHT AND LICENSE information at the end of this file. + + ----- + + arch.h -- code and definitions specific to POWER architecture + + */ + +#ifndef ARCH_PPC_H +#define ARCH_PPC_H + +#define MB() __asm__ __volatile__ ("sync" : : : "memory") +#define RMB() __asm__ __volatile__ ("lwsync" : : : "memory") +#define WMB() __asm__ __volatile__ ("lwsync" : : : "memory") +#define ISYNC() __asm__ __volatile__ ("isync" : : : "memory") + +static inline +void mpiP_atomic_wmb(void) +{ + WMB(); +} + +static inline +void opal_atomic_isync(void) +{ + ISYNC(); +} + +static inline int64_t mpiP_atomic_swap(int64_t *addr, int64_t newval) +{ + int64_t ret; + + __asm__ __volatile__ ("1: ldarx %0, 0, %2 \n\t" + " stdcx. %3, 0, %2 \n\t" + " bne- 1b \n\t" + : "=&r" (ret), "=m" (*addr) + : "r" (addr), "r" (OPAL_ASM_VALUE64(newval)) + : "cc", "memory"); + + return ret; +} + +#endif + +/* + + + +This code was derived from Open MPI OPAL layer. + +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-2017 IBM Corporation. All rights reserved. +Copyright (c) 2015-2018 Los Alamos National Security, LLC. All rights + reserved. +Copyright (c) 2019 Mellanox Technologies Ltd. All rights reserved. + +This file is part of mpiP. For details, see http://llnl.github.io/mpiP. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +* Redistributions of source code must retain the above copyright +notice, this list of conditions and the disclaimer below. + +* Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the disclaimer (as noted below) in +the documentation and/or other materials provided with the +distribution. + +* Neither the name of the UC/LLNL nor the names of its contributors +may be used to endorse or promote products derived from this software +without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OF +THE UNIVERSITY OF CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY OR +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +Additional BSD Notice + +1. This notice is required to be provided under our contract with the +U.S. Department of Energy (DOE). This work was produced at the +University of California, Lawrence Livermore National Laboratory under +Contract No. W-7405-ENG-48 with the DOE. + +2. Neither the United States Government nor the University of +California nor any of their employees, makes any warranty, express or +implied, or assumes any liability or responsibility for the accuracy, +completeness, or usefulness of any information, apparatus, product, or +process disclosed, or represents that its use would not infringe +privately-owned rights. + +3. Also, reference herein to any specific commercial products, +process, or services by trade name, trademark, manufacturer or +otherwise does not necessarily constitute or imply its endorsement, +recommendation, or favoring by the United States Government or the +University of California. The views and opinions of authors expressed +herein do not necessarily state or reflect those of the United States +Government or the University of California, and shall not be used for +advertising or product endorsement purposes. + + + +*/ diff --git a/arch/arch_x86_64.h b/arch/arch_x86_64.h new file mode 100644 index 0000000..9aaf602 --- /dev/null +++ b/arch/arch_x86_64.h @@ -0,0 +1,111 @@ +#ifndef ARCH_X86_64_H +#define ARCH_X86_64_H + +#include + +#define MB() __asm__ __volatile__("": : :"memory") + +static inline void mpiP_atomic_wmb(void) +{ + MB(); +} + +static inline void mpiP_atomic_isync(void) +{ +} + +static inline int64_t mpiP_atomic_swap(int64_t *addr, int64_t newval) +{ + int64_t oldval; + + __asm__ __volatile__("xchgq %1, %0" : + "=r" (oldval), "+m" (*addr) : + "0" (newval) : + "memory"); + return oldval; +} + +#endif + + +/* + + + +This code was derived from Open MPI OPAL layer. + +Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana + University Research and Technology + Corporation. All rights reserved. +Copyright (c) 2004-2010 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 Sun Microsystems, Inc. All rights reserverd. +Copyright (c) 2012-2018 Los Alamos National Security, LLC. All rights + reserved. +Copyright (c) 2016-2017 Research Organization for Information Science + and Technology (RIST). All rights reserved. +Copyright (c) 2019 Mellanox Technologies Ltd. All rights reserved. + +This file is part of mpiP. For details, see http://llnl.github.io/mpiP. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +* Redistributions of source code must retain the above copyright +notice, this list of conditions and the disclaimer below. + +* Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the disclaimer (as noted below) in +the documentation and/or other materials provided with the +distribution. + +* Neither the name of the UC/LLNL nor the names of its contributors +may be used to endorse or promote products derived from this software +without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OF +THE UNIVERSITY OF CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY OR +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +Additional BSD Notice + +1. This notice is required to be provided under our contract with the +U.S. Department of Energy (DOE). This work was produced at the +University of California, Lawrence Livermore National Laboratory under +Contract No. W-7405-ENG-48 with the DOE. + +2. Neither the United States Government nor the University of +California nor any of their employees, makes any warranty, express or +implied, or assumes any liability or responsibility for the accuracy, +completeness, or usefulness of any information, apparatus, product, or +process disclosed, or represents that its use would not infringe +privately-owned rights. + +3. Also, reference herein to any specific commercial products, +process, or services by trade name, trademark, manufacturer or +otherwise does not necessarily constitute or imply its endorsement, +recommendation, or favoring by the United States Government or the +University of California. The views and opinions of authors expressed +herein do not necessarily state or reflect those of the United States +Government or the University of California, and shall not be used for +advertising or product endorsement purposes. + + + +*/ diff --git a/mpiP-threads.c b/mpiP-threads.c new file mode 100644 index 0000000..e69de29 diff --git a/mpiP-threads.h b/mpiP-threads.h new file mode 100644 index 0000000..ef711e5 --- /dev/null +++ b/mpiP-threads.h @@ -0,0 +1,9 @@ +#ifndef MPIP_THREADS_H +#define MPIP_THREADS_H + +#include "mpiPi_def.h" +#include "mpiP-tslist.h" +#include "mpiP-hash.h" +#include "mpiP-statistics.h" + +#endif // MPIP_THREADS_H diff --git a/mpiP-tslist.c b/mpiP-tslist.c new file mode 100644 index 0000000..5dbe41f --- /dev/null +++ b/mpiP-tslist.c @@ -0,0 +1,167 @@ +/* -*- C -*- + + mpiP MPI Profiler ( http://llnl.github.io/mpiP ) + + Please see COPYRIGHT AND LICENSE information at the end of this file. + + ----- + + thread_safe_list.c -- Implementation of the thread-safe list based on atomics + NOTE: only one thread is allowed to extract elements, but many can contribute. + This fits perfectly fine with the purpose of holding TLS pointers in mpiP. + + */ + +#include +#include +#include +#include "arch/arch.h" +#include "mpiP-tslist.h" + +mpiP_tslist_t *mpiPi_tslist_create() +{ + mpiP_tslist_t *list = calloc(1, sizeof(*list)); + if( NULL == list ) { + return NULL; + } + list->head = calloc(1, sizeof(*list->head)); + list->tail = list->head; + return list; +} +void mpiPi_tslist_release(mpiP_tslist_t *list) +{ + free(list->head); + list->head = list->tail = NULL; + free(list); +} + +void mpiPi_tslist_append(mpiP_tslist_t *list, mpiP_tslist_elem_t *elem) +{ + elem->next = NULL; + /* Ensure that all chnages to the elem structure are complete *///// + mpiP_atomic_wmb(); + /* Atomically swap the tail of the list to point to this element */ + mpiP_tslist_elem_t *prev = (mpiP_tslist_elem_t*)mpiP_atomic_swap((uint64_t*)&list->tail, (uint64_t)elem); + prev->next = elem; +} + +void mpiPi_tslist_dequeue(mpiP_tslist_t *list, mpiP_tslist_elem_t **_elem) +{ + *_elem = NULL; + if( list->head == list->tail ){ + // the list is empty + return; + } + + if(list->head->next == NULL ){ + // Someone is adding a new element, but it is not yet ready + return; + } + + mpiP_tslist_elem_t *elem = list->head->next; + if( elem->next ) { + /* We have more than one elements in the list + * it is safe to dequeue this elemen as only one thread + * is allowed to dequeue + */ + list->head->next = elem->next; + *_elem = elem; + /* Terminate element */ + elem->next = NULL; + return; + } + + mpiP_tslist_elem_t *iter; + /* requeue the dummy element to make sure that no one is adding currently */ + mpiPi_tslist_append(list, list->head); + iter = elem; + while(iter->next != list->head) { + mpiP_atomic_isync(); + if((volatile void*)iter->next) { + iter = iter->next; + } + } + /* Terminate the extracted chain */ + iter->next = NULL; + *_elem = elem; +} + +mpiP_tslist_elem_t *mpiPi_tslist_first(mpiP_tslist_t *list) +{ + return list->head->next; +} + +mpiP_tslist_elem_t *mpiPi_tslist_next(mpiP_tslist_elem_t *current) +{ + return current->next; +} + +/* + + + +Derived from +https://github.com/artpol84/poc/blob/master/arch/concurrency/thread-safe_list + +Copyright (c) 2019 Mellanox Technologies Ltd. +Written by Artem Polyakov +All rights reserved. + +This file is part of mpiP. For details, see http://llnl.github.io/mpiP. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +* Redistributions of source code must retain the above copyright +notice, this list of conditions and the disclaimer below. + +* Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the disclaimer (as noted below) in +the documentation and/or other materials provided with the +distribution. + +* Neither the name of the UC/LLNL nor the names of its contributors +may be used to endorse or promote products derived from this software +without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OF +THE UNIVERSITY OF CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY OR +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +Additional BSD Notice + +1. This notice is required to be provided under our contract with the +U.S. Department of Energy (DOE). This work was produced at the +University of California, Lawrence Livermore National Laboratory under +Contract No. W-7405-ENG-48 with the DOE. + +2. Neither the United States Government nor the University of +California nor any of their employees, makes any warranty, express or +implied, or assumes any liability or responsibility for the accuracy, +completeness, or usefulness of any information, apparatus, product, or +process disclosed, or represents that its use would not infringe +privately-owned rights. + +3. Also, reference herein to any specific commercial products, +process, or services by trade name, trademark, manufacturer or +otherwise does not necessarily constitute or imply its endorsement, +recommendation, or favoring by the United States Government or the +University of California. The views and opinions of authors expressed +herein do not necessarily state or reflect those of the United States +Government or the University of California, and shall not be used for +advertising or product endorsement purposes. + + + +*/ diff --git a/mpiP-tslist.h b/mpiP-tslist.h new file mode 100644 index 0000000..2dc9fe1 --- /dev/null +++ b/mpiP-tslist.h @@ -0,0 +1,106 @@ +/* -*- C -*- + + mpiP MPI Profiler ( http://llnl.github.io/mpiP ) + + Please see COPYRIGHT AND LICENSE information at the end of this file. + + ----- + + thread_safe_list.h -- Implementation of the thread-safe list based on atomics + NOTE: only one thread is allowed to extract elements, but many can contribute. + This fits perfectly fine with the purpose of holding TLS pointers in mpiP. + + */ + +#ifndef THREAD_SAFE_LIST_H +#define THREAD_SAFE_LIST_H + +#include "arch/arch.h" + +typedef struct tslist_elem_s { + void *ptr; + struct tslist_elem_s *next; +} mpiP_tslist_elem_t; + +typedef struct tslist_s { + mpiP_tslist_elem_t *head, *tail; +} mpiP_tslist_t; + +mpiP_tslist_t *mpiPi_tslist_create(); +void mpiPi_tslist_release(mpiP_tslist_t *list); +void mpiPi_tslist_append(mpiP_tslist_t *list, mpiP_tslist_elem_t *ptr); +void mpiPi_tslist_dequeue(mpiP_tslist_t *list, mpiP_tslist_elem_t **_elem); +mpiP_tslist_elem_t *mpiPi_tslist_first(mpiP_tslist_t *list); +mpiP_tslist_elem_t *mpiPi_tslist_next(mpiP_tslist_elem_t *current); + +#endif // THREAD_SAFE_LIST_H + +/* + + + +Derived from +https://github.com/artpol84/poc/blob/master/arch/concurrency/thread-safe_list + +Copyright (c) 2019 Mellanox Technologies Ltd. +Written by Artem Polyakov +All rights reserved. + +This file is part of mpiP. For details, see http://llnl.github.io/mpiP. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +* Redistributions of source code must retain the above copyright +notice, this list of conditions and the disclaimer below. + +* Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the disclaimer (as noted below) in +the documentation and/or other materials provided with the +distribution. + +* Neither the name of the UC/LLNL nor the names of its contributors +may be used to endorse or promote products derived from this software +without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OF +THE UNIVERSITY OF CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY OR +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +Additional BSD Notice + +1. This notice is required to be provided under our contract with the +U.S. Department of Energy (DOE). This work was produced at the +University of California, Lawrence Livermore National Laboratory under +Contract No. W-7405-ENG-48 with the DOE. + +2. Neither the United States Government nor the University of +California nor any of their employees, makes any warranty, express or +implied, or assumes any liability or responsibility for the accuracy, +completeness, or usefulness of any information, apparatus, product, or +process disclosed, or represents that its use would not infringe +privately-owned rights. + +3. Also, reference herein to any specific commercial products, +process, or services by trade name, trademark, manufacturer or +otherwise does not necessarily constitute or imply its endorsement, +recommendation, or favoring by the United States Government or the +University of California. The views and opinions of authors expressed +herein do not necessarily state or reflect those of the United States +Government or the University of California, and shall not be used for +advertising or product endorsement purposes. + + + +*/