performance - Instruction to get the current time on x86 -
is there x86 instruction current time?
basically... replacement clock_get_time ... minimum overhead... don't care getting time in specific format... long it's format can use.
basically i'm doing work "detect how physical real life time" has gone by... , want able measure time possible!
i guess can imagine i'm doing profiling app... :)
i need aggressively efficient access hardware time. ideally... asm time... store somewhere... massage later format can process.
i'm not interested in _rdtsc measures number of cycles gone by. need know how physical time has executed... not cycles can vary due thermal fluctations or so..
for profiling, it's useful profile in terms of cpu clock cycles, rather wall-clock time. cpu dynamic clocking (turbo , power saving) makes annoying cpu ramped full speed before start of measurement period.
if still need wall-clock time after that:
recent x86 cpus have tsc runs @ fixed rate, regardless of cpu frequency adjustment power-saving. also, tsc doesn't stop when cpu halted. (i.e. no work do, ran hlt
instruction wait interrupt in low-power mode.)
it turned out efficient access useful time-source more useful have in hardware actual clock cycle counter, that's rdtsc
morphed into, few cpu generations after introduction. we're using hardware performance counters measuring clock cycles.
in linux, constant_tsc
, nonstop_tsc
in cpu features flags in /proc/cpuinfo
. idk if there cpuid
bits those. if no, use linux's code (if can use gpled code).
on cpu 2 key features, linux uses tsc clocksource, iirc.
the lowest overhead way current time in user-space work out conversion between rdtsc
ticks , real time. while profiling, might store 64bit tsc snapshots, , convert real-time later. (so can handle tsc wraparound then). rdtsc
takes 24 cycles (agner fog's instruction table, intel haswell). think overhead of system call order of magnitude higher that. (the kernel have rdtsc
in there somewhere anyway).
agner fog has documented profiling / timing methods, , has example code. haven't looked recently, might have useful stuff application.
Comments
Post a Comment