All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] timer: Make msleep(0) a nop
@ 2016-08-12  8:40 ville.syrjala
  2016-08-17 19:39 ` John Stultz
  0 siblings, 1 reply; 2+ messages in thread
From: ville.syrjala @ 2016-08-12  8:40 UTC (permalink / raw)
  To: linux-kernel; +Cc: Thomas Gleixner, John Stultz, Ville Syrjälä

From: Ville Syrjälä <ville.syrjala@linux.intel.com>

Thanks to the msecs_to_jiffies()+1 msleep(0) may actually sleep for up
to one jiffy. Presumably the caller should be satisfied if we "sleep"
for 0 jiffies instead of 0-1 jiffies, so let's just turn msleep(0)
into a nop.

This can simplify some callers as they don't have to check for the
0 msecs case themselves anymore. Or if they're not checking for 0,
they might avoid a needless sleep occasionally.

A slight concern might be that someone is calling msleep(0) and
depending on some delay being there. But that can clearly blow up
even without this change, so I'm not overly worried about it.

Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: John Stultz <john.stultz@linaro.org>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 kernel/time/timer.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/time/timer.c b/kernel/time/timer.c
index 555670a5143c..1f9ccfccb68f 100644
--- a/kernel/time/timer.c
+++ b/kernel/time/timer.c
@@ -1870,7 +1870,7 @@ void __init init_timers(void)
  */
 void msleep(unsigned int msecs)
 {
-	unsigned long timeout = msecs_to_jiffies(msecs) + 1;
+	unsigned long timeout = msecs ? msecs_to_jiffies(msecs) + 1 : 0;
 
 	while (timeout)
 		timeout = schedule_timeout_uninterruptible(timeout);
@@ -1884,7 +1884,7 @@ EXPORT_SYMBOL(msleep);
  */
 unsigned long msleep_interruptible(unsigned int msecs)
 {
-	unsigned long timeout = msecs_to_jiffies(msecs) + 1;
+	unsigned long timeout = msecs ? msecs_to_jiffies(msecs) + 1 : 0;
 
 	while (timeout && !signal_pending(current))
 		timeout = schedule_timeout_interruptible(timeout);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] timer: Make msleep(0) a nop
  2016-08-12  8:40 [PATCH] timer: Make msleep(0) a nop ville.syrjala
@ 2016-08-17 19:39 ` John Stultz
  0 siblings, 0 replies; 2+ messages in thread
From: John Stultz @ 2016-08-17 19:39 UTC (permalink / raw)
  To: Ville Syrjälä; +Cc: lkml, Thomas Gleixner

On Fri, Aug 12, 2016 at 1:40 AM,  <ville.syrjala@linux.intel.com> wrote:
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
>
> Thanks to the msecs_to_jiffies()+1 msleep(0) may actually sleep for up
> to one jiffy. Presumably the caller should be satisfied if we "sleep"
> for 0 jiffies instead of 0-1 jiffies, so let's just turn msleep(0)
> into a nop.
>
> This can simplify some callers as they don't have to check for the
> 0 msecs case themselves anymore. Or if they're not checking for 0,
> they might avoid a needless sleep occasionally.
>
> A slight concern might be that someone is calling msleep(0) and
> depending on some delay being there. But that can clearly blow up
> even without this change, so I'm not overly worried about it.

I think this is more then a slight concern. Calls to *sleep() make
sure to sleep for at least the amount of time specified, but there is
no upper bound on how long that sleep might actually be. So msleep(0)
sleeping for 1 jiffy or more is correct. And when folks want the
minimum sleep granularity, msleep(0) is a valid way to get that.

So I don't think this is a good idea to change, at least w/o a much
stronger rational.

thanks
-john

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-08-17 19:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-12  8:40 [PATCH] timer: Make msleep(0) a nop ville.syrjala
2016-08-17 19:39 ` John Stultz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.