linux/include/asm-m68knommu
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
..
Kbuild Add empty Kbuild files for 'make headers_install' in remaining arches. 2006-06-18 12:58:53 +01:00
MC68EZ328.h [PATCH] __attribute__ placement fixes 2005-05-01 08:59:09 -07:00
MC68VZ328.h [PATCH] __attribute__ placement fixes 2005-05-01 08:59:09 -07:00
MC68328.h [PATCH] __attribute__ placement fixes 2005-05-01 08:59:09 -07:00
MC68332.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
a.out.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
anchor.h [PATCH] m68knommu: use board name defines to differentiate board definitions 2005-11-01 21:41:19 -08: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 [PATCH] auxiliary vector cleanups 2005-09-07 16:57:21 -07:00
bitops.h include/asm-m68knommu/: Spelling fixes 2008-02-03 17:38:04 +02:00
bootinfo.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
bootstd.h [PATCH] m68knommu: fix clobber list in uCdimm/uCsimm helper asm 2006-06-28 15:03:47 -07:00
bug.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
bugs.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
byteorder.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
cache.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
cachectl.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
cacheflush.h m68knommu: fix 528x ColdFire cache settings 2008-02-01 21:00:01 +11:00
checksum.h [NET]: M68Knommu checksum annotations and cleanups. 2006-12-02 21:23:08 -08:00
coldfire.h [PATCH] m68knommu: configurable frequency selection header 2006-06-25 21:04:24 -07:00
commproc.h include/asm-m68knommu/: Spelling fixes 2008-02-03 17:38:04 +02:00
cputime.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
current.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
dbg.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
delay.h include/asm-m68knommu/: Spelling fixes 2008-02-03 17:38:04 +02:00
device.h Driver core: add dev_archdata to struct device 2006-12-01 14:52:01 -08:00
div64.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
dma-mapping.h [PATCH] m68knommu: fix dma-mapping.h 2006-12-04 08:28:47 -08:00
dma.h m68knommu: define DMA channels for ColdFire 532x 2007-10-23 20:45:44 -07:00
elf.h Cleanup asm/{elf,page,user}.h: #ifdef __KERNEL__ is no longer needed 2008-02-07 08:42:30 -08:00
elia.h Don't include linux/config.h from anywhere else in include/ 2006-04-26 12:56:16 +01:00
emergency-restart.h [PATCH] Add emergency_restart() 2005-07-26 14:35:41 -07:00
entry.h Don't include linux/config.h from anywhere else in include/ 2006-04-26 12:56:16 +01:00
errno.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
fb.h fbdev: detect primary display device 2007-07-17 10:23:11 -07:00
fcntl.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
flat.h Binfmt_flat: Add minimum support for the Blackfin relocations 2007-10-03 23:41:43 +08:00
fpu.h Don't include linux/config.h from anywhere else in include/ 2006-04-26 12:56:16 +01:00
futex.h [PATCH] consolidate asm/futex.h 2006-01-08 20:13:39 -08:00
hardirq.h m68knommu: add prototype for ack_bad_irq 2007-07-26 11:05:20 -07:00
hw_irq.h m68knommu: create hw_irq.h 2007-07-25 11:05:01 -07:00
hwtest.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
io.h remove mm_{ptov,vtop}() 2008-02-06 10:41:01 -08:00
ioctl.h [PATCH] Generic ioctl.h 2006-01-10 08:01:34 -08:00
ioctls.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
ipcbuf.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
irq.h m68knommu: generic irq handling 2007-07-19 10:04:50 -07:00
irq_regs.h [PATCH] m68knommu: fix up for the irq_handler_t changes 2006-11-20 10:16:49 -08:00
kdebug.h move die notifier handling to common code 2007-05-08 11:15:04 -07:00
kmap_types.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
linkage.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
local.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
m520xsim.h [PATCH] m68knommu: memory register defines for 520x ColdFire CPU's 2006-12-04 08:26:12 -08:00
m523xsim.h Don't include linux/config.h from anywhere else in include/ 2006-04-26 12:56:16 +01:00
m527xsim.h Don't include linux/config.h from anywhere else in include/ 2006-04-26 12:56:16 +01:00
m528xsim.h [PATCH] m68knommu: GPIO line defines for the ColdFire 5282 2007-03-06 18:08:38 -08:00
m532xsim.h [PATCH] m68knommu: ColdFire 532x register definitions 2006-06-25 17:43:33 -07:00
m5206sim.h Don't include linux/config.h from anywhere else in include/ 2006-04-26 12:56:16 +01:00
m5249sim.h include/asm-m68knommu/: Spelling fixes 2008-02-03 17:38:04 +02:00
m5272sim.h Don't include linux/config.h from anywhere else in include/ 2006-04-26 12:56:16 +01:00
m5307sim.h include/asm-m68knommu/: Spelling fixes 2008-02-03 17:38:04 +02:00
m5407sim.h include/asm-m68knommu/: Spelling fixes 2008-02-03 17:38:04 +02:00
m68360.h m68knommu: generic irq handling 2007-07-19 10:04:50 -07:00
m68360_enet.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
m68360_pram.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
m68360_quicc.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
m68360_regs.h include/asm-m68knommu/: Spelling fixes 2008-02-03 17:38:04 +02:00
machdep.h m68knommu: remove unused machdep variable definitions 2007-10-23 20:45:44 -07:00
math-emu.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
mc146818rtc.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
mcfcache.h m68knommu: fix 528x ColdFire cache settings 2008-02-01 21:00:01 +11:00
mcfdma.h m68knommu: fix definition of MCFDMA_DIR_INV 2007-07-25 11:05:01 -07:00
mcfmbus.h Fix misc .c/.h comment typos 2006-11-30 05:24:39 +01:00
mcfne.h m68knomu: remove dead config symbols from m68knomu code 2008-02-05 09:44:21 -08:00
mcfpci.h Don't include linux/config.h from anywhere else in include/ 2006-04-26 12:56:16 +01:00
mcfpit.h [PATCH] m68knommu: read/write register access for PIT timer 2006-06-25 17:43:33 -07:00
mcfsim.h m68knomu: remove dead config symbols from m68knomu code 2008-02-05 09:44:21 -08:00
mcfsmc.h Don't include linux/config.h from anywhere else in include/ 2006-04-26 12:56:16 +01:00
mcftimer.h m68knomu: remove dead config symbols from m68knomu code 2008-02-05 09:44:21 -08:00
mcfuart.h m68knomu: remove dead config symbols from m68knomu code 2008-02-05 09:44:21 -08:00
mcfwdebug.h Don't include linux/config.h from anywhere else in include/ 2006-04-26 12:56:16 +01:00
md.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
mman.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
mmu.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
mmu_context.h [PATCH] x86: PARAVIRT: add hooks to intercept mm creation and destruction 2007-05-02 19:27:14 +02:00
module.h m68knommu: local module/elf definitions 2007-10-23 08:32:07 -07:00
movs.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
msgbuf.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
mutex.h [PATCH] mutex subsystem, add default include/asm-*/mutex.h files 2006-01-09 15:59:19 -08:00
namei.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
nettel.h Don't include linux/config.h from anywhere else in include/ 2006-04-26 12:56:16 +01:00
openprom.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
oplib.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
page.h Cleanup asm/{elf,page,user}.h: #ifdef __KERNEL__ is no longer needed 2008-02-07 08:42:30 -08:00
page_offset.h [PATCH] m68knommu: use configurable RAM setup page_offset.h 2006-06-26 10:59:44 -07:00
param.h avoid overflows in kernel/time.c 2008-02-08 09:22:39 -08:00
pci.h PCI: remove pci_dac_dma_... APIs 2007-07-11 16:02:11 -07:00
percpu.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
pgalloc.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
pgtable.h m68knommu: include asm-generic/pgtable.h 2007-08-23 21:32:54 -07:00
poll.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
posix_types.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
processor.h fix file specification in comments 2006-10-03 23:01:26 +02:00
ptrace.h [PATCH] m68knommu: remove NO_FORMAT_VECi from ptrace.h header 2006-06-27 18:30:14 -07:00
quicc_simple.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
resource.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
rtc.h [PATCH] m68knommu: create rtc.h 2006-12-06 07:41:26 -08:00
scatterlist.h m68knommu: remove sg_address() 2007-10-23 12:42:47 +02:00
sections.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
segment.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
semaphore-helper.h Don't include linux/config.h from anywhere else in include/ 2006-04-26 12:56:16 +01:00
semaphore.h kill DECLARE_MUTEX_LOCKED 2007-10-17 08:42:47 -07:00
sembuf.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
setup.h [PATCH] cleanup asm/setup.h userspace visibility 2006-12-07 08:39:46 -08:00
shm.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
shmbuf.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
shmparam.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
sigcontext.h [PATCH] m68knommu: save reg a5 on context change 2006-01-10 09:31:27 -08:00
siginfo.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
signal.h [PATCH] irq-flags: M68KNOMMU: Use the new IRQF_ constants 2006-07-02 13:58:47 -07:00
smp.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
socket.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
sockios.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
spinlock.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
stat.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
statfs.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
string.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
system.h Add cmpxchg_local to m68knommu 2008-02-07 08:42:32 -08:00
termbits.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
termios.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
thread_info.h remove unused TIF_NOTIFY_RESUME flag 2007-07-31 15:39:38 -07:00
timex.h m68knommu: fix tick timer definition for coldfire 2007-07-25 11:05:01 -07:00
tlb.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
tlbflush.h remove unused flush_tlb_pgtables 2007-10-19 11:53:34 -07:00
topology.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
traps.h m68knommu: generic irq handling 2007-07-19 10:04:50 -07:00
types.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
uaccess.h m68knommu: define __clear_user macro 2007-10-23 08:32:07 -07:00
ucontext.h [PATCH] m68knommu: remove FP conditionals in ucontext struct 2006-12-06 07:41:26 -08:00
unaligned.h Don't include linux/config.h from anywhere else in include/ 2006-04-26 12:56:16 +01:00
unistd.h m68knommu: fix pread/pwrite defines 2007-11-05 15:12:33 -08:00
user.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00