Message ID | 20250401122027.302468-1-shitao@kylinos.cn (mailing list archive) |
---|---|
State | Changes Requested, archived |
Headers | show |
Series | [v1] ACPI / battery: Use rounding to optimize the power calculation | expand |
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index 6760330a8af5..e5181c6cf73a 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -279,8 +279,8 @@ static int acpi_battery_get_property(struct power_supply *psy, full_capacity == ACPI_BATTERY_VALUE_UNKNOWN) ret = -ENODEV; else - val->intval = battery->capacity_now * 100/ - full_capacity; + val->intval = DIV_ROUND_CLOSEST_ULL((uint64_t)battery->capacity_now * 100, + battery->full_charge_capacity); break; case POWER_SUPPLY_PROP_CAPACITY_LEVEL: if (battery->state & ACPI_BATTERY_STATE_CRITICAL)
Some batteries may have the problem of aging and losing power too quickly, users may immediately display 99% battery level after unplugging the charger. This will bring some unnecessary misunderstandings or troubles to users. Use rounding to optimize the power calculation, and expect to display 100% when capacity_now is only slightly less than full_charge_capacity. Try to avoid unnecessary feedback from users about the battery not being fully charged or dropping out too quickly. Signed-off-by: shitao <shitao@kylinos.cn> --- drivers/acpi/battery.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)