Commit d38c59e9 authored by Abhilash Jindal's avatar Abhilash Jindal Committed by Greg Kroah-Hartman

staging: comedi: serial2002: Use monotonic clock

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: default avatarAbhilash Jindal <klock.android@gmail.com>
Reviewed-by: default avatarIan Abbott <abbotti@mev.co.uk>
Reviewed-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 365741e6
...@@ -32,6 +32,7 @@ Status: in development ...@@ -32,6 +32,7 @@ Status: in development
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/ktime.h>
#include <linux/termios.h> #include <linux/termios.h>
#include <asm/ioctls.h> #include <asm/ioctls.h>
...@@ -121,9 +122,9 @@ static int serial2002_tty_write(struct file *f, unsigned char *buf, int count) ...@@ -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) static void serial2002_tty_read_poll_wait(struct file *f, int timeout)
{ {
struct poll_wqueues table; struct poll_wqueues table;
struct timeval start, now; ktime_t start, now;
do_gettimeofday(&start); start = ktime_get();
poll_initwait(&table); poll_initwait(&table);
while (1) { while (1) {
long elapsed; long elapsed;
...@@ -134,9 +135,8 @@ static void serial2002_tty_read_poll_wait(struct file *f, int timeout) ...@@ -134,9 +135,8 @@ static void serial2002_tty_read_poll_wait(struct file *f, int timeout)
POLLHUP | POLLERR)) { POLLHUP | POLLERR)) {
break; break;
} }
do_gettimeofday(&now); now = ktime_get();
elapsed = 1000000 * (now.tv_sec - start.tv_sec) + elapsed = ktime_us_delta(now, start);
now.tv_usec - start.tv_usec;
if (elapsed > timeout) if (elapsed > timeout)
break; break;
set_current_state(TASK_INTERRUPTIBLE); set_current_state(TASK_INTERRUPTIBLE);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment