Re: [RFC PATCH v11 6/9] media: tegra: Add Tegra210 Video input driver

From: Sowjanya Komatineni
Date: Thu Apr 30 2020 - 16:22:47 EST



On 4/30/20 1:21 PM, Dmitry Osipenko wrote:
30.04.2020 23:09, Sowjanya Komatineni ÐÐÑÐÑ:
On 4/30/20 1:08 PM, Sowjanya Komatineni wrote:
On 4/30/20 1:06 PM, Dmitry Osipenko wrote:
30.04.2020 01:00, Sowjanya Komatineni ÐÐÑÐÑ:
+static int chan_capture_kthread_start(void *data)
+{
+ÂÂÂ struct tegra_vi_channel *chan = data;
+ÂÂÂ struct tegra_channel_buffer *buf;
+ÂÂÂ int err = 0;
+
+ÂÂÂ set_freezable();
+
+ÂÂÂ while (1) {
+ÂÂÂÂÂÂÂ try_to_freeze();
+
+ÂÂÂÂÂÂÂ /*
+ÂÂÂÂÂÂÂÂ * Source is not streaming if error is non-zero.
+ÂÂÂÂÂÂÂÂ * So, do not dequeue buffers on error and let the thread
sleep
+ÂÂÂÂÂÂÂÂ * till kthread stop signal is received.
+ÂÂÂÂÂÂÂÂ */
+ÂÂÂÂÂÂÂ wait_event_interruptible(chan->start_wait,
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ kthread_should_stop() ||
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ (!list_empty(&chan->capture) &&
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ !err));
...
+static void tegra_channel_buffer_queue(struct vb2_buffer *vb)
+{
+ÂÂÂ struct tegra_vi_channel *chan = vb2_get_drv_priv(vb->vb2_queue);
+ÂÂÂ struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+ÂÂÂ struct tegra_channel_buffer *buf = to_tegra_channel_buffer(vbuf);
+
+ÂÂÂ /* put buffer into the capture queue */
+ÂÂÂ spin_lock(&chan->start_lock);
+ÂÂÂ list_add_tail(&buf->queue, &chan->capture);
+ÂÂÂ spin_unlock(&chan->start_lock);
+
+ÂÂÂ /* wait up kthread for capture */
+ÂÂÂ wake_up_interruptible(&chan->start_wait);
+}
The V4L doc says that buffers could be enqueued before streaming is
started. I guess it should be a trouble here, shouldn't it?

https://elixir.bootlin.com/linux/v5.7-rc3/source/include/media/videobuf2-core.h#L379

what trouble are you referring here?

I dont think so as we set min buffers needed as 2 always there will be
2 per-queued buffers.
typo* pre-queued buffers before streaming start
But buffers from this queue will be dequeued only when ready to
processes in the capture thread
I see now that the threads won't be running until start_streaming() is
invoked, should be okay then.
ok. yes threads run only during streaming