Commit 2da050c4 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[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.
parent f9d4cdfc
...@@ -110,24 +110,24 @@ struct cpufreq_freqs { ...@@ -110,24 +110,24 @@ struct cpufreq_freqs {
* @div: divisor * @div: divisor
* @mult: multiplier * @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 * new = old * mult / div
*/ */
static inline unsigned long cpufreq_scale(unsigned long old, u_int div, u_int mult) 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; u64 result = ((u64) old) * ((u64) mult);
div /= 100; do_div(result, div);
val = (old / div) * mult; return (unsigned long) result;
carry = old % div;
carry = carry * mult / div;
return carry + val; #elif BITS_PER_LONG == 64
unsigned long result = old * ((u64) mult);
result /= div;
return result;
#endif
}; };
/********************************************************************* /*********************************************************************
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment