drm: Fix fb changes for async updates
Subsystems (10)
v3 cover drm: Fix fb changes for async updates
Hello,
This series fixes the slow down in performance introduced by "[PATCH v2] drm: Block fb changes for async plane updates" where async update falls back to a sync update, causing igt failures of type:
"CRITICAL: completed 97 cursor updated in a period of 30 flips, we expect to complete approximately 15360 updates, with the threshold set at 7680"
Please read the commit message of "drm: don't block fb changes for async plane updates" to understand how it works.
I tested on the rockchip, on i915 and on vc4 with igt plane_cursor_legacy and kms_cursor_legacy and I didn't see any regressions.
I couldn't test on MSM and AMD because I don't have the hardware I would appreciate if anyone could help me testing those.
v1 link: https://patchwork.kernel.org/cover/10837847/
Thanks!
Helen
Changes in v3:
- use swap() to swap old and new framebuffers in async_update
- get the reference to old_fb and set the worker after vop_plane_atomic_update()
- add a FIXME tag for when we have multiple fbs to be released when vblank happens.
- update commit message
- Add Reviewed-by tags
- Add TODO in drm_atomic_helper_async_commit()
Changes in v2:
- added reviewed-by tag
- update CC stable and Fixes tag
- Added reviewed-by tag
- updated CC stable and Fixes tag
- Change the order of the patch in the series, add this as the last one.
- Add documentation
- s/ballanced/balanced
Helen Koike (5):
drm/rockchip: fix fb references in async update drm/amd: fix fb references in async update drm/msm: fix fb references in async update drm/vc4: fix fb references in async update
drm: don't block fb changes for async plane updates
.../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 3 +- drivers/gpu/drm/drm_atomic_helper.c | 22 ++++---- drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c | 4 ++ drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 51 ++++++++++--------- drivers/gpu/drm/vc4/vc4_plane.c | 2 +- include/drm/drm_modeset_helper_vtables.h | 5 ++ 6 files changed, 49 insertions(+), 38 deletions(-)
Signature · 6 lines
2.20.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH v3 1/5 drm/rockchip: fix fb references in async update
In the case of async update, modifications are done in place, i.e. in the current plane state, so the new_state is prepared and the new_state is cleaned up (instead of the old_state, unlike what happens in a normal sync update).
To cleanup the old_fb properly, it needs to be placed in the new_state in the end of async_update, so cleanup call will unreference the old_fb correctly.
Also, the previous code had a:
plane_state = plane->funcs->atomic_duplicate_state(plane);
...
swap(plane_state, plane->state);
if (plane->state->fb && plane->state->fb != new_state->fb) {
...
}Which was wrong, as the fb were just assigned to be equal, so this if statement nevers evaluates to true.
Another details is that the function drm_crtc_vblank_get() can only be called when vop->is_enabled is true, otherwise it has no effect and trows a WARN_ON().
Calling drm_atomic_set_fb_for_plane() (which get a referent of the new fb and pus the old fb) is not required, as it is taken care by drm_mode_cursor_universal() when calling drm_atomic_helper_update_plane().
---
Hello,
I tested on the rockchip ficus v1.1 using igt plane_cursor_legacy and kms_cursor_legacy and I didn't see any regressions.
Changes in v3:
- use swap() to swap old and new framebuffers in async_update
- get the reference to old_fb and set the worker after vop_plane_atomic_update()
- add a FIXME tag for when we have multiple fbs to be released when vblank happens.
- update commit message
Changes in v2: None
drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 51 +++++++++++---------- 1 file changed, 26 insertions(+), 25 deletions(-)
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +26 -25
@@ -912,29 +912,17 @@ static void vop_plane_atomic_async_update(struct drm_plane *plane, struct drm_plane_state *new_state) {struct vop *vop =to_vop (plane->state->crtc); -struct drm_plane_state *plane_state; - - plane_state = plane->funcs->atomic_duplicate_state (plane); - plane_state->crtc_x = new_state->crtc_x; - plane_state->crtc_y = new_state->crtc_y; - plane_state->crtc_h = new_state->crtc_h; - plane_state->crtc_w = new_state->crtc_w; - plane_state->src_x = new_state->src_x; - plane_state->src_y = new_state->src_y; - plane_state->src_h = new_state->src_h; - plane_state->src_w = new_state->src_w; - -if (plane_state->fb != new_state->fb) -drm_atomic_set_fb_for_plane (plane_state, new_state->fb); - -swap (plane_state, plane->state); - -if (plane->state->fb && plane->state->fb != new_state->fb) { -drm_framebuffer_get (plane->state->fb); -WARN_ON (drm_crtc_vblank_get (plane->state->crtc) !=0 ); -drm_flip_work_queue (&vop->fb_unref_work, plane->state->fb); -set_bit (VOP_PENDING_FB_UNREF , &vop->pending); - } +struct drm_framebuffer *old_fb = plane->state->fb; + + plane->state->crtc_x = new_state->crtc_x; + plane->state->crtc_y = new_state->crtc_y; + plane->state->crtc_h = new_state->crtc_h; + plane->state->crtc_w = new_state->crtc_w; + plane->state->src_x = new_state->src_x; + plane->state->src_y = new_state->src_y; + plane->state->src_h = new_state->src_h; + plane->state->src_w = new_state->src_w; +swap (plane->state->fb, new_state->fb);if (vop->is_enabled) {rockchip_drm_psr_inhibit_get_state (new_state->state);
@@ -943,9 +931,22 @@ static void vop_plane_atomic_async_update(struct drm_plane *plane,vop_cfg_done (vop);spin_unlock (&vop->reg_lock);rockchip_drm_psr_inhibit_put_state (new_state->state); - } - plane->funcs->atomic_destroy_state (plane, plane_state); +/* +* A scanout can still be occurring, so we can't drop the +* reference to the old framebuffer. To solve this we get a +* reference to old_fb and set a worker to release it later. +* FIXME: if we perform 500 async_update calls before the +* vblank, then we can have 500 different framebuffers waiting +* to be released. +*/ +if (old_fb && plane->state->fb != old_fb) { +drm_framebuffer_get (old_fb); +WARN_ON (drm_crtc_vblank_get (plane->state->crtc) !=0 ); +drm_flip_work_queue (&vop->fb_unref_work, old_fb); +set_bit (VOP_PENDING_FB_UNREF , &vop->pending); + } + } }static const struct drm_plane_helper_funcs plane_helper_funcs = {
Signature · 6 lines
2.20.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v3 2/5 drm/amd: fix fb references in async update
In reply to Helen KoikeAsync update callbacks are expected to set the old_fb in the new_state so prepare/cleanup framebuffers are balanced.
Calling drm_atomic_set_fb_for_plane() (which gets a reference of the new fb and put the old fb) is not required, as it's taken care by drm_mode_cursor_universal() when calling drm_atomic_helper_update_plane().
---
Changes in v3: None
Changes in v2:
- added reviewed-by tag
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -2
@@ -3760,8 +3760,7 @@ static void dm_plane_atomic_async_update(struct drm_plane *plane,struct drm_plane_state *old_state =drm_atomic_get_old_plane_state (new_state->state, plane); -if (plane->state->fb != new_state->fb) -drm_atomic_set_fb_for_plane (plane->state, new_state->fb); +swap (plane->state->fb, new_state->fb); plane->state->src_x = new_state->src_x; plane->state->src_y = new_state->src_y;
Signature · 6 lines
2.20.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v3 3/5 drm/msm: fix fb references in async update
In reply to Helen KoikeAsync update callbacks are expected to set the old_fb in the new_state so prepare/cleanup framebuffers are balanced.
---
Hello,
As mentioned in the cover letter,
But I couldn't test on MSM because I don't have the hardware and I would appreciate if anyone could test it.
In other platforms (VC4, AMD, Rockchip), there is a hidden drm_framebuffer_get(new_fb)/drm_framebuffer_put(old_fb) in async_update that is wrong, but I couldn't identify those here, not sure if it is hidden somewhere else, but if tests fail this is probably the cause.
Thanks!
Helen
Changes in v3: None
Changes in v2:
- update CC stable and Fixes tag
drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c +4 -0
@@ -502,6 +502,8 @@ static int mdp5_plane_atomic_async_check(struct drm_plane *plane,static void mdp5_plane_atomic_async_update (struct drm_plane *plane,struct drm_plane_state *new_state) { +struct drm_framebuffer *old_fb = plane->state->fb; + plane->state->src_x = new_state->src_x; plane->state->src_y = new_state->src_y; plane->state->crtc_x = new_state->crtc_x;
@@ -524,6 +526,8 @@ static void mdp5_plane_atomic_async_update(struct drm_plane *plane, *to_mdp5_plane_state (plane->state) = *to_mdp5_plane_state (new_state); + + new_state->fb = old_fb; }static const struct drm_plane_helper_funcs mdp5_plane_helper_funcs = {
Signature · 1 line
2.20.1
Re: [PATCH v3 3/5] drm/msm: fix fb references in async update
Quoted 16 lines · Helen Koike
Async update callbacks are expected to set the
old_fbin thenew_stateso prepare/cleanup framebuffers are balanced.Cc <[email protected]> # v4.14+Fixes 224a4c970987 ("drm/msm: update cursors asynchronously through atomic")Suggested-by Boris Brezillon <[email protected]>Signed-off-by Helen Koike <[email protected]>---
Hello,As mentioned in the cover letter,
But I couldn't test on MSM because I don't have the hardware and I would appreciate if anyone could test it.
Quoted 7 lines
In other platforms (VC4, AMD, Rockchip), there is a hidden drm_framebuffer_get(new_fb)/drm_framebuffer_put(old_fb) in
async_updatethat is wrong, but I couldn't identify those here, not sure if it is hidden somewhere else, but if tests fail this is probably the cause.Thanks!
Helen
Apologies, I haven't had a chance to test this yet, and it is likely to be a few weeks before I have a chance..
That said, not refcnt'ing the fb seems suspicious. I read the
explanation in the other patches, but kind of think it is more clear to keep the extra refcnt'ing.. or at least have a comment.
I do a bit wonder if we hold the ref to the outgoing cursor long enough.. I think the hw will actually continue to scan it out until the next vblank. But Archit was the one who added async_update support so maybe that is handled somewhere else. It's been a while since I've looked at this.
BR,
-R
Quoted 33 lines
Changes in v3: None
Changes in v2:
- update CC stable and Fixes tagdrivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c +4
-1@@ -502,6 +502,8 @@ static int mdp5_plane_atomic_async_check(struct drm_plane *plane,static void mdp5_plane_atomic_async_update (struct drm_plane *plane,struct drm_plane_state *new_state) { +struct drm_framebuffer *old_fb = plane->state->fb; + plane->state->src_x = new_state->src_x; plane->state->src_y = new_state->src_y; plane->state->crtc_x = new_state->crtc_x;@@ -524,6 +526,8 @@ static void mdp5_plane_atomic_async_update(struct drm_plane *plane, *to_mdp5_plane_state (plane->state) = *to_mdp5_plane_state (new_state); + + new_state->fb = old_fb; }static const struct drm_plane_helper_funcs mdp5_plane_helper_funcs = { --2.20.1
Re: [PATCH v3 3/5] drm/msm: fix fb references in async update
Hi Rob,
Quoted 25 lines · Rob Clark
Quoted 16 lines · Helen Koike
Async update callbacks are expected to set the
old_fbin thenew_stateso prepare/cleanup framebuffers are balanced.Cc <[email protected]> # v4.14+Fixes 224a4c970987 ("drm/msm: update cursors asynchronously through atomic")Suggested-by Boris Brezillon <[email protected]>Signed-off-by Helen Koike <[email protected]>---
Hello,As mentioned in the cover letter,
But I couldn't test on MSM because I don't have the hardware and I would appreciate if anyone could test it.Quoted 7 lines
In other platforms (VC4, AMD, Rockchip), there is a hidden drm_framebuffer_get(new_fb)/drm_framebuffer_put(old_fb) in
async_updatethat is wrong, but I couldn't identify those here, not sure if it is hidden somewhere else, but if tests fail this is probably the cause.Thanks!
Helen
Quoted 6 lines
Apologies, I haven't had a chance to test this yet, and it is likely to be a few weeks before I have a chance..
That said, not refcnt'ing the fb seems suspicious. I read the
explanation in the other patches, but kind of think it is more clear to keep the extra refcnt'ing.. or at least have a comment.
Refcnt'ing is taken care by drm_mode_cursor_universal() when calling drm_atomic_helper_update_plane().
The other codes had a drm_atomic_set_fb_for_plane() (which get a referent of the new fb and put the old fb), but the problem is that the cleanup_plane will also put the ref of the old fb.
In the other drivers I saw, drm_atomic_set_fb_for_plane() shouldn't be called, but this issue should be triggered very easily with a test.
I can add this is in the async_check() docs.
Quoted 6 lines
I do a bit wonder if we hold the ref to the outgoing cursor long enough.. I think the hw will actually continue to scan it out until the next vblank. But Archit was the one who added
async_updatesupport so maybe that is handled somewhere else. It's been a while since I've looked at this.
I don't know much about MSM, but if I understand correctly, MSM don't support true async, is that correct?
Then I think we need to do something similar to the rockchip:
https://patchwork.kernel.org/patch/10852039/
and setup a drm_flip_work_queue().
But this seems another problem that is already there no? Not really related to this patch. I could send a separate patch for this (but I don't have the means to test it).
Regards,
Helen
Quoted 35 lines
BR,
-RQuoted 29 lines
Changes in v3: None
Changes in v2:
- update CC stable and Fixes tagdrivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c +4
-0@@ -502,6 +502,8 @@ static int mdp5_plane_atomic_async_check(struct drm_plane *plane,static void mdp5_plane_atomic_async_update (struct drm_plane *plane,struct drm_plane_state *new_state) { +struct drm_framebuffer *old_fb = plane->state->fb; + plane->state->src_x = new_state->src_x; plane->state->src_y = new_state->src_y; plane->state->crtc_x = new_state->crtc_x;@@ -524,6 +526,8 @@ static void mdp5_plane_atomic_async_update(struct drm_plane *plane, *to_mdp5_plane_state (plane->state) = *to_mdp5_plane_state (new_state); + + new_state->fb = old_fb; }
Quoted 5 lines
Quoted 4 lines
drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c +0
-1static const struct drm_plane_helper_funcs mdp5_plane_helper_funcs = { --2.20.1
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v3 3/5] drm/msm: fix fb references in async update
In reply to Helen KoikeHello,
Quoted 8 lines · Helen Koike
Async update callbacks are expected to set the
old_fbin thenew_stateso prepare/cleanup framebuffers are balanced.Cc <[email protected]> # v4.14+Fixes 224a4c970987 ("drm/msm: update cursors asynchronously through atomic")Suggested-by Boris Brezillon <[email protected]>Signed-off-by Helen Koike <[email protected]>
Quoted 6 lines
---
Hello,As mentioned in the cover letter,
But I couldn't test on MSM because I don't have the hardware and I would appreciate if anyone could test it.
I got this tested on a dragonboard 410c, no regressions where found and no extra warnings.
These two tests where already failing for other reasons:
flip-vs-cursor-crc-atomic flip-vs-cursor-crc-legacy
If you want to see the full log:
https://people.collabora.com/~koike/drm-fixes-results.zip
Thanks
Helen
Quoted 39 lines
In other platforms (VC4, AMD, Rockchip), there is a hidden drm_framebuffer_get(new_fb)/drm_framebuffer_put(old_fb) in
async_updatethat is wrong, but I couldn't identify those here, not sure if it is hidden somewhere else, but if tests fail this is probably the cause.Thanks!
HelenChanges in v3: None
Changes in v2:
- update CC stable and Fixes tagdrivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c +4
-0@@ -502,6 +502,8 @@ static int mdp5_plane_atomic_async_check(struct drm_plane *plane,static void mdp5_plane_atomic_async_update (struct drm_plane *plane,struct drm_plane_state *new_state) { +struct drm_framebuffer *old_fb = plane->state->fb; + plane->state->src_x = new_state->src_x; plane->state->src_y = new_state->src_y; plane->state->crtc_x = new_state->crtc_x;@@ -524,6 +526,8 @@ static void mdp5_plane_atomic_async_update(struct drm_plane *plane, *to_mdp5_plane_state (plane->state) = *to_mdp5_plane_state (new_state); + + new_state->fb = old_fb; }static const struct drm_plane_helper_funcs mdp5_plane_helper_funcs = {
Rob Clark
Acked-byRe: [PATCH v3 3/5] drm/msm: fix fb references in async update
Quoted 11 lines · Helen Koike
Hello,
Quoted 7 lines · Helen Koike
Async update callbacks are expected to set the
old_fbin thenew_stateso prepare/cleanup framebuffers are balanced.Cc <[email protected]> # v4.14+Fixes 224a4c970987 ("drm/msm: update cursors asynchronously through atomic")Suggested-by Boris Brezillon <[email protected]>Signed-off-by Helen Koike <[email protected]>
Thanks, I'm not super happy about the refcnt'ing subtleness here (mostly because it makes it harder to page in how things work on kernel/display side after spending most of my time in userspace/mesa), but I don't want to hold this up..
Quoted 53 lines
Quoted 7 lines
---
Hello,As mentioned in the cover letter,
But I couldn't test on MSM because I don't have the hardware and I would appreciate if anyone could test it.I got this tested on a dragonboard 410c, no regressions where found and no extra warnings.
These two tests where already failing for other reasons:
flip-vs-cursor-crc-atomic flip-vs-cursor-crc-legacyIf you want to see the full log:
https://people.collabora.com/~koike/drm-fixes-results.zip
Thanks
HelenQuoted 31 lines
In other platforms (VC4, AMD, Rockchip), there is a hidden drm_framebuffer_get(new_fb)/drm_framebuffer_put(old_fb) in
async_updatethat is wrong, but I couldn't identify those here, not sure if it is hidden somewhere else, but if tests fail this is probably the cause.Thanks!
HelenChanges in v3: None
Changes in v2:
- update CC stable and Fixes tagdrivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c +2
-0@@ -502,6 +502,8 @@ static int mdp5_plane_atomic_async_check(struct drm_plane *plane,static void mdp5_plane_atomic_async_update (struct drm_plane *plane,struct drm_plane_state *new_state) { +struct drm_framebuffer *old_fb = plane->state->fb; + plane->state->src_x = new_state->src_x; plane->state->src_y = new_state->src_y; plane->state->crtc_x = new_state->crtc_x;@@ -524,6 +526,8 @@ static void mdp5_plane_atomic_async_update(struct drm_plane *plane,
Quoted 8 lines
drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c static void mdp5_plane_atomic_async_update(struct drm_plane *plane, · line 533
Quoted 8 lines
drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c +2
-0*to_mdp5_plane_state (plane->state) = *to_mdp5_plane_state (new_state); + + new_state->fb = old_fb; }static const struct drm_plane_helper_funcs mdp5_plane_helper_funcs = {
_______________________________________________
Freedreno mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/freedreno
PATCH v3 4/5 drm/vc4: fix fb references in async update
In reply to Helen KoikeAsync update callbacks are expected to set the old_fb in the new_state so prepare/cleanup framebuffers are balanced.
Calling drm_atomic_set_fb_for_plane() (which gets a reference of the new fb and put the old fb) is not required, as it's taken care by drm_mode_cursor_universal() when calling drm_atomic_helper_update_plane().
---
Hello,
I tested on a Raspberry Pi model B rev2 with igt plane_cursor_legacy and kms_cursor_legacy and I didn't see any regressions.
Changes in v3: None
Changes in v2:
- Added reviewed-by tag
- updated CC stable and Fixes tag
drivers/gpu/drm/vc4/vc4_plane.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/vc4/vc4_plane.c +1 -1
@@ -1025,7 +1025,7 @@ static void vc4_plane_atomic_async_update(struct drm_plane *plane, {struct vc4_plane_state *vc4_state, *new_vc4_state; -drm_atomic_set_fb_for_plane (plane->state, state->fb); +swap (plane->state->fb, state->fb); plane->state->crtc_x = state->crtc_x; plane->state->crtc_y = state->crtc_y; plane->state->crtc_w = state->crtc_w;
Signature · 1 line
2.20.1
Sasha Levin
maintainerRe: [PATCH v3 4/5] drm/vc4: fix fb references in async update
Hi,
[This is an automated email]
This commit has been processed because it contains a "Fixes:" tag, fixing commit: 539c320bfa97 drm/vc4: update cursors asynchronously through atomic.
The bot has tested the following trees: v5.0.3, v4.19.30.
v5.0.3: Build OK!
v4.19.30: Failed to apply! Possible dependencies:
1d4118ca165e ("drm/vc4: Rework the async update logic") 5a43911fd256 ("drm/vc4: Fix NULL pointer dereference in the async update path")
How should we proceed with this patch?
--
Thanks,
Sasha
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v3 5/5 drm: don't block fb changes for async plane updates
In reply to Helen KoikeIn the case of a normal sync update, the preparation of framebuffers (be it calling drm_atomic_helper_prepare_planes() or doing setups with drm_framebuffer_get()) are performed in the new_state and the respective cleanups are performed in the old_state.
In the case of async updates, the preparation is also done in the new_state but the cleanups are done in the new_state (because updates are performed in place, i.e. in the current state).
The current code blocks async udpates when the fb is changed, turning async updates into sync updates, slowing down cursor updates and introducing regressions in igt tests with errors of type:
"CRITICAL: completed 97 cursor updated in a period of 30 flips, we expect to complete approximately 15360 updates, with the threshold set at 7680"
Fb changes in async updates were prevented to avoid the following scenario:
- Async update, oldfb = NULL, newfb = fb1, prepare fb1, cleanup fb1
- Async update, oldfb = fb1, newfb = fb2, prepare fb2, cleanup fb2
- Non-async commit, oldfb = fb2, newfb = fb1, prepare fb1, cleanup fb2 (wrong) Where we have a single call to prepare fb2 but double cleanup call to fb2.
To solve the above problems, instead of blocking async fb changes, we place the old framebuffer in the new_state object, so when the code performs cleanups in the new_state it will cleanup the old_fb and we will have the following scenario instead:
- Async update, oldfb = NULL, newfb = fb1, prepare fb1, no cleanup
- Async update, oldfb = fb1, newfb = fb2, prepare fb2, cleanup fb1
- Non-async commit, oldfb = fb2, newfb = fb1, prepare fb1, cleanup fb2
Where calls to prepare/cleanup are balanced.
---
Hello,
I added a TODO in drm_atomic_helper_async_commit() regarding doing a full state swap(), Boris and Nicholas, let me know if this is ok and if I can keep your Reviewed-by tags)
As mentioned in the cover letter, I tested in almost all platforms with igt plane_cursor_legacy and kms_cursor_legacy and I didn't see any regressions. But I couldn't test on MSM and AMD because I don't have the hardware I would appreciate if anyone could help me testing those.
Thanks!
Helen
Changes in v3:
- Add Reviewed-by tags
- Add TODO in drm_atomic_helper_async_commit()
Changes in v2:
- Change the order of the patch in the series, add this as the last one.
- Add documentation
- s/ballanced/balanced
drivers/gpu/drm/drm_atomic_helper.c | 22 ++++++++++++---------- include/drm/drm_modeset_helper_vtables.h | 5 +++++ 2 files changed, 17 insertions(+), 10 deletions(-)
drivers/gpu/drm/drm_atomic_helper.c +12 -10
@@ -1608,15 +1608,6 @@ int drm_atomic_helper_async_check(struct drm_device *dev, old_plane_state->crtc != new_plane_state->crtc)return -EINVAL ; -/* -* FIXME: Since prepare_fb and cleanup_fb are always called on -* the new_plane_state for async updates we need to block framebuffer -* changes. This prevents use of a fb that's been cleaned up and -* double cleanups from occuring. -*/ -if (old_plane_state->fb != new_plane_state->fb) -return -EINVAL ; - funcs = plane->helper_private;if (!funcs->atomic_async_update)return -EINVAL ;
@@ -1647,6 +1638,8 @@ EXPORT_SYMBOL(drm_atomic_helper_async_check);* drm_atomic_async_check() succeeds. Async commits are not supposed to swap * the states like normal sync commits, but just do in-place changes on the * current state. +* +* TODO: Implement full swap instead of doing in-place changes. */ void drm_atomic_helper_async_commit (struct drm_device *dev,struct drm_atomic_state *state)
@@ -1657,6 +1650,9 @@ void drm_atomic_helper_async_commit(struct drm_device *dev,int i;for_each_new_plane_in_state (state, plane, plane_state, i) { +struct drm_framebuffer *new_fb = plane_state->fb; +struct drm_framebuffer *old_fb = plane->state->fb; + funcs = plane->helper_private; funcs->atomic_async_update (plane, plane_state);
@@ -1665,11 +1661,17 @@ void drm_atomic_helper_async_commit(struct drm_device *dev,* plane->state in-place, make sure at least common * properties have been properly updated. */ -WARN_ON_ONCE (plane->state->fb != plane_state->fb); +WARN_ON_ONCE (plane->state->fb != new_fb);WARN_ON_ONCE (plane->state->crtc_x != plane_state->crtc_x);WARN_ON_ONCE (plane->state->crtc_y != plane_state->crtc_y);WARN_ON_ONCE (plane->state->src_x != plane_state->src_x);WARN_ON_ONCE (plane->state->src_y != plane_state->src_y); + +/* +* Make sure the FBs have been swapped so that cleanups in the +* new_state performs a cleanup in the old FB. +*/ +WARN_ON_ONCE (plane_state->fb != old_fb); } }EXPORT_SYMBOL (drm_atomic_helper_async_commit);
include/drm/drm_modeset_helper_vtables.h +5 -0
@@ -1174,6 +1174,11 @@ struct drm_plane_helper_funcs {* current one with the new plane configurations in the new * plane_state. * +* Drivers should also swap the framebuffers between plane state +* and new_state. This is required because prepare and cleanup calls +* are performed on the new_state object, then to cleanup the old +* framebuffer, it needs to be placed inside the new_state object. +* * FIXME: * - It only works for single plane updates * - Async Pageflips are not supported yet
Signature · 6 lines
2.20.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Sean Paul
reviewerRe: [PATCH v3 5/5] drm: don't block fb changes for async plane updates
Quoted 29 lines · Helen Koike
In the case of a normal sync update, the preparation of framebuffers (be it calling
drm_atomic_helper_prepare_planes()or doing setups withdrm_framebuffer_get()) are performed in thenew_stateand the respective cleanups are performed in theold_state.In the case of async updates, the preparation is also done in the
new_statebut the cleanups are done in thenew_state(because updates are performed in place, i.e. in the current state).The current code blocks async udpates when the fb is changed, turning async updates into sync updates, slowing down cursor updates and introducing regressions in igt tests with errors of type:
"CRITICAL: completed 97 cursor updated in a period of 30 flips, we expect to complete approximately 15360 updates, with the threshold set at 7680"
Fb changes in async updates were prevented to avoid the following scenario:
- Async update, oldfb = NULL, newfb = fb1, prepare fb1, cleanup fb1
- Async update, oldfb = fb1, newfb = fb2, prepare fb2, cleanup fb2
- Non-async commit, oldfb = fb2, newfb = fb1, prepare fb1, cleanup fb2 (wrong) Where we have a single call to prepare fb2 but double cleanup call to fb2.To solve the above problems, instead of blocking async fb changes, we place the old framebuffer in the
new_stateobject, so when the code performs cleanups in thenew_stateit will cleanup theold_fband we will have the following scenario instead:
Quoted 7 lines
- Async update, oldfb = NULL, newfb = fb1, prepare fb1, no cleanup
- Async update, oldfb = fb1, newfb = fb2, prepare fb2, cleanup fb1
- Non-async commit, oldfb = fb2, newfb = fb1, prepare fb1, cleanup fb2Where calls to prepare/cleanup are balanced.
Cc <[email protected]> # v4.14+
I'm not convinced this should be cc: stable, seems more in the improvement category than a bug fix.
Quoted 97 lines
Fixes 25dc194b34dd ("drm: Block fb changes for async plane updates")Suggested-by Boris Brezillon <[email protected]>Signed-off-by Helen Koike <[email protected]>Reviewed-by Boris Brezillon <[email protected]>Reviewed-by Nicholas Kazlauskas <[email protected]>---
Hello,I added a TODO in
drm_atomic_helper_async_commit()regarding doing a full stateswap(), Boris and Nicholas, let me know if this is ok and if I can keep your Reviewed-by tags)As mentioned in the cover letter, I tested in almost all platforms with igt
plane_cursor_legacyandkms_cursor_legacyand I didn't see any regressions. But I couldn't test on MSM and AMD because I don't have the hardware I would appreciate if anyone could help me testing those.Thanks!
HelenChanges in v3:
- Add Reviewed-by tags
- Add TODO indrm_atomic_helper_async_commit()Changes in v2:
- Change the order of the patch in the series, add this as the last one.
- Add documentation
- s/ballanced/balanceddrivers/gpu/drm/drm_atomic_helper.c | 22 ++++++++++++---------- include/drm/drm_modeset_helper_vtables.h | 5 +++++ 2 files changed, 17 insertions(+), 10 deletions(-)drivers/gpu/drm/drm_atomic_helper.c +12
-10@@ -1608,15 +1608,6 @@ int drm_atomic_helper_async_check(struct drm_device *dev, old_plane_state->crtc != new_plane_state->crtc)return -EINVAL ; -/* -* FIXME: Since prepare_fb and cleanup_fb are always called on -* the new_plane_state for async updates we need to block framebuffer -* changes. This prevents use of a fb that's been cleaned up and -* double cleanups from occuring. -*/ -if (old_plane_state->fb != new_plane_state->fb) -return -EINVAL ; - funcs = plane->helper_private;if (!funcs->atomic_async_update)return -EINVAL ;@@ -1647,6 +1638,8 @@ EXPORT_SYMBOL(drm_atomic_helper_async_check);* drm_atomic_async_check() succeeds. Async commits are not supposed to swap * the states like normal sync commits, but just do in-place changes on the * current state. +* +* TODO: Implement full swap instead of doing in-place changes. */ void drm_atomic_helper_async_commit (struct drm_device *dev,struct drm_atomic_state *state)@@ -1657,6 +1650,9 @@ void drm_atomic_helper_async_commit(struct drm_device *dev,int i;for_each_new_plane_in_state (state, plane, plane_state, i) { +struct drm_framebuffer *new_fb = plane_state->fb; +struct drm_framebuffer *old_fb = plane->state->fb; + funcs = plane->helper_private; funcs->atomic_async_update (plane, plane_state);@@ -1665,11 +1661,17 @@ void drm_atomic_helper_async_commit(struct drm_device *dev,* plane->state in-place, make sure at least common * properties have been properly updated. */ -WARN_ON_ONCE (plane->state->fb != plane_state->fb); +WARN_ON_ONCE (plane->state->fb != new_fb);WARN_ON_ONCE (plane->state->crtc_x != plane_state->crtc_x);WARN_ON_ONCE (plane->state->crtc_y != plane_state->crtc_y);WARN_ON_ONCE (plane->state->src_x != plane_state->src_x);WARN_ON_ONCE (plane->state->src_y != plane_state->src_y); + +/* +* Make sure the FBs have been swapped so that cleanups in the +* new_state performs a cleanup in the old FB. +*/ +WARN_ON_ONCE (plane_state->fb != old_fb); } }EXPORT_SYMBOL (drm_atomic_helper_async_commit);include/drm/drm_modeset_helper_vtables.h +0
-0
include/drm/drm_modeset_helper_vtables.h struct drm_plane_helper_funcs { · line 1177
Quoted 4 lines
include/drm/drm_modeset_helper_vtables.h +1
-0@@ -1174,6 +1174,11 @@ struct drm_plane_helper_funcs {* current one with the new plane configurations in the new * plane_state. * +* Drivers should also swap the framebuffers between plane state
Perhaps add "current" before plane state and then after add "(&drm_plane.state)" so it's more clear what you're referring to here?
include/drm/drm_modeset_helper_vtables.h struct drm_plane_helper_funcs { · line 1180
Quoted 3 lines
include/drm/drm_modeset_helper_vtables.h +3
-0+* and new_state. This is required because prepare and cleanup calls +* are performed on the new_state object, then to cleanup the old +* framebuffer, it needs to be placed inside the new_state object.
I'd change this bit to:
* This is required since cleanup for async commits is performed on
* the new state, rather than old state like for traditional commits.
* Since we want to give up the reference on the current (old) fb instead
* of our brand new one, swap them in the driver during the async commit.
Quoted 7 lines
include/drm/drm_modeset_helper_vtables.h +1
-0+* * FIXME: * - It only works for single plane updates * - Async Pageflips are not supported yet Signature · 1 line
2.20.1
Signature · 1 line
Sean Paul, Software Engineer, Google / Chromium OS
Re: [PATCH v3 5/5] drm: don't block fb changes for async plane updates
Quoted 34 lines · Sean Paul
Quoted 33 lines · Helen Koike
In the case of a normal sync update, the preparation of framebuffers (be it calling
drm_atomic_helper_prepare_planes()or doing setups withdrm_framebuffer_get()) are performed in thenew_stateand the respective cleanups are performed in theold_state.In the case of async updates, the preparation is also done in the
new_statebut the cleanups are done in thenew_state(because updates are performed in place, i.e. in the current state).The current code blocks async udpates when the fb is changed, turning async updates into sync updates, slowing down cursor updates and introducing regressions in igt tests with errors of type:
"CRITICAL: completed 97 cursor updated in a period of 30 flips, we expect to complete approximately 15360 updates, with the threshold set at 7680"
Fb changes in async updates were prevented to avoid the following scenario:
- Async update, oldfb = NULL, newfb = fb1, prepare fb1, cleanup fb1
- Async update, oldfb = fb1, newfb = fb2, prepare fb2, cleanup fb2
- Non-async commit, oldfb = fb2, newfb = fb1, prepare fb1, cleanup fb2 (wrong) Where we have a single call to prepare fb2 but double cleanup call to fb2.To solve the above problems, instead of blocking async fb changes, we place the old framebuffer in the
new_stateobject, so when the code performs cleanups in thenew_stateit will cleanup theold_fband we will have the following scenario instead:- Async update, oldfb = NULL, newfb = fb1, prepare fb1, no cleanup
- Async update, oldfb = fb1, newfb = fb2, prepare fb2, cleanup fb1
- Non-async commit, oldfb = fb2, newfb = fb1, prepare fb1, cleanup fb2
Quoted 6 lines
Quoted 3 lines
Where calls to prepare/cleanup are balanced.
Cc <[email protected]> # v4.14+I'm not convinced this should be cc: stable, seems more in the improvement category than a bug fix.
I'm cc'ing to stable because the commit mentioned below inserted a regression regarding the speed that cursors can be updated.
Quoted 117 lines
Quoted 98 lines
Fixes 25dc194b34dd ("drm: Block fb changes for async plane updates")Suggested-by Boris Brezillon <[email protected]>Signed-off-by Helen Koike <[email protected]>Reviewed-by Boris Brezillon <[email protected]>Reviewed-by Nicholas Kazlauskas <[email protected]>---
Hello,I added a TODO in
drm_atomic_helper_async_commit()regarding doing a full stateswap(), Boris and Nicholas, let me know if this is ok and if I can keep your Reviewed-by tags)As mentioned in the cover letter, I tested in almost all platforms with igt
plane_cursor_legacyandkms_cursor_legacyand I didn't see any regressions. But I couldn't test on MSM and AMD because I don't have the hardware I would appreciate if anyone could help me testing those.Thanks!
HelenChanges in v3:
- Add Reviewed-by tags
- Add TODO indrm_atomic_helper_async_commit()Changes in v2:
- Change the order of the patch in the series, add this as the last one.
- Add documentation
- s/ballanced/balanceddrivers/gpu/drm/drm_atomic_helper.c | 22 ++++++++++++---------- include/drm/drm_modeset_helper_vtables.h | 5 +++++ 2 files changed, 17 insertions(+), 10 deletions(-)drivers/gpu/drm/drm_atomic_helper.c +12
-10@@ -1608,15 +1608,6 @@ int drm_atomic_helper_async_check(struct drm_device *dev, old_plane_state->crtc != new_plane_state->crtc)return -EINVAL ; -/* -* FIXME: Since prepare_fb and cleanup_fb are always called on -* the new_plane_state for async updates we need to block framebuffer -* changes. This prevents use of a fb that's been cleaned up and -* double cleanups from occuring. -*/ -if (old_plane_state->fb != new_plane_state->fb) -return -EINVAL ; - funcs = plane->helper_private;if (!funcs->atomic_async_update)return -EINVAL ;@@ -1647,6 +1638,8 @@ EXPORT_SYMBOL(drm_atomic_helper_async_check);* drm_atomic_async_check() succeeds. Async commits are not supposed to swap * the states like normal sync commits, but just do in-place changes on the * current state. +* +* TODO: Implement full swap instead of doing in-place changes. */ void drm_atomic_helper_async_commit (struct drm_device *dev,struct drm_atomic_state *state)@@ -1657,6 +1650,9 @@ void drm_atomic_helper_async_commit(struct drm_device *dev,int i;for_each_new_plane_in_state (state, plane, plane_state, i) { +struct drm_framebuffer *new_fb = plane_state->fb; +struct drm_framebuffer *old_fb = plane->state->fb; + funcs = plane->helper_private; funcs->atomic_async_update (plane, plane_state);@@ -1665,11 +1661,17 @@ void drm_atomic_helper_async_commit(struct drm_device *dev,* plane->state in-place, make sure at least common * properties have been properly updated. */ -WARN_ON_ONCE (plane->state->fb != plane_state->fb); +WARN_ON_ONCE (plane->state->fb != new_fb);WARN_ON_ONCE (plane->state->crtc_x != plane_state->crtc_x);WARN_ON_ONCE (plane->state->crtc_y != plane_state->crtc_y);WARN_ON_ONCE (plane->state->src_x != plane_state->src_x);WARN_ON_ONCE (plane->state->src_y != plane_state->src_y); + +/* +* Make sure the FBs have been swapped so that cleanups in the +* new_state performs a cleanup in the old FB. +*/ +WARN_ON_ONCE (plane_state->fb != old_fb); } }EXPORT_SYMBOL (drm_atomic_helper_async_commit);include/drm/drm_modeset_helper_vtables.h +0
-0include/drm/drm_modeset_helper_vtables.h struct drm_plane_helper_funcs { · line 1177
Quoted 4 lines
include/drm/drm_modeset_helper_vtables.h +1
-0@@ -1174,6 +1174,11 @@ struct drm_plane_helper_funcs {* current one with the new plane configurations in the new * plane_state. * +* Drivers should also swap the framebuffers between plane state Perhaps add "current" before plane state and then after add "(&drm_plane.state)" so it's more clear what you're referring to here?
include/drm/drm_modeset_helper_vtables.h struct drm_plane_helper_funcs { · line 1180
Quoted 3 lines
include/drm/drm_modeset_helper_vtables.h +3
-0+* and new_state. This is required because prepare and cleanup calls +* are performed on the new_state object, then to cleanup the old +* framebuffer, it needs to be placed inside the new_state object. I'd change this bit to:
* This is required since cleanup for async commits is performed on
* the new state, rather than old state like for traditional commits.
* Since we want to give up the reference on the current (old) fb instead
* of our brand new one, swap them in the driver during the async commit.
Quoted 8 lines
Quoted 7 lines
include/drm/drm_modeset_helper_vtables.h +1
-0+* * FIXME: * - It only works for single plane updates * - Async Pageflips are not supported yet Signature · 1 line
2.20.1
Thanks, I'm sending this update in v4.
Helen