Repository navigation
Report only the batteries present on FreeBSD and DragonFly BSD - #3797
Conversation
FreeBsdPowerSource always returned one battery named BAT0, so a machine with no battery, including every VM, reported a full battery that was not on line power, and a machine with two reported one. The kernel creates the hw.acpi.battery sysctls only when a battery driver attaches, so a missing or zero hw.acpi.battery.units now means no power sources. Each battery is read with acpiconf -i N, skipping any reported as not present. The hw.acpi.battery values are totals across all batteries, so they fill in for acpiconf only when there is a single battery. Also fixes the units: voltage was reported in mV instead of V, and amperage as mW / mV, which is A rather than mA. A battery reporting in mA prints "N mA (M mW)", whose mA figure was read as mW. Power usage and amperage are now negative while discharging, as documented. Line power (hw.acpi.acline), cycle count and current capacity, which were never read, are now reported; acpiconf prints the remaining charge only as a percentage, so current capacity is that share of the last full capacity. DragonFly BSD uses this class and its acpiconf prints the same labels, without the cycle count.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📜 Recent review details
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to The reviewed battery-reporting changes have no identified issue requiring a fix before merge. Real battery hardware was not available for validation. Pre-merge checks ·
|
Fixes
getPowerSources()on FreeBSD and DragonFly BSD, which shareFreeBsdPowerSource. Found in the ground-truth surveys on cfarm430 (FreeBSD 16-CURRENT) and cfarm152 (DragonFly 6.4): both are VMs with no battery, and both reported a fullBAT0that was not on line power.No battery, no entry; one entry per battery
hw.acpi.batterysysctls only when a battery driver attaches (acpi_battery_register→acpi_battery_init), so a missing or zerohw.acpi.battery.unitsnow returns an empty list.acpiconf -i Nand namedBAT0,BAT1, …; a bay reported asnot presentis skipped. Previously onlyBAT0was ever reported.hw.acpi.battery.{state,time,life}values are totals across all batteries, so they fill in foracpiconfonly when there is a single battery (e.g. whenacpiconfcannot open/dev/acpi).Units and missing fields
getVoltage()was mV; it is now V, as documented.getAmperage()was mW / mV, i.e. A; it is now mA. For a battery reporting in mA,acpiconfprintsN mA (M mW), whose mA figure was read as mW; both are now read from it.getPowerUsageRate()andgetAmperage()are negative while discharging, as documented.isPowerOnLine()now readshw.acpi.acline(it was always false); cycle count is read fromacpiconf; current capacity is the remaining percentage of the last full capacity, sinceacpiconfprints the remaining charge only as a percentage.The parser follows the
printfformats inacpi_battinfo()in FreeBSD'susr.sbin/acpi/acpiconf/acpiconf.c. DragonFly'sacpiconfprints the same labels and rate format, withoutCycle Count, which is optional here.Testing
not presentbay,acpiconffailing with the sysctl totals as fallback, and no battery.-Perror-pronegreen.A battery-less machine still logs one WARN per call, for the missing
hw.acpi.battery.unitssysctl (down from three).Summary by CodeRabbit