rpi/pisp: a camera stops delivering frames for good, with nothing logged, when a frame's CFE config buffer is dequeued last
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 18/100
- Issue 類型
- 缺陷
- 描述清晰度
- 基本清楚
- 活躍度
- 活躍
- 技術堆疊
- cpp, embedded-iot, linux
- 領域
- embedded-iot
研究方向
The fault is in the PiSP pipeline handler under src/libcamera/pipeline/rpi/pisp, where the readiness check tests the newest CFE job while the oldest job is the one run. Read the job queue and buffer dequeue code, then reproduce by checking the order of CFE node file descriptors and holding requests back. Done means a camera keeps delivering frames after several frames arrive with no request queued, with the test program showing no added latency.
由索引模型根據 Issue 內容生成。
描述
Summary
On a Raspberry Pi 5 one camera can stop delivering frames permanently. No error, no warning and no timeout is reported by libcamera, the camera stays in the Running state, queueRequest() keeps succeeding, and other cameras in the same process keep running normally. Only stopping and starting the camera brings the frames back.
The cause is in the PiSP pipeline handler. The check that decides whether a CFE job may be run looks at the newest job in the job queue, but the job that is then run is the oldest one. Whenever those two are not the same job, a frame that has everything it needs is left waiting, even though the Back End is idle and the application has a request queued.
Symptom
- No request of that camera ever completes again. Requests queued afterwards are accepted and simply sit there.
- Nothing is written to the libcamera log for that camera at any log level. In particular there is no dequeue timer expiry and no frontend timeout: the watchdog on the CFE image node only runs while buffers are queued on that node, and in this state none are.
- The sensor keeps streaming. The CFE interrupt count of that camera keeps rising the whole time.
- Stopping and starting the camera recovers it within a fraction of a second, but the process stays susceptible, because what makes it susceptible does not change while the camera manager lives.
- Shortly before the stall the latency of that camera typically grows in steps of exactly one frame period and never comes back down. There may be no warning at all, though: in one case the camera went from normal operation to stalled in under a third of a second.
What happens
Every frame produces three CFE buffers: image, stats and config. The handler groups the buffers it dequeues into jobs, and a job counts as complete once it holds the image and the stats buffer. The config buffer is not part of that test, but it is still stored in the newest job.
So if the config buffer of a frame is dequeued after that frame's image and stats buffers, it finds the newest job already complete and opens a fresh job that contains nothing but itself. Between frames the newest job is therefore always incomplete and the readiness check is false. The only moment at which anything can be started is the instant between the dequeue of a frame's image and stats buffers and the dequeue of its config buffer, which comes around once per frame.
If the pipeline cannot start at that one moment, the ready job stays in the queue. A request queued by the application a few milliseconds later does not start it, and neither does the end of the previous Back End run: both find the newest job incomplete and return. The waiting job is started only by the arrival of the next frame, which then has to wait for the frame after it, and so on. The camera now runs one frame late and never catches up, and every further occurrence adds one more frame of permanent latency.
Each waiting job holds one of the CFE image buffers, of which there are four by default. After the fourth occurrence all four are parked in the job queue. The CFE then has nothing to capture into, so no image or stats buffer is ever dequeued again, so the newest job can never become complete, so nothing can ever be started again. That is the stall, and it is final until the camera is stopped.
With the config buffer dequeued second, or first, the newest job is complete between frames, so a late request or the end of the previous Back End run starts the oldest job straight away and any backlog drains. That is why this is normally invisible.
Conditions
Two things have to come together.
The config node must have the highest file descriptor number among that camera's CFE nodes. The three buffers of a frame become ready at essentially the same time, and the poll dispatcher services ready descriptors in ascending numerical order, so within a frame the buffers are dequeued in the order of the descriptor numbers of the three nodes. The nodes are opened in the order image, config, stats, so a process that gets three consecutive numbers has the config node in the middle and is unaffected. The config node ends up last when another thread of the same process closes a lower-numbered descriptor between the opening of the config node and the opening of the stats node. In a multi-threaded application that starts other I/O while the camera manager starts, this was the case for a given camera in 11 of 50 process starts, and once it happens it holds for the lifetime of the camera manager. For a sensor that also delivers embedded data the rule is the same, with the config node last of four.
The pipeline has to miss that one chance to start, four times. A miss happens when, at the moment a frame arrives, the application has no request queued, or the Back End is still busy with the previous frame. The four misses need not be related: they can accumulate over many minutes, or happen all at once, since a single gap in which four consecutive frames arrive with nothing queued is enough. At 30 fps that gap is only 100 to 133 ms. An application that is occasionally slow to hand requests back, or one running the Back End with an output large enough that a run takes longer than a frame period, produces such misses on its own.
An application that always has a request queued in time shows nothing even with the config node last, which is presumably why this has gone unnoticed. Conversely, with any other descriptor order the very same gap on the application side costs only a few delayed frames, and the pipeline catches up by itself.
Environment
Raspberry Pi 5 Model B Rev 1.1, Debian 13 (trixie), kernel 6.18.50+rpt-rpi-2712, two IMX219 modules. Reproduced with the stock libcamera 0.7.2+rpt20261009-1 packages and with main built from source. The relevant code is identical in next and upstream, and has not changed since the PiSP handler was first added. The rpi/vc4 handler is not affected, as there the queue that is tested is the queue the frame is taken from.
What was observed
With a small test program that uses nothing but libcamera, arranges for the config node to get the highest descriptor and then holds back all four requests for a given time, the behaviour is reproducible every time and scales exactly as described above: holding the requests back long enough for one, two or three frames to arrive with nothing queued adds one, two or three frame periods of latency permanently, and four frames stall the camera for good. The same program with the usual descriptor order, and the same program with the fix below, show no change in any of those cases. Keeping the Back End busy instead of holding requests back costs the affected camera about 40 % of its frame rate and some 20 ms of latency, again with no change for the other descriptor orders.
It was first found in a multi-threaded application. Three sessions in which one camera had the config node last ended with that camera stalled after 14, 18 and 22 minutes, each time in exactly the state described above: all four image buffers dequeued, the Back End idle, and requests queued later never starting anything. Sessions in which the same camera had the config node last but was never short of requests ran to the end, as did every session with any other descriptor order.
- 主要語言
- C++
- 星號
- 493
- 分支
- 205
- PR 合併指標
- 30 天內沒有已合併 PR
環境準備
這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
raspberrypi/libcamera 的其他 Issue
-
難度 3/5 半天 新手友好度 35/100
raspberrypi/libcamera#368 · 9 則留言 ·
-
難度 4/5 3-5 天 新手友好度 42/100
raspberrypi/libcamera#367 · 1 則留言 ·
-
難度 3/5 1-2 天 新手友好度 55/100
raspberrypi/libcamera#362 · 2 則留言 ·
查看 raspberrypi/libcamera 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 85/100
Niko1221/Strata#7211 · 3 則留言 ·
維護者通常 5 天內回覆
-
難度 2/5 1-3 小時 新手友好度 66/100
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 76/100
維護者通常 1 天內回覆
-
enhancement P5 XS
難度 1/5 1-3 小時 新手友好度 88/100
open-astro/AlpacaBridge#2683 ·
維護者通常 1 天內回覆
-
Linux Copr构建失败未關閉
難度 2/5 1-3 小時 新手友好度 69/100
metasequoiaime/msime#11908 ·
維護者通常 1 天內回覆