]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
media: v4l2-event: keep track of the timestamp in ns
authorHans Verkuil <hverkuil-cisco@xs4all.nl>
Mon, 21 Jan 2019 13:32:22 +0000 (08:32 -0500)
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>
Thu, 7 Feb 2019 17:11:15 +0000 (12:11 -0500)
Internally use ktime_get_ns() to get the timestamp of the event.
Only convert to timespec when interfacing with userspace.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
drivers/media/v4l2-core/v4l2-event.c
include/media/v4l2-event.h

index 481e3c65cf97a63202e1223b106c59b5e670651b..c46d14c996fced6187ce6ed7d8316deb68b740de 100644 (file)
@@ -52,6 +52,7 @@ static int __v4l2_event_dequeue(struct v4l2_fh *fh, struct v4l2_event *event)
 
        kev->event.pending = fh->navailable;
        *event = kev->event;
+       event->timestamp = ns_to_timespec(kev->ts);
        kev->sev->first = sev_pos(kev->sev, 1);
        kev->sev->in_use--;
 
@@ -103,8 +104,8 @@ static struct v4l2_subscribed_event *v4l2_event_subscribed(
        return NULL;
 }
 
-static void __v4l2_event_queue_fh(struct v4l2_fh *fh, const struct v4l2_event *ev,
-               const struct timespec *ts)
+static void __v4l2_event_queue_fh(struct v4l2_fh *fh,
+                                 const struct v4l2_event *ev, u64 ts)
 {
        struct v4l2_subscribed_event *sev;
        struct v4l2_kevent *kev;
@@ -144,7 +145,7 @@ static void __v4l2_event_queue_fh(struct v4l2_fh *fh, const struct v4l2_event *e
        if (copy_payload)
                kev->event.u = ev->u;
        kev->event.id = ev->id;
-       kev->event.timestamp = *ts;
+       kev->ts = ts;
        kev->event.sequence = fh->sequence;
        sev->in_use++;
        list_add_tail(&kev->list, &fh->available);
@@ -158,17 +159,17 @@ void v4l2_event_queue(struct video_device *vdev, const struct v4l2_event *ev)
 {
        struct v4l2_fh *fh;
        unsigned long flags;
-       struct timespec timestamp;
+       u64 ts;
 
        if (vdev == NULL)
                return;
 
-       ktime_get_ts(&timestamp);
+       ts = ktime_get_ns();
 
        spin_lock_irqsave(&vdev->fh_lock, flags);
 
        list_for_each_entry(fh, &vdev->fh_list, list)
-               __v4l2_event_queue_fh(fh, ev, &timestamp);
+               __v4l2_event_queue_fh(fh, ev, ts);
 
        spin_unlock_irqrestore(&vdev->fh_lock, flags);
 }
@@ -177,12 +178,10 @@ EXPORT_SYMBOL_GPL(v4l2_event_queue);
 void v4l2_event_queue_fh(struct v4l2_fh *fh, const struct v4l2_event *ev)
 {
        unsigned long flags;
-       struct timespec timestamp;
-
-       ktime_get_ts(&timestamp);
+       u64 ts = ktime_get_ns();
 
        spin_lock_irqsave(&fh->vdev->fh_lock, flags);
-       __v4l2_event_queue_fh(fh, ev, &timestamp);
+       __v4l2_event_queue_fh(fh, ev, ts);
        spin_unlock_irqrestore(&fh->vdev->fh_lock, flags);
 }
 EXPORT_SYMBOL_GPL(v4l2_event_queue_fh);
index 17833e886e11132a9e78bf5688ca9abc56cb88ef..c2b6cdc714d281dc8996ebb824949aa7fbfc1e42 100644 (file)
@@ -34,11 +34,13 @@ struct video_device;
  * @list:      List node for the v4l2_fh->available list.
  * @sev:       Pointer to parent v4l2_subscribed_event.
  * @event:     The event itself.
+ * @ts:                The timestamp of the event.
  */
 struct v4l2_kevent {
        struct list_head        list;
        struct v4l2_subscribed_event *sev;
        struct v4l2_event       event;
+       u64                     ts;
 };
 
 /**