Q: How to change values in /sys/class/power_supply ?

Kernels & Hardware, configuring network, installing services

Q: How to change values in /sys/class/power_supply ?

Postby macguru » 2018-09-13 18:25

Hi,

How to change values in /sys/class/power_supply?

This doesn’t work when executed as root, get permission error.
echo 68000000 > /sys/class/power_supply/BAT0/capacity_full_design

chmod (as root) u+w /sys/class/power_supply/BAT0/capacity_full_design
doesn't work because of denied permissions, even chattr can't be used.
Code: Select all
lsattr: Inappropriate ioctl for device While reading flags on


May be is possible to set it in /etc/sysctl.conf, rc.local or with grub boot parameters?

Thanks in advance for any help.
Last edited by macguru on 2018-09-14 05:13, edited 1 time in total.
macguru
 
Posts: 7
Joined: 2018-09-13 18:09

Re: Q: How to change values in /sys/class/power_supply ?

Postby bw123 » 2018-09-13 23:11

I never had much luck writing to anything under /sys it is not a normal fs. There may be some way to get at some of the things there through /proc/sys? https://en.wikipedia.org/wiki/sysfs

I don't see how trying to fool the kernel that you have a good battery would be helpful? If it's dead it's dead.
User avatar
bw123
 
Posts: 3516
Joined: 2011-05-09 06:02
Location: TN_USA

Re: Q: How to change values in /sys/class/power_supply ?

Postby debiman » 2018-09-14 04:32

you probably shouldn't, and won't be able to make it persistent.
Code: Select all
mount | grep /sys
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
(...)
https://www.startpage.com/do/dsearch?query=what+is+linux+sysfs
User avatar
debiman
 
Posts: 3015
Joined: 2013-03-12 07:18

Re: Q: How to change values in /sys/class/power_supply ?

Postby macguru » 2018-09-14 05:11

bw123 wrote:I never had much luck writing to anything under /sys it is not a normal fs. There may be some way to get at some of the things there through /proc/sys? https://en.wikipedia.org/wiki/sysfs

I don't see how trying to fool the kernel that you have a good battery would be helpful? If it's dead it's dead.


I reconditioned battery with new high-capacity cells, yet EEPROM chip holds old (and incorrect info). Unfortunately, have no hardware to reflash EEPROM.
macguru
 
Posts: 7
Joined: 2018-09-13 18:09

Re: Q: How to change values in /sys/class/power_supply ?

Postby macguru » 2018-09-14 06:33

I followed symlinks and finally changed write attributes of one of the /sys/class files. Notebook left in another location, so I had to experiment with stationery PC and another /sys/class variable, but anyway, if it works, it should work anyway with notebook.

All as root (not sudo)

# cd /sys/class/hwmon/hwmon0
# ls -la
-rw-rw-rw- 1 root root 4096 Sep 14 10:03 temp1_crit
# cat temp1_crit
106000

# echo 105000 > temp1_crit
-bash: echo: write error: Input/output error

# getfattr -d -m - temp1_crit
temp1_crit: system.posix_acl_access: Operation not supported
temp1_crit: system.posix_acl_default: Operation not supported

PS. May be its possible to alter these variables through udev ?
macguru
 
Posts: 7
Joined: 2018-09-13 18:09

Re: Q: How to change values in /sys/class/power_supply ?

Postby macguru » 2018-09-14 13:11

Wrote udev rule in /etc/udev/rules.d

Code: Select all
ACTION=="add|change", KERNEL=="BAT*", SUBSYSTEM=="power_supply", ATTR{energy_full_design}="*", MODE="0664"
ACTION=="add|change", KERNEL=="BAT*", SUBSYSTEM=="power_supply", ATTR{energy_full_design}="68000000"


Reloaded rules.
Code: Select all
# udevadm control --reload; udevadm trigger; cat /sys/class/power_supply/BAT1/energy_full_design
47520000 # old value

# udevadm test /sys/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0A:00/power_supply/BAT1

ATTR '/sys/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0A:00/power_supply/BAT1/energy_full_design' writing '68000000' /etc/udev/rules.d/62-adjust-battery-capacity.rules:5
error opening ATTR{/sys/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0A:00/power_supply/BAT1/energy_full_design} for writing: Permission denied


OK, then, probably thus udev rule have to be copied to initramfs.
Moved to /usr/lib/dracut/modules.d/95udev-rules/96-battery-adjust.rules

Edited dracut module setup script:

Code: Select all
# nano /usr/lib/dracut/modules.d/95udev-rules/module-setup.sh
# My custom rule for battery
prepare_udev_rules 96-battery-adjust.rules
inst_rules “$moddir/96-battery-adjust.rules”

# dracut -fv


My script still not included in initramfs, no error messages in the output.
What went wrong? Thanks in advance.
macguru
 
Posts: 7
Joined: 2018-09-13 18:09

Re: Q: How to change values in /sys/class/power_supply ?

Postby CwF » 2018-09-14 14:12

macguru wrote:This doesn’t work when executed as root, get permission error.
echo 68000000 > /sys/class/power_supply/BAT0/capacity_full_design

When this does work then;

May be is possible to set it in /etc/sysctl.conf,

should work like

Code: Select all
/sys/class/power_supply/BAT0/capacity_full_design = 68000000

But I'm thinking this should not work! Back in the day I had a toughbook I looked at this. Panasonic had a nice utility for cycling the battery, short and long, and it did indeed update the battery status and then better estimate discharge. BUT, I'm pretty sure the utility talked to some chip and the results stored essentially in firmware.

Since I'm thinking the OS may read once at boot there is not a use case for a user to change it. Some magic utility needs to write to the bios/firmware. At the OS level without such utility the only option may be to figure out how to ignore it. Or look to the vendor/manufacturer of your gadget for a battery calibrator utility
CwF
 
Posts: 147
Joined: 2018-06-20 15:16

Re: Q: How to change values in /sys/class/power_supply ?

Postby macguru » 2018-09-14 15:26

May be is possible to set it in /etc/sysctl.conf,
should work like
Code: Select all
/sys/class/power_supply/BAT0/capacity_full_design = 68000000

But I'm thinking this should not work! Back in the day I had a toughbook I looked at this. Panasonic had a nice utility for cycling the battery, short and long, and it did indeed update the battery status and then better estimate discharge. BUT, I'm pretty sure the utility talked to some chip and the results stored essentially in firmware.

Since I'm thinking the OS may read once at boot there is not a use case for a user to change it. Some magic utility needs to write to the bios/firmware. At the OS level without such utility the only option may be to figure out how to ignore it. Or look to the vendor/manufacturer of your gadget for a battery calibrator utility


I checked, this variable not listed in sysctl -a, thus, it can't be changed this way, unfortunately.

The culprit is a battery controller board with EEPROM.
In order to reflash it one needs a special hardware, not expensive, yet meaningless to purchase in this particular case. Its not possible to overwrite battery EEPROM from notebook.

I reconditioned battery with new finest quality Li-Ion cells which have 1.59 times larger capacity compared to the old ones.

Battery calibration won't help (already verified), because power manager counts on old capacity.
Another option is to buy third-party high-capacity battery, which composed of dirty cheap s*** cells, and as my experience suggests, advertised numbers are close to fake.

So the only meaningful way is to hack udev/power manager, yet I didn't expected it would be so cumbersome.
macguru
 
Posts: 7
Joined: 2018-09-13 18:09

Re: Q: How to change values in /sys/class/power_supply ?

Postby debiman » 2018-09-15 09:31

macguru wrote:I reconditioned battery with new finest quality Li-Ion cells which have 1.59 times larger capacity compared to the old ones.

so you changed the actual battery cells only, but the chip inside the battery does not know that and still thinks the old cells are in there.
that sucks.
i hope you can fix it with udev; another approach could be through /proc?
https://www.simplified.guide/linux/view ... nformation

where do you actually need this? power management?

one problem i still see is how to get the actual capacity?

maybe this search can help.
User avatar
debiman
 
Posts: 3015
Joined: 2013-03-12 07:18

Re: Q: How to change values in /sys/class/power_supply ?

Postby macguru » 2018-09-15 10:37

Yes, problem is with charging and discharging, battery doesn't run at full capacity.

I don't know for sure if power manager reads values from /proc or /sys, if someone knows, please suggest. I running MATE Desktop, it uses Gnome power manager GUI, which I suppose is a front-end of UPower.

BTW, here what is written
https://askubuntu.com/questions/913768/ ... my-battery
that
/proc/acpi/battery is now /sys/class/power_supply/

I know its possible to include kernel modules with "dracut --add-drivers xxx-kernel-module-name", but how to include udev rules, which dracut config file needs to be edited?
Googling didn't help, one men advised to edit "/usr/lib/dracut/modules.d/95udev-rules/module-setup.sh", I did, and my udev rule is still not in initramfs.
macguru
 
Posts: 7
Joined: 2018-09-13 18:09

Re: Q: How to change values in /sys/class/power_supply ?

Postby macguru » 2018-09-18 09:47

I included my custom udev rules into initramfs.
/etc/dracut.conf.d/my-udev-battery.conf
install_items+="/etc/udev/rules.d/62-adjust-battery-capacity.rules”

its there - "dracut -vf" logs succesful inclusion.

/etc/udev/rules.d/62-adjust-battery-capacity.rules
### Rule start ###
ACTION=="add|change", KERNEL=="BAT*", SUBSYSTEM=="power_supply", ATTR{energy_full_design}="*", MODE="0664"
ACTION=="add|change", KERNEL=="BAT*", SUBSYSTEM=="power_supply", ATTR{energy_full_design}="68000000"
### Rule end ###

Unfortunately
cat /sys/class/power_supply/BAT1/energy_full
still displays old value.

Even tried to add grub boot parameter, no luck.
power_supply.energy_full_design=68000000
macguru
 
Posts: 7
Joined: 2018-09-13 18:09

Re: Q: How to change values in /sys/class/power_supply ?

Postby reinob » 2018-09-20 17:39

macguru wrote:I included my custom udev rules into initramfs.
/etc/dracut.conf.d/my-udev-battery.conf
install_items+="/etc/udev/rules.d/62-adjust-battery-capacity.rules”

its there - "dracut -vf" logs succesful inclusion.

/etc/udev/rules.d/62-adjust-battery-capacity.rules
### Rule start ###
ACTION=="add|change", KERNEL=="BAT*", SUBSYSTEM=="power_supply", ATTR{energy_full_design}="*", MODE="0664"
ACTION=="add|change", KERNEL=="BAT*", SUBSYSTEM=="power_supply", ATTR{energy_full_design}="68000000"
### Rule end ###

Unfortunately
cat /sys/class/power_supply/BAT1/energy_full
still displays old value.

Even tried to add grub boot parameter, no luck.
power_supply.energy_full_design=68000000


AFAIK the output (content) of /sys/class/power_suppy/*/energy* are read off the hardware (battery controller), so it doesn't make any sense to "write".

The /proc and /sys "filesystems" merely expose some variables which may or may not be writable (configurable).
It's as if you wanted to change the CPU temperature by merely "writing" on /sys/cpu/temp (or whatever the actual path may be).
reinob
 
Posts: 557
Joined: 2014-06-30 11:42


Return to System configuration

Who is online

Users browsing this forum: No registered users and 5 guests

fashionable