From: John Stultz <john.stultz@linaro.org>
To: linux-input@vger.kernel.org
Cc: "John Stultz" <john.stultz@linaro.org>,
"Dmitry Torokhov" <dmitry.torokhov@gmail.com>,
"Daniel Kurtz" <djkurtz@google.com>,
"Arve Hjønnevåg" <arve@android.com>
Subject: [RFC][PATCH] Input: Add infrastrucutre for selecting clockid for event time stamps.
Date: Thu, 5 Jan 2012 18:50:12 -0800 [thread overview]
Message-ID: <1325818212-24752-1-git-send-email-john.stultz@linaro.org> (raw)
Here's another revision, incorperating Dmitry's suggestion.
As noted by Arve and others, since wall time can jump backwards, it
is difficult to use for input because one cannot determine if one
event occured before another or for how long a key was pressed.
However, the timestamp field is part of the kernel ABI, and cannot
be changed without possibly breaking existing users.
This patch adds a new IOCTL that allows a clockid to be set in
the evdev_client struct that will specify which time base to
use for event timestamps (ie: CLOCK_MONOTONIC instead
of CLOCK_REALTIME).
For now we only support CLOCK_MONOTONIC and CLOCK_REALTIME, but
in the future we could support other clockids if appropriate.
The default remains CLOCK_REALTIME, so we don't change the ABI.
CC: Dmitry Torokhov <dmitry.torokhov@gmail.com>
CC: Daniel Kurtz <djkurtz@google.com>
CC: linux-input@vger.kernel.org
CC: Arve Hjønnevåg <arve@android.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
drivers/input/evdev.c | 33 +++++++++++++++++++++++++++++----
include/linux/input.h | 2 ++
2 files changed, 31 insertions(+), 4 deletions(-)
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index 4cf2534..4b71484 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -46,6 +46,7 @@ struct evdev_client {
struct fasync_struct *fasync;
struct evdev *evdev;
struct list_head node;
+ bool timestamp_clkid;
unsigned int bufsize;
struct input_event buffer[];
};
@@ -54,8 +55,19 @@ static struct evdev *evdev_table[EVDEV_MINORS];
static DEFINE_MUTEX(evdev_table_mutex);
static void evdev_pass_event(struct evdev_client *client,
- struct input_event *event)
+ struct input_event *event,
+ ktime_t mono, ktime_t real)
{
+ struct timespec ts;
+
+ if (client->timestamp_clkid == CLOCK_MONOTONIC)
+ ts = ktime_to_timespec(mono);
+ else
+ ts = ktime_to_timespec(real);
+ event->time.tv_sec = ts.tv_sec;
+ event->time.tv_usec = ts.tv_nsec / NSEC_PER_USEC;
+
+
/* Interrupts are disabled, just acquire the lock. */
spin_lock(&client->buffer_lock);
@@ -94,8 +106,11 @@ static void evdev_event(struct input_handle *handle,
struct evdev *evdev = handle->private;
struct evdev_client *client;
struct input_event event;
+ ktime_t time_mono, time_real;
+
+ time_mono = ktime_get();
+ time_real = ktime_sub(time_mono, ktime_get_monotonic_offset());
- do_gettimeofday(&event.time);
event.type = type;
event.code = code;
event.value = value;
@@ -103,11 +118,12 @@ static void evdev_event(struct input_handle *handle,
rcu_read_lock();
client = rcu_dereference(evdev->grab);
+
if (client)
- evdev_pass_event(client, &event);
+ evdev_pass_event(client, &event, time_mono, time_real);
else
list_for_each_entry_rcu(client, &evdev->client_list, node)
- evdev_pass_event(client, &event);
+ evdev_pass_event(client, &event, time_mono, time_real);
rcu_read_unlock();
@@ -683,6 +699,15 @@ static long evdev_do_ioctl(struct file *file, unsigned int cmd,
else
return evdev_ungrab(evdev, client);
+ case EVIOCCLOCKID:
+ if (copy_from_user(&i, p, sizeof(unsigned int)))
+ return -EFAULT;
+ if ((i == CLOCK_MONOTONIC) || (i == CLOCK_REALTIME)) {
+ client->timestamp_clkid = i;
+ return 0;
+ }
+ return -EINVAL;
+
case EVIOCGKEYCODE:
return evdev_handle_get_keycode(dev, p);
diff --git a/include/linux/input.h b/include/linux/input.h
index 3862e32..9618e14 100644
--- a/include/linux/input.h
+++ b/include/linux/input.h
@@ -129,6 +129,8 @@ struct input_keymap_entry {
#define EVIOCGRAB _IOW('E', 0x90, int) /* Grab/Release device */
+#define EVIOCCLOCKID _IOW('E', 0xA0, int) /* Set clockid to be used for timestamps */
+
/*
* Device properties and quirks
*/
--
1.7.3.2.146.gca209
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next reply other threads:[~2012-01-06 2:50 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-06 2:50 John Stultz [this message]
2012-01-06 9:20 ` [RFC][PATCH] Input: Add infrastrucutre for selecting clockid for event time stamps Daniel Kurtz
2012-01-06 19:39 ` John Stultz
-- strict thread matches above, loose matches on Subject: below --
2012-01-07 3:40 John Stultz
2012-01-07 6:42 ` Daniel Kurtz
2012-01-09 18:04 ` Dmitry Torokhov
[not found] ` <CAGS+omDkkH_cVQV4CvF1iz-aSRdNTGcsEghXU3MNBLAgsp7jFA@mail.gmail.com>
2012-01-09 18:48 ` Dmitry Torokhov
2012-01-09 22:49 ` Arve Hjønnevåg
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=1325818212-24752-1-git-send-email-john.stultz@linaro.org \
--to=john.stultz@linaro.org \
--cc=arve@android.com \
--cc=djkurtz@google.com \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-input@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).