PAPI  5.7.0.0
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 
27 int 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 
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_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 
100  PAPI_shutdown();
101 
102  return 0;
103 }
#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
static int expected[NUM_THREADS]
int PAPI_reset(int EventSet)
Definition: papi.c:2459
int main(int argc, char **argv)
Definition: papi_br_ins.c:27
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: fpapi.h:14
#define CODE_UNIMPLEMENTED
Definition: testcode.h:2
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
int PAPI_library_init(int version)
Definition: papi.c:500
void PAPI_shutdown(void)
Definition: papi.c:4461
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 branches_testcode(void)
static int total
Definition: rapl_overflow.c:9
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
int i
Definition: fileop.c:140