linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* Re: testing/pre-7 and do_poll()
@ 1999-01-11 12:54 Colin Plumb
  0 siblings, 0 replies; 13+ messages in thread
From: Colin Plumb @ 1999-01-11 12:54 UTC (permalink / raw)
  To: chip; +Cc: linux-kernel, linux-mm

Chip Salzenberg wrote:
> Well, I forgot the (unsigned long) cast, as someone else noted:

>	timeout = ROUND_UP((unsigned long) timeout, 1000/HZ);

>
> Otherwise, the code is Just Right.

Um, this works perfectly when HZ == 100, but consider what happens when
HZ == 1024.  1000/HZ == 0, and then computing (x+0-1)/0 doesn't work so well.

If you want accuracy with no danger of overflow, try the following trick:

	ticks = (msec/1000)*HZ + (msec%1000)*HZ/1000.

To make this more efficient, use that only on large values of msec,
and the simpler (msec*HZ)/1000.  In thhe HZ > 1000 case, you also lose
the guarantee that every legal msec value corresponds to a 

(C experts will note that none of the parens are necessary, but I though
it was clearer to include them.)

So, for perfection, you want:

unsigned long msec_to_ticks(unsigned long msec)
{
	if (msec <= ULONG_MAX/HZ)
		return msec*HZ/1000;
#if HZ > 1000
	/* Wups, can overflow - saturate return value */
	if (msec > (ULONG_MAX/HZ)*1000 + (ULONG_MAX % HZ)*1000/HZ)
		return ULONG_MAX
#endif
	return (msec/1000)*HZ + (msec%1000)*HZ/1000;
}

Um... this is the rounding-down case, and also saturates at ULONG_MAX
instead of MAX_SCHEDULE_TIMEOUT (LONG_MAX).  Let me adjust the boundary
cases a bit...

#if MAX_SCHEDULE_TIMEOUT != LONG_MAX
#error Adjust this code - it assumes identical input and output ranges
#endif
unsigned long msec_to_ticks(unsigned long msec)
{
	if (msec < ULONG_MAX/HZ - 999)
		return (msec+999)*HZ/1000;
	msec--;	/* Following code rounds up and adds one */
#if HZ > 1000
	/* Wups, can overflow - saturate return value */
	if (msec >= (ULONG_MAX/HZ)*1000 + (ULONG_MAX % HZ)*1000/HZ)
		return MAX_SCHEDULE_TIMEOUT;
#endif
	return (msec/1000)*HZ + (msec%1000)*HZ/1000 + 1;
}
-- 
	-Colin
--
This is a majordomo managed list.  To unsubscribe, send a message with
the body 'unsubscribe linux-mm me@address' to: majordomo@kvack.org

^ permalink raw reply	[flat|nested] 13+ messages in thread
* Re: Results: pre6 vs pre6+zlatko's_patch  vs pre5 vs arcavm13
@ 1999-01-10 20:29 Steve Bergman
  1999-01-10 21:41 ` Linus Torvalds
  0 siblings, 1 reply; 13+ messages in thread
From: Steve Bergman @ 1999-01-10 20:29 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: Andrea Arcangeli, brent verner, Garst R. Reese, Kalle Andersson,
	Zlatko Calusic, Ben McCann, bredelin, linux-kernel, linux-mm,
	Alan Cox, Stephen C. Tweedie

Linus Torvalds wrote:

> The logic for that would be something like the attached patch to
> page_alloc.c..


I tried the patch in the 'image test' and it helped little if any.  Still a lot
of swapping in and the numbers are close enough that I'm not sure it helped at
all.  This was a comparison between vanilla pre6 and vanilla
pre6+page_alloc_patch with no other patches applied.

-Steve
--
This is a majordomo managed list.  To unsubscribe, send a message with
the body 'unsubscribe linux-mm me@address' to: majordomo@kvack.org

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

end of thread, other threads:[~1999-01-12  8:26 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-01-11 12:54 testing/pre-7 and do_poll() Colin Plumb
  -- strict thread matches above, loose matches on Subject: below --
1999-01-10 20:29 Results: pre6 vs pre6+zlatko's_patch vs pre5 vs arcavm13 Steve Bergman
1999-01-10 21:41 ` Linus Torvalds
1999-01-10 23:33   ` testing/pre-7 and do_poll() Chip Salzenberg
1999-01-11  6:02     ` Linus Torvalds
1999-01-11  6:26       ` Chip Salzenberg
1999-01-11  6:46         ` Linus Torvalds
1999-01-11  6:59           ` Chip Salzenberg
1999-01-11  7:02             ` Linus Torvalds
1999-01-11 22:08               ` Shawn Leas
1999-01-11 22:13                 ` Linus Torvalds
1999-01-12  0:25                   ` estafford
1999-01-12  8:25                     ` Shawn Leas
1999-01-12  7:06                   ` Gregory Maxwell
1999-01-11 20:20     ` Adam Heath

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox