PAPI 7.1.0.0
Loading...
Searching...
No Matches
papi_br_tkn.c File Reference
Include dependency graph for papi_br_tkn.c:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 21 of file papi_br_tkn.c.

21 {
22
23 int num_runs=100,i;
24 long long high=0,low=0,average=0;
25 long long expected_cond=500000,expected_total=1000000;
26 double error;
27
28 long long count,total=0;
29 int quiet=0,retval,ins_result;
30 int eventset_total=PAPI_NULL;
31 int eventset_conditional=PAPI_NULL;
32 int eventset_taken=PAPI_NULL;
33 int eventset_nottaken=PAPI_NULL;
34 long long count_total,count_conditional,count_taken,count_nottaken;
35 int cond_avail=1,nottaken_avail=1;
36 int not_expected=0;
37
38 quiet=tests_quiet(argc,argv);
39
40 if (!quiet) {
41 printf("\nTesting the PAPI_BR_TKN event.\n");
42 printf("\tIt measures total number of conditional branches not taken\n");
43 }
44
45 /* Init the PAPI library */
47 if ( retval != PAPI_VER_CURRENT ) {
48 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
49 }
50
51 /* Create Total Eventset */
52 retval=PAPI_create_eventset(&eventset_total);
53 if (retval!=PAPI_OK) {
54 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
55 }
56
57 retval=PAPI_add_named_event(eventset_total,"PAPI_BR_INS");
58 if (retval!=PAPI_OK) {
59 test_skip( __FILE__, __LINE__, "adding PAPI_BR_INS", retval );
60 }
61
62
63 /* Create Total Eventset */
64 retval=PAPI_create_eventset(&eventset_conditional);
65 if (retval!=PAPI_OK) {
66 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
67 }
68
69 retval=PAPI_add_named_event(eventset_conditional,"PAPI_BR_CN");
70 if (retval!=PAPI_OK) {
71 if (!quiet) printf("Could not add PAPI_BR_CN\n");
72 cond_avail=0;
73 //test_skip( __FILE__, __LINE__, "adding PAPI_BR_CN", retval );
74 }
75
76 /* Create Taken Eventset */
77 retval=PAPI_create_eventset(&eventset_taken);
78 if (retval!=PAPI_OK) {
79 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
80 }
81
82 retval=PAPI_add_named_event(eventset_taken,"PAPI_BR_TKN");
83 if (retval!=PAPI_OK) {
84 if (!quiet) printf("Could not add PAPI_BR_TKN\n");
85 test_skip( __FILE__, __LINE__, "adding PAPI_BR_TKN", retval );
86 }
87
88 /* Create Not-Taken Eventset */
89 retval=PAPI_create_eventset(&eventset_nottaken);
90 if (retval!=PAPI_OK) {
91 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
92 }
93
94 retval=PAPI_add_named_event(eventset_nottaken,"PAPI_BR_NTK");
95 if (retval!=PAPI_OK) {
96 if (!quiet) printf("Could not add PAPI_BR_NTK\n");
97 nottaken_avail=0;
98 //test_skip( __FILE__, __LINE__, "adding PAPI_BR_NTK", retval );
99 }
100
101 /* Get total count */
102 PAPI_reset(eventset_total);
103 PAPI_start(eventset_total);
104 ins_result=branches_testcode();
105 retval=PAPI_stop(eventset_total,&count_total);
106
107 /* Get conditional count */
108 if (cond_avail) {
109 PAPI_reset(eventset_conditional);
110 PAPI_start(eventset_conditional);
111 ins_result=branches_testcode();
112 retval=PAPI_stop(eventset_conditional,&count_conditional);
113 }
114
115 /* Get taken count */
116 PAPI_reset(eventset_taken);
117 PAPI_start(eventset_taken);
118 ins_result=branches_testcode();
119 retval=PAPI_stop(eventset_taken,&count_taken);
120
121
122 /* Get not-taken count */
123 if (nottaken_avail) {
124 PAPI_reset(eventset_nottaken);
125 PAPI_start(eventset_nottaken);
126 ins_result=branches_testcode();
127 retval=PAPI_stop(eventset_nottaken,&count_nottaken);
128 }
129
130 if (!quiet) {
131 printf("The test code has:\n");
132 printf("\t%lld total branches\n",count_total);
133 if (cond_avail) {
134 printf("\t%lld conditional branches\n",count_conditional);
135 }
136 printf("\t%lld taken branches\n",count_taken);
137 if (nottaken_avail) {
138 printf("\t%lld not-taken branches\n",count_nottaken);
139 }
140
141 }
142
143 if (!quiet) {
144 printf("Testing a loop with %lld conditional taken branches (%d times):\n",
145 expected_cond,num_runs);
146 }
147
148 for(i=0;i<num_runs;i++) {
149 PAPI_reset(eventset_taken);
150 PAPI_start(eventset_taken);
151
152 ins_result=branches_testcode();
153
154 retval=PAPI_stop(eventset_taken,&count);
155
156 if (ins_result==CODE_UNIMPLEMENTED) {
157 fprintf(stderr,"\tCode unimplemented\n");
158 test_skip( __FILE__, __LINE__, "unimplemented", 0);
159 }
160
161 if (retval!=PAPI_OK) {
162 test_fail( __FILE__, __LINE__,
163 "reading PAPI_BR_TKN", retval );
164 }
165
166 if (count>high) high=count;
167 if ((low==0) || (count<low)) low=count;
168 total+=count;
169 }
170
171 average=(total/num_runs);
172
173 error=display_error(average,high,low,expected_cond,quiet);
174
175 if ((error > 1.0) || (error<-1.0)) {
176 if (!quiet) printf("Instruction count off by more than 1%%\n");
177 not_expected=1;
178 //test_fail( __FILE__, __LINE__, "Error too high", 1 );
179 }
180
181 if (!quiet) printf("\n");
182
183 /* Check if using TOTAL instead of CONDITIONAL */
184 if (not_expected) {
185
186 error=display_error(average,high,low,expected_total,quiet);
187
188 if ((error > 1.0) || (error<-1.0)) {
189 if (!quiet) printf("Instruction count off by more than 1%%\n");
190 test_fail( __FILE__, __LINE__, "Error too high", 1 );
191 }
192 else {
193 test_warn(__FILE__,__LINE__,"Using TOTAL BRANCHES as base rather than CONDITIONAL BRANCHES\n",0);
194 }
195 }
196
197 test_pass( __FILE__ );
198
200
201 return 0;
202}
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.
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
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 test_warn(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:547
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:584
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
Here is the call graph for this function: