PAPI  5.7.0.0
papi_hw_int.c
Go to the documentation of this file.
1 /* This file attempts to test the PAPI_HW_INT */
2 /* performance counter (Total hardware interrupts). */
3 
4 /* This assumes that interrupts will be happening in the background */
5 /* Including a regular timer tick of HZ. This is not always true */
6 /* but should be roughly true on your typical Linux system. */
7 
8 /* by Vince Weaver, <vincent.weaver@maine.edu> */
9 
10 
11 #include <stdlib.h>
12 #include <stdio.h>
13 #include <unistd.h>
14 #include <string.h>
15 #include <sys/time.h>
16 
17 #include <time.h>
18 
19 #include "papi.h"
20 #include "papi_test.h"
21 
22 #include "display_error.h"
23 
24 
25 int main(int argc, char **argv) {
26 
27  int quiet;
28 
29  long long count;
30  int retval;
31  int eventset=PAPI_NULL;
32 
33  struct timespec before,after;
34  unsigned long long seconds;
35  unsigned long long ns;
36 
37  quiet=tests_quiet(argc,argv);
38 
39  /* Init the PAPI library */
41  if ( retval != PAPI_VER_CURRENT ) {
42  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
43  }
44 
45  if (!quiet) {
46  printf("\nTesting PAPI_HW_INT\n");
47  }
48 
49  retval=PAPI_create_eventset(&eventset);
50  if (retval!=PAPI_OK) {
51  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
52  }
53 
54  retval=PAPI_add_named_event(eventset,"PAPI_HW_INT");
55  if (retval!=PAPI_OK) {
56  if (!quiet) printf("Could not add PAPI_HW_INT\n");
57  test_skip( __FILE__, __LINE__, "adding PAPI_HW_INT", retval );
58  }
59 
60  /********************************/
61  /* testing 3 seconds of runtime */
62  /********************************/
63 
64  if (!quiet) {
65  printf("\nRunning for 3 seconds\n");
66  }
67 
68  clock_gettime(CLOCK_REALTIME,&before);
69 
70  PAPI_reset(eventset);
71  PAPI_start(eventset);
72 
73  while(1) {
74  clock_gettime(CLOCK_REALTIME,&after);
75 
76  seconds=after.tv_sec - before.tv_sec;
77  ns = after.tv_nsec - before.tv_nsec;
78  ns = (seconds*1000000000ULL)+ns;
79 
80  /* be done if 3 billion nanoseconds has passed */
81  if (ns>3000000000ULL) break;
82  }
83 
84  retval=PAPI_stop(eventset,&count);
85 
86  if (retval!=PAPI_OK) {
87  test_fail( __FILE__, __LINE__, "Problem stopping!", retval );
88  }
89 
90  if (!quiet) {
91  printf("\tMeasured interrupts = %lld\n",count);
92  /* FIXME: find actua Hz on system */
93  /* Or even, read /proc/interrupts */
94  printf("\tAssuming HZ=250, expect roughly 750\n");
95  }
96 
97  if (!quiet) printf("\n");
98 
99  if (count<10) {
100  if (!quiet) printf("Too few interrupts!\n");
101  test_fail( __FILE__, __LINE__, "Too few interrupts!", 1 );
102  }
103 
104  test_pass( __FILE__ );
105 
106  return 0;
107 }
#define PAPI_OK
Definition: fpapi.h:105
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
void test_pass(const char *filename)
Definition: test_utils.c:432
int PAPI_reset(int EventSet)
Definition: papi.c:2459
__time_t tv_sec
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
int retval
Definition: zero_fork.c:53
Return codes and api definitions.
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:561
int PAPI_add_named_event(int EventSet, const char *EventName)
Definition: papi.c:1876
__syscall_slong_t tv_nsec
int PAPI_library_init(int version)
Definition: papi.c:500
int quiet
Definition: rapl_overflow.c:18
#define PAPI_NULL
Definition: fpapi.h:13
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
int main(int argc, char **argv)
Definition: papi_hw_int.c:25
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
int PAPI_start(int EventSet)
Definition: papi.c:2096
static long count