linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] usbip: fix off-by-one frame number calculation
@ 2017-11-07 10:39 ` Arnd Bergmann
  2017-11-07 10:39   ` [PATCH 2/2] usbip: use monotonic timestamps Arnd Bergmann
  2017-11-07 11:21   ` [PATCH 1/2] usbip: fix off-by-one frame number calculation Krzysztof Opasiak
  0 siblings, 2 replies; 6+ messages in thread
From: Arnd Bergmann @ 2017-11-07 10:39 UTC (permalink / raw)
  To: Valentina Manea, Shuah Khan, Greg Kroah-Hartman
  Cc: Arnd Bergmann, Krzysztof Opasiak, Johan Hovold, linux-usb, linux-kernel

vgadget_get_frame returns a frame number from 0 to 2046, which
may require an expensive division operation to wrap at one lower
than the usual number.

I can't see any reason for this, and all other drivers wrap at
a power-of-two number. My best explanation is that it was a simple
typo, so I'm changing the % modulo operator into a cheaper bitmask
that the other drivers use, to make it wrap after 0x7ff rather than
before it.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/usb/usbip/vudc_dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/usbip/vudc_dev.c b/drivers/usb/usbip/vudc_dev.c
index 0c07348820ea..16fb4f85a6f6 100644
--- a/drivers/usb/usbip/vudc_dev.c
+++ b/drivers/usb/usbip/vudc_dev.c
@@ -145,7 +145,7 @@ static int vgadget_get_frame(struct usb_gadget *_gadget)
 	do_gettimeofday(&now);
 	return ((now.tv_sec - udc->start_time.tv_sec) * 1000 +
 			(now.tv_usec - udc->start_time.tv_usec) / 1000)
-			% 0x7FF;
+			& 0x7FF;
 }
 
 static int vgadget_set_selfpowered(struct usb_gadget *_gadget, int value)
-- 
2.9.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] usbip: use monotonic timestamps
  2017-11-07 10:39 ` [PATCH 1/2] usbip: fix off-by-one frame number calculation Arnd Bergmann
@ 2017-11-07 10:39   ` Arnd Bergmann
  2017-11-07 11:22     ` Krzysztof Opasiak
  2017-11-07 11:21   ` [PATCH 1/2] usbip: fix off-by-one frame number calculation Krzysztof Opasiak
  1 sibling, 1 reply; 6+ messages in thread
From: Arnd Bergmann @ 2017-11-07 10:39 UTC (permalink / raw)
  To: Valentina Manea, Shuah Khan, Greg Kroah-Hartman
  Cc: Arnd Bergmann, Johan Hovold, Felipe Balbi, Krzysztof Opasiak,
	linux-usb, linux-kernel

This gets rid of the deprecated do_gettimeofday() function in usbip.
The comment above vgadget_get_frame() mentions that it suffers
from issues with the time jumps due to suspend and settimeofday,
so I'm changing it to use ktime_get_ts64() to use monotonic times
that don't have this problem.

I couldn't tell whether we should use CLOCK_MONOTONIC or
CLOCK_MONOTONIC_RAW here, the difference being the exact rate
when correcting for NTP. I picked monotonic time since it doesn't
change the speed to the existing code and should be better
synchronized with other machines we talk to.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/usb/usbip/vudc.h       | 2 +-
 drivers/usb/usbip/vudc_dev.c   | 7 +++----
 drivers/usb/usbip/vudc_sysfs.c | 2 +-
 3 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/usbip/vudc.h b/drivers/usb/usbip/vudc.h
index 44fb24193acd..8282362176d5 100644
--- a/drivers/usb/usbip/vudc.h
+++ b/drivers/usb/usbip/vudc.h
@@ -105,7 +105,7 @@ struct vudc {
 
 	struct usbip_device ud;
 	struct transfer_timer tr_timer;
-	struct timeval start_time;
+	struct timespec64 start_time;
 
 	struct list_head urb_queue;
 
diff --git a/drivers/usb/usbip/vudc_dev.c b/drivers/usb/usbip/vudc_dev.c
index 16fb4f85a6f6..fe07e799e481 100644
--- a/drivers/usb/usbip/vudc_dev.c
+++ b/drivers/usb/usbip/vudc_dev.c
@@ -136,15 +136,14 @@ struct vep *vudc_find_endpoint(struct vudc *udc, u8 address)
 
 /* gadget ops */
 
-/* FIXME - this will probably misbehave when suspend/resume is added */
 static int vgadget_get_frame(struct usb_gadget *_gadget)
 {
-	struct timeval now;
+	struct timespec64 now;
 	struct vudc *udc = usb_gadget_to_vudc(_gadget);
 
-	do_gettimeofday(&now);
+	ktime_get_ts64(&now);
 	return ((now.tv_sec - udc->start_time.tv_sec) * 1000 +
-			(now.tv_usec - udc->start_time.tv_usec) / 1000)
+		(now.tv_nsec - udc->start_time.tv_nsec) / NSEC_PER_MSEC)
 			& 0x7FF;
 }
 
diff --git a/drivers/usb/usbip/vudc_sysfs.c b/drivers/usb/usbip/vudc_sysfs.c
index 7d978b824ed4..49e0123caa53 100644
--- a/drivers/usb/usbip/vudc_sysfs.c
+++ b/drivers/usb/usbip/vudc_sysfs.c
@@ -162,7 +162,7 @@ static ssize_t store_sockfd(struct device *dev, struct device_attribute *attr,
 		udc->ud.status = SDEV_ST_USED;
 		spin_unlock_irq(&udc->ud.lock);
 
-		do_gettimeofday(&udc->start_time);
+		ktime_get_ts64(&udc->start_time);
 		v_start_timer(udc);
 		udc->connected = 1;
 	} else {
-- 
2.9.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] usbip: fix off-by-one frame number calculation
  2017-11-07 10:39 ` [PATCH 1/2] usbip: fix off-by-one frame number calculation Arnd Bergmann
  2017-11-07 10:39   ` [PATCH 2/2] usbip: use monotonic timestamps Arnd Bergmann
@ 2017-11-07 11:21   ` Krzysztof Opasiak
  2017-11-07 21:10     ` Shuah Khan
  1 sibling, 1 reply; 6+ messages in thread
From: Krzysztof Opasiak @ 2017-11-07 11:21 UTC (permalink / raw)
  To: Arnd Bergmann, Valentina Manea, Shuah Khan, Greg Kroah-Hartman
  Cc: Johan Hovold, linux-usb, linux-kernel



On 11/07/2017 11:39 AM, Arnd Bergmann wrote:
> vgadget_get_frame returns a frame number from 0 to 2046, which
> may require an expensive division operation to wrap at one lower
> than the usual number.
> 
> I can't see any reason for this, and all other drivers wrap at
> a power-of-two number. My best explanation is that it was a simple
> typo, so I'm changing the % modulo operator into a cheaper bitmask
> that the other drivers use, to make it wrap after 0x7ff rather than
> before it.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Looks good to me:
Reviewed-by: Krzysztof Opasiak <k.opasiak@samsung.com>

-- 
Krzysztof Opasiak
Samsung R&D Institute Poland
Samsung Electronics

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] usbip: use monotonic timestamps
  2017-11-07 10:39   ` [PATCH 2/2] usbip: use monotonic timestamps Arnd Bergmann
@ 2017-11-07 11:22     ` Krzysztof Opasiak
  2017-11-07 21:10       ` Shuah Khan
  0 siblings, 1 reply; 6+ messages in thread
From: Krzysztof Opasiak @ 2017-11-07 11:22 UTC (permalink / raw)
  To: Arnd Bergmann, Valentina Manea, Shuah Khan, Greg Kroah-Hartman
  Cc: Johan Hovold, Felipe Balbi, linux-usb, linux-kernel



On 11/07/2017 11:39 AM, Arnd Bergmann wrote:
> This gets rid of the deprecated do_gettimeofday() function in usbip.
> The comment above vgadget_get_frame() mentions that it suffers
> from issues with the time jumps due to suspend and settimeofday,
> so I'm changing it to use ktime_get_ts64() to use monotonic times
> that don't have this problem.
> 
> I couldn't tell whether we should use CLOCK_MONOTONIC or
> CLOCK_MONOTONIC_RAW here, the difference being the exact rate
> when correcting for NTP. I picked monotonic time since it doesn't
> change the speed to the existing code and should be better
> synchronized with other machines we talk to.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Looks good to me:
Reviewed-by: Krzysztof Opasiak <k.opasiak@samsung.com>

-- 
Krzysztof Opasiak
Samsung R&D Institute Poland
Samsung Electronics

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] usbip: fix off-by-one frame number calculation
  2017-11-07 11:21   ` [PATCH 1/2] usbip: fix off-by-one frame number calculation Krzysztof Opasiak
@ 2017-11-07 21:10     ` Shuah Khan
  0 siblings, 0 replies; 6+ messages in thread
From: Shuah Khan @ 2017-11-07 21:10 UTC (permalink / raw)
  To: Krzysztof Opasiak, Arnd Bergmann, Valentina Manea, Greg Kroah-Hartman
  Cc: Johan Hovold, linux-usb, linux-kernel

On 11/07/2017 04:21 AM, Krzysztof Opasiak wrote:
> 
> 
> On 11/07/2017 11:39 AM, Arnd Bergmann wrote:
>> vgadget_get_frame returns a frame number from 0 to 2046, which
>> may require an expensive division operation to wrap at one lower
>> than the usual number.
>>
>> I can't see any reason for this, and all other drivers wrap at
>> a power-of-two number. My best explanation is that it was a simple
>> typo, so I'm changing the % modulo operator into a cheaper bitmask
>> that the other drivers use, to make it wrap after 0x7ff rather than
>> before it.
>>
>> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> 
> Looks good to me:
> Reviewed-by: Krzysztof Opasiak <k.opasiak@samsung.com>
> 

Acked-by: Shuah Khan <shuahkh@osg.samsung.com>

thanks,
-- Shuah

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] usbip: use monotonic timestamps
  2017-11-07 11:22     ` Krzysztof Opasiak
@ 2017-11-07 21:10       ` Shuah Khan
  0 siblings, 0 replies; 6+ messages in thread
From: Shuah Khan @ 2017-11-07 21:10 UTC (permalink / raw)
  To: Krzysztof Opasiak, Arnd Bergmann, Valentina Manea, Greg Kroah-Hartman
  Cc: Johan Hovold, Felipe Balbi, linux-usb, linux-kernel, Shuah Khan,
	Shuah Khan

On 11/07/2017 04:22 AM, Krzysztof Opasiak wrote:
> 
> 
> On 11/07/2017 11:39 AM, Arnd Bergmann wrote:
>> This gets rid of the deprecated do_gettimeofday() function in usbip.
>> The comment above vgadget_get_frame() mentions that it suffers
>> from issues with the time jumps due to suspend and settimeofday,
>> so I'm changing it to use ktime_get_ts64() to use monotonic times
>> that don't have this problem.
>>
>> I couldn't tell whether we should use CLOCK_MONOTONIC or
>> CLOCK_MONOTONIC_RAW here, the difference being the exact rate
>> when correcting for NTP. I picked monotonic time since it doesn't
>> change the speed to the existing code and should be better
>> synchronized with other machines we talk to.
>>
>> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> 
> Looks good to me:
> Reviewed-by: Krzysztof Opasiak <k.opasiak@samsung.com>
> 

Acked-by: Shuah Khan <shuahkh@osg.samsung.com>

thanks,
-- Shuah

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-11-07 21:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20171107104018epcas5p1f9c72d541c679e1c5a44e03a901e8498@epcas5p1.samsung.com>
2017-11-07 10:39 ` [PATCH 1/2] usbip: fix off-by-one frame number calculation Arnd Bergmann
2017-11-07 10:39   ` [PATCH 2/2] usbip: use monotonic timestamps Arnd Bergmann
2017-11-07 11:22     ` Krzysztof Opasiak
2017-11-07 21:10       ` Shuah Khan
2017-11-07 11:21   ` [PATCH 1/2] usbip: fix off-by-one frame number calculation Krzysztof Opasiak
2017-11-07 21:10     ` Shuah Khan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).