Commit a88845d8 authored by David S. Miller's avatar David S. Miller

Merge branch 'timer-add-fsleep-for-flexible-sleeping'

Heiner Kallweit says:

====================
timer: add fsleep for flexible sleeping

Sleeping for a certain amount of time requires use of different
functions, depending on the time period.
Documentation/timers/timers-howto.rst explains when to use which
function, and also checkpatch checks for some potentially
problematic cases.

So let's create a helper that automatically chooses the appropriate
sleep function -> fsleep(), for flexible sleeping
Not sure why such a helper doesn't exist yet, or where the pitfall is,
because it's a quite obvious idea.

If the delay is a constant, then the compiler should be able to ensure
that the new helper doesn't create overhead. If the delay is not
constant, then the new helper can save some code.

First user is the r8169 network driver. If nothing speaks against it,
then this series could go through the netdev tree.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 969c5464 d6836ef0
......@@ -110,3 +110,6 @@ NON-ATOMIC CONTEXT:
short, the difference is whether the sleep can be ended
early by a signal. In general, just use msleep unless
you know you have a need for the interruptible variant.
FLEXIBLE SLEEPING (any delay, uninterruptible)
* Use fsleep
This diff is collapsed.
......@@ -65,4 +65,15 @@ static inline void ssleep(unsigned int seconds)
msleep(seconds * 1000);
}
/* see Documentation/timers/timers-howto.rst for the thresholds */
static inline void fsleep(unsigned long usecs)
{
if (usecs <= 10)
udelay(usecs);
else if (usecs <= 20000)
usleep_range(usecs, 2 * usecs);
else
msleep(DIV_ROUND_UP(usecs, 1000));
}
#endif /* defined(_LINUX_DELAY_H) */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment