drm: Add new plane helpers to begin/end FB access
Subsystems (2)
Thomas Zimmermann
maintainerv2 cover drm: Add new plane helpers to begin/end FB access
This patchset adds the callbacks begin_fb_access and end_fb_access to struct drm_plane_helper_funcs. They provide hooks to acquire and release resources that are only held during the commit. It adds related simple-KMS helpers and converts shadow-plane helpers.
As resource allocation often can fail, we have to do this before an atomic commit starts the update in order to handle the error. But prepare_fb is only reverted after the next pageflip. We want to reduce the time resources are held for a commit, which requires the new hooks.
With this in place, move shadow-plane helpers' automatic vmap/vunmap behind the new callbacks. The shadow-plane mapping is only required during the atomic commit.
Tested with combinations of radeon, udl and simpledrm under X11, Weston and Wayland-Gnome.
Thomas Zimmermann (2):
drm/atomic-helper: Add {begin,end}_fb_access to plane helpers drm/gem: Implement shadow-plane {begin,end}_fb_access with vmap
drivers/gpu/drm/drm_atomic_helper.c | 34 ++++++++++-- drivers/gpu/drm/drm_gem_atomic_helper.c | 66 +++++++++++------------- drivers/gpu/drm/drm_simple_kms_helper.c | 26 ++++++++++ include/drm/drm_gem_atomic_helper.h | 20 +++---- include/drm/drm_modeset_helper_vtables.h | 41 ++++++++++++++- include/drm/drm_simple_kms_helper.h | 20 +++++++ 6 files changed, 157 insertions(+), 50 deletions(-)
base-commit: 746559738f1335241ea686566cb654847c20d7a4
Signature · 1 line
2.38.0
Thomas Zimmermann
maintainerPATCH v2 1/2 drm/atomic-helper: Add {begin, end}_fb_access to plane helpers
Add {begin,end}_fb_access helpers to run at the beginning and end of an atomic commit. The begin_fb_access helper aquires resources that are necessary to perform the atomic commit. It it similar to prepare_fb, except that the resources are to be released at the end of the commit. Resources acquired by prepare_fb are held until after the next pageflip.
The end_fb_access helper performs the corresponding resource cleanup. Atomic helpers call it with the new plane state. This is differnt from cleanup_fb, which releases resources of the old plane state.
--- drivers/gpu/drm/drm_atomic_helper.c | 34 ++++++++++++++++++-- drivers/gpu/drm/drm_gem_atomic_helper.c | 19 ++++++----- drivers/gpu/drm/drm_simple_kms_helper.c | 26 +++++++++++++++ include/drm/drm_modeset_helper_vtables.h | 41 +++++++++++++++++++++++- include/drm/drm_simple_kms_helper.h | 20 ++++++++++++ 5 files changed, 126 insertions(+), 14 deletions(-)
drivers/gpu/drm/drm_atomic_helper.c +31 -3
@@ -2536,7 +2536,7 @@ int drm_atomic_helper_prepare_planes(struct drm_device *dev,if (funcs->prepare_fb) { ret = funcs->prepare_fb (plane, new_plane_state);if (ret) - goto fail; + goto fail_prepare_fb; }else {WARN_ON_ONCE (funcs->cleanup_fb);
@@ -2545,13 +2545,34 @@ int drm_atomic_helper_prepare_planes(struct drm_device *dev, ret =drm_gem_plane_helper_prepare_fb (plane, new_plane_state);if (ret) - goto fail; + goto fail_prepare_fb; + } + } + +for_each_new_plane_in_state (state, plane, new_plane_state, i) { +const struct drm_plane_helper_funcs *funcs = plane->helper_private; + +if (funcs->begin_fb_access) { + ret = funcs->begin_fb_access (plane, new_plane_state); +if (ret) + goto fail_begin_fb_access; } }return 0 ; -fail: +fail_begin_fb_access: +for_each_new_plane_in_state (state, plane, new_plane_state, j) { +const struct drm_plane_helper_funcs *funcs = plane->helper_private; + +if (j >= i) +continue ; + +if (funcs->end_fb_access) + funcs->end_fb_access (plane, new_plane_state); + } + i = j;/* set i to upper limit to cleanup all planes */ +fail_prepare_fb:for_each_new_plane_in_state (state, plane, new_plane_state, j) {const struct drm_plane_helper_funcs *funcs;
@@ -2827,6 +2848,13 @@ void drm_atomic_helper_cleanup_planes(struct drm_device *dev,struct drm_plane_state *old_plane_state, *new_plane_state;int i; +for_each_oldnew_plane_in_state (old_state, plane, old_plane_state, new_plane_state, i) { +const struct drm_plane_helper_funcs *funcs = plane->helper_private; + +if (funcs->end_fb_access) + funcs->end_fb_access (plane, new_plane_state); + } +for_each_oldnew_plane_in_state (old_state, plane, old_plane_state, new_plane_state, i) {const struct drm_plane_helper_funcs *funcs;struct drm_plane_state *plane_state;
drivers/gpu/drm/drm_gem_atomic_helper.c +9 -10
@@ -414,16 +414,14 @@ void drm_gem_cleanup_shadow_fb(struct drm_plane *plane, struct drm_plane_state *EXPORT_SYMBOL (drm_gem_cleanup_shadow_fb);/** -* drm_gem_simple_kms_prepare_shadow_fb - prepares shadow framebuffers +* drm_gem_simple_kms_begin_shadow_fb_access - prepares shadow framebuffers for CPU access * @pipe: the simple display pipe * @plane_state: the plane state of type struct drm_shadow_plane_state * -* This function implements struct drm_simple_display_funcs.prepare_fb. It -* maps all buffer objects of the plane's framebuffer into kernel address -* space and stores them in struct drm_shadow_plane_state.map. The -* framebuffer will be synchronized as part of the atomic commit. +* This function implements struct drm_simple_display_funcs.begin_fb_access. * -* See drm_gem_simple_kms_cleanup_shadow_fb() for cleanup. +* See drm_gem_begin_shadow_fb_access() for details and +* drm_gem_simple_kms_cleanup_shadow_fb() for cleanup. * * Returns: * 0 on success, or a negative errno code otherwise.
@@ -436,14 +434,15 @@ int drm_gem_simple_kms_prepare_shadow_fb(struct drm_simple_display_pipe *pipe,EXPORT_SYMBOL (drm_gem_simple_kms_prepare_shadow_fb);/** -* drm_gem_simple_kms_cleanup_shadow_fb - releases shadow framebuffers +* drm_gem_simple_kms_end_shadow_fb_access - releases shadow framebuffers from CPU access * @pipe: the simple display pipe * @plane_state: the plane state of type struct drm_shadow_plane_state * -* This function implements struct drm_simple_display_funcs.cleanup_fb. -* This function unmaps all buffer objects of the plane's framebuffer. +* This function implements struct drm_simple_display_funcs.end_fb_access. +* It undoes all effects of drm_gem_simple_kms_begin_shadow_fb_access() in +* reverse order. * -* See drm_gem_simple_kms_prepare_shadow_fb(). +* See drm_gem_simple_kms_begin_shadow_fb_access(). */ void drm_gem_simple_kms_cleanup_shadow_fb (struct drm_simple_display_pipe *pipe,struct drm_plane_state *plane_state)
drivers/gpu/drm/drm_simple_kms_helper.c +26 -0
@@ -285,6 +285,30 @@ static void drm_simple_kms_plane_cleanup_fb(struct drm_plane *plane, pipe->funcs->cleanup_fb (pipe, state); } +static int drm_simple_kms_plane_begin_fb_access (struct drm_plane *plane, +struct drm_plane_state *new_plane_state) +{ +struct drm_simple_display_pipe *pipe; + + pipe = container_of(plane, struct drm_simple_display_pipe, plane); +if (!pipe->funcs || !pipe->funcs->begin_fb_access) +return 0 ; + +return pipe->funcs->begin_fb_access (pipe, new_plane_state); +} + +static void drm_simple_kms_plane_end_fb_access (struct drm_plane *plane, +struct drm_plane_state *new_plane_state) +{ +struct drm_simple_display_pipe *pipe; + + pipe = container_of(plane, struct drm_simple_display_pipe, plane); +if (!pipe->funcs || !pipe->funcs->end_fb_access) +return ; + + pipe->funcs->end_fb_access (pipe, new_plane_state); +} +static bool drm_simple_kms_format_mod_supported (struct drm_plane *plane,uint32_t format,uint64_t modifier)
@@ -295,6 +319,8 @@ static bool drm_simple_kms_format_mod_supported(struct drm_plane *plane,static const struct drm_plane_helper_funcs drm_simple_kms_plane_helper_funcs = { .prepare_fb = drm_simple_kms_plane_prepare_fb, .cleanup_fb = drm_simple_kms_plane_cleanup_fb, + .begin_fb_access = drm_simple_kms_plane_begin_fb_access, + .end_fb_access = drm_simple_kms_plane_end_fb_access, .atomic_check = drm_simple_kms_plane_atomic_check, .atomic_update = drm_simple_kms_plane_atomic_update, };
include/drm/drm_modeset_helper_vtables.h +40 -1
57 lines not on this page · raw message
include/drm/drm_simple_kms_helper.h +20 -0
@@ -135,6 +135,26 @@ struct drm_simple_display_pipe_funcs {void (*cleanup_fb)(struct drm_simple_display_pipe *pipe,struct drm_plane_state *plane_state); +/** +* @begin_fb_access: +* +* Optional, called by &drm_plane_helper_funcs.begin_fb_access. Please read +* the documentation for the &drm_plane_helper_funcs.begin_fb_access hook for +* more details. +*/ +int (*begin_fb_access)(struct drm_simple_display_pipe *pipe, +struct drm_plane_state *new_plane_state); + +/** +* @end_fb_access: +* +* Optional, called by &drm_plane_helper_funcs.end_fb_access. Please read +* the documentation for the &drm_plane_helper_funcs.end_fb_access hook for +* more details. +*/ +void (*end_fb_access)(struct drm_simple_display_pipe *pipe, +struct drm_plane_state *plane_state); +/** * @enable_vblank: *
Signature · 1 line
2.38.0
Re: [PATCH v2 1/2] drm/atomic-helper: Add {begin,end}_fb_access to plane helpers
Hello Thomas,
On 10/25/22 12:17, Thomas Zimmermann wrote:> Add {begin,end}_fb_access helpers to run at the beginning and end of
Quoted 1 line
an atomic commit. The
begin_fb_accesshelper aquires resources that
acquires
Quoted 6 lines
are necessary to perform the atomic commit. It it similar to
prepare_fb, except that the resources are to be released at the end of the commit. Resources acquired byprepare_fbare held until after the next pageflip.The
end_fb_accesshelper performs the corresponding resource cleanup. Atomic helpers call it with the new plane state. This is differnt from
different
Quoted 4 lines
cleanup_fb, which releases resources of the old plane state.Signed-off-by Thomas Zimmermann <[email protected]>---
The change makes sense to me.
Signature · 5 lines
Best regards, Javier Martinez Canillas Core Platforms Red Hat
Thomas Zimmermann
maintainerPATCH v2 2/2 drm/gem: Implement shadow-plane {begin, end}_fb_access with vmap
In reply to Thomas ZimmermannMove the vmap code for shadow-plane helpers from prepare_fb to begin_fb_access helpers. Vunmap is now performed at the end of the current pageflip, instead of the end of the following pageflip.
Reduces the duration of the mapping from while the framebuffer is being displayed to just the atomic commit. This is safe as outside of the pageflip, nothing should access the mapped buffer memory. Unmapping the framebuffer BO memory early allows reduces address-space consumption and possibly allows for evicting the memory pages.
The change is effectively a rename of prepare_fb and cleanup_fb implementations, plus updates to the shadow-plane init macro. As there's no longer a prepare_fb helper for shadow planes, atomic helpers will call drm_gem_plane_helper_prepare_fb() automatically.
--- drivers/gpu/drm/drm_gem_atomic_helper.c | 47 +++++++++++-------------- include/drm/drm_gem_atomic_helper.h | 20 +++++------ 2 files changed, 31 insertions(+), 36 deletions(-)
drivers/gpu/drm/drm_gem_atomic_helper.c +21 -26
@@ -360,48 +360,43 @@ void drm_gem_reset_shadow_plane(struct drm_plane *plane)EXPORT_SYMBOL (drm_gem_reset_shadow_plane);/** -* drm_gem_prepare_shadow_fb - prepares shadow framebuffers +* drm_gem_begin_shadow_fb_access - prepares shadow framebuffers for CPU access * @plane: the plane * @plane_state: the plane state of type struct drm_shadow_plane_state * -* This function implements struct &drm_plane_helper_funcs.prepare_fb. It +* This function implements struct &drm_plane_helper_funcs.begin_fb_access. It * maps all buffer objects of the plane's framebuffer into kernel address -* space and stores them in &struct drm_shadow_plane_state.map. The -* framebuffer will be synchronized as part of the atomic commit. +* space and stores them in struct &drm_shadow_plane_state.map. The first data +* bytes are available in struct &drm_shadow_plane_state.data. * -* See drm_gem_cleanup_shadow_fb() for cleanup. +* See drm_gem_end_shadow_fb_access() for cleanup. * * Returns: * 0 on success, or a negative errno code otherwise. */ -int drm_gem_prepare_shadow_fb (struct drm_plane *plane,struct drm_plane_state *plane_state) +int drm_gem_begin_shadow_fb_access (struct drm_plane *plane,struct drm_plane_state *plane_state) {struct drm_shadow_plane_state *shadow_plane_state =to_drm_shadow_plane_state (plane_state);struct drm_framebuffer *fb = plane_state->fb; -int ret;if (!fb)return 0 ; - ret =drm_gem_plane_helper_prepare_fb (plane, plane_state); -if (ret) -return ret; -return drm_gem_fb_vmap (fb, shadow_plane_state->map, shadow_plane_state->data); } -EXPORT_SYMBOL (drm_gem_prepare_shadow_fb); +EXPORT_SYMBOL (drm_gem_begin_shadow_fb_access);/** -* drm_gem_cleanup_shadow_fb - releases shadow framebuffers +* drm_gem_end_shadow_fb_access - releases shadow framebuffers from CPU access * @plane: the plane * @plane_state: the plane state of type struct drm_shadow_plane_state * -* This function implements struct &drm_plane_helper_funcs.cleanup_fb. -* This function unmaps all buffer objects of the plane's framebuffer. +* This function implements struct &drm_plane_helper_funcs.end_fb_access. It +* undoes all effects of drm_gem_begin_shadow_fb_access() in reverse order. * -* See drm_gem_prepare_shadow_fb() for more information. +* See drm_gem_begin_shadow_fb_access() for more information. */ -void drm_gem_cleanup_shadow_fb (struct drm_plane *plane,struct drm_plane_state *plane_state) +void drm_gem_end_shadow_fb_access (struct drm_plane *plane,struct drm_plane_state *plane_state) {struct drm_shadow_plane_state *shadow_plane_state =to_drm_shadow_plane_state (plane_state);struct drm_framebuffer *fb = plane_state->fb;
@@ -411,7 +406,7 @@ void drm_gem_cleanup_shadow_fb(struct drm_plane *plane, struct drm_plane_state *drm_gem_fb_vunmap (fb, shadow_plane_state->map); } -EXPORT_SYMBOL (drm_gem_cleanup_shadow_fb); +EXPORT_SYMBOL (drm_gem_end_shadow_fb_access);/** * drm_gem_simple_kms_begin_shadow_fb_access - prepares shadow framebuffers for CPU access
@@ -426,12 +421,12 @@ EXPORT_SYMBOL(drm_gem_cleanup_shadow_fb);* Returns: * 0 on success, or a negative errno code otherwise. */ -int drm_gem_simple_kms_prepare_shadow_fb (struct drm_simple_display_pipe *pipe, -struct drm_plane_state *plane_state) +int drm_gem_simple_kms_begin_shadow_fb_access (struct drm_simple_display_pipe *pipe, +struct drm_plane_state *plane_state) { -return drm_gem_prepare_shadow_fb (&pipe->plane, plane_state); +return drm_gem_begin_shadow_fb_access (&pipe->plane, plane_state); } -EXPORT_SYMBOL (drm_gem_simple_kms_prepare_shadow_fb); +EXPORT_SYMBOL (drm_gem_simple_kms_begin_shadow_fb_access);/** * drm_gem_simple_kms_end_shadow_fb_access - releases shadow framebuffers from CPU access
@@ -444,12 +439,12 @@ EXPORT_SYMBOL(drm_gem_simple_kms_prepare_shadow_fb);* * See drm_gem_simple_kms_begin_shadow_fb_access(). */ -void drm_gem_simple_kms_cleanup_shadow_fb (struct drm_simple_display_pipe *pipe, -struct drm_plane_state *plane_state) +void drm_gem_simple_kms_end_shadow_fb_access (struct drm_simple_display_pipe *pipe, +struct drm_plane_state *plane_state) { -drm_gem_cleanup_shadow_fb (&pipe->plane, plane_state); +drm_gem_end_shadow_fb_access (&pipe->plane, plane_state); } -EXPORT_SYMBOL (drm_gem_simple_kms_cleanup_shadow_fb); +EXPORT_SYMBOL (drm_gem_simple_kms_end_shadow_fb_access);/** * drm_gem_simple_kms_reset_shadow_plane - resets a shadow-buffered plane
include/drm/drm_gem_atomic_helper.h +10 -10
@@ -103,8 +103,8 @@ void drm_gem_destroy_shadow_plane_state(struct drm_plane *plane, .atomic_duplicate_state = drm_gem_duplicate_shadow_plane_state, \ .atomic_destroy_state = drm_gem_destroy_shadow_plane_state -int drm_gem_prepare_shadow_fb (struct drm_plane *plane,struct drm_plane_state *plane_state); -void drm_gem_cleanup_shadow_fb (struct drm_plane *plane,struct drm_plane_state *plane_state); +int drm_gem_begin_shadow_fb_access (struct drm_plane *plane,struct drm_plane_state *plane_state); +void drm_gem_end_shadow_fb_access (struct drm_plane *plane,struct drm_plane_state *plane_state);/** * DRM_GEM_SHADOW_PLANE_HELPER_FUNCS -
@@ -115,13 +115,13 @@ void drm_gem_cleanup_shadow_fb(struct drm_plane *plane, struct drm_plane_state ** functions. */ #define DRM_GEM_SHADOW_PLANE_HELPER_FUNCS \ - .prepare_fb = drm_gem_prepare_shadow_fb, \ - .cleanup_fb = drm_gem_cleanup_shadow_fb + .begin_fb_access = drm_gem_begin_shadow_fb_access, \ + .end_fb_access = drm_gem_end_shadow_fb_access -int drm_gem_simple_kms_prepare_shadow_fb (struct drm_simple_display_pipe *pipe, -struct drm_plane_state *plane_state); -void drm_gem_simple_kms_cleanup_shadow_fb (struct drm_simple_display_pipe *pipe, -struct drm_plane_state *plane_state); +int drm_gem_simple_kms_begin_shadow_fb_access (struct drm_simple_display_pipe *pipe, +struct drm_plane_state *plane_state); +void drm_gem_simple_kms_end_shadow_fb_access (struct drm_simple_display_pipe *pipe, +struct drm_plane_state *plane_state);void drm_gem_simple_kms_reset_shadow_plane (struct drm_simple_display_pipe *pipe);struct drm_plane_state *drm_gem_simple_kms_duplicate_shadow_plane_state (struct drm_simple_display_pipe *pipe);
@@ -137,8 +137,8 @@ void drm_gem_simple_kms_destroy_shadow_plane_state(struct drm_simple_display_pip* functions. */ #define DRM_GEM_SIMPLE_DISPLAY_PIPE_SHADOW_PLANE_FUNCS \ - .prepare_fb = drm_gem_simple_kms_prepare_shadow_fb, \ - .cleanup_fb = drm_gem_simple_kms_cleanup_shadow_fb, \ + .begin_fb_access = drm_gem_simple_kms_begin_shadow_fb_access, \ + .end_fb_access = drm_gem_simple_kms_end_shadow_fb_access, \ .reset_plane = drm_gem_simple_kms_reset_shadow_plane, \ .duplicate_plane_state = drm_gem_simple_kms_duplicate_shadow_plane_state, \ .destroy_plane_state = drm_gem_simple_kms_destroy_shadow_plane_state
Signature · 1 line
2.38.0
Re: [PATCH v2 2/2] drm/gem: Implement shadow-plane {begin,end}_fb_access with vmap
Quoted 8 lines · Thomas Zimmermann
Move the vmap code for shadow-plane helpers from
prepare_fbtobegin_fb_accesshelpers. Vunmap is now performed at the end of the current pageflip, instead of the end of the following pageflip.Reduces the duration of the mapping from while the framebuffer is being displayed to just the atomic commit. This is safe as outside of the pageflip, nothing should access the mapped buffer memory. Unmapping the framebuffer BO memory early allows reduces address-space
"allows to reduce" or "allows a reduced" ?
Quoted 9 lines
consumption and possibly allows for evicting the memory pages.
The change is effectively a rename of
prepare_fbandcleanup_fbimplementations, plus updates to the shadow-plane init macro. As there's no longer aprepare_fbhelper for shadow planes, atomic helpers will calldrm_gem_plane_helper_prepare_fb()automatically.Signed-off-by Thomas Zimmermann <[email protected]>---
Signature · 5 lines
Best regards, Javier Martinez Canillas Core Platforms Red Hat
Thomas Zimmermann
maintainerping. Any comments?
Am 25.10.22 um 12:17 schrieb Thomas Zimmermann:
Quoted 32 lines
This patchset adds the callbacks
begin_fb_accessandend_fb_accessto structdrm_plane_helper_funcs. They provide hooks to acquire and release resources that are only held during the commit. It adds related simple-KMS helpers and converts shadow-plane helpers.As resource allocation often can fail, we have to do this before an atomic commit starts the update in order to handle the error. But
prepare_fbis only reverted after the next pageflip. We want to reduce the time resources are held for a commit, which requires the new hooks.With this in place, move shadow-plane helpers' automatic vmap/vunmap behind the new callbacks. The shadow-plane mapping is only required during the atomic commit.
Tested with combinations of radeon, udl and simpledrm under X11, Weston and Wayland-Gnome.
Thomas Zimmermann (2):
drm/atomic-helper: Add {begin,end}_fb_access to plane helpers drm/gem: Implement shadow-plane {begin,end}_fb_access with vmapdrivers/gpu/drm/drm_atomic_helper.c | 34 ++++++++++-- drivers/gpu/drm/drm_gem_atomic_helper.c | 66 +++++++++++------------- drivers/gpu/drm/drm_simple_kms_helper.c | 26 ++++++++++ include/drm/drm_gem_atomic_helper.h | 20 +++---- include/drm/drm_modeset_helper_vtables.h | 41 ++++++++++++++- include/drm/drm_simple_kms_helper.h | 20 +++++++ 6 files changed, 157 insertions(+), 50 deletions(-)base-commit:
746559738f1335241ea686566cb654847c20d7a4
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo Totev