PAPI  5.6.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 <stdio.h>
14 #include <stdlib.h>
15 
16 #include "papi.h"
17 #include "papi_test.h"
18 
19 #include "do_loops.h"
20 
21 #define OVER_FMT "handler(%d) Overflow at %p! vector=%#llx\n"
22 #define OUT_FMT "%-12s : %16lld%16lld\n"
23 
24 typedef struct
25 {
26  long long mask;
27  int count;
28 } ocount_t;
29 
30 /* there are three possible vectors, one counter overflows, the other
31  counter overflows, both overflow */
32 /*not used*/ ocount_t overflow_counts[3] = { {0, 0}, {0, 0}, {0, 0} };
33 /*not used*/ int total_unknown = 0;
34 
35 /*added*/ long long dummyvalues[2];
36 
37 void
38 handler( int EventSet, void *address, long long overflow_vector, void *context )
39 {
40  int retval;
41 
42  ( void ) context;
43 
44  if ( !TESTS_QUIET ) {
45  fprintf( stderr, OVER_FMT, EventSet, address, overflow_vector );
46  }
47 
48  if ( ( retval = PAPI_read( EventSet, dummyvalues ) ) != PAPI_OK )
49  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
50 
51  if ( !TESTS_QUIET ) {
52  fprintf( stderr, TWO12, dummyvalues[0], dummyvalues[1],
53  "(Reading counters)\n" );
54  }
55  if ( dummyvalues[1] == 0 )
56  test_fail( __FILE__, __LINE__, "Total Cycles == 0", 1 );
57 }
58 
59 int
60 main( int argc, char **argv )
61 {
62  int EventSet;
63  long long **values = NULL;
64  int retval;
65  int PAPI_event;
67  int num_events1, mask1;
68  int quiet;
69 
70  /* Set TESTS_QUIET variable */
71  quiet=tests_quiet( argc, argv );
72 
74  if ( retval != PAPI_VER_CURRENT ) {
75  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
76  }
77 
78  /* add PAPI_TOT_CYC and one of the events in PAPI_FP_INS, PAPI_FP_OPS or
79  PAPI_TOT_INS, depends on the availability of the event on the
80  platform */
81 /* NOTE: Only adding one overflow on PAPI_event -- no overflow for PAPI_TOT_CYC*/
82  EventSet = add_two_nonderived_events( &num_events1,
83  &PAPI_event, &mask1 );
84  if (num_events1==0) {
85  if (!quiet) printf("Trouble adding events\n");
86  test_skip(__FILE__,__LINE__,"Adding event",1);
87  }
88 
89  values = allocate_test_space( 2, num_events1 );
90 
91  if ( ( retval =
92  PAPI_event_code_to_name( PAPI_event, event_name ) ) != PAPI_OK )
93  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
94 
95  retval = PAPI_start( EventSet );
96  if ( retval != PAPI_OK )
97  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
98 
100 
101  retval = PAPI_stop( EventSet, values[0] );
102  if ( retval != PAPI_OK )
103  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
104 
105  retval = PAPI_overflow( EventSet, PAPI_event, THRESHOLD, 0, handler );
106  if ( retval != PAPI_OK )
107  test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
108 
109  retval = PAPI_start( EventSet );
110  if ( retval != PAPI_OK )
111  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
112 
113  do_flops( NUM_FLOPS );
114 
115  retval = PAPI_stop( EventSet, values[1] );
116  if ( retval != PAPI_OK )
117  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
118 
119  remove_test_events( &EventSet, mask1 );
120 
121 
122  if ( !TESTS_QUIET ) {
123  printf
124  ( "Test case: Overflow dispatch of 1st event in set with 2 events.\n" );
125  printf
126  ( "---------------------------------------------------------------\n" );
127  printf( "Threshold for overflow is: %d\n", THRESHOLD );
128  printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
129  printf( "-----------------------------------------------\n" );
130 
131  printf( "Test type : %16d%16d\n", 1, 2 );
132  printf( OUT_FMT, event_name, ( values[0] )[0], ( values[1] )[0] );
133  printf( OUT_FMT, "PAPI_TOT_CYC", ( values[0] )[1], ( values[1] )[1] );
134  }
135 
136  test_pass( __FILE__ );
137 
138  return 0;
139 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
int mask1
Definition: zero_fork.c:48
#define TWO12
Definition: papi_test.h:93
int PAPI_event[2]
Definition: data_range.c:30
void test_pass(const char *filename)
Definition: test_utils.c:432
int num_events1
Definition: zero_fork.c:49
int EventSet
return PAPI_OK
Definition: linux-nvml.c:497
int count
Definition: iozone.c:22422
int PAPI_overflow(int EventSet, int EventCode, int threshold, int flags, PAPI_overflow_handler_t handler)
Definition: papi.c:4788
void
Definition: iozone.c:18627
#define NUM_FLOPS
Definition: sdsc-mpx.c:24
int int argc
Definition: iozone.c:1609
ocount_t overflow_counts[3]
#define OVER_FMT
Return codes and api definitions.
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:559
char ** argv
Definition: iozone.c:1610
int PAPI_library_init(int version)
Definition: papi.c:500
int quiet
Definition: rapl_overflow.c:18
long long dummyvalues[2]
int total_unknown
void handler(int EventSet, void *address, long long overflow_vector, void *context)
Definition: rapl_overflow.c:20
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:915
#define OUT_FMT
void do_flops(int n)
Definition: multiplex.c:23
printf("\tTry: -i 0 -i 1 \n\n")
int TESTS_QUIET
Definition: test_utils.c:18
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
#define PAPI_MAX_STR_LEN
Definition: papi.h:465
int add_two_nonderived_events(int *num_events, int *papi_event, int *mask)
Definition: test_utils.c:646
int PAPI_read(int EventSet, long long *values)
Definition: papi.c:2559
int PAPI_start(int EventSet)
Definition: papi.c:2096
#define THRESHOLD
Definition: earprofile.c:37
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:46
#define PAPI_VER_CURRENT
Definition: papi.h:225
int main(int argc, char **argv)
List all appio events codes and names.
int remove_test_events(int *EventSet, int mask)
Definition: test_utils.c:201