PAPI  5.3.2.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
overflow_values.c
Go to the documentation of this file.
1 /*
2 * File: overflow_values.c
3 * CVS: $Id$
4 * Author: Harald Servat
5 * harald@cepba.upc.edu
6 * Mods: <your name here>
7 * <your email address>
8 */
9 
10 /* This file performs the following test: overflow values check
11 
12  The Eventset contains:
13  + PAPI_TOT_INS (overflow monitor)
14  + PAPI_TOT_CYC
15  + PAPI_L1_DCM
16 
17  - Start eventset
18  - Read and report event counts mod 1000
19  - report overflow event counts
20  - visually inspect for consistency
21  - Stop eventset
22 */
23 
24 #include "papi_test.h"
25 
26 #define OVRFLOW 5000000
27 #define LOWERFLOW (OVRFLOW - (OVRFLOW/100))
28 #define UPPERFLOW (OVRFLOW/100)
29 #define ERRORFLOW (UPPERFLOW/5)
30 static long long ovrflow = 0;
31 
32 void
33 handler( int EventSet, void *address, long long overflow_vector, void *context )
34 {
35  int ret;
36  int i;
37  long long vals[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
38 
39  printf( "\nOverflow at %p! bit=%#llx \n", address, overflow_vector );
40  ret = PAPI_read( EventSet, vals );
41  printf( "Overflow read vals :" );
42  for ( i = 0; i < 3 /* 8 */ ; i++ )
43  printf( "%lld ", vals[i] );
44  printf( "\n\n" );
45  ovrflow = vals[0];
46 }
47 
48 int
49 main( int argc, char *argv[] )
50 {
51  int EventSet = PAPI_NULL;
52  int retval, i, dash = 0, evt3 = PAPI_L1_DCM;
54  PAPI_option_t options2;
55  const PAPI_hw_info_t *hwinfo;
56  long long lwrflow = 0, error, max_error = 0;
57  long long vals[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
58 
59  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
60 
62  if ( retval != PAPI_VER_CURRENT && retval > 0 )
63  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
64 
65  retval = PAPI_get_opt( PAPI_HWINFO, &options );
66  if ( retval < 0 )
67  test_fail( __FILE__, __LINE__, "PAPI_get_opt", retval );
68  printf( "ovf_info = %d (%#x)\n", options.ovf_info.type,
69  options.ovf_info.type );
70 
71  retval = PAPI_get_opt( PAPI_SUBSTRATEINFO, &options2 );
72  if ( retval < 0 )
73  test_fail( __FILE__, __LINE__, "PAPI_get_opt", retval );
74  printf( "sub_info->hardware_intr = %d\n\n",
75  options2.sub_info->hardware_intr );
76 
77  if ( ( hwinfo = PAPI_get_hardware_info( ) ) == NULL )
78  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", PAPI_EMISC );
79 
80  printf( "Architecture %s, %d\n", hwinfo->model_string, hwinfo->model );
81 
82 /* processing exceptions is a pain */
83 #if ((defined(linux) && (defined(__i386__) || (defined __x86_64__))) )
84  if ( !strncmp( hwinfo->model_string, "Intel Pentium 4", 15 ) ) {
85  evt3 = PAPI_L2_TCM;
86  } else if ( !strncmp( hwinfo->model_string, "AMD K7", 6 ) ) {
87  /* do nothing */
88  } else if ( !strncmp( hwinfo->model_string, "AMD K8", 6 ) ) {
89  /* do nothing */
90  } else if ( !strncmp( hwinfo->model_string, "Intel Core", 10 ) ) {
91  evt3 = 0;
92  } else
93  evt3 = 0; /* for default PIII */
94 #endif
95 
96  retval = PAPI_create_eventset( &EventSet );
97  if ( retval < 0 )
98  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
99 
100  retval = PAPI_add_event( EventSet, PAPI_TOT_INS );
101  if ( retval < 0 )
102  test_fail( __FILE__, __LINE__, "PAPI_add_event:PAPI_TOT_INS", retval );
103  retval = PAPI_add_event( EventSet, PAPI_TOT_CYC );
104  if ( retval < 0 )
105  test_fail( __FILE__, __LINE__, "PAPI_add_event:PAPI_TOT_CYC", retval );
106  if ( evt3 ) {
107  retval = PAPI_add_event( EventSet, evt3 );
108  if ( retval < 0 )
109  test_fail( __FILE__, __LINE__, "PAPI_add_event:evt3", retval );
110  }
111  retval = PAPI_overflow( EventSet, PAPI_TOT_INS, OVRFLOW, 0, handler );
112  if ( retval < 0 )
113  test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
114 
115  retval = PAPI_start( EventSet );
116  if ( retval < 0 )
117  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
118 
119  for ( i = 0; i < 1000000; i++ ) {
120  if ( i % 1000 == 0 ) {
121  int i;
122 
123  PAPI_read( EventSet, vals );
124  if ( vals[0] % OVRFLOW > LOWERFLOW ||
125  vals[0] % OVRFLOW < UPPERFLOW ) {
126  dash = 0;
127  printf( "Main loop read vals :" );
128  for ( i = 0; i < 3 /* 8 */ ; i++ )
129  printf( "%lld ", vals[i] );
130  printf( "\n" );
131  if ( ovrflow ) {
132  error = ovrflow - ( lwrflow + vals[0] ) / 2;
133  printf( "Difference: %lld\n", error );
134  ovrflow = 0;
135  if ( abs( error ) > max_error )
136  max_error = abs( error );
137  }
138  lwrflow = vals[0];
139  } else if ( vals[0] % OVRFLOW > UPPERFLOW && !dash ) {
140  dash = 1;
141  printf( "---------------------\n" );
142  }
143  }
144  }
145 
146  retval = PAPI_stop( EventSet, vals );
147  if ( retval != PAPI_OK )
148  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
149 
150  retval = PAPI_cleanup_eventset( EventSet );
151  if ( retval != PAPI_OK )
152  test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );
153 
154  retval = PAPI_destroy_eventset( &EventSet );
155  if ( retval != PAPI_OK )
156  test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );
157 
158  printf( "Verification:\n" );
159  printf
160  ( "Maximum absolute difference between overflow value\nand adjacent measured values is: %lld\n",
161  max_error );
162  if ( max_error >= ERRORFLOW ) {
163  printf( "This exceeds the error limit: %d\n", ERRORFLOW );
164  test_fail( __FILE__, __LINE__, "Overflows", 1 );
165  }
166  printf( "This is within the error limit: %d\n", ERRORFLOW );
167  test_pass( __FILE__, NULL, 0 );
168  exit( 1 );
169 }
#define ERRORFLOW
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2232
#define PAPI_L2_TCM
Definition: fpapi.h:142
#define PAPI_EMISC
Definition: fpapi.h:119
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1604
Hardware info structure.
Definition: papi.h:775
#define PAPI_NULL
Definition: fpapi.h:13
#define PAPI_TOT_INS
Definition: fpapi.h:185
static long long ovrflow
#define UPPERFLOW
return PAPI_OK
Definition: linux-nvml.c:458
#define LOWERFLOW
tests_quiet(argc, argv)
int PAPI_overflow(int EventSet, int EventCode, int threshold, int flags, PAPI_overflow_handler_t handler)
Definition: papi.c:4668
A pointer to the following is passed to PAPI_set/get_opt()
Definition: papi.h:843
#define printf
Definition: papi_test.h:125
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
long long ret
Definition: iozone.c:1346
char ** argv
Definition: iozone.c:1610
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_library_init(int version)
Definition: papi.c:495
int i
Definition: fileop.c:140
#define PAPI_TOT_CYC
Definition: fpapi.h:194
int PAPI_get_opt(int option, PAPI_option_t *ptr)
Definition: papi.c:4041
#define PAPI_HWINFO
Definition: fpapi.h:59
#define OVRFLOW
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
void handler(int EventSet, void *address, long long overflow_vector, void *context)
Definition: rapl_overflow.c:16
int PAPI_cleanup_eventset(int EventSet)
Definition: papi.c:2805
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1406
int EventSet
#define PAPI_L1_DCM
Definition: fpapi.h:135
int model
Definition: papi.h:784
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:1944
char model_string[PAPI_MAX_STR_LEN]
Definition: papi.h:785
int PAPI_read(int EventSet, long long *values)
Definition: papi.c:2476
int PAPI_start(int EventSet)
Definition: papi.c:2026
const PAPI_hw_info_t * PAPI_get_hardware_info(void)
Definition: papi.c:6059
ssize_t retval
Definition: libasync.c:338
static options_t options
int main(int argc, char **argv)
List all appio events codes and names.
void exit()