Bug 500219 - Wayland: compositor running at half the selected refresh rate
Summary: Wayland: compositor running at half the selected refresh rate
Status: RESOLVED UPSTREAM
Alias: None
Product: kwin
Classification: Plasma
Component: performance (other bugs)
Version First Reported In: 6.3.0
Platform: Arch Linux Linux
: NOR normal
Target Milestone: ---
Assignee: KWin default assignee
URL: https://gitlab.freedesktop.org/drm/xe...
Keywords:
: 500754 505371 (view as bug list)
Depends on:
Blocks:
 
Reported: 2025-02-17 00:11 UTC by Nathan F.
Modified: 2025-06-23 13:29 UTC (History)
7 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
KWIN_LOG_PERFORMANCE_DATA (78.25 KB, text/csv)
2025-02-17 18:22 UTC, Mario
Details
KWin performance CSVs (560.80 KB, application/zip)
2025-02-17 19:47 UTC, Nathan F.
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nathan F. 2025-02-17 00:11:58 UTC
SUMMARY
In Wayland, but not X11, displays run at half the refresh rate that they're meant to be, running the BlurBusters UFO test on my 60 Hz secondary monitor shows that it's running at 30 fps and dragging the test to the 165 Hz primary monitor causes it to run at 82 fps. Running any vsync application also corroborates the issue, and even the cursor is obviously running at half the refresh rate. However, a fullscreen application that triggers adaptive sync on the primary monitor runs at the full refresh rate. Setting adaptive sync to "Always" also allows the primary monitor to run at the full refresh rate, but not the secondary monitor as it does not have adaptive sync support.

STEPS TO REPRODUCE
1. Have an Intel Battlemage GPU running the Xe driver
2. Set adaptive sync on your display to "Off" or "Adaptive"
3. Run anything that can display the vsync framerate or just observe the cursor movement

OBSERVED RESULT
Displays run at exactly half the selected refresh rate

EXPECTED RESULT
Displays run at the selected refresh rate

ADDITIONAL INFORMATION
Despite also being an Intel (UHD 620) GPU, my laptop has no such issue - may be driver dependent, but kwin-wayland is at fault as well because it doesn't happen on X11
Comment 1 David Edmundson 2025-02-17 09:42:26 UTC
*** Bug 500096 has been marked as a duplicate of this bug. ***
Comment 2 Zamundaaa 2025-02-17 17:28:12 UTC
This sounds like the driver takes a very long time from commit to pageflip. Please put KWIN_LOG_PERFORMANCE_DATA=1 into /etc/environment, reboot, use the computer for a minute and then attach the csv file from your home folder here; with that we should be able to judge whether or not this is a driver issue.
Comment 3 Mario 2025-02-17 18:21:56 UTC
(In reply to Zamundaaa from comment #2)
> This sounds like the driver takes a very long time from commit to pageflip.
> Please put KWIN_LOG_PERFORMANCE_DATA=1 into /etc/environment, reboot, use
> the computer for a minute and then attach the csv file from your home folder
> here; with that we should be able to judge whether or not this is a driver
> issue.

Hello, I captured this info, please check. :)
Comment 4 Mario 2025-02-17 18:22:42 UTC
Created attachment 178492 [details]
KWIN_LOG_PERFORMANCE_DATA
Comment 5 Nathan F. 2025-02-17 19:47:12 UTC
Created attachment 178495 [details]
KWin performance CSVs

DP-2 is my primary (1440p @ 165Hz with adaptive sync available) and HDMI-A-3 is my secondary (1080p @ 60Hz without adaptive sync available) monitor. For testing purposes, I fullscreened a game on DP-2 for a bit, which triggered automatic adaptive sync and the performance improvement was immediately obvious - this is visible in the vrr=1 segment.
Comment 6 Zamundaaa 2025-02-17 21:35:49 UTC
My tool to look at that data says 67% of frames are dropped on DP-2, and 100% on HDMI-A-3. In both cases, the very vast majority because of commits being too late.
That means KWin seems to be doing everything correctly, and the kernel is just too late.

There is a second possible cause, which we've hit with Intel GPUs before. If you set https://invent.kde.org/plasma/kwin/-/wikis/Environment-Variables#kwin_drm_disable_buffer_readability_checks to 1, does that change anything?
Comment 7 Mario 2025-02-17 21:38:01 UTC
(In reply to Zamundaaa from comment #6)
> Mi herramienta para analizar esos datos indica que el 67 % de los fotogramas
> se pierden en DP-2 y el 100 % en HDMI-A-3. En ambos casos, la gran mayoría
> se debe a que las confirmaciones se realizan demasiado tarde.
> Eso significa que KWin parece estar haciendo todo correctamente y que el
> kernel llega demasiado tarde.
> 
> Existe una segunda causa posible, que ya hemos encontrado antes con las GPU
> Intel. Si configura
> https://invent.kde.org/plasma/kwin/-/wikis/Environment-
> Variables#kwin_drm_disable_buffer_readability_checks en 1, ¿eso cambia algo?

What about My log file? U.u
Comment 8 Zamundaaa 2025-02-17 22:01:58 UTC
(In reply to Mario from comment #7)
> What about My log file? U.u
Sorry, I forgot to put it in the same folder to be analyzed.

The tool reports that basically no frames are dropped in your case, but looking at the file myself, something weirder happens. The pageflips happen with a distance of 21ms, which is a multiple of 8.33ms. So that's a driver issue - it's not actually changing the refresh rate, but just pretending to. As KWin doesn't know the real refresh rate, things don't work out nicely.
You can follow https://gitlab.freedesktop.org/drm/amd/-/issues/2501 for that.
Comment 9 Nathan F. 2025-02-18 00:09:00 UTC
(In reply to Zamundaaa from comment #6)
> My tool to look at that data says 67% of frames are dropped on DP-2, and
> 100% on HDMI-A-3. In both cases, the very vast majority because of commits
> being too late.
> That means KWin seems to be doing everything correctly, and the kernel is
> just too late.
> 
> There is a second possible cause, which we've hit with Intel GPUs before. If
> you set
> https://invent.kde.org/plasma/kwin/-/wikis/Environment-
> Variables#kwin_drm_disable_buffer_readability_checks to 1, does that change
> anything?

This didn't solve the problem for me on either monitor, and what's strange is that I'm pretty sure the issue only started with Plasma 6.3, I don't think there was a corresponding change to the Intel driver.
Comment 10 Zamundaaa 2025-02-19 13:24:02 UTC
(In reply to Nathan F. from comment #9)
> This didn't solve the problem for me on either monitor, and what's strange
> is that I'm pretty sure the issue only started with Plasma 6.3, I don't
> think there was a corresponding change to the Intel driver.
Well, there were no frame scheduling changes in Plasma 6.3 either. Other than the kernel being a lot slower than expected, I have no explanation for it.
With VRR enabled, the pageflips also arrive at the expected time, so that makes me quite certain that this is on the kernel side. So please report this at https://gitlab.freedesktop.org/drm/xe/kernel/-/issues
Comment 11 Zamundaaa 2025-02-28 13:45:01 UTC
*** Bug 500754 has been marked as a duplicate of this bug. ***
Comment 12 Bug Janitor Service 2025-02-28 14:38:29 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kwin/-/merge_requests/7249
Comment 13 Zamundaaa 2025-02-28 23:07:52 UTC
Git commit ea0a7f0a43f4808155c3bf4b6258b015274ea8ac by Xaver Hugl.
Committed on 28/02/2025 at 14:37.
Pushed by zamundaaa into branch 'master'.

backends/drm: allow overriding the safety margin

This can be useful for debugging issues with slow drivers.

M  +11   -1    src/backends/drm/drm_commit_thread.cpp

https://invent.kde.org/plasma/kwin/-/commit/ea0a7f0a43f4808155c3bf4b6258b015274ea8ac
Comment 14 Bug Janitor Service 2025-02-28 23:56:04 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kwin/-/merge_requests/7251
Comment 15 Zamundaaa 2025-03-01 00:10:43 UTC
Git commit 8b4237bc6a1bb1fe0bbd7cbfd2cfee1283bc4c69 by Xaver Hugl.
Committed on 28/02/2025 at 23:55.
Pushed by zamundaaa into branch 'Plasma/6.3'.

backends/drm: allow overriding the safety margin

This can be useful for debugging issues with slow drivers.


(cherry picked from commit ea0a7f0a43f4808155c3bf4b6258b015274ea8ac)

Co-authored-by: Xaver Hugl <xaver.hugl@gmail.com>

M  +11   -1    src/backends/drm/drm_commit_thread.cpp

https://invent.kde.org/plasma/kwin/-/commit/8b4237bc6a1bb1fe0bbd7cbfd2cfee1283bc4c69
Comment 16 Morice Olbert 2025-03-02 13:09:03 UTC
(In reply to Zamundaaa from comment #15)
> Git commit 8b4237bc6a1bb1fe0bbd7cbfd2cfee1283bc4c69 by Xaver Hugl.
> Committed on 28/02/2025 at 23:55.
> Pushed by zamundaaa into branch 'Plasma/6.3'.
> 
> backends/drm: allow overriding the safety margin
> 
> This can be useful for debugging issues with slow drivers.
> 
> 
> (cherry picked from commit ea0a7f0a43f4808155c3bf4b6258b015274ea8ac)
> 
> Co-authored-by: Xaver Hugl <xaver.hugl@gmail.com>
> 
> M  +11   -1    src/backends/drm/drm_commit_thread.cpp
> 
> https://invent.kde.org/plasma/kwin/-/commit/
> 8b4237bc6a1bb1fe0bbd7cbfd2cfee1283bc4c69

Yep seems to help when setting KWIN_DRM_OVERRIDE_SAFETY_MARGIN to atleast 2200, now im getting 165HZ in ufotest
Comment 17 Zamundaaa 2025-06-09 21:21:24 UTC
*** Bug 505371 has been marked as a duplicate of this bug. ***
Comment 18 Mario 2025-06-23 12:09:42 UTC
This was fix me for me with plasma 6.4
Comment 19 Zamundaaa 2025-06-23 13:29:41 UTC
Yeah, https://invent.kde.org/plasma/kwin/-/merge_requests/7438 basically works around the driver being so slow by automatically increasing latency instead of you having to do it manually with the env var.