usleep_range_state(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’€ usleep_range_state(9) πŸ’€

okay bestie, welcome to the Kernel API Manual ✨ this one's literally called usleep_range_state and it does exactly what it says on the tin β€” no cap.


🌸 NAME 🌸

usleep_range_state β€” sleep for an approximate time in a given state πŸŽ€


✨ SYNOPSIS ✨

void usleep_range_state (unsigned long min , unsigned long max ,
       unsigned int state );

like... that's the whole vibe. three args, one nap. πŸ¦‹


🫢 ARGUMENTS 🫢

  • min β€” the minimum time in usecs to sleep. the floor, the bare minimum, the "at least this long" of it all πŸ’…
  • max β€” the maximum time in usecs to sleep. the ceiling, the upper limit, the "not a usec longer" πŸŽ€
  • state β€” the state of the current task while it's sleeping. yes, that state. it will be while sleeping. iconique πŸ’œ

πŸ”₯ DESCRIPTION πŸ”₯

okay so picture this: usleep_range_state sleeps at least for the minimum time you specified, but not longer than the maximum amount of time you specified. so far so straightforward, right? πŸ’…

but here's the slay part β€” that range might lowkey reduce power usage by letting hrtimers coalesce an already scheduled interrupt with this hrtimer. the way that works?? literally saving watts. ⚑ and in the worst case, an interrupt is scheduled for the upper bound. worst case is still fine, bestie. we love a graceful fallback. 🫢

the sleeping task is set to the specified state before starting the sleep. like getting into bed before you doomscroll. πŸ›οΈβœ¨

now, listen β€” in non-atomic context where the exact wakeup time is flexible, use usleep_range or its variants instead of udelay. and why? because the sleep improves responsiveness by avoiding the CPU-hogging busy-wait of udelay. udelay is out here spinning and hogging the CPU like that one friend who won't let anyone else talk 😭 not the move. usleep_range is giving main character energy and it's polite to your processor. 🌈

⭐ tiny vibe check: min and max are in usecs β€” microseconds, babe. don't come at me later like "wait, what unit". i told you. πŸ’€

πŸ‘‘ SEE ALSO πŸ‘‘

the whole scheduling friend group 😌 iykyk πŸ’–


πŸ“ aaaand that's the page!! brought to you by the lovely humans of ./kernel/time, dropping October 2026 β€” see you in the next manpage, bestie, mwah πŸ’‹βœ¨πŸŒ· sleep well (for somewhere between min and max usecs) πŸ’€πŸŒˆ
πŸ“¦ where this page comes from