Message ID | 20231031093921.755204-1-guanyulin@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b90f:0:b0:403:3b70:6f57 with SMTP id t15csp116275vqg; Tue, 31 Oct 2023 02:41:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGrcDBCtF42b/OT9rlCuFjpeNoObdUTg4EXx7/vIC404gQnF+127m1s/ui+i73C1m/VKNmO X-Received: by 2002:a17:903:230c:b0:1cc:32df:8eb5 with SMTP id d12-20020a170903230c00b001cc32df8eb5mr5867908plh.6.1698745296392; Tue, 31 Oct 2023 02:41:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698745296; cv=none; d=google.com; s=arc-20160816; b=mM/IdTIq+O/pJ8KD5j7CMpYgQlL+O2BViHU5GxDUbqG0f6xSBd3oD58iCOepHKr0XY LfghD2W9h91gIkZ2d2b+V0inMVihzr3cM6yKA+ehKmJakxORBlYtKONO9pEw/o5rMRGC IJRE5MLkayJ55EaLv5lPODmXGUttdGoYOoKYFUy43FhUA98wXv6oAviLsuWsHTkzvFK+ /lK4MEDUbiRgJXbsYhGhUjVScUDbRZD3f3yjJ24m3ReVSSFvYO7fS8PepSUvbSkUO91i W/5R7/mc48DLZllfCzGQDGXABNcIieFOjdMUtYKzWg+cEahegeSrF3kGMqMVdNmMBEai VnOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=AAE8DZ37OcIWWcnHaRuH9NBD5aoBnldXmYIwxjbhOaA=; fh=Ko59WlNiCEgeoijRLOiMUqrjLRsUnqipeDEj6zduCyY=; b=wq5mdlbPgqKWsMedR4gHnLeJZPKht70btgprVEBbLDPEapV+WCWaJScB8lJOqP/4k3 rMirKYyRJaklkTqcP2651zoxHQBYjm3BVWu6IkCuaSJywh8wWMkn/u3np5jrRjlXUoKC rExiG4SRrrbs2HbHQCwz2Kii1ZteYF3TgHcYY+EAPtqi95irqxetIY8H4GQ0pwbAcPTE 6fLa2q6S5dprohrsqKW+ggpemw82ZsKLpteyJ7RdHc4s/aAwiHrF/dRkflwgKjbx3wP5 MXy/8ob+Hr5X3OJMWLmE/5JSWbWTTxViPYauF+Hl0UvWN3/XuQ+73YwsyoKxPjP3pYKI wLGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=KH2KR+sd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id le3-20020a170902fb0300b001c610ae885bsi782867plb.59.2023.10.31.02.41.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 02:41:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=KH2KR+sd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 436E680330E4; Tue, 31 Oct 2023 02:41:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229723AbjJaJlV (ORCPT <rfc822;gah0developer@gmail.com> + 34 others); Tue, 31 Oct 2023 05:41:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229436AbjJaJlU (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 31 Oct 2023 05:41:20 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5D7ADA for <linux-kernel@vger.kernel.org>; Tue, 31 Oct 2023 02:41:16 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d9a5a16fa94so4661359276.0 for <linux-kernel@vger.kernel.org>; Tue, 31 Oct 2023 02:41:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698745276; x=1699350076; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=AAE8DZ37OcIWWcnHaRuH9NBD5aoBnldXmYIwxjbhOaA=; b=KH2KR+sdtQpHU8T/m8rxtdxeszlvRfGg+jb91Qu68O6LhKppAx7PNRzkEkw8cv3c/g yuCxfpA6s5qeX1lLHpWKuHd15lSS3LsKxjTvv8YqBpbMWnHmnY2C85S9sw9sCGS4eb0I Yuuk5uZYcnpD9nqgsWBfCmxl7YP1eojF790tprUlWJnsXksraEs3FNQtL7ZamSirA9vU V47lLjttRby5nA+UBLHXv7dQt54Gx1LgzfGCllcaZKbFYkCv4azgEf2Q+bEAmXfKIQau NQE47hMS2+lW9gW38E01pCfZzbEp0r8oFMp/iC3mMcJBDhl9YOtQGzjeIzmRz/bV8cr2 WF4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698745276; x=1699350076; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=AAE8DZ37OcIWWcnHaRuH9NBD5aoBnldXmYIwxjbhOaA=; b=X5c9OP6TzEev/YT5iIGKuIiJ3MWVNQUjAwtRR4+fRysAl9/lWXMkyjRnuNWyrIZjeh J2QwYv9Xad3GFPoWlK0U6GVIXNqrirkATgusYMNx6lc/79kusV0Xj5Opic5eQRcBDVBt TPoS1GiKYI7jYva4gM91FoeaxMHOi4Q//0LHDdyD+Y5Wuwu7HAsUC+KH3kEBrZY2+WG/ E2K1G1TigOLBcUouWQRpP399/y3zovRquX8jnRDjlozVQywEX5+DOhTbI5WGQDOUoCOO a2WErTRpUBGDisSAWjeaPlx0AS2YdtSYUMap9D5FePPj9oSXjdBHmc+/4oFeJXnSCjXW qSrQ== X-Gm-Message-State: AOJu0YxxDL2wycRWbKW0uO8LudMAABiEepvPCHI7xu58hSMUOp+dpEfk NAXJI9RPnQu4ISzPhOl16uBLtq8aUdQra8o= X-Received: from guanyulin-p620linsp01.ntc.corp.google.com ([2401:fa00:fc:202:a5e:4630:6c4b:b198]) (user=guanyulin job=sendgmr) by 2002:a25:a526:0:b0:da0:c924:4fdc with SMTP id h35-20020a25a526000000b00da0c9244fdcmr44590ybi.6.1698745275891; Tue, 31 Oct 2023 02:41:15 -0700 (PDT) Date: Tue, 31 Oct 2023 17:38:55 +0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.820.g83a721a137-goog Message-ID: <20231031093921.755204-1-guanyulin@google.com> Subject: [PATCH] rpm: pm: enable PM_RPM_EXCEPTION config flag From: Guan-Yu Lin <guanyulin@google.com> To: gregkh@linuxfoundation.org, rafael@kernel.org, len.brown@intel.com, pavel@ucw.cz, stern@rowland.harvard.edu, heikki.krogerus@linux.intel.com, mkl@pengutronix.de, hadess@hadess.net, mailhol.vincent@wanadoo.fr, ivan.orlov0322@gmail.com Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, pumahsu@google.com, raychi@google.com, albertccwang@google.com, Guan-Yu Lin <guanyulin@google.com> Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Tue, 31 Oct 2023 02:41:34 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781263547650782108 X-GMAIL-MSGID: 1781263547650782108 |
Series |
rpm: pm: enable PM_RPM_EXCEPTION config flag
|
|
Commit Message
Guan-Yu Lin
Oct. 31, 2023, 9:38 a.m. UTC
Introducing PM_RPM_EXCEPTION config flag, which may alter the priority
between system power management and runtime power management. In
suspend-to-idle flow, PM core will suspend all devices to avoid device
interact with the system. However, chances are devices might be used by
other systems rather than a single system. In this case, PM core shouldn't
suspend the devices. One may use PM_RPM_EXCEPTION config flag to mark
such exception, and determine the power state of a device with runtime
power management rather than system power management.
Signed-off-by: Guan-Yu Lin <guanyulin@google.com>
---
drivers/usb/core/generic.c | 6 ++++++
drivers/usb/core/usb.h | 16 ++++++++++++++++
kernel/power/Kconfig | 8 ++++++++
3 files changed, 30 insertions(+)
Comments
On Tue, Oct 31, 2023 at 05:38:55PM +0800, Guan-Yu Lin wrote: > Introducing PM_RPM_EXCEPTION config flag, which may alter the priority > between system power management and runtime power management. In > suspend-to-idle flow, PM core will suspend all devices to avoid device > interact with the system. However, chances are devices might be used by > other systems rather than a single system. In this case, PM core shouldn't > suspend the devices. One may use PM_RPM_EXCEPTION config flag to mark > such exception, and determine the power state of a device with runtime > power management rather than system power management. > > Signed-off-by: Guan-Yu Lin <guanyulin@google.com> > --- > drivers/usb/core/generic.c | 6 ++++++ > drivers/usb/core/usb.h | 16 ++++++++++++++++ > kernel/power/Kconfig | 8 ++++++++ > 3 files changed, 30 insertions(+) > > diff --git a/drivers/usb/core/generic.c b/drivers/usb/core/generic.c > index 740342a2812a..bb0dfcfc9764 100644 > --- a/drivers/usb/core/generic.c > +++ b/drivers/usb/core/generic.c > @@ -266,6 +266,9 @@ int usb_generic_driver_suspend(struct usb_device *udev, pm_message_t msg) > { > int rc; > > + if (usb_runtime_pm_exception(udev)) > + return 0; > + > /* Normal USB devices suspend through their upstream port. > * Root hubs don't have upstream ports to suspend, > * so we have to shut down their downstream HC-to-USB > @@ -294,6 +297,9 @@ int usb_generic_driver_resume(struct usb_device *udev, pm_message_t msg) > { > int rc; > > + if (usb_runtime_pm_exception(udev)) > + return 0; > + > /* Normal USB devices resume/reset through their upstream port. > * Root hubs don't have upstream ports to resume or reset, > * so we have to start up their downstream HC-to-USB > diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h > index 60363153fc3f..14a054f814a2 100644 > --- a/drivers/usb/core/usb.h > +++ b/drivers/usb/core/usb.h > @@ -90,6 +90,22 @@ extern void usb_major_cleanup(void); > extern int usb_device_supports_lpm(struct usb_device *udev); > extern int usb_port_disable(struct usb_device *udev); > > +#ifdef CONFIG_PM_RPM_EXCEPTION > + > +static inline int usb_runtime_pm_exception(struct usb_device *udev) > +{ > + return atomic_read(&udev->dev.power.usage_count); > +} > + > +#else > + > +static inline int usb_runtime_pm_exception(struct usb_device *udev) > +{ > + return 0; > +} > + > +#endif > + > #ifdef CONFIG_PM > > extern int usb_suspend(struct device *dev, pm_message_t msg); > diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig > index 4b31629c5be4..beba7a0f3947 100644 > --- a/kernel/power/Kconfig > +++ b/kernel/power/Kconfig > @@ -193,6 +193,14 @@ config PM > responsible for the actual handling of device suspend requests and > wake-up events. > > +config PM_RPM_EXCEPTION > + bool "Prioritize Runtime Power Management more than Power Management" > + default n The default is always 'n' so no need to specify it. > + help > + Provides a way to prioritize Runtime Power Management more than Power > + Management. This way system can suspnd with maintaining specific > + components in operation. This really doesn't give me a good description of why someone would ever want to enable this at all. And why does this have to be a build option? That feels very heavy, why not make it changable at runtime? If this is a build option, how are you going to get all the distros and all of the Android/ChromeOS systems in the world to enable it? thanks, greg k-h
On Tue, Oct 31, 2023 at 05:38:55PM +0800, Guan-Yu Lin wrote: > Introducing PM_RPM_EXCEPTION config flag, which may alter the priority > between system power management and runtime power management. In > suspend-to-idle flow, PM core will suspend all devices to avoid device Your patch affects all forms of system suspend, not just suspend-to-idle. What do you actually mean here? > interact with the system. However, chances are devices might be used by > other systems rather than a single system. In this case, PM core shouldn't > suspend the devices. One may use PM_RPM_EXCEPTION config flag to mark > such exception, and determine the power state of a device with runtime > power management rather than system power management. This sort of arrangement -- a device shared between two different systems -- could happen with any sort of device. Why does your patch affect only USB devices? > diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig > index 4b31629c5be4..beba7a0f3947 100644 > --- a/kernel/power/Kconfig > +++ b/kernel/power/Kconfig > @@ -193,6 +193,14 @@ config PM > responsible for the actual handling of device suspend requests and > wake-up events. > > +config PM_RPM_EXCEPTION > + bool "Prioritize Runtime Power Management more than Power Management" Runtime Power Management is a form of Power Management, so what you wrote doesn't make sense. What you really meant is: Prioritize Runtime Power Management more than System Power Management. > + default n > + help > + Provides a way to prioritize Runtime Power Management more than Power > + Management. This way system can suspnd with maintaining specific s/suspnd/suspend/ s/with/while/ > + components in operation. Your patch does not allow _specific_ components to be kept in operation. _All_ in-use components that support prioritized PM (with this patch, all USB components) will remain powered during system suspend, even if the user wants only _some_ of them to be kept powered. Alan Stern > + > config PM_DEBUG > bool "Power Management Debug Support" > depends on PM > -- > 2.42.0.820.g83a721a137-goog >
On Tue, Oct 31, 2023 at 5:48 PM Greg KH <gregkh@linuxfoundation.org> wrote: > > On Tue, Oct 31, 2023 at 05:38:55PM +0800, Guan-Yu Lin wrote: > > Introducing PM_RPM_EXCEPTION config flag, which may alter the priority > > between system power management and runtime power management. In > > suspend-to-idle flow, PM core will suspend all devices to avoid device > > interact with the system. However, chances are devices might be used by > > other systems rather than a single system. In this case, PM core shouldn't > > suspend the devices. One may use PM_RPM_EXCEPTION config flag to mark > > such exception, and determine the power state of a device with runtime > > power management rather than system power management. > > > > Signed-off-by: Guan-Yu Lin <guanyulin@google.com> > > --- > > drivers/usb/core/generic.c | 6 ++++++ > > drivers/usb/core/usb.h | 16 ++++++++++++++++ > > kernel/power/Kconfig | 8 ++++++++ > > 3 files changed, 30 insertions(+) > > > > diff --git a/drivers/usb/core/generic.c b/drivers/usb/core/generic.c > > index 740342a2812a..bb0dfcfc9764 100644 > > --- a/drivers/usb/core/generic.c > > +++ b/drivers/usb/core/generic.c > > @@ -266,6 +266,9 @@ int usb_generic_driver_suspend(struct usb_device *udev, pm_message_t msg) > > { > > int rc; > > > > + if (usb_runtime_pm_exception(udev)) > > + return 0; > > + > > /* Normal USB devices suspend through their upstream port. > > * Root hubs don't have upstream ports to suspend, > > * so we have to shut down their downstream HC-to-USB > > @@ -294,6 +297,9 @@ int usb_generic_driver_resume(struct usb_device *udev, pm_message_t msg) > > { > > int rc; > > > > + if (usb_runtime_pm_exception(udev)) > > + return 0; > > + > > /* Normal USB devices resume/reset through their upstream port. > > * Root hubs don't have upstream ports to resume or reset, > > * so we have to start up their downstream HC-to-USB > > diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h > > index 60363153fc3f..14a054f814a2 100644 > > --- a/drivers/usb/core/usb.h > > +++ b/drivers/usb/core/usb.h > > @@ -90,6 +90,22 @@ extern void usb_major_cleanup(void); > > extern int usb_device_supports_lpm(struct usb_device *udev); > > extern int usb_port_disable(struct usb_device *udev); > > > > +#ifdef CONFIG_PM_RPM_EXCEPTION > > + > > +static inline int usb_runtime_pm_exception(struct usb_device *udev) > > +{ > > + return atomic_read(&udev->dev.power.usage_count); > > +} > > + > > +#else > > + > > +static inline int usb_runtime_pm_exception(struct usb_device *udev) > > +{ > > + return 0; > > +} > > + > > +#endif > > + > > #ifdef CONFIG_PM > > > > extern int usb_suspend(struct device *dev, pm_message_t msg); > > diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig > > index 4b31629c5be4..beba7a0f3947 100644 > > --- a/kernel/power/Kconfig > > +++ b/kernel/power/Kconfig > > @@ -193,6 +193,14 @@ config PM > > responsible for the actual handling of device suspend requests and > > wake-up events. > > > > +config PM_RPM_EXCEPTION > > + bool "Prioritize Runtime Power Management more than Power Management" > > + default n > > The default is always 'n' so no need to specify it. > Thanks, I will include this in the next version. > > + help > > + Provides a way to prioritize Runtime Power Management more than Power > > + Management. This way system can suspnd with maintaining specific > > + components in operation. > > This really doesn't give me a good description of why someone would ever > want to enable this at all. > > And why does this have to be a build option? That feels very heavy, why > not make it changable at runtime? > > If this is a build option, how are you going to get all the distros and > all of the Android/ChromeOS systems in the world to enable it? > > thanks, > > greg k-h Let's reach a consensus on what this patch should do first. I'll then change the description and implementation accordingly if needed. Please see the next reply for an explanation of my idea. Thanks, Guan-Yu
On Tue, Oct 31, 2023 at 10:39 PM Alan Stern <stern@rowland.harvard.edu> wrote: > > On Tue, Oct 31, 2023 at 05:38:55PM +0800, Guan-Yu Lin wrote: > > Introducing PM_RPM_EXCEPTION config flag, which may alter the priority > > between system power management and runtime power management. In > > suspend-to-idle flow, PM core will suspend all devices to avoid device > > Your patch affects all forms of system suspend, not just > suspend-to-idle. What do you actually mean here? > > > interact with the system. However, chances are devices might be used by > > other systems rather than a single system. In this case, PM core shouldn't > > suspend the devices. One may use PM_RPM_EXCEPTION config flag to mark > > such exception, and determine the power state of a device with runtime > > power management rather than system power management. > > This sort of arrangement -- a device shared between two different > systems -- could happen with any sort of device. Why does your patch > affect only USB devices? > > > diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig > > index 4b31629c5be4..beba7a0f3947 100644 > > --- a/kernel/power/Kconfig > > +++ b/kernel/power/Kconfig > > @@ -193,6 +193,14 @@ config PM > > responsible for the actual handling of device suspend requests and > > wake-up events. > > > > +config PM_RPM_EXCEPTION > > + bool "Prioritize Runtime Power Management more than Power Management" > > Runtime Power Management is a form of Power Management, so what you > wrote doesn't make sense. What you really meant is: Prioritize Runtime > Power Management more than System Power Management. > > > + default n > > + help > > + Provides a way to prioritize Runtime Power Management more than Power > > + Management. This way system can suspnd with maintaining specific > > s/suspnd/suspend/ > s/with/while/ > > > + components in operation. > > Your patch does not allow _specific_ components to be kept in operation. > _All_ in-use components that support prioritized PM (with this patch, > all USB components) will remain powered during system suspend, even if > the user wants only _some_ of them to be kept powered. > > Alan Stern > > > + > > config PM_DEBUG > > bool "Power Management Debug Support" > > depends on PM > > -- > > 2.42.0.820.g83a721a137-goog > > Thanks for the questions. Let me first introduce my motivation for proposing this feature. We can discuss the implementation details later. Motivation: Currently, system PM operations always override runtime PM operations. As runtime PM reflects the power status of devices, there is a possibility that runtime PM states that a device is in use, but system PM decides to suspend it. Up to now, we have assumed that a device can't function without resources from the system, so the device should acquire a wakelock to prevent this from happening. However, what if the device does not need the system's support to function? Or only needs limited resources (e.g., only limited power source or clock) to function? In this situation, we would like to keep the device on but allow the system to suspend. This is an example where we would like devices to follow runtime PM rather than system PM. Feature Supported: 1. Devices could control the priority of system PM and runtime PM during runtime. 2. The control should be at the device level, meaning that different devices should control their own priorities. Goal of This Patch: 1. Design a framework to support features above. 2. Apply it into usb for demonstration. Thanks, Guan-Yu
On Wed, Nov 08, 2023 at 04:45:43PM +0800, Guan-Yu Lin wrote: > Thanks for the questions. Let me first introduce my motivation for > proposing this feature. We can discuss the implementation details later. > > Motivation: > Currently, system PM operations always override runtime PM operations. > As runtime PM reflects the power status of devices, there is a > possibility that runtime PM states that a device is in use, but system > PM decides to suspend it. Up to now, we have assumed that a device can't > function without resources from the system, so the device should acquire > a wakelock to prevent this from happening. However, what if the device [From the fact that you mention wakelocks, I assume that you're trying to implement something for Android systems rather than Linux systems in general.] > does not need the system's support to function? Or only needs limited > resources (e.g., only limited power source or clock) to function? In this > situation, we would like to keep the device on but allow the system to > suspend. This is an example where we would like devices to follow runtime > PM rather than system PM. To put it more simply, you want a way to leave some devices in an active state while the rest of the system is suspended. It's not clear why you have dragged runtime PM into the discussion (apart from the obvious fact that you won't want to keep a device active if it isn't active already). This sounds like a major change, not something to be done with a simple override. You should discuss it with Rafael Wysocki and the linux-pm mailing list before trying to implement anything. > Feature Supported: > 1. Devices could control the priority of system PM and runtime PM during > runtime. This seems like a totally unnecessary side issue. Forget about runtime PM for the time being and concentrate instead on which devices you want to keep active. > 2. The control should be at the device level, meaning that different > devices should control their own priorities. > > Goal of This Patch: > 1. Design a framework to support features above. > 2. Apply it into usb for demonstration. You may find that it is easier (and less work in the long run) to design the general framework and get it working than to concentrate on one particular subsystem. Alan Stern
On Wed, Nov 8, 2023 at 11:56 PM Alan Stern <stern@rowland.harvard.edu> wrote: > > On Wed, Nov 08, 2023 at 04:45:43PM +0800, Guan-Yu Lin wrote: > > Thanks for the questions. Let me first introduce my motivation for > > proposing this feature. We can discuss the implementation details later. > > > > Motivation: > > Currently, system PM operations always override runtime PM operations. > > As runtime PM reflects the power status of devices, there is a > > possibility that runtime PM states that a device is in use, but system > > PM decides to suspend it. Up to now, we have assumed that a device can't > > function without resources from the system, so the device should acquire > > a wakelock to prevent this from happening. However, what if the device > > [From the fact that you mention wakelocks, I assume that you're trying > to implement something for Android systems rather than Linux systems > in general.] > Apologies, I should use "wakeup source" here. > > does not need the system's support to function? Or only needs limited > > resources (e.g., only limited power source or clock) to function? In this > > situation, we would like to keep the device on but allow the system to > > suspend. This is an example where we would like devices to follow runtime > > PM rather than system PM. > > To put it more simply, you want a way to leave some devices in an active > state while the rest of the system is suspended. It's not clear why you > have dragged runtime PM into the discussion (apart from the obvious fact > that you won't want to keep a device active if it isn't active already). > > This sounds like a major change, not something to be done with a simple > override. You should discuss it with Rafael Wysocki and the linux-pm > mailing list before trying to implement anything. > > > Feature Supported: > > 1. Devices could control the priority of system PM and runtime PM during > > runtime. > > This seems like a totally unnecessary side issue. Forget about runtime > PM for the time being and concentrate instead on which devices you want > to keep active. > > > 2. The control should be at the device level, meaning that different > > devices should control their own priorities. > > > > Goal of This Patch: > > 1. Design a framework to support features above. > > 2. Apply it into usb for demonstration. > > You may find that it is easier (and less work in the long run) to design > the general framework and get it working than to concentrate on one > particular subsystem. > > Alan Stern Hi Rafael, We'd like to implement a feature to allow system suspend with several devices still active. Do you have any consideration on this? Thanks, Guan-Yu
On Tue, Nov 14, 2023 at 10:08 AM Guan-Yu Lin <guanyulin@google.com> wrote: > > On Wed, Nov 8, 2023 at 11:56 PM Alan Stern <stern@rowland.harvard.edu> wrote: > > > > On Wed, Nov 08, 2023 at 04:45:43PM +0800, Guan-Yu Lin wrote: > > > Thanks for the questions. Let me first introduce my motivation for > > > proposing this feature. We can discuss the implementation details later. > > > > > > Motivation: > > > Currently, system PM operations always override runtime PM operations. > > > As runtime PM reflects the power status of devices, there is a > > > possibility that runtime PM states that a device is in use, but system > > > PM decides to suspend it. Up to now, we have assumed that a device can't > > > function without resources from the system, so the device should acquire > > > a wakelock to prevent this from happening. However, what if the device > > > > [From the fact that you mention wakelocks, I assume that you're trying > > to implement something for Android systems rather than Linux systems > > in general.] > > > > Apologies, I should use "wakeup source" here. > > > > does not need the system's support to function? Or only needs limited > > > resources (e.g., only limited power source or clock) to function? In this > > > situation, we would like to keep the device on but allow the system to > > > suspend. This is an example where we would like devices to follow runtime > > > PM rather than system PM. > > > > To put it more simply, you want a way to leave some devices in an active > > state while the rest of the system is suspended. It's not clear why you > > have dragged runtime PM into the discussion (apart from the obvious fact > > that you won't want to keep a device active if it isn't active already). > > > > This sounds like a major change, not something to be done with a simple > > override. You should discuss it with Rafael Wysocki and the linux-pm > > mailing list before trying to implement anything. > > > > > Feature Supported: > > > 1. Devices could control the priority of system PM and runtime PM during > > > runtime. > > > > This seems like a totally unnecessary side issue. Forget about runtime > > PM for the time being and concentrate instead on which devices you want > > to keep active. > > > > > 2. The control should be at the device level, meaning that different > > > devices should control their own priorities. > > > > > > Goal of This Patch: > > > 1. Design a framework to support features above. > > > 2. Apply it into usb for demonstration. > > > > You may find that it is easier (and less work in the long run) to design > > the general framework and get it working than to concentrate on one > > particular subsystem. > > > > Alan Stern > > Hi Rafael, > We'd like to implement a feature to allow system suspend with several > devices still active. Do you have any consideration on this? I will have more time to think about this when I'm back from the conference I'm participating in now. In the meantime, I would recommend you to address Alan's comments.
On Wed, Nov 8, 2023 at 11:56 PM Alan Stern <stern@rowland.harvard.edu> wrote: > > On Wed, Nov 08, 2023 at 04:45:43PM +0800, Guan-Yu Lin wrote: > > Thanks for the questions. Let me first introduce my motivation for > > proposing this feature. We can discuss the implementation details later. > > > > Motivation: > > Currently, system PM operations always override runtime PM operations. > > As runtime PM reflects the power status of devices, there is a > > possibility that runtime PM states that a device is in use, but system > > PM decides to suspend it. Up to now, we have assumed that a device can't > > function without resources from the system, so the device should acquire > > a wakelock to prevent this from happening. However, what if the device > > [From the fact that you mention wakelocks, I assume that you're trying > to implement something for Android systems rather than Linux systems > in general.] > > > does not need the system's support to function? Or only needs limited > > resources (e.g., only limited power source or clock) to function? In this > > situation, we would like to keep the device on but allow the system to > > suspend. This is an example where we would like devices to follow runtime > > PM rather than system PM. > > To put it more simply, you want a way to leave some devices in an active > state while the rest of the system is suspended. It's not clear why you > have dragged runtime PM into the discussion (apart from the obvious fact > that you won't want to keep a device active if it isn't active already). > The determination of which device should remain active when the system suspends can be based on various factors. One straightforward approach is to consider the device's runtime pm state. Alternatively, we could explore more elaborate techniques that consider additional criteria. > This sounds like a major change, not something to be done with a simple > override. You should discuss it with Rafael Wysocki and the linux-pm > mailing list before trying to implement anything. > > > Feature Supported: > > 1. Devices could control the priority of system PM and runtime PM during > > runtime. > > This seems like a totally unnecessary side issue. Forget about runtime > PM for the time being and concentrate instead on which devices you want > to keep active. > > > 2. The control should be at the device level, meaning that different > > devices should control their own priorities. > > > > Goal of This Patch: > > 1. Design a framework to support features above. > > 2. Apply it into usb for demonstration. > > You may find that it is easier (and less work in the long run) to design > the general framework and get it working than to concentrate on one > particular subsystem. > > Alan Stern The big picture is "a way to leave some devices in an active state while the rest of the system is suspended", I think it could be separated into: (1) Each system should be able to choose which device(s) is included in this feature. (2) For devices chosen in (1), each of them should have the flexibility to determine when it will not suspend with the system, not just always being active when the system suspends. Regards, Guan-Yu
On Wed, Nov 15, 2023 at 8:08 AM Guan-Yu Lin <guanyulin@google.com> wrote: > > On Wed, Nov 8, 2023 at 11:56 PM Alan Stern <stern@rowland.harvard.edu> wrote: > > > > On Wed, Nov 08, 2023 at 04:45:43PM +0800, Guan-Yu Lin wrote: > > > Thanks for the questions. Let me first introduce my motivation for > > > proposing this feature. We can discuss the implementation details later. > > > > > > Motivation: > > > Currently, system PM operations always override runtime PM operations. > > > As runtime PM reflects the power status of devices, there is a > > > possibility that runtime PM states that a device is in use, but system > > > PM decides to suspend it. Up to now, we have assumed that a device can't > > > function without resources from the system, so the device should acquire > > > a wakelock to prevent this from happening. However, what if the device > > > > [From the fact that you mention wakelocks, I assume that you're trying > > to implement something for Android systems rather than Linux systems > > in general.] > > > > > does not need the system's support to function? Or only needs limited > > > resources (e.g., only limited power source or clock) to function? In this > > > situation, we would like to keep the device on but allow the system to > > > suspend. This is an example where we would like devices to follow runtime > > > PM rather than system PM. > > > > To put it more simply, you want a way to leave some devices in an active > > state while the rest of the system is suspended. It's not clear why you > > have dragged runtime PM into the discussion (apart from the obvious fact > > that you won't want to keep a device active if it isn't active already). > > > > The determination of which device should remain active when the system > suspends can be based on various factors. One straightforward approach > is to consider the device's runtime pm state. Not really. The runtime PM status has no bearing on whether or not the device should remain active over a system suspend/resume cycle. > Alternatively, we could > explore more elaborate techniques that consider additional criteria. In fact, the device's driver decides what is going to happen to it during the system suspend transition. It very well may decide to leave the device in the operational state, but it needs to take dependencies between into account. > > This sounds like a major change, not something to be done with a simple > > override. You should discuss it with Rafael Wysocki and the linux-pm > > mailing list before trying to implement anything. > > > > > Feature Supported: > > > 1. Devices could control the priority of system PM and runtime PM during > > > runtime. > > > > This seems like a totally unnecessary side issue. Forget about runtime > > PM for the time being and concentrate instead on which devices you want > > to keep active. > > > > > 2. The control should be at the device level, meaning that different > > > devices should control their own priorities. > > > > > > Goal of This Patch: > > > 1. Design a framework to support features above. > > > 2. Apply it into usb for demonstration. > > > > You may find that it is easier (and less work in the long run) to design > > the general framework and get it working than to concentrate on one > > particular subsystem. > > > > Alan Stern > > The big picture is "a way to leave some devices in an active state > while the rest of the system is suspended", I think it could be > separated into: > (1) Each system should be able to choose which device(s) is included > in this feature. > (2) For devices chosen in (1), each of them should have the flexibility > to determine when it will not suspend with the system, not just > always being active when the system suspends. A specific use case, please.
On Wed, Nov 15, 2023 at 10:10 PM Rafael J. Wysocki <rafael@kernel.org> wrote: > > On Wed, Nov 15, 2023 at 8:08 AM Guan-Yu Lin <guanyulin@google.com> wrote: > > > > On Wed, Nov 8, 2023 at 11:56 PM Alan Stern <stern@rowland.harvard.edu> wrote: > > > > > > On Wed, Nov 08, 2023 at 04:45:43PM +0800, Guan-Yu Lin wrote: > > > > Thanks for the questions. Let me first introduce my motivation for > > > > proposing this feature. We can discuss the implementation details later. > > > > > > > > Motivation: > > > > Currently, system PM operations always override runtime PM operations. > > > > As runtime PM reflects the power status of devices, there is a > > > > possibility that runtime PM states that a device is in use, but system > > > > PM decides to suspend it. Up to now, we have assumed that a device can't > > > > function without resources from the system, so the device should acquire > > > > a wakelock to prevent this from happening. However, what if the device > > > > > > [From the fact that you mention wakelocks, I assume that you're trying > > > to implement something for Android systems rather than Linux systems > > > in general.] > > > > > > > does not need the system's support to function? Or only needs limited > > > > resources (e.g., only limited power source or clock) to function? In this > > > > situation, we would like to keep the device on but allow the system to > > > > suspend. This is an example where we would like devices to follow runtime > > > > PM rather than system PM. > > > > > > To put it more simply, you want a way to leave some devices in an active > > > state while the rest of the system is suspended. It's not clear why you > > > have dragged runtime PM into the discussion (apart from the obvious fact > > > that you won't want to keep a device active if it isn't active already). > > > > > > > The determination of which device should remain active when the system > > suspends can be based on various factors. One straightforward approach > > is to consider the device's runtime pm state. > > Not really. The runtime PM status has no bearing on whether or not > the device should remain active over a system suspend/resume cycle. > Thanks for the information. > > Alternatively, we could > > explore more elaborate techniques that consider additional criteria. > > In fact, the device's driver decides what is going to happen to it > during the system suspend transition. It very well may decide to > leave the device in the operational state, but it needs to take > dependencies between into account. Seems like it would be better for each device to modify its suspend/ resume code rather than designing a generic framework. As the specific use cases of each component are not yet fully understood, the device driver provides ample flexibility for customization at this stage. > > > > This sounds like a major change, not something to be done with a simple > > > override. You should discuss it with Rafael Wysocki and the linux-pm > > > mailing list before trying to implement anything. > > > > > > > Feature Supported: > > > > 1. Devices could control the priority of system PM and runtime PM during > > > > runtime. > > > > > > This seems like a totally unnecessary side issue. Forget about runtime > > > PM for the time being and concentrate instead on which devices you want > > > to keep active. > > > > > > > 2. The control should be at the device level, meaning that different > > > > devices should control their own priorities. > > > > > > > > Goal of This Patch: > > > > 1. Design a framework to support features above. > > > > 2. Apply it into usb for demonstration. > > > > > > You may find that it is easier (and less work in the long run) to design > > > the general framework and get it working than to concentrate on one > > > particular subsystem. > > > > > > Alan Stern > > > > The big picture is "a way to leave some devices in an active state > > while the rest of the system is suspended", I think it could be > > separated into: > > (1) Each system should be able to choose which device(s) is included > > in this feature. > > (2) For devices chosen in (1), each of them should have the flexibility > > to determine when it will not suspend with the system, not just > > always being active when the system suspends. > > A specific use case, please. We have a sub-system sharing some devices (e.g., usb controller, host controller) with the main system. In the current system power management framework, when the main system suspends, the devices will suspend, too. However, sometimes these devices are still used by the sub-system, so we don't want the main system to always suspend the devices. Regards, Guan-Yu
diff --git a/drivers/usb/core/generic.c b/drivers/usb/core/generic.c index 740342a2812a..bb0dfcfc9764 100644 --- a/drivers/usb/core/generic.c +++ b/drivers/usb/core/generic.c @@ -266,6 +266,9 @@ int usb_generic_driver_suspend(struct usb_device *udev, pm_message_t msg) { int rc; + if (usb_runtime_pm_exception(udev)) + return 0; + /* Normal USB devices suspend through their upstream port. * Root hubs don't have upstream ports to suspend, * so we have to shut down their downstream HC-to-USB @@ -294,6 +297,9 @@ int usb_generic_driver_resume(struct usb_device *udev, pm_message_t msg) { int rc; + if (usb_runtime_pm_exception(udev)) + return 0; + /* Normal USB devices resume/reset through their upstream port. * Root hubs don't have upstream ports to resume or reset, * so we have to start up their downstream HC-to-USB diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h index 60363153fc3f..14a054f814a2 100644 --- a/drivers/usb/core/usb.h +++ b/drivers/usb/core/usb.h @@ -90,6 +90,22 @@ extern void usb_major_cleanup(void); extern int usb_device_supports_lpm(struct usb_device *udev); extern int usb_port_disable(struct usb_device *udev); +#ifdef CONFIG_PM_RPM_EXCEPTION + +static inline int usb_runtime_pm_exception(struct usb_device *udev) +{ + return atomic_read(&udev->dev.power.usage_count); +} + +#else + +static inline int usb_runtime_pm_exception(struct usb_device *udev) +{ + return 0; +} + +#endif + #ifdef CONFIG_PM extern int usb_suspend(struct device *dev, pm_message_t msg); diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig index 4b31629c5be4..beba7a0f3947 100644 --- a/kernel/power/Kconfig +++ b/kernel/power/Kconfig @@ -193,6 +193,14 @@ config PM responsible for the actual handling of device suspend requests and wake-up events. +config PM_RPM_EXCEPTION + bool "Prioritize Runtime Power Management more than Power Management" + default n + help + Provides a way to prioritize Runtime Power Management more than Power + Management. This way system can suspnd with maintaining specific + components in operation. + config PM_DEBUG bool "Power Management Debug Support" depends on PM