NAME
tc_init
—
timecounting subsystem
SYNOPSIS
#include
<sys/timetc.h>
void
tc_init
(struct
timecounter *tc);
DESCRIPTION
The timecounting subsystem implements a uniform interface to timekeeping hardware, measures the passage of time, and implements the kernel's software clocks (see microtime(9) for details).
A hardware clock is suitable for counting time if it meets the following requirements:
- It is a binary counter.
- It advances at a fixed, known frequency.
- Its count is synchronized between all CPUs on the system.
- It continues counting when it rolls over.
- If hz(9) is less than or equal to one millisecond, the counter does not roll over in less than two milliseconds. If hz(9) exceeds one millisecond, the counter does not roll over in less than (2 / hz) seconds.
Hardware clocks are described with a timecounter structure:
struct timecounter { u_int (*tc_get_timecount)(struct timecounter *); u_int tc_counter_mask; u_int64_t tc_frequency; char *tc_name; int tc_quality; void *tc_priv; u_int tc_user; };
- u_int
(*tc_get_timecount)
(struct timecounter *) - Reads the hardware clock and returns its count. Any unimplemented bits only need to be masked if they are not constant. If the counter is larger than 32 bits, this function must return a 32-bit subset. The subsystem requires an upward count; downward counts must be inverted before they are returned.
- tc_counter_mask
- The mask of implemented bits. Used to discard unimplemented bits from
tc_get_timecount
(). - tc_frequency
- The counter's fixed frequency.
- tc_name
- The counter's unique name. A
NUL
-terminated string. - tc_quality
- A relative quality metric used to compare counters. Higher values indicate a better counter. A negative value indicates that the counter is non-monotonic or otherwise deficient. The system will only use negative-quality counters if requested.
- tc_priv
- May point to anything the driver needs during
tc_get_timecount
(). - tc_user
- If non-zero, a unique value identifying the userspace implementation of
tc_get_timecount
().
To register a timecounter, a device driver
initializes the above-described fields of a
timecounter structure and calls
tc_init
()
with a pointer to that structure as argument.
CONTEXT
tc_init
() may only be called during
autoconf.
CODE REFERENCES
sys/kern/kern_tc.c
SEE ALSO
amdpm(4), gscpm(4), ichpcib(4), viapm(4), hz(9), microtime(9)
Poul-Henning Kamp, Timecounter: Efficient and precise timekeeping in SMP kernels, The FreeBSD Project, https://papers.freebsd.org/2002/phk-timecounters.files/timecounter.pdf, 2002.
HISTORY
The timecounting subsystem first appeared in FreeBSD 3.0. It was ported to OpenBSD 3.6.
AUTHORS
Poul-Henning Kamp