PAPI 7.1.0.0
Loading...
Searching...
No Matches
threads.h
Go to the documentation of this file.
1
6#ifndef PAPI_THREADS_H
7#define PAPI_THREADS_H
8
9#include <stdlib.h>
10#include <stdio.h>
11#include <unistd.h>
12
13#ifdef HAVE_THREAD_LOCAL_STORAGE
14#define THREAD_LOCAL_STORAGE_KEYWORD HAVE_THREAD_LOCAL_STORAGE
15#else
16#define THREAD_LOCAL_STORAGE_KEYWORD
17#endif
18
19#if defined(ANY_THREAD_GETS_SIGNAL) && !defined(_AIX)
20#error "lookup_and_set_thread_symbols and _papi_hwi_broadcast_signal have only been tested on AIX"
21#endif
22
23typedef struct _ThreadInfo
24{
25 unsigned long int tid;
26 unsigned long int allocator_tid;
27 struct _ThreadInfo *next;
29 void *thread_storage[PAPI_MAX_TLS];
31 EventSetInfo_t *from_esi; /* ESI used for last update this control state */
33
34 // The current event code can be stored here prior to
35 // component calls and cleared after the component returns.
36 unsigned int tls_papi_event_code;
39
43extern volatile ThreadInfo_t *_papi_hwi_thread_head;
44
45/* If we have TLS, this variable ALWAYS points to our thread descriptor. It's like magic! */
46
47#if defined(HAVE_THREAD_LOCAL_STORAGE)
49#endif
50
54extern unsigned long int ( *_papi_hwi_thread_id_fn ) ( void );
55
59extern int ( *_papi_hwi_thread_kill_fn ) ( int, int );
60
61extern int _papi_hwi_initialize_thread( ThreadInfo_t ** dest, int tid );
62extern int _papi_hwi_init_global_threads( void );
63extern int _papi_hwi_shutdown_thread( ThreadInfo_t * thread, int force );
64extern int _papi_hwi_shutdown_global_threads( void );
65extern int _papi_hwi_broadcast_signal( unsigned int mytid );
66extern int _papi_hwi_set_thread_id_fn( unsigned long int ( *id_fn ) ( void ) );
67
70{
72 _papi_hwd_lock( lck );
73 THRDBG( "Lock %d\n", lck );
74 } else {
75 ( void ) lck; /* unused if !defined(DEBUG) */
76 THRDBG( "Skipped lock %d\n", lck );
77 }
78
79 return ( PAPI_OK );
80}
81
84{
86 _papi_hwd_unlock( lck );
87 THRDBG( "Unlock %d\n", lck );
88 } else {
89 ( void ) lck; /* unused if !defined(DEBUG) */
90 THRDBG( "Skipped unlock %d\n", lck );
91 }
92
93 return ( PAPI_OK );
94}
95
97_papi_hwi_lookup_thread( int custom_tid )
98{
99
100 unsigned long int tid;
102
103
104 if (custom_tid==0) {
105#ifdef HAVE_THREAD_LOCAL_STORAGE
106 THRDBG( "TLS returning %p\n", _papi_hwi_my_thread );
107 return ( _papi_hwi_my_thread );
108#else
109 if ( _papi_hwi_thread_id_fn == NULL ) {
110 THRDBG( "Threads not initialized, returning master thread at %p\n",
112 return ( ( ThreadInfo_t * ) _papi_hwi_thread_head );
113 }
114
115 tid = ( *_papi_hwi_thread_id_fn ) ( );
116#endif
117 }
118 else {
119 tid=custom_tid;
120 }
121 THRDBG( "Threads initialized, looking for thread %#lx\n", tid );
122
124
126 while ( tmp != NULL ) {
127 THRDBG( "Examining thread tid %#lx at %p\n", tmp->tid, tmp );
128 if ( tmp->tid == tid )
129 break;
130 tmp = tmp->next;
131 if ( tmp == _papi_hwi_thread_head ) {
132 tmp = NULL;
133 break;
134 }
135 }
136
137 if ( tmp ) {
139 THRDBG( "Found thread %ld at %p\n", tid, tmp );
140 } else {
141 THRDBG( "Did not find tid %ld\n", tid );
142 }
143
145 return ( tmp );
146
147}
148
151{
153 int retval = PAPI_OK;
154
155 if ( tmp == NULL )
157
158 if ( retval == PAPI_OK )
159 *here = tmp;
160
161 return ( retval );
162}
163
164/* Prototypes */
172unsigned long _papi_gettid(void);
173unsigned long _papi_getpid(void);
174
175#endif
double tmp
#define _papi_hwd_unlock(lck)
Definition: aix-lock.h:11
#define _papi_hwd_lock(lck)
Definition: aix-lock.h:6
#define PAPI_OK
Definition: f90papi.h:73
void * thread(void *arg)
Definition: kufrin.c:38
#define THRDBG(format, args...)
Definition: papi_debug.h:67
#define inline_static
#define THREADS_LOCK
Definition: papi_internal.h:87
#define PAPI_MAX_TLS
Definition: papi_internal.h:81
int
Definition: sde_internal.h:89
unsigned long int allocator_tid
Definition: threads.h:26
EventSetInfo_t ** running_eventset
Definition: threads.h:30
EventSetInfo_t * from_esi
Definition: threads.h:31
hwd_context_t ** context
Definition: threads.h:28
unsigned long int tid
Definition: threads.h:25
int wants_signal
Definition: threads.h:32
int tls_papi_event_code_changed
Definition: threads.h:37
struct _ThreadInfo * next
Definition: threads.h:27
unsigned int tls_papi_event_code
Definition: threads.h:36
THREAD_LOCAL_STORAGE_KEYWORD ThreadInfo_t * _papi_hwi_my_thread
Definition: threads.c:37
unsigned long int(* _papi_hwi_thread_id_fn)(void)
Definition: threads.c:42
int _papi_hwi_set_thread_id_fn(unsigned long int(*id_fn)(void))
int _papi_hwi_init_global_threads(void)
Definition: threads.c:541
void _papi_hwi_shutdown_the_thread_list(void)
inline_static int _papi_hwi_lookup_or_create_thread(ThreadInfo_t **here, int tid)
Definition: threads.h:150
inline_static ThreadInfo_t * _papi_hwi_lookup_thread(int custom_tid)
Definition: threads.h:97
int _papi_hwi_initialize_thread(ThreadInfo_t **dest, int tid)
Definition: threads.c:278
unsigned long _papi_gettid(void)
Definition: threads.c:613
int(* _papi_hwi_thread_kill_fn)(int, int)
unsigned long _papi_getpid(void)
Definition: threads.c:634
inline_static int _papi_hwi_lock(int lck)
Definition: threads.h:69
int _papi_hwi_broadcast_signal(unsigned int mytid)
int _papi_hwi_gather_all_thrspec_data(int tag, PAPI_all_thr_spec_t *where)
Definition: threads.c:568
#define THREAD_LOCAL_STORAGE_KEYWORD
Definition: threads.h:16
int _papi_hwi_get_thr_context(void **)
int _papi_hwi_shutdown_thread(ThreadInfo_t *thread, int force)
Definition: threads.c:424
void _papi_hwi_cleanup_thread_list(void)
volatile ThreadInfo_t * _papi_hwi_thread_head
Definition: threads.c:32
inline_static int _papi_hwi_unlock(int lck)
Definition: threads.h:83
int _papi_hwi_shutdown_global_threads(void)
Definition: threads.c:470
ThreadInfo_t * _papi_hwi_lookup_in_thread_list()
int _papi_hwi_insert_in_thread_list(ThreadInfo_t *ptr)
int retval
Definition: zero_fork.c:53