PAPI  5.7.0.0
fork_overflow.c File Reference
Include dependency graph for fork_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 zero_count (void)
 
static void print_here (const char *str)
 
static void print_rate (const char *str)
 
static void do_cycles (int program_time)
 
static void my_papi_init (void)
 
static void my_papi_start (void)
 
static void my_papi_stop (void)
 
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 int num_events = 1
 
static int EventSet = PAPI_NULL
 
static const char * name = "unknown"
 
static struct timeval start last
 
static long count
 
static long total
 

Macro Definition Documentation

◆ MAX_EVENTS

#define MAX_EVENTS   3

Definition at line 15 of file fork_overflow.c.

Function Documentation

◆ do_cycles()

static void do_cycles ( int  program_time)
static

Definition at line 95 of file fork_overflow.c.

96 {
97  struct timeval start, now;
98  double x, sum;
99 
100  gettimeofday( &start, NULL );
101 
102  for ( ;; ) {
103  sum = 1.0;
104  for ( x = 1.0; x < 250000.0; x += 1.0 )
105  sum += x;
106  if ( sum < 0.0 )
107  printf( "==>> SUM IS NEGATIVE !! <<==\n" );
108 
109  gettimeofday( &now, NULL );
110  if ( now.tv_sec >= start.tv_sec + program_time )
111  break;
112  }
113 }
static struct timeval start
static int program_time
__time_t tv_sec
int gettimeofday(void *ptr1, void *ptr2)
int x
Definition: fileop.c:78
Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 169 of file fork_overflow.c.

170 {
171  char buf[100];
172 
173  int quiet,retval;
174 
175  /* Used to be able to set this via command line */
176  num_events=1;
177 
178  /* Set TESTS_QUIET variable */
179  quiet=tests_quiet( argc, argv );
180 
181  do_cycles( 1 );
182 
183  zero_count( );
184 
186  if (retval!=PAPI_VER_CURRENT) {
187  test_fail( name, __LINE__, "PAPI_library_init failed", 1 );
188  }
189 
190  name = argv[0];
191  if (!quiet) printf( "[%d] %s, num_events = %d\n", getpid( ), name, num_events );
192  sprintf( buf, "%d", num_events );
193  my_papi_start( );
194  run( name, 3 );
195 
196  print_here( "fork" );
197  {
198  int ret = fork( );
199  if ( ret < 0 )
200  test_fail( name, __LINE__, "fork failed", 1 );
201  if ( ret == 0 ) {
202  /*
203  * Child process.
204  */
205  zero_count( );
206  my_papi_init( );
207  my_papi_start( );
208  run( "child", 5 );
209  print_here( "stop" );
210  my_papi_stop( );
211  sleep( 3 );
212  print_here( "end" );
213  exit( 0 );
214  }
215  run( "main", 14 );
216  my_papi_stop( );
217  {
218  int status;
219  wait( &status );
220  print_here( "end" );
221  if ( WEXITSTATUS( status ) != 0 )
222  test_fail( name, __LINE__, "child failed", 1 );
223  else
224  test_pass( name);
225  }
226  }
227 
228  return 0;
229 }
static void my_papi_start(void)
static const char * name
Definition: fork_overflow.c:31
void test_pass(const char *filename)
Definition: test_utils.c:432
static void run(const char *str, int len)
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
static void print_here(const char *str)
Definition: fork_overflow.c:57
int retval
Definition: zero_fork.c:53
static void my_papi_stop(void)
static void zero_count(void)
Definition: fork_overflow.c:48
int PAPI_library_init(int version)
Definition: papi.c:500
int quiet
Definition: rapl_overflow.c:18
int wait()
long long ret
Definition: iozone.c:1346
static int num_events
Definition: fork_overflow.c:29
static void do_cycles(int program_time)
Definition: fork_overflow.c:95
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
long long status
Definition: iozone.c:1335
static void my_papi_init(void)
volatile int buf[CACHE_FLUSH_BUFFER_SIZE_INTS]
Definition: do_loops.c:12
void exit()
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 36 of file fork_overflow.c.

37 {
38  ( void ) EventSet;
39  ( void ) pc;
40  ( void ) ovec;
41  ( void ) context;
42 
43  count++;
44  total++;
45 }
static long count
Definition: fork_overflow.c:33
static long total
Definition: fork_overflow.c:33
static int EventSet
Definition: fork_overflow.c:30
Here is the caller graph for this function:

◆ my_papi_init()

static void my_papi_init ( void  )
static

Definition at line 116 of file fork_overflow.c.

117 {
119  test_fail( name, __LINE__, "PAPI_library_init failed", 1 );
120 }
static const char * name
Definition: fork_overflow.c:31
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
int PAPI_library_init(int version)
Definition: papi.c:500
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
Here is the call graph for this function:
Here is the caller graph for this function:

◆ my_papi_start()

static void my_papi_start ( void  )
static

Definition at line 123 of file fork_overflow.c.

124 {
125  int ev;
126 
128 
130  test_fail( name, __LINE__, "PAPI_create_eventset failed", 1 );
131 
132  for ( ev = 0; ev < num_events; ev++ ) {
133  if ( PAPI_add_event( EventSet, Event[ev] ) != PAPI_OK ) {
134  if (!TESTS_QUIET) printf("Trouble adding event\n");
135  test_skip( name, __LINE__, "PAPI_add_event failed", 1 );
136  }
137  }
138 
139  for ( ev = 0; ev < num_events; ev++ ) {
140  if ( PAPI_overflow( EventSet, Event[ev], Threshold[ev], 0, my_handler )
141  != PAPI_OK ) {
142  test_fail( name, __LINE__, "PAPI_overflow failed", 1 );
143  }
144  }
145 
146  if ( PAPI_start( EventSet ) != PAPI_OK )
147  test_fail( name, __LINE__, "PAPI_start failed", 1 );
148 }
#define PAPI_OK
Definition: fpapi.h:105
static const char * name
Definition: fork_overflow.c:31
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1663
int PAPI_overflow(int EventSet, int EventCode, int threshold, int flags, PAPI_overflow_handler_t handler)
Definition: papi.c:4788
static int Threshold[MAX_EVENTS]
Definition: fork_overflow.c:23
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:561
static int EventSet
Definition: fork_overflow.c:30
#define PAPI_NULL
Definition: fpapi.h:13
static int num_events
Definition: fork_overflow.c:29
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
static void my_handler(int EventSet, void *pc, long long ovec, void *context)
Definition: fork_overflow.c:36
int TESTS_QUIET
Definition: test_utils.c:18
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
int PAPI_start(int EventSet)
Definition: papi.c:2096
static int Event[MAX_EVENTS]
Definition: fork_overflow.c:17
Here is the call graph for this function:
Here is the caller graph for this function:

◆ my_papi_stop()

static void my_papi_stop ( void  )
static

Definition at line 151 of file fork_overflow.c.

152 {
153  if ( PAPI_stop( EventSet, NULL ) != PAPI_OK )
154  test_fail( name, __LINE__, "PAPI_stop failed", 1 );
155 }
#define PAPI_OK
Definition: fpapi.h:105
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
static const char * name
Definition: fork_overflow.c:31
static int EventSet
Definition: fork_overflow.c:30
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_here()

static void print_here ( const char *  str)
static

Definition at line 57 of file fork_overflow.c.

57  {
58 
59  if (!TESTS_QUIET) printf("[%d] %s, %s\n", getpid(), name, str);
60 }
static const char * name
Definition: fork_overflow.c:31
int TESTS_QUIET
Definition: test_utils.c:18
Here is the caller graph for this function:

◆ print_rate()

static void print_rate ( const char *  str)
static

Definition at line 63 of file fork_overflow.c.

64 {
65  static int last_count = -1;
66  struct timeval now;
67  double st_secs, last_secs;
68 
69  gettimeofday( &now, NULL );
70  st_secs = ( double ) ( now.tv_sec - start.tv_sec )
71  + ( ( double ) ( now.tv_usec - start.tv_usec ) ) / 1000000.0;
72  last_secs = ( double ) ( now.tv_sec - last.tv_sec )
73  + ( ( double ) ( now.tv_usec - last.tv_usec ) ) / 1000000.0;
74  if ( last_secs <= 0.001 )
75  last_secs = 0.001;
76 
77  if (!TESTS_QUIET) {
78  printf( "[%d] %s, time = %.3f, total = %ld, last = %ld, rate = %.1f/sec\n",
79  getpid( ), str, st_secs, total, count,
80  ( ( double ) count ) / last_secs );
81  }
82 
83  if ( last_count != -1 ) {
84  if ( count < .1 * last_count ) {
85  test_fail( name, __LINE__, "Interrupt rate changed!", 1 );
86  exit( 1 );
87  }
88  }
89  last_count = ( int ) count;
90  count = 0;
91  last = now;
92 }
static const char * name
Definition: fork_overflow.c:31
static struct timeval start
static long count
Definition: fork_overflow.c:33
static long total
Definition: fork_overflow.c:33
__time_t tv_sec
__suseconds_t tv_usec
int gettimeofday(void *ptr1, void *ptr2)
int TESTS_QUIET
Definition: test_utils.c:18
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
static struct timeval start last
Definition: fork_overflow.c:32
void exit()
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 158 of file fork_overflow.c.

159 {
160  int n;
161 
162  for ( n = 1; n <= len; n++ ) {
163  do_cycles( 1 );
164  print_rate( str );
165  }
166 }
static void do_cycles(int program_time)
Definition: fork_overflow.c:95
static void print_rate(const char *str)
Definition: fork_overflow.c:63
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zero_count()

static void zero_count ( void  )
static

Definition at line 48 of file fork_overflow.c.

49 {
50  gettimeofday( &start, NULL );
51  last = start;
52  count = 0;
53  total = 0;
54 }
static struct timeval start
static long count
Definition: fork_overflow.c:33
static long total
Definition: fork_overflow.c:33
int gettimeofday(void *ptr1, void *ptr2)
static struct timeval start last
Definition: fork_overflow.c:32
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 33 of file fork_overflow.c.

◆ Event

int Event[MAX_EVENTS]
static
Initial value:
= {
}
#define PAPI_FAD_INS
Definition: fpapi.h:234
#define PAPI_TOT_CYC
Definition: fpapi.h:195
#define PAPI_FP_INS
Definition: fpapi.h:188

Definition at line 17 of file fork_overflow.c.

◆ EventSet

int EventSet = PAPI_NULL
static

Definition at line 30 of file fork_overflow.c.

◆ last

struct timeval start last
static

Definition at line 32 of file fork_overflow.c.

◆ name

const char* name = "unknown"
static

Definition at line 31 of file fork_overflow.c.

◆ num_events

int num_events = 1
static

Definition at line 29 of file fork_overflow.c.

◆ Threshold

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

Definition at line 23 of file fork_overflow.c.

◆ total

long total
static

Definition at line 33 of file fork_overflow.c.