Re: [PATCH] drm/ast: Optimize cursor updates and reduce overhead
From: Herman Semenoff
Date: Wed Nov 25 2026 - 08:52:08 EST
I’m sorry. First, I didn’t break it down into multiple patches, and
second, I didn’t test it properly, and I also didn’t note that this
patch Assisted-by: LLM.
ср, 25 нояб. 2026 г. в 14:53, Thomas Zimmermann <tzimmermann@xxxxxxx>:
>
>
>
> Am 25.11.26 um 12:24 schrieb Herman Semenoff:
> > From f9574b5a246bf9021ea75f530a9a8ab7c9995274 Mon Sep 17 00:00:00 2001
> > From: Herman Semenoff <GermanAizek@xxxxxxxxx>
> > Date: Tue, 24 Nov 2026 12:53:31 +0300
> > Subject: [PATCH] drm/ast: Optimize cursor updates and reduce overhead
> >
> > On server platforms equipped with ASPEED BMC GPUs (such as AST2400 on
> > Lenovo RD450X), VRAM is mapped over a slow PCIe link with limited
> > bandwidth.
> >
> > Currently, on every cursor move (e.g. via drmModeMoveCursor or atomic
> > commit updating plane coordinates without damage clips),
> > ast_cursor_plane_helper_atomic_update() invokes
> > drm_atomic_helper_damage_merged(). Because userspace does not provide
> > damage clips for pure cursor movements,
> > drm_atomic_helper_damage_iter_init() treats the absence of clips as a
> > full plane update. Consequently, on every mouse move event:
> > 1. ast_cursor_plane_get_argb4444() performs format conversion on CPU
> > 2. ast_set_cursor_image() recalculates 32-bit checksum on CPU
> > 3. memcpy_toio() pushes 8192 bytes over the slow PCIe link into VRAM
> > 4. Cursor base registers are reprogrammed
> >
> > Fix this by only updating the cursor image and base when the image
> > actually changes (fb != old_fb, plane was previously invisible, or
> > damage clips were provided). For pure position updates, only update
> > the coordinates in the hardware cursor signature and registers,
> > skipping VRAM transfer, format conversion, and checksum calculation.
> >
> > Additionally:
> > - Add DRM_FORMAT_XRGB8888 support to ast_cursor_plane_formats and handle
> > it with opaque alpha in ast_cursor_plane_get_argb4444(), preventing
> > compositors from unnecessarily falling back to software cursors on the
> > primary plane
> > - Implement .panic_flush in ast_primary_plane_helper_funcs to disable the
> > hardware cursor during kernel panics (CONFIG_DRM_PANIC)
>
> I this is mostly wrong and the patch is terrible. I refuse to further
> deal with any of this.
>
> >
> > Signed-off-by: Herman Semenoff <GermanAizek@xxxxxxxxx>
> > Signed-off-by: Herman Semenoff <GermanAizek@xxxxxxxxxxxxx>
> > ---
> > drivers/gpu/drm/ast/ast_cursor.c | 39 +++++++++++++++++++++++++++++---
> > drivers/gpu/drm/ast/ast_drv.h | 1 +
> > drivers/gpu/drm/ast/ast_mode.c | 8 +++++++
> > 3 files changed, 45 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/ast/ast_cursor.c b/drivers/gpu/drm/ast/ast_cursor.c
> > index 690d4cd1db5e..883d1e6f20bd 100644
> > --- a/drivers/gpu/drm/ast/ast_cursor.c
> > +++ b/drivers/gpu/drm/ast/ast_cursor.c
> > @@ -142,7 +142,7 @@ static void ast_set_cursor_location(struct
> > ast_device *ast, u16 x, u16 y,
> > ast_set_index_reg(ast, AST_IO_VGACRI, 0xc7, y1);
> > }
> >
> > -static void ast_set_cursor_enabled(struct ast_device *ast, bool enabled)
> > +void ast_set_cursor_enabled(struct ast_device *ast, bool enabled)
> > {
> > static const u8 mask = (u8)~(AST_IO_VGACRCB_HWC_16BPP |
> > AST_IO_VGACRCB_HWC_ENABLED);
> > @@ -162,6 +162,7 @@ static void ast_set_cursor_enabled(struct
> > ast_device *ast, bool enabled)
> > static const uint32_t ast_cursor_plane_formats[] = {
> > DRM_FORMAT_ARGB4444,
> > DRM_FORMAT_ARGB8888,
> > + DRM_FORMAT_XRGB8888,
> > };
> >
> > static int ast_cursor_plane_helper_atomic_check(struct drm_plane *plane,
> > @@ -229,6 +230,30 @@ static const u8
> > *ast_cursor_plane_get_argb4444(struct ast_cursor_plane *ast_curs
> > argb4444 = argb4444_dst[0].vaddr;
> > }
> > break;
> > + case DRM_FORMAT_XRGB8888:
> > + {
> > + struct iosys_map argb4444_dst[DRM_FORMAT_MAX_PLANES] = {
> > + IOSYS_MAP_INIT_VADDR(ast_cursor_plane->argb4444),
> > + };
> > + unsigned int argb4444_dst_pitch[DRM_FORMAT_MAX_PLANES] = {
> > + AST_HWC_PITCH,
> > + };
> > + unsigned int x, y;
> > + u16 *dst16;
> > +
> > + drm_fb_argb8888_to_argb4444(argb4444_dst, argb4444_dst_pitch,
> > + shadow_plane_state->data, fb, clip,
> > + &shadow_plane_state->fmtcnv_state);
> > +
> > + for (y = clip->y1; y < clip->y2; y++) {
> > + dst16 = (u16 *)(ast_cursor_plane->argb4444 +
> > + y * AST_HWC_PITCH);
> > + for (x = clip->x1; x < clip->x2; x++)
> > + dst16[x] |= 0xf000;
> > + }
> > + argb4444 = argb4444_dst[0].vaddr;
> > + }
> > + break;
> > }
> >
> > drm_gem_fb_end_cpu_access(fb, DMA_FROM_DEVICE);
> > @@ -261,13 +286,21 @@ static void
> > ast_cursor_plane_helper_atomic_update(struct drm_plane *plane,
> > unsigned int offset_x, offset_y;
> > u16 x, y;
> > u8 x_offset, y_offset;
> > + bool update_image;
> >
> > /*
> > * Do data transfer to hardware buffer and point the scanout
> > - * engine to the offset.
> > + * engine to the offset only if the cursor image actually changed
> > + * or the plane became visible. For pure cursor moves, avoid
> > + * expensive PCIe bus transfers, format conversion, and checksum
> > + * calculation.
> > */
> > + update_image = (fb != old_plane_state->fb) ||
> > + !old_plane_state->visible ||
> > + drm_plane_get_damage_clips_count(plane_state);
> >
> > - if (drm_atomic_helper_damage_merged(old_plane_state, plane_state, &damage)) {
> > + if (update_image &&
> > + drm_atomic_helper_damage_merged(old_plane_state, plane_state, &damage)) {
> > const u8 *argb4444 = ast_cursor_plane_get_argb4444(ast_cursor_plane,
> > shadow_plane_state,
> > &damage);
> > diff --git a/drivers/gpu/drm/ast/ast_drv.h b/drivers/gpu/drm/ast/ast_drv.h
> > index 4f221b848d68..d846d5cf4f5e 100644
> > --- a/drivers/gpu/drm/ast/ast_drv.h
> > +++ b/drivers/gpu/drm/ast/ast_drv.h
> > @@ -542,6 +542,7 @@ int ast_sil164_output_init(struct ast_device *ast);
> > /* ast_cursor.c */
> > long ast_cursor_vram_offset(struct ast_device *ast);
> > int ast_cursor_plane_init(struct ast_device *ast);
> > +void ast_set_cursor_enabled(struct ast_device *ast, bool enabled);
> >
> > /* ast dp501 */
> > bool ast_backup_fw(struct ast_device *ast, u8 *addr, u32 size);
> > diff --git a/drivers/gpu/drm/ast/ast_mode.c b/drivers/gpu/drm/ast/ast_mode.c
> > index 08db132acae8..f94f849d157b 100644
> > --- a/drivers/gpu/drm/ast/ast_mode.c
> > +++ b/drivers/gpu/drm/ast/ast_mode.c
> > @@ -639,6 +639,13 @@ static int
> > ast_primary_plane_helper_get_scanout_buffer(struct drm_plane *plane,
> > return -ENODEV;
> > }
> >
> > +static void ast_primary_plane_helper_panic_flush(struct drm_plane *plane)
> > +{
> > + struct ast_device *ast = to_ast_device(plane->dev);
> > +
> > + ast_set_cursor_enabled(ast, false);
> > +}
> > +
> > static const struct drm_plane_helper_funcs ast_primary_plane_helper_funcs = {
> > DRM_GEM_SHADOW_PLANE_HELPER_FUNCS,
> > .atomic_check = ast_primary_plane_helper_atomic_check,
> > @@ -646,6 +653,7 @@ static const struct drm_plane_helper_funcs
> > ast_primary_plane_helper_funcs = {
> > .atomic_enable = ast_primary_plane_helper_atomic_enable,
> > .atomic_disable = ast_primary_plane_helper_atomic_disable,
> > .get_scanout_buffer = ast_primary_plane_helper_get_scanout_buffer,
> > + .panic_flush = ast_primary_plane_helper_panic_flush,
> > };
> >
> > static const struct drm_plane_funcs ast_primary_plane_funcs = {
>
> --
> --
> Thomas Zimmermann
> Graphics Driver Developer
> SUSE Software Solutions Germany GmbH
> Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
> GF: Stefan Gaiser, Jochen Jaser, Abhinav Puri, (HRB 36809, AG Nürnberg)
>
>