PAPI  5.3.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
overflow_single_event.c
Go to the documentation of this file.
1 /*
2 * File: overflow_single_event.c
3 * CVS: $Id$
4 * Author: Philip Mucci
5 * mucci@cs.utk.edu
6 * Mods: <your name here>
7 * <your email address>
8 */
9 
10 /* This file performs the following test: overflow dispatch of an eventset
11  with just a single event.
12 
13  The Eventset contains:
14  + PAPI_FP_INS (overflow monitor)
15 
16  - Start eventset 1
17  - Do flops
18  - Stop and measure eventset 1
19  - Set up overflow on eventset 1
20  - Start eventset 1
21  - Do flops
22  - Stop eventset 1
23 */
24 
25 #include "papi_test.h"
26 
27 #define OVER_FMT "handler(%d ) Overflow at %p overflow_vector=0x%llx!\n"
28 #define OUT_FMT "%-12s : %16lld%16lld\n"
29 
30 static int total = 0; /* total overflows */
31 
32 void
33 handler( int EventSet, void *address, long long overflow_vector, void *context )
34 {
35  ( void ) context;
36 
37  if ( !TESTS_QUIET ) {
38  fprintf( stderr, OVER_FMT, EventSet, address, overflow_vector );
39  }
40 
41  total++;
42 }
43 
44 int
45 main( int argc, char **argv )
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:2225
#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:1597
Hardware info structure.
Definition: papi.h:775
#define OUT_FMT
#define PAPI_NULL
Definition: fpapi.h:13
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43
#define PAPI_TOT_INS
Definition: fpapi.h:185
return PAPI_OK
Definition: linux-nvml.c:458
#define PAPI_FP_OPS
Definition: fpapi.h:237
tests_quiet(argc, argv)
int PAPI_overflow(int EventSet, int EventCode, int threshold, int flags, PAPI_overflow_handler_t handler)
Definition: papi.c:4655
void
Definition: iozone.c:18627
#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:495
Create a new empty PAPI EventSet.
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
long long
Definition: iozone.c:19827
#define min(x, y)
Definition: darwin-common.h:4
#define PAPI_FP_INS
Definition: fpapi.h:187
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:920
char vendor_string[PAPI_MAX_STR_LEN]
Definition: papi.h:783
void do_flops(int n)
Definition: multiplex.c:23
int PAPI_query_event(int EventCode)
Definition: papi.c:695
int EventSet
static int total
Definition: rapl_overflow.c:5
int cpu_max_mhz
Definition: papi.h:791
int
Definition: iozone.c:18528
#define OVER_FMT
char model_string[PAPI_MAX_STR_LEN]
Definition: papi.h:785
int find_nonderived_event(void)
Definition: test_utils.c:159
long long mythreshold
int PAPI_start(int EventSet)
Definition: papi.c:2019
#define THRESHOLD
Definition: earprofile.c:31
const PAPI_hw_info_t * PAPI_get_hardware_info(void)
Definition: papi.c:6046
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
static const PAPI_hw_info_t * hw_info
Definition: byte_profile.c:23
int main(int argc, char **argv)
List all appio events codes and names.
void exit()
#define OVR_TOLERANCE
Definition: test_utils.h:14