Skip to content

isp: wait 200 ms for AE to settle, not a full second - #334

Open
vrilutza wants to merge 2 commits into
patjak:masterfrom
vrilutza:ae-settle-200ms
Open

vrilutza wants to merge 2 commits into
patjak:masterfrom
vrilutza:ae-settle-200ms

Conversation

@vrilutza

@vrilutza vrilutza commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

The auto-exposure wait in fthd_start_channel() goes from mdelay(1000) to msleep(200). It is paid on every VIDIOC_STREAMON, not once per open.

Two commits, because they do different things. Measured on a MacBookPro14,1, mean of five repetitions each against a module built from clean master, min and max in brackets:

                     STREAMON              system CPU burned
master               1078 ms [1077-1081]      986 ms [978-991]
+ msleep             1097 ms [1091-1103]        1 ms [1-1]
+ msleep + 200 ms     288 ms [287-294]           1 ms [0-1]

The msleep shortens nothing — it stops burning a CPU for the second. The 200 ms is what shortens the wait. Taking the value change without the msleep would mean 200 ms of a busy-held CPU instead of 1000, which is an improvement of the wrong kind, so both are here.

Why 200. The value has been 1000 ms since 2015 and there is nothing in the history behind it. Sweeping it as a module parameter, four interleaved repetitions per value with the light held constant, each run compared against its own final brightness: from 100 ms up the first frame already has the brightness the stream settles on; at 50 ms and below it comes out black. Repeated with 60 s of idle before each run so the exposure could not start from the previous state — 100 ms still good, three times out of three. 200 ms is twice the smallest value that worked.

Worth pointing at: a full second is not even the better choice. It delivers a first frame 10% brighter than where the stream settles, where 100 ms lands on it.

What this does not cover. One camera, and the measurement is of luma only — if the wait was also protecting the white balance, this would not have seen it. The driver also still waits blind rather than polling the firmware's CISP_CMD_CH_AE_* state; if someone who knows the ISP wants to replace the wait with a poll, this patch should be thrown away in favour of that.


The series

One of nine open PRs on this driver; the others are #331, #338, #340, #342, #343, #344, #345 and #347. They apply independently, with two exceptions: #344 contains the first commit of #343, and #331 should go in together with #347.

Comment thread fthd_isp.c Outdated
Every channel start busy-waits for one second after the firmware starts
capture. This occupies a CPU while waiting for automatic exposure even
though this path can sleep.

Replace mdelay() with msleep(), keeping the one-second settling delay.
The wait no longer keeps a CPU busy; its duration is unchanged apart
from scheduler timing. Adjusting the settling time is a separate change.

Based-on: patjak#334
The fixed settling delay is paid on every STREAMON, including restarts
during format negotiation. A one-second wait therefore adds substantial
latency to opening or reconfiguring the camera.

Reduce the sleep to 200 ms. This removes 800 ms from the requested wait;
complete stream startup also includes firmware commands and scheduling.
The corrected series starts capture in about 290 ms on the tested
MacBookPro14,1.

The delay remains a fixed allowance rather than a firmware readiness
check. Settling on other sensors and white-balance convergence still
need validation; a successful stream start does not establish either.

Based-on: patjak#334
@vrilutza

Copy link
Copy Markdown
Contributor Author

Updated the branch onto master c5c7fac4e6da061ededd4c46545930ff7cdc0529 and revised the commit explanations. The resulting code change is identical to the previous revision.

The two logical changes remain separate: first replace mdelay(1000) with msleep(1000) to stop busy-waiting, then reduce the sleep to 200 ms to shorten startup. The source comment remains the short /* Needed to settle AE */ discussed in review.

The revised individual branch builds against Linux 7.1.13+deb14-amd64 with W=1, retaining the two existing compiler warnings. In the previously tested combined series, complete stream startup took approximately 289–299 ms on MacBookPro14,1; that includes firmware work as well as the sleep. No new exposure sweep was performed for this update. Settling on other sensors and white-balance convergence remain unverified, and the wait is still a fixed delay rather than a firmware readiness check.

Revision: 041d624fe2100ef1a57692f9736c082c58d96781.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants