From: Nicolas Dufresne <nicolas@ndufresne.ca>
To: "Sven Püschel" <s.pueschel@pengutronix.de>,
"Jacob Chen" <jacob-chen@iotwrt.com>,
"Ezequiel Garcia" <ezequiel@vanguardiasur.com.ar>,
"Mauro Carvalho Chehab" <mchehab@kernel.org>,
"Heiko Stuebner" <heiko@sntech.de>,
"Philipp Zabel" <p.zabel@pengutronix.de>
Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, kernel@pengutronix.de,
Detlev Casanova <detlev.casanova@collabora.com>,
Michael Tretter <m.tretter@pengutronix.de>,
Guangshuo Li <lgs201920130244@gmail.com>
Subject: Re: [PATCH v2 06/17] media: v4l2-mem2mem: drop curr_ctx member from v4l2_m2m_dev struct
Date: Tue, 24 Nov 2026 15:55:05 -0500 [thread overview]
Message-ID: <82a6933335048ca8f9969481cde8340dac19ccb1.camel@ndufresne.ca> (raw)
In-Reply-To: <20260916-spu-rga3multicore-v2-6-23aa2cb74e61@pengutronix.de>
[-- Attachment #1: Type: text/plain, Size: 6873 bytes --]
Le mercredi 16 septembre 2026 à 17:09 +0200, Sven Püschel a écrit :
> Drop the curr_ctx member from the v4l2_m2m_dev struct in preparation of
> adding support for running multiple jobs in parallel.
>
> The curr_ctx member of a v4l2_m2m_dev was used to track the
> currently running context. But the currently running context will always
> be at the top of the job_queue. As the TRANS_RUNNING flag can be used to
> check if the queue head is already running, the curr_ctx member can be
> completely dropped.
>
> By eliminating the struct member the code is mostly agnostic whenever
> only one job is running at a time or multiple run at the same time. The
> main exception is the v4l2_m2m_get_curr_priv function, which is by it's
> design incompatible with running multiple jobs in parallel.
>
> Signed-off-by: Sven Püschel <s.pueschel@pengutronix.de>
>
> ---
> v2:
> - split curr_ctx removal into a separate commit
> - add WARN_ON to _v4l2_m2m_job_finish to prevent mismatching context to
> device (and an unused m2m_dev argument)
> - rewrite v4l2_m2m_get_curr_priv to get private data inside the spinlock
> (https://sashiko.dev/#/patchset/20260606-spu-rga3multicore-v1-0-3ec2b15675f7%40pengutronix.de?part=5)
> ---
> drivers/media/v4l2-core/v4l2-mem2mem.c | 61 ++++++++++++++++++----------------
> 1 file changed, 33 insertions(+), 28 deletions(-)
>
> diff --git a/drivers/media/v4l2-core/v4l2-mem2mem.c b/drivers/media/v4l2-core/v4l2-mem2mem.c
> index a65cbb124cfe0..60cca94195166 100644
> --- a/drivers/media/v4l2-core/v4l2-mem2mem.c
> +++ b/drivers/media/v4l2-core/v4l2-mem2mem.c
> @@ -84,7 +84,6 @@ static const char * const m2m_entity_name[] = {
> * v4l2_m2m_unregister_media_controller().
> * @intf_devnode: &struct media_intf devnode pointer with the interface
> * with controls the M2M device.
> - * @curr_ctx: currently running instance
> * @job_queue: instances queued to run
> * @job_spinlock: protects job_queue
> * @job_work: worker to run queued jobs.
> @@ -93,7 +92,6 @@ static const char * const m2m_entity_name[] = {
> * @kref: device reference count
> */
> struct v4l2_m2m_dev {
> - struct v4l2_m2m_ctx *curr_ctx;
> #ifdef CONFIG_MEDIA_CONTROLLER
> struct media_entity *source;
> struct media_pad source_pad;
> @@ -232,8 +230,14 @@ void *v4l2_m2m_get_curr_priv(struct v4l2_m2m_dev *m2m_dev)
> void *ret = NULL;
>
> spin_lock_irqsave(&m2m_dev->job_spinlock, flags);
> - if (m2m_dev->curr_ctx)
> - ret = m2m_dev->curr_ctx->priv;
> + if (!list_empty(&m2m_dev->job_queue)) {
> + struct v4l2_m2m_ctx *first_ctx =
> + list_first_entry(&m2m_dev->job_queue,
> + struct v4l2_m2m_ctx, queue);
> +
> + if (first_ctx->job_flags & TRANS_RUNNING)
> + ret = first_ctx->priv;
> + }
> spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags);
>
> return ret;
> @@ -252,14 +256,9 @@ EXPORT_SYMBOL(v4l2_m2m_get_curr_priv);
> static void v4l2_m2m_try_run(struct v4l2_m2m_dev *m2m_dev)
> {
> unsigned long flags;
> + struct v4l2_m2m_ctx *chosen_ctx;
>
> spin_lock_irqsave(&m2m_dev->job_spinlock, flags);
> - if (NULL != m2m_dev->curr_ctx) {
> - spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags);
> - dprintk("Another instance is running, won't run now\n");
> - return;
> - }
> -
> if (list_empty(&m2m_dev->job_queue)) {
> spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags);
> dprintk("No job pending\n");
> @@ -272,13 +271,18 @@ static void v4l2_m2m_try_run(struct v4l2_m2m_dev *m2m_dev)
> return;
> }
>
> - m2m_dev->curr_ctx = list_first_entry(&m2m_dev->job_queue,
> - struct v4l2_m2m_ctx, queue);
> - m2m_dev->curr_ctx->job_flags |= TRANS_RUNNING;
> + chosen_ctx = list_first_entry(&m2m_dev->job_queue, struct v4l2_m2m_ctx, queue);
> + if (chosen_ctx->job_flags & TRANS_RUNNING) {
> + spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags);
> + dprintk("Another instance is running, won't run now\n");
> + return;
> + }
> +
> + chosen_ctx->job_flags |= TRANS_RUNNING;
> spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags);
>
> - dprintk("Running job on m2m_ctx: %p\n", m2m_dev->curr_ctx);
> - m2m_dev->m2m_ops->device_run(m2m_dev->curr_ctx->priv);
> + dprintk("Running job on m2m_ctx: %p\n", chosen_ctx);
> + m2m_dev->m2m_ops->device_run(chosen_ctx->priv);
> }
>
> /*
> @@ -469,15 +473,16 @@ static void v4l2_m2m_schedule_next_job(struct v4l2_m2m_dev *m2m_dev,
> static bool _v4l2_m2m_job_finish(struct v4l2_m2m_dev *m2m_dev,
> struct v4l2_m2m_ctx *m2m_ctx)
> {
> - if (!m2m_dev->curr_ctx || m2m_dev->curr_ctx != m2m_ctx) {
> + if (!m2m_ctx || !(m2m_ctx->job_flags & TRANS_RUNNING)) {
> dprintk("Called by an instance not currently running\n");
> return false;
> }
>
> - list_del(&m2m_dev->curr_ctx->queue);
> - m2m_dev->curr_ctx->job_flags &= ~(TRANS_QUEUED | TRANS_RUNNING);
> - wake_up(&m2m_dev->curr_ctx->finished);
> - m2m_dev->curr_ctx = NULL;
> + WARN_ON(m2m_dev != m2m_ctx->m2m_dev);
> +
> + list_del(&m2m_ctx->queue);
> + m2m_ctx->job_flags &= ~(TRANS_QUEUED | TRANS_RUNNING);
> + wake_up(&m2m_ctx->finished);
> return true;
> }
>
> @@ -548,12 +553,15 @@ void v4l2_m2m_suspend(struct v4l2_m2m_dev *m2m_dev)
>
> spin_lock_irqsave(&m2m_dev->job_spinlock, flags);
> m2m_dev->job_queue_flags |= QUEUE_PAUSED;
> - curr_ctx = m2m_dev->curr_ctx;
> + if (list_empty(&m2m_dev->job_queue)) {
> + spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags);
> + return;
> + }
> +
> + curr_ctx = list_first_entry(&m2m_dev->job_queue, struct v4l2_m2m_ctx, queue);
> spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags);
>
> - if (curr_ctx)
> - wait_event(curr_ctx->finished,
> - !(curr_ctx->job_flags & TRANS_RUNNING));
> + wait_event(curr_ctx->finished, !(curr_ctx->job_flags & TRANS_RUNNING));
> }
> EXPORT_SYMBOL(v4l2_m2m_suspend);
>
> @@ -896,10 +904,8 @@ int v4l2_m2m_streamoff(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
> q_ctx->num_rdy = 0;
> spin_unlock_irqrestore(&q_ctx->rdy_spinlock, flags);
>
> - if (m2m_dev->curr_ctx == m2m_ctx) {
> - m2m_dev->curr_ctx = NULL;
> + if (m2m_ctx->job_flags & TRANS_RUNNING)
> wake_up(&m2m_ctx->finished);
Sashiko report that wake_up() is unreachable, that job_flags have been clear
previously.
If that is correct, its not a big issue:
Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
> - }
> spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags_job);
>
> return 0;
> @@ -1194,7 +1200,6 @@ struct v4l2_m2m_dev *v4l2_m2m_init(const struct v4l2_m2m_ops *m2m_ops)
> if (!m2m_dev)
> return ERR_PTR(-ENOMEM);
>
> - m2m_dev->curr_ctx = NULL;
> m2m_dev->m2m_ops = m2m_ops;
> INIT_LIST_HEAD(&m2m_dev->job_queue);
> spin_lock_init(&m2m_dev->job_spinlock);
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2026-11-24 20:55 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-16 15:09 [PATCH v2 00/17] media: rockchip: rga: Add multi-core support Sven Püschel
2026-09-16 15:09 ` [PATCH v2 01/17] media: rockchip: rga: zero cmdbuf in shared code Sven Püschel
2026-11-24 20:44 ` Nicolas Dufresne
2026-09-16 15:09 ` [PATCH v2 02/17] media: rockchip: rga: add comment about pixel alignment for YUV formats Sven Püschel
2026-11-24 20:45 ` Nicolas Dufresne
2026-09-16 15:09 ` [PATCH v2 03/17] media: rockchip: rga: move early return into if condition in vidioc_enum_fmt Sven Püschel
2026-11-24 20:46 ` Nicolas Dufresne
2026-09-16 15:09 ` [PATCH v2 04/17] media: rockchip: rga: removed unused regmap member Sven Püschel
2026-11-24 20:46 ` Nicolas Dufresne
2026-09-16 15:09 ` [PATCH v2 05/17] media: rockchip: rga: use devres version of pm_runtime_enable Sven Püschel
2026-11-24 20:51 ` Nicolas Dufresne
2026-09-16 15:09 ` [PATCH v2 06/17] media: v4l2-mem2mem: drop curr_ctx member from v4l2_m2m_dev struct Sven Püschel
2026-11-24 20:55 ` Nicolas Dufresne [this message]
2026-09-16 15:09 ` [PATCH v2 07/17] media: v4l2-mem2mem: support running multiple jobs in parallel Sven Püschel
2026-11-24 21:12 ` Nicolas Dufresne
2026-09-16 15:09 ` [PATCH v2 08/17] media: rockchip: rga: move power handling to device_run Sven Püschel
2026-11-24 21:14 ` Nicolas Dufresne
2026-09-16 15:09 ` [PATCH v2 09/17] media: rockchip: rga: adjust get_version to return the version Sven Püschel
2026-11-24 21:15 ` Nicolas Dufresne
2026-09-16 15:09 ` [PATCH v2 10/17] media: rockchip: rga: add rga_core structure Sven Püschel
2026-11-24 21:16 ` Nicolas Dufresne
2026-09-16 15:09 ` [PATCH v2 11/17] media: rockchip: rga: use components to manage multiple cores Sven Püschel
2026-11-24 21:29 ` Nicolas Dufresne
2026-09-16 15:09 ` [PATCH v2 12/17] media: rockchip: rga: move rockchip_rga allocation to master probe Sven Püschel
2026-11-24 21:30 ` Nicolas Dufresne
2026-09-16 15:09 ` [PATCH v2 13/17] media: rockchip: rga: move core initialization from bind to probe Sven Püschel
2026-11-24 21:35 ` Nicolas Dufresne
2026-09-16 15:09 ` [PATCH v2 14/17] media: rockchip: rga: move video device to the master Sven Püschel
2026-11-24 21:38 ` Nicolas Dufresne
2026-09-16 15:09 ` [PATCH v2 15/17] media: rockchip: rga: bind all cores " Sven Püschel
2026-11-24 21:43 ` Nicolas Dufresne
2026-09-16 15:09 ` [PATCH v2 16/17] media: rockchip: rga: put all cores into first core iommu domain Sven Püschel
2026-11-24 21:50 ` Nicolas Dufresne
2026-09-16 15:09 ` [PATCH v2 17/17] media: rockchip: rga: schedule jobs to multiple cores Sven Püschel
2026-11-24 21:52 ` Nicolas Dufresne
2026-11-14 4:50 ` [PATCH v2 00/17] media: rockchip: rga: Add multi-core support Arun Iyengar
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=82a6933335048ca8f9969481cde8340dac19ccb1.camel@ndufresne.ca \
--to=nicolas@ndufresne.ca \
--cc=detlev.casanova@collabora.com \
--cc=ezequiel@vanguardiasur.com.ar \
--cc=heiko@sntech.de \
--cc=jacob-chen@iotwrt.com \
--cc=kernel@pengutronix.de \
--cc=lgs201920130244@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=m.tretter@pengutronix.de \
--cc=mchehab@kernel.org \
--cc=p.zabel@pengutronix.de \
--cc=s.pueschel@pengutronix.de \
/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
all inboxes | Powered by JetHome®