PAPI 7.1.0.0
Loading...
Searching...
No Matches
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
25int 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
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}
static long count
add PAPI preset or native hardware event by name to an EventSet
Create a new empty PAPI EventSet.
initialize the PAPI library.
Reset the hardware event counts in an event set.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
Return codes and api definitions.
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_pass(const char *filename)
Definition: test_utils.c:432
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:584
int main()
Definition: pernode.c:20
int quiet
Definition: rapl_overflow.c:19
__syscall_slong_t tv_nsec
__time_t tv_sec
int retval
Definition: zero_fork.c:53