PAPI 7.1.0.0
Loading...
Searching...
No Matches
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)
30static long long ovrflow = 0;
31
32void
33handler( 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
48int
49main( 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
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
97 if ( retval < 0 )
98 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
99
101 if ( retval < 0 )
102 test_fail( __FILE__, __LINE__, "PAPI_add_event:PAPI_TOT_INS", retval );
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 }
112 if ( retval < 0 )
113 test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
114
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
151 if ( retval != PAPI_OK )
152 test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );
153
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}
int i
add PAPI preset or native hardware event to an event set
Empty and destroy an EventSet.
Create a new empty PAPI EventSet.
Empty and destroy an EventSet.
get information about the system hardware
Get PAPI library or event set options.
initialize the PAPI library.
Set up an event set to begin registering overflows.
Read hardware counters from an event set.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_TOT_CYC
Definition: f90papi.h:308
#define PAPI_L1_DCM
Definition: f90papi.h:364
#define PAPI_L2_TCM
Definition: f90papi.h:320
#define PAPI_EMISC
Definition: f90papi.h:122
#define PAPI_TOT_INS
Definition: f90papi.h:317
#define PAPI_HWINFO
Definition: f90papi.h:27
static int EventSet
Definition: init_fini.c:8
static long long ovrflow
#define OVRFLOW
#define LOWERFLOW
#define UPPERFLOW
#define ERRORFLOW
void handler(int EventSet, void *address, long long overflow_vector, void *context)
static options_t options
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:491
void PAPI_NORETURN test_pass(const char *filename)
Definition: test_utils.c:432
int main()
Definition: pernode.c:20
Hardware info structure.
Definition: papi.h:774
int model
Definition: papi.h:783
char model_string[PAPI_MAX_STR_LEN]
Definition: papi.h:784
A pointer to the following is passed to PAPI_set/get_opt()
Definition: papi.h:843
int retval
Definition: zero_fork.c:53