SBINTIME(9)

πŸ“¦ version 14.5, in freebsd 14.5

✨ SBINTIME(9) β€” Q32.32 fixed point time, but make it make sense ✨

okay bestie, gather round, because this one is genuinely iconic once you get it. this is the sbintime_t manual page, from the Kernel Developer's Manual. it's a Q32.32 fixed point representation of time and honestly? it ate. let's get into it πŸ’…


🌸 NAME 🌸

sbintime_t, sbintime_getsec, bttosbt, sbttobt, sbttons, nstosbt, sbttous, ustosbt, sbttoms, mstosbt, sbttots, tstosbt, sbttotv, tvtosbt β€” a Q32.32 fixed point representation of time πŸ•°οΈ


πŸŽ€ SYNOPSIS πŸŽ€

like, the whole cast list, fr fr:

#include <sys/types.h>
#include <sys/time.h>

typedef __int64_t __sbintime_t;
typedef __sbintime_t sbintime_t;

#define SBT_1S ((sbintime_t)1 << 32)
#define SBT_1M (SBT_1S * 60)
#define SBT_1MS (SBT_1S / 1000)
#define SBT_1US (SBT_1S / 1000000)
#define SBT_1NS (SBT_1S / 1000000000)

int
sbintime_getsec(sbintime_t sbt);

sbintime_t
bttosbt(const struct bintime bt);

struct bintime
sbttobt(sbintime_t sbt);

int64_t
sbttons(sbintime_t sbt);

sbintime_t
nstosbt(int64_t ns);

int64_t
sbttous(sbintime_t sbt);

sbintime_t
ustosbt(int64_t us);

int64_t
sbttoms(sbintime_t sbt);

sbintime_t
mstosbt(int64_t ms);

struct timespec
sbttots(sbintime_t sbt);

sbintime_t
tstosbt(struct timespec ts);

struct timeval
sbttotv(sbintime_t sbt);

sbintime_t
tvtosbt(struct timeval tv);

πŸ’– DESCRIPTION πŸ’–

so. the sbintime_t type is a Q32.32 fixed point representation of time. the high 32-bit integral bits are the number of seconds, and the low 32-bit fractional bits are the sub-second part. and because the lower 32 bits are counting with a base unit of 1/2^32 seconds, (sbintime_t)0x1 is just under 250 picoseconds. like, tiny tiny. microscopic. a crumb of a second 🫢

and here's the slay: all of these conversion functions are designed to do the conversion without the large truncation errors you'd get from naive math. no cap, that's the whole point. it's giving precision.

🌟 the functions 🌟

  • sbintime_getsec(sbt) β€” returns the whole number of seconds from the sbintime_t you passed as the sbt argument. just the whole ones, no fractional crumbs.
  • bttosbt(bt) β€” converts a struct bintime (that's the bt argument) into an sbintime_t.
  • sbttobt(sbt) β€” converts an sbintime_t (the sbt argument) into a struct bintime.
  • sbttons(sbt) β€” converts an sbintime_t (the sbt argument) into the number of nanoseconds.
  • nstosbt(ns) β€” converts the number of nanoseconds (the ns argument) into an sbintime_t.
  • sbttous(sbt) β€” converts an sbintime_t (the sbt argument) into the number of microseconds.
  • ustosbt(us) β€” converts the number of microseconds (the us argument) into an sbintime_t.
  • sbttoms(sbt) β€” converts an sbintime_t (the sbt argument) into the number of milliseconds.
  • mstosbt(ms) β€” converts the number of milliseconds (the ms argument) into an sbintime_t.
  • sbttots(sbt) β€” converts an sbintime_t (the sbt argument) into a struct timespec.
  • tstosbt(ts) β€” converts a struct timespec (the ts argument) into an sbintime_t.
  • sbttotv(sbt) β€” converts an sbintime_t (the sbt argument) into a struct timeval.
  • tvtosbt(tv) β€” converts a struct timeval (the tv argument) into an sbintime_t.

the pattern is lowkey genius: sbttosomething goes out of sbintime_t, somethingtosbt comes in to sbintime_t. iykyk 🌈


πŸ¦‹ SEE ALSO πŸ¦‹

go read those too, bestie, they're in the same friend group πŸ’œ


⭐ HISTORY ⭐

the sbintime_t type and most of the helper functions first appeared in FreeBSD 10.0. and the Xstosbt functions first appeared in FreeBSD 12.0. glow-up timeline fr fr πŸ”₯


πŸ‘‘ AUTHORS πŸ‘‘

this manual page was written by Ka Ho Ng <khng@FreeBSD.org>. iconic behavior, thank you for your service 🫑


ok that's the whole page, no skips, no cuts πŸ’€ every function accounted for, every argument named, every header included. you're welcome.

🌸 this Debian build of the page is dated July 12, 2026 β€” that's the source/version and date, bestie, consider it mentioned. mwah, go convert some time πŸ’…βœ¨

πŸ“¦ where this page comes from