mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jesper Juhl <juhl-lkml@dif.dk>
To: Nick Piggin <nickpiggin@yahoo.com.au>
Cc: Ingo Molnar <mingo@elte.hu>, Robert Love <rml@tech9.net>,
	Linus Torvalds <torvalds@osdl.org>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] sched: fix never executed code due to expression always false
Date: Fri, 15 Apr 2005 02:23:31 +0200 (CEST)	[thread overview]
Message-ID: <Pine.LNX.4.62.0504150222390.3466@dragon.hyggekrogen.localhost> (raw)
In-Reply-To: <425F0735.6010407@yahoo.com.au>

On Fri, 15 Apr 2005, Nick Piggin wrote:

> Jesper Juhl wrote:
> > On Fri, 15 Apr 2005, Nick Piggin wrote:
> > 
> > 
> > > Jesper Juhl wrote:
> > > 
> > > > There are two expressions in kernel/sched.c that are always false since
> > > > they
> > > > test for <0 but the result of the expression is unsigned so they will
> > > > never
> > > > be less than zero. This patch implement the logic that I believe is
> > > > intended
> > > > without the signedness issue and without the nasty casts.
> > > > <disclaimer>patch is compile tested only</disclaimer>
> > > > 
> > > This is not *quite* the intended behaviour. It is OK for prev->timestamp
> > > to be '0 - a bit' and now to be '0 + a bit' in the case of wrapping.
> > > 
> > > Although considering they're 64-bit values, I'm not sure how much we care.
> > > 
> > 
> > How do you propose to fix this then?  As the code is now the expressionsa
> > are always false - should we just remove the them?  Or do you have a
> > sensible definition of "a bit" ?  or ome other suggestion alltogether?
> > 
> 
> Make it a signed comparison?
> 
As per this patch perhaps? : 

Signed-off-by: Jesper Juhl <juhl-lkml@dif.dk>

--- linux-2.6.12-rc2-mm3-orig/kernel/sched.c	2005-04-11 21:20:56.000000000 +0200
+++ linux-2.6.12-rc2-mm3/kernel/sched.c	2005-04-15 02:21:34.000000000 +0200
@@ -2697,9 +2697,10 @@ need_resched_nonpreemptible:
 	schedstat_inc(rq, sched_cnt);
 	now = sched_clock();
 	if (likely((long long)now - prev->timestamp < NS_MAX_SLEEP_AVG)) {
-		run_time = now - prev->timestamp;
-		if (unlikely((long long)now - prev->timestamp < 0))
+		if (unlikely(((long long)now - (long long)prev->timestamp) < 0))
 			run_time = 0;
+		else
+			run_time = now - prev->timestamp;
 	} else
 		run_time = NS_MAX_SLEEP_AVG;
 
@@ -2776,7 +2777,7 @@ go_idle:
 
 	if (!rt_task(next) && next->activated > 0) {
 		unsigned long long delta = now - next->timestamp;
-		if (unlikely((long long)now - next->timestamp < 0))
+		if (unlikely(((long long)now - (long long)next->timestamp) < 0))
 			delta = 0;
 
 		if (next->activated == 1)



  reply	other threads:[~2005-04-15  0:23 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-14 23:49 Jesper Juhl
2005-04-15  0:09 ` Nick Piggin
2005-04-15  0:14   ` Jesper Juhl
2005-04-15  0:13     ` Nick Piggin
2005-04-15  0:23       ` Jesper Juhl [this message]
2005-04-15  0:23         ` Nick Piggin
2005-04-15  2:32           ` Matt Mackall
2005-04-15  2:59         ` Herbert Xu
2005-04-15  3:25           ` Nick Piggin
2005-04-15  7:58         ` Ingo Molnar
2005-04-16 13:54           ` Jesper Juhl

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=Pine.LNX.4.62.0504150222390.3466@dragon.hyggekrogen.localhost \
    --to=juhl-lkml@dif.dk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=nickpiggin@yahoo.com.au \
    --cc=rml@tech9.net \
    --cc=torvalds@osdl.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

all inboxes | Powered by JetHome®