Skip to content

Commit

Permalink
Support X86 without rdtscp
Browse files Browse the repository at this point in the history
  • Loading branch information
gritukan committed Jul 9, 2023
1 parent b178f1c commit 5fb129d
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions yt/yt/core/profiling/tscp-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,46 @@
#endif
#undef TSCP_INL_H_

#include <util/system/cpu_id.h>

namespace NYT::NProfiling {

////////////////////////////////////////////////////////////////////////////////

namespace {

////////////////////////////////////////////////////////////////////////////////

#if defined(__x86_64__)

const bool SupportsRdtscp = NX86::HaveRDTSCP();

#endif

////////////////////////////////////////////////////////////////////////////////

} // namespace

inline TTscp TTscp::Get()
{
#if defined(__x86_64__)
ui64 rax, rcx, rdx;
asm volatile ( "rdtscp\n" : "=a" (rax), "=c" (rcx), "=d" (rdx) : : );
ui64 t = (rdx << 32) + rax;
ui64 c = rcx;
ui64 t;
ui64 c;
if (SupportsRdtscp) {
ui64 rax, rcx, rdx;
asm volatile ( "rdtscp\n" : "=a" (rax), "=c" (rcx), "=d" (rdx) : : );
t = (rdx << 32) + rax;
c = rcx;
} else {
ui64 rax, rdx;
asm volatile ( "rdtsc\n" : "=a" (rax), "=d" (rdx) : : );
t = (rdx << 32) + rax;

// cpuId[1] >> 24 is an APIC id.
ui32 cpuId[4];
NX86::CpuId(1, 0, cpuId);
c = cpuId[1] >> 24;
}
#elif defined(__arm64__) || defined(__aarch64__)
ui64 c;
__asm__ volatile("mrs %x0, tpidrro_el0" : "=r"(c));
Expand Down

0 comments on commit 5fb129d

Please sign in to comment.