diff options
| author | Andrew Morton <akpm@osdl.org> | 2004-02-18 04:54:50 -0800 |
|---|---|---|
| committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2004-02-18 04:54:50 -0800 |
| commit | 2da050c495c5844e7feba3662bb4a274c9447901 (patch) | |
| tree | d32ff295526c0bc9b7558d681fba9c78543ece56 /include | |
| parent | f9d4cdfcaca93884ca6eda81ee1e0d0e9a6923b0 (diff) | |
[PATCH] cpufreq_scale() fixes
From: Dominik Brodowski <linux@dominikbrodowski.de>
Use do_div on 32-bit archs in cpufreq_scale, and native "/" on 64-bit
archs.
Diffstat (limited to 'include')
| -rw-r--r-- | include/linux/cpufreq.h | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index bbc983dc8913..3a8e279897ed 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -110,24 +110,24 @@ struct cpufreq_freqs { * @div: divisor * @mult: multiplier * - * Needed for loops_per_jiffy and similar calculations. We do it - * this way to avoid math overflow on 32-bit machines. This will - * become architecture dependent once high-resolution-timer is - * merged (or any other thing that introduces sc_math.h). * * new = old * mult / div */ static inline unsigned long cpufreq_scale(unsigned long old, u_int div, u_int mult) { - unsigned long val, carry; +#if BITS_PER_LONG == 32 - mult /= 100; - div /= 100; - val = (old / div) * mult; - carry = old % div; - carry = carry * mult / div; + u64 result = ((u64) old) * ((u64) mult); + do_div(result, div); + return (unsigned long) result; - return carry + val; +#elif BITS_PER_LONG == 64 + + unsigned long result = old * ((u64) mult); + result /= div; + return result; + +#endif }; /********************************************************************* |
