From patchwork Fri May 1 10:03:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 6309091 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id ED33A9F1C2 for ; Fri, 1 May 2015 10:04:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BCA19203AB for ; Fri, 1 May 2015 10:04:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AE12520454 for ; Fri, 1 May 2015 10:04:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753463AbbEAKEW (ORCPT ); Fri, 1 May 2015 06:04:22 -0400 Received: from mail-wi0-f172.google.com ([209.85.212.172]:38518 "EHLO mail-wi0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751995AbbEAKEU (ORCPT ); Fri, 1 May 2015 06:04:20 -0400 Received: by wiun10 with SMTP id n10so44115200wiu.1; Fri, 01 May 2015 03:04:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id; bh=lyS/zLZmoIXqVq9p8FGoRjfiTeEUm2Aba8Q0SbGZciY=; b=geWYl9OhZMdm2Tw0W2ujgmbMmyN6rmaBbrtANrVJ0fzdBHfqYTNbhglwGGsNEbbDLl xmUnenfQkTGPh64J/yVHugstKVbDIcLvYusr5HWsP9vvMISK1BBVzRERZZqCeAjy1UJP 2K4B/COoTEaC56BoWr3YJpvkMtlZkg6UMx0/q9SS2jMwqKWUmUSIYVbYirhiUWgUdrml 0y0wW+C+lwz8/xtFLduIYEkBHJgA53r45JLau8eL4/x07vsJJotr3HPlPVML22bu0XHT LUVZA5AjQKIlozIms37/MJGsRacxQa+yKaFeP1RfmMO8HHGn5Oh/qLMq4iBA15XUJs62 YMWw== X-Received: by 10.194.236.33 with SMTP id ur1mr16360184wjc.77.1430474659267; Fri, 01 May 2015 03:04:19 -0700 (PDT) Received: from cizrna.lan ([109.72.12.61]) by mx.google.com with ESMTPSA id l1sm6106493wiy.20.2015.05.01.03.04.17 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 May 2015 03:04:18 -0700 (PDT) From: Tomeu Vizoso To: linux-kernel@vger.kernel.org Cc: Alan Stern , Laurent Pinchart , Dmitry Torokhov , Tomeu Vizoso , "Rafael J. Wysocki" , Len Brown , Pavel Machek , Greg Kroah-Hartman , linux-pm@vger.kernel.org Subject: [PATCH] PM / sleep: Let devices force direct_complete Date: Fri, 1 May 2015 12:03:30 +0200 Message-Id: <1430474611-25560-1-git-send-email-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 2.3.6 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Introduce a new per-device flag power.force_direct_complete that will instruct the PM core to let that device remain in runtime suspend when the system goes into a sleep power state, regardless of the PM state of any of its descendants. This is needed because otherwise it would be needed to get dozens of drivers to implement the prepare() callback and be runtime PM active even if they don't have a 1-to-1 relationship with a piece of HW. This only applies to devices that aren't wakeup-capable, as those would need to setup their IRQs as wakeup-capable in their prepare() callbacks. Signed-off-by: Tomeu Vizoso --- Hi, I'm sending this as a standalone patch as suggested by Alan. Thanks, Tomeu --- Documentation/power/runtime_pm.txt | 10 ++++++++++ drivers/base/power/main.c | 14 ++++++++++---- include/linux/pm.h | 1 + 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Documentation/power/runtime_pm.txt b/Documentation/power/runtime_pm.txt index 44fe1d2..3b0c68d 100644 --- a/Documentation/power/runtime_pm.txt +++ b/Documentation/power/runtime_pm.txt @@ -665,6 +665,16 @@ as appropriate. This only applies to system suspend transitions that are not related to hibernation (see Documentation/power/devices.txt for more information). +For devices that know that can remain runtime suspended when the system +transitions to a sleep state regardless of the PM state of their descendants, +the flag power.force_direct_complete can be set on their device structures. +This can be useful when a real device has several virtual devices as +descendants and it would be very cumbersome to make sure that they return a +positive value in their .prepare() callback and have runtime PM enabled. Usage +of power.force_direct_complete is only allowed to devices that aren't +wakeup-capable, as they would need to set their IRQs as wakeups in their +.prepare() callbacks before the system transitions to a sleep state. + The PM core does its best to reduce the probability of race conditions between the runtime PM and system suspend/resume (and hibernation) callbacks by carrying out the following operations: diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c index 3d874ec..7b962f5 100644 --- a/drivers/base/power/main.c +++ b/drivers/base/power/main.c @@ -1438,7 +1438,9 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async) if (parent) { spin_lock_irq(&parent->power.lock); - dev->parent->power.direct_complete = false; + if (!dev->parent->power.force_direct_complete) + dev->parent->power.direct_complete = false; + if (dev->power.wakeup_path && !dev->parent->power.ignore_children) dev->parent->power.wakeup_path = true; @@ -1605,9 +1607,13 @@ static int device_prepare(struct device *dev, pm_message_t state) * will do the same thing with all of its descendants". This only * applies to suspend transitions, however. */ - spin_lock_irq(&dev->power.lock); - dev->power.direct_complete = ret > 0 && state.event == PM_EVENT_SUSPEND; - spin_unlock_irq(&dev->power.lock); + if (state.event == PM_EVENT_SUSPEND) { + spin_lock_irq(&dev->power.lock); + dev->power.direct_complete = ret > 0 || + (dev->power.force_direct_complete && + !device_can_wakeup(dev)); + spin_unlock_irq(&dev->power.lock); + } return 0; } diff --git a/include/linux/pm.h b/include/linux/pm.h index 2d29c64..2e41cfd 100644 --- a/include/linux/pm.h +++ b/include/linux/pm.h @@ -553,6 +553,7 @@ struct dev_pm_info { bool ignore_children:1; bool early_init:1; /* Owned by the PM core */ bool direct_complete:1; /* Owned by the PM core */ + bool force_direct_complete:1; spinlock_t lock; #ifdef CONFIG_PM_SLEEP struct list_head entry;