From patchwork Tue Dec 16 16:56:34 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aniroop Mathur X-Patchwork-Id: 5502311 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id ADBEFBEEA8 for ; Tue, 16 Dec 2014 16:56:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9F29920A1E for ; Tue, 16 Dec 2014 16:56:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9F2A020A1C for ; Tue, 16 Dec 2014 16:56:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751059AbaLPQ4t (ORCPT ); Tue, 16 Dec 2014 11:56:49 -0500 Received: from mail-pa0-f51.google.com ([209.85.220.51]:63224 "EHLO mail-pa0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750981AbaLPQ4t (ORCPT ); Tue, 16 Dec 2014 11:56:49 -0500 Received: by mail-pa0-f51.google.com with SMTP id ey11so14498558pad.38 for ; Tue, 16 Dec 2014 08:56:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=vgqzVQHi6rKLSejPQHrmi7ADNDmCVNvu+INdVnbnN8U=; b=YPiQ56uTV2lzlglQ1QXVGquzlgi3G6UdbDI1HYo/QI1Rroqc983mfIYmrrlQ5LgeH8 bkjKwu/Rb5x1YfjjkGpxf0jsSeROQA04iEam7ZGgpEdQJ5ppiAmDIoTaGC6CCmLe0sGL TsqCW+URGq3W1mq9W31YtpW1BGRcr+qI5Jn9bC6OJI3iOM062EH6NDpI1f96hdRw+HKy x7CQHqGcfEyJ8aWoAfC/G1teHAV5vjeboy7O7HoCqVqEYk77S64dcnbD8lmRFSvDjqpn SlZH6MzpBz1nLV2w5tDbYk8d2i7OuT42tmVrfiZD/gRUp8McAeeEvk/y+3DEVW58XHY4 ZeHQ== X-Received: by 10.66.142.166 with SMTP id rx6mr63237053pab.33.1418749008601; Tue, 16 Dec 2014 08:56:48 -0800 (PST) Received: from localhost.localdomain ([115.118.72.85]) by mx.google.com with ESMTPSA id vb4sm1510550pab.19.2014.12.16.08.56.45 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Dec 2014 08:56:47 -0800 (PST) From: Aniroop Mathur To: , , Cc: , Subject: [PATCH] Input: Add support for CLOCK_BOOTTIME Date: Tue, 16 Dec 2014 22:26:34 +0530 Message-Id: <1418748994-2875-1-git-send-email-aniroop.mathur@gmail.com> X-Mailer: git-send-email 1.9.1 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds support for CLOCK_BOOTTIME for input event timestamp. CLOCK_BOOTTIME includes suspend time, so it would allow aplications to get correct time difference between two events even when system resumes from suspend state. Signed-off-by: Aniroop Mathur --- drivers/input/evdev.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c index de05545..7825794 100644 --- a/drivers/input/evdev.c +++ b/drivers/input/evdev.c @@ -28,6 +28,13 @@ #include #include "input-compat.h" +enum clock_type { + REAL = 0, + MONO, + BOOT, + CLK_MAX +}; + struct evdev { int open; struct input_handle handle; @@ -108,8 +115,9 @@ static void evdev_queue_syn_dropped(struct evdev_client *client) struct input_event ev; ktime_t time; - time = (client->clkid == CLOCK_MONOTONIC) ? - ktime_get() : ktime_get_real(); + time = (client->clkid == CLOCK_REALTIME) ? + ktime_get_real() : (client->clkid == CLOCK_MONOTONIC) ? + ktime_get() : ktime_get_boottime(); ev.time = ktime_to_timeval(time); ev.type = EV_SYN; @@ -159,7 +167,7 @@ static void __pass_event(struct evdev_client *client, static void evdev_pass_values(struct evdev_client *client, const struct input_value *vals, unsigned int count, - ktime_t mono, ktime_t real) + ktime_t *ev_time) { struct evdev *evdev = client->evdev; const struct input_value *v; @@ -169,8 +177,9 @@ static void evdev_pass_values(struct evdev_client *client, if (client->revoked) return; - event.time = ktime_to_timeval(client->clkid == CLOCK_MONOTONIC ? - mono : real); + event.time = ktime_to_timeval(client->clkid == CLOCK_REALTIME ? + ev_time[REAL] : client->clkid == CLOCK_MONOTONIC ? + ev_time[MONO] : ev_time[BOOT]); /* Interrupts are disabled, just acquire the lock. */ spin_lock(&client->buffer_lock); @@ -198,21 +207,21 @@ static void evdev_events(struct input_handle *handle, { struct evdev *evdev = handle->private; struct evdev_client *client; - ktime_t time_mono, time_real; + ktime_t ev_time[CLK_MAX]; - time_mono = ktime_get(); - time_real = ktime_mono_to_real(time_mono); + ev_time[MONO] = ktime_get(); + ev_time[REAL] = ktime_mono_to_real(ev_time[MONO]); + ev_time[BOOT] = ktime_get_boottime(); rcu_read_lock(); client = rcu_dereference(evdev->grab); if (client) - evdev_pass_values(client, vals, count, time_mono, time_real); + evdev_pass_values(client, vals, count, ev_time); else list_for_each_entry_rcu(client, &evdev->client_list, node) - evdev_pass_values(client, vals, count, - time_mono, time_real); + evdev_pass_values(client, vals, count, ev_time); rcu_read_unlock(); } @@ -874,7 +883,7 @@ static long evdev_do_ioctl(struct file *file, unsigned int cmd, case EVIOCSCLOCKID: if (copy_from_user(&i, p, sizeof(unsigned int))) return -EFAULT; - if (i != CLOCK_MONOTONIC && i != CLOCK_REALTIME) + if (i != CLOCK_MONOTONIC && i != CLOCK_REALTIME && i != CLOCK_BOOTTIME) return -EINVAL; client->clkid = i; return 0;