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

Macro Definition Documentation

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

Definition at line 31 of file overflow2.c.

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

Definition at line 30 of file overflow2.c.

Function Documentation

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

Definition at line 36 of file overflow2.c.

37 {
38  ( void ) context;
39 
40  if ( !TESTS_QUIET ) {
41  fprintf( stderr, OVER_FMT, EventSet, address, overflow_vector );
42  }
43  total++;
44 }
int EventSet
void
Definition: iozone.c:18627
#define OVER_FMT
Definition: overflow2.c:30
int TESTS_QUIET
Definition: test_utils.c:18
static int total
Definition: rapl_overflow.c:9
int main ( int  argc,
char **  argv 
)

Definition at line 47 of file overflow2.c.

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

Here is the call graph for this function:

Variable Documentation

int total = 0

Definition at line 33 of file overflow2.c.