TC_INIT(9)
π TC_INIT(9) β timecounting subsystem (Kernel Developer's Manual) π
πΈ NAME πΈ
tc_init β timecounting subsystem
okay so bestie, this is the whole vibe: tc_init() is your little doorway into the timecounting subsystem, and we're gonna walk through it together. no cap. π«Ά
β¨ SYNOPSIS β¨
#include <sys/timetc.h>
void
tc_init(struct timecounter *tc);
π DESCRIPTION π
The timecounting subsystem is literally the main character that gives you a uniform interface to timekeeping hardware, measures the passage of time, and implements the kernel's software clocks (see microtime(9) for the details). slay. β°β¨
A hardware clock is suitable for counting time if it meets the following requirements β vibe check, fr fr:
- 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. Ifhz(9)exceeds one millisecond, the counter does not roll over in less than(2 / hz)seconds.
Hardware clocks are described with a timecounter structure β here's the exact fit, no edits:
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(u_int) β The mask of implemented bits. Used to discard unimplemented bits fromtc_get_timecount().tc_frequency(u_int64_t) β The counter's fixed frequency.tc_name(char *) β The counter's unique name. A NUL-terminated string.tc_quality(int) β 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(void *) β May point to anything the driver needs duringtc_get_timecount().tc_user(u_int) β If non-zero, a unique value identifying the userspace implementation oftc_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. that's it, that's the registration moment. π
π¦ CONTEXT π¦
tc_init() may only be called during autoconf. that's the rule, bestie β autoconf only. no calling it whenever. π
π 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. iconic behavior honestly. π
π AUTHORS π
Poul-Henning Kamp
okay that's the page, bestie β it's from Debian, dated April 2, 2023, and the footer says TC_INIT(9). byeee ππ«Ά
π¦ where this page comes from
- nixpkgs unstable: cvs-export
- Copyright (c) 2004 Alexander Yurchenko <grange@openbsd.org>
- Copyright (c) 2023 Scott Cheloha <cheloha@openbsd.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms