From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Hans Verkuil <hverkuil@xs4all.nl>
Cc: "Tomasz Figa" <tfiga@chromium.org>,
"Marek Szyprowski" <m.szyprowski@samsung.com>,
"Mauro Carvalho Chehab" <mchehab@kernel.org>,
"Shuah Khan" <skhan@linuxfoundation.org>,
"Kieran Bingham" <kieran.bingham@ideasonboard.com>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Andy Walls" <awalls@md.metrocast.net>,
"Yong Zhi" <yong.zhi@intel.com>,
"Sakari Ailus" <sakari.ailus@linux.intel.com>,
"Bingbu Cao" <bingbu.cao@intel.com>,
"Dan Scally" <djrscally@gmail.com>,
"Tianshu Qiu" <tian.shu.qiu@intel.com>,
"Martin Tuma" <martin.tuma@digiteqautomotive.com>,
"Bluecherry Maintainers" <maintainers@bluecherrydvr.com>,
"Andrey Utkin" <andrey_utkin@fastmail.com>,
"Ismael Luceno" <ismael@iodev.co.uk>,
"Ezequiel Garcia" <ezequiel@vanguardiasur.com.ar>,
"Corentin Labbe" <clabbe@baylibre.com>,
"Michael Krufky" <mkrufky@linuxtv.org>,
"Matt Ranostay" <matt@ranostay.sg>,
"Michael Tretter" <m.tretter@pengutronix.de>,
"Pengutronix Kernel Team" <kernel@pengutronix.de>,
"Neil Armstrong" <neil.armstrong@linaro.org>,
"Kevin Hilman" <khilman@baylibre.com>,
"Jerome Brunet" <jbrunet@baylibre.com>,
"Martin Blumenstingl" <martin.blumenstingl@googlemail.com>,
"Ming Qian" <ming.qian@nxp.com>, "Zhou Peng" <eagle.zhou@nxp.com>,
"Eddie James" <eajames@linux.ibm.com>,
"Joel Stanley" <joel@jms.id.au>,
"Andrew Jeffery" <andrew@codeconstruct.com.au>,
"Eugen Hristev" <eugen.hristev@collabora.com>,
"Nicolas Ferre" <nicolas.ferre@microchip.com>,
"Alexandre Belloni" <alexandre.belloni@bootlin.com>,
"Claudiu Beznea" <claudiu.beznea@tuxon.dev>,
"Raspberry Pi Kernel Maintenance" <kernel-list@raspberrypi.com>,
"Florian Fainelli" <florian.fainelli@broadcom.com>,
"Broadcom internal kernel review list"
<bcm-kernel-feedback-list@broadcom.com>,
"Ray Jui" <rjui@broadcom.com>,
"Scott Branden" <sbranden@broadcom.com>,
"Philipp Zabel" <p.zabel@pengutronix.de>,
"Nas Chung" <nas.chung@chipsnmedia.com>,
"Jackson Lee" <jackson.lee@chipsnmedia.com>,
"Devarsh Thakkar" <devarsht@ti.com>,
"Bin Liu" <bin.liu@mediatek.com>,
"Matthias Brugger" <matthias.bgg@gmail.com>,
"AngeloGioacchino Del Regno"
<angelogioacchino.delregno@collabora.com>,
"Minghsiu Tsai" <minghsiu.tsai@mediatek.com>,
"Houlong Wei" <houlong.wei@mediatek.com>,
"Andrew-CT Chen" <andrew-ct.chen@mediatek.com>,
"Tiffany Lin" <tiffany.lin@mediatek.com>,
"Yunfei Dong" <yunfei.dong@mediatek.com>,
"Joseph Liu" <kwliu@nuvoton.com>,
"Marvin Lin" <kflin@nuvoton.com>,
"Dmitry Osipenko" <digetx@gmail.com>,
"Thierry Reding" <thierry.reding@gmail.com>,
"Jonathan Hunter" <jonathanh@nvidia.com>,
"Xavier Roumegue" <xavier.roumegue@oss.nxp.com>,
"Mirela Rabulea" <mirela.rabulea@nxp.com>,
"Shawn Guo" <shawnguo@kernel.org>,
"Sascha Hauer" <s.hauer@pengutronix.de>,
"Fabio Estevam" <festevam@gmail.com>,
"Rui Miguel Silva" <rmfrfs@gmail.com>,
"Martin Kepplinger" <martink@posteo.de>,
"Purism Kernel Team" <kernel@puri.sm>,
"Robert Foss" <rfoss@kernel.org>,
"Todor Tomov" <todor.too@gmail.com>,
"Bryan O'Donoghue" <bryan.odonoghue@linaro.org>,
"Stanimir Varbanov" <stanimir.k.varbanov@gmail.com>,
"Vikash Garodia" <quic_vgarodia@quicinc.com>,
"Jacopo Mondi" <jacopo.mondi@ideasonboard.com>,
"Niklas Söderlund" <niklas.soderlund@ragnatech.se>,
"Fabrizio Castro" <fabrizio.castro.jz@renesas.com>,
"Kieran Bingham" <kieran.bingham+renesas@ideasonboard.com>,
"Mikhail Ulyanov" <mikhail.ulyanov@cogentembedded.com>,
"Jacob Chen" <jacob-chen@iotwrt.com>,
"Heiko Stuebner" <heiko@sntech.de>,
"Dafna Hirschfeld" <dafna@fastmail.com>,
"Krzysztof Kozlowski" <krzk@kernel.org>,
"Alim Akhtar" <alim.akhtar@samsung.com>,
"Sylwester Nawrocki" <s.nawrocki@samsung.com>,
"Łukasz Stelmach" <l.stelmach@samsung.com>,
"Andrzej Pietrasiewicz" <andrzejtp2010@gmail.com>,
"Jacek Anaszewski" <jacek.anaszewski@gmail.com>,
"Andrzej Hajda" <andrzej.hajda@intel.com>,
"Fabien Dessenne" <fabien.dessenne@foss.st.com>,
"Hugues Fruchet" <hugues.fruchet@foss.st.com>,
"Jean-Christophe Trotin" <jean-christophe.trotin@foss.st.com>,
"Maxime Coquelin" <mcoquelin.stm32@gmail.com>,
"Alexandre Torgue" <alexandre.torgue@foss.st.com>,
"Alain Volmat" <alain.volmat@foss.st.com>,
"Maxime Ripard" <mripard@kernel.org>,
"Chen-Yu Tsai" <wens@csie.org>,
"Jernej Skrabec" <jernej.skrabec@gmail.com>,
"Samuel Holland" <samuel@sholland.org>,
"Yong Deng" <yong.deng@magewell.com>,
"Paul Kocialkowski" <paul.kocialkowski@bootlin.com>,
"Benoit Parrot" <bparrot@ti.com>,
"Jai Luthra" <jai.luthra@linux.dev>,
"Michal Simek" <michal.simek@amd.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Hans de Goede" <hdegoede@redhat.com>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Steve Longerbeam" <slongerbeam@gmail.com>,
"Jack Zhu" <jack.zhu@starfivetech.com>,
"Changhuang Liang" <changhuang.liang@starfivetech.com>,
"Sowjanya Komatineni" <skomatineni@nvidia.com>,
"Luca Ceresoli" <luca.ceresoli@bootlin.com>,
linux-media@vger.kernel.org
Subject: Re: [PATCH 01/10] media: videobuf2-core: update vb2_thread if wait_finish/prepare are NULL
Date: Wed, 16 Oct 2024 11:20:48 +0300 [thread overview]
Message-ID: <20241016082048.GD2712@pendragon.ideasonboard.com> (raw)
In-Reply-To: <ff498f0a-7f04-4376-8d98-50fa0cfa2b9b@xs4all.nl>
Hi Hans,
On Tue, Oct 15, 2024 at 08:56:30AM +0200, Hans Verkuil wrote:
> On 14/10/2024 21:15, Laurent Pinchart wrote:
> > On Mon, Oct 14, 2024 at 05:06:28PM +0200, Hans Verkuil wrote:
> >> For read/write support the vb2_thread is used. This will queue and
> >> dequeue buffers automatically to provide the read() or write() feature.
> >>
> >> It calls wait_finish/prepare around vb2_core_dqbuf() and vb2_core_qbuf(),
> >> but that assumes all drivers have these ops set. But that will change
> >> due to commit 88785982a19d ("media: vb2: use lock if wait_prepare/finish
> >> are NULL").
> >>
> >> So instead check if the callback is available, and if not, use q->lock,
> >> just as __vb2_wait_for_done_vb() does.
> >>
> >> It was also used around vb2_core_qbuf(), but VIDIOC_QBUF doesn't
> >> need this since it doesn't do a blocking wait, so just drop the
> >> wait_finish/prepare callbacks around vb2_core_qbuf().
> >>
> >> Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
> >> ---
> >> drivers/media/common/videobuf2/videobuf2-core.c | 12 ++++++++----
> >> 1 file changed, 8 insertions(+), 4 deletions(-)
> >>
> >> diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c
> >> index d064e0664851b26b2da71e0a374c49a2d2c5e217..e9c1d9e3222323be50b3039eb463384a3d558239 100644
> >> --- a/drivers/media/common/videobuf2/videobuf2-core.c
> >> +++ b/drivers/media/common/videobuf2/videobuf2-core.c
> >> @@ -3218,10 +3218,16 @@ static int vb2_thread(void *data)
> >> continue;
> >> prequeue--;
> >> } else {
> >> - call_void_qop(q, wait_finish, q);
> >> + if (q->ops->wait_finish)
> >> + call_void_qop(q, wait_finish, q);
> >> + else if (q->lock)
> >> + mutex_lock(q->lock);
> >
> > I would still prefer moving vb2_ops_wait_prepare() and
> > vb2_ops_wait_finish() to videobuf2-core.c and calling the functions
> > here, instead of locking the mutex directly. I think it would make the
> > code more readable. I won't block the patch for this, but I think it
> > would be better.
>
> The whole point of this series is to prepare for the removal of the
> wait_finish/prepare callbacks. So this patch is just a temporary change.
>
> Eventually this code will change to just a mutex_lock.
OK.
> > Also, should we check at queue init time that drivers either set a queue
> > lock or provide the .wait_prepare() and .wait_finish() operations ?
>
> It does that already, from videobuf2-core.c, vb2_core_queue_init():
>
> /* Warn if q->lock is NULL and no custom wait_prepare is provided */
> if (WARN_ON(!q->lock && !q->ops->wait_prepare))
> return -EINVAL;
Perfect :-)
> >> if (!threadio->stop)
> >> ret = vb2_core_dqbuf(q, &index, NULL, 0);
> >> - call_void_qop(q, wait_prepare, q);
> >> + if (q->ops->wait_prepare)
> >> + call_void_qop(q, wait_prepare, q);
> >> + else if (q->lock)
> >> + mutex_unlock(q->lock);
> >> dprintk(q, 5, "file io: vb2_dqbuf result: %d\n", ret);
> >> if (!ret)
> >> vb = vb2_get_buffer(q, index);
> >> @@ -3233,12 +3239,10 @@ static int vb2_thread(void *data)
> >> if (vb->state != VB2_BUF_STATE_ERROR)
> >> if (threadio->fnc(vb, threadio->priv))
> >> break;
> >> - call_void_qop(q, wait_finish, q);
> >> if (copy_timestamp)
> >> vb->timestamp = ktime_get_ns();
> >> if (!threadio->stop)
> >> ret = vb2_core_qbuf(q, vb, NULL, NULL);
> >> - call_void_qop(q, wait_prepare, q);
> >> if (ret || threadio->stop)
> >> break;
> >> }
> >>
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2024-10-16 8:20 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-14 15:06 [PATCH 00/10] media: start work to remove wait_prepare/finish callbacks Hans Verkuil
2024-10-14 15:06 ` [PATCH 01/10] media: videobuf2-core: update vb2_thread if wait_finish/prepare are NULL Hans Verkuil
2024-10-14 19:15 ` Laurent Pinchart
2024-10-15 6:56 ` Hans Verkuil
2024-10-16 8:20 ` Laurent Pinchart [this message]
2024-10-17 14:38 ` Mauro Carvalho Chehab
2024-10-17 14:51 ` Hans Verkuil
2024-10-17 15:09 ` [PATCHv2 " Hans Verkuil
2024-10-18 4:14 ` Mauro Carvalho Chehab
2024-10-14 15:06 ` [PATCH 02/10] media: test-drivers: drop vb2_ops_wait_prepare/finish Hans Verkuil
2024-10-15 15:17 ` Shuah
2024-10-14 15:06 ` [PATCH 03/10] media: pci: " Hans Verkuil
2024-10-19 11:51 ` Sakari Ailus
2024-10-14 15:06 ` [PATCH 04/10] media: usb: " Hans Verkuil
2024-10-14 15:06 ` [PATCH 05/10] media: video-i2c: " Hans Verkuil
2024-10-19 11:49 ` Sakari Ailus
2024-10-14 15:06 ` [PATCH 06/10] media: rtl2832_sdr: " Hans Verkuil
2024-12-11 4:23 ` Arthur Marsh
2024-10-14 15:06 ` [PATCH 07/10] media: platform: " Hans Verkuil
2024-10-15 8:01 ` Neil Armstrong
2024-10-19 21:10 ` Andrzej Pietrasiewicz
2024-10-27 12:53 ` Andrzej Pietrasiewicz
2024-10-14 15:06 ` [PATCH 08/10] media: common: saa7146: " Hans Verkuil
2024-10-14 15:06 ` [PATCH 09/10] staging: media: " Hans Verkuil
2024-10-15 8:00 ` Neil Armstrong
2024-10-16 7:50 ` Luca Ceresoli
2024-10-14 15:06 ` [PATCH 10/10] media: samples: v4l2-pci-skeleton.c: " Hans Verkuil
2024-10-14 15:13 ` [PATCH 00/10] media: start work to remove wait_prepare/finish callbacks Hans Verkuil
2024-10-14 19:16 ` Laurent Pinchart
2024-10-15 15:13 ` Shuah
2024-10-15 15:23 ` Hans Verkuil
2024-10-16 15:00 ` Shuah
2024-10-16 15:11 ` Laurent Pinchart
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=20241016082048.GD2712@pendragon.ideasonboard.com \
--to=laurent.pinchart@ideasonboard.com \
--cc=alain.volmat@foss.st.com \
--cc=alexandre.belloni@bootlin.com \
--cc=alexandre.torgue@foss.st.com \
--cc=alim.akhtar@samsung.com \
--cc=andrew-ct.chen@mediatek.com \
--cc=andrew@codeconstruct.com.au \
--cc=andrey_utkin@fastmail.com \
--cc=andrzej.hajda@intel.com \
--cc=andrzejtp2010@gmail.com \
--cc=andy@kernel.org \
--cc=angelogioacchino.delregno@collabora.com \
--cc=awalls@md.metrocast.net \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=bin.liu@mediatek.com \
--cc=bingbu.cao@intel.com \
--cc=bparrot@ti.com \
--cc=bryan.odonoghue@linaro.org \
--cc=changhuang.liang@starfivetech.com \
--cc=clabbe@baylibre.com \
--cc=claudiu.beznea@tuxon.dev \
--cc=dafna@fastmail.com \
--cc=daniel.almeida@collabora.com \
--cc=devarsht@ti.com \
--cc=digetx@gmail.com \
--cc=djrscally@gmail.com \
--cc=eagle.zhou@nxp.com \
--cc=eajames@linux.ibm.com \
--cc=eugen.hristev@collabora.com \
--cc=ezequiel@vanguardiasur.com.ar \
--cc=fabien.dessenne@foss.st.com \
--cc=fabrizio.castro.jz@renesas.com \
--cc=festevam@gmail.com \
--cc=florian.fainelli@broadcom.com \
--cc=gregkh@linuxfoundation.org \
--cc=hdegoede@redhat.com \
--cc=heiko@sntech.de \
--cc=houlong.wei@mediatek.com \
--cc=hugues.fruchet@foss.st.com \
--cc=hverkuil@xs4all.nl \
--cc=ismael@iodev.co.uk \
--cc=jacek.anaszewski@gmail.com \
--cc=jack.zhu@starfivetech.com \
--cc=jackson.lee@chipsnmedia.com \
--cc=jacob-chen@iotwrt.com \
--cc=jacopo.mondi@ideasonboard.com \
--cc=jai.luthra@linux.dev \
--cc=jbrunet@baylibre.com \
--cc=jean-christophe.trotin@foss.st.com \
--cc=jernej.skrabec@gmail.com \
--cc=joel@jms.id.au \
--cc=jonathanh@nvidia.com \
--cc=kernel-list@raspberrypi.com \
--cc=kernel@pengutronix.de \
--cc=kernel@puri.sm \
--cc=kflin@nuvoton.com \
--cc=khilman@baylibre.com \
--cc=kieran.bingham+renesas@ideasonboard.com \
--cc=kieran.bingham@ideasonboard.com \
--cc=krzk@kernel.org \
--cc=kwliu@nuvoton.com \
--cc=l.stelmach@samsung.com \
--cc=linux-media@vger.kernel.org \
--cc=luca.ceresoli@bootlin.com \
--cc=m.szyprowski@samsung.com \
--cc=m.tretter@pengutronix.de \
--cc=maintainers@bluecherrydvr.com \
--cc=martin.blumenstingl@googlemail.com \
--cc=martin.tuma@digiteqautomotive.com \
--cc=martink@posteo.de \
--cc=matt@ranostay.sg \
--cc=matthias.bgg@gmail.com \
--cc=mchehab@kernel.org \
--cc=mcoquelin.stm32@gmail.com \
--cc=michal.simek@amd.com \
--cc=mikhail.ulyanov@cogentembedded.com \
--cc=ming.qian@nxp.com \
--cc=minghsiu.tsai@mediatek.com \
--cc=mirela.rabulea@nxp.com \
--cc=mkrufky@linuxtv.org \
--cc=mripard@kernel.org \
--cc=nas.chung@chipsnmedia.com \
--cc=neil.armstrong@linaro.org \
--cc=nicolas.ferre@microchip.com \
--cc=niklas.soderlund@ragnatech.se \
--cc=p.zabel@pengutronix.de \
--cc=paul.kocialkowski@bootlin.com \
--cc=quic_vgarodia@quicinc.com \
--cc=rfoss@kernel.org \
--cc=rjui@broadcom.com \
--cc=rmfrfs@gmail.com \
--cc=s.hauer@pengutronix.de \
--cc=s.nawrocki@samsung.com \
--cc=sakari.ailus@linux.intel.com \
--cc=samuel@sholland.org \
--cc=sbranden@broadcom.com \
--cc=shawnguo@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=skomatineni@nvidia.com \
--cc=slongerbeam@gmail.com \
--cc=stanimir.k.varbanov@gmail.com \
--cc=tfiga@chromium.org \
--cc=thierry.reding@gmail.com \
--cc=tian.shu.qiu@intel.com \
--cc=tiffany.lin@mediatek.com \
--cc=todor.too@gmail.com \
--cc=wens@csie.org \
--cc=xavier.roumegue@oss.nxp.com \
--cc=yong.deng@magewell.com \
--cc=yong.zhi@intel.com \
--cc=yunfei.dong@mediatek.com \
/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