MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / include / linux / times.h
blob0c5aa078dad4a2daf0b3523da9ef1b1b072ad147
1 #ifndef _LINUX_TIMES_H
2 #define _LINUX_TIMES_H
4 #ifdef __KERNEL__
5 #include <linux/timex.h>
6 #include <asm/div64.h>
7 #include <asm/types.h>
8 #include <asm/param.h>
10 static inline clock_t jiffies_to_clock_t(long x)
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
21 static inline unsigned long clock_t_to_jiffies(unsigned long x)
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;
30 /* Don't worry about loss of precision here .. */
31 if (x >= ~0UL / HZ * USER_HZ)
32 return ~0UL;
34 /* .. but do try to contain it here */
35 jif = x * (u64) HZ;
36 do_div(jif, USER_HZ);
37 return jif;
38 #endif
41 static inline u64 jiffies_64_to_clock_t(u64 x)
43 #if (TICK_NSEC % (NSEC_PER_SEC / USER_HZ)) == 0
44 do_div(x, HZ / USER_HZ);
45 #else
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..
51 x *= TICK_NSEC;
52 do_div(x, (NSEC_PER_SEC / USER_HZ));
53 #endif
54 return x;
56 #endif
58 static inline u64 nsec_to_clock_t(u64 x)
60 #if (NSEC_PER_SEC % USER_HZ) == 0
61 do_div(x, (NSEC_PER_SEC / USER_HZ));
62 #elif (USER_HZ % 512) == 0
63 x *= USER_HZ/512;
64 do_div(x, (NSEC_PER_SEC / 512));
65 #else
67 * max relative error 5.7e-8 (1.8s per year) for USER_HZ <= 1024,
68 * overflow after 64.99 years.
69 * exact for HZ=60, 72, 90, 120, 144, 180, 300, 600, 900, ...
71 x *= 9;
72 do_div(x, (unsigned long)((9ull * NSEC_PER_SEC + (USER_HZ/2))
73 / USER_HZ));
74 #endif
75 return x;
78 struct tms {
79 clock_t tms_utime;
80 clock_t tms_stime;
81 clock_t tms_cutime;
82 clock_t tms_cstime;
85 #endif