Skip to content

Commit

Permalink
Fix threadsPerCore check for Zen 2 (AMD)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maksim Lopatin committed Oct 26, 2024
1 parent 60035f3 commit 27e993c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions cpuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -800,11 +800,16 @@ func threadsPerCore() int {
_, b, _, _ := cpuidex(0xb, 0)
if b&0xffff == 0 {
if vend == AMD {
// Workaround for AMD returning 0, assume 2 if >= Zen 2
// It will be more correct than not.
// if >= Zen 2 0x8000001e EBX 15-8 bits means threads per core.
// The number of threads per core is ThreadsPerCore+1
// See PPR for AMD Family 17h Models 00h-0Fh (page 82)
fam, _, _ := familyModel()
_, _, _, d := cpuid(1)
if (d&(1<<28)) != 0 && fam >= 23 {
if maxExtendedFunction() >= 0x8000001e {
_, b, _, _ := cpuid(0x8000001e)
return int((b>>8)&0xff) + 1
}
return 2
}
}
Expand Down

0 comments on commit 27e993c

Please sign in to comment.