From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88EFDC35640 for ; Fri, 21 Feb 2020 09:07:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4F71520679 for ; Fri, 21 Feb 2020 09:07:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582276060; bh=VDDY6QDiH8J+5X+ZpW0SLzGl3vPhD7fk7AYbWVpieC8=; h=References:In-Reply-To:From:Date:Subject:To:Cc:List-ID:From; b=cuaAEvfhBPYfXSzVaQIsEkIn1ZQRIm6vmaZU5AHbyDua7NN/LBlf/PsvUTUv3T1z2 etBfUvERF1m2H/x5FjNbmCsOXZqrDY/3BokCSqVjJT+UvCBmqTsoJJdSLCwLLC0dEs kFGbpg6r+ye89+vl5fS08k/G8LjI49WaoV2d+fWI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727815AbgBUJHj (ORCPT ); Fri, 21 Feb 2020 04:07:39 -0500 Received: from mail-ot1-f67.google.com ([209.85.210.67]:37150 "EHLO mail-ot1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727629AbgBUJHj (ORCPT ); Fri, 21 Feb 2020 04:07:39 -0500 Received: by mail-ot1-f67.google.com with SMTP id b3so1392059otp.4 for ; Fri, 21 Feb 2020 01:07:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Z0diNZQf5HZZ7B9Ku9aThWBNofz9C2xpIf2HlqFxG7s=; b=WmyxccyrDojvN0Jh7KHm+aKUuqn+ZZ2y2iLr5hh+7DYCNJ78lQ0O/6/fg+neNr6dOT bH45IygQLoS1tq6njihgnUf/KXtbf76r38CVsY3b95UWdPKPgU+7c9Y/INWYNoPNubOY v7WMAtTui5dduiRHD9pfRDB9JaN3iVt89fvpgY4RiEX9LEzjjc+ETEoqyfGjmwrWvFYO U7/bRQ/Kmjiv+MQHpZh79iFLMe1K8gX0Oif293mLk0yT52tTICMpGOqQtMFBpXbaTOlg NpGgaB0R2QCcgM5SZ7es9IzlCumFGE2COA8Fx354HY14MJroJLvcJdX8uazwlKGRG55F aRKw== X-Gm-Message-State: APjAAAUiBFYi5ihplvLZmZZNiJx1NWkp9X6cumc/ZSqL/23pgHEnTzPM FV7z189aL+kx0xGIANnaT5atqMjZnT4cM49ZN14= X-Google-Smtp-Source: APXvYqwaTcgmCh5t5XP9fypH5lMZCjiD4QHJSItwkaXm5ierNt008qPgvgOR1jDJozfsQ1qSdIGjnkykx7uU2MnpHt0= X-Received: by 2002:a9d:7559:: with SMTP id b25mr26516156otl.189.1582276058238; Fri, 21 Feb 2020 01:07:38 -0800 (PST) MIME-Version: 1.0 References: <20200219101724.27521-1-sakari.ailus@linux.intel.com> In-Reply-To: <20200219101724.27521-1-sakari.ailus@linux.intel.com> From: "Rafael J. Wysocki" Date: Fri, 21 Feb 2020 10:07:27 +0100 Message-ID: Subject: Re: [PATCH 1/1] PM-runtime: Add pm_runtime_get_if_active To: Sakari Ailus Cc: ACPI Devel Maling List , "Rafael J. Wysocki" Content-Type: text/plain; charset="UTF-8" Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org On Wed, Feb 19, 2020 at 11:21 AM Sakari Ailus wrote: > > pm_runtime_get_if_in_use() bumps the usage count if the usage count is > non-zero and the device's runtime PM status is active. This works for > drivers that do not use autoidle, but for those that do, the function > returns zero even when the device is active. > > In order to maintain sane device state while the device is powered on in > hope it'll be needed, pm_runtime_get_if_active(dev, true) returns greater > than zero if the device was in active state when it was called, in which > case it also increments the device's usage_count. > > If the second argument of pm_runtime_get_if_active() is false, the function > acts just as pm_runtime_get_if_in_use() does. This patch also makes the > latter as a wrapper for the former. > > Signed-off-by: Sakari Ailus Can you please CC this to linux-pm too? > --- > Documentation/power/runtime_pm.rst | 6 +++++ > drivers/base/power/runtime.c | 36 ++++++++++++++++++++++-------- > include/linux/pm_runtime.h | 12 +++++++++- > 3 files changed, 44 insertions(+), 10 deletions(-) > > diff --git a/Documentation/power/runtime_pm.rst b/Documentation/power/runtime_pm.rst > index ab8406c84254..0553008b6279 100644 > --- a/Documentation/power/runtime_pm.rst > +++ b/Documentation/power/runtime_pm.rst > @@ -382,6 +382,12 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h: > nonzero, increment the counter and return 1; otherwise return 0 without > changing the counter > > + `int pm_runtime_get_if_active(struct device *dev, bool ign_usage_count);` > + - return -EINVAL if 'power.disable_depth' is nonzero; otherwise, if the > + runtime PM status is RPM_ACTIVE, and either ign_usage_count is true > + or the device's usage_count is non-zero, increment the counter and > + return 1; otherwise return 0 without changing the counter > + > `void pm_runtime_put_noidle(struct device *dev);` > - decrement the device's usage counter > > diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c > index 16134a69bf6f..99c7da112c95 100644 > --- a/drivers/base/power/runtime.c > +++ b/drivers/base/power/runtime.c > @@ -1087,29 +1087,47 @@ int __pm_runtime_resume(struct device *dev, int rpmflags) > EXPORT_SYMBOL_GPL(__pm_runtime_resume); > > /** > - * pm_runtime_get_if_in_use - Conditionally bump up the device's usage counter. > + * pm_runtime_get_if_active - Conditionally bump up the device's usage counter. > * @dev: Device to handle. > * > * Return -EINVAL if runtime PM is disabled for the device. > * > - * If that's not the case and if the device's runtime PM status is RPM_ACTIVE > - * and the runtime PM usage counter is nonzero, increment the counter and > - * return 1. Otherwise return 0 without changing the counter. > + * Otherwise, if the device's runtime PM status is RPM_ACTIVE and either > + * ign_usage_count is true or the device's usage_count is non-zero, increment > + * the counter and return 1. Otherwise return 0 without changing the counter. > + * > + * If ign_usage_count is true, the function can be used to prevent suspending > + * the device when its runtime PM status is RPM_ACTIVE. > + * > + * If ign_usage_count is false, the function can be used to prevent suspending > + * the device when both its runtime PM status is RPM_ACTIVE and its usage_count > + * is non-zero. > + * > + * The caller is resposible for putting the device's usage count when ther > + * return value is greater than zero. > */ > -int pm_runtime_get_if_in_use(struct device *dev) > +int pm_runtime_get_if_active(struct device *dev, bool ign_usage_count) > { > unsigned long flags; > int retval; > > spin_lock_irqsave(&dev->power.lock, flags); > - retval = dev->power.disable_depth > 0 ? -EINVAL : > - dev->power.runtime_status == RPM_ACTIVE > - && atomic_inc_not_zero(&dev->power.usage_count); > + if (dev->power.disable_depth > 0) { > + retval = -EINVAL; > + } else if (dev->power.runtime_status != RPM_ACTIVE) { > + retval = 0; > + } else if (ign_usage_count) { > + retval = 1; > + atomic_inc(&dev->power.usage_count); > + } else { > + retval = atomic_inc_not_zero(&dev->power.usage_count); > + } > trace_rpm_usage_rcuidle(dev, 0); > spin_unlock_irqrestore(&dev->power.lock, flags); > + > return retval; > } > -EXPORT_SYMBOL_GPL(pm_runtime_get_if_in_use); > +EXPORT_SYMBOL_GPL(pm_runtime_get_if_active); > > /** > * __pm_runtime_set_status - Set runtime PM status of a device. > diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h > index 22af69d237a6..3bdcbce8141a 100644 > --- a/include/linux/pm_runtime.h > +++ b/include/linux/pm_runtime.h > @@ -38,7 +38,7 @@ extern int pm_runtime_force_resume(struct device *dev); > extern int __pm_runtime_idle(struct device *dev, int rpmflags); > extern int __pm_runtime_suspend(struct device *dev, int rpmflags); > extern int __pm_runtime_resume(struct device *dev, int rpmflags); > -extern int pm_runtime_get_if_in_use(struct device *dev); > +extern int pm_runtime_get_if_active(struct device *dev, bool ign_usage_count); > extern int pm_schedule_suspend(struct device *dev, unsigned int delay); > extern int __pm_runtime_set_status(struct device *dev, unsigned int status); > extern int pm_runtime_barrier(struct device *dev); > @@ -60,6 +60,11 @@ extern void pm_runtime_put_suppliers(struct device *dev); > extern void pm_runtime_new_link(struct device *dev); > extern void pm_runtime_drop_link(struct device *dev); > > +static inline int pm_runtime_get_if_in_use(struct device *dev) > +{ > + return pm_runtime_get_if_active(dev, false); > +} > + > static inline void pm_suspend_ignore_children(struct device *dev, bool enable) > { > dev->power.ignore_children = enable; > @@ -143,6 +148,11 @@ static inline int pm_runtime_get_if_in_use(struct device *dev) > { > return -EINVAL; > } > +static inline int pm_runtime_get_if_active(struct device *dev, > + bool ign_usage_count) > +{ > + return -EINVAL; > +} > static inline int __pm_runtime_set_status(struct device *dev, > unsigned int status) { return 0; } > static inline int pm_runtime_barrier(struct device *dev) { return 0; } > -- > 2.20.1 >