Sunshine icon indicating copy to clipboard operation
Sunshine copied to clipboard

Mouse movement spikes CPU usage with KMS

Open oryschakj opened this issue 8 months ago • 4 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

Is your issue described in the documentation?

  • [x] I have read the documentation

Is your issue present in the latest beta/pre-release?

This issue is present in the latest pre-release

Describe the Bug

Mouse movements on the desktop spike CPU usage (over 50% for Sunshine process) when using the KMS capture method, causing apparent lag and stuttering. Switching to XDG Portal resolves the issue, and Sunshine doesn't seem to go above 6% CPU usage when using that capture method.

Screenshot shows high CPU usage and processing time for Sunshine:

Image

Expected Behavior

Mouse movement shouldn't affect the streaming experience at all.

Additional Context

KDE Plasma 6.6.3

Host Operating System

Linux

Operating System Version

Linux 6.19.9-1-cachyos

Architecture

amd64/x86_64

Package

Linux - LizardByte/pacman-repo

GPU Type

NVIDIA

GPU Model

RTX 5090

GPU Driver/Mesa Version

595.45.04

Capture Method

KMS (Linux)

Apps


Log output

Gist link provided. Gist kept giving an Error 500 with the full log so I snipped ~100k lines of text showing mouse events as I wiggled.

Online logs

https://gist.github.com/oryschakj-personal/14b693716b56ba775fc1184d5d4d5f58

oryschakj avatar Mar 24 '26 12:03 oryschakj

The kmsgrab update_cursor code is the cause of the high CPU usage; I'm not sure if it can be improved all that much. You can bypass the high CPU by disabling the hardware cursor plane via this environment variable, but it may reduce performance in other ways:

KWIN_FORCE_SW_CURSOR=1

A little off-topic, but are there issues with portal capture that prevents you from using it instead of kmsgrab?

psyke83 avatar Mar 24 '26 17:03 psyke83

Thanks for the suggestion - I’ll give it a look.

I had no idea the portal capture even existed until this week so that was a big one. It may not have been an option in the release version of Sunshine and I didn’t start messing around with the nightlies until this week.

A genuine issue for me using it, though, is that it doesn’t seem to support HDR on my Macbook Pro and Linux clients so I get 10 bit SDR instead. I think that’s a Moonlight client problem, though.

oryschakj avatar Mar 24 '26 17:03 oryschakj

To be clear, the high CPU is not exactly caused by mouse movement; to be more specific, it happens when the cursor shape changes.

Please check the following: while the hardware cursor plane is active, enable the moonlight streaming statistics and watch the stream FPS whilst hovering over content that causes the mouse shape to change repeatedly; for example, moving over lines of text on a website which triggers constant changes between the selection cursor and regular mouse cursor. Do you see the decoding framerate violating the stream limit, and/or the frame queue delay getting unusually high?

If so, try setting the config minimum_fps_target = 1 and let me know if it eases these symptoms when the mouse shape is changing. This setting doesn't decrease Sunshine's CPU usage, but it will improve stream fluidity during cursor change activity. Thanks.

psyke83 avatar Mar 29 '26 05:03 psyke83

I've been running with minim_fps_target = 1 for a few hours now and the fluidity does seem much better during the shape changes. Meaning that there's no perceptible change to streaming behavior (slowing down, stuttering) as I'm using the mouse in the desktop.

oryschakj avatar Apr 01 '26 15:04 oryschakj