From: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
To: Arnd Bergmann <arnd@arndb.de>, Jiri Kosina <jikos@kernel.org>
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 3/5] HID: intel_ish-hid: convert timespec to ktime_t
Date: Fri, 26 May 2017 13:58:33 -0700 [thread overview]
Message-ID: <1495832313.79527.4.camel@linux.intel.com> (raw)
In-Reply-To: <20170518202144.3482304-4-arnd@arndb.de>
On Thu, 2017-05-18 at 22:21 +0200, Arnd Bergmann wrote:
> 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 <arnd@arndb.de>
Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
> ---
> 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 f54689ee67e1..007443ef5fca 100644
> --- a/drivers/hid/intel-ish-hid/ishtp/client.c
> +++ b/drivers/hid/intel-ish-hid/ishtp/client.c
> @@ -921,7 +921,7 @@ void recv_ishtp_cl_msg(struct ishtp_device *dev,
>
> if (complete_rb) {
> cl = complete_rb->cl;
> - getnstimeofday(&cl->ts_rx);
> + cl->ts_rx = ktime_get();
> ++cl->recv_msg_cnt_ipc;
> ishtp_cl_read_complete(complete_rb);
> }
> @@ -1038,7 +1038,7 @@ void recv_ishtp_cl_msg_dma(struct ishtp_device
> *dev, void *msg,
>
> if (complete_rb) {
> cl = complete_rb->cl;
> - 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 {
next prev parent reply other threads:[~2017-05-27 1:16 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-18 20:21 HID: intel_ish-hid: various cleanups Arnd Bergmann
2017-05-18 20:21 ` [PATCH v2 1/5] HID: intel_ish-hid: fix potential uninitialized data usage Arnd Bergmann
2017-05-22 19:17 ` Srinivas Pandruvada
2017-05-22 21:33 ` Arnd Bergmann
2017-05-23 22:24 ` Srinivas Pandruvada
2017-05-24 8:29 ` Arnd Bergmann
2017-05-26 20:58 ` Srinivas Pandruvada
2017-05-18 20:21 ` [PATCH v2 2/5] HID: intel_ish-hid: clarify locking in client code Arnd Bergmann
2017-05-26 20:58 ` Srinivas Pandruvada
2017-05-18 20:21 ` [PATCH v2 3/5] HID: intel_ish-hid: convert timespec to ktime_t Arnd Bergmann
2017-05-26 20:58 ` Srinivas Pandruvada [this message]
2017-05-18 20:21 ` [PATCH v2 4/5] HID: intel_ish-hid: fix format string for size_t Arnd Bergmann
2017-05-22 23:46 ` Srinivas Pandruvada
2017-05-23 8:35 ` Arnd Bergmann
2017-05-26 20:58 ` Srinivas Pandruvada
2017-05-18 20:21 ` [PATCH v2 5/5] HID: intel_ish-hid: enable compile testing Arnd Bergmann
2017-05-26 20:59 ` Srinivas Pandruvada
2017-05-26 20:57 ` HID: intel_ish-hid: various cleanups Srinivas Pandruvada
2017-05-30 12:13 ` Jiri Kosina
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1495832313.79527.4.camel@linux.intel.com \
--to=srinivas.pandruvada@linux.intel.com \
--cc=arnd@arndb.de \
--cc=jikos@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).