From patchwork Thu Nov 6 07:15:34 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AceLan Kao X-Patchwork-Id: 407332 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id C8A831400B6; Thu, 6 Nov 2014 18:15:56 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1XmHIM-0002ox-Ug; Thu, 06 Nov 2014 07:15:50 +0000 Received: from mail-pd0-f177.google.com ([209.85.192.177]) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1XmHIC-0002nm-Rt for kernel-team@lists.ubuntu.com; Thu, 06 Nov 2014 07:15:41 +0000 Received: by mail-pd0-f177.google.com with SMTP id v10so595398pde.22 for ; Wed, 05 Nov 2014 23:15:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=nnYPH2zK/DbeeA+0zevjRO27nqsICD8SGAh3/0focIQ=; b=yfKTKtzJLB8j3vm3oibUFXn9gU2kZndcYfj46htXXbi5MEJG4Iuofp92QxengK4blB dPvJ8Ze4jXalIPFNaJR8zt0K29L1rlEK4dtI5gHVPKtIJDlL0v1RLGyF7FC30EbJwVP/ g+BqVU8wUXSaX6wheyhvDDYkASUm0ibjeMCxQdPcaTlLb6HvgJxjrJzhVP264wh8d9c4 9RvU+fEXfaOe9XcltLlbz//dIRk6ozt/+wCRVF9Ygw+gQj12Y5f1ika+jcyiIKbjg8zk l1tFnvzSDqY6zeMw4snlQAG9cg1y6GrmlWzgpgePdXSIvYZ8lbWxBClz3fzeVfuh31BB +jMQ== X-Received: by 10.68.65.10 with SMTP id t10mr1895590pbs.156.1415258140159; Wed, 05 Nov 2014 23:15:40 -0800 (PST) Received: from localhost ([175.41.48.77]) by mx.google.com with ESMTPSA id dl1sm5056288pbc.16.2014.11.05.23.15.38 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Nov 2014 23:15:39 -0800 (PST) From: AceLan Kao To: kernel-team@lists.ubuntu.com Subject: [Trusty SRU] ACPI / battery: Accelerate battery resume callback Date: Thu, 6 Nov 2014 15:15:34 +0800 Message-Id: <1415258134-22068-2-git-send-email-acelan.kao@canonical.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1415258134-22068-1-git-send-email-acelan.kao@canonical.com> References: <1415258134-22068-1-git-send-email-acelan.kao@canonical.com> X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: kernel-team-bounces@lists.ubuntu.com From: Lan Tianyu BugLink: https://bugs.launchpad.net/bugs/838543 Most time of battery resume callback is spent on executing AML code _BTP, _BIF and _BIF to get battery info, status and set alarm. These AML methods may access EC operation regions several times and consumes time. These operations are not necessary during devices resume and can run during POST_SUSPEND/HIBERNATION event when all processes are thawed. This also can avoid removing and adding battery sysfs nodes every system resume even if the battery unit is not actually changed. The original code updates sysfs nodes without check and this seems not reasonable. Signed-off-by: Lan Tianyu Signed-off-by: Rafael J. Wysocki (backported from commit 9e50bc14a7f58b5d8a55973b2d69355852ae2dae) Signed-off-by: AceLan Kao Conflicts: drivers/acpi/battery.c Acked-by: Andy Whitcroft --- drivers/acpi/battery.c | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index 2928e95..fabd751 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -700,7 +700,7 @@ static void acpi_battery_quirks(struct acpi_battery *battery) } } -static int acpi_battery_update(struct acpi_battery *battery) +static int acpi_battery_update(struct acpi_battery *battery, bool resume) { int result, old_present = acpi_battery_present(battery); result = acpi_battery_get_status(battery); @@ -711,6 +711,10 @@ static int acpi_battery_update(struct acpi_battery *battery) battery->update_time = 0; return 0; } + + if (resume) + return 0; + if (!battery->update_time || old_present != acpi_battery_present(battery)) { result = acpi_battery_get_info(battery); @@ -919,7 +923,7 @@ static print_func acpi_print_funcs[ACPI_BATTERY_NUMFILES] = { static int acpi_battery_read(int fid, struct seq_file *seq) { struct acpi_battery *battery = seq->private; - int result = acpi_battery_update(battery); + int result = acpi_battery_update(battery, false); return acpi_print_funcs[fid](seq, result); } @@ -1034,7 +1038,7 @@ static void acpi_battery_notify(struct acpi_device *device, u32 event) old = battery->bat.dev; if (event == ACPI_BATTERY_NOTIFY_INFO) acpi_battery_refresh(battery); - acpi_battery_update(battery); + acpi_battery_update(battery, false); acpi_bus_generate_netlink_event(device->pnp.device_class, dev_name(&device->dev), event, acpi_battery_present(battery)); @@ -1048,13 +1052,27 @@ static int battery_notify(struct notifier_block *nb, { struct acpi_battery *battery = container_of(nb, struct acpi_battery, pm_nb); + int result; + switch (mode) { case PM_POST_HIBERNATION: case PM_POST_SUSPEND: - if (battery->bat.dev) { - sysfs_remove_battery(battery); - sysfs_add_battery(battery); - } + if (!acpi_battery_present(battery)) + return 0; + + if (!battery->bat.dev) { + result = acpi_battery_get_info(battery); + if (result) + return result; + + result = sysfs_add_battery(battery); + if (result) + return result; + } else + acpi_battery_refresh(battery); + + acpi_battery_init_alarm(battery); + acpi_battery_get_state(battery); break; } @@ -1085,7 +1103,7 @@ static int acpi_battery_update_retry(struct acpi_battery *battery) int retry, ret; for (retry = 5; retry; retry--) { - ret = acpi_battery_update(battery); + ret = acpi_battery_update(battery, false); if (!ret) break; @@ -1176,7 +1194,7 @@ static int acpi_battery_resume(struct device *dev) return -EINVAL; battery->update_time = 0; - acpi_battery_update(battery); + acpi_battery_update(battery, true); return 0; } #endif