Bug 19861 – core.cpuid reports the wrong number of threads

Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2019-05-11T14:36:39Z
Last change time
2020-05-17T16:33:19Z
Keywords
pull
Assigned to
No Owner
Creator
Francesco Mecca

Comments

Comment #0 by me — 2019-05-11T14:36:39Z
user~> lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 4 On-line CPU(s) list: 0-3 Thread(s) per core: 2 Core(s) per socket: 2 CPU family: 21 Model: 101 Model name: AMD A12-9700P RADEON R7, 10 COMPUTE CORES 4C+6G user~> cat cpus.d import core.cpuid; void main() { import std.stdio; writeln(threadsPerCPU(), " ", coresPerCPU()); } user~> ./cpus 1 4 This is happening also on AMD A6-6400K APU that has 2 cores and 2 threads and it reports 1 thread and 2 cores.
Comment #1 by greeenify — 2019-05-16T23:28:21Z
That's why people are using mir-cpuid these days :/
Comment #2 by ilyayaroshenko — 2019-05-19T03:20:40Z
You can try `dub --single report.d` from the mir-cpuid project [1] Does it work for your CPU? [1] https://github.com/libmir/mir-cpuid
Comment #3 by r.sagitario — 2019-05-25T10:14:15Z
I shortly tried it on an AMD Ryzen 8-core, and it failed, too (reported 16 cores, but 1 thread). Debugging it a bit showed that there is probably incomplete support for CPUID#8000_0008: https://www.amd.com/system/files/TechDocs/54945_PPR_Family_17h_Models_00h-0Fh.pdf or https://wiki.osdev.org/Detecting_CPU_Topology_(80x86)#AMD:_CPUID_eax.3D0x80000008 I didn't try mir-cpuid, but looking at the source code now, I don't see any use of that CPUID function, so it probably won't work, too.
Comment #4 by ilyayaroshenko — 2019-05-27T03:49:52Z
Rainer Schuetze, yes thanks. Will add AMD leaf 8 information. https://github.com/libmir/mir-cpuid/issues/40
Comment #5 by ilyayaroshenko — 2019-05-27T04:36:25Z
(In reply to Rainer Schuetze from comment #3) > I shortly tried it on an AMD Ryzen 8-core, and it failed, too (reported 16 > cores, but 1 thread). Debugging it a bit showed that there is probably > incomplete support for CPUID#8000_0008: > https://www.amd.com/system/files/TechDocs/54945_PPR_Family_17h_Models_00h- > 0Fh.pdf or > https://wiki.osdev.org/Detecting_CPU_Topology_(80x86)#AMD:_CPUID_eax. > 3D0x80000008 > > I didn't try mir-cpuid, but looking at the source code now, I don't see any > use of that CPUID function, so it probably won't work, too. CPUID#8000_0008 has been added. https://github.com/libmir/mir-cpuid/pull/41 Rainer Schuetze, could you please check if it works now.
Comment #6 by r.sagitario — 2019-05-28T06:21:37Z
I tried the latest version of mir-cpuid from github, it reports 16 cores and 16 threads for the 8-core Ryzen. That's no change from earlier versions, but at least slightly better than what core.cpuid does.
Comment #7 by ilyayaroshenko — 2019-05-28T10:54:13Z
(In reply to Rainer Schuetze from comment #6) > I tried the latest version of mir-cpuid from github, it reports 16 cores and > 16 threads for the 8-core Ryzen. That's no change from earlier versions, but > at least slightly better than what core.cpuid does. Thank you. I added another one fix that uses 1E extended leaf information to retrieve the number of threads per core. https://github.com/libmir/mir-cpuid/pull/42 Please check with recent the mir-cpuid master.
Comment #8 by dlang-bot — 2019-05-30T06:48:22Z
@rainers created dlang/druntime pull request #2620 "fix Issue 19861 - core.cpuid reports the wrong number of threads" fixing this issue: - fix Issue 19861 - core.cpuid reports the wrong number of threads do not use i7 detection on AMD processors use cpuid 0x8000_001E to detect the number of threads per core https://github.com/dlang/druntime/pull/2620
Comment #9 by dlang-bot — 2019-06-28T04:29:17Z
dlang/druntime pull request #2620 "fix Issue 19861 - core.cpuid reports the wrong number of threads" was merged into stable: - 0723a38a858aaaae83a9c5c0d43a0400571ef2a0 by Rainer Schuetze: fix Issue 19861 - core.cpuid reports the wrong number of threads do not use i7 detection on AMD processors use cpuid 0x8000_001E to detect the number of threads per core https://github.com/dlang/druntime/pull/2620
Comment #10 by dlang-bot — 2020-05-17T16:33:19Z
dlang/druntime pull request #3107 "[dmd-cxx] fix Issue 19861 - core.cpuid reports the wrong number of threads" was merged into dmd-cxx: - d989df32ae1645203ceb24ccfa62ddfd46f078d4 by Rainer Schuetze: fix Issue 19861 - core.cpuid reports the wrong number of threads do not use i7 detection on AMD processors use cpuid 0x8000_001E to detect the number of threads per core https://github.com/dlang/druntime/pull/3107