You are not logged in.

#1 2013-12-30 20:33:05

rin
Member
Registered: 2013-12-24
Posts: 31

[SOLVED] How to identify what is changing brightness

I have a Lenovo L430.
I'm using xfce and xfwm.
When I press the brightness up/down buttons on my keyboard, they don't work properly. When I press them, a dialog appears in the middle of my screen with a sun and a brightness bar that goes up and down (which looks fine) but the brightness itself doesn't change when it should.

I have to press the brightness up button like 5 times before it changes the brightness, and then it pretty much doubles in brightness instead of going up step by step. It seems to have 3 brightness levels. Dark as possible, medium, and super bright.

Here's what I've done to try and fix it.

I'm trying to use acpi. I first got acpi working with volume control, to figure out how to use it.
Now for the brightness, I've changed /etc/acpi/handler.sh and added lines to change the brightness, for example:

bl_dev=/sys/class/backlight/acpi_video0
b_step=5
... # somewhere in the case block
    video/brightnessup)
        case "$2" in
            BRTUP)
                logger 'BrtUp pressed'
                echo $((`cat $bl_dev/brightness` + $b_step)) >$bl_dev/brightness
                ;;
        esac
        ;;

Which works fine from the command line, and the line is definitely getting reached (I can see my custom log message (BrtUp pressed) with journalctl -f)

But this isn't working. I'm guessing that whatever was getting controlled by the brightness buttons before, is still doing it. If this is the case, I think I need to disable it and let acpi be the only handler. But I have no idea what it could be!
Edit: I'm pretty sure that there are indeed two things getting invoked when the brightness key is pressed - I can see a flicker of brightness change when I press it, then back to what it was before, meaning the acpi code gets called then the other thing gets called?

Any help or pointers would be much appreciated. Thanks!

Last edited by rin (2014-02-21 22:48:22)

Offline

#2 2014-01-02 15:02:46

outro_tipo
Member
Registered: 2013-03-08
Posts: 28

Re: [SOLVED] How to identify what is changing brightness

check /sys/class/backlight/. maybe you are changing acpi_video0/actual_brightness and your monitor is actualy using /intel_backlight/actual_brightness. happened to me before

Offline

#3 2014-01-02 18:26:59

rin
Member
Registered: 2013-12-24
Posts: 31

Re: [SOLVED] How to identify what is changing brightness

outro_tipo wrote:

check /sys/class/backlight/. maybe you are changing acpi_video0/actual_brightness and your monitor is actualy using /intel_backlight/actual_brightness. happened to me before

I think you're onto something here! I did a little experimenting...
Sorry for the large post, I wanted to keep these notes, and I thought I might as well leave them here in case someone does find them useful.

tom@nyx:/sys/class/backlight$ ls *
acpi_video0:
actual_brightness  brightness  max_brightness  subsystem  uevent
bl_power           device      power           type

intel_backlight:
actual_brightness  brightness  max_brightness  subsystem  uevent
bl_power           device      power           type
tom@nyx:/sys/class/backlight$ grep '' */{brightness,actual_brightness}
acpi_video0/brightness:50
intel_backlight/brightness:833
acpi_video0/actual_brightness:50
intel_backlight/actual_brightness:833

50 means 50% (I think?) and the screen does appear to be at half brightness. Everything looks fine so far.
Now, I'll try to change the brightness through each of these files. (I can't change the actual_brightness files because they're read only.)

First, acpi_video0/brightness:

tom@nyx:/sys/class/backlight$ echo 70 | sudo tee acpi_video0/brightness 
70
tom@nyx:/sys/class/backlight$ grep '' */{brightness,actual_brightness}
acpi_video0/brightness:70
intel_backlight/brightness:2210
acpi_video0/actual_brightness:70
intel_backlight/actual_brightness:2210

The brightness seems to have changed by the correct amount on my screen, and both the acpi and intel file contents look reasonable. Setting it back to how it was works fine too.

tom@nyx:/sys/class/backlight$ echo 50 | sudo tee acpi_video0/brightness 
50
tom@nyx:/sys/class/backlight$ grep '' */{brightness,actual_brightness}
acpi_video0/brightness:50
intel_backlight/brightness:833
acpi_video0/actual_brightness:50
intel_backlight/actual_brightness:833

Next, intel_backlight/brightness. I'll go for 2210, so it should be the same brightness as the other one:

tom@nyx:/sys/class/backlight$ echo 2210 | sudo tee intel_backlight/brightness
tom@nyx:/sys/class/backlight$ grep '' */{brightness,actual_brightness}
acpi_video0/brightness:50
intel_backlight/brightness:2210
acpi_video0/actual_brightness:50
intel_backlight/actual_brightness:2210

Not what I expected there! The screen's brightness did increase by the same amount, but the acpi files didn't change.

Reverting back works fine.

tom@nyx:/sys/class/backlight$ echo 833 | sudo tee intel_backlight/brightness
833
tom@nyx:/sys/class/backlight$ grep '' */{brightness,actual_brightness}
acpi_video0/brightness:50
intel_backlight/brightness:833
acpi_video0/actual_brightness:50
intel_backlight/actual_brightness:833

Not sure what's going on there. Anyway, next I'll try using the button on my laptop (Fn+F9) to increase the brightness.
The brightness and actual_brightness files are the same, so I'll only paste one in.
Starting at 50 and 833:

# press increase brightness button
acpi_video0/brightness:61
intel_backlight/brightness:833
# no visable brightness change

# press increase brightness button
acpi_video0/brightness:72
intel_backlight/brightness:833
# no visable brightness change

# press increase brightness button
acpi_video0/brightness:83
intel_backlight/brightness:833
# no visable brightness change

# press increase brightness button
acpi_video0/brightness:94
intel_backlight/brightness:833
# no visable brightness change

# press increase brightness button
acpi_video0/brightness:100
intel_backlight/brightness:4335
# screen goes to max brightness

And, back down again, pressing the brightness decrease button this time (Fn+F8)

# press decrease brightness button
acpi_video0/brightness:89
intel_backlight/brightness:4335
# no visable brightness change

# press decrease brightness button
acpi_video0/brightness:78
intel_backlight/brightness:4335
# no visable brightness change

# press decrease brightness button
acpi_video0/brightness:67
intel_backlight/brightness:4335
# no visable brightness change

# press decrease brightness button
acpi_video0/brightness:56
intel_backlight/brightness:4335
# no visable brightness change

# press decrease brightness button
acpi_video0/brightness:45
intel_backlight/brightness:612
# brightness changes!

# 5 more presses and the output is:
acpi_video0/brightness:0
intel_backlight/brightness:612
# no matter how many presses, can't decrease brightness.

After a lot more experimenting with echoing to acpi_brightness (and using xbacklight), there are only a few specific values that actually change the brightness. In my experiments above I used 50 and 70, which are two of these. The full list is: 100, 90, 80, 70, 65, 60, 55, 50, 45, 40, 35, 30, 25, 20, 10, 5. Note that 0 isn't in the list. Echoing any of these numbers to acpi_brightness changes the screen's brightness (and the value of intel_backlight/brightness). Any other number only changes the acpi_brightness file and not the screen (nor the intel file).
So the brightness hotkey modifies this file and goes up in increments of 11, which explains why it only changes the brightness every 5 clicks. Funnily enough, the increment/decrement step was 10, not 11, yeseterday, and 16 the day before. Who knows what's going on there.

This explains why using the xfce4 panel brightness plugin slider usually works. Because I drag the slider slowly, it must go through all the values one by one. If I jerk the mouse and move it fast enough down to 0 (a number not in 'the list') so that it doesn't register the intermediate values, there's no brightness change, so it must be using acpi_video0/brightness.

Any value (in range) echoed to the intel file correctly changes the brightness. Even 0 (which turns off the backlight, beware!). Changing the intel file never seems to change the acpi file.

So, I changed /etc/acpi/handler.sh to use intel_brightness, thinking it would fix everything. But it's not working! There are still two things trying to change the brightness when I press the button! I can see a flicker of two different brightness changes when I press the button. First it increases, then it reverts, in a fraction of a second. Likewise for decreasing.

Is there a trick I can use to see what's writing to acpi_video0/brightness? Is there some sort of lsof argument to "follow" a specific file?

Offline

#4 2014-01-02 18:53:47

vacant
Member
From: downstairs
Registered: 2004-11-05
Posts: 816

Re: [SOLVED] How to identify what is changing brightness

As you're using xfce and you've found an array of values that do work, you could use a few of them (say five) in a script to give sensible changes to brightness each time you tap the relevant key.

My max_brightness is 2800 and I use this script and set F7  "up" and F6 "down" in settings -> keyboard -> application shortcuts (using Arch on a Samsung ARM chromebook, Arch on my Acer 5742z worked out of the box).

#!/bin/bash
NOW=`pkexec xfpm-power-backlight-helper --get-brightness`
MAX=`pkexec xfpm-power-backlight-helper --get-max-brightness`
if [ $1 == "up" ] ; then
    let "NOW += 200"
elif [ $1 == "down" ] ; then
    let "NOW -= 200"
fi
pkexec xfpm-power-backlight-helper --set-brightness $NOW > /dev/null
NOW=`pkexec xfpm-power-backlight-helper --get-brightness`
let "MAX = NOW * 100 / $MAX"
notify-send -t 1500 "brightness" "$MAX%  ($NOW)"

Offline

#5 2014-01-02 19:03:16

rin
Member
Registered: 2013-12-24
Posts: 31

Re: [SOLVED] How to identify what is changing brightness

vacant wrote:

As you're using xfce and you've found an array of values that do work, you could use a few of them (say five) in a script to give sensible changes to brightness each time you tap the relevant key.

I'll do this as a last resort, if I can't get my dedicated brightness keys working. Thanks!

Offline

#6 2014-01-02 22:54:07

outro_tipo
Member
Registered: 2013-03-08
Posts: 28

Re: [SOLVED] How to identify what is changing brightness

so as i understood the keys are changing acpi's and what controlls your brightness is intel's? sorry im in a hurry. if that is it try creating something like this in /etc/X11/xorg.conf.d :

Section "Device"
        Identifier "intel_backlight"
        Driver  "Intel"
        Option "Backlight" "intel_backlight"
EndSection

sorry if it doesnt help. ill pass here soon to check more carefully.

Offline

#7 2014-01-02 23:45:30

rin
Member
Registered: 2013-12-24
Posts: 31

Re: [SOLVED] How to identify what is changing brightness

outro_tipo wrote:

so as i understood the keys are changing acpi's and what controlls your brightness is intel's? sorry im in a hurry. if that is it try creating something like this in /etc/X11/xorg.conf.d :

Section "Device"
        Identifier "intel_backlight"
        Driver  "Intel"
        Option "Backlight" "intel_backlight"
EndSection

sorry if it doesnt help. ill pass here soon to check more carefully.

I think you are on to something :) Pressing the brightness buttons is now changing the value of intel_backlight/brightness, instead of acpi_video0/brightness.

But now there's only two brightness values reachable by using the hotkeys.
The values in intel_backlight/brightness are 390 and 1276 depending on whether I press brightness down or up. If I echo a different value to acpi_video0/brightness, these two brightness values are different.
Here's some examples:
acpi 10, intel 0/545
acpi 30, intel 0/698
acpi 40, intel 16/902
acpi 50, intel 390/1276
acpi 70, intel 1767/2653
acpi 100, intel 3892/4437
where intel_backlight/max_brightness = 4437

I have no idea why this could be happening.

I am going to kill my X server and see if there's any unusual behaviour from a text terminal.
Edit: the hotkeys don't work, but echoing to the backlight files works the same.

Edit 2: I've never written a xorg conf file before, so I don't know if what I'm about to ask is possible: can I modify the backlight file I just created in xorg.conf.d to give X no option/driver for Backlight? Then I can let the acpi handler be the only thing that controls it?

Last edited by rin (2014-01-03 00:06:02)

Offline

#8 2014-01-03 01:46:27

outro_tipo
Member
Registered: 2013-03-08
Posts: 28

Re: [SOLVED] How to identify what is changing brightness

ok i just realized i didnt say something in my first comment. and then forgot completely. have you tried changing this in your /etc/acpi/handler.sh

bl_dev=/sys/class/backlight/acpi_video0

to this:

bl_dev=/sys/class/backlight/intel_backlight

Edit 2: I've never written a xorg conf file before, so I don't know if what I'm about to ask is possible: can I modify the backlight file I just created in xorg.conf.d to give X no option/driver for Backlight? Then I can let the acpi handler be the only thing that controls it?

i think the problem is xfce since X doest respont to the "fn" keys without you assigning something to them with some script/software.
if you are running xfce4-power-manager try killing it to see if it makes any difference.

Offline

#9 2014-01-03 09:57:54

rin
Member
Registered: 2013-12-24
Posts: 31

Re: [SOLVED] How to identify what is changing brightness

outro_tipo wrote:

ok i just realized i didnt say something in my first comment. and then forgot completely. have you tried changing this in your /etc/acpi/handler.sh

bl_dev=/sys/class/backlight/acpi_video0

to this:

bl_dev=/sys/class/backlight/intel_backlight

Yes I did that, but it wasn't working. I mean, it was getting run and setting the brightness correctly, but then immediately after, something else changes the brightness back. (Edit: actually it's the other way round - see edit below)

outro_tipo wrote:

i think the problem is xfce since X doest respont to the "fn" keys without you assigning something to them with some script/software.
if you are running xfce4-power-manager try killing it to see if it makes any difference.

I killed it, no difference. What I have noticed is that before I log in, with just lightdm running and no xfce, I still have the problem. Which is, brightness keys control intel brightness but there are only two levels.
Here are the relevant parts of my hander.sh

# Brightness level
bl_dev=/sys/class/backlight/intel_backlight
# Brightness level step
b_step=200

case "$1" in
    video/brightnessup)
        case "$2" in
            BRTUP)
                logger 'BrtUp pressed'
                echo $((`cat $bl_dev/brightness` + $b_step)) >$bl_dev/brightness
                ;;
        esac
        ;;
    video/brightnessdown)
        case "$2" in
            BRTDN)
                logger 'BrtDn pressed'
                echo $((`cat $bl_dev/brightness` - $b_step)) >$bl_dev/brightness
                ;;
        esac
        ;;

Also, after adding the xorg conf file, the xfce panel brightness plugin (basically a GUI slider) controls intel brightness instead of acpi brightness.

Edit:
I have added "sleep 1" into handler.sh, before the lines that change the brightness. This is what happens
# before
/sys/class/backlight/acpi_video0/brightness:50
/sys/class/backlight/intel_backlight/brightness:1476

# 0.5 seconds after pressing brightness up (before handler.sh code), visible DROP in brightness
/sys/class/backlight/acpi_video0/brightness:50
/sys/class/backlight/intel_backlight/brightness:1276

# after sleep 1 completes in handler.sh, brightness is back to what it was
/sys/class/backlight/acpi_video0/brightness:50
/sys/class/backlight/intel_backlight/brightness:1476

I think the drop in brightness is because acpi_video0/brightness is 50, so it thinks it's raising the brightness.
For pressing the brightness decrease button, this is what happens

# before
/sys/class/backlight/acpi_video0/brightness:50
/sys/class/backlight/intel_backlight/brightness:1476

# 0.5 seconds after pressing brightness down, visible drop in brightness
/sys/class/backlight/acpi_video0/brightness:50
/sys/class/backlight/intel_backlight/brightness:390

# after sleep 1 completes in handler.sh, brightness drops even more
/sys/class/backlight/acpi_video0/brightness:50
/sys/class/backlight/intel_backlight/brightness:190

Pressing brightness up again after this:
/sys/class/backlight/acpi_video0/brightness:50
/sys/class/backlight/intel_backlight/brightness:1276
/sys/class/backlight/acpi_video0/brightness:50
/sys/class/backlight/intel_backlight/brightness:1476
Same as pressing brightness up before.

This is the reason it drops by exactly the same amount as my step variable: I changed the step variable in handler.sh to 300, and it went 1476 -> 1276 -> 1576. Then pressing it again: 1576 -> 1276 -> 1576.
So to conclude, something reads acpi_video and modifies intel_backlight?

Edit: the same thing was happening (two brightness changes) when I logged off, stopped lightdm and X. So I don't think it's xfce or X after all.

Edit: a workaround I am considering is storing the brightness in a file in /tmp, and reading that in /etc/acpi/handler.sh

Last edited by rin (2014-01-03 10:47:34)

Offline

#10 2014-01-04 15:06:42

outro_tipo
Member
Registered: 2013-03-08
Posts: 28

Re: [SOLVED] How to identify what is changing brightness

can you post lsmod output please. just to check any strange modules about video output.

Offline

#11 2014-01-05 13:31:05

rin
Member
Registered: 2013-12-24
Posts: 31

Re: [SOLVED] How to identify what is changing brightness

outro_tipo wrote:

can you post lsmod output please. just to check any strange modules about video output.

Module                  Size  Used by
fuse                   74768  3 
x86_pkg_temp_thermal     6999  0 
intel_powerclamp        8642  0 
coretemp                6334  0 
kvm                   388773  0 
crct10dif_pclmul        4754  0 
crct10dif_common        1380  1 crct10dif_pclmul
crc32_pclmul            3027  0 
crc32c_intel           14257  0 
ghash_clmulni_intel     4509  0 
aesni_intel            46100  2 
r8169                  58463  0 
aes_x86_64              7407  1 aesni_intel
snd_hda_codec_hdmi     30162  1 
lrw                     3573  1 aesni_intel
arc4                    2008  2 
gf128mul                5866  1 lrw
snd_hda_codec_realtek    41263  1 
rtl8192ce              50623  0 
rtl_pci                15594  1 rtl8192ce
rtlwifi                47739  2 rtl_pci,rtl8192ce
glue_helper             4617  1 aesni_intel
ablk_helper             1980  1 aesni_intel
cryptd                  8481  3 ghash_clmulni_intel,aesni_intel,ablk_helper
i915                  657793  2 
snd_hda_intel          36904  4 
btusb                  18632  0 
rtl8192c_common        36701  1 rtl8192ce
bluetooth             309116  2 btusb
mac80211              468122  3 rtl_pci,rtlwifi,rtl8192ce
snd_hda_codec         150305  3 snd_hda_codec_realtek,snd_hda_codec_hdmi,snd_hda_intel
thinkpad_acpi          61357  1 
tpm_tis                10694  0 
mii                     4035  1 r8169
iTCO_wdt                5407  0 
cfg80211              412886  2 mac80211,rtlwifi
tpm                    15091  1 tpm_tis
nvram                   5882  1 thinkpad_acpi
iTCO_vendor_support     1937  1 iTCO_wdt
intel_agp              10880  1 i915
evdev                  11085  23 
rtsx_pci_ms             7266  0 
memstick                7472  1 rtsx_pci_ms
intel_gtt              12664  2 i915,intel_agp
microcode              15216  0 
drm_kms_helper         36286  1 i915
snd_hwdep               6340  1 snd_hda_codec
drm                   238206  3 i915,drm_kms_helper
psmouse                85460  0 
tpm_bios                9753  1 tpm
rfkill                 15651  4 cfg80211,thinkpad_acpi,bluetooth
snd_pcm                77709  3 snd_hda_codec_hdmi,snd_hda_codec,snd_hda_intel
serio_raw               5049  0 
pcspkr                  2035  0 
snd_page_alloc          7242  2 snd_pcm,snd_hda_intel
wmi                     8419  0 
i2c_algo_bit            5399  1 i915
i2c_i801               11277  0 
snd_timer              18726  1 snd_pcm
thermal                 8532  0 
ac                      3332  0 
i2c_core               24164  5 drm,i915,i2c_i801,drm_kms_helper,i2c_algo_bit
battery                 6837  0 
snd                    59141  18 snd_hda_codec_realtek,snd_hwdep,snd_timer,snd_hda_codec_hdmi,snd_pcm,snd_hda_codec,snd_hda_intel,thinkpad_acpi
processor              24935  0 
mei_me                  9400  0 
mei                    62286  1 mei_me
lpc_ich                13376  0 
video                  11228  1 i915
button                  4677  1 i915
shpchp                 25465  0 
soundcore               5450  1 snd
ext4                  474251  1 
crc16                   1367  2 ext4,bluetooth
mbcache                 6082  1 ext4
jbd2                   83504  1 ext4
sr_mod                 14898  0 
sd_mod                 30821  3 
cdrom                  34848  1 sr_mod
rtsx_pci_sdmmc         14332  0 
mmc_core               95691  1 rtsx_pci_sdmmc
ahci                   23056  2 
libahci                21674  1 ahci
libata                170856  2 ahci,libahci
scsi_mod              130701  3 libata,sd_mod,sr_mod
ehci_pci                4000  0 
xhci_hcd              145185  0 
ehci_hcd               59220  1 ehci_pci
rtsx_pci               32209  2 rtsx_pci_ms,rtsx_pci_sdmmc
usbcore               180136  4 btusb,ehci_hcd,ehci_pci,xhci_hcd
usb_common              1656  1 usbcore

Offline

#12 2014-01-07 06:58:31

lin
Member
From: Kilifi
Registered: 2014-01-07
Posts: 2
Website

Re: [SOLVED] How to identify what is changing brightness

Hello,

The best way to change backlight brightness is to use the ACPI_VENDOR BIOS calls to manage backlight.
To use them, add the line:
acpi_backlight=vendor acpi_osi=linux

To the end of GRUB_CMDLINE_LINUX
in /etc/default/grub

Good luck.


Make install.
Not conflict.

Offline

#13 2014-02-21 22:48:05

rin
Member
Registered: 2013-12-24
Posts: 31

Re: [SOLVED] How to identify what is changing brightness

Solved smile

I have this in my /etc/default/grub now
GRUB_CMDLINE_LINUX_DEFAULT="quiet acpi_osi='!Windows 2012'"

And the final step was stopping xfce4-power-manager from also trying to control the brightness at the same time:
xfconf-query -c xfce4-power-manager -n -p "/xfce4-power-manager/change-brightness-on-key-events" -t bool -s false

And disabling the annoying brightness popup:
xfconf-query -c xfce4-power-manager -n -p "/xfce4-power-manager/show-brightness-popup" -t bool -s false

Offline

Board footer

Powered by FluxBB