[PATCH v2] ACPI / battery: Use rounding to optimize the power calculation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Some batteries may have the problem of aging and losing power too quickly,
and 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@xxxxxxxxxx>
---
 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..8eb9dc98c2c4 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, full_capacity);
 		break;
 	case POWER_SUPPLY_PROP_CAPACITY_LEVEL:
 		if (battery->state & ACPI_BATTERY_STATE_CRITICAL)
-- 
2.25.1





[Index of Archives]     [Linux IBM ACPI]     [Linux Power Management]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]
  Powered by Linux