-
Notifications
You must be signed in to change notification settings - Fork 13
/
pfcdemo.c
292 lines (254 loc) · 6.85 KB
/
pfcdemo.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
/* Includes */
#include "libpfc.h"
#include <ctype.h>
#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
/* Typedefs */
typedef unsigned long long ull;
typedef signed long long sll;
/**
* Code snippet to bench
*/
static inline void code1(void){
asm volatile(
"vzeroall\n\t"
"xor %%eax, %%eax\n\t"
"mov $1000000000, %%rsi\n\t"
"0:\n\t"
"vfmadd231ps %%ymm0, %%ymm15, %%ymm0\n\t"
"vfmadd231ps %%ymm1, %%ymm15, %%ymm1\n\t"
"vfmadd231ps %%ymm2, %%ymm15, %%ymm2\n\t"
"vpaddd %%ymm10, %%ymm15, %%ymm10\n\t"
"vfmadd231ps %%ymm3, %%ymm15, %%ymm3\n\t"
"vfmadd231ps %%ymm4, %%ymm15, %%ymm4\n\t"
"vfmadd231ps %%ymm5, %%ymm15, %%ymm5\n\t"
"vpaddd %%ymm11, %%ymm15, %%ymm11\n\t"
"vfmadd231ps %%ymm6, %%ymm15, %%ymm6\n\t"
"vfmadd231ps %%ymm7, %%ymm15, %%ymm7\n\t"
"vpaddd %%ymm12, %%ymm15, %%ymm12\n\t"
"vpaddd %%ymm13, %%ymm15, %%ymm13\n\t"
"vfmadd231ps %%ymm8, %%ymm15, %%ymm8\n\t"
"vfmadd231ps %%ymm9, %%ymm15, %%ymm9\n\t"
"vpaddd %%ymm14, %%ymm15, %%ymm14\n\t"
"dec %%rsi\n\t"
"jnz 0b\n\t"
: /* No outputs we care about */
: /* No inputs we care about */
: "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7",
"xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15",
"rsi", "rax", "rbx", "rcx", "rdx",
"memory"
);
}
/* Test Schedule */
static const char* const SCHEDULE[];
static const int NUMCOUNTS;
/**
* Main
*/
int main(int argc, char* argv[]){
int i;
int verbose = 0, dump = 0, option;
/**
* Process command line arguments
*/
while ((option = getopt(argc, argv, "dv")) != -1) {
switch (option) {
case 'v':
verbose = 1;
break;
case 'd':
dump = 1;
break;
default:
fprintf(stderr, "Usage: pfcdemo [-d] [-v]\n"
"\t-d\n\t\tDump the list of available events and quit\n"
"\t-v\n\t\tVerbose output\n");
exit(1);
}
}
(void)verbose;
if(dump){
pfcDumpEvts();
exit(1);
}
/**
* Initialize library.
*/
pfcPinThread(3);
if(pfcInit() != 0){
printf("Could not open /sys/module/pfc/* handles; Is module loaded?\n");
exit(1);
}
/**
* Warm up.
*/
static const PFC_CNT ZERO_CNT[7] = {0,0,0,0,0,0,0};
PFC_CNT CNT[7] = {0,0,0,0,0,0,0};
PFC_CFG CFG[7] = {2,2,2,0,0,0,0};
for(i=0;i<1;i++){
code1();
}
/**
* Run master loop under all counter configurations in SCHEDULE.
*/
for(i=0;i<NUMCOUNTS;i+=4){
/* Configure general-purpose counters. */
const char* sched0 = i+0 < NUMCOUNTS ? SCHEDULE[i+0] : "";
const char* sched1 = i+1 < NUMCOUNTS ? SCHEDULE[i+1] : "";
const char* sched2 = i+2 < NUMCOUNTS ? SCHEDULE[i+2] : "";
const char* sched3 = i+3 < NUMCOUNTS ? SCHEDULE[i+3] : "";
CFG[3] = pfcParseCfg(sched0);
CFG[4] = pfcParseCfg(sched1);
CFG[5] = pfcParseCfg(sched2);
CFG[6] = pfcParseCfg(sched3);
/* Reconfigure PMCs and clear their counts. */
pfcWrCfgs(0, 7, CFG);
pfcWrCnts(0, 7, ZERO_CNT);
/**
* We benchmark the warmed-up code.
*
* The PFCSTART()/PFCEND() macro pair must sandwich the code to be
* tested as accurately as possible, although frequently one or more
* intruder instructions appear. Their argument is the buffer of (7)
* PFC_CNT counters.
*
* PFCSTART() and PFCEND() do *not* replace the old values in the array.
* Instead they *accumulate* into the array a (biased) difference between
* the values of the counters at the moment PFCSTART() and PFCEND() were
* called. The bias is computable more-or-less precisely, and can be
* removed by invoking pfcRemoveBias(CNT).
*/
memset(CNT, 0, sizeof(CNT));
/************** Hot section **************/
PFCSTART(CNT);
code1();
PFCEND (CNT);
/************ End Hot section ************/
/**
* Remove bias.
*
* The "mul" argument should exactly equal the number of times
* the PFCSTART()/PFCEND() pair has been executed in
* the hot section.
*/
pfcRemoveBias(CNT, 1);
/**
* Print the lovely results
*/
printf("Instructions Issued : %20lld\n", (sll)CNT[0]);
printf("Unhalted core cycles : %20lld\n", (sll)CNT[1]);
printf("Unhalted reference cycles : %20lld\n", (sll)CNT[2]);
printf("%-37s: %20lld\n", sched0 , (sll)CNT[3]);
printf("%-37s: %20lld\n", sched1 , (sll)CNT[4]);
printf("%-37s: %20lld\n", sched2 , (sll)CNT[5]);
printf("%-37s: %20lld\n", sched3 , (sll)CNT[6]);
}
/**
* Close up shop
*/
pfcFini();
return 0;
}
static const char* const SCHEDULE[] = {
/* Batch */
"uops_issued.any",
"uops_issued.any<1",
"uops_issued.any>=1",
"uops_issued.any>=2",
/* Batch */
"uops_issued.any>=3",
"uops_issued.any>=4",
"uops_issued.any>=5",
"uops_issued.any>=6",
/* Batch */
"uops_executed_port.port_0",
"uops_executed_port.port_1",
"uops_executed_port.port_2",
"uops_executed_port.port_3",
/* Batch */
"uops_executed_port.port_4",
"uops_executed_port.port_5",
"uops_executed_port.port_6",
"uops_executed_port.port_7",
/* Batch */
"resource_stalls.any",
"resource_stalls.rs",
"resource_stalls.sb",
"resource_stalls.rob",
/* Batch */
"uops_retired.all",
"uops_retired.all<1",
"uops_retired.all>=1",
"uops_retired.all>=2",
/* Batch */
"uops_retired.all>=3",
"uops_retired.all>=4",
"uops_retired.all>=5",
"uops_retired.all>=6",
/* Batch */
"inst_retired.any_p",
"inst_retired.any_p<1",
"inst_retired.any_p>=1",
"inst_retired.any_p>=2",
/* Batch */
"inst_retired.any_p>=3",
"inst_retired.any_p>=4",
"inst_retired.any_p>=5",
"inst_retired.any_p>=6",
/* Batch */
"idq_uops_not_delivered.core",
"idq_uops_not_delivered.core<1",
"idq_uops_not_delivered.core>=1",
"idq_uops_not_delivered.core>=2",
/* Batch */
"idq_uops_not_delivered.core>=3",
"idq_uops_not_delivered.core>=4",
"rs_events.empty",
"idq.empty",
/* Batch */
"idq.mite_uops",
"idq.dsb_uops",
"idq.ms_dsb_uops",
"idq.ms_mite_uops",
/* Batch */
"idq.mite_all_uops",
"idq.mite_all_uops<1",
"idq.mite_all_uops>=1",
"idq.mite_all_uops>=2",
/* Batch */
"idq.mite_all_uops>=3",
"idq.mite_all_uops>=4",
"move_elimination.int_not_eliminated",
"move_elimination.simd_not_eliminated",
/* Batch */
"lsd.uops",
"lsd.uops<1",
"lsd.uops>=1",
"lsd.uops>=2",
/* Batch */
"lsd.uops>=3",
"lsd.uops>=4",
"ild_stall.lcp",
"ild_stall.iq_full",
/* Batch */
"br_inst_exec.all_branches",
"br_inst_exec.0x81",
"br_inst_exec.0x82",
"icache.misses",
/* Batch */
"br_misp_exec.all_branches",
"br_misp_exec.0x81",
"br_misp_exec.0x82",
"fp_assist.any",
/* Batch */
"cpu_clk_unhalted.core_clk",
"cpu_clk_unhalted.ref_xclk",
"baclears.any",
"idq.ms_uops"
};
static const int NUMCOUNTS = sizeof(SCHEDULE)/sizeof(*SCHEDULE);