public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: mmc@maruska.dyndns.org (Michal Maruška)
To: linux-kernel@vger.kernel.org
Cc: vojtech@suse.cz, arjan@infradead.org, george@mvista.com
Subject: Re: [PATCH 2.6.15-rc7] clocks: export symbol do_posix_clock_monotonic_gettime + input: monotonic timestamps for evdev
Date: Wed, 28 Dec 2005 00:07:49 +0100	[thread overview]
Message-ID: <m2bqz2m94q.fsf_-_@linux11.maruska.tin.it> (raw)
In-Reply-To: <1135669949.2926.13.camel@laptopd505.fenrus.org> (Arjan van de Ven's message of "Tue, 27 Dec 2005 08:52:29 +0100")

[-- Attachment #1: Type: text/plain, Size: 473 bytes --]


Arjan van de Ven <arjan@infradead.org> writes:

> could you also include the patch to add the user (say evdev) in the same
> patch please?

here is my complete patch updated for -rc7:

Summary:
- export do_posix_clock_monotonic_gettime 
- implement an ioctl call for EVDEV to request timestamping of events with
  monotonic time. 

For complete explanation see my previous mail http://lkml.org/lkml/2005/10/6/92 



Signed-off-by: Michal Maruska <mmc@maruska.dyndns.org> 

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: mono-evdev.patch --]
[-- Type: text/x-patch, Size: 4479 bytes --]

--- linux-2.6.15-rc7/kernel/posix-timers.c	2005-12-26 13:01:54.000000000 +0100
+++ linux-2.6.15-rc7.mmc/kernel/posix-timers.c	2005-12-26 22:59:11.883817855 +0100
@@ -1219,6 +1219,7 @@ int do_posix_clock_monotonic_gettime(str
 {
 	return do_posix_clock_monotonic_get(CLOCK_MONOTONIC, tp);
 }
+EXPORT_SYMBOL_GPL(do_posix_clock_monotonic_gettime);
 
 int do_posix_clock_nosettime(clockid_t clockid, struct timespec *tp)
 {
--- linux-2.6.15-rc7/drivers/input/evdev.c	2005-12-26 13:01:54.000000000 +0100
+++ linux-2.6.15-rc7.mmc/drivers/input/evdev.c	2005-12-27 16:41:06.842396740 +0100
@@ -6,6 +6,11 @@
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 as published by
  * the Free Software Foundation.
+ *
+ * 
+ * 2005-12-27  Optional timestamping with monotonic time
+ *                by  Michal Maruska <mmc@maruska.dyndns.org>
+ *     
  */
 
 #define EVDEV_MINOR_BASE	64
@@ -37,6 +42,7 @@ struct evdev_list {
 	struct input_event buffer[EVDEV_BUFFER_SIZE];
 	int head;
 	int tail;
+        int time_kind;      /* which time to use for the timestamps. Monotonic or timeofday. Should I use enum? */
 	struct fasync_struct *fasync;
 	struct evdev *evdev;
 	struct list_head node;
@@ -44,15 +50,37 @@ struct evdev_list {
 
 static struct evdev *evdev_table[EVDEV_MINORS];
 
+static inline
+void 
+mem_copy_time(struct timeval *a, struct timeval* b)
+{
+        memcpy(a, b, sizeof(struct timeval));
+}
+
 static void evdev_event(struct input_handle *handle, unsigned int type, unsigned int code, int value)
 {
 	struct evdev *evdev = handle->private;
 	struct evdev_list *list;
 
+        struct timeval mtv, dtv;
+        /* `do_posix_clock_monotonic_gettime' delivers a different struct,
+         * but i do the conversion immediately, and once. */
+        struct timespec mts;
+        
+        do_posix_clock_monotonic_gettime(&mts);
+        mtv.tv_sec = mts.tv_sec;
+        mtv.tv_usec = mts.tv_nsec / 1000;
+        
+        do_gettimeofday(&dtv);         /* for backward compatibility: */
+
 	if (evdev->grab) {
 		list = evdev->grab;
 
-		do_gettimeofday(&list->buffer[list->head].time);
+                if (list->time_kind == EV_USE_DAY_TIME)
+                        mem_copy_time(&list->buffer[list->head].time,&dtv);
+                else
+                        mem_copy_time(&list->buffer[list->head].time,&mtv);
+
 		list->buffer[list->head].type = type;
 		list->buffer[list->head].code = code;
 		list->buffer[list->head].value = value;
@@ -62,7 +90,11 @@ static void evdev_event(struct input_han
 	} else
 		list_for_each_entry(list, &evdev->list, node) {
 
-			do_gettimeofday(&list->buffer[list->head].time);
+                        if (list->time_kind == EV_USE_DAY_TIME)
+                                mem_copy_time(&list->buffer[list->head].time,&dtv);
+                        else
+                                mem_copy_time(&list->buffer[list->head].time,&mtv);
+
 			list->buffer[list->head].type = type;
 			list->buffer[list->head].code = code;
 			list->buffer[list->head].value = value;
@@ -134,6 +166,7 @@ static int evdev_open(struct inode * ino
 		return -ENOMEM;
 	memset(list, 0, sizeof(struct evdev_list));
 
+        list->time_kind = EV_USE_DAY_TIME; /* for backward compatibility! */
 	list->evdev = evdev_table[i];
 	list_add_tail(&list->node, &evdev_table[i]->list);
 	file->private_data = list;
@@ -370,6 +403,17 @@ static long evdev_ioctl(struct file *fil
 				evdev->grab = NULL;
 				return 0;
 			}
+                case EVIOCTIME:
+                        switch (arg) {
+                        case EV_USE_MONOTONIC_TIME:
+                                list->time_kind = EV_USE_MONOTONIC_TIME;
+				return 0;
+			case EV_USE_DAY_TIME:
+                                list->time_kind = EV_USE_DAY_TIME;
+				return 0;
+                        default:
+                                return -EINVAL;
+			}
 
 		default:
 
--- linux-2.6.15-rc7/include/linux/input.h	2005-12-26 13:01:54.000000000 +0100
+++ linux-2.6.15-rc7.mmc/include/linux/input.h	2005-12-27 16:48:09.932302548 +0100
@@ -79,6 +79,15 @@ struct input_absinfo {
 
 #define EVIOCGRAB		_IOW('E', 0x90, int)			/* Grab/Release device */
 
+#define EVIOCTIME		_IOW('E', 0x91, int)			/* choose what kind of time to use for timestamps */
+
+/*
+ * Time used to timestamp 
+ */
+#define EV_USE_MONOTONIC_TIME 0
+#define EV_USE_DAY_TIME 1
+
+
 /*
  * Event types
  */

      reply	other threads:[~2005-12-27 23:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-12-26 22:20 [PATCH 2.6.15-rc7] clocks: export symbol do_posix_clock_monotonic_gettime Michal Maruška
2005-12-27  7:52 ` Arjan van de Ven
2005-12-27 23:07   ` Michal Maruška [this message]

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=m2bqz2m94q.fsf_-_@linux11.maruska.tin.it \
    --to=mmc@maruska.dyndns.org \
    --cc=arjan@infradead.org \
    --cc=george@mvista.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vojtech@suse.cz \
    /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