Skip to content

Commit 8355a85

Browse files
authored
Fix AMD cores count (#42)
1 parent eb9695f commit 8355a85

2 files changed

Lines changed: 62 additions & 5 deletions

File tree

source/cpuid/amd.d

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ union LeafExt8Information
211211
uint CLZERO();
212212
/// Instructions retired count support
213213
uint IRPerf();
214+
///
214215
uint XSaveErPtr();
215216
/// Number of threads in the package - 1
216217
uint NC();
@@ -233,9 +234,9 @@ union LeafExt8Information
233234

234235
/// EBX
235236
mixin(bitfields!(
236-
uint, "CLZERO", 1,
237-
uint, "IRPerf", 1,
238-
uint, "XSaveErPtr", 1,
237+
bool, "CLZERO", 1,
238+
bool, "IRPerf", 1,
239+
bool, "XSaveErPtr", 1,
239240
uint, "", 31 - 3 + 1,
240241
));
241242

@@ -251,6 +252,55 @@ union LeafExt8Information
251252
}
252253
}
253254

255+
/++
256+
Extended APIC ID.
257+
258+
Core Identifiers.
259+
260+
Node Identifiers.
261+
262+
Specification: AMD
263+
+/
264+
union LeafExt1EInformation
265+
{
266+
/// CPUID payload
267+
CpuInfo info;
268+
269+
///
270+
struct
271+
{
272+
import mir.bitmanip: bitfields;
273+
// EAX
274+
/// Extended APIC ID
275+
uint ExtendedApicId;
276+
// EBX
277+
ushort __reserved__EBX;
278+
/// The number of threads per core is ThreadsPerCore+1.
279+
ubyte ThreadsPerCore;
280+
/// Core ID
281+
ubyte CoreId;
282+
version(D_Ddoc)
283+
{
284+
const @trusted @property pure nothrow @nogc:
285+
/// Node per processor.
286+
uint NodesPerProcessor();
287+
/// Node ID
288+
uint NodeId();
289+
}
290+
else
291+
{
292+
@trusted @property pure nothrow @nogc:
293+
294+
/// ECX
295+
mixin(bitfields!(
296+
uint, "", 31 - 11 + 1,
297+
uint, "NodesPerProcessor", 10 - 8 + 1,
298+
uint, "NodeId", 7 - 0 + 1,
299+
));
300+
}
301+
}
302+
}
303+
254304
/++
255305
Decodes Associativity Fields for L2/L3 Cache or TLB.
256306
`T.max` is used to represent full-associative Cache/TLB.

source/cpuid/unified.d

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,12 @@ void mir_cpuid_init()
109109
static import cpuid.amd;
110110

111111
/// for old CPUs
112-
_threads._mut = _cores._mut = maxLogicalProcessors;
113112
if(htt)
114113
{
115-
_threads._mut *= 2;
114+
_threads._mut = _cores._mut = maxLogicalProcessors;
115+
_cores._mut /= 2;
116116
}
117+
117118
if (vendorIndex == VendorIndex.amd ||
118119
vendorIndex == VendorIndex.amd_old ||
119120
vendorIndex == VendorIndex.centaur ||
@@ -196,6 +197,12 @@ void mir_cpuid_init()
196197
{
197198
auto leafExt8 = cpuid.amd.LeafExt8Information(_cpuid(0x8000_0008));
198199
_threads._mut = leafExt8.NC + 1;
200+
201+
if (maxExtendedLeaf >= 0x8000_001E)
202+
{
203+
auto leafExt1E = cpuid.amd.LeafExt1EInformation(_cpuid(0x8000_001E));
204+
_cores._mut = _threads / (leafExt1E.ThreadsPerCore + 1);
205+
}
199206
}
200207
}
201208
}

0 commit comments

Comments
 (0)