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_NATIVE, 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_NATIVE
20 #include <asm-generic/cputime.h>
22 static inline void setup_cputime_one_jiffy(void) { }
26 #include <linux/types.h>
27 #include <linux/time.h>
28 #include <asm/div64.h>
30 #include <asm/param.h>
32 typedef u64 __nocast cputime_t
;
33 typedef u64 __nocast cputime64_t
;
38 * One jiffy in timebase units computed during initialization
40 extern cputime_t cputime_one_jiffy
;
43 * Convert cputime <-> jiffies
45 extern u64 __cputime_jiffies_factor
;
46 DECLARE_PER_CPU(unsigned long, cputime_last_delta
);
47 DECLARE_PER_CPU(unsigned long, cputime_scaled_last_delta
);
49 static inline unsigned long cputime_to_jiffies(const cputime_t ct
)
51 return mulhdu((__force u64
) ct
, __cputime_jiffies_factor
);
54 /* Estimate the scaled cputime by scaling the real cputime based on
55 * the last scaled to real ratio */
56 static inline cputime_t
cputime_to_scaled(const cputime_t ct
)
58 if (cpu_has_feature(CPU_FTR_SPURR
) &&
59 __get_cpu_var(cputime_last_delta
))
60 return (__force u64
) ct
*
61 __get_cpu_var(cputime_scaled_last_delta
) /
62 __get_cpu_var(cputime_last_delta
);
66 static inline cputime_t
jiffies_to_cputime(const unsigned long jif
)
71 /* have to be a little careful about overflow */
75 ct
*= tb_ticks_per_sec
;
79 ct
+= (cputime_t
) sec
* tb_ticks_per_sec
;
80 return (__force cputime_t
) ct
;
83 static inline void setup_cputime_one_jiffy(void)
85 cputime_one_jiffy
= jiffies_to_cputime(1);
88 static inline cputime64_t
jiffies64_to_cputime64(const u64 jif
)
93 /* have to be a little careful about overflow */
97 ct
*= tb_ticks_per_sec
;
101 ct
+= (u64
) sec
* tb_ticks_per_sec
;
102 return (__force cputime64_t
) ct
;
105 static inline u64
cputime64_to_jiffies64(const cputime_t ct
)
107 return mulhdu((__force u64
) ct
, __cputime_jiffies_factor
);
111 * Convert cputime <-> microseconds
113 extern u64 __cputime_usec_factor
;
115 static inline unsigned long cputime_to_usecs(const cputime_t ct
)
117 return mulhdu((__force u64
) ct
, __cputime_usec_factor
);
120 static inline cputime_t
usecs_to_cputime(const unsigned long us
)
125 /* have to be a little careful about overflow */
129 ct
*= tb_ticks_per_sec
;
133 ct
+= (cputime_t
) sec
* tb_ticks_per_sec
;
134 return (__force cputime_t
) ct
;
137 #define usecs_to_cputime64(us) usecs_to_cputime(us)
140 * Convert cputime <-> seconds
142 extern u64 __cputime_sec_factor
;
144 static inline unsigned long cputime_to_secs(const cputime_t ct
)
146 return mulhdu((__force u64
) ct
, __cputime_sec_factor
);
149 static inline cputime_t
secs_to_cputime(const unsigned long sec
)
151 return (__force cputime_t
)((u64
) sec
* tb_ticks_per_sec
);
155 * Convert cputime <-> timespec
157 static inline void cputime_to_timespec(const cputime_t ct
, struct timespec
*p
)
159 u64 x
= (__force u64
) ct
;
162 frac
= do_div(x
, tb_ticks_per_sec
);
164 x
= (u64
) frac
* 1000000000;
165 do_div(x
, tb_ticks_per_sec
);
169 static inline cputime_t
timespec_to_cputime(const struct timespec
*p
)
173 ct
= (u64
) p
->tv_nsec
* tb_ticks_per_sec
;
174 do_div(ct
, 1000000000);
175 return (__force cputime_t
)(ct
+ (u64
) p
->tv_sec
* tb_ticks_per_sec
);
179 * Convert cputime <-> timeval
181 static inline void cputime_to_timeval(const cputime_t ct
, struct timeval
*p
)
183 u64 x
= (__force u64
) ct
;
186 frac
= do_div(x
, tb_ticks_per_sec
);
188 x
= (u64
) frac
* 1000000;
189 do_div(x
, tb_ticks_per_sec
);
193 static inline cputime_t
timeval_to_cputime(const struct timeval
*p
)
197 ct
= (u64
) p
->tv_usec
* tb_ticks_per_sec
;
199 return (__force cputime_t
)(ct
+ (u64
) p
->tv_sec
* tb_ticks_per_sec
);
203 * Convert cputime <-> clock_t (units of 1/USER_HZ seconds)
205 extern u64 __cputime_clockt_factor
;
207 static inline unsigned long cputime_to_clock_t(const cputime_t ct
)
209 return mulhdu((__force u64
) ct
, __cputime_clockt_factor
);
212 static inline cputime_t
clock_t_to_cputime(const unsigned long clk
)
217 /* have to be a little careful about overflow */
221 ct
*= tb_ticks_per_sec
;
225 ct
+= (u64
) sec
* tb_ticks_per_sec
;
226 return (__force cputime_t
) ct
;
229 #define cputime64_to_clock_t(ct) cputime_to_clock_t((cputime_t)(ct))
231 static inline void arch_vtime_task_switch(struct task_struct
*tsk
) { }
233 #endif /* __KERNEL__ */
234 #endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
235 #endif /* __POWERPC_CPUTIME_H */