staging: comedi: serial2002: Use monotonic clock
authorAbhilash Jindal <klock.android@gmail.com>
Tue, 11 Aug 2015 14:31:53 +0000 (10:31 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 15 Aug 2015 00:33:22 +0000 (17:33 -0700)
Wall time obtained from do_gettimeofday is susceptible to sudden jumps due to
user setting the time or due to NTP.

Monotonic time is constantly increasing time better suited for comparing two
timestamps.

Signed-off-by: Abhilash Jindal <klock.android@gmail.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/serial2002.c

index 83da162deb526c0a790efba41b23ff4784e563b8..5f19374c460de63f4431ca3bd73d241a0ba37c76 100644 (file)
@@ -32,6 +32,7 @@ Status: in development
 #include <linux/delay.h>
 #include <linux/sched.h>
 #include <linux/slab.h>
+#include <linux/ktime.h>
 
 #include <linux/termios.h>
 #include <asm/ioctls.h>
@@ -121,9 +122,9 @@ static int serial2002_tty_write(struct file *f, unsigned char *buf, int count)
 static void serial2002_tty_read_poll_wait(struct file *f, int timeout)
 {
        struct poll_wqueues table;
-       struct timeval start, now;
+       ktime_t start, now;
 
-       do_gettimeofday(&start);
+       start = ktime_get();
        poll_initwait(&table);
        while (1) {
                long elapsed;
@@ -134,9 +135,8 @@ static void serial2002_tty_read_poll_wait(struct file *f, int timeout)
                            POLLHUP | POLLERR)) {
                        break;
                }
-               do_gettimeofday(&now);
-               elapsed = 1000000 * (now.tv_sec - start.tv_sec) +
-                         now.tv_usec - start.tv_usec;
+               now = ktime_get();
+               elapsed = ktime_us_delta(now, start);
                if (elapsed > timeout)
                        break;
                set_current_state(TASK_INTERRUPTIBLE);
This page took 0.026256 seconds and 5 git commands to generate.