Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc: Fix wrong divisor in usecs_to_cputime

Commit d57af9b (taskstats: use real microsecond granularity for CPU times)
renamed msecs_to_cputime to usecs_to_cputime, but failed to update all
numbers on the way. This causes nonsensical cpu idle/iowait values to be
displayed in /proc/stat (the only user of usecs_to_cputime so far).

This also renames __cputime_msec_factor to __cputime_usec_factor, adapting
its value and using it directly in cputime_to_usecs instead of doing two
multiplications.

Signed-off-by: Andreas Schwab <schwab@linux-m68k.org>
Acked-by: Anton Blanchard <anton@samba.org>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

authored by

Andreas Schwab and committed by
Benjamin Herrenschmidt
9f5072d4 2011b1d0

+8 -8
+3 -3
arch/powerpc/include/asm/cputime.h
··· 126 126 /* 127 127 * Convert cputime <-> microseconds 128 128 */ 129 - extern u64 __cputime_msec_factor; 129 + extern u64 __cputime_usec_factor; 130 130 131 131 static inline unsigned long cputime_to_usecs(const cputime_t ct) 132 132 { 133 - return mulhdu(ct, __cputime_msec_factor) * USEC_PER_MSEC; 133 + return mulhdu(ct, __cputime_usec_factor); 134 134 } 135 135 136 136 static inline cputime_t usecs_to_cputime(const unsigned long us) ··· 143 143 sec = us / 1000000; 144 144 if (ct) { 145 145 ct *= tb_ticks_per_sec; 146 - do_div(ct, 1000); 146 + do_div(ct, 1000000); 147 147 } 148 148 if (sec) 149 149 ct += (cputime_t) sec * tb_ticks_per_sec;
+5 -5
arch/powerpc/kernel/time.c
··· 158 158 #ifdef CONFIG_VIRT_CPU_ACCOUNTING 159 159 /* 160 160 * Factors for converting from cputime_t (timebase ticks) to 161 - * jiffies, milliseconds, seconds, and clock_t (1/USER_HZ seconds). 161 + * jiffies, microseconds, seconds, and clock_t (1/USER_HZ seconds). 162 162 * These are all stored as 0.64 fixed-point binary fractions. 163 163 */ 164 164 u64 __cputime_jiffies_factor; 165 165 EXPORT_SYMBOL(__cputime_jiffies_factor); 166 - u64 __cputime_msec_factor; 167 - EXPORT_SYMBOL(__cputime_msec_factor); 166 + u64 __cputime_usec_factor; 167 + EXPORT_SYMBOL(__cputime_usec_factor); 168 168 u64 __cputime_sec_factor; 169 169 EXPORT_SYMBOL(__cputime_sec_factor); 170 170 u64 __cputime_clockt_factor; ··· 182 182 183 183 div128_by_32(HZ, 0, tb_ticks_per_sec, &res); 184 184 __cputime_jiffies_factor = res.result_low; 185 - div128_by_32(1000, 0, tb_ticks_per_sec, &res); 186 - __cputime_msec_factor = res.result_low; 185 + div128_by_32(1000000, 0, tb_ticks_per_sec, &res); 186 + __cputime_usec_factor = res.result_low; 187 187 div128_by_32(1, 0, tb_ticks_per_sec, &res); 188 188 __cputime_sec_factor = res.result_low; 189 189 div128_by_32(USER_HZ, 0, tb_ticks_per_sec, &res);