xref: /freebsd/share/man/man9/sbintime.9 (revision c3f6c655dd155f4c84ce743c86e07d9f0b6b348a)
1.\"
2.\" Copyright (c) 2026 Ka Ho Ng
3.\"
4.\" SPDX-License-Identifier: BSD-2-Clause
5.\"
6.Dd July 12, 2026
7.Dt SBINTIME 9
8.Os
9.Sh NAME
10.Nm sbintime_t ,
11.Nm sbintime_getsec ,
12.Nm bttosbt ,
13.Nm sbttobt ,
14.Nm sbttons ,
15.Nm nstosbt ,
16.Nm sbttous ,
17.Nm ustosbt ,
18.Nm sbttoms ,
19.Nm mstosbt ,
20.Nm sbttots ,
21.Nm tstosbt ,
22.Nm sbttotv ,
23.Nm tvtosbt
24.Nd Q32.32 fixed point representation of time
25.Sh SYNOPSIS
26.In sys/types.h
27.In sys/time.h
28.Vt typedef __int64_t __sbintime_t ;
29.Vt typedef __sbintime_t sbintime_t ;
30.Fd #define SBT_1S ((sbintime_t)1 << 32)
31.Fd #define SBT_1M (SBT_1S * 60)
32.Fd #define SBT_1MS (SBT_1S / 1000)
33.Fd #define SBT_1US (SBT_1S / 1000000)
34.Fd #define SBT_1NS (SBT_1S / 1000000000)
35.Ft int
36.Fn sbintime_getsec "sbintime_t sbt"
37.Ft sbintime_t
38.Fn bttosbt "const struct bintime bt"
39.Ft struct bintime
40.Fn sbttobt "sbintime_t sbt"
41.Ft int64_t
42.Fn sbttons "sbintime_t sbt"
43.Ft sbintime_t
44.Fn nstosbt "int64_t ns"
45.Ft int64_t
46.Fn sbttous "sbintime_t sbt"
47.Ft sbintime_t
48.Fn ustosbt "int64_t us"
49.Ft int64_t
50.Fn sbttoms "sbintime_t sbt"
51.Ft sbintime_t
52.Fn mstosbt "int64_t ms"
53.Ft struct timespec
54.Fn sbttots "sbintime_t sbt"
55.Ft sbintime_t
56.Fn tstosbt "struct timespec ts"
57.Ft struct timeval
58.Fn sbttotv "sbintime_t sbt"
59.Ft sbintime_t
60.Fn tvtosbt "struct timeval tv"
61.Sh DESCRIPTION
62The
63.Vt sbintime_t
64type is a Q32.32 fixed point representation of time.
65The high 32-bit integral bits specify the number of seconds,
66and the low 32-bit fractional bits specify the sub-second portion.
67Since the lower 32 bits are counting with a base unit of 1/2^32 seconds,
68.Ql (sbintime_t)0x1
69is just under 250 picoseconds.
70.Pp
71All of the conversion functions are designed to do the conversion without large
72truncation errors that are possible with naive math.
73.\" Begin of helper functions subsection
74.Bl -tag -width indent
75.It Fn sbintime_getsec sbt
76Return the whole number of seconds from a
77.Vt sbintime_t
78specified by the
79.Fa sbt
80argument.
81.It Fn bttosbt bt
82Convert a
83.Vt struct bintime
84specified by the
85.Fa bt
86argument to a
87.Vt sbintime_t .
88.It Fn sbttobt sbt
89Convert a
90.Vt sbintime_t
91specified by the
92.Fa sbt
93argument to a
94.Vt "struct bintime" .
95.It Fn sbttons sbt
96Convert a
97.Vt sbintime_t
98specified by the
99.Fa sbt
100argument to the number of nanoseconds.
101.It Fn nstosbt ns
102Convert the number of nanoseconds specified by the
103.Fa ns
104argument to a
105.Vt sbintime_t .
106.It Fn sbttous sbt
107Convert a
108.Vt sbintime_t
109specified by the
110.Fa sbt
111argument to the number of microseconds.
112.It Fn ustosbt us
113Convert the number of microseconds specified by the
114.Fa us
115argument to a
116.Vt sbintime_t .
117.It Fn sbttoms sbt
118Convert a
119.Vt sbintime_t
120specified by the
121.Fa sbt
122argument to the number of milliseconds.
123.It Fn mstosbt ms
124Convert the number of milliseconds specified by the
125.Fa ms
126argument to a
127.Vt sbintime_t .
128.It Fn sbttots sbt
129Convert a
130.Vt sbintime_t
131specified by the
132.Fa sbt
133argument to a
134.Vt "struct timespec" .
135.It Fn tstosbt ts
136Convert a
137.Vt "struct timespec"
138specified by the
139.Fa ts
140argument to a
141.Vt sbintime_t .
142.It Fn sbttotv sbt
143Convert a
144.Vt sbintime_t
145specified by the
146.Fa sbt
147argument to a
148.Vt "struct timeval" .
149.It Fn tvtosbt tv
150Convert a
151.Vt "struct timeval"
152specified by the
153.Fa tv
154argument to a
155.Vt sbintime_t .
156.El
157.\" End of helper functions subsection
158.Sh SEE ALSO
159.Xr bintime 9 ,
160.Xr callout 9 ,
161.Xr tvtohz 9
162.Sh HISTORY
163The
164.Nm sbintime_t
165type and most of the helper functions first appeared in
166.Fx 10.0 .
167The Xstosbt functions first appeared in
168.Fx 12.0 .
169.Sh AUTHORS
170This manual page was written by
171.An Ka Ho Ng Aq Mt khng@FreeBSD.org .
172