From patchwork Tue May 16 11:09:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 9728863 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 98049602B4 for ; Tue, 16 May 2017 11:10:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A61728A13 for ; Tue, 16 May 2017 11:10:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7F17928A16; Tue, 16 May 2017 11:10:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 221F928A13 for ; Tue, 16 May 2017 11:10:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752546AbdEPLJ4 (ORCPT ); Tue, 16 May 2017 07:09:56 -0400 Received: from mout.kundenserver.de ([212.227.126.135]:51936 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751932AbdEPLJT (ORCPT ); Tue, 16 May 2017 07:09:19 -0400 Received: from wuerfel.lan ([78.42.17.5]) by mrelayeu.kundenserver.de (mreue002 [212.227.15.129]) with ESMTPA (Nemesis) id 0MEwG2-1dCFJd3nty-00G3m7; Tue, 16 May 2017 13:09:12 +0200 From: Arnd Bergmann To: Srinivas Pandruvada , Jiri Kosina Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, arnd@arndb.de Subject: [PATCH 3/5] HID: intel_ish-hid: convert timespec to ktime_t Date: Tue, 16 May 2017 13:09:05 +0200 Message-Id: <20170516110907.3545799-4-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170516110907.3545799-1-arnd@arndb.de> References: <20170516110907.3545799-1-arnd@arndb.de> X-Provags-ID: V03:K0:pfhl7LhDrEjRxEqX43IlOQEaVz3WJAcfP4A2BG9We3qZi9RXWrL eSpY5ZvZoKn4/Uo0FyaFO6lLPOriEAf+JmLRZxJkKhH7I0DwPzHvu+U8LrSRyfokINV9Ks6 nBsQ1T7WcVH+UFPZ1zDsM+te5Efv4gwEUXMMTTy7moocFvXIzDcRM/p104mu5mH9cqdZQ3I tOEQaEfwTtZ2Oaq+0izWg== X-UI-Out-Filterresults: notjunk:1; V01:K0:Ug0FJjog9PY=:9zICYWReHr98qfVr9xA3fl tQDunzqCRP1Vt2F4iw0b1EU+OMBctgztNec8vHSV8lxctPPeQqR7tgY0vy3ZmsRHtsckGydPc Dbsk6Qw+O2X8SeiTmbZi+JuUaKWr3BngahwdCJe6sO6rqcS++H6MORp+D44F7WP42Ju+z4dxH W5YF+lNxhS1F3BdD3ixIAMBl51BxJ36WACuTtVQ50r49AxRxjd/d564e8mkKCa57e1UUxDy9U MxoLru+XblR0b7Y0xtZzRCFJBw1h7fvPL6o9y1dQOkgd1PIlj7v0AIm2BhwHaIhOq64vT5UQe oFPXBRczFtjlAkZIcNaN2gJTub9cwmMqUny0nqmydr1zkMqUoDB2WGKrku9CN7xQDy/OpFVSC LHea+Q8CsBKX/54j7m5D/+evPtnXbebD5LdojDQgb1/2eN/Wh2Al9d2PG0hFMR9RQoEhhdKK6 tm7AarnimubghqlBUwkpQrtqAehdiudqaLO2ahfZ3nERDSALuXUKoHDrXffULQ5rZRQ9OSU1S FC3qFObtCEk7Zsnt9/1AINAis2qRKygR+TLo9VCsUKcl5uNn5tiyaLuZf2ewraP/jhPMKyxBD oZR/qrgUAz2WdlxDs2eEGVcNuw0U3roH0wc3sx1Zf2YsvFl3A8gYGa0Vbzx1KrZRrsZQJEBpZ zmaakC/5nNQMSmQ0/WifHpA63DmjeSvgafbiwQC+cvXnt8gizRLK1B6sRwCABiuQH5xg= Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The internal accounting uses 'timespec' based time stamps, which is slightly inefficient and also problematic once we get to the time_t overflow in 2038. When communicating to the firmware, we even get an open-coded 64-bit division that prevents the code from being build-tested on 32-bit architectures and is inefficient due to the double conversion from 64-bit nanoseconds to seconds+nanoseconds and then microseconds. This changes the code to use ktime_t instead. Signed-off-by: Arnd Bergmann --- drivers/hid/intel-ish-hid/ipc/ipc.c | 15 ++++----------- drivers/hid/intel-ish-hid/ishtp/client.c | 4 ++-- drivers/hid/intel-ish-hid/ishtp/client.h | 6 +++--- drivers/hid/intel-ish-hid/ishtp/hbm.c | 11 ++++------- 4 files changed, 13 insertions(+), 23 deletions(-) diff --git a/drivers/hid/intel-ish-hid/ipc/ipc.c b/drivers/hid/intel-ish-hid/ipc/ipc.c index 842d8416a7a6..9a60ec13cb10 100644 --- a/drivers/hid/intel-ish-hid/ipc/ipc.c +++ b/drivers/hid/intel-ish-hid/ipc/ipc.c @@ -296,17 +296,12 @@ static int write_ipc_from_queue(struct ishtp_device *dev) /* If sending MNG_SYNC_FW_CLOCK, update clock again */ if (IPC_HEADER_GET_PROTOCOL(doorbell_val) == IPC_PROTOCOL_MNG && IPC_HEADER_GET_MNG_CMD(doorbell_val) == MNG_SYNC_FW_CLOCK) { - struct timespec ts_system; - struct timeval tv_utc; - uint64_t usec_system, usec_utc; + uint64_t usec_system, usec_utc; struct ipc_time_update_msg time_update; struct time_sync_format ts_format; - get_monotonic_boottime(&ts_system); - do_gettimeofday(&tv_utc); - usec_system = (timespec_to_ns(&ts_system)) / NSEC_PER_USEC; - usec_utc = (uint64_t)tv_utc.tv_sec * 1000000 + - ((uint32_t)tv_utc.tv_usec); + usec_system = ktime_to_us(ktime_get_boottime()); + usec_utc = ktime_to_us(ktime_get_real()); ts_format.ts1_source = HOST_SYSTEM_TIME_USEC; ts_format.ts2_source = HOST_UTC_TIME_USEC; ts_format.reserved = 0; @@ -575,15 +570,13 @@ static void fw_reset_work_fn(struct work_struct *unused) static void _ish_sync_fw_clock(struct ishtp_device *dev) { static unsigned long prev_sync; - struct timespec ts; uint64_t usec; if (prev_sync && jiffies - prev_sync < 20 * HZ) return; prev_sync = jiffies; - get_monotonic_boottime(&ts); - usec = (timespec_to_ns(&ts)) / NSEC_PER_USEC; + usec = ktime_to_us(ktime_get_boottime()); ipc_send_mng_msg(dev, MNG_SYNC_FW_CLOCK, &usec, sizeof(uint64_t)); } diff --git a/drivers/hid/intel-ish-hid/ishtp/client.c b/drivers/hid/intel-ish-hid/ishtp/client.c index a4511ac8a87f..6cb78c29d111 100644 --- a/drivers/hid/intel-ish-hid/ishtp/client.c +++ b/drivers/hid/intel-ish-hid/ishtp/client.c @@ -925,7 +925,7 @@ void recv_ishtp_cl_msg(struct ishtp_device *dev, } if (complete_rb) { - getnstimeofday(&cl->ts_rx); + cl->ts_rx = ktime_get(); ++cl->recv_msg_cnt_ipc; ishtp_cl_read_complete(complete_rb); } @@ -1045,7 +1045,7 @@ void recv_ishtp_cl_msg_dma(struct ishtp_device *dev, void *msg, } if (complete_rb) { - getnstimeofday(&cl->ts_rx); + cl->ts_rx = ktime_get(); ++cl->recv_msg_cnt_dma; ishtp_cl_read_complete(complete_rb); } diff --git a/drivers/hid/intel-ish-hid/ishtp/client.h b/drivers/hid/intel-ish-hid/ishtp/client.h index 444d069c2ed4..79eade547f5d 100644 --- a/drivers/hid/intel-ish-hid/ishtp/client.h +++ b/drivers/hid/intel-ish-hid/ishtp/client.h @@ -118,9 +118,9 @@ struct ishtp_cl { unsigned int out_flow_ctrl_cnt; /* Rx msg ... out FC timing */ - struct timespec ts_rx; - struct timespec ts_out_fc; - struct timespec ts_max_fc_delay; + ktime_t ts_rx; + ktime_t ts_out_fc; + ktime_t ts_max_fc_delay; void *client_data; }; diff --git a/drivers/hid/intel-ish-hid/ishtp/hbm.c b/drivers/hid/intel-ish-hid/ishtp/hbm.c index b7213608ce43..ae4a69f7f2f4 100644 --- a/drivers/hid/intel-ish-hid/ishtp/hbm.c +++ b/drivers/hid/intel-ish-hid/ishtp/hbm.c @@ -321,13 +321,10 @@ int ishtp_hbm_cl_flow_control_req(struct ishtp_device *dev, if (!rv) { ++cl->out_flow_ctrl_creds; ++cl->out_flow_ctrl_cnt; - getnstimeofday(&cl->ts_out_fc); - if (cl->ts_rx.tv_sec && cl->ts_rx.tv_nsec) { - struct timespec ts_diff; - - ts_diff = timespec_sub(cl->ts_out_fc, cl->ts_rx); - if (timespec_compare(&ts_diff, &cl->ts_max_fc_delay) - > 0) + cl->ts_out_fc = ktime_get(); + if (cl->ts_rx) { + ktime_t ts_diff = ktime_sub(cl->ts_out_fc, cl->ts_rx); + if (ktime_after(ts_diff, cl->ts_max_fc_delay)) cl->ts_max_fc_delay = ts_diff; } } else {