PAPI  5.4.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 28 of file overflow_single_event.c.

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

Definition at line 27 of file overflow_single_event.c.

Function Documentation

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

Definition at line 33 of file overflow_single_event.c.

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

Definition at line 45 of file overflow_single_event.c.

46 {
47  int EventSet = PAPI_NULL;
48  long long values[2] = { 0, 0 };
49  long long min, max;
50  int num_flops = NUM_FLOPS, retval;
51  int PAPI_event = 0, mythreshold;
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 ( ( !strncmp( hw_info->model_string, "UltraSPARC", 10 ) &&
66  !( strncmp( hw_info->vendor_string, "SUN", 3 ) ) ) ||
67  ( !strncmp( hw_info->model_string, "AMD K7", 6 ) ) ||
68  ( !strncmp( hw_info->vendor_string, "Cray", 4 ) ) ||
69  ( strstr( hw_info->model_string, "POWER3" ) ) ) {
70  /* query and set up the right instruction to monitor */
72  PAPI_event = PAPI_TOT_INS;
73  } else {
74  test_fail( __FILE__, __LINE__,
75  "PAPI_TOT_INS not available on this Sun platform!", 0 );
76  }
77  } else {
78  /* query and set up the right instruction to monitor */
79  PAPI_event = find_nonderived_event( );
80  }
81 
82  if (( PAPI_event == PAPI_FP_OPS ) || ( PAPI_event == PAPI_FP_INS ))
84  else
85 #if defined(linux)
86  mythreshold = ( int ) hw_info->cpu_max_mhz * 20000;
87 #else
88  mythreshold = THRESHOLD * 2;
89 #endif
90 
91  retval = PAPI_create_eventset( &EventSet );
92  if ( retval != PAPI_OK )
93  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
94 
95  retval = PAPI_add_event( EventSet, PAPI_event );
96  if ( retval != PAPI_OK )
97  test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
98 
99  retval = PAPI_start( EventSet );
100  if ( retval != PAPI_OK )
101  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
102 
103  do_flops( NUM_FLOPS );
104 
105  retval = PAPI_stop( EventSet, &values[0] );
106  if ( retval != PAPI_OK )
107  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
108 
109  retval = PAPI_overflow( EventSet, PAPI_event, mythreshold, 0, handler );
110  if ( retval != PAPI_OK )
111  test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
112 
113  retval = PAPI_start( EventSet );
114  if ( retval != PAPI_OK )
115  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
116 
117  do_flops( NUM_FLOPS );
118 
119  retval = PAPI_stop( EventSet, &values[1] );
120  if ( retval != PAPI_OK )
121  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
122 
123 #if defined(linux) || defined(__ia64__) || defined(_POWER4)
124  num_flops *= 2;
125 #endif
126 
127  if ( !TESTS_QUIET ) {
128  if ( ( retval =
129  PAPI_event_code_to_name( PAPI_event, event_name ) ) != PAPI_OK )
130  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
131 
132  printf
133  ( "Test case: Overflow dispatch of 1st event in set with 1 event.\n" );
134  printf
135  ( "--------------------------------------------------------------\n" );
136  printf( "Threshold for overflow is: %d\n", mythreshold );
137  printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
138  printf( "-----------------------------------------------\n" );
139 
140  printf( "Test type : %16d%16d\n", 1, 2 );
141  printf( OUT_FMT, event_name, values[0], values[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  printf("Column 1 approximately equals column 2\n");
150 */
151  printf( "Row 3 approximately equals %u +- %u %%\n",
152  ( unsigned ) ( ( values[0] ) / ( long long ) mythreshold ),
153  ( unsigned ) ( OVR_TOLERANCE * 100.0 ) );
154 
155  }
156 
157 /*
158  min = (long long)(values[0]*(1.0-TOLERANCE));
159  max = (long long)(values[0]*(1.0+TOLERANCE));
160  if ( values[1] > max || values[1] < min )
161  test_fail(__FILE__, __LINE__, event_name, 1);
162 */
163 
164  min =
165  ( long long ) ( ( ( double ) values[0] * ( 1.0 - OVR_TOLERANCE ) ) /
166  ( double ) mythreshold );
167  max =
168  ( long long ) ( ( ( double ) values[0] * ( 1.0 + OVR_TOLERANCE ) ) /
169  ( double ) mythreshold );
170  if ( total > max || total < min )
171  test_fail( __FILE__, __LINE__, "Overflows", 1 );
172 
173  test_pass( __FILE__, NULL, 0 );
174  exit( 1 );
175 }
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 OUT_FMT
#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.
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:16
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:926
char vendor_string[PAPI_MAX_STR_LEN]
Definition: papi.h:785
void do_flops(int n)
Definition: multiplex.c:23
int PAPI_query_event(int EventCode)
Definition: papi.c:698
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
char model_string[PAPI_MAX_STR_LEN]
Definition: papi.h:787
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 total = 0
static

Definition at line 30 of file overflow_single_event.c.