From bdc807871d58285737d50dc6163d0feb72cb0dc2 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Fri, 8 Feb 2008 04:21:26 -0800 Subject: 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 Cc: Ralf Baechle , Cc: Sam Ravnborg , Cc: Paul Mundt , Cc: Richard Henderson , Cc: Michael Starvik , Cc: David Howells , Cc: Yoshinori Sato , Cc: Hirokazu Takata , Cc: Geert Uytterhoeven , Cc: Roman Zippel , Cc: William L. Irwin , Cc: Chris Zankel , Cc: H. Peter Anvin , Cc: Jan Engelhardt Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- arch/alpha/Kconfig | 5 +++++ arch/cris/Kconfig | 4 ++++ arch/frv/Kconfig | 4 ++++ arch/h8300/Kconfig | 4 ++++ arch/m32r/Kconfig | 4 ++++ arch/m68k/Kconfig | 4 ++++ arch/m68knommu/Kconfig | 5 +++++ arch/sparc/Kconfig | 4 ++++ arch/v850/Kconfig | 7 +++++++ arch/xtensa/Kconfig | 4 ++++ 10 files changed, 45 insertions(+) (limited to 'arch') diff --git a/arch/alpha/Kconfig b/arch/alpha/Kconfig index d9df913..5b7dcd5 100644 --- a/arch/alpha/Kconfig +++ b/arch/alpha/Kconfig @@ -615,6 +615,11 @@ config VERBOSE_MCHECK_ON Take the default (1) unless you want more control or more info. +config HZ + int + default 1200 if ALPHA_RAWHIDE + default 1024 + source "drivers/pci/Kconfig" source "drivers/eisa/Kconfig" diff --git a/arch/cris/Kconfig b/arch/cris/Kconfig index 27b082a..ff078e6 100644 --- a/arch/cris/Kconfig +++ b/arch/cris/Kconfig @@ -55,6 +55,10 @@ config CRIS bool default y +config HZ + int + default 100 + source "init/Kconfig" menu "General setup" diff --git a/arch/frv/Kconfig b/arch/frv/Kconfig index 96f7d70..9e561ed 100644 --- a/arch/frv/Kconfig +++ b/arch/frv/Kconfig @@ -57,6 +57,10 @@ config ARCH_HAS_ILOG2_U64 bool default y +config HZ + int + default 1000 + mainmenu "Fujitsu FR-V Kernel Configuration" source "init/Kconfig" diff --git a/arch/h8300/Kconfig b/arch/h8300/Kconfig index b4ba4f8..f69e5ea 100644 --- a/arch/h8300/Kconfig +++ b/arch/h8300/Kconfig @@ -82,6 +82,10 @@ config PCI bool default n +config HZ + int + default 100 + source "init/Kconfig" source "arch/h8300/Kconfig.cpu" diff --git a/arch/m32r/Kconfig b/arch/m32r/Kconfig index fe61e00..d4679ab 100644 --- a/arch/m32r/Kconfig +++ b/arch/m32r/Kconfig @@ -38,6 +38,10 @@ config NO_DMA config ARCH_SUPPORTS_AOUT def_bool y +config HZ + int + default 100 + source "init/Kconfig" diff --git a/arch/m68k/Kconfig b/arch/m68k/Kconfig index bcbf3e4..2b0ed89 100644 --- a/arch/m68k/Kconfig +++ b/arch/m68k/Kconfig @@ -55,6 +55,10 @@ config NO_DMA config ARCH_SUPPORTS_AOUT def_bool y +config HZ + int + default 100 + mainmenu "Linux/68k Kernel Configuration" source "init/Kconfig" diff --git a/arch/m68knommu/Kconfig b/arch/m68knommu/Kconfig index 24f7323..548a7b3 100644 --- a/arch/m68knommu/Kconfig +++ b/arch/m68knommu/Kconfig @@ -525,6 +525,11 @@ config 4KSTACKS running more threads on a system and also reduces the pressure on the VM subsystem for higher order allocations. +config HZ + int + default 1000 if CLEOPATRA + default 100 + comment "RAM configuration" config RAMBASE diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig index 08821b0..7c674a3 100644 --- a/arch/sparc/Kconfig +++ b/arch/sparc/Kconfig @@ -30,6 +30,10 @@ config OF config ARCH_SUPPORTS_AOUT def_bool y +config HZ + int + default 100 + source "init/Kconfig" menu "General machine setup" diff --git a/arch/v850/Kconfig b/arch/v850/Kconfig index 225f30d..7b6d371 100644 --- a/arch/v850/Kconfig +++ b/arch/v850/Kconfig @@ -215,6 +215,13 @@ menu "Processor type and features" bool default !V850E_CACHE && !V850E2_CACHE + # HZ depends on the platform + config HZ + int + default 24 if V850E_SIM || V850E2_SIM85E2 + default 122 if V850E2_FPGA85E2C + default 100 + #### Misc config config ROM_KERNEL diff --git a/arch/xtensa/Kconfig b/arch/xtensa/Kconfig index 5d5546c..fd36764 100644 --- a/arch/xtensa/Kconfig +++ b/arch/xtensa/Kconfig @@ -49,6 +49,10 @@ config ARCH_HAS_ILOG2_U64 config NO_IOPORT def_bool y +config HZ + int + default 100 + source "init/Kconfig" menu "Processor type and features" -- cgit v1.1