Re: [PATCH] bring sanity to div64.h and do_div usage

From: Maciej W. Rozycki (macro@ds2.pg.gda.pl)
Date: Fri Feb 08 2002 - 13:49:30 EST


On Fri, 8 Feb 2002, Troy Benjegerdes wrote:

> Several people I have talked to on the issue specifically asked for the
> panic(), as people using do_div() should really know better than to do 64
> bit divides in the kernel.

 There are legitimate cases where you cannot avoid a double-precision
division and the inefficiency is negligible. For example for MIPS it's
used in do_*_gettimeoffset() and at most once a jiffy (actually we use
do_div64_32() to reduce work, as we know the quotient will *always* fit in
32 bits).

> The generic C algorithm only handles base < 65536.
>
> I can think of a couple ways around this..
>
> 1) Make the base argument be a 'u16 base', and people with too large a
> base would get compile warnings/errors.
>
> 2) run-time check on base, and panic if too large
>
> 3) run-time check on base, print dmesg warning if too large

 4) Use a generic division algorithm using shifts and subtracts such as
one of these described in academic books. You may port the implementation
from include/asm-mips/div64.h. ;-)

Note that in do_*_gettimeoffset() the divisor is an arbitrary 32-bit
number, mostly depending on the uptime.

-- 
+  Maciej W. Rozycki, Technical University of Gdansk, Poland   +
+--------------------------------------------------------------+
+        e-mail: macro@ds2.pg.gda.pl, PGP key available        +

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



This archive was generated by hypermail 2b29 : Fri Feb 15 2002 - 21:00:20 EST