Re: [RFC v2 4/5] ACPI, PM, Specify lowest allowed state for devicesleep state
From: huang ying
Date: Sat May 05 2012 - 03:25:45 EST
On Sat, May 5, 2012 at 4:10 AM, Rafael J. Wysocki <rjw@xxxxxxx> wrote:
> On Friday, May 04, 2012, Huang Ying wrote:
>> Lower device sleep state can save more power, but has more exit
>> latency too. ÂSometimes, to satisfy some power QoS and other
>> requirement, we need to constrain the lowest device sleep state.
>>
>> In this patch, a parameter to specify lowest allowed state for
>> acpi_pm_device_sleep_state is added. ÂSo that the caller can enforce
>> the constraint via the parameter.
>>
>> Signed-off-by: Huang Ying <ying.huang@xxxxxxxxx>
>> ---
>> Âdrivers/acpi/sleep.c    |  18 +++++++++++++++---
>> Âdrivers/pci/pci-acpi.c   |  Â3 ++-
>> Âdrivers/pnp/pnpacpi/core.c | Â Â4 ++--
>> Âinclude/acpi/acpi_bus.h  Â|  Â6 +++---
>> Â4 files changed, 22 insertions(+), 9 deletions(-)
>>
>> --- a/drivers/acpi/sleep.c
>> +++ b/drivers/acpi/sleep.c
>> @@ -677,6 +677,7 @@ int acpi_suspend(u32 acpi_state)
>> Â * Â @dev: device to examine; its driver model wakeup flags control
>> Â * Â Â Â Â Â whether it should be able to wake up the system
>> Â * Â @d_min_p: used to store the upper limit of allowed states range
>> + * Â @d_max_in: specify the lowest allowed states
>> Â * Â Return value: preferred power state of the device on success, -ENODEV on
>> Â * Â Â Â Â Â failure (ie. if there's no 'struct acpi_device' for @dev)
>> Â *
>> @@ -693,7 +694,7 @@ int acpi_suspend(u32 acpi_state)
>> Â * Â via @wake.
>> Â */
>>
>> -int acpi_pm_device_sleep_state(struct device *dev, int *d_min_p)
>> +int acpi_pm_device_sleep_state(struct device *dev, int *d_min_p, int d_max_in)
>> Â{
>> Â Â Â acpi_handle handle = DEVICE_ACPI_HANDLE(dev);
>> Â Â Â struct acpi_device *adev;
>> @@ -704,11 +705,14 @@ int acpi_pm_device_sleep_state(struct de
>> Â Â Â Â Â Â Â printk(KERN_DEBUG "ACPI handle has no context!\n");
>> Â Â Â Â Â Â Â return -ENODEV;
>> Â Â Â }
>> + Â Â d_max_in = clamp_t(int, d_max_in, ACPI_STATE_D0, ACPI_STATE_D3);
>
> Shouldn't that be clamp_val(), rather?
Yes. clamp_val() is sufficient here.
>> Â Â Â acpi_method[2] = '0' + acpi_target_sleep_state;
>> Â Â Â /*
>> - Â Â Â* If the sleep state is S0, we will return D3, but if the device has
>> - Â Â Â* _S0W, we will use the value from _S0W
>> + Â Â Â* If the sleep state is S0, the lowest limit from ACPI is D3,
>> + Â Â Â* but if the device has _S0W, we will use the value from _S0W
>> + Â Â Â* as the lowest limit from ACPI. ÂFinally, we will constrain
>> + Â Â Â* the lowest limit with the specified one.
>> Â Â Â Â*/
>> Â Â Â d_min = ACPI_STATE_D0;
>> Â Â Â d_max = ACPI_STATE_D3;
>> @@ -754,6 +758,14 @@ int acpi_pm_device_sleep_state(struct de
>>
>> Â Â Â if (d_min_p)
>> Â Â Â Â Â Â Â *d_min_p = d_min;
>> + Â Â /* constrain d_max with specified lowest limit (max number) */
>> + Â Â if (d_max > d_max_in) {
>> + Â Â Â Â Â Â d_max = d_max_in;
>> + Â Â Â Â Â Â for (;d_max > d_min; d_max--) {
>
> Well, why didn't you do
>
> + Â Â Â Â Â Â Â for (d_max = d_max_in; d_max > d_min; d_max--)
Because I think it is possible that d_max < d_max_in.
>> + Â Â Â Â Â Â Â Â Â Â if (adev->power.states[d_max].flags.valid)
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â break;
>> + Â Â Â Â Â Â }
>> + Â Â }
>
> And what if d_min > d_max_in ?
I think that means something bad happens. Maybe we can do something as follow
if (d_min > d_max_in) {
pr_warning("acpi_pm_device_sleep_state: the specified lowest
state is higher than the highest state from ACPI!");
d_max_in = d_min;
}
if (d_max > d_max_in) {
...
}
>> Â Â Â return d_max;
>> Â}
>> Â#endif /* CONFIG_PM */
>> --- a/drivers/pci/pci-acpi.c
>> +++ b/drivers/pci/pci-acpi.c
>> @@ -189,7 +189,8 @@ static pci_power_t acpi_pci_choose_state
>> Â{
>> Â Â Â int acpi_state;
>>
>> - Â Â acpi_state = acpi_pm_device_sleep_state(&pdev->dev, NULL);
>> + Â Â acpi_state = acpi_pm_device_sleep_state(&pdev->dev, NULL,
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ACPI_STATE_D3);
>> Â Â Â if (acpi_state < 0)
>> Â Â Â Â Â Â Â return PCI_POWER_ERROR;
>>
>> --- a/drivers/pnp/pnpacpi/core.c
>> +++ b/drivers/pnp/pnpacpi/core.c
>> @@ -170,8 +170,8 @@ static int pnpacpi_suspend(struct pnp_de
>> Â Â Â }
>>
>> Â Â Â if (acpi_bus_power_manageable(handle)) {
>> - Â Â Â Â Â Â int power_state = acpi_pm_device_sleep_state(&dev->dev, NULL);
>> -
>> + Â Â Â Â Â Â int power_state = acpi_pm_device_sleep_state(&dev->dev, NULL,
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ÂACPI_STATE_D3);
>> Â Â Â Â Â Â Â if (power_state < 0)
>> Â Â Â Â Â Â Â Â Â Â Â power_state = (state.event == PM_EVENT_ON) ?
>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ACPI_STATE_D0 : ACPI_STATE_D3;
>> --- a/include/acpi/acpi_bus.h
>> +++ b/include/acpi/acpi_bus.h
>> @@ -383,13 +383,13 @@ int acpi_enable_wakeup_device_power(stru
>> Âint acpi_disable_wakeup_device_power(struct acpi_device *dev);
>>
>> Â#ifdef CONFIG_PM
>> -int acpi_pm_device_sleep_state(struct device *, int *);
>> +int acpi_pm_device_sleep_state(struct device *, int *, int);
>> Â#else
>> -static inline int acpi_pm_device_sleep_state(struct device *d, int *p)
>> +static inline int acpi_pm_device_sleep_state(struct device *d, int *p, int m)
>> Â{
>> Â Â Â if (p)
>> Â Â Â Â Â Â Â *p = ACPI_STATE_D0;
>> - Â Â return ACPI_STATE_D3;
>> + Â Â return m == ACPI_STATE_D3 ? m : ACPI_STATE_D0;
>
> Shouldn't m be returned (so long as it is between D0 and D3 inclusive)? ÂIOW:
>
> + Â Â Â return (m >= ACPI_STATE_D0 && m <= ACPI_STATE_D3) ? m : ACPI_STATE_D0;
My original idea is that only D0 and D3 is guaranteed to be valid for
the device. If that need not to be considered here, you one is
better.
Best Regards,
Huang Ying
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/