TLP
TLP copied to clipboard
[Dell] Battery Wear Control
My understanding is that currently only ThinkPad devices have advanced battery features available, due to the existence of tp_smapi. For Dell devices there exists the 'Dell Command | Configure' which appears to provide similar functionality in regards to battery management, for example running off AC power and express charging, even though the interface is rather suboptimal. That's all the more reason to build a tool for it, but the question is if it should be this one.
These are Windows binaries, dear. If you want things moving, implement a kernel interface e.g. driver for your hardware. See: https://github.com/linrunner/TLP/issues/321
I'm afraid you are mistaken, there are Linux binaries available as well: https://www.dell.com/support/article/us/en/04/sln311302/dell-command-configure?lang=en
I see.
--PrimaryBattChargeCfg seems do to charge thresholds. Did you spot something like force_discharge (for recalibration)?
Contras:
- I didn't see source downloads and there are binary packages for Ubuntu 16.04 and RHEL 6/7 only.
- I won't call a closed source tool from inside TLP and would still prefer using the generic kernel interface mentioned above.
Yesterday I stumbled over smbios-utils: https://github.com/dell/libsmbios/ Any volunteers to check out and document how to use it? Command line args are a bit cryptic.
ps. I don't have Dell hardware within reach.
My daily machine is a Dell XPS running openSUSE with TLP. So what do you exactly need?
General question: are Dell battery features similar enough to the ThinkPad approach so one can integrate them into the existing TLP commands (setcharge/discharge/recalibrate):
- What are the exact commands (with binary path) to set the start and stop threshold?
- Valid ranges for the threshold values/parameters?
- How to read back actual threshold values from the firmware
- What is the exact command to check Dell battery features are actually supported on a laptop?
- Is there a command to discharge a battery while AC is connected?
- How to select primary / secondary battery in the above commands on Dell laptops (if dual batteries models exist)?
Ok. I've got the latest smbios installed. It's shipped with openSUSE, so that's the good news. The bad news is that I get nothing out of it. For example, a 'sudo smbios-battery-ctl --battery-charge' results in this:
Libsmbios version : 2.4.2
smbios-battery-ctl version : 2.4.2
Supported battery charging features:
NIL
Battery charging Status:
NIL
No difference what so ever with AC plugged in or not. So I'm not sure if this libsmbios is actually bringing something to the table...
Dead end? Just for the record: could you post the output of
tlp-stat -s
As for the first three points: the relevant option is described in the manual here As for the last two points, I can't find anything that would allow it.
I'm also getting NILs from smbios, I'm going to report it in the libsmbios repository.
In any case, smbios-battery-ctl is pretty low-level could do the trick, but on the other hand, I'm not sure if it wouldn't conflict with the BIOS settings.
$ tlp-stat -s
--- TLP 1.2.2 --------------------------------------------
+++ System Info
System = Dell Inc. Vostro 3580
BIOS = 1.0.0
Kernel = 4.19.45-1-lts #1 SMP Wed May 22 13:02:41 CEST 2019 x86_64
/proc/cmdline = BOOT_IMAGE=/vmlinuz-linux-lts <mount-related options>
Init system = systemd
Boot mode = UEFI
+++ TLP Status
State = enabled
RDW state = enabled
Last run = 02:29:23, 8 sec(s) ago
Mode = battery
Power source = battery
Thanks. Just for the record:
cctk --PrimaryBattChargeCfg=Custom:50-70
/remark: the reply was substantially edited
On the other hand, I have second thoughts about introducing a proprietary opt-dependency to tlp.
It appears that smbios already exposes the API using the low-level token API: token_list.csv Still
# smbios-token-ctl -i 0x0349
prints the token as a bool, which is clearly invalid
================================================================================
Token: 0x0349 - Primary Battery Custom Charge Start (NA)
value: bool = false
Desc: Sets the percentage value at which the battery charging will start Impl
ementation Note: This field must be in the range [50, 95] with a step v
alue of 1 and at least 5% less than Primary Custom Charge End
Trying to access the token directly using the Python bindings is weird but feasible - they numeric values are encoded as 2-byte little-endian integers.
# ipython
In [1]: from libsmbios_c import smbios_token
In [2]: t = smbios_token.TokenTable()
In [3]: tok = t[0x0349]
In [7]: tok.getString()
Out[7]: b'2\x00'
In [9]: tok.getType()
Out[9]: 218
In [10]: tok.isBool() # What the hell?
Out[10]: True
In [11]: tok.isString()
Out[11]: True
In [20]: int.from_bytes(tok.getString(), "little")
Out[20]: 50
In [21]: int.from_bytes(t[0x034A].getString(), "little")
Out[21]: 90
Probably the best idea would be to contribute the API to smbios-battery-ctl
and only use the shell tool through tlp.
While I can't guarantee code contributions to this one (I'll see what I can do), I can promise I'll test the changes related to power-management on Dell laptops.
For reference, here's the issue about smbios-battery-ctl
returning NILs: https://github.com/dell/libsmbios/issues/71
However, i'm not going to include code that calls a proprietary tool.
ps. and i would definitely prefer a kernel solution that uses the natacpi framework laid out in #321.
On the other hand, I have second thoughts about introducing a proprietary opt-dependency to tlp.
However, i'm not going to include code that calls a proprietary tool. ps. and i would definitely prefer a kernel solution that uses the natacpi framework laid out in #321.
What I meant was that cctk
is proprietary and that I think it may be a bad idea to depend on it ;) It's great that we agree on this. :)
So we can either use libsmbios (GPL2) or natacpi. It looks like I've already solved the major obstacles, so I think I can extend smbios-battery-ctl
to support PrimaryBatteryChargeCfg during the weekend.
I won't be able to help with natacpi in any other way than testing. You may consider contacting the Dell developers. (I'm not affiliated with Dell in any way, I'm just using a laptop produced by the company)
@linrunner let me know if you're ok with this CLI
@linrunner the pull request to dell/libsmbios has been merged. You can now use it to implement tlp fullcharge
and tlp setcharge
on Dell laptops.
OK, then let's get started.
I'll need a bit more than just the description of the CLI because the routines in func.d/35-tlp-func-batt do a lot of checks before actually writing anything - and I don't have the hardware of course ...
I need the exact commands and their corresponding outputs / return codes for the following:
(1) Is libsmbios installed and is it supporting the new CLI?
OK, i'll guess we just have to check for smbios-battery-ctl in the PATH.
(2) Does the laptop actually support thresholds?
(3) Reading the thresholds
(4) Writing the thresholds (+ what happens with invalid param values?)
(5) Checking for batteries: are Dell laptops BAT0 only or are there models with two batteries?
For reference: I'll call the feature dellsm in TLP.
What happened here? I was very interested in this work as I am thinking in buying a dell device
For reference: I'll call the feature dellsm in TLP.
@linrunner and @marmistrz: did you start implementing this somewhere? For instance, is there a branch that contains the initial pluming for using smbios rather than one of the kernel modules?
I have a Dell Latitude laptop that supports setting the thresholds in the bios or via the cctk
utility and I would be interested in getting this to work in TLP.
Sorry, I completely forgot about it. Unfortunately, smbios didn't have a new release after my changes accepted, so you need to patch smbios-battery-ctl
manually.
OK, then let's get started.
I'll need a bit more than just the description of the CLI because the routines in func.d/35-tlp-func-batt do a lot of checks before actually writing anything - and I don't have the hardware of course ...
I need the exact commands and their corresponding outputs / return codes for the following:
(1) Is libsmbios installed and is it supporting the new CLI? OK, i'll guess we just have to check for smbios-battery-ctl in the PATH.
You can probably grep smbios-battery-ctl --help
(2) Does the laptop actually support thresholds?
I don't know, but I guess that smbios-battery-ctl
would return an error
(3) Reading the thresholds
smbios-battery-ctl --get-charging-cfg
(4) Writing the thresholds (+ what happens with invalid param values?)
smbios-battery-ctl --set-charging-mode X
smbios-battery-ctl --set-custom-charge-interval low high
I don't know what happens if params are invalid.
(5) Checking for batteries: are Dell laptops BAT0 only or are there models with two batteries?
No idea. For all those things I don't know about it's probably best to ask in dell/libsmbios (e.g. through github issues)
See also this fragment from --help
.
--get-charging-cfg Get the current Primary Battery Charge Configuration
--set-charging-mode=<MODE>
Set the current Primary Battery Charge Configuration.
Valid choices are: ['primarily_ac', 'adaptive',
'custom', 'standard', 'express']
--set-custom-charge-interval=<START> <END>
Set the percentage bounds for custom charge. Both must
be integers. START must lie in the range [50, 95], END
must lie in the range [55, 100], END must be at least
(START + 5)
I have no plans to implement this myself. Reasons are:
- It's hopeless without a Dell laptop at hand for try and error
- I've not enough time
Hi guys, I'm confused by your discussion. I'm thinking of buying a dell laptop. My question is simple. Is the latest version now available to set battery threshold of dell laptops? I only have a thinkpad at hand. Is there anyone who has tested command like smbios-battery-ctl --set-custom-charge-interval low high
on a dell machine?
Hi,
With TLP i don't think something was implemented but you can use dell tools and smbios to change thermal and charge thresholds, I created the above script that I use to change them and it works great on Dell XPS 7590
#!/bin/bash
if [ $# -eq 0 ]
then
echo "\$0 charge/thermal"
echo "\$1 value"
exit 1
fi
if [ $1 = 'charge' ]
then
if [ $# -eq 1 ]
then
echo "a value of:
PrimAcUse, Custom:50-70,
Adaptive, Express, Standard"
exit 1
fi
read -sp "Setup Password:" password
/opt/dell/dcc/cctk --ValSetupPwd=$password --PrimaryBattChargeCfg=$2
exit 0
fi
if [ $1 = 'thermal' ]
then
if [ $# -eq 1 ]
then
echo "a value of:
balanced, cool-bottom,
quiet, performance"
/usr/sbin/smbios-thermal-ctl -g
exit 1
fi
/usr/sbin/smbios-thermal-ctl --set-thermal-mode=$2
/usr/sbin/smbios-thermal-ctl -g
exit 0
/opt/dell/dcc/cctk is Dell Command Configure util developed by Dell, you can download a .deb from their website
I have only used the cctk
utility a few times and never got to test the libsmbios utilities properly since the version on my system is too old. Also, I don't really need it as I set the thresholds once and use them ever since without modification.
I reckon this will become all much easier once there is support for this in the kernel which is currently work-in-progress, see: https://lkml.org/lkml/2020/7/29/87. There is also an open issue in libsmbios which has some further information, but no progress on the libsmbios side yet since the kernel interface is still missing obviously.
@raduburla Wow, this is very good. Thank you! I think I will get a dell laptop!
@awehrfritz I see it now. Thank you for your link. After some research. I found that the battery threshold is closely related to battery firmware which is much more closesource compared to the host driver. Maybe that is reason why it is so hard to implement.
@cheng3100 smbios-battery-ctl --set-custom-charge-interval low high
was implemented by me and works on my Dell laptop :P
You also need smbios-battery-ctl --set-charging-mode custom
But I'm using it standalone, without tlp.
@marmistrz Thanks, I will try it after my new dell laptop arrive.
Hi,
With TLP i don't think something was implemented but you can use dell tools and smbios to change thermal and charge thresholds, I created the above script that I use to change them and it works great on Dell XPS 7590
#!/bin/bash if [ $# -eq 0 ] then echo "\$0 charge/thermal" echo "\$1 value" exit 1 fi if [ $1 = 'charge' ] then if [ $# -eq 1 ] then echo "a value of: PrimAcUse, Custom:50-70, Adaptive, Express, Standard" exit 1 fi read -sp "Setup Password:" password /opt/dell/dcc/cctk --ValSetupPwd=$password --PrimaryBattChargeCfg=$2 exit 0 fi if [ $1 = 'thermal' ] then if [ $# -eq 1 ] then echo "a value of: balanced, cool-bottom, quiet, performance" /usr/sbin/smbios-thermal-ctl -g exit 1 fi /usr/sbin/smbios-thermal-ctl --set-thermal-mode=$2 /usr/sbin/smbios-thermal-ctl -g exit 0
/opt/dell/dcc/cctk is Dell Command Configure util developed by Dell, you can download a .deb from their website
This is actually a super cool script! Would it be possible for you to explain it?
Hi,
Sure, to use it save it as a .sh file then chmod +x
that file. For the bellow examples I use the name of the sh file as dell.sh
The script supports 2 main options that you want to change:
-
charge
- where you set charge thresholds like PrimAcUse, Custom:50-70, Adaptive, Express or Standard For example if you want to set the laptop to Adaptive charge you run it like this:
sudo bash dell.sh charge Adaptive
If you have set a Bios password it will ask for the password. I did not test without a password, if it does not work try replace the following line in the script /opt/dell/dcc/cctk --ValSetupPwd=$password --PrimaryBattChargeCfg=$2
with /opt/dell/dcc/cctk --PrimaryBattChargeCfg=$2
and remove read -sp "Setup Password:" password
-
thermal
- to change the thermal settings of the laptop, like balanced, cool-bottom, quiet or performance For example if you want it to performance you run it like this:
sudo bash dell.sh thermal performance
You will need cctk (https://www.dell.com/support/kbdoc/ro-ro/000178000/dell-command-configure) and smbios (https://github.com/dell/libsmbios) installed
If you get errors you might need to change some Bios configurations. I had to disable some security features from the Bios for the charge settings to work, I can't remember exactly what settings. Can post a list of my actual settings if needed.
Hope this help
Current state of things is: I would love to support Dell, but not by means of an external tool (or external kernel module). I had my fair share of experience with that in > 10 years on ThinkPads.
So the prerequisite is mainline kernel support for
/sys/class/power_supply/BAT0/charge_control_start_threshold
/sys/class/power_supply/BAT0/charge_control_end_threshold
Let's see what happens here:
- https://github.com/dell/libsmbios/issues/84
- https://lkml.org/lkml/2020/7/29/87