diff options
| author | Linus Torvalds <torvalds@home.osdl.org> | 2003-07-16 19:54:52 -0700 |
|---|---|---|
| committer | Linus Torvalds <torvalds@home.osdl.org> | 2003-07-16 19:54:52 -0700 |
| commit | 220443f8fa6562345e6848fa9f3c956343daf0d6 (patch) | |
| tree | 4eb8005b1a547b0359d818fd187dddf4f82674ad /include/linux | |
| parent | faa3c7787357bab31158988fd5405869a3740717 (diff) | |
Add "clock_t_to_jiffies()" conversion function with
some rather minimal overflow protection.
Diffstat (limited to 'include/linux')
| -rw-r--r-- | include/linux/times.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/include/linux/times.h b/include/linux/times.h index 9895fd31bd5f..42eff6b7b08d 100644 --- a/include/linux/times.h +++ b/include/linux/times.h @@ -11,6 +11,26 @@ # define jiffies_to_clock_t(x) ((clock_t) jiffies_64_to_clock_t((u64) x)) #endif +static inline unsigned long clock_t_to_jiffies(unsigned long x) +{ +#if (HZ % USER_HZ)==0 + if (x >= ~0UL / (HZ / USER_HZ)) + return ~0UL; + return x * (HZ / USER_HZ); +#else + u64 jif; + + /* Don't worry about loss of precision here .. */ + if (x >= ~0UL / HZ * USER_HZ) + return ~0UL; + + /* .. but do try to contain it here */ + jif = x * (u64) HZ; + do_div(jif, USER_HZ); + return jif; +#endif +} + static inline u64 jiffies_64_to_clock_t(u64 x) { #if (HZ % USER_HZ)==0 |
