From patchwork Tue Nov 7 10:39:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 118145 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp3810434qgn; Tue, 7 Nov 2017 02:40:31 -0800 (PST) X-Google-Smtp-Source: ABhQp+SeMGaRV5mw7sIL4aiTQWPao+uMYPHih0zp8AFkDYBb9wKt0VEYSQpmeUdnSdzUJl5xsdjC X-Received: by 10.101.68.69 with SMTP id e5mr17943601pgq.282.1510051231512; Tue, 07 Nov 2017 02:40:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510051231; cv=none; d=google.com; s=arc-20160816; b=LMU72RA9hJlxhYND5RHD9KB2sw4Wuf42XIaDbkaCRBMZWUWcbFNDhcanVsEAcIBRs8 W7oE9zHQzQ3tQu22h7Kpp/dXbqvF8P140uY5YalqpaR6nV5ezkhZMXYUXsvKK98b/0MF Xo3542TfF65LZ20uwCGd4o2zWDGs3+IuWHmLofDlWB4d0YpSdlqHTkTOH/OewmgZCDO3 3gVtF9F2pa/qiBiogJj2xVwLPcGEbbGOeDm81xCCCyrdlsn2wPfxJKN4ihdIklRpivpK SdQ9GjfjDcCAeIePQglTgjifoONLb9q+ScC7nxBE6NmbLIYf+mZfTDzlhRW3phj91ja2 oINQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=Y3FfHTCD/8HpbPZeKyM1h1sjdoOh2fFIEnfHZt4gASc=; b=iIlrqZg87MXaqccYbpUs1cv5PvUtC7bWgkyB8FiVfnf9Krm/maamaWuls9XCwmggG7 +tINp92x7vb9yMlgw31U+FMbhGApN+9ABYnru8Z3IoDn8mdLg0Y+Z5tEBvi9At3IWxaH frvL/XoQqoJxeBD7Zl5lHHIQ8/wX5+uPW/3nWnOqMxDNqKKUU5aBL3UTwgTbzp1pBpKy SGRcvhgGXs+9CGoTFqWs7UbsifgIQD4uhqMyRLlqkViL9YdE2kIsNlxoDrfTfFoRdA4u aa7hUCjOhBgQ07F4gZ2Qia4cvY4o0w/1rl8GunmDmpq9/XaHWchgCUg6mGFFyr/Haojx HBRg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s19si863845plp.458.2017.11.07.02.40.31; Tue, 07 Nov 2017 02:40:31 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757136AbdKGKk2 (ORCPT + 26 others); Tue, 7 Nov 2017 05:40:28 -0500 Received: from mout.kundenserver.de ([217.72.192.73]:51067 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757119AbdKGKkX (ORCPT ); Tue, 7 Nov 2017 05:40:23 -0500 Received: from wuerfel.lan ([109.193.157.232]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.145]) with ESMTPA (Nemesis) id 0MWRtC-1ejgLx2whu-00XbiV; Tue, 07 Nov 2017 11:40:11 +0100 From: Arnd Bergmann To: Valentina Manea , Shuah Khan , Greg Kroah-Hartman Cc: Arnd Bergmann , Krzysztof Opasiak , Johan Hovold , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] usbip: fix off-by-one frame number calculation Date: Tue, 7 Nov 2017 11:39:56 +0100 Message-Id: <20171107104010.2884193-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:TxQacLp55x7jhRYC8cT/3bd4g/andhnLCNOrNuqw2hxsecqWCwH dRtBRsALJlAJIrXirEsHqm3hAQ57uHAUeXwQJR+UCKX1TTSLpnfhx1QNtlJW+dzgD3ZOMck v1vyRuowsFaCCqacFdlyJGe6WUd5PhX1kaFN7yt2F+rMdQ0dpafTLVANfNerXI0D1OmNJIE E3aE3ni/viiQuySnmifIA== X-UI-Out-Filterresults: notjunk:1; V01:K0:OiNH6YCWpWU=:1upv3CwE2wpkjufpyrjja2 2IE5nzjJjUS3oBPsVXi7eoC154K5bjaYTM9VY5ZfzVg/fp+eMNCbSoUMHNwG0qrpXv0BDNE6W vmiNIiwoq99+yImYZzRsdGttEYE5mYAc44IGU+1vCH5k3Mn5KlO5wq1VskVCtPwKz0puK0Suf Fl4oa0u1ILPWQmjYNgsO8r2kRs4xQklpHb07UxxCxQn2Ik1wwIStlVz0QoZRZleJkzZXvjpvm CTxwMvbMar/UkzrlRyaQMqKf7VjJagUujqjczdhaxyl9pwIkVr4JzLo0kUFXkp3G7gUSwSGy0 uSB/EGxxwvvwOGFc0paDM2fJ6+jWjLJryTx40u+swTyE2Ng57QNxLdV3pdHGHTwXPTjTG38UU pSQ9c9oqLw97xR161q7tWUzvt6nsDBs4/pBkovBX8A0uWIIJVczHa8uTp/rqlHIC3hGNVzXhX wnk8Zz8bKUEsdOBBPcmE/mzaW8VNNV4ZSp1zCcoLxZii8f0ddDhDVUnZptcrG9a8DVvFj/m2A sT0MNg1dj4ICglCVWXe2fEIjxnc0OTxGOanN+Mh7OusSWxJvpc9uWE6H08ISfBk1y1dIIRwyv pisbpqyKh97SQRsp+H5poxYhMsDEMwTFwq3kNXl7wCr22OCaYTgyHI/qqm+IaNEoU2m8K5qaK SJaPkC2/Zw2Jf+1Im/isdIe+OgcOSwZXjUwjJ/OBarWnyJeAbXThva57JM4JJ0T7DPsXHo/5M /H1luS1Dnp6H1VhsEhU1q8IRsLf1bJatwyjCPQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/usb/usbip/vudc_dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.9.0 Reviewed-by: Krzysztof Opasiak Acked-by: Shuah Khan 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) From patchwork Tue Nov 7 10:39:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 118146 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp3810621qgn; Tue, 7 Nov 2017 02:40:47 -0800 (PST) X-Google-Smtp-Source: ABhQp+QcDXtoDBSI3NstLxYQ3qIKg4vnjQZkn1UbTjn6AbY3hVnl+PtjFP7uAwcp5RKLtOH9wsjj X-Received: by 10.84.157.74 with SMTP id u10mr17808988plu.304.1510051247188; Tue, 07 Nov 2017 02:40:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510051247; cv=none; d=google.com; s=arc-20160816; b=txwt1Fep6qmiJpXb6pexnLNFLH9NcLz94U6eFNVIuETb404qbhNXeCQFL2XMIbXrn5 qFeeYqQ7qOKAY2+46Ku2LvjiiGliAlbcNrZxMeYGGMzv/C8HEroWuT5m0LIvupdLgs6B +mn6oiNxBXXfsYOoiY/UK1+fQUc6R1JZTM0MwjUV/GoPBGxilE6Ue4SIzHSsx3Lsvnd6 kc12jWK7QDCkCpWbBkiXTrhpYdoqZlmgWAdHU6Y7yHPCeRloeOWXC/YEl/2fYjSJyV/H +kk+w223r+hvBNswcoD2H8ls1BLDtisoe6c80GYYcnD6EnX9JExZwrP4eyC52MWOC5bX +VeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=66GLylgnH4E5/wBtzunEAvTAoEd/zXa0e5G3eQzYhDs=; b=aeC8oHkEs1X/I2Qkd8TzcR7M4KzYbVSbcPLXOUulSEuUf2fiY+yEt086B6ek0Qxaib gcNiThsMCmqbdVPSLSMgyua4pP4Xto3efh7BdJ8+gckwJYz5ZAvisHlvFji+cimDj9tH 1lUwghJOr8wBM81sU0ldpqPNdRHFXUzP74XHGIHT9FWjRiHn79g/qw9Y7h26WKNOgX7u Dqe2qeSkkdaXKx3Q7O8o4SBjmmQ0/cd6BbQB8HV6SIBpnbQMs9yp3hQt9W5XaZfScEQH uzmcrkAEDuBVHAhTrJYYiPdbl9sxQmDkMXjjJsNZP8qFTs42nBYo0lwnUPjWJYfHqHS8 5m0g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r7si828883pgp.220.2017.11.07.02.40.46; Tue, 07 Nov 2017 02:40:47 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757157AbdKGKkk (ORCPT + 26 others); Tue, 7 Nov 2017 05:40:40 -0500 Received: from mout.kundenserver.de ([217.72.192.73]:65056 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757132AbdKGKkh (ORCPT ); Tue, 7 Nov 2017 05:40:37 -0500 Received: from wuerfel.lan ([109.193.157.232]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.145]) with ESMTPA (Nemesis) id 0MKaKl-1eDOLj07rL-001zws; Tue, 07 Nov 2017 11:40:28 +0100 From: Arnd Bergmann To: Valentina Manea , Shuah Khan , Greg Kroah-Hartman Cc: Arnd Bergmann , Johan Hovold , Felipe Balbi , Krzysztof Opasiak , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] usbip: use monotonic timestamps Date: Tue, 7 Nov 2017 11:39:57 +0100 Message-Id: <20171107104010.2884193-2-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20171107104010.2884193-1-arnd@arndb.de> References: <20171107104010.2884193-1-arnd@arndb.de> X-Provags-ID: V03:K0:1Unn8jPrpkbwU0tsIsGpZF7YHH13PmB2Nwxsww31h7PFOlPTxWT XKkOoezgNX9/0urQZVkCGmV9Dqk3v247Z/+D3oA5r4c1+u2ieT814QR+BFSk3nfTV8zq/CC dttCtjp4RbSnrig5Oz2pqdzWvEYAXRZcN6MCX4Fp4BMiAgrix7TxAYkKjjos+AfEEPKfImm POP9UfZtnjqUpcOCW8YOQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:4aX492ivHe0=:NP9JkLLSMcKRUnsSiKNtDs +TbhH4n4gl3e6y2A/Wnud52p2tuu+6EDUKkfHMeYI8AYhyr8KxQK0yV6Ln8I2oTHghqGDGcSz Q0M+GSiJEuduKsMFTIyI741k2WjKZTFXmWMy4ld/lbcLl5tFMYWdjN9NMd5Czz3A/NPj6P5N0 o3D3og3+DmRttDkvzXF/WLCgz9H6pYIEhu2IiGTszSBY59Bbd0rNCdh/tK9Cw/DJIjo8sNEbn ZqoRF6H7MhdA2j8uuV0Xhd2lO2Fs4Y5b5w0TJimAtJXg41jLp7N8lENbdso5kSjNZUT5fvgCl fH93glwPfmCpouJQ0w8w4hWiUnP5KSqdt0QA2EJdR7q5dSJZ577yNFdL5K5hCZQUMUS46ujtX T+E+bD0Nbd6ma/9w9NTs8kjSO0VHFab8tJm/tEtn8K2yrOJsZCsp41irEtJjqtM9OIe+y+8qc aY10dQbgPtap1eoqKMHLs1THq9J6MnPY8b7TDkDZTxLLgfKarbl2MnMQcBZBTbofbwVdNZo8x gGcPKYlu/GL+Pz/oYnCiH+Tl5QH1e2AmrN5HAAUMzxbVbNq2d8CIt7273qEsMoFxuaNOIvQQo px7QaotdVQNSoDinziQBakZaF8VHkA0L1CXRI1eyX3uM6qTJ2nGXWRwcbd7ud+oJw2hPTyCv5 Ortj5TvzOHgQAVVA5k/xgPQTi8D0TZNeuO3pcz1tmeHfnRyTdlXIO2gd/yS9o8Eof3EguGGpa jq429ehSTVB2gpGCWm+dtot024SaBZ2x8VLKGQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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(-) -- 2.9.0 Reviewed-by: Krzysztof Opasiak Acked-by: Shuah Khan 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 {