ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / include / linux / times.h
1 #ifndef _LINUX_TIMES_H
2 #define _LINUX_TIMES_H
3
4 #ifdef __KERNEL__
5 #include <asm/div64.h>
6 #include <asm/types.h>
7 #include <asm/param.h>
8
9 #if (HZ % USER_HZ)==0
10 # define jiffies_to_clock_t(x) ((x) / (HZ / USER_HZ))
11 #else
12 # define jiffies_to_clock_t(x) ((clock_t) jiffies_64_to_clock_t((u64) x))
13 #endif
14
15 static inline unsigned long clock_t_to_jiffies(unsigned long x)
16 {
17 #if (HZ % USER_HZ)==0
18         if (x >= ~0UL / (HZ / USER_HZ))
19                 return ~0UL;
20         return x * (HZ / USER_HZ);
21 #else
22         u64 jif;
23
24         /* Don't worry about loss of precision here .. */
25         if (x >= ~0UL / HZ * USER_HZ)
26                 return ~0UL;
27
28         /* .. but do try to contain it here */
29         jif = x * (u64) HZ;
30         do_div(jif, USER_HZ);
31         return jif;
32 #endif
33 }
34
35 static inline u64 jiffies_64_to_clock_t(u64 x)
36 {
37 #if (HZ % USER_HZ)==0
38         do_div(x, HZ / USER_HZ);
39 #else
40         /*
41          * There are better ways that don't overflow early,
42          * but even this doesn't overflow in hundreds of years
43          * in 64 bits, so..
44          */
45         x *= USER_HZ;
46         do_div(x, HZ);
47 #endif
48         return x;
49 }
50 #endif
51
52 struct tms {
53         clock_t tms_utime;
54         clock_t tms_stime;
55         clock_t tms_cutime;
56         clock_t tms_cstime;
57 };
58
59 #endif