Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _ASM_GENERIC_CPUTIME_H |
| 2 | #define _ASM_GENERIC_CPUTIME_H |
| 3 | |
| 4 | #include <linux/time.h> |
| 5 | #include <linux/jiffies.h> |
| 6 | |
Martin Schwidefsky | 6486163 | 2011-12-15 14:56:09 +0100 | [diff] [blame] | 7 | typedef unsigned long __nocast cputime_t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | |
Stanislaw Gruszka | a42548a | 2009-07-29 12:15:29 +0200 | [diff] [blame] | 9 | #define cputime_one_jiffy jiffies_to_cputime(1) |
Martin Schwidefsky | 6486163 | 2011-12-15 14:56:09 +0100 | [diff] [blame] | 10 | #define cputime_to_jiffies(__ct) (__force unsigned long)(__ct) |
Michael Neuling | 06b8e87 | 2008-02-06 01:36:12 -0800 | [diff] [blame] | 11 | #define cputime_to_scaled(__ct) (__ct) |
Martin Schwidefsky | 6486163 | 2011-12-15 14:56:09 +0100 | [diff] [blame] | 12 | #define jiffies_to_cputime(__hz) (__force cputime_t)(__hz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | |
Martin Schwidefsky | 6486163 | 2011-12-15 14:56:09 +0100 | [diff] [blame] | 14 | typedef u64 __nocast cputime64_t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
Martin Schwidefsky | 6486163 | 2011-12-15 14:56:09 +0100 | [diff] [blame] | 16 | #define cputime64_to_jiffies64(__ct) (__force u64)(__ct) |
| 17 | #define jiffies64_to_cputime64(__jif) (__force cputime64_t)(__jif) |
Venkatesh Pallipadi | a1dabb6 | 2010-12-21 17:09:01 -0800 | [diff] [blame] | 18 | |
Martin Schwidefsky | 6486163 | 2011-12-15 14:56:09 +0100 | [diff] [blame] | 19 | #define nsecs_to_cputime64(__ct) \ |
| 20 | jiffies64_to_cputime64(nsecs_to_jiffies64(__ct)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
| 22 | |
| 23 | /* |
Michael Holzheu | d57af9b | 2010-10-27 15:34:45 -0700 | [diff] [blame] | 24 | * Convert cputime to microseconds and back. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | */ |
Martin Schwidefsky | 6486163 | 2011-12-15 14:56:09 +0100 | [diff] [blame] | 26 | #define cputime_to_usecs(__ct) \ |
Linus Torvalds | 0db49b7 | 2012-01-06 08:33:28 -0800 | [diff] [blame^] | 27 | jiffies_to_usecs(cputime_to_jiffies(__ct)) |
| 28 | #define usecs_to_cputime(__usec) \ |
| 29 | jiffies_to_cputime(usecs_to_jiffies(__usec)) |
| 30 | #define usecs_to_cputime64(__usec) \ |
| 31 | jiffies64_to_cputime64(nsecs_to_jiffies64((__usec) * 1000)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
| 33 | /* |
| 34 | * Convert cputime to seconds and back. |
| 35 | */ |
Martin Schwidefsky | 6486163 | 2011-12-15 14:56:09 +0100 | [diff] [blame] | 36 | #define cputime_to_secs(jif) (cputime_to_jiffies(jif) / HZ) |
| 37 | #define secs_to_cputime(sec) jiffies_to_cputime((sec) * HZ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
| 39 | /* |
| 40 | * Convert cputime to timespec and back. |
| 41 | */ |
Martin Schwidefsky | 6486163 | 2011-12-15 14:56:09 +0100 | [diff] [blame] | 42 | #define timespec_to_cputime(__val) \ |
| 43 | jiffies_to_cputime(timespec_to_jiffies(__val)) |
| 44 | #define cputime_to_timespec(__ct,__val) \ |
| 45 | jiffies_to_timespec(cputime_to_jiffies(__ct),__val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
| 47 | /* |
| 48 | * Convert cputime to timeval and back. |
| 49 | */ |
Martin Schwidefsky | 6486163 | 2011-12-15 14:56:09 +0100 | [diff] [blame] | 50 | #define timeval_to_cputime(__val) \ |
| 51 | jiffies_to_cputime(timeval_to_jiffies(__val)) |
| 52 | #define cputime_to_timeval(__ct,__val) \ |
| 53 | jiffies_to_timeval(cputime_to_jiffies(__ct),__val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | /* |
| 56 | * Convert cputime to clock and back. |
| 57 | */ |
Martin Schwidefsky | 6486163 | 2011-12-15 14:56:09 +0100 | [diff] [blame] | 58 | #define cputime_to_clock_t(__ct) \ |
| 59 | jiffies_to_clock_t(cputime_to_jiffies(__ct)) |
| 60 | #define clock_t_to_cputime(__x) \ |
| 61 | jiffies_to_cputime(clock_t_to_jiffies(__x)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
| 63 | /* |
| 64 | * Convert cputime64 to clock. |
| 65 | */ |
Martin Schwidefsky | 6486163 | 2011-12-15 14:56:09 +0100 | [diff] [blame] | 66 | #define cputime64_to_clock_t(__ct) \ |
| 67 | jiffies_64_to_clock_t(cputime64_to_jiffies64(__ct)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
| 69 | #endif |