x86: pit_clockevent can be static
[wrt350n-kernel.git] / include / asm-powerpc / cputime.h
blobf42e623030eece0edb4a8f30c37db795c44f2395
1 /*
2 * Definitions for measuring cputime on powerpc machines.
4 * Copyright (C) 2006 Paul Mackerras, IBM Corp.
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.
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.
16 #ifndef __POWERPC_CPUTIME_H
17 #define __POWERPC_CPUTIME_H
19 #ifndef CONFIG_VIRT_CPU_ACCOUNTING
20 #include <asm-generic/cputime.h>
21 #else
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>
29 typedef u64 cputime_t;
30 typedef u64 cputime64_t;
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))
44 #define cputime64_zero ((cputime64_t)0)
45 #define cputime64_add(__a, __b) ((__a) + (__b))
46 #define cputime64_sub(__a, __b) ((__a) - (__b))
47 #define cputime_to_cputime64(__ct) (__ct)
49 #ifdef __KERNEL__
52 * Convert cputime <-> jiffies
54 extern u64 __cputime_jiffies_factor;
55 DECLARE_PER_CPU(unsigned long, cputime_last_delta);
56 DECLARE_PER_CPU(unsigned long, cputime_scaled_last_delta);
58 static inline unsigned long cputime_to_jiffies(const cputime_t ct)
60 return mulhdu(ct, __cputime_jiffies_factor);
63 /* Estimate the scaled cputime by scaling the real cputime based on
64 * the last scaled to real ratio */
65 static inline cputime_t cputime_to_scaled(const cputime_t ct)
67 if (cpu_has_feature(CPU_FTR_SPURR) &&
68 per_cpu(cputime_last_delta, smp_processor_id()))
69 return ct *
70 per_cpu(cputime_scaled_last_delta, smp_processor_id())/
71 per_cpu(cputime_last_delta, smp_processor_id());
72 return ct;
75 static inline cputime_t jiffies_to_cputime(const unsigned long jif)
77 cputime_t ct;
78 unsigned long sec;
80 /* have to be a little careful about overflow */
81 ct = jif % HZ;
82 sec = jif / HZ;
83 if (ct) {
84 ct *= tb_ticks_per_sec;
85 do_div(ct, HZ);
87 if (sec)
88 ct += (cputime_t) sec * tb_ticks_per_sec;
89 return ct;
92 static inline cputime64_t jiffies64_to_cputime64(const u64 jif)
94 cputime_t ct;
95 u64 sec;
97 /* have to be a little careful about overflow */
98 ct = jif % HZ;
99 sec = jif / HZ;
100 if (ct) {
101 ct *= tb_ticks_per_sec;
102 do_div(ct, HZ);
104 if (sec)
105 ct += (cputime_t) sec * tb_ticks_per_sec;
106 return ct;
109 static inline u64 cputime64_to_jiffies64(const cputime_t ct)
111 return mulhdu(ct, __cputime_jiffies_factor);
115 * Convert cputime <-> milliseconds
117 extern u64 __cputime_msec_factor;
119 static inline unsigned long cputime_to_msecs(const cputime_t ct)
121 return mulhdu(ct, __cputime_msec_factor);
124 static inline cputime_t msecs_to_cputime(const unsigned long ms)
126 cputime_t ct;
127 unsigned long sec;
129 /* have to be a little careful about overflow */
130 ct = ms % 1000;
131 sec = ms / 1000;
132 if (ct) {
133 ct *= tb_ticks_per_sec;
134 do_div(ct, 1000);
136 if (sec)
137 ct += (cputime_t) sec * tb_ticks_per_sec;
138 return ct;
142 * Convert cputime <-> seconds
144 extern u64 __cputime_sec_factor;
146 static inline unsigned long cputime_to_secs(const cputime_t ct)
148 return mulhdu(ct, __cputime_sec_factor);
151 static inline cputime_t secs_to_cputime(const unsigned long sec)
153 return (cputime_t) sec * tb_ticks_per_sec;
157 * Convert cputime <-> timespec
159 static inline void cputime_to_timespec(const cputime_t ct, struct timespec *p)
161 u64 x = ct;
162 unsigned int frac;
164 frac = do_div(x, tb_ticks_per_sec);
165 p->tv_sec = x;
166 x = (u64) frac * 1000000000;
167 do_div(x, tb_ticks_per_sec);
168 p->tv_nsec = x;
171 static inline cputime_t timespec_to_cputime(const struct timespec *p)
173 cputime_t ct;
175 ct = (u64) p->tv_nsec * tb_ticks_per_sec;
176 do_div(ct, 1000000000);
177 return ct + (u64) p->tv_sec * tb_ticks_per_sec;
181 * Convert cputime <-> timeval
183 static inline void cputime_to_timeval(const cputime_t ct, struct timeval *p)
185 u64 x = ct;
186 unsigned int frac;
188 frac = do_div(x, tb_ticks_per_sec);
189 p->tv_sec = x;
190 x = (u64) frac * 1000000;
191 do_div(x, tb_ticks_per_sec);
192 p->tv_usec = x;
195 static inline cputime_t timeval_to_cputime(const struct timeval *p)
197 cputime_t ct;
199 ct = (u64) p->tv_usec * tb_ticks_per_sec;
200 do_div(ct, 1000000);
201 return ct + (u64) p->tv_sec * tb_ticks_per_sec;
205 * Convert cputime <-> clock_t (units of 1/USER_HZ seconds)
207 extern u64 __cputime_clockt_factor;
209 static inline unsigned long cputime_to_clock_t(const cputime_t ct)
211 return mulhdu(ct, __cputime_clockt_factor);
214 static inline cputime_t clock_t_to_cputime(const unsigned long clk)
216 cputime_t ct;
217 unsigned long sec;
219 /* have to be a little careful about overflow */
220 ct = clk % USER_HZ;
221 sec = clk / USER_HZ;
222 if (ct) {
223 ct *= tb_ticks_per_sec;
224 do_div(ct, USER_HZ);
226 if (sec)
227 ct += (cputime_t) sec * tb_ticks_per_sec;
228 return ct;
231 #define cputime64_to_clock_t(ct) cputime_to_clock_t((cputime_t)(ct))
233 #endif /* __KERNEL__ */
234 #endif /* CONFIG_VIRT_CPU_ACCOUNTING */
235 #endif /* __POWERPC_CPUTIME_H */