PAPI  5.3.2.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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

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

Variables

int TESTS_QUIET
 
unsigned int length
 
caddr_t my_start
 
caddr_t my_end
 

Macro Definition Documentation

#define FLOPS   100000000

Definition at line 9 of file profile_pthreads.c.

#define THR   1000000

Definition at line 8 of file profile_pthreads.c.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 114 of file profile_pthreads.c.

115 {
117  int flops[NUM_THREADS];
118  int i, rc, retval;
119  pthread_attr_t attr;
120  long long elapsed_us, elapsed_cyc;
121  const PAPI_exe_info_t *prginfo = NULL;
122 
123  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
124 
125  if ( ( retval =
127  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
128  if ( ( retval =
129  PAPI_thread_init( ( unsigned
130  long ( * )( void ) ) ( pthread_self ) ) ) !=
131  PAPI_OK ) {
132  if ( retval == PAPI_ECMP )
133  test_skip( __FILE__, __LINE__, "PAPI_thread_init", retval );
134  else
135  test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval );
136  }
137  if ( ( prginfo = PAPI_get_executable_info( ) ) == NULL ) {
138  retval = 1;
139  test_fail( __FILE__, __LINE__, "PAPI_get_executable_info", retval );
140  }
141  my_start = prginfo->address_info.text_start;
142  my_end = prginfo->address_info.text_end;
143  length = ( unsigned int ) ( my_end - my_start );
144 
145  elapsed_us = PAPI_get_real_usec( );
146 
147  elapsed_cyc = PAPI_get_real_cyc( );
148 
149  pthread_attr_init( &attr );
150 #ifdef PTHREAD_CREATE_UNDETACHED
151  pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_UNDETACHED );
152 #endif
153 #ifdef PTHREAD_SCOPE_SYSTEM
154  retval = pthread_attr_setscope( &attr, PTHREAD_SCOPE_SYSTEM );
155  if ( retval != 0 )
156  test_skip( __FILE__, __LINE__, "pthread_attr_setscope", retval );
157 #endif
158 
159  for ( i = 0; i < NUM_THREADS; i++ ) {
160  flops[i] = FLOPS * ( i + 1 );
161  rc = pthread_create( &id[i], &attr, Thread, ( void * ) &flops[i] );
162  if ( rc )
163  return ( FAILURE );
164  }
165  for ( i = 0; i < NUM_THREADS; i++ )
166  pthread_join( id[i], NULL );
167 
168  pthread_attr_destroy( &attr );
169 
170  elapsed_cyc = PAPI_get_real_cyc( ) - elapsed_cyc;
171 
172  elapsed_us = PAPI_get_real_usec( ) - elapsed_us;
173 
174  if ( !TESTS_QUIET ) {
175  printf( "Master real usec : \t%lld\n", elapsed_us );
176  printf( "Master real cycles : \t%lld\n", elapsed_cyc );
177  }
178 
179  test_pass( __FILE__, NULL, 0 );
180  pthread_exit( NULL );
181  exit( 1 );
182 }
unsigned long long length
Definition: iozone.c:17106
caddr_t my_end
caddr_t text_end
Definition: papi.h:693
void test_skip(char *file, int line, char *call, int retval)
Definition: test_utils.c:614
get the executable&#39;s info
Definition: papi.h:702
return PAPI_OK
Definition: linux-nvml.c:458
tests_quiet(argc, argv)
#define printf
Definition: papi_test.h:125
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
int TESTS_QUIET
Definition: test_utils.c:11
char ** argv
Definition: iozone.c:1610
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_thread_init(unsigned long int(*id_fn)(void))
Definition: papi.c:118
int PAPI_library_init(int version)
Definition: papi.c:495
int i
Definition: fileop.c:140
const PAPI_exe_info_t * PAPI_get_executable_info(void)
Definition: papi.c:5988
long long elapsed_cyc
Definition: zero_fork.c:43
caddr_t text_start
Definition: papi.h:692
#define PAPI_ECMP
Definition: fpapi.h:109
#define NUM_THREADS
Definition: test_utils.h:8
PAPI_address_map_t address_info
Definition: papi.h:704
caddr_t my_start
#define FAILURE
Definition: test_utils.h:6
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
void * Thread(void *arg)
pthread_t
Definition: iozone.c:18557
long long PAPI_get_real_usec(void)
Definition: papi.c:6138
int
Definition: iozone.c:18528
#define FLOPS
int rc
Definition: iozone.c:20281
long long PAPI_get_real_cyc(void)
Definition: papi.c:6091
ssize_t retval
Definition: libasync.c:338
long long elapsed_us
Definition: zero_fork.c:43
void exit()
pthread_attr_t attr
Definition: iozone.c:18466

Here is the call graph for this function:

void* Thread ( void arg)

Definition at line 15 of file profile_pthreads.c.

16 {
17  int retval, num_tests = 1, i;
19  int num_events1;
20  long long **values;
21  long long elapsed_us, elapsed_cyc;
22  unsigned short *profbuf;
24 
25  retval = PAPI_register_thread( );
26  if ( retval != PAPI_OK )
27  test_fail( __FILE__, __LINE__, "PAPI_register_thread", retval );
28  profbuf = ( unsigned short * ) malloc( length * sizeof ( unsigned short ) );
29  if ( profbuf == NULL )
30  exit( 1 );
31  memset( profbuf, 0x00, length * sizeof ( unsigned short ) );
32 
33  /* add PAPI_TOT_CYC and one of the events in PAPI_FP_INS, PAPI_FP_OPS or
34  PAPI_TOT_INS, depends on the availability of the event on the
35  platform */
36  EventSet1 =
37  add_two_nonderived_events( &num_events1, &PAPI_event, &mask1 );
38 
39  values = allocate_test_space( num_tests, num_events1 );
40 
41  if ( ( retval =
42  PAPI_event_code_to_name( PAPI_event, event_name ) ) != PAPI_OK )
43  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
44 
45  elapsed_us = PAPI_get_real_usec( );
46 
47  elapsed_cyc = PAPI_get_real_cyc( );
48 
49  retval = PAPI_profil( profbuf, length, my_start, 65536,
50  EventSet1, PAPI_event, THR, PAPI_PROFIL_POSIX );
51  if ( retval )
52  test_fail( __FILE__, __LINE__, "PAPI_profil", retval );
53 
54  if ( ( retval = PAPI_start( EventSet1 ) ) != PAPI_OK )
55  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
56 
57  do_flops( *( int * ) arg );
58 
59  if ( ( retval = PAPI_stop( EventSet1, values[0] ) ) != PAPI_OK )
60  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
61 
62  elapsed_us = PAPI_get_real_usec( ) - elapsed_us;
63 
64  elapsed_cyc = PAPI_get_real_cyc( ) - elapsed_cyc;
65 
66  /* to remove the profile flag */
67  retval = PAPI_profil( profbuf, length, my_start, 65536,
68  EventSet1, PAPI_event, 0, PAPI_PROFIL_POSIX );
69  if ( retval )
70  test_fail( __FILE__, __LINE__, "PAPI_profil", retval );
71 
72 
73  remove_test_events( &EventSet1, mask1 );
74 
75  if ( !TESTS_QUIET ) {
76  if ( mask1 == 0x3 ) {
77  printf( "Thread %#x PAPI_TOT_INS : \t%lld\n",
78  ( int ) pthread_self( ), ( values[0] )[0] );
79  } else {
80  printf( "Thread %#x PAPI_FP_INS : \t%lld\n",
81  ( int ) pthread_self( ), ( values[0] )[0] );
82  }
83  printf( "Thread %#x PAPI_TOT_CYC: \t%lld\n", ( int ) pthread_self( ),
84  ( values[0] )[1] );
85  printf( "Thread %#x Real usec : \t%lld\n", ( int ) pthread_self( ),
86  elapsed_us );
87  printf( "Thread %#x Real cycles : \t%lld\n", ( int ) pthread_self( ),
88  elapsed_cyc );
89 
90  printf( "Test case: PAPI_profil() for pthreads\n" );
91  printf( "----Profile buffer for Thread %#x---\n",
92  ( int ) pthread_self( ) );
93  for ( i = 0; i < ( int ) length; i++ ) {
94  if ( profbuf[i] )
95  printf( "%#lx\t%d\n", ( unsigned long ) ( my_start + 2 * i ),
96  profbuf[i] );
97  }
98  }
99  for ( i = 0; i < ( int ) length; i++ )
100  if ( profbuf[i] )
101  break;
102 
103  if ( i >= ( int ) length )
104  test_fail( __FILE__, __LINE__, "No information in buffers", 1 );
105  free_test_space( values, num_tests );
106 
107  retval = PAPI_unregister_thread( );
108  if ( retval != PAPI_OK )
109  test_fail( __FILE__, __LINE__, "PAPI_unregister_thread", retval );
110  return ( NULL );
111 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:23
memset(eventId, 0, size)
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2232
int mask1
Definition: zero_fork.c:41
unsigned long long length
Definition: iozone.c:17106
int PAPI_event[2]
Definition: data_range.c:24
#define PAPI_NULL
Definition: fpapi.h:13
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43
int num_events1
Definition: zero_fork.c:42
int PAPI_register_thread(void)
Definition: papi.c:203
return PAPI_OK
Definition: linux-nvml.c:458
#define PAPI_PROFIL_POSIX
Definition: fpapi.h:75
#define printf
Definition: papi_test.h:125
int TESTS_QUIET
Definition: test_utils.c:11
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_profil(void *buf, unsigned bufsiz, caddr_t offset, unsigned scale, int EventSet, int EventCode, int threshold, int flags)
Definition: papi.c:5316
int i
Definition: fileop.c:140
#define THR
long long elapsed_cyc
Definition: zero_fork.c:43
caddr_t my_start
void * profbuf[5]
Definition: prof_utils.c:28
void free_test_space(long long **values, int num_tests)
Definition: test_utils.c:131
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:924
int num_tests
Definition: zero_fork.c:46
void do_flops(int n)
Definition: multiplex.c:23
long long PAPI_get_real_usec(void)
Definition: papi.c:6138
int PAPI_unregister_thread(void)
Definition: papi.c:239
int
Definition: iozone.c:18528
int add_two_nonderived_events(int *num_events, int *papi_event, int *mask)
Definition: test_utils.c:723
long long PAPI_get_real_cyc(void)
Definition: papi.c:6091
int PAPI_start(int EventSet)
Definition: papi.c:2026
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
long long elapsed_us
Definition: zero_fork.c:43
long long ** allocate_test_space(int num_tests, int num_events)
Definition: test_utils.c:107
void exit()
int remove_test_events(int *EventSet, int mask)
Definition: test_utils.c:277
int EventSet1
Definition: zero_fork.c:40

Here is the call graph for this function:

Variable Documentation

unsigned int length

Definition at line 11 of file profile_pthreads.c.

caddr_t my_end

Definition at line 12 of file profile_pthreads.c.

caddr_t my_start

Definition at line 12 of file profile_pthreads.c.

int TESTS_QUIET

Definition at line 11 of file test_utils.c.