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

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

Commit Message

Naushir Patuck Nov. 24, 2026, 10:54 a.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 opened, and a
complete job that could not run yet is left waiting for 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: 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(-)

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();