-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vc_dispmanx_update_submit_sync hangs forever after being called exactly 128 times on RPi 4 #1182
Comments
I am getting reports that vsync is also broken on previous models. See ali1234/raspi-teletext#22 Not sure if it is the same problem yet. |
Calling a vchiq function from a vchiq callback is a recipe for deadlock and not supported. |
This solves the problem for me. Does it look okay? |
Yes, that looks fine. |
Thanks! |
After testing the theaded code I have found the real problem: the behaviour of I need to be able to update the screen exactly once per frame in a way that is compatible with past and future firmwares. |
|
Yes, the difference is that In other words the old version would never call the vsync callback during a call to |
There was a firmware fix for late vsync callbacks on June 23. Looks like your firmware is just too old. Can you try updating? |
I'm on the latest apt-get firmware. I'll try rpi-update. |
rpi-update firmware has the same behaviour. I am able to reliably hit the frame deadlines by doing this: ali1234/raspi-teletext@d269857 I need to do some more testing to see if it is still dropping frames. |
Even this drops frames, even though I'm meeting every deadline and submitting the updates as soon as possible. I am sending alternating black and white frames so that frame drops are very easy to see. And I have added a callback parameter to the
And I see output like:
Note that every S is followed by an AB, meaning I'm meeting the deadline - Sending an update and then receiving two vsyncs before it actually completes is exactly the same problem as I had with I also tried removing the printfs incase that was causing blocking when redrawing the terminal, and I still see the same frame drops. |
I've made a stripped down version of my test code (warning, it strobes the display):
On a Pi 4 it outputs like this:
and visibly drops a frame every time this happens. On a Pi 3 it only outputs This was tested with the same SD card, which was apt updated and rpi-update updated yesterday. I have removed all the assert checking for clarity. It has no effect on the bug. |
I just read this on #1154 "Due to a quirk in the way the hardware was behaving, the loading of the display list into the live HVS registers moved from an interrupt approx 32 lines before the end of the frame, to the start of frame. This means that your dispmanx_update_submit_sync has almost certainly missed the slot for the current frame as you only get the vblank interval." So I added a |
In brief testing this seems to work okay on pi 3 as well. Note that drawing one frame late is acceptable for my use case. The only thing I need is to show every frame exactly once. |
Loading the HVS display list at the start of frame resulted in increased display latency and using dispmanx_update_submit_sync would only get half the display framerate. It's now being loaded off a timer approx 2ms (IIRC) before the vsync. It may be possible to pull it closer to the vsync, but that was the initial, slightly conservative, value that meant dispmanx_update_submit_sync would run at full speed again. |
I am currently using these firmwares: Pi 3: Pi 4: If the HVS is loaded 2ms before the vsync, then that means it is loaded 14.6ms after the previous vsync. My userspace thread calls I can only see two possible explanations for this:
What do you think? |
Today I connected a scope to the composite video out and asserted a gpio from the vsync callback. There are the results, using firmware that I updated today. First Pi 4: Here you can see that the vsync callback is called approximately 1ms before the real vsync. It is possible to submit an update in this time if you are very fast, but notice that the vsync occasionally arrives late, as much as 4ms late, which pushes it well in to the next frame and guarantees a frame drop. And Pi 3: Here the result is mostly the same: vsync callback arrives 1ms before the real vsync. But notice that although the vsync callback is sometimes late, it does not happen as often, and when it does it is only about 1ms late. This is still enough to cause a frame drop, but it happens less often, which is exactly what I've observed previously. So overall I would expect the vsync callback to be called immediately after the real vsync, to give the maximum possible time for userspace to submit update. But instead it seems to get called at the last possible time you can submit an update for the current frame, meaning it is nearly but not quite impossible to ever get a stable frame rate without intentionally delaying updates so that they always go to the next frame. This means if you use The Pi 3 firmware version I tested was:
Unfortunately I forgot to write down the Pi 4 version, but it came from the same rpi-update. |
Forgot to mention: The scope traces are from top to bottom: composite video, GPIO 5, 6, 13. The scope is set to trigger on the vsync of the odd field which is positioned in the middle of the scope. The horizontal scale shows about half of a field (12ms). And here is the source code of the program I used to generate the test:
|
Any updates to achieve RPi4 60Hz refresh rate exactly? |
On being called for the 128th time inside the vsync callback,
vc_dispmanx_update_submit_sync
never returns. It works fine up until this point. This seems to be 100% reproducible on RPi 4 and it always hangs after exactly 128 calls. I strongly suspect that some queue inside the firmware is being filled to capacity.Code: https://github.com/ali1234/raspi-teletext/blob/master/teletext.c#L66
This software has been widely deployed on earlier RPi hardware and works fine there.
Note that you don't need to use the tvctl utility (not yet ported) or have a CRT TV to reproduce this.
Running Raspbian Buster which i just upgraded. Firmware version:
The text was updated successfully, but these errors were encountered: