Re: [PATCH] staging: comedi: Use monotonic clock

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 11/08/15 15:31, Abhilash Jindal wrote:
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@xxxxxxxxx>
---
  drivers/staging/comedi/drivers/serial2002.c |   10 +++++-----
  1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/comedi/drivers/serial2002.c b/drivers/staging/comedi/drivers/serial2002.c
index 83da162..5f19374 100644
--- a/drivers/staging/comedi/drivers/serial2002.c
+++ b/drivers/staging/comedi/drivers/serial2002.c
@@ -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);


Thanks, and sorry for the email address mix-up earlier!

Reviewed-by: Ian Abbott <abbotti@xxxxxxxxx>

--
-=( Ian Abbott @ MEV Ltd.    E-mail: <abbotti@xxxxxxxxx> )=-
-=(                          Web: http://www.mev.co.uk/  )=-
_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel



[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux