FreeBSD/Linux Kernel Cross Reference
sys/sys/timetc.h
1 /* $OpenBSD: timetc.h,v 1.13 2022/08/12 02:20:36 cheloha Exp $ */
2
3 /*
4 * Copyright (c) 2000 Poul-Henning Kamp <phk@FreeBSD.org>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 /*
20 * If we meet some day, and you think this stuff is worth it, you
21 * can buy me a beer in return. Poul-Henning Kamp
22 */
23
24 #ifndef _SYS_TIMETC_H_
25 #define _SYS_TIMETC_H_
26
27 #if !defined(_KERNEL) && !defined(_LIBC)
28 #error "no user-serviceable parts inside"
29 #endif
30
31 #include <machine/timetc.h>
32 #include <sys/queue.h>
33
34 /*-
35 * `struct timecounter' is the interface between the hardware which implements
36 * a timecounter and the MI code which uses this to keep track of time.
37 *
38 * A timecounter is a binary counter which has two properties:
39 * * it runs at a fixed, known frequency.
40 * * it has sufficient bits to not roll over in less than approximately
41 * max(2 msec, 2/HZ seconds). (The value 2 here is really 1 + delta,
42 * for some indeterminate value of delta.)
43 */
44
45 struct timecounter;
46 typedef u_int timecounter_get_t(struct timecounter *);
47 typedef void timecounter_pps_t(struct timecounter *);
48
49 /*
50 * Locks used to protect struct members in this file:
51 * I immutable after initialization
52 * T tc_lock
53 * W windup_mtx
54 */
55
56 struct timecounter {
57 timecounter_get_t *tc_get_timecount; /* [I] */
58 /*
59 * This function reads the counter. It is not required to
60 * mask any unimplemented bits out, as long as they are
61 * constant.
62 */
63 timecounter_pps_t *tc_poll_pps; /* [I] */
64 /*
65 * This function is optional. It will be called whenever the
66 * timecounter is rewound, and is intended to check for PPS
67 * events. Normal hardware does not need it but timecounters
68 * which latch PPS in hardware (like sys/pci/xrpu.c) do.
69 */
70 u_int tc_counter_mask; /* [I] */
71 /* This mask should mask off any unimplemented bits. */
72 u_int64_t tc_frequency; /* [I] */
73 /* Frequency of the counter in Hz. */
74 char *tc_name; /* [I] */
75 /* Name of the timecounter. */
76 int tc_quality; /* [I] */
77 /*
78 * Used to determine if this timecounter is better than
79 * another timecounter higher means better. Negative
80 * means "only use at explicit request".
81 */
82 void *tc_priv; /* [I] */
83 /* Pointer to the timecounter's private parts. */
84 int tc_user; /* [I] */
85 /* Expose this timecounter to userland. */
86 SLIST_ENTRY(timecounter) tc_next; /* [I] */
87 /* Pointer to the next timecounter. */
88 int64_t tc_freq_adj; /* [T,W] */
89 /* Current frequency adjustment. */
90 u_int64_t tc_precision; /* [I] */
91 /* Precision of the counter. Computed in tc_init(). */
92 };
93
94 struct timekeep {
95 /* set at initialization */
96 uint32_t tk_version; /* version number */
97
98 /* timehands members */
99 uint64_t tk_scale;
100 u_int tk_offset_count;
101 struct bintime tk_offset;
102 struct bintime tk_naptime;
103 struct bintime tk_boottime;
104 volatile u_int tk_generation;
105
106 /* timecounter members */
107 int tk_user;
108 u_int tk_counter_mask;
109 };
110 #define TK_VERSION 0
111
112 struct rwlock;
113 extern struct rwlock tc_lock;
114
115 extern struct timecounter *timecounter;
116
117 extern struct uvm_object *timekeep_object;
118 extern struct timekeep *timekeep;
119
120 u_int64_t tc_getfrequency(void);
121 u_int64_t tc_getprecision(void);
122 void tc_init(struct timecounter *tc);
123 void tc_reset_quality(struct timecounter *, int);
124 void tc_setclock(const struct timespec *ts);
125 void tc_setrealtimeclock(const struct timespec *ts);
126 void tc_ticktock(void);
127 void inittimecounter(void);
128 int sysctl_tc(int *, u_int, void *, size_t *, void *, size_t);
129 void tc_adjfreq(int64_t *, int64_t *);
130 void tc_adjtime(int64_t *, int64_t *);
131
132 #endif /* !_SYS_TIMETC_H_ */
Cache object: c72469e0619ba3252b45964ae550d246
|