This file is indexed.

/usr/share/doc/papi-examples/ctests/overflow.c is in papi-examples 5.6.0-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
* File:    overflow.c
* Author:  Philip Mucci
*          mucci@cs.utk.edu
*/

/* This file performs the following test: overflow dispatch

     The Eventset contains:
     + PAPI_TOT_CYC
     + PAPI_FP_INS (overflow monitor)

   - Start eventset 1
   - Do flops
   - Stop and measure eventset 1
   - Set up overflow on eventset 1
   - Start eventset 1
   - Do flops
   - Stop eventset 1
*/

#include <stdio.h>
#include <stdlib.h>

#include "papi.h"
#include "papi_test.h"

#include "do_loops.h"

#define OVER_FMT	"handler(%d ) Overflow at %p! bit=%#llx \n"
#define OUT_FMT		"%-12s : %16lld%16lld\n"

static int total = 0;				   /* total overflows */


void
handler( int EventSet, void *address, long long overflow_vector, void *context )
{
	( void ) context;

	if ( !TESTS_QUIET ) {
		fprintf( stderr, OVER_FMT, EventSet, address, overflow_vector );
	}
	total++;
}

int
main( int argc, char **argv )
{
	int EventSet = PAPI_NULL;
	long long ( values[2] )[2];
	long long min, max;
	int num_flops = NUM_FLOPS, retval;
	int PAPI_event, mythreshold = THRESHOLD;
	char event_name1[PAPI_MAX_STR_LEN];
	const PAPI_hw_info_t *hw_info = NULL;
	int num_events, mask;
	int quiet;

	/* Set TESTS_QUIET variable */
	quiet = tests_quiet( argc, argv );

	/* Init PAPI */
	retval = PAPI_library_init( PAPI_VER_CURRENT );
	if ( retval != PAPI_VER_CURRENT ) {
		test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
	}

	/* Get hardware info */
	hw_info = PAPI_get_hardware_info(  );
	if ( hw_info == NULL ) {
		test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
	}

	/* add PAPI_TOT_CYC and one of the events in     */
        /*     PAPI_FP_INS, PAPI_FP_OPS or PAPI_TOT_INS, */
	/* depending on the availability of the event on */
	/* the platform */
	EventSet = add_two_nonderived_events( &num_events, &PAPI_event, &mask );

	if (num_events==0) {
		if (!quiet) printf("Trouble adding event!\n");
		test_skip(__FILE__,__LINE__,"Event add",1);
	}

	if (!quiet) {
		printf("Using %#x for the overflow event\n",PAPI_event);
	}

	if ( PAPI_event == PAPI_FP_INS ) {
		mythreshold = THRESHOLD;
	}
	else {
#if defined(linux)
		mythreshold = ( int ) hw_info->cpu_max_mhz * 20000;
#else
		mythreshold = THRESHOLD * 2;
#endif
	}

	/* Start the run calibration run */
	retval = PAPI_start( EventSet );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_start", retval );

	do_flops( NUM_FLOPS );

	/* stop the calibration run */
	retval = PAPI_stop( EventSet, values[0] );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_stop", retval );


	/* set up overflow handler */
	retval = PAPI_overflow( EventSet, PAPI_event, mythreshold, 0, handler );
	if ( retval != PAPI_OK ) {
	   test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
	}

	/* Start overflow run */
	retval = PAPI_start( EventSet );
	if ( retval != PAPI_OK ) {
	   test_fail( __FILE__, __LINE__, "PAPI_start", retval );
	}

	do_flops( num_flops );

	/* stop overflow run */
	retval = PAPI_stop( EventSet, values[1] );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
	retval = PAPI_overflow( EventSet, PAPI_event, 0, 0, handler );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );

	if ( !TESTS_QUIET ) {
		retval = PAPI_event_code_to_name( PAPI_event, event_name1 );
		if (retval != PAPI_OK ) {
			test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
		}

		printf( "Test case: Overflow dispatch of 2nd event in set with 2 events.\n" );
		printf( "---------------------------------------------------------------\n" );
		printf( "Threshold for overflow is: %d\n", mythreshold );
		printf( "Using %d iterations of c += a*b\n", num_flops );
		printf( "-----------------------------------------------\n" );

		printf( "Test type    : %16d%16d\n", 1, 2 );
		printf( OUT_FMT, event_name1, ( values[0] )[1], ( values[1] )[1] );
		printf( OUT_FMT, "PAPI_TOT_CYC", ( values[0] )[0], ( values[1] )[0] );
		printf( "Overflows    : %16s%16d\n", "", total );
		printf( "-----------------------------------------------\n" );
	}

	retval = PAPI_cleanup_eventset( EventSet );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );

	retval = PAPI_destroy_eventset( &EventSet );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );

	if ( !TESTS_QUIET ) {
		printf( "Verification:\n" );
#if defined(linux) || defined(__ia64__) || defined(_POWER4)
		num_flops *= 2;
#endif
		if ( PAPI_event == PAPI_FP_INS || PAPI_event == PAPI_FP_OPS ) {
			printf( "Row 1 approximately equals %d %d\n", num_flops,
					num_flops );
		}
		printf( "Column 1 approximately equals column 2\n" );
		printf( "Row 3 approximately equals %u +- %u %%\n",
				( unsigned ) ( ( values[0] )[1] / ( long long ) mythreshold ),
				( unsigned ) ( OVR_TOLERANCE * 100.0 ) );
	}
/*
  min = (long long)((values[0])[1]*(1.0-TOLERANCE));
  max = (long long)((values[0])[1]*(1.0+TOLERANCE));
  if ( (values[0])[1] > max || (values[0])[1] < min )
  	test_fail(__FILE__, __LINE__, event_name, 1);
*/

	min =
		( long long ) ( ( ( double ) values[0][1] * ( 1.0 - OVR_TOLERANCE ) ) /
						( double ) mythreshold );
	max =
		( long long ) ( ( ( double ) values[0][1] * ( 1.0 + OVR_TOLERANCE ) ) /
						( double ) mythreshold );
	if (!quiet) {
		printf( "Overflows: total(%d) > max(%lld) || "
			"total(%d) < min(%lld) \n", total, max, total, min );
	}
	if ( total > max || total < min ) {
		test_fail( __FILE__, __LINE__, "Overflows", 1 );
	}

	test_pass( __FILE__ );
	return 0;

}