summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorHeiner Kallweit <hkallweit1@gmail.com>2020-05-01 23:27:21 +0200
committerDavid S. Miller <davem@davemloft.net>2020-05-06 17:03:34 -0700
commitc6af13d334759c33c14b6fad4c676c6d1dbf9564 (patch)
tree7ec9292a89a88376a78f4ad035dc9986d1dcad7e /include
parent969c54646af0d7d94a5f0f37adbbfe024e85466e (diff)
downloadlinux-stable-c6af13d334759c33c14b6fad4c676c6d1dbf9564.tar.gz
linux-stable-c6af13d334759c33c14b6fad4c676c6d1dbf9564.tar.bz2
linux-stable-c6af13d334759c33c14b6fad4c676c6d1dbf9564.zip
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 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. Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include')
-rw-r--r--include/linux/delay.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/include/linux/delay.h b/include/linux/delay.h
index 8e6828094c1e..5e016a4029d9 100644
--- a/include/linux/delay.h
+++ b/include/linux/delay.h
@@ -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) */