From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758786AbcAKIQW (ORCPT ); Mon, 11 Jan 2016 03:16:22 -0500 Received: from www.linutronix.de ([62.245.132.108]:44951 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758710AbcAKIQU (ORCPT ); Mon, 11 Jan 2016 03:16:20 -0500 Date: Mon, 11 Jan 2016 09:15:25 +0100 (CET) From: Thomas Gleixner To: Nicholas Mc Guire cc: John Stultz , linux-kernel@vger.kernel.org Subject: Re: [PATCH RFC] timer: drop the unnecessary while loop in msleep In-Reply-To: <1452337264-32209-1-git-send-email-hofrat@osadl.org> Message-ID: References: <1452337264-32209-1-git-send-email-hofrat@osadl.org> User-Agent: Alpine 2.11 (DEB 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 9 Jan 2016, Nicholas Mc Guire wrote: > The while loop in msleep does not seem necessary as > timeout is unsigned long and no larger than MAX_JIFFY_OFFSET (which is > LONG_MAX/2 - 1) so the while-loop condition is always true at the beginning > (msecs_to_jiffies will return >=0 always and with the +1 timeout is >= 1 so > the while condition is always true at the start) and > schedule_timeout_uninterruptible always returns 0, so the while loop always > terminates after the first loop. Err, no. schedule_timeout_uninterruptible() can return > 0 when there was a non timer wakeup. Thinks spurious wakeups. So we need that loop. > Q: what is the purpose of the + 1 offset to the jiffies here ? > > msleep was introduced in 2.6.7 but without the + 1, so with: > unsigned long timeout = msecs_to_jiffies(msecs); > in 2.6.10-rc2 the msecs_to_jiffies(msecs) + 1; is introduced. > Nishanth Aravamudan (https://lkml.org/lkml/2004/11/19/294) > seems to be the origin while converting msleep to a macro, but no reason > for the + 1 is given there. Not really. The +1 was introduced with the following commit: https://git.kernel.org/cgit/linux/kernel/git/tglx/history.git/commit/kernel/timer.c?id=c259ef842622a5e64418d9dab3b62ee051867edf Thanks, tglx