[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <5e3c3f78-344c-ae03-b6ae-ea55e402c1e7@gmail.com>
Date: Fri, 1 May 2020 23:27:21 +0200
From: Heiner Kallweit <hkallweit1@...il.com>
To: Thomas Gleixner <tglx@...utronix.de>,
Jonathan Corbet <corbet@....net>,
Realtek linux nic maintainers <nic_swsd@...ltek.com>,
David Miller <davem@...emloft.net>
Cc: "netdev@...r.kernel.org" <netdev@...r.kernel.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
linux-doc@...r.kernel.org
Subject: [PATCH net-next 1/2] 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@...il.com>
---
Documentation/timers/timers-howto.rst | 3 +++
include/linux/delay.h | 11 +++++++++++
2 files changed, 14 insertions(+)
diff --git a/Documentation/timers/timers-howto.rst b/Documentation/timers/timers-howto.rst
index 7e3167bec..afb0a43b8 100644
--- a/Documentation/timers/timers-howto.rst
+++ b/Documentation/timers/timers-howto.rst
@@ -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
diff --git a/include/linux/delay.h b/include/linux/delay.h
index 8e6828094..cb1d508ca 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) */
--
2.26.2
Powered by blists - more mailing lists