diff options
| author | Tim Schmielau <tim@physik3.uni-rostock.de> | 2003-02-03 18:19:44 -0800 |
|---|---|---|
| committer | Linus Torvalds <torvalds@home.transmeta.com> | 2003-02-03 18:19:44 -0800 |
| commit | 3da2fe139367719839cf44325ba44eae3d37f38f (patch) | |
| tree | cf3a0d8a5add20617e315380ad8f402c312269a6 /include/linux | |
| parent | 81c0cfccff334bf6e9c35233fb53341ff1b47f9a (diff) | |
[PATCH] use 64 bit jiffies: infrastructure
Provide a sane way to avoid unneccessary locking on 64 bit platforms,
and a 64 bit analogous to "jiffies_to_clock_t()".
Diffstat (limited to 'include/linux')
| -rw-r--r-- | include/linux/jiffies.h | 22 | ||||
| -rw-r--r-- | include/linux/times.h | 23 |
2 files changed, 44 insertions, 1 deletions
diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h index 7367127511b3..c81b51bab1e3 100644 --- a/include/linux/jiffies.h +++ b/include/linux/jiffies.h @@ -2,15 +2,35 @@ #define _LINUX_JIFFIES_H #include <linux/types.h> +#include <linux/spinlock.h> +#include <asm/system.h> #include <asm/param.h> /* for HZ */ /* * The 64-bit value is not volatile - you MUST NOT read it - * without holding read_lock_irq(&xtime_lock) + * without holding read_lock_irq(&xtime_lock). + * get_jiffies_64() will do this for you as appropriate. */ extern u64 jiffies_64; extern unsigned long volatile jiffies; +static inline u64 get_jiffies_64(void) +{ +#if BITS_PER_LONG < 64 + extern rwlock_t xtime_lock; + unsigned long flags; + u64 tmp; + + read_lock_irqsave(&xtime_lock, flags); + tmp = jiffies_64; + read_unlock_irqrestore(&xtime_lock, flags); + return tmp; +#else + return (u64)jiffies; +#endif +} + + /* * These inlines deal with timer wrapping correctly. You are * strongly encouraged to use them diff --git a/include/linux/times.h b/include/linux/times.h index 1174e9f88ea2..9895fd31bd5f 100644 --- a/include/linux/times.h +++ b/include/linux/times.h @@ -2,7 +2,30 @@ #define _LINUX_TIMES_H #ifdef __KERNEL__ +#include <asm/div64.h> +#include <asm/types.h> + +#if (HZ % USER_HZ)==0 # define jiffies_to_clock_t(x) ((x) / (HZ / USER_HZ)) +#else +# define jiffies_to_clock_t(x) ((clock_t) jiffies_64_to_clock_t((u64) x)) +#endif + +static inline u64 jiffies_64_to_clock_t(u64 x) +{ +#if (HZ % USER_HZ)==0 + do_div(x, HZ / USER_HZ); +#else + /* + * There are better ways that don't overflow early, + * but even this doesn't overflow in hundreds of years + * in 64 bits, so.. + */ + x *= USER_HZ; + do_div(x, HZ); +#endif + return x; +} #endif struct tms { |
