Bug 465424 - Attaching external monitor turns both screens black and kwin_x11 hogs CPU until manually restarted
Summary: Attaching external monitor turns both screens black and kwin_x11 hogs CPU unt...
Status: RESOLVED FIXED
Alias: None
Product: kwin
Classification: Plasma
Component: multi-screen (show other bugs)
Version: 5.26.90
Platform: Debian testing Linux
: VHI normal
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-02-07 14:57 UTC by Conor
Modified: 2023-04-15 03:21 UTC (History)
3 users (show)

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


Attachments
Debug & Sysinfo (3.99 KB, application/zip)
2023-02-07 14:57 UTC, Conor
Details
Output of kscreen-console (7.67 KB, text/plain)
2023-02-08 12:15 UTC, Conor
Details
Flamegraph (373.33 KB, image/png)
2023-02-24 10:43 UTC, Conor
Details
Xrandr, xrb-query & xsession-errors (24.25 KB, text/plain)
2023-02-24 16:10 UTC, Conor
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Conor 2023-02-07 14:57:01 UTC
Created attachment 156030 [details]
Debug & Sysinfo

When I attach an external monitor to my laptop's HDMI port the monitor is recognised but both the laptop and external screen go blank after a few seconds, with only the mouse cursor functioning.

kwin_x11 is using 100% cpu and when i kill -9 it, kwin restarts and everything works fine (until the HDMI cable is removed and re-inserted).

This is with Debian 12 (testing) on a Lenovo P1 with Intel/ Nvidia graphics (nouveau driver). I believe the HDMI ports are hard-wired to the discrete GPU.

I installed the Nvidia driver and updated to version 5.26.90. The behaviour is similar, except it will function properly until after a reboot.

I did try Wayland and nothing happens when attaching the monitor.

Attached is a debug file and system information (Nouveau & V5.26.4). 

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Debian 12
KDE Plasma Version: 5.26.90
KDE Frameworks Version: 5.102.0
Qt Version: 5.15.8
Comment 1 Marco Martin 2023-02-08 11:47:37 UTC
can you also paste the output of the command kscreen-console ?

I'm curious if all the edids are found correctly, as is a known problem of erratic behavior when there are screens with invalid or duplicated edid (especially on displayport)
Comment 2 Conor 2023-02-08 12:15:45 UTC
Created attachment 156069 [details]
Output of kscreen-console

I've not installed the display port driver if that's relevant.
Comment 3 Nate Graham 2023-02-11 02:03:53 UTC
> Enabled:  false
Seems like Bug 460341 except you're not using the proprietary driver.
Comment 4 Conor 2023-02-11 11:17:59 UTC
I think it's an issue with kwin as kwn_x11 maxes out cpu and killing it fixes it (Until the cable is removed & reinserted without the proprietary driver or until reboot with the Nvidia driver).

The above bug is only about the screen being turned off in settings whereas my screen is turned on and kwin crashes.
Comment 5 Vlad Zahorodnii 2023-02-23 15:13:48 UTC
> I did try Wayland and nothing happens when attaching the monitor.

Can you clarify what you mean by "nothing happens"?

> kwin_x11 is using 100% cpu

Can you run hotspot with kwin? either attach to kwin_x11 process or run `sudo perf record --call-graph dwarf -p $(pidof kwin_x11)` and then analyze its output in hotspot 
https://github.com/KDAB/hotspot

Can you also check whether the issue is reproducible when compositing is disabled?
Comment 6 Conor 2023-02-23 16:51:47 UTC
Regarding Wayland, when I attached the monitor there was no indication it was attached. Nothing in the GUI and I don't remember what commands I ran but nothing showed any indication of an external monitor. I have tried with Gnome wayland and it worked fine.

The issue is present with compositing disabled.

I got the following output from perf record:

>[ perf record: Woken up 5595 times to write data \] 
>Warning: 
>Processed 114541 events and lost 12 chunks!  
>  
>Check IO/CPU overload!  
>  
>Warning: 
>9354 out of order events recorded. \
>[ perf record: Captured and wrote 784.348 MB perf.data (97303 samples) \]

The .perfparser file saved from hotspot is 24MB. I'm only able to attach 4MB files here, how should I send the data?
Comment 7 Vlad Zahorodnii 2023-02-24 09:50:43 UTC
> The .perfparser file saved from hotspot is 24MB. I'm only able to attach 4MB files here, how should I send the data?

Those files cannot be opened and analyzed on another computer. Can you open it locally and post the screenshots of the flamegraph here?
Comment 8 Conor 2023-02-24 10:43:15 UTC
Created attachment 156667 [details]
Flamegraph

The man says they are self contained, not the perf.data but .perfparser. I noticed that Debian had the "save as" function removed from hotspot so I did it with the appimage version (I guess they had some security concerns...).

https://github.com/KDAB/hotspot#import-export

Regardless, attached is the flamegraph.
Comment 9 Conor 2023-02-24 10:50:15 UTC
Export is a new function in hotspot since December and the Debian release is out of date.
Comment 10 Vlad Zahorodnii 2023-02-24 15:24:56 UTC
It looks like kwin or rather breeze decoration spends a lot of cpu cycles in fontconfig stuff, I wonder why. Could you try running kwin_x11 with QT_LOGGING_RULES="*.debug=true" envvar and post its output here, maybe Qt would print something

  QT_LOGGING_RULES="*.debug=true" kwin_x11 --replace

This also explains why the issue is present when compositing is disabled. Breeze decoration would be still used in that case.
Comment 11 Vlad Zahorodnii 2023-02-24 15:51:16 UTC
Can you post the output of these two commands as well

  xrandr

and

  xrdb -query
Comment 12 Conor 2023-02-24 16:10:18 UTC
Created attachment 156680 [details]
Xrandr, xrb-query & xsession-errors

Attached is the output of the two commands and .xsession-errors after turning on logging as per the wiki (slightly different to the ENV you posted).

https://community.kde.org/KWin/Debugging#Getting_debug_log_output

As an aside the external screen didn't go black on this occasion, instead it froze until kwin_x11 was restarted.
Comment 13 Vlad Zahorodnii 2023-02-28 07:37:53 UTC
xrdb doesn't contain Xft.dpi.. Can you try forcing specific font dpi in system settings? i.e. go to font system settings, force specific font dpi, reboot, and then try to reproduce the issue again
Comment 14 Conor 2023-02-28 13:17:45 UTC
I can't reproduce the issue after forcing specific font dpi, nicely done!
Comment 15 Nate Graham 2023-04-15 03:21:27 UTC
Sounds good, and we're handling DPI better in other places too as of Plasma 5.27.4.