Skip to contentSkip to conversation

media: nxp: imx8-isi: Fix single frame capture and optimize buffer usage

PATCH Superseded Guoniu Zhou 2 participants 6 messages Mar 12 – Mar 20

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover media: nxp: imx8-isi: Fix single frame capture and optimize buffer usage

This series fixes a hang issue when capturing single frames and improves buffer utilization by prioritizing user buffers over discard buffers.

Patch 1 reduces min_queued_buffers to allow streaming with a single buffer, fixing hangs in applications like libcamera's cam tool.

Patch 2 changes the buffer selection logic to use pending user buffers first, minimizing unnecessary frame drops at stream start.

---
Changes in v2:
- Add fix tag
- Replace "This ensures" with "ensure"
- Reduce min_queued_buffers from 2 to 0 suggested by Jacopo Mondi
- Put example from commit message to comment in driver suggested by Frank
- Detailed changes can be found in each patch's changelog
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Guoniu Zhou (2):
media: nxp: imx8-isi: Reduce minimum queued buffers from 2 to 0
media: nxp: imx8-isi: Prioritize pending buffers over discard buffers

 drivers/media/platform/nxp/imx8-isi/imx8-isi-video.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

---
base-commit: 6de23f81a5e08be8fbf5e8d7e9febc72a5b5f27f
change-id: 20260310-isi_min_buffers-4b490a124223

Best regards,

Signature · 1 line
Guoniu Zhou <[email protected]>
#1 lore raw

PATCH v2 1/2 media: nxp: imx8-isi: Reduce minimum queued buffers from 2 to 0

From: Guoniu Zhou <[email protected]>

Fix a hang issue when capturing a single frame with applications like cam in libcamera. It would hang waiting for the driver to complete the buffer, but streaming never starts because min_queued_buffers was set to 2.

The ISI module uses a ping-pong buffer mechanism that requires two buffers to be programmed at all times. However, when fewer than 2 user buffers are available, the driver use internal discard buffers to fill the remaining slot(s). Reduce minimum queued buffers from 2 to 0 allows streaming to start without any queued buffers.

Fixes cf21f328fcaf ("media: nxp: Add i.MX8 ISI driver")

---
Changes in v2:
- Reduce min_queued_buffers from 2 to 0 suggested by Jacopo Mondi
https://lore.kernel.org/linux-media/[email protected]/T/#mcd4b7dcc218a02e2f218ba2c83b947ccefd9308b
- Add fix tag

---
 drivers/media/platform/nxp/imx8-isi/imx8-isi-video.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/nxp/imx8-isi/imx8-isi-video.c +1 -1
index 13682bf6e9f8895bb9eb1f92d5f74b0d5968544e..1be3a728f32f89338a75ddcc4e96e7501ed954e1 100644
@@ -1410,7 +1410,7 @@ int mxc_isi_video_register(struct mxc_isi_pipe *pipe,
 	q->mem_ops = &vb2_dma_contig_memops;
 	q->buf_struct_size = sizeof(struct mxc_isi_buffer);
 	q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
-	q->min_queued_buffers = 2;
+	q->min_queued_buffers = 0;
 	q->lock = &video->lock;
 	q->dev = pipe->isi->dev;
 
Signature · 1 line
2.34.1
maintainer Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] media: nxp: imx8-isi: Reduce minimum queued buffers from 2 to 0

Hi Guoniu,

Thank you for the patch.

Quoted 29 lines · Guoniu Zhou

From: Guoniu Zhou <[email protected]>

Fix a hang issue when capturing a single frame with applications like cam in libcamera. It would hang waiting for the driver to complete the buffer, but streaming never starts because min_queued_buffers was set to 2.

The ISI module uses a ping-pong buffer mechanism that requires two buffers to be programmed at all times. However, when fewer than 2 user buffers are available, the driver use internal discard buffers to fill the remaining slot(s). Reduce minimum queued buffers from 2 to 0 allows streaming to start without any queued buffers.

Fixes cf21f328fcaf ("media: nxp: Add i.MX8 ISI driver")

---
Changes in v2:
- Reduce min_queued_buffers from 2 to 0 suggested by Jacopo Mondi
https://lore.kernel.org/linux-media/[email protected]/T/#mcd4b7dcc218a02e2f218ba2c83b947ccefd9308b
- Add fix tag

---
 drivers/media/platform/nxp/imx8-isi/imx8-isi-video.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/nxp/imx8-isi/imx8-isi-video.c +0 -0
index 13682bf6e9f8895bb9eb1f92d5f74b0d5968544e..1be3a728f32f89338a75ddcc4e96e7501ed954e1 100644

drivers/media/platform/nxp/imx8-isi/imx8-isi-video.c int mxc_isi_video_register(struct mxc_isi_pipe *pipe, · line 1413

Quoted 5 lines
drivers/media/platform/nxp/imx8-isi/imx8-isi-video.c +1 -1
@@ -1410,7 +1410,7 @@ int mxc_isi_video_register(struct mxc_isi_pipe *pipe,
 	q->mem_ops = &vb2_dma_contig_memops;
 	q->buf_struct_size = sizeof(struct mxc_isi_buffer);
 	q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
-	q->min_queued_buffers = 2;
+	q->min_queued_buffers = 0;

A simple way to fix the issue, that's nice.

Quoted 4 lines
drivers/media/platform/nxp/imx8-isi/imx8-isi-video.c +0 -0
 	q->lock = &video->lock;
 	q->dev = pipe->isi->dev;
 
Signature · 3 lines
Regards,

Laurent Pinchart
#3 lore raw

PATCH v2 2/2 media: nxp: imx8-isi: Prioritize pending buffers over discard buffers

In reply to Guoniu Zhou

From: Guoniu Zhou <[email protected]>

Change the buffer selection logic to use pending buffers first (up to the number available), and only use discard buffers to fill remaining slots when insufficient pending buffers are queued. Ensure user buffers are utilized as soon as possible, improving efficiency and reducing the number of discarded frames at stream start.

---
Changes in v2:
- Replace "This ensures" with "ensure"
- Put example from commit message to comment in driver suggested by Frank
https://lore.kernel.org/linux-media/[email protected]/T/#m2774912ed31553ef1fdcc840bd6eae53a03ecccd

---
 drivers/media/platform/nxp/imx8-isi/imx8-isi-video.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/media/platform/nxp/imx8-isi/imx8-isi-video.c +8 -1
index 1be3a728f32f89338a75ddcc4e96e7501ed954e1..77ebff03323ace50ff039c8333d25a9c3dd44880 100644
@@ -792,7 +792,14 @@ static void mxc_isi_video_queue_first_buffers(struct mxc_isi_video *video)
 		struct mxc_isi_buffer *buf;
 		struct list_head *list;
 
-		list = i < discard ? &video->out_discard : &video->out_pending;
+		/*
+		 * Queue buffers: prioritize pending buffers, then discard buffers
+		 * For example:
+		 * - 2 pending buffers: both slots use pending buffers
+		 * - 1 pending buffer: first slot uses pending, second uses discard
+		 * - 0 pending buffers: both slots use discard buffers
+		 */
+		list = (i < 2 - discard) ? &video->out_pending : &video->out_discard;
 		buf = list_first_entry(list, struct mxc_isi_buffer, list);
 
 		mxc_isi_channel_set_outbuf(video->pipe, buf->dma_addrs, buf_id);
Signature · 1 line
2.34.1
maintainer
#4 lore raw

Re: [PATCH v2 2/2] media: nxp: imx8-isi: Prioritize pending buffers over discard buffers

Hi Guoniu,

Thank you for the patch.

Quoted 7 lines · Guoniu Zhou

From: Guoniu Zhou <[email protected]>

Change the buffer selection logic to use pending buffers first (up to the number available), and only use discard buffers to fill remaining slots when insufficient pending buffers are queued. Ensure user buffers are utilized as soon as possible, improving efficiency and reducing the number of discarded frames at stream start.

The commit message should explain *why* the change is good. How does this improve the behaviour ?

I'll queue 1/2 in my tree already.

Quoted 31 lines

---
Changes in v2:
- Replace "This ensures" with "ensure"
- Put example from commit message to comment in driver suggested by Frank
https://lore.kernel.org/linux-media/[email protected]/T/#m2774912ed31553ef1fdcc840bd6eae53a03ecccd

---
 drivers/media/platform/nxp/imx8-isi/imx8-isi-video.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/media/platform/nxp/imx8-isi/imx8-isi-video.c +8 -1
index 1be3a728f32f89338a75ddcc4e96e7501ed954e1..77ebff03323ace50ff039c8333d25a9c3dd44880 100644
@@ -792,7 +792,14 @@ static void mxc_isi_video_queue_first_buffers(struct mxc_isi_video *video)
 		struct mxc_isi_buffer *buf;
 		struct list_head *list;
 
-		list = i < discard ? &video->out_discard : &video->out_pending;
+		/*
+		 * Queue buffers: prioritize pending buffers, then discard buffers
+		 * For example:
+		 * - 2 pending buffers: both slots use pending buffers
+		 * - 1 pending buffer: first slot uses pending, second uses discard
+		 * - 0 pending buffers: both slots use discard buffers
+		 */
+		list = (i < 2 - discard) ? &video->out_pending : &video->out_discard;
 		buf = list_first_entry(list, struct mxc_isi_buffer, list);
 
 		mxc_isi_channel_set_outbuf(video->pipe, buf->dma_addrs, buf_id);
Signature · 3 lines
Regards,

Laurent Pinchart
#5 lore raw

RE: [PATCH v2 2/2] media: nxp: imx8-isi: Prioritize pending buffers over discard buffers

Hi Laurent,

Thanks for your review.

Quoted 23 lines

-----Original Message-----
From: Laurent Pinchart <[email protected]>
Sent: Friday, March 20, 2026 5:59 AM
To: G.N. Zhou (OSS) <[email protected]>
Cc: Mauro Carvalho Chehab <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Stefan Riedmüller <[email protected]>; Jacopo Mondi <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; [email protected]; Alexi Birlinger <[email protected]>; Aisheng Dong <[email protected]>; G.N. Zhou <[email protected]>
Subject: Re: [PATCH v2 2/2] media: nxp: imx8-isi: Prioritize pending buffers over discard buffers

Hi Guoniu,

Thank you for the patch.

Quoted 2 lines · Guoniu Zhou

From: Guoniu Zhou <[email protected]>

Quoted 8 lines
Quoted 5 lines

Change the buffer selection logic to use pending buffers first (up to the number available), and only use discard buffers to fill remaining slots when insufficient pending buffers are queued. Ensure user buffers are utilized as soon as possible, improving efficiency and reducing the number of discarded frames at stream start.

The commit message should explain *why* the change is good. How does this improve the behaviour ?

Will add the info in next version.

Quoted 51 lines

I'll queue 1/2 in my tree already.

Quoted 14 lines

---
Changes in v2:
- Replace "This ensures" with "ensure"
- Put example from commit message to comment in driver suggested by Frank

https://lore.kernel.org/linux-media/20260311-isi_min_buffers-v1-0-c929
[email protected]/T/#m2774912ed31553ef1fdcc840bd6eae53a03ecccd

---
 drivers/media/platform/nxp/imx8-isi/imx8-isi-video.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/media/platform/nxp/imx8-isi/imx8-isi-video.c +0 -0
Quoted 2 lines

index

1be3a728f32f89338a75ddcc4e96e7501ed954e1..77ebff03323ace50ff039c833 3d2

drivers/media/platform/nxp/imx8-isi/imx8-isi-video.c static void

Quoted 4 lines

5a9c3dd44880 100644

drivers/media/platform/nxp/imx8-isi/imx8-isi-video.c +0 -0
@@ -792,7 +792,14 @@ static void

mxc_isi_video_queue_first_buffers(struct mxc_isi_video *video)

drivers/media/platform/nxp/imx8-isi/imx8-isi-video.c static void mxc_isi_video_queue_first_buffers(struct mxc_isi_video *video)

Quoted 6 lines
drivers/media/platform/nxp/imx8-isi/imx8-isi-video.c +2 -1
 		struct mxc_isi_buffer *buf;
 		struct list_head *list;
 
-		list = i < discard ? &video->out_discard : &video->out_pending;
+		/*
+		 * Queue buffers: prioritize pending buffers, then discard

buffers

drivers/media/platform/nxp/imx8-isi/imx8-isi-video.c static void mxc_isi_video_queue_first_buffers(struct mxc_isi_video *video)

Quoted 3 lines
drivers/media/platform/nxp/imx8-isi/imx8-isi-video.c +3 -0
+		 * For example:
+		 * - 2 pending buffers: both slots use pending buffers
+		 * - 1 pending buffer: first slot uses pending, second uses

discard

drivers/media/platform/nxp/imx8-isi/imx8-isi-video.c static void mxc_isi_video_queue_first_buffers(struct mxc_isi_video *video)

Quoted 7 lines
drivers/media/platform/nxp/imx8-isi/imx8-isi-video.c +4 -0
+		 * - 0 pending buffers: both slots use discard buffers
+		 */
+		list = (i < 2 - discard) ? &video->out_pending :
+&video->out_discard;
 		buf = list_first_entry(list, struct mxc_isi_buffer, list);
 
 		mxc_isi_channel_set_outbuf(video->pipe, buf->dma_addrs,

buf_id);

Quoted 1 line

--
Regards,

Laurent Pinchart