Bug 20118 – rt/trace: rdtsc is unordered without preceding memory barrier

Status
NEW
Severity
normal
Priority
P3
Component
druntime
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2019-08-10T18:55:22Z
Last change time
2024-12-07T13:39:33Z
Assigned to
No Owner
Creator
Hiroki Noda
Moved to GitHub: dmd#17181 →

Comments

Comment #0 by kubo39 — 2019-08-10T18:55:22Z
RDTSC is not ordered on Intel and AMD CPUs without preceding memory barrier, and worse, the results can be non-monotonic if compared on different processors. The intel SDM says lfence;rdtsc causes all previous instrusctions to complete before the tsc read, and AMD APM says to use mfence;rdtsc to do same thing. This is what GNU/Linux kernel does on its rdtsc_ordered function. * https://github.com/torvalds/linux/blob/03b9730b769fc4d87e40f6104f4c5b2e43889f19/arch/x86/include/asm/msr.h#L130-L154
Comment #1 by kubo39 — 2019-08-10T19:01:23Z
I tried to fix on x86_64 only. https://github.com/dlang/druntime/pull/2727
Comment #2 by robert.schadek — 2024-12-07T13:39:33Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17181 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB