xref: /freebsd-src/sys/sys/timeffc.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1b0fdc837SLawrence Stewart /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3c4e20cadSPedro F. Giffuni  *
4b0fdc837SLawrence Stewart  * Copyright (c) 2011 The University of Melbourne
5b0fdc837SLawrence Stewart  * All rights reserved.
6b0fdc837SLawrence Stewart  *
7b0fdc837SLawrence Stewart  * This software was developed by Julien Ridoux at the University of Melbourne
8b0fdc837SLawrence Stewart  * under sponsorship from the FreeBSD Foundation.
9b0fdc837SLawrence Stewart  *
10b0fdc837SLawrence Stewart  * Redistribution and use in source and binary forms, with or without
11b0fdc837SLawrence Stewart  * modification, are permitted provided that the following conditions
12b0fdc837SLawrence Stewart  * are met:
13b0fdc837SLawrence Stewart  * 1. Redistributions of source code must retain the above copyright
14b0fdc837SLawrence Stewart  *    notice, this list of conditions and the following disclaimer.
15b0fdc837SLawrence Stewart  * 2. Redistributions in binary form must reproduce the above copyright
16b0fdc837SLawrence Stewart  *    notice, this list of conditions and the following disclaimer in the
17b0fdc837SLawrence Stewart  *    documentation and/or other materials provided with the distribution.
18b0fdc837SLawrence Stewart  *
19b0fdc837SLawrence Stewart  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20b0fdc837SLawrence Stewart  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21b0fdc837SLawrence Stewart  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22b0fdc837SLawrence Stewart  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23b0fdc837SLawrence Stewart  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24b0fdc837SLawrence Stewart  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25b0fdc837SLawrence Stewart  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26b0fdc837SLawrence Stewart  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27b0fdc837SLawrence Stewart  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28b0fdc837SLawrence Stewart  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29b0fdc837SLawrence Stewart  * SUCH DAMAGE.
30b0fdc837SLawrence Stewart  */
31b0fdc837SLawrence Stewart 
32b0fdc837SLawrence Stewart #ifndef _SYS_TIMEFF_H_
33b0fdc837SLawrence Stewart #define _SYS_TIMEFF_H_
34b0fdc837SLawrence Stewart 
35b0fdc837SLawrence Stewart #include <sys/_ffcounter.h>
36b0fdc837SLawrence Stewart 
37b0fdc837SLawrence Stewart /*
38b0fdc837SLawrence Stewart  * Feed-forward clock estimate
39b0fdc837SLawrence Stewart  * Holds time mark as a ffcounter and conversion to bintime based on current
40b0fdc837SLawrence Stewart  * timecounter period and offset estimate passed by the synchronization daemon.
41b0fdc837SLawrence Stewart  * Provides time of last daemon update, clock status and bound on error.
42b0fdc837SLawrence Stewart  */
43b0fdc837SLawrence Stewart struct ffclock_estimate {
44b0fdc837SLawrence Stewart 	struct bintime	update_time;	/* Time of last estimates update. */
45b0fdc837SLawrence Stewart 	ffcounter	update_ffcount;	/* Counter value at last update. */
46b0fdc837SLawrence Stewart 	ffcounter	leapsec_next;	/* Counter value of next leap second. */
47b0fdc837SLawrence Stewart 	uint64_t	period;		/* Estimate of counter period. */
48b0fdc837SLawrence Stewart 	uint32_t	errb_abs;	/* Bound on absolute clock error [ns]. */
49b0fdc837SLawrence Stewart 	uint32_t	errb_rate;	/* Bound on counter rate error [ps/s]. */
50b0fdc837SLawrence Stewart 	uint32_t	status;		/* Clock status. */
51b0fdc837SLawrence Stewart 	int16_t		leapsec_total;	/* All leap seconds seen so far. */
52b0fdc837SLawrence Stewart 	int8_t		leapsec;	/* Next leap second (in {-1,0,1}). */
53b0fdc837SLawrence Stewart };
54b0fdc837SLawrence Stewart 
55b0fdc837SLawrence Stewart #if __BSD_VISIBLE
56b0fdc837SLawrence Stewart #ifdef _KERNEL
57b0fdc837SLawrence Stewart 
5866dcfed3SLawrence Stewart /* Define the kern.sysclock sysctl tree. */
5966dcfed3SLawrence Stewart SYSCTL_DECL(_kern_sysclock);
6066dcfed3SLawrence Stewart 
6166dcfed3SLawrence Stewart /* Define the kern.sysclock.ffclock sysctl tree. */
6266dcfed3SLawrence Stewart SYSCTL_DECL(_kern_sysclock_ffclock);
6366dcfed3SLawrence Stewart 
64b0fdc837SLawrence Stewart /*
659bce0f05SLawrence Stewart  * Index into the sysclocks array for obtaining the ASCII name of a particular
669bce0f05SLawrence Stewart  * sysclock.
679bce0f05SLawrence Stewart  */
689bce0f05SLawrence Stewart #define	SYSCLOCK_FBCK	0
699bce0f05SLawrence Stewart #define	SYSCLOCK_FFWD	1
706f83fc51SLawrence Stewart extern int sysclock_active;
719bce0f05SLawrence Stewart 
729bce0f05SLawrence Stewart /*
73b0fdc837SLawrence Stewart  * Parameters of counter characterisation required by feed-forward algorithms.
74b0fdc837SLawrence Stewart  */
75b0fdc837SLawrence Stewart #define	FFCLOCK_SKM_SCALE	1024
76b0fdc837SLawrence Stewart 
77b0fdc837SLawrence Stewart /*
78b0fdc837SLawrence Stewart  * Feed-forward clock status
79b0fdc837SLawrence Stewart  */
80b0fdc837SLawrence Stewart #define	FFCLOCK_STA_UNSYNC	1
81b0fdc837SLawrence Stewart #define	FFCLOCK_STA_WARMUP	2
82b0fdc837SLawrence Stewart 
83b0fdc837SLawrence Stewart /*
846cedd609SLawrence Stewart  * Flags for use by sysclock_snap2bintime() and various ffclock_ functions to
856cedd609SLawrence Stewart  * control how the timecounter hardware is read and how the hardware snapshot is
866cedd609SLawrence Stewart  * converted into absolute time.
876cedd609SLawrence Stewart  * {FB|FF}CLOCK_FAST:	Do not read the hardware counter, instead using the
886cedd609SLawrence Stewart  *			value at last tick. The time returned has a resolution
896cedd609SLawrence Stewart  *			of the kernel tick timer (1/hz [s]).
906cedd609SLawrence Stewart  * FFCLOCK_LERP:	Linear interpolation of ffclock time to guarantee
916cedd609SLawrence Stewart  *			monotonic time.
926cedd609SLawrence Stewart  * FFCLOCK_LEAPSEC:	Include leap seconds.
936cedd609SLawrence Stewart  * {FB|FF}CLOCK_UPTIME:	Time stamp should be relative to system boot, not epoch.
94b0fdc837SLawrence Stewart  */
956cedd609SLawrence Stewart #define	FFCLOCK_FAST		0x00000001
966cedd609SLawrence Stewart #define	FFCLOCK_LERP		0x00000002
976cedd609SLawrence Stewart #define	FFCLOCK_LEAPSEC		0x00000004
986cedd609SLawrence Stewart #define	FFCLOCK_UPTIME		0x00000008
996cedd609SLawrence Stewart #define	FFCLOCK_MASK		0x0000ffff
1006cedd609SLawrence Stewart 
1016cedd609SLawrence Stewart #define	FBCLOCK_FAST		0x00010000 /* Currently unused. */
1026cedd609SLawrence Stewart #define	FBCLOCK_UPTIME		0x00020000
1036cedd609SLawrence Stewart #define	FBCLOCK_MASK		0xffff0000
1046cedd609SLawrence Stewart 
1056cedd609SLawrence Stewart /*
1066cedd609SLawrence Stewart  * Feedback clock specific info structure. The feedback clock's estimation of
1076cedd609SLawrence Stewart  * clock error is an absolute figure determined by the NTP algorithm. The status
1086cedd609SLawrence Stewart  * is determined by the userland daemon.
1096cedd609SLawrence Stewart  */
1106cedd609SLawrence Stewart struct fbclock_info {
1116cedd609SLawrence Stewart 	struct bintime		error;
1126cedd609SLawrence Stewart 	struct bintime		tick_time;
1136cedd609SLawrence Stewart 	uint64_t		th_scale;
1146cedd609SLawrence Stewart 	int			status;
1156cedd609SLawrence Stewart };
1166cedd609SLawrence Stewart 
1176cedd609SLawrence Stewart /*
1186cedd609SLawrence Stewart  * Feed-forward clock specific info structure. The feed-forward clock's
1196cedd609SLawrence Stewart  * estimation of clock error is an upper bound, which although potentially
1206cedd609SLawrence Stewart  * looser than the feedback clock equivalent, is much more reliable. The status
1216cedd609SLawrence Stewart  * is determined by the userland daemon.
1226cedd609SLawrence Stewart  */
1236cedd609SLawrence Stewart struct ffclock_info {
1246cedd609SLawrence Stewart 	struct bintime		error;
1256cedd609SLawrence Stewart 	struct bintime		tick_time;
1266cedd609SLawrence Stewart 	struct bintime		tick_time_lerp;
1276cedd609SLawrence Stewart 	uint64_t		period;
1286cedd609SLawrence Stewart 	uint64_t		period_lerp;
1296cedd609SLawrence Stewart 	int			leapsec_adjustment;
1306cedd609SLawrence Stewart 	int			status;
1316cedd609SLawrence Stewart };
1326cedd609SLawrence Stewart 
1336cedd609SLawrence Stewart /*
1346cedd609SLawrence Stewart  * Snapshot of system clocks and related information. Holds time read from each
1356cedd609SLawrence Stewart  * clock based on a single read of the active hardware timecounter, as well as
1366cedd609SLawrence Stewart  * respective clock information such as error estimates and the ffcounter value
1376cedd609SLawrence Stewart  * at the time of the read.
1386cedd609SLawrence Stewart  */
1396cedd609SLawrence Stewart struct sysclock_snap {
1406cedd609SLawrence Stewart 	struct fbclock_info	fb_info;
1416cedd609SLawrence Stewart 	struct ffclock_info	ff_info;
1426cedd609SLawrence Stewart 	ffcounter		ffcount;
1436cedd609SLawrence Stewart 	unsigned int		delta;
1446cedd609SLawrence Stewart 	int			sysclock_active;
1456cedd609SLawrence Stewart };
1466cedd609SLawrence Stewart 
1476cedd609SLawrence Stewart /* Take a snapshot of the system clocks and related information. */
1486cedd609SLawrence Stewart void sysclock_getsnapshot(struct sysclock_snap *clock_snap, int fast);
1496cedd609SLawrence Stewart 
1506cedd609SLawrence Stewart /* Convert a timestamp from the selected system clock into bintime. */
1516cedd609SLawrence Stewart int sysclock_snap2bintime(struct sysclock_snap *cs, struct bintime *bt,
1526cedd609SLawrence Stewart     int whichclock, uint32_t flags);
153b0fdc837SLawrence Stewart 
154b0fdc837SLawrence Stewart /* Resets feed-forward clock from RTC */
155b0fdc837SLawrence Stewart void ffclock_reset_clock(struct timespec *ts);
156b0fdc837SLawrence Stewart 
157b0fdc837SLawrence Stewart /*
158b0fdc837SLawrence Stewart  * Return the current value of the feed-forward clock counter. Essential to
159b0fdc837SLawrence Stewart  * measure time interval in counter units. If a fast timecounter is used by the
160b0fdc837SLawrence Stewart  * system, may also allow fast but accurate timestamping.
161b0fdc837SLawrence Stewart  */
162b0fdc837SLawrence Stewart void ffclock_read_counter(ffcounter *ffcount);
163b0fdc837SLawrence Stewart 
164b0fdc837SLawrence Stewart /*
165b0fdc837SLawrence Stewart  * Retrieve feed-forward counter value and time of last kernel tick. This
166b0fdc837SLawrence Stewart  * accepts the FFCLOCK_LERP flag.
167b0fdc837SLawrence Stewart  */
168b0fdc837SLawrence Stewart void ffclock_last_tick(ffcounter *ffcount, struct bintime *bt, uint32_t flags);
169b0fdc837SLawrence Stewart 
170b0fdc837SLawrence Stewart /*
171b0fdc837SLawrence Stewart  * Low level routines to convert a counter timestamp into absolute time and a
172b0fdc837SLawrence Stewart  * counter timestamp interval into an interval in seconds. The absolute time
173b0fdc837SLawrence Stewart  * conversion accepts the FFCLOCK_LERP flag.
174b0fdc837SLawrence Stewart  */
175b0fdc837SLawrence Stewart void ffclock_convert_abs(ffcounter ffcount, struct bintime *bt, uint32_t flags);
176b0fdc837SLawrence Stewart void ffclock_convert_diff(ffcounter ffdelta, struct bintime *bt);
177b0fdc837SLawrence Stewart 
178f464c5ccSLawrence Stewart /*
179f464c5ccSLawrence Stewart  * Feed-forward clock routines.
180f464c5ccSLawrence Stewart  *
181f464c5ccSLawrence Stewart  * These functions rely on the timecounters and ffclock_estimates stored in
182f464c5ccSLawrence Stewart  * fftimehands. Note that the error_bound parameter is not the error of the
183f464c5ccSLawrence Stewart  * clock but an upper bound on the error of the absolute time or time interval
184f464c5ccSLawrence Stewart  * returned.
185f464c5ccSLawrence Stewart  *
186f464c5ccSLawrence Stewart  * ffclock_abstime(): retrieves current time as counter value and convert this
187f464c5ccSLawrence Stewart  *     timestamp in seconds. The value (in seconds) of the converted timestamp
188f464c5ccSLawrence Stewart  *     depends on the flags passed: for a given counter value, different
189f464c5ccSLawrence Stewart  *     conversions are possible. Different clock models can be selected by
190f464c5ccSLawrence Stewart  *     combining flags (for example (FFCLOCK_LERP|FFCLOCK_UPTIME) produces
191f464c5ccSLawrence Stewart  *     linearly interpolated uptime).
192f464c5ccSLawrence Stewart  * ffclock_difftime(): computes a time interval in seconds based on an interval
193f464c5ccSLawrence Stewart  *     measured in ffcounter units. This should be the preferred way to measure
194f464c5ccSLawrence Stewart  *     small time intervals very accurately.
195f464c5ccSLawrence Stewart  */
196f464c5ccSLawrence Stewart void ffclock_abstime(ffcounter *ffcount, struct bintime *bt,
197f464c5ccSLawrence Stewart     struct bintime *error_bound, uint32_t flags);
198f464c5ccSLawrence Stewart void ffclock_difftime(ffcounter ffdelta, struct bintime *bt,
199f464c5ccSLawrence Stewart     struct bintime *error_bound);
200f464c5ccSLawrence Stewart 
2019bce0f05SLawrence Stewart /*
2029bce0f05SLawrence Stewart  * Wrapper routines to return current absolute time using the feed-forward
2039bce0f05SLawrence Stewart  * clock. These functions are named after those defined in <sys/time.h>, which
2049bce0f05SLawrence Stewart  * contains a description of the original ones.
2059bce0f05SLawrence Stewart  */
2069bce0f05SLawrence Stewart void ffclock_bintime(struct bintime *bt);
2079bce0f05SLawrence Stewart void ffclock_nanotime(struct timespec *tsp);
2089bce0f05SLawrence Stewart void ffclock_microtime(struct timeval *tvp);
2099bce0f05SLawrence Stewart 
2109bce0f05SLawrence Stewart void ffclock_getbintime(struct bintime *bt);
2119bce0f05SLawrence Stewart void ffclock_getnanotime(struct timespec *tsp);
2129bce0f05SLawrence Stewart void ffclock_getmicrotime(struct timeval *tvp);
2139bce0f05SLawrence Stewart 
2149bce0f05SLawrence Stewart void ffclock_binuptime(struct bintime *bt);
2159bce0f05SLawrence Stewart void ffclock_nanouptime(struct timespec *tsp);
2169bce0f05SLawrence Stewart void ffclock_microuptime(struct timeval *tvp);
2179bce0f05SLawrence Stewart 
2189bce0f05SLawrence Stewart void ffclock_getbinuptime(struct bintime *bt);
2199bce0f05SLawrence Stewart void ffclock_getnanouptime(struct timespec *tsp);
2209bce0f05SLawrence Stewart void ffclock_getmicrouptime(struct timeval *tvp);
2219bce0f05SLawrence Stewart 
2229bce0f05SLawrence Stewart /*
2239bce0f05SLawrence Stewart  * Wrapper routines to convert a time interval specified in ffcounter units into
2249bce0f05SLawrence Stewart  * seconds using the current feed-forward clock estimates.
2259bce0f05SLawrence Stewart  */
2269bce0f05SLawrence Stewart void ffclock_bindifftime(ffcounter ffdelta, struct bintime *bt);
2279bce0f05SLawrence Stewart void ffclock_nanodifftime(ffcounter ffdelta, struct timespec *tsp);
2289bce0f05SLawrence Stewart void ffclock_microdifftime(ffcounter ffdelta, struct timeval *tvp);
2299bce0f05SLawrence Stewart 
230e977bac3SLawrence Stewart /*
231e977bac3SLawrence Stewart  * When FFCLOCK is enabled in the kernel, [get]{bin,nano,micro}[up]time() become
232e977bac3SLawrence Stewart  * wrappers around equivalent feedback or feed-forward functions. Provide access
233e977bac3SLawrence Stewart  * outside of kern_tc.c to the feedback clock equivalent functions for
234e977bac3SLawrence Stewart  * specialised use i.e. these are not for general consumption.
235e977bac3SLawrence Stewart  */
236e977bac3SLawrence Stewart void fbclock_bintime(struct bintime *bt);
237e977bac3SLawrence Stewart void fbclock_nanotime(struct timespec *tsp);
238e977bac3SLawrence Stewart void fbclock_microtime(struct timeval *tvp);
239e977bac3SLawrence Stewart 
240e977bac3SLawrence Stewart void fbclock_getbintime(struct bintime *bt);
241e977bac3SLawrence Stewart void fbclock_getnanotime(struct timespec *tsp);
242e977bac3SLawrence Stewart void fbclock_getmicrotime(struct timeval *tvp);
243e977bac3SLawrence Stewart 
244e977bac3SLawrence Stewart void fbclock_binuptime(struct bintime *bt);
245e977bac3SLawrence Stewart void fbclock_nanouptime(struct timespec *tsp);
246e977bac3SLawrence Stewart void fbclock_microuptime(struct timeval *tvp);
247e977bac3SLawrence Stewart 
248e977bac3SLawrence Stewart void fbclock_getbinuptime(struct bintime *bt);
249e977bac3SLawrence Stewart void fbclock_getnanouptime(struct timespec *tsp);
250e977bac3SLawrence Stewart void fbclock_getmicrouptime(struct timeval *tvp);
251e977bac3SLawrence Stewart 
25217c43cd8SLawrence Stewart /*
25317c43cd8SLawrence Stewart  * Public system clock wrapper API which allows consumers to select which clock
25417c43cd8SLawrence Stewart  * to obtain time from, independent of the current default system clock. These
25517c43cd8SLawrence Stewart  * wrappers should be used instead of directly calling the underlying fbclock_
25617c43cd8SLawrence Stewart  * or ffclock_ functions.
25717c43cd8SLawrence Stewart  */
25817c43cd8SLawrence Stewart static inline void
bintime_fromclock(struct bintime * bt,int whichclock)25917c43cd8SLawrence Stewart bintime_fromclock(struct bintime *bt, int whichclock)
26017c43cd8SLawrence Stewart {
26117c43cd8SLawrence Stewart 
26217c43cd8SLawrence Stewart 	if (whichclock == SYSCLOCK_FFWD)
26317c43cd8SLawrence Stewart 		ffclock_bintime(bt);
26417c43cd8SLawrence Stewart 	else
26517c43cd8SLawrence Stewart 		fbclock_bintime(bt);
26617c43cd8SLawrence Stewart }
26717c43cd8SLawrence Stewart 
26817c43cd8SLawrence Stewart static inline void
nanotime_fromclock(struct timespec * tsp,int whichclock)26917c43cd8SLawrence Stewart nanotime_fromclock(struct timespec *tsp, int whichclock)
27017c43cd8SLawrence Stewart {
27117c43cd8SLawrence Stewart 
27217c43cd8SLawrence Stewart 	if (whichclock == SYSCLOCK_FFWD)
27317c43cd8SLawrence Stewart 		ffclock_nanotime(tsp);
27417c43cd8SLawrence Stewart 	else
27517c43cd8SLawrence Stewart 		fbclock_nanotime(tsp);
27617c43cd8SLawrence Stewart }
27717c43cd8SLawrence Stewart 
27817c43cd8SLawrence Stewart static inline void
microtime_fromclock(struct timeval * tvp,int whichclock)27917c43cd8SLawrence Stewart microtime_fromclock(struct timeval *tvp, int whichclock)
28017c43cd8SLawrence Stewart {
28117c43cd8SLawrence Stewart 
28217c43cd8SLawrence Stewart 	if (whichclock == SYSCLOCK_FFWD)
28317c43cd8SLawrence Stewart 		ffclock_microtime(tvp);
28417c43cd8SLawrence Stewart 	else
28517c43cd8SLawrence Stewart 		fbclock_microtime(tvp);
28617c43cd8SLawrence Stewart }
28717c43cd8SLawrence Stewart 
28817c43cd8SLawrence Stewart static inline void
getbintime_fromclock(struct bintime * bt,int whichclock)28917c43cd8SLawrence Stewart getbintime_fromclock(struct bintime *bt, int whichclock)
29017c43cd8SLawrence Stewart {
29117c43cd8SLawrence Stewart 
29217c43cd8SLawrence Stewart 	if (whichclock == SYSCLOCK_FFWD)
29317c43cd8SLawrence Stewart 		ffclock_getbintime(bt);
29417c43cd8SLawrence Stewart 	else
29517c43cd8SLawrence Stewart 		fbclock_getbintime(bt);
29617c43cd8SLawrence Stewart }
29717c43cd8SLawrence Stewart 
29817c43cd8SLawrence Stewart static inline void
getnanotime_fromclock(struct timespec * tsp,int whichclock)29917c43cd8SLawrence Stewart getnanotime_fromclock(struct timespec *tsp, int whichclock)
30017c43cd8SLawrence Stewart {
30117c43cd8SLawrence Stewart 
30217c43cd8SLawrence Stewart 	if (whichclock == SYSCLOCK_FFWD)
30317c43cd8SLawrence Stewart 		ffclock_getnanotime(tsp);
30417c43cd8SLawrence Stewart 	else
30517c43cd8SLawrence Stewart 		fbclock_getnanotime(tsp);
30617c43cd8SLawrence Stewart }
30717c43cd8SLawrence Stewart 
30817c43cd8SLawrence Stewart static inline void
getmicrotime_fromclock(struct timeval * tvp,int whichclock)30917c43cd8SLawrence Stewart getmicrotime_fromclock(struct timeval *tvp, int whichclock)
31017c43cd8SLawrence Stewart {
31117c43cd8SLawrence Stewart 
31217c43cd8SLawrence Stewart 	if (whichclock == SYSCLOCK_FFWD)
31317c43cd8SLawrence Stewart 		ffclock_getmicrotime(tvp);
31417c43cd8SLawrence Stewart 	else
31517c43cd8SLawrence Stewart 		fbclock_getmicrotime(tvp);
31617c43cd8SLawrence Stewart }
31717c43cd8SLawrence Stewart 
31817c43cd8SLawrence Stewart static inline void
binuptime_fromclock(struct bintime * bt,int whichclock)31917c43cd8SLawrence Stewart binuptime_fromclock(struct bintime *bt, int whichclock)
32017c43cd8SLawrence Stewart {
32117c43cd8SLawrence Stewart 
32217c43cd8SLawrence Stewart 	if (whichclock == SYSCLOCK_FFWD)
32317c43cd8SLawrence Stewart 		ffclock_binuptime(bt);
32417c43cd8SLawrence Stewart 	else
32517c43cd8SLawrence Stewart 		fbclock_binuptime(bt);
32617c43cd8SLawrence Stewart }
32717c43cd8SLawrence Stewart 
32817c43cd8SLawrence Stewart static inline void
nanouptime_fromclock(struct timespec * tsp,int whichclock)32917c43cd8SLawrence Stewart nanouptime_fromclock(struct timespec *tsp, int whichclock)
33017c43cd8SLawrence Stewart {
33117c43cd8SLawrence Stewart 
33217c43cd8SLawrence Stewart 	if (whichclock == SYSCLOCK_FFWD)
33317c43cd8SLawrence Stewart 		ffclock_nanouptime(tsp);
33417c43cd8SLawrence Stewart 	else
33517c43cd8SLawrence Stewart 		fbclock_nanouptime(tsp);
33617c43cd8SLawrence Stewart }
33717c43cd8SLawrence Stewart 
33817c43cd8SLawrence Stewart static inline void
microuptime_fromclock(struct timeval * tvp,int whichclock)33917c43cd8SLawrence Stewart microuptime_fromclock(struct timeval *tvp, int whichclock)
34017c43cd8SLawrence Stewart {
34117c43cd8SLawrence Stewart 
34217c43cd8SLawrence Stewart 	if (whichclock == SYSCLOCK_FFWD)
34317c43cd8SLawrence Stewart 		ffclock_microuptime(tvp);
34417c43cd8SLawrence Stewart 	else
34517c43cd8SLawrence Stewart 		fbclock_microuptime(tvp);
34617c43cd8SLawrence Stewart }
34717c43cd8SLawrence Stewart 
34817c43cd8SLawrence Stewart static inline void
getbinuptime_fromclock(struct bintime * bt,int whichclock)34917c43cd8SLawrence Stewart getbinuptime_fromclock(struct bintime *bt, int whichclock)
35017c43cd8SLawrence Stewart {
35117c43cd8SLawrence Stewart 
35217c43cd8SLawrence Stewart 	if (whichclock == SYSCLOCK_FFWD)
35317c43cd8SLawrence Stewart 		ffclock_getbinuptime(bt);
35417c43cd8SLawrence Stewart 	else
35517c43cd8SLawrence Stewart 		fbclock_getbinuptime(bt);
35617c43cd8SLawrence Stewart }
35717c43cd8SLawrence Stewart 
35817c43cd8SLawrence Stewart static inline void
getnanouptime_fromclock(struct timespec * tsp,int whichclock)35917c43cd8SLawrence Stewart getnanouptime_fromclock(struct timespec *tsp, int whichclock)
36017c43cd8SLawrence Stewart {
36117c43cd8SLawrence Stewart 
36217c43cd8SLawrence Stewart 	if (whichclock == SYSCLOCK_FFWD)
36317c43cd8SLawrence Stewart 		ffclock_getnanouptime(tsp);
36417c43cd8SLawrence Stewart 	else
36517c43cd8SLawrence Stewart 		fbclock_getnanouptime(tsp);
36617c43cd8SLawrence Stewart }
36717c43cd8SLawrence Stewart 
36817c43cd8SLawrence Stewart static inline void
getmicrouptime_fromclock(struct timeval * tvp,int whichclock)36917c43cd8SLawrence Stewart getmicrouptime_fromclock(struct timeval *tvp, int whichclock)
37017c43cd8SLawrence Stewart {
37117c43cd8SLawrence Stewart 
37217c43cd8SLawrence Stewart 	if (whichclock == SYSCLOCK_FFWD)
37317c43cd8SLawrence Stewart 		ffclock_getmicrouptime(tvp);
37417c43cd8SLawrence Stewart 	else
37517c43cd8SLawrence Stewart 		fbclock_getmicrouptime(tvp);
37617c43cd8SLawrence Stewart }
37717c43cd8SLawrence Stewart 
378cf13a585SLawrence Stewart #else /* !_KERNEL */
379cf13a585SLawrence Stewart 
380cf13a585SLawrence Stewart /* Feed-Forward Clock system calls. */
381cf13a585SLawrence Stewart __BEGIN_DECLS
382cf13a585SLawrence Stewart int ffclock_getcounter(ffcounter *ffcount);
383cf13a585SLawrence Stewart int ffclock_getestimate(struct ffclock_estimate *cest);
384cf13a585SLawrence Stewart int ffclock_setestimate(struct ffclock_estimate *cest);
385cf13a585SLawrence Stewart __END_DECLS
386cf13a585SLawrence Stewart 
387b0fdc837SLawrence Stewart #endif /* _KERNEL */
388b0fdc837SLawrence Stewart #endif /* __BSD_VISIBLE */
389b0fdc837SLawrence Stewart #endif /* _SYS_TIMEFF_H_ */
390