]> rtime.felk.cvut.cz Git - hercules2020/nv-tegra/linux-4.4.git/commitdiff
drivers: media: evaluate capture init latency
authorJerry Chang <jerchang@nvidia.com>
Tue, 9 Jan 2018 09:26:04 +0000 (17:26 +0800)
committermobile promotions <svcmobile_promotions@nvidia.com>
Fri, 26 Jan 2018 03:21:07 +0000 (19:21 -0800)
- check VI driver's capture init latency
- evaluate the latency between videobuf2 queue init
  and first captured frame release to user-space
- add debug prints for SOF and EOF

Bug 200376318
Bug 2016843

Change-Id: I7cd6c6c33c12f7bdc8b36621341b0f46eecf62f8
Signed-off-by: Jerry Chang <jerchang@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/1634665
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
drivers/media/platform/tegra/camera/vi/channel.c
drivers/media/platform/tegra/camera/vi/vi2_fops.c
drivers/media/platform/tegra/camera/vi/vi4_fops.c

index 115be1adec7b024211a2760d24003fc0653bb3d1..46d4ff1d745825c3f81ed8866964082610d8cbc3 100644 (file)
@@ -44,6 +44,8 @@
 
 #define TPG_CSI_GROUP_ID       10
 
+static s64 queue_init_ts;
+
 static void gang_buffer_offsets(struct tegra_channel *chan)
 {
        int i;
@@ -296,6 +298,7 @@ static void tegra_channel_fmts_bitmap_init(struct tegra_channel *chan)
 void release_buffer(struct tegra_channel *chan, struct tegra_channel_buffer* buf)
 {
        struct vb2_v4l2_buffer* vbuf = &buf->buf;
+       s64 frame_arrived_ts = 0;
        /* release one frame */
        vbuf->sequence = chan->sequence++;
        vbuf->field = V4L2_FIELD_NONE;
@@ -312,6 +315,19 @@ void release_buffer(struct tegra_channel *chan, struct tegra_channel_buffer* buf
                buf->state = VB2_BUF_STATE_ERROR;
        }
 
+       if (chan->sequence == 1) {
+               /*
+                * Evaluate the initial capture latency between videobuf2 queue
+                * and first captured frame release to user-space.
+                */
+               frame_arrived_ts = ktime_to_ms(ktime_get());
+               dev_dbg(&chan->video.dev, "%s: capture init latency is %lld ms\n",
+                       __func__, (frame_arrived_ts - queue_init_ts));
+       }
+
+       dev_dbg(&chan->video.dev,
+               "%s: release buf[%p] frame[%d] to user-space\n",
+               __func__, buf, chan->sequence);
        vb2_buffer_done(&vbuf->vb2_buf, buf->state);
 }
 
@@ -434,6 +450,14 @@ static void tegra_channel_buffer_queue(struct vb2_buffer *vb)
        if (chan->bypass)
                return;
 
+       if (!queue_init_ts) {
+               /*
+                * Record videobuf2 queue initial timestamp.
+                * Note: latency is accurate when streaming is already turned ON
+                */
+               queue_init_ts = ktime_to_ms(ktime_get());
+       }
+
        /* Put buffer into the capture queue */
        spin_lock(&chan->start_lock);
        list_add_tail(&buf->queue, &chan->capture);
@@ -582,6 +606,9 @@ static void tegra_channel_stop_streaming(struct vb2_queue *vq)
 
        if (vi->fops)
                vi->fops->vi_stop_streaming(vq);
+
+       /* Clean-up recorded videobuf2 queue initial timestamp */
+       queue_init_ts = 0;
 }
 
 static const struct vb2_ops tegra_channel_queue_qops = {
index f6d420e648fca84490a71a1298e377f0d050432e..d8cb190c665c63dcd24577b5d096105fdbc0a5c9 100644 (file)
@@ -484,6 +484,8 @@ static int tegra_channel_capture_frame(struct tegra_channel *chan,
                        chan->capture_state = CAPTURE_TIMEOUT;
                        break;
                }
+               dev_dbg(&chan->video.dev,
+                       "%s: vi2 got SOF syncpt buf[%p]\n", __func__, buf);
        }
 
        if (!err && !chan->pg_mode) {
@@ -617,6 +619,9 @@ static void tegra_channel_release_frame(struct tegra_channel *chan,
                if (err)
                        dev_err(&chan->video.dev,
                                "MW_ACK_DONE syncpoint time out!%d\n", index);
+
+               dev_dbg(&chan->video.dev,
+                       "%s: vi2 got EOF syncpt buf[%p]\n", __func__, buf);
        }
 
        if (err) {
index 86c1840500e5b3d60afd53e868424e0b705b4c31..67763dd46b80015648c1891d4580666d3f123e69 100644 (file)
@@ -536,6 +536,8 @@ static int tegra_channel_capture_frame(struct tegra_channel *chan,
 
        /* wait for vi notifier events */
        vi_notify_wait(chan, &ts);
+       dev_dbg(&chan->video.dev,
+               "%s: vi4 got SOF syncpt buf[%p]\n", __func__, buf);
 
        vi4_check_status(chan);
 
@@ -590,6 +592,8 @@ static void tegra_channel_release_frame(struct tegra_channel *chan,
                        dev_err(&chan->video.dev,
                                "MW_ACK_DONE syncpoint time out!%d\n", index);
        }
+       dev_dbg(&chan->video.dev,
+               "%s: vi4 got EOF syncpt buf[%p]\n", __func__, buf);
 
        if (err) {
                buf->state = VB2_BUF_STATE_ERROR;