linux/include/asm-xtensa
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
..
platform-iss fix file specification in comments 2007-05-09 08:58:16 +02:00
variant-fsf
a.out.h aout: move STACK_TOP[_MAX] to asm/processor.h 2008-02-08 09:22:29 -08:00
asmmacro.h
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
bootparam.h
bug.h
bugs.h [XTENSA] Remove extraneous include statement 2007-08-27 13:53:27 -07:00
byteorder.h [XTENSA] clean-up header files 2007-05-31 17:47:01 -07:00
cache.h [XTENSA] Add support for cache-aliasing 2007-08-27 13:54:16 -07:00
cacheasm.h
cacheflush.h [XTENSA] Add support for cache-aliasing 2007-08-27 13:54:16 -07:00
checksum.h
coprocessor.h [XTENSA] Remove non-rt signal handling 2007-05-31 17:49:32 -07:00
cpumask.h
cputime.h
current.h
delay.h
device.h
div64.h [XTENSA] Use generic 64-bit division 2007-05-31 17:46:09 -07:00
dma-mapping.h xtensa: dma-mapping.h is using linux/scatterlist.h functions, so include it 2007-10-24 13:28:40 +02:00
dma.h
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
fb.h fbdev: detect primary display device 2007-07-17 10:23:11 -07:00
fcntl.h Xtensa: use asm-generic/fcntl.h 2007-05-31 20:18:25 -07:00
futex.h
hardirq.h
highmem.h
hw_irq.h
ide.h
io.h [XTENSA] Add support for cache-aliasing 2007-08-27 13:54:16 -07:00
ioctl.h
ioctls.h [patch 1/2] Xtensa: enable arbitary tty speed setting ioctls 2007-08-27 13:54:25 -07:00
ipcbuf.h
irq_regs.h
irq.h
Kbuild
kdebug.h move die notifier handling to common code 2007-05-08 11:15:04 -07:00
kmap_types.h
linkage.h
local.h
mman.h [PATCH] Remove final references to deprecated "MAP_ANON" page protection flag 2007-02-11 10:51:17 -08:00
mmu_context.h [XTENSA] clean-up header files 2007-05-31 17:47:01 -07:00
mmu.h
module.h
msgbuf.h
mutex.h
namei.h
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-bridge.h
pci.h PCI: remove pci_dac_dma_... APIs 2007-07-11 16:02:11 -07:00
percpu.h
pgalloc.h add mm argument to pte/pmd/pud/pgd_free 2008-02-05 09:44:18 -08:00
pgtable.h [XTENSA] Add support for cache-aliasing 2007-08-27 13:54:16 -07:00
platform.h
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 [XTENSA] Remove non-rt signal handling 2007-05-31 17:49:32 -07:00
regs.h
resource.h
rmap.h
rwsem.h
scatterlist.h Add CONFIG_DEBUG_SG sg validation 2007-10-22 21:20:03 +02:00
sections.h
segment.h
semaphore.h kill DECLARE_MUTEX_LOCKED 2007-10-17 08:42:47 -07:00
sembuf.h
serial.h
setup.h
shmbuf.h
shmparam.h [XTENSA] clean-up header files 2007-05-31 17:47:01 -07:00
sigcontext.h [XTENSA] Remove non-rt signal handling 2007-05-31 17:49:32 -07:00
siginfo.h
signal.h
smp.h
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
stat.h
statfs.h
string.h
syscall.h [XTENSA] Fix fadvise64_64 2007-08-27 13:53:32 -07:00
system.h Add cmpxchg_local to xtensa 2008-02-07 08:42:33 -08:00
termbits.h [patch 1/2] Xtensa: enable arbitary tty speed setting ioctls 2007-08-27 13:54:25 -07:00
termios.h [patch 1/2] Xtensa: enable arbitary tty speed setting ioctls 2007-08-27 13:54:25 -07:00
thread_info.h remove unused TIF_NOTIFY_RESUME flag 2007-07-31 15:39:38 -07:00
timex.h [XTENSA] Fix timer instabilities. 2007-08-27 13:53:37 -07:00
tlb.h add mm argument to pte/pmd/pud/pgd_free 2008-02-05 09:44:18 -08:00
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
ucontext.h
unaligned.h
unistd.h [XTENSA] Fix fadvise64_64 2007-08-27 13:53:32 -07:00
user.h
vga.h
xor.h