Skip to content

Commit ee7cba9

Browse files
maksimioMaksim Lopatin
andauthored
Fix threadsPerCore check for Zen 2 (AMD) (#149)
Co-authored-by: Maksim Lopatin <lopatinma@mts.ru>
1 parent 60035f3 commit ee7cba9

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

cpuid.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -800,11 +800,16 @@ func threadsPerCore() int {
800800
_, b, _, _ := cpuidex(0xb, 0)
801801
if b&0xffff == 0 {
802802
if vend == AMD {
803-
// Workaround for AMD returning 0, assume 2 if >= Zen 2
804-
// It will be more correct than not.
803+
// if >= Zen 2 0x8000001e EBX 15-8 bits means threads per core.
804+
// The number of threads per core is ThreadsPerCore+1
805+
// See PPR for AMD Family 17h Models 00h-0Fh (page 82)
805806
fam, _, _ := familyModel()
806807
_, _, _, d := cpuid(1)
807808
if (d&(1<<28)) != 0 && fam >= 23 {
809+
if maxExtendedFunction() >= 0x8000001e {
810+
_, b, _, _ := cpuid(0x8000001e)
811+
return int((b>>8)&0xff) + 1
812+
}
808813
return 2
809814
}
810815
}

0 commit comments

Comments
 (0)