Gibtnix / MSIKLM

Control the SteelSeries keyboard of your MSI gaming notebook with Linux
GNU General Public License v3.0
242 stars 50 forks source link

Backlight flickers after ubuntu 21.04 update #39

Closed gabriele2000 closed 3 years ago

gabriele2000 commented 3 years ago

Basically if I run sudo msiklm green the backlight of medium and low is stable (I control the intensity through hotkeys, of course) but when I create the autostart rule through ./autostart.sh green when I reboot the medium and the lower intensity are flickering... I "investigated" and it seems there is a reset happening, like, 50 times a second, even more, because if I run sudo msiklm red the color changes to red, but only for a fraction of second, then it returns to green... this is clearly not the intended behaviour, nor the one that I had before updating to ubuntu 21.04... oh, pardon, it's pop_os 21.04

Gibtnix commented 3 years ago

Actually it's hard to say anything about this without further testing which is pretty much impossible for me without a respective device. If it is caused by an automatic reset, my first try would be to add a sleep 1 to delay the executing by one second (adjust the time to whatever delay you want to try, maybe even much longer is also worth a try) by adding this to to command in the udev rule. So either after creating the rules file, manually edit it and extend the RUN+=/usr/local/bin/msiklm part to RUN+= sleep 1 ; /usr/local/bin/msiklm. Alternatively, you can also modify the autostart script to directly create a modified rules, i.e. replace RUN+=\"$msiklm " by RUN+=\"sleep 1 ; $msiklm " and re-run the script.

WARrior-Alex commented 3 years ago

Some additional info about this issue: it flickers because udev always bind and unbind the keyboard. And it happens only with udev-rules script. Also udev takes too much CPU for this action.

WARrior-Alex commented 3 years ago

Here is some logs from udevadm monitor:

KERNEL[47.734346] remove   /devices/pci0000:00/0000:00:14.0/usb1/1-7/1-7:1.0/0003:1770:FF00.059B (hid)
KERNEL[47.734377] unbind   /devices/pci0000:00/0000:00:14.0/usb1/1-7/1-7:1.0 (usb)
KERNEL[47.737100] add      /devices/pci0000:00/0000:00:14.0/usb1/1-7/1-7:1.0/0003:1770:FF00.059C (hid)
KERNEL[47.737134] bind     /devices/pci0000:00/0000:00:14.0/usb1/1-7/1-7:1.0 (usb)
UDEV  [47.737529] add      /devices/pci0000:00/0000:00:14.0/usb1/1-7/1-7:1.0/0003:1770:FF00.0599 (hid)
UDEV  [47.739500] bind     /devices/pci0000:00/0000:00:14.0/usb1/1-7/1-7:1.0 (usb)
UDEV  [47.740698] remove   /devices/pci0000:00/0000:00:14.0/usb1/1-7/1-7:1.0/0003:1770:FF00.0599 (hid)
UDEV  [47.742015] unbind   /devices/pci0000:00/0000:00:14.0/usb1/1-7/1-7:1.0 (usb)

And it repeats always! But if I disable autostart via udev rules and start msiklm via command line, it works normally.

gabriele2000 commented 3 years ago

That's why the CPU is always at 22%! And I've got an i7-7700HQ

Gibtnix commented 3 years ago

Well, might this be a problem related to udev that it keeps reporting the device over and over again? If the device is reconnected again, the udev rule triggers msiklm, that's normal. So in my opinion, the flickering is simply caused from udev. I don't know whats going wrong here... maybe it's worth a try to use a Live Linux running from USB and check if this reproduces the issue or not.

WARrior-Alex commented 3 years ago

This problem started from last update of OS: Ubuntu by @gabriele2000 and Fedora by me. So there is some breaking change in udev (as I think). But I have no any experience with udev, so cannot propose any solution. But I'm ready to help with test and/or debug to find a fix for this issue.

WARrior-Alex commented 3 years ago

BTW, I've made clear install of msiklm, but it doesn't help

WARrior-Alex commented 3 years ago

@Gibtnix can you specify, how to test this with live cd. The problem always begins after reboot. So, probably we need to clean install of latest version of OS?

WARrior-Alex commented 3 years ago

May be this issue caused by this? https://github.com/systemd/systemd/blob/main/NEWS#L907-L1016 BTW I have now systemd-udev v248.

Gibtnix commented 3 years ago

@WARrior-Alex Testing with a Live Linux (USB / CD) should be possible by using the standby / power saving mode instead of a reboot. Resuming from standby mode should reset the keyboard similarly to a reboot and the udev rule should be triggered, at least if I remember correctly. It might be necessary to run something like udevadm control --reload-rules && udevadm trigger before.

I don't really know whats going wrong with udev. Maybe the behavior changed somehow and there is a simple fix for this in the rules file which is created by the autostart script. I tried to find out something about this, still I didn't find a fix. If there is any modification required I will fix it as soon as I have the information what has to be changed.

WARrior-Alex commented 3 years ago

@Gibtnix Just tested with Fedora 34 Live CD. After compile/install/udevadm-script all was fine. But when I put my note to stand by and back online the issue repeated. So you are right - the problem is with udev script.

Gibtnix commented 3 years ago

Thanks for this information. I do not know how this can be fixed but at least your tests helped a lot in locating the problem. I asked a question about this at askubuntu, hopefully someone knows how this can be fixed.

gabriele2000 commented 3 years ago

Thanks for this information. I do not know how this can be fixed but at least your tests helped a lot in locating the problem. I asked a question about this at askubuntu, hopefully someone knows how this can be fixed.

I don't know how, but I think it's fixed... I'm using a custom kernel, xanmod (5.12.12 updated today) and the problem disappeared

Gibtnix commented 3 years ago

So maybe it was simply a small bug? At least it seems to be fixed for the moment...

gabriele2000 commented 3 years ago

So maybe it was simply a small bug? At least it seems to be fixed for the moment...

Yeah, I'll check the changelog for 5.12.12 kernel because 5.12.11 still had the issue EDIT: strange I can't see anything relevant here maybe it's because I don't understand too much of this...

WARrior-Alex commented 3 years ago

Just received kernel update v.5.12.12 and conirm that all is working fine. The issue can be closed now. Thank you!

Gibtnix commented 3 years ago

Alright and thanks for this information. I will close the issue then 👍

MiguelAngelLV commented 3 years ago

In Manjaro, with 5.13.4, the bug persists

Gibtnix commented 3 years ago

Thanks for pointing out, still I think I cannot really do something to fix it.