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

Go to the source code of this file.

Macros

#define THR   1000000
 
#define FLOPS   100000000
 

Functions

void * Thread (void *arg)
 
int main (int argc, char **argv)
 

Variables

unsigned int length
 
vptr_t my_start
 
vptr_t my_end
 

Macro Definition Documentation

◆ FLOPS

#define FLOPS   100000000

Definition at line 14 of file profile_pthreads.c.

◆ THR

#define THR   1000000

Definition at line 13 of file profile_pthreads.c.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 131 of file profile_pthreads.c.

132{
134 int flops[NUM_THREADS];
135 int i, rc, retval;
136 pthread_attr_t attr;
137 long long elapsed_us, elapsed_cyc;
138 const PAPI_exe_info_t *prginfo = NULL;
139 int quiet;
140
141 /* Set TESTS_QUIET variable */
142 quiet=tests_quiet( argc, argv );
143
145 if (retval != PAPI_VER_CURRENT ) {
146 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
147 }
148
150 if (retval != PAPI_OK) {
151
152 if (!quiet) printf("Trouble adding event\n");
153 test_skip(__FILE__,__LINE__,"No events",0);
154 }
155
156 retval = PAPI_thread_init( ( unsigned long ( * )( void ) ) ( pthread_self ));
157 if (retval != PAPI_OK ) {
158 if ( retval == PAPI_ECMP )
159 test_skip( __FILE__, __LINE__, "PAPI_thread_init", retval );
160 else
161 test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval );
162 }
163
164 if ( ( prginfo = PAPI_get_executable_info( ) ) == NULL ) {
165 retval = 1;
166 test_fail( __FILE__, __LINE__, "PAPI_get_executable_info", retval );
167 }
168
170 my_end = prginfo->address_info.text_end;
171 length = ( unsigned int ) ( my_end - my_start );
172
174
176
177 pthread_attr_init( &attr );
178#ifdef PTHREAD_CREATE_UNDETACHED
179 pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_UNDETACHED );
180#endif
181#ifdef PTHREAD_SCOPE_SYSTEM
182 retval = pthread_attr_setscope( &attr, PTHREAD_SCOPE_SYSTEM );
183 if ( retval != 0 )
184 test_skip( __FILE__, __LINE__, "pthread_attr_setscope", retval );
185#endif
186
187 for ( i = 0; i < NUM_THREADS; i++ ) {
188 flops[i] = FLOPS * ( i + 1 );
189 rc = pthread_create( &id[i], &attr, Thread, ( void * ) &flops[i] );
190 if ( rc )
191 return ( FAILURE );
192 }
193 for ( i = 0; i < NUM_THREADS; i++ )
194 pthread_join( id[i], NULL );
195
196 pthread_attr_destroy( &attr );
197
199
201
202 if ( !quiet ) {
203 printf( "Master real usec : \t%lld\n", elapsed_us );
204 printf( "Master real cycles : \t%lld\n", elapsed_cyc );
205 }
206
207 test_pass( __FILE__ );
208
209 pthread_exit( NULL );
210
211 return 0;
212
213}
int i
Get the executable's address space info.
get real time counter value in clock cycles Returns the total real time passed since some arbitrary s...
get real time counter value in microseconds
initialize the PAPI library.
Query if PAPI event exists.
Initialize thread support in the PAPI library.
#define FAILURE
Definition: do_loops.h:6
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_TOT_CYC
Definition: f90papi.h:308
#define PAPI_ECMP
Definition: f90papi.h:214
unsigned long int pthread_t
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
vptr_t my_start
#define FLOPS
vptr_t my_end
unsigned int length
void * Thread(void *arg)
rc
Definition: pscanf.h:23
#define NUM_THREADS
Definition: pthread_hl.c:9
int quiet
Definition: rapl_overflow.c:19
int
Definition: sde_internal.h:89
vptr_t text_start
Definition: papi.h:686
vptr_t text_end
Definition: papi.h:687
get the executable's info
Definition: papi.h:696
PAPI_address_map_t address_info
Definition: papi.h:698
long long elapsed_cyc
Definition: zero_fork.c:50
long long elapsed_us
Definition: zero_fork.c:50
int retval
Definition: zero_fork.c:53
Here is the call graph for this function:

◆ Thread()

void * Thread ( void *  arg)

Definition at line 20 of file profile_pthreads.c.

21{
22 int retval, num_tests = 1, i;
24 int num_events1;
25 long long **values;
26 long long elapsed_us, elapsed_cyc;
27 unsigned short *profbuf;
29
31 if ( retval != PAPI_OK ) {
32 test_fail( __FILE__, __LINE__, "PAPI_register_thread", retval );
33 }
34
35 profbuf = ( unsigned short * ) malloc( length * sizeof ( unsigned short ) );
36 if ( profbuf == NULL ) {
37 test_fail(__FILE__, __LINE__, "Allocate memory",0);
38 }
39
40 memset( profbuf, 0x00, length * sizeof ( unsigned short ) );
41
42 /* add PAPI_TOT_CYC and one of the events in PAPI_FP_INS, PAPI_FP_OPS or
43 PAPI_TOT_INS, depends on the availability of the event on the
44 platform */
46
48
50 if (retval != PAPI_OK ) {
51 test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
52 }
53
55
57
60 if ( retval ) {
61 test_fail( __FILE__, __LINE__, "PAPI_profil", retval );
62 }
63
65 if (retval != PAPI_OK ) {
66 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
67 }
68
69 do_flops( *( int * ) arg );
70
72 if (retval != PAPI_OK ) {
73 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
74 }
75
77
79
80 /* to remove the profile flag */
83 if ( retval ) {
84 test_fail( __FILE__, __LINE__, "PAPI_profil", retval );
85 }
86
88
89 if ( !TESTS_QUIET ) {
90 if ( mask1 == 0x3 ) {
91 printf( "Thread %#x PAPI_TOT_INS : \t%lld\n",
92 ( int ) pthread_self( ), ( values[0] )[0] );
93 } else {
94 printf( "Thread %#x PAPI_FP_INS : \t%lld\n",
95 ( int ) pthread_self( ), ( values[0] )[0] );
96 }
97 printf( "Thread %#x PAPI_TOT_CYC: \t%lld\n", ( int ) pthread_self( ),
98 ( values[0] )[1] );
99 printf( "Thread %#x Real usec : \t%lld\n", ( int ) pthread_self( ),
100 elapsed_us );
101 printf( "Thread %#x Real cycles : \t%lld\n", ( int ) pthread_self( ),
102 elapsed_cyc );
103
104 printf( "Test case: PAPI_profil() for pthreads\n" );
105 printf( "----Profile buffer for Thread %#x---\n",
106 ( int ) pthread_self( ) );
107 for ( i = 0; i < ( int ) length; i++ ) {
108 if ( profbuf[i] )
109 printf( "%#lx\t%d\n", ( unsigned long ) ( my_start + 2 * i ),
110 profbuf[i] );
111 }
112 }
113 for ( i = 0; i < ( int ) length; i++ )
114 if ( profbuf[i] )
115 break;
116
117 if ( i >= ( int ) length ) {
118 test_fail( __FILE__, __LINE__, "No information in buffers", 1 );
119 }
121
123 if ( retval != PAPI_OK ) {
124 test_fail( __FILE__, __LINE__, "PAPI_unregister_thread", retval );
125 }
126
127 return NULL;
128}
Convert a numeric hardware event code to a name.
Generate a histogram of hardware counter overflows vs. PC addresses.
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'.
int PAPI_event[2]
Definition: data_range.c:30
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_PROFIL_POSIX
Definition: f90papi.h:44
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
void do_flops(int n)
Definition: multiplex.c:23
int TESTS_QUIET
Definition: test_utils.c:18
int add_two_nonderived_events(int *num_events, int *papi_event, int *mask)
Definition: test_utils.c:671
void free_test_space(long long **values, int num_tests)
Definition: test_utils.c:70
long long ** allocate_test_space(int num_tests, int num_events)
Definition: test_utils.c:46
int remove_test_events(int *EventSet, int mask)
Definition: test_utils.c:201
void * profbuf[5]
Definition: prof_utils.c:33
#define THR
int EventSet1
Definition: zero_fork.c:47
int num_events1
Definition: zero_fork.c:49
int mask1
Definition: zero_fork.c:48
int num_tests
Definition: zero_fork.c:53
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ length

unsigned int length

Definition at line 16 of file profile_pthreads.c.

◆ my_end

vptr_t my_end

Definition at line 17 of file profile_pthreads.c.

◆ my_start

vptr_t my_start

Definition at line 17 of file profile_pthreads.c.