compat: generic compat_sys_sched_rr_get_interval() implementation
[deliverable/linux.git] / arch / powerpc / include / asm / cputime.h
CommitLineData
c6622f63
PM
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
88999ceb 20#include <asm-generic/cputime.h>
a42548a1
SG
21#ifdef __KERNEL__
22static inline void setup_cputime_one_jiffy(void) { }
23#endif
c6622f63
PM
24#else
25
26#include <linux/types.h>
27#include <linux/time.h>
28#include <asm/div64.h>
29#include <asm/time.h>
30#include <asm/param.h>
31
64861634
MS
32typedef u64 __nocast cputime_t;
33typedef u64 __nocast cputime64_t;
c6622f63
PM
34
35#ifdef __KERNEL__
36
a42548a1
SG
37/*
38 * One jiffy in timebase units computed during initialization
39 */
40extern cputime_t cputime_one_jiffy;
41
c6622f63
PM
42/*
43 * Convert cputime <-> jiffies
44 */
45extern u64 __cputime_jiffies_factor;
06b8e878
MN
46DECLARE_PER_CPU(unsigned long, cputime_last_delta);
47DECLARE_PER_CPU(unsigned long, cputime_scaled_last_delta);
c6622f63
PM
48
49static inline unsigned long cputime_to_jiffies(const cputime_t ct)
50{
64861634 51 return mulhdu((__force u64) ct, __cputime_jiffies_factor);
c6622f63
PM
52}
53
06b8e878
MN
54/* Estimate the scaled cputime by scaling the real cputime based on
55 * the last scaled to real ratio */
56static inline cputime_t cputime_to_scaled(const cputime_t ct)
57{
58 if (cpu_has_feature(CPU_FTR_SPURR) &&
61c03ddb 59 __get_cpu_var(cputime_last_delta))
64861634
MS
60 return (__force u64) ct *
61 __get_cpu_var(cputime_scaled_last_delta) /
62 __get_cpu_var(cputime_last_delta);
06b8e878
MN
63 return ct;
64}
65
c6622f63
PM
66static inline cputime_t jiffies_to_cputime(const unsigned long jif)
67{
64861634 68 u64 ct;
c6622f63
PM
69 unsigned long sec;
70
71 /* have to be a little careful about overflow */
72 ct = jif % HZ;
73 sec = jif / HZ;
74 if (ct) {
75 ct *= tb_ticks_per_sec;
76 do_div(ct, HZ);
77 }
78 if (sec)
79 ct += (cputime_t) sec * tb_ticks_per_sec;
64861634 80 return (__force cputime_t) ct;
c6622f63
PM
81}
82
a42548a1
SG
83static inline void setup_cputime_one_jiffy(void)
84{
85 cputime_one_jiffy = jiffies_to_cputime(1);
86}
87
a8e0c51c
DW
88static inline cputime64_t jiffies64_to_cputime64(const u64 jif)
89{
64861634 90 u64 ct;
a8e0c51c
DW
91 u64 sec;
92
93 /* have to be a little careful about overflow */
94 ct = jif % HZ;
95 sec = jif / HZ;
96 if (ct) {
97 ct *= tb_ticks_per_sec;
98 do_div(ct, HZ);
99 }
100 if (sec)
64861634
MS
101 ct += (u64) sec * tb_ticks_per_sec;
102 return (__force cputime64_t) ct;
a8e0c51c
DW
103}
104
c6622f63
PM
105static inline u64 cputime64_to_jiffies64(const cputime_t ct)
106{
64861634 107 return mulhdu((__force u64) ct, __cputime_jiffies_factor);
c6622f63
PM
108}
109
110/*
d57af9b2 111 * Convert cputime <-> microseconds
c6622f63 112 */
9f5072d4 113extern u64 __cputime_usec_factor;
c6622f63 114
d57af9b2 115static inline unsigned long cputime_to_usecs(const cputime_t ct)
c6622f63 116{
e4e88f31 117 return mulhdu((__force u64) ct, __cputime_usec_factor);
c6622f63
PM
118}
119
d57af9b2 120static inline cputime_t usecs_to_cputime(const unsigned long us)
c6622f63 121{
64861634 122 u64 ct;
c6622f63
PM
123 unsigned long sec;
124
125 /* have to be a little careful about overflow */
d57af9b2
MH
126 ct = us % 1000000;
127 sec = us / 1000000;
c6622f63
PM
128 if (ct) {
129 ct *= tb_ticks_per_sec;
9f5072d4 130 do_div(ct, 1000000);
c6622f63
PM
131 }
132 if (sec)
133 ct += (cputime_t) sec * tb_ticks_per_sec;
64861634 134 return (__force cputime_t) ct;
c6622f63
PM
135}
136
34845636
AS
137#define usecs_to_cputime64(us) usecs_to_cputime(us)
138
c6622f63
PM
139/*
140 * Convert cputime <-> seconds
141 */
142extern u64 __cputime_sec_factor;
143
144static inline unsigned long cputime_to_secs(const cputime_t ct)
145{
64861634 146 return mulhdu((__force u64) ct, __cputime_sec_factor);
c6622f63
PM
147}
148
149static inline cputime_t secs_to_cputime(const unsigned long sec)
150{
64861634 151 return (__force cputime_t)((u64) sec * tb_ticks_per_sec);
c6622f63
PM
152}
153
154/*
155 * Convert cputime <-> timespec
156 */
157static inline void cputime_to_timespec(const cputime_t ct, struct timespec *p)
158{
64861634 159 u64 x = (__force u64) ct;
c6622f63
PM
160 unsigned int frac;
161
162 frac = do_div(x, tb_ticks_per_sec);
163 p->tv_sec = x;
164 x = (u64) frac * 1000000000;
165 do_div(x, tb_ticks_per_sec);
166 p->tv_nsec = x;
167}
168
169static inline cputime_t timespec_to_cputime(const struct timespec *p)
170{
64861634 171 u64 ct;
c6622f63
PM
172
173 ct = (u64) p->tv_nsec * tb_ticks_per_sec;
174 do_div(ct, 1000000000);
64861634 175 return (__force cputime_t)(ct + (u64) p->tv_sec * tb_ticks_per_sec);
c6622f63
PM
176}
177
178/*
179 * Convert cputime <-> timeval
180 */
181static inline void cputime_to_timeval(const cputime_t ct, struct timeval *p)
182{
64861634 183 u64 x = (__force u64) ct;
c6622f63
PM
184 unsigned int frac;
185
186 frac = do_div(x, tb_ticks_per_sec);
187 p->tv_sec = x;
188 x = (u64) frac * 1000000;
189 do_div(x, tb_ticks_per_sec);
190 p->tv_usec = x;
191}
192
193static inline cputime_t timeval_to_cputime(const struct timeval *p)
194{
64861634 195 u64 ct;
c6622f63
PM
196
197 ct = (u64) p->tv_usec * tb_ticks_per_sec;
198 do_div(ct, 1000000);
64861634 199 return (__force cputime_t)(ct + (u64) p->tv_sec * tb_ticks_per_sec);
c6622f63
PM
200}
201
202/*
203 * Convert cputime <-> clock_t (units of 1/USER_HZ seconds)
204 */
205extern u64 __cputime_clockt_factor;
206
207static inline unsigned long cputime_to_clock_t(const cputime_t ct)
208{
64861634 209 return mulhdu((__force u64) ct, __cputime_clockt_factor);
c6622f63
PM
210}
211
212static inline cputime_t clock_t_to_cputime(const unsigned long clk)
213{
64861634 214 u64 ct;
c6622f63
PM
215 unsigned long sec;
216
217 /* have to be a little careful about overflow */
218 ct = clk % USER_HZ;
219 sec = clk / USER_HZ;
220 if (ct) {
221 ct *= tb_ticks_per_sec;
222 do_div(ct, USER_HZ);
223 }
224 if (sec)
64861634
MS
225 ct += (u64) sec * tb_ticks_per_sec;
226 return (__force cputime_t) ct;
c6622f63
PM
227}
228
229#define cputime64_to_clock_t(ct) cputime_to_clock_t((cputime_t)(ct))
230
e3942ba0
FW
231static inline void arch_vtime_task_switch(struct task_struct *tsk) { }
232
c6622f63
PM
233#endif /* __KERNEL__ */
234#endif /* CONFIG_VIRT_CPU_ACCOUNTING */
235#endif /* __POWERPC_CPUTIME_H */
This page took 0.561324 seconds and 5 git commands to generate.