tod_to_ns(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– tod_to_ns(9) β€” the Kernel API Manual moment πŸŽ€

Okay bestie, welcome to tod_to_ns(9), straight out of the kernel API manual. We're doing some time math today and honestly? It's giving bit-shifting main character energy. ✨


🌸 NAME 🌸

tod_to_ns β€” convert a TOD format value to nanoseconds πŸ•°οΈπŸ’«


✨ SYNOPSIS ✨

unsigned long tod_to_ns (unsigned long todval );

🫢 ARGUMENTS 🫢

  • todval β€” the TOD format value that's getting converted, bestie. That's the one.

πŸ‘‘ RETURN πŸ‘‘

It hands you back the number of nanoseconds that correspond to that TOD format value. Slay. πŸ’…


πŸ’œ DESCRIPTION πŸ’œ

Okay so here's the tea β˜• β€” converting a 64 bit TOD format value to nanoseconds means the value has to be divided by 4.096. And like… we're not just gonna do that, obviously. The move is to multiply by 125 and divide by 512 instead:

ns = (todval * 125) >> 9;

But wait πŸ›‘ β€” to avoid an overflow with the multiplication, we can rewrite this whole thing. With a split todval == 2^9 * th + tl (where th is the upper 55 bits and tl is the lower 9 bits), we end up with:

ns = ((2^9 * th + tl) * 125 ) >> 9; -> ns = (th * 125) + ((tl * 125) >> 9);

No cap, that's the whole glow-up. πŸ¦‹πŸ”₯


🌈 SEE ALSO 🌈

Kernel file ./arch/s390/include/asm/timex.h β€” plus tod_after(9) and tod_after_eq(9). Go read those next, iykyk πŸ’–


Big kiss and a huge thank you to ./arch/s390/include/asm β€” this page is dated October 2026 and it's iconic for it. πŸŽ€πŸ’œβœ¨

πŸ“¦ where this page comes from