Bug 421131 - Wayland: cursor lags under heavy CPU load
Summary: Wayland: cursor lags under heavy CPU load
Status: RESOLVED WORKSFORME
Alias: None
Product: kwin
Classification: Plasma
Component: input (show other bugs)
Version: git master
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords: wayland
Depends on:
Blocks:
 
Reported: 2020-05-07 03:19 UTC by Nate Graham
Modified: 2022-01-13 03:13 UTC (History)
14 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nate Graham 2020-05-07 03:19:06 UTC
All KDE software built from today's git master on top of openSUSE Tumbleweed.

While in a Wayland session, cursor movement is buttery smooth as long as the CPU usage is pretty low. Once usage gets to about 25% or higher (on a 4-core system, so one core at 100%), the cursor movement starts to drop frames and become choppy. At 50% total utilization, cursor movement visibly lags for me, sometimes for a second or more.
Comment 1 tromzy 2020-07-01 07:35:51 UTC
For me it's not just the cursor, it's the whole session. All animations become laggy on Wayland under high CPU load, but the cursor choppiness is what you see the most easily.
Comment 2 Martin Flöser 2020-08-08 11:39:26 UTC
Can you please check whether KWin is running with real-time scheduling? The whole idea of giving real-time scheduling was to prevent laggy situations on heavy system load. But not all distributions were able to deliver it (in case of openSUSE I remember that the security team had comments).
Comment 3 Nate Graham 2020-08-10 23:10:38 UTC
How does one find out that information?
Comment 4 Martin Flöser 2020-08-11 08:49:43 UTC
You can use ksysguard. Enable the process priority column and check whether kwin_wayland is marked as realtime or FIFO. I would like to give you a screenshot how it should look like, but on KDE neon it's defunct and my kwin_wayland does not use rt-priority. (if it shows a 0 it's wrong).
Comment 5 Martin Flöser 2020-08-11 08:52:42 UTC
You could also check 
getcap /usr/bin/kwin_wayland

it should print:
/usr/bin/kwin_wayland = cap_sys_nice+ep
Comment 6 David Edmundson 2020-08-11 09:21:27 UTC
make that:

getcap `which kwin_wayland`

AFAIK Nate compiles his own kwin...which also wouldn't have setcap set.

(FWIW my new pending systemd boot should also fix this in a way that won't require root anywhere)
Comment 7 Nate Graham 2020-08-11 19:22:36 UTC
Yes indeed, I compile my own KWin. Is there a way to compile it with this support turned on?
Comment 8 Martin Flöser 2020-08-13 14:35:41 UTC
cmake looks for optional build dependency Libcap. Verify that you have built KWin with that dependency. In case your KWin is built with libcap support do:

sudo setcap CAP_SYS_NICE=+ep `which kwin_wayland`

Unfortunatelly you will have to do this after every make/ninja install. In case you run make/ninja install as root, this should be done automatically.
Comment 9 Kai Krakow 2020-10-19 10:17:19 UTC
I'm not sure if using setcap on kwin_wayland is correct: Now all desktop processes are running with FIFO/1 priority, probably because plasma forked from kwin_wayland.

On supported kernels, it could try to use isochronous scheduling which is supported by some kernels and doesn't need special privileges: It works mostly like FIFO scheduling.

But in the first place, it shouldn't spawn any processes while running with raised priority.

Also, why doesn't it use rt-kit as a fallback? Or a small suid helper which checks if the parent process is kwin and then changes the priority?
Comment 10 Brian 2020-11-28 21:56:57 UTC
Wayland definitely becomes laggy and slow when the system is under load (I've tested various distros and builds from git). It's not just the cursor however, but with that said gnome seems to have moved the cursor rendering to a seperate CPU thread... Perhaps the same might be good for Plasma Wayland?
Comment 11 Kai Krakow 2021-01-05 18:45:26 UTC
BTW: It's not only the mouse cursor lagging, key presses are also simply not detected. And this even happens with a low average CPU load if you just have some processes stuck in IO for a few ms: I was thinking I'm not able to properly spell words any longer with this because every now and then, a letter goes missing while typing.
Comment 12 Alex 2021-02-04 13:23:52 UTC
I haven't really noticed this at all on Plasma 5.21 Beta. I tried running prime95 and noticed no cursor lag at all, even during the CPU torture-test.
Comment 13 David Edmundson 2021-02-04 13:33:57 UTC
This bug doesn't really contain anything particularly actionable. 

We will always get some lag under extreme load. The amount is variable, so this falls into generic optimisation, which is something we're always doing regardless of a report.
Comment 14 Kai Krakow 2021-02-04 13:44:25 UTC
I'd say that "loss of input events" should be actionable... (reported in comment #11) I don't care if mouse lags behind a little bit or jumps during CPU spikes, this also happens using X11. But it also loses input events (some keypresses are just discarded), and this particular problem seems very sensitive to even slight load spikes, and it was really distracting as texts I type had a lot of missing letters as if I couldn't type properly.

I'm not sure if this has been fixed meanwhile because I switched back to kwin_x11 for that matter (and a lot of other quirks like context menus showing as windows etc). I'll give it another shot with 5.21: Seems at least a lot of quirks had been fixed.