drm/mgag200: Add a workaround for low-latency
Subsystems (3)
Jocelyn Falempe
reviewerPATCH 1/1 drm/mgag200: Add a workaround for low-latency
We found a regression in v5.10 on real-time server, using the rt-kernel and the mgag200 driver. It's some really specialized workload, with <10us latency expectation on isolated core. After the v5.10, the real time tasks missed their <10us latency when something prints on the screen (fbcon or printk)
The regression has been bisected to 2 commits:
commit 0b34d58b6c32 ("drm/mgag200: Enable caching for SHMEM pages") commit 4862ffaec523 ("drm/mgag200: Move vmap out of commit tail")
The first one changed the system memory framebuffer from Write-Combine to the default caching.
Before the second commit, the mgag200 driver used to unmap the framebuffer after each frame, which implicitly does a cache flush. Both regressions are fixed by this commit, which restore WC mapping for the framebuffer in system memory, and add a cache flush. This is only needed on x86_64, for low-latency workload,
so the new kconfig DRM_MGAG200_LATENCY_WORKAROUND depends on PREEMPT_RT and X86.
For more context, the whole thread can be found here:
https://lore.kernel.org/dri-devel/[email protected]/
--- drivers/gpu/drm/mgag200/Kconfig | 10 ++++++++++ drivers/gpu/drm/mgag200/mgag200_drv.c | 17 +++++++++++++++++ drivers/gpu/drm/mgag200/mgag200_mode.c | 8 ++++++++ 3 files changed, 35 insertions(+)
drivers/gpu/drm/mgag200/Kconfig +10 -0
@@ -11,3 +11,13 @@ config DRM_MGAG200 MGA G200 desktop chips and the server variants. It requires 0.3.0 of the modesetting userspace driver, and a version of mga driver that will fail on KMS enabled devices. + +config DRM_MGAG200_LATENCY_WORKAROUND + bool "Enable workaround for low latency server" + depends on DRM_MGAG200 && PREEMPT_RT && X86 + help + Enable a workaround to have better latency with mgag200 driver. + It restores the <v5.10 behavior, by mapping the framebuffer in system + RAM as Write-Combining, and flushing the cache after each write. + This is only needed on x86_64 and if you want low-latency. + If unsure, say N.
drivers/gpu/drm/mgag200/mgag200_drv.c +17 -0
@@ -84,6 +84,20 @@ resource_size_t mgag200_probe_vram(void __iomem *mem, resource_size_t size)return offset -65536 ; } +#if defined(CONFIG_DRM_MGAG200_LATENCY_WORKAROUND ) +static struct drm_gem_object *mgag200_create_object (struct drm_device *dev,size_t size) +{ +struct drm_gem_shmem_object *shmem; + + shmem =kzalloc (sizeof (*shmem),GFP_KERNEL ); +if (!shmem) +return NULL ; + + shmem->map_wc = true; +return &shmem->base; +} +#endif +/* * DRM driver */
@@ -99,6 +113,9 @@ static const struct drm_driver mgag200_driver = { .major = DRIVER_MAJOR, .minor = DRIVER_MINOR, .patchlevel = DRIVER_PATCHLEVEL, +#if defined(CONFIG_DRM_MGAG200_LATENCY_WORKAROUND ) + .gem_create_object = mgag200_create_object, +#endif DRM_GEM_SHMEM_DRIVER_OPS, };
drivers/gpu/drm/mgag200/mgag200_mode.c +8 -0
@@ -13,6 +13,7 @@#include <drm/drm_atomic.h> #include <drm/drm_atomic_helper.h> +#include <drm/drm_cache.h> #include <drm/drm_damage_helper.h> #include <drm/drm_edid.h> #include <drm/drm_format_helper.h>
@@ -436,6 +437,13 @@ static void mgag200_handle_damage(struct mga_device *mdev, const struct iosys_maiosys_map_incr (&dst,drm_fb_clip_offset (fb->pitches[0 ], fb->format, clip));drm_fb_memcpy (&dst, fb->pitches, vmap, fb, clip); + +/* Flushing the cache greatly improves latency on x86_64 */ +#if defined(CONFIG_DRM_MGAG200_LATENCY_WORKAROUND ) +if (!vmap->is_iomem) +drm_clflush_virt_range (vmap->vaddr + clip->y1 * fb->pitches[0 ], +drm_rect_height (clip) * fb->pitches[0 ]); +#endif }/*
base-commit: 1f36d634670d8001a45fe2f2dcae546819f9c7d8
Signature · 1 line
2.43.0
Thomas Zimmermann
maintainerHi
Am 06.02.24 um 23:21 schrieb Jocelyn Falempe:
Quoted 20 lines
We found a regression in v5.10 on real-time server, using the rt-kernel and the mgag200 driver. It's some really specialized workload, with <10us latency expectation on isolated core. After the v5.10, the real time tasks missed their <10us latency when something prints on the screen (fbcon or printk)
The regression has been bisected to 2 commits:
commit0b34d58b6c32("drm/mgag200: Enable caching for SHMEM pages") commit4862ffaec523("drm/mgag200: Move vmap out of commit tail")The first one changed the system memory framebuffer from Write-Combine to the default caching.
Before the second commit, the mgag200 driver used to unmap the framebuffer after each frame, which implicitly does a cache flush. Both regressions are fixed by this commit, which restore WC mapping for the framebuffer in system memory, and add a cache flush. This is only needed onx86_64, for low-latency workload,
so the new kconfigDRM_MGAG200_LATENCY_WORKAROUNDdepends onPREEMPT_RTand X86.
Quoted 2 lines
For more context, the whole thread can be found here:
https://lore.kernel.org/dri-devel/[email protected]/
This URL should be in a Link tag below the SoB line, like this:
Quoted 13 lines
Signed-off-by Jocelyn Falempe <[email protected]>--- drivers/gpu/drm/mgag200/Kconfig | 10 ++++++++++ drivers/gpu/drm/mgag200/mgag200_drv.c | 17 +++++++++++++++++ drivers/gpu/drm/mgag200/mgag200_mode.c | 8 ++++++++ 3 files changed, 35 insertions(+)drivers/gpu/drm/mgag200/Kconfig +0
-0
drivers/gpu/drm/mgag200/Kconfig config DRM_MGAG200 · line 15
Quoted 5 lines
drivers/gpu/drm/mgag200/Kconfig +2
-0@@ -11,3 +11,13 @@ config DRM_MGAG200 MGA G200 desktop chips and the server variants. It requires 0.3.0 of the modesetting userspace driver, and a version of mga driver that will fail on KMS enabled devices. + +config DRM_MGAG200_LATENCY_WORKAROUND
Can we call this DRM_MGAG200_IOBURST_WORKAROUND? I know what you mean by latency, but that's not what is happening in the driver. The latency you refer to is the deterministic response time of your process, but the response time of the driver actually goes up (because of the disabled caching).
drivers/gpu/drm/mgag200/Kconfig config DRM_MGAG200 · line 16
Quoted 1 line
drivers/gpu/drm/mgag200/Kconfig +1
-0+ bool "Enable workaround for low latency server"
This is a 'low-latency server'. But I'd just say "Disabled buffer caching", so that users know what they are getting into.
drivers/gpu/drm/mgag200/Kconfig config DRM_MGAG200 · line 19
Quoted 3 lines
drivers/gpu/drm/mgag200/Kconfig +3
-0+ depends on DRM_MGAG200 && PREEMPT_RT && X86 + help + Enable a workaround to have better latency with mgag200 driver.
Here I'd say "Enable a workaround to avoid I/O bursts within the mgag200 driver at the expense of overall display performance."
drivers/gpu/drm/mgag200/Kconfig config DRM_MGAG200 · line 22
Quoted 3 lines
drivers/gpu/drm/mgag200/Kconfig +3
-0+ It restores the <v5.10 behavior, by mapping the framebuffer in system + RAM as Write-Combining, and flushing the cache after each write. + This is only needed on x86_64 and if you want low-latency.
Maybe "This is only useful on x86_64 if you want to run processes with deterministic latency."
The code itself looks good to me.
Best regards
Thomas
Quoted 64 lines
drivers/gpu/drm/mgag200/Kconfig +1
-0+ If unsure, say N.drivers/gpu/drm/mgag200/mgag200_drv.c +17
-0@@ -84,6 +84,20 @@ resource_size_t mgag200_probe_vram(void __iomem *mem, resource_size_t size)return offset -65536 ; } +#if defined(CONFIG_DRM_MGAG200_LATENCY_WORKAROUND ) +static struct drm_gem_object *mgag200_create_object (struct drm_device *dev,size_t size) +{ +struct drm_gem_shmem_object *shmem; + + shmem =kzalloc (sizeof (*shmem),GFP_KERNEL ); +if (!shmem) +return NULL ; + + shmem->map_wc = true; +return &shmem->base; +} +#endif +/* * DRM driver */ @@ -99,6 +113,9 @@ static const struct drm_driver mgag200_driver = { .major = DRIVER_MAJOR, .minor = DRIVER_MINOR, .patchlevel = DRIVER_PATCHLEVEL, +#if defined(CONFIG_DRM_MGAG200_LATENCY_WORKAROUND ) + .gem_create_object = mgag200_create_object, +#endif DRM_GEM_SHMEM_DRIVER_OPS, };drivers/gpu/drm/mgag200/mgag200_mode.c +8
-0@@ -13,6 +13,7 @@#include <drm/drm_atomic.h> #include <drm/drm_atomic_helper.h> +#include <drm/drm_cache.h> #include <drm/drm_damage_helper.h> #include <drm/drm_edid.h> #include <drm/drm_format_helper.h> @@ -436,6 +437,13 @@ static void mgag200_handle_damage(struct mga_device *mdev, const struct iosys_maiosys_map_incr (&dst,drm_fb_clip_offset (fb->pitches[0 ], fb->format, clip));drm_fb_memcpy (&dst, fb->pitches, vmap, fb, clip); + +/* Flushing the cache greatly improves latency on x86_64 */ +#if defined(CONFIG_DRM_MGAG200_LATENCY_WORKAROUND ) +if (!vmap->is_iomem) +drm_clflush_virt_range (vmap->vaddr + clip->y1 * fb->pitches[0 ], +drm_rect_height (clip) * fb->pitches[0 ]); +#endif }/* base-commit:
1f36d634670d8001a45fe2f2dcae546819f9c7d8
Signature · 7 lines
-- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Frankenstrasse 146, 90461 Nuernberg, Germany GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman HRB 36809 (AG Nuernberg)
Jocelyn Falempe
reviewerQuoted 23 lines · Thomas Zimmermann
Hi
Am 06.02.24 um 23:21 schrieb Jocelyn Falempe:
Quoted 20 lines
We found a regression in v5.10 on real-time server, using the rt-kernel and the mgag200 driver. It's some really specialized workload, with <10us latency expectation on isolated core. After the v5.10, the real time tasks missed their <10us latency when something prints on the screen (fbcon or printk)
The regression has been bisected to 2 commits:
commit0b34d58b6c32("drm/mgag200: Enable caching for SHMEM pages") commit4862ffaec523("drm/mgag200: Move vmap out of commit tail")The first one changed the system memory framebuffer from Write-Combine to the default caching.
Before the second commit, the mgag200 driver used to unmap the framebuffer after each frame, which implicitly does a cache flush. Both regressions are fixed by this commit, which restore WC mapping for the framebuffer in system memory, and add a cache flush. This is only needed onx86_64, for low-latency workload,
so the new kconfigDRM_MGAG200_LATENCY_WORKAROUNDdepends onPREEMPT_RTand X86.
Quoted 6 lines
Quoted 2 lines
For more context, the whole thread can be found here:
https://lore.kernel.org/dri-devel/[email protected]/This URL should be in a Link tag below the SoB line, like this:
Link https://lore.kernel.org/dri-devel/[email protected]/ # 1 You can refer to it from within the text with [1]. open here
ok
Quoted 31 lines
Quoted 16 lines
Signed-off-by Jocelyn Falempe <[email protected]>---
drivers/gpu/drm/mgag200/Kconfig | 10 ++++++++++ drivers/gpu/drm/mgag200/mgag200_drv.c | 17 +++++++++++++++++drivers/gpu/drm/mgag200/mgag200_mode.c| 8 ++++++++3 files changed, 35 insertions(+)drivers/gpu/drm/mgag200/Kconfig +0
-0@@ -11,3 +11,13 @@ config DRM_MGAG200MGA G200 desktop chips and the server variants. It requires 0.3.0 of the modesetting userspace driver, and a version of mga driver that will fail on KMS enabled devices.
drivers/gpu/drm/mgag200/Kconfig config DRM_MGAG200 · line 15
Quoted 2 lines
drivers/gpu/drm/mgag200/Kconfig +2
-0+ +config DRM_MGAG200_LATENCY_WORKAROUNDCan we call this
DRM_MGAG200_IOBURST_WORKAROUND? I know what you mean by latency, but that's not what is happening in the driver. The latency you refer to is the deterministic response time of your process, but the response time of the driver actually goes up (because of the disabled caching).Quoted 1 line
+ bool "Enable workaround for low latency server"
This is a 'low-latency server'. But I'd just say "Disabled buffer caching", so that users know what they are getting into.
Quoted 3 lines
+ depends on
DRM_MGAG200&&PREEMPT_RT&& X86
+ help
+ Enable a workaround to have better latency with mgag200 driver.Here I'd say "Enable a workaround to avoid I/O bursts within the mgag200 driver at the expense of overall display performance."
Quoted 8 lines
Quoted 4 lines
+ It restores the <v5.10 behavior, by mapping the framebuffer in system
+ RAM as Write-Combining, and flushing the cache after each write. + This is only needed onx86_64and if you want low-latency.Maybe "This is only useful on
x86_64if you want to run processes with deterministic latency."The code itself looks good to me.
Thanks, I will send a v2 with all these changes.
Signature · 1 line
Jocelyn
Quoted 67 lines
Best regards
ThomasQuoted 62 lines
+ If unsure, say N.
drivers/gpu/drm/mgag200/mgag200_drv.c +14
-0@@ -84,6 +84,20 @@ resource_size_t mgag200_probe_vram(void __iomem *mem, resource_size_t size) return offset - 65536; } +#if defined(CONFIG_DRM_MGAG200_LATENCY_WORKAROUND ) +static struct drm_gem_object *mgag200_create_object (struct drm_device *dev,size_t size) +{ + struct drm_gem_shmem_object *shmem; + + shmem = kzalloc(sizeof(*shmem), GFP_KERNEL); + if (!shmem) + return NULL; + + shmem->map_wc = true; + return &shmem->base; +} +#endif + /** DRM driver */
drivers/gpu/drm/mgag200/mgag200_drv.c +3
-0@@ -99,6 +113,9 @@ static const struct drm_driver mgag200_driver = { .major = DRIVER_MAJOR, .minor = DRIVER_MINOR, .patchlevel = DRIVER_PATCHLEVEL, +#if defined(CONFIG_DRM_MGAG200_LATENCY_WORKAROUND ) + .gem_create_object = mgag200_create_object, +#endif DRM_GEM_SHMEM_DRIVER_OPS, };drivers/gpu/drm/mgag200/mgag200_mode.c +1
-0@@ -13,6 +13,7 @@ #include <drm/drm_atomic.h> #include <drm/drm_atomic_helper.h> +#include <drm/drm_cache.h> #include <drm/drm_damage_helper.h> #include <drm/drm_edid.h> #include <drm/drm_format_helper.h>@@ -436,6 +437,13 @@ static void mgag200_handle_damage(struct
mga_device*mdev, const structiosys_ma
iosys_map_incr(&dst, drm_fb_clip_offset(fb->pitches[0], fb->format, clip));drm_fb_memcpy(&dst, fb->pitches, vmap, fb, clip);drivers/gpu/drm/mgag200/mgag200_mode.c +7
-0+ + /* Flushing the cache greatly improves latency on x86_64 */ +#if defined(CONFIG_DRM_MGAG200_LATENCY_WORKAROUND ) + if (!vmap->is_iomem) + drm_clflush_virt_range(vmap->vaddr + clip->y1 * fb->pitches[0], + drm_rect_height(clip) * fb->pitches[0]); +#endif }
/*base-commit:
1f36d634670d8001a45fe2f2dcae546819f9c7d8