android_kernel_xiaomi_sm8350/include/asm-sparc
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
apc.h
asi.h
asmmacro.h
atomic.h Add cmpxchg_local to sparc, move __cmpxchg to system.h 2008-02-07 08:42:32 -08:00
auxio.h
auxvec.h
bitext.h
bitops.h forbid asm/bitops.h direct inclusion 2007-10-19 11:53:41 -07:00
bpp.h
bsderrno.h
btfixup.h
bug.h
bugs.h
byteorder.h
cache.h
cacheflush.h
checksum.h
clock.h
contregs.h
cpudata.h
cputime.h
current.h
cypress.h
delay.h
device.h [SPARC64]: Fix conflicts in SBUS/PCI/EBUS/ISA DMA handling. 2007-07-30 00:27:34 -07:00
div64.h
dma-mapping.h
dma.h [SPARC32]: __inline__ --> inline 2007-10-27 00:17:01 -07:00
ebus.h
ecc.h
eeprom.h
elf.h Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc-2.6 2008-02-07 10:21:26 -08:00
emergency-restart.h
errno.h
fb.h [SPARC]: Implement fb_is_primary_device(). 2007-07-20 17:15:09 -07:00
fbio.h
fcntl.h [SPARC32]: Fix build. 2007-08-04 21:17:18 -07:00
fixmap.h
floppy.h [SPARC32]: __inline__ --> inline 2007-10-27 00:17:01 -07:00
futex.h
hardirq.h
head.h
highmem.h
hw_irq.h
ide.h [SPARC32]: __inline__ --> inline 2007-10-27 00:17:01 -07:00
idprom.h
io-unit.h
io.h Remove dma_cache_(wback|inv|wback_inv) functions 2007-10-17 08:42:57 -07:00
ioctl.h
ioctls.h [SPARC]: Support for new termios. 2007-10-17 19:38:10 -07:00
iommu.h
ipcbuf.h
irq_regs.h
irq.h [SPARC32]: Fix modular build of floppy driver. 2007-08-03 14:08:42 -07:00
irqflags.h [SPARC32]: Add irqflags.h to sparc32 and use it from generic code. 2007-10-13 21:53:11 -07:00
jsflash.h
Kbuild
kdebug.h [SPARC32]: Fix sparc32 kdebug changes. 2007-05-14 03:22:08 -07:00
kgdb.h
kmap_types.h
linkage.h
local.h
machines.h
mbus.h
mc146818rtc.h
memreg.h
mman.h
mmu_context.h
mmu.h
module.h
mostek.h
mpmbox.h
msgbuf.h
msi.h
mutex.h
mxcc.h
namei.h
obio.h
of_device.h Create linux/of_platorm.h 2007-07-20 14:25:22 +10:00
of_platform.h [SPARC/64]: Consolidate of_register_driver 2007-10-17 21:17:42 -07:00
openprom.h
openpromio.h
oplib.h [SPARC]: Fix serial console device detection. 2007-07-20 16:59:26 -07: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
pbm.h
pci.h PCI: remove pci_dac_dma_... APIs 2007-07-11 16:02:11 -07:00
pcic.h
pconf.h
percpu.h
perfctr.h
pgalloc.h add mm argument to pte/pmd/pud/pgd_free 2008-02-05 09:44:18 -08:00
pgtable.h [SPARC32]: Make PAGE_SHARED a read-mostly variable. 2007-07-21 19:20:34 -07:00
pgtsrmmu.h
pgtsun4.h
pgtsun4c.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
prom.h [SPARC]: Centralize find_in_proplist() instead of duplicating N times. 2007-08-07 18:46:36 -07:00
psr.h
ptrace.h [SPARC]: Move over to arch_ptrace(). 2008-02-07 03:00:17 -08:00
reg.h
resource.h
ross.h
rtc.h
sbi.h
sbus.h [SPARC32]: Remove iommu from struct sbus_bus and use archdata like sparc64. 2007-08-10 15:52:06 -07:00
scatterlist.h Add CONFIG_DEBUG_SG sg validation 2007-10-22 21:20:03 +02:00
sections.h
semaphore.h kill DECLARE_MUTEX_LOCKED 2007-10-17 08:42:47 -07:00
sembuf.h
setup.h
sfp-machine.h [MATH-EMU]: Fix underflow exception reporting. 2007-08-16 22:59:49 -07:00
shmbuf.h
shmparam.h
sigcontext.h
siginfo.h
signal.h
smp.h
smpprim.h
socket.h [NET]: Introducing socket mark socket option. 2008-01-31 19:27:19 -08:00
sockios.h
solerrno.h
spinlock_types.h
spinlock.h
stat.h
statfs.h
string.h
sun4paddr.h
sun4prom.h
sunbpp.h
svr4.h
swift.h
sysen.h
system.h Add cmpxchg_local to sparc, move __cmpxchg to system.h 2008-02-07 08:42:32 -08:00
termbits.h [SPARC]: Support for new termios. 2007-10-17 19:38:10 -07:00
termios.h [SPARC]: Support for new termios. 2007-10-17 19:38:10 -07:00
thread_info.h
timer.h
timex.h
tlb.h
tlbflush.h remove unused flush_tlb_pgtables 2007-10-19 11:53:34 -07:00
topology.h
traps.h
tsunami.h
turbosparc.h
types.h
uaccess.h aout: remove unnecessary inclusions of {asm, linux}/a.out.h 2008-02-08 09:22:30 -08:00
unaligned.h
unistd.h [SPARC]: Add new timerfd syscall entries. 2008-02-06 04:12:23 -08:00
user.h
vac-ops.h
vaddrs.h
vfc_ioctls.h
vga.h
viking.h
winmacro.h
xor.h