alistair23-linux/include/asm-m32r
H. Peter Anvin bdc807871d avoid overflows in kernel/time.c
When the conversion factor between jiffies and milli- or microseconds is
not a single multiply or divide, as for the case of HZ == 300, we currently
do a multiply followed by a divide.  The intervening result, however, is
subject to overflows, especially since the fraction is not simplified (for
HZ == 300, we multiply by 300 and divide by 1000).

This is exposed to the user when passing a large timeout to poll(), for
example.

This patch replaces the multiply-divide with a reciprocal multiplication on
32-bit platforms.  When the input is an unsigned long, there is no portable
way to do this on 64-bit platforms there is no portable way to do this
since it requires a 128-bit intermediate result (which gcc does support on
64-bit platforms but may generate libgcc calls, e.g.  on 64-bit s390), but
since the output is a 32-bit integer in the cases affected, just simplify
the multiply-divide (*3/10 instead of *300/1000).

The reciprocal multiply used can have off-by-one errors in the upper half
of the valid output range.  This could be avoided at the expense of having
to deal with a potential 65-bit intermediate result.  Since the intent is
to avoid overflow problems and most of the other time conversions are only
semiexact, the off-by-one errors were considered an acceptable tradeoff.

At Ralf Baechle's suggestion, this version uses a Perl script to compute
the necessary constants.  We already have dependencies on Perl for kernel
compiles.  This does, however, require the Perl module Math::BigInt, which
is included in the standard Perl distribution starting with version 5.8.0.
In order to support older versions of Perl, include a table of canned
constants in the script itself, and structure the script so that
Math::BigInt isn't required if pulling values from said table.

Running the script requires that the HZ value is available from the
Makefile.  Thus, this patch also adds the Kconfig variable CONFIG_HZ to the
architectures which didn't already have it (alpha, cris, frv, h8300, m32r,
m68k, m68knommu, sparc, v850, and xtensa.) It does *not* touch the sh or
sh64 architectures, since Paul Mundt has dealt with those separately in the
sh tree.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Cc: Ralf Baechle <ralf@linux-mips.org>,
Cc: Sam Ravnborg <sam@ravnborg.org>,
Cc: Paul Mundt <lethal@linux-sh.org>,
Cc: Richard Henderson <rth@twiddle.net>,
Cc: Michael Starvik <starvik@axis.com>,
Cc: David Howells <dhowells@redhat.com>,
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>,
Cc: Hirokazu Takata <takata@linux-m32r.org>,
Cc: Geert Uytterhoeven <geert@linux-m68k.org>,
Cc: Roman Zippel <zippel@linux-m68k.org>,
Cc: William L. Irwin <sparclinux@vger.kernel.org>,
Cc: Chris Zankel <chris@zankel.net>,
Cc: H. Peter Anvin <hpa@zytor.com>,
Cc: Jan Engelhardt <jengelh@computergmbh.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-02-08 09:22:39 -08:00
..
m32104ut [PATCH] m32r: cosmetic updates and trivial fixes 2007-02-11 10:51:20 -08:00
m32700ut m32r: remove dead config symbols from M32R code 2008-02-05 09:44:08 -08:00
mappi2 [PATCH] m32r: cosmetic updates and trivial fixes 2007-02-11 10:51:20 -08:00
mappi3 [PATCH] m32r: cosmetic updates and trivial fixes 2007-02-11 10:51:20 -08:00
opsput [PATCH] m32r: cosmetic updates and trivial fixes 2007-02-11 10:51:20 -08:00
a.out.h aout: move STACK_TOP[_MAX] to asm/processor.h 2008-02-08 09:22:29 -08:00
addrspace.h [PATCH] m32r: cosmetic updates and trivial fixes 2007-02-11 10:51:20 -08:00
assembler.h m32r: Rename STI/CLI macros 2007-09-06 11:10:56 +09:00
atomic.h atomic.h: atomic_add_unless as inline. Remove system.h atomic.h circular dependency 2007-05-08 11:15:20 -07:00
auxvec.h
bitops.h forbid asm/bitops.h direct inclusion 2007-10-19 11:53:41 -07:00
bug.h
bugs.h [PATCH] m32r: cosmetic updates and trivial fixes 2007-02-11 10:51:20 -08:00
byteorder.h [PATCH] m32r: cosmetic updates and trivial fixes 2007-02-11 10:51:20 -08:00
cache.h [PATCH] m32r: cosmetic updates and trivial fixes 2007-02-11 10:51:20 -08:00
cachectl.h
cacheflush.h [PATCH] m32r: cosmetic updates and trivial fixes 2007-02-11 10:51:20 -08:00
checksum.h [NET]: M32R checksum annotations and cleanups. 2006-12-02 21:23:06 -08:00
cputime.h
current.h [PATCH] m32r: cosmetic updates and trivial fixes 2007-02-11 10:51:20 -08:00
delay.h Fix __const_udelay declaration and definition mismatches 2008-02-06 10:41:06 -08:00
device.h Driver core: add dev_archdata to struct device 2006-12-01 14:52:01 -08:00
div64.h
dma.h [PATCH] m32r: cosmetic updates and trivial fixes 2007-02-11 10:51:20 -08:00
elf.h Cleanup asm/{elf,page,user}.h: #ifdef __KERNEL__ is no longer needed 2008-02-07 08:42:30 -08:00
emergency-restart.h
errno.h [PATCH] m32r: cosmetic updates and trivial fixes 2007-02-11 10:51:20 -08:00
fb.h fbdev: detect primary display device 2007-07-17 10:23:11 -07:00
fcntl.h
flat.h Binfmt_flat: Add minimum support for the Blackfin relocations 2007-10-03 23:41:43 +08:00
futex.h [PATCH] consolidate asm/futex.h 2006-01-08 20:13:39 -08:00
hardirq.h Don't include linux/config.h from anywhere else in include/ 2006-04-26 12:56:16 +01:00
hw_irq.h [PATCH] genirq: add ->retrigger() irq op to consolidate hw_irq_resend() 2006-06-29 10:26:23 -07:00
ide.h ide: add CONFIG_IDE_ARCH_OBSOLETE_INIT 2007-10-20 00:32:32 +02:00
io.h [PATCH] Consolidate check_signature 2006-10-11 11:14:23 -07:00
ioctl.h [PATCH] Generic ioctl.h 2006-01-10 08:01:34 -08:00
ioctls.h m32r: enable arbitary speed tty rate setting 2007-07-16 09:05:38 -07:00
ipcbuf.h [PATCH] m32r: cosmetic updates and trivial fixes 2007-02-11 10:51:20 -08:00
irq.h m32r: remove dead config symbols from M32R code 2008-02-05 09:44:08 -08:00
irq_regs.h [PATCH] m32r pt_regs fixes 2006-10-07 10:51:15 -07:00
Kbuild Add empty Kbuild files for 'make headers_install' in remaining arches. 2006-06-18 12:58:53 +01:00
kdebug.h move die notifier handling to common code 2007-05-08 11:15:04 -07:00
kmap_types.h [PATCH] m32r: cosmetic updates and trivial fixes 2007-02-11 10:51:20 -08:00
linkage.h
local.h local_t m32r use architecture specific cmpxchg_local 2008-02-07 08:42:32 -08:00
m32r.h m32r: Define symbols to unify platform-dependent ICU checks 2007-09-03 11:30:18 +09:00
m32r_mp_fpga.h
m32102.h [PATCH] m32r: support a synthesizable M32700 core 2006-12-08 08:28:37 -08:00
mc146818rtc.h [PATCH] m32r: cosmetic updates and trivial fixes 2007-02-11 10:51:20 -08:00
mman.h [PATCH] m32r: cosmetic updates and trivial fixes 2007-02-11 10:51:20 -08:00
mmu.h [PATCH] m32r: cosmetic updates and trivial fixes 2007-02-11 10:51:20 -08:00
mmu_context.h [PATCH] x86: PARAVIRT: add hooks to intercept mm creation and destruction 2007-05-02 19:27:14 +02:00
mmzone.h [PATCH] unify pfn_to_page: m32r pfn_to_page 2006-03-27 08:44:45 -08:00
module.h [PATCH] m32r: cosmetic updates and trivial fixes 2007-02-11 10:51:20 -08:00
msgbuf.h [PATCH] m32r: cosmetic updates and trivial fixes 2007-02-11 10:51:20 -08:00
mutex.h [PATCH] mutex subsystem, add default include/asm-*/mutex.h files 2006-01-09 15:59:19 -08:00
namei.h [PATCH] m32r: cosmetic updates and trivial fixes 2007-02-11 10:51:20 -08:00
page.h Cleanup asm/{elf,page,user}.h: #ifdef __KERNEL__ is no longer needed 2008-02-07 08:42:30 -08:00
param.h avoid overflows in kernel/time.c 2008-02-08 09:22:39 -08:00
pci.h [PATCH] m32r: cosmetic updates and trivial fixes 2007-02-11 10:51:20 -08:00
percpu.h
pgalloc.h add mm argument to pte/pmd/pud/pgd_free 2008-02-05 09:44:18 -08:00
pgtable-2level.h m32r: fix pte_to_pgoff(), pgoff_to_pte() and __swp_type() macros 2007-05-11 08:29:33 -07:00
pgtable.h remove asm/bitops.h includes 2007-10-19 11:53:41 -07:00
poll.h Consolidate asm/poll.h 2007-05-11 08:29:34 -07:00
posix_types.h asm-*/posix_types.h: scrub __GLIBC__ 2008-02-08 09:22:34 -08:00
processor.h aout: move STACK_TOP[_MAX] to asm/processor.h 2008-02-08 09:22:29 -08:00
ptrace.h m32r: convert to generic sys_ptrace 2007-10-16 09:43:04 -07:00
resource.h
rtc.h [PATCH] m32r: cosmetic updates and trivial fixes 2007-02-11 10:51:20 -08:00
s1d13806.h
scatterlist.h Add CONFIG_DEBUG_SG sg validation 2007-10-22 21:20:03 +02:00
sections.h [PATCH] m32r: cosmetic updates and trivial fixes 2007-02-11 10:51:20 -08:00
segment.h [PATCH] m32r: cosmetic updates and trivial fixes 2007-02-11 10:51:20 -08:00
semaphore.h kill DECLARE_MUTEX_LOCKED 2007-10-17 08:42:47 -07:00
sembuf.h [PATCH] m32r: cosmetic updates and trivial fixes 2007-02-11 10:51:20 -08:00
serial.h Don't include linux/config.h from anywhere else in include/ 2006-04-26 12:56:16 +01:00
setup.h [PATCH] m32r: cosmetic updates and trivial fixes 2007-02-11 10:51:20 -08:00
shmbuf.h [PATCH] m32r: cosmetic updates and trivial fixes 2007-02-11 10:51:20 -08:00
shmparam.h [PATCH] m32r: cosmetic updates and trivial fixes 2007-02-11 10:51:20 -08:00
sigcontext.h [PATCH] m32r: cosmetic updates and trivial fixes 2007-02-11 10:51:20 -08:00
siginfo.h [PATCH] m32r: cosmetic updates and trivial fixes 2007-02-11 10:51:20 -08:00
signal.h core: remove last users of empty FASTCALL macro 2008-01-30 13:31:17 +01:00
smp.h Remove hardcoding of hard_smp_processor_id on UP systems 2007-05-09 12:30:48 -07:00
socket.h [NET]: Introducing socket mark socket option. 2008-01-31 19:27:19 -08:00
sockios.h [NET]: Introduce SIOCGSTAMPNS ioctl to get timestamps with nanosec resolution 2007-04-25 22:24:04 -07:00
spinlock.h [PATCH] Directed yield: cpu_relax variants for spinlocks and rw-locks 2006-10-01 00:39:21 -07:00
spinlock_types.h [PATCH] m32r: cosmetic updates and trivial fixes 2007-02-11 10:51:20 -08:00
stat.h [PATCH] m32r: cosmetic updates and trivial fixes 2007-02-11 10:51:20 -08:00
statfs.h
string.h [PATCH] m32r: cosmetic updates and trivial fixes 2007-02-11 10:51:20 -08:00
syscall.h [PATCH] m32r: cosmetic updates and trivial fixes 2007-02-11 10:51:20 -08:00
system.h Fix m32r __xchg 2008-02-07 08:42:32 -08:00
termbits.h m32r: enable arbitary speed tty rate setting 2007-07-16 09:05:38 -07:00
termios.h m32r: enable arbitary speed tty rate setting 2007-07-16 09:05:38 -07:00
thread_info.h m32r: Update sys_rt_sigsuspend 2007-11-28 01:24:04 +09:00
timex.h [PATCH] m32r: cosmetic updates and trivial fixes 2007-02-11 10:51:20 -08:00
tlb.h
tlbflush.h remove unused flush_tlb_pgtables 2007-10-19 11:53:34 -07:00
topology.h
types.h remove strict ansi check from __u64 in asm/types.h 2007-10-17 08:42:53 -07:00
uaccess.h [PATCH] fix sparse warnings from {asm,net}/checksum.h 2007-02-11 10:51:31 -08:00
ucontext.h [PATCH] m32r: cosmetic updates and trivial fixes 2007-02-11 10:51:20 -08:00
unaligned.h [PATCH] m32r: cosmetic updates and trivial fixes 2007-02-11 10:51:20 -08:00
unistd.h timerfd: fix remaining architectures 2008-02-05 14:37:15 -08:00
user.h Sanitize the type of struct user.u_ar0 2008-02-07 08:42:30 -08:00
vga.h [PATCH] m32r: cosmetic updates and trivial fixes 2007-02-11 10:51:20 -08:00
xor.h [PATCH] m32r: cosmetic updates and trivial fixes 2007-02-11 10:51:20 -08:00