fah-issues icon indicating copy to clipboard operation
fah-issues copied to clipboard

FAHClient does not detect "on battery" state correctly (Linux)

Open milos7250 opened this issue 4 years ago • 4 comments

Your issue may already be reported! Please search on the issue tracker before creating one.

Your Environment

  • F@H Software version: 7.6.13
  • Operating System: Linux 5.8.16-2-MANJARO x86_64
  • Browser: Brave (not important) NVIDIA Optimus laptop (Lenovo Y50-70) Gnome desktop with X11 display

Expected Behavior

FAHClient stops folding when AC power is disconnected.


Current Behavior

FAHClient does not stop folding when AC power is disconnected. The "on battery" state is always false.


Possible Solution (Optional)

I discussed this issue on Discord and found out that FAHClient uses cbang to determine battery state. In the cbang code, they refer to AC power supplies by path /sys/class/power_supply/AC or /sys/class/power_supply/AC0. The problem is that on my laptop, the power supply device is listed as /sys/class/power_supply/ACAD. Running $ cat /sys/class/power_supply/ACAD/online returns 0 or 1 correctly.


Steps To Reproduce

I do not know how hard it is to reproduce this, as I do not know whether or not the device name can be manually adjusted or not.


Context

Well, obviously, while trying to fold on my laptop, I'd love to have the ability to automatically pause folding when not connected to the wall. Right now, it is a bit obnoxius, having to run FAHControl to manually pause/unpause the client.

On a possibly related note: Another thing I noticed in the cbang code is that cbang is responsible for detecting the idle state. This is also not working right now on my laptop. I can't however figure out what information it gathers to detect the idle state.


milos7250 avatar Nov 01 '20 17:11 milos7250

On my Lenovo V130 the ACPI Power Supply name is ADP1:

[oreggin@v130 ~]$ sudo dmesg | grep 'AC Adapter'
[    4.909777] ACPI: AC Adapter [ADP1] (off-line)
[oreggin@v130 ~]$

The OS is the same.

oreggin avatar Nov 01 '20 20:11 oreggin

Alright, so we found a workaround for this problem, using udev rule and a little shell script.

I created a file /etc/udev/rules.d/80-power.rules: SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="\"/path/to/script.sh"" SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="1", RUN+="\"/path/to/script.sh""

The content of the shell script:

#!/bin/sh

if [ $(cat /sys/class/power_supply/ACAD/online) = 1 ]; then
	FAHClient --send-unpause
else
	FAHClient --send-pause
fi

This might work without the script by simply putting RUN+="FAHClient --send-pause" in the udev rule, but I haven't tried that.

The biggest catch however is that you have to edit the udev service file to allow it to use network. I edited the file /lib/systemd/system/systemd-udevd.service and below the [Service] tag at the bottom there is a line saying IPAddressDeny=any. This denies all udev rules from using network. I added a line before that saying IPAddressAllow=localhost.

Save the service file and then run

# systemctl daemon-reload
# systemctl restart systemd-udevd

If you want to stop a short power disconnects from pausing and unpausing folding, add sleep 10 to the beginning of the shell script.

milos7250 avatar Nov 01 '20 23:11 milos7250

Hiya @milos7250

Just wondering if this also happens in the latest release, V7.6.21 (https://foldingathome.org/alternative-downloads/)?

PantherX avatar Nov 15 '20 04:11 PantherX

Hey,

Yes, I've just installed the 7.6.21 version (from AUR, if that's relevant) and the problem still remains.

milos7250 avatar Nov 15 '20 08:11 milos7250