-
Notifications
You must be signed in to change notification settings - Fork 8
/
report.d
283 lines (253 loc) · 6.33 KB
/
report.d
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
/+ dub.json:
{
"name": "cpuid-report",
"dependencies": {"mir-cpuid": {"path": "./"}},
}
+/
/++
Text information generators.
License: $(WEB www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
Authors: Ilia Ki
+/
module cpuid.report;
void main()
{
import cpuid.unified;
import cpuid.report;
import std.stdio;
cpuid.report.unified.writeln;
version(X86)
cpuid.report.x86_any.writeln;
version(X86_64)
cpuid.report.x86_any.writeln;
}
/// Returns report for `cpuid.unified`.
string unified()()
{
import std.traits;
import std.array;
import std.format;
import cpuid.unified;
auto app = appender!string;
void putAssociative(T)(T v)
{
switch(v)
{
case 1:
app.formattedWrite("\t\tAssociativity: direct mapped\n");
break;
case T.max:
app.formattedWrite("\t\tAssociativity: Fully associative\n");
break;
default:
app.formattedWrite("\t\tAssociativity: %s-way associative\n", v);
}
}
void putCache(Cache cache)
{
app.formattedWrite("\t\tCache size = %s KB\n", cache.size);
app.formattedWrite("\t\tLine = %s bytes\n", cache.line);
app.formattedWrite("\t\tCores per cache = %s\n", cache.cores);
app.formattedWrite("\t\tInclusive: %s\n", cache.inclusive);
putAssociative(cache.associative);
}
void putTlb(Tlb tlb)
{
app.formattedWrite("\t\tPage size = %s KB\n", tlb.page);
app.formattedWrite("\t\tPages count = %s\n", tlb.entries);
putAssociative(tlb.associative);
}
app.formattedWrite("################ Unified Information ################\n");
app.formattedWrite("Cores per CPU: %s\n", cores);
app.formattedWrite("Threads per CPU: %s\n", threads);
app.formattedWrite("------------------ TLB Information ------------------\n");
app.formattedWrite("Instruction TLB:\n");
foreach(i, tlb; iTlb)
{
app.formattedWrite("- - - - - ITLB%s: - - - - - - - - - - - - - - - - - -\n", i + 1);
putTlb(tlb);
}
app.formattedWrite("Data TLB:\n");
foreach(i, tlb; dTlb)
{
app.formattedWrite("- - - - - DTLB%s: - - - - - - - - - - - - - - - - - -\n", i + 1);
putTlb(tlb);
}
app.formattedWrite("Unified TLB:\n");
foreach(i, tlb; uTlb)
{
app.formattedWrite("- - - - - UTLB%s: - - - - - - - - - - - - - - - - - -\n", i + 1);
putTlb(tlb);
}
app.formattedWrite("----------------- Cache Information -----------------\n");
app.formattedWrite("Instruction Cache:\n");
foreach(i, cache; iCache)
{
app.formattedWrite("- - - - - ICache%s: - - - - - - - - - - - - - - - - -\n", i + 1);
putCache(cache);
}
app.formattedWrite("Data Cache:\n");
foreach(i, cache; dCache)
{
app.formattedWrite("- - - - - DCache%s: - - - - - - - - - - - - - - - - -\n", i + 1);
putCache(cache);
}
app.formattedWrite("Unified Cache:\n");
foreach(i, cache; uCache)
{
app.formattedWrite("- - - - - UCache%s: - - - - - - - - - - - - - - - - -\n", i + 1);
putCache(cache);
}
return app.data;
}
private alias AliasSeq(T...) = T;
/// Returns report for `cpuid.x86_any`.
string x86_any()()
{
import std.traits;
import std.array;
import std.format;
import cpuid.x86_any;
auto app = appender!string;
app.formattedWrite("################## x86 Information ##################\n");
//app.formattedWrite("CPU count = %s\n", cpus);
char[48] brandName = void;
auto len = brand(brandName);
app.formattedWrite("%20s: %s\n", "brand", brandName[0 .. len]);
foreach(i, name; AliasSeq!(
"vendor",
"virtualVendor",
"virtual",
"vendorIndex",
"virtualVendorIndex",
"brandIndex",
"maxBasicLeaf",
"maxExtendedLeaf",
"max7SubLeafs",
"acpi",
"adx",
"aes",
"apic",
"avx",
"avx2",
"avx512bitalg",
"avx512bw",
"avx512cd",
"avx512dq",
"avx512er",
"avx512f",
"avx512ifma",
"avx512pf",
"avx512vbmi",
"avx512vbmi2",
"avx512vl",
"avx512vnni",
"avx512vpopcntdq",
"bmi1",
"bmi2",
"cet_ss",
"cldemote",
"clflushLineSize",
"clflushopt",
"clfsh",
"clwb",
"cmov",
"cmpxchg16b",
"cnxt_id",
"cx8",
"dca",
"de",
"deprecates",
"ds_cpl",
"ds",
"dtes64",
"eist",
"extendedFamily",
"extendedModel",
"f16c",
"family",
"fdp_excptn_only",
"fma",
"fpu",
"fsgsbase",
"fxsr",
"gfni",
"hle",
"htt",
"ia32_tsc_adjust",
"initialAPIC",
"intel_pt",
"invpcid",
"mawau",
"max7SubLeafs",
"maxLogicalProcessors",
"mca",
"mce",
"mmx",
"model",
"monitor",
"movbe",
"movdir64b",
"movdiri",
"mpx",
"msr",
"mtrr",
"ospke",
"osxsave",
"pae",
"pat",
"pbe",
"pcid",
"pclmulqdq",
"pcommit",
"pdcm",
"pge",
"pku",
"popcnt",
"prefetchwt1",
"pse",
"pse36",
"psn",
"rdrand",
"rdseed",
"rdt_a",
"rdt_m",
"rtm",
"sdbg",
"self_snoop",
"sep",
"sgx_lc",
"sgx",
"sha",
"smap",
"smep",
"smx",
"sse",
"sse2",
"sse3",
"sse41",
"sse42",
"ssse3",
"stepping",
"supports",
"therm_monitor",
"therm_monitor2",
"tsc_deadline",
"tsc",
"type",
"umip",
"vaes",
"vme",
"vmx",
"vpclmulqdq",
"waitpkg",
"x2apic",
"xsave",
"xtpr",
))
static if(mixin(`isIntegral!(typeof(` ~ name ~ `))`))
mixin(`app.formattedWrite("%20s: 0x%X\n", "` ~ name ~ `", ` ~ name ~ `);`);
else
mixin(`app.formattedWrite("%20s: %s\n", "` ~ name ~ `", ` ~ name ~ `);`);
return app.data;
}