schedule_hrtimeout_range(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’€ schedule_hrtimeout_range β€” sleep until timeout πŸ’€

okay so bestie, this is a Kernel API Manual page, section 9 β€” we're in kernel-internals territory and honestly it's kind of a vibe. Buckle up, this one's about making the current task nap until a specific moment in time. ✨


πŸŽ€ SYNOPSIS πŸŽ€

int schedule_hrtimeout_range (ktime_t *expires , u64 delta , const enum
hrtimer_mode mode );

three args, one int back, and yes the spacing is iconic, don't touch it πŸ’…


🌸 ARGUMENTS 🌸

  • expires β€” the timeout value, and it's a ktime_t (which, note, the manpage lists as ktime_t even though the synopsis says ktime_t *… we report, we don't fix 🫢). This is your "wake me up at this moment" moment.
  • delta β€” the slack in the expires timeout (also listed as ktime_t). Think of it as your flex window, more on that below 😌
  • mode β€” the timer mode. It's a const enum hrtimer_mode, fr fr.

πŸ¦‹ DESCRIPTION πŸ¦‹

Make the current task sleep until the given expiry time has elapsed. That's the whole job, and it does it.

⚠️ Big one: the routine will return immediately unless the current task state has been set (see set_current_state). So set that state first or you're just gonna blaze right through this thing 😭

The delta argument gives the kernel the freedom to schedule the actual wakeup to a time that's both power and performance friendly β€” for regular (non RT/DL) tasks. The kernel gives the normal best effort behavior for "expires+delta", but may decide to fire the timer earlier, but no earlier than expires. So it's never early-early, only early-within-your-slack. No cap. πŸ”₯

You can set the task state as follows β€”

  • TASK_UNINTERRUPTIBLE β€” at least the timeout time is guaranteed to pass before the routine returns, unless the current task is explicitly woken up (e.g. by wake_up_process). It's committed. It's loyal. πŸ‘‘
  • TASK_INTERRUPTIBLE β€” the routine may return early if a signal is delivered to the current task, or the current task is explicitly woken up. Sleeps with one eye open πŸ’€

And the glow-up at the end: the current task state is guaranteed to be TASK_RUNNING when this routine returns. Periodt. You always leave running, never asleep. ✨


🌈 RETURN 🌈

  • 0 β€” when the timer has expired. clean, correct, slay πŸ’–
  • -EINTR β€” if the task was woken before the timer expired, either by a signal (only possible in state TASK_INTERRUPTIBLE) or by an explicit wakeup. Rude but valid πŸ™ˆ

πŸ’œ SEE ALSO πŸ’œ

Kernel file ./kernel/time/sleep_timeout.c β€” go read the source bestie, it's giving main character energy:


okay that's the whole page, go take a nap (the well-timed, delta-tolerant kind) πŸ§šβ€β™€οΈπŸŒ™

signed off with love from ./kernel/time, dated October 2026, in the Kernel API Manual β€” bye bestie, ily, don't forget set_current_state πŸ’…πŸŒΈ

πŸ“¦ where this page comes from