diff options
Diffstat (limited to 'include/asm-powerpc/cputime.h')
| -rw-r--r-- | include/asm-powerpc/cputime.h | 202 |
1 files changed, 202 insertions, 0 deletions
diff --git a/include/asm-powerpc/cputime.h b/include/asm-powerpc/cputime.h index 6d68ad7e0ea3..a21185d47883 100644 --- a/include/asm-powerpc/cputime.h +++ b/include/asm-powerpc/cputime.h | |||
| @@ -1 +1,203 @@ | |||
| 1 | /* | ||
| 2 | * Definitions for measuring cputime on powerpc machines. | ||
| 3 | * | ||
| 4 | * Copyright (C) 2006 Paul Mackerras, IBM Corp. | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or | ||
| 7 | * modify it under the terms of the GNU General Public License | ||
| 8 | * as published by the Free Software Foundation; either version | ||
| 9 | * 2 of the License, or (at your option) any later version. | ||
| 10 | * | ||
| 11 | * If we have CONFIG_VIRT_CPU_ACCOUNTING, we measure cpu time in | ||
| 12 | * the same units as the timebase. Otherwise we measure cpu time | ||
| 13 | * in jiffies using the generic definitions. | ||
| 14 | */ | ||
| 15 | |||
| 16 | #ifndef __POWERPC_CPUTIME_H | ||
| 17 | #define __POWERPC_CPUTIME_H | ||
| 18 | |||
| 19 | #ifndef CONFIG_VIRT_CPU_ACCOUNTING | ||
| 1 | #include <asm-generic/cputime.h> | 20 | #include <asm-generic/cputime.h> |
| 21 | #else | ||
| 22 | |||
| 23 | #include <linux/types.h> | ||
| 24 | #include <linux/time.h> | ||
| 25 | #include <asm/div64.h> | ||
| 26 | #include <asm/time.h> | ||
| 27 | #include <asm/param.h> | ||
| 28 | |||
| 29 | typedef u64 cputime_t; | ||
| 30 | typedef u64 cputime64_t; | ||
| 31 | |||
| 32 | #define cputime_zero ((cputime_t)0) | ||
| 33 | #define cputime_max ((~((cputime_t)0) >> 1) - 1) | ||
| 34 | #define cputime_add(__a, __b) ((__a) + (__b)) | ||
| 35 | #define cputime_sub(__a, __b) ((__a) - (__b)) | ||
| 36 | #define cputime_div(__a, __n) ((__a) / (__n)) | ||
| 37 | #define cputime_halve(__a) ((__a) >> 1) | ||
| 38 | #define cputime_eq(__a, __b) ((__a) == (__b)) | ||
| 39 | #define cputime_gt(__a, __b) ((__a) > (__b)) | ||
| 40 | #define cputime_ge(__a, __b) ((__a) >= (__b)) | ||
| 41 | #define cputime_lt(__a, __b) ((__a) < (__b)) | ||
| 42 | #define cputime_le(__a, __b) ((__a) <= (__b)) | ||
| 43 | |||
| 44 | #define cputime64_zero ((cputime64_t)0) | ||
| 45 | #define cputime64_add(__a, __b) ((__a) + (__b)) | ||
| 46 | #define cputime_to_cputime64(__ct) (__ct) | ||
| 47 | |||
| 48 | #ifdef __KERNEL__ | ||
| 49 | |||
| 50 | /* | ||
| 51 | * Convert cputime <-> jiffies | ||
| 52 | */ | ||
| 53 | extern u64 __cputime_jiffies_factor; | ||
| 54 | |||
| 55 | static inline unsigned long cputime_to_jiffies(const cputime_t ct) | ||
| 56 | { | ||
| 57 | return mulhdu(ct, __cputime_jiffies_factor); | ||
| 58 | } | ||
| 59 | |||
| 60 | static inline cputime_t jiffies_to_cputime(const unsigned long jif) | ||
| 61 | { | ||
| 62 | cputime_t ct; | ||
| 63 | unsigned long sec; | ||
| 64 | |||
| 65 | /* have to be a little careful about overflow */ | ||
| 66 | ct = jif % HZ; | ||
| 67 | sec = jif / HZ; | ||
| 68 | if (ct) { | ||
| 69 | ct *= tb_ticks_per_sec; | ||
| 70 | do_div(ct, HZ); | ||
| 71 | } | ||
| 72 | if (sec) | ||
| 73 | ct += (cputime_t) sec * tb_ticks_per_sec; | ||
| 74 | return ct; | ||
| 75 | } | ||
| 76 | |||
| 77 | static inline u64 cputime64_to_jiffies64(const cputime_t ct) | ||
| 78 | { | ||
| 79 | return mulhdu(ct, __cputime_jiffies_factor); | ||
| 80 | } | ||
| 81 | |||
| 82 | /* | ||
| 83 | * Convert cputime <-> milliseconds | ||
| 84 | */ | ||
| 85 | extern u64 __cputime_msec_factor; | ||
| 86 | |||
| 87 | static inline unsigned long cputime_to_msecs(const cputime_t ct) | ||
| 88 | { | ||
| 89 | return mulhdu(ct, __cputime_msec_factor); | ||
| 90 | } | ||
| 91 | |||
| 92 | static inline cputime_t msecs_to_cputime(const unsigned long ms) | ||
| 93 | { | ||
| 94 | cputime_t ct; | ||
| 95 | unsigned long sec; | ||
| 96 | |||
| 97 | /* have to be a little careful about overflow */ | ||
| 98 | ct = ms % 1000; | ||
| 99 | sec = ms / 1000; | ||
| 100 | if (ct) { | ||
| 101 | ct *= tb_ticks_per_sec; | ||
| 102 | do_div(ct, 1000); | ||
| 103 | } | ||
| 104 | if (sec) | ||
| 105 | ct += (cputime_t) sec * tb_ticks_per_sec; | ||
| 106 | return ct; | ||
| 107 | } | ||
| 108 | |||
| 109 | /* | ||
| 110 | * Convert cputime <-> seconds | ||
| 111 | */ | ||
| 112 | extern u64 __cputime_sec_factor; | ||
| 113 | |||
| 114 | static inline unsigned long cputime_to_secs(const cputime_t ct) | ||
| 115 | { | ||
| 116 | return mulhdu(ct, __cputime_sec_factor); | ||
| 117 | } | ||
| 118 | |||
| 119 | static inline cputime_t secs_to_cputime(const unsigned long sec) | ||
| 120 | { | ||
| 121 | return (cputime_t) sec * tb_ticks_per_sec; | ||
| 122 | } | ||
| 123 | |||
| 124 | /* | ||
| 125 | * Convert cputime <-> timespec | ||
| 126 | */ | ||
| 127 | static inline void cputime_to_timespec(const cputime_t ct, struct timespec *p) | ||
| 128 | { | ||
| 129 | u64 x = ct; | ||
| 130 | unsigned int frac; | ||
| 131 | |||
| 132 | frac = do_div(x, tb_ticks_per_sec); | ||
| 133 | p->tv_sec = x; | ||
| 134 | x = (u64) frac * 1000000000; | ||
| 135 | do_div(x, tb_ticks_per_sec); | ||
| 136 | p->tv_nsec = x; | ||
| 137 | } | ||
| 138 | |||
| 139 | static inline cputime_t timespec_to_cputime(const struct timespec *p) | ||
| 140 | { | ||
| 141 | cputime_t ct; | ||
| 142 | |||
| 143 | ct = (u64) p->tv_nsec * tb_ticks_per_sec; | ||
| 144 | do_div(ct, 1000000000); | ||
| 145 | return ct + (u64) p->tv_sec * tb_ticks_per_sec; | ||
| 146 | } | ||
| 147 | |||
| 148 | /* | ||
| 149 | * Convert cputime <-> timeval | ||
| 150 | */ | ||
| 151 | static inline void cputime_to_timeval(const cputime_t ct, struct timeval *p) | ||
| 152 | { | ||
| 153 | u64 x = ct; | ||
| 154 | unsigned int frac; | ||
| 155 | |||
| 156 | frac = do_div(x, tb_ticks_per_sec); | ||
| 157 | p->tv_sec = x; | ||
| 158 | x = (u64) frac * 1000000; | ||
| 159 | do_div(x, tb_ticks_per_sec); | ||
| 160 | p->tv_usec = x; | ||
| 161 | } | ||
| 162 | |||
| 163 | static inline cputime_t timeval_to_cputime(const struct timeval *p) | ||
| 164 | { | ||
| 165 | cputime_t ct; | ||
| 166 | |||
| 167 | ct = (u64) p->tv_usec * tb_ticks_per_sec; | ||
| 168 | do_div(ct, 1000000); | ||
| 169 | return ct + (u64) p->tv_sec * tb_ticks_per_sec; | ||
| 170 | } | ||
| 171 | |||
| 172 | /* | ||
| 173 | * Convert cputime <-> clock_t (units of 1/USER_HZ seconds) | ||
| 174 | */ | ||
| 175 | extern u64 __cputime_clockt_factor; | ||
| 176 | |||
| 177 | static inline unsigned long cputime_to_clock_t(const cputime_t ct) | ||
| 178 | { | ||
| 179 | return mulhdu(ct, __cputime_clockt_factor); | ||
| 180 | } | ||
| 181 | |||
| 182 | static inline cputime_t clock_t_to_cputime(const unsigned long clk) | ||
| 183 | { | ||
| 184 | cputime_t ct; | ||
| 185 | unsigned long sec; | ||
| 186 | |||
| 187 | /* have to be a little careful about overflow */ | ||
| 188 | ct = clk % USER_HZ; | ||
| 189 | sec = clk / USER_HZ; | ||
| 190 | if (ct) { | ||
| 191 | ct *= tb_ticks_per_sec; | ||
| 192 | do_div(ct, USER_HZ); | ||
| 193 | } | ||
| 194 | if (sec) | ||
| 195 | ct += (cputime_t) sec * tb_ticks_per_sec; | ||
| 196 | return ct; | ||
| 197 | } | ||
| 198 | |||
| 199 | #define cputime64_to_clock_t(ct) cputime_to_clock_t((cputime_t)(ct)) | ||
| 200 | |||
| 201 | #endif /* __KERNEL__ */ | ||
| 202 | #endif /* CONFIG_VIRT_CPU_ACCOUNTING */ | ||
| 203 | #endif /* __POWERPC_CPUTIME_H */ | ||
