* [PATCH] checkpatch: suggest fsleep() for short msleep() calls
@ 2026-02-08 15:59 Neel Bullywon
2026-02-08 16:36 ` Joe Perches
2026-02-09 8:32 ` Andy Shevchenko
0 siblings, 2 replies; 6+ messages in thread
From: Neel Bullywon @ 2026-02-08 15:59 UTC (permalink / raw)
To: apw, joe
Cc: dwaipayanray1, lukas.bulwahn, andriy.shevchenko, linux-kernel,
Neel Bullywon
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
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] checkpatch: suggest fsleep() for short msleep() calls
2026-02-08 15:59 [PATCH] checkpatch: suggest fsleep() for short msleep() calls Neel Bullywon
@ 2026-02-08 16:36 ` Joe Perches
2026-02-08 18:41 ` Neel Bullywon
2026-02-08 18:44 ` Joe Perches
2026-02-09 8:32 ` Andy Shevchenko
1 sibling, 2 replies; 6+ messages in thread
From: Joe Perches @ 2026-02-08 16:36 UTC (permalink / raw)
To: Neel Bullywon, apw
Cc: dwaipayanray1, lukas.bulwahn, andriy.shevchenko, linux-kernel
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.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] checkpatch: suggest fsleep() for short msleep() calls
2026-02-08 16:36 ` Joe Perches
@ 2026-02-08 18:41 ` Neel Bullywon
2026-02-08 18:44 ` Joe Perches
1 sibling, 0 replies; 6+ messages in thread
From: Neel Bullywon @ 2026-02-08 18:41 UTC (permalink / raw)
To: joe; +Cc: apw, dwaipayanray1, lukas.bulwahn, andriy.shevchenko,
linux-kernel
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?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] checkpatch: suggest fsleep() for short msleep() calls
2026-02-08 16:36 ` Joe Perches
2026-02-08 18:41 ` Neel Bullywon
@ 2026-02-08 18:44 ` Joe Perches
1 sibling, 0 replies; 6+ messages in thread
From: Joe Perches @ 2026-02-08 18:44 UTC (permalink / raw)
To: Neel Bullywon, apw
Cc: dwaipayanray1, lukas.bulwahn, andriy.shevchenko, linux-kernel
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] checkpatch: suggest fsleep() for short msleep() calls
2026-02-08 15:59 [PATCH] checkpatch: suggest fsleep() for short msleep() calls Neel Bullywon
2026-02-08 16:36 ` Joe Perches
@ 2026-02-09 8:32 ` Andy Shevchenko
2026-02-09 8:34 ` Andy Shevchenko
1 sibling, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2026-02-09 8:32 UTC (permalink / raw)
To: Neel Bullywon; +Cc: apw, joe, dwaipayanray1, lukas.bulwahn, linux-kernel
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] checkpatch: suggest fsleep() for short msleep() calls
2026-02-09 8:32 ` Andy Shevchenko
@ 2026-02-09 8:34 ` Andy Shevchenko
0 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2026-02-09 8:34 UTC (permalink / raw)
To: Neel Bullywon; +Cc: apw, joe, dwaipayanray1, lukas.bulwahn, linux-kernel
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
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-02-09 8:34 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-08 15:59 [PATCH] checkpatch: suggest fsleep() for short msleep() calls Neel Bullywon
2026-02-08 16:36 ` Joe Perches
2026-02-08 18:41 ` Neel Bullywon
2026-02-08 18:44 ` Joe Perches
2026-02-09 8:32 ` Andy Shevchenko
2026-02-09 8:34 ` Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox