Rate-limit shadow-FB-to-console-update to screen refresh
Subsystems (3)
Thomas Zimmermann
maintainerv3 cover Rate-limit shadow-FB-to-console-update to screen refresh
A full-screen memcpy() moves the console's shadow buffer to hardware; with possibly significant runtime overhead. [1] Synchronizing the screen update with VBLANK events can hopefully reduce the number of screen updates.
The patchset first adds vblank support to mgag200 as the problem was initially reported for Matrox hardware.
The console's dirty worker now waits for the vblank to rate limit the output frequency. Screen output can pile up while waiting and there's a chance that multiple screen updates can be handled with a single memcpy(). Note that this has no effect on tearing: while the dirty worker updates the hardware buffer, new data can still arrive in the shadow buffer. This can create a tearing effcet, even though console output is synchronized to vblank.
In version 2 of this patchset, fbdev emulation missed the first vblank event because mgag200 initialized the fbdev console before the irq. Initializing fbdev last fixes this problem. If other drivers now start reporting a missed vblank during boot, this might be the reason.
The patchset was tested by running fbdev emulation and Gnome (X11) on mgag200 HW.
v3:
* fbdev: hold helper->mutex
* fbdev: acquire DRM master so other masters cannot interfere
* mgag200: init fbdev after irq avoids missing first vblank
* mgag200: trigger irq at <vdisplay> + 1 matches vblank
v2:
* remove locking from fbdev patch
* use constants for mgag200 register names and fields
* double-check that VLINE irq is active on mgag200
* only signal vblank on CRTC 0 of mgag200
* coding-style fixes
[1] https://lists.freedesktop.org/archives/dri-devel/2019-July/228663.html
Thomas Zimmermann (4):
drm/mgag200: Create fbdev console after registering device drm/mgag200: Rename constant MGAREG_Status to MGAREG_STATUS drm/mgag200: Add vblank support
drm/fb-helper: Synchronize dirty worker with vblank
drivers/gpu/drm/drm_fb_helper.c | 21 ++++++++++ drivers/gpu/drm/mgag200/mgag200_drv.c | 7 ++++ drivers/gpu/drm/mgag200/mgag200_drv.h | 1 + drivers/gpu/drm/mgag200/mgag200_main.c | 38 +++++++++++++++++- drivers/gpu/drm/mgag200/mgag200_mode.c | 54 ++++++++++++++++++++++---- drivers/gpu/drm/mgag200/mgag200_reg.h | 7 +++- 6 files changed, 119 insertions(+), 9 deletions(-)
--
2.23.0
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerPATCH v3 1/4 drm/mgag200: Create fbdev console after registering device
Generic fbdev console emulation is a DRM client. For consistency with other clients, it should be created after registering the DRM device. Hence move the fbdev code to the appropriate place.
--- drivers/gpu/drm/mgag200/mgag200_drv.c | 6 ++++++ drivers/gpu/drm/mgag200/mgag200_main.c | 4 ---- 2 files changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/mgag200/mgag200_drv.c +6 -0
@@ -74,8 +74,14 @@ static int mga_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)if (ret) goto err_mgag200_driver_unload; + ret =drm_fbdev_generic_setup (dev,0 ); +if (ret) + goto err_mgag200_driver_unregister; +return 0 ; +err_mgag200_driver_unregister: +drm_dev_unregister (dev); err_mgag200_driver_unload:mgag200_driver_unload (dev); err_drm_dev_put:
drivers/gpu/drm/mgag200/mgag200_main.c +0 -4
@@ -181,10 +181,6 @@ int mgag200_driver_load(struct drm_device *dev, unsigned long flags)dev_warn (&dev->pdev->dev,"Could not initialize cursors. Not doing hardware cursors.\n" ); - r =drm_fbdev_generic_setup (mdev->dev,0 ); -if (r) - goto err_modeset; -return 0 ; err_modeset:
Signature · 6 lines
2.23.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerPATCH v3 2/4 drm/mgag200: Rename constant MGAREG_Status to MGAREG_STATUS
In reply to Thomas ZimmermannRegister constants are upper case. Fix MGAREG_Status accordingly.
--- drivers/gpu/drm/mgag200/mgag200_mode.c | 6 +++--- drivers/gpu/drm/mgag200/mgag200_reg.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/mgag200/mgag200_mode.c +3 -3
@@ -79,12 +79,12 @@ static inline void mga_wait_vsync(struct mga_device *mdev)unsigned int status =0 ;do { - status =RREG32 (MGAREG_Status); + status =RREG32 (MGAREG_STATUS ); }while ((status &0x08 ) &&time_before (jiffies, timeout)); timeout = jiffies +HZ /10 ; status =0 ;do { - status =RREG32 (MGAREG_Status); + status =RREG32 (MGAREG_STATUS ); }while (!(status &0x08 ) &&time_before (jiffies, timeout)); }
@@ -93,7 +93,7 @@ static inline void mga_wait_busy(struct mga_device *mdev)unsigned long timeout = jiffies +HZ ;unsigned int status =0 ;do { - status =RREG8 (MGAREG_Status +2 ); + status =RREG8 (MGAREG_STATUS +2 ); }while ((status &0x01 ) &&time_before (jiffies, timeout)); }
drivers/gpu/drm/mgag200/mgag200_reg.h +1 -1
@@ -101,7 +101,7 @@#define MGAREG_EXEC 0x0100#define MGAREG_FIFOSTATUS 0x1e10 -#define MGAREG_Status 0x1e14 +#define MGAREG_STATUS 0x1e14#define MGAREG_CACHEFLUSH 0x1fff#define MGAREG_ICLEAR 0x1e18#define MGAREG_IEN 0x1e1c
Signature · 6 lines
2.23.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerPATCH v3 3/4 drm/mgag200: Add vblank support
In reply to Thomas ZimmermannThere's no VBLANK interrupt on Matrox chipsets. The workaround that is being used here and in other free Matrox drivers is to program <linecomp> to the value of <vdisplay> + 1 and enable the VLINE interrupt. This triggers an interrupt at the time when VBLANK begins.
VLINE uses separate registers for enabling and clearing pending interrupts. No extra syncihronization between irq handler and the rest of the driver is required.
v3:
* set <linecomp> to <vdisplay> + 1 to trigger at VBLANK
* expand comment on linecomp
v2:
* only signal vblank on CRTC 0
* use constants for registers and fields
* set VLINECLR before enabling interrupt
* test against STATUS and IEN in irq handler
* coding-style fixes
--- drivers/gpu/drm/mgag200/mgag200_drv.c | 1 + drivers/gpu/drm/mgag200/mgag200_drv.h | 1 + drivers/gpu/drm/mgag200/mgag200_main.c | 40 +++++++++++++++++++++ drivers/gpu/drm/mgag200/mgag200_mode.c | 48 +++++++++++++++++++++++--- drivers/gpu/drm/mgag200/mgag200_reg.h | 5 +++ 5 files changed, 91 insertions(+), 4 deletions(-)
drivers/gpu/drm/mgag200/mgag200_drv.c +1 -0
@@ -133,6 +133,7 @@ int mgag200_driver_dumb_create(struct drm_file *file,static struct drm_driver driver = { .driver_features =DRIVER_GEM |DRIVER_MODESET , + .irq_handler = mgag200_irq_handler, .fops = &mgag200_driver_fops, .name =DRIVER_NAME , .desc =DRIVER_DESC ,
drivers/gpu/drm/mgag200/mgag200_drv.h +1 -0
@@ -206,6 +206,7 @@ void mgag200_modeset_fini(struct mga_device *mdev);/* mgag200_main.c */ int mgag200_driver_load (struct drm_device *dev,unsigned long flags);void mgag200_driver_unload (struct drm_device *dev); +irqreturn_t mgag200_irq_handler (int irq,void *arg);/* mgag200_i2c.c */ struct mga_i2c_chan *mgag200_i2c_create (struct drm_device *dev);
drivers/gpu/drm/mgag200/mgag200_main.c +40 -0
@@ -12,6 +12,8 @@#include <drm/drm_crtc_helper.h> #include <drm/drm_gem_framebuffer_helper.h> +#include <drm/drm_irq.h> +#include <drm/drm_vblank.h> #include "mgag200_drv.h"
@@ -181,6 +183,14 @@ int mgag200_driver_load(struct drm_device *dev, unsigned long flags)dev_warn (&dev->pdev->dev,"Could not initialize cursors. Not doing hardware cursors.\n" ); + r =drm_vblank_init (dev,1 ); +if (r) + goto err_modeset; + + r =drm_irq_install (dev, dev->pdev->irq); +if (r) + goto err_modeset; +return 0 ; err_modeset:
@@ -199,9 +209,39 @@ void mgag200_driver_unload(struct drm_device *dev)if (mdev ==NULL )return ; +drm_irq_uninstall (dev);mgag200_modeset_fini (mdev);drm_mode_config_cleanup (dev);mgag200_cursor_fini (mdev);mgag200_mm_fini (mdev); dev->dev_private =NULL ; } + +irqreturn_t mgag200_irq_handler (int irq,void *arg) +{ +struct drm_device *dev = arg; +struct mga_device *mdev = dev->dev_private; +struct drm_crtc *crtc; +u32 status, ien, iclear; + + status =RREG32 (MGAREG_STATUS ); + +if (status &MGA_VLINEPEN ) { + ien =RREG32 (MGAREG_IEN ); +if (!(ien &MGA_VLINEIEN )) + goto out; + + crtc =drm_crtc_from_index (dev,0 ); +if (WARN_ON_ONCE (!crtc)) + goto out; +drm_crtc_handle_vblank (crtc); + + iclear =RREG32 (MGAREG_ICLEAR ); + iclear |=MGA_VLINECLR ; +WREG32 (MGAREG_ICLEAR , iclear); +return IRQ_HANDLED ; + } + +out: +return IRQ_NONE ; +};
drivers/gpu/drm/mgag200/mgag200_mode.c +44 -4
94 lines not on this page · raw message
drivers/gpu/drm/mgag200/mgag200_reg.h +5 -0
@@ -122,6 +122,11 @@#define MGAREG_MEMCTL 0x2e08 +/* Interrupt fields */ +#define MGA_VLINEPEN (0x01 << 5) +#define MGA_VLINECLR (0x01 << 5) +#define MGA_VLINEIEN (0x01 << 5) +/* OPMODE register additives */ #define MGAOPM_DMA_GENERAL (0x00 << 2)
Signature · 6 lines
2.23.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v3 3/4] drm/mgag200: Add vblank support
Hi Thomas.
Some nits you can address when applying, if you think they shall be addressed.
Sam
Quoted 7 lines · Thomas Zimmermann
There's no VBLANK interrupt on Matrox chipsets. The workaround that is being used here and in other free Matrox drivers is to program <linecomp> to the value of <vdisplay> + 1 and enable the VLINE interrupt. This triggers an interrupt at the time when VBLANK begins.
VLINE uses separate registers for enabling and clearing pending interrupts. No extra syncihronization between irq handler and the rest of the driver is
s/syncihronization/synchronization/
Quoted 16 lines
required.
drivers/gpu/drm/mgag200/mgag200_mode.c +2
-2((vsyncstart &0x100 ) >>6 ) | ((vdisplay &0x100 ) >>5 ) | - ((vdisplay &0x100 ) >>4 ) |/* linecomp */ + ((linecomp &0x100 ) >>4 ) | ((vtotal &0x200 ) >>4 )| ((vdisplay &0x200 ) >>3 ) | ((vsyncstart & 0x200) >> 2));WREG_CRT (9 , ((vdisplay &0x200 ) >>4 ) | - ((vdisplay &0x200 ) >>3 )); + ((linecomp &0x200 ) >>3 ));WREG_CRT (10 ,0 );WREG_CRT (11 ,0 );WREG_CRT (12 ,0 );
drivers/gpu/drm/mgag200/mgag200_mode.c static int mga_crtc_mode_set(struct drm_crtc *crtc, · line 1096
Quoted 5 lines
drivers/gpu/drm/mgag200/mgag200_mode.c +1
-1@@ -1083,7 +1093,7 @@ static int mga_crtc_mode_set(struct drm_crtc *crtc,WREG_CRT (21 , vdisplay &0xFF );WREG_CRT (22 , (vtotal +1 ) &0xFF );WREG_CRT (23 ,0xc3 ); -WREG_CRT (24 , vdisplay &0xFF ); +WREG_CRT (24 , linecomp &0xff );
Use 0xFF like other code nearby?
Quoted 61 lines
drivers/gpu/drm/mgag200/mgag200_mode.c +31
-1ext_vga[0 ] =0 ; ext_vga[5 ] =0 ;@@ -1099,7 +1109,7 @@ static int mga_crtc_mode_set(struct drm_crtc *crtc, ((vdisplay &0x400 ) >>8 ) | ((vdisplay &0xc00 ) >>7 ) | ((vsyncstart &0xc00 ) >>5 ) | - ((vdisplay &0x400 ) >>3 ); + ((linecomp &0x400 ) >>3 );if (fb->format->cpp[0 ] *8 ==24 ) ext_vga[3 ] = (((1 << bppshift) *3 ) -1 ) |0x80 ;else @@ -1411,6 +1421,34 @@ static void mga_crtc_disable(struct drm_crtc *crtc) crtc->primary->fb =NULL ; } +static int mga_crtc_enable_vblank (struct drm_crtc *crtc) +{ +struct drm_device *dev = crtc->dev; +struct mga_device *mdev = dev->dev_private; +u32 iclear, ien; + + iclear =RREG32 (MGAREG_ICLEAR ); + iclear |=MGA_VLINECLR ; +WREG32 (MGAREG_ICLEAR , iclear); + + ien =RREG32 (MGAREG_IEN ); + ien |=MGA_VLINEIEN ; +WREG32 (MGAREG_IEN , ien); + +return 0 ; +} + +static void mga_crtc_disable_vblank (struct drm_crtc *crtc) +{ +struct drm_device *dev = crtc->dev; +struct mga_device *mdev = dev->dev_private; +u32 ien; + + ien =RREG32 (MGAREG_IEN ); + ien &= ~(MGA_VLINEIEN ); +WREG32 (MGAREG_IEN , ien); +} +/* These provide the minimum set of functions required to handle a CRTC */ static const struct drm_crtc_funcs mga_crtc_funcs = { .cursor_set = mgag200_crtc_cursor_set,@@ -1418,6 +1456,8 @@ static const struct drm_crtc_funcs mga_crtc_funcs = { .gamma_set = mga_crtc_gamma_set, .set_config = drm_crtc_helper_set_config, .destroy = mga_crtc_destroy, + .enable_vblank = mga_crtc_enable_vblank, + .disable_vblank = mga_crtc_disable_vblank, };static const struct drm_crtc_helper_funcs mga_helper_funcs = {drivers/gpu/drm/mgag200/mgag200_reg.h +0
-0
drivers/gpu/drm/mgag200/mgag200_reg.h line 128
Quoted 7 lines
drivers/gpu/drm/mgag200/mgag200_reg.h +4
-0@@ -122,6 +122,11 @@#define MGAREG_MEMCTL 0x2e08 +/* Interrupt fields */ +#define MGA_VLINEPEN (0x01 << 5) +#define MGA_VLINECLR (0x01 << 5) +#define MGA_VLINEIEN (0x01 << 5)
Use BIT(5)?
The bitfield name could be more readable if they included the register name.
Example:
#define MGA_STATUS_VLINEPEN BIT(5)
#define MGA_ICLEAR_VLINECLR BIT(5)
#define MGA_IEN_VLINEIEN BIT(5)
Sam
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerRe: [PATCH v3 3/4] drm/mgag200: Add vblank support
Hi
Am 05.12.19 um 18:25 schrieb Sam Ravnborg:
Quoted 8 lines
Hi Thomas.
Some nits you can address when applying, if you think they shall be addressed.
Sam
On Thu, Dec 05, 2019 at 05:01:41PM +0100, Thomas Zimmermann wrote:
Quoted 8 lines
Quoted 7 lines
There's no VBLANK interrupt on Matrox chipsets. The workaround that is being used here and in other free Matrox drivers is to program <linecomp> to the value of <vdisplay> + 1 and enable the VLINE interrupt. This triggers an interrupt at the time when VBLANK begins.
VLINE uses separate registers for enabling and clearing pending interrupts. No extra syncihronization between irq handler and the rest of the driver is
s/syncihronization/synchronization/
Oh.
Quoted 15 lines
Quoted 15 lines
required.
drivers/gpu/drm/mgag200/mgag200_mode.c +2
-2((vsyncstart &0x100 ) >>6 ) | ((vdisplay &0x100 ) >>5 ) | - ((vdisplay &0x100 ) >>4 ) |/* linecomp */ + ((linecomp &0x100 ) >>4 ) | ((vtotal &0x200 ) >>4 )| ((vdisplay &0x200 ) >>3 ) | ((vsyncstart & 0x200) >> 2));WREG_CRT (9 , ((vdisplay &0x200 ) >>4 ) | - ((vdisplay &0x200 ) >>3 )); + ((linecomp &0x200 ) >>3 ));WREG_CRT (10 ,0 );WREG_CRT (11 ,0 );
Quoted 8 lines
drivers/gpu/drm/mgag200/mgag200_mode.c static int mga_crtc_mode_set(struct drm_crtc *crtc, · line 1096
Quoted 7 lines
drivers/gpu/drm/mgag200/mgag200_mode.c +1
-1WREG_CRT (12 ,0 );@@ -1083,7 +1093,7 @@ static int mga_crtc_mode_set(struct drm_crtc *crtc,WREG_CRT (21 , vdisplay &0xFF );WREG_CRT (22 , (vtotal +1 ) &0xFF );WREG_CRT (23 ,0xc3 ); -WREG_CRT (24 , vdisplay &0xFF ); +WREG_CRT (24 , linecomp &0xff );Use
0xFFlike other code nearby?
The code in this file is a mixture of numbers in upper and lower case. I used lower case here as I found if more pleasant to read. Hopefully the other constants can be switched when the code is converted to atomic modesetting.
Quoted 65 lines
Quoted 65 lines
drivers/gpu/drm/mgag200/mgag200_mode.c +31
-1ext_vga[0 ] =0 ; ext_vga[5 ] =0 ;@@ -1099,7 +1109,7 @@ static int mga_crtc_mode_set(struct drm_crtc *crtc, ((vdisplay &0x400 ) >>8 ) | ((vdisplay &0xc00 ) >>7 ) | ((vsyncstart &0xc00 ) >>5 ) | - ((vdisplay &0x400 ) >>3 ); + ((linecomp &0x400 ) >>3 );if (fb->format->cpp[0 ] *8 ==24 ) ext_vga[3 ] = (((1 << bppshift) *3 ) -1 ) |0x80 ;else @@ -1411,6 +1421,34 @@ static void mga_crtc_disable(struct drm_crtc *crtc) crtc->primary->fb =NULL ; } +static int mga_crtc_enable_vblank (struct drm_crtc *crtc) +{ +struct drm_device *dev = crtc->dev; +struct mga_device *mdev = dev->dev_private; +u32 iclear, ien; + + iclear =RREG32 (MGAREG_ICLEAR ); + iclear |=MGA_VLINECLR ; +WREG32 (MGAREG_ICLEAR , iclear); + + ien =RREG32 (MGAREG_IEN ); + ien |=MGA_VLINEIEN ; +WREG32 (MGAREG_IEN , ien); + +return 0 ; +} + +static void mga_crtc_disable_vblank (struct drm_crtc *crtc) +{ +struct drm_device *dev = crtc->dev; +struct mga_device *mdev = dev->dev_private; +u32 ien; + + ien =RREG32 (MGAREG_IEN ); + ien &= ~(MGA_VLINEIEN ); +WREG32 (MGAREG_IEN , ien); +} +/* These provide the minimum set of functions required to handle a CRTC */ static const struct drm_crtc_funcs mga_crtc_funcs = { .cursor_set = mgag200_crtc_cursor_set,@@ -1418,6 +1456,8 @@ static const struct drm_crtc_funcs mga_crtc_funcs = { .gamma_set = mga_crtc_gamma_set, .set_config = drm_crtc_helper_set_config, .destroy = mga_crtc_destroy, + .enable_vblank = mga_crtc_enable_vblank, + .disable_vblank = mga_crtc_disable_vblank, };static const struct drm_crtc_helper_funcs mga_helper_funcs = {drivers/gpu/drm/mgag200/mgag200_reg.h +0
-0@@ -122,6 +122,11 @@#define MGAREG_MEMCTL 0x2e08
Quoted 11 lines
drivers/gpu/drm/mgag200/mgag200_reg.h line 128
Quoted 4 lines
drivers/gpu/drm/mgag200/mgag200_reg.h +4
-0+/* Interrupt fields */ +#define MGA_VLINEPEN (0x01 << 5) +#define MGA_VLINECLR (0x01 << 5) +#define MGA_VLINEIEN (0x01 << 5)Use BIT(5)?
The bitfield name could be more readable if they included the register name.
Example:
#defineMGA_STATUS_VLINEPENBIT(5)
#defineMGA_ICLEAR_VLINECLRBIT(5)
#defineMGA_IEN_VLINEIENBIT(5)
Oh, good point. I wasn't aware of this macro.
Best regards
Thomas
Quoted 7 lines
Sam
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
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: Felix Imendörffer
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Emil Velikov
Reviewed-byRe: [PATCH v3 3/4] drm/mgag200: Add vblank support
Quoted 12 lines · Thomas Zimmermann
Quoted 11 lines
drivers/gpu/drm/mgag200/mgag200_reg.h line 128
Quoted 4 lines
drivers/gpu/drm/mgag200/mgag200_reg.h +4
-0+/* Interrupt fields */ +#define MGA_VLINEPEN (0x01 << 5) +#define MGA_VLINECLR (0x01 << 5) +#define MGA_VLINEIEN (0x01 << 5)Use BIT(5)?
The bitfield name could be more readable if they included the register name.
Example:#define MGA_STATUS_VLINEPEN BIT(5) #define MGA_ICLEAR_VLINECLR BIT(5) #define MGA_IEN_VLINEIEN BIT(5)
Quoted 2 lines
Oh, good point. I wasn't aware of this macro.
While at it, please keep bitfields close to the respective registers.
Don't know much about the driver to review this, for 1&2
I'll look at 4/4 first thing tomorrow.
Thanks
Emil
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerPATCH v3 4/4 drm/fb-helper: Synchronize dirty worker with vblank
In reply to Thomas ZimmermannBefore updating the display from the console's shadow buffer, the dirty worker now waits for a vblank. This allows several screen updates to pile up and acts as a rate limiter. If a DRM master is present, it could interfere with the vblank. Don't wait in this case.
v3:
* add back helper->lock
* acquire DRM master status while waiting for vblank
v2:
* don't hold helper->lock while waiting for vblank
--- drivers/gpu/drm/drm_fb_helper.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
drivers/gpu/drm/drm_fb_helper.c +21 -0
@@ -404,8 +404,29 @@ static void drm_fb_helper_dirty_work(struct work_struct *work) dirty_work);struct drm_clip_rect *clip = &helper->dirty_clip;struct drm_clip_rect clip_copy; +struct drm_crtc *crtc;unsigned long flags;void *vaddr; +int ret; + +/* +* Rate-limit update frequency to vblank. If there's a DRM master +* present, it could interfere while we're waiting for the vblank +* event. Don't wait in this case. +*/ +mutex_lock (&helper->lock); +if (!drm_master_internal_acquire (helper->dev)) { + goto unlock; + } + crtc = helper->client.modesets[0 ].crtc; + ret =drm_crtc_vblank_get (crtc); +if (!ret) { +drm_crtc_wait_one_vblank (crtc); +drm_crtc_vblank_put (crtc); + } +drm_master_internal_release (helper->dev); +unlock: +mutex_unlock (&helper->lock);spin_lock_irqsave (&helper->dirty_lock, flags); clip_copy = *clip;
Signature · 6 lines
2.23.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v3 4/4] drm/fb-helper: Synchronize dirty worker with vblank
Hi Thomas,
Quoted 39 lines · Thomas Zimmermann
Before updating the display from the console's shadow buffer, the dirty worker now waits for a vblank. This allows several screen updates to pile up and acts as a rate limiter. If a DRM master is present, it could interfere with the vblank. Don't wait in this case.
v3:
* add backhelper->lock
* acquire DRM master status while waiting for vblank
v2:
* don't holdhelper->lockwhile waiting for vblankSigned-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/drm_fb_helper.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)drivers/gpu/drm/drm_fb_helper.c +12
-0@@ -404,8 +404,29 @@ static void drm_fb_helper_dirty_work(struct work_struct *work) dirty_work);struct drm_clip_rect *clip = &helper->dirty_clip;struct drm_clip_rect clip_copy; +struct drm_crtc *crtc;unsigned long flags;void *vaddr; +int ret; + +/* +* Rate-limit update frequency to vblank. If there's a DRM master +* present, it could interfere while we're waiting for the vblank +* event. Don't wait in this case. +*/ +mutex_lock (&helper->lock); +if (!drm_master_internal_acquire (helper->dev)) { + goto unlock; + }
drivers/gpu/drm/drm_fb_helper.c static void drm_fb_helper_dirty_work(struct work_struct *work) · line 430
Quoted 10 lines
drivers/gpu/drm/drm_fb_helper.c +9
-0+ crtc = helper->client.modesets[0 ].crtc; + ret =drm_crtc_vblank_get (crtc); +if (!ret) { +drm_crtc_wait_one_vblank (crtc); +drm_crtc_vblank_put (crtc); + } +drm_master_internal_release (helper->dev); +unlock: +mutex_unlock (&helper->lock);
This hunk seems surprisingly similar to the FBIO_WAITFORVSYNC code in drm_fb_helper_ioctl().
Modulo the really neat comment, which answers the "why do we use modeset[0]" instead of any other (or all).
Can I suggest fleshing that function out (alongside all the locking) into a helper and reusing it here.
Pretty sure we can live with the (very unlikely) EBUSY -> ENOTTY change, in drm_fb_helper_ioctl()
HTH
Emil
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Hi Thomas.
Quoted 35 lines · Thomas Zimmermann
A full-screen
memcpy()moves the console's shadow buffer to hardware; with possibly significant runtime overhead. [1] Synchronizing the screen update with VBLANK events can hopefully reduce the number of screen updates.The patchset first adds vblank support to mgag200 as the problem was initially reported for Matrox hardware.
The console's dirty worker now waits for the vblank to rate limit the output frequency. Screen output can pile up while waiting and there's a chance that multiple screen updates can be handled with a single
memcpy(). Note that this has no effect on tearing: while the dirty worker updates the hardware buffer, new data can still arrive in the shadow buffer. This can create a tearing effcet, even though console output is synchronized to vblank.In version 2 of this patchset, fbdev emulation missed the first vblank event because mgag200 initialized the fbdev console before the irq. Initializing fbdev last fixes this problem. If other drivers now start reporting a missed vblank during boot, this might be the reason.
The patchset was tested by running fbdev emulation and Gnome (X11) on mgag200 HW.
v3:
* fbdev: holdhelper->mutex
* fbdev: acquire DRM master so other masters cannot interfere
* mgag200: init fbdev after irq avoids missing first vblank
* mgag200: trigger irq at <vdisplay> + 1 matches vblank
v2:
* remove locking from fbdev patch
* use constants for mgag200 register names and fields
* double-check that VLINE irq is active on mgag200
* only signal vblank on CRTC 0 of mgag200
* coding-style fixes
Quoted 7 lines
[1] https://lists.freedesktop.org/archives/dri-devel/2019-July/228663.html
Thomas Zimmermann (4):
drm/mgag200: Create fbdev console after registering device drm/mgag200: Rename constantMGAREG_StatustoMGAREG_STATUSdrm/mgag200: Add vblank support
drm/fb-helper: Synchronize dirty worker with vblank
Whole series is:
The code all looked good, but I am not familiar enough with the code to say I reviewed it all.
A few nits in one patch sent in a separate mail.
Sam
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel