diff options
author | H. Peter Anvin <hpa@zytor.com> | 2008-02-08 04:21:26 -0800 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2008-02-08 09:22:39 -0800 |
commit | bdc807871d58285737d50dc6163d0feb72cb0dc2 (patch) | |
tree | 1a6d35f3537ed1a7460811549efd045ae97a0e6e /include | |
parent | 7ef3d2fd17c377ef64a2aa19677d17576606c3b4 (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 'include')
-rw-r--r-- | include/asm-alpha/param.h | 10 | ||||
-rw-r--r-- | include/asm-cris/param.h | 2 | ||||
-rw-r--r-- | include/asm-frv/param.h | 2 | ||||
-rw-r--r-- | include/asm-h8300/param.h | 2 | ||||
-rw-r--r-- | include/asm-m32r/param.h | 2 | ||||
-rw-r--r-- | include/asm-m68k/param.h | 2 | ||||
-rw-r--r-- | include/asm-m68knommu/param.h | 8 | ||||
-rw-r--r-- | include/asm-sparc/param.h | 2 | ||||
-rw-r--r-- | include/asm-v850/anna.h | 6 | ||||
-rw-r--r-- | include/asm-v850/as85ep1.h | 6 | ||||
-rw-r--r-- | include/asm-v850/fpga85e2c.h | 6 | ||||
-rw-r--r-- | include/asm-v850/param.h | 3 | ||||
-rw-r--r-- | include/asm-v850/rte_cb.h | 6 | ||||
-rw-r--r-- | include/asm-v850/sim.h | 5 | ||||
-rw-r--r-- | include/asm-v850/sim85e2.h | 6 | ||||
-rw-r--r-- | include/asm-xtensa/param.h | 2 |
16 files changed, 10 insertions, 60 deletions
diff --git a/include/asm-alpha/param.h b/include/asm-alpha/param.h index 214e7996346..0982f1d3949 100644 --- a/include/asm-alpha/param.h +++ b/include/asm-alpha/param.h @@ -5,15 +5,7 @@ hardware ignores reprogramming. We also need userland buy-in to the change in HZ, since this is visible in the wait4 resources etc. */ - -#ifndef HZ -# ifndef CONFIG_ALPHA_RAWHIDE -# define HZ 1024 -# else -# define HZ 1200 -# endif -#endif - +#define HZ CONFIG_HZ #define USER_HZ HZ #define EXEC_PAGESIZE 8192 diff --git a/include/asm-cris/param.h b/include/asm-cris/param.h index b2497263983..0e47994e40b 100644 --- a/include/asm-cris/param.h +++ b/include/asm-cris/param.h @@ -3,7 +3,7 @@ /* Currently we assume that HZ=100 is good for CRIS. */ #ifdef __KERNEL__ -# define HZ 100 /* Internal kernel timer frequency */ +# define HZ CONFIG_HZ /* Internal kernel timer frequency */ # define USER_HZ 100 /* .. some user interfaces are in "ticks" */ # define CLOCKS_PER_SEC (USER_HZ) /* like times() */ #endif diff --git a/include/asm-frv/param.h b/include/asm-frv/param.h index 365653b1726..6859dd503ed 100644 --- a/include/asm-frv/param.h +++ b/include/asm-frv/param.h @@ -2,7 +2,7 @@ #define _ASM_PARAM_H #ifdef __KERNEL__ -#define HZ 1000 /* Internal kernel timer frequency */ +#define HZ CONFIG_HZ /* Internal kernel timer frequency */ #define USER_HZ 100 /* .. some user interfaces are in "ticks" */ #define CLOCKS_PER_SEC (USER_HZ) /* like times() */ #endif diff --git a/include/asm-h8300/param.h b/include/asm-h8300/param.h index c25806ed1fb..04f64f10037 100644 --- a/include/asm-h8300/param.h +++ b/include/asm-h8300/param.h @@ -3,7 +3,7 @@ #ifndef HZ -#define HZ 100 +#define HZ CONFIG_HZ #endif #ifdef __KERNEL__ diff --git a/include/asm-m32r/param.h b/include/asm-m32r/param.h index 3e14026e39c..94c77019604 100644 --- a/include/asm-m32r/param.h +++ b/include/asm-m32r/param.h @@ -2,7 +2,7 @@ #define _ASM_M32R_PARAM_H #ifdef __KERNEL__ -# define HZ 100 /* Internal kernel timer frequency */ +# define HZ CONFIG_HZ /* Internal kernel timer frequency */ # define USER_HZ 100 /* .. some user interfaces are in "ticks" */ # define CLOCKS_PER_SEC (USER_HZ) /* like times() */ #endif diff --git a/include/asm-m68k/param.h b/include/asm-m68k/param.h index 60f409d8165..536a2788835 100644 --- a/include/asm-m68k/param.h +++ b/include/asm-m68k/param.h @@ -2,7 +2,7 @@ #define _M68K_PARAM_H #ifdef __KERNEL__ -# define HZ 100 /* Internal kernel timer frequency */ +# define HZ CONFIG_HZ /* Internal kernel timer frequency */ # define USER_HZ 100 /* .. some user interfaces are in "ticks" */ # define CLOCKS_PER_SEC (USER_HZ) /* like times() */ #endif diff --git a/include/asm-m68knommu/param.h b/include/asm-m68knommu/param.h index 4c9904d6512..96c45101832 100644 --- a/include/asm-m68knommu/param.h +++ b/include/asm-m68knommu/param.h @@ -1,13 +1,7 @@ #ifndef _M68KNOMMU_PARAM_H #define _M68KNOMMU_PARAM_H - -#if defined(CONFIG_CLEOPATRA) -#define HZ 1000 -#endif -#ifndef HZ -#define HZ 100 -#endif +#define HZ CONFIG_HZ #ifdef __KERNEL__ #define USER_HZ HZ diff --git a/include/asm-sparc/param.h b/include/asm-sparc/param.h index beaf02d364f..86ba59af9d2 100644 --- a/include/asm-sparc/param.h +++ b/include/asm-sparc/param.h @@ -3,7 +3,7 @@ #define _ASMSPARC_PARAM_H #ifdef __KERNEL__ -# define HZ 100 /* Internal kernel timer frequency */ +# define HZ CONFIG_HZ /* Internal kernel timer frequency */ # define USER_HZ 100 /* .. some user interfaces are in "ticks" */ # define CLOCKS_PER_SEC (USER_HZ) #endif diff --git a/include/asm-v850/anna.h b/include/asm-v850/anna.h index 3be77d5ecfc..cd5eaee103b 100644 --- a/include/asm-v850/anna.h +++ b/include/asm-v850/anna.h @@ -134,10 +134,4 @@ extern void anna_uart_pre_configure (unsigned chan, #define V850E_TIMER_D_TMCD_CS_MIN 1 /* min 2^1 divider */ -/* For <asm/param.h> */ -#ifndef HZ -#define HZ 100 -#endif - - #endif /* __V850_ANNA_H__ */ diff --git a/include/asm-v850/as85ep1.h b/include/asm-v850/as85ep1.h index 659bc910ffd..5a5ca9073d0 100644 --- a/include/asm-v850/as85ep1.h +++ b/include/asm-v850/as85ep1.h @@ -149,10 +149,4 @@ extern void as85ep1_uart_pre_configure (unsigned chan, #define V850E_TIMER_D_TMCD_CS_MIN 2 /* min 2^2 divider */ -/* For <asm/param.h> */ -#ifndef HZ -#define HZ 100 -#endif - - #endif /* __V850_AS85EP1_H__ */ diff --git a/include/asm-v850/fpga85e2c.h b/include/asm-v850/fpga85e2c.h index d32f04504b1..23aae666c71 100644 --- a/include/asm-v850/fpga85e2c.h +++ b/include/asm-v850/fpga85e2c.h @@ -79,10 +79,4 @@ extern char _r0_ram; #endif -/* For <asm/param.h> */ -#ifndef HZ -#define HZ 122 /* actually, 8.192ms ticks =~ 122.07 */ -#endif - - #endif /* __V850_FPGA85E2C_H__ */ diff --git a/include/asm-v850/param.h b/include/asm-v850/param.h index 3c65bd57378..28183269029 100644 --- a/include/asm-v850/param.h +++ b/include/asm-v850/param.h @@ -23,8 +23,7 @@ #define MAXHOSTNAMELEN 64 /* max length of hostname */ #ifdef __KERNEL__ -#include <asm/machdep.h> /* For HZ */ - +# define HZ CONFIG_HZ # define USER_HZ 100 # define CLOCKS_PER_SEC USER_HZ #endif diff --git a/include/asm-v850/rte_cb.h b/include/asm-v850/rte_cb.h index e85d261b79b..db9879f00aa 100644 --- a/include/asm-v850/rte_cb.h +++ b/include/asm-v850/rte_cb.h @@ -69,12 +69,6 @@ #endif /* CONFIG_RTE_MB_A_PCI */ -/* For <asm/param.h> */ -#ifndef HZ -#define HZ 100 -#endif - - #ifndef __ASSEMBLY__ extern void rte_cb_early_init (void); extern void rte_cb_init_irqs (void); diff --git a/include/asm-v850/sim.h b/include/asm-v850/sim.h index 10236abbe9b..026932d476c 100644 --- a/include/asm-v850/sim.h +++ b/include/asm-v850/sim.h @@ -40,11 +40,6 @@ #define R0_RAM_ADDR 0xFFFFF000 -/* For <asm/param.h> */ -#ifndef HZ -#define HZ 24 /* Minimum supported frequency. */ -#endif - /* For <asm/irq.h> */ #define NUM_CPU_IRQS 6 diff --git a/include/asm-v850/sim85e2.h b/include/asm-v850/sim85e2.h index 17dd4fa318e..8b4d6974066 100644 --- a/include/asm-v850/sim85e2.h +++ b/include/asm-v850/sim85e2.h @@ -66,10 +66,4 @@ #define R0_RAM_ADDR 0xFFFFE000 -/* For <asm/param.h> */ -#ifndef HZ -#define HZ 24 /* Minimum supported frequency. */ -#endif - - #endif /* __V850_SIM85E2_H__ */ diff --git a/include/asm-xtensa/param.h b/include/asm-xtensa/param.h index ce3a336cad0..82ad34d92d3 100644 --- a/include/asm-xtensa/param.h +++ b/include/asm-xtensa/param.h @@ -12,7 +12,7 @@ #define _XTENSA_PARAM_H #ifdef __KERNEL__ -# define HZ 100 /* internal timer frequency */ +# define HZ CONFIG_HZ /* internal timer frequency */ # define USER_HZ 100 /* for user interfaces in "ticks" */ # define CLOCKS_PER_SEC (USER_HZ) /* frequnzy at which times() counts */ #endif |