{"id":833991,"url":"http://patchwork.ozlabs.org/api/1.2/patches/833991/?format=json","web_url":"http://patchwork.ozlabs.org/project/netdev/patch/20171103163220.3799742-2-arnd@arndb.de/","project":{"id":7,"url":"http://patchwork.ozlabs.org/api/1.2/projects/7/?format=json","name":"Linux network development","link_name":"netdev","list_id":"netdev.vger.kernel.org","list_email":"netdev@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20171103163220.3799742-2-arnd@arndb.de>","list_archive_url":null,"date":"2017-11-03T16:31:37","name":"[2/2] can: peak_usb: use ktime_t consistently","commit_ref":null,"pull_url":null,"state":"awaiting-upstream","archived":true,"hash":"596bebc0905832559e81279110048dc81b8bb5f8","submitter":{"id":30,"url":"http://patchwork.ozlabs.org/api/1.2/people/30/?format=json","name":"Arnd Bergmann","email":"arnd@arndb.de"},"delegate":{"id":34,"url":"http://patchwork.ozlabs.org/api/1.2/users/34/?format=json","username":"davem","first_name":"David","last_name":"Miller","email":"davem@davemloft.net"},"mbox":"http://patchwork.ozlabs.org/project/netdev/patch/20171103163220.3799742-2-arnd@arndb.de/mbox/","series":[{"id":11780,"url":"http://patchwork.ozlabs.org/api/1.2/series/11780/?format=json","web_url":"http://patchwork.ozlabs.org/project/netdev/list/?series=11780","date":"2017-11-03T16:31:37","name":"[1/2] can: peak_usb: remove some 'struct timeval' users","version":1,"mbox":"http://patchwork.ozlabs.org/series/11780/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/833991/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/833991/checks/","tags":{},"related":[],"headers":{"Return-Path":"<netdev-owner@vger.kernel.org>","X-Original-To":"patchwork-incoming@ozlabs.org","Delivered-To":"patchwork-incoming@ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=netdev-owner@vger.kernel.org;\n\treceiver=<UNKNOWN>)","Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3yT6vn6Qbvz9sNr\n\tfor <patchwork-incoming@ozlabs.org>;\n\tSat,  4 Nov 2017 03:33:25 +1100 (AEDT)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1756065AbdKCQdM (ORCPT <rfc822;patchwork-incoming@ozlabs.org>);\n\tFri, 3 Nov 2017 12:33:12 -0400","from mout.kundenserver.de ([212.227.126.187]:57777 \"EHLO\n\tmout.kundenserver.de\" rhost-flags-OK-OK-OK-OK) by vger.kernel.org\n\twith ESMTP id S1755977AbdKCQdG (ORCPT\n\t<rfc822;netdev@vger.kernel.org>); Fri, 3 Nov 2017 12:33:06 -0400","from wuerfel.lan ([109.193.157.232]) by mrelayeu.kundenserver.de\n\t(mreue006 [212.227.15.129]) with ESMTPA (Nemesis) id\n\t0Lhp7m-1dOgol3gXa-00nAaK; Fri, 03 Nov 2017 17:32:50 +0100"],"From":"Arnd Bergmann <arnd@arndb.de>","To":"Wolfgang Grandegger <wg@grandegger.com>,\n\tMarc Kleine-Budde <mkl@pengutronix.de>","Cc":"Arnd Bergmann <arnd@arndb.de>, Stephane Grosjean\n\t<s.grosjean@peak-system.com>, =?utf-8?b?7LaU7KeA7Zi4?=\n\t<jiho.chu@samsung.com>, Johan Hovold <johan@kernel.org>,\n\tlinux-can@vger.kernel.org, netdev@vger.kernel.org,\n\tlinux-kernel@vger.kernel.org","Subject":"[PATCH 2/2] can: peak_usb: use ktime_t consistently","Date":"Fri,  3 Nov 2017 17:31:37 +0100","Message-Id":"<20171103163220.3799742-2-arnd@arndb.de>","X-Mailer":"git-send-email 2.9.0","In-Reply-To":"<20171103163220.3799742-1-arnd@arndb.de>","References":"<20171103163220.3799742-1-arnd@arndb.de>","X-Provags-ID":"V03:K0:/E1BfImCKFLcUZhcGCTTQ+2gbE1iQw4z+wqT/GhynmtFu2FAnsU\n\tI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ger.kernel.org","Precedence":"bulk","List-ID":"<netdev.vger.kernel.org>","X-Mailing-List":"netdev@vger.kernel.org"},"content":"This changes the calculation of the timestamps to use ktime_t\ninstead of struct timeval as the base. This gets rid of one\nof the few remaining users of the deprecated ktime_to_timeval()\nand timeval_to_ktime() helpers.\n\nThe code should also get more efficient, as we have now removed\nall of the divisions.\n\nI have left the cut-off for resetting the counters as 4.200\nseconds, in order to leave the behavior unchanged otherwise.\n\nSigned-off-by: Arnd Bergmann <arnd@arndb.de>\n---\n drivers/net/can/usb/peak_usb/pcan_usb_core.c | 46 +++++++++-------------------\n drivers/net/can/usb/peak_usb/pcan_usb_core.h |  2 +-\n 2 files changed, 15 insertions(+), 33 deletions(-)","diff":"diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.c b/drivers/net/can/usb/peak_usb/pcan_usb_core.c\nindex 695a75a9b4bb..8f699ee6a528 100644\n--- a/drivers/net/can/usb/peak_usb/pcan_usb_core.c\n+++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.c\n@@ -80,21 +80,6 @@ void peak_usb_init_time_ref(struct peak_time_ref *time_ref,\n \t}\n }\n \n-static void peak_usb_add_us(struct timeval *tv, u32 delta_us)\n-{\n-\t/* number of s. to add to final time */\n-\tu32 delta_s = delta_us / 1000000;\n-\n-\tdelta_us -= delta_s * 1000000;\n-\n-\ttv->tv_usec += delta_us;\n-\tif (tv->tv_usec >= 1000000) {\n-\t\ttv->tv_usec -= 1000000;\n-\t\tdelta_s++;\n-\t}\n-\ttv->tv_sec += delta_s;\n-}\n-\n /*\n  * sometimes, another now may be  more recent than current one...\n  */\n@@ -103,7 +88,7 @@ void peak_usb_update_ts_now(struct peak_time_ref *time_ref, u32 ts_now)\n \ttime_ref->ts_dev_2 = ts_now;\n \n \t/* should wait at least two passes before computing */\n-\tif (time_ref->tv_host.tv_sec > 0) {\n+\tif (ktime_to_ns(time_ref->tv_host) > 0) {\n \t\tu32 delta_ts = time_ref->ts_dev_2 - time_ref->ts_dev_1;\n \n \t\tif (time_ref->ts_dev_2 < time_ref->ts_dev_1)\n@@ -118,26 +103,26 @@ void peak_usb_update_ts_now(struct peak_time_ref *time_ref, u32 ts_now)\n  */\n void peak_usb_set_ts_now(struct peak_time_ref *time_ref, u32 ts_now)\n {\n-\tif (time_ref->tv_host_0.tv_sec == 0) {\n+\tif (ktime_to_ns(time_ref->tv_host_0) == 0) {\n \t\t/* use monotonic clock to correctly compute further deltas */\n-\t\ttime_ref->tv_host_0 = ktime_to_timeval(ktime_get());\n-\t\ttime_ref->tv_host.tv_sec = 0;\n+\t\ttime_ref->tv_host_0 = ktime_get();\n+\t\ttime_ref->tv_host = ktime_set(0, 0);\n \t} else {\n \t\t/*\n-\t\t * delta_us should not be >= 2^32 => delta_s should be < 4294\n+\t\t * delta_us should not be >= 2^32 => delta should be < 4294s\n \t\t * handle 32-bits wrapping here: if count of s. reaches 4200,\n \t\t * reset counters and change time base\n \t\t */\n-\t\tif (time_ref->tv_host.tv_sec != 0) {\n-\t\t\tu32 delta_s = time_ref->tv_host.tv_sec\n-\t\t\t\t\t\t- time_ref->tv_host_0.tv_sec;\n-\t\t\tif (delta_s > 4200) {\n+\t\tif (ktime_to_ns(time_ref->tv_host)) {\n+\t\t\tktime_t delta = ktime_sub(time_ref->tv_host,\n+\t\t\t\t\t\t  time_ref->tv_host_0);\n+\t\t\tif (ktime_to_ns(delta) > (4200ull * NSEC_PER_SEC)) {\n \t\t\t\ttime_ref->tv_host_0 = time_ref->tv_host;\n \t\t\t\ttime_ref->ts_total = 0;\n \t\t\t}\n \t\t}\n \n-\t\ttime_ref->tv_host = ktime_to_timeval(ktime_get());\n+\t\ttime_ref->tv_host = ktime_get();\n \t\ttime_ref->tick_count++;\n \t}\n \n@@ -146,13 +131,12 @@ void peak_usb_set_ts_now(struct peak_time_ref *time_ref, u32 ts_now)\n }\n \n /*\n- * compute timeval according to current ts and time_ref data\n+ * compute time according to current ts and time_ref data\n  */\n void peak_usb_get_ts_time(struct peak_time_ref *time_ref, u32 ts, ktime_t *time)\n {\n-\t/* protect from getting timeval before setting now */\n-\tif (time_ref->tv_host.tv_sec > 0) {\n-\t\tstruct timeval tv;\n+\t/* protect from getting time before setting now */\n+\tif (ktime_to_ns(time_ref->tv_host)) {\n \t\tu64 delta_us;\n \n \t\tdelta_us = ts - time_ref->ts_dev_2;\n@@ -164,9 +148,7 @@ void peak_usb_get_ts_time(struct peak_time_ref *time_ref, u32 ts, ktime_t *time)\n \t\tdelta_us *= time_ref->adapter->us_per_ts_scale;\n \t\tdelta_us >>= time_ref->adapter->us_per_ts_shift;\n \n-\t\ttv = time_ref->tv_host_0;\n-\t\tpeak_usb_add_us(&tv, (u32)delta_us);\n-\t\t*time = timeval_to_ktime(tv);\n+\t\t*time = ktime_add_us(time_ref->tv_host_0, delta_us);\n \t} else {\n \t\t*time = ktime_get();\n \t}\ndiff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.h b/drivers/net/can/usb/peak_usb/pcan_usb_core.h\nindex b9a221ea7e5c..29f03dccca10 100644\n--- a/drivers/net/can/usb/peak_usb/pcan_usb_core.h\n+++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.h\n@@ -96,7 +96,7 @@ extern const struct peak_usb_adapter pcan_usb_pro_fd;\n extern const struct peak_usb_adapter pcan_usb_x6;\n \n struct peak_time_ref {\n-\tstruct timeval tv_host_0, tv_host;\n+\tktime_t tv_host_0, tv_host;\n \tu32 ts_dev_1, ts_dev_2;\n \tu64 ts_total;\n \tu32 tick_count;\n","prefixes":["2/2"]}