Bug 471493

Summary: Discrete GPU is not turning off when using on-demand mode in Wayland session
Product: [Plasma] kwin Reporter: ilkerk
Component: compositingAssignee: KWin default assignee <kwin-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: andre.vmatos, nagrigoriadis, nate, xaver.hugl
Priority: NOR Keywords: wayland-only
Version First Reported In: 5.27.6   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In: 6.1.0
Sentry Crash Report:

Description ilkerk 2023-06-27 08:32:34 UTC
SUMMARY
***
NOTE: If you are reporting a crash, please try to attach a backtrace with debug symbols.
See https://community.kde.org/Guidelines_and_HOWTOs/Debugging/How_to_create_useful_crash_reports

Discrete GPU is not turning off when using on-demand mode in Wayland session.

***


STEPS TO REPRODUCE
1.  Open a Wayland session
2.  Check compositor is enabled and discrete GPU is  on-demand mode.  
3.  Connect an external monitor that uses discrete GPU, observe the card is turned on ( cat runtime_status)
4.  Disable the monitor using display configuration widget

OBSERVED RESULT
Discrete GPU is still  turned on and high power consumption
To check this I use:   cat /sys/bus/pci/devices/0000:01:00.0/power/runtime_status

EXPECTED RESULT
In about 30 seconds discrete GPU should be turned off
NOTES:  
a. Same steps on X11 works as expected. 
b. If the monitor is physically disconnected (at step 4) then it works as expected. 
c. Interestingly, after step 4 if I go to compositor settings and change any setting and apply then GPU turns off as expected.


SOFTWARE/OS VERSIONS
Windows: 
macOS: 
Linux/KDE Plasma:  Kubuntu 
(available in About System)
KDE Plasma Version:  5.27.6
KDE Frameworks Version: 
Qt Version: 

ADDITIONAL INFORMATION
Comment 1 ilkerk 2023-06-27 08:42:11 UTC
A minor correction:   "Check compositor is enabled" in step 2 is not needed to reproduce the bug.
Comment 2 Zamundaaa 2023-07-05 23:03:16 UTC
> Interestingly, after step 4 if I go to compositor settings and change any setting and apply then GPU turns off as expected

That is indeed very interesting. What kind of GPU do you have?
Comment 3 Zamundaaa 2023-07-23 15:32:30 UTC
.
Comment 4 ilkerk 2023-07-23 17:05:01 UTC
(In reply to Zamundaaa from comment #3)
> .

Sorry for the late response,
I have an Nvidia A2000 mobile GPU.
Comment 5 Zamundaaa 2023-07-26 18:28:16 UTC
With the NVidia card in my laptop `cat runtime_status` just says "unsupported", so I can't really test this myself. I assume though that this problem is caused by KWin keeping some buffers around even once an output isn't used anymore, which require the dedicated GPU memory to stay powered on. When you change compositor settings, all buffers are deleted, OpenGL resources are reset and only things that are really needed are created again.
Comment 6 Nickolas Grigoriadis 2024-01-04 08:14:23 UTC
Hi, I have the same symptoms (but a little worse).

If I use my notebook without an external monitor in wayland, the dGPU will turn on/off as needed, but once I plug in an external monitor (used both the DP and HDMI connectors on the notebook) and the compositor uses the external display, it will never power down the dGPU even if everything is unplugged and the notebook is on battery.

On X11 the dGPU will power down when unplugged and on battery.

The DP & HDMI ports on this notebook is connected to the dGPU. Internal display is on iGPU.

I suspect that once the compositor uses a display port it keeps a handle open to it, which inhibits the dGPU powering down at all.

My system:
Plasma Wayland 5.27.10 (Fedora 39 KDE)
kernel 6.6.8 (was the same on 6.5 series)
CPU/iGPU: AMD 4800H (renoir)
dGPU: AMD RX5600m 6GB
Notebook: MSI Alpha A4DEK
Using PPD for power management.
Comment 7 ilkerk 2024-01-04 13:06:51 UTC
(In reply to Nickolas Grigoriadis from comment #6)
> Hi, I have the same symptoms (but a little worse).
> 
> If I use my notebook without an external monitor in wayland, the dGPU will
> turn on/off as needed, but once I plug in an external monitor (used both the
> DP and HDMI connectors on the notebook) and the compositor uses the external
> display, it will never power down the dGPU even if everything is unplugged
> and the notebook is on battery.
> 
> On X11 the dGPU will power down when unplugged and on battery.
> 
> The DP & HDMI ports on this notebook is connected to the dGPU. Internal
> display is on iGPU.
> 
> I suspect that once the compositor uses a display port it keeps a handle
> open to it, which inhibits the dGPU powering down at all.
> 
> My system:
> Plasma Wayland 5.27.10 (Fedora 39 KDE)
> kernel 6.6.8 (was the same on 6.5 series)
> CPU/iGPU: AMD 4800H (renoir)
> dGPU: AMD RX5600m 6GB
> Notebook: MSI Alpha A4DEK
> Using PPD for power management.

Does it turn it off if you go to compositor settings and change any setting? 
(In my case it was turning it off about 30 seconds after changing a compositor setting)
Comment 8 Nickolas Grigoriadis 2024-01-04 18:26:55 UTC
(In reply to ilkerk from comment #7)
> (In reply to Nickolas Grigoriadis from comment #6)
> > Hi, I have the same symptoms (but a little worse).
> > 
> > If I use my notebook without an external monitor in wayland, the dGPU will
> > turn on/off as needed, but once I plug in an external monitor (used both the
> > DP and HDMI connectors on the notebook) and the compositor uses the external
> > display, it will never power down the dGPU even if everything is unplugged
> > and the notebook is on battery.
> > 
> > On X11 the dGPU will power down when unplugged and on battery.
> > 
> > The DP & HDMI ports on this notebook is connected to the dGPU. Internal
> > display is on iGPU.
> > 
> > I suspect that once the compositor uses a display port it keeps a handle
> > open to it, which inhibits the dGPU powering down at all.
> > 
> > My system:
> > Plasma Wayland 5.27.10 (Fedora 39 KDE)
> > kernel 6.6.8 (was the same on 6.5 series)
> > CPU/iGPU: AMD 4800H (renoir)
> > dGPU: AMD RX5600m 6GB
> > Notebook: MSI Alpha A4DEK
> > Using PPD for power management.
> 
> Does it turn it off if you go to compositor settings and change any setting? 
> (In my case it was turning it off about 30 seconds after changing a
> compositor setting)

I never tried before, I just tried it now, and unfortunately it never turned the dGPU off.
If I log out of my session and re-login, then it will turn the dGPU off.
Comment 9 Nickolas Grigoriadis 2024-06-10 20:11:43 UTC
(In reply to Nickolas Grigoriadis from comment #6)
> Hi, I have the same symptoms (but a little worse).
> 
> If I use my notebook without an external monitor in wayland, the dGPU will
> turn on/off as needed, but once I plug in an external monitor (used both the
> DP and HDMI connectors on the notebook) and the compositor uses the external
> display, it will never power down the dGPU even if everything is unplugged
> and the notebook is on battery.
> 
> On X11 the dGPU will power down when unplugged and on battery.
> 
> The DP & HDMI ports on this notebook is connected to the dGPU. Internal
> display is on iGPU.
> 
> I suspect that once the compositor uses a display port it keeps a handle
> open to it, which inhibits the dGPU powering down at all.
> 
> My system:
> Plasma Wayland 5.27.10 (Fedora 39 KDE)
> kernel 6.6.8 (was the same on 6.5 series)
> CPU/iGPU: AMD 4800H (renoir)
> dGPU: AMD RX5600m 6GB
> Notebook: MSI Alpha A4DEK
> Using PPD for power management.

Just an update that with KDE Plasma Wayland 6.0 (using Fedora 40 KDE edition) this bug completely disappeared for me.
Comment 10 Nate Graham 2024-06-12 15:04:49 UTC
Great, thanks for following up!