From patchwork Wed Apr 25 23:40:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Berger X-Patchwork-Id: 10364359 X-Patchwork-Delegate: rjw@sisk.pl 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 19714602D6 for ; Wed, 25 Apr 2018 23:40:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC72F28C90 for ; Wed, 25 Apr 2018 23:40:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DF5E528FC3; Wed, 25 Apr 2018 23:40:55 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham 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 7DE9528C90 for ; Wed, 25 Apr 2018 23:40:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753769AbeDYXky (ORCPT ); Wed, 25 Apr 2018 19:40:54 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:32775 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753349AbeDYXkx (ORCPT ); Wed, 25 Apr 2018 19:40:53 -0400 Received: by mail-pg0-f67.google.com with SMTP id i194so14450431pgd.0; Wed, 25 Apr 2018 16:40:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=57ZcBhPMO/Mv73uLpTyizcSpI54Kkqk+NugqTChZEEA=; b=WJLKtBoXTJmTLr+n05+04Bb2l2naNUHmNIhRMomyeXBfueHjLdogygPVqaNsy0Xj2c t2RtFEdtKzgOT/GtKndvDsFWu+P1A6IJtE+4ihdHVvJ1z1BTlGnyJnzqV8oidy3wT1IK fFmDgdeXVEf62HCuwLpWJSRnsso+Nn1VJWeUYYmBcUA18RaPDFcl7TNGYPaMCXzQLBij R0gCUjx2bdnUgmHH40JAGbfEvcIlM4wn5N3+OsIwHcF6lnugVRVq9qfqUONgRbLi9cYN 0t4BafSu46CGWwba7WTUztHw8fWobgRTn30MBdNlbNpzOoBrnGjvAPjmDjnv+DDG+FPj Wghw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=57ZcBhPMO/Mv73uLpTyizcSpI54Kkqk+NugqTChZEEA=; b=lAdZtvCB2lE9qPaEpzZksSOTfAMoFX98s7FIkhLhtyMjiT6MuTR3/c/hIK4Dsmdkh+ l3NuElKr9T63rBQ2RjeQ/bkC/HsRqXz4+asgaMklzcs1xAuN4YsdiSfWlLg+NY52N4xP zVzUvthkSRjTF8WjX1NOEoYApRRm73ZdTJXF0QVGW64W0qPXP3GTphO/9gVne+gK3K98 k0GfYoSBQHR1pk5sCb2jBf5KWZgOFCXC4hCNvYUc0TdHqCIbyVgtvwjFdYNsacx3zDbP lROJ6VpIj3rvQpptgcDVo7bm5Rdl1tQmOgH4rKwhiWD1ciEH9nAqn+K9TGtdh9VjI4sM l7yQ== X-Gm-Message-State: ALQs6tCWNPjU96oB42dWf2Xik0eamilgi012cUBlureqVSw9NQtO2YIX xg+NOM5tTf7zp1lC1U3RHI8= X-Google-Smtp-Source: AIpwx4+uhe7sTOtNGZs4wWhLlvSwx01wVmmC804pKa8Mddg8pzoH/KyTd9Q1pzTXEtAaGQCFw85TXg== X-Received: by 10.99.36.7 with SMTP id k7mr25352002pgk.63.1524699653029; Wed, 25 Apr 2018 16:40:53 -0700 (PDT) Received: from stbirv-lnx-3.igp.broadcom.net ([192.19.223.250]) by smtp.gmail.com with ESMTPSA id j1sm269398pfc.159.2018.04.25.16.40.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 25 Apr 2018 16:40:52 -0700 (PDT) From: Doug Berger To: "Rafael J. Wysocki" Cc: Pavel Machek , Len Brown , Greg Kroah-Hartman , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Doug Berger Subject: [PATCH] PM / Sleep: only update last time for active wakeup sources Date: Wed, 25 Apr 2018 16:40:30 -0700 Message-Id: <1524699630-30573-1-git-send-email-opendmb@gmail.com> X-Mailer: git-send-email 2.7.4 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When wakelock support was added, the wakeup_source_add() function was updated to set the last_time value of the wakeup source. This has the unintended side effect of producing confusing output from pm_print_active_wakeup_sources() when a wakeup source is added prior to a sleep that is blocked by a different wakeup source. The function pm_print_active_wakeup_sources() will search for the most recently active wakeup source when no active source is found. If a wakeup source is added after a different wakeup source blocks the system from going to sleep it may have a later last_time value than the blocking source and be output as the last active wakeup source even if it has never actually been active. It looks to me like the change to wakeup_source_add() was made to prevent the wakelock garbage collection from accidentally dropping a wakelock during the narrow window between adding the wakelock to the wakelock list in wakelock_lookup_add() and the activation of the wakeup source in pm_wake_lock(). This commit changes the behavior so that only the last_time of the wakeup source used by a wakelock is initialized prior to adding it to the wakeup source list. This preserves the meaning of the last_time value as the last time the wakeup source was active and allows a wakeup source that has never been active to have a last_time value of 0. Fixes: b86ff982 ("PM / Sleep: Add user space interface for manipulating wakeup sources, v3") Signed-off-by: Doug Berger --- drivers/base/power/wakeup.c | 1 - kernel/power/wakelock.c | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c index ea01621..230160e 100644 --- a/drivers/base/power/wakeup.c +++ b/drivers/base/power/wakeup.c @@ -183,7 +183,6 @@ void wakeup_source_add(struct wakeup_source *ws) spin_lock_init(&ws->lock); timer_setup(&ws->timer, pm_wakeup_timer_fn, 0); ws->active = false; - ws->last_time = ktime_get(); spin_lock_irqsave(&events_lock, flags); list_add_rcu(&ws->entry, &wakeup_sources); diff --git a/kernel/power/wakelock.c b/kernel/power/wakelock.c index dfba59b..4210152 100644 --- a/kernel/power/wakelock.c +++ b/kernel/power/wakelock.c @@ -188,6 +188,7 @@ static struct wakelock *wakelock_lookup_add(const char *name, size_t len, return ERR_PTR(-ENOMEM); } wl->ws.name = wl->name; + wl->ws.last_time = ktime_get(); wakeup_source_add(&wl->ws); rb_link_node(&wl->node, parent, node); rb_insert_color(&wl->node, &wakelocks_tree);