summaryrefslogtreecommitdiff
path: root/kernel/time.c
diff options
context:
space:
mode:
authorChristoph Lameter <clameter@sgi.com>2004-08-22 22:47:16 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2004-08-22 22:47:16 -0700
commitb9cbc585eda36c84edbf05c0e83e3bf950ff45fa (patch)
treeb23b0f8016bcfc8e256f5a61fa20803ba4ffada1 /kernel/time.c
parent346ed9c13aab9be890a8bd52d06fd6761876bb85 (diff)
[PATCH] gettimeofday nanoseconds patch
This issue was discussed on lkml and linux-ia64. The patch introduces "getnstimeofday" and removes all the code scaling gettimeofday to nanoseoncs. It makes it possible for the posix-timer functions to return higher accuracy. Signed-off-by: Christoph Lameter <clameter@sgi.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'kernel/time.c')
-rw-r--r--kernel/time.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/kernel/time.c b/kernel/time.c
index 68c22f2bf452..b0bdef2b7f20 100644
--- a/kernel/time.c
+++ b/kernel/time.c
@@ -22,6 +22,9 @@
* "A Kernel Model for Precision Timekeeping" by Dave Mills
* Allow time_constant larger than MAXTC(6) for NTP v4 (MAXTC == 10)
* (Even though the technical memorandum forbids it)
+ * 2004-07-14 Christoph Lameter
+ * Added getnstimeofday to allow the posix timer functions to return
+ * with nanosecond accuracy
*/
#include <linux/module.h>
@@ -421,6 +424,41 @@ struct timespec current_kernel_time(void)
EXPORT_SYMBOL(current_kernel_time);
+#ifdef CONFIG_TIME_INTERPOLATION
+void getnstimeofday (struct timespec *tv)
+{
+ unsigned long seq,sec,nsec;
+
+ do {
+ seq = read_seqbegin(&xtime_lock);
+ sec = xtime.tv_sec;
+ nsec = xtime.tv_nsec+time_interpolator_get_offset();
+ } while (unlikely(read_seqretry(&xtime_lock, seq)));
+
+ while (unlikely(nsec >= NSEC_PER_SEC)) {
+ nsec -= NSEC_PER_SEC;
+ ++sec;
+ }
+ tv->tv_sec = sec;
+ tv->tv_nsec = nsec;
+}
+#else
+/*
+ * Simulate gettimeofday using do_gettimeofday which only allows a timeval
+ * and therefore only yields usec accuracy
+ */
+void getnstimeofday(struct timespec *tv)
+{
+ struct timeval x;
+
+ do_gettimeofday(&x);
+ tv->tv_sec = x.tv_sec;
+ tv->tv_nsec = x.tv_usec * NSEC_PER_USEC;
+}
+#endif
+
+EXPORT_SYMBOL(getnstimeofday);
+
#if (BITS_PER_LONG < 64)
u64 get_jiffies_64(void)
{