TIME(9)

πŸ’– TIME(9) β€” Kernel Developer's Manual, bestie edition πŸ’–

okay so you're in the 9 section, which is where the kernel developer girlies live, and this page is literally just three global variables that run the whole clock situation. no cap. let's go πŸ•βœ¨


🌸 NAME 🌸

boottime, time_second, time_uptime β€” the system time variables, aka the three icons keeping track of when things are happening πŸ‘‘


✨ SYNOPSIS ✨

#include <sys/time.h>

extern struct timeval boottime;
extern time_t time_second;
extern time_t time_uptime;

that's it. that's the whole cast. three externs and a header. slay πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

okay so boom, meet the trio:

  • boottime β€” this one holds the system boot time. like, the exact moment the system woke up and said "hi bestie, I'm alive" πŸŒ…. it's a struct timeval, so she's got sub-second precision energy.
  • time_second β€” this is the system's β€œwall time” clock, rounded to the second. the vibes clock. the one you glance at. ⏰
  • time_uptime β€” the number of seconds since boot. not the time of day, just how long have we been up, like a "days since last incident" sign but for your kernel πŸ”₯

now here's the tea, bestie πŸ«– β€” if you want the current time and you want it accurate and atomic (no half-updated nonsense, no race conditions sneaking in like a toxic ex), use these instead:

bintime(9), getbintime(9), microtime(9), getmicrotime(9), nanotime(9), and getnanotime(9) β€” they give you the current time more accurately and in an atomic manner. periodt ✨

and if what you actually want is how much time has elapsed since boot, also accurate, also atomic, hit up:

binuptime(9), getbinuptime(9), microuptime(9), getmicrouptime(9), nanouptime(9), and getnanouptime(9) β€” these give you the time elapse since boot, more accurately and in an atomic manner 🧚

but boottime? she's different. the boottime variable may be read and written without special precautions. lowkey the most chill of the three. no locking drama, no atomic requirements, just vibes 🫢

πŸ‘‘ SEE ALSO πŸ‘‘

the whole friend group, alphabetized, no one left out:

and the required reading for the academic girlies πŸ“š:

  • Poul-Henning Kamp, β€œTimecounters: Efficient and precise timekeeping in SMP kernels”, Proceedings of EuroBSDCon 2002, Amsterdam, /usr/share/doc/papers/timecounter.ascii.gz.
  • Marshall Kirk McKusick and George V. Neville-Neil, The Design and Implementation of the FreeBSD Operating System, Addison-Wesley, 57-61,65-66, July 2004.

and that's the whole page bestie!! this one came from Debian, dated September 17, 2004, and honestly for a manpage that old she's still serving πŸ’œ go read bintime(9) if you want the atomic upgrade, love u bye πŸŽ€βœ¨

πŸ“¦ where this page comes from