Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755738Ab2ECNsd (ORCPT ); Thu, 3 May 2012 09:48:33 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:54977 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753154Ab2ECNsc (ORCPT ); Thu, 3 May 2012 09:48:32 -0400 From: Andy Whitcroft To: Matthew Garrett , "Rafael J. Wysocki" , Jonathan Nieder Cc: Andy Whitcroft , ACPI Devel Maling List , Linux-pm mailing list , Adrian Fita , Len Brown , Ralf Jung , Paolo Scarabelli , linux-kernel@vger.kernel.org Subject: [PATCH 1/1] battery: only refresh the sysfs files when pertinant information changes Date: Thu, 3 May 2012 14:48:26 +0100 Message-Id: <1336052907-15084-1-git-send-email-apw@canonical.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <20120503124708.GA18622@srcf.ucam.org> References: <20120503124708.GA18622@srcf.ucam.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1392 Lines: 46 We only need to regenerate the sysfs files when the capacity units change, avoid the update otherwise. Signed-off-by: Andy Whitcroft --- drivers/acpi/battery.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) Based on Matthew's feedback here is a version which optimises based on the power_unit field as returned from the battery info. Could someone who suffers from this issue please test this out and report back. Thanks. diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index 86933ca..7dd3f9f 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -643,11 +643,19 @@ static int acpi_battery_update(struct acpi_battery *battery) static void acpi_battery_refresh(struct acpi_battery *battery) { + int power_unit; + if (!battery->bat.dev) return; + power_unit = battery->power_unit; + acpi_battery_get_info(battery); - /* The battery may have changed its reporting units. */ + + if (power_unit == battery->power_unit) + return; + + /* The battery has changed its reporting units. */ sysfs_remove_battery(battery); sysfs_add_battery(battery); } -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/