Askannz / optimus-manager

A Linux program to handle GPU switching on Optimus laptops.
MIT License
2.27k stars 165 forks source link

Session hangs (Plasma crashes) after optimus-manager switch (no matter which) #353

Closed Alarg closed 2 months ago

Alarg commented 3 years ago

Describe the bug In 90% of times, switching of graphics cards will make the system hang after loading screen of display manager, while crashing Plasma.

System info

Logs

    ~  optimus-manager --status                                                                            ✔  at 12:01:46  
Optimus Manager (Client) version 1.3

Current GPU mode : nvidia
GPU mode requested for next login : no change
GPU at startup : integrated
Temporary config path: no

    ~  xrandr --listproviders                                                                              ✔  at 12:02:13  
Providers: number : 2
Provider 0: id: 0x1b8 cap: 0x1, Source Output crtcs: 0 outputs: 0 associated providers: 1 name:NVIDIA-0
Provider 1: id: 0x1dd cap: 0xf, Source Output, Sink Output, Source Offload, Sink Offload crtcs: 3 outputs: 2 associated providers: 1 name:modesetting

    ~  glxinfo | grep "OpenGL renderer"                                                                    ✔  at 12:02:15  
OpenGL renderer string: GeForce MX250/PCIe/SSE2                   

Xorg.0.log daemon-20201218T115214.log switch-20201218T115316.log plasmashell-20201218-115526.log (renamed it from .kcrash so I could upload it) optimus-manager.txt

Plasmashell log, I think, is relevant, since crash log just popped up. I switched to Nvidia mode right before I wanted to test it and logs are from this switch. The switch worked however I experienced the hanging once more. I can access tty and such while the desktop crashes.

I hope you could help me out with this.

Best regards, Alarg

Alarg commented 3 years ago

Also to add, Hybrid mode also hangs a lot but it does switch at the end. Same with switching back to integrated. Sometimes it works but more often than not it doesn't.

Askannz commented 3 years ago

Likely related to https://github.com/Askannz/optimus-manager/issues/267 and https://github.com/Askannz/optimus-manager/issues/289.

Does disabling Kscreen2 solve the issue ? (System Settings -> Startup and Shutdown -> Background Services -> Uncheck KScreen 2 -> Apply)

Alarg commented 3 years ago

Just tried that, I still get the crashes.

However, I've got more info, at least, a makeshift solution. I'm not sure if systemd is to blame, but something happens during logging which probably crashes Plasma.

I rebooted my laptop twice. Then, I switched graphics once, and it worked, successfully. After that, next switching will cause the crash. I wait for my cursor to appear and switch to tty2. Login as root, type shutdown now and press the power off button after that. During the next boot, before regular arch linux boot message (storage block count) there stands another one: root: recovering journal. If I try to switch graphics when I login, it hangs immediately.

The solution that is a workaround to prevent crashes is this: After switching graphics, reboot twice. (lmao idk any better) While this message persists, Plasma will crash.

Also, I noticed this: After Plasma crashes and manages to start again, I get disabled compositor (I'm on OpenGL 3.1). I have to manually reenable it to get theming back (taskbar and window status bar blur is on). I'll try disabling the blur and switch again and I'll report right after, and I'll repeat this procedure and provide logs a bit later.

Alarg commented 3 years ago

I'm even more confused now.

I disabled blur and the switching immediately started working, but: after boot, I can only switch between Nvidia and Hybrid modes (xrandr --listproviders and glxinfo | grep "OpenGL renderer" both say the correct things for their modes) but the icon in the taskbar is always displaying Hybrid. It won't crash no matter how many times I switch between the two, but as soon as I switch to Intel, it crashes.

Alarg commented 3 years ago

Sorry for spam, I'm providing just a bit more info that might be of relevance, since I believe that theming might also be an issue:

------------ 
OS: Arch Linux x86_64 
Host: 81ND Lenovo IdeaPad S540-14IWL 
Kernel: 5.9.14-arch1-1 
Resolution: 1920x1080 
DE: Plasma 5.20.4 
WM: KWin 
WM Theme: Layan 
Theme: Layan [Plasma], Breeze [GTK2/3] 
Icons: Tela-dark [Plasma], Tela-dark [GTK2/3]

I'll test the theming later, also, but for now it works much better as expected, and unless I switch to Intel mode, there is no root: recovering journal message.

Askannz commented 3 years ago

My current theory is that optimus-manager calls xrandr at the same time that Plasma tries to start plasmashell, causing a crash as Plasma is trying to acquire a display that is (temporarily) gone. It's a race condition, which would explain why the bug is intermittent and why I can't reproduce it.

Would you mind testing this theory by trying the no_xsetup branch ? You can use the PKGBUILD here, it should already point to the correct branch.

Note that this branch disables Prime setup, so your laptop screen will stay black at the login screen. I suggest enabling auto-logging or plugging an external monitor. You also need to re-enable KScreen2, or else your screen will stay black at the desktop as well.

Szybet commented 3 years ago

Try to change compositor settings in KDE, it makes sometimes problems

Alarg commented 3 years ago

Hey, sorry for not answering for 2 weeks, I took my time for these holidays.

I didn't yet try no_xsetup branch, but I will try, just in case. I updated packages and there was a bbswitch update (might have contributed to solution but I'm not quite sure) As @Szybet said, I tried changing compositor settings (it was on OpenGL 2.0). I went for XRender, and that didn't change anything, and then switched to OpenGL 3.1 Also, I changed the config for Intel mode to load modesetting driver, not Intel one.

My KDE compositor settings are:

Enable compositor on startup: On
Scale method: Accurate
Rendering backend: OpenGL 3.1
Tearing prevention ("vsync"): Automatic
Keep window thumbnails: Only for shown windows
Allow applications to block compositing: OFF

Allow applications to block compositing was on, before. I managed to switch several times from Intel to Nvidia and back, from Intel to Hybrid, from Nvidia to Hybrid, like 7-8 times already and no crashes. Could it be possible that this particular compositor option from Plasma might have prevented the compositor to load properly? I'll also check whether disabling compositor on startup helps, if more issues arise.

Currently, everything is working fine. I'll keep testing more, and I'll also check the other build of optimus-manager. I'll keep you notified. If you think that it's necessary right now, close this issue and I'll reopen it if something new comes across.

Happy New year and holidays!

EDIT: Nevermind, it doesn't work. I was being overly enthusiastic since I probably switched way too fast. It does, at least, suggest to me that there certainly is a process that starts several seconds after logging in and it causes Plasma to crash. If you switch fast enough, there won't be any crashes, that's for certain.

nwildner commented 2 months ago

@Alarg whats up? Have you been able to reproduce this recently, using a modern distribution and a recent linux kernel, nvidia drivers and optimus-manager-git?

Since this issue isn't active for the last 4 years ago and a lot has changed in many aspects of multiple software, we'll keep this case opened for some days and close it if no further comments are provided. We're dealing with backlog here to try to keep optimus-manager in a good shape and active as a project.

Have a nice week ahead.