PAPI 7.1.0.0
Loading...
Searching...
No Matches
Overflow_Driver.c
Go to the documentation of this file.
1#include <stdio.h>
2#include <stdint.h>
3#include <stdlib.h>
4#include <string.h>
5#include "papi.h"
6#include "papi_test.h"
7
8#define EV_THRESHOLD 10
9
10void cclib_init(void);
11void cclib_do_work(void);
12void cclib_do_more_work(void);
13void setup_PAPI(int *event_set, int threshold);
14
16int be_verbose = 0;
17
18int main(int argc, char **argv){
19 int i, ret, event_set = PAPI_NULL;
20 long long counter_values[1] = {0};
21
22 if( (argc > 1) && !strcmp(argv[1], "-verbose") )
23 be_verbose = 1;
24
25 cclib_init();
26
27 setup_PAPI(&event_set, EV_THRESHOLD);
28
29 // --- Start PAPI
30 if((ret=PAPI_start(event_set)) != PAPI_OK){
31 test_fail( __FILE__, __LINE__, "PAPI_start", ret );
32 }
33
34 for(i=0; i<4; i++){
35
37
38 // --- Read the event counters _and_ reset them
39 if((ret=PAPI_accum(event_set, counter_values)) != PAPI_OK){
40 test_fail( __FILE__, __LINE__, "PAPI_accum", ret );
41 }
42 if( be_verbose ) printf("Epsilon count in cclib_do_work(): %lld\n",counter_values[0]);
43 counter_values[0] = 0;
44
46
47 // --- Read the event counters _and_ reset them
48 if((ret=PAPI_accum(event_set, counter_values)) != PAPI_OK){
49 test_fail( __FILE__, __LINE__, "PAPI_accum", ret );
50 }
51 if( be_verbose ) printf("Epsilon count in cclib_do_more_work(): %lld\n",counter_values[0]);
52 counter_values[0] = 0;
53
54 }
55
56 // --- Stop PAPI
57 if((ret=PAPI_stop(event_set, counter_values)) != PAPI_OK){
58 test_fail( __FILE__, __LINE__, "PAPI_stop", ret );
59 }
60
61 if( remaining_handler_invocations <= 1 ) // Let's allow for up to one missed signal, or race condition.
62 test_pass(__FILE__);
63 else
64 test_fail( __FILE__, __LINE__, "SDE overflow handler was not invoked as expected!", 0 );
65
66 // The following "return" is dead code, because both test_pass() and test_fail() call exit(),
67 // however, we need it to prevent compiler warnings.
68 return 0;
69}
70
71
72void overflow_handler(int event_set, void *address, long long overflow_vector, void *context){
74 int ret, *event_codes, event_index, number=1;
75
76 (void)address;
77 (void)context;
78
79 if( (ret = PAPI_get_overflow_event_index(event_set, overflow_vector, &event_index, &number)) != PAPI_OK){
80 test_fail( __FILE__, __LINE__, "PAPI_get_overflow_event_index", ret );
81 }
82
83 number = event_index+1;
84 event_codes = (int *)calloc(number, sizeof(int));
85
86 if( (ret = PAPI_list_events( event_set, event_codes, &number)) != PAPI_OK ){
87 test_fail( __FILE__, __LINE__, "PAPI_list_events", ret );
88 }
89
90 if( (ret=PAPI_event_code_to_name(event_codes[event_index], event_name)) != PAPI_OK){
91 test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", ret );
92 }
93 free(event_codes);
94
95 if( be_verbose ){
96 printf("Event \"%s\" at index: %d exceeded its threshold again.\n",event_name, event_index);
97 fflush(stdout);
98 }
99
100 if( !strcmp(event_name, "sde:::Lib_With_CC::epsilon_count") || !event_index )
102
103
104 return;
105}
106
107void setup_PAPI(int *event_set, int threshold){
108 int ret, event_code;
109
111 test_fail( __FILE__, __LINE__, "PAPI_library_init", ret );
112 }
113
114 if((ret=PAPI_create_eventset(event_set)) != PAPI_OK){
115 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", ret );
116 }
117
118 if((ret=PAPI_event_name_to_code("sde:::Lib_With_CC::epsilon_count", &event_code)) != PAPI_OK){
119 test_fail( __FILE__, __LINE__, "PAPI_event_name_to_code", ret );
120 }
121
122 if((ret=PAPI_add_event(*event_set, event_code)) != PAPI_OK){
123 test_fail( __FILE__, __LINE__, "PAPI_add_event", ret );
124 }
125
126 if((ret = PAPI_overflow(*event_set, event_code, threshold, PAPI_OVERFLOW_HARDWARE, overflow_handler)) != PAPI_OK){
127 test_fail( __FILE__, __LINE__, "PAPI_overflow", ret );
128 }
129
130 return;
131}
132
#define EV_THRESHOLD
int be_verbose
void cclib_init(void)
void overflow_handler(int event_set, void *address, long long overflow_vector, void *context)
void cclib_do_work(void)
void setup_PAPI(int *event_set, int threshold)
int remaining_handler_invocations
void cclib_do_more_work(void)
int i
Accumulate and reset counters in an EventSet.
add PAPI preset or native hardware event to an event set
Create a new empty PAPI EventSet.
Convert a numeric hardware event code to a name.
Convert a name to a numeric hardware event code.
converts an overflow vector into an array of indexes to overflowing events
initialize the PAPI library.
list the events in an event set
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.
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
#define PAPI_OVERFLOW_HARDWARE
Definition: f90papi.h:157
static int threshold
Return codes and api definitions.
FILE * stdout
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