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

Go to the source code of this file.

Macros

#define OVER_FMT   "handler(%d ) Overflow at %p overflow_vector=%#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

static int total = 0
 

Macro Definition Documentation

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

Definition at line 32 of file overflow_single_event.c.

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

Definition at line 31 of file overflow_single_event.c.

Function Documentation

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

Definition at line 37 of file overflow_single_event.c.

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

Definition at line 49 of file overflow_single_event.c.

50 {
51  int EventSet = PAPI_NULL;
52  long long values[2] = { 0, 0 };
53  long long min, max;
54  int num_flops = NUM_FLOPS, retval;
55  int PAPI_event = 0, mythreshold;
57  const PAPI_hw_info_t *hw_info = NULL;
58  int quiet;
59 
60  /* Set TESTS_QUIET variable */
61  quiet=tests_quiet( argc, argv );
62 
64  if ( retval != PAPI_VER_CURRENT ) {
65  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
66  }
67 
68  hw_info = PAPI_get_hardware_info( );
69  if ( hw_info == NULL )
70  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
71 
72  /* Ugh */
73  if ( ( !strncmp( hw_info->model_string, "UltraSPARC", 10 ) &&
74  !( strncmp( hw_info->vendor_string, "SUN", 3 ) ) ) ||
75  ( !strncmp( hw_info->model_string, "AMD K7", 6 ) ) ||
76  ( !strncmp( hw_info->vendor_string, "Cray", 4 ) ) ||
77  ( strstr( hw_info->model_string, "POWER3" ) ) ) {
78  /* query and set up the right instruction to monitor */
80  PAPI_event = PAPI_TOT_INS;
81  } else {
82  test_fail( __FILE__, __LINE__,
83  "PAPI_TOT_INS not available on this Sun platform!", 0 );
84  }
85  } else {
86  /* query and set up the right instruction to monitor */
87  PAPI_event = find_nonderived_event( );
88  }
89 
90  if (PAPI_event==0) {
91  if (!quiet) printf("Trouble adding event\n");
92  test_skip(__FILE__,__LINE__,"Event trouble",1);
93  }
94 
95  if (( PAPI_event == PAPI_FP_OPS ) || ( PAPI_event == PAPI_FP_INS )) {
97  }
98  else {
99 #if defined(linux)
100  mythreshold = ( int ) hw_info->cpu_max_mhz * 20000;
101 #else
102  mythreshold = THRESHOLD * 2;
103 #endif
104  }
105 
106  retval = PAPI_create_eventset( &EventSet );
107  if ( retval != PAPI_OK ) {
108  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
109  }
110 
111  retval = PAPI_add_event( EventSet, PAPI_event );
112  if ( retval != PAPI_OK ) {
113  test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
114  }
115 
116  retval = PAPI_start( EventSet );
117  if ( retval != PAPI_OK ) {
118  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
119  }
120 
121  do_flops( NUM_FLOPS );
122 
123  retval = PAPI_stop( EventSet, &values[0] );
124  if ( retval != PAPI_OK ) {
125  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
126  }
127 
128  retval = PAPI_overflow( EventSet, PAPI_event, mythreshold, 0, handler );
129  if ( retval != PAPI_OK ) {
130  test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
131  }
132 
133  retval = PAPI_start( EventSet );
134  if ( retval != PAPI_OK ) {
135  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
136  }
137 
138  do_flops( NUM_FLOPS );
139 
140  retval = PAPI_stop( EventSet, &values[1] );
141  if ( retval != PAPI_OK ) {
142  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
143  }
144 
145  /* double ugh */
146 #if defined(linux) || defined(__ia64__) || defined(_POWER4)
147  num_flops *= 2;
148 #endif
149 
150  if ( !quiet ) {
151  if ( ( retval =
152  PAPI_event_code_to_name( PAPI_event, event_name ) ) != PAPI_OK )
153  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
154 
155  printf
156  ( "Test case: Overflow dispatch of 1st event in set with 1 event.\n" );
157  printf
158  ( "--------------------------------------------------------------\n" );
159  printf( "Threshold for overflow is: %d\n", mythreshold );
160  printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
161  printf( "-----------------------------------------------\n" );
162 
163  printf( "Test type : %16d%16d\n", 1, 2 );
164  printf( OUT_FMT, event_name, values[0], values[1] );
165  printf( "Overflows : %16s%16d\n", "", total );
166  printf( "-----------------------------------------------\n" );
167 
168  printf( "Verification:\n" );
169 /*
170  if (PAPI_event == PAPI_FP_INS)
171  printf("Row 1 approximately equals %d %d\n", num_flops, num_flops);
172  printf("Column 1 approximately equals column 2\n");
173 */
174  printf( "Row 3 approximately equals %u +- %u %%\n",
175  ( unsigned ) ( ( values[0] ) / ( long long ) mythreshold ),
176  ( unsigned ) ( OVR_TOLERANCE * 100.0 ) );
177 
178  }
179 
180 /*
181  min = (long long)(values[0]*(1.0-TOLERANCE));
182  max = (long long)(values[0]*(1.0+TOLERANCE));
183  if ( values[1] > max || values[1] < min )
184  test_fail(__FILE__, __LINE__, event_name, 1);
185 */
186 
187  min =
188  ( long long ) ( ( ( double ) values[0] * ( 1.0 - OVR_TOLERANCE ) ) /
189  ( double ) mythreshold );
190  max =
191  ( long long ) ( ( ( double ) values[0] * ( 1.0 + OVR_TOLERANCE ) ) /
192  ( double ) mythreshold );
193  if ( total > max || total < min )
194  test_fail( __FILE__, __LINE__, "Overflows", 1 );
195 
196  test_pass( __FILE__ );
197 
198  return 0;
199 }
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 OUT_FMT
#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
int quiet
Definition: rapl_overflow.c:18
long long
Definition: iozone.c:19827
#define min(x, y)
Definition: darwin-common.h:4
void handler(int EventSet, void *address, long long overflow_vector, void *context)
Definition: rapl_overflow.c:20
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:915
char vendor_string[PAPI_MAX_STR_LEN]
Definition: papi.h:788
void do_flops(int n)
Definition: multiplex.c:23
int PAPI_query_event(int EventCode)
Definition: papi.c:684
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
char model_string[PAPI_MAX_STR_LEN]
Definition: papi.h:790
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
static

Definition at line 34 of file overflow_single_event.c.