summaryrefslogtreecommitdiff
path: root/include/linux
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/jiffies.h22
-rw-r--r--include/linux/times.h23
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 {