On Mon, Apr 7, 2025 at 10:55 AM shitao <shitao@xxxxxxxxxx> wrote: > > 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@xxxxxxxxxx> > > --- > 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(-) > > 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) > -- Since this is a change in behavior, albeit small, I'd prefer it to get some coverage in linux-next before it goes into the mainline. Please resend it after 6.16-rc1 is out unless the 6.15 release is deferred (in which case I will pick it up). Thanks!