Bug 355687

Summary: Powerdevil does not act (e.g. suspend, dim) when switching to battery mode
Product: [Plasma] Powerdevil Reporter: Wilhelm Eger <wilhelm.eger>
Component: generalAssignee: Plasma Development Mailing List <plasma-devel>
Status: RESOLVED FIXED    
Severity: major CC: kde
Priority: NOR    
Version: 5.4.3   
Target Milestone: ---   
Platform: Arch Linux   
OS: Linux   
Latest Commit: Version Fixed In: 5.5.0
Sentry Crash Report:
Attachments: Patch to reenable the automatic brightness control due to mixed up absolute/relative values

Description Wilhelm Eger 2015-11-21 12:46:17 UTC
Hey,

I reported this loosely some time ago in the comments of this blogpost:

http://blog.broulik.de/2015/02/power-management-in-5-3/#comment-369

So the bug is still there. My system is a wetab, which is basically an old intel atom system (https://en.wikipedia.org/wiki/WeTab#Technical_specifications). Plasma runs fine on it. However, the following bug remains:

Let's say powerdevil is configured to dim the brightness of the screen to 50% when running in battery mode and to go to full brightness (100%) if the power cable is plugged in. Expected behavior would be to see the change in brightness when plugging the cable in and out.

However, I can only observe a dimming action when going from battery mode to plugged in mode. The brightness slider works. So I plug out the cable, slide brightness to 50%, plug the cable in and the brightness goes up to 100%.

The other way round, however, does not work. If I am in plugged in mode and the brightness is at 100%, the brightness stays at 100% when the cable is plugged out.

The system also does not go in suspend when being in battery mode even if it is switched on the configuration. This bothers me most.

So there seems to be a problem in that powerdevil does not act on being in battery mode even thought the modes are recognized (simply see by the change of the powerdevil icon when plugging, unplugging the cable).

I searched the systems for other daemons being repsonsible for this, e.g. tlp, laptop-mode etc. There is nothing on the computer like that. I also disabled systemd backlight control.

Btw. I just checked this behavior on my Acer 7750G (i5) with AMD graphics card. It is the same! I just never realized, as I never unplug the cable. Or very rarely.

So it seems not to be a hardware related bug.

Please let me know if you need more information.

Reproducible: Always

Steps to Reproduce:
1. Configure backlight to 50% for battery mode
2. Unplug cable to enter battery mode
3. Look at the backlight slider

Actual Results:  
Backlight is still at 100%

Expected Results:  
Backlight should switch to 50%
Comment 1 Kai Uwe Broulik 2015-11-21 13:44:43 UTC
Can you kill kded5 and run it from console? PowerDevil should print a debug message when it's switching profiles or changes brightness.
Comment 2 Wilhelm Eger 2015-11-21 14:34:13 UTC
powerdevil: 
powerdevil: Can't contact ck
powerdevil: We are now into activity  "9324fd99-91a1-41e2-a00b-7c23f09aaa1e"
powerdevil: () ()
powerdevil: () ()
powerdevil: Loading profile for unplugged AC
powerdevil: Activity is not forcing a profile
powerdevil: 
powerdevil: Loading timeouts with  120000
Created alarm 8388617
Created alarm 8388618
Created alarm 8388619
powerdevil: Profiles:  "Battery" "AC"
powerdevil: Screen brightness value:  9
powerdevil: Not changing brightness, the current one is lower and the profile is more conservative
Created alarm 8388620
Created alarm 8388621
Created alarm 8388622
Created alarm 8388623
powerdevil: 
powerdevil: Can't contact ck
powerdevil: We are now into activity  "9324fd99-91a1-41e2-a00b-7c23f09aaa1e"
powerdevil: () ()
powerdevil: () ()
powerdevil: Loading profile for plugged AC
powerdevil: Activity is not forcing a profile
powerdevil: 
powerdevil: Loading timeouts with  300000
Created alarm 8388624
Created alarm 8388625
Created alarm 8388626
powerdevil: Profiles:  "AC" "Battery"
powerdevil: Screen brightness value max:  9
powerdevil: set screen brightness value:  9
Created alarm 8388627
Created alarm 8388628
powerdevil: Udev device changed "/sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0/backlight/acpi_video0" "/sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0/backlight/acpi_video0"
Comment 3 Wilhelm Eger 2015-11-21 14:42:52 UTC
above was the laptop, this is the wetab

powerdevil: 
powerdevil: Can't contact ck
powerdevil: We are now into activity  "87d6f93d-1ae5-4285-9be2-762865f86d8e"
powerdevil: () ()
powerdevil: () ()
powerdevil: Loading profile for unplugged AC
powerdevil: Activity is not forcing a profile
powerdevil: 
powerdevil: Loading timeouts with  120000
Created alarm 8388618
Created alarm 8388619
Created alarm 8388620
Created alarm 8388621
Created alarm 8388622
powerdevil: Profiles:  "Battery" "AC"
powerdevil: Screen brightness value:  15
powerdevil: Not changing brightness, the current one is lower and the profile is more conservative
Created alarm 8388623
Created alarm 8388624
powerdevil: 
powerdevil: Can't contact ck
powerdevil: We are now into activity  "87d6f93d-1ae5-4285-9be2-762865f86d8e"
powerdevil: () ()
powerdevil: () ()
powerdevil: Loading profile for plugged AC
powerdevil: Activity is not forcing a profile
powerdevil: 
powerdevil: Loading timeouts with  300000
Created alarm 8388625
Created alarm 8388626
Created alarm 8388627
powerdevil: Profiles:  "AC" "Battery"
powerdevil: Screen brightness value max:  15
powerdevil: set screen brightness value:  15
Created alarm 8388628
Created alarm 8388629
powerdevil: Screen brightness value:  15
powerdevil: Brightness changed!!
powerdevil: Screen brightness value:  15
powerdevil: Brightness changed!!
Comment 4 Kai Uwe Broulik 2015-11-21 16:10:19 UTC
OK so we can see that it switches profiles when plugging in/out the AC. I don't see anything particularly noteworthy broken in the output  :/
Comment 5 Wilhelm Eger 2015-11-21 16:52:19 UTC
powerdevil: Screen brightness value:  9
powerdevil: Not changing brightness, the current one is lower and the profile is more conservative

My value for Battery Mode is 60 according to the config file. But 60 means 60 percent. Could it be that powerdevil tries to set 60 instead of 60 percent? In that case it would never be able to switch the brightness as the value is always lower (9<60). Maybe the calculation for the brightness level for the AC mode is correct, but for the battery mode is somehow weird and uses 60 as absolute value?

I tried to set my battery brightness to 6 to see if it gets changed, but then the screen went black and i had to restart.
Comment 6 Kai Uwe Broulik 2015-11-21 17:20:27 UTC
Thought so too. Could be. I'll have a look. that doesn't explain broken auto suspend
Comment 7 Wilhelm Eger 2015-11-22 13:59:28 UTC
Created attachment 95654 [details]
Patch to reenable the automatic brightness control due to mixed up absolute/relative values

This patch should deal with the problem of absolute and relative values being compared.
Comment 8 Wilhelm Eger 2015-11-22 14:04:04 UTC
Btw. autosuspend works for me on my laptop, so the bug on the wetab might be related to the kidletime library as you mentioned in the reply to the blog post above. I will have a look into this, too.
Comment 9 Wilhelm Eger 2015-11-22 14:32:09 UTC
https://bugs.kde.org/show_bug.cgi?id=355732
Comment 10 Kai Uwe Broulik 2015-11-22 15:01:17 UTC
Yes, we were right. Thanks for your help in investigating this! The code checks for if (m_defaultValue > brightness()) with m_defaultValue being the saved config value from 0-100 whereas brightness() is the absolute value from 0 to whatever the driver reports as maximum. I'll fix this.
Comment 11 Kai Uwe Broulik 2015-11-22 15:42:52 UTC
Please give a try to: https://git.reviewboard.kde.org/r/126138/
Comment 12 Wilhelm Eger 2015-11-22 15:56:47 UTC
I cannot log in to the review board due to missing KDE credentials.

Also, the patch does not apply to powerdevil 5.4.3, which version I am currently using. Thus I changed the 5.4.3 powerdevil accordingly and it works as expected.

However, the keyboard brightness could not be verified as I do not have keyboard leds.

You might consider changing absoluteBrightnessValue to keyboardabsoluteBrightnessValue for the keyboardbrightnesscontrol.cpp to keep the naming consistent.
Comment 13 Kai Uwe Broulik 2015-11-23 14:12:33 UTC
Git commit 6b4ffe32367a6413d8c270480445a4955d63e71f by Kai Uwe Broulik.
Committed on 23/11/2015 at 14:02.
Pushed by broulik into branch 'Plasma/5.5'.

Use absolute brightness value in conservative check when loading profile

There's a check that ensures the brightness isn't ramped up when we switch
to a more conservative profile and then current brightness is lower.
However, it compared the raw hardware value with the config percentage value.
FIXED-IN: 5.5.0
REVIEW: 126138

M  +7    -6    daemon/actions/bundled/brightnesscontrol.cpp
M  +6    -6    daemon/actions/bundled/keyboardbrightnesscontrol.cpp

http://commits.kde.org/powerdevil/6b4ffe32367a6413d8c270480445a4955d63e71f
Comment 14 Martin Flöser 2016-06-21 16:59:42 UTC
*** Bug 355732 has been marked as a duplicate of this bug. ***