Bug 56236

Summary: [regression] Mouse lags in Sims 3 under wine
Product: DRI Reporter: Deve <deveee>
Component: DRM/IntelAssignee: Daniel Vetter <daniel>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: medium CC: ben, chris, daniel, jbarnes
Version: unspecified   
Hardware: x86 (IA32)   
OS: Linux (All)   
Whiteboard:
i915 platform: i915 features:
Attachments:
Description Flags
log from top
none
Xorg.0.log
none
top with WCHAN
none
cat /proc/`pidof X`/stack
none
trace-cmd.log.tar.bz2 none

Description Deve 2012-10-20 21:17:23 UTC
When I run Sims 3 (real game, not menu), mouse lags. One second is OK, about half second mouse stay in one place, then one second it runs etc.

Btw: After close game or after ctrl+alt+backspace I must to use power button because I see black screen. It wasn't in previous version too.

Lastest working verion: 
xserver-xorg-video-intel 2.20.9

Tested:
Intel 965GM
xserver-xorg-video-intel 2.20.12
mesa 7.12.2
libdrm 2.4.33
linux-image 3.5.5
wine 1.4.1

Game loads a lot of time in my case so I can't create log from Xorg, because I have a little free space in my hard disk.
Comment 1 Chris Wilson 2012-10-21 08:06:14 UTC
How about if you watch 'sudo perf top' and see what is most active whilst the most lags?
Comment 2 Deve 2012-10-21 09:14:58 UTC
Top shows nothing special - logs in attachment.

Acceleration SNA of course.

I don't have problems, when I run it in virtual desktop (as window). Problems are only on fullscreen.

Mouse stutters always in real game. Not more or less.


Crash on closing game is also problem. Try to shutdown on running game also freezes computer.
Comment 3 Deve 2012-10-21 09:15:23 UTC
Created attachment 68864 [details]
log from top
Comment 4 Chris Wilson 2012-10-21 09:23:13 UTC
Hmm, a scary number of times that Xorg is stuck in 'D' -- meaning that it is blocked from running due (normally) to IO.

Can you attach a normal /var/log/Xorg.0.log? Grabbing a stack trace whilst Xorg is in 'D' would be fantastic, or maybe just enable WCHAN output in top.
Comment 5 Deve 2012-10-21 09:52:09 UTC
Xorg log in attachment. My previous logs were much larger, so I wrote about little space in my disk.
Comment 6 Deve 2012-10-21 09:52:51 UTC
Created attachment 68867 [details]
Xorg.0.log
Comment 7 Chris Wilson 2012-10-21 10:01:56 UTC
Just to be sure, do you also see the lag when you compile without --enable-debug=full?
Comment 8 Deve 2012-10-21 10:30:56 UTC
Yes. I always compile drivers without debug at first. 
./configure --prefix=/usr

Then, if something doesn't work, I create debug-version.
./configure --prefix=/usr --enable-debug=full

Log from top was also without debug drivers.
Comment 9 Chris Wilson 2012-10-21 10:46:18 UTC
Ok, can you enable WCHAN reporting in top (press f, highlight WCHAN and hit space) and grab a few samples when Xorg is stuck in 'D'. Or 'sudo cat /proc/`pidof X`/stack'
Comment 10 Deve 2012-10-21 11:43:38 UTC
Created attachment 68872 [details]
top with WCHAN
Comment 11 Deve 2012-10-21 11:44:28 UTC
Created attachment 68873 [details]
cat /proc/`pidof X`/stack
Comment 12 Chris Wilson 2012-10-21 12:14:28 UTC
Ah, so the 'D' is due to the uninterruptible wait for i915_gem_object_pin_to_display_plane(). Except that it should not block here...

The alternative is i915_gem_object_get_fence(), but again there should be no reason for a long wait there.

Can you please install 'trace-cmd' and run 'sudo trace-cmd record -e i915 -e drm' whilst it lags, and then attach the output of trace-cmd report.

trace-cmd is available here: git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/trace-cmd.git
Comment 13 Deve 2012-10-21 13:42:09 UTC
Created attachment 68875 [details]
trace-cmd.log.tar.bz2
Comment 14 Chris Wilson 2012-10-21 14:02:07 UTC
The culprit seems to be that we wait for mesa for very long periods of time to complete it rendering, during which time we will not even update the mouse. It looks like you need:

commit 79158103bf20c9ff55204ceb78a5773f422b03be
Author: Chris Wilson <chris@chris-wilson.co.uk>
Date:   Wed May 23 11:13:58 2012 +0100

    drm/i915: Make the lock for pageflips interruptible
    
    As we take the struct_mutex lock to access the command-stream, there is
    a possibility that we may need to wait for a GPU hang and so should make
    the lock both interruptible and error-checking.
    
    References: https://bugs.freedesktop.org/show_bug.cgi?id=50069
    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
    Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>

and

commit 3236f57a0162391f84b93f39fc1882c49a8998c7
Author: Chris Wilson <chris@chris-wilson.co.uk>
Date:   Fri Aug 24 09:35:09 2012 +0100

    drm/i915: Use a non-blocking wait for set-to-domain ioctl
    
    The principal use for set-to-domain is for userspace to serialise
    operations with a particular buffer, for example to maintain coherency
    with a CPU map or to ratelimit its rendering by waiting on all previous
    operations before continuing. As such we tend to hold the struct_mutex
    for long periods during the synchronisation and so cause contention
    issues with other users of the graphics device, even for independent
    operations as memory management. An example is the contention between
    compiz and X which causes jitter in the display and a drop in peak
    throughput.
    
    The ultimate solution would be a set of fine grained locks and lockless
    operations, but an intermediate step is to first attempt the
    synchronisation for set-to-domain without holding the mutex. This
    introduces a number of race conditions, so we limit it use to the ioctl
    periphery where we have no dependent state and can safely complete with
    a locked synchronisation afterwards.
    
    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
    Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>

would it be possible for you to test a 3.7-r2 kernel (or perhaps drm-intel-next)?
Comment 15 Chris Wilson 2012-10-21 14:03:05 UTC
Though that doesn't explain why this feels like a regression from -intel-2.20.9. If you can bisect -intel, that may help us to find an alternative solution.
Comment 16 Deve 2012-10-21 15:09:24 UTC
git bisect good 2.20.9
git bisect bad 2.20.10



3e770f09dbe76287293fea0a8a1f231885aa1c1f is the first bad commit
commit 3e770f09dbe76287293fea0a8a1f231885aa1c1f
Author: Chris Wilson <chris@chris-wilson.co.uk>
Date:   Wed Oct 3 13:00:25 2012 +0100

    sna/dri: Delay the deactivation of the pageflipping
    
    As we need to clflush the scanout buffer as we return it to the bo cache
    on SNB+, it is costly to terminate the pageflipping as soon as we drop a
    frame as mesa often fails to keep up to the vrefresh rate.
    
    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>

:040000 040000 c52079be324edc5d4daa9c2d966115d028997d1c 4842f09c9467a1beb1a64b91d712b0296fd2f0bf M	src



It also causes the crashing/freezing system on closing the game. I think in changing resolution.

Testing newest kernel is hard, because lastest in my repos is 3.5.5. Configuration and compilation take a lot of time. I will see on ubuntu repositories, maybe there is recent version.
Comment 17 Chris Wilson 2012-10-21 15:19:09 UTC
Hmm, yes, given your kernel that will actually impair responsiveness due to the lock contention.

Not seen a crash with modeswitching whilst pageflipping, care to attach gdb and grab a bt? Meanwhile, one of the ~kernel-ppa/mainline will carry the pair of patches that I think you need.
Comment 18 Deve 2012-10-21 17:19:34 UTC
I should run gdb startx? I'm not sure if I understand.

I will try new kernel if it will be in repository.
Comment 19 Chris Wilson 2012-10-21 17:25:07 UTC
Running X under gdb is easiest using a second computer. So don't worry if you can't, just attach an Xorg.log with the crash info and I may ask you translate some of the stacktraces.
Comment 20 Chris Wilson 2012-10-21 17:26:19 UTC
For the kernel package, try http://kernel.ubuntu.com/~kernel-ppa/mainline/drm-intel-experimental/current/
Comment 21 Deve 2012-10-21 18:23:30 UTC
I tried install:
linux-image-3.6.0-994-generic_3.6.0-994.201210200406_i386.deb

But on booting I have information about problems with calibration, then resolution doesn't change and I can't do anything.

Computer also freezed when I create Xorg log from comment 6. I think it will also freeze when I will run gdb, so I won't read bt log. And I don't have other computer to run X from it.
Comment 22 Chris Wilson 2012-10-21 18:40:40 UTC
(In reply to comment #21)
> I tried install:
> linux-image-3.6.0-994-generic_3.6.0-994.201210200406_i386.deb
> 
> But on booting I have information about problems with calibration, then
> resolution doesn't change and I can't do anything.

Ok, that's bizarre and I'm not sure what to suggest. Maybe just keep an eye out for a mainline kernel through the usual channels? Or some other ppa?
 
> Computer also freezed when I create Xorg log from comment 6. I think it will
> also freeze when I will run gdb, so I won't read bt log. And I don't have
> other computer to run X from it.

Running X under gdb is quite complicated due to gdb trapping the signals that X uses to switch VT and so you lose control of machine.
Comment 23 Chris Wilson 2012-10-22 14:52:35 UTC
I'm satisfied that this the lock contention judging by the trace you provided. It would be fantastic if you were able to confirm that by finding a 3.7 kernel to test. Please do report back when you get the chance, thanks.
Comment 24 Deve 2012-10-22 15:19:48 UTC
I tested it few minutes ago with kernel 3.7-rc2. Everything works, system doesn't crash. I think you can close. Thank you for your suggestion with recent kernel.

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.