PAPI 7.1.0.0
Loading...
Searching...
No Matches
papi_br_ins.c
Go to the documentation of this file.
1/* This file attempts to test the retired branches instruction */
2/* performance counter PAPI_BR_INS */
3
4/* by Vince Weaver, <vincent.weaver@maine.edu> */
5
6/* This test seems to work on: */
7/* + x86 */
8/* + ARMv6 (Raspberry Pi) */
9/* It is known to not work on: */
10/* + ARMv7 (Pi2 CortexA7 Panda CortexA9 */
11/* failure is odd, 1/3 missing but not consistent */
12/* something weird with event 0xC PC_WRITE ? */
13
14
15#include <stdlib.h>
16#include <stdio.h>
17#include <unistd.h>
18#include <string.h>
19
20#include "papi.h"
21#include "papi_test.h"
22
23#include "display_error.h"
24#include "testcode.h"
25
26
27int main(int argc, char **argv) {
28
29 int num_runs=100,i;
30 long long high=0,low=0,average=0,expected=1500000;
31 double error;
32
33 long long count,total=0;
34 int quiet=0,retval,ins_result;
35 int eventset=PAPI_NULL;
36
37 quiet=tests_quiet(argc,argv);
38
39 if (!quiet) {
40 printf("\nTesting the PAPI_BR_INS event.\n");
41 }
42
43 /* Init the PAPI library */
45 if ( retval != PAPI_VER_CURRENT ) {
46 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
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_BR_INS");
55 if (retval!=PAPI_OK) {
56 test_skip( __FILE__, __LINE__, "adding PAPI_BR_INS", retval );
57 }
58
59 if (!quiet) {
60 printf("Testing a loop with %lld branches (%d times):\n",
61 expected,num_runs);
62 }
63
64 for(i=0;i<num_runs;i++) {
65 PAPI_reset(eventset);
66 PAPI_start(eventset);
67
68 ins_result=branches_testcode();
69
70 retval=PAPI_stop(eventset,&count);
71
72 if (ins_result==CODE_UNIMPLEMENTED) {
73 fprintf(stderr,"\tCode unimplemented\n");
74 test_skip( __FILE__, __LINE__, "unimplemented", 0);
75 }
76
77 if (retval!=PAPI_OK) {
78 test_fail( __FILE__, __LINE__,
79 "reading PAPI_TOT_INS", retval );
80 }
81
82 if (count>high) high=count;
83 if ((low==0) || (count<low)) low=count;
84 total+=count;
85 }
86
87 average=(total/num_runs);
88
89 error=display_error(average,high,low,expected,quiet);
90
91 if ((error > 1.0) || (error<-1.0)) {
92 if (!quiet) printf("Instruction count off by more than 1%%\n");
93 test_fail( __FILE__, __LINE__, "Error too high", 1 );
94 }
95
96 if (!quiet) printf("\n");
97
98 test_pass( __FILE__ );
99
101
102 return 0;
103}
int i
int branches_testcode(void)
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.
Finish using PAPI and free all related resources.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
static int expected[NUM_THREADS]
double display_error(long long average, long long high, long long low, long long expected, int quiet)
Definition: display_error.c:7
#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.
FILE * stderr
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
static int total
Definition: rapl_overflow.c:9
#define CODE_UNIMPLEMENTED
Definition: testcode.h:2
int retval
Definition: zero_fork.c:53