NAME
tc_init
—
machine-independent binary
timescale
SYNOPSIS
#include
<sys/timetc.h>
void
tc_init
(struct
timecounter *tc);
DESCRIPTION
The timecounter interface is a machine-independent implementation of a binary timescale using whatever hardware support is at hand for tracking time.
A timecounter is a binary counter which has two properties:
- it runs at a fixed, known frequency
- it has sufficient bits to not roll over in less than approximately max(2 msec, 2/HZ seconds) (the value 2 here is really 1 + delta, for some indeterminate value of delta)
The interface between the hardware which implements a timecounter and the machine-independent code which uses this to keep track of time is a timecounter structure:
struct timecounter { timecounter_get_t *tc_get_timecount; timecounter_pps_t *tc_poll_pps; u_int tc_counter_mask; u_int64_t tc_frequency; char *tc_name; int tc_quality; void *tc_priv; struct timecounter *tc_next; }
The fields of the timecounter structure are described below.
- u_int
(*tc_get_timecount)
(struct timecounter *) - This function reads the counter. It is not required to mask any unimplemented bits out, as long as they are constant.
- void
(*tc_poll_pps)
(struct timecounter *) - This function is optional and can be set to NULL. It will be called whenever the timecounter is rewound, and is intended to check for PPS events. Normal hardware does not need it but timecounters which latch PPS in hardware do.
- tc_counter_mask
- This mask should mask off any unimplemented bits.
- tc_frequency
- Frequency of the counter in Hz.
- tc_name
- Name of the timecounter. Can be any null-terminated string.
- tc_quality
- Used to determine if this timecounter is better than another timecounter - higher means better. Negative means ``only use at explicit request''.
- tc_priv
- Pointer to the timecounter's private parts.
- tc_next
- For internal use.
To register a new timecounter, the hardware device
driver should fill a timecounter structure with
appropriate values and call the
tc_init
()
function, giving a pointer to the structure as a tc
parameter.
CODE REFERENCES
The timecounter framework is implemented in the file sys/kern/kern_tc.c.
SEE ALSO
amdpm(4), elansc(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, http://phk.freebsd.dk/pubs/timecounter.pdf.
HISTORY
The timecounter interface first appeared in OpenBSD 3.6.