drm/bochs: use devm_ioremap_wc() to map framebuffer
Subsystems (5)
PATCH v2 1/1 drm/bochs: use devm_ioremap_wc() to map framebuffer
Opt for devm_ioremap_wc() over devm_ioremap() when mapping the framebuffer.
Using devm_ioremap() results in the VA being mapped with PAT=UC-, which considerably slows down drm_fb_memcpy(). In contrast, devm_ioremap_wc() maps the VA with PAT set to WC, leading to better performance on platforms where access to UC memory is much slower than WC memory.
Here's the performance data measured in a guest on the physical machine "Sapphire Rapids XCC".
With host KVM honors guest PAT memory types, the effective memory type for this framebuffer range is
- WC when devm_ioremap_wc() is used
- UC- when devm_ioremap() is used.
The data presented is an average from 10 execution runs.
Cycles: Avg cycles of executed bochs_primary_plane_helper_atomic_update()
from VM boot to GDM show up
Cnt: Avg cnt of executed bochs_primary_plane_helper_atomic_update()
from VM boot to GDM show up
T: Avg time of each bochs_primary_plane_helper_atomic_update().
-------------------------------------------------
| | devm_ioremap() | devm_ioremap_wc() | |------------|----------------|-------------------| | Cycles | 211.545M | 0.157M | |------------|----------------|-------------------| | Cnt | 142 | 1917 | |------------|----------------|-------------------| | T | 0.1748s | 0.0004s |
-------------------------------------------------
Note:
Following the rebase to [3], the previously reported GDM failure on the VGA device [1] can no longer be reproduced, thanks to the memory management improvements made in [2]. Despite this, I have proceeded to submit this patch because of the noticeable performance improvements it provides.
---
v2:
- Rebased to the latest drm-misc-next branch. [2]
- Updated patch log to match the base code.
v1: https://lore.kernel.org/all/[email protected]
--- drivers/gpu/drm/tiny/bochs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/tiny/bochs.c +1 -1
@@ -268,7 +268,7 @@ static int bochs_hw_init(struct bochs_device *bochs)if (!devm_request_mem_region (&pdev->dev, addr, size,"bochs-drm" ))DRM_WARN ("Cannot request framebuffer, boot fb still active?\n" ); - bochs->fb_map =devm_ioremap (&pdev->dev, addr, size); + bochs->fb_map =devm_ioremap_wc (&pdev->dev, addr, size);if (bochs->fb_map ==NULL ) {DRM_ERROR ("Cannot map framebuffer\n" );return -ENOMEM ;
Signature · 1 line
2.43.2
Hi
Am 09.09.24 um 15:16 schrieb Yan Zhao:
Quoted 23 lines
Opt for
devm_ioremap_wc()overdevm_ioremap()when mapping the framebuffer.Using
devm_ioremap()results in the VA being mapped with PAT=UC-, which considerably slows downdrm_fb_memcpy(). In contrast,devm_ioremap_wc()maps the VA with PAT set to WC, leading to better performance on platforms where access to UC memory is much slower than WC memory.Here's the performance data measured in a guest on the physical machine "Sapphire Rapids XCC".
With host KVM honors guest PAT memory types, the effective memory type for this framebuffer range is
- WC whendevm_ioremap_wc()is used
- UC- whendevm_ioremap()is used.The data presented is an average from 10 execution runs.
Cycles: Avg cycles of executed
bochs_primary_plane_helper_atomic_update()
from VM boot to GDM show up
Cnt: Avg cnt of executedbochs_primary_plane_helper_atomic_update()
from VM boot to GDM show up
T: Avg time of eachbochs_primary_plane_helper_atomic_update().-------------------------------------------------
Quoted 8 lines
| | devm_ioremap() | devm_ioremap_wc() | |------------|----------------|-------------------| | Cycles | 211.545M | 0.157M | |------------|----------------|-------------------| | Cnt | 142 | 1917 | |------------|----------------|-------------------| | T | 0.1748s | 0.0004s |-------------------------------------------------
Very nice. Thank you so much.
Quoted 6 lines
Note:
Following the rebase to [3], the previously reported GDM failure on the VGA device [1] can no longer be reproduced, thanks to the memory management improvements made in [2]. Despite this, I have proceeded to submit this patch because of the noticeable performance improvements it provides.
Quoted 10 lines
Reported-by Vitaly Kuznetsov <[email protected]>Cc Sean Christopherson <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Kevin Tian <[email protected]>Cc Thomas Zimmermann <[email protected]>Signed-off-by Yan Zhao <[email protected]>
If no other reviews come in, I'll merge the patch by the end of the week.
Best regards
Thomas
Quoted 23 lines
---
v2:
- Rebased to the latest drm-misc-next branch. [2]
- Updated patch log to match the base code.v1: https://lore.kernel.org/all/[email protected]
--- drivers/gpu/drm/tiny/bochs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/tiny/bochs.c +1
-1@@ -268,7 +268,7 @@ static int bochs_hw_init(struct bochs_device *bochs)if (!devm_request_mem_region (&pdev->dev, addr, size,"bochs-drm" ))DRM_WARN ("Cannot request framebuffer, boot fb still active?\n" ); - bochs->fb_map =devm_ioremap (&pdev->dev, addr, size); + bochs->fb_map =devm_ioremap_wc (&pdev->dev, addr, size);if (bochs->fb_map ==NULL ) {DRM_ERROR ("Cannot map framebuffer\n" );return -ENOMEM ;
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)
Quoted 2 lines · Thomas Zimmermann
Reviewed-by Thomas Zimmermann <[email protected]>Texted-by Thomas Zimmermann <[email protected]>
Thank you!
I suppose this is "Tested-by", right?
Am 10.09.24 um 10:05 schrieb Yan Zhao:
Quoted 5 lines · Thomas Zimmermann
Quoted 2 lines
Reviewed-by Thomas Zimmermann <[email protected]>Texted-by Thomas Zimmermann <[email protected]>Thank you!
I suppose this is "Tested-by", right?
Yes
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)
Quoted 32 lines · Yan Zhao
Opt for
devm_ioremap_wc()overdevm_ioremap()when mapping the framebuffer.Using
devm_ioremap()results in the VA being mapped with PAT=UC-, which considerably slows downdrm_fb_memcpy(). In contrast,devm_ioremap_wc()maps the VA with PAT set to WC, leading to better performance on platforms where access to UC memory is much slower than WC memory.Here's the performance data measured in a guest on the physical machine "Sapphire Rapids XCC".
With host KVM honors guest PAT memory types, the effective memory type for this framebuffer range is
- WC whendevm_ioremap_wc()is used
- UC- whendevm_ioremap()is used.The data presented is an average from 10 execution runs.
Cycles: Avg cycles of executed
bochs_primary_plane_helper_atomic_update()
from VM boot to GDM show up
Cnt: Avg cnt of executedbochs_primary_plane_helper_atomic_update()
from VM boot to GDM show up
T: Avg time of eachbochs_primary_plane_helper_atomic_update().-------------------------------------------------
| | devm_ioremap() | devm_ioremap_wc() | |------------|----------------|-------------------| | Cycles | 211.545M | 0.157M | |------------|----------------|-------------------| | Cnt | 142 | 1917 | |------------|----------------|-------------------| | T | 0.1748s | 0.0004s |-------------------------------------------------
Quoted 7 lines
Note:
Following the rebase to [3], the previously reported GDM failure on the VGA device [1] can no longer be reproduced, thanks to the memory management improvements made in [2]. Despite this, I have proceeded to submit this patch because of the noticeable performance improvements it provides.Reported-by Vitaly Kuznetsov <[email protected]>
FWIW, this patch (alone) resolves the observed issue, thanks!
I, however, share Paolo's concern around existing VMs which KVM's change is effectively breaking.
Quoted 32 lines
Cc Sean Christopherson <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Kevin Tian <[email protected]>Cc Thomas Zimmermann <[email protected]>Signed-off-by Yan Zhao <[email protected]>---
v2:
- Rebased to the latest drm-misc-next branch. [2]
- Updated patch log to match the base code.v1: https://lore.kernel.org/all/[email protected]
--- drivers/gpu/drm/tiny/bochs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/tiny/bochs.c +1
-1@@ -268,7 +268,7 @@ static int bochs_hw_init(struct bochs_device *bochs)if (!devm_request_mem_region (&pdev->dev, addr, size,"bochs-drm" ))DRM_WARN ("Cannot request framebuffer, boot fb still active?\n" ); - bochs->fb_map =devm_ioremap (&pdev->dev, addr, size); + bochs->fb_map =devm_ioremap_wc (&pdev->dev, addr, size);if (bochs->fb_map ==NULL ) {DRM_ERROR ("Cannot map framebuffer\n" );return -ENOMEM ;
Signature · 1 line
Vitaly