* [PATCH] Input: Add CLOCK_BOOTTIME support
@ 2014-12-17 23:25 Aniroop Mathur
2014-12-17 23:51 ` Dmitry Torokhov
0 siblings, 1 reply; 7+ messages in thread
From: Aniroop Mathur @ 2014-12-17 23:25 UTC (permalink / raw)
To: dmitry.torokhov, dtor, linux-input; +Cc: aniroop.mathur, a.mathur
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 <a.mathur@samsung.com>
---
drivers/input/evdev.c | 57 ++++++++++++++++++++++++++++++++++++---------------
1 file changed, 41 insertions(+), 16 deletions(-)
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index de05545..914b498 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -28,6 +28,13 @@
#include <linux/cdev.h>
#include "input-compat.h"
+enum evdev_clock_type {
+ EV_CLK_REAL = 0,
+ EV_CLK_MONO,
+ EV_CLK_BOOT,
+ EV_CLK_MAX
+};
+
struct evdev {
int open;
struct input_handle handle;
@@ -49,12 +56,32 @@ struct evdev_client {
struct fasync_struct *fasync;
struct evdev *evdev;
struct list_head node;
- int clkid;
+ int clk_type;
bool revoked;
unsigned int bufsize;
struct input_event buffer[];
};
+static int evdev_set_clk_type(int id, struct evdev_client *client)
+{
+ switch (id) {
+
+ case CLOCK_REALTIME:
+ client->clk_type = EV_CLK_REAL;
+ break;
+ case CLOCK_MONOTONIC:
+ client->clk_type = EV_CLK_MONO;
+ break;
+ case CLOCK_BOOTTIME:
+ client->clk_type = EV_CLK_BOOT;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
/* flush queued events of type @type, caller must hold client->buffer_lock */
static void __evdev_flush_queue(struct evdev_client *client, unsigned int type)
{
@@ -108,8 +135,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->clk_type == EV_CLK_REAL) ?
+ ktime_get_real() : (client->clk_type == EV_CLK_MONO) ?
+ ktime_get() : ktime_get_boottime();
ev.time = ktime_to_timeval(time);
ev.type = EV_SYN;
@@ -159,7 +187,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 +197,7 @@ 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(ev_time[client->clk_type]);
/* Interrupts are disabled, just acquire the lock. */
spin_lock(&client->buffer_lock);
@@ -198,21 +225,22 @@ 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[EV_CLK_MAX];
- time_mono = ktime_get();
- time_real = ktime_mono_to_real(time_mono);
+ ev_time[EV_CLK_MONO] = ktime_get();
+ ev_time[EV_CLK_REAL] = ktime_mono_to_real(ev_time[EV_CLK_MONO]);
+ ev_time[EV_CLK_BOOT] = ktime_mono_to_any(ev_time[EV_CLK_MONO],
+ TK_OFFS_BOOT);
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,10 +902,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)
- return -EINVAL;
- client->clkid = i;
- return 0;
+ return evdev_set_clk_type(i, client);
case EVIOCGKEYCODE:
return evdev_handle_get_keycode(dev, p);
--
1.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] Input: Add CLOCK_BOOTTIME support
2014-12-17 23:25 [PATCH] Input: Add CLOCK_BOOTTIME support Aniroop Mathur
@ 2014-12-17 23:51 ` Dmitry Torokhov
2014-12-17 23:53 ` Aniroop Mathur
0 siblings, 1 reply; 7+ messages in thread
From: Dmitry Torokhov @ 2014-12-17 23:51 UTC (permalink / raw)
To: Aniroop Mathur; +Cc: linux-input, a.mathur
On Thu, Dec 18, 2014 at 04:55:00AM +0530, Aniroop Mathur wrote:
> 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 <a.mathur@samsung.com>
Applied with minor edits, thank you.
> ---
> drivers/input/evdev.c | 57 ++++++++++++++++++++++++++++++++++++---------------
> 1 file changed, 41 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
> index de05545..914b498 100644
> --- a/drivers/input/evdev.c
> +++ b/drivers/input/evdev.c
> @@ -28,6 +28,13 @@
> #include <linux/cdev.h>
> #include "input-compat.h"
>
> +enum evdev_clock_type {
> + EV_CLK_REAL = 0,
> + EV_CLK_MONO,
> + EV_CLK_BOOT,
> + EV_CLK_MAX
> +};
> +
> struct evdev {
> int open;
> struct input_handle handle;
> @@ -49,12 +56,32 @@ struct evdev_client {
> struct fasync_struct *fasync;
> struct evdev *evdev;
> struct list_head node;
> - int clkid;
> + int clk_type;
> bool revoked;
> unsigned int bufsize;
> struct input_event buffer[];
> };
>
> +static int evdev_set_clk_type(int id, struct evdev_client *client)
> +{
> + switch (id) {
> +
> + case CLOCK_REALTIME:
> + client->clk_type = EV_CLK_REAL;
> + break;
> + case CLOCK_MONOTONIC:
> + client->clk_type = EV_CLK_MONO;
> + break;
> + case CLOCK_BOOTTIME:
> + client->clk_type = EV_CLK_BOOT;
> + break;
> + default:
> + return -EINVAL;
> + }
> +
> + return 0;
> +}
> +
> /* flush queued events of type @type, caller must hold client->buffer_lock */
> static void __evdev_flush_queue(struct evdev_client *client, unsigned int type)
> {
> @@ -108,8 +135,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->clk_type == EV_CLK_REAL) ?
> + ktime_get_real() : (client->clk_type == EV_CLK_MONO) ?
> + ktime_get() : ktime_get_boottime();
>
> ev.time = ktime_to_timeval(time);
> ev.type = EV_SYN;
> @@ -159,7 +187,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 +197,7 @@ 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(ev_time[client->clk_type]);
>
> /* Interrupts are disabled, just acquire the lock. */
> spin_lock(&client->buffer_lock);
> @@ -198,21 +225,22 @@ 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[EV_CLK_MAX];
>
> - time_mono = ktime_get();
> - time_real = ktime_mono_to_real(time_mono);
> + ev_time[EV_CLK_MONO] = ktime_get();
> + ev_time[EV_CLK_REAL] = ktime_mono_to_real(ev_time[EV_CLK_MONO]);
> + ev_time[EV_CLK_BOOT] = ktime_mono_to_any(ev_time[EV_CLK_MONO],
> + TK_OFFS_BOOT);
>
> 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,10 +902,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)
> - return -EINVAL;
> - client->clkid = i;
> - return 0;
> + return evdev_set_clk_type(i, client);
>
> case EVIOCGKEYCODE:
> return evdev_handle_get_keycode(dev, p);
> --
> 1.9.1
>
--
Dmitry
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Input: Add CLOCK_BOOTTIME support
2014-12-17 23:51 ` Dmitry Torokhov
@ 2014-12-17 23:53 ` Aniroop Mathur
0 siblings, 0 replies; 7+ messages in thread
From: Aniroop Mathur @ 2014-12-17 23:53 UTC (permalink / raw)
To: Dmitry Torokhov; +Cc: linux-input@vger.kernel.org, a.mathur
On Thu, Dec 18, 2014 at 5:21 AM, Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
> On Thu, Dec 18, 2014 at 04:55:00AM +0530, Aniroop Mathur wrote:
>> 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 <a.mathur@samsung.com>
>
> Applied with minor edits, thank you.
>
Thanks a lot Mr. Torokhov !! :)
Regards,
Aniroop
>> ---
>> drivers/input/evdev.c | 57 ++++++++++++++++++++++++++++++++++++---------------
>> 1 file changed, 41 insertions(+), 16 deletions(-)
>>
>> diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
>> index de05545..914b498 100644
>> --- a/drivers/input/evdev.c
>> +++ b/drivers/input/evdev.c
>> @@ -28,6 +28,13 @@
>> #include <linux/cdev.h>
>> #include "input-compat.h"
>>
>> +enum evdev_clock_type {
>> + EV_CLK_REAL = 0,
>> + EV_CLK_MONO,
>> + EV_CLK_BOOT,
>> + EV_CLK_MAX
>> +};
>> +
>> struct evdev {
>> int open;
>> struct input_handle handle;
>> @@ -49,12 +56,32 @@ struct evdev_client {
>> struct fasync_struct *fasync;
>> struct evdev *evdev;
>> struct list_head node;
>> - int clkid;
>> + int clk_type;
>> bool revoked;
>> unsigned int bufsize;
>> struct input_event buffer[];
>> };
>>
>> +static int evdev_set_clk_type(int id, struct evdev_client *client)
>> +{
>> + switch (id) {
>> +
>> + case CLOCK_REALTIME:
>> + client->clk_type = EV_CLK_REAL;
>> + break;
>> + case CLOCK_MONOTONIC:
>> + client->clk_type = EV_CLK_MONO;
>> + break;
>> + case CLOCK_BOOTTIME:
>> + client->clk_type = EV_CLK_BOOT;
>> + break;
>> + default:
>> + return -EINVAL;
>> + }
>> +
>> + return 0;
>> +}
>> +
>> /* flush queued events of type @type, caller must hold client->buffer_lock */
>> static void __evdev_flush_queue(struct evdev_client *client, unsigned int type)
>> {
>> @@ -108,8 +135,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->clk_type == EV_CLK_REAL) ?
>> + ktime_get_real() : (client->clk_type == EV_CLK_MONO) ?
>> + ktime_get() : ktime_get_boottime();
>>
>> ev.time = ktime_to_timeval(time);
>> ev.type = EV_SYN;
>> @@ -159,7 +187,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 +197,7 @@ 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(ev_time[client->clk_type]);
>>
>> /* Interrupts are disabled, just acquire the lock. */
>> spin_lock(&client->buffer_lock);
>> @@ -198,21 +225,22 @@ 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[EV_CLK_MAX];
>>
>> - time_mono = ktime_get();
>> - time_real = ktime_mono_to_real(time_mono);
>> + ev_time[EV_CLK_MONO] = ktime_get();
>> + ev_time[EV_CLK_REAL] = ktime_mono_to_real(ev_time[EV_CLK_MONO]);
>> + ev_time[EV_CLK_BOOT] = ktime_mono_to_any(ev_time[EV_CLK_MONO],
>> + TK_OFFS_BOOT);
>>
>> 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,10 +902,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)
>> - return -EINVAL;
>> - client->clkid = i;
>> - return 0;
>> + return evdev_set_clk_type(i, client);
>>
>> case EVIOCGKEYCODE:
>> return evdev_handle_get_keycode(dev, p);
>> --
>> 1.9.1
>>
>
> --
> Dmitry
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] Input: Add CLOCK_BOOTTIME Support
@ 2014-12-17 23:07 Aniroop Mathur
2014-12-17 23:17 ` Dmitry Torokhov
0 siblings, 1 reply; 7+ messages in thread
From: Aniroop Mathur @ 2014-12-17 23:07 UTC (permalink / raw)
To: dmitry.torokhov, dtor, linux-input; +Cc: aniroop.mathur, a.mathur
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 <a.mathur@samsung.com>
---
drivers/input/evdev.c | 52 +++++++++++++++++++++++++++++++++++++--------------
1 file changed, 38 insertions(+), 14 deletions(-)
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index de05545..bfca214 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -28,6 +28,13 @@
#include <linux/cdev.h>
#include "input-compat.h"
+enum evdev_clock_type {
+ EV_CLK_REAL = 0,
+ EV_CLK_MONO,
+ EV_CLK_BOOT,
+ EV_CLK_MAX
+};
+
struct evdev {
int open;
struct input_handle handle;
@@ -49,12 +56,29 @@ struct evdev_client {
struct fasync_struct *fasync;
struct evdev *evdev;
struct list_head node;
- int clkid;
+ int clk_type;
bool revoked;
unsigned int bufsize;
struct input_event buffer[];
};
+static int evdev_set_clk_type(int id, struct evdev_client *client)
+{
+ switch (id) {
+
+ case CLOCK_REALTIME:
+ client->clk_type = EV_CLK_REAL; break;
+ case CLOCK_MONOTONIC:
+ client->clk_type = EV_CLK_MONO; break;
+ case CLOCK_BOOTTIME:
+ client->clk_type = EV_CLK_BOOT; break;
+ default:
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
/* flush queued events of type @type, caller must hold client->buffer_lock */
static void __evdev_flush_queue(struct evdev_client *client, unsigned int type)
{
@@ -108,8 +132,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->clk_type == EV_CLK_REAL) ?
+ ktime_get_real() : (client->clk_type == EV_CLK_MONO) ?
+ ktime_get() : ktime_get_boottime();
ev.time = ktime_to_timeval(time);
ev.type = EV_SYN;
@@ -159,7 +184,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 +194,7 @@ 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(ev_time[client->clk_type]);
/* Interrupts are disabled, just acquire the lock. */
spin_lock(&client->buffer_lock);
@@ -198,21 +222,22 @@ 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[EV_CLK_MAX];
- time_mono = ktime_get();
- time_real = ktime_mono_to_real(time_mono);
+ ev_time[EV_CLK_MONO] = ktime_get();
+ ev_time[EV_CLK_REAL] = ktime_mono_to_real(ev_time[EV_CLK_MONO]);
+ ev_time[EV_CLK_BOOT] = ktime_mono_to_any(ev_time[EV_CLK_BOOT],
+ TK_OFFS_BOOT);
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,9 +899,8 @@ 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 (evdev_set_clk_type(i, client))
return -EINVAL;
- client->clkid = i;
return 0;
case EVIOCGKEYCODE:
--
1.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] Input: Add CLOCK_BOOTTIME Support
2014-12-17 23:07 [PATCH] Input: Add CLOCK_BOOTTIME Support Aniroop Mathur
@ 2014-12-17 23:17 ` Dmitry Torokhov
2014-12-17 23:42 ` Aniroop Mathur
0 siblings, 1 reply; 7+ messages in thread
From: Dmitry Torokhov @ 2014-12-17 23:17 UTC (permalink / raw)
To: Aniroop Mathur; +Cc: linux-input, a.mathur
On Thu, Dec 18, 2014 at 04:37:54AM +0530, Aniroop Mathur wrote:
> 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 <a.mathur@samsung.com>
> ---
> drivers/input/evdev.c | 52 +++++++++++++++++++++++++++++++++++++--------------
> 1 file changed, 38 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
> index de05545..bfca214 100644
> --- a/drivers/input/evdev.c
> +++ b/drivers/input/evdev.c
> @@ -28,6 +28,13 @@
> #include <linux/cdev.h>
> #include "input-compat.h"
>
> +enum evdev_clock_type {
> + EV_CLK_REAL = 0,
> + EV_CLK_MONO,
> + EV_CLK_BOOT,
> + EV_CLK_MAX
> +};
> +
> struct evdev {
> int open;
> struct input_handle handle;
> @@ -49,12 +56,29 @@ struct evdev_client {
> struct fasync_struct *fasync;
> struct evdev *evdev;
> struct list_head node;
> - int clkid;
> + int clk_type;
> bool revoked;
> unsigned int bufsize;
> struct input_event buffer[];
> };
>
> +static int evdev_set_clk_type(int id, struct evdev_client *client)
> +{
> + switch (id) {
> +
> + case CLOCK_REALTIME:
> + client->clk_type = EV_CLK_REAL; break;
> + case CLOCK_MONOTONIC:
> + client->clk_type = EV_CLK_MONO; break;
> + case CLOCK_BOOTTIME:
> + client->clk_type = EV_CLK_BOOT; break;
Please put "break" on separate lines.
> + default:
> + return -EINVAL;
> + }
> +
> + return 0;
> +}
> +
> /* flush queued events of type @type, caller must hold client->buffer_lock */
> static void __evdev_flush_queue(struct evdev_client *client, unsigned int type)
> {
> @@ -108,8 +132,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->clk_type == EV_CLK_REAL) ?
> + ktime_get_real() : (client->clk_type == EV_CLK_MONO) ?
> + ktime_get() : ktime_get_boottime();
>
> ev.time = ktime_to_timeval(time);
> ev.type = EV_SYN;
> @@ -159,7 +184,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 +194,7 @@ 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(ev_time[client->clk_type]);
>
> /* Interrupts are disabled, just acquire the lock. */
> spin_lock(&client->buffer_lock);
> @@ -198,21 +222,22 @@ 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[EV_CLK_MAX];
>
> - time_mono = ktime_get();
> - time_real = ktime_mono_to_real(time_mono);
> + ev_time[EV_CLK_MONO] = ktime_get();
> + ev_time[EV_CLK_REAL] = ktime_mono_to_real(ev_time[EV_CLK_MONO]);
> + ev_time[EV_CLK_BOOT] = ktime_mono_to_any(ev_time[EV_CLK_BOOT],
> + TK_OFFS_BOOT);
Nope, that should have read
ev_time[EV_CLK_BOOT] = ktime_mono_to_any(ev_time[EV_CLK_BOOT],
TK_OFFS_BOOT);
Thanks.
--
Dmitry
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Input: Add CLOCK_BOOTTIME Support
2014-12-17 23:17 ` Dmitry Torokhov
@ 2014-12-17 23:42 ` Aniroop Mathur
2014-12-17 23:51 ` Dmitry Torokhov
0 siblings, 1 reply; 7+ messages in thread
From: Aniroop Mathur @ 2014-12-17 23:42 UTC (permalink / raw)
To: Dmitry Torokhov; +Cc: linux-input@vger.kernel.org, a.mathur
Hello Mr. Torokhov,
On Thu, Dec 18, 2014 at 4:47 AM, Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
> On Thu, Dec 18, 2014 at 04:37:54AM +0530, Aniroop Mathur wrote:
>> 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 <a.mathur@samsung.com>
>> ---
>> drivers/input/evdev.c | 52 +++++++++++++++++++++++++++++++++++++--------------
>> 1 file changed, 38 insertions(+), 14 deletions(-)
>>
>> diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
>> index de05545..bfca214 100644
>> --- a/drivers/input/evdev.c
>> +++ b/drivers/input/evdev.c
>> @@ -28,6 +28,13 @@
>> #include <linux/cdev.h>
>> #include "input-compat.h"
>>
>> +enum evdev_clock_type {
>> + EV_CLK_REAL = 0,
>> + EV_CLK_MONO,
>> + EV_CLK_BOOT,
>> + EV_CLK_MAX
>> +};
>> +
>> struct evdev {
>> int open;
>> struct input_handle handle;
>> @@ -49,12 +56,29 @@ struct evdev_client {
>> struct fasync_struct *fasync;
>> struct evdev *evdev;
>> struct list_head node;
>> - int clkid;
>> + int clk_type;
>> bool revoked;
>> unsigned int bufsize;
>> struct input_event buffer[];
>> };
>>
>> +static int evdev_set_clk_type(int id, struct evdev_client *client)
>> +{
>> + switch (id) {
>> +
>> + case CLOCK_REALTIME:
>> + client->clk_type = EV_CLK_REAL; break;
>> + case CLOCK_MONOTONIC:
>> + client->clk_type = EV_CLK_MONO; break;
>> + case CLOCK_BOOTTIME:
>> + client->clk_type = EV_CLK_BOOT; break;
>
> Please put "break" on separate lines.
>
>> + default:
>> + return -EINVAL;
>> + }
>> +
>> + return 0;
>> +}
>> +
>> /* flush queued events of type @type, caller must hold client->buffer_lock */
>> static void __evdev_flush_queue(struct evdev_client *client, unsigned int type)
>> {
>> @@ -108,8 +132,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->clk_type == EV_CLK_REAL) ?
>> + ktime_get_real() : (client->clk_type == EV_CLK_MONO) ?
>> + ktime_get() : ktime_get_boottime();
>>
>> ev.time = ktime_to_timeval(time);
>> ev.type = EV_SYN;
>> @@ -159,7 +184,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 +194,7 @@ 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(ev_time[client->clk_type]);
>>
>> /* Interrupts are disabled, just acquire the lock. */
>> spin_lock(&client->buffer_lock);
>> @@ -198,21 +222,22 @@ 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[EV_CLK_MAX];
>>
>> - time_mono = ktime_get();
>> - time_real = ktime_mono_to_real(time_mono);
>> + ev_time[EV_CLK_MONO] = ktime_get();
>> + ev_time[EV_CLK_REAL] = ktime_mono_to_real(ev_time[EV_CLK_MONO]);
>> + ev_time[EV_CLK_BOOT] = ktime_mono_to_any(ev_time[EV_CLK_BOOT],
>> + TK_OFFS_BOOT);
>
> Nope, that should have read
>
> ev_time[EV_CLK_BOOT] = ktime_mono_to_any(ev_time[EV_CLK_BOOT],
> TK_OFFS_BOOT);
>
Ahhh... okay need to change BOOT to MONO
> Thanks.
>
>
> --
> Dmitry
Thanks for the corrections !!
I have sent the updated the patch with new changes done.
Regards,
Aniroop
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Input: Add CLOCK_BOOTTIME Support
2014-12-17 23:42 ` Aniroop Mathur
@ 2014-12-17 23:51 ` Dmitry Torokhov
0 siblings, 0 replies; 7+ messages in thread
From: Dmitry Torokhov @ 2014-12-17 23:51 UTC (permalink / raw)
To: Aniroop Mathur; +Cc: linux-input@vger.kernel.org, a.mathur
On Thu, Dec 18, 2014 at 05:12:29AM +0530, Aniroop Mathur wrote:
> Hello Mr. Torokhov,
>
> On Thu, Dec 18, 2014 at 4:47 AM, Dmitry Torokhov
> <dmitry.torokhov@gmail.com> wrote:
> > On Thu, Dec 18, 2014 at 04:37:54AM +0530, Aniroop Mathur wrote:
> >> 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 <a.mathur@samsung.com>
> >> ---
> >> drivers/input/evdev.c | 52 +++++++++++++++++++++++++++++++++++++--------------
> >> 1 file changed, 38 insertions(+), 14 deletions(-)
> >>
> >> diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
> >> index de05545..bfca214 100644
> >> --- a/drivers/input/evdev.c
> >> +++ b/drivers/input/evdev.c
> >> @@ -28,6 +28,13 @@
> >> #include <linux/cdev.h>
> >> #include "input-compat.h"
> >>
> >> +enum evdev_clock_type {
> >> + EV_CLK_REAL = 0,
> >> + EV_CLK_MONO,
> >> + EV_CLK_BOOT,
> >> + EV_CLK_MAX
> >> +};
> >> +
> >> struct evdev {
> >> int open;
> >> struct input_handle handle;
> >> @@ -49,12 +56,29 @@ struct evdev_client {
> >> struct fasync_struct *fasync;
> >> struct evdev *evdev;
> >> struct list_head node;
> >> - int clkid;
> >> + int clk_type;
> >> bool revoked;
> >> unsigned int bufsize;
> >> struct input_event buffer[];
> >> };
> >>
> >> +static int evdev_set_clk_type(int id, struct evdev_client *client)
> >> +{
> >> + switch (id) {
> >> +
> >> + case CLOCK_REALTIME:
> >> + client->clk_type = EV_CLK_REAL; break;
> >> + case CLOCK_MONOTONIC:
> >> + client->clk_type = EV_CLK_MONO; break;
> >> + case CLOCK_BOOTTIME:
> >> + client->clk_type = EV_CLK_BOOT; break;
> >
> > Please put "break" on separate lines.
> >
> >> + default:
> >> + return -EINVAL;
> >> + }
> >> +
> >> + return 0;
> >> +}
> >> +
> >> /* flush queued events of type @type, caller must hold client->buffer_lock */
> >> static void __evdev_flush_queue(struct evdev_client *client, unsigned int type)
> >> {
> >> @@ -108,8 +132,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->clk_type == EV_CLK_REAL) ?
> >> + ktime_get_real() : (client->clk_type == EV_CLK_MONO) ?
> >> + ktime_get() : ktime_get_boottime();
> >>
> >> ev.time = ktime_to_timeval(time);
> >> ev.type = EV_SYN;
> >> @@ -159,7 +184,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 +194,7 @@ 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(ev_time[client->clk_type]);
> >>
> >> /* Interrupts are disabled, just acquire the lock. */
> >> spin_lock(&client->buffer_lock);
> >> @@ -198,21 +222,22 @@ 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[EV_CLK_MAX];
> >>
> >> - time_mono = ktime_get();
> >> - time_real = ktime_mono_to_real(time_mono);
> >> + ev_time[EV_CLK_MONO] = ktime_get();
> >> + ev_time[EV_CLK_REAL] = ktime_mono_to_real(ev_time[EV_CLK_MONO]);
> >> + ev_time[EV_CLK_BOOT] = ktime_mono_to_any(ev_time[EV_CLK_BOOT],
> >> + TK_OFFS_BOOT);
> >
> > Nope, that should have read
> >
> > ev_time[EV_CLK_BOOT] = ktime_mono_to_any(ev_time[EV_CLK_BOOT],
> > TK_OFFS_BOOT);
> >
>
> Ahhh... okay need to change BOOT to MONO
Ugh, apparently I failed to actually type properly what I meant. Glad
you still understood me ;)
Thanks.
--
Dmitry
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2014-12-17 23:53 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-17 23:25 [PATCH] Input: Add CLOCK_BOOTTIME support Aniroop Mathur
2014-12-17 23:51 ` Dmitry Torokhov
2014-12-17 23:53 ` Aniroop Mathur
-- strict thread matches above, loose matches on Subject: below --
2014-12-17 23:07 [PATCH] Input: Add CLOCK_BOOTTIME Support Aniroop Mathur
2014-12-17 23:17 ` Dmitry Torokhov
2014-12-17 23:42 ` Aniroop Mathur
2014-12-17 23:51 ` Dmitry Torokhov
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).