[v2] pipeline: rpi: pisp: Check the oldest CFE job in tryRunPipeline()
diff mbox series

Message ID 20261130154713.55915-1-naush@raspberrypi.com
State New
Headers show
Series
  • [v2] pipeline: rpi: pisp: Check the oldest CFE job in tryRunPipeline()
Related show

Commit Message

Naushir Patuck Nov. 30, 2026, 3:47 p.m. UTC
From: solomai <solomaj@gmail.com>

tryRunPipeline() runs the oldest job in cfeJobQueue_, but checks the
newest one with cfeJobComplete(). If a CFE config buffer is dequeued
after its image and stats buffers, a new empty job is pushed to the back
of the queue.  In turn, the now ready job is left waiting instead of
being sent to the IPA and Backend until the next frame. Once every CFE
image buffer is held by a waiting job, the CFE stalls and the camera
stops silently.

Fix this by passing the job to test into cfeJobComplete() so that
tryRunPipeline() checks the oldest job and cfeBufferDequeue() the newest.

Link: https://github.com/raspberrypi/libcamera/issues/369
Signed-off-by: Andrii Solomai <solomaj@gmail.com>
Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
---
 src/libcamera/pipeline/rpi/pisp/pisp.cpp | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

Comments

David Plowman Nov. 30, 2026, 4:04 p.m. UTC | #1
Hi Naush

Thanks for the update!

On Mon, 30 Nov 2026 at 15:47, Naushir Patuck <naush@raspberrypi.com> wrote:
>
> From: solomai <solomaj@gmail.com>
>
> tryRunPipeline() runs the oldest job in cfeJobQueue_, but checks the
> newest one with cfeJobComplete(). If a CFE config buffer is dequeued
> after its image and stats buffers, a new empty job is pushed to the back
> of the queue.  In turn, the now ready job is left waiting instead of
> being sent to the IPA and Backend until the next frame. Once every CFE
> image buffer is held by a waiting job, the CFE stalls and the camera
> stops silently.
>
> Fix this by passing the job to test into cfeJobComplete() so that
> tryRunPipeline() checks the oldest job and cfeBufferDequeue() the newest.
>
> Link: https://github.com/raspberrypi/libcamera/issues/369
> Signed-off-by: Andrii Solomai <solomaj@gmail.com>
> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>

Yes, that reads a bit more clearly to me.

Reviewed-by: David Plowman <david.plowman@raspberrypi.com>

Thanks!

David

> ---
>  src/libcamera/pipeline/rpi/pisp/pisp.cpp | 20 ++++++++++++--------
>  1 file changed, 12 insertions(+), 8 deletions(-)
>
> diff --git a/src/libcamera/pipeline/rpi/pisp/pisp.cpp b/src/libcamera/pipeline/rpi/pisp/pisp.cpp
> index 159c6b05ee7b..ee61992d3f8c 100644
> --- a/src/libcamera/pipeline/rpi/pisp/pisp.cpp
> +++ b/src/libcamera/pipeline/rpi/pisp/pisp.cpp
> @@ -834,12 +834,8 @@ private:
>
>         std::queue<CfeJob> cfeJobQueue_;
>
> -       bool cfeJobComplete() const
> +       bool cfeJobComplete(const CfeJob &job) const
>         {
> -               if (cfeJobQueue_.empty())
> -                       return false;
> -
> -               const CfeJob &job = cfeJobQueue_.back();
>                 return job.buffers.count(&cfe_[Cfe::Output0]) &&
>                        job.buffers.count(&cfe_[Cfe::Stats]) &&
>                        (!sensorMetadata_ ||
> @@ -1733,7 +1729,7 @@ void PiSPCameraData::cfeBufferDequeue(FrameBuffer *buffer)
>         }
>
>         /* If the last CFE job has completed, we need a new job entry in the queue. */
> -       if (cfeJobQueue_.empty() || cfeJobComplete())
> +       if (cfeJobQueue_.empty() || cfeJobComplete(cfeJobQueue_.back()))
>                 cfeJobQueue_.push({});
>
>         CfeJob &job = cfeJobQueue_.back();
> @@ -2337,8 +2333,16 @@ void PiSPCameraData::prepareBe(uint32_t bufferId, bool stitchSwapBuffers)
>
>  void PiSPCameraData::tryRunPipeline()
>  {
> -       /* If any of our request or buffer queues are empty, we cannot proceed. */
> -       if (state_ != State::Idle || requestQueue_.empty() || !cfeJobComplete())
> +       /*
> +        * If any of our request or buffer queues are empty, we cannot proceed.
> +        *
> +        * The job that gets run is the oldest one in the queue. The newest job
> +        * may be incomplete (for example, holding only a config buffer that was
> +        * dequeued after the image and stats buffers of its frame) while older
> +        * jobs are ready to run.
> +        */
> +       if (state_ != State::Idle || requestQueue_.empty() ||
> +           cfeJobQueue_.empty() || !cfeJobComplete(cfeJobQueue_.front()))
>                 return;
>
>         CfeJob &job = cfeJobQueue_.front();
> --
> 2.53.0
>

Patch
diff mbox series

diff --git a/src/libcamera/pipeline/rpi/pisp/pisp.cpp b/src/libcamera/pipeline/rpi/pisp/pisp.cpp
index 159c6b05ee7b..ee61992d3f8c 100644
--- a/src/libcamera/pipeline/rpi/pisp/pisp.cpp
+++ b/src/libcamera/pipeline/rpi/pisp/pisp.cpp
@@ -834,12 +834,8 @@  private:
 
 	std::queue<CfeJob> cfeJobQueue_;
 
-	bool cfeJobComplete() const
+	bool cfeJobComplete(const CfeJob &job) const
 	{
-		if (cfeJobQueue_.empty())
-			return false;
-
-		const CfeJob &job = cfeJobQueue_.back();
 		return job.buffers.count(&cfe_[Cfe::Output0]) &&
 		       job.buffers.count(&cfe_[Cfe::Stats]) &&
 		       (!sensorMetadata_ ||
@@ -1733,7 +1729,7 @@  void PiSPCameraData::cfeBufferDequeue(FrameBuffer *buffer)
 	}
 
 	/* If the last CFE job has completed, we need a new job entry in the queue. */
-	if (cfeJobQueue_.empty() || cfeJobComplete())
+	if (cfeJobQueue_.empty() || cfeJobComplete(cfeJobQueue_.back()))
 		cfeJobQueue_.push({});
 
 	CfeJob &job = cfeJobQueue_.back();
@@ -2337,8 +2333,16 @@  void PiSPCameraData::prepareBe(uint32_t bufferId, bool stitchSwapBuffers)
 
 void PiSPCameraData::tryRunPipeline()
 {
-	/* If any of our request or buffer queues are empty, we cannot proceed. */
-	if (state_ != State::Idle || requestQueue_.empty() || !cfeJobComplete())
+	/*
+	 * If any of our request or buffer queues are empty, we cannot proceed.
+	 *
+	 * The job that gets run is the oldest one in the queue. The newest job
+	 * may be incomplete (for example, holding only a config buffer that was
+	 * dequeued after the image and stats buffers of its frame) while older
+	 * jobs are ready to run.
+	 */
+	if (state_ != State::Idle || requestQueue_.empty() ||
+	    cfeJobQueue_.empty() || !cfeJobComplete(cfeJobQueue_.front()))
 		return;
 
 	CfeJob &job = cfeJobQueue_.front();