PAPI  5.6.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ctests/overflow_pthreads.c File Reference
Include dependency graph for ctests/overflow_pthreads.c:

Go to the source code of this file.

Functions

static void handler (int EventSet, void *address, long long overflow_vector, void *context)
 
static voidThread (void *arg)
 
int main (int argc, char **argv)
 

Variables

static const PAPI_hw_info_thw_info = NULL
 
static int total [NUM_THREADS]
 
static int expected [NUM_THREADS]
 
static pthread_t myid [NUM_THREADS]
 
static long long mythreshold =0
 

Function Documentation

static void handler ( int  EventSet,
void address,
long long  overflow_vector,
void context 
)
static

Definition at line 33 of file ctests/overflow_pthreads.c.

34 {
35 #if 0
36  printf( "handler(%d,%#lx,%llx) Overflow %d in thread %lx\n",
37  EventSet, ( unsigned long ) address, overflow_vector,
39  printf( "%lx vs %lx\n", myid[EventSet], PAPI_thread_id( ) );
40 #else /* eliminate unused parameter warning message */
41  ( void ) address;
42  ( void ) overflow_vector;
43  ( void ) context;
44 #endif
45  total[EventSet]++;
46 }
unsigned long PAPI_thread_id(void)
Definition: papi.c:162
long long myid
Definition: iozone.c:1335
int EventSet
void
Definition: iozone.c:18627
printf("\tTry: -i 0 -i 1 \n\n")
static int total
Definition: rapl_overflow.c:9

Here is the call graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 132 of file ctests/overflow_pthreads.c.

133 {
135  int flops[NUM_THREADS];
136  int i, rc, retval;
137  pthread_attr_t attr;
138  float ratio;
139  int quiet;
140 
141  /* Set TESTS_QUIET variable */
142  quiet = tests_quiet( argc, argv );
143 
144  memset( total, 0x0, NUM_THREADS * sizeof ( *total ) );
145  memset( expected, 0x0, NUM_THREADS * sizeof ( *expected ) );
146  memset( myid, 0x0, NUM_THREADS * sizeof ( *myid ) );
147 
149  if (retval != PAPI_VER_CURRENT ) {
150  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
151  }
152 
154  if ( hw_info == NULL ) {
155  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
156  }
157 
158  retval = PAPI_thread_init( ( unsigned long ( * )( void ) )
159  ( pthread_self ) );
160  if (retval != PAPI_OK ) {
161  if ( retval == PAPI_ECMP )
162  test_skip( __FILE__, __LINE__, "PAPI_thread_init", retval );
163  else
164  test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval );
165  }
166 #if defined(linux)
167  mythreshold = ((long long)hw_info->cpu_max_mhz) * 10000 * 2;
168 #else
169  mythreshold = THRESHOLD * 2;
170 #endif
171 
172  pthread_attr_init( &attr );
173 #ifdef PTHREAD_CREATE_UNDETACHED
174  pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_UNDETACHED );
175 #endif
176 #ifdef PTHREAD_SCOPE_SYSTEM
177  retval = pthread_attr_setscope( &attr, PTHREAD_SCOPE_SYSTEM );
178  if ( retval != 0 )
179  test_skip( __FILE__, __LINE__, "pthread_attr_setscope", retval );
180 #endif
181 
182  for ( i = 0; i < NUM_THREADS; i++ ) {
183  flops[i] = NUM_FLOPS * ( i + 1 );
184  rc = pthread_create( &id[i], &attr, Thread, ( void * ) &flops[i] );
185  if ( rc )
186  test_fail( __FILE__, __LINE__, "pthread_create", PAPI_ESYS );
187  }
188  for ( i = 0; i < NUM_THREADS; i++ )
189  pthread_join( id[i], NULL );
190 
191  pthread_attr_destroy( &attr );
192 
193  {
194  long long t = 0, r = 0;
195  for ( i = 0; i < NUM_THREADS; i++ ) {
196  t += ( NUM_FLOPS * ( i + 1 ) ) / mythreshold;
197  r += total[i];
198  }
199  if (!quiet) {
200  printf( "Expected total overflows: %lld\n", t );
201  printf( "Received total overflows: %lld\n", r );
202  }
203  }
204 // FIXME: are we actually testing this properly?
205 
206 /* ratio = (float)total[0] / (float)expected[0]; */
207 /* printf("Ratio of total to expected: %f\n",ratio); */
208  ratio = 1.0;
209  for ( i = 0; i < NUM_THREADS; i++ ) {
210  if (!quiet) printf( "Overflows thread %d: %d, expected %d\n",
211  i, total[i], ( int ) ( ratio * ( float ) expected[i] ) );
212  }
213 
214  for ( i = 0; i < NUM_THREADS; i++ ) {
215  if ( total[i] < ( int ) ( ( ratio * ( float ) expected[i] ) / 2.0 ) )
216  test_fail( __FILE__, __LINE__, "not enough overflows", PAPI_EMISC );
217  }
218 
219  test_pass( __FILE__ );
220 
221  pthread_exit( NULL );
222 
223  return 0;
224 
225 }
#define NUM_THREADS
Definition: do_loops.h:8
void test_pass(const char *filename)
Definition: test_utils.c:432
static int expected[NUM_THREADS]
long long myid
Definition: iozone.c:1335
return PAPI_OK
Definition: linux-nvml.c:497
#define NUM_FLOPS
Definition: sdsc-mpx.c:24
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
#define PAPI_EMISC
Definition: papi.h:267
t
Definition: iozone.c:23562
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_ESYS
Definition: papi.h:255
long long
Definition: iozone.c:19827
#define PAPI_ECMP
Definition: papi.h:256
pthread_t
Definition: iozone.c:18557
printf("\tTry: -i 0 -i 1 \n\n")
static int total
Definition: rapl_overflow.c:9
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 cpu_max_mhz
Definition: papi.h:796
static void * Thread(void *arg)
static long long mythreshold
#define THRESHOLD
Definition: earprofile.c:37
const PAPI_hw_info_t * PAPI_get_hardware_info(void)
Definition: papi.c:6185
ssize_t retval
Definition: libasync.c:338
#define PAPI_VER_CURRENT
Definition: papi.h:225
static const PAPI_hw_info_t * hw_info
Definition: byte_profile.c:28
pthread_attr_t attr
Definition: iozone.c:18466

Here is the call graph for this function:

static void* Thread ( void arg)
static

Definition at line 51 of file ctests/overflow_pthreads.c.

52 {
53  int retval, num_tests = 1;
54  int EventSet1 = PAPI_NULL;
55  int mask1, papi_event;
56  int num_events1;
57  long long **values;
58  long long elapsed_us, elapsed_cyc;
60 
61  retval = PAPI_register_thread( );
62  if ( retval != PAPI_OK )
63  test_fail( __FILE__, __LINE__, "PAPI_register_thread", retval );
64 
65  /* add PAPI_TOT_CYC and one of the events in PAPI_FP_INS, PAPI_FP_OPS or
66  PAPI_TOT_INS, depends on the availability of the event on the
67  platform */
68  EventSet1 =
69  add_two_nonderived_events( &num_events1, &papi_event, &mask1 );
70 
71  if (EventSet1 < 0) return NULL;
72 
73  /* Wait, we're indexing a per-thread array with the EventSet number? */
74  /* does that make any sense at all???? -- vmw */
75  expected[EventSet1] = *( int * ) arg / mythreshold;
77 
78  values = allocate_test_space( num_tests, num_events1 );
79 
80  elapsed_us = PAPI_get_real_usec( );
81 
82  elapsed_cyc = PAPI_get_real_cyc( );
83 
84  if ((retval = PAPI_overflow( EventSet1, papi_event,
85  mythreshold, 0, handler ) ) != PAPI_OK ) {
86  test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
87  }
88 
89  /* start_timer(1); */
90  if ( ( retval = PAPI_start( EventSet1 ) ) != PAPI_OK )
91  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
92 
93  do_stuff( );
94 
95  if ( ( retval = PAPI_stop( EventSet1, values[0] ) ) != PAPI_OK )
96  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
97 
98  elapsed_us = PAPI_get_real_usec( ) - elapsed_us;
99 
100  elapsed_cyc = PAPI_get_real_cyc( ) - elapsed_cyc;
101 
102  retval = PAPI_overflow( EventSet1, papi_event, 0, 0, NULL );
103  if (retval != PAPI_OK ) {
104  test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
105  }
106 
107  remove_test_events( &EventSet1, mask1 );
108 
109  retval = PAPI_event_code_to_name( papi_event, event_name );
110  if (retval != PAPI_OK ) {
111  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
112  }
113 
114  if ( !TESTS_QUIET ) {
115  printf( "Thread %#x %s : \t%lld\n", ( int ) pthread_self( ),
116  event_name, ( values[0] )[0] );
117  printf( "Thread %#x PAPI_TOT_CYC: \t%lld\n", ( int ) pthread_self( ),
118  ( values[0] )[1] );
119  printf( "Thread %#x Real usec : \t%lld\n", ( int ) pthread_self( ),
120  elapsed_us );
121  printf( "Thread %#x Real cycles : \t%lld\n", ( int ) pthread_self( ),
122  elapsed_cyc );
123  }
124  free_test_space( values, num_tests );
125  retval = PAPI_unregister_thread( );
126  if ( retval != PAPI_OK )
127  test_fail( __FILE__, __LINE__, "PAPI_unregister_thread", retval );
128  return ( NULL );
129 }
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
static int expected[NUM_THREADS]
unsigned long PAPI_thread_id(void)
Definition: papi.c:162
long long myid
Definition: iozone.c:1335
#define PAPI_NULL
Definition: papi.h:292
int num_events1
Definition: zero_fork.c:49
void do_stuff(void)
Definition: do_loops.c:256
int PAPI_register_thread(void)
Definition: papi.c:208
return PAPI_OK
Definition: linux-nvml.c:497
int PAPI_overflow(int EventSet, int EventCode, int threshold, int flags, PAPI_overflow_handler_t handler)
Definition: papi.c:4788
long long elapsed_cyc
Definition: zero_fork.c:50
void free_test_space(long long **values, int num_tests)
Definition: test_utils.c:70
void handler(int EventSet, void *address, long long overflow_vector, void *context)
Definition: rapl_overflow.c:20
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:915
int num_tests
Definition: zero_fork.c:53
long long PAPI_get_real_usec(void)
Definition: papi.c:6264
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
#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
static long long mythreshold
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:

Here is the caller graph for this function:

Variable Documentation

int expected[NUM_THREADS]
static

Definition at line 29 of file ctests/overflow_pthreads.c.

const PAPI_hw_info_t* hw_info = NULL
static

Definition at line 27 of file ctests/overflow_pthreads.c.

pthread_t myid[NUM_THREADS]
static

Definition at line 30 of file ctests/overflow_pthreads.c.

long long mythreshold =0
static

Definition at line 48 of file ctests/overflow_pthreads.c.

int total[NUM_THREADS]
static

Definition at line 28 of file ctests/overflow_pthreads.c.