usleep_range_state(9)
π€ 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:minandmaxare in usecs β microseconds, babe. don't come at me later like "wait, what unit". i told you. π
π SEE ALSO π
- Kernel file
./kernel/time/sleep_timeout.cβ the source, the origin story, the mothership π§ schedule_timeout(9)schedule_timeout_interruptible(9)schedule_timeout_killable(9)schedule_timeout_uninterruptible(9)schedule_timeout_idle(9)schedule_hrtimeout_range_clock(9)schedule_hrtimeout_range(9)schedule_hrtimeout(9)msleep(9)msleep_interruptible(9)
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
- 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