25 {
26
28 int num_random_branches=500000;
29 long long high=0,low=0,average=0,
expected=1500000;
30 long long expected_high,expected_low;
31
35
37
39 printf("\nTesting the PAPI_BR_PRC event.\n\n");
40 printf("This should measure predicted correctly conditional branches\n");
41 printf("If such a counter is not available, it may report predicted correctly\n");
42 printf("total branches instead.\n");
43 }
44
45
49 }
50
51
55 }
56
59 if (!
quiet) printf(
"Could not add PAPI_BR_CN\n");
60
61
64 if (!
quiet) printf(
"Could not add PAPI_BR_INS\n");
66 }
67 }
68
69
70
71
72
73
77 }
78
81 if (!
quiet) printf(
"Could not add PAPI_BR_PRC\n");
83 }
84
86 printf("\nPart 1: Testing that easy to predict loop has few misses\n");
87 printf("Testing a loop with %lld branches (%d times):\n",
89 printf("\tOn a simple loop like this, "
90 "hit rate should be very high.\n");
91 }
92
93 for(
i=0;
i<num_runs;
i++) {
94
97
99
101
103 fprintf(
stderr,
"\tCode unimplemented\n");
104 test_skip( __FILE__, __LINE__,
"unimplemented", 0);
105 }
106
109 "reading PAPI_TOT_INS",
retval );
110 }
111
115 }
116
117 average=(
total/num_runs);
118
119 if (!
quiet) printf(
"\tAverage number of branch hits: %lld\n",average);
120
122 if (!
quiet) printf(
"Branch miss rate too high\n");
123 test_fail( __FILE__, __LINE__,
"Error too high", 1 );
124 }
125
126
127
129 printf("\nPart 2\n");
130 }
131
132 high=0; low=0;
total=0;
133
134 for(
i=0;
i<num_runs;
i++) {
137
139
141
143 fprintf(
stderr,
"\tCode unimplemented\n");
144 test_skip( __FILE__, __LINE__,
"unimplemented", 0);
145 }
146
149 "reading PAPI_TOT_INS",
retval );
150 }
151
155 }
156
157 average=
total/num_runs;
158
161 printf("\nTesting a function that branches "
162 "based on a random number\n");
163 printf(
" The loop has %lld conditional branches.\n",
expected);
164 printf(" %d are random branches.\n",num_random_branches);
165 }
166
167 high=0; low=0;
total=0;
168
169 for(
i=0;
i<num_runs;
i++) {
172
174
176
178 fprintf(
stderr,
"\tCode unimplemented\n");
179 test_skip( __FILE__, __LINE__,
"unimplemented", 0);
180 }
181
184 "reading eventset",
retval );
185 }
186
190 }
191
192 average=
total/num_runs;
193
194 expected_low=
expected-((num_random_branches/4)*3);
195 expected_high=
expected-(num_random_branches/4);
196
198 printf("\nOut of %lld branches, "
199 "%lld were correctly predicted\n",
expected,average);
200 printf("Assuming a good random number generator and no "
201 "freaky luck\n");
202 printf("The mispredicts should be roughly "
203 "between %lld and %lld\n",
204 expected_low,expected_high);
205
206 }
207
208 if ( average < expected_low) {
209 if (!
quiet) printf(
"Branch hits too low\n");
210 test_fail( __FILE__, __LINE__,
"Error too low", 1 );
211 }
212
213 if (average > expected_high) {
214 if (!
quiet) printf(
"Branch hits too high\n");
215 test_fail( __FILE__, __LINE__,
"Error too high", 1 );
216 }
217
218 if (!
quiet) printf(
"\n");
219
221
223
224 return 0;
225
226}
int branches_testcode(void)
int random_branches_testcode(int number, int quiet)
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]
int tests_quiet(int argc, char **argv)
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
void PAPI_NORETURN test_pass(const char *filename)
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
#define CODE_UNIMPLEMENTED