Bug 103791

Summary: Tearing after screen wakeup/on
Product: xorg Reporter: denisgolovan
Component: Driver/AMDgpuAssignee: xf86-video-ati maintainers <xorg-driver-ati>
Status: RESOLVED FIXED QA Contact: Xorg Project Team <xorg-team>
Severity: normal    
Priority: medium    
Version: git   
Hardware: Other   
OS: All   
Whiteboard:
i915 platform: i915 features:
Attachments:
Description Flags
xorg.conf
none
dmesg
none
Xorg.0.log
none
dmesg + debug
none
Add debugging output why the ioctls return -EINVAL
none
dmesg with debug
none
drm_vblank_get debugging output
none
dmesg with vblank debug
none
Debugging output related to enabling/disabling the vblank interrupt
none
dmesg with vblank interrupt none

Description denisgolovan 2017-11-17 11:57:02 UTC
Hi

Sometimes after screen wakeup/turning on I start to experience tearing.
Tear free mode works fine before sleep/turning display off.

My hardware is XFX Radeon RX580.
Software:
kernel-4.13.13+ck1,
xorg-1.19.5,
xf86-video-amdgpu (git 3a4f7422913093ed9e26b73ecd7f9e773478cb1e), 
libdrm-2.4.88

See dmesg, Xorg.0.log, xorg.conf attached.
Comment 1 denisgolovan 2017-11-17 11:57:51 UTC
Created attachment 135552 [details]
xorg.conf
Comment 2 denisgolovan 2017-11-17 11:58:32 UTC
Created attachment 135553 [details]
dmesg
Comment 3 denisgolovan 2017-11-17 11:59:06 UTC
Created attachment 135554 [details]
Xorg.0.log
Comment 4 Michel Dänzer 2017-11-24 15:30:40 UTC
We need to find out why the kernel starts returning -EINVAL from the page flip and wait for vblank ioctls.

Can you try writing 255 to /sys/module/drm/parameters/debug before reproducing the problem, and attach the resulting dmesg output? (Note that writing non-0 to /sys/module/drm/parameters/debug will cause a lot of debugging output to be generated, so you'll want to write 0 to it again soon afterwards)

In case that doesn't reveal why -EINVAL is being returned, are you able to recompile the drm.ko / amdgpu.ko kernel modules with a patch applied?
Comment 5 denisgolovan 2017-11-24 15:43:52 UTC
(In reply to Michel Dänzer from comment #4)
> We need to find out why the kernel starts returning -EINVAL from the page
> flip and wait for vblank ioctls.
> 
> Can you try writing 255 to /sys/module/drm/parameters/debug before
> reproducing the problem, and attach the resulting dmesg output? (Note that
> writing non-0 to /sys/module/drm/parameters/debug will cause a lot of
> debugging output to be generated, so you'll want to write 0 to it again soon
> afterwards)

Got it. I'll attach dmesg as soon as I reproduce the issue.

> In case that doesn't reveal why -EINVAL is being returned, are you able to
> recompile the drm.ko / amdgpu.ko kernel modules with a patch applied?

Sure. Gentoo is there :)
Comment 6 denisgolovan 2017-11-24 20:24:10 UTC
Created attachment 135701 [details]
dmesg + debug
Comment 7 denisgolovan 2017-11-24 20:25:18 UTC
See attached dmesg with debug. 
Tearing appeared after turning display on.
Comment 8 denisgolovan 2017-11-29 09:45:57 UTC
Any news on that?
Should I report some more information/logs/etc?
Comment 9 Michel Dänzer 2017-11-29 17:56:23 UTC
Created attachment 135808 [details] [review]
Add debugging output why the ioctls return -EINVAL

Sorry, been busy with other fires.

Please recompile the drm.ko module with this patch applied, reproduce the result with the resulting binary and attach the dmesg output.
Comment 10 Michel Dänzer 2017-11-29 17:57:25 UTC
BTW, the patch is completely untested; if it fails to compile, hopefully it won't be hard to fix it up.
Comment 11 denisgolovan 2017-12-04 07:49:56 UTC
Yes, I fixed some small issues with the patch.
Now I have following appear in dmesg:
[ 2108.319205] [drm] drm_crtc_vblank_get returned -EINVAL
[ 2108.319235] [drm] crtc 0 failed to acquire vblank counter, -22
Comment 12 denisgolovan 2017-12-04 07:50:56 UTC
Created attachment 135917 [details]
dmesg with debug
Comment 13 Michel Dänzer 2017-12-04 11:40:48 UTC
Created attachment 135923 [details] [review]
drm_vblank_get debugging output

Please do the same with this patch, to see why drm_vblank_get returns -EINVAL.
Comment 14 denisgolovan 2017-12-04 19:27:54 UTC
Created attachment 135938 [details]
dmesg with vblank debug
Comment 15 Michel Dänzer 2017-12-05 11:45:49 UTC
Created attachment 135969 [details] [review]
Debugging output related to enabling/disabling the vblank interrupt

Another iteration, to find out why the vblank interrupt doesn't get enabled.
Comment 16 denisgolovan 2017-12-05 20:47:07 UTC
Created attachment 135989 [details]
dmesg with vblank interrupt
Comment 17 Michel Dänzer 2017-12-06 17:32:17 UTC
Thanks. I think I see what's happening, but I need some time to think about how to address it.

Meanwhile, you should be able to re-enable TearFree by forcing a modeset, e.g. by re-enabling the TearFree property:

xrandr --output DisplayPort-0 --set TearFree on
Comment 18 Anthony Parsons 2017-12-18 19:35:10 UTC
Hi, I'm seeing the same problem on an RX550 (polaris12). Running xrandr doesn't seem to work as a workaround but flipping VTs does. Would having the debug output for this one be useful, or was the other log enough?

kernel 4.14.5-zen+
xorg 1.19.5
xf86-video-amdgpu 1.4.0
libdrm 2.4.88
Comment 19 denisgolovan 2017-12-19 12:50:28 UTC
Still better to have a proper fix first as New Year present to us (poor users) ;)
Comment 20 denisgolovan 2018-01-07 14:23:04 UTC
Doing 
$ xrandr --output DisplayPort-0 --set TearFree on

... does not help. Tearing is still present.
Comment 21 Michel Dänzer 2018-03-09 17:22:11 UTC
(In reply to Anthony Parsons from comment #18)
> Running xrandr doesn't seem to work as a workaround but flipping VTs does.

Have you tried turning it off and on again? (Who gets the reference? :)

xrandr --output DisplayPort-0 --set TearFree off
xrandr --output DisplayPort-0 --set TearFree on
Comment 22 Michel Dänzer 2018-11-21 17:58:25 UTC
Does https://gitlab.freedesktop.org/daenzer/xf86-video-amdgpu/commits/TearFree-flip-failure-retry help? If not, please attach the log file captured after reproducing the problem with a driver built from that branch.
Comment 23 denisgolovan 2018-11-21 19:50:48 UTC
I am on 4.18.12 now.
The bug no longer reproduces.
Comment 24 Michel Dänzer 2018-12-13 11:25:13 UTC
FWIW, https://gitlab.freedesktop.org/xorg/driver/xf86-video-amdgpu/merge_requests/15 is merged now.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.