PAPI 7.1.0.0
Loading...
Searching...
No Matches
multiplex3_pthreads.c File Reference
Include dependency graph for multiplex3_pthreads.c:

Go to the source code of this file.

Macros

#define MAX_TO_ADD   5
 

Functions

void * thread_fn (void *dummy)
 
static void mainloop (int arg)
 
int main (int argc, char **argv)
 

Macro Definition Documentation

◆ MAX_TO_ADD

#define MAX_TO_ADD   5

Definition at line 23 of file multiplex3_pthreads.c.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 199 of file multiplex3_pthreads.c.

200{
201 int i, rc, retval;
203 pthread_attr_t attr;
204 int quiet;
205
206 /* Set TESTS_QUIET variable */
207 quiet = tests_quiet( argc, argv );
208
209 if (!quiet) {
210 printf( "%s: Using %d threads\n\n", argv[0], NUM_THREADS );
211 printf( "Does non-threaded multiplexing work "
212 "with extraneous threads present?\n" );
213 }
214
215 /* Create a bunch of unused pthreads, to simulate threads created
216 * by the system that the user doesn't know about.
217 */
218 pthread_attr_init( &attr );
219#ifdef PTHREAD_CREATE_UNDETACHED
220 pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_UNDETACHED );
221#endif
222#ifdef PTHREAD_SCOPE_SYSTEM
223 retval = pthread_attr_setscope( &attr, PTHREAD_SCOPE_SYSTEM );
224 if ( retval != 0 )
225 test_skip( __FILE__, __LINE__, "pthread_attr_setscope", retval );
226#endif
227
228#ifdef PPC64
229 sigset_t sigprof;
230 sigemptyset( &sigprof );
231 sigaddset( &sigprof, SIGPROF );
232 retval = sigprocmask( SIG_BLOCK, &sigprof, NULL );
233 if ( retval != 0 )
234 test_fail( __FILE__, __LINE__, "sigprocmask SIG_BLOCK", retval );
235#endif
236
237 for ( i = 0; i < NUM_THREADS; i++ ) {
238 rc = pthread_create( &id[i], &attr, thread_fn, NULL );
239 if ( rc )
240 test_fail( __FILE__, __LINE__, "pthread_create", rc );
241 }
242 pthread_attr_destroy( &attr );
243
244#ifdef PPC64
245 retval = sigprocmask( SIG_UNBLOCK, &sigprof, NULL );
246 if ( retval != 0 )
247 test_fail( __FILE__, __LINE__, "sigprocmask SIG_UNBLOCK", retval );
248#endif
249
251
252 test_pass( __FILE__ );
253
254 return 0;
255
256}
int i
void * thread_fn(void *dummy)
static void mainloop(int arg)
#define NUM_ITERS
Definition: multiplex.c:19
unsigned long int pthread_t
int sigprocmask(int __how, const sigset_t *__restrict __set, sigset_t *__restrict __oset) __attribute__((__nothrow__
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:491
void PAPI_NORETURN test_pass(const char *filename)
Definition: test_utils.c:432
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:584
rc
Definition: pscanf.h:23
#define NUM_THREADS
Definition: pthread_hl.c:9
int quiet
Definition: rapl_overflow.c:19
int retval
Definition: zero_fork.c:53
Here is the call graph for this function:

◆ mainloop()

static void mainloop ( int  arg)
static

Definition at line 41 of file multiplex3_pthreads.c.

42{
43 int allvalid;
44 long long *values;
45 int EventSet = PAPI_NULL;
46 int retval, i, j = 2, skipped_counters=0;
48
49 ( void ) arg;
50
51 /* Initialize the library */
52
54 if ( retval != PAPI_VER_CURRENT ) {
55 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
56 }
57
59 if ( retval != PAPI_OK ) {
60 test_fail( __FILE__, __LINE__, "PAPI multiplex init fail\n", retval );
61 }
62
64 if ( retval != PAPI_OK ) {
65 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
66 }
67
68 /* In Component PAPI, EventSets must be assigned a component index
69 before you can fiddle with their internals.
70 0 is always the cpu component */
72 if ( retval != PAPI_OK ) {
73 test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component",
74 retval );
75 }
76
78 if ( retval == PAPI_ENOSUPP) {
79 test_skip(__FILE__, __LINE__, "Multiplex not supported", 1);
80 } else if ( retval != PAPI_OK ) {
81 test_fail( __FILE__, __LINE__, "PAPI_set_multiplex", retval );
82 }
83
84 retval = PAPI_thread_init( ( unsigned long ( * )( void ) ) ( pthread_self ) );
85 if (retval != PAPI_OK ) {
86 if ( retval == PAPI_ECMP )
87 test_skip( __FILE__, __LINE__, "PAPI_thread_init", retval );
88 else
89 test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval );
90 }
91
93 if ( ( retval != PAPI_OK ) && ( retval != PAPI_ECNFLCT ) ) {
94 if (!TESTS_QUIET) printf("Trouble adding PAPI_TOT_INS\n");
95 test_skip( __FILE__, __LINE__, "PAPI_add_event", retval );
96 }
97
98 if ( !TESTS_QUIET ) {
99 printf( "Added %s\n", "PAPI_TOT_INS" );
100 }
101
103 if ( ( retval != PAPI_OK ) && ( retval != PAPI_ECNFLCT ) )
104 test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
105 if ( !TESTS_QUIET ) {
106 printf( "Added %s\n", "PAPI_TOT_CYC" );
107 }
108
109 values = ( long long * ) malloc( MAX_TO_ADD * sizeof ( long long ) );
110 if ( values == NULL )
111 test_fail( __FILE__, __LINE__, "malloc", 0 );
112
113 for ( i = 0; i < PAPI_MAX_PRESET_EVENTS; i++ ) {
115 if ( retval != PAPI_OK )
116 test_fail( __FILE__, __LINE__, "PAPI_get_event_info", retval );
117
118 if ( pset.count ) {
119 if (!TESTS_QUIET) printf( "Adding %s\n", pset.symbol );
120
121 retval = PAPI_add_event( EventSet, ( int ) pset.event_code );
122 if ( ( retval != PAPI_OK ) && ( retval != PAPI_ECNFLCT ) )
123 test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
124
125 if ( retval == PAPI_OK ) {
126 if (!TESTS_QUIET) printf( "Added %s\n", pset.symbol );
127 } else {
128 if (!TESTS_QUIET) printf( "Could not add %s\n", pset.symbol );
129 }
130
131 do_stuff( );
132
133 if ( retval == PAPI_OK ) {
135 if ( retval != PAPI_OK )
136 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
137
138 do_stuff( );
139
141 if ( retval != PAPI_OK )
142 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
143
144 if ( values[j] ) {
145 if ( ++j >= MAX_TO_ADD )
146 break;
147 } else {
148 retval =
149 PAPI_remove_event( EventSet, ( int ) pset.event_code );
150 if ( retval == PAPI_OK )
151 if (!TESTS_QUIET) printf( "Removed %s\n", pset.symbol );
152 /* This added because the test */
153 /* can take a long time if mplexing */
154 /* is broken and all values are 0 */
155 skipped_counters++;
156 if (skipped_counters>MAX_TO_ADD) break;
157
158 }
159 }
160 }
161 }
162
164 if ( retval != PAPI_OK )
165 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
166
167 do_stuff( );
168
170 if ( retval != PAPI_OK )
171 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
172
173 if (!TESTS_QUIET) {
174 test_print_event_header( "multiplex3_pthreads:\n", EventSet );
175 }
176 allvalid = 0;
177 for ( i = 0; i < MAX_TO_ADD; i++ ) {
178 if (!TESTS_QUIET) printf( ONENUM, values[i] );
179 if ( values[i] != 0 )
180 allvalid++;
181 }
182 if (!TESTS_QUIET) printf( "\n" );
183 if ( !allvalid )
184 test_fail( __FILE__, __LINE__, "all counter registered no counts", 1 );
185
187 if ( retval != PAPI_OK )
188 test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );
189
191 if ( retval != PAPI_OK )
192 test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );
193
194 free( values );
195 PAPI_shutdown( );
196}
add PAPI preset or native hardware event to an event set
Assign a component index to an existing but empty EventSet.
Empty and destroy an EventSet.
Create a new empty PAPI EventSet.
Empty and destroy an EventSet.
Get the event's name and description info.
initialize the PAPI library.
Initialize multiplex support in the PAPI library.
removes a hardware event from a PAPI event set.
Convert a standard event set to a multiplexed event set.
Finish using PAPI and free all related resources.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
Initialize thread support in the PAPI library.
void do_stuff(void)
Definition: do_loops.c:256
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_TOT_CYC
Definition: f90papi.h:308
#define PAPI_ECNFLCT
Definition: f90papi.h:234
#define PAPI_ENOSUPP
Definition: f90papi.h:244
#define PAPI_ECMP
Definition: f90papi.h:214
#define PAPI_TOT_INS
Definition: f90papi.h:317
static int EventSet
Definition: init_fini.c:8
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
#define MAX_TO_ADD
int TESTS_QUIET
Definition: test_utils.c:18
#define PAPI_PRESET_MASK
#define PAPI_MAX_PRESET_EVENTS
void test_print_event_header(const char *call, int evset)
Definition: test_utils.c:605
#define ONENUM
Definition: papi_test.h:97
unsigned int count
Definition: papi.h:981
unsigned int event_code
Definition: papi.h:958
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:960
Here is the call graph for this function:
Here is the caller graph for this function:

◆ thread_fn()

void * thread_fn ( void *  dummy)

Definition at line 29 of file multiplex3_pthreads.c.

30{
31 ( void ) dummy;
32 while ( 1 ) {
33 do_stuff( );
34 }
35 return NULL;
36}
void dummy(void *array)
Definition: do_loops.c:306
Here is the call graph for this function:
Here is the caller graph for this function: