From ff3b3b33231a6a0862f7bc605a6ddf5580316996 Mon Sep 17 00:00:00 2001 From: Jerry Chang Date: Tue, 9 Jan 2018 17:26:04 +0800 Subject: [PATCH] drivers: media: evaluate capture init latency - 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 Reviewed-on: https://git-master.nvidia.com/r/1634665 Reviewed-by: mobile promotions Tested-by: mobile promotions --- .../media/platform/tegra/camera/vi/channel.c | 27 +++++++++++++++++++ .../media/platform/tegra/camera/vi/vi2_fops.c | 5 ++++ .../media/platform/tegra/camera/vi/vi4_fops.c | 4 +++ 3 files changed, 36 insertions(+) diff --git a/drivers/media/platform/tegra/camera/vi/channel.c b/drivers/media/platform/tegra/camera/vi/channel.c index 115be1adec7b..46d4ff1d7458 100644 --- a/drivers/media/platform/tegra/camera/vi/channel.c +++ b/drivers/media/platform/tegra/camera/vi/channel.c @@ -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 = { diff --git a/drivers/media/platform/tegra/camera/vi/vi2_fops.c b/drivers/media/platform/tegra/camera/vi/vi2_fops.c index f6d420e648fc..d8cb190c665c 100644 --- a/drivers/media/platform/tegra/camera/vi/vi2_fops.c +++ b/drivers/media/platform/tegra/camera/vi/vi2_fops.c @@ -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) { diff --git a/drivers/media/platform/tegra/camera/vi/vi4_fops.c b/drivers/media/platform/tegra/camera/vi/vi4_fops.c index 86c1840500e5..67763dd46b80 100644 --- a/drivers/media/platform/tegra/camera/vi/vi4_fops.c +++ b/drivers/media/platform/tegra/camera/vi/vi4_fops.c @@ -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; -- 2.39.2