android_kernel_xiaomi_sm8350/include/asm-m68k
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
..
a.out-core.h aout: suppress A.OUT library support if !CONFIG_ARCH_SUPPORTS_AOUT 2008-02-08 09:22:30 -08:00
a.out.h aout: move STACK_TOP[_MAX] to asm/processor.h 2008-02-08 09:22:29 -08:00
adb_iop.h
amigahw.h
amigaints.h
amigayle.h
amipcmcia.h
apollodma.h
apollohw.h
atafd.h
atafdreg.h
atari_joystick.h
atari_stdma.h
atari_stram.h
atarihw.h further UTF-8 fixes and name correction 2007-05-11 19:09:46 +02:00
atariints.h further UTF-8 fixes and name correction 2007-05-11 19:09:46 +02:00
atarikb.h m68k: Atari keyboard and mouse support. 2007-05-04 17:59:05 -07: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 ext4: Add ext4_find_next_bit() 2008-01-28 23:58:27 -05:00
blinken.h
bootinfo.h
bug.h
bugs.h
bvme6000hw.h
byteorder.h
cache.h
cachectl.h
cacheflush.h
checksum.h
contregs.h
cputime.h
current.h
delay.h
device.h
div64.h [NET]: div64_64 consolidate (rev3) 2007-04-25 22:23:33 -07:00
dma-mapping.h
dma.h
dsp56k.h
dvma.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
entry.h
errno.h
fb.h fbdev: detect primary display device 2007-07-17 10:23:11 -07:00
fbio.h
fcntl.h
floppy.h cleanup floppy.h 2007-10-17 08:42:55 -07:00
fpu.h
futex.h
hardirq.h
hp300hw.h
hw_irq.h
hwtest.h
ide.h ide: add hwif->ack_intr hook 2007-10-20 00:32:32 +02:00
idprom.h
intersil.h
io.h Remove dma_cache_(wback|inv|wback_inv) functions 2007-10-17 08:42:57 -07:00
ioctl.h
ioctls.h m68k: Enable arbitary speed tty support 2007-08-22 19:52:45 -07:00
ipcbuf.h
irq_regs.h
irq.h take declarations of enable_irq() et.al. to linux/interrupt.h 2007-07-22 11:44:00 -07:00
Kbuild m68k: Export cachectl.h 2007-10-13 09:41:03 -07:00
kdebug.h move die notifier handling to common code 2007-05-08 11:15:04 -07:00
kmap_types.h
linkage.h
local.h
mac_asc.h
mac_baboon.h
mac_iop.h
mac_mouse.h
mac_oss.h
mac_psc.h
mac_via.h
machdep.h
machines.h
machw.h
macintosh.h mac68k: remove dead code 2008-02-05 09:44:24 -08:00
macints.h
math-emu.h
mc146818rtc.h
md.h
mman.h
mmu_context.h [PATCH] x86: PARAVIRT: add hooks to intercept mm creation and destruction 2007-05-02 19:27:14 +02:00
mmu.h
mmzone.h m68k: discontinuous memory support 2007-05-31 07:58:14 -07:00
module.h m68k: discontinuous memory support 2007-05-31 07:58:14 -07:00
motorola_pgalloc.h add mm argument to pte/pmd/pud/pgd_free 2008-02-05 09:44:18 -08:00
motorola_pgtable.h m68k: kill page walker compile warning 2008-02-07 09:10:06 -08:00
movs.h
msgbuf.h
mutex.h
mvme16xhw.h
mvme147hw.h
namei.h
nubus.h
openprom.h
oplib.h
page_offset.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
parport.h
pci.h PCI: Use a weak symbol for the empty version of pcibios_add_platform_entries() 2007-07-11 16:02:07 -07:00
percpu.h
pgalloc.h m68k: discontinuous memory support 2007-05-31 07:58:14 -07:00
pgtable.h cleanup after APUS removal 2008-02-06 10:41:01 -08: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
q40_master.h
q40ints.h
raw_io.h m68k {in,out}_le{16,32} endianness misannotation 2007-07-26 11:11:57 -07:00
resource.h
rtc.h
sbus.h
scatterlist.h Add CONFIG_DEBUG_SG sg validation 2007-10-22 21:20:03 +02:00
sections.h
segment.h
semaphore-helper.h
semaphore.h kill DECLARE_MUTEX_LOCKED 2007-10-17 08:42:47 -07:00
sembuf.h
serial.h
setup.h
shm.h
shmbuf.h
shmparam.h
sigcontext.h
siginfo.h
signal.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
sun3_pgalloc.h add mm argument to pte/pmd/pud/pgd_free 2008-02-05 09:44:18 -08:00
sun3_pgtable.h page table handling cleanup 2007-07-16 09:05:36 -07:00
sun3-head.h
sun3ints.h
sun3mmu.h
sun3x.h
sun3xflop.h
sun3xprom.h
suspend.h
system.h Add cmpxchg_local to m86k 2008-02-07 08:42:32 -08:00
termbits.h m68k: Enable arbitary speed tty support 2007-08-22 19:52:45 -07:00
termios.h m68k: Enable arbitary speed tty support 2007-08-22 19:52:45 -07:00
thread_info.h rename thread_info to stack 2007-05-09 12:30:56 -07:00
timex.h
tlb.h
tlbflush.h remove unused flush_tlb_pgtables 2007-10-19 11:53:34 -07:00
topology.h
traps.h
types.h remove strict ansi check from __u64 in asm/types.h 2007-10-17 08:42:53 -07:00
uaccess.h m68k: implement __clear_user() 2007-05-15 08:54:00 -07:00
ucontext.h
unaligned.h
unistd.h m68k: ignore restart_syscall 2007-10-13 09:41:03 -07:00
user.h Sanitize the type of struct user.u_ar0 2008-02-07 08:42:30 -08:00
virtconvert.h m68k: discontinuous memory support 2007-05-31 07:58:14 -07:00
xor.h
zorro.h