public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Nishanth Aravamudan <nacc@us.ibm.com>
To: Roman Zippel <zippel@linux-m68k.org>
Cc: Arjan van de Ven <arjan@infradead.org>,
	Andrew Morton <akpm@osdl.org>,
	domen@coderock.org, linux-kernel@vger.kernel.org,
	clucas@rotomalug.org
Subject: [UPDATE PATCH] push rounding up of relative request to schedule_timeout()
Date: Wed, 3 Aug 2005 22:14:34 -0700	[thread overview]
Message-ID: <20050804051434.GA4520@us.ibm.com> (raw)
In-Reply-To: <20050804005147.GC4255@us.ibm.com>

On 03.08.2005 [17:51:47 -0700], Nishanth Aravamudan wrote:
> On 03.08.2005 [16:20:57 +0200], Roman Zippel wrote:
> > Hi,
> > 
> > On Mon, 1 Aug 2005, Nishanth Aravamudan wrote:
> > 
> > > +unsigned int __sched schedule_timeout_msecs(unsigned int timeout_msecs)
> > > +{
> > > +	unsigned long expire_jifs;
> > > +
> > > +	if (timeout_msecs == MAX_SCHEDULE_TIMEOUT_MSECS) {
> > > +		expire_jifs = MAX_SCHEDULE_TIMEOUT;
> > > +	} else {
> > > +		/*
> > > +		 * msecs_to_jiffies() is a unit conversion, which truncates
> > > +		 * (rounds down), so we need to add 1.
> > > +		 */
> > > +		expire_jifs = msecs_to_jiffies(timeout_msecs) + 1;
> > > +	}
> > > +
> > > +	expire_jifs = schedule_timeout(expire_jifs);
> > > +
> > > +	/*
> > > +	 * don't need to add 1 here, even though there is truncation,
> > > +	 * because we will add 1 if/when the value is sent back in
> > > +	 */
> > > +	return jiffies_to_msecs(expire_jifs);
> > > +}
> > 
> > As I already mentioned for msleep_interruptible this is a really terrible 
> > interface.
> > The "jiffies_to_msecs(msecs_to_jiffies(timeout_msecs) + 1)" case (when the 
> > process is immediately woken up again) makes the caller suspectible to 
> > timeout manipulations and requires constant reauditing, that no caller 
> > gets it wrong, so it's better to avoid this error source completely.
> 
> After some thought today, I realized the +1 case is not specific to
> milliseconds. It's just that it's only being done *correctly* in the
> milliseconds case...I think ;)

<snip>

> Description: Ensure that schedule_timeout() requests can not possibly
> expire early in the timeout case, by adding the requested relative jiffy
> value to the next value of jiffies. Currently, by adding to the current
> value of jiffies, we might actually expire a jiffy too early (in a
> corner case).

Sorry, I forgot that sys_nanosleep() also always adds 1 to the request
(to account for this same issue, I believe, as POSIX demands no early
return from nanosleep() calls). There are some other locations where
similar

	+ (t.tv_sec || t.tv_nsec)

rounding-ups occur. I'll fix those separately if this patch goes in.  I
change the one in sys_nanosleep() below to maintain the same latency as
we currently have. I also screwed up my layout in the previous
submission, sorry about that.

Description: Ensure that schedule_timeout() requests can not possibly
expire early in the timeout case, by adding the requested relative jiffy
value to the next value of jiffies. Currently, by adding to the current
value of jiffies, we might actually expire a jiffy too early (in a
corner case). Modify the callers of schedule_timeout() in timer.c to not
add 1 themselves.

Signed-off-by: Nishanth Aravamudan <nacc@us.ibm.com>

---

 timer.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)

--- 2.6.13-rc4-dev/kernel/timer.c	2005-08-01 12:31:53.000000000 -0700
+++ 2.6.13-rc5/kernel/timer.c	2005-08-03 22:05:16.000000000 -0700
@@ -1134,7 +1134,7 @@ fastcall signed long __sched schedule_ti
 		}
 	}
 
-	expire = timeout + jiffies;
+	expire = timeout + jiffies + 1;
 
 	init_timer(&timer);
 	timer.expires = expire;
@@ -1190,9 +1190,10 @@ unsigned int __sched schedule_timeout_ms
 	} else {
 		/*
 		 * msecs_to_jiffies() is a unit conversion, which truncates
-		 * (rounds down), so we need to add 1.
+		 * (rounds down), so we need to add 1, but this is taken
+		 * care of by schedule_timeout() now.
 		 */
-		expire_jifs = msecs_to_jiffies(timeout_msecs) + 1;
+		expire_jifs = msecs_to_jiffies(timeout_msecs);
 	}
 
 	expire_jifs = schedule_timeout(expire_jifs);
@@ -1286,7 +1287,7 @@ asmlinkage long sys_nanosleep(struct tim
 	if ((t.tv_nsec >= 1000000000L) || (t.tv_nsec < 0) || (t.tv_sec < 0))
 		return -EINVAL;
 
-	expire = timespec_to_jiffies(&t) + (t.tv_sec || t.tv_nsec);
+	expire = timespec_to_jiffies(&t);
 	current->state = TASK_INTERRUPTIBLE;
 	expire = schedule_timeout(expire);
 
@@ -1675,7 +1676,7 @@ unregister_time_interpolator(struct time
  */
 void msleep(unsigned int msecs)
 {
-	unsigned long timeout = msecs_to_jiffies(msecs) + 1;
+	unsigned long timeout = msecs_to_jiffies(msecs);
 
 	while (timeout) {
 		set_current_state(TASK_UNINTERRUPTIBLE);
@@ -1691,7 +1692,7 @@ EXPORT_SYMBOL(msleep);
  */
 unsigned long msleep_interruptible(unsigned int msecs)
 {
-	unsigned long timeout = msecs_to_jiffies(msecs) + 1;
+	unsigned long timeout = msecs_to_jiffies(msecs);
 
 	while (timeout && !signal_pending(current)) {
 		set_current_state(TASK_INTERRUPTIBLE);


  reply	other threads:[~2005-08-04  5:14 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-07 21:31 [patch 1/4] drivers/char/ip2/i2lib.c: replace direct assignment with set_current_state() domen
2005-07-08 23:08 ` Andrew Morton
2005-07-08 23:22   ` Nish Aravamudan
2005-07-23  0:27   ` [PATCH] Add schedule_timeout_{interruptible,uninterruptible}{,_msecs}() interfaces Nishanth Aravamudan
2005-07-23  0:31     ` Arjan van de Ven
2005-07-23  1:08       ` [UPDATE PATCH] Add schedule_timeout_{interruptible,uninterruptible}_msecs() interfaces Nishanth Aravamudan
2005-07-23  2:30         ` Andrew Morton
2005-07-23 16:23           ` Nishanth Aravamudan
2005-07-23 10:50       ` [PATCH] Add schedule_timeout_{interruptible,uninterruptible}{,_msecs}() interfaces Roman Zippel
2005-07-23 11:09         ` Arjan van de Ven
2005-07-23 11:55           ` Roman Zippel
2005-07-23 12:51             ` Arjan van de Ven
2005-07-23 13:04               ` Roman Zippel
2005-07-23 13:12                 ` Arjan van de Ven
2005-07-23 13:29                   ` Roman Zippel
2005-07-23 13:32                     ` Arjan van de Ven
2005-07-23 15:56                       ` Roman Zippel
2005-07-23 16:44                     ` Nishanth Aravamudan
2005-07-23 16:43                 ` Nishanth Aravamudan
2005-07-23 17:17                   ` Roman Zippel
2005-07-23 19:10                     ` Nishanth Aravamudan
2005-07-23 20:12                       ` Roman Zippel
2005-07-27 22:29                         ` Nishanth Aravamudan
2005-07-30 23:35                           ` Roman Zippel
2005-08-01 19:35                             ` [UPDATE PATCH] Add schedule_timeout_{intr,unintr}{,_msecs}() interfaces Nishanth Aravamudan
2005-08-03 14:20                               ` Roman Zippel
2005-08-04  0:51                                 ` [PATCH] push rounding up of relative request to schedule_timeout() Nishanth Aravamudan
2005-08-04  5:14                                   ` Nishanth Aravamudan [this message]
2005-08-04 16:45                                     ` [UPDATE PATCH] " George Anzinger
2005-08-04 18:48                                       ` Nish Aravamudan
2005-08-16 23:05                                       ` Nishanth Aravamudan
2005-08-17  0:39                                         ` George Anzinger
2005-08-17  5:56                                           ` Nishanth Aravamudan
2005-08-17 19:51                                             ` George Anzinger
2005-08-17 22:24                                               ` Nishanth Aravamudan
2005-08-04 17:05                                     ` George Anzinger
2005-08-04 18:49                                       ` Nish Aravamudan
2005-08-04  9:38                                   ` [PATCH] " Roman Zippel
2005-08-04 14:33                                     ` Nishanth Aravamudan
2005-08-04 18:59                                       ` Roman Zippel
2005-08-04 19:11                                         ` Nishanth Aravamudan
2005-08-04 23:20                                           ` Roman Zippel
2005-08-04 17:08                                     ` Andrew Morton
2005-08-04 19:00                                       ` [PATCH] add schedule_timeout_{,un}intr() interfaces Nishanth Aravamudan
2005-08-05  7:38                                         ` Andrew Morton
2005-07-23 16:37             ` [PATCH] Add schedule_timeout_{interruptible,uninterruptible}{,_msecs}() interfaces Nishanth Aravamudan
2005-07-23 17:01               ` Roman Zippel
2005-07-23 19:06                 ` Nishanth Aravamudan
2005-07-23 20:22                   ` Roman Zippel
2005-07-23 16:30         ` Nishanth Aravamudan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050804051434.GA4520@us.ibm.com \
    --to=nacc@us.ibm.com \
    --cc=akpm@osdl.org \
    --cc=arjan@infradead.org \
    --cc=clucas@rotomalug.org \
    --cc=domen@coderock.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=zippel@linux-m68k.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox