Message ID | 20250522031056.2401832-1-shitao@kylinos.cn |
---|---|
State | New |
Headers | show |
Series | [v3] ACPI / battery: Use rounding to optimize the power calculation | expand |
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index 6760330a8af5..6905b56bf3e4 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(battery->capacity_now * 100ULL, + full_capacity); break; case POWER_SUPPLY_PROP_CAPACITY_LEVEL: if (battery->state & ACPI_BATTERY_STATE_CRITICAL)
If the difference between capacity_now and full_capacity is within 0.5%, 100% is arguably a better number to expose than 99% and exposing the latter may confuse the user to think that there's something wrong with the battery. Use rounding to optimize the power calculation. Signed-off-by: shitao <shitao@kylinos.cn> --- change for v3 -Optimization problem description. -Use 100ULL. change for v2 -battery->full_charge_capacity is changed to full_capacity. Thanks! --- drivers/acpi/battery.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)