diff mbox

[v3,1/8] PM / Sleep: Make the runtime PM centric path known to the PM core

Message ID 1504018610-10822-2-git-send-email-ulf.hansson@linaro.org (mailing list archive)
State Rejected, archived
Headers show

Commit Message

Ulf Hansson Aug. 29, 2017, 2:56 p.m. UTC
The main principle behind the runtime PM centric path, is to re-use the
runtime PM callbacks to implement system sleep - and while doing that also
achieve a fully optimized behaviour from PM point of view.

More precisely, avoid to wake up a device from its low power state during
system sleep, unless the device is really needed to be operational. That
does not only mean avoiding to waste power, but may also decrease system
suspend/resume time for a device.

However, using the runtime PM centric path for a device, does put some
requirements on the behaviour of the PM core and a potential PM domain that
may be attached to the device. So far, these requirements are not being
specially considered, except by the generic PM domain.

To move forward and to make it possible to deploy the runtime PM centric
path for cross SoC drivers, which may have different PM domains attached to
its devices depending on the SoC, we must address how to deal with these
requirements. This change starts by making some adoptions to the PM core,
while other parts, such as the ACPI PM domain needs to be taken care of
separately.

In the runtime PM centric path, the driver is expected to make use of the
pm_runtime_force_suspend|resume() helpers, to deploy system sleep support.
More precisely it may assign the system sleep callbacks to these helpers or
may call them from its own callbacks, in case it needs to perform
additional actions during system sleep.

In other words, the PM core must always invoke the system sleep callbacks
for the device when they are present, to allow the driver to deal with
the system sleep operations.

In case the PM core decides to run the direct_complete path for the device,
it skips invoking most of the system sleep callbacks, besides
->prepare|complete(). Therefore using the direct_complete path in
combination with the runtime PM centric patch for a device, does not play
well.

To deal with this issue, let's add a flag 'is_rpm_sleep', to the struct
dev_pm_info. The driver that deploys the runtime PM centric path, shall set
the flag for the device during ->probe(), to inform the PM core about that
it must not use the direct_complete path for the device.

Note, not allowing the direct_complete path for a device, doesn't implicit
need to propagate to the device's parent/suppliers. Therefore make the PM
core check this condition in device_suspend(), before it decides to abandon
the direct_complete path for parent/suppliers.

To make the is_rpm_sleep flag internal to the PM core, let's add two APIs.
	- dev_pm_use_rpm_sleep(): It sets the flag and should be called by
	  the driver during ->probe().
	- dev_pm_is_rpm_sleep(): Makes it possible for users of the device,
	  like a PM domain, to fetch the state of the flag.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---

Changes in v3:
	- New patch.
	- This replaces the earlier method of adding the no_direct_complete to
	the ACPI structures, according to comments from Rafael.
	- This change also address the consern Rafael had around that
	direct_complete should not have to be disabled for parent/suppliers, in
	case a device use the runtime PM centric path for system sleep.

---
 drivers/base/power/main.c    | 49 +++++++++++++++++++++++++++++++++++++++-----
 drivers/base/power/runtime.c |  1 +
 include/linux/pm.h           |  7 +++++++
 3 files changed, 52 insertions(+), 5 deletions(-)

Comments

Rafael J. Wysocki Aug. 29, 2017, 3:15 p.m. UTC | #1
On Tuesday, August 29, 2017 4:56:43 PM CEST Ulf Hansson wrote:
> The main principle behind the runtime PM centric path, is to re-use the
> runtime PM callbacks to implement system sleep - and while doing that also
> achieve a fully optimized behaviour from PM point of view.
> 
> More precisely, avoid to wake up a device from its low power state during
> system sleep, unless the device is really needed to be operational. That
> does not only mean avoiding to waste power, but may also decrease system
> suspend/resume time for a device.
> 
> However, using the runtime PM centric path for a device, does put some
> requirements on the behaviour of the PM core and a potential PM domain that
> may be attached to the device. So far, these requirements are not being
> specially considered, except by the generic PM domain.
> 
> To move forward and to make it possible to deploy the runtime PM centric
> path for cross SoC drivers, which may have different PM domains attached to
> its devices depending on the SoC, we must address how to deal with these
> requirements. This change starts by making some adoptions to the PM core,
> while other parts, such as the ACPI PM domain needs to be taken care of
> separately.
> 
> In the runtime PM centric path, the driver is expected to make use of the
> pm_runtime_force_suspend|resume() helpers, to deploy system sleep support.
> More precisely it may assign the system sleep callbacks to these helpers or
> may call them from its own callbacks, in case it needs to perform
> additional actions during system sleep.
> 
> In other words, the PM core must always invoke the system sleep callbacks
> for the device when they are present, to allow the driver to deal with
> the system sleep operations.
> 
> In case the PM core decides to run the direct_complete path for the device,
> it skips invoking most of the system sleep callbacks, besides
> ->prepare|complete(). Therefore using the direct_complete path in
> combination with the runtime PM centric patch for a device, does not play
> well.
> 
> To deal with this issue, let's add a flag 'is_rpm_sleep', to the struct
> dev_pm_info. The driver that deploys the runtime PM centric path, shall set
> the flag for the device during ->probe(), to inform the PM core about that
> it must not use the direct_complete path for the device.
> 
> Note, not allowing the direct_complete path for a device, doesn't implicit
> need to propagate to the device's parent/suppliers. Therefore make the PM
> core check this condition in device_suspend(), before it decides to abandon
> the direct_complete path for parent/suppliers.
> 
> To make the is_rpm_sleep flag internal to the PM core, let's add two APIs.
> 	- dev_pm_use_rpm_sleep(): It sets the flag and should be called by
> 	  the driver during ->probe().
> 	- dev_pm_is_rpm_sleep(): Makes it possible for users of the device,
> 	  like a PM domain, to fetch the state of the flag.
> 
> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
> ---
> 
> Changes in v3:
> 	- New patch.
> 	- This replaces the earlier method of adding the no_direct_complete to
> 	the ACPI structures, according to comments from Rafael.
> 	- This change also address the consern Rafael had around that
> 	direct_complete should not have to be disabled for parent/suppliers, in
> 	case a device use the runtime PM centric path for system sleep.
> 
> ---
>  drivers/base/power/main.c    | 49 +++++++++++++++++++++++++++++++++++++++-----
>  drivers/base/power/runtime.c |  1 +
>  include/linux/pm.h           |  7 +++++++
>  3 files changed, 52 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
> index ea1732e..865737a 100644
> --- a/drivers/base/power/main.c
> +++ b/drivers/base/power/main.c
> @@ -1549,14 +1549,16 @@ 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->power.is_rpm_sleep)
> +				dev->parent->power.direct_complete = false;

This doesn't look good to me at all.

It potentially breaks the fundamental assumption of the direct_complete
mechanism that no devices with that flag set will ever be runtime resumed
during system suspend.

Which can happen with this change if a device with power.is_rpm_sleep is
resumed causing the parent to be resumed too.

>  			if (dev->power.wakeup_path
>  			    && !dev->parent->power.ignore_children)
>  				dev->parent->power.wakeup_path = true;
>  
>  			spin_unlock_irq(&parent->power.lock);
>  		}
> -		dpm_clear_suppliers_direct_complete(dev);
> +		if (!dev->power.is_rpm_sleep)
> +			dpm_clear_suppliers_direct_complete(dev);

And same here.

>  	}
>  
>  	device_unlock(dev);
> @@ -1709,11 +1711,14 @@ static int device_prepare(struct device *dev, pm_message_t state)
>  	 * A positive return value from ->prepare() means "this device appears
>  	 * to be runtime-suspended and its state is fine, so if it really is
>  	 * runtime-suspended, you can leave it in that state provided that you
> -	 * will do the same thing with all of its descendants".  This only
> -	 * applies to suspend transitions, however.
> +	 * will do the same thing with all of its descendants". To allow this,
> +	 * the is_rpm_sleep flag must not be set, which is default false, but
> +	 * may have been changed by a driver. This only applies to suspend
> +	 * transitions, however.
>  	 */
>  	spin_lock_irq(&dev->power.lock);
> -	dev->power.direct_complete = ret > 0 && state.event == PM_EVENT_SUSPEND;
> +	dev->power.direct_complete = ret > 0 && !dev->power.is_rpm_sleep &&
> +				state.event == PM_EVENT_SUSPEND;

The only problem addressed by avoiding direct_complete is when runtime PM needs
to work during __device_suspend() for devices with direct_complete set.  You
said that this was not the case with the i2c designware driver, so I'm not sure
what the purpose of this is.

It doesn't solve any other problems at all.

>  	spin_unlock_irq(&dev->power.lock);
>  	return 0;
>  }
> @@ -1841,6 +1846,40 @@ void dpm_for_each_dev(void *data, void (*fn)(struct device *, void *))
>  }
>  EXPORT_SYMBOL_GPL(dpm_for_each_dev);
>  
> +/**
> + * dev_pm_use_rpm_sleep - use the runtime PM centric sleep path.
> + * @dev: the device to use the path for.
> + *
> + * The runtime PM centric path requires the system sleep callbacks for the
> + * driver of the device to be invoked. This function sets the is_rpm_sleep flag
> + * to enable this path to be used, which makes the PM core to adopt to this
> + * behaviour. More precisely the PM core makes sure to not run the
> + * direct_complete path for the chosen device during system sleep, when the
> + * is_rpm_sleep flag is set. A driver using the runtime PM centric path, shall
> + * use the pm_runtime_force_suspend|resume() helpers, to deploy system sleep
> + * support and call this function during ->probe().
> + * The is_rpm_sleep flag is cleared when unbinding/bind-failure of the driver.
> + */
> +void dev_pm_use_rpm_sleep(struct device *dev)
> +{
> +	dev->power.is_rpm_sleep = true;
> +}
> +EXPORT_SYMBOL_GPL(dev_pm_use_rpm_sleep);
> +
> +/**
> + * dev_pm_is_rpm_sleep - Returns the value of the is_rpm_sleep flag.
> + * @dev: the device to return the flag for.
> + *
> + * The caller of this function is typically a subsystem or a PM domain that
> + * needs to know if the runtime PM centric path is used for the device. It may
> + * be invoked during any of the system sleep phases.
> + */
> +bool dev_pm_is_rpm_sleep(struct device *dev)
> +{
> +	return dev->power.is_rpm_sleep;
> +}
> +EXPORT_SYMBOL_GPL(dev_pm_is_rpm_sleep);
> +
>  static bool pm_ops_is_empty(const struct dev_pm_ops *ops)
>  {
>  	if (!ops)
> diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
> index 7bcf80f..b2ab22c 100644
> --- a/drivers/base/power/runtime.c
> +++ b/drivers/base/power/runtime.c
> @@ -1522,6 +1522,7 @@ void pm_runtime_reinit(struct device *dev)
>  				pm_runtime_put(dev->parent);
>  		}
>  	}
> +	dev->power.is_rpm_sleep = false;
>  }
>  
>  /**
> diff --git a/include/linux/pm.h b/include/linux/pm.h
> index 47ded8a..5bf96d2 100644
> --- a/include/linux/pm.h
> +++ b/include/linux/pm.h
> @@ -559,6 +559,7 @@ struct dev_pm_info {
>  	bool			is_suspended:1;	/* Ditto */
>  	bool			is_noirq_suspended:1;
>  	bool			is_late_suspended:1;
> +	bool			is_rpm_sleep:1;	/* Owned by the PM core */

It is expected to be set by drivers, so by definition it is *not* owned by the
PM core.

>  	bool			early_init:1;	/* Owned by the PM core */
>  	bool			direct_complete:1;	/* Owned by the PM core */
>  	spinlock_t		lock;
> @@ -716,6 +717,9 @@ extern void __suspend_report_result(const char *function, void *fn, int ret);
>  extern int device_pm_wait_for_dev(struct device *sub, struct device *dev);
>  extern void dpm_for_each_dev(void *data, void (*fn)(struct device *, void *));
>  
> +extern void dev_pm_use_rpm_sleep(struct device *dev);
> +extern bool dev_pm_is_rpm_sleep(struct device *dev);
> +
>  extern int pm_generic_prepare(struct device *dev);
>  extern int pm_generic_suspend_late(struct device *dev);
>  extern int pm_generic_suspend_noirq(struct device *dev);
> @@ -759,6 +763,9 @@ static inline void dpm_for_each_dev(void *data, void (*fn)(struct device *, void
>  {
>  }
>  
> +static inline void dev_pm_use_rpm_sleep(struct device *dev) {}
> +static inline bool dev_pm_is_rpm_sleep(struct device *dev) { return false; }
> +
>  #define pm_generic_prepare		NULL
>  #define pm_generic_suspend_late		NULL
>  #define pm_generic_suspend_noirq	NULL
> 

Thanks,
Rafael

--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Ulf Hansson Aug. 30, 2017, 7:13 a.m. UTC | #2
On 29 August 2017 at 17:15, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
> On Tuesday, August 29, 2017 4:56:43 PM CEST Ulf Hansson wrote:
>> The main principle behind the runtime PM centric path, is to re-use the
>> runtime PM callbacks to implement system sleep - and while doing that also
>> achieve a fully optimized behaviour from PM point of view.
>>
>> More precisely, avoid to wake up a device from its low power state during
>> system sleep, unless the device is really needed to be operational. That
>> does not only mean avoiding to waste power, but may also decrease system
>> suspend/resume time for a device.
>>
>> However, using the runtime PM centric path for a device, does put some
>> requirements on the behaviour of the PM core and a potential PM domain that
>> may be attached to the device. So far, these requirements are not being
>> specially considered, except by the generic PM domain.
>>
>> To move forward and to make it possible to deploy the runtime PM centric
>> path for cross SoC drivers, which may have different PM domains attached to
>> its devices depending on the SoC, we must address how to deal with these
>> requirements. This change starts by making some adoptions to the PM core,
>> while other parts, such as the ACPI PM domain needs to be taken care of
>> separately.
>>
>> In the runtime PM centric path, the driver is expected to make use of the
>> pm_runtime_force_suspend|resume() helpers, to deploy system sleep support.
>> More precisely it may assign the system sleep callbacks to these helpers or
>> may call them from its own callbacks, in case it needs to perform
>> additional actions during system sleep.
>>
>> In other words, the PM core must always invoke the system sleep callbacks
>> for the device when they are present, to allow the driver to deal with
>> the system sleep operations.
>>
>> In case the PM core decides to run the direct_complete path for the device,
>> it skips invoking most of the system sleep callbacks, besides
>> ->prepare|complete(). Therefore using the direct_complete path in
>> combination with the runtime PM centric patch for a device, does not play
>> well.
>>
>> To deal with this issue, let's add a flag 'is_rpm_sleep', to the struct
>> dev_pm_info. The driver that deploys the runtime PM centric path, shall set
>> the flag for the device during ->probe(), to inform the PM core about that
>> it must not use the direct_complete path for the device.
>>
>> Note, not allowing the direct_complete path for a device, doesn't implicit
>> need to propagate to the device's parent/suppliers. Therefore make the PM
>> core check this condition in device_suspend(), before it decides to abandon
>> the direct_complete path for parent/suppliers.
>>
>> To make the is_rpm_sleep flag internal to the PM core, let's add two APIs.
>>       - dev_pm_use_rpm_sleep(): It sets the flag and should be called by
>>         the driver during ->probe().
>>       - dev_pm_is_rpm_sleep(): Makes it possible for users of the device,
>>         like a PM domain, to fetch the state of the flag.
>>
>> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
>> ---
>>
>> Changes in v3:
>>       - New patch.
>>       - This replaces the earlier method of adding the no_direct_complete to
>>       the ACPI structures, according to comments from Rafael.
>>       - This change also address the consern Rafael had around that
>>       direct_complete should not have to be disabled for parent/suppliers, in
>>       case a device use the runtime PM centric path for system sleep.
>>
>> ---
>>  drivers/base/power/main.c    | 49 +++++++++++++++++++++++++++++++++++++++-----
>>  drivers/base/power/runtime.c |  1 +
>>  include/linux/pm.h           |  7 +++++++
>>  3 files changed, 52 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
>> index ea1732e..865737a 100644
>> --- a/drivers/base/power/main.c
>> +++ b/drivers/base/power/main.c
>> @@ -1549,14 +1549,16 @@ 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->power.is_rpm_sleep)
>> +                             dev->parent->power.direct_complete = false;
>
> This doesn't look good to me at all.
>
> It potentially breaks the fundamental assumption of the direct_complete
> mechanism that no devices with that flag set will ever be runtime resumed
> during system suspend.
>
> Which can happen with this change if a device with power.is_rpm_sleep is
> resumed causing the parent to be resumed too.

Doesn't the exact same problem you describe, already exist prior my change!?

That is, if the current device is runtime suspended and the
direct_complete flag is set for it, then __device_suspend() has
already disabled runtime PM for the device, when we reach this point.
That means, a following attempts to runtime resume the device will
fail and thus also to runtime resume its parent.

So to me, this is a different problem, related how to work out the
correct order of how to suspend devices.

>
>>                       if (dev->power.wakeup_path
>>                           && !dev->parent->power.ignore_children)
>>                               dev->parent->power.wakeup_path = true;
>>
>>                       spin_unlock_irq(&parent->power.lock);
>>               }
>> -             dpm_clear_suppliers_direct_complete(dev);
>> +             if (!dev->power.is_rpm_sleep)
>> +                     dpm_clear_suppliers_direct_complete(dev);
>
> And same here.

See comment above.

>
>>       }
>>
>>       device_unlock(dev);
>> @@ -1709,11 +1711,14 @@ static int device_prepare(struct device *dev, pm_message_t state)
>>        * A positive return value from ->prepare() means "this device appears
>>        * to be runtime-suspended and its state is fine, so if it really is
>>        * runtime-suspended, you can leave it in that state provided that you
>> -      * will do the same thing with all of its descendants".  This only
>> -      * applies to suspend transitions, however.
>> +      * will do the same thing with all of its descendants". To allow this,
>> +      * the is_rpm_sleep flag must not be set, which is default false, but
>> +      * may have been changed by a driver. This only applies to suspend
>> +      * transitions, however.
>>        */
>>       spin_lock_irq(&dev->power.lock);
>> -     dev->power.direct_complete = ret > 0 && state.event == PM_EVENT_SUSPEND;
>> +     dev->power.direct_complete = ret > 0 && !dev->power.is_rpm_sleep &&
>> +                             state.event == PM_EVENT_SUSPEND;
>
> The only problem addressed by avoiding direct_complete is when runtime PM needs
> to work during __device_suspend() for devices with direct_complete set.  You
> said that this was not the case with the i2c designware driver, so I'm not sure
> what the purpose of this is.

I should probably work more on my changelog, because I tried to
explain it there.

Anyway, let me quote the important parts, and this is not specific for
the i2c-designware-driver, but generic to drivers using
pm_runtime_force_suspend|resume().

"In the runtime PM centric path, the driver is expected to make use of
the pm_runtime_force_suspend|resume() helpers, to deploy system sleep
support. More precisely it may assign the system sleep callbacks to
these helpers or may call them from its own callbacks, in case it
needs to perform additional actions during system sleep.

In other words, the PM core must always invoke the system sleep
callbacks for the device when they are present, to allow the driver to
deal with the system sleep operations."

A concrete example is drivers/spi/spi-fsl-espi.c, but one can easily find more.

>
> It doesn't solve any other problems at all.
>
>>       spin_unlock_irq(&dev->power.lock);
>>       return 0;
>>  }
>> @@ -1841,6 +1846,40 @@ void dpm_for_each_dev(void *data, void (*fn)(struct device *, void *))
>>  }
>>  EXPORT_SYMBOL_GPL(dpm_for_each_dev);
>>
>> +/**
>> + * dev_pm_use_rpm_sleep - use the runtime PM centric sleep path.
>> + * @dev: the device to use the path for.
>> + *
>> + * The runtime PM centric path requires the system sleep callbacks for the
>> + * driver of the device to be invoked. This function sets the is_rpm_sleep flag
>> + * to enable this path to be used, which makes the PM core to adopt to this
>> + * behaviour. More precisely the PM core makes sure to not run the
>> + * direct_complete path for the chosen device during system sleep, when the
>> + * is_rpm_sleep flag is set. A driver using the runtime PM centric path, shall
>> + * use the pm_runtime_force_suspend|resume() helpers, to deploy system sleep
>> + * support and call this function during ->probe().
>> + * The is_rpm_sleep flag is cleared when unbinding/bind-failure of the driver.
>> + */
>> +void dev_pm_use_rpm_sleep(struct device *dev)
>> +{
>> +     dev->power.is_rpm_sleep = true;
>> +}
>> +EXPORT_SYMBOL_GPL(dev_pm_use_rpm_sleep);
>> +
>> +/**
>> + * dev_pm_is_rpm_sleep - Returns the value of the is_rpm_sleep flag.
>> + * @dev: the device to return the flag for.
>> + *
>> + * The caller of this function is typically a subsystem or a PM domain that
>> + * needs to know if the runtime PM centric path is used for the device. It may
>> + * be invoked during any of the system sleep phases.
>> + */
>> +bool dev_pm_is_rpm_sleep(struct device *dev)
>> +{
>> +     return dev->power.is_rpm_sleep;
>> +}
>> +EXPORT_SYMBOL_GPL(dev_pm_is_rpm_sleep);
>> +
>>  static bool pm_ops_is_empty(const struct dev_pm_ops *ops)
>>  {
>>       if (!ops)
>> diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
>> index 7bcf80f..b2ab22c 100644
>> --- a/drivers/base/power/runtime.c
>> +++ b/drivers/base/power/runtime.c
>> @@ -1522,6 +1522,7 @@ void pm_runtime_reinit(struct device *dev)
>>                               pm_runtime_put(dev->parent);
>>               }
>>       }
>> +     dev->power.is_rpm_sleep = false;
>>  }
>>
>>  /**
>> diff --git a/include/linux/pm.h b/include/linux/pm.h
>> index 47ded8a..5bf96d2 100644
>> --- a/include/linux/pm.h
>> +++ b/include/linux/pm.h
>> @@ -559,6 +559,7 @@ struct dev_pm_info {
>>       bool                    is_suspended:1; /* Ditto */
>>       bool                    is_noirq_suspended:1;
>>       bool                    is_late_suspended:1;
>> +     bool                    is_rpm_sleep:1; /* Owned by the PM core */
>
> It is expected to be set by drivers, so by definition it is *not* owned by the
> PM core.

Ahh, I see. I didn't quite get those comments, thanks for clarifying.

>
>>       bool                    early_init:1;   /* Owned by the PM core */
>>       bool                    direct_complete:1;      /* Owned by the PM core */
>>       spinlock_t              lock;
>> @@ -716,6 +717,9 @@ extern void __suspend_report_result(const char *function, void *fn, int ret);
>>  extern int device_pm_wait_for_dev(struct device *sub, struct device *dev);
>>  extern void dpm_for_each_dev(void *data, void (*fn)(struct device *, void *));
>>
>> +extern void dev_pm_use_rpm_sleep(struct device *dev);
>> +extern bool dev_pm_is_rpm_sleep(struct device *dev);
>> +
>>  extern int pm_generic_prepare(struct device *dev);
>>  extern int pm_generic_suspend_late(struct device *dev);
>>  extern int pm_generic_suspend_noirq(struct device *dev);
>> @@ -759,6 +763,9 @@ static inline void dpm_for_each_dev(void *data, void (*fn)(struct device *, void
>>  {
>>  }
>>
>> +static inline void dev_pm_use_rpm_sleep(struct device *dev) {}
>> +static inline bool dev_pm_is_rpm_sleep(struct device *dev) { return false; }
>> +
>>  #define pm_generic_prepare           NULL
>>  #define pm_generic_suspend_late              NULL
>>  #define pm_generic_suspend_noirq     NULL
>>
>
> Thanks,
> Rafael
>

Thanks for reviewing!

Kind regards
Uffe
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Rafael J. Wysocki Aug. 30, 2017, 1:37 p.m. UTC | #3
On Wednesday, August 30, 2017 9:13:47 AM CEST Ulf Hansson wrote:
> On 29 August 2017 at 17:15, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
> > On Tuesday, August 29, 2017 4:56:43 PM CEST Ulf Hansson wrote:
> >> The main principle behind the runtime PM centric path, is to re-use the
> >> runtime PM callbacks to implement system sleep - and while doing that also
> >> achieve a fully optimized behaviour from PM point of view.
> >>
> >> More precisely, avoid to wake up a device from its low power state during
> >> system sleep, unless the device is really needed to be operational. That
> >> does not only mean avoiding to waste power, but may also decrease system
> >> suspend/resume time for a device.
> >>
> >> However, using the runtime PM centric path for a device, does put some
> >> requirements on the behaviour of the PM core and a potential PM domain that
> >> may be attached to the device. So far, these requirements are not being
> >> specially considered, except by the generic PM domain.
> >>
> >> To move forward and to make it possible to deploy the runtime PM centric
> >> path for cross SoC drivers, which may have different PM domains attached to
> >> its devices depending on the SoC, we must address how to deal with these
> >> requirements. This change starts by making some adoptions to the PM core,
> >> while other parts, such as the ACPI PM domain needs to be taken care of
> >> separately.
> >>
> >> In the runtime PM centric path, the driver is expected to make use of the
> >> pm_runtime_force_suspend|resume() helpers, to deploy system sleep support.
> >> More precisely it may assign the system sleep callbacks to these helpers or
> >> may call them from its own callbacks, in case it needs to perform
> >> additional actions during system sleep.
> >>
> >> In other words, the PM core must always invoke the system sleep callbacks
> >> for the device when they are present, to allow the driver to deal with
> >> the system sleep operations.
> >>
> >> In case the PM core decides to run the direct_complete path for the device,
> >> it skips invoking most of the system sleep callbacks, besides
> >> ->prepare|complete(). Therefore using the direct_complete path in
> >> combination with the runtime PM centric patch for a device, does not play
> >> well.
> >>
> >> To deal with this issue, let's add a flag 'is_rpm_sleep', to the struct
> >> dev_pm_info. The driver that deploys the runtime PM centric path, shall set
> >> the flag for the device during ->probe(), to inform the PM core about that
> >> it must not use the direct_complete path for the device.
> >>
> >> Note, not allowing the direct_complete path for a device, doesn't implicit
> >> need to propagate to the device's parent/suppliers. Therefore make the PM
> >> core check this condition in device_suspend(), before it decides to abandon
> >> the direct_complete path for parent/suppliers.
> >>
> >> To make the is_rpm_sleep flag internal to the PM core, let's add two APIs.
> >>       - dev_pm_use_rpm_sleep(): It sets the flag and should be called by
> >>         the driver during ->probe().
> >>       - dev_pm_is_rpm_sleep(): Makes it possible for users of the device,
> >>         like a PM domain, to fetch the state of the flag.
> >>
> >> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
> >> ---
> >>
> >> Changes in v3:
> >>       - New patch.
> >>       - This replaces the earlier method of adding the no_direct_complete to
> >>       the ACPI structures, according to comments from Rafael.
> >>       - This change also address the consern Rafael had around that
> >>       direct_complete should not have to be disabled for parent/suppliers, in
> >>       case a device use the runtime PM centric path for system sleep.
> >>
> >> ---
> >>  drivers/base/power/main.c    | 49 +++++++++++++++++++++++++++++++++++++++-----
> >>  drivers/base/power/runtime.c |  1 +
> >>  include/linux/pm.h           |  7 +++++++
> >>  3 files changed, 52 insertions(+), 5 deletions(-)
> >>
> >> diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
> >> index ea1732e..865737a 100644
> >> --- a/drivers/base/power/main.c
> >> +++ b/drivers/base/power/main.c
> >> @@ -1549,14 +1549,16 @@ 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->power.is_rpm_sleep)
> >> +                             dev->parent->power.direct_complete = false;
> >
> > This doesn't look good to me at all.
> >
> > It potentially breaks the fundamental assumption of the direct_complete
> > mechanism that no devices with that flag set will ever be runtime resumed
> > during system suspend.
> >
> > Which can happen with this change if a device with power.is_rpm_sleep is
> > resumed causing the parent to be resumed too.
> 
> Doesn't the exact same problem you describe, already exist prior my change!?

No, it doesn't.

> That is, if the current device is runtime suspended and the
> direct_complete flag is set for it, then __device_suspend() has
> already disabled runtime PM for the device, when we reach this point.
> That means, a following attempts to runtime resume the device will
> fail and thus also to runtime resume its parent.

That's because any devices with direct_complete set *cannot* be runtime
resumed after __device_suspend().  That's intentional and how the thing
is designed.  It cannot work differently, sorry.

> So to me, this is a different problem, related how to work out the
> correct order of how to suspend devices.

The ordering matters here, but it is not the problem.

Setting direct_complete means that PM callbacks for this device won't be
invoked going forward.  However, if the state of the device was to change
(like as a result of runtime PM resume), it would be necessary to run those
callbacks after all, but after __device_suspend() it may be too late for
that, because the ->suspend callback may have been skipped already.

The only way to address that is to prevent runtime PM resume of the device
from happening at the point the PM core decides to use direct_complete for it,
but that requires runtime PM to be disabled for it.  Moreover, since the
device is now suspended with runtime PM disabled and its children might rely
on it if they were active, the children must be suspended with runtime PM
disabled at this point too.  That's why direct_complete can only be set
for a device if it is set for the entire hierarchy below it.

Summary: If you allow a device to be runtime resumed during system susped,
direct_complete cannot be set for it and it cannot be set for its parent and
so on.

[cut]

> >> @@ -1709,11 +1711,14 @@ static int device_prepare(struct device *dev, pm_message_t state)
> >>        * A positive return value from ->prepare() means "this device appears
> >>        * to be runtime-suspended and its state is fine, so if it really is
> >>        * runtime-suspended, you can leave it in that state provided that you
> >> -      * will do the same thing with all of its descendants".  This only
> >> -      * applies to suspend transitions, however.
> >> +      * will do the same thing with all of its descendants". To allow this,
> >> +      * the is_rpm_sleep flag must not be set, which is default false, but
> >> +      * may have been changed by a driver. This only applies to suspend
> >> +      * transitions, however.
> >>        */
> >>       spin_lock_irq(&dev->power.lock);
> >> -     dev->power.direct_complete = ret > 0 && state.event == PM_EVENT_SUSPEND;
> >> +     dev->power.direct_complete = ret > 0 && !dev->power.is_rpm_sleep &&
> >> +                             state.event == PM_EVENT_SUSPEND;
> >
> > The only problem addressed by avoiding direct_complete is when runtime PM needs
> > to work during __device_suspend() for devices with direct_complete set.  You
> > said that this was not the case with the i2c designware driver, so I'm not sure
> > what the purpose of this is.
> 
> I should probably work more on my changelog, because I tried to
> explain it there.
> 
> Anyway, let me quote the important parts, and this is not specific for
> the i2c-designware-driver, but generic to drivers using
> pm_runtime_force_suspend|resume().
> 
> "In the runtime PM centric path, the driver is expected to make use of
> the pm_runtime_force_suspend|resume() helpers, to deploy system sleep
> support. More precisely it may assign the system sleep callbacks to
> these helpers or may call them from its own callbacks, in case it
> needs to perform additional actions during system sleep.
> 
> In other words, the PM core must always invoke the system sleep
> callbacks for the device when they are present, to allow the driver to
> deal with the system sleep operations."
> 
> A concrete example is drivers/spi/spi-fsl-espi.c, but one can easily find more.

In fact, the new flag introduced here means "assume that that the driver of this
device points ->late_suspend and ->early_resume to pm_runtime_force_suspend()
and pm_runtime_force_resume(), respectively."  Which then implies that
direct_complete cannot be used with it and (and with its parent and so on)
and that it is not necessary to runtime resume it during system suspend.

However, there are (or at least there may be) devices that need not be
runtime resumed during system suspend even though their drivers don't use
_force_suspend/resume().

Also there are devices whose drivers don't want direct_complete to be used with
them, even though they don't use _force_suspend/resume() and they *do* need
their devices to be runtime resumed during system suspend.

Moreover, some drivers may not mind direct_complete even though their devices
need not be runtime resumed during system suspend.  All of that doesn't have
to be related to using _force_suspend/resume() at all.

So I don't see any reason whatever for combining all of these three *different*
conditions under one flag.

Thanks,
Rafael

--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Ulf Hansson Aug. 31, 2017, 9:06 a.m. UTC | #4
[...]

>> >> diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
>> >> index ea1732e..865737a 100644
>> >> --- a/drivers/base/power/main.c
>> >> +++ b/drivers/base/power/main.c
>> >> @@ -1549,14 +1549,16 @@ 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->power.is_rpm_sleep)
>> >> +                             dev->parent->power.direct_complete = false;
>> >
>> > This doesn't look good to me at all.
>> >
>> > It potentially breaks the fundamental assumption of the direct_complete
>> > mechanism that no devices with that flag set will ever be runtime resumed
>> > during system suspend.
>> >
>> > Which can happen with this change if a device with power.is_rpm_sleep is
>> > resumed causing the parent to be resumed too.
>>
>> Doesn't the exact same problem you describe, already exist prior my change!?
>
> No, it doesn't.
>
>> That is, if the current device is runtime suspended and the
>> direct_complete flag is set for it, then __device_suspend() has
>> already disabled runtime PM for the device, when we reach this point.
>> That means, a following attempts to runtime resume the device will
>> fail and thus also to runtime resume its parent.
>
> That's because any devices with direct_complete set *cannot* be runtime
> resumed after __device_suspend().  That's intentional and how the thing
> is designed.  It cannot work differently, sorry.
>
>> So to me, this is a different problem, related how to work out the
>> correct order of how to suspend devices.
>
> The ordering matters here, but it is not the problem.
>
> Setting direct_complete means that PM callbacks for this device won't be
> invoked going forward.  However, if the state of the device was to change
> (like as a result of runtime PM resume), it would be necessary to run those
> callbacks after all, but after __device_suspend() it may be too late for
> that, because the ->suspend callback may have been skipped already.
>
> The only way to address that is to prevent runtime PM resume of the device
> from happening at the point the PM core decides to use direct_complete for it,
> but that requires runtime PM to be disabled for it.  Moreover, since the
> device is now suspended with runtime PM disabled and its children might rely
> on it if they were active, the children must be suspended with runtime PM
> disabled at this point too.  That's why direct_complete can only be set
> for a device if it is set for the entire hierarchy below it.

Thanks, this was a very nice description of the direct_complete path!

>
> Summary: If you allow a device to be runtime resumed during system susped,
> direct_complete cannot be set for it and it cannot be set for its parent and
> so on.

Yes, this is what it seems to boils done to!

Perhaps the ACPI PM domain is special in this case, because in its
->prepare() callback it asks the ACPI FW about whether the
direct_complete path is possible for a device. In other words, the
ACPI FW seems to be capable of providing information about if a device
may become runtime resumed during system suspend. But, really, isn't
that just a best guess? No?

On those ARM SoCs I am working on, non-ACPI, the information about
whether a device may become runtime resumed during system suspend,
most often can't be find out in a deterministic way. That's because
this information depends on how a device is being used by other
devices, which changes dynamically and from one system suspend
sequence to another. In cases like the i2c-designware-plat driver used
in Hikey (ARM64 board), it can't ever know before hand, if someone is
going to request an i2c transfer during system suspend or not.

To really deal with these devices properly, we have to suspend them in
the correct order.

My point is, doesn't the ordering problem exists also for a device,
which the PM core runs the direct_complete path for, even if the ACPI
PM domain is attached to the device? Just because runtime PM is
disabled for a device, doesn't mean the ordering issue disappears,
right?

>
> [cut]
>
>> >> @@ -1709,11 +1711,14 @@ static int device_prepare(struct device *dev, pm_message_t state)
>> >>        * A positive return value from ->prepare() means "this device appears
>> >>        * to be runtime-suspended and its state is fine, so if it really is
>> >>        * runtime-suspended, you can leave it in that state provided that you
>> >> -      * will do the same thing with all of its descendants".  This only
>> >> -      * applies to suspend transitions, however.
>> >> +      * will do the same thing with all of its descendants". To allow this,
>> >> +      * the is_rpm_sleep flag must not be set, which is default false, but
>> >> +      * may have been changed by a driver. This only applies to suspend
>> >> +      * transitions, however.
>> >>        */
>> >>       spin_lock_irq(&dev->power.lock);
>> >> -     dev->power.direct_complete = ret > 0 && state.event == PM_EVENT_SUSPEND;
>> >> +     dev->power.direct_complete = ret > 0 && !dev->power.is_rpm_sleep &&
>> >> +                             state.event == PM_EVENT_SUSPEND;
>> >
>> > The only problem addressed by avoiding direct_complete is when runtime PM needs
>> > to work during __device_suspend() for devices with direct_complete set.  You
>> > said that this was not the case with the i2c designware driver, so I'm not sure
>> > what the purpose of this is.
>>
>> I should probably work more on my changelog, because I tried to
>> explain it there.
>>
>> Anyway, let me quote the important parts, and this is not specific for
>> the i2c-designware-driver, but generic to drivers using
>> pm_runtime_force_suspend|resume().
>>
>> "In the runtime PM centric path, the driver is expected to make use of
>> the pm_runtime_force_suspend|resume() helpers, to deploy system sleep
>> support. More precisely it may assign the system sleep callbacks to
>> these helpers or may call them from its own callbacks, in case it
>> needs to perform additional actions during system sleep.
>>
>> In other words, the PM core must always invoke the system sleep
>> callbacks for the device when they are present, to allow the driver to
>> deal with the system sleep operations."
>>
>> A concrete example is drivers/spi/spi-fsl-espi.c, but one can easily find more.
>
> In fact, the new flag introduced here means "assume that that the driver of this
> device points ->late_suspend and ->early_resume to pm_runtime_force_suspend()
> and pm_runtime_force_resume(), respectively."  Which then implies that
> direct_complete cannot be used with it and (and with its parent and so on)
> and that it is not necessary to runtime resume it during system suspend.
>
> However, there are (or at least there may be) devices that need not be
> runtime resumed during system suspend even though their drivers don't use
> _force_suspend/resume().
>
> Also there are devices whose drivers don't want direct_complete to be used with
> them, even though they don't use _force_suspend/resume() and they *do* need
> their devices to be runtime resumed during system suspend.
>
> Moreover, some drivers may not mind direct_complete even though their devices
> need not be runtime resumed during system suspend.  All of that doesn't have
> to be related to using _force_suspend/resume() at all.
>
> So I don't see any reason whatever for combining all of these three *different*
> conditions under one flag.

Okay!

>
> Thanks,
> Rafael
>

Kind regards
Uffe
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Rafael J. Wysocki Sept. 2, 2017, 2:48 p.m. UTC | #5
On Thursday, August 31, 2017 11:06:05 AM CEST Ulf Hansson wrote:
> [...]
> 
> >> >> diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
> >> >> index ea1732e..865737a 100644
> >> >> --- a/drivers/base/power/main.c
> >> >> +++ b/drivers/base/power/main.c
> >> >> @@ -1549,14 +1549,16 @@ 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->power.is_rpm_sleep)
> >> >> +                             dev->parent->power.direct_complete = false;
> >> >
> >> > This doesn't look good to me at all.
> >> >
> >> > It potentially breaks the fundamental assumption of the direct_complete
> >> > mechanism that no devices with that flag set will ever be runtime resumed
> >> > during system suspend.
> >> >
> >> > Which can happen with this change if a device with power.is_rpm_sleep is
> >> > resumed causing the parent to be resumed too.
> >>
> >> Doesn't the exact same problem you describe, already exist prior my change!?
> >
> > No, it doesn't.
> >
> >> That is, if the current device is runtime suspended and the
> >> direct_complete flag is set for it, then __device_suspend() has
> >> already disabled runtime PM for the device, when we reach this point.
> >> That means, a following attempts to runtime resume the device will
> >> fail and thus also to runtime resume its parent.
> >
> > That's because any devices with direct_complete set *cannot* be runtime
> > resumed after __device_suspend().  That's intentional and how the thing
> > is designed.  It cannot work differently, sorry.
> >
> >> So to me, this is a different problem, related how to work out the
> >> correct order of how to suspend devices.
> >
> > The ordering matters here, but it is not the problem.
> >
> > Setting direct_complete means that PM callbacks for this device won't be
> > invoked going forward.  However, if the state of the device was to change
> > (like as a result of runtime PM resume), it would be necessary to run those
> > callbacks after all, but after __device_suspend() it may be too late for
> > that, because the ->suspend callback may have been skipped already.
> >
> > The only way to address that is to prevent runtime PM resume of the device
> > from happening at the point the PM core decides to use direct_complete for it,
> > but that requires runtime PM to be disabled for it.  Moreover, since the
> > device is now suspended with runtime PM disabled and its children might rely
> > on it if they were active, the children must be suspended with runtime PM
> > disabled at this point too.  That's why direct_complete can only be set
> > for a device if it is set for the entire hierarchy below it.
> 
> Thanks, this was a very nice description of the direct_complete path!
> 
> >
> > Summary: If you allow a device to be runtime resumed during system susped,
> > direct_complete cannot be set for it and it cannot be set for its parent and
> > so on.
> 
> Yes, this is what it seems to boils done to!
> 
> Perhaps the ACPI PM domain is special in this case, because in its
> ->prepare() callback it asks the ACPI FW about whether the
> direct_complete path is possible for a device. In other words, the
> ACPI FW seems to be capable of providing information about if a device
> may become runtime resumed during system suspend. But, really, isn't
> that just a best guess? No?

I wouldn't call it a guess, but it may go too far.

The part that the ACPI PM domain can figure out is whether or not the power
state of the device needs to be updated due to differences between runtime
PM and system suspend configuration requirements.  If it doesn't need to be
updated, acpi_subsys_prepare() returns 1 which may me overoptimistic.

For many devices that works, because the only possible reason why they may
need to be accessed during system suspend is to update their power state.

It may not work for some devices, though, because there may be other reasons
for accessing them during system suspend and that's where some opt-out way
is needed.

> On those ARM SoCs I am working on, non-ACPI, the information about
> whether a device may become runtime resumed during system suspend,
> most often can't be find out in a deterministic way. That's because
> this information depends on how a device is being used by other
> devices, which changes dynamically and from one system suspend
> sequence to another. In cases like the i2c-designware-plat driver used
> in Hikey (ARM64 board), it can't ever know before hand, if someone is
> going to request an i2c transfer during system suspend or not.

Well, I2C is somewhat special in that respect, because dependencies between
devices in there are not tracked AFAICS. 

> To really deal with these devices properly, we have to suspend them in
> the correct order.

Right, but in order to achieve that the right ordering actually needs
to be known.  If it is not known, there is no way to get that right in
general. :-)

The problem basically is that during system suspend you need to disable
the controller at one point, sooner or later, and keep it disabled from
that point on.   Of course, that should happen when it is guaranteed that
there won't be any new transactions going forward, but you cannot actually
guaranee that without knowing that all of its "consumers" have already
been suspended.

> My point is, doesn't the ordering problem exists also for a device,
> which the PM core runs the direct_complete path for, even if the ACPI
> PM domain is attached to the device? Just because runtime PM is
> disabled for a device, doesn't mean the ordering issue disappears,
> right?

The ordering issue is there if there are dependencies between devices the
PM core doesn't know about.  Otherwise, the rule that direct_complete can
only be used for a given device if it also is used for the entire hierarchy
below it (and for all of the device's "consumers" and everything that depends
on them too for that matter) makes it go away (it serves as a guarantee that
all of the device's "consumers" have already been suspended).

Thanks,
Rafael

--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index ea1732e..865737a 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -1549,14 +1549,16 @@  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->power.is_rpm_sleep)
+				dev->parent->power.direct_complete = false;
 			if (dev->power.wakeup_path
 			    && !dev->parent->power.ignore_children)
 				dev->parent->power.wakeup_path = true;
 
 			spin_unlock_irq(&parent->power.lock);
 		}
-		dpm_clear_suppliers_direct_complete(dev);
+		if (!dev->power.is_rpm_sleep)
+			dpm_clear_suppliers_direct_complete(dev);
 	}
 
 	device_unlock(dev);
@@ -1709,11 +1711,14 @@  static int device_prepare(struct device *dev, pm_message_t state)
 	 * A positive return value from ->prepare() means "this device appears
 	 * to be runtime-suspended and its state is fine, so if it really is
 	 * runtime-suspended, you can leave it in that state provided that you
-	 * will do the same thing with all of its descendants".  This only
-	 * applies to suspend transitions, however.
+	 * will do the same thing with all of its descendants". To allow this,
+	 * the is_rpm_sleep flag must not be set, which is default false, but
+	 * may have been changed by a driver. This only applies to suspend
+	 * transitions, however.
 	 */
 	spin_lock_irq(&dev->power.lock);
-	dev->power.direct_complete = ret > 0 && state.event == PM_EVENT_SUSPEND;
+	dev->power.direct_complete = ret > 0 && !dev->power.is_rpm_sleep &&
+				state.event == PM_EVENT_SUSPEND;
 	spin_unlock_irq(&dev->power.lock);
 	return 0;
 }
@@ -1841,6 +1846,40 @@  void dpm_for_each_dev(void *data, void (*fn)(struct device *, void *))
 }
 EXPORT_SYMBOL_GPL(dpm_for_each_dev);
 
+/**
+ * dev_pm_use_rpm_sleep - use the runtime PM centric sleep path.
+ * @dev: the device to use the path for.
+ *
+ * The runtime PM centric path requires the system sleep callbacks for the
+ * driver of the device to be invoked. This function sets the is_rpm_sleep flag
+ * to enable this path to be used, which makes the PM core to adopt to this
+ * behaviour. More precisely the PM core makes sure to not run the
+ * direct_complete path for the chosen device during system sleep, when the
+ * is_rpm_sleep flag is set. A driver using the runtime PM centric path, shall
+ * use the pm_runtime_force_suspend|resume() helpers, to deploy system sleep
+ * support and call this function during ->probe().
+ * The is_rpm_sleep flag is cleared when unbinding/bind-failure of the driver.
+ */
+void dev_pm_use_rpm_sleep(struct device *dev)
+{
+	dev->power.is_rpm_sleep = true;
+}
+EXPORT_SYMBOL_GPL(dev_pm_use_rpm_sleep);
+
+/**
+ * dev_pm_is_rpm_sleep - Returns the value of the is_rpm_sleep flag.
+ * @dev: the device to return the flag for.
+ *
+ * The caller of this function is typically a subsystem or a PM domain that
+ * needs to know if the runtime PM centric path is used for the device. It may
+ * be invoked during any of the system sleep phases.
+ */
+bool dev_pm_is_rpm_sleep(struct device *dev)
+{
+	return dev->power.is_rpm_sleep;
+}
+EXPORT_SYMBOL_GPL(dev_pm_is_rpm_sleep);
+
 static bool pm_ops_is_empty(const struct dev_pm_ops *ops)
 {
 	if (!ops)
diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
index 7bcf80f..b2ab22c 100644
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -1522,6 +1522,7 @@  void pm_runtime_reinit(struct device *dev)
 				pm_runtime_put(dev->parent);
 		}
 	}
+	dev->power.is_rpm_sleep = false;
 }
 
 /**
diff --git a/include/linux/pm.h b/include/linux/pm.h
index 47ded8a..5bf96d2 100644
--- a/include/linux/pm.h
+++ b/include/linux/pm.h
@@ -559,6 +559,7 @@  struct dev_pm_info {
 	bool			is_suspended:1;	/* Ditto */
 	bool			is_noirq_suspended:1;
 	bool			is_late_suspended:1;
+	bool			is_rpm_sleep:1;	/* Owned by the PM core */
 	bool			early_init:1;	/* Owned by the PM core */
 	bool			direct_complete:1;	/* Owned by the PM core */
 	spinlock_t		lock;
@@ -716,6 +717,9 @@  extern void __suspend_report_result(const char *function, void *fn, int ret);
 extern int device_pm_wait_for_dev(struct device *sub, struct device *dev);
 extern void dpm_for_each_dev(void *data, void (*fn)(struct device *, void *));
 
+extern void dev_pm_use_rpm_sleep(struct device *dev);
+extern bool dev_pm_is_rpm_sleep(struct device *dev);
+
 extern int pm_generic_prepare(struct device *dev);
 extern int pm_generic_suspend_late(struct device *dev);
 extern int pm_generic_suspend_noirq(struct device *dev);
@@ -759,6 +763,9 @@  static inline void dpm_for_each_dev(void *data, void (*fn)(struct device *, void
 {
 }
 
+static inline void dev_pm_use_rpm_sleep(struct device *dev) {}
+static inline bool dev_pm_is_rpm_sleep(struct device *dev) { return false; }
+
 #define pm_generic_prepare		NULL
 #define pm_generic_suspend_late		NULL
 #define pm_generic_suspend_noirq	NULL