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

Go to the source code of this file.

Macros

#define MAX_EVENTS   3
 

Functions

static void my_handler (int EventSet, void *pc, long long ovec, void *context)
 
static void print_rate (const char *str)
 
static void run (const char *str, int len)
 
int main (int argc, char **argv)
 

Variables

static int Event [MAX_EVENTS]
 
static int Threshold [MAX_EVENTS]
 
static struct timeval start last
 
static long count
 
static long total
 

Macro Definition Documentation

◆ MAX_EVENTS

#define MAX_EVENTS   3

Definition at line 17 of file exec_overflow.c.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 94 of file exec_overflow.c.

95{
96 int num_events = 1;
97 const char *name = "unknown";
98 int ev,EventSet = PAPI_NULL;
99 int quiet,retval;
100
101 /* Used to be able to set this via command line */
102 num_events=1;
103
104 /* Set TESTS_QUIET variable */
105 quiet=tests_quiet( argc, argv );
106
107 do_cycles( 1 );
108
109 /* Zero out the Counters */
110 gettimeofday( &start, NULL );
111 last = start;
112 count = 0;
113 total = 0;
114
115 /* Initialize PAPI */
118 test_fail( __FILE__, __LINE__, "PAPI_library_init failed", 1 );
119 }
120
121 name = argv[0];
122 if (!quiet) {
123 printf( "[%d] %s, num_events = %d\n", getpid(),
124 name, num_events );
125 }
126
127 /* Create eventset */
129 test_fail( __FILE__, __LINE__, "PAPI_create_eventset failed", 1 );
130 }
131
132 /* Add events */
133 for ( ev = 0; ev < num_events; ev++ ) {
134 if ( PAPI_add_event( EventSet, Event[ev] ) != PAPI_OK ) {
135 if (!quiet) printf("Trouble adding event\n");
136 test_skip( __FILE__, __LINE__, "PAPI_add_event failed", 1 );
137 }
138 }
139
140 /* Set overflow */
141 for ( ev = 0; ev < num_events; ev++ ) {
142 if ( PAPI_overflow( EventSet, Event[ev],
143 Threshold[ev], 0, my_handler )
144 != PAPI_OK ) {
145 test_fail( __FILE__, __LINE__, "PAPI_overflow failed", 1 );
146 }
147 }
148
149 /* Start measuring */
150 if ( PAPI_start( EventSet ) != PAPI_OK ) {
151 test_fail( __FILE__, __LINE__, "PAPI_start failed", 1 );
152 }
153
154
155
156 /* Tun a bit */
157 run( name, 3 );
158
159 /* Stop measuring */
160 if (!quiet) {
161 printf("[%d] %s, %s\n", getpid(), name, "stop");
162 }
163
164 if ( PAPI_stop( EventSet, NULL ) != PAPI_OK ) {
165 test_fail( name, __LINE__, "PAPI_stop failed", 1 );
166 }
167
168 if (!quiet) {
169 printf("[%d] %s, %s\n", getpid(),
170 name, "exec(./child_overflow)");
171 }
172
173 /* exec the child_overflow helper program */
174 /* we should never return from this */
175 if ( access( "./child_overflow", X_OK ) == 0 )
176 execl( "./child_overflow", "./child_overflow",
177 ( quiet ? "TESTS_QUIET" : NULL ), NULL );
178 else if ( access( "./ctests/child_overflow", X_OK ) == 0 )
179 execl( "./ctests/child_overflow", "./ctests/child_overflow",
180 ( quiet ? "TESTS_QUIET" : NULL ), NULL );
181
182 test_fail( name, __LINE__, "exec failed", 1 );
183
184 return 0;
185}
add PAPI preset or native hardware event to an event set
Create a new empty PAPI EventSet.
initialize the PAPI library.
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.
static struct timeval start last
Definition: exec_overflow.c:31
static long total
Definition: exec_overflow.c:32
static void run(const char *str, int len)
Definition: exec_overflow.c:83
static long count
Definition: exec_overflow.c:32
static int Event[MAX_EVENTS]
Definition: exec_overflow.c:19
static int Threshold[MAX_EVENTS]
Definition: exec_overflow.c:25
static void my_handler(int EventSet, void *pc, long long ovec, void *context)
Definition: exec_overflow.c:35
static void do_cycles(int program_time)
Definition: fork_overflow.c:95
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
static int EventSet
Definition: init_fini.c:8
static struct timeval start
static int num_events
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:491
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:584
int quiet
Definition: rapl_overflow.c:19
const char * name
Definition: rocs.c:225
int retval
Definition: zero_fork.c:53
Here is the call graph for this function:

◆ my_handler()

static void my_handler ( int  EventSet,
void *  pc,
long long  ovec,
void *  context 
)
static

Definition at line 35 of file exec_overflow.c.

36{
37 ( void ) EventSet;
38 ( void ) pc;
39 ( void ) ovec;
40 ( void ) context;
41
42 count++;
43 total++;
44}
Here is the caller graph for this function:

◆ print_rate()

static void print_rate ( const char *  str)
static

Definition at line 51 of file exec_overflow.c.

52{
53 static int last_count = -1;
54 struct timeval now;
55 double st_secs, last_secs;
56
57 gettimeofday( &now, NULL );
58 st_secs = ( double ) ( now.tv_sec - start.tv_sec )
59 + ( ( double ) ( now.tv_usec - start.tv_usec ) ) / 1000000.0;
60 last_secs = ( double ) ( now.tv_sec - last.tv_sec )
61 + ( ( double ) ( now.tv_usec - last.tv_usec ) ) / 1000000.0;
62 if ( last_secs <= 0.001 )
63 last_secs = 0.001;
64
65 if (!TESTS_QUIET) {
66 printf( "[%d] %s, time = %.3f, total = %ld, last = %ld, rate = %.1f/sec\n",
67 getpid( ), str, st_secs, total, count,
68 ( ( double ) count ) / last_secs );
69 }
70
71 if ( last_count != -1 ) {
72 if ( count < .1 * last_count ) {
73 test_fail( __FILE__, __LINE__, "Interrupt rate changed!", 1 );
74 exit( 1 );
75 }
76 }
77 last_count = ( int ) count;
78 count = 0;
79 last = now;
80}
int TESTS_QUIET
Definition: test_utils.c:18
int
Definition: sde_internal.h:89
__time_t tv_sec
__suseconds_t tv_usec
Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

static void run ( const char *  str,
int  len 
)
static

Definition at line 83 of file exec_overflow.c.

84{
85 int n;
86
87 for ( n = 1; n <= len; n++ ) {
88 do_cycles( 1 );
89 print_rate( str );
90 }
91}
static void print_rate(const char *str)
Definition: exec_overflow.c:51
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ count

long count
static

Definition at line 32 of file exec_overflow.c.

◆ Event

int Event[MAX_EVENTS]
static
Initial value:
= {
}
#define PAPI_TOT_CYC
Definition: f90papi.h:308
#define PAPI_FAD_INS
Definition: f90papi.h:340
#define PAPI_FP_INS
Definition: f90papi.h:366

Definition at line 19 of file exec_overflow.c.

◆ last

struct timeval start last
static

Definition at line 31 of file exec_overflow.c.

◆ Threshold

int Threshold[MAX_EVENTS]
static
Initial value:
= {
8000000,
4000000,
4000000,
}

Definition at line 25 of file exec_overflow.c.

◆ total

long total
static

Definition at line 32 of file exec_overflow.c.