PAPI  5.6.0.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

unsigned int length
 
caddr_t my_start
 
caddr_t my_end
 

Macro Definition Documentation

#define FLOPS   100000000

Definition at line 14 of file profile_pthreads.c.

#define THR   1000000

Definition at line 13 of file profile_pthreads.c.

Function Documentation

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 
149  retval = PAPI_query_event(PAPI_TOT_CYC);
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 
169  my_start = prginfo->address_info.text_start;
170  my_end = prginfo->address_info.text_end;
171  length = ( unsigned int ) ( my_end - my_start );
172 
173  elapsed_us = PAPI_get_real_usec( );
174 
175  elapsed_cyc = PAPI_get_real_cyc( );
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 
198  elapsed_cyc = PAPI_get_real_cyc( ) - elapsed_cyc;
199 
200  elapsed_us = PAPI_get_real_usec( ) - elapsed_us;
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 }
#define NUM_THREADS
Definition: do_loops.h:8
unsigned long long length
Definition: iozone.c:17106
void test_pass(const char *filename)
Definition: test_utils.c:432
caddr_t my_end
#define FAILURE
Definition: do_loops.h:6
caddr_t text_end
Definition: papi.h:698
get the executable&#39;s info
Definition: papi.h:707
return PAPI_OK
Definition: linux-nvml.c:497
int int argc
Definition: iozone.c:1609
int rc
Definition: iozone.c:20281
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:559
char ** argv
Definition: iozone.c:1610
int PAPI_thread_init(unsigned long int(*id_fn)(void))
Definition: papi.c:123
int PAPI_library_init(int version)
Definition: papi.c:500
int i
Definition: fileop.c:140
int quiet
Definition: rapl_overflow.c:18
#define PAPI_TOT_CYC
const PAPI_exe_info_t * PAPI_get_executable_info(void)
Definition: papi.c:6114
long long elapsed_cyc
Definition: zero_fork.c:50
caddr_t text_start
Definition: papi.h:697
PAPI_address_map_t address_info
Definition: papi.h:709
caddr_t my_start
#define PAPI_ECMP
Definition: papi.h:256
pthread_t
Definition: iozone.c:18557
int PAPI_query_event(int EventCode)
Definition: papi.c:684
long long PAPI_get_real_usec(void)
Definition: papi.c:6264
printf("\tTry: -i 0 -i 1 \n\n")
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
int
Definition: iozone.c:18528
static void * Thread(void *arg)
#define FLOPS
long long PAPI_get_real_cyc(void)
Definition: papi.c:6217
ssize_t retval
Definition: libasync.c:338
long long elapsed_us
Definition: zero_fork.c:50
#define PAPI_VER_CURRENT
Definition: papi.h:225
pthread_attr_t attr
Definition: iozone.c:18466

Here is the call graph for this function:

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 
30  retval = PAPI_register_thread( );
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 */
45  EventSet1 = add_two_nonderived_events( &num_events1, &PAPI_event, &mask1 );
46 
47  values = allocate_test_space( num_tests, num_events1 );
48 
49  retval = PAPI_event_code_to_name( PAPI_event, event_name );
50  if (retval != PAPI_OK ) {
51  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
52  }
53 
54  elapsed_us = PAPI_get_real_usec( );
55 
56  elapsed_cyc = PAPI_get_real_cyc( );
57 
58  retval = PAPI_profil( profbuf, length, my_start, 65536,
59  EventSet1, PAPI_event, THR, PAPI_PROFIL_POSIX );
60  if ( retval ) {
61  test_fail( __FILE__, __LINE__, "PAPI_profil", retval );
62  }
63 
64  retval = PAPI_start( EventSet1 );
65  if (retval != PAPI_OK ) {
66  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
67  }
68 
69  do_flops( *( int * ) arg );
70 
71  retval = PAPI_stop( EventSet1, values[0] );
72  if (retval != PAPI_OK ) {
73  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
74  }
75 
76  elapsed_us = PAPI_get_real_usec( ) - elapsed_us;
77 
78  elapsed_cyc = PAPI_get_real_cyc( ) - elapsed_cyc;
79 
80  /* to remove the profile flag */
81  retval = PAPI_profil( profbuf, length, my_start, 65536,
82  EventSet1, PAPI_event, 0, PAPI_PROFIL_POSIX );
83  if ( retval ) {
84  test_fail( __FILE__, __LINE__, "PAPI_profil", retval );
85  }
86 
87  remove_test_events( &EventSet1, mask1 );
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  }
120  free_test_space( values, num_tests );
121 
122  retval = PAPI_unregister_thread( );
123  if ( retval != PAPI_OK ) {
124  test_fail( __FILE__, __LINE__, "PAPI_unregister_thread", retval );
125  }
126 
127  return NULL;
128 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
int mask1
Definition: zero_fork.c:48
unsigned long long length
Definition: iozone.c:17106
int PAPI_event[2]
Definition: data_range.c:30
#define PAPI_NULL
Definition: papi.h:292
int num_events1
Definition: zero_fork.c:49
int PAPI_register_thread(void)
Definition: papi.c:208
return PAPI_OK
Definition: linux-nvml.c:497
int PAPI_profil(void *buf, unsigned bufsiz, caddr_t offset, unsigned scale, int EventSet, int EventCode, int threshold, int flags)
Definition: papi.c:5438
int i
Definition: fileop.c:140
#define THR
long long elapsed_cyc
Definition: zero_fork.c:50
caddr_t my_start
void * profbuf[5]
Definition: prof_utils.c:33
void free_test_space(long long **values, int num_tests)
Definition: test_utils.c:70
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:915
int num_tests
Definition: zero_fork.c:53
void do_flops(int n)
Definition: multiplex.c:23
long long PAPI_get_real_usec(void)
Definition: papi.c:6264
#define PAPI_PROFIL_POSIX
Definition: papi.h:396
printf("\tTry: -i 0 -i 1 \n\n")
int PAPI_unregister_thread(void)
Definition: papi.c:244
int TESTS_QUIET
Definition: test_utils.c:18
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
int
Definition: iozone.c:18528
#define PAPI_MAX_STR_LEN
Definition: papi.h:465
int add_two_nonderived_events(int *num_events, int *papi_event, int *mask)
Definition: test_utils.c:646
long long PAPI_get_real_cyc(void)
Definition: papi.c:6217
int PAPI_start(int EventSet)
Definition: papi.c:2096
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:50
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
int EventSet1
Definition: zero_fork.c:47

Here is the call graph for this function:

Variable Documentation

unsigned int length

Definition at line 16 of file profile_pthreads.c.

caddr_t my_end

Definition at line 17 of file profile_pthreads.c.

caddr_t my_start

Definition at line 17 of file profile_pthreads.c.