PAPI  5.4.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
overflow2.c File Reference
Include dependency graph for overflow2.c:

Go to the source code of this file.

Macros

#define OVER_FMT   "handler(%d ) Overflow at %p! bit=%#llx \n"
 
#define OUT_FMT   "%-12s : %16lld%16lld\n"
 

Functions

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

Variables

int total = 0
 
int TESTS_QUIET
 

Macro Definition Documentation

#define OUT_FMT   "%-12s : %16lld%16lld\n"

Definition at line 28 of file overflow2.c.

#define OVER_FMT   "handler(%d ) Overflow at %p! bit=%#llx \n"

Definition at line 27 of file overflow2.c.

Function Documentation

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

Definition at line 34 of file overflow2.c.

35 {
36  ( void ) context;
37 
38  if ( !TESTS_QUIET ) {
39  fprintf( stderr, OVER_FMT, EventSet, address, overflow_vector );
40  }
41  total++;
42 }
int EventSet
Definition: data_range.c:25
void
Definition: iozone.c:18627
int TESTS_QUIET
Definition: test_utils.c:11
#define OVER_FMT
Definition: overflow2.c:27
static int total
Definition: rapl_overflow.c:5
int main ( int  argc,
char **  argv 
)

Definition at line 45 of file overflow2.c.

46 {
47  int EventSet = PAPI_NULL;
48  long long ( values[2] )[2];
49  long long min, max;
50  int num_flops, retval;
53  const PAPI_hw_info_t *hw_info = NULL;
54 
55  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
56 
58  if ( retval != PAPI_VER_CURRENT )
59  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
60 
61  hw_info = PAPI_get_hardware_info( );
62  if ( hw_info == NULL )
63  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
64 
65 #if defined(POWER3) || defined(__sparc__)
66  PAPI_event = PAPI_TOT_INS;
67 #else
68  /* query and set up the right instruction to monitor */
69  PAPI_event = find_nonderived_event( );
70 #endif
71 
72  if (( PAPI_event == PAPI_FP_OPS ) || ( PAPI_event == PAPI_FP_INS ))
73  mythreshold = THRESHOLD;
74  else
75 #if defined(linux)
76  mythreshold = ( int ) hw_info->cpu_max_mhz * 10000 * 2;
77 #else
78  mythreshold = THRESHOLD * 2;
79 #endif
80 
81  retval = PAPI_create_eventset( &EventSet );
82  if ( retval != PAPI_OK )
83  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
84 
85  retval = PAPI_add_event( EventSet, PAPI_event );
86  if ( retval != PAPI_OK )
87  test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
88 
89  retval = PAPI_add_event( EventSet, PAPI_TOT_CYC );
90  if ( retval != PAPI_OK )
91  test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
92 
93  retval = PAPI_start( EventSet );
94  if ( retval != PAPI_OK )
95  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
96 
98 
99  retval = PAPI_stop( EventSet, values[0] );
100  if ( retval != PAPI_OK )
101  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
102 
103  retval = PAPI_overflow( EventSet, PAPI_event, mythreshold, 0, handler );
104  if ( retval != PAPI_OK )
105  test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
106 
107  retval = PAPI_start( EventSet );
108  if ( retval != PAPI_OK )
109  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
110 
111  do_flops( NUM_FLOPS );
112 
113  retval = PAPI_stop( EventSet, values[1] );
114  if ( retval != PAPI_OK )
115  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
116 
117  retval = PAPI_overflow( EventSet, PAPI_event, 0, 0, handler );
118  if ( retval != PAPI_OK )
119  test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
120 
121  num_flops = NUM_FLOPS;
122 #if defined(linux) || defined(__ia64__) || defined(_POWER4)
123  num_flops *= 2;
124 #endif
125 
126  if ( !TESTS_QUIET ) {
127  if ( ( retval =
128  PAPI_event_code_to_name( PAPI_event, event_name ) ) != PAPI_OK )
129  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
130 
131  printf
132  ( "Test case: Overflow dispatch of 1st event in set with 2 events.\n" );
133  printf
134  ( "---------------------------------------------------------------\n" );
135  printf( "Threshold for overflow is: %d\n", mythreshold );
136  printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
137  printf( "-----------------------------------------------\n" );
138 
139  printf( "Test type : %16d%16d\n", 1, 2 );
140  printf( OUT_FMT, event_name, ( values[0] )[0], ( values[1] )[0] );
141  printf( OUT_FMT, "PAPI_TOT_CYC", ( values[0] )[1], ( values[1] )[1] );
142  printf( "Overflows : %16s%16d\n", "", total );
143  printf( "-----------------------------------------------\n" );
144 
145  printf( "Verification:\n" );
146 /*
147  if (PAPI_event == PAPI_FP_INS)
148  printf("Row 1 approximately equals %d %d\n", num_flops, num_flops);
149 */
150  /* Note that the second run prints output on stdout. On some systems
151  * this is costly. PAPI_TOT_INS or PAPI_TOT_CYC are likely to be _very_
152  * different between the two runs.
153  * printf("Column 1 approximately equals column 2\n");
154  */
155  printf( "Row 3 approximately equals %u +- %u %%\n",
156  ( unsigned ) ( ( values[0] )[0] / ( long long ) mythreshold ),
157  ( unsigned ) ( OVR_TOLERANCE * 100.0 ) );
158  }
159 /*
160  min = (long long)((values[0])[0]*(1.0-TOLERANCE));
161  max = (long long)((values[0])[0]*(1.0+TOLERANCE));
162  if ( (values[1])[0] > max || (values[1])[0] < min )
163  test_fail(__FILE__, __LINE__, event_name, 1);
164 */
165 
166  min =
167  ( long long ) ( ( ( double ) values[0][0] * ( 1.0 - OVR_TOLERANCE ) ) /
168  ( double ) mythreshold );
169  max =
170  ( long long ) ( ( ( double ) values[0][0] * ( 1.0 + OVR_TOLERANCE ) ) /
171  ( double ) mythreshold );
172  if ( total > max || total < min )
173  test_fail( __FILE__, __LINE__, "Overflows", 1 );
174 
175  test_pass( __FILE__, NULL, 0 );
176  exit( 1 );
177 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:23
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2258
#define NUM_FLOPS
int PAPI_event[2]
Definition: data_range.c:24
off64_t max
Definition: libasync.c:331
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1622
Hardware info structure.
Definition: papi.h:777
#define PAPI_FP_OPS
#define PAPI_NULL
Definition: papi.h:290
int EventSet
Definition: data_range.c:25
#define PAPI_TOT_INS
return PAPI_OK
Definition: linux-nvml.c:458
tests_quiet(argc, argv)
int PAPI_overflow(int EventSet, int EventCode, int threshold, int flags, PAPI_overflow_handler_t handler)
Definition: papi.c:4714
#define printf
Definition: papi_test.h:125
static double
Definition: fileop.c:1281
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_library_init(int version)
Definition: papi.c:497
Create a new empty PAPI EventSet.
#define PAPI_TOT_CYC
long long
Definition: iozone.c:19827
#define min(x, y)
Definition: darwin-common.h:4
#define OUT_FMT
Definition: overflow2.c:28
void handler(int EventSet, void *address, long long overflow_vector, void *context)
Definition: rapl_overflow.c:16
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:926
void do_flops(int n)
Definition: multiplex.c:23
static int total
Definition: rapl_overflow.c:5
int cpu_max_mhz
Definition: papi.h:793
int
Definition: iozone.c:18528
#define PAPI_MAX_STR_LEN
Definition: papi.h:463
int find_nonderived_event(void)
Definition: test_utils.c:159
long long mythreshold
int PAPI_start(int EventSet)
Definition: papi.c:2053
#define THRESHOLD
Definition: earprofile.c:31
const PAPI_hw_info_t * PAPI_get_hardware_info(void)
Definition: papi.c:6111
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
#define PAPI_VER_CURRENT
Definition: papi.h:223
static const PAPI_hw_info_t * hw_info
Definition: byte_profile.c:23
void exit()
#define PAPI_FP_INS
#define OVR_TOLERANCE
Definition: test_utils.h:14

Here is the call graph for this function:

Variable Documentation

int TESTS_QUIET

Definition at line 11 of file test_utils.c.

int total = 0

Definition at line 30 of file overflow2.c.