Bug 177123

Summary: Switching between powerdevil states hangs kded
Product: [Frameworks and Libraries] solid Reporter: Torrie Fischer <tdfischer>
Component: powermanagement-daemonAssignee: Dario Freddi <drf>
Status: RESOLVED FIXED    
Severity: normal CC: andresjarv, digitalpioneer, jacopods+kde, jaroslav.petras, sitter, tiposchi, zdenek.zikan
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Unspecified   
Latest Commit: Version Fixed In:
Attachments: patch for the daemon
patch for krunner

Description Torrie Fischer 2008-12-07 07:55:27 UTC
Version:            (using Devel)
Installed from:    Compiled sources

When my laptop goes below 25% or so, powerdevil switches into the 'aggressive powersave' state. Normally, this would display a notification about my power, but sometimes it hangs for a little bit of time. In that time, my keyboard is locked up and input is queued until it lets go. The same thing happens when switching to any other power state.

I can't reproduce this reliably and futhermore, I'm not yet sure if its a transient bug that only appears in random SVN revisions.

Not sure if this is related either, but my .xsession-errors has a few of these around the same time:

kwin(3625)/kdeui (KNotification) KNotification::close: -1
Comment 1 Emanuele Cisotti 2008-12-22 21:32:59 UTC
Same problem here, when the program switch to aggressive powersave, I can't use anymore my keyboard.
Comment 2 Jaroslav Petráš 2008-12-30 02:48:53 UTC
KDE 4.1.86 (4.2 >= 20081221), Debian experimental + unreleased (deb http://kde42.debian.net/debian/ UNRELEASED main), amd64

Same problem here. I can use mouse in this time period. It happens after manual profile switch too.
Comment 3 Dario Freddi 2008-12-30 12:47:55 UTC
This issue is related to DPMS. Knowing what video card you are on could definitely help.
Comment 4 Jaroslav Petráš 2008-12-31 06:01:38 UTC
(In reply to comment #3)
> This issue is related to DPMS. Knowing what video card you are on could
> definitely help.
> 

asfalatus@mobileworkshop:~$ lspci -k | grep VGA
01:05.0 VGA compatible controller: ATI Technologies Inc RS780M/RS780MN [Radeon HD 3200 Graphics]
02:00.0 VGA compatible controller: ATI Technologies Inc Mobility Radeon HD 3400 Series

I am using radeon driver just now, but no matters which driver I use (fglrx before, or radeonhd).

But this is interesting:

asfalatus@mobileworkshop:~$ cat /var/log/Xorg.0.log | grep DPMS
(II) Loading extension DPMS
(II) Loading extension DPMS
(II) RADEON(0): No DPMS capabilities specified
(II) RADEON(0): No DPMS capabilities specified
(**) RADEON(0): DPMS enabled
(II) RADEON(0): No DPMS capabilities specified
(II) RADEON(0): No DPMS capabilities specified
... 

But as I said here: http://bugs.kde.org/show_bug.cgi?id=178642 , default display power manager in KDE4 works well. In KDE 3.5.9 (with kpowersave app) everything works well too.

Strange things happen around DPMS ^^ 
Comment 5 Harald Sitter 2008-12-31 13:27:53 UTC
Ubuntu bug https://bugs.edge.launchpad.net/ubuntu/+source/kdebase-workspace/+bug/312549 describes the same problem IMO. 

I also see a delay in reaction (for some profile switches I only get the change notification after >10 seconds), however mouse and keyboard appear to working just fine.

00:02.0 VGA compatible controller: Intel Corporation Mobile 945GM/GMS, 943/940GML Express Integrated Graphics Controller (rev03)
        Subsystem: Dell Device 01bd
        Flags: bus master, fast devsel, latency 0, IRQ 16
        Memory at eff00000 (32-bit, non-prefetchable) [size=512K]
        I/O ports at eff8 [size=8]
        Memory at d0000000 (32-bit, prefetchable) [size=256M]
        Memory at efec0000 (32-bit, non-prefetchable) [size=256K]
        Capabilities: [90] Message Signalled Interrupts: Mask- 64bit- Queue=0/0 Enable-
        Capabilities: [d0] Power Management version 2
        Kernel modules: intelfb
Comment 6 Harald Sitter 2008-12-31 15:20:06 UTC
From the Ubuntu bug:
michael@michaelspc:~$ sudo lspci -v -s 01:00.0
01:00.0 VGA compatible controller: nVidia Corporation GeForce 8600M GT (rev a1)
       Subsystem: Dell Device 0228
       Flags: bus master, fast devsel, latency 0, IRQ 16
       Memory at fd000000 (32-bit, non-prefetchable) [size=16M]
       Memory at e0000000 (64-bit, prefetchable) [size=256M]
       Memory at fa000000 (64-bit, non-prefetchable) [size=32M]
       I/O ports at ef00 [size=128]
       [virtual] Expansion ROM at fea00000 [disabled] [size=128K]
       Capabilities: [60] Power Management version 2
       Capabilities: [68] Message Signalled Interrupts: Mask- 64bit+ Queue=0/0 Enable-
       Capabilities: [78] Express Endpoint, MSI 00
       Capabilities: [100] Virtual Channel <?>
       Capabilities: [128] Power Budgeting <?>
       Capabilities: [600] Vendor Specific Information <?>
       Kernel driver in use: nvidia
       Kernel modules: nvidiafb, nvidia
Comment 7 Andres Järv 2009-01-15 19:08:14 UTC
I am experiencing the same problem.

$ lspci | grep VGA
00:02.0 VGA compatible controller: Intel Corporation Mobile GM965/GL960 Integrated Graphics Controller (rev 0c)
Comment 8 Jacopo De Simoi 2009-01-29 07:51:25 UTC
*** Bug 178999 has been marked as a duplicate of this bug. ***
Comment 9 Jacopo De Simoi 2009-01-29 07:55:11 UTC
I experience the same here, with this video card:

00:12.0 VGA compatible controller: nVidia Corporation Device 0531 (rev a2)

(II) NVIDIA(0): Support for GLX with the Damage and Composite X extensions is                                          
(II) NVIDIA(0):     enabled.                                                                                           
(II) NVIDIA(0): NVIDIA GPU GeForce 7150M / nForce 630M (C67) at PCI:0:18:0                                             
(II) NVIDIA(0):     (GPU-0)                                                                                            
(--) NVIDIA(0): Memory: 262144 kBytes                                                                                  
(--) NVIDIA(0): VideoBIOS: 05.67.32.16.06                                                                              
(--) NVIDIA(0): Interlaced video modes are supported on this GPU                                                       
(--) NVIDIA(0): Connected display device(s) on GeForce 7150M / nForce 630M at                                          
(--) NVIDIA(0):     PCI:0:18:0:                                                                                        
(--) NVIDIA(0):     CMO (DFP-0)                                                                                        
(--) NVIDIA(0): CMO (DFP-0): 310.0 MHz maximum pixel clock                                                             
(--) NVIDIA(0): CMO (DFP-0): Internal Dual Link LVDS  
.....
(**) Option "dpms" "true"                                                                                              
(**) NVIDIA(0): DPMS enabled                                                                                           
-----

This happens with both nvidia drivers 177.82 and 180.22 
if I comment out the DPMS code in the daemon, /apparently/ the problem is solved.
Is it the driver or X? It seems that we have quite different video cards with the same issue.
xorg-server is version 1.3.0.0 if that might help.
Comment 10 Jacopo De Simoi 2009-01-29 15:58:23 UTC
The issue appears to be gone by commenting out the following call:
 
PowerDevilDaemon.cpp:~520

void PowerDevilDaemon::setUpDPMS()
{
...
  d->kscreenSaverIface->configure();
}

I am unable to further debug this call as I don't know what function corresponds to the dbus call. 
Can anybody confirm that?
Comment 11 Jacopo De Simoi 2009-01-31 08:00:25 UTC
I've done some additional research; apparently the dbus call itself hangs kded; I replaced the called function in krunner/screensaver with a function that just returns and the hang still persists. On the other hand the code in kcontrol/energy/ which does the same looks pretty much identical. But that one does not hang dbus, as it doesn't hang by directly calling the method with qdbus. 
I am most confused. 

Btw, Dario, what's the reason for calling the function with a delay?
QTimer::singleShot(300, this, SLOT(setUpDPMS()));

  Jacopo
Comment 12 Jacopo De Simoi 2009-02-03 06:47:10 UTC
The bug is caused by a dbus deadlock in the setProfile call; 
the powerdevil runner is waiting for the powerdevil daemon while the daemon is waiting for krunner/screensaver. 

Sometimes you can even get two deadlocks in a row (~50 secs) when changing profile with the battery applet or the runner because actually they call refreshStatus before setProfile; this actually means that if for some reason you are in a profile which is different from the "default", you'll get two calls to setProfile. *** is this the expected behaviour *** ?

Following a suggestion by Thiago, the patch works by letting powerdevil emit a signal which is received by krunner/screensaver without any deadlock.

-- it's my very first time to write code with dbus and such, so please have a look at the code; it's should be simple to see if I did something really bad-- 

Besides, this patch should fix also Bug #178642 (have a look at the code :P)

The patch is composed of one file for powerdevil/daemon and another one for krunner/screensaver

 J
Comment 13 Jacopo De Simoi 2009-02-03 06:48:03 UTC
Created attachment 30891 [details]
patch for the daemon
Comment 14 Jacopo De Simoi 2009-02-03 06:48:42 UTC
Created attachment 30892 [details]
patch for krunner
Comment 15 Dario Freddi 2009-02-07 13:06:20 UTC
SVN commit 922619 by dafre:

BUG: 177123
BUG: 178642
CCMAIL: jacopods@gmail.com

Applying Jacopo's patch, and removing generation of (now) useless kscreensaver interface.
This should solve every kind of problems with DPMS. I will backport to 4.2 soon



 M  +18 -0     krunner/screensaver/saverengine.cpp  
 M  +2 -2      powerdevil/daemon/CMakeLists.txt  
 M  +19 -14    powerdevil/daemon/PowerDevilDaemon.cpp  
 M  +3 -2      powerdevil/daemon/PowerDevilDaemon.h  
 M  +3 -2      powerdevil/daemon/org.kde.PowerDevil.xml  


WebSVN link: http://websvn.kde.org/?view=rev&revision=922619
Comment 16 Dario Freddi 2009-02-07 13:35:51 UTC
SVN commit 922628 by dafre:

BUG: 177123
BUG: 178642

Backporting to 4.2



 M  +18 -0     krunner/screensaver/saverengine.cpp  
 M  +2 -2      powerdevil/daemon/CMakeLists.txt  
 M  +19 -14    powerdevil/daemon/PowerDevilDaemon.cpp  
 M  +3 -2      powerdevil/daemon/PowerDevilDaemon.h  
 M  +3 -2      powerdevil/daemon/org.kde.PowerDevil.xml  


WebSVN link: http://websvn.kde.org/?view=rev&revision=922628
Comment 17 Dario Freddi 2009-02-08 13:27:56 UTC
*** Bug 182685 has been marked as a duplicate of this bug. ***
Comment 18 Jonathan Thomas 2009-03-04 17:17:24 UTC
*** Bug 184992 has been marked as a duplicate of this bug. ***
Comment 19 Jonathan Thomas 2009-03-19 20:00:11 UTC
*** Bug 183867 has been marked as a duplicate of this bug. ***