udelay(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

udelay(9) πŸ’… β€” Kernel API Manual bestie briefing πŸ¦‹

🌸 NAME 🌸

udelay β€” inserting a delay based on microseconds with busy waiting ✨

✨ SYNOPSIS ✨

void udelay (unsigned long usec );

πŸŽ€ ARGUMENTS πŸŽ€

  • usec β€” the requested delay in microseconds 🫢

πŸ’– DESCRIPTION πŸ’–

Okay so when you're delaying in an atomic context, ndelay, udelay, and mdelay are literally the only valid variants of delaying/sleeping to go with β€” periodt. πŸ‘‘

When inserting delays in non atomic context which are shorter than the time which is required to queue e.g. an hrtimer and to enter the scheduler, it is also valuable to use udelay. But it is not simple to specify a generic threshold for this which will fit for all systems. An approximation is a threshold for all delays up to 10 microseconds ⭐.

When having a delay which is larger than the architecture specific MAX_UDELAY_MS value, please make sure mdelay is used. Otherwise an overflow risk is given 😭.

⚠️ heads up bestie: please note that ndelay, udelay, and mdelay may return early for several reasons (https://lists.openwall.net/linux-kernel/2011/01/09/56):
  1. computed loops_per_jiffy too low (due to the time taken to execute the timer interrupt.) πŸ’€
  2. cache behaviour affecting the time it takes to execute the loop function. 🧚
  3. CPU clock rate changes. πŸ”₯

🌈 SEE ALSO 🌈

Kernel file ./include/asm-generic/delay.h β€” and also go peek at ndelay(9) 🫢


β€” with love from source/version ./include/asm-generic, dated October 2026, and this whole udelay(9) moment is signed off with sparkles πŸ’Œβœ¨πŸŽ€

πŸ“¦ where this page comes from