[PATCH] usbtest: Use boottime

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

 



Wall time obtained from do_gettimeofday is susceptible to sudden jumps due to
user setting the time or due to NTP.  Boot time is constantly increasing time
better suited for comparing two timestamps.

Signed-off-by: Abhilash Jindal <klock.android@xxxxxxxxx>
---
 drivers/usb/misc/usbtest.c |   15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
index 0bbafe7..61cc639 100644
--- a/drivers/usb/misc/usbtest.c
+++ b/drivers/usb/misc/usbtest.c
@@ -30,7 +30,7 @@ struct usbtest_param {
 	unsigned		sglen;
 
 	/* outputs */
-	struct timeval		duration;
+	ktime_t		duration;
 };
 #define USBTEST_REQUEST	_IOWR('U', 100, struct usbtest_param)
 
@@ -2047,7 +2047,7 @@ usbtest_ioctl(struct usb_interface *intf, unsigned int code, void *buf)
 	struct urb		*urb;
 	struct scatterlist	*sg;
 	struct usb_sg_request	req;
-	struct timeval		start;
+	ktime_t		start;
 	unsigned		i;
 
 	/* FIXME USBDEVFS_CONNECTINFO doesn't say how fast the device is. */
@@ -2095,7 +2095,7 @@ usbtest_ioctl(struct usb_interface *intf, unsigned int code, void *buf)
 	 * FIXME add more tests!  cancel requests, verify the data, control
 	 * queueing, concurrent read+write threads, and so on.
 	 */
-	do_gettimeofday(&start);
+	start = ktime_get_boottime();
 	switch (param->test_num) {
 
 	case 0:
@@ -2487,13 +2487,8 @@ usbtest_ioctl(struct usb_interface *intf, unsigned int code, void *buf)
 		simple_free_urb(urb);
 		break;
 	}
-	do_gettimeofday(&param->duration);
-	param->duration.tv_sec -= start.tv_sec;
-	param->duration.tv_usec -= start.tv_usec;
-	if (param->duration.tv_usec < 0) {
-		param->duration.tv_usec += 1000 * 1000;
-		param->duration.tv_sec -= 1;
-	}
+	param->duration = ktime_get_boottime();
+	param->duration = ktime_sub(param->duration, start);
 	mutex_unlock(&dev->lock);
 	return retval;
 }
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux