MSTOHZ(9)

πŸ“¦ version 11.0, in nixpkgs unstable

πŸ’… MSTOHZ(9) β€” the manual page, but make it group chat

Okay so bestie, let me tell you about MSTOHZ(9), the kernel dev manual page that's literally the main character for converting between milliseconds and system clock ticks. No cap, this one's a little icon.


✨ NAME ✨

mstohz, hztoms β€” convert between milliseconds and system clock ticks πŸ•°οΈπŸ’–


🌸 SYNOPSIS 🌸

#include <sys/param.h>

unsigned int
mstohz(unsigned int ms);

unsigned int
hztoms(unsigned int hz);

πŸŽ€ DESCRIPTION πŸŽ€

The mstohz() macro is your go-to bestie for converting time in milliseconds to system clock ticks β€” the same kind the callout(9) facility uses β€” and it does it in an integer-overflow safe way. Slay. πŸ’…

Conversely, hztoms() converts system clock ticks back to milliseconds. The way these two just vibe with each other? Obsessed.

These macros are defined in the <sys/param.h> header, periodt. And fr fr, individual ports can have a processor-specific, more efficient version implemented in their <machine/param.h> header as a define. That's some main character energy right there. 🧚✨


🌈 RETURN VALUES 🌈

The return value is either the number of clock ticks or milliseconds for the specified value. Simple as that, bestie. 🫢


πŸ¦‹ SEE ALSO πŸ¦‹

These are the linked besties, iykyk. ✨


πŸ’€ BUGS πŸ’€

Neither mstohz() nor hztoms() make use of expensive 64-bit integer arithmetic. The result from mstohz() will be rounded down to one second if the parameter is larger than 131072 milliseconds. 😭

So like, lowkey important: don't come for these macros unless you know the math is intentionally lightweight. It's giving "efficient but with a catch," and that catch is real. πŸ™ˆ


πŸ‘‘ SIGN-OFF πŸ‘‘

That's the whole vibe for this one! Big Debian energy, dated September 28, 2019, and honestly? Iconic. πŸ’–πŸŽ€πŸ’… Go forth and convert your ticks, bestie. πŸ¦‹πŸŒΈ

πŸ“¦ where this page comes from