PAPI 7.1.0.0
Loading...
Searching...
No Matches
papi_br_cn.c
Go to the documentation of this file.
1/* This file attempts to test the conditional branch instructions */
2/* performance counter PAPI_BR_CN */
3
4/* by Vince Weaver, <vincent.weaver@maine.edu> */
5
6#include <stdlib.h>
7#include <stdio.h>
8#include <unistd.h>
9#include <string.h>
10
11#include "papi.h"
12#include "papi_test.h"
13
14#include "display_error.h"
15#include "testcode.h"
16
17
18int main(int argc, char **argv) {
19
20 int num_runs=100,i;
21 long long high=0,low=0,average=0,expected=1000000;
22 double error;
23
24 long long count,total=0;
25 int quiet=0,retval,ins_result;
26 int eventset=PAPI_NULL;
27
28 quiet=tests_quiet(argc,argv);
29
30 if (!quiet) {
31 printf("\nTesting the PAPI_BR_CN event.\n");
32 }
33
34 /* Init the PAPI library */
36 if ( retval != PAPI_VER_CURRENT ) {
37 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
38 }
39
41 if (retval!=PAPI_OK) {
42 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
43 }
44
45 retval=PAPI_add_named_event(eventset,"PAPI_BR_CN");
46 if (retval!=PAPI_OK) {
47 test_skip( __FILE__, __LINE__, "adding PAPI_BR_CN", retval );
48 }
49
50 if (!quiet) {
51 printf("Testing a loop with %lld conditional branches (%d times):\n",
52 expected,num_runs);
53 }
54
55 for(i=0;i<num_runs;i++) {
56 PAPI_reset(eventset);
57 PAPI_start(eventset);
58
59 ins_result=branches_testcode();
60
61 retval=PAPI_stop(eventset,&count);
62
63 if (ins_result==CODE_UNIMPLEMENTED) {
64 fprintf(stderr,"\tCode unimplemented\n");
65 test_skip( __FILE__, __LINE__, "unimplemented", 0);
66 }
67
68 if (retval!=PAPI_OK) {
69 test_fail( __FILE__, __LINE__,
70 "reading PAPI_TOT_INS", retval );
71 }
72
73 if (count>high) high=count;
74 if ((low==0) || (count<low)) low=count;
75 total+=count;
76 }
77
78 average=(total/num_runs);
79
80 error=display_error(average,high,low,expected,quiet);
81
82 if ((error > 1.0) || (error<-1.0)) {
83 if (!quiet) printf("Instruction count off by more than 1%%\n");
84 test_fail( __FILE__, __LINE__, "Error too high", 1 );
85 }
86
87 if (!quiet) printf("\n");
88
89 test_pass( __FILE__ );
90
92
93 return 0;
94}
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