PAPI 7.1.0.0
Loading...
Searching...
No Matches
Overflow_Driver.c File Reference
Include dependency graph for Overflow_Driver.c:

Go to the source code of this file.

Macros

#define EV_THRESHOLD   10
 

Functions

void cclib_init (void)
 
void cclib_do_work (void)
 
void cclib_do_more_work (void)
 
void setup_PAPI (int *event_set, int threshold)
 
int main (int argc, char **argv)
 
void overflow_handler (int event_set, void *address, long long overflow_vector, void *context)
 

Variables

int remaining_handler_invocations = 22
 
int be_verbose = 0
 

Macro Definition Documentation

◆ EV_THRESHOLD

#define EV_THRESHOLD   10

Definition at line 8 of file Overflow_Driver.c.

Function Documentation

◆ cclib_do_more_work()

void cclib_do_more_work ( void  )

Definition at line 66 of file Lib_With_Created_Counter.c.

66 {
67 int i;
68
69 for(i=0; i<500*1000; i++){
70 BRNG();
71 double r = (1.0*result)/(1.0*INT_MAX);
72 if( r < MY_EPSILON && r > -MY_EPSILON ){
74 }
75 // Do some usefull work here
76 if( !(i%20) )
77 (void)usleep(1);
78 }
79
80 return;
81}
#define MY_EPSILON
void * cntr_handle
#define BRNG()
volatile int result
int i
int papi_sde_inc_counter(papi_handle_t cntr_handle, long long int increment)
Definition: sde_lib.c:637
Here is the caller graph for this function:

◆ cclib_do_work()

void cclib_do_work ( void  )

Definition at line 49 of file Lib_With_Created_Counter.c.

49 {
50 int i;
51
52 for(i=0; i<100*1000; i++){
53 BRNG();
54 double r = (1.0*result)/(1.0*INT_MAX);
55 if( r < MY_EPSILON && r > -MY_EPSILON ){
57 }
58 // Do some usefull work here
59 if( !(i%100) )
60 (void)usleep(1);
61 }
62
63 return;
64}
Here is the caller graph for this function:

◆ cclib_init()

void cclib_init ( void  )

Definition at line 35 of file Lib_With_Created_Counter.c.

35 {
36 papi_handle_t sde_handle;
37
38 sde_handle = papi_sde_init("Lib_With_CC");
40
41 z1=42;
42 z2=420;
43 z3=42000;
44 z4=424242;
45
46 return;
47}
volatile unsigned int z1
static const char * event_names[1]
volatile unsigned int z2
volatile unsigned int z3
volatile unsigned int z4
papi_handle_t papi_sde_init(const char *name_of_library)
Definition: sde_lib.c:119
int papi_sde_create_counter(papi_handle_t handle, const char *event_name, int cntr_mode, void **cntr_handle)
Definition: sde_lib.c:576
void * papi_handle_t
Definition: sde_lib.h:100
#define PAPI_SDE_DELTA
Definition: sde_lib.h:25
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 18 of file Overflow_Driver.c.

18 {
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}
#define EV_THRESHOLD
int be_verbose
void cclib_init(void)
void cclib_do_work(void)
void setup_PAPI(int *event_set, int threshold)
int remaining_handler_invocations
void cclib_do_more_work(void)
Accumulate and reset counters in an EventSet.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
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
Here is the call graph for this function:

◆ overflow_handler()

void overflow_handler ( int  event_set,
void *  address,
long long  overflow_vector,
void *  context 
)

Definition at line 72 of file Overflow_Driver.c.

72 {
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}
Convert a numeric hardware event code to a name.
converts an overflow vector into an array of indexes to overflowing events
list the events in an event set
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
FILE * stdout
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setup_PAPI()

void setup_PAPI ( int event_set,
int  threshold 
)

Definition at line 107 of file Overflow_Driver.c.

107 {
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}
void overflow_handler(int event_set, void *address, long long overflow_vector, void *context)
add PAPI preset or native hardware event to an event set
Create a new empty PAPI EventSet.
Convert a name to a numeric hardware event code.
initialize the PAPI library.
Set up an event set to begin registering overflows.
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OVERFLOW_HARDWARE
Definition: f90papi.h:157
static int threshold
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ be_verbose

int be_verbose = 0

Definition at line 16 of file Overflow_Driver.c.

◆ remaining_handler_invocations

int remaining_handler_invocations = 22

Definition at line 15 of file Overflow_Driver.c.