PAPI  5.4.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
overflow_one_and_read.c
Go to the documentation of this file.
1 /*
2 * File: overflow_one_and_read.c : based on overflow_twoevents.c
3 * Mods: Philip Mucci
4 * mucci@cs.utk.edu
5 * Kevin London
6 * london@cs.utk.edu
7 */
8 
9 /* This file performs the following test: overflow dispatch on 1 counter.
10  * In the handler read events.
11 */
12 
13 #include "papi_test.h"
14 
15 #define OVER_FMT "handler(%d) Overflow at %p! vector=%#llx\n"
16 #define OUT_FMT "%-12s : %16lld%16lld\n"
17 
18 typedef struct
19 {
20  long long mask;
21  int count;
22 } ocount_t;
23 
24 /* there are three possible vectors, one counter overflows, the other
25  counter overflows, both overflow */
26 /*not used*/ ocount_t overflow_counts[3] = { {0, 0}, {0, 0}, {0, 0} };
27 /*not used*/ int total_unknown = 0;
28 
29 /*added*/ long long dummyvalues[2];
30 
31 void
32 handler( int EventSet, void *address, long long overflow_vector, void *context )
33 {
34  int retval;
35 
36  ( void ) context;
37 
38  if ( !TESTS_QUIET ) {
39  fprintf( stderr, OVER_FMT, EventSet, address, overflow_vector );
40  }
41 
42  if ( ( retval = PAPI_read( EventSet, dummyvalues ) ) != PAPI_OK )
43  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
44 
45  if ( !TESTS_QUIET ) {
46  fprintf( stderr, TWO12, dummyvalues[0], dummyvalues[1],
47  "(Reading counters)\n" );
48  }
49  if ( dummyvalues[1] == 0 )
50  test_fail( __FILE__, __LINE__, "Total Cycles == 0", 1 );
51 }
52 
53 int
54 main( int argc, char **argv )
55 {
56  int EventSet;
57  long long **values = NULL;
58  int retval;
59  int PAPI_event;
61  int num_events1, mask1;
62 
63  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
64 
66  if ( retval != PAPI_VER_CURRENT )
67  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
68 
69  /* add PAPI_TOT_CYC and one of the events in PAPI_FP_INS, PAPI_FP_OPS or
70  PAPI_TOT_INS, depends on the availability of the event on the
71  platform */
72 /* NOTE: Only adding one overflow on PAPI_event -- no overflow for PAPI_TOT_CYC*/
73  EventSet =
74  add_two_nonderived_events( &num_events1, &PAPI_event, &mask1 );
75 
76  values = allocate_test_space( 2, num_events1 );
77 
78  if ( ( retval =
79  PAPI_event_code_to_name( PAPI_event, event_name ) ) != PAPI_OK )
80  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
81 
82  retval = PAPI_start( EventSet );
83  if ( retval != PAPI_OK )
84  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
85 
87 
88  retval = PAPI_stop( EventSet, values[0] );
89  if ( retval != PAPI_OK )
90  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
91 
92  retval = PAPI_overflow( EventSet, PAPI_event, THRESHOLD, 0, handler );
93  if ( retval != PAPI_OK )
94  test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
95 
96  retval = PAPI_start( EventSet );
97  if ( retval != PAPI_OK )
98  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
99 
100  do_flops( NUM_FLOPS );
101 
102  retval = PAPI_stop( EventSet, values[1] );
103  if ( retval != PAPI_OK )
104  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
105 
106  remove_test_events( &EventSet, mask1 );
107 
108 
109  if ( !TESTS_QUIET ) {
110  printf
111  ( "Test case: Overflow dispatch of 1st event in set with 2 events.\n" );
112  printf
113  ( "---------------------------------------------------------------\n" );
114  printf( "Threshold for overflow is: %d\n", THRESHOLD );
115  printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
116  printf( "-----------------------------------------------\n" );
117 
118  printf( "Test type : %16d%16d\n", 1, 2 );
119  printf( OUT_FMT, event_name, ( values[0] )[0], ( values[1] )[0] );
120  printf( OUT_FMT, "PAPI_TOT_CYC", ( values[0] )[1], ( values[1] )[1] );
121  }
122 
123  test_pass( __FILE__, NULL, 0 );
124  exit( 1 );
125 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:23
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2258
#define NUM_FLOPS
int mask1
Definition: zero_fork.c:41
#define TWO12
Definition: papi_test.h:117
int PAPI_event[2]
Definition: data_range.c:24
int num_events1
Definition: zero_fork.c:42
int EventSet
Definition: data_range.c:25
return PAPI_OK
Definition: linux-nvml.c:458
int count
Definition: iozone.c:22422
tests_quiet(argc, argv)
int PAPI_overflow(int EventSet, int EventCode, int threshold, int flags, PAPI_overflow_handler_t handler)
Definition: papi.c:4714
void
Definition: iozone.c:18627
#define printf
Definition: papi_test.h:125
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
#define OVER_FMT
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:497
long long dummyvalues[2]
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:926
#define OUT_FMT
void do_flops(int n)
Definition: multiplex.c:23
int total_unknown
#define PAPI_MAX_STR_LEN
Definition: papi.h:463
int add_two_nonderived_events(int *num_events, int *papi_event, int *mask)
Definition: test_utils.c:723
int PAPI_read(int EventSet, long long *values)
Definition: papi.c:2503
int PAPI_start(int EventSet)
Definition: papi.c:2053
#define THRESHOLD
Definition: earprofile.c:31
ocount_t overflow_counts[3]
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
long long ** allocate_test_space(int num_tests, int num_events)
Definition: test_utils.c:107
#define PAPI_VER_CURRENT
Definition: papi.h:223
int main(int argc, char **argv)
List all appio events codes and names.
void exit()
int remove_test_events(int *EventSet, int mask)
Definition: test_utils.c:277