Skip to content

drm/vc4: Fix out of order frames during asynchronous page flips - #4571

Merged
pelwell merged 1 commit into
raspberrypi:rpi-5.10.yfrom
mripard:rpi/5.10-out-of-order-frames
Sep 28, 2021
Merged

pelwell merged 1 commit into
raspberrypi:rpi-5.10.yfrom
mripard:rpi/5.10-out-of-order-frames

Conversation

@mripard

@mripard mripard commented Sep 8, 2021

Copy link
Copy Markdown
Contributor

When doing an asynchronous page flip (PAGE_FLIP ioctl with the
DRM_MODE_PAGE_FLIP_ASYNC flag set), the current code waits for the
possible GPU buffer being rendered through a call to
vc4_queue_seqno_cb().

On the BCM2835-37, the GPU driver is part of the vc4 driver and that
function is defined in vc4_gem.c to wait for the buffer to be rendered,
and once it's done, call a callback.

However, on the BCM2711 used on the RaspberryPi4, the GPU driver is
separate (v3d) and that function won't do anything. This was working
because we were going into a path, due to uninitialized variables, that
was always scheduling the callback.

However, we were never actually waiting for the buffer to be rendered
which was resulting in frames being displayed out of order.

The generic API to signal those kind of completion in the kernel are the
DMA fences, and fortunately the v3d drivers supports them and signal
when its job is done. That API also provides an equivalent function that
allows to have a callback being executed when the fence is signalled as
done.

Let's change our driver a bit to rely on the previous function for the
older SoCs, and on DMA fences for the BCM2711.

We should probably wait a bit for some more testing before merging this.

@popcornmix

Copy link
Copy Markdown
Collaborator

Not seeing any change issues with kodi on a Pi4 (which doesn't use asynchronous flips).
The non pi4 case looks like a no-op from the code, so should be safe.

I'm not sure I have a use case that triggers the original bug, so can't test for that.

When doing an asynchronous page flip (PAGE_FLIP ioctl with the
DRM_MODE_PAGE_FLIP_ASYNC flag set), the current code waits for the
possible GPU buffer being rendered through a call to
vc4_queue_seqno_cb().

On the BCM2835-37, the GPU driver is part of the vc4 driver and that
function is defined in vc4_gem.c to wait for the buffer to be rendered,
and once it's done, call a callback.

However, on the BCM2711 used on the RaspberryPi4, the GPU driver is
separate (v3d) and that function won't do anything. This was working
because we were going into a path, due to uninitialized variables, that
was always scheduling the callback.

However, we were never actually waiting for the buffer to be rendered
which was resulting in frames being displayed out of order.

The generic API to signal those kind of completion in the kernel are the
DMA fences, and fortunately the v3d drivers supports them and signal
when its job is done. That API also provides an equivalent function that
allows to have a callback being executed when the fence is signalled as
done.

Let's change our driver a bit to rely on the previous function for the
older SoCs, and on DMA fences for the BCM2711.

Signed-off-by: Maxime Ripard <maxime@cerno.tech>
@mripard
mripard force-pushed the rpi/5.10-out-of-order-frames branch from 3fa66e8 to bc78913 Compare September 27, 2021 12:03
@pelwell

pelwell commented Sep 28, 2021

Copy link
Copy Markdown
Contributor

What's the position with this PR? Is the force-push a change or just a rebase?

@mripard

mripard commented Sep 28, 2021

Copy link
Copy Markdown
Contributor Author

The first version had a regression that would get an asynchronous page flip stuck indefinitely if the buffer it switches to had a fence but was already signalled before we would wait for it. This new version fixed it in my setup but I'm still waiting for additional testing. This new version is thus both that fix and a rebase

@pelwell

pelwell commented Sep 28, 2021

Copy link
Copy Markdown
Contributor

Thanks - in the absence of any independent confirmation of a fix I'll accept confirmation of Kodi still working.

@mripard

mripard commented Sep 28, 2021

Copy link
Copy Markdown
Contributor Author

The original reporter just confirmed that the original issue is now fixed and the regression is no longer there. So if Kodi is happy as well, I think this can be merged

@popcornmix

Copy link
Copy Markdown
Collaborator

Kodi is still happy with updated version of this (although I don't believe it uses the async code path).

@mripard

mripard commented Sep 28, 2021

Copy link
Copy Markdown
Contributor Author

Indeed, it doesn't use the async code path

@pelwell
pelwell merged commit f694d1c into raspberrypi:rpi-5.10.y Sep 28, 2021
@pelwell

pelwell commented Sep 28, 2021

Copy link
Copy Markdown
Contributor

Thanks!

popcornmix added a commit to raspberrypi/firmware that referenced this pull request Oct 6, 2021
See: raspberrypi/linux#4571

kernel: rpi-5.10.y fixups
See: raspberrypi/linux#4608

kernel: Add IMX519 driver and device tree overlay
See: raspberrypi/linux#4548

kernel: dtoverlays: Add overlay for ST7735R (160x128) TinyDRM driver
See: raspberrypi/linux#4615
popcornmix added a commit to Hexxeh/rpi-firmware that referenced this pull request Oct 6, 2021
See: raspberrypi/linux#4571

kernel: rpi-5.10.y fixups
See: raspberrypi/linux#4608

kernel: Add IMX519 driver and device tree overlay
See: raspberrypi/linux#4548

kernel: dtoverlays: Add overlay for ST7735R (160x128) TinyDRM driver
See: raspberrypi/linux#4615
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.

3 participants