tod_to_ns(9)
π 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
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms