aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2008-02-08 07:21:26 -0500
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2008-02-08 12:22:39 -0500
commitbdc807871d58285737d50dc6163d0feb72cb0dc2 (patch)
tree1a6d35f3537ed1a7460811549efd045ae97a0e6e /arch
parent7ef3d2fd17c377ef64a2aa19677d17576606c3b4 (diff)
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>
Diffstat (limited to 'arch')
-rw-r--r--arch/alpha/Kconfig5
-rw-r--r--arch/cris/Kconfig4
-rw-r--r--arch/frv/Kconfig4
-rw-r--r--arch/h8300/Kconfig4
-rw-r--r--arch/m32r/Kconfig4
-rw-r--r--arch/m68k/Kconfig4
-rw-r--r--arch/m68knommu/Kconfig5
-rw-r--r--arch/sparc/Kconfig4
-rw-r--r--arch/v850/Kconfig7
-rw-r--r--arch/xtensa/Kconfig4
10 files changed, 45 insertions, 0 deletions
diff --git a/arch/alpha/Kconfig b/arch/alpha/Kconfig
index d9df913a464d..5b7dcd5a0e75 100644
--- a/arch/alpha/Kconfig
+++ b/arch/alpha/Kconfig
@@ -615,6 +615,11 @@ config VERBOSE_MCHECK_ON
615 615
616 Take the default (1) unless you want more control or more info. 616 Take the default (1) unless you want more control or more info.
617 617
618config HZ
619 int
620 default 1200 if ALPHA_RAWHIDE
621 default 1024
622
618source "drivers/pci/Kconfig" 623source "drivers/pci/Kconfig"
619source "drivers/eisa/Kconfig" 624source "drivers/eisa/Kconfig"
620 625
diff --git a/arch/cris/Kconfig b/arch/cris/Kconfig
index 27b082ac7f11..ff078e60e76d 100644
--- a/arch/cris/Kconfig
+++ b/arch/cris/Kconfig
@@ -55,6 +55,10 @@ config CRIS
55 bool 55 bool
56 default y 56 default y
57 57
58config HZ
59 int
60 default 100
61
58source "init/Kconfig" 62source "init/Kconfig"
59 63
60menu "General setup" 64menu "General setup"
diff --git a/arch/frv/Kconfig b/arch/frv/Kconfig
index 96f7d70f4473..9e561ede0925 100644
--- a/arch/frv/Kconfig
+++ b/arch/frv/Kconfig
@@ -57,6 +57,10 @@ config ARCH_HAS_ILOG2_U64
57 bool 57 bool
58 default y 58 default y
59 59
60config HZ
61 int
62 default 1000
63
60mainmenu "Fujitsu FR-V Kernel Configuration" 64mainmenu "Fujitsu FR-V Kernel Configuration"
61 65
62source "init/Kconfig" 66source "init/Kconfig"
diff --git a/arch/h8300/Kconfig b/arch/h8300/Kconfig
index b4ba4f8b505c..f69e5ea38558 100644
--- a/arch/h8300/Kconfig
+++ b/arch/h8300/Kconfig
@@ -82,6 +82,10 @@ config PCI
82 bool 82 bool
83 default n 83 default n
84 84
85config HZ
86 int
87 default 100
88
85source "init/Kconfig" 89source "init/Kconfig"
86 90
87source "arch/h8300/Kconfig.cpu" 91source "arch/h8300/Kconfig.cpu"
diff --git a/arch/m32r/Kconfig b/arch/m32r/Kconfig
index fe61e00a604f..d4679ab55b96 100644
--- a/arch/m32r/Kconfig
+++ b/arch/m32r/Kconfig
@@ -38,6 +38,10 @@ config NO_DMA
38config ARCH_SUPPORTS_AOUT 38config ARCH_SUPPORTS_AOUT
39 def_bool y 39 def_bool y
40 40
41config HZ
42 int
43 default 100
44
41source "init/Kconfig" 45source "init/Kconfig"
42 46
43 47
diff --git a/arch/m68k/Kconfig b/arch/m68k/Kconfig
index bcbf3e4ee9d4..2b0ed89cd173 100644
--- a/arch/m68k/Kconfig
+++ b/arch/m68k/Kconfig
@@ -55,6 +55,10 @@ config NO_DMA
55config ARCH_SUPPORTS_AOUT 55config ARCH_SUPPORTS_AOUT
56 def_bool y 56 def_bool y
57 57
58config HZ
59 int
60 default 100
61
58mainmenu "Linux/68k Kernel Configuration" 62mainmenu "Linux/68k Kernel Configuration"
59 63
60source "init/Kconfig" 64source "init/Kconfig"
diff --git a/arch/m68knommu/Kconfig b/arch/m68knommu/Kconfig
index 24f732342d3e..548a7b321633 100644
--- a/arch/m68knommu/Kconfig
+++ b/arch/m68knommu/Kconfig
@@ -525,6 +525,11 @@ config 4KSTACKS
525 running more threads on a system and also reduces the pressure 525 running more threads on a system and also reduces the pressure
526 on the VM subsystem for higher order allocations. 526 on the VM subsystem for higher order allocations.
527 527
528config HZ
529 int
530 default 1000 if CLEOPATRA
531 default 100
532
528comment "RAM configuration" 533comment "RAM configuration"
529 534
530config RAMBASE 535config RAMBASE
diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig
index 08821b078ecc..7c674a3503b6 100644
--- a/arch/sparc/Kconfig
+++ b/arch/sparc/Kconfig
@@ -30,6 +30,10 @@ config OF
30config ARCH_SUPPORTS_AOUT 30config ARCH_SUPPORTS_AOUT
31 def_bool y 31 def_bool y
32 32
33config HZ
34 int
35 default 100
36
33source "init/Kconfig" 37source "init/Kconfig"
34 38
35menu "General machine setup" 39menu "General machine setup"
diff --git a/arch/v850/Kconfig b/arch/v850/Kconfig
index 225f30d7cb32..7b6d3716efca 100644
--- a/arch/v850/Kconfig
+++ b/arch/v850/Kconfig
@@ -215,6 +215,13 @@ menu "Processor type and features"
215 bool 215 bool
216 default !V850E_CACHE && !V850E2_CACHE 216 default !V850E_CACHE && !V850E2_CACHE
217 217
218 # HZ depends on the platform
219 config HZ
220 int
221 default 24 if V850E_SIM || V850E2_SIM85E2
222 default 122 if V850E2_FPGA85E2C
223 default 100
224
218 #### Misc config 225 #### Misc config
219 226
220 config ROM_KERNEL 227 config ROM_KERNEL
diff --git a/arch/xtensa/Kconfig b/arch/xtensa/Kconfig
index 5d5546ce88fe..fd36764d7fb7 100644
--- a/arch/xtensa/Kconfig
+++ b/arch/xtensa/Kconfig
@@ -49,6 +49,10 @@ config ARCH_HAS_ILOG2_U64
49config NO_IOPORT 49config NO_IOPORT
50 def_bool y 50 def_bool y
51 51
52config HZ
53 int
54 default 100
55
52source "init/Kconfig" 56source "init/Kconfig"
53 57
54menu "Processor type and features" 58menu "Processor type and features"