linrunner / TLP

TLP - Optimize Linux Laptop Battery Life
https://linrunner.de/tlp
GNU General Public License v2.0
2.68k stars 128 forks source link

Battery care support for Acer laptops - how to re-engineer? #596

Open wojpawlik opened 2 years ago

wojpawlik commented 2 years ago

I own Acer SF314-43. What tools can I use to investigate how Acer Care Center communicates with hardware?

linrunner commented 2 years ago

I have no idea, but I leave it open here, in case someone who reads here knows it.

dxvsh commented 2 years ago

@wojpawlik Hey, I have the exact same laptop! I'm running a windows/void linux dualboot and I have a curious observation to report. I limited the battery charging threshold to 80% using the acer care center and it works exactly as advertised on windows. But somehow, this setting persists even when running linux! So now, the battery stops charging at 80 even inside linux. Acer care center is just a normal windows program but strangely its setting survives across different operating systems just as if it were a bios setting.

It would be great if this gets working in tlp so people won't have to set up a dualboot just to limit the battery charge percentage. Here's hoping someone figures this one out. Good luck folks!

Bartvelp commented 2 years ago

Just to chime in, @dxmuses. Setting a battery charging limit in the Acer Care Center and then booting into linux worked for me as well. But at some time, it just stopped charging even when it was below 80%. This was actually really annoying since windows wanted to update and did not boot because my battery was below 25%, but I also couldn't charge it. So this method can actually be sort of "dangerous". Another reason that getting it to work in TLP would be nice.

dxvsh commented 2 years ago

@Bartvelp That sounds rough. Sorry if I landed you in some trouble! In my case though, I've had this setting turned on for about a week now and its been working fine between linux and windows so far. There could be so many variations between your setup and mine that its hard to pinpoint what could be causing this strange behavior [eg: might be a different (bios/kernel/windows version/some other setting?)].

But you're totally right, it'd be much safer and cleaner to have this working in tlp. Someday, I hope!

balthier82 commented 2 years ago

Hi guys, I have an Acer Nitro 5. I would really need the plugin for this laptop. I hope someone can figure out how to do this.

linrunner commented 2 years ago

Please save your declarations of wanting to have. They do nothing at all here in the issue. One of you Acer owners has to go and program a corresponding extension of the kernel driver. Writing the plugin is then trivial.

frederik-h commented 2 years ago

Please save your declarations of wanting to have. They do nothing at all here in the issue. One of you Acer owners has to go and program a corresponding extension of the kernel driver. Writing the plugin is then trivial.

I have implemented an experimental kernel driver for Acer's WMI battery control interface. So far I have only tested it on a Swift 3, but I would expect that Acer uses the same interface on other laptops as well. If you give it a try, please let me know if it works on your system.

linrunner commented 2 years ago

@frederik-h Great. It's nice when the light appears at the end of the tunnel. I suggest you include a note in your driver documentation about the percentage where charging stops when health mode is active. I will need the value for the TLP docs as well.

Are you planning to submit the driver for the mainline kernel?

frederik-h commented 2 years ago

@frederik-h Great. It's nice when the light appears at the end of the tunnel. I suggest you include a note in your driver documentation about the percentage where charging stops when health mode is active. I will need the value for the TLP docs as well.

I will add it. It stops at 79% on my system. I could not find any methods to modify this threshold. From the Acer Care Center screenshots and documentation that I have seen, I assume that the threshold is fixed. I have no Windows installation to verify the actual settings that are available in the Care Center.

Are you planning to submit the driver for the mainline kernel?

Yes, but it would be great to test it on some more systems beforehand. I am also a bit unsure if it wouldn't be better to offer the settings separately for all batteries found in the system. The WMI methods take the battery index as an argument, but all invocations of this method that I could find in the Care Center binaries seemed to call it for the first battery only. Hence, I decided to implement it like this as well.

Bartvelp commented 2 years ago

Yes, but it would be great to test it on some more systems beforehand.

Just tested it out on a Acer Aspire 5 A515-45G-R5A1, works like a charm.

I will add it. It stops at 79% on my system. I could not find any methods to modify this threshold. From the Acer Care Center screenshots and documentation that I have seen, I assume that the threshold is fixed. I have no Windows installation to verify the actual settings that are available in the Care Center.

Stops at 79% for me as well. I do have a windows install and can confirm the battery care toggle is modified when toggling using your kernel driver. There is no way to modify the threshold in Acer Care Center, as you already mentioned.

Thanks for your work @frederik-h , I am interested as to how you reverse engineered the care center, any plans on disclosing that?

linrunner commented 2 years ago

OK. I assume the charge threshold is 80% and the 79% is due to rounding.

Edit: confirmed by this Acer support article.

frederik-h commented 2 years ago

Yes, but it would be great to test it on some more systems beforehand.

Just tested it out on a Acer Aspire 5 A515-45G-R5A1, works like a charm.

I will add it. It stops at 79% on my system. I could not find any methods to modify this threshold. From the Acer Care Center screenshots and documentation that I have seen, I assume that the threshold is fixed. I have no Windows installation to verify the actual settings that are available in the Care Center.

Stops at 79% for me as well. I do have a windows install and can confirm the battery care toggle is modified when toggling using your kernel driver. There is no way to modify the threshold in Acer Care Center, as you already mentioned.

Thanks for your work @frederik-h , [...]

Thanks for the feedback @Bartvelp and @linrunner!

I am interested as to how you reverse engineered the care center, any plans on disclosing that?

There exists some useful information to get you started with WMI driver developement: This old LWN article and this Ubuntu Wiki page. There you will learn that, in order to control some of the features of your laptop, you want to understand what's inside the MOF buffer in the APCI DSDT tables. The article and the wiki page claim that those binary buffers cannot be decompiled, but fortunately this is not/no longer true: You can use the bmfdec tool to decompile the buffers on Linux. I fear that I cannot share the decompiled MOF files for copyright reasons. Decompiling the MOF will provide you with interesting information about the available WMI methods, events etc.. This way I found WMI methods that looked promising, but it still was not clear how to call the methods correctly. I noticed that the Acer Care Center is a .Net application and .Net code can usually by decompiled to a quite readable form. I used ilspy which can be build with .Net Core on linux (the command line part of it) to decompile the libraries and executables. This way I learned about the correct way to call the WMI methods.

linrunner commented 2 years ago

The WMI methods take the battery index as an argument, but all invocations of this method that I could find in the Care Center binaries seemed to call it for the first battery only. Hence, I decided to implement it like this as well.

@frederik-h : On other laptops with a fixed threshold, it seems to apply to all batteries. For Lenovo Non-ThinkPads, LG, Samsung and Sony I just assumed so when creating their plugins, see BC Vendor Specifics. Apart from ThinkPads, devices with multiple batteries seem to be quite rare anyway.

Btw: how can I check for an Acer laptop: probing for the /sys/devices/platform/acer-wmi/ directory?

frederik-h commented 2 years ago

The WMI methods take the battery index as an argument, but all invocations of this method that I could find in the Care Center binaries seemed to call it for the first battery only. Hence, I decided to implement it like this as well.

@frederik-h : On other laptops with a fixed threshold, it seems to apply to all batteries. For Lenovo Non-ThinkPads, LG, Samsung and Sony I just assumed so when creating their plugins, see BC Vendor Specifics. Apart from ThinkPads, devices with multiple batteries seem to be quite rare anyway.

Thanks, this confirms that I probably do not need to worry about this now.

Btw: how can I check for an Acer laptop: probing for the /sys/devices/platform/acer-wmi/ directory?

Do you mean in general or with the goal of using the sysfs interface provided by this driver? In the latter case, I would suggest to probe for the /sys/bus/wmi/drivers/acer-wmi-battery/health_mode directly. There are certainly Acer laptops out there which do not provide the battery charge limit.

linrunner commented 2 years ago

@frederik-h : I would like to first detect if it is an Acer (to load the plugin) and then if health mode is present (e.g. for display in tlp-stat -b).

Have you thought about adding the functionality to acer-wmi instead of creating your own driver?

wojpawlik commented 2 years ago

I'm getting make[1]: *** /lib/modules/5.17.9-300.fc36.x86_64/build: No such file or directory. Stop. when trying to build the module on Fedora 36, despite having kernel-headers installed.

frederik-h commented 2 years ago

@frederik-h : I would like to first detect if it is an Acer (to load the plugin) and then if health mode is present (e.g. for display in tlp-stat -b).

Right, probing for the acer-wmi directory seems reasonable to me then, although the module seems (according to the comments and quirks-handling in its source) to support some laptops by other vendors as well.

Have you thought about adding the functionality to acer-wmi instead of creating your own driver?

Yes, but I have implemented it for myself in the first place and doing a standalone module seemed easier to me. Since there is some interest in the module, I will try to upstream it time permits. If it will be necessary to integrate it into acer-wmi, this should be easily possible, given how simple the module is. One potential advantage is that sysfs files could live under the same path as the other Acer-related files.

linrunner commented 2 years ago

@frederik-h : To be honest, I don't really want to release the Acer plugin until the feature is in the mainline kernel. Otherwise, too much support for the external kernel module ends up here (see https://github.com/linrunner/TLP/issues/596#issuecomment-1150020853). I've had this experience with ThinkPads for > 10 years and I'm not going to have that again.

I'll think about it :).

MatteoGalletta commented 2 years ago

If you give it a try, please let me know if it works on your system.

Thanks @frederik-h, the driver is working on my Acer Aspire 1 A114-33-C4FF, stops as well at 79%. Tested on Manjaro (5.15.60-1).

wojpawlik commented 2 years ago

I confirm the driver stopping the charging at 79% on Acer Swift SF314-43. Any plans on upstreaming?

Sasikuttan2163 commented 2 years ago

@frederik-h the driver works well on my Acer Nitro 5, AN515-44. Stops charging at 79%.

re-ynd commented 2 years ago

On Acer Aspire 7 running linux 5.19.7-1-MANJARO, I am getting permission denied error

sudo echo 1 > /sys/bus/wmi/drivers/acer-wmi-battery/health_mode
zsh: permission denied: /sys/bus/wmi/drivers/acer-wmi-battery/health_mode
MatteoGalletta commented 2 years ago

On Acer Aspire 7 running linux 5.19.7-1-MANJARO, I am getting permission denied error

sudo echo 1 > /sys/bus/wmi/drivers/acer-wmi-battery/health_mode
zsh: permission denied: /sys/bus/wmi/drivers/acer-wmi-battery/health_mode

It's not related to the script itself, I faced this problem before and it's related to the shell sudo behaviour, check this

re-ynd commented 2 years ago

Ah perfect! That was dumb on my part. Thanks! It works on Acer Aspire 7 running 5.19.7-1-MANJARO.

tarruda commented 2 years ago

@frederik-h thank you, also working on Acer Predator Helios 300 (2021 model)

mnlipp commented 1 year ago

I tried this on an Aspire 5 A515-45 and a Swift 1 SF113-31.

echo 1 > /sys/bus/wmi/drivers/acer-wmi-battery/health_mode does not give an error, but cat /sys/bus/wmi/drivers/acer-wmi-battery/health_mode returns 0 (before and after the echo).

So I suppose it doesn't work. But as this device has never seen Windows, therefore I cannot tell if the hardware is supposed to support this (cannot check using "Acer Care Center").

frederik-h commented 1 year ago

I tried this on an Aspire 5 A515-45 and a Swift 1 SF113-31.

echo 1 > /sys/bus/wmi/drivers/acer-wmi-battery/health_mode does not give an error, but cat /sys/bus/wmi/drivers/acer-wmi-battery/health_mode returns 0 (before and after the echo).

So I suppose it doesn't work. But as this device has never seen Windows, therefore I cannot tell if the hardware is supposed to support this (cannot check using "Acer Care Center").

I have opened issue frederik-h/acer-wmi-battery#9 for further discussion on this.

Dmivaka commented 1 year ago

@frederik-h Tried it on Acer Extensa EX215-22-R2H8. Since my OS is Windows (and for some unknown reasons battery care cannot be enabled on my machine here) I've booted into Ubuntu 20.04 from USB stick and enabled health mode with your module. After booting back into Windows the battery discharged to 80% and is still there. Thank you!

PedroVNasc commented 1 year ago

Worked like a charm on Acer Aspire A315-23G

Vinz-S commented 1 year ago

I'm getting make[1]: *** /lib/modules/5.17.9-300.fc36.x86_64/build: No such file or directory. Stop. when trying to build the module on Fedora 36, despite having kernel-headers installed.

I had the same issue because I installed the kernel-devel package from dnf, which was for another kernel version. I got the correct version from here where you first have to find your kernel, for you that would be 5.17.9-300.fc36, and then the correct devel, installing that should fix that issue.

If you have secure boot enabled you'll also encounter an issue related to keys, which you can read more about here , I haven't gotten to solving that myself yet.

tien-vo commented 1 year ago

@frederik-h Works on my Acer Swift Edge SFA16-41. Thanks for your work. Would love to see this upstream at some point!

ShayonRoy commented 2 months ago

@frederik-h It works totally fine on my Acer Aspire 7 A715-42G. Installed using the script from Diman119's script. But to make the health mode stick more then say 10 15 days without having to reenable it manually i had to add "options acer-wmi-battery enable_health_mode=1" in the /etc/modprobe.d/acer-wmi-battery.conf file.