PAPI 7.1.0.0
Loading...
Searching...
No Matches
overflow.c
Go to the documentation of this file.
1/*
2* File: overflow.c
3* Author: Philip Mucci
4* mucci@cs.utk.edu
5*/
6
7/* This file performs the following test: overflow dispatch
8
9 The Eventset contains:
10 + PAPI_TOT_CYC
11 + PAPI_FP_INS (overflow monitor)
12
13 - Start eventset 1
14 - Do flops
15 - Stop and measure eventset 1
16 - Set up overflow on eventset 1
17 - Start eventset 1
18 - Do flops
19 - Stop eventset 1
20*/
21
22#include <stdio.h>
23#include <stdlib.h>
24
25#include "papi.h"
26#include "papi_test.h"
27
28#include "do_loops.h"
29
30#define OVER_FMT "handler(%d ) Overflow at %p! bit=%#llx \n"
31#define OUT_FMT "%-12s : %16lld%16lld\n"
32
33static int total = 0; /* total overflows */
34
35
36void
37handler( int EventSet, void *address, long long overflow_vector, void *context )
38{
39 ( void ) context;
40
41 if ( !TESTS_QUIET ) {
42 fprintf( stderr, OVER_FMT, EventSet, address, overflow_vector );
43 }
44 total++;
45}
46
47int
48main( int argc, char **argv )
49{
50 int EventSet = PAPI_NULL;
51 long long ( values[2] )[2];
52 long long min, max;
53 int num_flops = NUM_FLOPS, retval;
55 char event_name1[PAPI_MAX_STR_LEN];
56 const PAPI_hw_info_t *hw_info = NULL;
57 int num_events, mask;
58 int quiet;
59
60 /* Set TESTS_QUIET variable */
61 quiet = tests_quiet( argc, argv );
62
63 /* Init PAPI */
65 if ( retval != PAPI_VER_CURRENT ) {
66 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
67 }
68
69 /* Get hardware info */
71 if ( hw_info == NULL ) {
72 test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
73 }
74
75 /* add PAPI_TOT_CYC and one of the events in */
76 /* PAPI_FP_INS, PAPI_FP_OPS or PAPI_TOT_INS, */
77 /* depending on the availability of the event on */
78 /* the platform */
80
81 if (num_events==0) {
82 if (!quiet) printf("Trouble adding event!\n");
83 test_skip(__FILE__,__LINE__,"Event add",1);
84 }
85
86 if (!quiet) {
87 printf("Using %#x for the overflow event\n",PAPI_event);
88 }
89
90 if ( PAPI_event == PAPI_FP_INS ) {
92 }
93 else {
94#if defined(linux)
95 mythreshold = ( int ) hw_info->cpu_max_mhz * 20000;
96#else
98#endif
99 }
100
101 /* Start the run calibration run */
103 if ( retval != PAPI_OK )
104 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
105
107
108 /* stop the calibration run */
110 if ( retval != PAPI_OK )
111 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
112
113
114 /* set up overflow handler */
116 if ( retval != PAPI_OK ) {
117 test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
118 }
119
120 /* Start overflow run */
122 if ( retval != PAPI_OK ) {
123 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
124 }
125
126 do_flops( num_flops );
127
128 /* stop overflow run */
130 if ( retval != PAPI_OK )
131 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
133 if ( retval != PAPI_OK )
134 test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
135
136 if ( !TESTS_QUIET ) {
137 retval = PAPI_event_code_to_name( PAPI_event, event_name1 );
138 if (retval != PAPI_OK ) {
139 test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
140 }
141
142 printf( "Test case: Overflow dispatch of 2nd event in set with 2 events.\n" );
143 printf( "---------------------------------------------------------------\n" );
144 printf( "Threshold for overflow is: %d\n", mythreshold );
145 printf( "Using %d iterations of c += a*b\n", num_flops );
146 printf( "-----------------------------------------------\n" );
147
148 printf( "Test type : %16d%16d\n", 1, 2 );
149 printf( OUT_FMT, event_name1, ( values[0] )[1], ( values[1] )[1] );
150 printf( OUT_FMT, "PAPI_TOT_CYC", ( values[0] )[0], ( values[1] )[0] );
151 printf( "Overflows : %16s%16d\n", "", total );
152 printf( "-----------------------------------------------\n" );
153 }
154
156 if ( retval != PAPI_OK )
157 test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );
158
160 if ( retval != PAPI_OK )
161 test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );
162
163 if ( !TESTS_QUIET ) {
164 printf( "Verification:\n" );
165#if defined(linux) || defined(__ia64__) || defined(_POWER4)
166 num_flops *= 2;
167#endif
169 printf( "Row 1 approximately equals %d %d\n", num_flops,
170 num_flops );
171 }
172 printf( "Column 1 approximately equals column 2\n" );
173 printf( "Row 3 approximately equals %u +- %u %%\n",
174 ( unsigned ) ( ( values[0] )[1] / ( long long ) mythreshold ),
175 ( unsigned ) ( OVR_TOLERANCE * 100.0 ) );
176 }
177/*
178 min = (long long)((values[0])[1]*(1.0-TOLERANCE));
179 max = (long long)((values[0])[1]*(1.0+TOLERANCE));
180 if ( (values[0])[1] > max || (values[0])[1] < min )
181 test_fail(__FILE__, __LINE__, event_name, 1);
182*/
183
184 min =
185 ( long long ) ( ( ( double ) values[0][1] * ( 1.0 - OVR_TOLERANCE ) ) /
186 ( double ) mythreshold );
187 max =
188 ( long long ) ( ( ( double ) values[0][1] * ( 1.0 + OVR_TOLERANCE ) ) /
189 ( double ) mythreshold );
190 if (!quiet) {
191 printf( "Overflows: total(%d) > max(%lld) || "
192 "total(%d) < min(%lld) \n", total, max, total, min );
193 }
194 if ( total > max || total < min ) {
195 test_fail( __FILE__, __LINE__, "Overflows", 1 );
196 }
197
198 test_pass( __FILE__ );
199 return 0;
200
201}
static const PAPI_hw_info_t * hw_info
Definition: byte_profile.c:28
Empty and destroy an EventSet.
Empty and destroy an EventSet.
Convert a numeric hardware event code to a name.
get information about the system hardware
initialize the PAPI library.
Set up an event set to begin registering overflows.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
static long long mythreshold
#define min(x, y)
Definition: darwin-common.h:4
int PAPI_event[2]
Definition: data_range.c:30
#define OVR_TOLERANCE
Definition: do_loops.h:14
#define THRESHOLD
Definition: earprofile.c:37
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_FP_INS
Definition: f90papi.h:366
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
#define PAPI_FP_OPS
Definition: f90papi.h:319
static int EventSet
Definition: init_fini.c:8
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
static int num_events
void do_flops(int n)
Definition: multiplex.c:23
int TESTS_QUIET
Definition: test_utils.c:18
#define OVER_FMT
Definition: overflow.c:30
static int total
Definition: overflow.c:33
void handler(int EventSet, void *address, long long overflow_vector, void *context)
Definition: overflow.c:37
#define OUT_FMT
Definition: overflow.c:31
Return codes and api definitions.
FILE * stderr
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
int add_two_nonderived_events(int *num_events, int *papi_event, int *mask)
Definition: test_utils.c:671
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
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:584
int main()
Definition: pernode.c:20
int quiet
Definition: rapl_overflow.c:19
int
Definition: sde_internal.h:89
long long int long long
Definition: sde_internal.h:85
#define NUM_FLOPS
Definition: sdsc-mpx.c:24
Hardware info structure.
Definition: papi.h:774
int cpu_max_mhz
Definition: papi.h:790
int retval
Definition: zero_fork.c:53