FreeBSD Timecounters
The FreeBSD kernel has multiple time counters as base for the calculation of the system time. FreeBSD chooses a certain counter when starting the system. In certain cases - when, for example, the notification "TIME_ERROR: 0x41: Clock Unsynchronized" appears during the start of ntpd, an alternative time counter can be set via sysctl.[1] This article informs about different time counters.
Time information in FreeBSD
The FreeBSD kernel uses multiple kinds of time referring devices:[2]
- Real time clocks: These are responsible for tracking time in the real world, mostly when the system fails.
- Time counters: are responsible for keeping track of time when the system is running.
- Event timer: are responsible for generating interrupts at a specific time or periodically in order to execute various time-based events.
Time counters
Nowadays, the time stamp counter, ACPI-timer, (Advanced Configuration and Power Interface, ACPI) and also often the High Precision Event Timer (HPET) are integrated in personal computers. These hardware counters are initialized to 0 during the system start and are incremented with the period of their respective oscillators. This interface is called Timecounter under FreeBSD and clocksource under Linux, and is internal to the kernel.[3]
TSC
The time stamp counter TSC (an implemented Intel P6-family) is a 64-Bit-counter that is set to 0 after a RESET of the processor. The counter increases after a RESET, when the processor is stopped by the HLT-processor or the STPCLK#-Pin.[4][5]
Processor families increment the time stamp counter differently:
- for Pentium M-processors (Family [06], Model [09, 0D]); for Pentium 4-processors, Intel Xeon-processors(Family [0F], models[00, 01 or 02]); and for processors of the p6-family: the time stamp counter increases with every internal processor clock cycle. The internal processor clock cycle is determined by the current core-clock to bus-clock ratio. Transitions in the Intel SpeedStep-technology can also have an influence on the processor clock.
- for Pentium 4-processors, Intel Xeon-processors (Family [0F], Model [03] and higher); for Intel Core Solo and Intel Core Duo-processors(Family [06H], Model [0E]); for the Intel Xeon-processors of the 5100 series and Intel Core 2 Duo-processors (Family [06], Model [0F]); for Intel Core 2 and Intel Xeon-processors(Family 06], DisplayModel [17]); for Intel Atom-processors(Family [06], DisplayModel [1C]): the time stamp counter increments with a constant rate. This rate can be set by the maximum core clock to bus clock ratio of the processor or by the maximum resolved frequency at which the processor is booted up. The maximum resolved frequency can deviate from the basis frequency of the processor.
- Constant TSC behavior ensures that the duration of each clock tick is consistent and supports the use of the TSC as a wall clock timer, even when the processor core changes frequency.
i8254
This is the time counter of the computer's hardware clock (Real-Time Clock, RTC).
ACPI-safe
A time counter that is based on ACPI.
Example: LES compact 4L
The following output is taken from a LES compact 4L (as an example):
root@fw-home:~ # dmesg | grep Timecounter Timecounter "TSC" frequency 1600052360 Hz quality 1000 Timecounter "i8254" frequency 1193182 Hz quality 0 Timecounter "ACPI-safe" frequency 3579545 Hz quality 850 Timecounters tick every 1.000 msec
| TSC | i8254 | ACPI-safe | |
|---|---|---|---|
| clock frequency | CPU clock frequency
(1,6 GHz in this example) |
1,19 MHz | 3,57 MHz |
| quality (in this example) | 1000 | 0 | 850 |
root@fw-home:~ # sysctl kern.timecounter kern.timecounter.tsc_shift: 1 kern.timecounter.smp_tsc_adjust: 0 kern.timecounter.smp_tsc: 1 kern.timecounter.invariant_tsc: 1 kern.timecounter.fast_gettime: 1 kern.timecounter.tick: 1 kern.timecounter.choice: ACPI-safe(850) i8254(0) TSC(1000) dummy(-1000000) kern.timecounter.hardware: TSC kern.timecounter.alloweddeviation: 5 kern.timecounter.timehands_count: 2 kern.timecounter.stepwarnings: 0 kern.timecounter.tc.ACPI-safe.quality: 850 kern.timecounter.tc.ACPI-safe.frequency: 3579545 kern.timecounter.tc.ACPI-safe.counter: 3332884 kern.timecounter.tc.ACPI-safe.mask: 16777215 kern.timecounter.tc.i8254.quality: 0 kern.timecounter.tc.i8254.frequency: 1193182 kern.timecounter.tc.i8254.counter: 41774 kern.timecounter.tc.i8254.mask: 65535 kern.timecounter.tc.TSC.quality: 1000 kern.timecounter.tc.TSC.frequency: 1600052360 kern.timecounter.tc.TSC.counter: 2006715792 kern.timecounter.tc.TSC.mask: 4294967295
More information
- (SOLVED) ntpd: kernel reports TIME_ERROR: 0x41: Clock Unsynchronized (forum.opnsense.org, 14.08.2020)
- H2 Time Clock Issues (11.07.2019)
- Timecounter quick question regarding ACPI-safe and ACPI-fast (forums.freebsd.org, 16.05.2012)
- Troubleshooting Clock Issues - Adjust Timecounter Hardware Setting (docs.netgate.com/pfsense/en/latest)
References
- ↑ Why does the clock on my computer keep incorrect time? (www.freebsd.org/doc/faq)
- ↑ TIMECOUNTERS(4) Manpage (www.freebsd.org)
- ↑ Counter Availability and Characteristics for Feed-forward Based Synchronization (ISPCS 2009 International IEEE Symposium on Precision Clock, Synchronization for Measurement, Control and Communication, Brescia, Italy, October 12-16, 2009)
- ↑ Intel 64 and IA-32 Architectures Software Developer's Manual Volume 3A, Chapter 17.17 TIME-STAMP COUNTER (software.intel.com)
- ↑ Time Stamp Counter (en.wikipedia.org)
|
Author: Werner Fischer Werner Fischer, working in the Knowledge Transfer team at Thomas-Krenn, completed his studies of Computer and Media Security at FH Hagenberg in Austria. He is a regular speaker at many conferences like LinuxTag, OSMC, OSDC, LinuxCon, and author for various IT magazines. In his spare time he enjoys playing the piano and training for a good result at the annual Linz marathon relay.
|
|
Translator: Alina Ranzinger Alina has been working at Thomas-Krenn.AG since 2024. After her training as multilingual business assistant, she got her job as assistant of the Product Management and is responsible for the translation of texts and for the organisation of the department.
|


