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