Re: [PATCH] Staircase scheduler v7.4

From: Peter Williams
Date: Sun Jun 27 2004 - 18:52:18 EST


Con Kolivas wrote:
On Sun, 27 Jun 2004, Con Kolivas wrote:


Ok I found a problem which alost certainly is responsible in the conversion from nanoseconds to Hz and may if you're unlucky give a blank timeslice. Can you try this (against staircase7.4). I'm almost certain it's responsbile.


Hmm that will be the problem but that may not compile because of the darn long long division thingy. I'll get a clean patch to you later on that does the same thing, sorry.

Here's a routine that I use for unsigned 64 bit divides. This is theoretically correct and (just to make sure :-)) thoroughly tested in a user space test program against a proper 64 bit divide. It can't be used to initialize static variables but that's OK because the compiler can do the 64 bit arithmetic itself to correctly initialize them.

static inline unsigned long long sched_div_64(unsigned long long a, unsigned long long b)
{
#if BITS_PER_LONG < 64
/*
* Assume that there's no 64 bit divide available
*/
if (a < b)
return 0;
/*
* Scale down until b less than 32 bits so that we can do
* a divide using do_div() (see div64.h).
*/
while (b > ULONG_MAX) { a >>= 1; b >>= 1; }

(void)do_div(a, (unsigned long)b);

return a;
#else
return a / b;
#endif
}

Peter
PS If we knew the calling conventions for the library routines (__udivdi3, etc.) that the compiler tries to use to do 64 bit divides we could implement them in the kernel (where necessary) and 64 bit divide problems would become a thing of the past.
--
Peter Williams pwil3058@xxxxxxxxxxxxxx

"Learning, n. The kind of ignorance distinguishing the studious."
-- Ambrose Bierce

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/