Commit d8a9ce3f8ad2b546b9ebaf65de809da0793f11c5

Authored by Frederic Weisbecker
1 parent bfc3f0281e

cputime: Bring cputime -> nsecs conversion

We already have nsecs_to_cputime(). Now we need to be able to convert
the other way around in order to fix a bug on steal time accounting.

Cc: Ingo Molnar <mingo@kernel.org>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Rik van Riel <riel@redhat.com>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>

Showing 3 changed files with 10 additions and 1 deletions Side-by-side Diff

include/asm-generic/cputime_jiffies.h
... ... @@ -15,8 +15,10 @@
15 15  
16 16  
17 17 /*
18   - * Convert nanoseconds to cputime
  18 + * Convert nanoseconds <-> cputime
19 19 */
  20 +#define cputime_to_nsecs(__ct) \
  21 + jiffies_to_nsecs(cputime_to_jiffies(__ct))
20 22 #define nsecs_to_cputime64(__nsec) \
21 23 jiffies64_to_cputime64(nsecs_to_jiffies64(__nsec))
22 24 #define nsecs_to_cputime(__nsec) \
include/asm-generic/cputime_nsecs.h
... ... @@ -44,6 +44,8 @@
44 44 /*
45 45 * Convert cputime <-> nanoseconds
46 46 */
  47 +#define cputime_to_nsecs(__ct) \
  48 + (__force u64)(__ct)
47 49 #define nsecs_to_cputime(__nsecs) \
48 50 (__force cputime_t)(__nsecs)
49 51  
include/linux/cputime.h
... ... @@ -3,6 +3,11 @@
3 3  
4 4 #include <asm/cputime.h>
5 5  
  6 +#ifndef cputime_to_nsecs
  7 +# define cputime_to_nsecs(__ct) \
  8 + (cputime_to_usecs(__ct) * NSEC_PER_USEC)
  9 +#endif
  10 +
6 11 #ifndef nsecs_to_cputime
7 12 # define nsecs_to_cputime(__nsecs) \
8 13 usecs_to_cputime((__nsecs) / NSEC_PER_USEC)