drm: Fix off-by-one in vblank hardware counter wraparound handling
Subsystems (3)
PATCH 1/2 drm: Fix off-by-one in vblank hardware counter wraparound handling
From: Michel Dänzer <[email protected]>
dev->max_vblank_count contains the largest value that can be represented by the hardware counter. When the hardware counter wraps around, we have to add that value + 1 to get the same value as if the hardware counter didn't wrap around.
--- drivers/gpu/drm/drm_irq.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_irq.c +2 -2
@@ -100,7 +100,7 @@ static void drm_update_vblank_count(struct drm_device *dev, int crtc)/* * Interrupts were disabled prior to this call, so deal with counter * wrap if needed. -* NOTE! It's possible we lost a full dev->max_vblank_count events +* NOTE! It's possible we lost a full dev->max_vblank_count + 1 events * here if the register is small or we had vblank interrupts off for * a long time. *
@@ -117,7 +117,7 @@ static void drm_update_vblank_count(struct drm_device *dev, int crtc)/* Deal with counter wrap */ diff = cur_vblank - vblank->last;if (cur_vblank < vblank->last) { - diff += dev->max_vblank_count; + diff += dev->max_vblank_count +1 ;DRM_DEBUG ("last_vblank[%d]=0x%x, cur_vblank=0x%x => diff=0x%x\n" , crtc, vblank->last, cur_vblank, diff);
Signature · 6 lines
2.1.4 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 2/2 drm/radeon: Fix max_vblank_count value for current display engines
From: Michel Dänzer <[email protected]>
The value was much too low, which could cause the userspace visible vblank counter to move backwards when the hardware counter wrapped around.
--- drivers/gpu/drm/radeon/radeon_irq_kms.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/radeon/radeon_irq_kms.c +7 -1
@@ -143,7 +143,13 @@ void radeon_driver_irq_preinstall_kms(struct drm_device *dev)*/ int radeon_driver_irq_postinstall_kms (struct drm_device *dev) { - dev->max_vblank_count =0x001fffff ; +struct radeon_device *rdev = dev->dev_private; + +if (ASIC_IS_AVIVO (rdev)) + dev->max_vblank_count =0x00ffffff ; +else + dev->max_vblank_count =0x001fffff ; +return 0 ; }
Signature · 6 lines
2.1.4 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Alex Deucher
AppliedRe: [PATCH 2/2] drm/radeon: Fix max_vblank_count value for current display engines
Quoted 7 lines · Michel Dänzer
From: Michel Dänzer <[email protected]>
The value was much too low, which could cause the userspace visible vblank counter to move backwards when the hardware counter wrapped around.
Signed-off-by Michel Dänzer <[email protected]>
Applied to my -next tree.
Thanks!
Quoted 26 lines
--- drivers/gpu/drm/radeon/radeon_irq_kms.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)drivers/gpu/drm/radeon/radeon_irq_kms.c +7
-2@@ -143,7 +143,13 @@ void radeon_driver_irq_preinstall_kms(struct drm_device *dev)*/ int radeon_driver_irq_postinstall_kms (struct drm_device *dev) { - dev->max_vblank_count =0x001fffff ; +struct radeon_device *rdev = dev->dev_private; + +if (ASIC_IS_AVIVO (rdev)) + dev->max_vblank_count =0x00ffffff ; +else + dev->max_vblank_count =0x001fffff ; +return 0 ; } --2.1.4
Quoted 4 lines
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Nice catch! Both patches in this series are Reviewed-by: Christian König <[email protected]>
Quoted 26 lines · Michel Dänzer
From: Michel Dänzer <[email protected]>
dev->max_vblank_countcontains the largest value that can be represented by the hardware counter. When the hardware counter wraps around, we have to add that value + 1 to get the same value as if the hardware counter didn't wrap around.Signed-off-by Michel Dänzer <[email protected]>--- drivers/gpu/drm/drm_irq.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/drm_irq.c +1
-1@@ -100,7 +100,7 @@ static void drm_update_vblank_count(struct drm_device *dev, int crtc)/* * Interrupts were disabled prior to this call, so deal with counter * wrap if needed. -* NOTE! It's possible we lost a full dev->max_vblank_count events +* NOTE! It's possible we lost a full dev->max_vblank_count + 1 events * here if the register is small or we had vblank interrupts off for * a long time. *
drivers/gpu/drm/drm_irq.c static void drm_update_vblank_count(struct drm_device *dev, int crtc) · line 123
Quoted 8 lines
drivers/gpu/drm/drm_irq.c +1
-1@@ -117,7 +117,7 @@ static void drm_update_vblank_count(struct drm_device *dev, int crtc)/* Deal with counter wrap */ diff = cur_vblank - vblank->last;if (cur_vblank < vblank->last) { - diff += dev->max_vblank_count; + diff += dev->max_vblank_count +1 ;DRM_DEBUG ("last_vblank[%d]=0x%x, cur_vblank=0x%x => diff=0x%x\n" , crtc, vblank->last, cur_vblank, diff);
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 8 lines · Michel Dänzer
From: Michel Dänzer <[email protected]>
dev->max_vblank_countcontains the largest value that can be represented by the hardware counter. When the hardware counter wraps around, we have to add that value + 1 to get the same value as if the hardware counter didn't wrap around.Signed-off-by Michel Dänzer <[email protected]>
Well there's two users of this really, one wants the max (this one here) and the other a mask. And all the drivers use it as a mask. Maybe rename it to vblank_counter_mask or similar while at it to prevent further confusion?
-Daniel
Quoted 33 lines
--- drivers/gpu/drm/drm_irq.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/drm_irq.c +2
-2@@ -100,7 +100,7 @@ static void drm_update_vblank_count(struct drm_device *dev, int crtc)/* * Interrupts were disabled prior to this call, so deal with counter * wrap if needed. -* NOTE! It's possible we lost a full dev->max_vblank_count events +* NOTE! It's possible we lost a full dev->max_vblank_count + 1 events * here if the register is small or we had vblank interrupts off for * a long time. * @@ -117,7 +117,7 @@ static void drm_update_vblank_count(struct drm_device *dev, int crtc)/* Deal with counter wrap */ diff = cur_vblank - vblank->last;if (cur_vblank < vblank->last) { - diff += dev->max_vblank_count; + diff += dev->max_vblank_count +1 ;DRM_DEBUG ("last_vblank[%d]=0x%x, cur_vblank=0x%x => diff=0x%x\n" , crtc, vblank->last, cur_vblank, diff);Signature · 6 lines
2.1.4 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 8 lines · Daniel Vetter
Quoted 7 lines · Michel Dänzer
From: Michel Dänzer <[email protected]>
dev->max_vblank_countcontains the largest value that can be represented by the hardware counter. When the hardware counter wraps around, we have to add that value + 1 to get the same value as if the hardware counter didn't wrap around.
Quoted 4 lines
Quoted 1 line
Signed-off-by Michel Dänzer <[email protected]>Well there's two users of this really, one wants the max (this one here) and the other a mask.
Well, this one has been around much longer. :) Looks like drm_vblank_on added a (probably valid, see below) assumption without updating the field name to reflect that.
Quoted 1 line
And all the drivers use it as a mask.
How so? They just assign the value, which happens to work for both meanings above in all cases.
Quoted 2 lines
Maybe rename it to
vblank_counter_maskor similar while at it to prevent further confusion?
I'm just fixing an off-by-one bug here; I invite you or anyone else to be my guest for anything more. :)
Signature · 6 lines
Earthling Michel Dänzer | http://www.amd.com Libre software enthusiast | Mesa and X developer _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 9 lines · Michel Dänzer
Quoted 8 lines · Daniel Vetter
Quoted 7 lines · Michel Dänzer
From: Michel Dänzer <[email protected]>
dev->max_vblank_countcontains the largest value that can be represented by the hardware counter. When the hardware counter wraps around, we have to add that value + 1 to get the same value as if the hardware counter didn't wrap around.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Michel Dänzer <[email protected]>Well there's two users of this really, one wants the max (this one here) and the other a mask.
Well, this one has been around much longer. :) Looks like
drm_vblank_onadded a (probably valid, see below) assumption without updating the field name to reflect that.
Yeah, might be clearer to open-code the (slower) divide just for clarity. Anyway applied this patch to drm-misc.
Quoted 4 lines
Quoted 1 line
And all the drivers use it as a mask.
How so? They just assign the value, which happens to work for both meanings above in all cases.
Yeah I had the usual confusion about where exactly we start counting here ;-) I was thinking of num_vblank_counts_before_wrap vs. mask. -Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 8 lines · Daniel Vetter
Quoted 7 lines · Michel Dänzer
From: Michel Dänzer <[email protected]>
dev->max_vblank_countcontains the largest value that can be represented by the hardware counter. When the hardware counter wraps around, we have to add that value + 1 to get the same value as if the hardware counter didn't wrap around.
Quoted 6 lines
Quoted 1 line
Signed-off-by Michel Dänzer <[email protected]>Well there's two users of this really, one wants the max (this one here) and the other a mask. And all the drivers use it as a mask. Maybe rename it to
vblank_counter_maskor similar while at it to prevent further confusion?
Well, really it's just 'value % (max + 1)'. Just happens to work with & since it's POT-1.
Quoted 44 lines
-Daniel
Quoted 33 lines
--- drivers/gpu/drm/drm_irq.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/drm_irq.c +2
-2@@ -100,7 +100,7 @@ static void drm_update_vblank_count(struct drm_device *dev, int crtc)/* * Interrupts were disabled prior to this call, so deal with counter * wrap if needed. -* NOTE! It's possible we lost a full dev->max_vblank_count events +* NOTE! It's possible we lost a full dev->max_vblank_count + 1 events * here if the register is small or we had vblank interrupts off for * a long time. * @@ -117,7 +117,7 @@ static void drm_update_vblank_count(struct drm_device *dev, int crtc)/* Deal with counter wrap */ diff = cur_vblank - vblank->last;if (cur_vblank < vblank->last) { - diff += dev->max_vblank_count; + diff += dev->max_vblank_count +1 ;DRM_DEBUG ("last_vblank[%d]=0x%x, cur_vblank=0x%x => diff=0x%x\n" , crtc, vblank->last, cur_vblank, diff);Signature · 6 lines
2.1.4 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-develSignature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 6 lines
Ville Syrjälä Intel OTC _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel