Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Sven Püschel" <s.pueschel@pengutronix.de>
To: Nicolas Dufresne <nicolas@ndufresne.ca>,
	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>
Subject: Re: [PATCH 05/17] media: v4l2-mem2mem: support running multiple jobs in parallel
Date: Wed, 15 Jul 2026 11:44:01 +0200	[thread overview]
Message-ID: <e89fd487-ea3f-42fd-8647-6fa74ac991e8@pengutronix.de> (raw)
In-Reply-To: <aae16dbfb26c8ee7e54247ca4d123b15748d623f.camel@ndufresne.ca>

Hi,

On 7/10/26 11:18 PM, Nicolas Dufresne wrote:
> Hi,
>
> Le samedi 06 juin 2026 à 00:06 +0200, Sven Püschel a écrit :
>> Add support for running multiple jobs in parallel for SoCs containing
>> multiple identical devices. An example is the Rockchip RK3588 SoC,
>> which contains two identical RGA3 devices. Therefore it is desirable to
>> have the kernel schedule the work across all available devices and only
>> expose one video device to the userspace.
>>
>> Previously 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
>>
>> To avoid queueing too many parallel jobs, the
>> v4l2_m2m_set_max_parallel_jobs method is added. It allows a driver
>> to set the number of parallel jobs and avoids calling device_run when
>> the given number of jobs is already running. This is set to 1 by default
>> to prevent parallel job runs. Drivers with the need and support for
>> scheduling jobs can adjust this value accordingly.
>>
>> Note that this change doesn't allow a context to be used multiple times
>> in parallel. So a single stream won't be able to utilize multiple devices
>> at once, but N streams can utilize up to N devices. This is caused by the
>> fact that a context is not added multiple times to the job_list and also
>> holds the job_flags to distinguish if it's currently running.
> I do prefer this over Detlev proposal, so let's move toward this. Would be it
> cleaner though to first remove curr_ctx and then add
> max_parallel_jobs ?

Nice idea. I could move the max_parallel_jobs variable and the new 
function to a new small commit.

I could also move the whole looping and counting of running jobs over 
the jobs to the new commit. But this would cause replacing the curr_ctx 
variable with a `list_first_entry(...)->job_flags & TRANS_RUNNING` and 
drop it in the commit afterwards to replace it with loops.

While the commits would look a bit nicer in the latter example (as the 
removal of curr_ctx wouldn't also prepare for parallel jobs), I think 
the addition and direct removal style is frowned upon and therefore I 
tend towards the first option. On the other side I'm unsure if a 10 line 
patch to just add max_parallel_jobs variable and function with 
everything done in a (removal) patch provides benefit or harms to get to 
the related changes.

>> @@ -252,13 +266,11 @@ 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 *ctx;
>> +	struct v4l2_m2m_ctx *chosen_ctx = NULL;
>> +	u32 running_jobs = 0;
>>   
>>   	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);
>> @@ -272,13 +284,30 @@ 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;
>> +	list_for_each_entry(ctx, &m2m_dev->job_queue, queue) {
>> +		if (!(ctx->job_flags & TRANS_RUNNING)) {
>> +			chosen_ctx = ctx;
>> +			break;
>> +		}
>> +
>> +		running_jobs++;
>> +	}
>> +	if (running_jobs >= m2m_dev->max_parallel_jobs) {
>> +		spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags);
>> +		dprintk("Maximum number of parallel jobs reached\n");
>> +		return;
>> +	}
>> +	if (!chosen_ctx) {
>> +		spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags);
>> +		dprintk("All jobs already running\n");
>> +		return;
>> +	}
>> +
>> +	chosen_ctx->job_flags |= TRANS_RUNNING;
>>   	spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags);

This is the most prominent example on how to split it up. E.g. either 
keep everything in the curr_ctx removal commit (and just use 1 for 
max_parallel_jobs) or use list_first_head to check if we have a curr_ctx 
and drop it afterwards for the counting logic.


Sincerely
     Sven



  reply	other threads:[~2026-07-15  9:44 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-05 22:06 [PATCH 00/17] media: rockchip: rga: Add multi-core support Sven Püschel
2026-06-05 22:06 ` [PATCH 01/17] media: rockchip: rga: zero cmdbuf in shared code Sven Püschel
2026-06-05 22:06 ` [PATCH 02/17] media: rockchip: rga: add comment about pixel alignment for YUV formats Sven Püschel
2026-06-05 22:06 ` [PATCH 03/17] media: rockchip: rga: move early return into if condition in vidioc_enum_fmt Sven Püschel
2026-06-05 22:06 ` [PATCH 04/17] media: rockchip: rga: removed unused regmap member Sven Püschel
2026-06-05 22:06 ` [PATCH 05/17] media: v4l2-mem2mem: support running multiple jobs in parallel Sven Püschel
2026-07-10 21:18   ` Nicolas Dufresne
2026-07-15  9:44     ` Sven Püschel [this message]
2026-08-10 15:44       ` Detlev Casanova
2026-08-18  9:09       ` Hans Verkuil
2026-08-10 15:39   ` Detlev Casanova
2026-06-05 22:06 ` [PATCH 06/17] media: rockchip: rga: move power handling to device_run Sven Püschel
2026-06-05 22:06 ` [PATCH 07/17] media: rockchip: rga: adjust get_version to return the version Sven Püschel
2026-06-05 22:06 ` [PATCH 08/17] media: rockchip: rga: add rga_core structure Sven Püschel
2026-06-05 22:06 ` [PATCH 09/17] media: rockchip: rga: use components to manage multiple cores Sven Püschel
2026-06-05 22:06 ` [PATCH 10/17] media: rockchip: rga: move rockchip_rga allocation to master probe Sven Püschel
2026-06-05 22:06 ` [PATCH 11/17] media: rockchip: rga: move video device to the master Sven Püschel
2026-06-05 22:06 ` [PATCH 12/17] media: rockchip: rga: move core initialization from bind to probe Sven Püschel
2026-06-05 22:06 ` [PATCH 13/17] media: rockchip: rga: bind all cores to the master Sven Püschel
2026-07-10 21:06   ` Nicolas Dufresne
2026-06-05 22:07 ` [PATCH 14/17] media: rockchip: rga: put all cores into first core iommu domain Sven Püschel
2026-06-05 22:07 ` [PATCH 15/17] media: rockchip: rga: schedule jobs to multiple cores Sven Püschel
2026-06-05 22:07 ` [PATCH 16/17] arm64: dts: rockchip: add rga3 dt nodes to rk3588 Sven Püschel
2026-06-05 22:07 ` [PATCH 17/17] iommu/rockchip: disable fetch dte time limit Sven Püschel

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=e89fd487-ea3f-42fd-8647-6fa74ac991e8@pengutronix.de \
    --to=s.pueschel@pengutronix.de \
    --cc=detlev.casanova@collabora.com \
    --cc=ezequiel@vanguardiasur.com.ar \
    --cc=heiko@sntech.de \
    --cc=jacob-chen@iotwrt.com \
    --cc=kernel@pengutronix.de \
    --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=nicolas@ndufresne.ca \
    --cc=p.zabel@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