Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752875AbdFUIz3 (ORCPT ); Wed, 21 Jun 2017 04:55:29 -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 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.39,368,1493708400"; d="scan'208";a="1143367434" 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-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3998 Lines: 90 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)); -- 2.7.4