mirror of
https://github.com/wolfpld/tracy.git
synced 2025-03-20 07:40:02 +08:00
Merge pull request #597 from Keno/kf/noplrdtsc
Use patchable rdtsc sequence to avoid slowdowns under rr
This commit is contained in:
@@ -209,7 +209,22 @@ public:
|
||||
if( HardwareSupportsInvariantTSC() )
|
||||
{
|
||||
uint64_t rax, rdx;
|
||||
#ifdef TRACY_PATCHABLE_NOPSLEDS
|
||||
// Some external tooling (such as rr) wants to patch our rdtsc and replace it by a
|
||||
// branch to control the external input seen by a program. This kind of patching is
|
||||
// not generally possible depending on the surrounding code and can lead to significant
|
||||
// slowdowns if the compiler generated unlucky code and rr and tracy are used together.
|
||||
// To avoid this, use the rr-safe `nopl 0(%rax, %rax, 1); rdtsc` instruction sequence,
|
||||
// which rr promises will be patchable independent of the surrounding code.
|
||||
asm volatile (
|
||||
// This is nopl 0(%rax, %rax, 1), but assemblers are inconsistent about whether
|
||||
// they emit that as a 4 or 5 byte sequence and we need to be guaranteed to use
|
||||
// the 5 byte one.
|
||||
".byte 0x0f, 0x1f, 0x44, 0x00, 0x00\n\t"
|
||||
"rdtsc" : "=a" (rax), "=d" (rdx) );
|
||||
#else
|
||||
asm volatile ( "rdtsc" : "=a" (rax), "=d" (rdx) );
|
||||
#endif
|
||||
return (int64_t)(( rdx << 32 ) + rax);
|
||||
}
|
||||
# else
|
||||
|
||||
Reference in New Issue
Block a user