-
Notifications
You must be signed in to change notification settings - Fork 0
/
uperf.cpp
228 lines (205 loc) · 7.36 KB
/
uperf.cpp
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
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "arch.h"
#include "osutils.h"
#include "pat_config.h"
// Oline compiler
// https://godbolt.org/
// Online asm generate
// https://disasm.pro/
// https://armconverter.com/
// https://defuse.ca/online-x86-assembler.htm
const unsigned JitMemorySize = 0x1000000;
const char *TestCaseName[TestCaseEnd] = {
"Inst Nop",
"Inst Mov",
"Inst IALU",
"Inst IALUChain",
"Inst FALU",
"Inst FALUChain",
"Inst Cmp",
"Inst Lea3",
"Inst Lea3Chain",
"Inst Load",
"Inst Store",
"Sqrt Delay + Nop",
"Sqrt Delay + Mov",
"Sqrt Delay + Mov Self",
"Sqrt Delay + Mov Self(FP)",
"Sqrt Delay + IALU",
"Udiv Delay + V/FALU",
"Sqrt Delay + Cmp",
"Sqrt Delay + Add&Cmp",
"Sqrt Delay + IALU&V/FALU",
"Sqrt Delay + Load Same Addr",
"Sqrt Delay + Load Linear Addr",
"Sqrt Delay + Load Unknown Addr",
"Sqrt Delay + Load Chain Addr",
"Sqrt Delay + Store Same Addr",
"Sqrt Delay + Store Linear Addr",
"Sqrt Delay + Store Unknown Addr",
"Sqrt Delay + Store Unknown Value",
"Sqrt Delay + ConditionJump",
"Sqrt Delay + Jump",
"Sqrt Delay + Jump&CJump",
"Sqrt Delay + Nop + IALU",
"Sqrt Delay + V/FALU + IALU",
"Sqrt Delay + IALU depency on Delay",
"Sqrt Delay + IALU chain depency on Delay",
"SDiv Delay + FALU depency on Delay",
"SDiv Delay + FALU chain depency on Delay",
"IALU + Nop",
"IALUChain + Nop",
"ICmp + Nop",
"FALU + Nop",
"FALUChain + Nop",
"Period IALU + Nop",
"Period ICmp + Nop",
"Period FALU + Nop",
};
bool runPattern(PatConfig &config, unsigned char *instBuf, TestParam ¶m, unsigned testCnt) {
genPattern(config, instBuf, param, testCnt);
size_t r0 = config.args.iArg0;
size_t r1 = config.args.iArg1;
void *r2 = config.args.ptrArg0;
void *r3 = config.args.ptrArg1;
// __debugbreak();
// warm icache
((size_t(*)(size_t, size_t, void *, void *))instBuf)(r0, r1, r2, r3);
size_t min = -1;
for (unsigned k = 0; k < 10; k++) {
size_t start = getclock();
for (unsigned i = 0; i < param.loopCnt; i++) {
((size_t(*)(size_t, size_t, void *, void *))instBuf)(r0, r1, r2, r3);
}
size_t end = getclock();
size_t clock = end - start;
if (min > clock)
min = clock;
}
printf("%.1f ", (double)min / param.loopCnt);
return true;
}
bool parseArgs(int argc, char *argv[], TestParam ¶m, TestCase &caseId, PatConfig &config,
unsigned &affinity) {
int configFileIdx = -1;
for (int i = 1; i < argc; i += 2) {
if (strcmp(argv[i], "-case") == 0)
caseId = static_cast<TestCase>(atoi(argv[i + 1]));
else if (strcmp(argv[i], "-start") == 0)
param.begin = atoi(argv[i + 1]);
else if (strcmp(argv[i], "-end") == 0)
param.end = atoi(argv[i + 1]);
else if (strcmp(argv[i], "-step") == 0)
param.step = atoi(argv[i + 1]);
else if (strcmp(argv[i], "-delay") == 0)
param.delayCnt = atoi(argv[i + 1]);
else if (strcmp(argv[i], "-prologue") == 0)
param.prologueCnt = atoi(argv[i + 1]);
else if (strcmp(argv[i], "-epilogue") == 0)
param.epilogueCnt = atoi(argv[i + 1]);
else if (strcmp(argv[i], "-loop") == 0)
param.loopCnt = atoi(argv[i + 1]);
else if (strcmp(argv[i], "-inst_num") == 0)
param.instNum = atoi(argv[i + 1]);
else if (strcmp(argv[i], "-thrput_inst") == 0)
param.testInstTP = atoi(argv[i + 1]);
else if (strcmp(argv[i], "-thrput_fill") == 0)
param.fillInstTP = atoi(argv[i + 1]);
else if (strcmp(argv[i], "-affinity") == 0)
affinity = atoi(argv[i + 1]);
else if (strcmp(argv[i], "-f") == 0) {
if (!parseConfig(config, argv[i + 1])) {
printf("Config file parse failed\n");
return false;
}
configFileIdx = i + 1;
} else {
printf("caseId case Name\n");
for (int i = 0; i < TestCaseEnd; i++) {
printf("%2d, %36s\n", i, TestCaseName[i]);
}
printf("DelayMode:\n"
"uperf -case 14 \n"
" -start 100 \n"
" -end 1000 \n"
" -step 10 \n"
" -delay 8 \n"
" -prologue 1 \n"
" -epilogue 160 \n"
"PeriodMode:\n"
"uperf -case 42 \n"
" -start 1 \n"
" -end 16 \n"
" -step 1 \n"
" -inst_num 10000 \n"
" -thrput_inst 6 \n"
" -thrput_fill 8 \n\n"
" -loop 1000 \n"
" -affinity 1 \n");
return false;
}
}
if (configFileIdx < 0) {
if ((caseId < 0 || caseId >= TestCaseEnd)) {
printf("caseId case Name\n");
for (int i = 0; i < TestCaseEnd; i++) {
printf("%2d, %36s\n", i, TestCaseName[i]);
}
return false;
}
if (caseId < SqrtNop)
param.delayCnt = 0;
if (!genConfigForDefaultCases(caseId, config))
return false;
printf("affinity:0x%x, loop: %d, case: %s\n", affinity, param.loopCnt,
TestCaseName[caseId]);
} else {
printf("affinity:0x%x, loop: %d, configfile: %s\n", affinity, param.loopCnt,
argv[configFileIdx]);
}
if (config.mode == WorkMode::DelayTest) {
if (config.di.delayPat.size())
printf("delayCnt:%d ", param.delayCnt);
if (config.di.prologuePat.size())
printf("prologueCnt:%d ", param.prologueCnt);
if (config.di.epiloguePat.size())
printf("epilogueCnt:%d ", param.epilogueCnt);
} else if (config.mode == WorkMode::PeriodTest) {
printf("instNum:%d test inst throughput:%d, fill inst throughput:%d", param.instNum,
param.testInstTP, param.fillInstTP);
}
printf("\n");
return true;
}
int main(int argc, char *argv[]) {
TestParam param;
TestCase caseId = SqrtNop;
PatConfig config = {};
unsigned affinity = 1;
if (!parseArgs(argc, argv, param, caseId, config, affinity))
return 0;
if (!procInit(affinity))
return 1;
unsigned char *instBuf = allocVM(JitMemorySize);
fillNop(instBuf, JitMemorySize);
printf("arg0:%llu, arg1:%llu, ptr0:%p, ptr1:%p\n", config.args.iArg0, config.args.iArg1,
config.args.ptrArg0, config.args.ptrArg1);
printf("test start:\n");
for (unsigned testCnt = param.begin; testCnt < param.end; testCnt += param.step) {
printf("%d ", testCnt);
if (!runPattern(config, instBuf, param, testCnt)) {
printf("current test case is not support on the platform\n");
return 1;
}
printf("\n");
}
freeVM(instBuf, JitMemorySize);
if (config.args.ptrArg0)
free(config.args.ptrArg0);
if (config.args.ptrArg1)
free(config.args.ptrArg1);
return 0;
}