Commit 2503f7ba authored by Arnd Bergmann's avatar Arnd Bergmann Committed by Jiri Kosina

HID: intel_ish-hid: convert timespec to ktime_t

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: default avatarArnd Bergmann <arnd@arndb.de>
Acked-by: default avatarSrinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
parent 538be0aa
...@@ -296,17 +296,12 @@ static int write_ipc_from_queue(struct ishtp_device *dev) ...@@ -296,17 +296,12 @@ static int write_ipc_from_queue(struct ishtp_device *dev)
/* If sending MNG_SYNC_FW_CLOCK, update clock again */ /* If sending MNG_SYNC_FW_CLOCK, update clock again */
if (IPC_HEADER_GET_PROTOCOL(doorbell_val) == IPC_PROTOCOL_MNG && if (IPC_HEADER_GET_PROTOCOL(doorbell_val) == IPC_PROTOCOL_MNG &&
IPC_HEADER_GET_MNG_CMD(doorbell_val) == MNG_SYNC_FW_CLOCK) { IPC_HEADER_GET_MNG_CMD(doorbell_val) == MNG_SYNC_FW_CLOCK) {
struct timespec ts_system; uint64_t usec_system, usec_utc;
struct timeval tv_utc;
uint64_t usec_system, usec_utc;
struct ipc_time_update_msg time_update; struct ipc_time_update_msg time_update;
struct time_sync_format ts_format; struct time_sync_format ts_format;
get_monotonic_boottime(&ts_system); usec_system = ktime_to_us(ktime_get_boottime());
do_gettimeofday(&tv_utc); usec_utc = ktime_to_us(ktime_get_real());
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);
ts_format.ts1_source = HOST_SYSTEM_TIME_USEC; ts_format.ts1_source = HOST_SYSTEM_TIME_USEC;
ts_format.ts2_source = HOST_UTC_TIME_USEC; ts_format.ts2_source = HOST_UTC_TIME_USEC;
ts_format.reserved = 0; ts_format.reserved = 0;
...@@ -575,15 +570,13 @@ static void fw_reset_work_fn(struct work_struct *unused) ...@@ -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 void _ish_sync_fw_clock(struct ishtp_device *dev)
{ {
static unsigned long prev_sync; static unsigned long prev_sync;
struct timespec ts;
uint64_t usec; uint64_t usec;
if (prev_sync && jiffies - prev_sync < 20 * HZ) if (prev_sync && jiffies - prev_sync < 20 * HZ)
return; return;
prev_sync = jiffies; prev_sync = jiffies;
get_monotonic_boottime(&ts); usec = ktime_to_us(ktime_get_boottime());
usec = (timespec_to_ns(&ts)) / NSEC_PER_USEC;
ipc_send_mng_msg(dev, MNG_SYNC_FW_CLOCK, &usec, sizeof(uint64_t)); ipc_send_mng_msg(dev, MNG_SYNC_FW_CLOCK, &usec, sizeof(uint64_t));
} }
......
...@@ -921,7 +921,7 @@ void recv_ishtp_cl_msg(struct ishtp_device *dev, ...@@ -921,7 +921,7 @@ void recv_ishtp_cl_msg(struct ishtp_device *dev,
if (complete_rb) { if (complete_rb) {
cl = complete_rb->cl; cl = complete_rb->cl;
getnstimeofday(&cl->ts_rx); cl->ts_rx = ktime_get();
++cl->recv_msg_cnt_ipc; ++cl->recv_msg_cnt_ipc;
ishtp_cl_read_complete(complete_rb); ishtp_cl_read_complete(complete_rb);
} }
...@@ -1038,7 +1038,7 @@ void recv_ishtp_cl_msg_dma(struct ishtp_device *dev, void *msg, ...@@ -1038,7 +1038,7 @@ void recv_ishtp_cl_msg_dma(struct ishtp_device *dev, void *msg,
if (complete_rb) { if (complete_rb) {
cl = complete_rb->cl; cl = complete_rb->cl;
getnstimeofday(&cl->ts_rx); cl->ts_rx = ktime_get();
++cl->recv_msg_cnt_dma; ++cl->recv_msg_cnt_dma;
ishtp_cl_read_complete(complete_rb); ishtp_cl_read_complete(complete_rb);
} }
......
...@@ -118,9 +118,9 @@ struct ishtp_cl { ...@@ -118,9 +118,9 @@ struct ishtp_cl {
unsigned int out_flow_ctrl_cnt; unsigned int out_flow_ctrl_cnt;
/* Rx msg ... out FC timing */ /* Rx msg ... out FC timing */
struct timespec ts_rx; ktime_t ts_rx;
struct timespec ts_out_fc; ktime_t ts_out_fc;
struct timespec ts_max_fc_delay; ktime_t ts_max_fc_delay;
void *client_data; void *client_data;
}; };
......
...@@ -321,13 +321,10 @@ int ishtp_hbm_cl_flow_control_req(struct ishtp_device *dev, ...@@ -321,13 +321,10 @@ int ishtp_hbm_cl_flow_control_req(struct ishtp_device *dev,
if (!rv) { if (!rv) {
++cl->out_flow_ctrl_creds; ++cl->out_flow_ctrl_creds;
++cl->out_flow_ctrl_cnt; ++cl->out_flow_ctrl_cnt;
getnstimeofday(&cl->ts_out_fc); cl->ts_out_fc = ktime_get();
if (cl->ts_rx.tv_sec && cl->ts_rx.tv_nsec) { if (cl->ts_rx) {
struct timespec ts_diff; ktime_t ts_diff = ktime_sub(cl->ts_out_fc, cl->ts_rx);
if (ktime_after(ts_diff, cl->ts_max_fc_delay))
ts_diff = timespec_sub(cl->ts_out_fc, cl->ts_rx);
if (timespec_compare(&ts_diff, &cl->ts_max_fc_delay)
> 0)
cl->ts_max_fc_delay = ts_diff; cl->ts_max_fc_delay = ts_diff;
} }
} else { } else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment