[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250626145119.2048423-1-jani.nikula@intel.com>
Date: Thu, 26 Jun 2025 17:51:19 +0300
From: Jani Nikula <jani.nikula@...el.com>
To: linux-kernel@...r.kernel.org
Cc: intel-gfx@...ts.freedesktop.org,
jani.nikula@...el.com,
Thomas Gleixner <tglx@...utronix.de>,
Geert Uytterhoeven <geert+renesas@...der.be>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Subject: [PATCH] iopoll: use fsleep() instead of usleep_range()
Sometimes it's necessary to poll with long sleeps, and the accuracy of
usleep_range() is overkill. Use the flexible sleep helper fsleep() for
sleeping in the read_poll_timeout() family of macros to automatically
choose the appropriate method of waiting.
Functionally there are a few consequences for existing users:
- 10 us and shorter sleeps will use usleep() instead of
usleep_range(). Presumably this will not be an issue.
- When it leads to a slack of less than 25%, msleep() will be used
instead of usleep_range(). Presumably this will not be an issue, given
the sleeps will be longer in this case.
- Otherwise, the usleep_range() slack gets switched from the begin of
the range to the end of the range, i.e. [sleep/2+1..sleep] ->
[sleep..sleep+sleep/2]. In theory, this could be an issue in some
cases, but difficult to determine before this hits the real world.
Signed-off-by: Jani Nikula <jani.nikula@...el.com>
---
Not really sure who to Cc, given MAINTAINERS doesn't match this. Adding
some past committers.
Cc: Thomas Gleixner <tglx@...utronix.de>
Cc: Geert Uytterhoeven <geert+renesas@...der.be>
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: linux-kernel@...r.kernel.org
---
include/linux/iopoll.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/include/linux/iopoll.h b/include/linux/iopoll.h
index 91324c331a4b..359ff5ab95de 100644
--- a/include/linux/iopoll.h
+++ b/include/linux/iopoll.h
@@ -20,7 +20,7 @@
* @val: Variable to read the value into
* @cond: Break condition (usually involving @val)
* @sleep_us: Maximum time to sleep between reads in us (0 tight-loops). Please
- * read usleep_range() function description for details and
+ * read fsleep() function description for details and
* limitations.
* @timeout_us: Timeout in us, 0 means never timeout
* @sleep_before_read: if it is true, sleep @sleep_us before read.
@@ -41,7 +41,7 @@
ktime_t __timeout = ktime_add_us(ktime_get(), __timeout_us); \
might_sleep_if((__sleep_us) != 0); \
if (sleep_before_read && __sleep_us) \
- usleep_range((__sleep_us >> 2) + 1, __sleep_us); \
+ fsleep(__sleep_us); \
for (;;) { \
(val) = op(args); \
if (cond) \
@@ -52,7 +52,7 @@
break; \
} \
if (__sleep_us) \
- usleep_range((__sleep_us >> 2) + 1, __sleep_us); \
+ fsleep(__sleep_us); \
cpu_relax(); \
} \
(cond) ? 0 : -ETIMEDOUT; \
@@ -120,7 +120,7 @@
* @val: Variable to read the value into
* @cond: Break condition (usually involving @val)
* @sleep_us: Maximum time to sleep between reads in us (0 tight-loops). Please
- * read usleep_range() function description for details and
+ * read fsleep() function description for details and
* limitations.
* @timeout_us: Timeout in us, 0 means never timeout
*
--
2.39.5
Powered by blists - more mailing lists