Re: [PATCH] Add explanation of udelay() inaccuracy

From: Pavel Machek
Date: Thu Feb 16 2017 - 16:52:57 EST


Hi!

> +++ b/include/linux/delay.h
> @@ -5,6 +5,17 @@
> * Copyright (C) 1993 Linus Torvalds
> *
> * Delay routines, using a pre-computed "loops_per_jiffy" value.
> + *
> + * Please note that ndelay(), udelay() and mdelay() may return early for
> + * several reasons:
> + * 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.
> + *

Hmm. Formulated like this, it would mean that udelay(100) can return
in 10usec (because of clock rate changes). No way can drivers work
reliably in that case.

Can we formulate something more useful? We don't want driver writers
to delay 10 times more "just for cpufreq", right?

Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html