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

Go to the source code of this file.

Macros

#define TOTAL_EVENTS   10
 

Functions

static void init_papi_pthreads (int *out_events, int *len)
 
static int do_pthreads (void *(*fn)(void *))
 
static void * case1_pthreads (void *arg)
 
static void * case2_pthreads (void *arg)
 
static void * case3_pthreads (void *arg)
 
static void * case4_pthreads (void *arg)
 
static int case1 (void)
 
static int case2 (void)
 
static int case3 (void)
 
static int case4 (void)
 
int main (int argc, char **argv)
 

Variables

static int solaris_preset_PAPI_events [TOTAL_EVENTS]
 
static int power6_preset_PAPI_events [TOTAL_EVENTS]
 
static int preset_PAPI_events [TOTAL_EVENTS]
 
static int PAPI_events [TOTAL_EVENTS] = { 0, }
 
static int PAPI_events_len = 0
 

Macro Definition Documentation

◆ TOTAL_EVENTS

#define TOTAL_EVENTS   10

Definition at line 19 of file multiplex1_pthreads.c.

Function Documentation

◆ case1()

static int case1 ( void  )
static

Definition at line 407 of file multiplex1_pthreads.c.

408{
409 int retval;
410
411 PAPI_events_len = 2;
413
415
416 PAPI_shutdown( );
417
418 return retval;
419}
Finish using PAPI and free all related resources.
static void * case1_pthreads(void *arg)
static int PAPI_events_len
static int PAPI_events[TOTAL_EVENTS]
static void init_papi_pthreads(int *out_events, int *len)
static int do_pthreads(void *(*fn)(void *))
int retval
Definition: zero_fork.c:53
Here is the call graph for this function:
Here is the caller graph for this function:

◆ case1_pthreads()

static void * case1_pthreads ( void *  arg)
static

Definition at line 139 of file multiplex1_pthreads.c.

140{
141 ( void ) arg; /*unused */
142 int retval, i, EventSet = PAPI_NULL;
143 long long values[2];
144
145 if ( ( retval = PAPI_register_thread( ) ) != PAPI_OK ) {
146 test_fail( __FILE__, __LINE__, "PAPI_register_thread", retval );
147 }
148
149 if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK ) {
150 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
151 }
152
153 for ( i = 0; i < PAPI_events_len; i++ ) {
154 char out[PAPI_MAX_STR_LEN];
155
157 if ( retval != PAPI_OK )
158 test_fail(__FILE__, __LINE__, "PAPI_add_event", retval );
160 if ( !TESTS_QUIET )
161 printf( "Added %s\n", out );
162 }
163
164 do_stuff( );
165
166 if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
167 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
168
169 do_stuff( );
170
171 if ( ( retval = PAPI_stop( EventSet, values ) ) != PAPI_OK )
172 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
173
174 if ( !TESTS_QUIET ) {
175 printf( "case1 thread %4x:", ( unsigned ) pthread_self( ) );
177 printf( "case1 thread %4x:", ( unsigned ) pthread_self( ) );
178 printf( TAB2, "", values[0], values[1] );
179 }
180
181 if ( ( retval = PAPI_cleanup_eventset( EventSet ) ) != PAPI_OK ) /* JT */
182 test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );
183
185 test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );
186
187 if ( ( retval = PAPI_unregister_thread( ) ) != PAPI_OK )
188 test_fail( __FILE__, __LINE__, "PAPI_unregister_thread", retval );
189
190 return ( ( void * ) SUCCESS );
191}
int i
add PAPI preset or native hardware event to an event set
Empty and destroy an EventSet.
Create a new empty PAPI EventSet.
Empty and destroy an EventSet.
Convert a numeric hardware event code to a name.
Notify PAPI that a thread has 'appeared'.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
Notify PAPI that a thread has 'disappeared'.
void do_stuff(void)
Definition: do_loops.c:256
#define SUCCESS
Definition: do_loops.h:5
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
static int EventSet
Definition: init_fini.c:8
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
int TESTS_QUIET
Definition: test_utils.c:18
void test_print_event_header(const char *call, int evset)
Definition: test_utils.c:605
#define TAB2
Definition: papi_test.h:99
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:491
Here is the call graph for this function:
Here is the caller graph for this function:

◆ case2()

static int case2 ( void  )
static

Definition at line 422 of file multiplex1_pthreads.c.

423{
424 int retval;
425
426 PAPI_events_len = 2;
428
430
431 PAPI_shutdown( );
432
433 return retval;
434}
static void * case2_pthreads(void *arg)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ case2_pthreads()

static void * case2_pthreads ( void *  arg)
static

Definition at line 196 of file multiplex1_pthreads.c.

197{
198 ( void ) arg; /*unused */
199 int retval, i, EventSet = PAPI_NULL;
200 long long values[2];
201
202 if ( ( retval = PAPI_register_thread( ) ) != PAPI_OK ) {
203 test_fail( __FILE__, __LINE__, "PAPI_register_thread", retval );
204 }
205
206 if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK ) {
207 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
208 }
209
210 /* In Component PAPI, EventSets must be assigned a component index
211 before you can fiddle with their internals.
212 0 is always the cpu component */
214 if ( retval != PAPI_OK ) {
215 test_fail(__FILE__, __LINE__, "PAPI_assign_eventset_component", retval );
216 }
217
218 if ( ( retval = PAPI_set_multiplex( EventSet ) ) != PAPI_OK ) {
219 if ( retval == PAPI_ENOSUPP) {
220 test_skip(__FILE__, __LINE__, "Multiplex not supported", 1);
221 }
222 test_fail( __FILE__, __LINE__, "PAPI_set_multiplex", retval );
223 }
224
225 if (!TESTS_QUIET) {
226 printf( "++case2 thread %4x:", ( unsigned ) pthread_self( ) );
227 }
228
229 for ( i = 0; i < PAPI_events_len; i++ ) {
230 char out[PAPI_MAX_STR_LEN];
231
233 if ( retval != PAPI_OK )
234 test_fail(__FILE__, __LINE__, "PAPI_add_event", retval );
236 if ( !TESTS_QUIET )
237 printf( "Added %s\n", out );
238 }
239
240 do_stuff( );
241
242 if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
243 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
244
245 do_stuff( );
246
247 if ( ( retval = PAPI_stop( EventSet, values ) ) != PAPI_OK )
248 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
249
250 if ( !TESTS_QUIET ) {
251 printf( "case2 thread %4x:", ( unsigned ) pthread_self( ) );
253 printf( "case2 thread %4x:", ( unsigned ) pthread_self( ) );
254 printf( TAB2, "", values[0], values[1] );
255 }
256
257 /* JT */
258 if ( ( retval = PAPI_cleanup_eventset( EventSet ) ) != PAPI_OK ) {
259 test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );
260 }
261
262 if ( ( retval = PAPI_destroy_eventset( &EventSet) ) != PAPI_OK ) {
263 test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );
264 }
265
266 if ( ( retval = PAPI_unregister_thread( ) ) != PAPI_OK ) {
267 test_fail( __FILE__, __LINE__, "PAPI_unregister_thread", retval );
268 }
269
270 return ( ( void * ) SUCCESS );
271}
Assign a component index to an existing but empty EventSet.
Convert a standard event set to a multiplexed event set.
#define PAPI_ENOSUPP
Definition: f90papi.h:244
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:584
Here is the call graph for this function:
Here is the caller graph for this function:

◆ case3()

static int case3 ( void  )
static

Definition at line 437 of file multiplex1_pthreads.c.

438{
439 int retval;
440
441 PAPI_events_len = 2;
443
445
446 PAPI_shutdown( );
447
448 return retval;
449}
static void * case3_pthreads(void *arg)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ case3_pthreads()

static void * case3_pthreads ( void *  arg)
static

Definition at line 276 of file multiplex1_pthreads.c.

277{
278 ( void ) arg; /*unused */
279 int retval, i, EventSet = PAPI_NULL;
280 long long values[2];
281
282 if ( ( retval = PAPI_register_thread( ) ) != PAPI_OK ) {
283 test_fail( __FILE__, __LINE__, "PAPI_register_thread", retval );
284 }
285
286 if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK ) {
287 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
288 }
289
290 for ( i = 0; i < PAPI_events_len; i++ ) {
291 char out[PAPI_MAX_STR_LEN];
292
294 if ( retval != PAPI_OK )
295 test_fail(__FILE__, __LINE__, "PAPI_add_event", retval );
297 if ( !TESTS_QUIET )
298 printf( "Added %s\n", out );
299 }
300
301 if ( ( retval = PAPI_set_multiplex( EventSet ) ) != PAPI_OK ) {
302 if ( retval == PAPI_ENOSUPP) {
303 test_skip(__FILE__, __LINE__, "Multiplex not supported", 1);
304 }
305 test_fail( __FILE__, __LINE__, "PAPI_set_multiplex", retval );
306 }
307 do_stuff( );
308
309 if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK ) {
310 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
311 }
312
313 do_stuff( );
314
315 if ( ( retval = PAPI_stop( EventSet, values ) ) != PAPI_OK ) {
316 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
317 }
318
319 if ( !TESTS_QUIET ) {
320 printf( "case3 thread %4x:", ( unsigned ) pthread_self( ) );
322 printf( "case3 thread %4x:", ( unsigned ) pthread_self( ) );
323 printf( TAB2, "", values[0], values[1] );
324 }
325
326 if ( ( retval = PAPI_cleanup_eventset( EventSet ) ) != PAPI_OK ) /* JT */
327 test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );
328
330 test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );
331
332 if ( ( retval = PAPI_unregister_thread( ) ) != PAPI_OK )
333 test_fail( __FILE__, __LINE__, "PAPI_unregister_thread", retval );
334
335 return ( ( void * ) SUCCESS );
336}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ case4()

static int case4 ( void  )
static

Definition at line 452 of file multiplex1_pthreads.c.

453{
454 int retval;
455
456 PAPI_events_len = 2;
458
460
461 PAPI_shutdown( );
462
463 return retval;
464}
static void * case4_pthreads(void *arg)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ case4_pthreads()

static void * case4_pthreads ( void *  arg)
static

Definition at line 341 of file multiplex1_pthreads.c.

342{
343 ( void ) arg; /*unused */
344 int retval, i, EventSet = PAPI_NULL;
345 long long values[4];
346 char out[PAPI_MAX_STR_LEN];
347
348 if ( ( retval = PAPI_register_thread( ) ) != PAPI_OK ) {
349 test_fail( __FILE__, __LINE__, "PAPI_register_thread", retval );
350 }
351
352 if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK ) {
353 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
354 }
355
356 i = 0;
358 if ( retval != PAPI_OK )
359 test_fail(__FILE__, __LINE__, "PAPI_add_event", retval );
361 if (!TESTS_QUIET) printf( "Added %s\n", out );
362
363 if ( ( retval = PAPI_set_multiplex( EventSet ) ) != PAPI_OK ) {
364 if ( retval == PAPI_ENOSUPP) {
365 test_skip(__FILE__, __LINE__, "Multiplex not supported", 1);
366 }
367
368 test_fail( __FILE__, __LINE__, "PAPI_set_multiplex", retval );
369 }
370 i = 1;
372 if ( retval != PAPI_OK )
373 test_fail(__FILE__, __LINE__, "PAPI_add_event", retval );
375 if (!TESTS_QUIET) printf( "Added %s\n", out );
376
377 do_stuff( );
378
379 if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
380 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
381
382 do_stuff( );
383
384 if ( ( retval = PAPI_stop( EventSet, values ) ) != PAPI_OK )
385 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
386
387 if ( !TESTS_QUIET ) {
388 printf( "case4 thread %4x:", ( unsigned ) pthread_self( ) );
390 printf( "case4 thread %4x:", ( unsigned ) pthread_self( ) );
391 printf( TAB2, "", values[0], values[1] );
392 }
393
394 if ( ( retval = PAPI_cleanup_eventset( EventSet ) ) != PAPI_OK ) /* JT */
395 test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );
396
398 test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );
399
400 if ( ( retval = PAPI_unregister_thread( ) ) != PAPI_OK )
401 test_fail( __FILE__, __LINE__, "PAPI_unregister_thread", retval );
402
403 return ( ( void * ) SUCCESS );
404}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_pthreads()

static int do_pthreads ( void *(*)(void *)  fn)
static

Definition at line 107 of file multiplex1_pthreads.c.

108{
109 int i, rc, retval;
110 pthread_attr_t attr;
112
113 pthread_attr_init( &attr );
114#ifdef PTHREAD_CREATE_UNDETACHED
115 pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_UNDETACHED );
116#endif
117#ifdef PTHREAD_SCOPE_SYSTEM
118 retval = pthread_attr_setscope( &attr, PTHREAD_SCOPE_SYSTEM );
119 if ( retval != 0 )
120 test_skip( __FILE__, __LINE__, "pthread_attr_setscope", retval );
121#endif
122
123 for ( i = 0; i < NUM_THREADS; i++ ) {
124 rc = pthread_create( &id[i], &attr, fn, NULL );
125 if ( rc )
126 return ( FAILURE );
127 }
128 for ( i = 0; i < NUM_THREADS; i++ )
129 pthread_join( id[i], NULL );
130
131 pthread_attr_destroy( &attr );
132
133 return ( SUCCESS );
134}
#define FAILURE
Definition: do_loops.h:6
unsigned long int pthread_t
rc
Definition: pscanf.h:23
#define NUM_THREADS
Definition: pthread_hl.c:9
Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_papi_pthreads()

static void init_papi_pthreads ( int out_events,
int len 
)
static

Definition at line 37 of file multiplex1_pthreads.c.

38{
39 int retval;
40 int i, real_len = 0;
41 int *in_events = preset_PAPI_events;
43
44 /* Initialize the library */
46 if ( retval != PAPI_VER_CURRENT ) {
47 test_fail(__FILE__, __LINE__, "PAPI_library_init", retval );
48 }
49
51 if ( hw_info == NULL ) {
52 test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
53 }
54
55 if ( strstr( hw_info->model_string, "UltraSPARC" ) ) {
57 }
58
59 if ( strcmp( hw_info->model_string, "POWER6" ) == 0 ) {
60 in_events = power6_preset_PAPI_events;
62 if ( retval != PAPI_OK ) {
63 test_fail(__FILE__, __LINE__,
64 "PAPI_set_domain", retval );
65 }
66 }
67
69 if ( retval == PAPI_ENOSUPP) {
70 test_skip(__FILE__, __LINE__, "Multiplex not supported", 1);
71 }
72 else if ( retval != PAPI_OK ) {
73 test_fail(__FILE__, __LINE__, "PAPI_multiplex_init", retval );
74 }
75
76 retval = PAPI_thread_init( ( unsigned long ( * )( void ) ) ( pthread_self ) );
77 if (retval != PAPI_OK ) {
78 if ( retval == PAPI_ECMP )
79 test_skip( __FILE__, __LINE__, "PAPI_thread_init", retval );
80 else
81 test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval );
82 }
83
84 for ( i = 0; in_events[i] != 0; i++ ) {
85 char out[PAPI_MAX_STR_LEN];
86 /* query and set up the right instruction to monitor */
87 retval = PAPI_query_event( in_events[i] );
88 if ( retval == PAPI_OK ) {
89 out_events[real_len++] = in_events[i];
90 PAPI_event_code_to_name( in_events[i], out );
91 if ( real_len == *len )
92 break;
93 } else {
94 PAPI_event_code_to_name( in_events[i], out );
95 if ( !TESTS_QUIET )
96 printf( "%s does not exist\n", out );
97 }
98 }
99 if ( real_len < 1 ) {
100 if (!TESTS_QUIET) printf("No counters available\n");
101 test_skip(__FILE__, __LINE__, "No counters available", 0 );
102 }
103 *len = real_len;
104}
static const PAPI_hw_info_t * hw_info
Definition: byte_profile.c:28
get information about the system hardware
initialize the PAPI library.
Initialize multiplex support in the PAPI library.
Query if PAPI event exists.
Set the default counting domain for new event sets bound to the cpu component.
Initialize thread support in the PAPI library.
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_ECMP
Definition: f90papi.h:214
#define PAPI_DOM_ALL
Definition: f90papi.h:261
static int preset_PAPI_events[TOTAL_EVENTS]
static int power6_preset_PAPI_events[TOTAL_EVENTS]
static int solaris_preset_PAPI_events[TOTAL_EVENTS]
Hardware info structure.
Definition: papi.h:774
char model_string[PAPI_MAX_STR_LEN]
Definition: papi.h:784
Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 467 of file multiplex1_pthreads.c.

468{
469 int retval;
470 int quiet;
471
472 /* Set TESTS_QUIET variable */
473 quiet = tests_quiet( argc, argv );
474
475 if (!quiet) {
476 printf( "%s: Using %d threads\n\n", argv[0], NUM_THREADS );
477 }
478
479 /* Case1 */
480 if (!quiet) {
481 printf ( "case1: Does PAPI_multiplex_init() "
482 "not break regular operation?\n" );
483 }
484
485 if ( case1() != SUCCESS ) {
486 test_fail( __FILE__, __LINE__, "case1", PAPI_ESYS );
487 }
488
489 /* Case2 */
490 if (!quiet) {
491 printf( "case2: Does setmpx/add work?\n" );
492 }
493 if ( case2( ) != SUCCESS ) {
494 test_fail( __FILE__, __LINE__, "case2", PAPI_ESYS );
495 }
496
497 /* Case3 */
498 if (!quiet) {
499 printf( "case3: Does add/setmpx work?\n" );
500 }
501 if ( case3( ) != SUCCESS ) {
502 test_fail( __FILE__, __LINE__, "case3", PAPI_ESYS );
503 }
504
505 /* Case4 */
506 if (!quiet) {
507 printf( "case4: Does add/setmpx/add work?\n" );
508 }
509 if ( case4( ) != SUCCESS ) {
510 test_fail( __FILE__, __LINE__, "case4", PAPI_ESYS );
511 }
512
513 /* Finally init PAPI? */
515 if ( retval != PAPI_VER_CURRENT ) {
516 test_fail(__FILE__, __LINE__, "PAPI_library_init", retval );
517 }
518
519 test_pass( __FILE__ );
520
521 return 0;
522
523}
#define PAPI_ESYS
Definition: f90papi.h:136
static int case1(void)
static int case4(void)
static int case3(void)
static int case2(void)
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void PAPI_NORETURN test_pass(const char *filename)
Definition: test_utils.c:432
int quiet
Definition: rapl_overflow.c:19
Here is the call graph for this function:

Variable Documentation

◆ PAPI_events

int PAPI_events[TOTAL_EVENTS] = { 0, }
static

Definition at line 33 of file multiplex1_pthreads.c.

◆ PAPI_events_len

int PAPI_events_len = 0
static

Definition at line 34 of file multiplex1_pthreads.c.

◆ power6_preset_PAPI_events

int power6_preset_PAPI_events[TOTAL_EVENTS]
static
Initial value:
= {
}
#define PAPI_TOT_CYC
Definition: f90papi.h:308
#define PAPI_L1_DCM
Definition: f90papi.h:364
#define PAPI_FP_INS
Definition: f90papi.h:366
#define PAPI_L1_ICM
Definition: f90papi.h:392

Definition at line 25 of file multiplex1_pthreads.c.

◆ preset_PAPI_events

int preset_PAPI_events[TOTAL_EVENTS]
static
Initial value:
= {
}
#define PAPI_TOT_INS
Definition: f90papi.h:317

Definition at line 29 of file multiplex1_pthreads.c.

◆ solaris_preset_PAPI_events

int solaris_preset_PAPI_events[TOTAL_EVENTS]
static
Initial value:
= {
}
#define PAPI_BR_MSP
Definition: f90papi.h:337
#define PAPI_L2_TCM
Definition: f90papi.h:320

Definition at line 21 of file multiplex1_pthreads.c.