5 #include <linux/timex.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
);
15 u64 tmp
= (u64
)x
* TICK_NSEC
;
16 do_div(tmp
, (NSEC_PER_SEC
/ USER_HZ
));
21 static inline unsigned long clock_t_to_jiffies(unsigned long x
)
24 if (x
>= ~0UL / (HZ
/ USER_HZ
))
26 return x
* (HZ
/ USER_HZ
);
30 /* Don't worry about loss of precision here .. */
31 if (x
>= ~0UL / HZ
* USER_HZ
)
34 /* .. but do try to contain it here */
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
);
47 * There are better ways that don't overflow early,
48 * but even this doesn't overflow in hundreds of years
52 do_div(x
, (NSEC_PER_SEC
/ USER_HZ
));
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
64 do_div(x
, (NSEC_PER_SEC
/ 512));
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, ...
72 do_div(x
, (unsigned long)((9ull * NSEC_PER_SEC
+ (USER_HZ
/2))