Skip to contentSkip to conversation

Automatic suspend

RFD Rafael J. Wysocki 21 participants 379 messages Feb 15, 2009 – Mar 5, 2009 Page 1 of 2

lore
Share & tools
lore
#0 lore raw

Hi,

The recent descussion about the Android PM patches sent by Arve shows that there is a need to introduce a mechanism allowing us to:
(1) automatically put the system as a whole into a sleep state (eg. suspend to RAM) when it is found to be "idle", where the meaning of "idle" has to be defined too,
(2) put given subset of devices into low power states whenever they are not used, without putting the entire system into a sleep state.
To allow these two things to happen, the Andriod patches introduced the wakelocks with the associated infrastructure and the "early suspend" mechanism. However, quite a number of reviewers did not like these patches, for various reasons, so they cannot be regarded as generally acceptable. For this reason, I think, we should discuss the problem in detail from the beginning and try to find a solution that everyone interested will be comfortable with.

For this purpose, IMO, we should at least reach an agreement on what the kernel's and the userland's roles in (1) and (2) are going to be. There also are quite a few questions that need to be answered. For instance, what conditions are going to be used to decide whether or not the system is idle enough so that we can put it into a sleep state? How are we going to check these conditions? What is going to happen if one (or more) of them changes while a system-wide power transition (eg. suspend) is in progress? Are we going to allow the user space to take part in this and if so, to what extent? What mechanisms are going be used to put devices into low power states at run time (ie. before starting any system-wide power transition) and how are they going to be related to the suspend-resume infrastructure used during system-wide power transitions? The answers to these (and other related) questions will likely affect all of the future Linux PM developlent, so IMO this is a very important matter.

Opinions and comments welcome.

Thanks,
Rafael

#1 lore raw
Quoted 9 lines · On Mon, 16 Feb 2009 00:10:15 +0100 "Rafael J. Wysocki" <[email protected]> wrote:

Hi,

The recent descussion about the Android PM patches sent by Arve shows that there is a need to introduce a mechanism allowing us to:
(1) automatically put the system as a whole into a sleep state (eg. suspend to RAM) when it is found to be "idle", where the meaning of "idle" has to be defined too,
(2) put given subset of devices into low power states whenever they are not used, without putting the entire system into a sleep state.

For (2), for me the answer is very obvious:

The Device Driver needs to make the decision to put the device to sleep. There are no ifs and buts about this.

It's the driver who
a) knows if there's any activity, such as open users and
b) is in the right position to know how to put things to sleep.

Of course, the subsystem the driver belongs to can provide helpers (such as generic activity timeout handlers etc).

For many cases, the drivers do this today already.
There are cases where doing this has side effects, mostly in terms of latency. It is reasonable to have a general mechanism that provides a central mechanism to track tolerable latencies; in fact PMQOS provides this on a high level, and I can imagine that PMQOS needs to be extended to provide a wider range of type of latencies.

Userland should never ever control the state of a device like this directly. It should do so by a) closing the device and b) setting latency / functional requirements.

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#2 lore raw
In reply to Rafael J. Wysocki
Quoted 9 lines · On Mon, 16 Feb 2009 00:10:15 +0100 "Rafael J. Wysocki" <[email protected]> wrote:

Hi,

The recent descussion about the Android PM patches sent by Arve shows that there is a need to introduce a mechanism allowing us to:
(1) automatically put the system as a whole into a sleep state (eg. suspend to RAM) when it is found to be "idle", where the meaning of "idle" has to be defined too,
(2) put given subset of devices into low power states whenever they are not used, without putting the entire system into a sleep state.

For (2), for me the answer is very obvious:

The Device Driver needs to make the decision to put the device to sleep. There are no ifs and buts about this.

It's the driver who
a) knows if there's any activity, such as open users and
b) is in the right position to know how to put things to sleep.

Of course, the subsystem the driver belongs to can provide helpers (such as generic activity timeout handlers etc).

For many cases, the drivers do this today already.
There are cases where doing this has side effects, mostly in terms of latency. It is reasonable to have a general mechanism that provides a central mechanism to track tolerable latencies; in fact PMQOS provides this on a high level, and I can imagine that PMQOS needs to be extended to provide a wider range of type of latencies.

Userland should never ever control the state of a device like this directly. It should do so by a) closing the device and b) setting latency / functional requirements.

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#3 lore raw
Quoted 14 lines · Arjan van de Ven
Quoted 9 lines · On Mon, 16 Feb 2009 00:10:15 +0100 "Rafael J. Wysocki" <[email protected]> wrote:

Hi,

The recent descussion about the Android PM patches sent by Arve shows that there is a need to introduce a mechanism allowing us to:
(1) automatically put the system as a whole into a sleep state (eg. suspend to RAM) when it is found to be "idle", where the meaning of "idle" has to be defined too,
(2) put given subset of devices into low power states whenever they are not used, without putting the entire system into a sleep state.

Quoted 1 line

For (2), for me the answer is very obvious:

.../...

I agree with pretty much everything Arjan wrote here.

Quoted 3 lines

Userland should never ever control the state of a device like this directly. It should do so by a) closing the device and b) setting latency / functional requirements

With the possible exception of things like wifi/bt killswitch or network or similar where the driver cannot shut the device down without losing the ability to detect activity (ie, switch your PHY off is nice but you lose the ability to monitor the link for example).

Cheers,
Ben.

#4 lore raw
In reply to Arjan van de Ven
Quoted 14 lines · Arjan van de Ven
Quoted 9 lines · On Mon, 16 Feb 2009 00:10:15 +0100 "Rafael J. Wysocki" <[email protected]> wrote:

Hi,

The recent descussion about the Android PM patches sent by Arve shows that there is a need to introduce a mechanism allowing us to:
(1) automatically put the system as a whole into a sleep state (eg. suspend to RAM) when it is found to be "idle", where the meaning of "idle" has to be defined too,
(2) put given subset of devices into low power states whenever they are not used, without putting the entire system into a sleep state.

Quoted 1 line

For (2), for me the answer is very obvious:

.../...

I agree with pretty much everything Arjan wrote here.

Quoted 3 lines

Userland should never ever control the state of a device like this directly. It should do so by a) closing the device and b) setting latency / functional requirements

With the possible exception of things like wifi/bt killswitch or network or similar where the driver cannot shut the device down without losing the ability to detect activity (ie, switch your PHY off is nice but you lose the ability to monitor the link for example).

Cheers,
Ben.

#5 lore raw
Quoted 20 lines · On Mon, 16 Feb 2009 13:12:40 +1100 Benjamin Herrenschmidt…
Quoted 15 lines · Arjan van de Ven
Quoted 10 lines · On Mon, 16 Feb 2009 00:10:15 +0100 "Rafael J. Wysocki" <[email protected]> wrote:

Hi,

The recent descussion about the Android PM patches sent by Arve shows that there is a need to introduce a mechanism allowing us
to: (1) automatically put the system as a whole into a sleep state (eg. suspend to RAM) when it is found to be "idle", where the meaning of "idle" has to be defined too,
(2) put given subset of devices into low power states whenever they are not used, without putting the entire system into a sleep state.

Quoted 1 line

For (2), for me the answer is very obvious:

.../...

Quoted 7 lines

I agree with pretty much everything Arjan wrote here.

Quoted 3 lines

Userland should never ever control the state of a device like this directly. It should do so by a) closing the device and b) setting latency / functional requirements

With the possible exception of things like wifi/bt killswitch

this is a functional switch; but yeah it is a little bit of an odd-one out. rfkill is also not REALLY for power, it's more for FAA stuff.

Quoted 4 lines

or
network or similar where the driver cannot shut the device down without losing the ability to detect activity (ie, switch your PHY off is nice but you lose the ability to monitor the link for example).

what this needs is a separation between "interface down, all off" and "interface down enough so that link detection works".
Some NICs can go all the way down and still do link detection, others cannot. This is obviously something the driver will know, nothing else in the system should know.

Quoted 4 lines

Cheers,
Ben.

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#6 lore raw
In reply to Benjamin Herrenschmidt
Quoted 20 lines · On Mon, 16 Feb 2009 13:12:40 +1100 Benjamin Herrenschmidt…
Quoted 15 lines · Arjan van de Ven
Quoted 10 lines · On Mon, 16 Feb 2009 00:10:15 +0100 "Rafael J. Wysocki" <[email protected]> wrote:

Hi,

The recent descussion about the Android PM patches sent by Arve shows that there is a need to introduce a mechanism allowing us
to: (1) automatically put the system as a whole into a sleep state (eg. suspend to RAM) when it is found to be "idle", where the meaning of "idle" has to be defined too,
(2) put given subset of devices into low power states whenever they are not used, without putting the entire system into a sleep state.

Quoted 1 line

For (2), for me the answer is very obvious:

.../...

Quoted 7 lines

I agree with pretty much everything Arjan wrote here.

Quoted 3 lines

Userland should never ever control the state of a device like this directly. It should do so by a) closing the device and b) setting latency / functional requirements

With the possible exception of things like wifi/bt killswitch

this is a functional switch; but yeah it is a little bit of an odd-one out. rfkill is also not REALLY for power, it's more for FAA stuff.

Quoted 4 lines

or
network or similar where the driver cannot shut the device down without losing the ability to detect activity (ie, switch your PHY off is nice but you lose the ability to monitor the link for example).

what this needs is a separation between "interface down, all off" and "interface down enough so that link detection works".
Some NICs can go all the way down and still do link detection, others cannot. This is obviously something the driver will know, nothing else in the system should know.

Quoted 4 lines

Cheers,
Ben.

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#7 lore raw
Quoted 5 lines · Arjan van de Ven

what this needs is a separation between "interface down, all off" and "interface down enough so that link detection works".
Some NICs can go all the way down and still do link detection, others cannot. This is obviously something the driver will know, nothing else in the system should know.

Sure, my point was just that the driver cannot make the decision to go all-off (and thus not detect link) without some kind of user setting allowing it to do so.

Cheers,
Ben.

#8 lore raw
In reply to Arjan van de Ven
Quoted 5 lines · Arjan van de Ven

what this needs is a separation between "interface down, all off" and "interface down enough so that link detection works".
Some NICs can go all the way down and still do link detection, others cannot. This is obviously something the driver will know, nothing else in the system should know.

Sure, my point was just that the driver cannot make the decision to go all-off (and thus not detect link) without some kind of user setting allowing it to do so.

Cheers,
Ben.

#9 lore raw
Quoted 10 lines · On Mon, 16 Feb 2009 14:23:41 +1100 Benjamin Herrenschmidt…
Quoted 5 lines · Arjan van de Ven

what this needs is a separation between "interface down, all off" and "interface down enough so that link detection works". Some NICs can go all the way down and still do link detection, others cannot. This is obviously something the driver will know, nothing else in the system should know.

Sure, my point was just that the driver cannot make the decision to go all-off (and thus not detect link) without some kind of user setting allowing it to do so.

to a very large degree, "want linkdetection" is a form of keeping the device open.. even if the current code doesn't quite work that way (maybe it should)

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#10 lore raw
In reply to Benjamin Herrenschmidt
Quoted 10 lines · On Mon, 16 Feb 2009 14:23:41 +1100 Benjamin Herrenschmidt…
Quoted 5 lines · Arjan van de Ven

what this needs is a separation between "interface down, all off" and "interface down enough so that link detection works". Some NICs can go all the way down and still do link detection, others cannot. This is obviously something the driver will know, nothing else in the system should know.

Sure, my point was just that the driver cannot make the decision to go all-off (and thus not detect link) without some kind of user setting allowing it to do so.

to a very large degree, "want linkdetection" is a form of keeping the device open.. even if the current code doesn't quite work that way (maybe it should)

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#291 lore raw
In reply to Arjan van de Ven
Quoted 7 lines
Quoted 2 lines

(2) put given subset of devices into low power states whenever they are not used, without putting the entire system into a sleep state.

For (2), for me the answer is very obvious:

The Device Driver needs to make the decision to put the device to sleep. There are no ifs and buts about this.

For PC-like systems this is probably all that needs to be said. However for highly integrated SoC systems (as Android is obviously targeting) there is another level of complexity due to the interdependency among various devices... eg things like if I know the SD controller and the wifi chip are both asleep then I can put my SDIO controller to sleep; and if the SDIO controller and the NAND controller are both asleep then I can stop clock X and save more power; etc etc.

This is what the PowerOp/DPM work was all about. Unfortunately that doesn't seem to have made much progress upstream. But there's no doubt in my mind that we need some framework beyond individual drivers that manages the system's power as a whole. And the current device tree is probably not sufficient -- eg the bus hierarchy of a device may not match up with the clock tree at all.

- R.

#292 lore raw
In reply to Arjan van de Ven
Quoted 7 lines
Quoted 2 lines

(2) put given subset of devices into low power states whenever they are not used, without putting the entire system into a sleep state.

For (2), for me the answer is very obvious:

The Device Driver needs to make the decision to put the device to sleep. There are no ifs and buts about this.

For PC-like systems this is probably all that needs to be said. However for highly integrated SoC systems (as Android is obviously targeting) there is another level of complexity due to the interdependency among various devices... eg things like if I know the SD controller and the wifi chip are both asleep then I can put my SDIO controller to sleep; and if the SDIO controller and the NAND controller are both asleep then I can stop clock X and save more power; etc etc.

This is what the PowerOp/DPM work was all about. Unfortunately that doesn't seem to have made much progress upstream. But there's no doubt in my mind that we need some framework beyond individual drivers that manages the system's power as a whole. And the current device tree is probably not sufficient -- eg the bus hierarchy of a device may not match up with the clock tree at all.

- R.

#297 lore raw
In reply to Arjan van de Ven

Am Monday 16 February 2009 01:44:56 schrieb Arjan van de Ven:

Quoted 16 lines
Quoted 9 lines · On Mon, 16 Feb 2009 00:10:15 +0100 "Rafael J. Wysocki" <[email protected]> wrote:

Hi,

The recent descussion about the Android PM patches sent by Arve shows that there is a need to introduce a mechanism allowing us to:
(1) automatically put the system as a whole into a sleep state (eg. suspend to RAM) when it is found to be "idle", where the meaning of "idle" has to be defined too,
(2) put given subset of devices into low power states whenever they are not used, without putting the entire system into a sleep state.

For (2), for me the answer is very obvious:

Quoted 7 lines

The Device Driver needs to make the decision to put the device to sleep. There are no ifs and buts about this.

It's the driver who
a) knows if there's any activity, such as open users and
b) is in the right position to know how to put things to sleep.

I think you need third option between decides to put to sleep and refuses to put to sleep. It is probably necessary to let drivers state that they would want to go along if the whole system goes to sleep.

Quoted 6 lines

Of course, the subsystem the driver belongs to can provide helpers (such as generic activity timeout handlers etc).

For many cases, the drivers do this today already.
There are cases where doing this has side effects, mostly in terms of latency. It is reasonable to have a general mechanism that provides a

Exactly.

Regards
Oliver

#298 lore raw
In reply to Arjan van de Ven

Am Monday 16 February 2009 01:44:56 schrieb Arjan van de Ven:

Quoted 16 lines
Quoted 9 lines · On Mon, 16 Feb 2009 00:10:15 +0100 "Rafael J. Wysocki" <[email protected]> wrote:

Hi,

The recent descussion about the Android PM patches sent by Arve shows that there is a need to introduce a mechanism allowing us to:
(1) automatically put the system as a whole into a sleep state (eg. suspend to RAM) when it is found to be "idle", where the meaning of "idle" has to be defined too,
(2) put given subset of devices into low power states whenever they are not used, without putting the entire system into a sleep state.

For (2), for me the answer is very obvious:

Quoted 7 lines

The Device Driver needs to make the decision to put the device to sleep. There are no ifs and buts about this.

It's the driver who
a) knows if there's any activity, such as open users and
b) is in the right position to know how to put things to sleep.

I think you need third option between decides to put to sleep and refuses to put to sleep. It is probably necessary to let drivers state that they would want to go along if the whole system goes to sleep.

Quoted 6 lines

Of course, the subsystem the driver belongs to can provide helpers (such as generic activity timeout handlers etc).

For many cases, the drivers do this today already.
There are cases where doing this has side effects, mostly in terms of latency. It is reasonable to have a general mechanism that provides a

Exactly.

Regards
Oliver

#13 lore raw
In reply to Arjan van de Ven

Am Monday 16 February 2009 03:20:12 schrieb Arjan van de Ven:

Quoted 10 lines
Quoted 4 lines

or
network or similar where the driver cannot shut the device down without losing the ability to detect activity (ie, switch your PHY off is nice but you lose the ability to monitor the link for example).

what this needs is a separation between "interface down, all off" and "interface down enough so that link detection works".
Some NICs can go all the way down and still do link detection, others cannot. This is obviously something the driver will know, nothing else in the system should know.

Why shouldn't user space know the consequences of still requesting a service and be able to decide on that basis which services to request?

Regards
Oliver

#290 lore raw
In reply to Arjan van de Ven

Am Monday 16 February 2009 03:20:12 schrieb Arjan van de Ven:

Quoted 10 lines
Quoted 4 lines

or
network or similar where the driver cannot shut the device down without losing the ability to detect activity (ie, switch your PHY off is nice but you lose the ability to monitor the link for example).

what this needs is a separation between "interface down, all off" and "interface down enough so that link detection works".
Some NICs can go all the way down and still do link detection, others cannot. This is obviously something the driver will know, nothing else in the system should know.

Why shouldn't user space know the consequences of still requesting a service and be able to decide on that basis which services to request?

Regards
Oliver

#293 lore raw
In reply to Roland Dreier
Quoted 9 lines · On Sun, 15 Feb 2009 22:23:04 -0800 Roland Dreier <[email protected]> wrote:
Quoted 8 lines
Quoted 3 lines

(2) put given subset of devices into low power states whenever they are not used, without putting the entire system into a sleep state.

For (2), for me the answer is very obvious:

The Device Driver needs to make the decision to put the device to sleep. There are no ifs and buts about this.

Quoted 8 lines

For PC-like systems this is probably all that needs to be said. However for highly integrated SoC systems (as Android is obviously targeting) there is another level of complexity due to the interdependency among various devices... eg things like if I know the SD controller and the wifi chip are both asleep then I can put my SDIO controller to sleep; and if the SDIO controller and the NAND controller are both asleep then I can stop clock X and save more power; etc etc.

This does not change the rules.
The individual drivers still make up the decision of what state their own block should be in.

What you're talking about is coordination. Some systems do this in silicon, and others, like you mention, need a small software layer to do this coordination. Fine. But this doesn't change the fundamentals.

Quoted 3 lines

This is what the PowerOp/DPM work was all about. Unfortunately that doesn't seem to have made much progress upstream.

PowerOP/DPM were... more or less hampered because they operated in global "modes". Everyone (including the OMAP guys) has pretty much gone away from the idea that modes are global. Power management is not global; if you treat it as global then you're in trouble, since the decisions really are local (and in better hw, even done in the hw)

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#294 lore raw
In reply to Roland Dreier
Quoted 9 lines · On Sun, 15 Feb 2009 22:23:04 -0800 Roland Dreier <[email protected]> wrote:
Quoted 8 lines
Quoted 3 lines

(2) put given subset of devices into low power states whenever they are not used, without putting the entire system into a sleep state.

For (2), for me the answer is very obvious:

The Device Driver needs to make the decision to put the device to sleep. There are no ifs and buts about this.

Quoted 8 lines

For PC-like systems this is probably all that needs to be said. However for highly integrated SoC systems (as Android is obviously targeting) there is another level of complexity due to the interdependency among various devices... eg things like if I know the SD controller and the wifi chip are both asleep then I can put my SDIO controller to sleep; and if the SDIO controller and the NAND controller are both asleep then I can stop clock X and save more power; etc etc.

This does not change the rules.
The individual drivers still make up the decision of what state their own block should be in.

What you're talking about is coordination. Some systems do this in silicon, and others, like you mention, need a small software layer to do this coordination. Fine. But this doesn't change the fundamentals.

Quoted 3 lines

This is what the PowerOp/DPM work was all about. Unfortunately that doesn't seem to have made much progress upstream.

PowerOP/DPM were... more or less hampered because they operated in global "modes". Everyone (including the OMAP guys) has pretty much gone away from the idea that modes are global. Power management is not global; if you treat it as global then you're in trouble, since the decisions really are local (and in better hw, even done in the hw)

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#14 lore raw
In reply to Oliver Neukum
Quoted 13 lines · On Mon, 16 Feb 2009 08:06:13 +0100 Oliver Neukum <[email protected]> wrote:

Am Monday 16 February 2009 03:20:12 schrieb Arjan van de Ven:

Quoted 11 lines
Quoted 5 lines

or
network or similar where the driver cannot shut the device down without losing the ability to detect activity (ie, switch your PHY off is nice but you lose the ability to monitor the link for example).

what this needs is a separation between "interface down, all off" and "interface down enough so that link detection works". Some NICs can go all the way down and still do link detection, others cannot. This is obviously something the driver will know, nothing else in the system should know.

Quoted 3 lines

Why shouldn't user space know the consequences of still requesting a service and be able to decide on that basis which services to request?

That's not what I said. Userspace should not be the part that goes "oh this is a realtek not an intel nic, so ..."
That is the drivers job.

Userspace should just be the part that says "I'm interested in link notifications". The driver then just goes to the lowest power state for its device that still gives those notifications.

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#15 lore raw
In reply to Oliver Neukum
Quoted 13 lines · On Mon, 16 Feb 2009 08:06:13 +0100 Oliver Neukum <[email protected]> wrote:

Am Monday 16 February 2009 03:20:12 schrieb Arjan van de Ven:

Quoted 11 lines
Quoted 5 lines

or
network or similar where the driver cannot shut the device down without losing the ability to detect activity (ie, switch your PHY off is nice but you lose the ability to monitor the link for example).

what this needs is a separation between "interface down, all off" and "interface down enough so that link detection works". Some NICs can go all the way down and still do link detection, others cannot. This is obviously something the driver will know, nothing else in the system should know.

Quoted 3 lines

Why shouldn't user space know the consequences of still requesting a service and be able to decide on that basis which services to request?

That's not what I said. Userspace should not be the part that goes "oh this is a realtek not an intel nic, so ..."
That is the drivers job.

Userspace should just be the part that says "I'm interested in link notifications". The driver then just goes to the lowest power state for its device that still gives those notifications.

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#16 lore raw

Am Monday 16 February 2009 16:40:48 schrieb Arjan van de Ven:

Quoted 7 lines
Quoted 3 lines

Why shouldn't user space know the consequences of still requesting a service and be able to decide on that basis which services to request?

That's not what I said. Userspace should not be the part that goes "oh this is a realtek not an intel nic, so ..."
That is the drivers job.

True.

Quoted 3 lines

Userspace should just be the part that says "I'm interested in link notifications". The driver then just goes to the lowest power state for its device that still gives those notifications.

Should there be a channel through which drivers can tell user space what the consequences in terms of reaching a sleep state are if a service is requested?

Regards
Oliver

#289 lore raw
In reply to Arjan van de Ven

Am Monday 16 February 2009 16:40:48 schrieb Arjan van de Ven:

Quoted 7 lines
Quoted 3 lines

Why shouldn't user space know the consequences of still requesting a service and be able to decide on that basis which services to request?

That's not what I said. Userspace should not be the part that goes "oh this is a realtek not an intel nic, so ..."
That is the drivers job.

True.

Quoted 3 lines

Userspace should just be the part that says "I'm interested in link notifications". The driver then just goes to the lowest power state for its device that still gives those notifications.

Should there be a channel through which drivers can tell user space what the consequences in terms of reaching a sleep state are if a service is requested?

Regards
Oliver

#17 lore raw
In reply to Oliver Neukum
Quoted 7 lines · On Mon, 16 Feb 2009 17:48:06 +0100 Oliver Neukum <[email protected]> wrote:
Quoted 3 lines

Userspace should just be the part that says "I'm interested in link notifications". The driver then just goes to the lowest power state for its device that still gives those notifications.

Should there be a channel through which drivers can tell user space what the consequences in terms of reaching a sleep state are if a service is requested?

Personally, I don't think so.
Think about it: what would userspace do?
Not ask for the functionality if it means no sleep state? Maybe it should just never ask for it then as a required functionality!

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#18 lore raw
In reply to Oliver Neukum
Quoted 7 lines · On Mon, 16 Feb 2009 17:48:06 +0100 Oliver Neukum <[email protected]> wrote:
Quoted 3 lines

Userspace should just be the part that says "I'm interested in link notifications". The driver then just goes to the lowest power state for its device that still gives those notifications.

Should there be a channel through which drivers can tell user space what the consequences in terms of reaching a sleep state are if a service is requested?

Personally, I don't think so.
Think about it: what would userspace do?
Not ask for the functionality if it means no sleep state? Maybe it should just never ask for it then as a required functionality!

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#19 lore raw
Quoted 9 lines · Arjan van de Ven
Quoted 3 lines · On Mon, 16 Feb 2009 17:48:06 +0100 Oliver Neukum <[email protected]> wrote:

Should there be a channel through which drivers can tell user space what the consequences in terms of reaching a sleep state are if a service is requested?

Personally, I don't think so.
Think about it: what would userspace do?
Not ask for the functionality if it means no sleep state? Maybe it should just never ask for it then as a required functionality!

Userspace may not have a useful decision-making capability regarding functionality versus power-saving, but the user it's talking to might!

I think it would be very useful to have a mechanism for userspace to find out "Link detection on this NIC costs ~50mW" and "No link has been detected for the last 15 minutes", so that it can compile all that sort of information and prompt the user what devices they would like to disable. Perhaps an "airline mode" sort of thing?

Cheers,
Kyle Moffett

#20 lore raw
In reply to Arjan van de Ven
Quoted 9 lines · Arjan van de Ven
Quoted 3 lines · On Mon, 16 Feb 2009 17:48:06 +0100 Oliver Neukum <[email protected]> wrote:

Should there be a channel through which drivers can tell user space what the consequences in terms of reaching a sleep state are if a service is requested?

Personally, I don't think so.
Think about it: what would userspace do?
Not ask for the functionality if it means no sleep state? Maybe it should just never ask for it then as a required functionality!

Userspace may not have a useful decision-making capability regarding functionality versus power-saving, but the user it's talking to might!

I think it would be very useful to have a mechanism for userspace to find out "Link detection on this NIC costs ~50mW" and "No link has been detected for the last 15 minutes", so that it can compile all that sort of information and prompt the user what devices they would like to disable. Perhaps an "airline mode" sort of thing?

Cheers,
Kyle Moffett

#21 lore raw
Quoted 5 lines · On Mon, 16 Feb 2009 15:08:09 -0500 Kyle Moffett <[email protected]> wrote:

I think it would be very useful to have a mechanism for userspace to find out "Link detection on this NIC costs ~50mW" and "No link has been detected for the last 15 minutes", so that it can compile all that sort of information and prompt the user what devices they would like to disable. Perhaps an "airline mode" sort of thing

modes suck... they're very much the wrong concept for power management (but that's a different story)

if the user (or something on its behalf) doesn't need link detection, he can turn it off. Really. He doesn't need to know that maybe on machine one this saves some power, and on machine two that power was already mostly saved while on machine three it doesn't save anything at all. Not to mention that the driver is extremely unlikely to know how much actual power will be saved...

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#22 lore raw
In reply to Kyle Moffett
Quoted 5 lines · On Mon, 16 Feb 2009 15:08:09 -0500 Kyle Moffett <[email protected]> wrote:

I think it would be very useful to have a mechanism for userspace to find out "Link detection on this NIC costs ~50mW" and "No link has been detected for the last 15 minutes", so that it can compile all that sort of information and prompt the user what devices they would like to disable. Perhaps an "airline mode" sort of thing

modes suck... they're very much the wrong concept for power management (but that's a different story)

if the user (or something on its behalf) doesn't need link detection, he can turn it off. Really. He doesn't need to know that maybe on machine one this saves some power, and on machine two that power was already mostly saved while on machine three it doesn't save anything at all. Not to mention that the driver is extremely unlikely to know how much actual power will be saved...

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#23 lore raw
In reply to Kyle Moffett
Quoted 8 lines · Kyle Moffett

Userspace may not have a useful decision-making capability regarding functionality versus power-saving, but the user it's talking to might!

I think it would be very useful to have a mechanism for userspace to find out "Link detection on this NIC costs ~50mW" and "No link has been detected for the last 15 minutes", so that it can compile all that sort of information and prompt the user what devices they would like to disable. Perhaps an "airline mode" sort of thing?

Even if drivers don't know how much power their devices consume (and generally I wouldn't expect them to), it still makes sense to offer userspace the discretionary power to force devices into a low-power mode. USB does this.

Alan Stern

#24 lore raw
In reply to Kyle Moffett
Quoted 8 lines · Kyle Moffett

Userspace may not have a useful decision-making capability regarding functionality versus power-saving, but the user it's talking to might!

I think it would be very useful to have a mechanism for userspace to find out "Link detection on this NIC costs ~50mW" and "No link has been detected for the last 15 minutes", so that it can compile all that sort of information and prompt the user what devices they would like to disable. Perhaps an "airline mode" sort of thing?

Even if drivers don't know how much power their devices consume (and generally I wouldn't expect them to), it still makes sense to offer userspace the discretionary power to force devices into a low-power mode. USB does this.

Alan Stern

#25 lore raw
Quoted 12 lines · On Mon, 16 Feb 2009 15:39:15 -0500 (EST) Alan Stern…
Quoted 9 lines · Kyle Moffett

Userspace may not have a useful decision-making capability regarding functionality versus power-saving, but the user it's talking to might!

I think it would be very useful to have a mechanism for userspace to find out "Link detection on this NIC costs ~50mW" and "No link has been detected for the last 15 minutes", so that it can compile all that sort of information and prompt the user what devices they would like to disable. Perhaps an "airline mode" sort of thing?

Quoted 4 lines

Even if drivers don't know how much power their devices consume (and generally I wouldn't expect them to), it still makes sense to offer userspace the discretionary power to force devices into a low-power mode. USB does this.

"stop using it" isn't this discretionary power ?
(for NICs this is "ifconfig .. down")

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#26 lore raw
In reply to Alan Stern
Quoted 12 lines · On Mon, 16 Feb 2009 15:39:15 -0500 (EST) Alan Stern…
Quoted 9 lines · Kyle Moffett

Userspace may not have a useful decision-making capability regarding functionality versus power-saving, but the user it's talking to might!

I think it would be very useful to have a mechanism for userspace to find out "Link detection on this NIC costs ~50mW" and "No link has been detected for the last 15 minutes", so that it can compile all that sort of information and prompt the user what devices they would like to disable. Perhaps an "airline mode" sort of thing?

Quoted 4 lines

Even if drivers don't know how much power their devices consume (and generally I wouldn't expect them to), it still makes sense to offer userspace the discretionary power to force devices into a low-power mode. USB does this.

"stop using it" isn't this discretionary power ?
(for NICs this is "ifconfig .. down")

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#27 lore raw
Quoted 19 lines

From: Arjan van de Ven [mailto:[email protected]]
Sent: Monday, February 16, 2009 2:45 PM

Quoted 12 lines · On Mon, 16 Feb 2009 15:39:15 -0500 (EST) Alan Stern…
Quoted 9 lines · Kyle Moffett

Userspace may not have a useful decision-making capability regarding functionality versus power-saving, but the user it's talking to might!

I think it would be very useful to have a mechanism for userspace to find out "Link detection on this NIC costs ~50mW" and "No link has been detected for the last 15 minutes", so that it can compile all that sort of information and prompt the user what devices they would like to disable. Perhaps an "airline mode" sort of thing?

Quoted 7 lines
Quoted 4 lines

Even if drivers don't know how much power their devices consume (and generally I wouldn't expect them to), it still makes sense to offer userspace the discretionary power to force devices into a low-power mode. USB does this.

"stop using it" isn't this discretionary power ?
(for NICs this is "ifconfig .. down")

Allowing a trusted user space process some hook in kernel PM has turned out useful for us.

- It gives a way for frame works which load codecs into DSPs a way to specify needs before loading. The DSP has its own internal dynamic predictor but it is not always good enough. Feeding this info in from user space is easy as it knows everything about the DSP algorithm it is loading. There isn't a reason to re-export all of that back into the kernel and might hurt DSP performance if it ran on it natively.

- It provides a way to handle overdrive/turbo operating points out of band from the generically tuned cpufreq governors like ondemand. The way we characterize overdrive is stricter then what Intel has talked about for x86.

In TI-reference code we effectively export sysfs knobs which influence system p-state and c-state choices (we borrowed Intel terms here as they are useful). This was done before pmqos was available. We would have considered extending pmqos but a couple things stopped this. One being it wasn't in kernel at the time and two being any change picks up a year of disagreements. As such we put some front end wrappers on the calls which use it to some degree.

There is a community-reference targeting kernel merging but I think it is only now reaching the point of the user space interface. People working there have expressed interest in a direct pmqos interface and removing our wrapping calls.

What we have done more follows what happens when you have a complex driver/subsystem which has pieces in both users and kernel space. It works ok for this.

This is ok for making sure the complex driver works well. It doesn't address all the other user space things going on which also need some kind of management so they don't sink system power. This is where wakelocks start to do something more generically useful.

Right now it seems no one is willing to own the whole system. It is easier to just say user space sucks and someone else should fix it...or my driver is fine it is someone else's problem. However, by not giving some kind of useful constraints interface to help control bad (or uncontrollable) elements the end result are non-competitive Linux systems or ugly out of tree vendor hacks. This is where wakelocks actually stand out. They actually try and do something useful generically.

It seems the perfect is often the enemy of the good when it comes to Linux PM discussions.

Regards,
Richard W.

#28 lore raw
In reply to Arjan van de Ven
Quoted 19 lines

From: Arjan van de Ven [mailto:[email protected]]
Sent: Monday, February 16, 2009 2:45 PM

Quoted 12 lines · On Mon, 16 Feb 2009 15:39:15 -0500 (EST) Alan Stern…
Quoted 9 lines · Kyle Moffett

Userspace may not have a useful decision-making capability regarding functionality versus power-saving, but the user it's talking to might!

I think it would be very useful to have a mechanism for userspace to find out "Link detection on this NIC costs ~50mW" and "No link has been detected for the last 15 minutes", so that it can compile all that sort of information and prompt the user what devices they would like to disable. Perhaps an "airline mode" sort of thing?

Quoted 7 lines
Quoted 4 lines

Even if drivers don't know how much power their devices consume (and generally I wouldn't expect them to), it still makes sense to offer userspace the discretionary power to force devices into a low-power mode. USB does this.

"stop using it" isn't this discretionary power ?
(for NICs this is "ifconfig .. down")

Allowing a trusted user space process some hook in kernel PM has turned out useful for us.

- It gives a way for frame works which load codecs into DSPs a way to specify needs before loading. The DSP has its own internal dynamic predictor but it is not always good enough. Feeding this info in from user space is easy as it knows everything about the DSP algorithm it is loading. There isn't a reason to re-export all of that back into the kernel and might hurt DSP performance if it ran on it natively.

- It provides a way to handle overdrive/turbo operating points out of band from the generically tuned cpufreq governors like ondemand. The way we characterize overdrive is stricter then what Intel has talked about for x86.

In TI-reference code we effectively export sysfs knobs which influence system p-state and c-state choices (we borrowed Intel terms here as they are useful). This was done before pmqos was available. We would have considered extending pmqos but a couple things stopped this. One being it wasn't in kernel at the time and two being any change picks up a year of disagreements. As such we put some front end wrappers on the calls which use it to some degree.

There is a community-reference targeting kernel merging but I think it is only now reaching the point of the user space interface. People working there have expressed interest in a direct pmqos interface and removing our wrapping calls.

What we have done more follows what happens when you have a complex driver/subsystem which has pieces in both users and kernel space. It works ok for this.

This is ok for making sure the complex driver works well. It doesn't address all the other user space things going on which also need some kind of management so they don't sink system power. This is where wakelocks start to do something more generically useful.

Right now it seems no one is willing to own the whole system. It is easier to just say user space sucks and someone else should fix it...or my driver is fine it is someone else's problem. However, by not giving some kind of useful constraints interface to help control bad (or uncontrollable) elements the end result are non-competitive Linux systems or ugly out of tree vendor hacks. This is where wakelocks actually stand out. They actually try and do something useful generically.

It seems the perfect is often the enemy of the good when it comes to Linux PM discussions.

Regards,
Richard W.

#299 lore raw
In reply to Arjan van de Ven
Quoted 19 lines · Arjan van de Ven
Quoted 9 lines · On Mon, 16 Feb 2009 00:10:15 +0100 "Rafael J. Wysocki" <[email protected]> wrote:

Hi,

The recent descussion about the Android PM patches sent by Arve shows that there is a need to introduce a mechanism allowing us to:
(1) automatically put the system as a whole into a sleep state (eg. suspend to RAM) when it is found to be "idle", where the meaning of "idle" has to be defined too,
(2) put given subset of devices into low power states whenever they are not used, without putting the entire system into a sleep state.

For (2), for me the answer is very obvious:

The Device Driver needs to make the decision to put the device to sleep. There are no ifs and buts about this.

Quoted 7 lines

It's the driver who
a) knows if there's any activity, such as open users and
b) is in the right position to know how to put things to sleep.

Of course, the subsystem the driver belongs to can provide helpers (such as generic activity timeout handlers etc).

While I generally agree, there is a difficulty that the driver itself need not have control over all of the bits needed to power manage the device. For example, we're going to make the PCI bus type handle the changing of PCI devices' power states, so the registers used for this purpose will be controlled by the PCI subsystem rather than by individual drivers.

In such cases we may need a mechanism by which the drivers can notify the higher layer that the device is inactive, so that the higher layer can put it into a low power state.

Quoted 6 lines

For many cases, the drivers do this today already.
There are cases where doing this has side effects, mostly in terms of latency. It is reasonable to have a general mechanism that provides a central mechanism to track tolerable latencies; in fact PMQOS provides this on a high level, and I can imagine that PMQOS needs to be extended to provide a wider range of type of latencies.

That indeed would be useful.

Quoted 3 lines

Userland should never ever control the state of a device like this directly. It should do so by a) closing the device and b) setting latency / functional requirements.

The user, however, may want to forcibly put a device into a low power state without stopping all of the applications that depend on it (eg. have it open). Do you think that we shouldn't allow users to do such things?

Rafael

#300 lore raw
In reply to Arjan van de Ven
Quoted 19 lines · Arjan van de Ven
Quoted 9 lines · On Mon, 16 Feb 2009 00:10:15 +0100 "Rafael J. Wysocki" <[email protected]> wrote:

Hi,

The recent descussion about the Android PM patches sent by Arve shows that there is a need to introduce a mechanism allowing us to:
(1) automatically put the system as a whole into a sleep state (eg. suspend to RAM) when it is found to be "idle", where the meaning of "idle" has to be defined too,
(2) put given subset of devices into low power states whenever they are not used, without putting the entire system into a sleep state.

For (2), for me the answer is very obvious:

The Device Driver needs to make the decision to put the device to sleep. There are no ifs and buts about this.

Quoted 7 lines

It's the driver who
a) knows if there's any activity, such as open users and
b) is in the right position to know how to put things to sleep.

Of course, the subsystem the driver belongs to can provide helpers (such as generic activity timeout handlers etc).

While I generally agree, there is a difficulty that the driver itself need not have control over all of the bits needed to power manage the device. For example, we're going to make the PCI bus type handle the changing of PCI devices' power states, so the registers used for this purpose will be controlled by the PCI subsystem rather than by individual drivers.

In such cases we may need a mechanism by which the drivers can notify the higher layer that the device is inactive, so that the higher layer can put it into a low power state.

Quoted 6 lines

For many cases, the drivers do this today already.
There are cases where doing this has side effects, mostly in terms of latency. It is reasonable to have a general mechanism that provides a central mechanism to track tolerable latencies; in fact PMQOS provides this on a high level, and I can imagine that PMQOS needs to be extended to provide a wider range of type of latencies.

That indeed would be useful.

Quoted 3 lines

Userland should never ever control the state of a device like this directly. It should do so by a) closing the device and b) setting latency / functional requirements.

The user, however, may want to forcibly put a device into a low power state without stopping all of the applications that depend on it (eg. have it open). Do you think that we shouldn't allow users to do such things?

Rafael

#29 lore raw
In reply to Woodruff, Richard
Quoted 5 lines · Richard

- It provides a way to handle overdrive/turbo operating points out of band from the generically tuned cpufreq governors like ondemand. The way we characterize overdrive is stricter then what Intel has talked about for x86.

if you have an improved-for-your-systems governor then I'm sure that is very welcome in the kernel.

I agree that perfect is the enemy of good.

I think just about all of us agree that the final decision needs to be in the driver (possibly followed by something that gets various device requests and combines it into hw settings); we're just talking about what inputs feed into that decision ;)

And for different types of devices that's guaranteed to be different... and sometimes we'll be hampered by existing interfaces, so we might end up with hacky stuff.

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#30 lore raw
In reply to Woodruff, Richard
Quoted 5 lines · Richard

- It provides a way to handle overdrive/turbo operating points out of band from the generically tuned cpufreq governors like ondemand. The way we characterize overdrive is stricter then what Intel has talked about for x86.

if you have an improved-for-your-systems governor then I'm sure that is very welcome in the kernel.

I agree that perfect is the enemy of good.

I think just about all of us agree that the final decision needs to be in the driver (possibly followed by something that gets various device requests and combines it into hw settings); we're just talking about what inputs feed into that decision ;)

And for different types of devices that's guaranteed to be different... and sometimes we'll be hampered by existing interfaces, so we might end up with hacky stuff.

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#301 lore raw
In reply to Rafael J. Wysocki
Quoted 7 lines · Rafael J. Wysocki
Quoted 3 lines

Userland should never ever control the state of a device like this directly. It should do so by a) closing the device and b) setting latency / functional requirements.

The user, however, may want to forcibly put a device into a low power state without stopping all of the applications that depend on it (eg. have it open). Do you think that we shouldn't allow users to do such things?

Sounds like a recipe for disaster.

#302 lore raw
In reply to Rafael J. Wysocki
Quoted 7 lines · Rafael J. Wysocki
Quoted 3 lines

Userland should never ever control the state of a device like this directly. It should do so by a) closing the device and b) setting latency / functional requirements.

The user, however, may want to forcibly put a device into a low power state without stopping all of the applications that depend on it (eg. have it open). Do you think that we shouldn't allow users to do such things?

Sounds like a recipe for disaster.

#303 lore raw
In reply to Rafael J. Wysocki
Quoted 8 lines · On Mon, 16 Feb 2009 22:48:32 +0100 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 3 lines

Userland should never ever control the state of a device like this directly. It should do so by a) closing the device and b) setting latency / functional requirements.

The user, however, may want to forcibly put a device into a low power state without stopping all of the applications that depend on it (eg. have it open). Do you think that we shouldn't allow users to do such things?

I would think that that is a bad mistake to do. It basically breaks the contract that the kernel has with userspace....

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#304 lore raw
In reply to Rafael J. Wysocki
Quoted 8 lines · On Mon, 16 Feb 2009 22:48:32 +0100 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 3 lines

Userland should never ever control the state of a device like this directly. It should do so by a) closing the device and b) setting latency / functional requirements.

The user, however, may want to forcibly put a device into a low power state without stopping all of the applications that depend on it (eg. have it open). Do you think that we shouldn't allow users to do such things?

I would think that that is a bad mistake to do. It basically breaks the contract that the kernel has with userspace....

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#305 lore raw
Quoted 7 lines · Arjan van de Ven
Quoted 4 lines · On Mon, 16 Feb 2009 22:48:32 +0100 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 3 lines

Userland should never ever control the state of a device like this directly. It should do so by a) closing the device and b) setting latency / functional requirements.

Quoted 7 lines
Quoted 4 lines

The user, however, may want to forcibly put a device into a low power state without stopping all of the applications that depend on it (eg. have it open). Do you think that we shouldn't allow users to do such things?

I would think that that is a bad mistake to do. It basically breaks the contract that the kernel has with userspace....

OK, so I think there are two things that user space may be allowed to do as far as putting devices into low power states is concerned:
* disable/enable the automatic power management of the device (provided that the driver supports the automatic PM)
* check what power states devices are in.

Thanks,
Rafael

#306 lore raw
In reply to Arjan van de Ven
Quoted 7 lines · Arjan van de Ven
Quoted 4 lines · On Mon, 16 Feb 2009 22:48:32 +0100 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 3 lines

Userland should never ever control the state of a device like this directly. It should do so by a) closing the device and b) setting latency / functional requirements.

Quoted 7 lines
Quoted 4 lines

The user, however, may want to forcibly put a device into a low power state without stopping all of the applications that depend on it (eg. have it open). Do you think that we shouldn't allow users to do such things?

I would think that that is a bad mistake to do. It basically breaks the contract that the kernel has with userspace....

OK, so I think there are two things that user space may be allowed to do as far as putting devices into low power states is concerned:
* disable/enable the automatic power management of the device (provided that the driver supports the automatic PM)
* check what power states devices are in.

Thanks,
Rafael

#31 lore raw
In reply to Arjan van de Ven
Quoted 6 lines

From: Arjan van de Ven [mailto:[email protected]]
Sent: Monday, February 16, 2009 3:52 PM

Quoted 1 line · Richard
Quoted 7 lines
Quoted 4 lines

- It provides a way to handle overdrive/turbo operating points out of band from the generically tuned cpufreq governors like ondemand. The way we characterize overdrive is stricter then what Intel has talked about for x86.

if you have an improved-for-your-systems governor then I'm sure that is very welcome in the kernel.

No, the generic governors were not substantially improved. Not every customer is using cpufreq for DVFS. As such we went underneath it. If we had more community presence at the start time we might have also tried that.

Quoted 8 lines

I think just about all of us agree that the final decision needs to be in the driver (possibly followed by something that gets various device requests and combines it into hw settings); we're just talking about what inputs feed into that decision ;)

And for different types of devices that's guaranteed to be different... and sometimes we'll be hampered by existing interfaces, so we might end up with hacky stuff.

Is there some kind of roadmap which can be plotted which goes from course to more granular control?

Phase 1 (all or nothing): like wakelocks (minus back light): system-auto-suspend-on, system-auto-suspend-off. The drivers can still veto as they do today.

Phase 2: Subsystem generic tunable, on say latency + bandwidth. Start with CPU then move to classes like USB.

Phase 3: ??? if needed add direct device control, hints on an extended fadvise(), and explicit control left to open/close and direct ioctls?

I don't know that 1,2,3 above even make sense. However, the notion of actually plotting out a course with goals does as it will take a long time and it is good to get some benefit along the way.

Thanks,
Richard W.

#32 lore raw
In reply to Arjan van de Ven
Quoted 6 lines

From: Arjan van de Ven [mailto:[email protected]]
Sent: Monday, February 16, 2009 3:52 PM

Quoted 1 line · Richard
Quoted 7 lines
Quoted 4 lines

- It provides a way to handle overdrive/turbo operating points out of band from the generically tuned cpufreq governors like ondemand. The way we characterize overdrive is stricter then what Intel has talked about for x86.

if you have an improved-for-your-systems governor then I'm sure that is very welcome in the kernel.

No, the generic governors were not substantially improved. Not every customer is using cpufreq for DVFS. As such we went underneath it. If we had more community presence at the start time we might have also tried that.

Quoted 8 lines

I think just about all of us agree that the final decision needs to be in the driver (possibly followed by something that gets various device requests and combines it into hw settings); we're just talking about what inputs feed into that decision ;)

And for different types of devices that's guaranteed to be different... and sometimes we'll be hampered by existing interfaces, so we might end up with hacky stuff.

Is there some kind of roadmap which can be plotted which goes from course to more granular control?

Phase 1 (all or nothing): like wakelocks (minus back light): system-auto-suspend-on, system-auto-suspend-off. The drivers can still veto as they do today.

Phase 2: Subsystem generic tunable, on say latency + bandwidth. Start with CPU then move to classes like USB.

Phase 3: ??? if needed add direct device control, hints on an extended fadvise(), and explicit control left to open/close and direct ioctls?

I don't know that 1,2,3 above even make sense. However, the notion of actually plotting out a course with goals does as it will take a long time and it is good to get some benefit along the way.

Thanks,
Richard W.

#307 lore raw
In reply to Rafael J. Wysocki
Quoted 4 lines · Rafael J. Wysocki

OK, so I think there are two things that user space may be allowed to do as far as putting devices into low power states is concerned:
* disable/enable the automatic power management of the device (provided that the driver supports the automatic PM)

Set the automatic PM parameters (idle timeout, state to go to, etc.). And disabling automatic PM altogether (effectively the same as setting the idle timeout to infinity).

Quoted 1 line

* check what power states devices are in.

What about situations where we want to distinguish between the power state of the device itself and the power state of the link? For a disk drive we may want to power the link on and off quite a lot, as that has low latency, but spinning the disk up and down takes a long time and so should have a longer idle-time value.

Alan Stern

#308 lore raw
In reply to Rafael J. Wysocki
Quoted 4 lines · Rafael J. Wysocki

OK, so I think there are two things that user space may be allowed to do as far as putting devices into low power states is concerned:
* disable/enable the automatic power management of the device (provided that the driver supports the automatic PM)

Set the automatic PM parameters (idle timeout, state to go to, etc.). And disabling automatic PM altogether (effectively the same as setting the idle timeout to infinity).

Quoted 1 line

* check what power states devices are in.

What about situations where we want to distinguish between the power state of the device itself and the power state of the link? For a disk drive we may want to power the link on and off quite a lot, as that has low latency, but spinning the disk up and down takes a long time and so should have a longer idle-time value.

Alan Stern

#295 lore raw
In reply to Roland Dreier
Quoted 16 lines · Roland Dreier
Quoted 7 lines
Quoted 2 lines

(2) put given subset of devices into low power states whenever they are not used, without putting the entire system into a sleep state.

For (2), for me the answer is very obvious:

The Device Driver needs to make the decision to put the device to sleep. There are no ifs and buts about this.

For PC-like systems this is probably all that needs to be said. However for highly integrated SoC systems (as Android is obviously targeting) there is another level of complexity due to the interdependency among various devices... eg things like if I know the SD controller and the wifi chip are both asleep then I can put my SDIO controller to sleep; and if the SDIO controller and the NAND controller are both asleep then I can stop clock X and save more power; etc etc.

Quoted 6 lines

This is what the PowerOp/DPM work was all about. Unfortunately that doesn't seem to have made much progress upstream. But there's no doubt in my mind that we need some framework beyond individual drivers that manages the system's power as a whole. And the current device tree is probably not sufficient -- eg the bus hierarchy of a device may not match up with the clock tree at all.

Well, that's why clock framework exists. But none of this is visible to userland.

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#296 lore raw
In reply to Roland Dreier
Quoted 16 lines · Roland Dreier
Quoted 7 lines
Quoted 2 lines

(2) put given subset of devices into low power states whenever they are not used, without putting the entire system into a sleep state.

For (2), for me the answer is very obvious:

The Device Driver needs to make the decision to put the device to sleep. There are no ifs and buts about this.

For PC-like systems this is probably all that needs to be said. However for highly integrated SoC systems (as Android is obviously targeting) there is another level of complexity due to the interdependency among various devices... eg things like if I know the SD controller and the wifi chip are both asleep then I can put my SDIO controller to sleep; and if the SDIO controller and the NAND controller are both asleep then I can stop clock X and save more power; etc etc.

Quoted 6 lines

This is what the PowerOp/DPM work was all about. Unfortunately that doesn't seem to have made much progress upstream. But there's no doubt in my mind that we need some framework beyond individual drivers that manages the system's power as a whole. And the current device tree is probably not sufficient -- eg the bus hierarchy of a device may not match up with the clock tree at all.

Well, that's why clock framework exists. But none of this is visible to userland.

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#339 lore raw
In reply to Rafael J. Wysocki

Hi!

Quoted 7 lines
Quoted 3 lines

Userland should never ever control the state of a device like this directly. It should do so by a) closing the device and b) setting latency / functional requirements.

The user, however, may want to forcibly put a device into a low power state without stopping all of the applications that depend on it (eg. have it open). Do you think that we shouldn't allow users to do such things?

I don't think we should do this... of you want device to be powered down, just don't keep it open. revoke should be enough :-).

...one execption here is the disk driver; unmounting filesystems to let the disk spin down is probably too heavy.

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#340 lore raw
In reply to Rafael J. Wysocki

Hi!

Quoted 7 lines
Quoted 3 lines

Userland should never ever control the state of a device like this directly. It should do so by a) closing the device and b) setting latency / functional requirements.

The user, however, may want to forcibly put a device into a low power state without stopping all of the applications that depend on it (eg. have it open). Do you think that we shouldn't allow users to do such things?

I don't think we should do this... of you want device to be powered down, just don't keep it open. revoke should be enough :-).

...one execption here is the disk driver; unmounting filesystems to let the disk spin down is probably too heavy.

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#341 lore raw
Quoted 11 lines · On Mon, 16 Feb 2009 23:51:16 +0100 Pavel Machek <[email protected]> wrote:

Hi!

Quoted 8 lines
Quoted 3 lines

Userland should never ever control the state of a device like this directly. It should do so by a) closing the device and b) setting latency / functional requirements.

The user, however, may want to forcibly put a device into a low power state without stopping all of the applications that depend on it (eg. have it open). Do you think that we shouldn't allow users to do such things?

Quoted 5 lines

I don't think we should do this... of you want device to be powered down, just don't keep it open. revoke should be enough :-).

...one execption here is the disk driver; unmounting filesystems to let the disk spin down is probably too heavy.

but spin down happens on non-activity ;)
it's more a slumber than a power down

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#342 lore raw
In reply to Pavel Machek
Quoted 11 lines · On Mon, 16 Feb 2009 23:51:16 +0100 Pavel Machek <[email protected]> wrote:

Hi!

Quoted 8 lines
Quoted 3 lines

Userland should never ever control the state of a device like this directly. It should do so by a) closing the device and b) setting latency / functional requirements.

The user, however, may want to forcibly put a device into a low power state without stopping all of the applications that depend on it (eg. have it open). Do you think that we shouldn't allow users to do such things?

Quoted 5 lines

I don't think we should do this... of you want device to be powered down, just don't keep it open. revoke should be enough :-).

...one execption here is the disk driver; unmounting filesystems to let the disk spin down is probably too heavy.

but spin down happens on non-activity ;)
it's more a slumber than a power down

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#309 lore raw
In reply to Alan Stern
Quoted 11 lines · On Mon, 16 Feb 2009 17:40:10 -0500 (EST) Alan Stern…
Quoted 4 lines · Rafael J. Wysocki

OK, so I think there are two things that user space may be allowed to do as far as putting devices into low power states is concerned:
* disable/enable the automatic power management of the device (provided that the driver supports the automatic PM)

Set the automatic PM parameters (idle timeout, state to go to, etc.). And disabling automatic PM altogether (effectively the same as setting the idle timeout to infinity).

shouldn't idle timeout etc be internal to the driver?
Yes policy preferences / constraints makes sense to communicate, actual settings do not. For one they keep changing fast all the time anyway.

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#310 lore raw
In reply to Alan Stern
Quoted 11 lines · On Mon, 16 Feb 2009 17:40:10 -0500 (EST) Alan Stern…
Quoted 4 lines · Rafael J. Wysocki

OK, so I think there are two things that user space may be allowed to do as far as putting devices into low power states is concerned:
* disable/enable the automatic power management of the device (provided that the driver supports the automatic PM)

Set the automatic PM parameters (idle timeout, state to go to, etc.). And disabling automatic PM altogether (effectively the same as setting the idle timeout to infinity).

shouldn't idle timeout etc be internal to the driver?
Yes policy preferences / constraints makes sense to communicate, actual settings do not. For one they keep changing fast all the time anyway.

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#349 lore raw
In reply to Rafael J. Wysocki

Hi!

Quoted 5 lines

The recent descussion about the Android PM patches sent by Arve shows that there is a need to introduce a mechanism allowing us to:
(1) automatically put the system as a whole into a sleep state (eg. suspend to RAM) when it is found to be "idle", where the meaning of "idle" has to be defined too,

Well; I'd prefer to keep the interface very minimal.

If no devices are being used, and next wakeup is far enough in the future, just put system to sleep. Long enough == so far away that suspend/wakeup is short compared to that... like 20 seconds on PC.

Ok, it probably needs to be opt-in: echo auto-mem > /sys/power/state should do the trick.

This will need either fixing all the applications not to poll, or maybe someone SIGSTOP-ing apps that are in background and poll too often.

Quoted 2 lines

(2) put given subset of devices into low power states whenever they are not used, without putting the entire system into a sleep state.

Arjan said this nicely...

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#350 lore raw
In reply to Rafael J. Wysocki

Hi!

Quoted 5 lines

The recent descussion about the Android PM patches sent by Arve shows that there is a need to introduce a mechanism allowing us to:
(1) automatically put the system as a whole into a sleep state (eg. suspend to RAM) when it is found to be "idle", where the meaning of "idle" has to be defined too,

Well; I'd prefer to keep the interface very minimal.

If no devices are being used, and next wakeup is far enough in the future, just put system to sleep. Long enough == so far away that suspend/wakeup is short compared to that... like 20 seconds on PC.

Ok, it probably needs to be opt-in: echo auto-mem > /sys/power/state should do the trick.

This will need either fixing all the applications not to poll, or maybe someone SIGSTOP-ing apps that are in background and poll too often.

Quoted 2 lines

(2) put given subset of devices into low power states whenever they are not used, without putting the entire system into a sleep state.

Arjan said this nicely...

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#33 lore raw
In reply to Woodruff, Richard
Quoted 31 lines · Richard
Quoted 6 lines

From: Arjan van de Ven [mailto:[email protected]]
Sent: Monday, February 16, 2009 3:52 PM

Quoted 1 line · Richard
Quoted 7 lines
Quoted 4 lines

- It provides a way to handle overdrive/turbo operating points out of band from the generically tuned cpufreq governors like ondemand. The way we characterize overdrive is stricter then what Intel has talked about for x86.

if you have an improved-for-your-systems governor then I'm sure that is very welcome in the kernel.

No, the generic governors were not substantially improved. Not every customer is using cpufreq for DVFS. As such we went underneath it. If we had more community presence at the start time we might have also tried that.

Quoted 8 lines

I think just about all of us agree that the final decision needs to be in the driver (possibly followed by something that gets various device requests and combines it into hw settings); we're just talking about what inputs feed into that decision ;)

And for different types of devices that's guaranteed to be different... and sometimes we'll be hampered by existing interfaces, so we might end up with hacky stuff.

Is there some kind of roadmap which can be plotted which goes from course to more granular control?

Quoted 6 lines

Phase 1 (all or nothing): like wakelocks (minus back light):
system-auto-suspend-on, system-auto-suspend-off. The drivers can still veto as they do today.

Phase 2: Subsystem generic tunable, on say latency + bandwidth. Start with CPU then move to classes like USB.

I think your phases are the wrong way around.
Phase 2 is already in progress and many of the "good" drivers and subsystems already do them.

Whole system suspend is a much more drastic thing; I don't see that happen generically in 2009 to be honest (not to mention how fragile linux suspend is). In addition, in hardware there does seem to be the trend where idle and suspend are converging (just look at the OLPC)... with chipsets powering down all unused pieces, and cpus in idle taking basically no power, there no longer is much of a difference in reality between suspend and good-idle...

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#34 lore raw
In reply to Woodruff, Richard
Quoted 31 lines · Richard
Quoted 6 lines

From: Arjan van de Ven [mailto:[email protected]]
Sent: Monday, February 16, 2009 3:52 PM

Quoted 1 line · Richard
Quoted 7 lines
Quoted 4 lines

- It provides a way to handle overdrive/turbo operating points out of band from the generically tuned cpufreq governors like ondemand. The way we characterize overdrive is stricter then what Intel has talked about for x86.

if you have an improved-for-your-systems governor then I'm sure that is very welcome in the kernel.

No, the generic governors were not substantially improved. Not every customer is using cpufreq for DVFS. As such we went underneath it. If we had more community presence at the start time we might have also tried that.

Quoted 8 lines

I think just about all of us agree that the final decision needs to be in the driver (possibly followed by something that gets various device requests and combines it into hw settings); we're just talking about what inputs feed into that decision ;)

And for different types of devices that's guaranteed to be different... and sometimes we'll be hampered by existing interfaces, so we might end up with hacky stuff.

Is there some kind of roadmap which can be plotted which goes from course to more granular control?

Quoted 6 lines

Phase 1 (all or nothing): like wakelocks (minus back light):
system-auto-suspend-on, system-auto-suspend-off. The drivers can still veto as they do today.

Phase 2: Subsystem generic tunable, on say latency + bandwidth. Start with CPU then move to classes like USB.

I think your phases are the wrong way around.
Phase 2 is already in progress and many of the "good" drivers and subsystems already do them.

Whole system suspend is a much more drastic thing; I don't see that happen generically in 2009 to be honest (not to mention how fragile linux suspend is). In addition, in hardware there does seem to be the trend where idle and suspend are converging (just look at the OLPC)... with chipsets powering down all unused pieces, and cpus in idle taking basically no power, there no longer is much of a difference in reality between suspend and good-idle...

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#343 lore raw
In reply to Pavel Machek
Quoted 10 lines · Pavel Machek

Hi!

Quoted 7 lines
Quoted 3 lines

Userland should never ever control the state of a device like this directly. It should do so by a) closing the device and b) setting latency / functional requirements.

The user, however, may want to forcibly put a device into a low power state without stopping all of the applications that depend on it (eg. have it open). Do you think that we shouldn't allow users to do such things?

Quoted 5 lines

I don't think we should do this... of you want device to be powered down, just don't keep it open. revoke should be enough :-).

...one execption here is the disk driver; unmounting filesystems to let the disk spin down is probably too heavy.

Well, I don't think it's viable to make any exceptions here. Either we do it or we don't. And the agreement appears to be that we don't.

Thanks,
Rafael

#344 lore raw
In reply to Pavel Machek
Quoted 10 lines · Pavel Machek

Hi!

Quoted 7 lines
Quoted 3 lines

Userland should never ever control the state of a device like this directly. It should do so by a) closing the device and b) setting latency / functional requirements.

The user, however, may want to forcibly put a device into a low power state without stopping all of the applications that depend on it (eg. have it open). Do you think that we shouldn't allow users to do such things?

Quoted 5 lines

I don't think we should do this... of you want device to be powered down, just don't keep it open. revoke should be enough :-).

...one execption here is the disk driver; unmounting filesystems to let the disk spin down is probably too heavy.

Well, I don't think it's viable to make any exceptions here. Either we do it or we don't. And the agreement appears to be that we don't.

Thanks,
Rafael

#318 lore raw
In reply to Alan Stern
Quoted 8 lines · Alan Stern
Quoted 4 lines · Rafael J. Wysocki

OK, so I think there are two things that user space may be allowed to do as far as putting devices into low power states is concerned:
* disable/enable the automatic power management of the device (provided that the driver supports the automatic PM)

Set the automatic PM parameters (idle timeout, state to go to, etc.).

Yes. I'm not sure about the state part, though.

Quoted 2 lines

And disabling automatic PM altogether (effectively the same as setting the idle timeout to infinity).

Yes.

Quoted 7 lines
Quoted 1 line

* check what power states devices are in.

What about situations where we want to distinguish between the power state of the device itself and the power state of the link? For a disk drive we may want to power the link on and off quite a lot, as that has low latency, but spinning the disk up and down takes a long time and so should have a longer idle-time value.

Well, I'm not sure at the moment.

Do you have any suggestions?

Rafael

#319 lore raw
In reply to Alan Stern
Quoted 8 lines · Alan Stern
Quoted 4 lines · Rafael J. Wysocki

OK, so I think there are two things that user space may be allowed to do as far as putting devices into low power states is concerned:
* disable/enable the automatic power management of the device (provided that the driver supports the automatic PM)

Set the automatic PM parameters (idle timeout, state to go to, etc.).

Yes. I'm not sure about the state part, though.

Quoted 2 lines

And disabling automatic PM altogether (effectively the same as setting the idle timeout to infinity).

Yes.

Quoted 7 lines
Quoted 1 line

* check what power states devices are in.

What about situations where we want to distinguish between the power state of the device itself and the power state of the link? For a disk drive we may want to power the link on and off quite a lot, as that has low latency, but spinning the disk up and down takes a long time and so should have a longer idle-time value.

Well, I'm not sure at the moment.

Do you have any suggestions?

Rafael

#11 lore raw
In reply to Benjamin Herrenschmidt
Quoted 10 lines · Benjamin Herrenschmidt
Quoted 5 lines · Arjan van de Ven

what this needs is a separation between "interface down, all off" and "interface down enough so that link detection works".
Some NICs can go all the way down and still do link detection, others cannot. This is obviously something the driver will know, nothing else in the system should know.

Sure, my point was just that the driver cannot make the decision to go all-off (and thus not detect link) without some kind of user setting allowing it to do so.

Maybe we need ifconfig eth0 reallyreallydown ?
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#12 lore raw
In reply to Benjamin Herrenschmidt
Quoted 10 lines · Benjamin Herrenschmidt
Quoted 5 lines · Arjan van de Ven

what this needs is a separation between "interface down, all off" and "interface down enough so that link detection works".
Some NICs can go all the way down and still do link detection, others cannot. This is obviously something the driver will know, nothing else in the system should know.

Sure, my point was just that the driver cannot make the decision to go all-off (and thus not detect link) without some kind of user setting allowing it to do so.

Maybe we need ifconfig eth0 reallyreallydown ?
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#107 lore raw
In reply to Woodruff, Richard
Quoted 31 lines · Richard
Quoted 6 lines

From: Arjan van de Ven [mailto:[email protected]]
Sent: Monday, February 16, 2009 3:52 PM

Quoted 1 line · Richard
Quoted 7 lines
Quoted 4 lines

- It provides a way to handle overdrive/turbo operating points out of band from the generically tuned cpufreq governors like ondemand. The way we characterize overdrive is stricter then what Intel has talked about for x86.

if you have an improved-for-your-systems governor then I'm sure that is very welcome in the kernel.

No, the generic governors were not substantially improved. Not every customer is using cpufreq for DVFS. As such we went underneath it. If we had more community presence at the start time we might have also tried that.

Quoted 8 lines

I think just about all of us agree that the final decision needs to be in the driver (possibly followed by something that gets various device requests and combines it into hw settings); we're just talking about what inputs feed into that decision ;)

And for different types of devices that's guaranteed to be different... and sometimes we'll be hampered by existing interfaces, so we might end up with hacky stuff.

Is there some kind of roadmap which can be plotted which goes from course to more granular control?

Phase 1 (all or nothing): like wakelocks (minus back light):
system-auto-suspend-on, system-auto-suspend-off. The drivers can still veto as they do today.

Quoted 7 lines

Phase 2: Subsystem generic tunable, on say latency + bandwidth. Start with CPU then move to classes like USB.

Phase 3: ??? if needed add direct device control, hints on an extended fadvise(), and explicit control left to open/close and direct ioctls?

I don't know that 1,2,3 above even make sense.

I'd like to talk about this.

Phase 1: I agree that system-auto-suspend-on, system-auto-suspend-off would be useful, but I don't like the wakelocks interface. Do you think there is an alternative way/mechanism of doing this?

Phase 2: I'm not sure. We may want to introduce such things for various subsystems in parallel (eg. USB already has such things).

Phase 3: Probably explicit control left to open/close.

Quoted 2 lines

However, the notion of actually plotting out a course with goals does as it will take a long time and it is good to get some benefit along the way.

Agreed.

Thanks,
Rafael

#108 lore raw
In reply to Woodruff, Richard
Quoted 31 lines · Richard
Quoted 6 lines

From: Arjan van de Ven [mailto:[email protected]]
Sent: Monday, February 16, 2009 3:52 PM

Quoted 1 line · Richard
Quoted 7 lines
Quoted 4 lines

- It provides a way to handle overdrive/turbo operating points out of band from the generically tuned cpufreq governors like ondemand. The way we characterize overdrive is stricter then what Intel has talked about for x86.

if you have an improved-for-your-systems governor then I'm sure that is very welcome in the kernel.

No, the generic governors were not substantially improved. Not every customer is using cpufreq for DVFS. As such we went underneath it. If we had more community presence at the start time we might have also tried that.

Quoted 8 lines

I think just about all of us agree that the final decision needs to be in the driver (possibly followed by something that gets various device requests and combines it into hw settings); we're just talking about what inputs feed into that decision ;)

And for different types of devices that's guaranteed to be different... and sometimes we'll be hampered by existing interfaces, so we might end up with hacky stuff.

Is there some kind of roadmap which can be plotted which goes from course to more granular control?

Phase 1 (all or nothing): like wakelocks (minus back light):
system-auto-suspend-on, system-auto-suspend-off. The drivers can still veto as they do today.

Quoted 7 lines

Phase 2: Subsystem generic tunable, on say latency + bandwidth. Start with CPU then move to classes like USB.

Phase 3: ??? if needed add direct device control, hints on an extended fadvise(), and explicit control left to open/close and direct ioctls?

I don't know that 1,2,3 above even make sense.

I'd like to talk about this.

Phase 1: I agree that system-auto-suspend-on, system-auto-suspend-off would be useful, but I don't like the wakelocks interface. Do you think there is an alternative way/mechanism of doing this?

Phase 2: I'm not sure. We may want to introduce such things for various subsystems in parallel (eg. USB already has such things).

Phase 3: Probably explicit control left to open/close.

Quoted 2 lines

However, the notion of actually plotting out a course with goals does as it will take a long time and it is good to get some benefit along the way.

Agreed.

Thanks,
Rafael

#351 lore raw
In reply to Pavel Machek
Quoted 3 lines · Pavel Machek

If no devices are being used, and next wakeup is far enough in the future, just put system to sleep. Long enough == so far away that suspend/wakeup is short compared to that... like 20 seconds on PC.

This is intrinsically difficult with PCs, since we have such a poorly defined set of wakeup events. We can't wakeup on generic network traffic, just WoL. Many machines won't wake up on keyboard events. Meanwhile, on embedded it's becoming a less interesting problem because idle and suspended are often now equivalent states. Concentrating on runtime PM of as much hardware as possible is arguably more interesting for the majority of use cases.

Signature · 1 line
Matthew Garrett | [email protected]
#352 lore raw
In reply to Pavel Machek
Quoted 3 lines · Pavel Machek

If no devices are being used, and next wakeup is far enough in the future, just put system to sleep. Long enough == so far away that suspend/wakeup is short compared to that... like 20 seconds on PC.

This is intrinsically difficult with PCs, since we have such a poorly defined set of wakeup events. We can't wakeup on generic network traffic, just WoL. Many machines won't wake up on keyboard events. Meanwhile, on embedded it's becoming a less interesting problem because idle and suspended are often now equivalent states. Concentrating on runtime PM of as much hardware as possible is arguably more interesting for the majority of use cases.

Signature · 1 line
Matthew Garrett | [email protected]
#345 lore raw
In reply to Rafael J. Wysocki
Quoted 11 lines · Rafael J. Wysocki
Quoted 10 lines · Pavel Machek

Hi!

Quoted 7 lines
Quoted 3 lines

Userland should never ever control the state of a device like this directly. It should do so by a) closing the device and b) setting latency / functional requirements.

The user, however, may want to forcibly put a device into a low power state without stopping all of the applications that depend on it (eg. have it open). Do you think that we shouldn't allow users to do such things?

Quoted 8 lines
Quoted 5 lines

I don't think we should do this... of you want device to be powered down, just don't keep it open. revoke should be enough :-).

...one execption here is the disk driver; unmounting filesystems to let the disk spin down is probably too heavy.

Well, I don't think it's viable to make any exceptions here. Either we do it or we don't. And the agreement appears to be that we don't.

We already have interface to force disk down (for disk protectioon stuff), so this is already done for other reasons.

But in general, close(joystick) is nicer interface then 'echo turn-off-joystick-even-when-open > /sys/somewhere'.

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#285 lore raw
In reply to Arjan van de Ven

Am Monday 16 February 2009 18:31:08 schrieb Arjan van de Ven:

Quoted 7 lines
Quoted 4 lines · On Mon, 16 Feb 2009 17:48:06 +0100 Oliver Neukum <[email protected]> wrote:
Quoted 3 lines

Userspace should just be the part that says "I'm interested in link notifications". The driver then just goes to the lowest power state for its device that still gives those notifications.

Quoted 8 lines
Quoted 3 lines

Should there be a channel through which drivers can tell user space what the consequences in terms of reaching a sleep state are if a service is requested?

Personally, I don't think so.
Think about it: what would userspace do?
Not ask for the functionality if it means no sleep state? Maybe it should just never ask for it then as a required functionality!

1. You may have a human being using the information to make the tradeoff.
2. User space may be able to select among several devices the one cheapest to use

Regards
Oliver

#346 lore raw
In reply to Rafael J. Wysocki
Quoted 11 lines · Rafael J. Wysocki
Quoted 10 lines · Pavel Machek

Hi!

Quoted 7 lines
Quoted 3 lines

Userland should never ever control the state of a device like this directly. It should do so by a) closing the device and b) setting latency / functional requirements.

The user, however, may want to forcibly put a device into a low power state without stopping all of the applications that depend on it (eg. have it open). Do you think that we shouldn't allow users to do such things?

Quoted 8 lines
Quoted 5 lines

I don't think we should do this... of you want device to be powered down, just don't keep it open. revoke should be enough :-).

...one execption here is the disk driver; unmounting filesystems to let the disk spin down is probably too heavy.

Well, I don't think it's viable to make any exceptions here. Either we do it or we don't. And the agreement appears to be that we don't.

We already have interface to force disk down (for disk protectioon stuff), so this is already done for other reasons.

But in general, close(joystick) is nicer interface then 'echo turn-off-joystick-even-when-open > /sys/somewhere'.

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#35 lore raw
In reply to Arjan van de Ven
Quoted 41 lines · Arjan van de Ven
Quoted 31 lines · Richard
Quoted 6 lines

From: Arjan van de Ven [mailto:[email protected]]
Sent: Monday, February 16, 2009 3:52 PM

Quoted 1 line · Richard
Quoted 7 lines
Quoted 4 lines

- It provides a way to handle overdrive/turbo operating points out of band from the generically tuned cpufreq governors like ondemand. The way we characterize overdrive is stricter then what Intel has talked about for x86.

if you have an improved-for-your-systems governor then I'm sure that is very welcome in the kernel.

No, the generic governors were not substantially improved. Not every customer is using cpufreq for DVFS. As such we went underneath it. If we had more community presence at the start time we might have also tried that.

Quoted 8 lines

I think just about all of us agree that the final decision needs to be in the driver (possibly followed by something that gets various device requests and combines it into hw settings); we're just talking about what inputs feed into that decision ;)

And for different types of devices that's guaranteed to be different... and sometimes we'll be hampered by existing interfaces, so we might end up with hacky stuff.

Is there some kind of roadmap which can be plotted which goes from course to more granular control?

Quoted 6 lines

Phase 1 (all or nothing): like wakelocks (minus back light):
system-auto-suspend-on, system-auto-suspend-off. The drivers can still veto as they do today.

Phase 2: Subsystem generic tunable, on say latency + bandwidth. Start with CPU then move to classes like USB.

Quoted 8 lines

I think your phases are the wrong way around.
Phase 2 is already in progress and many of the "good" drivers and subsystems already do them.

Whole system suspend is a much more drastic thing; I don't see that happen generically in 2009 to be honest (not to mention how fragile linux suspend is).

This applies to x86/ACPI mostly, IMO. Embedded platforms appear to be much more controllable and tend to work better w/ system-wide sleep states.

Quoted 4 lines

In addition, in hardware there does seem to be the trend where idle and
suspend are converging (just look at the OLPC)... with chipsets powering
down all unused pieces, and cpus in idle taking basically no power, there no longer is much of a difference in reality between suspend and good-idle...

This, again, seems to be a bit x86-centric. :-) The Android people are telling us that on the hardware they deal with it does make sense to put the entire system to sleep even for relatively short periods of time, since the latencies involved are not too bad.

While I agree that on a PC it would probably make more sense to go towards fine-grained run-time power management, maybe even without using system-wide suspend at all (I don't see this happen any time soon, though), I'm not sure about the other platforms.

Thanks,
Rafael

#288 lore raw
In reply to Arjan van de Ven

Am Monday 16 February 2009 18:31:08 schrieb Arjan van de Ven:

Quoted 7 lines
Quoted 4 lines · On Mon, 16 Feb 2009 17:48:06 +0100 Oliver Neukum <[email protected]> wrote:
Quoted 3 lines

Userspace should just be the part that says "I'm interested in link notifications". The driver then just goes to the lowest power state for its device that still gives those notifications.

Quoted 8 lines
Quoted 3 lines

Should there be a channel through which drivers can tell user space what the consequences in terms of reaching a sleep state are if a service is requested?

Personally, I don't think so.
Think about it: what would userspace do?
Not ask for the functionality if it means no sleep state? Maybe it should just never ask for it then as a required functionality!

1. You may have a human being using the information to make the tradeoff.
2. User space may be able to select among several devices the one cheapest to use

Regards
Oliver

#36 lore raw
In reply to Arjan van de Ven
Quoted 41 lines · Arjan van de Ven
Quoted 31 lines · Richard
Quoted 6 lines

From: Arjan van de Ven [mailto:[email protected]]
Sent: Monday, February 16, 2009 3:52 PM

Quoted 1 line · Richard
Quoted 7 lines
Quoted 4 lines

- It provides a way to handle overdrive/turbo operating points out of band from the generically tuned cpufreq governors like ondemand. The way we characterize overdrive is stricter then what Intel has talked about for x86.

if you have an improved-for-your-systems governor then I'm sure that is very welcome in the kernel.

No, the generic governors were not substantially improved. Not every customer is using cpufreq for DVFS. As such we went underneath it. If we had more community presence at the start time we might have also tried that.

Quoted 8 lines

I think just about all of us agree that the final decision needs to be in the driver (possibly followed by something that gets various device requests and combines it into hw settings); we're just talking about what inputs feed into that decision ;)

And for different types of devices that's guaranteed to be different... and sometimes we'll be hampered by existing interfaces, so we might end up with hacky stuff.

Is there some kind of roadmap which can be plotted which goes from course to more granular control?

Quoted 6 lines

Phase 1 (all or nothing): like wakelocks (minus back light):
system-auto-suspend-on, system-auto-suspend-off. The drivers can still veto as they do today.

Phase 2: Subsystem generic tunable, on say latency + bandwidth. Start with CPU then move to classes like USB.

Quoted 8 lines

I think your phases are the wrong way around.
Phase 2 is already in progress and many of the "good" drivers and subsystems already do them.

Whole system suspend is a much more drastic thing; I don't see that happen generically in 2009 to be honest (not to mention how fragile linux suspend is).

This applies to x86/ACPI mostly, IMO. Embedded platforms appear to be much more controllable and tend to work better w/ system-wide sleep states.

Quoted 4 lines

In addition, in hardware there does seem to be the trend where idle and
suspend are converging (just look at the OLPC)... with chipsets powering
down all unused pieces, and cpus in idle taking basically no power, there no longer is much of a difference in reality between suspend and good-idle...

This, again, seems to be a bit x86-centric. :-) The Android people are telling us that on the hardware they deal with it does make sense to put the entire system to sleep even for relatively short periods of time, since the latencies involved are not too bad.

While I agree that on a PC it would probably make more sense to go towards fine-grained run-time power management, maybe even without using system-wide suspend at all (I don't see this happen any time soon, though), I'm not sure about the other platforms.

Thanks,
Rafael

#353 lore raw
In reply to Matthew Garrett
Quoted 9 lines · Matthew Garrett
Quoted 3 lines · Pavel Machek

If no devices are being used, and next wakeup is far enough in the future, just put system to sleep. Long enough == so far away that suspend/wakeup is short compared to that... like 20 seconds on PC.

This is intrinsically difficult with PCs, since we have such a poorly defined set of wakeup events. We can't wakeup on generic network traffic, just WoL.

At least e1000 in thinkpad can wakeup on generic network traffic. If particular network card can't, you just can't sleep when network is up.

Quoted 1 line

Many machines won't wake up on keyboard events.

Too bad. You'll have to close the lid for autosuspend to work on such hw. (Or maybe you can do some hack telling the kernel to suspend anyway if just keyboard prevents it.)

Quoted 2 lines

Meanwhile, on embedded it's becoming a less interesting problem because idle and suspended are often now equivalent states.

Android people tell us otherwise.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#354 lore raw
In reply to Matthew Garrett
Quoted 9 lines · Matthew Garrett
Quoted 3 lines · Pavel Machek

If no devices are being used, and next wakeup is far enough in the future, just put system to sleep. Long enough == so far away that suspend/wakeup is short compared to that... like 20 seconds on PC.

This is intrinsically difficult with PCs, since we have such a poorly defined set of wakeup events. We can't wakeup on generic network traffic, just WoL.

At least e1000 in thinkpad can wakeup on generic network traffic. If particular network card can't, you just can't sleep when network is up.

Quoted 1 line

Many machines won't wake up on keyboard events.

Too bad. You'll have to close the lid for autosuspend to work on such hw. (Or maybe you can do some hack telling the kernel to suspend anyway if just keyboard prevents it.)

Quoted 2 lines

Meanwhile, on embedded it's becoming a less interesting problem because idle and suspended are often now equivalent states.

Android people tell us otherwise.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#37 lore raw
In reply to Rafael J. Wysocki
Quoted 4 lines · Rafael J. Wysocki

This, again, seems to be a bit x86-centric. :-) The Android people are telling us that on the hardware they deal with it does make sense to put the entire system to sleep even for relatively short periods of time, since the latencies involved are not too bad.

Arve said that the power state was equivalent in idle and suspend, but that they preferred suspend because it stopped any periodic timers. I'd be more interested in making sure that unnecessary timers aren't running than focusing on automatically entering system-wide suspend - Nokia have been managing this since 2005 with good results.

Signature · 1 line
Matthew Garrett | [email protected]
#38 lore raw
In reply to Rafael J. Wysocki
Quoted 4 lines · Rafael J. Wysocki

This, again, seems to be a bit x86-centric. :-) The Android people are telling us that on the hardware they deal with it does make sense to put the entire system to sleep even for relatively short periods of time, since the latencies involved are not too bad.

Arve said that the power state was equivalent in idle and suspend, but that they preferred suspend because it stopped any periodic timers. I'd be more interested in making sure that unnecessary timers aren't running than focusing on automatically entering system-wide suspend - Nokia have been managing this since 2005 with good results.

Signature · 1 line
Matthew Garrett | [email protected]
#371 lore raw
In reply to Pavel Machek
Quoted 11 lines · Pavel Machek

Hi!

Quoted 5 lines

The recent descussion about the Android PM patches sent by Arve shows that there is a need to introduce a mechanism allowing us to:
(1) automatically put the system as a whole into a sleep state (eg. suspend to RAM) when it is found to be "idle", where the meaning of "idle" has to be defined too,

Well; I'd prefer to keep the interface very minimal.

If no devices are being used,

We'll need some kind of infrastructure to detect such situations.

Quoted 1 line

and next wakeup is far enough in the future,

What exactly do you mean by "next wakeup"?

Quoted 2 lines

just put system to sleep. Long enough == so far away that suspend/wakeup is short compared to that... like 20 seconds on PC.

Well 10s will be fine on the majority of my test boxes, but that's a detail.

Quoted 2 lines

Ok, it probably needs to be opt-in: echo auto-mem > /sys/power/state should do the trick.

Agreed.

Quoted 3 lines

This will need either fixing all the applications not to poll, or maybe someone SIGSTOP-ing apps that are in background and poll too often.

Polling in general is not PM-friendly, so we'll need to deal with it somehow at one point anyway.

Thanks,
Rafael

#372 lore raw
In reply to Pavel Machek
Quoted 11 lines · Pavel Machek

Hi!

Quoted 5 lines

The recent descussion about the Android PM patches sent by Arve shows that there is a need to introduce a mechanism allowing us to:
(1) automatically put the system as a whole into a sleep state (eg. suspend to RAM) when it is found to be "idle", where the meaning of "idle" has to be defined too,

Well; I'd prefer to keep the interface very minimal.

If no devices are being used,

We'll need some kind of infrastructure to detect such situations.

Quoted 1 line

and next wakeup is far enough in the future,

What exactly do you mean by "next wakeup"?

Quoted 2 lines

just put system to sleep. Long enough == so far away that suspend/wakeup is short compared to that... like 20 seconds on PC.

Well 10s will be fine on the majority of my test boxes, but that's a detail.

Quoted 2 lines

Ok, it probably needs to be opt-in: echo auto-mem > /sys/power/state should do the trick.

Agreed.

Quoted 3 lines

This will need either fixing all the applications not to poll, or maybe someone SIGSTOP-ing apps that are in background and poll too often.

Polling in general is not PM-friendly, so we'll need to deal with it somehow at one point anyway.

Thanks,
Rafael

#311 lore raw
In reply to Arjan van de Ven
Quoted 15 lines · Arjan van de Ven
Quoted 11 lines · On Mon, 16 Feb 2009 17:40:10 -0500 (EST) Alan Stern…
Quoted 4 lines · Rafael J. Wysocki

OK, so I think there are two things that user space may be allowed to do as far as putting devices into low power states is concerned:
* disable/enable the automatic power management of the device (provided that the driver supports the automatic PM)

Set the automatic PM parameters (idle timeout, state to go to, etc.). And disabling automatic PM altogether (effectively the same as setting the idle timeout to infinity).

Quoted 4 lines

shouldn't idle timeout etc be internal to the driver?
Yes policy preferences / constraints makes sense to communicate, actual settings do not. For one they keep changing fast all the time anyway.

Usually different devices are handled by the same driver. I don't really think the same value will be suitable for all of them, so the users should at least be able to override the driver default, IMO.

Thanks,
Rafael

#312 lore raw
In reply to Arjan van de Ven
Quoted 15 lines · Arjan van de Ven
Quoted 11 lines · On Mon, 16 Feb 2009 17:40:10 -0500 (EST) Alan Stern…
Quoted 4 lines · Rafael J. Wysocki

OK, so I think there are two things that user space may be allowed to do as far as putting devices into low power states is concerned:
* disable/enable the automatic power management of the device (provided that the driver supports the automatic PM)

Set the automatic PM parameters (idle timeout, state to go to, etc.). And disabling automatic PM altogether (effectively the same as setting the idle timeout to infinity).

Quoted 4 lines

shouldn't idle timeout etc be internal to the driver?
Yes policy preferences / constraints makes sense to communicate, actual settings do not. For one they keep changing fast all the time anyway.

Usually different devices are handled by the same driver. I don't really think the same value will be suitable for all of them, so the users should at least be able to override the driver default, IMO.

Thanks,
Rafael

#347 lore raw
In reply to Pavel Machek

Am Monday 16 February 2009 23:51:16 schrieb Pavel Machek:

Quoted 6 lines
Quoted 3 lines

The user, however, may want to forcibly put a device into a low power state without stopping all of the applications that depend on it (eg. have it open). Do you think that we shouldn't allow users to do such things?

I don't think we should do this... of you want device to be powered down, just don't keep it open. revoke should be enough :-).

Keeping a device open also guarantees identity. Secondly you may not have opened a device yourself and indeed be unable to do so.

Regards
Oliver

#105 lore raw
In reply to Rafael J. Wysocki
Quoted 7 lines · On Tue, 17 Feb 2009 00:19:38 +0100 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 5 lines

In addition, in hardware there does seem to be the trend where idle
and suspend are converging (just look at the OLPC)... with
chipsets powering down all unused pieces, and cpus in idle taking basically no power, there no longer is much of a difference in reality between suspend and good-idle...

This, again, seems to be a bit x86-centric. :-)

actually absolutely not. To the contrary. It is, as you said, the embedded systems that have, and increasingly get, finer grained per device controls. (x86 embedded and otherwise). The more fine grained control you have, the less a system wide state will give you in additional power savings. This is pretty much the industry trend for all power sensitive systems.

Android might be using last years hardware. I'm not saying we shouldn't support that, but we need to be careful to not design the system only looking backwards.

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#106 lore raw
In reply to Rafael J. Wysocki
Quoted 7 lines · On Tue, 17 Feb 2009 00:19:38 +0100 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 5 lines

In addition, in hardware there does seem to be the trend where idle
and suspend are converging (just look at the OLPC)... with
chipsets powering down all unused pieces, and cpus in idle taking basically no power, there no longer is much of a difference in reality between suspend and good-idle...

This, again, seems to be a bit x86-centric. :-)

actually absolutely not. To the contrary. It is, as you said, the embedded systems that have, and increasingly get, finer grained per device controls. (x86 embedded and otherwise). The more fine grained control you have, the less a system wide state will give you in additional power savings. This is pretty much the industry trend for all power sensitive systems.

Android might be using last years hardware. I'm not saying we shouldn't support that, but we need to be careful to not design the system only looking backwards.

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#313 lore raw
In reply to Arjan van de Ven
Quoted 9 lines · Arjan van de Ven
Quoted 4 lines

Set the automatic PM parameters (idle timeout, state to go to, etc.). And disabling automatic PM altogether (effectively the same as setting the idle timeout to infinity).

shouldn't idle timeout etc be internal to the driver?
Yes policy preferences / constraints makes sense to communicate, actual settings do not. For one they keep changing fast all the time anyway.

Sorry, I don't agree. A single driver may control many different kinds of device -- it may not even be aware of the distinction! Consider the SCSI disk driver: It has to handle both traditional rotating media and solid-state disks. Clearly they should have different runtime PM parameters. But the driver isn't in a good position to know what those parameters should be.

Alan Stern

#320 lore raw
In reply to Rafael J. Wysocki
Quoted 11 lines · Rafael J. Wysocki
Quoted 8 lines · Alan Stern
Quoted 4 lines · Rafael J. Wysocki

OK, so I think there are two things that user space may be allowed to do as far as putting devices into low power states is concerned:
* disable/enable the automatic power management of the device (provided that the driver supports the automatic PM)

Set the automatic PM parameters (idle timeout, state to go to, etc.).

Yes. I'm not sure about the state part, though.

Maybe, maybe not. IMO it's too early to tell whether anyone will need this ability, so we shouldn't rule it out.

Quoted 9 lines
Quoted 5 lines

What about situations where we want to distinguish between the power state of the device itself and the power state of the link? For a disk drive we may want to power the link on and off quite a lot, as that has low latency, but spinning the disk up and down takes a long time and so should have a longer idle-time value.

Well, I'm not sure at the moment.

Do you have any suggestions?

Not very well fleshed-out ones. I've got a vague idea for allowing a disk to have a 3-level power arrangement: full power, link disabled but drive still spinning, and device suspended. Arranging for automatic transitions among those states will be a little clumsy but it can be done. As an example of the clumsiness, this scheme requires that the drive has _two_ idle-timeout values, one for the link and one for the drive itself.

Another possibility is to set up independent runtime PM for the transport and the device. This means allowing the possibility that the transport is suspended while its child (the device) is not. This is a little simpler (there's only one idle-timeout per device, since the link is treated as an independent device), but it violates the principle of never suspending a parent while there is an active child.

Alan Stern

#321 lore raw
In reply to Rafael J. Wysocki
Quoted 11 lines · Rafael J. Wysocki
Quoted 8 lines · Alan Stern
Quoted 4 lines · Rafael J. Wysocki

OK, so I think there are two things that user space may be allowed to do as far as putting devices into low power states is concerned:
* disable/enable the automatic power management of the device (provided that the driver supports the automatic PM)

Set the automatic PM parameters (idle timeout, state to go to, etc.).

Yes. I'm not sure about the state part, though.

Maybe, maybe not. IMO it's too early to tell whether anyone will need this ability, so we shouldn't rule it out.

Quoted 9 lines
Quoted 5 lines

What about situations where we want to distinguish between the power state of the device itself and the power state of the link? For a disk drive we may want to power the link on and off quite a lot, as that has low latency, but spinning the disk up and down takes a long time and so should have a longer idle-time value.

Well, I'm not sure at the moment.

Do you have any suggestions?

Not very well fleshed-out ones. I've got a vague idea for allowing a disk to have a 3-level power arrangement: full power, link disabled but drive still spinning, and device suspended. Arranging for automatic transitions among those states will be a little clumsy but it can be done. As an example of the clumsiness, this scheme requires that the drive has _two_ idle-timeout values, one for the link and one for the drive itself.

Another possibility is to set up independent runtime PM for the transport and the device. This means allowing the possibility that the transport is suspended while its child (the device) is not. This is a little simpler (there's only one idle-timeout per device, since the link is treated as an independent device), but it violates the principle of never suspending a parent while there is an active child.

Alan Stern

#314 lore raw
In reply to Alan Stern
Quoted 12 lines · On Mon, 16 Feb 2009 21:43:52 -0500 (EST) Alan Stern…
Quoted 9 lines · Arjan van de Ven
Quoted 4 lines

Set the automatic PM parameters (idle timeout, state to go to, etc.). And disabling automatic PM altogether (effectively the same as setting the idle timeout to infinity).

shouldn't idle timeout etc be internal to the driver?
Yes policy preferences / constraints makes sense to communicate, actual settings do not. For one they keep changing fast all the time anyway.

Quoted 6 lines

Sorry, I don't agree. A single driver may control many different kinds of device -- it may not even be aware of the distinction! Consider the SCSI disk driver: It has to handle both traditional rotating media and solid-state disks. Clearly they should have different runtime PM parameters. But the driver isn't in a good position to know what those parameters should be.

... and userspace is ?
Sorry I don't buy that. Kernel is supposed to abstract the hardware... That's its fundamental task. Now if the driver doesn't know it can get help from the subsystem, that's perfectly fine.

(and quiet often the kernel gets updated more often as the userspace)

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#315 lore raw
In reply to Alan Stern
Quoted 12 lines · On Mon, 16 Feb 2009 21:43:52 -0500 (EST) Alan Stern…
Quoted 9 lines · Arjan van de Ven
Quoted 4 lines

Set the automatic PM parameters (idle timeout, state to go to, etc.). And disabling automatic PM altogether (effectively the same as setting the idle timeout to infinity).

shouldn't idle timeout etc be internal to the driver?
Yes policy preferences / constraints makes sense to communicate, actual settings do not. For one they keep changing fast all the time anyway.

Quoted 6 lines

Sorry, I don't agree. A single driver may control many different kinds of device -- it may not even be aware of the distinction! Consider the SCSI disk driver: It has to handle both traditional rotating media and solid-state disks. Clearly they should have different runtime PM parameters. But the driver isn't in a good position to know what those parameters should be.

... and userspace is ?
Sorry I don't buy that. Kernel is supposed to abstract the hardware... That's its fundamental task. Now if the driver doesn't know it can get help from the subsystem, that's perfectly fine.

(and quiet often the kernel gets updated more often as the userspace)

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#109 lore raw
In reply to Rafael J. Wysocki
Quoted 3 lines · Rafael J. Wysocki

Phase 1: I agree that system-auto-suspend-on, system-auto-suspend-off would be useful, but I don't like the wakelocks interface. Do you think there is an alternative way/mechanism of doing this?

I rather like the suggestions Matthew Garrett has been making. They show how to improve the wakelock interface without losing any function.

Really, the idea behind wakelocks comes down to the question of how to determine when the system is sufficiently idle to go into auto-suspend. There may be occasions when no task is runnable but userspace knows that the system should not go to sleep because some work will be done in the near future. (Arve's example of a non-empty input buffer is such a case.) How should userspace let the kernel know whether it's okay to suspend at these times? That is the problem userspace wakelocks are meant to solve.

Kernel wakelocks are a separate matter. They are more like a form of optimization, preventing the kernel from starting an auto-suspend when some driver knows beforehand that it will return -EBUSY.

Quoted 1 line

Phase 3: Probably explicit control left to open/close.

While that's generally a good idea, it's important to recognize that some devices should be runtime-suspended even while they are open. Basically, any device that is "always open" falls in this category. Some examples are the screen, the keyboard, the mouse, and disk drives. And of course, some of these things already have runtime power management.

Alan Stern

#110 lore raw
In reply to Rafael J. Wysocki
Quoted 3 lines · Rafael J. Wysocki

Phase 1: I agree that system-auto-suspend-on, system-auto-suspend-off would be useful, but I don't like the wakelocks interface. Do you think there is an alternative way/mechanism of doing this?

I rather like the suggestions Matthew Garrett has been making. They show how to improve the wakelock interface without losing any function.

Really, the idea behind wakelocks comes down to the question of how to determine when the system is sufficiently idle to go into auto-suspend. There may be occasions when no task is runnable but userspace knows that the system should not go to sleep because some work will be done in the near future. (Arve's example of a non-empty input buffer is such a case.) How should userspace let the kernel know whether it's okay to suspend at these times? That is the problem userspace wakelocks are meant to solve.

Kernel wakelocks are a separate matter. They are more like a form of optimization, preventing the kernel from starting an auto-suspend when some driver knows beforehand that it will return -EBUSY.

Quoted 1 line

Phase 3: Probably explicit control left to open/close.

While that's generally a good idea, it's important to recognize that some devices should be runtime-suspended even while they are open. Basically, any device that is "always open" falls in this category. Some examples are the screen, the keyboard, the mouse, and disk drives. And of course, some of these things already have runtime power management.

Alan Stern

#316 lore raw
In reply to Arjan van de Ven
Quoted 5 lines · Arjan van de Ven
Quoted 5 lines
Quoted 4 lines

shouldn't idle timeout etc be internal to the driver?
Yes policy preferences / constraints makes sense to communicate, actual settings do not. For one they keep changing fast all the time anyway.

Quoted 8 lines
Quoted 6 lines

Sorry, I don't agree. A single driver may control many different kinds of device -- it may not even be aware of the distinction! Consider the SCSI disk driver: It has to handle both traditional rotating media and solid-state disks. Clearly they should have different runtime PM parameters. But the driver isn't in a good position to know what those parameters should be.

... and userspace is ?

Certainly it is. Programs like hal can maintain databases of device IDs and appropriate timeout values, and allow the user to change the values as needed. Such databases don't belong in the kernel.

Furthermore, the user may have a better idea of the kind of workload he wants to impose and his latency requirements than the kernel does.

Quoted 3 lines

Sorry I don't buy that. Kernel is supposed to abstract the hardware... That's its fundamental task. Now if the driver doesn't know it can get help from the subsystem, that's perfectly fine.

There are various levels of abstraction. If the kernel really abstracted _everything_ then we wouldn't need ioctl. :-)

Quoted 1 line

(and quiet often the kernel gets updated more often as the userspace)

(That's hardly a valid argument for putting something into the kernel when it belongs in userspace.)

Alan Stern

#317 lore raw
In reply to Arjan van de Ven
Quoted 5 lines · Arjan van de Ven
Quoted 5 lines
Quoted 4 lines

shouldn't idle timeout etc be internal to the driver?
Yes policy preferences / constraints makes sense to communicate, actual settings do not. For one they keep changing fast all the time anyway.

Quoted 8 lines
Quoted 6 lines

Sorry, I don't agree. A single driver may control many different kinds of device -- it may not even be aware of the distinction! Consider the SCSI disk driver: It has to handle both traditional rotating media and solid-state disks. Clearly they should have different runtime PM parameters. But the driver isn't in a good position to know what those parameters should be.

... and userspace is ?

Certainly it is. Programs like hal can maintain databases of device IDs and appropriate timeout values, and allow the user to change the values as needed. Such databases don't belong in the kernel.

Furthermore, the user may have a better idea of the kind of workload he wants to impose and his latency requirements than the kernel does.

Quoted 3 lines

Sorry I don't buy that. Kernel is supposed to abstract the hardware... That's its fundamental task. Now if the driver doesn't know it can get help from the subsystem, that's perfectly fine.

There are various levels of abstraction. If the kernel really abstracted _everything_ then we wouldn't need ioctl. :-)

Quoted 1 line

(and quiet often the kernel gets updated more often as the userspace)

(That's hardly a valid argument for putting something into the kernel when it belongs in userspace.)

Alan Stern

#348 lore raw
In reply to Pavel Machek

Am Monday 16 February 2009 23:51:16 schrieb Pavel Machek:

Quoted 6 lines
Quoted 3 lines

The user, however, may want to forcibly put a device into a low power state without stopping all of the applications that depend on it (eg. have it open). Do you think that we shouldn't allow users to do such things?

I don't think we should do this... of you want device to be powered down, just don't keep it open. revoke should be enough :-).

Keeping a device open also guarantees identity. Secondly you may not have opened a device yourself and indeed be unable to do so.

Regards
Oliver

#39 lore raw
In reply to Matthew Garrett

Am Tuesday 17 February 2009 00:23:30 schrieb Matthew Garrett:

Quoted 7 lines · Rafael J. Wysocki
Quoted 5 lines

This, again, seems to be a bit x86-centric. :-) The Android people are telling us that on the hardware they deal with it does make sense to put the entire system to sleep even for relatively short periods of time, since the latencies involved are not too bad.

Quoted 5 lines

Arve said that the power state was equivalent in idle and suspend, but that they preferred suspend because it stopped any periodic timers. I'd be more interested in making sure that unnecessary timers aren't running than focusing on automatically entering system-wide suspend - Nokia have been managing this since 2005 with good results.

I agree. For a general purpose system it would be very hard to call some timers unnecessary and others necessary.

Regards
Oliver

#40 lore raw
In reply to Matthew Garrett

Am Tuesday 17 February 2009 00:23:30 schrieb Matthew Garrett:

Quoted 7 lines · Rafael J. Wysocki
Quoted 5 lines

This, again, seems to be a bit x86-centric. :-) The Android people are telling us that on the hardware they deal with it does make sense to put the entire system to sleep even for relatively short periods of time, since the latencies involved are not too bad.

Quoted 5 lines

Arve said that the power state was equivalent in idle and suspend, but that they preferred suspend because it stopped any periodic timers. I'd be more interested in making sure that unnecessary timers aren't running than focusing on automatically entering system-wide suspend - Nokia have been managing this since 2005 with good results.

I agree. For a general purpose system it would be very hard to call some timers unnecessary and others necessary.

Regards
Oliver

#41 lore raw
In reply to Matthew Garrett
Quoted 5 lines · Matthew Garrett

Arve said that the power state was equivalent in idle and suspend, but that they preferred suspend because it stopped any periodic timers. I'd be more interested in making sure that unnecessary timers aren't running than focusing on automatically entering system-wide suspend - Nokia have been managing this since 2005 with good results.

Definitely. Even in the embedded case there is hardware which takes a relatively long time to fully power down and resume without winning an enormous amount on the power front (analogue stuff is a common culprit here, it can take a noticable amount of time to bring it up cleanly).

#42 lore raw
In reply to Matthew Garrett
Quoted 5 lines · Matthew Garrett

Arve said that the power state was equivalent in idle and suspend, but that they preferred suspend because it stopped any periodic timers. I'd be more interested in making sure that unnecessary timers aren't running than focusing on automatically entering system-wide suspend - Nokia have been managing this since 2005 with good results.

Definitely. Even in the embedded case there is hardware which takes a relatively long time to fully power down and resume without winning an enormous amount on the power front (analogue stuff is a common culprit here, it can take a noticable amount of time to bring it up cleanly).

#356 lore raw
In reply to Matthew Garrett

[Matthew Garrett <[email protected]>]

Quoted 9 lines · Pavel Machek
Quoted 5 lines · Matthew Garrett
Quoted 2 lines

Meanwhile, on embedded it's becoming a less interesting problem because idle and suspended are often now equivalent states.

Android people tell us otherwise.

https://lists.linux-foundation.org/pipermail/linux-pm/2009-January/019493.html
says that they're the same on their current platform.

Well on the Qualcomm MSM72xx SoCs, yeah they're pretty similar -- we can reasonably enter power collapse (full shutdown of the ARM11 and peripherals) from idle. But this is not (to my knowledge) true of *all* SoCs out there. Also, resuming from this state can take 5-30ms (depending on how distracted the baseband processor is by what's going on on the network).

Brian

#357 lore raw
Quoted 10 lines · Brian Swetland

[Matthew Garrett <[email protected]>]

Quoted 2 lines

https://lists.linux-foundation.org/pipermail/linux-pm/2009-January/019493.html
says that they're the same on their current platform.

Well on the Qualcomm MSM72xx SoCs, yeah they're pretty similar -- we can reasonably enter power collapse (full shutdown of the ARM11 and peripherals) from idle. But this is not (to my knowledge) true of *all* SoCs out there. Also, resuming from this state can take 5-30ms (depending on how distracted the baseband processor is by what's going on on the network).

Mm. Resume from deep idle on x86 is typically in the usec range, but this is the kind of constraint that pm_qos exposes nicely.

Signature · 1 line
Matthew Garrett | [email protected]
#358 lore raw
In reply to Brian Swetland
Quoted 10 lines · Brian Swetland

[Matthew Garrett <[email protected]>]

Quoted 2 lines

https://lists.linux-foundation.org/pipermail/linux-pm/2009-January/019493.html
says that they're the same on their current platform.

Well on the Qualcomm MSM72xx SoCs, yeah they're pretty similar -- we can reasonably enter power collapse (full shutdown of the ARM11 and peripherals) from idle. But this is not (to my knowledge) true of *all* SoCs out there. Also, resuming from this state can take 5-30ms (depending on how distracted the baseband processor is by what's going on on the network).

Mm. Resume from deep idle on x86 is typically in the usec range, but this is the kind of constraint that pm_qos exposes nicely.

Signature · 1 line
Matthew Garrett | [email protected]
#43 lore raw
In reply to Matthew Garrett

[Matthew Garrett <[email protected]>]

Quoted 7 lines · Rafael J. Wysocki
Quoted 5 lines

This, again, seems to be a bit x86-centric. :-) The Android people are telling us that on the hardware they deal with it does make sense to put the entire system to sleep even for relatively short periods of time, since the latencies involved are not too bad.

Quoted 5 lines

Arve said that the power state was equivalent in idle and suspend, but that they preferred suspend because it stopped any periodic timers. I'd be more interested in making sure that unnecessary timers aren't running than focusing on automatically entering system-wide suspend - Nokia have been managing this since 2005 with good results.

We'd totally agree that doing something about periodic timers would be a big win. There's also the situation that the longest ARM linux can sit in idle right now is ~2s at a time (Arve can expand on the exact issue relating to a 32bit signed nanosecond value somewhere iirc), which we'd want to sort out as well.

Of course that still doesn't address userspace. Aggressively going to suspend lets us compensate for userspace programs that do somewhat silly things (I agree that it would be best if they didn't but they do and getting *everyone* to write their userspace code to avoid spinning or avoid waking up on short-duration timers to poll is a losing battle).

Brian

#44 lore raw
In reply to Matthew Garrett

[Matthew Garrett <[email protected]>]

Quoted 7 lines · Rafael J. Wysocki
Quoted 5 lines

This, again, seems to be a bit x86-centric. :-) The Android people are telling us that on the hardware they deal with it does make sense to put the entire system to sleep even for relatively short periods of time, since the latencies involved are not too bad.

Quoted 5 lines

Arve said that the power state was equivalent in idle and suspend, but that they preferred suspend because it stopped any periodic timers. I'd be more interested in making sure that unnecessary timers aren't running than focusing on automatically entering system-wide suspend - Nokia have been managing this since 2005 with good results.

We'd totally agree that doing something about periodic timers would be a big win. There's also the situation that the longest ARM linux can sit in idle right now is ~2s at a time (Arve can expand on the exact issue relating to a 32bit signed nanosecond value somewhere iirc), which we'd want to sort out as well.

Of course that still doesn't address userspace. Aggressively going to suspend lets us compensate for userspace programs that do somewhat silly things (I agree that it would be best if they didn't but they do and getting *everyone* to write their userspace code to avoid spinning or avoid waking up on short-duration timers to poll is a losing battle).

Brian

#45 lore raw
Quoted 5 lines · Brian Swetland

Of course that still doesn't address userspace. Aggressively going to suspend lets us compensate for userspace programs that do somewhat silly things (I agree that it would be best if they didn't but they do and getting *everyone* to write their userspace code to avoid spinning or avoid waking up on short-duration timers to poll is a losing battle).

Like Pavel pointed out, you could (in principle) handle this by sending a SIGSTOP to everything. The obvious problem with doing so is that this wouldn't result in the processes letting go of the devices, so you wouldn't neccessarily actually get to enter the runtime idle state as a result. Hmm. I'll think about this.

Signature · 1 line
Matthew Garrett | [email protected]
#46 lore raw
In reply to Brian Swetland
Quoted 5 lines · Brian Swetland

Of course that still doesn't address userspace. Aggressively going to suspend lets us compensate for userspace programs that do somewhat silly things (I agree that it would be best if they didn't but they do and getting *everyone* to write their userspace code to avoid spinning or avoid waking up on short-duration timers to poll is a losing battle).

Like Pavel pointed out, you could (in principle) handle this by sending a SIGSTOP to everything. The obvious problem with doing so is that this wouldn't result in the processes letting go of the devices, so you wouldn't neccessarily actually get to enter the runtime idle state as a result. Hmm. I'll think about this.

Signature · 1 line
Matthew Garrett | [email protected]
#49 lore raw
In reply to Brian Swetland
Quoted 6 lines · On Tue, 17 Feb 2009 06:20:01 -0800 Brian Swetland <[email protected]> wrote:

Of course that still doesn't address userspace. Aggressively going to suspend lets us compensate for userspace programs that do somewhat silly things (I agree that it would be best if they didn't but they do and getting *everyone* to write their userspace code to avoid spinning or avoid waking up on short-duration timers to poll is a losing battle).

actually with powertop... on the open source side things are actually won. It took all of 6 months...
I don't see that as a valid excuse. In fact, if this kind of solution makes real userspace scheduled timers to be missed then I consider it a serious functionality misfeature.

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#50 lore raw
In reply to Brian Swetland
Quoted 6 lines · On Tue, 17 Feb 2009 06:20:01 -0800 Brian Swetland <[email protected]> wrote:

Of course that still doesn't address userspace. Aggressively going to suspend lets us compensate for userspace programs that do somewhat silly things (I agree that it would be best if they didn't but they do and getting *everyone* to write their userspace code to avoid spinning or avoid waking up on short-duration timers to poll is a losing battle).

actually with powertop... on the open source side things are actually won. It took all of 6 months...
I don't see that as a valid excuse. In fact, if this kind of solution makes real userspace scheduled timers to be missed then I consider it a serious functionality misfeature.

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#51 lore raw
Quoted 5 lines · Arjan van de Ven

actually with powertop... on the open source side things are actually won. It took all of 6 months...
I don't see that as a valid excuse. In fact, if this kind of solution makes real userspace scheduled timers to be missed then I consider it a serious functionality misfeature.

Remember that Android has an open marketplace designed to appeal to Java programmers - users are going to end up downloading code from there and then blaming the platform if their battery life heads towards zero. I think "We can't trust our userland not to be dumb" is a valid concern.

Signature · 1 line
Matthew Garrett | [email protected]
#52 lore raw
In reply to Arjan van de Ven
Quoted 5 lines · Arjan van de Ven

actually with powertop... on the open source side things are actually won. It took all of 6 months...
I don't see that as a valid excuse. In fact, if this kind of solution makes real userspace scheduled timers to be missed then I consider it a serious functionality misfeature.

Remember that Android has an open marketplace designed to appeal to Java programmers - users are going to end up downloading code from there and then blaming the platform if their battery life heads towards zero. I think "We can't trust our userland not to be dumb" is a valid concern.

Signature · 1 line
Matthew Garrett | [email protected]
#47 lore raw
In reply to Matthew Garrett

Am Tuesday 17 February 2009 15:24:53 schrieb Matthew Garrett:

Quoted 8 lines · Brian Swetland
Quoted 6 lines

Of course that still doesn't address userspace. Aggressively going to suspend lets us compensate for userspace programs that do somewhat silly things (I agree that it would be best if they didn't but they do and getting *everyone* to write their userspace code to avoid spinning or avoid waking up on short-duration timers to poll is a losing battle).

Quoted 5 lines

Like Pavel pointed out, you could (in principle) handle this by sending a SIGSTOP to everything. The obvious problem with doing so is that this wouldn't result in the processes letting go of the devices, so you wouldn't neccessarily actually get to enter the runtime idle state as a result. Hmm. I'll think about this.

They don't let go of the devices if you suspend either. If you want that you need active cooperation from user space. In fact if you suspend you give drivers the guarantee of not getting any output without prior notification, making their lives easier.

Regards
Oliver

#53 lore raw
In reply to Matthew Garrett
Quoted 8 lines · On Tue, 17 Feb 2009 14:51:41 +0000 Matthew Garrett <[email protected]> wrote:
Quoted 5 lines · Arjan van de Ven

actually with powertop... on the open source side things are actually won. It took all of 6 months...
I don't see that as a valid excuse. In fact, if this kind of solution makes real userspace scheduled timers to be missed then I consider it a serious functionality misfeature.

Quoted 5 lines

Remember that Android has an open marketplace designed to appeal to Java programmers - users are going to end up downloading code from there and then blaming the platform if their battery life heads towards zero. I think "We can't trust our userland not to be dumb" is a valid concern.

so use range timers / timer slack for those apps that you do not trust. That is not a big deal, and solves the issue of timer wakeups...

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#54 lore raw
In reply to Matthew Garrett
Quoted 8 lines · On Tue, 17 Feb 2009 14:51:41 +0000 Matthew Garrett <[email protected]> wrote:
Quoted 5 lines · Arjan van de Ven

actually with powertop... on the open source side things are actually won. It took all of 6 months...
I don't see that as a valid excuse. In fact, if this kind of solution makes real userspace scheduled timers to be missed then I consider it a serious functionality misfeature.

Quoted 5 lines

Remember that Android has an open marketplace designed to appeal to Java programmers - users are going to end up downloading code from there and then blaming the platform if their battery life heads towards zero. I think "We can't trust our userland not to be dumb" is a valid concern.

so use range timers / timer slack for those apps that you do not trust. That is not a big deal, and solves the issue of timer wakeups...

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#48 lore raw
In reply to Matthew Garrett

Am Tuesday 17 February 2009 15:24:53 schrieb Matthew Garrett:

Quoted 8 lines · Brian Swetland
Quoted 6 lines

Of course that still doesn't address userspace. Aggressively going to suspend lets us compensate for userspace programs that do somewhat silly things (I agree that it would be best if they didn't but they do and getting *everyone* to write their userspace code to avoid spinning or avoid waking up on short-duration timers to poll is a losing battle).

Quoted 5 lines

Like Pavel pointed out, you could (in principle) handle this by sending a SIGSTOP to everything. The obvious problem with doing so is that this wouldn't result in the processes letting go of the devices, so you wouldn't neccessarily actually get to enter the runtime idle state as a result. Hmm. I'll think about this.

They don't let go of the devices if you suspend either. If you want that you need active cooperation from user space. In fact if you suspend you give drivers the guarantee of not getting any output without prior notification, making their lives easier.

Regards
Oliver

#73 lore raw
In reply to Matthew Garrett

Hi,

Quoted 6 lines · ext Matthew Garrett

On Tue, Feb 17, 2009 at 06:46:30AM -0800, Arjan van de Ven wrote:

Remember that Android has an open marketplace designed to appeal to Java programmers - users are going to end up downloading code from there and then blaming the platform if their battery life heads towards zero. I think "We can't trust our userland not to be dumb" is a valid concern.

It took few years of preaching but eventually our (admittedly small) userbase did start to see the truth and not blame the platform but rather the applications they had installed on top of it.

Powertop is a good tool.

Maybe slamming a nice GUI on top of that would turn all the userbase into a horde of bug reporters for the offending apps.

Or maybe it's just wishful thinking .... :)

Signature · 6 lines
Cheers, Igor

---

Igor Stoppa
Maemo Software - Nokia Devices R&D - Helsinki
#74 lore raw
In reply to Matthew Garrett

Hi,

Quoted 6 lines · ext Matthew Garrett

On Tue, Feb 17, 2009 at 06:46:30AM -0800, Arjan van de Ven wrote:

Remember that Android has an open marketplace designed to appeal to Java programmers - users are going to end up downloading code from there and then blaming the platform if their battery life heads towards zero. I think "We can't trust our userland not to be dumb" is a valid concern.

It took few years of preaching but eventually our (admittedly small) userbase did start to see the truth and not blame the platform but rather the applications they had installed on top of it.

Powertop is a good tool.

Maybe slamming a nice GUI on top of that would turn all the userbase into a horde of bug reporters for the offending apps.

Or maybe it's just wishful thinking .... :)

Signature · 6 lines
Cheers, Igor

---

Igor Stoppa
Maemo Software - Nokia Devices R&D - Helsinki
#75 lore raw
In reply to Arjan van de Ven

[Arjan van de Ven <[email protected]>]

Quoted 10 lines
Quoted 6 lines · On Tue, 17 Feb 2009 06:20:01 -0800 Brian Swetland <[email protected]> wrote:

Of course that still doesn't address userspace. Aggressively going to suspend lets us compensate for userspace programs that do somewhat silly things (I agree that it would be best if they didn't but they do and getting *everyone* to write their userspace code to avoid spinning or avoid waking up on short-duration timers to poll is a losing battle).

Quoted 5 lines

actually with powertop... on the open source side things are actually won. It took all of 6 months...
I don't see that as a valid excuse. In fact, if this kind of solution makes real userspace scheduled timers to be missed then I consider it a serious functionality misfeature.

While you can't expect the kernel to solve all the problems of userspace, here's the broad situation one could end up in (note this specific sequence is generic and not based on any one specific product experience):

- carrier deploys a device
- carrier agrees to allow installation of arbitrary third party apps without some horrible certification program requiring app authors to jump through hoops, wait ages for approval, etc
- users rejoice and install all kinds of apps
- some apps are poorly written and impact battery life
- users complain to carrier about battery life

You will end up with some crappy apps that do really dumb things. However, even if they're badly written users may still install and use these apps because hey, they do something the user likes.

Quoted 1 line

From the Android standpoint, we're trying to balance protecting the

system from poorly designed apps and somehow letting the user know "hey app X is chewing up a lot of power" (work in progress on this).

While I'd love for every app developer to actively tune their apps for a good mobile experience, I am skeptical that this is going to happen.

Brian

#76 lore raw
In reply to Arjan van de Ven

[Arjan van de Ven <[email protected]>]

Quoted 10 lines
Quoted 6 lines · On Tue, 17 Feb 2009 06:20:01 -0800 Brian Swetland <[email protected]> wrote:

Of course that still doesn't address userspace. Aggressively going to suspend lets us compensate for userspace programs that do somewhat silly things (I agree that it would be best if they didn't but they do and getting *everyone* to write their userspace code to avoid spinning or avoid waking up on short-duration timers to poll is a losing battle).

Quoted 5 lines

actually with powertop... on the open source side things are actually won. It took all of 6 months...
I don't see that as a valid excuse. In fact, if this kind of solution makes real userspace scheduled timers to be missed then I consider it a serious functionality misfeature.

While you can't expect the kernel to solve all the problems of userspace, here's the broad situation one could end up in (note this specific sequence is generic and not based on any one specific product experience):

- carrier deploys a device
- carrier agrees to allow installation of arbitrary third party apps without some horrible certification program requiring app authors to jump through hoops, wait ages for approval, etc
- users rejoice and install all kinds of apps
- some apps are poorly written and impact battery life
- users complain to carrier about battery life

You will end up with some crappy apps that do really dumb things. However, even if they're badly written users may still install and use these apps because hey, they do something the user likes.

Quoted 1 line

From the Android standpoint, we're trying to balance protecting the

system from poorly designed apps and somehow letting the user know "hey app X is chewing up a lot of power" (work in progress on this).

While I'd love for every app developer to actively tune their apps for a good mobile experience, I am skeptical that this is going to happen.

Brian

#55 lore raw
In reply to Arjan van de Ven
Quoted 14 lines

From: Arjan van de Ven [mailto:[email protected]]
Sent: Tuesday, February 17, 2009 8:56 AM

Quoted 7 lines · On Tue, 17 Feb 2009 14:51:41 +0000 Matthew Garrett <[email protected]> wrote:
Quoted 5 lines · Arjan van de Ven

actually with powertop... on the open source side things are actually won. It took all of 6 months...
I don't see that as a valid excuse. In fact, if this kind of solution makes real userspace scheduled timers to be missed then I consider it a serious functionality misfeature.

Maybe for the optimization time scales x86 is targeting. User space across OS still throws off our MHz a good distance from ideal estimates.

I still hear complaints about frequent wakes even when using a bare minimum user space which can get 95+% lowest C-state residency with average 700mS. If you frequency scale in lowest C-State YMMV if your external power chip is slow. Waiting on voltage ramp times is lost power.

One of our Application people (application is low level here) went though and tweaked kernel in a few spots with minimum user space and could get (this is with out a meaningful UI on NFS root mounted system):

1st set of hacks got:
Cn Avg residency
C0 (cpu running) ( 0.0%)
C1 0.0ms ( 0.0%)
C2 0.0ms ( 0.0%)
C3 217.2ms ( 1.8%)
C4 0.0ms ( 0.0%)
C5 0.0ms ( 0.0%)
C6 354.9ms ( 0.3%)
C7 1953.4ms (97.8%)

Second set got:

# powertop -d -t 300
PowerTOP 1.10 (C) 2007 Intel Corporation
Collecting data for 300 seconds
Cn Avg residency
C0 (cpu running) ( 0.0%)
C1 0.0ms ( 0.0%)
C2 0.2ms ( 0.0%)
C3 3.8ms ( 0.0%)
C4 0.0ms ( 0.0%)
C5 0.0ms ( 0.0%)
C6 0.0ms ( 0.0%)
C7 73165.9ms (100.0%)

I'll see about posting his change write up. Not all probably can be done but several could.

Quoted 8 lines
Quoted 5 lines

Remember that Android has an open marketplace designed to appeal to Java programmers - users are going to end up downloading code from there and then blaming the platform if their battery life heads towards zero. I think "We can't trust our userland not to be dumb" is a valid concern.

so use range timers / timer slack for those apps that you do not trust. That is not a big deal, and solves the issue of timer wakeups...

I not so sure it is that straight forward in practice. End systems integrate a lot of 3rd party software who view performance 1st and have no thought of power.

It might be android has a better chance to control more of those api's being exported but its coverage isn't complete and others gluing pieces together won't.

Regards,
Richard W.

#56 lore raw
In reply to Arjan van de Ven
Quoted 14 lines

From: Arjan van de Ven [mailto:[email protected]]
Sent: Tuesday, February 17, 2009 8:56 AM

Quoted 7 lines · On Tue, 17 Feb 2009 14:51:41 +0000 Matthew Garrett <[email protected]> wrote:
Quoted 5 lines · Arjan van de Ven

actually with powertop... on the open source side things are actually won. It took all of 6 months...
I don't see that as a valid excuse. In fact, if this kind of solution makes real userspace scheduled timers to be missed then I consider it a serious functionality misfeature.

Maybe for the optimization time scales x86 is targeting. User space across OS still throws off our MHz a good distance from ideal estimates.

I still hear complaints about frequent wakes even when using a bare minimum user space which can get 95+% lowest C-state residency with average 700mS. If you frequency scale in lowest C-State YMMV if your external power chip is slow. Waiting on voltage ramp times is lost power.

One of our Application people (application is low level here) went though and tweaked kernel in a few spots with minimum user space and could get (this is with out a meaningful UI on NFS root mounted system):

1st set of hacks got:
Cn Avg residency
C0 (cpu running) ( 0.0%)
C1 0.0ms ( 0.0%)
C2 0.0ms ( 0.0%)
C3 217.2ms ( 1.8%)
C4 0.0ms ( 0.0%)
C5 0.0ms ( 0.0%)
C6 354.9ms ( 0.3%)
C7 1953.4ms (97.8%)

Second set got:

# powertop -d -t 300
PowerTOP 1.10 (C) 2007 Intel Corporation
Collecting data for 300 seconds
Cn Avg residency
C0 (cpu running) ( 0.0%)
C1 0.0ms ( 0.0%)
C2 0.2ms ( 0.0%)
C3 3.8ms ( 0.0%)
C4 0.0ms ( 0.0%)
C5 0.0ms ( 0.0%)
C6 0.0ms ( 0.0%)
C7 73165.9ms (100.0%)

I'll see about posting his change write up. Not all probably can be done but several could.

Quoted 8 lines
Quoted 5 lines

Remember that Android has an open marketplace designed to appeal to Java programmers - users are going to end up downloading code from there and then blaming the platform if their battery life heads towards zero. I think "We can't trust our userland not to be dumb" is a valid concern.

so use range timers / timer slack for those apps that you do not trust. That is not a big deal, and solves the issue of timer wakeups...

I not so sure it is that straight forward in practice. End systems integrate a lot of 3rd party software who view performance 1st and have no thought of power.

It might be android has a better chance to control more of those api's being exported but its coverage isn't complete and others gluing pieces together won't.

Regards,
Richard W.

#359 lore raw
In reply to Matthew Garrett
Quoted 6 lines · Matthew Garrett
Quoted 3 lines · Pavel Machek

If no devices are being used, and next wakeup is far enough in the future, just put system to sleep. Long enough == so far away that suspend/wakeup is short compared to that... like 20 seconds on PC.

Quoted 7 lines

This is intrinsically difficult with PCs, since we have such a poorly defined set of wakeup events. We can't wakeup on generic network traffic, just WoL. Many machines won't wake up on keyboard events. Meanwhile, on embedded it's becoming a less interesting problem because idle and suspended are often now equivalent states. Concentrating on runtime PM of as much hardware as possible is arguably more interesting for the majority of use cases.

Putting the wake on key event issue aside, is it possible to have wake up's on the ms time scale? I ask because I thought the XO did exactly this (but left the screen live). Why does it take 20 sec to get into or out of S3 on my laptop?

--mgross

Quoted 3 lines
Signature · 2 lines
-- 
Matthew Garrett | [email protected]
#370 lore raw
In reply to Matthew Garrett
Quoted 6 lines · Matthew Garrett
Quoted 3 lines · Pavel Machek

If no devices are being used, and next wakeup is far enough in the future, just put system to sleep. Long enough == so far away that suspend/wakeup is short compared to that... like 20 seconds on PC.

Quoted 7 lines

This is intrinsically difficult with PCs, since we have such a poorly defined set of wakeup events. We can't wakeup on generic network traffic, just WoL. Many machines won't wake up on keyboard events. Meanwhile, on embedded it's becoming a less interesting problem because idle and suspended are often now equivalent states. Concentrating on runtime PM of as much hardware as possible is arguably more interesting for the majority of use cases.

Putting the wake on key event issue aside, is it possible to have wake up's on the ms time scale? I ask because I thought the XO did exactly this (but left the screen live). Why does it take 20 sec to get into or out of S3 on my laptop?

--mgross

Quoted 3 lines
Signature · 2 lines
-- 
Matthew Garrett | [email protected]
#360 lore raw
In reply to mark gross
Quoted 4 lines · mark gross

Putting the wake on key event issue aside, is it possible to have wake up's on the ms time scale? I ask because I thought the XO did exactly this (but left the screen live). Why does it take 20 sec to get into or out of S3 on my laptop?

Graphics reinit, dumping graphics contents back into RAM, us resuming devices in series, that kind of thing. On some hardware you'll spend a noticable amount of time in the BIOS before any of the Linux resume code gets touched. I thought the XO had got sub second, but I wasn't sure that they were in the low ms range.

Signature · 1 line
Matthew Garrett | [email protected]
#361 lore raw
In reply to mark gross
Quoted 4 lines · mark gross

Putting the wake on key event issue aside, is it possible to have wake up's on the ms time scale? I ask because I thought the XO did exactly this (but left the screen live). Why does it take 20 sec to get into or out of S3 on my laptop?

Graphics reinit, dumping graphics contents back into RAM, us resuming devices in series, that kind of thing. On some hardware you'll spend a noticable amount of time in the BIOS before any of the Linux resume code gets touched. I thought the XO had got sub second, but I wasn't sure that they were in the low ms range.

Signature · 1 line
Matthew Garrett | [email protected]
#362 lore raw
Quoted 11 lines · Matthew Garrett
Quoted 4 lines · mark gross

Putting the wake on key event issue aside, is it possible to have wake up's on the ms time scale? I ask because I thought the XO did exactly this (but left the screen live). Why does it take 20 sec to get into or out of S3 on my laptop?

Graphics reinit, dumping graphics contents back into RAM, us resuming devices in series, that kind of thing. On some hardware you'll spend a noticable amount of time in the BIOS before any of the Linux resume code gets touched. I thought the XO had got sub second, but I wasn't sure that they were in the low ms range.

IME a good chunk of it is BIOS time. On my x200s resume is very fast (on the order of a second or two though I haven't measured), while on my Eee and T61 machines it's much slower, even though they're all using Intel gfx.

Of course we should really be shooting for sub-second times or about the time it takes you to open your lid (or even much faster in the case of demand suspend/resume for servers/desktops).

Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center
#363 lore raw
In reply to Matthew Garrett
Quoted 11 lines · Matthew Garrett
Quoted 4 lines · mark gross

Putting the wake on key event issue aside, is it possible to have wake up's on the ms time scale? I ask because I thought the XO did exactly this (but left the screen live). Why does it take 20 sec to get into or out of S3 on my laptop?

Graphics reinit, dumping graphics contents back into RAM, us resuming devices in series, that kind of thing. On some hardware you'll spend a noticable amount of time in the BIOS before any of the Linux resume code gets touched. I thought the XO had got sub second, but I wasn't sure that they were in the low ms range.

IME a good chunk of it is BIOS time. On my x200s resume is very fast (on the order of a second or two though I haven't measured), while on my Eee and T61 machines it's much slower, even though they're all using Intel gfx.

Of course we should really be shooting for sub-second times or about the time it takes you to open your lid (or even much faster in the case of demand suspend/resume for servers/desktops).

Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center
#111 lore raw
In reply to Alan Stern
Quoted 9 lines · Alan Stern
Quoted 3 lines · Rafael J. Wysocki

Phase 1: I agree that system-auto-suspend-on, system-auto-suspend-off would be useful, but I don't like the wakelocks interface. Do you think there is an alternative way/mechanism of doing this?

I rather like the suggestions Matthew Garrett has been making. They show how to improve the wakelock interface without losing any function.

Quoted 8 lines

Really, the idea behind wakelocks comes down to the question of how to determine when the system is sufficiently idle to go into auto-suspend. There may be occasions when no task is runnable but userspace knows that the system should not go to sleep because some work will be done in the near future. (Arve's example of a non-empty input buffer is such a case.) How should userspace let the kernel know whether it's okay to suspend at these times? That is the problem userspace wakelocks are meant to solve.

Still, do we really need multiple user space wakelocks (I'd prefer to call them sleeplocks)? It seems that one such lock and a user space manager controlling it should be sufficient.

Quoted 3 lines

Kernel wakelocks are a separate matter. They are more like a form of optimization, preventing the kernel from starting an auto-suspend when some driver knows beforehand that it will return -EBUSY.

I think kernel-side autosuspend (or rather autosleep) should only happen after certain subset of devices have been suspended using a per-device run-time autosuspend mechanism.

Quoted 6 lines
Quoted 1 line

Phase 3: Probably explicit control left to open/close.

While that's generally a good idea, it's important to recognize that some devices should be runtime-suspended even while they are open.

From the kernel side, yes (and that should be transparent to the user space

having them open). By the user space, no.

Quoted 4 lines

Basically, any device that is "always open" falls in this category. Some examples are the screen, the keyboard, the mouse, and disk drives. And of course, some of these things already have runtime power management.

Thanks,
Rafael

#112 lore raw
In reply to Alan Stern
Quoted 9 lines · Alan Stern
Quoted 3 lines · Rafael J. Wysocki

Phase 1: I agree that system-auto-suspend-on, system-auto-suspend-off would be useful, but I don't like the wakelocks interface. Do you think there is an alternative way/mechanism of doing this?

I rather like the suggestions Matthew Garrett has been making. They show how to improve the wakelock interface without losing any function.

Quoted 8 lines

Really, the idea behind wakelocks comes down to the question of how to determine when the system is sufficiently idle to go into auto-suspend. There may be occasions when no task is runnable but userspace knows that the system should not go to sleep because some work will be done in the near future. (Arve's example of a non-empty input buffer is such a case.) How should userspace let the kernel know whether it's okay to suspend at these times? That is the problem userspace wakelocks are meant to solve.

Still, do we really need multiple user space wakelocks (I'd prefer to call them sleeplocks)? It seems that one such lock and a user space manager controlling it should be sufficient.

Quoted 3 lines

Kernel wakelocks are a separate matter. They are more like a form of optimization, preventing the kernel from starting an auto-suspend when some driver knows beforehand that it will return -EBUSY.

I think kernel-side autosuspend (or rather autosleep) should only happen after certain subset of devices have been suspended using a per-device run-time autosuspend mechanism.

Quoted 6 lines
Quoted 1 line

Phase 3: Probably explicit control left to open/close.

While that's generally a good idea, it's important to recognize that some devices should be runtime-suspended even while they are open.

From the kernel side, yes (and that should be transparent to the user space

having them open). By the user space, no.

Quoted 4 lines

Basically, any device that is "always open" falls in this category. Some examples are the screen, the keyboard, the mouse, and disk drives. And of course, some of these things already have runtime power management.

Thanks,
Rafael

#322 lore raw
In reply to Alan Stern
Quoted 23 lines · Alan Stern
Quoted 11 lines · Rafael J. Wysocki
Quoted 8 lines · Alan Stern
Quoted 4 lines · Rafael J. Wysocki

OK, so I think there are two things that user space may be allowed to do as far as putting devices into low power states is concerned:
* disable/enable the automatic power management of the device (provided that the driver supports the automatic PM)

Set the automatic PM parameters (idle timeout, state to go to, etc.).

Yes. I'm not sure about the state part, though.

Maybe, maybe not. IMO it's too early to tell whether anyone will need this ability, so we shouldn't rule it out.

Quoted 6 lines
Quoted 5 lines

What about situations where we want to distinguish between the power state of the device itself and the power state of the link? For a disk drive we may want to power the link on and off quite a lot, as that has low latency, but spinning the disk up and down takes a long time and so should have a longer idle-time value.

Quoted 7 lines
Quoted 3 lines

Well, I'm not sure at the moment.

Do you have any suggestions?

Not very well fleshed-out ones. I've got a vague idea for allowing a disk to have a 3-level power arrangement: full power, link disabled but drive still spinning, and device suspended.

I was thinking about that too.

Quoted 4 lines

Arranging for automatic transitions among those states will be a little clumsy but it can be done. As an example of the clumsiness, this scheme requires that the drive has _two_ idle-timeout values, one for the link and one for the drive itself.

Well, this generally is the case for PCI devices supporting more than two power states.

Quoted 6 lines

Another possibility is to set up independent runtime PM for the transport and the device. This means allowing the possibility that the transport is suspended while its child (the device) is not. This is a little simpler (there's only one idle-timeout per device, since the link is treated as an independent device), but it violates the principle of never suspending a parent while there is an active child.

Well, I think the first approach would be better.

Thanks,
Rafael

#323 lore raw
In reply to Alan Stern
Quoted 23 lines · Alan Stern
Quoted 11 lines · Rafael J. Wysocki
Quoted 8 lines · Alan Stern
Quoted 4 lines · Rafael J. Wysocki

OK, so I think there are two things that user space may be allowed to do as far as putting devices into low power states is concerned:
* disable/enable the automatic power management of the device (provided that the driver supports the automatic PM)

Set the automatic PM parameters (idle timeout, state to go to, etc.).

Yes. I'm not sure about the state part, though.

Maybe, maybe not. IMO it's too early to tell whether anyone will need this ability, so we shouldn't rule it out.

Quoted 6 lines
Quoted 5 lines

What about situations where we want to distinguish between the power state of the device itself and the power state of the link? For a disk drive we may want to power the link on and off quite a lot, as that has low latency, but spinning the disk up and down takes a long time and so should have a longer idle-time value.

Quoted 7 lines
Quoted 3 lines

Well, I'm not sure at the moment.

Do you have any suggestions?

Not very well fleshed-out ones. I've got a vague idea for allowing a disk to have a 3-level power arrangement: full power, link disabled but drive still spinning, and device suspended.

I was thinking about that too.

Quoted 4 lines

Arranging for automatic transitions among those states will be a little clumsy but it can be done. As an example of the clumsiness, this scheme requires that the drive has _two_ idle-timeout values, one for the link and one for the drive itself.

Well, this generally is the case for PCI devices supporting more than two power states.

Quoted 6 lines

Another possibility is to set up independent runtime PM for the transport and the device. This means allowing the possibility that the transport is suspended while its child (the device) is not. This is a little simpler (there's only one idle-timeout per device, since the link is treated as an independent device), but it violates the principle of never suspending a parent while there is an active child.

Well, I think the first approach would be better.

Thanks,
Rafael

#364 lore raw
In reply to Jesse Barnes
Quoted 17 lines

From: Jesse Barnes [mailto:[email protected]]
Sent: Tuesday, February 17, 2009 4:19 PM

Quoted 11 lines · Matthew Garrett
Quoted 4 lines · mark gross

Putting the wake on key event issue aside, is it possible to have wake up's on the ms time scale? I ask because I thought the XO did exactly this (but left the screen live). Why does it take 20 sec to get into or out of S3 on my laptop?

Graphics reinit, dumping graphics contents back into RAM, us resuming devices in series, that kind of thing. On some hardware you'll spend a noticable amount of time in the BIOS before any of the Linux resume code gets touched. I thought the XO had got sub second, but I wasn't sure that they were in the low ms range.

Quoted 7 lines

IME a good chunk of it is BIOS time. On my x200s resume is very fast (on the order of a second or two though I haven't measured), while on my Eee and T61 machines it's much slower, even though they're all using Intel gfx.

Of course we should really be shooting for sub-second times or about the time it takes you to open your lid (or even much faster in the case of demand suspend/resume for servers/desktops).

This is good example of embedded ARM time scales not matching up with x86 ones. For OMAP3 our resumption from OFF mode (full SOC context lost) software budget was in the 10s of milliSeconds. There is no BIOS and we must generate most of the code.

As such very frequent fast OFF mode transitions are useful and possible. As I said in another part of the thread, the slow part is Voltage ramp time. Also clock setup time of external oscillator can be 5-10mS by itself.

This tight timing was the requirement of some modems which required a response ASAP when data was coming. Not every modem is so tight but some are.

Regards,
Richard W.

#365 lore raw
In reply to Jesse Barnes
Quoted 17 lines

From: Jesse Barnes [mailto:[email protected]]
Sent: Tuesday, February 17, 2009 4:19 PM

Quoted 11 lines · Matthew Garrett
Quoted 4 lines · mark gross

Putting the wake on key event issue aside, is it possible to have wake up's on the ms time scale? I ask because I thought the XO did exactly this (but left the screen live). Why does it take 20 sec to get into or out of S3 on my laptop?

Graphics reinit, dumping graphics contents back into RAM, us resuming devices in series, that kind of thing. On some hardware you'll spend a noticable amount of time in the BIOS before any of the Linux resume code gets touched. I thought the XO had got sub second, but I wasn't sure that they were in the low ms range.

Quoted 7 lines

IME a good chunk of it is BIOS time. On my x200s resume is very fast (on the order of a second or two though I haven't measured), while on my Eee and T61 machines it's much slower, even though they're all using Intel gfx.

Of course we should really be shooting for sub-second times or about the time it takes you to open your lid (or even much faster in the case of demand suspend/resume for servers/desktops).

This is good example of embedded ARM time scales not matching up with x86 ones. For OMAP3 our resumption from OFF mode (full SOC context lost) software budget was in the 10s of milliSeconds. There is no BIOS and we must generate most of the code.

As such very frequent fast OFF mode transitions are useful and possible. As I said in another part of the thread, the slow part is Voltage ramp time. Also clock setup time of external oscillator can be 5-10mS by itself.

This tight timing was the requirement of some modems which required a response ASAP when data was coming. Not every modem is so tight but some are.

Regards,
Richard W.

#57 lore raw
In reply to Woodruff, Richard
Quoted 7 lines · Richard
Quoted 3 lines

so use range timers / timer slack for those apps that you do not trust. That is not a big deal, and solves the issue of timer wakeups...

I not so sure it is that straight forward in practice. End systems integrate a lot of 3rd party software who view performance 1st and have no thought of power.

you know that with the range timers/slack, you can control the "rounding" of the timer of the application, right?
You can *directly* throttle the number of wakeups an application causes that way to a value you set.

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#58 lore raw
In reply to Woodruff, Richard
Quoted 7 lines · Richard
Quoted 3 lines

so use range timers / timer slack for those apps that you do not trust. That is not a big deal, and solves the issue of timer wakeups...

I not so sure it is that straight forward in practice. End systems integrate a lot of 3rd party software who view performance 1st and have no thought of power.

you know that with the range timers/slack, you can control the "rounding" of the timer of the application, right?
You can *directly* throttle the number of wakeups an application causes that way to a value you set.

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#59 lore raw
Quoted 7 lines
Quoted 4 lines · Richard
Quoted 3 lines

so use range timers / timer slack for those apps that you do not trust. That is not a big deal, and solves the issue of timer wakeups...

Quoted 6 lines
Quoted 3 lines

I not so sure it is that straight forward in practice. End systems integrate a lot of 3rd party software who view performance 1st and have no thought of power.

you know that with the range timers/slack, you can control the "rounding" of the timer of the application, right?

I've not explored user space for this.

Can on a per-application basis some controlling application cause timers of a target process to be rounded or is it global? Or do you need to link the new application to use special glib variants (as described in OLS papers a few years ago)?

Quoted 2 lines

You can *directly* throttle the number of wakeups an application causes that way to a value you set.

Are you talking about your work as seen in lwn.net summary?

http://lwn.net/Articles/296578/

Your change here does look like something which could be used to control timers. Don't you still need some dynamic way to set the fuzz/slack if its globally applied? It seems like you might want some timers precise and others fuzzy.

Would the holding of a wakelock or some activity counter be a good trigger for switching rounding time? If wakelocks held "minor adjustment" else "major adjustment"

Thanks for the good pointer assuming I understood it in quick scan.

Thanks,
Richard W.

#60 lore raw
In reply to Arjan van de Ven
Quoted 7 lines
Quoted 4 lines · Richard
Quoted 3 lines

so use range timers / timer slack for those apps that you do not trust. That is not a big deal, and solves the issue of timer wakeups...

Quoted 6 lines
Quoted 3 lines

I not so sure it is that straight forward in practice. End systems integrate a lot of 3rd party software who view performance 1st and have no thought of power.

you know that with the range timers/slack, you can control the "rounding" of the timer of the application, right?

I've not explored user space for this.

Can on a per-application basis some controlling application cause timers of a target process to be rounded or is it global? Or do you need to link the new application to use special glib variants (as described in OLS papers a few years ago)?

Quoted 2 lines

You can *directly* throttle the number of wakeups an application causes that way to a value you set.

Are you talking about your work as seen in lwn.net summary?

http://lwn.net/Articles/296578/

Your change here does look like something which could be used to control timers. Don't you still need some dynamic way to set the fuzz/slack if its globally applied? It seems like you might want some timers precise and others fuzzy.

Would the holding of a wakelock or some activity counter be a good trigger for switching rounding time? If wakelocks held "minor adjustment" else "major adjustment"

Thanks for the good pointer assuming I understood it in quick scan.

Thanks,
Richard W.

#375 lore raw
In reply to Rafael J. Wysocki
Quoted 7 lines · Rafael J. Wysocki

Hi,

The recent descussion about the Android PM patches sent by Arve shows that there is a need to introduce a mechanism allowing us to:
(1) automatically put the system as a whole into a sleep state (eg. suspend to RAM) when it is found to be "idle", where the meaning of "idle" has to be defined too,

Can a fast STR state be created for the generic kernel across architectures? Something that can go into and out of SRT in < 20ms? (I picked 20ms as that gives 50Hz screen refresh) I guess the XO does something like this between keystrokes.

Note: I don't know (but I should) if such a PM design popping into and out of STR at worst every 20ms is worth doing on IA but lets assume its not so bad for the sake of argument.

One could assume the system would be idle except for selects on HID events when operating in this mode.

Quoted 2 lines

(2) put given subset of devices into low power states whenever they are not used, without putting the entire system into a sleep state.

This is a driver deal to drop the hardware they control into lower power states. Give information for PM-QOS the drivers could do the right things here. (or should be able too)

Also how do we attempt to coordinate this with an automatic STR state?

How to coexist with user requested STR?

Do we need to more carefully define what STR really means? (I'm thinking we do)

Quoted 22 lines

To allow these two things to happen, the Andriod patches introduced the wakelocks with the associated infrastructure and the "early suspend" mechanism. However, quite a number of reviewers did not like these patches, for various reasons, so they cannot be regarded as generally acceptable. For this reason, I think, we should discuss the problem in detail from the beginning and try to find a solution that everyone interested will be comfortable with.

For this purpose, IMO, we should at least reach an agreement on what the kernel's and the userland's roles in (1) and (2) are going to be. There also are quite a few questions that need to be answered. For instance, what conditions are going to be used to decide whether or not the system is idle enough so that we can put it into a sleep state? How are we going to check these conditions? What is going to happen if one (or more) of them changes while a system-wide power transition (eg. suspend) is in progress? Are we going to allow the user space to take part in this and if so, to what extent? What mechanisms are going be used to put devices into low power states at run time (ie. before starting any system-wide power transition) and how are they going to be related to the suspend-resume infrastructure used during system-wide power transitions? The answers to these (and other related) questions will likely affect all of the future Linux PM developlent, so IMO this is a very important matter.

Quoted 2 lines

Opinions and comments welcome.

thank you for starting this FRD.

--mgross

Quoted 2 lines

Thanks,
Rafael

#378 lore raw
In reply to Rafael J. Wysocki
Quoted 7 lines · Rafael J. Wysocki

Hi,

The recent descussion about the Android PM patches sent by Arve shows that there is a need to introduce a mechanism allowing us to:
(1) automatically put the system as a whole into a sleep state (eg. suspend to RAM) when it is found to be "idle", where the meaning of "idle" has to be defined too,

Can a fast STR state be created for the generic kernel across architectures? Something that can go into and out of SRT in < 20ms? (I picked 20ms as that gives 50Hz screen refresh) I guess the XO does something like this between keystrokes.

Note: I don't know (but I should) if such a PM design popping into and out of STR at worst every 20ms is worth doing on IA but lets assume its not so bad for the sake of argument.

One could assume the system would be idle except for selects on HID events when operating in this mode.

Quoted 2 lines

(2) put given subset of devices into low power states whenever they are not used, without putting the entire system into a sleep state.

This is a driver deal to drop the hardware they control into lower power states. Give information for PM-QOS the drivers could do the right things here. (or should be able too)

Also how do we attempt to coordinate this with an automatic STR state?

How to coexist with user requested STR?

Do we need to more carefully define what STR really means? (I'm thinking we do)

Quoted 22 lines

To allow these two things to happen, the Andriod patches introduced the wakelocks with the associated infrastructure and the "early suspend" mechanism. However, quite a number of reviewers did not like these patches, for various reasons, so they cannot be regarded as generally acceptable. For this reason, I think, we should discuss the problem in detail from the beginning and try to find a solution that everyone interested will be comfortable with.

For this purpose, IMO, we should at least reach an agreement on what the kernel's and the userland's roles in (1) and (2) are going to be. There also are quite a few questions that need to be answered. For instance, what conditions are going to be used to decide whether or not the system is idle enough so that we can put it into a sleep state? How are we going to check these conditions? What is going to happen if one (or more) of them changes while a system-wide power transition (eg. suspend) is in progress? Are we going to allow the user space to take part in this and if so, to what extent? What mechanisms are going be used to put devices into low power states at run time (ie. before starting any system-wide power transition) and how are they going to be related to the suspend-resume infrastructure used during system-wide power transitions? The answers to these (and other related) questions will likely affect all of the future Linux PM developlent, so IMO this is a very important matter.

Quoted 2 lines

Opinions and comments welcome.

thank you for starting this FRD.

--mgross

Quoted 2 lines

Thanks,
Rafael

#366 lore raw
In reply to Jesse Barnes
Quoted 13 lines · Jesse Barnes
Quoted 11 lines · Matthew Garrett
Quoted 4 lines · mark gross

Putting the wake on key event issue aside, is it possible to have wake up's on the ms time scale? I ask because I thought the XO did exactly this (but left the screen live). Why does it take 20 sec to get into or out of S3 on my laptop?

Graphics reinit, dumping graphics contents back into RAM, us resuming devices in series, that kind of thing. On some hardware you'll spend a noticable amount of time in the BIOS before any of the Linux resume code gets touched. I thought the XO had got sub second, but I wasn't sure that they were in the low ms range.

Quoted 7 lines

IME a good chunk of it is BIOS time. On my x200s resume is very fast (on the order of a second or two though I haven't measured), while on my Eee and T61 machines it's much slower, even though they're all using Intel gfx.

Of course we should really be shooting for sub-second times or about the time it takes you to open your lid (or even much faster in the case of demand suspend/resume for servers/desktops).

yeah I was thinking vertical blank refresh times.

We would need a state where the graphics stayed on somehow too.

--mgross

#367 lore raw
In reply to Jesse Barnes
Quoted 13 lines · Jesse Barnes
Quoted 11 lines · Matthew Garrett
Quoted 4 lines · mark gross

Putting the wake on key event issue aside, is it possible to have wake up's on the ms time scale? I ask because I thought the XO did exactly this (but left the screen live). Why does it take 20 sec to get into or out of S3 on my laptop?

Graphics reinit, dumping graphics contents back into RAM, us resuming devices in series, that kind of thing. On some hardware you'll spend a noticable amount of time in the BIOS before any of the Linux resume code gets touched. I thought the XO had got sub second, but I wasn't sure that they were in the low ms range.

Quoted 7 lines

IME a good chunk of it is BIOS time. On my x200s resume is very fast (on the order of a second or two though I haven't measured), while on my Eee and T61 machines it's much slower, even though they're all using Intel gfx.

Of course we should really be shooting for sub-second times or about the time it takes you to open your lid (or even much faster in the case of demand suspend/resume for servers/desktops).

yeah I was thinking vertical blank refresh times.

We would need a state where the graphics stayed on somehow too.

--mgross

#91 lore raw
In reply to Matthew Garrett
Quoted 7 lines · Matthew Garrett
Quoted 4 lines · Rafael J. Wysocki

This, again, seems to be a bit x86-centric. :-) The Android people are telling us that on the hardware they deal with it does make sense to put the entire system to sleep even for relatively short periods of time, since the latencies involved are not too bad.

Quoted 6 lines

Arve said that the power state was equivalent in idle and suspend, but that they preferred suspend because it stopped any periodic timers. I'd be more interested in making sure that unnecessary timers aren't running than focusing on automatically entering system-wide suspend - Nokia have been managing this since 2005 with good results.

I think they where talking timers as hardware devices pulling electrons, not SW timers triggering wake ups. I guess the timer hardware could be running, and pulling power, even when not programmed to trigger any event or IRQ.

--mgross

#92 lore raw
In reply to Matthew Garrett
Quoted 7 lines · Matthew Garrett
Quoted 4 lines · Rafael J. Wysocki

This, again, seems to be a bit x86-centric. :-) The Android people are telling us that on the hardware they deal with it does make sense to put the entire system to sleep even for relatively short periods of time, since the latencies involved are not too bad.

Quoted 6 lines

Arve said that the power state was equivalent in idle and suspend, but that they preferred suspend because it stopped any periodic timers. I'd be more interested in making sure that unnecessary timers aren't running than focusing on automatically entering system-wide suspend - Nokia have been managing this since 2005 with good results.

I think they where talking timers as hardware devices pulling electrons, not SW timers triggering wake ups. I guess the timer hardware could be running, and pulling power, even when not programmed to trigger any event or IRQ.

--mgross

#63 lore raw
In reply to Arjan van de Ven
Quoted 7 lines · Arjan van de Ven
Quoted 4 lines · Richard
Quoted 3 lines

so use range timers / timer slack for those apps that you do not trust. That is not a big deal, and solves the issue of timer wakeups...

Quoted 9 lines
Quoted 3 lines

I not so sure it is that straight forward in practice. End systems integrate a lot of 3rd party software who view performance 1st and have no thought of power.

you know that with the range timers/slack, you can control the "rounding" of the timer of the application, right?
You can *directly* throttle the number of wakeups an application causes that way to a value you set.

As the application code is mostly managed it should be a slam dunk to make range timers work withing the android framework or Dalvik layers.

--mgross

#77 lore raw
In reply to Brian Swetland
Quoted 22 lines · Brian Swetland

[Arjan van de Ven <[email protected]>]

Quoted 10 lines
Quoted 6 lines · On Tue, 17 Feb 2009 06:20:01 -0800 Brian Swetland <[email protected]> wrote:

Of course that still doesn't address userspace. Aggressively going to suspend lets us compensate for userspace programs that do somewhat silly things (I agree that it would be best if they didn't but they do and getting *everyone* to write their userspace code to avoid spinning or avoid waking up on short-duration timers to poll is a losing battle).

Quoted 5 lines

actually with powertop... on the open source side things are actually won. It took all of 6 months...
I don't see that as a valid excuse. In fact, if this kind of solution makes real userspace scheduled timers to be missed then I consider it a serious functionality misfeature.

While you can't expect the kernel to solve all the problems of userspace, here's the broad situation one could end up in (note this specific sequence is generic and not based on any one specific product experience):

Quoted 7 lines

- carrier deploys a device
- carrier agrees to allow installation of arbitrary third party apps without some horrible certification program requiring app authors to jump through hoops, wait ages for approval, etc
- users rejoice and install all kinds of apps
- some apps are poorly written and impact battery life
- users complain to carrier about battery life

Carrier pushes ISV for fix app, and updates that don't suck are deployed.

Where is the problem?

--mgross

Quoted 13 lines

You will end up with some crappy apps that do really dumb things. However, even if they're badly written users may still install and use these apps because hey, they do something the user likes.

Quoted 1 line

From the Android standpoint, we're trying to balance protecting the

system from poorly designed apps and somehow letting the user know "hey app X is chewing up a lot of power" (work in progress on this).

While I'd love for every app developer to actively tune their apps for a good mobile experience, I am skeptical that this is going to happen.

Brian

#64 lore raw
In reply to Arjan van de Ven
Quoted 7 lines · Arjan van de Ven
Quoted 4 lines · Richard
Quoted 3 lines

so use range timers / timer slack for those apps that you do not trust. That is not a big deal, and solves the issue of timer wakeups...

Quoted 9 lines
Quoted 3 lines

I not so sure it is that straight forward in practice. End systems integrate a lot of 3rd party software who view performance 1st and have no thought of power.

you know that with the range timers/slack, you can control the "rounding" of the timer of the application, right?
You can *directly* throttle the number of wakeups an application causes that way to a value you set.

As the application code is mostly managed it should be a slam dunk to make range timers work withing the android framework or Dalvik layers.

--mgross

#78 lore raw
In reply to Brian Swetland
Quoted 22 lines · Brian Swetland

[Arjan van de Ven <[email protected]>]

Quoted 10 lines
Quoted 6 lines · On Tue, 17 Feb 2009 06:20:01 -0800 Brian Swetland <[email protected]> wrote:

Of course that still doesn't address userspace. Aggressively going to suspend lets us compensate for userspace programs that do somewhat silly things (I agree that it would be best if they didn't but they do and getting *everyone* to write their userspace code to avoid spinning or avoid waking up on short-duration timers to poll is a losing battle).

Quoted 5 lines

actually with powertop... on the open source side things are actually won. It took all of 6 months...
I don't see that as a valid excuse. In fact, if this kind of solution makes real userspace scheduled timers to be missed then I consider it a serious functionality misfeature.

While you can't expect the kernel to solve all the problems of userspace, here's the broad situation one could end up in (note this specific sequence is generic and not based on any one specific product experience):

Quoted 7 lines

- carrier deploys a device
- carrier agrees to allow installation of arbitrary third party apps without some horrible certification program requiring app authors to jump through hoops, wait ages for approval, etc
- users rejoice and install all kinds of apps
- some apps are poorly written and impact battery life
- users complain to carrier about battery life

Carrier pushes ISV for fix app, and updates that don't suck are deployed.

Where is the problem?

--mgross

Quoted 13 lines

You will end up with some crappy apps that do really dumb things. However, even if they're badly written users may still install and use these apps because hey, they do something the user likes.

Quoted 1 line

From the Android standpoint, we're trying to balance protecting the

system from poorly designed apps and somehow letting the user know "hey app X is chewing up a lot of power" (work in progress on this).

While I'd love for every app developer to actively tune their apps for a good mobile experience, I am skeptical that this is going to happen.

Brian

#79 lore raw
In reply to Brian Swetland
Quoted 11 lines

You will end up with some crappy apps that do really dumb things. However, even if they're badly written users may still install and use these apps because hey, they do something the user likes.

Quoted 1 line

From the Android standpoint, we're trying to balance protecting the

system from poorly designed apps and somehow letting the user know "hey app X is chewing up a lot of power" (work in progress on this).

While I'd love for every app developer to actively tune their apps for a good mobile experience, I am skeptical that this is going to happen.

One idea I've been toying around was to have powertune as some kind of background thingy, and have it pop an icon in the notification area when some app seems to behave badly (of course, defining "badly" is hard but heh...). IE. actively inform the user "this application is sucking the life out of your battery".

Cheers,
Ben.

#113 lore raw
In reply to Rafael J. Wysocki
Quoted 19 lines · Rafael J. Wysocki
Quoted 9 lines · Alan Stern
Quoted 3 lines · Rafael J. Wysocki

Phase 1: I agree that system-auto-suspend-on, system-auto-suspend-off would be useful, but I don't like the wakelocks interface. Do you think there is an alternative way/mechanism of doing this?

I rather like the suggestions Matthew Garrett has been making. They show how to improve the wakelock interface without losing any function.

Quoted 8 lines

Really, the idea behind wakelocks comes down to the question of how to determine when the system is sufficiently idle to go into auto-suspend. There may be occasions when no task is runnable but userspace knows that the system should not go to sleep because some work will be done in the near future. (Arve's example of a non-empty input buffer is such a case.) How should userspace let the kernel know whether it's okay to suspend at these times? That is the problem userspace wakelocks are meant to solve.

Quoted 3 lines

Still, do we really need multiple user space wakelocks (I'd prefer to call them sleeplocks)? It seems that one such lock and a user space manager controlling it should be sufficient.

Yes, we could have a user space manager that all userspace wakelocks go through, but it would have to start before any other processes that need wakelocks and it would need a blocking ipc mechanism. The wakelock api that is provided to android applications does all this, but it is only available to java code. Supporting multiple userspace wakelocks in the kernel is simpler than adding another userspace wakelock layer.

Quoted 7 lines
Quoted 3 lines

Kernel wakelocks are a separate matter. They are more like a form of optimization, preventing the kernel from starting an auto-suspend when some driver knows beforehand that it will return -EBUSY.

I think kernel-side autosuspend (or rather autosleep) should only happen after certain subset of devices have been suspended using a per-device run-time autosuspend mechanism.

When the last wakelock is released the task that we woke up to perform has finished. Why wait to re-enter suspend.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Phase 3: Probably explicit control left to open/close.

While that's generally a good idea, it's important to recognize that some devices should be runtime-suspended even while they are open.

From the kernel side, yes (and that should be transparent to the user space having them open). By the user space, no.

Allowing user space to suspend input devices while they are still open is useful. The user-space code that reads from the input devices does not need to know if the device is suspended or not, and the kernel cannot auto suspend input devices based on inactivity.

Signature · 1 line
Arve Hjønnevåg
#114 lore raw
In reply to Rafael J. Wysocki
Quoted 19 lines · Rafael J. Wysocki
Quoted 9 lines · Alan Stern
Quoted 3 lines · Rafael J. Wysocki

Phase 1: I agree that system-auto-suspend-on, system-auto-suspend-off would be useful, but I don't like the wakelocks interface. Do you think there is an alternative way/mechanism of doing this?

I rather like the suggestions Matthew Garrett has been making. They show how to improve the wakelock interface without losing any function.

Quoted 8 lines

Really, the idea behind wakelocks comes down to the question of how to determine when the system is sufficiently idle to go into auto-suspend. There may be occasions when no task is runnable but userspace knows that the system should not go to sleep because some work will be done in the near future. (Arve's example of a non-empty input buffer is such a case.) How should userspace let the kernel know whether it's okay to suspend at these times? That is the problem userspace wakelocks are meant to solve.

Quoted 3 lines

Still, do we really need multiple user space wakelocks (I'd prefer to call them sleeplocks)? It seems that one such lock and a user space manager controlling it should be sufficient.

Yes, we could have a user space manager that all userspace wakelocks go through, but it would have to start before any other processes that need wakelocks and it would need a blocking ipc mechanism. The wakelock api that is provided to android applications does all this, but it is only available to java code. Supporting multiple userspace wakelocks in the kernel is simpler than adding another userspace wakelock layer.

Quoted 7 lines
Quoted 3 lines

Kernel wakelocks are a separate matter. They are more like a form of optimization, preventing the kernel from starting an auto-suspend when some driver knows beforehand that it will return -EBUSY.

I think kernel-side autosuspend (or rather autosleep) should only happen after certain subset of devices have been suspended using a per-device run-time autosuspend mechanism.

When the last wakelock is released the task that we woke up to perform has finished. Why wait to re-enter suspend.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Phase 3: Probably explicit control left to open/close.

While that's generally a good idea, it's important to recognize that some devices should be runtime-suspended even while they are open.

From the kernel side, yes (and that should be transparent to the user space having them open). By the user space, no.

Allowing user space to suspend input devices while they are still open is useful. The user-space code that reads from the input devices does not need to know if the device is suspended or not, and the kernel cannot auto suspend input devices based on inactivity.

Signature · 1 line
Arve Hjønnevåg
#65 lore raw
In reply to Arjan van de Ven
Quoted 7 lines · Arjan van de Ven
Quoted 4 lines · Richard
Quoted 3 lines

so use range timers / timer slack for those apps that you do not trust. That is not a big deal, and solves the issue of timer wakeups...

Quoted 8 lines
Quoted 3 lines

I not so sure it is that straight forward in practice. End systems integrate a lot of 3rd party software who view performance 1st and have no thought of power.

you know that with the range timers/slack, you can control the "rounding" of the timer of the application, right?
You can *directly* throttle the number of wakeups an application causes that way to a value you set.

I thought the point of range timers was to align multiple timers so they wakeup at the same time, not to throttle individual timers.

Signature · 1 line
Arve Hjønnevåg
#66 lore raw
In reply to Arjan van de Ven
Quoted 7 lines · Arjan van de Ven
Quoted 4 lines · Richard
Quoted 3 lines

so use range timers / timer slack for those apps that you do not trust. That is not a big deal, and solves the issue of timer wakeups...

Quoted 8 lines
Quoted 3 lines

I not so sure it is that straight forward in practice. End systems integrate a lot of 3rd party software who view performance 1st and have no thought of power.

you know that with the range timers/slack, you can control the "rounding" of the timer of the application, right?
You can *directly* throttle the number of wakeups an application causes that way to a value you set.

I thought the point of range timers was to align multiple timers so they wakeup at the same time, not to throttle individual timers.

Signature · 1 line
Arve Hjønnevåg
#61 lore raw
In reply to Woodruff, Richard
Quoted 11 lines · Richard
Quoted 11 lines
Quoted 7 lines · Richard
Quoted 3 lines

so use range timers / timer slack for those apps that you do not trust. That is not a big deal, and solves the issue of timer wakeups...

I not so sure it is that straight forward in practice. End systems integrate a lot of 3rd party software who view performance 1st and have no thought of power.

Quoted 7 lines
Quoted 2 lines

you know that with the range timers/slack, you can control the "rounding" of the timer of the application, right?

I've not explored user space for this.

Can on a per-application basis some controlling application cause timers of a target process to be rounded or is it global?

it is actually per thread.. so rather fine grained

Quoted 3 lines

Or do you
need to link the new application to use special glib variants (as described in OLS papers a few years ago)?

no you can do it for 100% existing binary

Quoted 5 lines

Your change here does look like something which could be used to control timers. Don't you still need some dynamic way to set the fuzz/slack if its globally applied? It seems like you might want some timers precise and others fuzzy.

right now it's prctl() based. We have been looking for a good use case for making it per syscall.. but haven't found a convincing one yet.

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#62 lore raw
In reply to Woodruff, Richard
Quoted 11 lines · Richard
Quoted 11 lines
Quoted 7 lines · Richard
Quoted 3 lines

so use range timers / timer slack for those apps that you do not trust. That is not a big deal, and solves the issue of timer wakeups...

I not so sure it is that straight forward in practice. End systems integrate a lot of 3rd party software who view performance 1st and have no thought of power.

Quoted 7 lines
Quoted 2 lines

you know that with the range timers/slack, you can control the "rounding" of the timer of the application, right?

I've not explored user space for this.

Can on a per-application basis some controlling application cause timers of a target process to be rounded or is it global?

it is actually per thread.. so rather fine grained

Quoted 3 lines

Or do you
need to link the new application to use special glib variants (as described in OLS papers a few years ago)?

no you can do it for 100% existing binary

Quoted 5 lines

Your change here does look like something which could be used to control timers. Don't you still need some dynamic way to set the fuzz/slack if its globally applied? It seems like you might want some timers precise and others fuzzy.

right now it's prctl() based. We have been looking for a good use case for making it per syscall.. but haven't found a convincing one yet.

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#67 lore raw
In reply to Arve Hjønnevåg
Quoted 13 lines · On Tue, 17 Feb 2009 21:11:31 -0800 Arve Hjønnevåg <[email protected]> wrote:
Quoted 11 lines · Arjan van de Ven
Quoted 7 lines · Richard
Quoted 3 lines

so use range timers / timer slack for those apps that you do not trust. That is not a big deal, and solves the issue of timer wakeups...

I not so sure it is that straight forward in practice. End systems integrate a lot of 3rd party software who view performance 1st and have no thought of power.

Quoted 7 lines
Quoted 4 lines

you know that with the range timers/slack, you can control the "rounding" of the timer of the application, right?
You can *directly* throttle the number of wakeups an application causes that way to a value you set.

I thought the point of range timers was to align multiple timers so they wakeup at the same time, not to throttle individual timers.

it works both ways.

Signature · 7 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm
#68 lore raw
In reply to Arve Hjønnevåg
Quoted 13 lines · On Tue, 17 Feb 2009 21:11:31 -0800 Arve Hjønnevåg <[email protected]> wrote:
Quoted 11 lines · Arjan van de Ven
Quoted 7 lines · Richard
Quoted 3 lines

so use range timers / timer slack for those apps that you do not trust. That is not a big deal, and solves the issue of timer wakeups...

I not so sure it is that straight forward in practice. End systems integrate a lot of 3rd party software who view performance 1st and have no thought of power.

Quoted 7 lines
Quoted 4 lines

you know that with the range timers/slack, you can control the "rounding" of the timer of the application, right?
You can *directly* throttle the number of wakeups an application causes that way to a value you set.

I thought the point of range timers was to align multiple timers so they wakeup at the same time, not to throttle individual timers.

it works both ways.

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#324 lore raw
In reply to Rafael J. Wysocki

Am Wednesday 18 February 2009 00:26:53 schrieb Rafael J. Wysocki:

Quoted 8 lines
Quoted 6 lines

Another possibility is to set up independent runtime PM for the transport and the device.  This means allowing the possibility that the transport is suspended while its child (the device) is not.  This is a little simpler (there's only one idle-timeout per device, since the link is treated as an independent device), but it violates the principle of never suspending a parent while there is an active child.

Well, I think the first approach would be better.

I am afraid it wouldn't be. How do you deal with shared transports?

Regards
Oliver

#338 lore raw
In reply to Rafael J. Wysocki

Am Wednesday 18 February 2009 00:26:53 schrieb Rafael J. Wysocki:

Quoted 8 lines
Quoted 6 lines

Another possibility is to set up independent runtime PM for the transport and the device.  This means allowing the possibility that the transport is suspended while its child (the device) is not.  This is a little simpler (there's only one idle-timeout per device, since the link is treated as an independent device), but it violates the principle of never suspending a parent while there is an active child.

Well, I think the first approach would be better.

I am afraid it wouldn't be. How do you deal with shared transports?

Regards
Oliver

#325 lore raw
In reply to Oliver Neukum
Quoted 9 lines · On Wed, 18 Feb 2009 09:53:48 +0100 Oliver Neukum <[email protected]> wrote:

Am Wednesday 18 February 2009 00:26:53 schrieb Rafael J. Wysocki:

Quoted 8 lines
Quoted 7 lines

Another possibility is to set up independent runtime PM for the transport and the device.  This means allowing the possibility that the transport is suspended while its child (the device) is not.  This is a little simpler (there's only one idle-timeout per device, since the link is treated as an independent device), but it violates the principle of never suspending a parent while there is an active child.

Quoted 4 lines
Quoted 1 line

Well, I think the first approach would be better.

I am afraid it wouldn't be. How do you deal with shared transports?

realistically, something like this you need to design like this Step 1) Assume the hardware is smart and can do this for you on the fly,
but it might need guidance.
(For many busses there are platforms that do this)
Step 2) For hardware that is not smart, emulate the smartness in the
driver, with help of the subsystem. These two together have the right knowledge to make such decisions.

Signature · 7 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm
#326 lore raw
In reply to Oliver Neukum
Quoted 9 lines · On Wed, 18 Feb 2009 09:53:48 +0100 Oliver Neukum <[email protected]> wrote:

Am Wednesday 18 February 2009 00:26:53 schrieb Rafael J. Wysocki:

Quoted 8 lines
Quoted 7 lines

Another possibility is to set up independent runtime PM for the transport and the device.  This means allowing the possibility that the transport is suspended while its child (the device) is not.  This is a little simpler (there's only one idle-timeout per device, since the link is treated as an independent device), but it violates the principle of never suspending a parent while there is an active child.

Quoted 4 lines
Quoted 1 line

Well, I think the first approach would be better.

I am afraid it wouldn't be. How do you deal with shared transports?

realistically, something like this you need to design like this Step 1) Assume the hardware is smart and can do this for you on the fly,
but it might need guidance.
(For many busses there are platforms that do this)
Step 2) For hardware that is not smart, emulate the smartness in the
driver, with help of the subsystem. These two together have the right knowledge to make such decisions.

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#327 lore raw

Am Wednesday 18 February 2009 15:51:58 schrieb Arjan van de Ven:

Quoted 17 lines
Quoted 9 lines · On Wed, 18 Feb 2009 09:53:48 +0100 Oliver Neukum <[email protected]> wrote:

Am Wednesday 18 February 2009 00:26:53 schrieb Rafael J. Wysocki:

Quoted 8 lines
Quoted 7 lines

Another possibility is to set up independent runtime PM for the transport and the device.  This means allowing the possibility that the transport is suspended while its child (the device) is not.  This is a little simpler (there's only one idle-timeout per device, since the link is treated as an independent device), but it violates the principle of never suspending a parent while there is an active child.

Quoted 4 lines
Quoted 1 line

Well, I think the first approach would be better.

I am afraid it wouldn't be. How do you deal with shared transports?

Quoted 7 lines

realistically, something like this you need to design like this Step 1) Assume the hardware is smart and can do this for you on the fly,
but it might need guidance.
(For many busses there are platforms that do this)
Step 2) For hardware that is not smart, emulate the smartness in the
driver, with help of the subsystem. These two together have the right knowledge to make such decisions.

But the transport and the driver may be in different subsystems, e.g. usb storage.

Regards
Oliver

#335 lore raw
In reply to Arjan van de Ven

Am Wednesday 18 February 2009 15:51:58 schrieb Arjan van de Ven:

Quoted 17 lines
Quoted 9 lines · On Wed, 18 Feb 2009 09:53:48 +0100 Oliver Neukum <[email protected]> wrote:

Am Wednesday 18 February 2009 00:26:53 schrieb Rafael J. Wysocki:

Quoted 8 lines
Quoted 7 lines

Another possibility is to set up independent runtime PM for the transport and the device.  This means allowing the possibility that the transport is suspended while its child (the device) is not.  This is a little simpler (there's only one idle-timeout per device, since the link is treated as an independent device), but it violates the principle of never suspending a parent while there is an active child.

Quoted 4 lines
Quoted 1 line

Well, I think the first approach would be better.

I am afraid it wouldn't be. How do you deal with shared transports?

Quoted 7 lines

realistically, something like this you need to design like this Step 1) Assume the hardware is smart and can do this for you on the fly,
but it might need guidance.
(For many busses there are platforms that do this)
Step 2) For hardware that is not smart, emulate the smartness in the
driver, with help of the subsystem. These two together have the right knowledge to make such decisions.

But the transport and the driver may be in different subsystems, e.g. usb storage.

Regards
Oliver

_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm

#336 lore raw
In reply to Arjan van de Ven
Quoted 17 lines · Arjan van de Ven
Quoted 9 lines · On Wed, 18 Feb 2009 09:53:48 +0100 Oliver Neukum <[email protected]> wrote:

Am Wednesday 18 February 2009 00:26:53 schrieb Rafael J. Wysocki:

Quoted 8 lines
Quoted 7 lines

Another possibility is to set up independent runtime PM for the transport and the device.  This means allowing the possibility that the transport is suspended while its child (the device) is not.  This is a little simpler (there's only one idle-timeout per device, since the link is treated as an independent device), but it violates the principle of never suspending a parent while there is an active child.

Quoted 4 lines
Quoted 1 line

Well, I think the first approach would be better.

I am afraid it wouldn't be. How do you deal with shared transports?

Quoted 7 lines

realistically, something like this you need to design like this Step 1) Assume the hardware is smart and can do this for you on the fly,
but it might need guidance.
(For many busses there are platforms that do this)
Step 2) For hardware that is not smart, emulate the smartness in the
driver, with help of the subsystem. These two together have the right knowledge to make such decisions.

Arjan, you're missing the point. This part of the discussion is already focussed on your Step 2. The question we are concerned with
is: _How_ shall the driver and subsystem go about emulating the smartness?

Oliver's comment is a good one. The principle of not suspending a parent with active children has never been set in stone; with care we should be able to circumvent it.

Alan Stern

#337 lore raw
In reply to Arjan van de Ven
Quoted 17 lines · Arjan van de Ven
Quoted 9 lines · On Wed, 18 Feb 2009 09:53:48 +0100 Oliver Neukum <[email protected]> wrote:

Am Wednesday 18 February 2009 00:26:53 schrieb Rafael J. Wysocki:

Quoted 8 lines
Quoted 7 lines

Another possibility is to set up independent runtime PM for the transport and the device.  This means allowing the possibility that the transport is suspended while its child (the device) is not.  This is a little simpler (there's only one idle-timeout per device, since the link is treated as an independent device), but it violates the principle of never suspending a parent while there is an active child.

Quoted 4 lines
Quoted 1 line

Well, I think the first approach would be better.

I am afraid it wouldn't be. How do you deal with shared transports?

Quoted 7 lines

realistically, something like this you need to design like this Step 1) Assume the hardware is smart and can do this for you on the fly,
but it might need guidance.
(For many busses there are platforms that do this)
Step 2) For hardware that is not smart, emulate the smartness in the
driver, with help of the subsystem. These two together have the right knowledge to make such decisions.

Arjan, you're missing the point. This part of the discussion is already focussed on your Step 2. The question we are concerned with
is: _How_ shall the driver and subsystem go about emulating the smartness?

Oliver's comment is a good one. The principle of not suspending a parent with active children has never been set in stone; with care we should be able to circumvent it.

Alan Stern

#328 lore raw
In reply to Oliver Neukum
Quoted 2 lines · Oliver Neukum

But the transport and the driver may be in different subsystems, e.g. usb storage.

We would have to add a part of usb-storage into the SCSI subsystem, by creating a USB transport class. Perhaps this class could be shared with Firewire/IEEE1394.

Alan Stern

#329 lore raw
In reply to Oliver Neukum
Quoted 2 lines · Oliver Neukum

But the transport and the driver may be in different subsystems, e.g. usb storage.

We would have to add a part of usb-storage into the SCSI subsystem, by creating a USB transport class. Perhaps this class could be shared with Firewire/IEEE1394.

Alan Stern

#69 lore raw
In reply to Arjan van de Ven
Quoted 2 lines · Arjan van de Ven

so use range timers / timer slack for those apps that you do not trust. That is not a big deal, and solves the issue of timer wakeups...

So have userspace say something like "The screen is turned off now, change the timer precision on all untrusted userland to sub 10 seconds"? That would work.

Signature · 1 line
Matthew Garrett | [email protected]
#70 lore raw
In reply to Arjan van de Ven
Quoted 2 lines · Arjan van de Ven

so use range timers / timer slack for those apps that you do not trust. That is not a big deal, and solves the issue of timer wakeups...

So have userspace say something like "The screen is turned off now, change the timer precision on all untrusted userland to sub 10 seconds"? That would work.

Signature · 1 line
Matthew Garrett | [email protected]
#71 lore raw
Quoted 6 lines
Quoted 2 lines

so use range timers / timer slack for those apps that you do not trust. That is not a big deal, and solves the issue of timer wakeups...

So have userspace say something like "The screen is turned off now, change the timer precision on all untrusted userland to sub 10 seconds"? That would work.

I also made a similar comment in thread to Arjan yesterday.

He did respond saying there was a pctrl to hit this. If it's a big list it might be messy. Unless it can be global. Probably would be good to look at code rather than speculate.

#72 lore raw
In reply to Matthew Garrett
Quoted 6 lines
Quoted 2 lines

so use range timers / timer slack for those apps that you do not trust. That is not a big deal, and solves the issue of timer wakeups...

So have userspace say something like "The screen is turned off now, change the timer precision on all untrusted userland to sub 10 seconds"? That would work.

I also made a similar comment in thread to Arjan yesterday.

He did respond saying there was a pctrl to hit this. If it's a big list it might be messy. Unless it can be global. Probably would be good to look at code rather than speculate.

#330 lore raw
In reply to Alan Stern

Am Wednesday 18 February 2009 16:10:48 schrieb Alan Stern:

Quoted 8 lines · Oliver Neukum
Quoted 3 lines

But the transport and the driver may be in different subsystems, e.g. usb storage.

We would have to add a part of usb-storage into the SCSI subsystem, by creating a USB transport class. Perhaps this class could be shared with Firewire/IEEE1394.

That would be a specific solution. But the problem is generic. Take for example HID. Several drivers may share one transport, but the transport may be USB 2.0/3.0 or bluetooth.

Regards
Oliver

#331 lore raw
Quoted 6 lines · Oliver Neukum

Am Wednesday 18 February 2009 16:10:48 schrieb Alan Stern:

Quoted 5 lines · Oliver Neukum
Quoted 3 lines

But the transport and the driver may be in different subsystems, e.g. usb storage.

Quoted 7 lines
Quoted 3 lines

We would have to add a part of usb-storage into the SCSI subsystem, by creating a USB transport class. Perhaps this class could be shared with Firewire/IEEE1394.

That would be a specific solution. But the problem is generic. Take for example HID. Several drivers may share one transport, but the transport may be USB 2.0/3.0 or bluetooth.

In essence what you're saying is that we won't be able to do link-suspend for HID until something like HID transport classes (or something simpler, devoted specifically to runtime PM) is implemented. And likewise for other subsystems. I can't argue with this conclusion.

Alan Stern

#332 lore raw
In reply to Oliver Neukum
Quoted 6 lines · Oliver Neukum

Am Wednesday 18 February 2009 16:10:48 schrieb Alan Stern:

Quoted 5 lines · Oliver Neukum
Quoted 3 lines

But the transport and the driver may be in different subsystems, e.g. usb storage.

Quoted 7 lines
Quoted 3 lines

We would have to add a part of usb-storage into the SCSI subsystem, by creating a USB transport class. Perhaps this class could be shared with Firewire/IEEE1394.

That would be a specific solution. But the problem is generic. Take for example HID. Several drivers may share one transport, but the transport may be USB 2.0/3.0 or bluetooth.

In essence what you're saying is that we won't be able to do link-suspend for HID until something like HID transport classes (or something simpler, devoted specifically to runtime PM) is implemented. And likewise for other subsystems. I can't argue with this conclusion.

Alan Stern

#333 lore raw

Am Wednesday 18 February 2009 17:39:21 schrieb Alan Stern:

Quoted 4 lines

In essence what you're saying is that we won't be able to do link-suspend for HID until something like HID transport classes (or something simpler, devoted specifically to runtime PM) is implemented. And likewise for other subsystems.  I can't argue with this conclusion.

I'd say, if it has sensible operations, it is a device and should be in the tree as such.

Regards
Oliver

#334 lore raw
In reply to Alan Stern

Am Wednesday 18 February 2009 17:39:21 schrieb Alan Stern:

Quoted 4 lines

In essence what you're saying is that we won't be able to do link-suspend for HID until something like HID transport classes (or something simpler, devoted specifically to runtime PM) is implemented. And likewise for other subsystems.  I can't argue with this conclusion.

I'd say, if it has sensible operations, it is a device and should be in the tree as such.

Regards
Oliver

#368 lore raw
In reply to mark gross

Hi Mark,

Quoted 3 lines

Putting the wake on key event issue aside, is it possible to have wake up's on the ms time scale? I ask because I thought the XO did exactly this (but left the screen live).

We're currently at 890ms for suspend+resume with USB on, and 180ms for suspend+resume when booted "nousb". Anything done upstream to make the first number closer to the second one will be very valuable to us.

Quoted 1 line

Why does it take 20 sec to get into or out of S3 on my laptop?

We found that the SMM version of S3 in our original development BIOS also took that long. We switched to using Open Firmware, turned off ACPI, worked out exactly which registers to use to enter S3, and scheduled device reinitialization such that hardware-required delays (such as clock stabilization for our GPU) start in the right order to keep the critical path short.

The main difference was the switch away from the vendor BIOS, though -- we were seeing something like a five-second delay between Linux entering S3 and the hardware noticing and putting the system into suspend, for example. There's not much market pressure to write efficient EC code for suspend/resume. (Or, we discovered, to write EC code that's able to handle suspend/resume more than a hundred times per boot without crashing.)

- Chris.

Signature · 1 line
Chris Ball   <[email protected]>
#369 lore raw
In reply to mark gross

Hi Mark,

Quoted 3 lines

Putting the wake on key event issue aside, is it possible to have wake up's on the ms time scale? I ask because I thought the XO did exactly this (but left the screen live).

We're currently at 890ms for suspend+resume with USB on, and 180ms for suspend+resume when booted "nousb". Anything done upstream to make the first number closer to the second one will be very valuable to us.

Quoted 1 line

Why does it take 20 sec to get into or out of S3 on my laptop?

We found that the SMM version of S3 in our original development BIOS also took that long. We switched to using Open Firmware, turned off ACPI, worked out exactly which registers to use to enter S3, and scheduled device reinitialization such that hardware-required delays (such as clock stabilization for our GPU) start in the right order to keep the critical path short.

The main difference was the switch away from the vendor BIOS, though -- we were seeing something like a five-second delay between Linux entering S3 and the hardware noticing and putting the system into suspend, for example. There's not much market pressure to write efficient EC code for suspend/resume. (Or, we discovered, to write EC code that's able to handle suspend/resume more than a hundred times per boot without crashing.)

- Chris.

Signature · 1 line
Chris Ball   <[email protected]>
#80 lore raw
In reply to Benjamin Herrenschmidt
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 9 lines

You will end up with some crappy apps that do really dumb things. However, even if they're badly written users may still install and use these apps because hey, they do something the user likes.

Quoted 1 line

From the Android standpoint, we're trying to balance protecting the

system from poorly designed apps and somehow letting the user know "hey app X is chewing up a lot of power" (work in progress on this).

Quoted 8 lines
Quoted 2 lines

While I'd love for every app developer to actively tune their apps for a good mobile experience, I am skeptical that this is going to happen.

One idea I've been toying around was to have powertune as some kind of background thingy, and have it pop an icon in the notification area when some app seems to behave badly (of course, defining "badly" is hard but heh...). IE. actively inform the user "this application is sucking the life out of your battery".

I think "powernag" would be a better name, and it would probably work pretty well. Users would be notified that certain apps should probably be shut down while they're on battery, and nag the authors to fix it.

Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center
#81 lore raw
In reply to Benjamin Herrenschmidt
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 9 lines

You will end up with some crappy apps that do really dumb things. However, even if they're badly written users may still install and use these apps because hey, they do something the user likes.

Quoted 1 line

From the Android standpoint, we're trying to balance protecting the

system from poorly designed apps and somehow letting the user know "hey app X is chewing up a lot of power" (work in progress on this).

Quoted 8 lines
Quoted 2 lines

While I'd love for every app developer to actively tune their apps for a good mobile experience, I am skeptical that this is going to happen.

One idea I've been toying around was to have powertune as some kind of background thingy, and have it pop an icon in the notification area when some app seems to behave badly (of course, defining "badly" is hard but heh...). IE. actively inform the user "this application is sucking the life out of your battery".

I think "powernag" would be a better name, and it would probably work pretty well. Users would be notified that certain apps should probably be shut down while they're on battery, and nag the authors to fix it.

Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center
#82 lore raw
Quoted 3 lines · Jesse Barnes

I think "powernag" would be a better name, and it would probably work pretty well. Users would be notified that certain apps should probably be shut down while they're on battery, and nag the authors to fix it.

How do you usefully tell the difference between an application that's waking up a lot because it's dumb and an application that's waking up a lot because it's doing something useful? One downside of powertop is that it's resulted in a lot of "How do I reduce the number of wakeups caused by i8042 whenever I use the mouse"-type questions. We don't want innocent app writers to be hit by this kind of thing.

Signature · 1 line
Matthew Garrett | [email protected]
#83 lore raw
In reply to Jesse Barnes
Quoted 3 lines · Jesse Barnes

I think "powernag" would be a better name, and it would probably work pretty well. Users would be notified that certain apps should probably be shut down while they're on battery, and nag the authors to fix it.

How do you usefully tell the difference between an application that's waking up a lot because it's dumb and an application that's waking up a lot because it's doing something useful? One downside of powertop is that it's resulted in a lot of "How do I reduce the number of wakeups caused by i8042 whenever I use the mouse"-type questions. We don't want innocent app writers to be hit by this kind of thing.

Signature · 1 line
Matthew Garrett | [email protected]
#84 lore raw
Quoted 11 lines · Matthew Garrett
Quoted 3 lines · Jesse Barnes

I think "powernag" would be a better name, and it would probably work pretty well. Users would be notified that certain apps should probably be shut down while they're on battery, and nag the authors to fix it.

How do you usefully tell the difference between an application that's waking up a lot because it's dumb and an application that's waking up a lot because it's doing something useful? One downside of powertop is that it's resulted in a lot of "How do I reduce the number of wakeups caused by i8042 whenever I use the mouse"-type questions. We don't want innocent app writers to be hit by this kind of thing.

Well Ben did mention that it would be hard to figure out a good set of heuristics, but a userspace app could be pretty flexible, allowing the user to whitelist apps they know are fine, average the data over a period of time, etc. Challenging, sure, but it should be possible to come up with something that's useful in many cases.

Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center
#85 lore raw
In reply to Matthew Garrett
Quoted 11 lines · Matthew Garrett
Quoted 3 lines · Jesse Barnes

I think "powernag" would be a better name, and it would probably work pretty well. Users would be notified that certain apps should probably be shut down while they're on battery, and nag the authors to fix it.

How do you usefully tell the difference between an application that's waking up a lot because it's dumb and an application that's waking up a lot because it's doing something useful? One downside of powertop is that it's resulted in a lot of "How do I reduce the number of wakeups caused by i8042 whenever I use the mouse"-type questions. We don't want innocent app writers to be hit by this kind of thing.

Well Ben did mention that it would be hard to figure out a good set of heuristics, but a userspace app could be pretty flexible, allowing the user to whitelist apps they know are fine, average the data over a period of time, etc. Challenging, sure, but it should be possible to come up with something that's useful in many cases.

Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center
#376 lore raw
In reply to mark gross
Quoted 11 lines · mark gross
Quoted 7 lines · Rafael J. Wysocki

Hi,

The recent descussion about the Android PM patches sent by Arve shows that there is a need to introduce a mechanism allowing us to:
(1) automatically put the system as a whole into a sleep state (eg. suspend to RAM) when it is found to be "idle", where the meaning of "idle" has to be defined too,

Can a fast STR state be created for the generic kernel across architectures? Something that can go into and out of SRT in < 20ms?

I don't think it's generally doable on PCs.

Quoted 10 lines

(I picked 20ms as that gives 50Hz screen refresh) I guess the XO does something like this between keystrokes.

Note: I don't know (but I should) if such a PM design popping into and out of STR at worst every 20ms is worth doing on IA but lets assume its not so bad for the sake of argument.

One could assume the system would be idle except for selects on HID events when operating in this mode.

Quoted 6 lines
Quoted 2 lines

(2) put given subset of devices into low power states whenever they are not used, without putting the entire system into a sleep state.

This is a driver deal to drop the hardware they control into lower power states. Give information for PM-QOS the drivers could do the right things here. (or should be able too)

That may also depend on the bus the driver is on (like PCI for one example).

Quoted 1 line

Also how do we attempt to coordinate this with an automatic STR state?

That's one thing to think about. In principle we can avoid suspending devices that already are in low power states before a system-wide transition is started (caveat: wake-up devices on ACPI systems).

Quoted 4 lines

How to coexist with user requested STR?

Do we need to more carefully define what STR really means? (I'm thinking we do)

Well, yes and no. In fact ACPI defines STR as one of the system sleep states in which the CPU does not execute instructions, but the ACPI definition need not be applicable to non-ACPI platforms.

Quoted 22 lines
Quoted 22 lines

To allow these two things to happen, the Andriod patches introduced the wakelocks with the associated infrastructure and the "early suspend" mechanism. However, quite a number of reviewers did not like these patches, for various reasons, so they cannot be regarded as generally acceptable. For this reason, I think, we should discuss the problem in detail from the beginning and try to find a solution that everyone interested will be comfortable with.

For this purpose, IMO, we should at least reach an agreement on what the kernel's and the userland's roles in (1) and (2) are going to be. There also are quite a few questions that need to be answered. For instance, what conditions are going to be used to decide whether or not the system is idle enough so that we can put it into a sleep state? How are we going to check these conditions? What is going to happen if one (or more) of them changes while a system-wide power transition (eg. suspend) is in progress? Are we going to allow the user space to take part in this and if so, to what extent? What mechanisms are going be used to put devices into low power states at run time (ie. before starting any system-wide power transition) and how are they going to be related to the suspend-resume infrastructure used during system-wide power transitions? The answers to these (and other related) questions will likely affect all of the future Linux PM developlent, so IMO this is a very important matter.

Quoted 4 lines
Quoted 2 lines

Opinions and comments welcome.

thank you for starting this FRD.

No big deal. :-)

Thanks,
Rafael

#377 lore raw
In reply to mark gross
Quoted 11 lines · mark gross
Quoted 7 lines · Rafael J. Wysocki

Hi,

The recent descussion about the Android PM patches sent by Arve shows that there is a need to introduce a mechanism allowing us to:
(1) automatically put the system as a whole into a sleep state (eg. suspend to RAM) when it is found to be "idle", where the meaning of "idle" has to be defined too,

Can a fast STR state be created for the generic kernel across architectures? Something that can go into and out of SRT in < 20ms?

I don't think it's generally doable on PCs.

Quoted 10 lines

(I picked 20ms as that gives 50Hz screen refresh) I guess the XO does something like this between keystrokes.

Note: I don't know (but I should) if such a PM design popping into and out of STR at worst every 20ms is worth doing on IA but lets assume its not so bad for the sake of argument.

One could assume the system would be idle except for selects on HID events when operating in this mode.

Quoted 6 lines
Quoted 2 lines

(2) put given subset of devices into low power states whenever they are not used, without putting the entire system into a sleep state.

This is a driver deal to drop the hardware they control into lower power states. Give information for PM-QOS the drivers could do the right things here. (or should be able too)

That may also depend on the bus the driver is on (like PCI for one example).

Quoted 1 line

Also how do we attempt to coordinate this with an automatic STR state?

That's one thing to think about. In principle we can avoid suspending devices that already are in low power states before a system-wide transition is started (caveat: wake-up devices on ACPI systems).

Quoted 4 lines

How to coexist with user requested STR?

Do we need to more carefully define what STR really means? (I'm thinking we do)

Well, yes and no. In fact ACPI defines STR as one of the system sleep states in which the CPU does not execute instructions, but the ACPI definition need not be applicable to non-ACPI platforms.

Quoted 22 lines
Quoted 22 lines

To allow these two things to happen, the Andriod patches introduced the wakelocks with the associated infrastructure and the "early suspend" mechanism. However, quite a number of reviewers did not like these patches, for various reasons, so they cannot be regarded as generally acceptable. For this reason, I think, we should discuss the problem in detail from the beginning and try to find a solution that everyone interested will be comfortable with.

For this purpose, IMO, we should at least reach an agreement on what the kernel's and the userland's roles in (1) and (2) are going to be. There also are quite a few questions that need to be answered. For instance, what conditions are going to be used to decide whether or not the system is idle enough so that we can put it into a sleep state? How are we going to check these conditions? What is going to happen if one (or more) of them changes while a system-wide power transition (eg. suspend) is in progress? Are we going to allow the user space to take part in this and if so, to what extent? What mechanisms are going be used to put devices into low power states at run time (ie. before starting any system-wide power transition) and how are they going to be related to the suspend-resume infrastructure used during system-wide power transitions? The answers to these (and other related) questions will likely affect all of the future Linux PM developlent, so IMO this is a very important matter.

Quoted 4 lines
Quoted 2 lines

Opinions and comments welcome.

thank you for starting this FRD.

No big deal. :-)

Thanks,
Rafael

#115 lore raw
In reply to Arve Hjønnevåg
Quoted 36 lines · Arve Hjønnevåg
Quoted 19 lines · Rafael J. Wysocki
Quoted 9 lines · Alan Stern
Quoted 3 lines · Rafael J. Wysocki

Phase 1: I agree that system-auto-suspend-on, system-auto-suspend-off would be useful, but I don't like the wakelocks interface. Do you think there is an alternative way/mechanism of doing this?

I rather like the suggestions Matthew Garrett has been making. They show how to improve the wakelock interface without losing any function.

Quoted 8 lines

Really, the idea behind wakelocks comes down to the question of how to determine when the system is sufficiently idle to go into auto-suspend. There may be occasions when no task is runnable but userspace knows that the system should not go to sleep because some work will be done in the near future. (Arve's example of a non-empty input buffer is such a case.) How should userspace let the kernel know whether it's okay to suspend at these times? That is the problem userspace wakelocks are meant to solve.

Quoted 3 lines

Still, do we really need multiple user space wakelocks (I'd prefer to call them sleeplocks)? It seems that one such lock and a user space manager controlling it should be sufficient.

Yes, we could have a user space manager that all userspace wakelocks go through, but it would have to start before any other processes that need wakelocks and it would need a blocking ipc mechanism. The wakelock api that is provided to android applications does all this, but it is only available to java code. Supporting multiple userspace wakelocks in the kernel is simpler than adding another userspace wakelock layer.

Quoted 4 lines
Quoted 3 lines

Kernel wakelocks are a separate matter. They are more like a form of optimization, preventing the kernel from starting an auto-suspend when some driver knows beforehand that it will return -EBUSY.

Quoted 6 lines
Quoted 3 lines

I think kernel-side autosuspend (or rather autosleep) should only happen after certain subset of devices have been suspended using a per-device run-time autosuspend mechanism.

When the last wakelock is released the task that we woke up to perform has finished. Why wait to re-enter suspend.

I don't really understand this comment. Could you please explain a bit?

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 1 line

Phase 3: Probably explicit control left to open/close.

While that's generally a good idea, it's important to recognize that some devices should be runtime-suspended even while they are open.

Quoted 7 lines
Quoted 2 lines

From the kernel side, yes (and that should be transparent to the user space having them open). By the user space, no.

Allowing user space to suspend input devices while they are still open is useful. The user-space code that reads from the input devices does not need to know if the device is suspended or not, and the kernel cannot auto suspend input devices based on inactivity.

Hmm. Why can't it?

Rafael

#116 lore raw
In reply to Arve Hjønnevåg
Quoted 36 lines · Arve Hjønnevåg
Quoted 19 lines · Rafael J. Wysocki
Quoted 9 lines · Alan Stern
Quoted 3 lines · Rafael J. Wysocki

Phase 1: I agree that system-auto-suspend-on, system-auto-suspend-off would be useful, but I don't like the wakelocks interface. Do you think there is an alternative way/mechanism of doing this?

I rather like the suggestions Matthew Garrett has been making. They show how to improve the wakelock interface without losing any function.

Quoted 8 lines

Really, the idea behind wakelocks comes down to the question of how to determine when the system is sufficiently idle to go into auto-suspend. There may be occasions when no task is runnable but userspace knows that the system should not go to sleep because some work will be done in the near future. (Arve's example of a non-empty input buffer is such a case.) How should userspace let the kernel know whether it's okay to suspend at these times? That is the problem userspace wakelocks are meant to solve.

Quoted 3 lines

Still, do we really need multiple user space wakelocks (I'd prefer to call them sleeplocks)? It seems that one such lock and a user space manager controlling it should be sufficient.

Yes, we could have a user space manager that all userspace wakelocks go through, but it would have to start before any other processes that need wakelocks and it would need a blocking ipc mechanism. The wakelock api that is provided to android applications does all this, but it is only available to java code. Supporting multiple userspace wakelocks in the kernel is simpler than adding another userspace wakelock layer.

Quoted 4 lines
Quoted 3 lines

Kernel wakelocks are a separate matter. They are more like a form of optimization, preventing the kernel from starting an auto-suspend when some driver knows beforehand that it will return -EBUSY.

Quoted 6 lines
Quoted 3 lines

I think kernel-side autosuspend (or rather autosleep) should only happen after certain subset of devices have been suspended using a per-device run-time autosuspend mechanism.

When the last wakelock is released the task that we woke up to perform has finished. Why wait to re-enter suspend.

I don't really understand this comment. Could you please explain a bit?

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 1 line

Phase 3: Probably explicit control left to open/close.

While that's generally a good idea, it's important to recognize that some devices should be runtime-suspended even while they are open.

Quoted 7 lines
Quoted 2 lines

From the kernel side, yes (and that should be transparent to the user space having them open). By the user space, no.

Allowing user space to suspend input devices while they are still open is useful. The user-space code that reads from the input devices does not need to know if the device is suspended or not, and the kernel cannot auto suspend input devices based on inactivity.

Hmm. Why can't it?

Rafael

#86 lore raw
In reply to Matthew Garrett
Quoted 6 lines · Matthew Garrett
Quoted 3 lines · Jesse Barnes

I think "powernag" would be a better name, and it would probably work pretty well. Users would be notified that certain apps should probably be shut down while they're on battery, and nag the authors to fix it.

Quoted 6 lines

How do you usefully tell the difference between an application that's waking up a lot because it's dumb and an application that's waking up a lot because it's doing something useful? One downside of powertop is that it's resulted in a lot of "How do I reduce the number of wakeups caused by i8042 whenever I use the mouse"-type questions. We don't want innocent app writers to be hit by this kind of thing.

Which is why nagging might not be the best thing... One thing I quite liked was something i had on MacOS 9 which was a watt-meter. I could basically see at any time what my consumption was. If the needle wasn't all the way to the left while I was expecting it to, I would dig for the culprit.

Maybe we can try to do something similar, and when clicking on it, you get an ordered list of apps from the biggest consumer down).

The main problem of course is for that "meter" to work, one need to have an idea of what min and max are on a given machine... Absolute watt numbers or things like that are a lot less telling to Joe average.

Cheers,
Ben.

#117 lore raw
In reply to Rafael J. Wysocki
Quoted 8 lines · Rafael J. Wysocki
Quoted 7 lines · Arve Hjønnevåg
Quoted 6 lines · Rafael J. Wysocki
Quoted 3 lines · Alan Stern

Kernel wakelocks are a separate matter. They are more like a form of optimization, preventing the kernel from starting an auto-suspend when some driver knows beforehand that it will return -EBUSY.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

I think kernel-side autosuspend (or rather autosleep) should only happen after certain subset of devices have been suspended using a per-device run-time autosuspend mechanism.

When the last wakelock is released the task that we woke up to perform has finished. Why wait to re-enter suspend.

I don't really understand this comment. Could you please explain a bit?

If some devices are autosuspended after a local inactivity timeout, I don't want to wait for those devices to autosuspend if I know the code that needed to run is done. This could cause delays in the normal case, and it could prevent suspend if a background process (not using wakelocks) is accessing a disk more frequently than its idle timeout.

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Phase 3: Probably explicit control left to open/close.

While that's generally a good idea, it's important to recognize that some devices should be runtime-suspended even while they are open.

From the kernel side, yes (and that should be transparent to the user space having them open). By the user space, no.

Quoted 6 lines
Quoted 4 lines

Allowing user space to suspend input devices while they are still open is useful. The user-space code that reads from the input devices does not need to know if the device is suspended or not, and the kernel cannot auto suspend input devices based on inactivity.

Hmm. Why can't it?

Because they stop working. It is OK for us to turn off the touchscreen when the screen is off, but when the screen is on the user will touch items on the screen and expect them to respond. (We could also turn off the touchscreen when the keyguard is on, but we don't currently do this.)

Signature · 1 line
Arve Hjønnevåg
#118 lore raw

Am Wednesday 18 February 2009 23:35:26 schrieb Arve Hjønnevåg:

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

Allowing user space to suspend input devices while they are still open is useful. The user-space code that reads from the input devices does not need to know if the device is suspended or not, and the kernel cannot auto suspend input devices based on inactivity.

Quoted 7 lines
Quoted 1 line

Hmm.  Why can't it?

Because they stop working. It is OK for us to turn off the touchscreen when the screen is off, but when the screen is on the user will touch items on the screen and expect them to respond. (We could also turn off the touchscreen when the keyguard is on, but we don't currently do this.)

This depends on the capabilities of the input device in question. Some USB keyboards can be autosuspended under these conditions because they can do remote wakeup.

Regards
Oliver

#119 lore raw
In reply to Arve Hjønnevåg
Quoted 16 lines · Arve Hjønnevåg
Quoted 15 lines · Rafael J. Wysocki
Quoted 13 lines · Arve Hjønnevåg
Quoted 9 lines · Rafael J. Wysocki
Quoted 3 lines · Alan Stern

Kernel wakelocks are a separate matter. They are more like a form of optimization, preventing the kernel from starting an auto-suspend when some driver knows beforehand that it will return -EBUSY.

I think kernel-side autosuspend (or rather autosleep) should only happen after certain subset of devices have been suspended using a per-device run-time autosuspend mechanism.

When the last wakelock is released the task that we woke up to perform has finished. Why wait to re-enter suspend.

Quoted 6 lines
Quoted 1 line

I don't really understand this comment. Could you please explain a bit?

If some devices are autosuspended after a local inactivity timeout, I don't want to wait for those devices to autosuspend if I know the code that needed to run is done. This could cause delays in the normal case,

Isn't it a matter of adjusting the inactivity timeouts in a suitable way?

Quoted 2 lines

and it could prevent suspend if a background process (not using wakelocks) is accessing a disk more frequently than its idle timeout.

Well, actually, shouldn't it prevent suspend from happening? Arguably, it just means that the disk is continuously being accessed with respect to the inactive timeout granularity.

Rafael

#120 lore raw
In reply to Arve Hjønnevåg
Quoted 16 lines · Arve Hjønnevåg
Quoted 15 lines · Rafael J. Wysocki
Quoted 13 lines · Arve Hjønnevåg
Quoted 9 lines · Rafael J. Wysocki
Quoted 3 lines · Alan Stern

Kernel wakelocks are a separate matter. They are more like a form of optimization, preventing the kernel from starting an auto-suspend when some driver knows beforehand that it will return -EBUSY.

I think kernel-side autosuspend (or rather autosleep) should only happen after certain subset of devices have been suspended using a per-device run-time autosuspend mechanism.

When the last wakelock is released the task that we woke up to perform has finished. Why wait to re-enter suspend.

Quoted 6 lines
Quoted 1 line

I don't really understand this comment. Could you please explain a bit?

If some devices are autosuspended after a local inactivity timeout, I don't want to wait for those devices to autosuspend if I know the code that needed to run is done. This could cause delays in the normal case,

Isn't it a matter of adjusting the inactivity timeouts in a suitable way?

Quoted 2 lines

and it could prevent suspend if a background process (not using wakelocks) is accessing a disk more frequently than its idle timeout.

Well, actually, shouldn't it prevent suspend from happening? Arguably, it just means that the disk is continuously being accessed with respect to the inactive timeout granularity.

Rafael

#121 lore raw
Quoted 6 lines · Rafael J. Wysocki
Quoted 4 lines

If some devices are autosuspended after a local inactivity timeout, I don't want to wait for those devices to autosuspend if I know the code that needed to run is done. This could cause delays in the normal case,

Isn't it a matter of adjusting the inactivity timeouts in a suitable way?

It's not that simple. A single device driver has a very local view, not suitable for deciding whether the entire system should go to sleep.

So for example, a disk driver might think it's appropriate to spin down the disk after 10 seconds of inactivity. But an overall system monitor might realize that nothing is going on right now and want to put the system to sleep immediately, without waiting the 10 seconds for the disk to autosuspend.

Quoted 6 lines
Quoted 2 lines

and it could prevent suspend if a background process (not using wakelocks) is accessing a disk more frequently than its idle timeout.

Well, actually, shouldn't it prevent suspend from happening? Arguably, it just means that the disk is continuously being accessed with respect to the inactive timeout granularity.

That's true, but it shows the problem of making the autosleep decision based on disk activity. An auto-sleep should not have to wait for every device (or some suitable subset) to become idle for some minimum time; it should be able to kick in at short notice.

Alan Stern

#122 lore raw
In reply to Rafael J. Wysocki
Quoted 6 lines · Rafael J. Wysocki
Quoted 4 lines

If some devices are autosuspended after a local inactivity timeout, I don't want to wait for those devices to autosuspend if I know the code that needed to run is done. This could cause delays in the normal case,

Isn't it a matter of adjusting the inactivity timeouts in a suitable way?

It's not that simple. A single device driver has a very local view, not suitable for deciding whether the entire system should go to sleep.

So for example, a disk driver might think it's appropriate to spin down the disk after 10 seconds of inactivity. But an overall system monitor might realize that nothing is going on right now and want to put the system to sleep immediately, without waiting the 10 seconds for the disk to autosuspend.

Quoted 6 lines
Quoted 2 lines

and it could prevent suspend if a background process (not using wakelocks) is accessing a disk more frequently than its idle timeout.

Well, actually, shouldn't it prevent suspend from happening? Arguably, it just means that the disk is continuously being accessed with respect to the inactive timeout granularity.

That's true, but it shows the problem of making the autosleep decision based on disk activity. An auto-sleep should not have to wait for every device (or some suitable subset) to become idle for some minimum time; it should be able to kick in at short notice.

Alan Stern

#123 lore raw
Quoted 9 lines · Alan Stern
Quoted 6 lines · Rafael J. Wysocki
Quoted 4 lines

If some devices are autosuspended after a local inactivity timeout, I don't want to wait for those devices to autosuspend if I know the code that needed to run is done. This could cause delays in the normal case,

Isn't it a matter of adjusting the inactivity timeouts in a suitable way?

Quoted 8 lines

It's not that simple. A single device driver has a very local view, not suitable for deciding whether the entire system should go to sleep.

So for example, a disk driver might think it's appropriate to spin down the disk after 10 seconds of inactivity. But an overall system monitor might realize that nothing is going on right now and want to put the system to sleep immediately, without waiting the 10 seconds for the disk to autosuspend.

Now, the question is what criteria would the overall system monitor use to make such a decision.

Quoted 11 lines
Quoted 6 lines
Quoted 2 lines

and it could prevent suspend if a background process (not using wakelocks) is accessing a disk more frequently than its idle timeout.

Well, actually, shouldn't it prevent suspend from happening? Arguably, it just means that the disk is continuously being accessed with respect to the inactive timeout granularity.

That's true, but it shows the problem of making the autosleep decision based on disk activity. An auto-sleep should not have to wait for every device (or some suitable subset) to become idle for some minimum time; it should be able to kick in at short notice.

Again, the decision to trigger automatic suspend has to be based on some well defined criteria and the (in)activity of devices seems to be one of them.

Thanks,
Rafael

#124 lore raw
In reply to Alan Stern
Quoted 9 lines · Alan Stern
Quoted 6 lines · Rafael J. Wysocki
Quoted 4 lines

If some devices are autosuspended after a local inactivity timeout, I don't want to wait for those devices to autosuspend if I know the code that needed to run is done. This could cause delays in the normal case,

Isn't it a matter of adjusting the inactivity timeouts in a suitable way?

Quoted 8 lines

It's not that simple. A single device driver has a very local view, not suitable for deciding whether the entire system should go to sleep.

So for example, a disk driver might think it's appropriate to spin down the disk after 10 seconds of inactivity. But an overall system monitor might realize that nothing is going on right now and want to put the system to sleep immediately, without waiting the 10 seconds for the disk to autosuspend.

Now, the question is what criteria would the overall system monitor use to make such a decision.

Quoted 11 lines
Quoted 6 lines
Quoted 2 lines

and it could prevent suspend if a background process (not using wakelocks) is accessing a disk more frequently than its idle timeout.

Well, actually, shouldn't it prevent suspend from happening? Arguably, it just means that the disk is continuously being accessed with respect to the inactive timeout granularity.

That's true, but it shows the problem of making the autosleep decision based on disk activity. An auto-sleep should not have to wait for every device (or some suitable subset) to become idle for some minimum time; it should be able to kick in at short notice.

Again, the decision to trigger automatic suspend has to be based on some well defined criteria and the (in)activity of devices seems to be one of them.

Thanks,
Rafael

#125 lore raw
Quoted 29 lines · Rafael J. Wysocki
Quoted 9 lines · Alan Stern
Quoted 6 lines · Rafael J. Wysocki
Quoted 4 lines

If some devices are autosuspended after a local inactivity timeout, I don't want to wait for those devices to autosuspend if I know the code that needed to run is done. This could cause delays in the normal case,

Isn't it a matter of adjusting the inactivity timeouts in a suitable way?

Quoted 8 lines

It's not that simple. A single device driver has a very local view, not suitable for deciding whether the entire system should go to sleep.

So for example, a disk driver might think it's appropriate to spin down the disk after 10 seconds of inactivity. But an overall system monitor might realize that nothing is going on right now and want to put the system to sleep immediately, without waiting the 10 seconds for the disk to autosuspend.

Now, the question is what criteria would the overall system monitor use to make such a decision.

Quoted 7 lines
Quoted 6 lines
Quoted 2 lines

and it could prevent suspend if a background process (not using wakelocks) is accessing a disk more frequently than its idle timeout.

Well, actually, shouldn't it prevent suspend from happening? Arguably, it just means that the disk is continuously being accessed with respect to the inactive timeout granularity.

Quoted 7 lines
Quoted 4 lines

That's true, but it shows the problem of making the autosleep decision based on disk activity. An auto-sleep should not have to wait for every device (or some suitable subset) to become idle for some minimum time; it should be able to kick in at short notice.

Again, the decision to trigger automatic suspend has to be based on some well defined criteria and the (in)activity of devices seems to be one of them.

I don't know what criteria the system monitor would use. It might have to be platform-specific. The Android people seem to have a pretty good idea of what criteria will work for them.

Inactivity of devices isn't always a good criterion. There might be a background task which wakes up every few seconds to do something as long as the system is awake, thereby keeping some device always active. The activity from this background task shouldn't prevent an auto-sleep.

Alan Stern

#126 lore raw
In reply to Rafael J. Wysocki
Quoted 29 lines · Rafael J. Wysocki
Quoted 9 lines · Alan Stern
Quoted 6 lines · Rafael J. Wysocki
Quoted 4 lines

If some devices are autosuspended after a local inactivity timeout, I don't want to wait for those devices to autosuspend if I know the code that needed to run is done. This could cause delays in the normal case,

Isn't it a matter of adjusting the inactivity timeouts in a suitable way?

Quoted 8 lines

It's not that simple. A single device driver has a very local view, not suitable for deciding whether the entire system should go to sleep.

So for example, a disk driver might think it's appropriate to spin down the disk after 10 seconds of inactivity. But an overall system monitor might realize that nothing is going on right now and want to put the system to sleep immediately, without waiting the 10 seconds for the disk to autosuspend.

Now, the question is what criteria would the overall system monitor use to make such a decision.

Quoted 7 lines
Quoted 6 lines
Quoted 2 lines

and it could prevent suspend if a background process (not using wakelocks) is accessing a disk more frequently than its idle timeout.

Well, actually, shouldn't it prevent suspend from happening? Arguably, it just means that the disk is continuously being accessed with respect to the inactive timeout granularity.

Quoted 7 lines
Quoted 4 lines

That's true, but it shows the problem of making the autosleep decision based on disk activity. An auto-sleep should not have to wait for every device (or some suitable subset) to become idle for some minimum time; it should be able to kick in at short notice.

Again, the decision to trigger automatic suspend has to be based on some well defined criteria and the (in)activity of devices seems to be one of them.

I don't know what criteria the system monitor would use. It might have to be platform-specific. The Android people seem to have a pretty good idea of what criteria will work for them.

Inactivity of devices isn't always a good criterion. There might be a background task which wakes up every few seconds to do something as long as the system is awake, thereby keeping some device always active. The activity from this background task shouldn't prevent an auto-sleep.

Alan Stern

#127 lore raw
Quoted 36 lines · Alan Stern
Quoted 34 lines · Rafael J. Wysocki
Quoted 9 lines · Alan Stern
Quoted 6 lines · Rafael J. Wysocki
Quoted 4 lines

If some devices are autosuspended after a local inactivity timeout, I don't want to wait for those devices to autosuspend if I know the code that needed to run is done. This could cause delays in the normal case,

Isn't it a matter of adjusting the inactivity timeouts in a suitable way?

Quoted 8 lines

It's not that simple. A single device driver has a very local view, not suitable for deciding whether the entire system should go to sleep.

So for example, a disk driver might think it's appropriate to spin down the disk after 10 seconds of inactivity. But an overall system monitor might realize that nothing is going on right now and want to put the system to sleep immediately, without waiting the 10 seconds for the disk to autosuspend.

Now, the question is what criteria would the overall system monitor use to make such a decision.

Quoted 11 lines
Quoted 6 lines
Quoted 2 lines

and it could prevent suspend if a background process (not using wakelocks) is accessing a disk more frequently than its idle timeout.

Well, actually, shouldn't it prevent suspend from happening? Arguably, it just means that the disk is continuously being accessed with respect to the inactive timeout granularity.

That's true, but it shows the problem of making the autosleep decision based on disk activity. An auto-sleep should not have to wait for every device (or some suitable subset) to become idle for some minimum time; it should be able to kick in at short notice.

Quoted 4 lines
Quoted 2 lines

Again, the decision to trigger automatic suspend has to be based on some well defined criteria and the (in)activity of devices seems to be one of them.

I don't know what criteria the system monitor would use.

I don't know either and this is the whole point. They need to be specified somehow and I'm not sure if "we suspend if no one is holding a wakelock" is the right approach.

Quoted 2 lines

It might have to be platform-specific. The Android people seem to have a pretty good idea of what criteria will work for them.

I'd really like to know in what situations Androind is supposed to suspend automatically.

Quoted 4 lines

Inactivity of devices isn't always a good criterion. There might be a background task which wakes up every few seconds to do something as long as the system is awake, thereby keeping some device always active. The activity from this background task shouldn't prevent an auto-sleep.

In fact there are two problems here. First, there may be a task preventing some devices from becoming inactive (like syslog). Second, there may be a task waiting for something important to happen, such that automatic suspend cannot be triggered while it's waiting. In both cases, IMO, the kernel is not in a point to decide whether to suspend or not, because the user space knows better.

Thanks,
Rafael

#128 lore raw
In reply to Alan Stern
Quoted 36 lines · Alan Stern
Quoted 34 lines · Rafael J. Wysocki
Quoted 9 lines · Alan Stern
Quoted 6 lines · Rafael J. Wysocki
Quoted 4 lines

If some devices are autosuspended after a local inactivity timeout, I don't want to wait for those devices to autosuspend if I know the code that needed to run is done. This could cause delays in the normal case,

Isn't it a matter of adjusting the inactivity timeouts in a suitable way?

Quoted 8 lines

It's not that simple. A single device driver has a very local view, not suitable for deciding whether the entire system should go to sleep.

So for example, a disk driver might think it's appropriate to spin down the disk after 10 seconds of inactivity. But an overall system monitor might realize that nothing is going on right now and want to put the system to sleep immediately, without waiting the 10 seconds for the disk to autosuspend.

Now, the question is what criteria would the overall system monitor use to make such a decision.

Quoted 11 lines
Quoted 6 lines
Quoted 2 lines

and it could prevent suspend if a background process (not using wakelocks) is accessing a disk more frequently than its idle timeout.

Well, actually, shouldn't it prevent suspend from happening? Arguably, it just means that the disk is continuously being accessed with respect to the inactive timeout granularity.

That's true, but it shows the problem of making the autosleep decision based on disk activity. An auto-sleep should not have to wait for every device (or some suitable subset) to become idle for some minimum time; it should be able to kick in at short notice.

Quoted 4 lines
Quoted 2 lines

Again, the decision to trigger automatic suspend has to be based on some well defined criteria and the (in)activity of devices seems to be one of them.

I don't know what criteria the system monitor would use.

I don't know either and this is the whole point. They need to be specified somehow and I'm not sure if "we suspend if no one is holding a wakelock" is the right approach.

Quoted 2 lines

It might have to be platform-specific. The Android people seem to have a pretty good idea of what criteria will work for them.

I'd really like to know in what situations Androind is supposed to suspend automatically.

Quoted 4 lines

Inactivity of devices isn't always a good criterion. There might be a background task which wakes up every few seconds to do something as long as the system is awake, thereby keeping some device always active. The activity from this background task shouldn't prevent an auto-sleep.

In fact there are two problems here. First, there may be a task preventing some devices from becoming inactive (like syslog). Second, there may be a task waiting for something important to happen, such that automatic suspend cannot be triggered while it's waiting. In both cases, IMO, the kernel is not in a point to decide whether to suspend or not, because the user space knows better.

Thanks,
Rafael

#129 lore raw

["Rafael J. Wysocki" <[email protected]>]

Quoted 6 lines
Quoted 3 lines

It might have to be platform-specific. The Android people seem to have a pretty good idea of what criteria will work for them.

I'd really like to know in what situations Androind is supposed to suspend automatically.

Currently, whenever the display is off (after the user-selectable timeout), we aggressively enter suspend -- wakelocks are used to prevent suspend when a driver or userspace entity needs the CPU to actually be awake.

Brian

#130 lore raw
In reply to Rafael J. Wysocki

["Rafael J. Wysocki" <[email protected]>]

Quoted 6 lines
Quoted 3 lines

It might have to be platform-specific. The Android people seem to have a pretty good idea of what criteria will work for them.

I'd really like to know in what situations Androind is supposed to suspend automatically.

Currently, whenever the display is off (after the user-selectable timeout), we aggressively enter suspend -- wakelocks are used to prevent suspend when a driver or userspace entity needs the CPU to actually be awake.

Brian

#131 lore raw
In reply to Rafael J. Wysocki
Quoted 8 lines · Rafael J. Wysocki
Quoted 4 lines
Quoted 2 lines

Again, the decision to trigger automatic suspend has to be based on some well defined criteria and the (in)activity of devices seems to be one of them.

I don't know what criteria the system monitor would use.

I don't know either and this is the whole point. They need to be specified somehow and I'm not sure if "we suspend if no one is holding a wakelock" is the right approach.

That isn't really a criterion; it's just a mechanism. All it does is push the problem back one level. Now the question becomes: When is it appropriate/necessary to hold a wakelock?

Quoted 5 lines
Quoted 2 lines

It might have to be platform-specific. The Android people seem to have a pretty good idea of what criteria will work for them.

I'd really like to know in what situations Androind is supposed to suspend automatically.

It might be better to ask in what situations Android is _not_ supposed to sleep automatically. In other words, in what situations is a wakelock acquired? Since the whole system is only a phone, this question should have a reasonably well-defined answer.

Quoted 7 lines
Quoted 4 lines

Inactivity of devices isn't always a good criterion. There might be a background task which wakes up every few seconds to do something as long as the system is awake, thereby keeping some device always active. The activity from this background task shouldn't prevent an auto-sleep.

In fact there are two problems here. First, there may be a task preventing some devices from becoming inactive (like syslog).

Which means that device inactivity isn't always a good indicator for auto-sleep. (But then there can be different levels of activity: A disk should always block auto-sleep while it is carrying out I/O, but it might not block auto-sleep just because it is spinning.)

Quoted 5 lines

Second, there may be
a task waiting for something important to happen, such that automatic suspend cannot be triggered while it's waiting. In both cases, IMO, the kernel is not in a point to decide whether to suspend or not, because the user space knows better.

That's the whole point behind userspace wakelocks! They provide a mechanism for userspace to tell the kernel when (as far as userspace is concerned) it is or is not okay to auto-sleep.

Alan Stern

#132 lore raw
In reply to Rafael J. Wysocki
Quoted 8 lines · Rafael J. Wysocki
Quoted 4 lines
Quoted 2 lines

Again, the decision to trigger automatic suspend has to be based on some well defined criteria and the (in)activity of devices seems to be one of them.

I don't know what criteria the system monitor would use.

I don't know either and this is the whole point. They need to be specified somehow and I'm not sure if "we suspend if no one is holding a wakelock" is the right approach.

That isn't really a criterion; it's just a mechanism. All it does is push the problem back one level. Now the question becomes: When is it appropriate/necessary to hold a wakelock?

Quoted 5 lines
Quoted 2 lines

It might have to be platform-specific. The Android people seem to have a pretty good idea of what criteria will work for them.

I'd really like to know in what situations Androind is supposed to suspend automatically.

It might be better to ask in what situations Android is _not_ supposed to sleep automatically. In other words, in what situations is a wakelock acquired? Since the whole system is only a phone, this question should have a reasonably well-defined answer.

Quoted 7 lines
Quoted 4 lines

Inactivity of devices isn't always a good criterion. There might be a background task which wakes up every few seconds to do something as long as the system is awake, thereby keeping some device always active. The activity from this background task shouldn't prevent an auto-sleep.

In fact there are two problems here. First, there may be a task preventing some devices from becoming inactive (like syslog).

Which means that device inactivity isn't always a good indicator for auto-sleep. (But then there can be different levels of activity: A disk should always block auto-sleep while it is carrying out I/O, but it might not block auto-sleep just because it is spinning.)

Quoted 5 lines

Second, there may be
a task waiting for something important to happen, such that automatic suspend cannot be triggered while it's waiting. In both cases, IMO, the kernel is not in a point to decide whether to suspend or not, because the user space knows better.

That's the whole point behind userspace wakelocks! They provide a mechanism for userspace to tell the kernel when (as far as userspace is concerned) it is or is not okay to auto-sleep.

Alan Stern

#133 lore raw
In reply to Rafael J. Wysocki
Quoted 8 lines · Rafael J. Wysocki
Quoted 4 lines
Quoted 2 lines

Again, the decision to trigger automatic suspend has to be based on some well defined criteria and the (in)activity of devices seems to be one of them.

I don't know what criteria the system monitor would use.

I don't know either and this is the whole point. They need to be specified somehow and I'm not sure if "we suspend if no one is holding a wakelock" is the right approach.

That isn't really a criterion; it's just a mechanism. All it does is push the problem back one level. Now the question becomes: When is it appropriate/necessary to hold a wakelock?

Quoted 5 lines
Quoted 2 lines

It might have to be platform-specific. The Android people seem to have a pretty good idea of what criteria will work for them.

I'd really like to know in what situations Androind is supposed to suspend automatically.

It might be better to ask in what situations Android is _not_ supposed to sleep automatically. In other words, in what situations is a wakelock acquired? Since the whole system is only a phone, this question should have a reasonably well-defined answer.

Quoted 7 lines
Quoted 4 lines

Inactivity of devices isn't always a good criterion. There might be a background task which wakes up every few seconds to do something as long as the system is awake, thereby keeping some device always active. The activity from this background task shouldn't prevent an auto-sleep.

In fact there are two problems here. First, there may be a task preventing some devices from becoming inactive (like syslog).

Which means that device inactivity isn't always a good indicator for auto-sleep. (But then there can be different levels of activity: A disk should always block auto-sleep while it is carrying out I/O, but it might not block auto-sleep just because it is spinning.)

Quoted 5 lines

Second, there may be
a task waiting for something important to happen, such that automatic suspend cannot be triggered while it's waiting. In both cases, IMO, the kernel is not in a point to decide whether to suspend or not, because the user space knows better.

That's the whole point behind userspace wakelocks! They provide a mechanism for userspace to tell the kernel when (as far as userspace is concerned) it is or is not okay to auto-sleep.

Alan Stern

#134 lore raw
In reply to Rafael J. Wysocki
Quoted 8 lines · Rafael J. Wysocki
Quoted 4 lines
Quoted 2 lines

Again, the decision to trigger automatic suspend has to be based on some well defined criteria and the (in)activity of devices seems to be one of them.

I don't know what criteria the system monitor would use.

I don't know either and this is the whole point. They need to be specified somehow and I'm not sure if "we suspend if no one is holding a wakelock" is the right approach.

That isn't really a criterion; it's just a mechanism. All it does is push the problem back one level. Now the question becomes: When is it appropriate/necessary to hold a wakelock?

Quoted 5 lines
Quoted 2 lines

It might have to be platform-specific. The Android people seem to have a pretty good idea of what criteria will work for them.

I'd really like to know in what situations Androind is supposed to suspend automatically.

It might be better to ask in what situations Android is _not_ supposed to sleep automatically. In other words, in what situations is a wakelock acquired? Since the whole system is only a phone, this question should have a reasonably well-defined answer.

Quoted 7 lines
Quoted 4 lines

Inactivity of devices isn't always a good criterion. There might be a background task which wakes up every few seconds to do something as long as the system is awake, thereby keeping some device always active. The activity from this background task shouldn't prevent an auto-sleep.

In fact there are two problems here. First, there may be a task preventing some devices from becoming inactive (like syslog).

Which means that device inactivity isn't always a good indicator for auto-sleep. (But then there can be different levels of activity: A disk should always block auto-sleep while it is carrying out I/O, but it might not block auto-sleep just because it is spinning.)

Quoted 5 lines

Second, there may be
a task waiting for something important to happen, such that automatic suspend cannot be triggered while it's waiting. In both cases, IMO, the kernel is not in a point to decide whether to suspend or not, because the user space knows better.

That's the whole point behind userspace wakelocks! They provide a mechanism for userspace to tell the kernel when (as far as userspace is concerned) it is or is not okay to auto-sleep.

Alan Stern

#135 lore raw
Quoted 45 lines · Alan Stern
Quoted 8 lines · Rafael J. Wysocki
Quoted 4 lines
Quoted 2 lines

Again, the decision to trigger automatic suspend has to be based on some well defined criteria and the (in)activity of devices seems to be one of them.

I don't know what criteria the system monitor would use.

I don't know either and this is the whole point. They need to be specified somehow and I'm not sure if "we suspend if no one is holding a wakelock" is the right approach.

That isn't really a criterion; it's just a mechanism. All it does is push the problem back one level. Now the question becomes: When is it appropriate/necessary to hold a wakelock?

Quoted 5 lines
Quoted 2 lines

It might have to be platform-specific. The Android people seem to have a pretty good idea of what criteria will work for them.

I'd really like to know in what situations Androind is supposed to suspend automatically.

It might be better to ask in what situations Android is _not_ supposed to sleep automatically. In other words, in what situations is a wakelock acquired? Since the whole system is only a phone, this question should have a reasonably well-defined answer.

Quoted 7 lines
Quoted 4 lines

Inactivity of devices isn't always a good criterion. There might be a background task which wakes up every few seconds to do something as long as the system is awake, thereby keeping some device always active. The activity from this background task shouldn't prevent an auto-sleep.

In fact there are two problems here. First, there may be a task preventing some devices from becoming inactive (like syslog).

Which means that device inactivity isn't always a good indicator for auto-sleep. (But then there can be different levels of activity: A disk should always block auto-sleep while it is carrying out I/O, but it might not block auto-sleep just because it is spinning.)

Quoted 5 lines

Second, there may be
a task waiting for something important to happen, such that automatic suspend cannot be triggered while it's waiting. In both cases, IMO, the kernel is not in a point to decide whether to suspend or not, because the user space knows better.

Quoted 3 lines

That's the whole point behind userspace wakelocks! They provide a mechanism for userspace to tell the kernel when (as far as userspace is concerned) it is or is not okay to auto-sleep.

Still, one can go further and observe that the user space can in fact start automatic suspend by itself whenever it knows it's appropriate ...

Thanks,
Rafael

#136 lore raw
In reply to Alan Stern
Quoted 45 lines · Alan Stern
Quoted 8 lines · Rafael J. Wysocki
Quoted 4 lines
Quoted 2 lines

Again, the decision to trigger automatic suspend has to be based on some well defined criteria and the (in)activity of devices seems to be one of them.

I don't know what criteria the system monitor would use.

I don't know either and this is the whole point. They need to be specified somehow and I'm not sure if "we suspend if no one is holding a wakelock" is the right approach.

That isn't really a criterion; it's just a mechanism. All it does is push the problem back one level. Now the question becomes: When is it appropriate/necessary to hold a wakelock?

Quoted 5 lines
Quoted 2 lines

It might have to be platform-specific. The Android people seem to have a pretty good idea of what criteria will work for them.

I'd really like to know in what situations Androind is supposed to suspend automatically.

It might be better to ask in what situations Android is _not_ supposed to sleep automatically. In other words, in what situations is a wakelock acquired? Since the whole system is only a phone, this question should have a reasonably well-defined answer.

Quoted 7 lines
Quoted 4 lines

Inactivity of devices isn't always a good criterion. There might be a background task which wakes up every few seconds to do something as long as the system is awake, thereby keeping some device always active. The activity from this background task shouldn't prevent an auto-sleep.

In fact there are two problems here. First, there may be a task preventing some devices from becoming inactive (like syslog).

Which means that device inactivity isn't always a good indicator for auto-sleep. (But then there can be different levels of activity: A disk should always block auto-sleep while it is carrying out I/O, but it might not block auto-sleep just because it is spinning.)

Quoted 5 lines

Second, there may be
a task waiting for something important to happen, such that automatic suspend cannot be triggered while it's waiting. In both cases, IMO, the kernel is not in a point to decide whether to suspend or not, because the user space knows better.

Quoted 3 lines

That's the whole point behind userspace wakelocks! They provide a mechanism for userspace to tell the kernel when (as far as userspace is concerned) it is or is not okay to auto-sleep.

Still, one can go further and observe that the user space can in fact start automatic suspend by itself whenever it knows it's appropriate ...

Thanks,
Rafael

#137 lore raw
In reply to Alan Stern
Quoted 45 lines · Alan Stern
Quoted 8 lines · Rafael J. Wysocki
Quoted 4 lines
Quoted 2 lines

Again, the decision to trigger automatic suspend has to be based on some well defined criteria and the (in)activity of devices seems to be one of them.

I don't know what criteria the system monitor would use.

I don't know either and this is the whole point. They need to be specified somehow and I'm not sure if "we suspend if no one is holding a wakelock" is the right approach.

That isn't really a criterion; it's just a mechanism. All it does is push the problem back one level. Now the question becomes: When is it appropriate/necessary to hold a wakelock?

Quoted 5 lines
Quoted 2 lines

It might have to be platform-specific. The Android people seem to have a pretty good idea of what criteria will work for them.

I'd really like to know in what situations Androind is supposed to suspend automatically.

It might be better to ask in what situations Android is _not_ supposed to sleep automatically. In other words, in what situations is a wakelock acquired? Since the whole system is only a phone, this question should have a reasonably well-defined answer.

Quoted 7 lines
Quoted 4 lines

Inactivity of devices isn't always a good criterion. There might be a background task which wakes up every few seconds to do something as long as the system is awake, thereby keeping some device always active. The activity from this background task shouldn't prevent an auto-sleep.

In fact there are two problems here. First, there may be a task preventing some devices from becoming inactive (like syslog).

Which means that device inactivity isn't always a good indicator for auto-sleep. (But then there can be different levels of activity: A disk should always block auto-sleep while it is carrying out I/O, but it might not block auto-sleep just because it is spinning.)

Quoted 5 lines

Second, there may be
a task waiting for something important to happen, such that automatic suspend cannot be triggered while it's waiting. In both cases, IMO, the kernel is not in a point to decide whether to suspend or not, because the user space knows better.

Quoted 3 lines

That's the whole point behind userspace wakelocks! They provide a mechanism for userspace to tell the kernel when (as far as userspace is concerned) it is or is not okay to auto-sleep.

Still, one can go further and observe that the user space can in fact start automatic suspend by itself whenever it knows it's appropriate ...

Thanks,
Rafael

#138 lore raw
In reply to Alan Stern
Quoted 45 lines · Alan Stern
Quoted 8 lines · Rafael J. Wysocki
Quoted 4 lines
Quoted 2 lines

Again, the decision to trigger automatic suspend has to be based on some well defined criteria and the (in)activity of devices seems to be one of them.

I don't know what criteria the system monitor would use.

I don't know either and this is the whole point. They need to be specified somehow and I'm not sure if "we suspend if no one is holding a wakelock" is the right approach.

That isn't really a criterion; it's just a mechanism. All it does is push the problem back one level. Now the question becomes: When is it appropriate/necessary to hold a wakelock?

Quoted 5 lines
Quoted 2 lines

It might have to be platform-specific. The Android people seem to have a pretty good idea of what criteria will work for them.

I'd really like to know in what situations Androind is supposed to suspend automatically.

It might be better to ask in what situations Android is _not_ supposed to sleep automatically. In other words, in what situations is a wakelock acquired? Since the whole system is only a phone, this question should have a reasonably well-defined answer.

Quoted 7 lines
Quoted 4 lines

Inactivity of devices isn't always a good criterion. There might be a background task which wakes up every few seconds to do something as long as the system is awake, thereby keeping some device always active. The activity from this background task shouldn't prevent an auto-sleep.

In fact there are two problems here. First, there may be a task preventing some devices from becoming inactive (like syslog).

Which means that device inactivity isn't always a good indicator for auto-sleep. (But then there can be different levels of activity: A disk should always block auto-sleep while it is carrying out I/O, but it might not block auto-sleep just because it is spinning.)

Quoted 5 lines

Second, there may be
a task waiting for something important to happen, such that automatic suspend cannot be triggered while it's waiting. In both cases, IMO, the kernel is not in a point to decide whether to suspend or not, because the user space knows better.

Quoted 3 lines

That's the whole point behind userspace wakelocks! They provide a mechanism for userspace to tell the kernel when (as far as userspace is concerned) it is or is not okay to auto-sleep.

Still, one can go further and observe that the user space can in fact start automatic suspend by itself whenever it knows it's appropriate ...

Thanks,
Rafael

#139 lore raw

Am Donnerstag 19 Februar 2009 23:21:46 schrieb Rafael J. Wysocki:

Quoted 2 lines
Quoted 2 lines

That's the whole point behind userspace wakelocks!  They provide a mechanism for userspace to tell the kernel when (as far as userspace

is

Quoted 4 lines
Quoted 1 line

concerned) it is or is not okay to auto-sleep.

Still, one can go further and observe that the user space can in fact start automatic suspend by itself whenever it knows it's appropriate ...

User space initiating this is a race condition.

Regards
Oliver

#151 lore raw
In reply to Rafael J. Wysocki

Am Donnerstag 19 Februar 2009 23:21:46 schrieb Rafael J. Wysocki:

Quoted 2 lines
Quoted 2 lines

That's the whole point behind userspace wakelocks!  They provide a mechanism for userspace to tell the kernel when (as far as userspace

is

Quoted 4 lines
Quoted 1 line

concerned) it is or is not okay to auto-sleep.

Still, one can go further and observe that the user space can in fact start automatic suspend by itself whenever it knows it's appropriate ...

User space initiating this is a race condition.

Regards
Oliver

#152 lore raw
In reply to Alan Stern
Quoted 10 lines · Alan Stern
Quoted 5 lines
Quoted 2 lines

It might have to be platform-specific. The Android people seem to have a pretty good idea of what criteria will work for them.

I'd really like to know in what situations Androind is supposed to suspend automatically.

It might be better to ask in what situations Android is _not_ supposed to sleep automatically. In other words, in what situations is a wakelock acquired? Since the whole system is only a phone, this question should have a reasonably well-defined answer.

On an android phone, any code that needs to run when the screen is off must hold a wakelock (directly or indirectly). In general if an application or the system is processing an event that may cause a user notification (new email, incoming phone call, alarm, etc.) it needs to prevent suspend. But, we also use wakelocks to upload stats or download system updates in the background, and for media player or (gps) data logging applications.

Signature · 1 line
Arve Hjønnevåg
#153 lore raw
In reply to Alan Stern
Quoted 10 lines · Alan Stern
Quoted 5 lines
Quoted 2 lines

It might have to be platform-specific. The Android people seem to have a pretty good idea of what criteria will work for them.

I'd really like to know in what situations Androind is supposed to suspend automatically.

It might be better to ask in what situations Android is _not_ supposed to sleep automatically. In other words, in what situations is a wakelock acquired? Since the whole system is only a phone, this question should have a reasonably well-defined answer.

On an android phone, any code that needs to run when the screen is off must hold a wakelock (directly or indirectly). In general if an application or the system is processing an event that may cause a user notification (new email, incoming phone call, alarm, etc.) it needs to prevent suspend. But, we also use wakelocks to upload stats or download system updates in the background, and for media player or (gps) data logging applications.

Signature · 1 line
Arve Hjønnevåg
#93 lore raw
In reply to Matthew Garrett
Quoted 7 lines · Matthew Garrett
Quoted 4 lines · Rafael J. Wysocki

This, again, seems to be a bit x86-centric. :-) The Android people are telling us that on the hardware they deal with it does make sense to put the entire system to sleep even for relatively short periods of time, since the latencies involved are not too bad.

Quoted 5 lines

Arve said that the power state was equivalent in idle and suspend, but that they preferred suspend because it stopped any periodic timers. I'd be more interested in making sure that unnecessary timers aren't running than focusing on automatically entering system-wide suspend - Nokia have been managing this since 2005 with good results.

I'm sure you can build a product with acceptable battery life without suspend. The average power draw on the G1 while idle with everything off is less than the power draw was in suspend on our previous hardware. However, on the same hardware you get 40 days standby using suspend versus 20 days using idle. If you turn on the radio and use the device every day, this starts to become irrelevant since you are lucky to get more than a few days standby time. However, if you install an application that wakes up 60 times a second (to check if it need to draw something on the screen) the difference between idle and suspend becomes 10 hours versus 40 days, or 10 hours versus 3 days with my use.

Signature · 1 line
Arve Hjønnevåg
#94 lore raw
In reply to Matthew Garrett
Quoted 7 lines · Matthew Garrett
Quoted 4 lines · Rafael J. Wysocki

This, again, seems to be a bit x86-centric. :-) The Android people are telling us that on the hardware they deal with it does make sense to put the entire system to sleep even for relatively short periods of time, since the latencies involved are not too bad.

Quoted 5 lines

Arve said that the power state was equivalent in idle and suspend, but that they preferred suspend because it stopped any periodic timers. I'd be more interested in making sure that unnecessary timers aren't running than focusing on automatically entering system-wide suspend - Nokia have been managing this since 2005 with good results.

I'm sure you can build a product with acceptable battery life without suspend. The average power draw on the G1 while idle with everything off is less than the power draw was in suspend on our previous hardware. However, on the same hardware you get 40 days standby using suspend versus 20 days using idle. If you turn on the radio and use the device every day, this starts to become irrelevant since you are lucky to get more than a few days standby time. However, if you install an application that wakes up 60 times a second (to check if it need to draw something on the screen) the difference between idle and suspend becomes 10 hours versus 40 days, or 10 hours versus 3 days with my use.

Signature · 1 line
Arve Hjønnevåg
#140 lore raw
In reply to Oliver Neukum
Quoted 10 lines · Oliver Neukum

Am Donnerstag 19 Februar 2009 23:21:46 schrieb Rafael J. Wysocki:

Quoted 2 lines
Quoted 2 lines

That's the whole point behind userspace wakelocks! They provide a mechanism for userspace to tell the kernel when (as far as userspace

is

Quoted 4 lines
Quoted 1 line

concerned) it is or is not okay to auto-sleep.

Still, one can go further and observe that the user space can in fact start automatic suspend by itself whenever it knows it's appropriate ...

User space initiating this is a race condition.

Do you mean a race with the other user space processes or with the kernel?

Rafael

#141 lore raw
In reply to Oliver Neukum
Quoted 10 lines · Oliver Neukum

Am Donnerstag 19 Februar 2009 23:21:46 schrieb Rafael J. Wysocki:

Quoted 2 lines
Quoted 2 lines

That's the whole point behind userspace wakelocks! They provide a mechanism for userspace to tell the kernel when (as far as userspace

is

Quoted 4 lines
Quoted 1 line

concerned) it is or is not okay to auto-sleep.

Still, one can go further and observe that the user space can in fact start automatic suspend by itself whenever it knows it's appropriate ...

User space initiating this is a race condition.

Do you mean a race with the other user space processes or with the kernel?

Rafael

#154 lore raw
In reply to Arve Hjønnevåg
Quoted 12 lines · Arve Hjønnevåg
Quoted 10 lines · Alan Stern
Quoted 5 lines
Quoted 2 lines

It might have to be platform-specific. The Android people seem to have a pretty good idea of what criteria will work for them.

I'd really like to know in what situations Androind is supposed to suspend automatically.

It might be better to ask in what situations Android is _not_ supposed to sleep automatically. In other words, in what situations is a wakelock acquired? Since the whole system is only a phone, this question should have a reasonably well-defined answer.

Quoted 7 lines

On an android phone, any code that needs to run when the screen is off must hold a wakelock (directly or indirectly). In general if an application or the system is processing an event that may cause a user notification (new email, incoming phone call, alarm, etc.) it needs to prevent suspend. But, we also use wakelocks to upload stats or download system updates in the background, and for media player or (gps) data logging applications.

All of this doesn't seem to require wakelocks acuired from kernel space. What do you need those wakelocks for?

Rafael

#155 lore raw
Quoted 21 lines · Rafael J. Wysocki
Quoted 12 lines · Arve Hjønnevåg
Quoted 10 lines · Alan Stern
Quoted 5 lines
Quoted 2 lines

It might have to be platform-specific. The Android people seem to have a pretty good idea of what criteria will work for them.

I'd really like to know in what situations Androind is supposed to suspend automatically.

It might be better to ask in what situations Android is _not_ supposed to sleep automatically. In other words, in what situations is a wakelock acquired? Since the whole system is only a phone, this question should have a reasonably well-defined answer.

Quoted 7 lines

On an android phone, any code that needs to run when the screen is off must hold a wakelock (directly or indirectly). In general if an application or the system is processing an event that may cause a user notification (new email, incoming phone call, alarm, etc.) it needs to prevent suspend. But, we also use wakelocks to upload stats or download system updates in the background, and for media player or (gps) data logging applications.

Quoted 2 lines

All of this doesn't seem to require wakelocks acuired from kernel space. What do you need those wakelocks for?

Most events do not originate in user-space. Alarms start in our alarm driver which locks a wakelock when its timer interrupt occurs. This wakelock stays locked until the user-space alarm manager calls the driver to wait for the next alarm. I've described how input events are handled before. Without kernel wakelocks, if the user space power manager had already turned off the screen and decided to suspend right before a wakeup key is pressed, then that key could sit in the in-kernel input queue until another key is pressed. Even if the user-space thread read the key event before being frozen, it cannot abort the suspend operation that was already started.

Signature · 1 line
Arve Hjønnevåg
#156 lore raw
In reply to Rafael J. Wysocki
Quoted 21 lines · Rafael J. Wysocki
Quoted 12 lines · Arve Hjønnevåg
Quoted 10 lines · Alan Stern
Quoted 5 lines
Quoted 2 lines

It might have to be platform-specific. The Android people seem to have a pretty good idea of what criteria will work for them.

I'd really like to know in what situations Androind is supposed to suspend automatically.

It might be better to ask in what situations Android is _not_ supposed to sleep automatically. In other words, in what situations is a wakelock acquired? Since the whole system is only a phone, this question should have a reasonably well-defined answer.

Quoted 7 lines

On an android phone, any code that needs to run when the screen is off must hold a wakelock (directly or indirectly). In general if an application or the system is processing an event that may cause a user notification (new email, incoming phone call, alarm, etc.) it needs to prevent suspend. But, we also use wakelocks to upload stats or download system updates in the background, and for media player or (gps) data logging applications.

Quoted 2 lines

All of this doesn't seem to require wakelocks acuired from kernel space. What do you need those wakelocks for?

Most events do not originate in user-space. Alarms start in our alarm driver which locks a wakelock when its timer interrupt occurs. This wakelock stays locked until the user-space alarm manager calls the driver to wait for the next alarm. I've described how input events are handled before. Without kernel wakelocks, if the user space power manager had already turned off the screen and decided to suspend right before a wakeup key is pressed, then that key could sit in the in-kernel input queue until another key is pressed. Even if the user-space thread read the key event before being frozen, it cannot abort the suspend operation that was already started.

Signature · 1 line
Arve Hjønnevåg
#95 lore raw
In reply to Arve Hjønnevåg
Quoted 5 lines · On Thu, 19 Feb 2009 21:35:39 -0800 Arve Hjønnevåg <[email protected]> wrote:

However, if you
install an application that wakes up 60 times a second (to check if it need to draw something on the screen) the difference between idle and suspend becomes 10 hours versus 40 days, or 10 hours versus 3 days with my use.

then that is the point where you use the timerslack to throttle such non-system applications.... that's very obvious and there today..

Signature · 7 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm
#96 lore raw
In reply to Arve Hjønnevåg
Quoted 5 lines · On Thu, 19 Feb 2009 21:35:39 -0800 Arve Hjønnevåg <[email protected]> wrote:

However, if you
install an application that wakes up 60 times a second (to check if it need to draw something on the screen) the difference between idle and suspend becomes 10 hours versus 40 days, or 10 hours versus 3 days with my use.

then that is the point where you use the timerslack to throttle such non-system applications.... that's very obvious and there today..

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#157 lore raw
In reply to Arve Hjønnevåg
Quoted 25 lines · Arve Hjønnevåg
Quoted 21 lines · Rafael J. Wysocki
Quoted 12 lines · Arve Hjønnevåg
Quoted 10 lines · Alan Stern
Quoted 5 lines
Quoted 2 lines

It might have to be platform-specific. The Android people seem to have a pretty good idea of what criteria will work for them.

I'd really like to know in what situations Androind is supposed to suspend automatically.

It might be better to ask in what situations Android is _not_ supposed to sleep automatically. In other words, in what situations is a wakelock acquired? Since the whole system is only a phone, this question should have a reasonably well-defined answer.

Quoted 7 lines

On an android phone, any code that needs to run when the screen is off must hold a wakelock (directly or indirectly). In general if an application or the system is processing an event that may cause a user notification (new email, incoming phone call, alarm, etc.) it needs to prevent suspend. But, we also use wakelocks to upload stats or download system updates in the background, and for media player or (gps) data logging applications.

Quoted 2 lines

All of this doesn't seem to require wakelocks acuired from kernel space. What do you need those wakelocks for?

Quoted 10 lines

Most events do not originate in user-space. Alarms start in our alarm driver which locks a wakelock when its timer interrupt occurs. This wakelock stays locked until the user-space alarm manager calls the driver to wait for the next alarm. I've described how input events are handled before. Without kernel wakelocks, if the user space power manager had already turned off the screen and decided to suspend right before a wakeup key is pressed, then that key could sit in the in-kernel input queue until another key is pressed. Even if the user-space thread read the key event before being frozen, it cannot abort the suspend operation that was already started.

OK, so what about the following approach:

* Keep the decision making logic (power manager etc.) in user space. Reasons:
- It may be arbitrarily complicated
- It may include such things as s2ram quirks or hal quirks needed for some graphics adapters

* Have a per-process (per-task or per-thread group, but the former would be easier IMO) "I_do_not_want_automatic_suspend_to_occur" flag.

* Add a new callback, say ->acknowledge(), to the set of each driver's PM operations, that will be called to check if the driver has anything against automatic suspend (true - suspend can happen right now, false - suspend can't happen).

* Introduce /sys/power/sleep that will work like /sys/power/state, but:
- First, it will call ->acknowledge() for each driver (via bus types) to check if any of them wants to postpone the suspend (this will prevent tasks from being frozen unnecessarily if it is known in advance that the suspend should not happen at the moment).
- Next, it will check the "I_do_not_want_automatic_suspend_to_occur" flag of each process and the suspend will be aborted if it is true for any of them (quite frankly, I think that should be integrated with the freezer, in particular the tasks that have TIF_FREEZE set shouldn't be able to set this flag and it should be checked in the freezer loop for every task with TIF_FREEZE unset).
- Next, it will proceed with suspending just like /sys/power/state does (the

    drivers that missed the opportunity to abort the suspend by returning
    'false' from ->acknowledge() can still abort the suspend by failing their
    ->suspend() routines).

Then, the decision making logic will be able to use /sys/power/sleep whenever it wishes to and the kernel will be able to refuse to suspend if it's not desirable at the moment.

It seems to be flexible enough to me.

Thanks,
Rafael

#158 lore raw
In reply to Arve Hjønnevåg
Quoted 25 lines · Arve Hjønnevåg
Quoted 21 lines · Rafael J. Wysocki
Quoted 12 lines · Arve Hjønnevåg
Quoted 10 lines · Alan Stern
Quoted 5 lines
Quoted 2 lines

It might have to be platform-specific. The Android people seem to have a pretty good idea of what criteria will work for them.

I'd really like to know in what situations Androind is supposed to suspend automatically.

It might be better to ask in what situations Android is _not_ supposed to sleep automatically. In other words, in what situations is a wakelock acquired? Since the whole system is only a phone, this question should have a reasonably well-defined answer.

Quoted 7 lines

On an android phone, any code that needs to run when the screen is off must hold a wakelock (directly or indirectly). In general if an application or the system is processing an event that may cause a user notification (new email, incoming phone call, alarm, etc.) it needs to prevent suspend. But, we also use wakelocks to upload stats or download system updates in the background, and for media player or (gps) data logging applications.

Quoted 2 lines

All of this doesn't seem to require wakelocks acuired from kernel space. What do you need those wakelocks for?

Quoted 10 lines

Most events do not originate in user-space. Alarms start in our alarm driver which locks a wakelock when its timer interrupt occurs. This wakelock stays locked until the user-space alarm manager calls the driver to wait for the next alarm. I've described how input events are handled before. Without kernel wakelocks, if the user space power manager had already turned off the screen and decided to suspend right before a wakeup key is pressed, then that key could sit in the in-kernel input queue until another key is pressed. Even if the user-space thread read the key event before being frozen, it cannot abort the suspend operation that was already started.

OK, so what about the following approach:

* Keep the decision making logic (power manager etc.) in user space. Reasons:
- It may be arbitrarily complicated
- It may include such things as s2ram quirks or hal quirks needed for some graphics adapters

* Have a per-process (per-task or per-thread group, but the former would be easier IMO) "I_do_not_want_automatic_suspend_to_occur" flag.

* Add a new callback, say ->acknowledge(), to the set of each driver's PM operations, that will be called to check if the driver has anything against automatic suspend (true - suspend can happen right now, false - suspend can't happen).

* Introduce /sys/power/sleep that will work like /sys/power/state, but:
- First, it will call ->acknowledge() for each driver (via bus types) to check if any of them wants to postpone the suspend (this will prevent tasks from being frozen unnecessarily if it is known in advance that the suspend should not happen at the moment).
- Next, it will check the "I_do_not_want_automatic_suspend_to_occur" flag of each process and the suspend will be aborted if it is true for any of them (quite frankly, I think that should be integrated with the freezer, in particular the tasks that have TIF_FREEZE set shouldn't be able to set this flag and it should be checked in the freezer loop for every task with TIF_FREEZE unset).
- Next, it will proceed with suspending just like /sys/power/state does (the

    drivers that missed the opportunity to abort the suspend by returning
    'false' from ->acknowledge() can still abort the suspend by failing their
    ->suspend() routines).

Then, the decision making logic will be able to use /sys/power/sleep whenever it wishes to and the kernel will be able to refuse to suspend if it's not desirable at the moment.

It seems to be flexible enough to me.

Thanks,
Rafael

#159 lore raw
Quoted 16 lines · Rafael J. Wysocki

* Introduce /sys/power/sleep that will work like /sys/power/state, but:
- First, it will call ->acknowledge() for each driver (via bus types) to check if any of them wants to postpone the suspend (this will prevent tasks from being frozen unnecessarily if it is known in advance that the suspend should not happen at the moment).
- Next, it will check the "I_do_not_want_automatic_suspend_to_occur" flag of each process and the suspend will be aborted if it is true for any of them (quite frankly, I think that should be integrated with the freezer, in particular the tasks that have TIF_FREEZE set shouldn't be able to set this flag and it should be checked in the freezer loop for every task with TIF_FREEZE unset).
- Next, it will proceed with suspending just like /sys/power/state does (the drivers that missed the opportunity to abort the suspend by returning 'false' from ->acknowledge() can still abort the suspend by failing their ->suspend() routines).

Quoted 3 lines

Then, the decision making logic will be able to use /sys/power/sleep whenever it wishes to and the kernel will be able to refuse to suspend if it's not desirable at the moment.

Then, for a userspace process handling input events:

1)  Unset "no-suspend flag"
2)  Poll event device
3)  When the poll returns true, set the "no-suspend flag"
4)  Read the event device and process the event(s)
5)  Go back to step 1

The event driver would responsible for atomically preventing suspend from the moment a button is pressed until it is actually delivered to a userspace process. Since at that time the userspace process will be preventing suspend, there will be no window in which we could go to sleep with pending events.

Cheers,
Kyle Moffett

#160 lore raw
In reply to Rafael J. Wysocki
Quoted 16 lines · Rafael J. Wysocki

* Introduce /sys/power/sleep that will work like /sys/power/state, but:
- First, it will call ->acknowledge() for each driver (via bus types) to check if any of them wants to postpone the suspend (this will prevent tasks from being frozen unnecessarily if it is known in advance that the suspend should not happen at the moment).
- Next, it will check the "I_do_not_want_automatic_suspend_to_occur" flag of each process and the suspend will be aborted if it is true for any of them (quite frankly, I think that should be integrated with the freezer, in particular the tasks that have TIF_FREEZE set shouldn't be able to set this flag and it should be checked in the freezer loop for every task with TIF_FREEZE unset).
- Next, it will proceed with suspending just like /sys/power/state does (the drivers that missed the opportunity to abort the suspend by returning 'false' from ->acknowledge() can still abort the suspend by failing their ->suspend() routines).

Quoted 3 lines

Then, the decision making logic will be able to use /sys/power/sleep whenever it wishes to and the kernel will be able to refuse to suspend if it's not desirable at the moment.

Then, for a userspace process handling input events:

1)  Unset "no-suspend flag"
2)  Poll event device
3)  When the poll returns true, set the "no-suspend flag"
4)  Read the event device and process the event(s)
5)  Go back to step 1

The event driver would responsible for atomically preventing suspend from the moment a button is pressed until it is actually delivered to a userspace process. Since at that time the userspace process will be preventing suspend, there will be no window in which we could go to sleep with pending events.

Cheers,
Kyle Moffett

#286 lore raw
In reply to Oliver Neukum
Quoted 12 lines · Oliver Neukum

Am Monday 16 February 2009 18:31:08 schrieb Arjan van de Ven:

Quoted 11 lines
Quoted 7 lines · On Mon, 16 Feb 2009 17:48:06 +0100 Oliver Neukum <[email protected]> wrote:
Quoted 3 lines

Userspace should just be the part that says "I'm interested in link notifications". The driver then just goes to the lowest power state for its device that still gives those notifications.

Should there be a channel through which drivers can tell user space what the consequences in terms of reaching a sleep state are if a service is requested?

Quoted 8 lines
Quoted 4 lines

Personally, I don't think so.
Think about it: what would userspace do?
Not ask for the functionality if it means no sleep state? Maybe it should just never ask for it then as a required functionality!

1. You may have a human being using the information to make the tradeoff.
2. User space may be able to select among several devices the one cheapest to use

Well, that sounds complex/fragile... and it is really exporting hardware impormation driver does not even neccessarily know.

If this is for user, perhaps it should be in documentation and/or hardware user manual?

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#287 lore raw
In reply to Oliver Neukum
Quoted 12 lines · Oliver Neukum

Am Monday 16 February 2009 18:31:08 schrieb Arjan van de Ven:

Quoted 11 lines
Quoted 7 lines · On Mon, 16 Feb 2009 17:48:06 +0100 Oliver Neukum <[email protected]> wrote:
Quoted 3 lines

Userspace should just be the part that says "I'm interested in link notifications". The driver then just goes to the lowest power state for its device that still gives those notifications.

Should there be a channel through which drivers can tell user space what the consequences in terms of reaching a sleep state are if a service is requested?

Quoted 8 lines
Quoted 4 lines

Personally, I don't think so.
Think about it: what would userspace do?
Not ask for the functionality if it means no sleep state? Maybe it should just never ask for it then as a required functionality!

1. You may have a human being using the information to make the tradeoff.
2. User space may be able to select among several devices the one cheapest to use

Well, that sounds complex/fragile... and it is really exporting hardware impormation driver does not even neccessarily know.

If this is for user, perhaps it should be in documentation and/or hardware user manual?

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#97 lore raw
In reply to Matthew Garrett
Quoted 8 lines · Matthew Garrett
Quoted 4 lines · Rafael J. Wysocki

This, again, seems to be a bit x86-centric. :-) The Android people are telling us that on the hardware they deal with it does make sense to put the entire system to sleep even for relatively short periods of time, since the latencies involved are not too bad.

Arve said that the power state was equivalent in idle and suspend, but

...for Arve's hardware. Not all embedded systems are like that, and OLPC / PCs are definitely not like that.

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#98 lore raw
In reply to Matthew Garrett
Quoted 8 lines · Matthew Garrett
Quoted 4 lines · Rafael J. Wysocki

This, again, seems to be a bit x86-centric. :-) The Android people are telling us that on the hardware they deal with it does make sense to put the entire system to sleep even for relatively short periods of time, since the latencies involved are not too bad.

Arve said that the power state was equivalent in idle and suspend, but

...for Arve's hardware. Not all embedded systems are like that, and OLPC / PCs are definitely not like that.

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#99 lore raw
Quoted 8 lines · Pavel Machek
Quoted 7 lines · Matthew Garrett
Quoted 4 lines · Rafael J. Wysocki

This, again, seems to be a bit x86-centric. :-) The Android people are telling us that on the hardware they deal with it does make sense to put the entire system to sleep even for relatively short periods of time, since the latencies involved are not too bad.

Quoted 4 lines
Quoted 1 line

Arve said that the power state was equivalent in idle and suspend, but

...for Arve's hardware. Not all embedded systems are like that, and OLPC / PCs are definitely not like that.

And PCs have enough latency over suspend/resume that we can't do it automatically in a non-intrusive manner anyway, so runtime pm is more interesting there as well.

Signature · 1 line
Matthew Garrett | [email protected]
#100 lore raw
In reply to Pavel Machek
Quoted 8 lines · Pavel Machek
Quoted 7 lines · Matthew Garrett
Quoted 4 lines · Rafael J. Wysocki

This, again, seems to be a bit x86-centric. :-) The Android people are telling us that on the hardware they deal with it does make sense to put the entire system to sleep even for relatively short periods of time, since the latencies involved are not too bad.

Quoted 4 lines
Quoted 1 line

Arve said that the power state was equivalent in idle and suspend, but

...for Arve's hardware. Not all embedded systems are like that, and OLPC / PCs are definitely not like that.

And PCs have enough latency over suspend/resume that we can't do it automatically in a non-intrusive manner anyway, so runtime pm is more interesting there as well.

Signature · 1 line
Matthew Garrett | [email protected]
#101 lore raw
Quoted 9 lines · Matthew Garrett
Quoted 8 lines · Pavel Machek
Quoted 7 lines · Matthew Garrett
Quoted 4 lines · Rafael J. Wysocki

This, again, seems to be a bit x86-centric. :-) The Android people are telling us that on the hardware they deal with it does make sense to put the entire system to sleep even for relatively short periods of time, since the latencies involved are not too bad.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Arve said that the power state was equivalent in idle and suspend, but

...for Arve's hardware. Not all embedded systems are like that, and OLPC / PCs are definitely not like that.

And PCs have enough latency over suspend/resume that we can't do it automatically in a non-intrusive manner anyway, so runtime pm is more interesting there as well.

Agreed.

Thanks,
Rafael

#102 lore raw
In reply to Matthew Garrett
Quoted 9 lines · Matthew Garrett
Quoted 8 lines · Pavel Machek
Quoted 7 lines · Matthew Garrett
Quoted 4 lines · Rafael J. Wysocki

This, again, seems to be a bit x86-centric. :-) The Android people are telling us that on the hardware they deal with it does make sense to put the entire system to sleep even for relatively short periods of time, since the latencies involved are not too bad.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Arve said that the power state was equivalent in idle and suspend, but

...for Arve's hardware. Not all embedded systems are like that, and OLPC / PCs are definitely not like that.

And PCs have enough latency over suspend/resume that we can't do it automatically in a non-intrusive manner anyway, so runtime pm is more interesting there as well.

Agreed.

Thanks,
Rafael

#161 lore raw
In reply to Kyle Moffett
Quoted 29 lines · Kyle Moffett
Quoted 16 lines · Rafael J. Wysocki

* Introduce /sys/power/sleep that will work like /sys/power/state, but:
- First, it will call ->acknowledge() for each driver (via bus types) to check if any of them wants to postpone the suspend (this will prevent tasks from being frozen unnecessarily if it is known in advance that the suspend should not happen at the moment).
- Next, it will check the "I_do_not_want_automatic_suspend_to_occur" flag of each process and the suspend will be aborted if it is true for any of them (quite frankly, I think that should be integrated with the freezer, in particular the tasks that have TIF_FREEZE set shouldn't be able to set this flag and it should be checked in the freezer loop for every task with TIF_FREEZE unset).
- Next, it will proceed with suspending just like /sys/power/state does (the drivers that missed the opportunity to abort the suspend by returning 'false' from ->acknowledge() can still abort the suspend by failing their ->suspend() routines).

Quoted 3 lines

Then, the decision making logic will be able to use /sys/power/sleep whenever it wishes to and the kernel will be able to refuse to suspend if it's not desirable at the moment.

Then, for a userspace process handling input events:

1)  Unset "no-suspend flag"
2)  Poll event device
3)  When the poll returns true, set the "no-suspend flag"
4)  Read the event device and process the event(s)
5)  Go back to step 1
Quoted 5 lines

The event driver would responsible for atomically preventing suspend from the moment a button is pressed until it is actually delivered to a userspace process. Since at that time the userspace process will be preventing suspend, there will be no window in which we could go to sleep with pending events.

That's correct.

How would you like to prevent it from happening?

Rafael

#162 lore raw
In reply to Kyle Moffett
Quoted 29 lines · Kyle Moffett
Quoted 16 lines · Rafael J. Wysocki

* Introduce /sys/power/sleep that will work like /sys/power/state, but:
- First, it will call ->acknowledge() for each driver (via bus types) to check if any of them wants to postpone the suspend (this will prevent tasks from being frozen unnecessarily if it is known in advance that the suspend should not happen at the moment).
- Next, it will check the "I_do_not_want_automatic_suspend_to_occur" flag of each process and the suspend will be aborted if it is true for any of them (quite frankly, I think that should be integrated with the freezer, in particular the tasks that have TIF_FREEZE set shouldn't be able to set this flag and it should be checked in the freezer loop for every task with TIF_FREEZE unset).
- Next, it will proceed with suspending just like /sys/power/state does (the drivers that missed the opportunity to abort the suspend by returning 'false' from ->acknowledge() can still abort the suspend by failing their ->suspend() routines).

Quoted 3 lines

Then, the decision making logic will be able to use /sys/power/sleep whenever it wishes to and the kernel will be able to refuse to suspend if it's not desirable at the moment.

Then, for a userspace process handling input events:

1)  Unset "no-suspend flag"
2)  Poll event device
3)  When the poll returns true, set the "no-suspend flag"
4)  Read the event device and process the event(s)
5)  Go back to step 1
Quoted 5 lines

The event driver would responsible for atomically preventing suspend from the moment a button is pressed until it is actually delivered to a userspace process. Since at that time the userspace process will be preventing suspend, there will be no window in which we could go to sleep with pending events.

That's correct.

How would you like to prevent it from happening?

Rafael

#163 lore raw
Quoted 36 lines · Rafael J. Wysocki
Quoted 29 lines · Kyle Moffett
Quoted 16 lines · Rafael J. Wysocki

* Introduce /sys/power/sleep that will work like /sys/power/state, but:
- First, it will call ->acknowledge() for each driver (via bus types) to check if any of them wants to postpone the suspend (this will prevent tasks from being frozen unnecessarily if it is known in advance that the suspend should not happen at the moment).
- Next, it will check the "I_do_not_want_automatic_suspend_to_occur" flag of each process and the suspend will be aborted if it is true for any of them (quite frankly, I think that should be integrated with the freezer, in particular the tasks that have TIF_FREEZE set shouldn't be able to set this flag and it should be checked in the freezer loop for every task with TIF_FREEZE unset).
- Next, it will proceed with suspending just like /sys/power/state does (the drivers that missed the opportunity to abort the suspend by returning 'false' from ->acknowledge() can still abort the suspend by failing their ->suspend() routines).

Quoted 3 lines

Then, the decision making logic will be able to use /sys/power/sleep whenever it wishes to and the kernel will be able to refuse to suspend if it's not desirable at the moment.

Then, for a userspace process handling input events:

1)  Unset "no-suspend flag"
2)  Poll event device
3)  When the poll returns true, set the "no-suspend flag"
4)  Read the event device and process the event(s)
5)  Go back to step 1
Quoted 5 lines

The event driver would responsible for atomically preventing suspend from the moment a button is pressed until it is actually delivered to a userspace process. Since at that time the userspace process will be preventing suspend, there will be no window in which we could go to sleep with pending events.

Quoted 3 lines

That's correct.

How would you like to prevent it from happening?

To clarify, we're talking about automatic suspend only. The "old" suspend interface is going to stay so that one can force suspend (or hibernation) to happen.

Thanks,
Rafael

#142 lore raw
In reply to Rafael J. Wysocki

Am Freitag 20 Februar 2009 11:46:55 schrieb Rafael J. Wysocki:

Quoted 9 lines · Oliver Neukum
Quoted 8 lines

Am Donnerstag 19 Februar 2009 23:21:46 schrieb Rafael J. Wysocki:

Quoted 2 lines
Quoted 2 lines

That's the whole point behind userspace wakelocks! They provide a mechanism for userspace to tell the kernel when (as far as userspace

is

Quoted 2 lines
Quoted 1 line

concerned) it is or is not okay to auto-sleep.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Still, one can go further and observe that the user space can in fact start automatic suspend by itself whenever it knows it's appropriate
...

User space initiating this is a race condition.

Do you mean a race with the other user space processes or with the kernel?

With the set of runnable processes.There's always a window between evaluating the current set of runnable tasks and telling the kernel to sleep. IMO the most elegant solution would be a task attribute that would signal the kernel that a task should not count as keeping the system busy even if it is runnable and trigger the sleep in kernel space.

Regards
Oliver

#150 lore raw
In reply to Rafael J. Wysocki

Am Freitag 20 Februar 2009 11:46:55 schrieb Rafael J. Wysocki:

Quoted 9 lines · Oliver Neukum
Quoted 8 lines

Am Donnerstag 19 Februar 2009 23:21:46 schrieb Rafael J. Wysocki:

Quoted 2 lines
Quoted 2 lines

That's the whole point behind userspace wakelocks! They provide a mechanism for userspace to tell the kernel when (as far as userspace

is

Quoted 2 lines
Quoted 1 line

concerned) it is or is not okay to auto-sleep.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Still, one can go further and observe that the user space can in fact start automatic suspend by itself whenever it knows it's appropriate
...

User space initiating this is a race condition.

Do you mean a race with the other user space processes or with the kernel?

With the set of runnable processes.There's always a window between evaluating the current set of runnable tasks and telling the kernel to sleep. IMO the most elegant solution would be a task attribute that would signal the kernel that a task should not count as keeping the system busy even if it is runnable and trigger the sleep in kernel space.

Regards
Oliver

#103 lore raw
In reply to Rafael J. Wysocki
Quoted 12 lines · Rafael J. Wysocki
Quoted 11 lines · Matthew Garrett
Quoted 10 lines · Pavel Machek
Quoted 8 lines · Matthew Garrett
Quoted 4 lines · Rafael J. Wysocki

This, again, seems to be a bit x86-centric. :-) The Android people are telling us that on the hardware they deal with it does make sense to put the entire system to sleep even for relatively short periods of time, since the latencies involved are not too bad.

Arve said that the power state was equivalent in idle and suspend, but

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

...for Arve's hardware. Not all embedded systems are like that, and OLPC / PCs are definitely not like that.

And PCs have enough latency over suspend/resume that we can't do it automatically in a non-intrusive manner anyway, so runtime pm is more interesting there as well.

Agreed.

That high latency is coupled to a large difference in power use. If the latency of the lowest power state is too high to use from idle, it makes it more important, not less important, to enter suspend when possible.

Signature · 1 line
Arve Hjønnevåg
#104 lore raw
In reply to Rafael J. Wysocki
Quoted 12 lines · Rafael J. Wysocki
Quoted 11 lines · Matthew Garrett
Quoted 10 lines · Pavel Machek
Quoted 8 lines · Matthew Garrett
Quoted 4 lines · Rafael J. Wysocki

This, again, seems to be a bit x86-centric. :-) The Android people are telling us that on the hardware they deal with it does make sense to put the entire system to sleep even for relatively short periods of time, since the latencies involved are not too bad.

Arve said that the power state was equivalent in idle and suspend, but

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

...for Arve's hardware. Not all embedded systems are like that, and OLPC / PCs are definitely not like that.

And PCs have enough latency over suspend/resume that we can't do it automatically in a non-intrusive manner anyway, so runtime pm is more interesting there as well.

Agreed.

That high latency is coupled to a large difference in power use. If the latency of the lowest power state is too high to use from idle, it makes it more important, not less important, to enter suspend when possible.

Signature · 1 line
Arve Hjønnevåg
#143 lore raw
In reply to Oliver Neukum
Quoted 16 lines · Oliver Neukum

Am Freitag 20 Februar 2009 11:46:55 schrieb Rafael J. Wysocki:

Quoted 15 lines · Oliver Neukum
Quoted 13 lines

Am Donnerstag 19 Februar 2009 23:21:46 schrieb Rafael J. Wysocki:

Quoted 2 lines
Quoted 2 lines

That's the whole point behind userspace wakelocks! They provide a mechanism for userspace to tell the kernel when (as far as userspace

is

Quoted 5 lines
Quoted 1 line

concerned) it is or is not okay to auto-sleep.

Still, one can go further and observe that the user space can in fact start automatic suspend by itself whenever it knows it's appropriate
...

User space initiating this is a race condition.

Quoted 7 lines
Quoted 1 line

Do you mean a race with the other user space processes or with the kernel?

With the set of runnable processes.There's always a window between evaluating the current set of runnable tasks and telling the kernel to sleep. IMO the most elegant solution would be a task attribute that would signal the kernel that a task should not count as keeping the system busy even if it is runnable and trigger the sleep in kernel space.

Please see my last reply to Arve (http://lkml.org/lkml/2009/2/20/182) and tell me what you think.

Best,
Rafael

#144 lore raw
In reply to Oliver Neukum
Quoted 16 lines · Oliver Neukum

Am Freitag 20 Februar 2009 11:46:55 schrieb Rafael J. Wysocki:

Quoted 15 lines · Oliver Neukum
Quoted 13 lines

Am Donnerstag 19 Februar 2009 23:21:46 schrieb Rafael J. Wysocki:

Quoted 2 lines
Quoted 2 lines

That's the whole point behind userspace wakelocks! They provide a mechanism for userspace to tell the kernel when (as far as userspace

is

Quoted 5 lines
Quoted 1 line

concerned) it is or is not okay to auto-sleep.

Still, one can go further and observe that the user space can in fact start automatic suspend by itself whenever it knows it's appropriate
...

User space initiating this is a race condition.

Quoted 7 lines
Quoted 1 line

Do you mean a race with the other user space processes or with the kernel?

With the set of runnable processes.There's always a window between evaluating the current set of runnable tasks and telling the kernel to sleep. IMO the most elegant solution would be a task attribute that would signal the kernel that a task should not count as keeping the system busy even if it is runnable and trigger the sleep in kernel space.

Please see my last reply to Arve (http://lkml.org/lkml/2009/2/20/182) and tell me what you think.

Best,
Rafael

#164 lore raw
In reply to Rafael J. Wysocki
Quoted 37 lines · Rafael J. Wysocki
Quoted 25 lines · Arve Hjønnevåg
Quoted 21 lines · Rafael J. Wysocki
Quoted 12 lines · Arve Hjønnevåg
Quoted 10 lines · Alan Stern
Quoted 5 lines
Quoted 2 lines

It might have to be platform-specific. The Android people seem to have a pretty good idea of what criteria will work for them.

I'd really like to know in what situations Androind is supposed to suspend automatically.

It might be better to ask in what situations Android is _not_ supposed to sleep automatically. In other words, in what situations is a wakelock acquired? Since the whole system is only a phone, this question should have a reasonably well-defined answer.

Quoted 7 lines

On an android phone, any code that needs to run when the screen is off must hold a wakelock (directly or indirectly). In general if an application or the system is processing an event that may cause a user notification (new email, incoming phone call, alarm, etc.) it needs to prevent suspend. But, we also use wakelocks to upload stats or download system updates in the background, and for media player or (gps) data logging applications.

Quoted 2 lines

All of this doesn't seem to require wakelocks acuired from kernel space. What do you need those wakelocks for?

Quoted 10 lines

Most events do not originate in user-space. Alarms start in our alarm driver which locks a wakelock when its timer interrupt occurs. This wakelock stays locked until the user-space alarm manager calls the driver to wait for the next alarm. I've described how input events are handled before. Without kernel wakelocks, if the user space power manager had already turned off the screen and decided to suspend right before a wakeup key is pressed, then that key could sit in the in-kernel input queue until another key is pressed. Even if the user-space thread read the key event before being frozen, it cannot abort the suspend operation that was already started.

Quoted 6 lines

OK, so what about the following approach:

* Keep the decision making logic (power manager etc.) in user space. Reasons:
- It may be arbitrarily complicated
- It may include such things as s2ram quirks or hal quirks needed for some graphics adapters

I don't using wakelocks in any different in this respect. When user space decides that it is ok for the kernel to suspend it should have performed all theses steps in both cases.

Quoted 3 lines

* Have a per-process (per-task or per-thread group, but the former would be easier IMO) "I_do_not_want_automatic_suspend_to_occur" flag.

A per-process (thread group) flag allows wakelocks to be implemented in a user space library. A per-thread flag does not. However, I don't see much benefit in tying this to a process instead of using a file descriptor.

Quoted 22 lines

* Add a new callback, say ->acknowledge(), to the set of each driver's PM operations, that will be called to check if the driver has anything against automatic suspend (true - suspend can happen right now, false - suspend can't happen).

* Introduce /sys/power/sleep that will work like /sys/power/state, but:
- First, it will call ->acknowledge() for each driver (via bus types) to check if any of them wants to postpone the suspend (this will prevent tasks from being frozen unnecessarily if it is known in advance that the suspend should not happen at the moment).
- Next, it will check the "I_do_not_want_automatic_suspend_to_occur" flag of each process and the suspend will be aborted if it is true for any of them (quite frankly, I think that should be integrated with the freezer, in particular the tasks that have TIF_FREEZE set shouldn't be able to set this flag and it should be checked in the freezer loop for every task with TIF_FREEZE unset).
- Next, it will proceed with suspending just like /sys/power/state does (the drivers that missed the opportunity to abort the suspend by returning 'false' from ->acknowledge() can still abort the suspend by failing their ->suspend() routines).

Quoted 5 lines

Then, the decision making logic will be able to use /sys/power/sleep whenever it wishes to and the kernel will be able to refuse to suspend if it's not desirable at the moment.

It seems to be flexible enough to me.

This seems flexible enough to avoid race conditions, but it forces the user space power manager to poll when the kernel refuse suspend. Also, like my original wakelock patches, it breaks sleep requests through /sys/power/state when there are input events queued.

Signature · 1 line
Arve Hjønnevåg
#165 lore raw
In reply to Rafael J. Wysocki
Quoted 37 lines · Rafael J. Wysocki
Quoted 25 lines · Arve Hjønnevåg
Quoted 21 lines · Rafael J. Wysocki
Quoted 12 lines · Arve Hjønnevåg
Quoted 10 lines · Alan Stern
Quoted 5 lines
Quoted 2 lines

It might have to be platform-specific. The Android people seem to have a pretty good idea of what criteria will work for them.

I'd really like to know in what situations Androind is supposed to suspend automatically.

It might be better to ask in what situations Android is _not_ supposed to sleep automatically. In other words, in what situations is a wakelock acquired? Since the whole system is only a phone, this question should have a reasonably well-defined answer.

Quoted 7 lines

On an android phone, any code that needs to run when the screen is off must hold a wakelock (directly or indirectly). In general if an application or the system is processing an event that may cause a user notification (new email, incoming phone call, alarm, etc.) it needs to prevent suspend. But, we also use wakelocks to upload stats or download system updates in the background, and for media player or (gps) data logging applications.

Quoted 2 lines

All of this doesn't seem to require wakelocks acuired from kernel space. What do you need those wakelocks for?

Quoted 10 lines

Most events do not originate in user-space. Alarms start in our alarm driver which locks a wakelock when its timer interrupt occurs. This wakelock stays locked until the user-space alarm manager calls the driver to wait for the next alarm. I've described how input events are handled before. Without kernel wakelocks, if the user space power manager had already turned off the screen and decided to suspend right before a wakeup key is pressed, then that key could sit in the in-kernel input queue until another key is pressed. Even if the user-space thread read the key event before being frozen, it cannot abort the suspend operation that was already started.

Quoted 6 lines

OK, so what about the following approach:

* Keep the decision making logic (power manager etc.) in user space. Reasons:
- It may be arbitrarily complicated
- It may include such things as s2ram quirks or hal quirks needed for some graphics adapters

I don't using wakelocks in any different in this respect. When user space decides that it is ok for the kernel to suspend it should have performed all theses steps in both cases.

Quoted 3 lines

* Have a per-process (per-task or per-thread group, but the former would be easier IMO) "I_do_not_want_automatic_suspend_to_occur" flag.

A per-process (thread group) flag allows wakelocks to be implemented in a user space library. A per-thread flag does not. However, I don't see much benefit in tying this to a process instead of using a file descriptor.

Quoted 22 lines

* Add a new callback, say ->acknowledge(), to the set of each driver's PM operations, that will be called to check if the driver has anything against automatic suspend (true - suspend can happen right now, false - suspend can't happen).

* Introduce /sys/power/sleep that will work like /sys/power/state, but:
- First, it will call ->acknowledge() for each driver (via bus types) to check if any of them wants to postpone the suspend (this will prevent tasks from being frozen unnecessarily if it is known in advance that the suspend should not happen at the moment).
- Next, it will check the "I_do_not_want_automatic_suspend_to_occur" flag of each process and the suspend will be aborted if it is true for any of them (quite frankly, I think that should be integrated with the freezer, in particular the tasks that have TIF_FREEZE set shouldn't be able to set this flag and it should be checked in the freezer loop for every task with TIF_FREEZE unset).
- Next, it will proceed with suspending just like /sys/power/state does (the drivers that missed the opportunity to abort the suspend by returning 'false' from ->acknowledge() can still abort the suspend by failing their ->suspend() routines).

Quoted 5 lines

Then, the decision making logic will be able to use /sys/power/sleep whenever it wishes to and the kernel will be able to refuse to suspend if it's not desirable at the moment.

It seems to be flexible enough to me.

This seems flexible enough to avoid race conditions, but it forces the user space power manager to poll when the kernel refuse suspend. Also, like my original wakelock patches, it breaks sleep requests through /sys/power/state when there are input events queued.

Signature · 1 line
Arve Hjønnevåg
#243 lore raw
In reply to Rafael J. Wysocki

Am Freitag 20 Februar 2009 16:56:59 schrieb Rafael J. Wysocki:

Quoted 4 lines

OK, so what about the following approach:

* Keep the decision making logic (power manager etc.) in user space.
Reasons: - It may be arbitrarily complicated

Therefore something functionally equivalent to wakelocks is needed.

Quoted 2 lines

- It may include such things as s2ram quirks or hal quirks needed for
some graphics adapters

If you can't do that I'd say the situation is hopeless. You need full support for all devices including graphics cards.

Quoted 2 lines

* Have a per-process (per-task or per-thread group, but the former would be easier IMO) "I_do_not_want_automatic_suspend_to_occur" flag.

I think you got the default logic inverted.

Quoted 10 lines

* Add a new callback, say ->acknowledge(), to the set of each driver's PM operations, that will be called to check if the driver has anything
against automatic suspend (true - suspend can happen right now, false - suspend can't happen).

* Introduce /sys/power/sleep that will work like /sys/power/state, but:
- First, it will call ->acknowledge() for each driver (via bus types) to check if any of them wants to postpone the suspend (this will prevent
tasks from being frozen unnecessarily if it is known in advance that the suspend should not happen at the moment).

Ideally most devices should be already suspended, so I am not sure a new callback is really needed. In any cases it is an optimization only.

Quoted 6 lines

- Next, it will check the "I_do_not_want_automatic_suspend_to_occur" flag of each process and the suspend will be aborted if it is true for any
of them (quite frankly, I think that should be integrated with the freezer, in particular the tasks that have TIF_FREEZE set shouldn't be able to set this flag and it should be checked in the freezer loop for every task with TIF_FREEZE unset).

Why in this order?

Quoted 8 lines

- Next, it will proceed with suspending just like /sys/power/state does
(the drivers that missed the opportunity to abort the suspend by returning 'false' from ->acknowledge() can still abort the suspend by failing their ->suspend() routines).

Then, the decision making logic will be able to use /sys/power/sleep whenever it wishes to and the kernel will be able to refuse to suspend if it's not desirable at the moment.

I think everything that uses a "trigger" logic from user space is not a good idea. This will necessary introduce a race between the decision and the execution during which circumstances can change.

So it seems to me that an allow/disallow system from user space would be better.

Regards
Oliver

#145 lore raw
In reply to Oliver Neukum
Quoted 16 lines · Oliver Neukum

Am Freitag 20 Februar 2009 11:46:55 schrieb Rafael J. Wysocki:

Quoted 15 lines · Oliver Neukum
Quoted 13 lines

Am Donnerstag 19 Februar 2009 23:21:46 schrieb Rafael J. Wysocki:

Quoted 2 lines
Quoted 2 lines

That's the whole point behind userspace wakelocks! They provide a mechanism for userspace to tell the kernel when (as far as userspace

is

Quoted 5 lines
Quoted 1 line

concerned) it is or is not okay to auto-sleep.

Still, one can go further and observe that the user space can in fact start automatic suspend by itself whenever it knows it's appropriate
...

User space initiating this is a race condition.

Quoted 7 lines
Quoted 1 line

Do you mean a race with the other user space processes or with the kernel?

With the set of runnable processes.There's always a window between evaluating the current set of runnable tasks and telling the kernel to sleep. IMO the most elegant solution would be a task attribute that would signal the kernel that a task should not count as keeping the system busy even if it is runnable and trigger the sleep in kernel space.

It is not always safe to enter suspend when no tasks are runnable. For instance, a key event could be on a user space queue, but the code that reads from that queue has been paged out.

Signature · 1 line
Arve Hjønnevåg
#260 lore raw
In reply to Rafael J. Wysocki

Am Freitag 20 Februar 2009 16:56:59 schrieb Rafael J. Wysocki:

Quoted 4 lines

OK, so what about the following approach:

* Keep the decision making logic (power manager etc.) in user space.
Reasons: - It may be arbitrarily complicated

Therefore something functionally equivalent to wakelocks is needed.

Quoted 2 lines

- It may include such things as s2ram quirks or hal quirks needed for
some graphics adapters

If you can't do that I'd say the situation is hopeless. You need full support for all devices including graphics cards.

Quoted 2 lines

* Have a per-process (per-task or per-thread group, but the former would be easier IMO) "I_do_not_want_automatic_suspend_to_occur" flag.

I think you got the default logic inverted.

Quoted 10 lines

* Add a new callback, say ->acknowledge(), to the set of each driver's PM operations, that will be called to check if the driver has anything
against automatic suspend (true - suspend can happen right now, false - suspend can't happen).

* Introduce /sys/power/sleep that will work like /sys/power/state, but:
- First, it will call ->acknowledge() for each driver (via bus types) to check if any of them wants to postpone the suspend (this will prevent
tasks from being frozen unnecessarily if it is known in advance that the suspend should not happen at the moment).

Ideally most devices should be already suspended, so I am not sure a new callback is really needed. In any cases it is an optimization only.

Quoted 6 lines

- Next, it will check the "I_do_not_want_automatic_suspend_to_occur" flag of each process and the suspend will be aborted if it is true for any
of them (quite frankly, I think that should be integrated with the freezer, in particular the tasks that have TIF_FREEZE set shouldn't be able to set this flag and it should be checked in the freezer loop for every task with TIF_FREEZE unset).

Why in this order?

Quoted 8 lines

- Next, it will proceed with suspending just like /sys/power/state does
(the drivers that missed the opportunity to abort the suspend by returning 'false' from ->acknowledge() can still abort the suspend by failing their ->suspend() routines).

Then, the decision making logic will be able to use /sys/power/sleep whenever it wishes to and the kernel will be able to refuse to suspend if it's not desirable at the moment.

I think everything that uses a "trigger" logic from user space is not a good idea. This will necessary introduce a race between the decision and the execution during which circumstances can change.

So it seems to me that an allow/disallow system from user space would be better.

Regards
Oliver

#146 lore raw
In reply to Arve Hjønnevåg

Am Samstag 21 Februar 2009 00:11:28 schrieb Arve Hjønnevåg:

Quoted 10 lines · Oliver Neukum
Quoted 8 lines

Am Freitag 20 Februar 2009 11:46:55 schrieb Rafael J. Wysocki:

Quoted 1 line · Oliver Neukum

With the set of runnable processes.There's always a window between evaluating the current set of runnable tasks and telling the kernel to sleep. IMO the most elegant solution would be a task attribute that would signal the kernel that a task should not count as keeping the system busy even if it is runnable and trigger the sleep in kernel space.

Quoted 3 lines

It is not always safe to enter suspend when no tasks are runnable. For instance, a key event could be on a user space queue, but the code that reads from that queue has been paged out.

In that case you'd have a task waiting for IO. The driver should refuse to suspend or wake up the system as IO is completed. It may be inefficient to suspend for such a presumably short time, but it is not a correctness issue.

Regards
Oliver

#149 lore raw
In reply to Arve Hjønnevåg

Am Samstag 21 Februar 2009 00:11:28 schrieb Arve Hjønnevåg:

Quoted 10 lines · Oliver Neukum
Quoted 8 lines

Am Freitag 20 Februar 2009 11:46:55 schrieb Rafael J. Wysocki:

Quoted 1 line · Oliver Neukum

With the set of runnable processes.There's always a window between evaluating the current set of runnable tasks and telling the kernel to sleep. IMO the most elegant solution would be a task attribute that would signal the kernel that a task should not count as keeping the system busy even if it is runnable and trigger the sleep in kernel space.

Quoted 3 lines

It is not always safe to enter suspend when no tasks are runnable. For instance, a key event could be on a user space queue, but the code that reads from that queue has been paged out.

In that case you'd have a task waiting for IO. The driver should refuse to suspend or wake up the system as IO is completed. It may be inefficient to suspend for such a presumably short time, but it is not a correctness issue.

Regards
Oliver

#244 lore raw
In reply to Oliver Neukum
Quoted 10 lines · Oliver Neukum

Am Freitag 20 Februar 2009 16:56:59 schrieb Rafael J. Wysocki:

Quoted 4 lines

OK, so what about the following approach:

* Keep the decision making logic (power manager etc.) in user space.
Reasons: - It may be arbitrarily complicated

Therefore something functionally equivalent to wakelocks is needed.

Quoted 6 lines
Quoted 2 lines

- It may include such things as s2ram quirks or hal quirks needed for
some graphics adapters

If you can't do that I'd say the situation is hopeless. You need full support for all devices including graphics cards.

We can't do the quirks from the kernel and that's one of the reasons why I think user space should start automatic suspend (it can do the quirks if necessary).

Quoted 4 lines
Quoted 2 lines

* Have a per-process (per-task or per-thread group, but the former would be easier IMO) "I_do_not_want_automatic_suspend_to_occur" flag.

I think you got the default logic inverted.

Well, it may be "suspend_possible_right_now" just as well. :-)

Quoted 11 lines
Quoted 10 lines

* Add a new callback, say ->acknowledge(), to the set of each driver's PM operations, that will be called to check if the driver has anything
against automatic suspend (true - suspend can happen right now, false - suspend can't happen).

* Introduce /sys/power/sleep that will work like /sys/power/state, but:
- First, it will call ->acknowledge() for each driver (via bus types) to check if any of them wants to postpone the suspend (this will prevent
tasks from being frozen unnecessarily if it is known in advance that the suspend should not happen at the moment).

Quoted 3 lines

Ideally most devices should be already suspended, so I am not sure a new callback is really needed. In any cases it is an optimization only.

Yes, it is, but an important one (the total time of freezing and thawing tasks can be substantial).

Quoted 8 lines
Quoted 6 lines

- Next, it will check the "I_do_not_want_automatic_suspend_to_occur" flag of each process and the suspend will be aborted if it is true for any
of them (quite frankly, I think that should be integrated with the freezer, in particular the tasks that have TIF_FREEZE set shouldn't be able to set this flag and it should be checked in the freezer loop for every task with TIF_FREEZE unset).

Why in this order?

Because the freezing of tasks takes time and it would be a bad idea to do it unnecessarily.

Quoted 5 lines
Quoted 5 lines

- Next, it will proceed with suspending just like /sys/power/state does
(the drivers that missed the opportunity to abort the suspend by returning 'false' from ->acknowledge() can still abort the suspend by failing their ->suspend() routines).

Quoted 7 lines
Quoted 3 lines

Then, the decision making logic will be able to use /sys/power/sleep whenever it wishes to and the kernel will be able to refuse to suspend if it's not desirable at the moment.

I think everything that uses a "trigger" logic from user space is not a good idea. This will necessary introduce a race between the decision and the execution during which circumstances can change.

Well, in this particulare case if the circumstances change in the meantime, the kernel will just refuse to suspend. Also, even if the kernel starts automatic suspend, it _still_ is possible that the conditions change in the meantime (for example, one of the tasks may enter a state in which it wouldn't like to the suspend to happen just after the operation is started and before it's frozen).

Quoted 2 lines

So it seems to me that an allow/disallow system from user space would be better.

I don't really see the benefit, but I can easily see drawbacks (the handling of graphics that requires user space quirks, for instance).

Thanks,
Rafael

#245 lore raw
In reply to Oliver Neukum
Quoted 10 lines · Oliver Neukum

Am Freitag 20 Februar 2009 16:56:59 schrieb Rafael J. Wysocki:

Quoted 4 lines

OK, so what about the following approach:

* Keep the decision making logic (power manager etc.) in user space.
Reasons: - It may be arbitrarily complicated

Therefore something functionally equivalent to wakelocks is needed.

Quoted 6 lines
Quoted 2 lines

- It may include such things as s2ram quirks or hal quirks needed for
some graphics adapters

If you can't do that I'd say the situation is hopeless. You need full support for all devices including graphics cards.

We can't do the quirks from the kernel and that's one of the reasons why I think user space should start automatic suspend (it can do the quirks if necessary).

Quoted 4 lines
Quoted 2 lines

* Have a per-process (per-task or per-thread group, but the former would be easier IMO) "I_do_not_want_automatic_suspend_to_occur" flag.

I think you got the default logic inverted.

Well, it may be "suspend_possible_right_now" just as well. :-)

Quoted 11 lines
Quoted 10 lines

* Add a new callback, say ->acknowledge(), to the set of each driver's PM operations, that will be called to check if the driver has anything
against automatic suspend (true - suspend can happen right now, false - suspend can't happen).

* Introduce /sys/power/sleep that will work like /sys/power/state, but:
- First, it will call ->acknowledge() for each driver (via bus types) to check if any of them wants to postpone the suspend (this will prevent
tasks from being frozen unnecessarily if it is known in advance that the suspend should not happen at the moment).

Quoted 3 lines

Ideally most devices should be already suspended, so I am not sure a new callback is really needed. In any cases it is an optimization only.

Yes, it is, but an important one (the total time of freezing and thawing tasks can be substantial).

Quoted 8 lines
Quoted 6 lines

- Next, it will check the "I_do_not_want_automatic_suspend_to_occur" flag of each process and the suspend will be aborted if it is true for any
of them (quite frankly, I think that should be integrated with the freezer, in particular the tasks that have TIF_FREEZE set shouldn't be able to set this flag and it should be checked in the freezer loop for every task with TIF_FREEZE unset).

Why in this order?

Because the freezing of tasks takes time and it would be a bad idea to do it unnecessarily.

Quoted 5 lines
Quoted 5 lines

- Next, it will proceed with suspending just like /sys/power/state does
(the drivers that missed the opportunity to abort the suspend by returning 'false' from ->acknowledge() can still abort the suspend by failing their ->suspend() routines).

Quoted 7 lines
Quoted 3 lines

Then, the decision making logic will be able to use /sys/power/sleep whenever it wishes to and the kernel will be able to refuse to suspend if it's not desirable at the moment.

I think everything that uses a "trigger" logic from user space is not a good idea. This will necessary introduce a race between the decision and the execution during which circumstances can change.

Well, in this particulare case if the circumstances change in the meantime, the kernel will just refuse to suspend. Also, even if the kernel starts automatic suspend, it _still_ is possible that the conditions change in the meantime (for example, one of the tasks may enter a state in which it wouldn't like to the suspend to happen just after the operation is started and before it's frozen).

Quoted 2 lines

So it seems to me that an allow/disallow system from user space would be better.

I don't really see the benefit, but I can easily see drawbacks (the handling of graphics that requires user space quirks, for instance).

Thanks,
Rafael

#246 lore raw
Quoted 3 lines · Rafael J. Wysocki

We can't do the quirks from the kernel and that's one of the reasons why I think user space should start automatic suspend (it can do the quirks if necessary).

Any sort of automatic suspend is simply impossible in a world where your drivers don't work properly. There's code for making intel and radeon handle suspend/resume themselves now, and nvidia before g80 should also be easy. More recent nvidia is going to be some work.

But yeah. Let's not have "Work around broken drivers" as a design goal. The argument against timeouts in wakelocks works just as well here.

Signature · 1 line
Matthew Garrett | [email protected]
#247 lore raw
In reply to Rafael J. Wysocki
Quoted 3 lines · Rafael J. Wysocki

We can't do the quirks from the kernel and that's one of the reasons why I think user space should start automatic suspend (it can do the quirks if necessary).

Any sort of automatic suspend is simply impossible in a world where your drivers don't work properly. There's code for making intel and radeon handle suspend/resume themselves now, and nvidia before g80 should also be easy. More recent nvidia is going to be some work.

But yeah. Let's not have "Work around broken drivers" as a design goal. The argument against timeouts in wakelocks works just as well here.

Signature · 1 line
Matthew Garrett | [email protected]
#166 lore raw
In reply to Arve Hjønnevåg
Quoted 40 lines · Arve Hjønnevåg
Quoted 39 lines · Rafael J. Wysocki
Quoted 25 lines · Arve Hjønnevåg
Quoted 21 lines · Rafael J. Wysocki
Quoted 12 lines · Arve Hjønnevåg
Quoted 10 lines · Alan Stern
Quoted 5 lines
Quoted 2 lines

It might have to be platform-specific. The Android people seem to have a pretty good idea of what criteria will work for them.

I'd really like to know in what situations Androind is supposed to suspend automatically.

It might be better to ask in what situations Android is _not_ supposed to sleep automatically. In other words, in what situations is a wakelock acquired? Since the whole system is only a phone, this question should have a reasonably well-defined answer.

Quoted 7 lines

On an android phone, any code that needs to run when the screen is off must hold a wakelock (directly or indirectly). In general if an application or the system is processing an event that may cause a user notification (new email, incoming phone call, alarm, etc.) it needs to prevent suspend. But, we also use wakelocks to upload stats or download system updates in the background, and for media player or (gps) data logging applications.

Quoted 2 lines

All of this doesn't seem to require wakelocks acuired from kernel space. What do you need those wakelocks for?

Quoted 10 lines

Most events do not originate in user-space. Alarms start in our alarm driver which locks a wakelock when its timer interrupt occurs. This wakelock stays locked until the user-space alarm manager calls the driver to wait for the next alarm. I've described how input events are handled before. Without kernel wakelocks, if the user space power manager had already turned off the screen and decided to suspend right before a wakeup key is pressed, then that key could sit in the in-kernel input queue until another key is pressed. Even if the user-space thread read the key event before being frozen, it cannot abort the suspend operation that was already started.

OK, so what about the following approach:

Quoted 8 lines
Quoted 4 lines

* Keep the decision making logic (power manager etc.) in user space. Reasons:
- It may be arbitrarily complicated
- It may include such things as s2ram quirks or hal quirks needed for some graphics adapters

I don't using wakelocks in any different in this respect. When user space decides that it is ok for the kernel to suspend it should have performed all theses steps in both cases.

If automatic suspend is to be started by the kernel, you have to make sure that at least one wakelock is held until these steps are completed. That may be somewhat tricky in general.

Quoted 7 lines
Quoted 2 lines

* Have a per-process (per-task or per-thread group, but the former would be easier IMO) "I_do_not_want_automatic_suspend_to_occur" flag.

A per-process (thread group) flag allows wakelocks to be implemented in a user space library. A per-thread flag does not. However, I don't see much benefit in tying this to a process instead of using a file descriptor.

Using a flag would allow us to remove the window between checking the wakelocks and freezing tasks (in principle a task may take a wakelock just before it's frozen).

Quoted 22 lines
Quoted 22 lines

* Add a new callback, say ->acknowledge(), to the set of each driver's PM operations, that will be called to check if the driver has anything against automatic suspend (true - suspend can happen right now, false - suspend can't happen).

* Introduce /sys/power/sleep that will work like /sys/power/state, but:
- First, it will call ->acknowledge() for each driver (via bus types) to check if any of them wants to postpone the suspend (this will prevent tasks from being frozen unnecessarily if it is known in advance that the suspend should not happen at the moment).
- Next, it will check the "I_do_not_want_automatic_suspend_to_occur" flag of each process and the suspend will be aborted if it is true for any of them (quite frankly, I think that should be integrated with the freezer, in particular the tasks that have TIF_FREEZE set shouldn't be able to set this flag and it should be checked in the freezer loop for every task with TIF_FREEZE unset).
- Next, it will proceed with suspending just like /sys/power/state does (the drivers that missed the opportunity to abort the suspend by returning 'false' from ->acknowledge() can still abort the suspend by failing their ->suspend() routines).

Quoted 8 lines
Quoted 5 lines

Then, the decision making logic will be able to use /sys/power/sleep whenever it wishes to and the kernel will be able to refuse to suspend if it's not desirable at the moment.

It seems to be flexible enough to me.

This seems flexible enough to avoid race conditions, but it forces the user space power manager to poll when the kernel refuse suspend.

And if the kernel is supposed to start automatic suspend, it has to monitor all of the wakelocks. IMO, it's better to allow the power manager to poll the kernel if it refuses to suspend.

Quoted 2 lines

Also, like my original wakelock patches, it breaks sleep requests through /sys/power/state when there are input events queued.

The idea is to have both /sys/power/state and /sys/power/sleep at the same time, where /sys/power/state will work just like it does right now. Sure, there must be mutual exclusion between the two, but that's a matter of implementation IMO.

Thanks,
Rafael

#167 lore raw
In reply to Arve Hjønnevåg
Quoted 40 lines · Arve Hjønnevåg
Quoted 39 lines · Rafael J. Wysocki
Quoted 25 lines · Arve Hjønnevåg
Quoted 21 lines · Rafael J. Wysocki
Quoted 12 lines · Arve Hjønnevåg
Quoted 10 lines · Alan Stern
Quoted 5 lines
Quoted 2 lines

It might have to be platform-specific. The Android people seem to have a pretty good idea of what criteria will work for them.

I'd really like to know in what situations Androind is supposed to suspend automatically.

It might be better to ask in what situations Android is _not_ supposed to sleep automatically. In other words, in what situations is a wakelock acquired? Since the whole system is only a phone, this question should have a reasonably well-defined answer.

Quoted 7 lines

On an android phone, any code that needs to run when the screen is off must hold a wakelock (directly or indirectly). In general if an application or the system is processing an event that may cause a user notification (new email, incoming phone call, alarm, etc.) it needs to prevent suspend. But, we also use wakelocks to upload stats or download system updates in the background, and for media player or (gps) data logging applications.

Quoted 2 lines

All of this doesn't seem to require wakelocks acuired from kernel space. What do you need those wakelocks for?

Quoted 10 lines

Most events do not originate in user-space. Alarms start in our alarm driver which locks a wakelock when its timer interrupt occurs. This wakelock stays locked until the user-space alarm manager calls the driver to wait for the next alarm. I've described how input events are handled before. Without kernel wakelocks, if the user space power manager had already turned off the screen and decided to suspend right before a wakeup key is pressed, then that key could sit in the in-kernel input queue until another key is pressed. Even if the user-space thread read the key event before being frozen, it cannot abort the suspend operation that was already started.

OK, so what about the following approach:

Quoted 8 lines
Quoted 4 lines

* Keep the decision making logic (power manager etc.) in user space. Reasons:
- It may be arbitrarily complicated
- It may include such things as s2ram quirks or hal quirks needed for some graphics adapters

I don't using wakelocks in any different in this respect. When user space decides that it is ok for the kernel to suspend it should have performed all theses steps in both cases.

If automatic suspend is to be started by the kernel, you have to make sure that at least one wakelock is held until these steps are completed. That may be somewhat tricky in general.

Quoted 7 lines
Quoted 2 lines

* Have a per-process (per-task or per-thread group, but the former would be easier IMO) "I_do_not_want_automatic_suspend_to_occur" flag.

A per-process (thread group) flag allows wakelocks to be implemented in a user space library. A per-thread flag does not. However, I don't see much benefit in tying this to a process instead of using a file descriptor.

Using a flag would allow us to remove the window between checking the wakelocks and freezing tasks (in principle a task may take a wakelock just before it's frozen).

Quoted 22 lines
Quoted 22 lines

* Add a new callback, say ->acknowledge(), to the set of each driver's PM operations, that will be called to check if the driver has anything against automatic suspend (true - suspend can happen right now, false - suspend can't happen).

* Introduce /sys/power/sleep that will work like /sys/power/state, but:
- First, it will call ->acknowledge() for each driver (via bus types) to check if any of them wants to postpone the suspend (this will prevent tasks from being frozen unnecessarily if it is known in advance that the suspend should not happen at the moment).
- Next, it will check the "I_do_not_want_automatic_suspend_to_occur" flag of each process and the suspend will be aborted if it is true for any of them (quite frankly, I think that should be integrated with the freezer, in particular the tasks that have TIF_FREEZE set shouldn't be able to set this flag and it should be checked in the freezer loop for every task with TIF_FREEZE unset).
- Next, it will proceed with suspending just like /sys/power/state does (the drivers that missed the opportunity to abort the suspend by returning 'false' from ->acknowledge() can still abort the suspend by failing their ->suspend() routines).

Quoted 8 lines
Quoted 5 lines

Then, the decision making logic will be able to use /sys/power/sleep whenever it wishes to and the kernel will be able to refuse to suspend if it's not desirable at the moment.

It seems to be flexible enough to me.

This seems flexible enough to avoid race conditions, but it forces the user space power manager to poll when the kernel refuse suspend.

And if the kernel is supposed to start automatic suspend, it has to monitor all of the wakelocks. IMO, it's better to allow the power manager to poll the kernel if it refuses to suspend.

Quoted 2 lines

Also, like my original wakelock patches, it breaks sleep requests through /sys/power/state when there are input events queued.

The idea is to have both /sys/power/state and /sys/power/sleep at the same time, where /sys/power/state will work just like it does right now. Sure, there must be mutual exclusion between the two, but that's a matter of implementation IMO.

Thanks,
Rafael

#168 lore raw
Quoted 46 lines · Rafael J. Wysocki
Quoted 45 lines · Arve Hjønnevåg
Quoted 43 lines · Rafael J. Wysocki
Quoted 25 lines · Arve Hjønnevåg
Quoted 21 lines · Rafael J. Wysocki
Quoted 12 lines · Arve Hjønnevåg
Quoted 10 lines · Alan Stern
Quoted 5 lines
Quoted 2 lines

It might have to be platform-specific. The Android people seem to have a pretty good idea of what criteria will work for them.

I'd really like to know in what situations Androind is supposed to suspend automatically.

It might be better to ask in what situations Android is _not_ supposed to sleep automatically. In other words, in what situations is a wakelock acquired? Since the whole system is only a phone, this question should have a reasonably well-defined answer.

Quoted 7 lines

On an android phone, any code that needs to run when the screen is off must hold a wakelock (directly or indirectly). In general if an application or the system is processing an event that may cause a user notification (new email, incoming phone call, alarm, etc.) it needs to prevent suspend. But, we also use wakelocks to upload stats or download system updates in the background, and for media player or (gps) data logging applications.

Quoted 2 lines

All of this doesn't seem to require wakelocks acuired from kernel space. What do you need those wakelocks for?

Quoted 10 lines

Most events do not originate in user-space. Alarms start in our alarm driver which locks a wakelock when its timer interrupt occurs. This wakelock stays locked until the user-space alarm manager calls the driver to wait for the next alarm. I've described how input events are handled before. Without kernel wakelocks, if the user space power manager had already turned off the screen and decided to suspend right before a wakeup key is pressed, then that key could sit in the in-kernel input queue until another key is pressed. Even if the user-space thread read the key event before being frozen, it cannot abort the suspend operation that was already started.

OK, so what about the following approach:

* Keep the decision making logic (power manager etc.) in user space. Reasons:
- It may be arbitrarily complicated
- It may include such things as s2ram quirks or hal quirks needed for some graphics adapters

Quoted 7 lines
Quoted 3 lines

I don't using wakelocks in any different in this respect. When user space decides that it is ok for the kernel to suspend it should have performed all theses steps in both cases.

If automatic suspend is to be started by the kernel, you have to make sure that at least one wakelock is held until these steps are completed. That may be somewhat tricky in general.

That is not tricky. If your code holds a wakelock, then at least one wakelock is held.

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

* Have a per-process (per-task or per-thread group, but the former would be easier IMO) "I_do_not_want_automatic_suspend_to_occur" flag.

Quoted 8 lines
Quoted 4 lines

A per-process (thread group) flag allows wakelocks to be implemented in a user space library. A per-thread flag does not. However, I don't see much benefit in tying this to a process instead of using a file descriptor.

Using a flag would allow us to remove the window between checking the wakelocks and freezing tasks (in principle a task may take a wakelock just before it's frozen).

You can check if there are wakelocks held from the same spot as you check your flag.

Quoted 27 lines
Quoted 27 lines
Quoted 27 lines

* Add a new callback, say ->acknowledge(), to the set of each driver's PM operations, that will be called to check if the driver has anything against automatic suspend (true - suspend can happen right now, false - suspend can't happen).

* Introduce /sys/power/sleep that will work like /sys/power/state, but:
- First, it will call ->acknowledge() for each driver (via bus types) to check if any of them wants to postpone the suspend (this will prevent tasks from being frozen unnecessarily if it is known in advance that the suspend should not happen at the moment).
- Next, it will check the "I_do_not_want_automatic_suspend_to_occur" flag of each process and the suspend will be aborted if it is true for any of them (quite frankly, I think that should be integrated with the freezer, in particular the tasks that have TIF_FREEZE set shouldn't be able to set this flag and it should be checked in the freezer loop for every task with TIF_FREEZE unset).
- Next, it will proceed with suspending just like /sys/power/state does (the drivers that missed the opportunity to abort the suspend by returning 'false' from ->acknowledge() can still abort the suspend by failing their ->suspend() routines).

Then, the decision making logic will be able to use /sys/power/sleep whenever it wishes to and the kernel will be able to refuse to suspend if it's not desirable at the moment.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

It seems to be flexible enough to me.

This seems flexible enough to avoid race conditions, but it forces the user space power manager to poll when the kernel refuse suspend.

And if the kernel is supposed to start automatic suspend, it has to monitor all of the wakelocks. IMO, it's better to allow the power manager to poll the kernel if it refuses to suspend.

What is better about polling in userspace?

Quoted 8 lines
Quoted 3 lines

Also, like my original wakelock patches, it breaks sleep requests through /sys/power/state when there are input events queued.

The idea is to have both /sys/power/state and /sys/power/sleep at the same time, where /sys/power/state will work just like it does right now. Sure, there must be mutual exclusion between the two, but that's a matter of implementation IMO.

If you want to only prevent suspend though one interface, you have to also pass information to the driver about its suspend hook is being called so it can conditionally return -EBUSY. The wakelock interface requires less code in each driver.

Signature · 1 line
Arve Hjønnevåg
#169 lore raw
In reply to Rafael J. Wysocki
Quoted 46 lines · Rafael J. Wysocki
Quoted 45 lines · Arve Hjønnevåg
Quoted 43 lines · Rafael J. Wysocki
Quoted 25 lines · Arve Hjønnevåg
Quoted 21 lines · Rafael J. Wysocki
Quoted 12 lines · Arve Hjønnevåg
Quoted 10 lines · Alan Stern
Quoted 5 lines
Quoted 2 lines

It might have to be platform-specific. The Android people seem to have a pretty good idea of what criteria will work for them.

I'd really like to know in what situations Androind is supposed to suspend automatically.

It might be better to ask in what situations Android is _not_ supposed to sleep automatically. In other words, in what situations is a wakelock acquired? Since the whole system is only a phone, this question should have a reasonably well-defined answer.

Quoted 7 lines

On an android phone, any code that needs to run when the screen is off must hold a wakelock (directly or indirectly). In general if an application or the system is processing an event that may cause a user notification (new email, incoming phone call, alarm, etc.) it needs to prevent suspend. But, we also use wakelocks to upload stats or download system updates in the background, and for media player or (gps) data logging applications.

Quoted 2 lines

All of this doesn't seem to require wakelocks acuired from kernel space. What do you need those wakelocks for?

Quoted 10 lines

Most events do not originate in user-space. Alarms start in our alarm driver which locks a wakelock when its timer interrupt occurs. This wakelock stays locked until the user-space alarm manager calls the driver to wait for the next alarm. I've described how input events are handled before. Without kernel wakelocks, if the user space power manager had already turned off the screen and decided to suspend right before a wakeup key is pressed, then that key could sit in the in-kernel input queue until another key is pressed. Even if the user-space thread read the key event before being frozen, it cannot abort the suspend operation that was already started.

OK, so what about the following approach:

* Keep the decision making logic (power manager etc.) in user space. Reasons:
- It may be arbitrarily complicated
- It may include such things as s2ram quirks or hal quirks needed for some graphics adapters

Quoted 7 lines
Quoted 3 lines

I don't using wakelocks in any different in this respect. When user space decides that it is ok for the kernel to suspend it should have performed all theses steps in both cases.

If automatic suspend is to be started by the kernel, you have to make sure that at least one wakelock is held until these steps are completed. That may be somewhat tricky in general.

That is not tricky. If your code holds a wakelock, then at least one wakelock is held.

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

* Have a per-process (per-task or per-thread group, but the former would be easier IMO) "I_do_not_want_automatic_suspend_to_occur" flag.

Quoted 8 lines
Quoted 4 lines

A per-process (thread group) flag allows wakelocks to be implemented in a user space library. A per-thread flag does not. However, I don't see much benefit in tying this to a process instead of using a file descriptor.

Using a flag would allow us to remove the window between checking the wakelocks and freezing tasks (in principle a task may take a wakelock just before it's frozen).

You can check if there are wakelocks held from the same spot as you check your flag.

Quoted 27 lines
Quoted 27 lines
Quoted 27 lines

* Add a new callback, say ->acknowledge(), to the set of each driver's PM operations, that will be called to check if the driver has anything against automatic suspend (true - suspend can happen right now, false - suspend can't happen).

* Introduce /sys/power/sleep that will work like /sys/power/state, but:
- First, it will call ->acknowledge() for each driver (via bus types) to check if any of them wants to postpone the suspend (this will prevent tasks from being frozen unnecessarily if it is known in advance that the suspend should not happen at the moment).
- Next, it will check the "I_do_not_want_automatic_suspend_to_occur" flag of each process and the suspend will be aborted if it is true for any of them (quite frankly, I think that should be integrated with the freezer, in particular the tasks that have TIF_FREEZE set shouldn't be able to set this flag and it should be checked in the freezer loop for every task with TIF_FREEZE unset).
- Next, it will proceed with suspending just like /sys/power/state does (the drivers that missed the opportunity to abort the suspend by returning 'false' from ->acknowledge() can still abort the suspend by failing their ->suspend() routines).

Then, the decision making logic will be able to use /sys/power/sleep whenever it wishes to and the kernel will be able to refuse to suspend if it's not desirable at the moment.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

It seems to be flexible enough to me.

This seems flexible enough to avoid race conditions, but it forces the user space power manager to poll when the kernel refuse suspend.

And if the kernel is supposed to start automatic suspend, it has to monitor all of the wakelocks. IMO, it's better to allow the power manager to poll the kernel if it refuses to suspend.

What is better about polling in userspace?

Quoted 8 lines
Quoted 3 lines

Also, like my original wakelock patches, it breaks sleep requests through /sys/power/state when there are input events queued.

The idea is to have both /sys/power/state and /sys/power/sleep at the same time, where /sys/power/state will work just like it does right now. Sure, there must be mutual exclusion between the two, but that's a matter of implementation IMO.

If you want to only prevent suspend though one interface, you have to also pass information to the driver about its suspend hook is being called so it can conditionally return -EBUSY. The wakelock interface requires less code in each driver.

Signature · 1 line
Arve Hjønnevåg
#147 lore raw
In reply to Oliver Neukum
Quoted 11 lines · Oliver Neukum

Am Samstag 21 Februar 2009 00:11:28 schrieb Arve Hjønnevåg:

Quoted 10 lines · Oliver Neukum
Quoted 8 lines

Am Freitag 20 Februar 2009 11:46:55 schrieb Rafael J. Wysocki:

Quoted 1 line · Oliver Neukum

With the set of runnable processes.There's always a window between evaluating the current set of runnable tasks and telling the kernel to sleep. IMO the most elegant solution would be a task attribute that would signal the kernel that a task should not count as keeping the system busy even if it is runnable and trigger the sleep in kernel space.

Quoted 8 lines
Quoted 3 lines

It is not always safe to enter suspend when no tasks are runnable. For instance, a key event could be on a user space queue, but the code that reads from that queue has been paged out.

In that case you'd have a task waiting for IO. The driver should refuse to suspend or wake up the system as IO is completed. It may be inefficient to suspend for such a presumably short time, but it is not a correctness issue.

In that case, yes. My point was that no-runnable-tasks is not a sufficient indicator of whether suspend should fail or not. We have no control of what a user space thread is waiting for though. It could be waiting on a mutex that is locked by a thread that is marked not to prevent suspend.

Signature · 1 line
Arve Hjønnevåg
#148 lore raw
In reply to Oliver Neukum
Quoted 11 lines · Oliver Neukum

Am Samstag 21 Februar 2009 00:11:28 schrieb Arve Hjønnevåg:

Quoted 10 lines · Oliver Neukum
Quoted 8 lines

Am Freitag 20 Februar 2009 11:46:55 schrieb Rafael J. Wysocki:

Quoted 1 line · Oliver Neukum

With the set of runnable processes.There's always a window between evaluating the current set of runnable tasks and telling the kernel to sleep. IMO the most elegant solution would be a task attribute that would signal the kernel that a task should not count as keeping the system busy even if it is runnable and trigger the sleep in kernel space.

Quoted 8 lines
Quoted 3 lines

It is not always safe to enter suspend when no tasks are runnable. For instance, a key event could be on a user space queue, but the code that reads from that queue has been paged out.

In that case you'd have a task waiting for IO. The driver should refuse to suspend or wake up the system as IO is completed. It may be inefficient to suspend for such a presumably short time, but it is not a correctness issue.

In that case, yes. My point was that no-runnable-tasks is not a sufficient indicator of whether suspend should fail or not. We have no control of what a user space thread is waiting for though. It could be waiting on a mutex that is locked by a thread that is marked not to prevent suspend.

Signature · 1 line
Arve Hjønnevåg
#170 lore raw
In reply to Arve Hjønnevåg
Quoted 51 lines · Arve Hjønnevåg
Quoted 50 lines · Rafael J. Wysocki
Quoted 48 lines · Arve Hjønnevåg
Quoted 37 lines · Rafael J. Wysocki
Quoted 25 lines · Arve Hjønnevåg
Quoted 21 lines · Rafael J. Wysocki
Quoted 12 lines · Arve Hjønnevåg
Quoted 10 lines · Alan Stern
Quoted 5 lines
Quoted 2 lines

It might have to be platform-specific. The Android people seem to have a pretty good idea of what criteria will work for them.

I'd really like to know in what situations Androind is supposed to suspend automatically.

It might be better to ask in what situations Android is _not_ supposed to sleep automatically. In other words, in what situations is a wakelock acquired? Since the whole system is only a phone, this question should have a reasonably well-defined answer.

Quoted 7 lines

On an android phone, any code that needs to run when the screen is off must hold a wakelock (directly or indirectly). In general if an application or the system is processing an event that may cause a user notification (new email, incoming phone call, alarm, etc.) it needs to prevent suspend. But, we also use wakelocks to upload stats or download system updates in the background, and for media player or (gps) data logging applications.

Quoted 2 lines

All of this doesn't seem to require wakelocks acuired from kernel space. What do you need those wakelocks for?

Quoted 10 lines

Most events do not originate in user-space. Alarms start in our alarm driver which locks a wakelock when its timer interrupt occurs. This wakelock stays locked until the user-space alarm manager calls the driver to wait for the next alarm. I've described how input events are handled before. Without kernel wakelocks, if the user space power manager had already turned off the screen and decided to suspend right before a wakeup key is pressed, then that key could sit in the in-kernel input queue until another key is pressed. Even if the user-space thread read the key event before being frozen, it cannot abort the suspend operation that was already started.

Quoted 6 lines

OK, so what about the following approach:

* Keep the decision making logic (power manager etc.) in user space. Reasons:
- It may be arbitrarily complicated
- It may include such things as s2ram quirks or hal quirks needed for some graphics adapters

I don't using wakelocks in any different in this respect. When user space decides that it is ok for the kernel to suspend it should have performed all theses steps in both cases.

Quoted 6 lines
Quoted 3 lines

If automatic suspend is to be started by the kernel, you have to make sure that at least one wakelock is held until these steps are completed. That may be somewhat tricky in general.

That is not tricky. If your code holds a wakelock, then at least one wakelock is held.

I meant, if one task releases its wakelock and another one takes a wakelock, you have to make sure there's no window between those events. Of course, you can have a single task holding a wakelock all the time and releasing it when it makes sure everything is ready, but then it would act as a user space power manager anyway.

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines

* Have a per-process (per-task or per-thread group, but the former would be easier IMO) "I_do_not_want_automatic_suspend_to_occur" flag.

A per-process (thread group) flag allows wakelocks to be implemented in a user space library. A per-thread flag does not. However, I don't see much benefit in tying this to a process instead of using a file descriptor.

Quoted 6 lines
Quoted 3 lines

Using a flag would allow us to remove the window between checking the wakelocks and freezing tasks (in principle a task may take a wakelock just before it's frozen).

You can check if there are wakelocks held from the same spot as you check your flag.

That would be _much_ more complicated and much less efficient (browsing a list vs checking a flag). And it would require additional locking if it's to be done in a non-racy way.

Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
Quoted 26 lines

* Add a new callback, say ->acknowledge(), to the set of each driver's PM operations, that will be called to check if the driver has anything against automatic suspend (true - suspend can happen right now, false - suspend can't happen).

* Introduce /sys/power/sleep that will work like /sys/power/state, but:
- First, it will call ->acknowledge() for each driver (via bus types) to check if any of them wants to postpone the suspend (this will prevent tasks from being frozen unnecessarily if it is known in advance that the suspend should not happen at the moment).
- Next, it will check the "I_do_not_want_automatic_suspend_to_occur" flag of each process and the suspend will be aborted if it is true for any of them (quite frankly, I think that should be integrated with the freezer, in particular the tasks that have TIF_FREEZE set shouldn't be able to set this flag and it should be checked in the freezer loop for every task with TIF_FREEZE unset).
- Next, it will proceed with suspending just like /sys/power/state does (the drivers that missed the opportunity to abort the suspend by returning 'false' from ->acknowledge() can still abort the suspend by failing their ->suspend() routines).

Then, the decision making logic will be able to use /sys/power/sleep whenever it wishes to and the kernel will be able to refuse to suspend if it's not desirable at the moment.

It seems to be flexible enough to me.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

This seems flexible enough to avoid race conditions, but it forces the user space power manager to poll when the kernel refuse suspend.

And if the kernel is supposed to start automatic suspend, it has to monitor all of the wakelocks. IMO, it's better to allow the power manager to poll the kernel if it refuses to suspend.

What is better about polling in userspace?

One kernel thread less, for example?

Quoted 8 lines
Quoted 7 lines
Quoted 2 lines

Also, like my original wakelock patches, it breaks sleep requests through /sys/power/state when there are input events queued.

The idea is to have both /sys/power/state and /sys/power/sleep at the same time, where /sys/power/state will work just like it does right now. Sure, there must be mutual exclusion between the two, but that's a matter of implementation IMO.

Quoted 4 lines

If you want to only prevent suspend though one interface, you have to also pass information to the driver about its suspend hook is being called so it can conditionally return -EBUSY. The wakelock interface requires less code in each driver.

Well, I don't think so. Moreover, it requires you to spread wakelocks all over the place if you don't use the timeouted ones which, let's face it, is hardly acceptable.

Thanks,
Rafael

#171 lore raw
In reply to Arve Hjønnevåg
Quoted 51 lines · Arve Hjønnevåg
Quoted 50 lines · Rafael J. Wysocki
Quoted 48 lines · Arve Hjønnevåg
Quoted 37 lines · Rafael J. Wysocki
Quoted 25 lines · Arve Hjønnevåg
Quoted 21 lines · Rafael J. Wysocki
Quoted 12 lines · Arve Hjønnevåg
Quoted 10 lines · Alan Stern
Quoted 5 lines
Quoted 2 lines

It might have to be platform-specific. The Android people seem to have a pretty good idea of what criteria will work for them.

I'd really like to know in what situations Androind is supposed to suspend automatically.

It might be better to ask in what situations Android is _not_ supposed to sleep automatically. In other words, in what situations is a wakelock acquired? Since the whole system is only a phone, this question should have a reasonably well-defined answer.

Quoted 7 lines

On an android phone, any code that needs to run when the screen is off must hold a wakelock (directly or indirectly). In general if an application or the system is processing an event that may cause a user notification (new email, incoming phone call, alarm, etc.) it needs to prevent suspend. But, we also use wakelocks to upload stats or download system updates in the background, and for media player or (gps) data logging applications.

Quoted 2 lines

All of this doesn't seem to require wakelocks acuired from kernel space. What do you need those wakelocks for?

Quoted 10 lines

Most events do not originate in user-space. Alarms start in our alarm driver which locks a wakelock when its timer interrupt occurs. This wakelock stays locked until the user-space alarm manager calls the driver to wait for the next alarm. I've described how input events are handled before. Without kernel wakelocks, if the user space power manager had already turned off the screen and decided to suspend right before a wakeup key is pressed, then that key could sit in the in-kernel input queue until another key is pressed. Even if the user-space thread read the key event before being frozen, it cannot abort the suspend operation that was already started.

Quoted 6 lines

OK, so what about the following approach:

* Keep the decision making logic (power manager etc.) in user space. Reasons:
- It may be arbitrarily complicated
- It may include such things as s2ram quirks or hal quirks needed for some graphics adapters

I don't using wakelocks in any different in this respect. When user space decides that it is ok for the kernel to suspend it should have performed all theses steps in both cases.

Quoted 6 lines
Quoted 3 lines

If automatic suspend is to be started by the kernel, you have to make sure that at least one wakelock is held until these steps are completed. That may be somewhat tricky in general.

That is not tricky. If your code holds a wakelock, then at least one wakelock is held.

I meant, if one task releases its wakelock and another one takes a wakelock, you have to make sure there's no window between those events. Of course, you can have a single task holding a wakelock all the time and releasing it when it makes sure everything is ready, but then it would act as a user space power manager anyway.

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines

* Have a per-process (per-task or per-thread group, but the former would be easier IMO) "I_do_not_want_automatic_suspend_to_occur" flag.

A per-process (thread group) flag allows wakelocks to be implemented in a user space library. A per-thread flag does not. However, I don't see much benefit in tying this to a process instead of using a file descriptor.

Quoted 6 lines
Quoted 3 lines

Using a flag would allow us to remove the window between checking the wakelocks and freezing tasks (in principle a task may take a wakelock just before it's frozen).

You can check if there are wakelocks held from the same spot as you check your flag.

That would be _much_ more complicated and much less efficient (browsing a list vs checking a flag). And it would require additional locking if it's to be done in a non-racy way.

Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
Quoted 26 lines

* Add a new callback, say ->acknowledge(), to the set of each driver's PM operations, that will be called to check if the driver has anything against automatic suspend (true - suspend can happen right now, false - suspend can't happen).

* Introduce /sys/power/sleep that will work like /sys/power/state, but:
- First, it will call ->acknowledge() for each driver (via bus types) to check if any of them wants to postpone the suspend (this will prevent tasks from being frozen unnecessarily if it is known in advance that the suspend should not happen at the moment).
- Next, it will check the "I_do_not_want_automatic_suspend_to_occur" flag of each process and the suspend will be aborted if it is true for any of them (quite frankly, I think that should be integrated with the freezer, in particular the tasks that have TIF_FREEZE set shouldn't be able to set this flag and it should be checked in the freezer loop for every task with TIF_FREEZE unset).
- Next, it will proceed with suspending just like /sys/power/state does (the drivers that missed the opportunity to abort the suspend by returning 'false' from ->acknowledge() can still abort the suspend by failing their ->suspend() routines).

Then, the decision making logic will be able to use /sys/power/sleep whenever it wishes to and the kernel will be able to refuse to suspend if it's not desirable at the moment.

It seems to be flexible enough to me.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

This seems flexible enough to avoid race conditions, but it forces the user space power manager to poll when the kernel refuse suspend.

And if the kernel is supposed to start automatic suspend, it has to monitor all of the wakelocks. IMO, it's better to allow the power manager to poll the kernel if it refuses to suspend.

What is better about polling in userspace?

One kernel thread less, for example?

Quoted 8 lines
Quoted 7 lines
Quoted 2 lines

Also, like my original wakelock patches, it breaks sleep requests through /sys/power/state when there are input events queued.

The idea is to have both /sys/power/state and /sys/power/sleep at the same time, where /sys/power/state will work just like it does right now. Sure, there must be mutual exclusion between the two, but that's a matter of implementation IMO.

Quoted 4 lines

If you want to only prevent suspend though one interface, you have to also pass information to the driver about its suspend hook is being called so it can conditionally return -EBUSY. The wakelock interface requires less code in each driver.

Well, I don't think so. Moreover, it requires you to spread wakelocks all over the place if you don't use the timeouted ones which, let's face it, is hardly acceptable.

Thanks,
Rafael

#248 lore raw
In reply to Matthew Garrett
Quoted 6 lines · Matthew Garrett
Quoted 3 lines · Rafael J. Wysocki

We can't do the quirks from the kernel and that's one of the reasons why I think user space should start automatic suspend (it can do the quirks if necessary).

Quoted 6 lines

Any sort of automatic suspend is simply impossible in a world where your drivers don't work properly. There's code for making intel and radeon handle suspend/resume themselves now, and nvidia before g80 should also be easy. More recent nvidia is going to be some work.

But yeah. Let's not have "Work around broken drivers" as a design goal.

OK, I'm withdrawing it, then. :-)

Quoted 1 line

The argument against timeouts in wakelocks works just as well here.

So, what do you thing about the approach desribed earlier in this thread
(http://lkml.org/lkml/2009/2/20/182)?

Rafael

#249 lore raw
In reply to Matthew Garrett
Quoted 6 lines · Matthew Garrett
Quoted 3 lines · Rafael J. Wysocki

We can't do the quirks from the kernel and that's one of the reasons why I think user space should start automatic suspend (it can do the quirks if necessary).

Quoted 6 lines

Any sort of automatic suspend is simply impossible in a world where your drivers don't work properly. There's code for making intel and radeon handle suspend/resume themselves now, and nvidia before g80 should also be easy. More recent nvidia is going to be some work.

But yeah. Let's not have "Work around broken drivers" as a design goal.

OK, I'm withdrawing it, then. :-)

Quoted 1 line

The argument against timeouts in wakelocks works just as well here.

So, what do you thing about the approach desribed earlier in this thread
(http://lkml.org/lkml/2009/2/20/182)?

Rafael

#172 lore raw
In reply to Rafael J. Wysocki
Quoted 56 lines · Rafael J. Wysocki
Quoted 55 lines · Arve Hjønnevåg
Quoted 53 lines · Rafael J. Wysocki
Quoted 40 lines · Arve Hjønnevåg
Quoted 39 lines · Rafael J. Wysocki
Quoted 25 lines · Arve Hjønnevåg
Quoted 21 lines · Rafael J. Wysocki
Quoted 12 lines · Arve Hjønnevåg
Quoted 10 lines · Alan Stern
Quoted 5 lines
Quoted 2 lines

It might have to be platform-specific. The Android people seem to have a pretty good idea of what criteria will work for them.

I'd really like to know in what situations Androind is supposed to suspend automatically.

It might be better to ask in what situations Android is _not_ supposed to sleep automatically. In other words, in what situations is a wakelock acquired? Since the whole system is only a phone, this question should have a reasonably well-defined answer.

Quoted 7 lines

On an android phone, any code that needs to run when the screen is off must hold a wakelock (directly or indirectly). In general if an application or the system is processing an event that may cause a user notification (new email, incoming phone call, alarm, etc.) it needs to prevent suspend. But, we also use wakelocks to upload stats or download system updates in the background, and for media player or (gps) data logging applications.

Quoted 2 lines

All of this doesn't seem to require wakelocks acuired from kernel space. What do you need those wakelocks for?

Quoted 10 lines

Most events do not originate in user-space. Alarms start in our alarm driver which locks a wakelock when its timer interrupt occurs. This wakelock stays locked until the user-space alarm manager calls the driver to wait for the next alarm. I've described how input events are handled before. Without kernel wakelocks, if the user space power manager had already turned off the screen and decided to suspend right before a wakeup key is pressed, then that key could sit in the in-kernel input queue until another key is pressed. Even if the user-space thread read the key event before being frozen, it cannot abort the suspend operation that was already started.

OK, so what about the following approach:

Quoted 8 lines
Quoted 4 lines

* Keep the decision making logic (power manager etc.) in user space. Reasons:
- It may be arbitrarily complicated
- It may include such things as s2ram quirks or hal quirks needed for some graphics adapters

I don't using wakelocks in any different in this respect. When user space decides that it is ok for the kernel to suspend it should have performed all theses steps in both cases.

If automatic suspend is to be started by the kernel, you have to make sure that at least one wakelock is held until these steps are completed. That may be somewhat tricky in general.

Quoted 8 lines
Quoted 2 lines

That is not tricky. If your code holds a wakelock, then at least one wakelock is held.

I meant, if one task releases its wakelock and another one takes a wakelock, you have to make sure there's no window between those events. Of course, you can have a single task holding a wakelock all the time and releasing it when it makes sure everything is ready, but then it would act as a user space power manager anyway.

If you are turning on and off hardware in user space that cannot survive a kernel suspend while it is on, then you hold a wakelock when this hardware is on. It should not matter how many times the kernel enter and exit suspend while your hardware is off.

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 8 lines
Quoted 3 lines

* Have a per-process (per-task or per-thread group, but the former would be easier IMO) "I_do_not_want_automatic_suspend_to_occur" flag.

A per-process (thread group) flag allows wakelocks to be implemented in a user space library. A per-thread flag does not. However, I don't see much benefit in tying this to a process instead of using a file descriptor.

Using a flag would allow us to remove the window between checking the wakelocks and freezing tasks (in principle a task may take a wakelock just before it's frozen).

Quoted 6 lines
Quoted 2 lines

You can check if there are wakelocks held from the same spot as you check your flag.

That would be _much_ more complicated and much less efficient (browsing a list vs checking a flag). And it would require additional locking if it's to be done in a non-racy way.

Browsing an empty list is not that inefficient. If you are concerned about the overhead of the extra spinlock, you could check if the list is empty before locking the spinlock.

Quoted 47 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 27 lines

* Add a new callback, say ->acknowledge(), to the set of each driver's PM operations, that will be called to check if the driver has anything against automatic suspend (true - suspend can happen right now, false - suspend can't happen).

* Introduce /sys/power/sleep that will work like /sys/power/state, but:
- First, it will call ->acknowledge() for each driver (via bus types) to check if any of them wants to postpone the suspend (this will prevent tasks from being frozen unnecessarily if it is known in advance that the suspend should not happen at the moment).
- Next, it will check the "I_do_not_want_automatic_suspend_to_occur" flag of each process and the suspend will be aborted if it is true for any of them (quite frankly, I think that should be integrated with the freezer, in particular the tasks that have TIF_FREEZE set shouldn't be able to set this flag and it should be checked in the freezer loop for every task with TIF_FREEZE unset).
- Next, it will proceed with suspending just like /sys/power/state does (the drivers that missed the opportunity to abort the suspend by returning 'false' from ->acknowledge() can still abort the suspend by failing their ->suspend() routines).

Then, the decision making logic will be able to use /sys/power/sleep whenever it wishes to and the kernel will be able to refuse to suspend if it's not desirable at the moment.

It seems to be flexible enough to me.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

This seems flexible enough to avoid race conditions, but it forces the user space power manager to poll when the kernel refuse suspend.

And if the kernel is supposed to start automatic suspend, it has to monitor all of the wakelocks. IMO, it's better to allow the power manager to poll the kernel if it refuses to suspend.

What is better about polling in userspace?

One kernel thread less, for example?

Quoted 8 lines
Quoted 7 lines
Quoted 2 lines

Also, like my original wakelock patches, it breaks sleep requests through /sys/power/state when there are input events queued.

The idea is to have both /sys/power/state and /sys/power/sleep at the same time, where /sys/power/state will work just like it does right now. Sure, there must be mutual exclusion between the two, but that's a matter of implementation IMO.

Quoted 8 lines
Quoted 4 lines

If you want to only prevent suspend though one interface, you have to also pass information to the driver about its suspend hook is being called so it can conditionally return -EBUSY. The wakelock interface requires less code in each driver.

Well, I don't think so. Moreover, it requires you to spread wakelocks all over the place if you don't use the timeouted ones which, let's face it, is hardly acceptable.

Your method does not reduce the number of places that has to be modified. Any component where we add a wakelock, you have to add a suspend handler to abort suspend when we would have held a wakelock.

Signature · 1 line
Arve Hjønnevåg
#173 lore raw
In reply to Rafael J. Wysocki
Quoted 56 lines · Rafael J. Wysocki
Quoted 55 lines · Arve Hjønnevåg
Quoted 53 lines · Rafael J. Wysocki
Quoted 40 lines · Arve Hjønnevåg
Quoted 39 lines · Rafael J. Wysocki
Quoted 25 lines · Arve Hjønnevåg
Quoted 21 lines · Rafael J. Wysocki
Quoted 12 lines · Arve Hjønnevåg
Quoted 10 lines · Alan Stern
Quoted 5 lines
Quoted 2 lines

It might have to be platform-specific. The Android people seem to have a pretty good idea of what criteria will work for them.

I'd really like to know in what situations Androind is supposed to suspend automatically.

It might be better to ask in what situations Android is _not_ supposed to sleep automatically. In other words, in what situations is a wakelock acquired? Since the whole system is only a phone, this question should have a reasonably well-defined answer.

Quoted 7 lines

On an android phone, any code that needs to run when the screen is off must hold a wakelock (directly or indirectly). In general if an application or the system is processing an event that may cause a user notification (new email, incoming phone call, alarm, etc.) it needs to prevent suspend. But, we also use wakelocks to upload stats or download system updates in the background, and for media player or (gps) data logging applications.

Quoted 2 lines

All of this doesn't seem to require wakelocks acuired from kernel space. What do you need those wakelocks for?

Quoted 10 lines

Most events do not originate in user-space. Alarms start in our alarm driver which locks a wakelock when its timer interrupt occurs. This wakelock stays locked until the user-space alarm manager calls the driver to wait for the next alarm. I've described how input events are handled before. Without kernel wakelocks, if the user space power manager had already turned off the screen and decided to suspend right before a wakeup key is pressed, then that key could sit in the in-kernel input queue until another key is pressed. Even if the user-space thread read the key event before being frozen, it cannot abort the suspend operation that was already started.

OK, so what about the following approach:

Quoted 8 lines
Quoted 4 lines

* Keep the decision making logic (power manager etc.) in user space. Reasons:
- It may be arbitrarily complicated
- It may include such things as s2ram quirks or hal quirks needed for some graphics adapters

I don't using wakelocks in any different in this respect. When user space decides that it is ok for the kernel to suspend it should have performed all theses steps in both cases.

If automatic suspend is to be started by the kernel, you have to make sure that at least one wakelock is held until these steps are completed. That may be somewhat tricky in general.

Quoted 8 lines
Quoted 2 lines

That is not tricky. If your code holds a wakelock, then at least one wakelock is held.

I meant, if one task releases its wakelock and another one takes a wakelock, you have to make sure there's no window between those events. Of course, you can have a single task holding a wakelock all the time and releasing it when it makes sure everything is ready, but then it would act as a user space power manager anyway.

If you are turning on and off hardware in user space that cannot survive a kernel suspend while it is on, then you hold a wakelock when this hardware is on. It should not matter how many times the kernel enter and exit suspend while your hardware is off.

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 8 lines
Quoted 3 lines

* Have a per-process (per-task or per-thread group, but the former would be easier IMO) "I_do_not_want_automatic_suspend_to_occur" flag.

A per-process (thread group) flag allows wakelocks to be implemented in a user space library. A per-thread flag does not. However, I don't see much benefit in tying this to a process instead of using a file descriptor.

Using a flag would allow us to remove the window between checking the wakelocks and freezing tasks (in principle a task may take a wakelock just before it's frozen).

Quoted 6 lines
Quoted 2 lines

You can check if there are wakelocks held from the same spot as you check your flag.

That would be _much_ more complicated and much less efficient (browsing a list vs checking a flag). And it would require additional locking if it's to be done in a non-racy way.

Browsing an empty list is not that inefficient. If you are concerned about the overhead of the extra spinlock, you could check if the list is empty before locking the spinlock.

Quoted 47 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 27 lines

* Add a new callback, say ->acknowledge(), to the set of each driver's PM operations, that will be called to check if the driver has anything against automatic suspend (true - suspend can happen right now, false - suspend can't happen).

* Introduce /sys/power/sleep that will work like /sys/power/state, but:
- First, it will call ->acknowledge() for each driver (via bus types) to check if any of them wants to postpone the suspend (this will prevent tasks from being frozen unnecessarily if it is known in advance that the suspend should not happen at the moment).
- Next, it will check the "I_do_not_want_automatic_suspend_to_occur" flag of each process and the suspend will be aborted if it is true for any of them (quite frankly, I think that should be integrated with the freezer, in particular the tasks that have TIF_FREEZE set shouldn't be able to set this flag and it should be checked in the freezer loop for every task with TIF_FREEZE unset).
- Next, it will proceed with suspending just like /sys/power/state does (the drivers that missed the opportunity to abort the suspend by returning 'false' from ->acknowledge() can still abort the suspend by failing their ->suspend() routines).

Then, the decision making logic will be able to use /sys/power/sleep whenever it wishes to and the kernel will be able to refuse to suspend if it's not desirable at the moment.

It seems to be flexible enough to me.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

This seems flexible enough to avoid race conditions, but it forces the user space power manager to poll when the kernel refuse suspend.

And if the kernel is supposed to start automatic suspend, it has to monitor all of the wakelocks. IMO, it's better to allow the power manager to poll the kernel if it refuses to suspend.

What is better about polling in userspace?

One kernel thread less, for example?

Quoted 8 lines
Quoted 7 lines
Quoted 2 lines

Also, like my original wakelock patches, it breaks sleep requests through /sys/power/state when there are input events queued.

The idea is to have both /sys/power/state and /sys/power/sleep at the same time, where /sys/power/state will work just like it does right now. Sure, there must be mutual exclusion between the two, but that's a matter of implementation IMO.

Quoted 8 lines
Quoted 4 lines

If you want to only prevent suspend though one interface, you have to also pass information to the driver about its suspend hook is being called so it can conditionally return -EBUSY. The wakelock interface requires less code in each driver.

Well, I don't think so. Moreover, it requires you to spread wakelocks all over the place if you don't use the timeouted ones which, let's face it, is hardly acceptable.

Your method does not reduce the number of places that has to be modified. Any component where we add a wakelock, you have to add a suspend handler to abort suspend when we would have held a wakelock.

Signature · 1 line
Arve Hjønnevåg
#250 lore raw
In reply to Rafael J. Wysocki
Quoted 11 lines · Rafael J. Wysocki
Quoted 3 lines

I think everything that uses a "trigger" logic from user space is not a good idea. This will necessary introduce a race between the decision and the execution during which circumstances can change.

Well, in this particulare case if the circumstances change in the meantime, the kernel will just refuse to suspend. Also, even if the kernel starts automatic suspend, it _still_ is possible that the conditions change in the meantime (for example, one of the tasks may enter a state in which it wouldn't like to the suspend to happen just after the operation is started and before it's frozen).

Quoted 5 lines
Quoted 2 lines

So it seems to me that an allow/disallow system from user space would be better.

I don't really see the benefit, but I can easily see drawbacks (the handling of graphics that requires user space quirks, for instance).

This discussion is circling around an important point: How should auto-sleep be initiated?

If userspace holds any wakelocks then the system mustn't auto-sleep. So auto-sleep can be initiated when the last userspace wakelock is released. That requires calling into the kernel anyway, so it isn't a problem.

But what about kernel wakelocks? Again, the simplest approach is to initiate an auto-sleep when the last one is released. But now this depends on how the implementation works.

In Rafael's scheme there isn't really such a thing as a kernel wakelock. Instead there are driver methods, so the only way to find out whether auto-sleep is allowed is to poll every driver. This is not good for systems that want to auto-sleep as soon as possible.

A variant on the scheme would use a new field in the dev_pm_info structure. I don't know if this is better or worse the a new method; it seems likely that the new method would have to work by checking the value of some field anyway. In any case, it shares the drawback that polling is required.

If kernel wakelocks were implemented more like refcounts, then releasing the last one could immediately initiate an auto-sleep. The problem with refcounts is that you can't tell (for accounting or debugging purposes) who owns the outstanding references. However we ought to be able to come up with something intermediate between a full-blown wakelock and a simple refcount that would satisfy everybody.

For example, we could use _both_ a new field in dev_pm_info and a refcount. Or even a per-cpu refcount, to avoid cache-line contention since drivers are likely to acquire and release these things quite often.

What about the overhead of having a permanent kernel thread that does nothing but handle auto-sleeps? This might well be an acceptable tradeoff for many people. Besides, you need something like it if a driver wants to release the last wakelock while in interrupt context. Unless you fall back on polling -- and then you need a thread to do the polling.

Alan Stern

#251 lore raw
In reply to Rafael J. Wysocki
Quoted 11 lines · Rafael J. Wysocki
Quoted 3 lines

I think everything that uses a "trigger" logic from user space is not a good idea. This will necessary introduce a race between the decision and the execution during which circumstances can change.

Well, in this particulare case if the circumstances change in the meantime, the kernel will just refuse to suspend. Also, even if the kernel starts automatic suspend, it _still_ is possible that the conditions change in the meantime (for example, one of the tasks may enter a state in which it wouldn't like to the suspend to happen just after the operation is started and before it's frozen).

Quoted 5 lines
Quoted 2 lines

So it seems to me that an allow/disallow system from user space would be better.

I don't really see the benefit, but I can easily see drawbacks (the handling of graphics that requires user space quirks, for instance).

This discussion is circling around an important point: How should auto-sleep be initiated?

If userspace holds any wakelocks then the system mustn't auto-sleep. So auto-sleep can be initiated when the last userspace wakelock is released. That requires calling into the kernel anyway, so it isn't a problem.

But what about kernel wakelocks? Again, the simplest approach is to initiate an auto-sleep when the last one is released. But now this depends on how the implementation works.

In Rafael's scheme there isn't really such a thing as a kernel wakelock. Instead there are driver methods, so the only way to find out whether auto-sleep is allowed is to poll every driver. This is not good for systems that want to auto-sleep as soon as possible.

A variant on the scheme would use a new field in the dev_pm_info structure. I don't know if this is better or worse the a new method; it seems likely that the new method would have to work by checking the value of some field anyway. In any case, it shares the drawback that polling is required.

If kernel wakelocks were implemented more like refcounts, then releasing the last one could immediately initiate an auto-sleep. The problem with refcounts is that you can't tell (for accounting or debugging purposes) who owns the outstanding references. However we ought to be able to come up with something intermediate between a full-blown wakelock and a simple refcount that would satisfy everybody.

For example, we could use _both_ a new field in dev_pm_info and a refcount. Or even a per-cpu refcount, to avoid cache-line contention since drivers are likely to acquire and release these things quite often.

What about the overhead of having a permanent kernel thread that does nothing but handle auto-sleeps? This might well be an acceptable tradeoff for many people. Besides, you need something like it if a driver wants to release the last wakelock while in interrupt context. Unless you fall back on polling -- and then you need a thread to do the polling.

Alan Stern