scripts/checkpatch.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Update the MSLEEP warning to suggest fsleep() as a duration based
sleep API. fsleep() autoselects the best sleep mechanism (udelay,
usleep_range, or msleep) based on the requested duration, making
it the preferred replacement for short msleep() calls.
Suggested-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Neel Bullywon <neelb2403@gmail.com>
---
scripts/checkpatch.pl | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index c0250244cf7a..c27045f9f13d 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -6636,7 +6636,7 @@ sub process {
if ($line =~ /\bmsleep\s*\((\d+)\);/) {
if ($1 < 20) {
WARN("MSLEEP",
- "msleep < 20ms can sleep for up to 20ms; see function description of msleep().\n" . $herecurr);
+ "msleep < 20ms can sleep for up to 20ms; see function description of fsleep().\n" . $herecurr);
}
}
base-commit: e7aa57247700733e52a8e2e4dee6a52c2a76de02
--
2.44.0
On Sun, Feb 08, 2026 at 10:59:35AM -0500, Neel Bullywon wrote: > Update the MSLEEP warning to suggest fsleep() as a duration based > sleep API. fsleep() autoselects the best sleep mechanism (udelay, > usleep_range, or msleep) based on the requested duration, making > it the preferred replacement for short msleep() calls. Hmm... My understanding was that the warning itself has a mention of usleep_range(). Looking at the patch I think the current wording is okay, but it may be expanded to suggest fsleep(). -- With Best Regards, Andy Shevchenko
On Mon, Feb 09, 2026 at 10:32:44AM +0200, Andy Shevchenko wrote: > On Sun, Feb 08, 2026 at 10:59:35AM -0500, Neel Bullywon wrote: > > Update the MSLEEP warning to suggest fsleep() as a duration based > > sleep API. fsleep() autoselects the best sleep mechanism (udelay, > > usleep_range, or msleep) based on the requested duration, making > > it the preferred replacement for short msleep() calls. > Hmm... My understanding was that the warning itself has a mention of > usleep_range(). Looking at the patch I think the current wording is > okay, but it may be expanded to suggest fsleep(). Yeah, I would expand this one to make sure we mention fsleep() and update the # prefer usleep_range over udelay one to also mention fsleep(). -- With Best Regards, Andy Shevchenko
On Sun, 2026-02-08 at 10:59 -0500, Neel Bullywon wrote:
> Update the MSLEEP warning to suggest fsleep() as a duration based
> sleep API. fsleep() autoselects the best sleep mechanism (udelay,
> usleep_range, or msleep) based on the requested duration, making
> it the preferred replacement for short msleep() calls.
[]
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
> @@ -6636,7 +6636,7 @@ sub process {
> if ($line =~ /\bmsleep\s*\((\d+)\);/) {
> if ($1 < 20) {
> WARN("MSLEEP",
> - "msleep < 20ms can sleep for up to 20ms; see function description of msleep().\n" . $herecurr);
> + "msleep < 20ms can sleep for up to 20ms; see function description of fsleep().\n" . $herecurr);
> }
> }
maybe change msleep to a #define macro so if the argument is
constant call fsleep instead
Something like:
#define msleep(msecs) \
do { \
if (__builtin_constant_p(msecs) && (msecs) < 20) \
fsleep((msecs) * 1000UL); \
else \
msleep(msecs); \
} while (0)
and change the definition of void msleep(unsigned int msecs) to
void (msleep)(unsigned int msecs)
{
etc...
}
and remove the checkpatch test.
On Sun, 2026-02-08 at 08:36 -0800, Joe Perches wrote:
> On Sun, 2026-02-08 at 10:59 -0500, Neel Bullywon wrote:
> > Update the MSLEEP warning to suggest fsleep() as a duration based
> > sleep API. fsleep() autoselects the best sleep mechanism (udelay,
> > usleep_range, or msleep) based on the requested duration, making
> > it the preferred replacement for short msleep() calls.
> []
> > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> []
> > @@ -6636,7 +6636,7 @@ sub process {
> > if ($line =~ /\bmsleep\s*\((\d+)\);/) {
> > if ($1 < 20) {
> > WARN("MSLEEP",
> > - "msleep < 20ms can sleep for up to 20ms; see function description of msleep().\n" . $herecurr);
> > + "msleep < 20ms can sleep for up to 20ms; see function description of fsleep().\n" . $herecurr);
> > }
> > }
>
> maybe change msleep to a #define macro so if the argument is
> constant call fsleep instead
>
> Something like:
>
> #define msleep(msecs) \
> do { \
> if (__builtin_constant_p(msecs) && (msecs) < 20) \
> fsleep((msecs) * 1000UL); \
> else \
> msleep(msecs); \
> } while (0)
>
> and change the definition of void msleep(unsigned int msecs) to
>
> void (msleep)(unsigned int msecs)
> {
> etc...
> }
>
> and remove the checkpatch test.
And there are quite a lot of msleep(<20)
$ git grep -Pon '\bmsleep\s*\(\s*(?:\d+)\s*\)' | \
awk -F'(' '{ if (strtonum($2) < 20) print; }' | \
wc -l
1709
On Sun, 2026-02-08 at 08:36 -0800, Joe Perches wrote: > maybe change msleep to a #define macro so if the argument is > constant call fsleep instead Thanks for the suggestion, I'd like to implement this for a v2 but want to clarify a few things. 1. fsleep() is static inline and calls msleep() on line 134 of delay.h. Since inline functions are expanded at the call site, the msleep() macro would expand inside fsleep() at every call site even if the macro is defined after fsleep(). I'd need to change that call to (msleep)() to suppress expansion. Same for ssleep() on line 103. Does that sound right? 2. Should this be a single patch or a small series of patches?
© 2016 - 2026 Red Hat, Inc.