tsc(9) - NetBSD Manual Pages

Command: Section: Arch: Collection:  
TSC(9)               NetBSD/x86 Kernel Developer's Manual               TSC(9)


NAME
tsc -- Time Stamp Counter
SYNOPSIS
#include <x86/x86/tsc.h> uint64_t rdtsc(void); void tsc_tc_init(void); void tsc_sync_ap(struct cpu_info *ci); void tsc_sync_bp(struct cpu_info *ci); void tsc_sync_drift(int64_t drift);
DESCRIPTION
The time stamp counter (TSC) is a hardware counter found in all contempo- rary x86 processors. The counter is implemented as a 64-bit model-spe- cific register (MSR) that is incremented at every clock cycle. The RDTSC (``read time stamp counter'') register has been present since the origi- nal Pentium. Already because of the access method, TSC provides a low-overhead and high-resolution way to obtain CPU timing information. This traditional premise was violated when such factors as system sleep states, CPU ``hotplugging'', ``hibernation'', and CPU frequency scaling were intro- duced to the x86 lineage. This was however mainly a short abruption: in many new x86 CPUs the time stamp counter is again invariant with respect to the stability of the clock frequency. Care should be however taken in implementations that rely on this assumption.
FUNCTIONS
rdtsc() The rdtsc() function returns the value read from RDTSC. tsc_tc_init() The tsc_tc_init() function initializes the TSC as a timecounter(9). The function is called early in the boot process when the proces- sors attach. tsc_sync_bp(ci) The tsc_sync_bp() function synchronizes the counter for the boot processor (BP). The supplied ci must refer to the BP itself. The tsc interface takes internally care of such issues as out-of-order execution, where instructions are not necessarily performed in the order of execution, possibly causing a misleading cycle count. tsc_sync_ap(ci) The tsc_sync_ap() function synchronize the counter for the applica- tion processor ci. Interrupts must be off at machine-level when the function is called. It is necessary to call both tsc_sync_ap() and tsc_sync_bp() during the boot, but additional synchronization may be required also dur- ing runtime. As an example, the TSC needs to be synchronized for all processors when the system resumes from an acpi(4) sleep state. tsc_sync_drift(drift) Finally, the tsc_sync_drift() function records drift, measured in clock cycles. This is called when the APs attach.
SEE ALSO
gettimeofday(2), hpet(4), hz(9), timecounter(9), x86/rdmsr(9) NetBSD 10.99 February 17, 2017 NetBSD 10.99
Powered by man-cgi (2024-03-20). Maintained for NetBSD by Kimmo Suominen. Based on man-cgi by Panagiotis Christias.