From patchwork Wed Jun 21 08:55:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lv Zheng X-Patchwork-Id: 9801225 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2CE5C60329 for ; Wed, 21 Jun 2017 08:57:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 19D1727968 for ; Wed, 21 Jun 2017 08:57:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0BF6F2853D; Wed, 21 Jun 2017 08:57:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 89E3027968 for ; Wed, 21 Jun 2017 08:57:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752840AbdFUIz1 (ORCPT ); Wed, 21 Jun 2017 04:55:27 -0400 Received: from mga02.intel.com ([134.134.136.20]:54264 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752002AbdFUIzY (ORCPT ); Wed, 21 Jun 2017 04:55:24 -0400 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Jun 2017 01:55:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.39,368,1493708400"; d="scan'208";a="1143367434" Received: from unknown (HELO lvzheng-MOBLsp3.sh.intel.com) ([10.239.159.55]) by orsmga001.jf.intel.com with ESMTP; 21 Jun 2017 01:55:11 -0700 From: Lv Zheng To: "Rafael J . Wysocki" , "Rafael J . Wysocki" , Len Brown Cc: Lv Zheng , Lv Zheng , linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, systemd-devel@lists.freedesktop.org, Benjamin Tissoires , Peter Hutterer Subject: [RFC PATCH v6 2/5] ACPI: button: Add an optional workaround to fix an event missing issue for old userspace Date: Wed, 21 Jun 2017 16:55:09 +0800 Message-Id: <14729dcd394f41facb871bd3cd3faf7fbf14231e.1498034513.git.lv.zheng@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: <2a779ae8c280c968b3237ac4a3d9580df7262a46.1493951798.git.lv.zheng@intel.com> Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There are platform variations implementing ACPI lid device in different ways: 1. Some platforms send "open" events to OS and the events arrive before button driver is resumed; 2. Some platforms send "open" events to OS, but the events arrive after button driver is resumed, ex., Samsung N210+; 3. Some platforms never send "open" events to OS, but send "open" events to update the cached _LID return value, and the update events arrive before button driver is resumed; 4. Some platforms never send "open" events to OS, but send "open" events to update the cached _LID return value, but the update events arrive after button driver is resumed, ex., Surface Pro 3; 5. Some platforms never send "open" events, _LID returns value sticks to "close", ex., Surface Pro 1. Currently, all cases work fine with systemd 233, but only case 1,2 work fine with systemd 229. Case 3,4 can be treated as an event missing issue: After seeing a LID "close" event, systemd 229 will wait several seconds (HoldoffTimeoutSec) before suspending the platform. Thus on case 4 platforms, if users close lid, and re-open it during the HoldoffTimeoutSec period, there is still no "open" events seen by the userspace. Thus systemd still considers the last state as "close" and suspends the platform after the HoldoffTimeoutSec times out. Note that not only systemd 229, desktop managers (ex., gnome-settings-daemon) also suffer from this issue. This patch tries to fix this issue by periodically sending _LID return value to userspace, which ensures to trigger a SW_LID event when the underlying hardware state has changed. As adding a periodic timer is not a power friendly way, this patch prepares an option for users to enable on failure platforms for old userspace programs. Users can configure update interval via button.lid_update_interval. This should be configured to a smaller value than HoldoffTimeoutSec in /etc/systemd/logind.conf. Cc: Cc: Benjamin Tissoires Cc: Peter Hutterer Signed-off-by: Lv Zheng --- drivers/acpi/button.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c index 67a0d78..a8b119e 100644 --- a/drivers/acpi/button.c +++ b/drivers/acpi/button.c @@ -126,6 +126,14 @@ static unsigned long lid_notify_timeout __read_mostly = 10; module_param(lid_notify_timeout, ulong, 0644); MODULE_PARM_DESC(lid_notify_timeout, "Timeout (s) before receiving lid notification"); +static bool lid_periodic_update __read_mostly = false; +module_param(lid_periodic_update, bool, 0644); +MODULE_PARM_DESC(lid_periodic_update, "Periodically sending lid state updates"); + +static unsigned long lid_update_interval __read_mostly = 1 * MSEC_PER_SEC; +module_param(lid_update_interval, ulong, 0644); +MODULE_PARM_DESC(lid_update_interval, "Interval (ms) between lid periodic updates"); + /* -------------------------------------------------------------------------- FS Interface (/proc) -------------------------------------------------------------------------- */ @@ -395,6 +403,8 @@ static void acpi_lid_initialize_state(struct acpi_device *device) break; case ACPI_BUTTON_LID_INIT_METHOD: (void)acpi_lid_update_state(device); + if (lid_periodic_update) + acpi_lid_start_timer(device, lid_update_interval); break; case ACPI_BUTTON_LID_INIT_IGNORE: default: @@ -560,8 +570,11 @@ static int acpi_button_add(struct acpi_device *device) * more we only care about the last one... */ lid_device = device; - acpi_lid_start_timer(device, - lid_notify_timeout * MSEC_PER_SEC); + if (lid_periodic_update) + acpi_lid_initialize_state(device); + else + acpi_lid_start_timer(device, + lid_notify_timeout * MSEC_PER_SEC); } printk(KERN_INFO PREFIX "%s [%s]\n", name, acpi_device_bid(device));