Skip to contentSkip to conversation

Attempted summary of suspend-blockers LKML thread

RFC PATCH New Paul E. McKenney 32 participants 817 messages Jul 31, 2010 – Sep 17, 2010 Page 2 of 6

Subsystems (4)
lore
Share & tools
lore
#141 lore raw
In reply to Arjan van de Ven
Quoted 11 lines · Arjan van de Ven
Quoted 8 lines · On Tue, 3 Aug 2010 17:10:15 -0700 "Paul E. McKenney"…

OK, I'll bite...

Quoted 1 line

From an Android perspective, the differences are as follows:

1. Deep idle states are entered only if there are no runnable
tasks. In contrast, opportunistic suspend can happen even when there
are tasks that are ready, willing, and able to run.

Quoted 8 lines

for "system suspend", this is an absolutely valid statement. for "use suspend as idle state", it's not so clearly valid. (but this is sort of a separate problem, basically the "when do we freeze the tasks that we don't like for power reasons" problem, which in first order is independent on what kind of idle power state you pick, and discussed extensively elsewhere in this thread)

From what I can see, the Android folks are are using "suspend" in

the "system suspend" sense.

I agree that the proposals for freezing subsets of the tasks in the system are independent of whether idle or suspend is being used. Instead, such freezing depends on (for example) whether or not the display is active.

That said, freezing subsets of tasks is a nice-to-have rather than a hard requirement for Android. Though I suspect that the appearance of a reliable way of freezing subsets of tasks just might promote this to a hard requirement. ;-)

Quoted 6 lines
Quoted 5 lines

2. There can be a set of input events that do not bring the
system out of suspend, but which would bring the system out of a deep
idle state. For example, I believe that it was stated that
one of the Android-based smartphones ignores touchscreen input while
suspended, but pays attention to it while in deep idle states.

Quoted 11 lines

I would argue that this is both a hardware specific issue, but also a policy issue. From the user point of view, screen off with idle and screen off with suspend aren't all that different (if my phone would decide to idle rather than suspend because some app blocks suspend... I wouldn't expect a difference in behavior when I touch the screen). "Screen off -> don't honor touch after a bit" is almost an independent, but very real, policy problem (and a forced one in suspend, I'll grant you that). I could even argue that the policy decision "we don't care about the touch screen input" is a pre-condition for entering suspend (or in android speak, caring for touch screen input/having the touch screen path active would be a suspend blocker)

I agree that the subset of input events that do not bring the system out of suspend would be governed both by hardware capabilities and by policy.

Quoted 9 lines
Quoted 8 lines

3. The system comes out of a deep idle state when a timer
expires. In contrast, timers cannot expire while the system is suspended. (This one is debatable: some people argue that timers are subject to jitter, and the suspend case for timers is the same as that for deep idle states, but with unbounded timer jitter. Others disagree. The resulting discussions have produced much heat, but little light. Such is life.)

Quoted 10 lines

I'll debate it even harder in that it's platform specific whether timers can get the system out of suspend or not. Clearly on the Android platform in question that's not the case, but for some of the Intel phone silicon for example, timers CAN be wake sources to get you out of suspend just fine. It just depend on which exact hw you talk about. Generally, even if the fast timers aren't wake up sources, there'll be some sort of alarm thing that you can pre-wake.. but yes you are right in saying that's rather lame.
Either way, it's not a general property of suspend, but a property of suspend on the specific platform in question.

Good point, I do need to emphasize the fact that whether or not timers pull the system out of suspend also depends both on hardware and on policy. So I will change my statement to say something like "The system comes out of a deep idle state when a timer expires. In contrast, timers do not necessarily expire while the system is suspended, depending on both hardware support and platform/application policy."

Thanx, Paul

Quoted 6 lines
Signature · 4 lines
-- 
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#142 lore raw
Quoted 73 lines · Paul E. McKenney
Quoted 11 lines · Arjan van de Ven
Quoted 8 lines · On Tue, 3 Aug 2010 17:10:15 -0700 "Paul E. McKenney"…

OK, I'll bite...

Quoted 1 line

From an Android perspective, the differences are as follows:

1. Deep idle states are entered only if there are no runnable
tasks. In contrast, opportunistic suspend can happen even when there
are tasks that are ready, willing, and able to run.

Quoted 6 lines

for "system suspend", this is an absolutely valid statement. for "use suspend as idle state", it's not so clearly valid. (but this is sort of a separate problem, basically the "when do we freeze the tasks that we don't like for power reasons" problem, which in first order is independent on what kind of idle power state you pick, and discussed extensively elsewhere in this thread)

From what I can see, the Android folks are are using "suspend" in the "system suspend" sense.

I agree that the proposals for freezing subsets of the tasks in the system are independent of whether idle or suspend is being used. Instead, such freezing depends on (for example) whether or not the display is active.

That said, freezing subsets of tasks is a nice-to-have rather than a hard requirement for Android. Though I suspect that the appearance of a reliable way of freezing subsets of tasks just might promote this to a hard requirement. ;-)

Quoted 6 lines
Quoted 5 lines

2. There can be a set of input events that do not bring the
system out of suspend, but which would bring the system out of a deep
idle state. For example, I believe that it was stated that
one of the Android-based smartphones ignores touchscreen input while
suspended, but pays attention to it while in deep idle states.

Quoted 11 lines

I would argue that this is both a hardware specific issue, but also a policy issue. From the user point of view, screen off with idle and screen off with suspend aren't all that different (if my phone would decide to idle rather than suspend because some app blocks suspend... I wouldn't expect a difference in behavior when I touch the screen). "Screen off -> don't honor touch after a bit" is almost an independent, but very real, policy problem (and a forced one in suspend, I'll grant you that). I could even argue that the policy decision "we don't care about the touch screen input" is a pre-condition for entering suspend (or in android speak, caring for touch screen input/having the touch screen path active would be a suspend blocker)

I agree that the subset of input events that do not bring the system out of suspend would be governed both by hardware capabilities and by policy.

Quoted 9 lines
Quoted 8 lines

3. The system comes out of a deep idle state when a timer
expires. In contrast, timers cannot expire while the system is suspended. (This one is debatable: some people argue that timers are subject to jitter, and the suspend case for timers is the same as that for deep idle states, but with unbounded timer jitter. Others disagree. The resulting discussions have produced much heat, but little light. Such is life.)

Quoted 10 lines

I'll debate it even harder in that it's platform specific whether timers can get the system out of suspend or not. Clearly on the Android platform in question that's not the case, but for some of the Intel phone silicon for example, timers CAN be wake sources to get you out of suspend just fine. It just depend on which exact hw you talk about. Generally, even if the fast timers aren't wake up sources, there'll be some sort of alarm thing that you can pre-wake.. but yes you are right in saying that's rather lame.
Either way, it's not a general property of suspend, but a property of suspend on the specific platform in question.

Quoted 6 lines

Good point, I do need to emphasize the fact that whether or not timers pull the system out of suspend also depends both on hardware and on policy. So I will change my statement to say something like "The system comes out of a deep idle state when a timer expires. In contrast, timers do not necessarily expire while the system is suspended, depending on both hardware support and platform/application policy."

That's correct IMO.

Thanks,
Rafael

#143 lore raw
In reply to Paul E. McKenney
Quoted 73 lines · Paul E. McKenney
Quoted 11 lines · Arjan van de Ven
Quoted 8 lines · On Tue, 3 Aug 2010 17:10:15 -0700 "Paul E. McKenney"…

OK, I'll bite...

Quoted 1 line

From an Android perspective, the differences are as follows:

1. Deep idle states are entered only if there are no runnable
tasks. In contrast, opportunistic suspend can happen even when there
are tasks that are ready, willing, and able to run.

Quoted 6 lines

for "system suspend", this is an absolutely valid statement. for "use suspend as idle state", it's not so clearly valid. (but this is sort of a separate problem, basically the "when do we freeze the tasks that we don't like for power reasons" problem, which in first order is independent on what kind of idle power state you pick, and discussed extensively elsewhere in this thread)

From what I can see, the Android folks are are using "suspend" in the "system suspend" sense.

I agree that the proposals for freezing subsets of the tasks in the system are independent of whether idle or suspend is being used. Instead, such freezing depends on (for example) whether or not the display is active.

That said, freezing subsets of tasks is a nice-to-have rather than a hard requirement for Android. Though I suspect that the appearance of a reliable way of freezing subsets of tasks just might promote this to a hard requirement. ;-)

Quoted 6 lines
Quoted 5 lines

2. There can be a set of input events that do not bring the
system out of suspend, but which would bring the system out of a deep
idle state. For example, I believe that it was stated that
one of the Android-based smartphones ignores touchscreen input while
suspended, but pays attention to it while in deep idle states.

Quoted 11 lines

I would argue that this is both a hardware specific issue, but also a policy issue. From the user point of view, screen off with idle and screen off with suspend aren't all that different (if my phone would decide to idle rather than suspend because some app blocks suspend... I wouldn't expect a difference in behavior when I touch the screen). "Screen off -> don't honor touch after a bit" is almost an independent, but very real, policy problem (and a forced one in suspend, I'll grant you that). I could even argue that the policy decision "we don't care about the touch screen input" is a pre-condition for entering suspend (or in android speak, caring for touch screen input/having the touch screen path active would be a suspend blocker)

I agree that the subset of input events that do not bring the system out of suspend would be governed both by hardware capabilities and by policy.

Quoted 9 lines
Quoted 8 lines

3. The system comes out of a deep idle state when a timer
expires. In contrast, timers cannot expire while the system is suspended. (This one is debatable: some people argue that timers are subject to jitter, and the suspend case for timers is the same as that for deep idle states, but with unbounded timer jitter. Others disagree. The resulting discussions have produced much heat, but little light. Such is life.)

Quoted 10 lines

I'll debate it even harder in that it's platform specific whether timers can get the system out of suspend or not. Clearly on the Android platform in question that's not the case, but for some of the Intel phone silicon for example, timers CAN be wake sources to get you out of suspend just fine. It just depend on which exact hw you talk about. Generally, even if the fast timers aren't wake up sources, there'll be some sort of alarm thing that you can pre-wake.. but yes you are right in saying that's rather lame.
Either way, it's not a general property of suspend, but a property of suspend on the specific platform in question.

Quoted 6 lines

Good point, I do need to emphasize the fact that whether or not timers pull the system out of suspend also depends both on hardware and on policy. So I will change my statement to say something like "The system comes out of a deep idle state when a timer expires. In contrast, timers do not necessarily expire while the system is suspended, depending on both hardware support and platform/application policy."

That's correct IMO.

Thanks,
Rafael

#144 lore raw
In reply to Arjan van de Ven

Hi,

Quoted 7 lines · On Sun, 1 Aug 2010 21:05:48 -0700 Arjan van de Ven <[email protected]> wrote:

I'm a little worried that this whole "I need to block suspend" is temporary. Yes today there is silicon from ARM and Intel where suspend is a heavy operation, yet at the same time it's not all THAT heavy anymore.... at least on the Intel side it's good enough to use pretty much all the time (when the screen is off for now, but that's a memory controller issue more than anything else). I'm pretty sure the ARM guys will not be far behind.

I think that the only thing that really matters (longterm) with suspend is that processes don't get scheduled anymore when the system is suspended.

Cheers,
Flo

#145 lore raw
In reply to Arjan van de Ven

Hi,

Quoted 7 lines · On Sun, 1 Aug 2010 21:05:48 -0700 Arjan van de Ven <[email protected]> wrote:

I'm a little worried that this whole "I need to block suspend" is temporary. Yes today there is silicon from ARM and Intel where suspend is a heavy operation, yet at the same time it's not all THAT heavy anymore.... at least on the Intel side it's good enough to use pretty much all the time (when the screen is off for now, but that's a memory controller issue more than anything else). I'm pretty sure the ARM guys will not be far behind.

I think that the only thing that really matters (longterm) with suspend is that processes don't get scheduled anymore when the system is suspended.

Cheers,
Flo

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

I'm a little worried that this whole "I need to block suspend" is temporary. Yes today there is silicon from ARM and Intel where suspend is a heavy operation, yet at the same time it's not all THAT heavy anymore....

Part of the problem here may also be a naming problem. There are multiple reasons why you might want to block suspend, and it goes far beyond what the CPU can do.

Let's give another example, from the laptop world. If you close the the MacBook, it "suspends". That is, all processes stop, and the CPU enters a sleep state. Sounds just like Linux's suspend-to-ram, right?

Except for the fact that if you insert a USB cable connected to a iPod/iPad/iPhone, the CPU wakes up, and iTunes will do a sync, and then the machine goes back to sleep. And if the Mail application is in the middle of manipulating the IMAP mailbox, it will be allowed to finish what it is doing, and then the system goes to sleep.

So in the case of both the MacBook, where the user has closed the laptop, and in the case of Cell Phone, where the user has pushed the button saying he/she's done working with the application, the _normal_ thing to do force all processes to go to sleep, and then let the CPU go to sleep.

But, you may have applications that are specially privileged so they can ignore the user command to suspend the machine. Maybe it's an iTunes-like situation, where in response to some hardware interrupt, it's allowed to wake up, do its thing, and then go back to sleep, allowing the hardware to go back to sleep. Maybe it's a mail application that wants to wakeup every 15 minutes, suck down any new mail, and then go back to sleep. The suspend blocker is a way to achieve this --- and this has nothing to do with chip technology, but with a specific use case.

- Ted

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

I'm a little worried that this whole "I need to block suspend" is temporary. Yes today there is silicon from ARM and Intel where suspend is a heavy operation, yet at the same time it's not all THAT heavy anymore....

Part of the problem here may also be a naming problem. There are multiple reasons why you might want to block suspend, and it goes far beyond what the CPU can do.

Let's give another example, from the laptop world. If you close the the MacBook, it "suspends". That is, all processes stop, and the CPU enters a sleep state. Sounds just like Linux's suspend-to-ram, right?

Except for the fact that if you insert a USB cable connected to a iPod/iPad/iPhone, the CPU wakes up, and iTunes will do a sync, and then the machine goes back to sleep. And if the Mail application is in the middle of manipulating the IMAP mailbox, it will be allowed to finish what it is doing, and then the system goes to sleep.

So in the case of both the MacBook, where the user has closed the laptop, and in the case of Cell Phone, where the user has pushed the button saying he/she's done working with the application, the _normal_ thing to do force all processes to go to sleep, and then let the CPU go to sleep.

But, you may have applications that are specially privileged so they can ignore the user command to suspend the machine. Maybe it's an iTunes-like situation, where in response to some hardware interrupt, it's allowed to wake up, do its thing, and then go back to sleep, allowing the hardware to go back to sleep. Maybe it's a mail application that wants to wakeup every 15 minutes, suck down any new mail, and then go back to sleep. The suspend blocker is a way to achieve this --- and this has nothing to do with chip technology, but with a specific use case.

- Ted

#148 lore raw
Quoted 14 lines · Ted Ts'o
Quoted 4 lines · Arjan van de Ven

I'm a little worried that this whole "I need to block suspend" is temporary. Yes today there is silicon from ARM and Intel where suspend is a heavy operation, yet at the same time it's not all THAT heavy anymore....

Part of the problem here may also be a naming problem. There are multiple reasons why you might want to block suspend, and it goes far beyond what the CPU can do.

Let's give another example, from the laptop world. If you close the the MacBook, it "suspends". That is, all processes stop, and the CPU enters a sleep state. Sounds just like Linux's suspend-to-ram, right?

Quoted 5 lines

Except for the fact that if you insert a USB cable connected to a iPod/iPad/iPhone, the CPU wakes up, and iTunes will do a sync, and then the machine goes back to sleep. And if the Mail application is in the middle of manipulating the IMAP mailbox, it will be allowed to finish what it is doing, and then the system goes to sleep.

I _think_ you can implement that with the current kernel's interfaces and an suitable power manager in user space. At least you should be.

The question really boils down to where the "power manager" activity should be located. Should it be in the kernel or in user space? Or is it better to have a "collective power manager", like in the wakelocks case? Moreover, what should the power manager be responsible for and what the kernel's role should be in deciding what "power" state to go into?

Quoted 8 lines

So in the case of both the MacBook, where the user has closed the laptop, and in the case of Cell Phone, where the user has pushed the button saying he/she's done working with the application, the _normal_ thing to do force all processes to go to sleep, and then let the CPU go to sleep.

But, you may have applications that are specially privileged so they can ignore the user command to suspend the machine.

I frankly don't think it's legitimate to overrule the user. If the user tells us "suspend" and specifies a set of devices that can be used for wakeup, we should follow, possibly monitoring the wakeup devices for events.

However, that doesn't apply 100% to the cell phone case, because on cell phones the software is actually owned by the device vendor and/or the network operator and they may want to have a mechanism to overrule the person using the phone. That is a more general issue, though.

Quoted 7 lines

Maybe it's an iTunes-like situation, where in response to some hardware interrupt, it's allowed to wake up, do its thing, and then go back to sleep, allowing the hardware to go back to sleep. Maybe it's a mail application that wants to wakeup every 15 minutes, suck down any new mail, and then go back to sleep. The suspend blocker is a way to achieve this --- and this has nothing to do with chip technology, but with a specific use case.

Assuming that your "power manager activity" will be a collective one, along the Android lines. Still, in principle, you can obtain a functionally equivalent behavior with the help of a power manager in user space.

Thanks,
Rafael

#149 lore raw
In reply to Ted Ts'o
Quoted 14 lines · Ted Ts'o
Quoted 4 lines · Arjan van de Ven

I'm a little worried that this whole "I need to block suspend" is temporary. Yes today there is silicon from ARM and Intel where suspend is a heavy operation, yet at the same time it's not all THAT heavy anymore....

Part of the problem here may also be a naming problem. There are multiple reasons why you might want to block suspend, and it goes far beyond what the CPU can do.

Let's give another example, from the laptop world. If you close the the MacBook, it "suspends". That is, all processes stop, and the CPU enters a sleep state. Sounds just like Linux's suspend-to-ram, right?

Quoted 5 lines

Except for the fact that if you insert a USB cable connected to a iPod/iPad/iPhone, the CPU wakes up, and iTunes will do a sync, and then the machine goes back to sleep. And if the Mail application is in the middle of manipulating the IMAP mailbox, it will be allowed to finish what it is doing, and then the system goes to sleep.

I _think_ you can implement that with the current kernel's interfaces and an suitable power manager in user space. At least you should be.

The question really boils down to where the "power manager" activity should be located. Should it be in the kernel or in user space? Or is it better to have a "collective power manager", like in the wakelocks case? Moreover, what should the power manager be responsible for and what the kernel's role should be in deciding what "power" state to go into?

Quoted 8 lines

So in the case of both the MacBook, where the user has closed the laptop, and in the case of Cell Phone, where the user has pushed the button saying he/she's done working with the application, the _normal_ thing to do force all processes to go to sleep, and then let the CPU go to sleep.

But, you may have applications that are specially privileged so they can ignore the user command to suspend the machine.

I frankly don't think it's legitimate to overrule the user. If the user tells us "suspend" and specifies a set of devices that can be used for wakeup, we should follow, possibly monitoring the wakeup devices for events.

However, that doesn't apply 100% to the cell phone case, because on cell phones the software is actually owned by the device vendor and/or the network operator and they may want to have a mechanism to overrule the person using the phone. That is a more general issue, though.

Quoted 7 lines

Maybe it's an iTunes-like situation, where in response to some hardware interrupt, it's allowed to wake up, do its thing, and then go back to sleep, allowing the hardware to go back to sleep. Maybe it's a mail application that wants to wakeup every 15 minutes, suck down any new mail, and then go back to sleep. The suspend blocker is a way to achieve this --- and this has nothing to do with chip technology, but with a specific use case.

Assuming that your "power manager activity" will be a collective one, along the Android lines. Still, in principle, you can obtain a functionally equivalent behavior with the help of a power manager in user space.

Thanks,
Rafael

#150 lore raw
In reply to Arjan van de Ven
Quoted 26 lines · Arjan van de Ven
Quoted 9 lines · On Sun, 1 Aug 2010 20:03:04 -0700 "Paul E. McKenney"…
Quoted 4 lines

on application programmers to do the right thing. That's not to say that we shouldn't give up on trying to influence application programmers --- but relying on that as the only strategy seems to depart from the path of wisdom.

Unless someone can reliably automate whacking the moles, history is not on the side of the mole-whackers. I won't say that such automation is impossible, but only because of all the "impossible" things in my lifetime that have turned out to be possible.

we have a few things going for us here though

1) It's easy to programatically detect the problems
1a) so programmers can detect issues before they ship software, unlike the fsync() thing Ted mentions. History is showing this is at least relatively successful in open source, but not with Adobe's proprietary software such as Flash
2) Users can be made aware of what the bad guys are
3) The business models of many of the mobile apps gives programmers a strong incentive to ship well behaving. The moment your first and second review of your app read "this app was identified as reducing battery life a lot"... your revenues will not go beyond the $1.98.. ... assuming these first two guys didn't refund their app.

Quoted 2 lines

Since we can detect who the bad guys are, we can also automatically quarantine them for the common cases..... which is good news.

Unless of course the app reducing battery life a lot does something that users like better than the increment in battery life.

Quoted 7 lines

I'm a little worried that this whole "I need to block suspend" is temporary. Yes today there is silicon from ARM and Intel where suspend is a heavy operation, yet at the same time it's not all THAT heavy anymore.... at least on the Intel side it's good enough to use pretty much all the time (when the screen is off for now, but that's a memory controller issue more than anything else). I'm pretty sure the ARM guys will not be far behind.

Heh! One could make the "might be temporary" argument against any new feature, including the ones that you are proposing. For but one example, I very well remember being told by many people in many communities that SMP was temporary -- Moore's-Law increases in clock frequency would soon mean that even the biggest systems would be uniprocessors.

If by "memory controller" you are referring to the need to save state for cache SRAMs and perhaps also DRAM, then yes, I agree that some of the most difficult low-power-state tradeoffs involve these devices.

Thanx, Paul

#151 lore raw
In reply to Arjan van de Ven
Quoted 26 lines · Arjan van de Ven
Quoted 9 lines · On Sun, 1 Aug 2010 20:03:04 -0700 "Paul E. McKenney"…
Quoted 4 lines

on application programmers to do the right thing. That's not to say that we shouldn't give up on trying to influence application programmers --- but relying on that as the only strategy seems to depart from the path of wisdom.

Unless someone can reliably automate whacking the moles, history is not on the side of the mole-whackers. I won't say that such automation is impossible, but only because of all the "impossible" things in my lifetime that have turned out to be possible.

we have a few things going for us here though

1) It's easy to programatically detect the problems
1a) so programmers can detect issues before they ship software, unlike the fsync() thing Ted mentions. History is showing this is at least relatively successful in open source, but not with Adobe's proprietary software such as Flash
2) Users can be made aware of what the bad guys are
3) The business models of many of the mobile apps gives programmers a strong incentive to ship well behaving. The moment your first and second review of your app read "this app was identified as reducing battery life a lot"... your revenues will not go beyond the $1.98.. ... assuming these first two guys didn't refund their app.

Quoted 2 lines

Since we can detect who the bad guys are, we can also automatically quarantine them for the common cases..... which is good news.

Unless of course the app reducing battery life a lot does something that users like better than the increment in battery life.

Quoted 7 lines

I'm a little worried that this whole "I need to block suspend" is temporary. Yes today there is silicon from ARM and Intel where suspend is a heavy operation, yet at the same time it's not all THAT heavy anymore.... at least on the Intel side it's good enough to use pretty much all the time (when the screen is off for now, but that's a memory controller issue more than anything else). I'm pretty sure the ARM guys will not be far behind.

Heh! One could make the "might be temporary" argument against any new feature, including the ones that you are proposing. For but one example, I very well remember being told by many people in many communities that SMP was temporary -- Moore's-Law increases in clock frequency would soon mean that even the biggest systems would be uniprocessors.

If by "memory controller" you are referring to the need to save state for cache SRAMs and perhaps also DRAM, then yes, I agree that some of the most difficult low-power-state tradeoffs involve these devices.

Thanx, Paul

#152 lore raw
In reply to Paul E. McKenney
Quoted 9 lines · On Sun, 1 Aug 2010 20:03:04 -0700 "Paul E. McKenney"…
Quoted 4 lines

on application programmers to do the right thing. That's not to say that we shouldn't give up on trying to influence application programmers --- but relying on that as the only strategy seems to depart from the path of wisdom.

Unless someone can reliably automate whacking the moles, history is not on the side of the mole-whackers. I won't say that such automation is impossible, but only because of all the "impossible" things in my lifetime that have turned out to be possible.

we have a few things going for us here though

1) It's easy to programatically detect the problems
1a) so programmers can detect issues before they ship software, unlike the fsync() thing Ted mentions. History is showing this is at least relatively successful in open source, but not with Adobe's proprietary software such as Flash
2) Users can be made aware of what the bad guys are
3) The business models of many of the mobile apps gives programmers a strong incentive to ship well behaving. The moment your first and second review of your app read "this app was identified as reducing battery life a lot"... your revenues will not go beyond the $1.98.. ... assuming these first two guys didn't refund their app.

Since we can detect who the bad guys are, we can also automatically quarantine them for the common cases..... which is good news.

I'm a little worried that this whole "I need to block suspend" is temporary. Yes today there is silicon from ARM and Intel where suspend is a heavy operation, yet at the same time it's not all THAT heavy anymore.... at least on the Intel side it's good enough to use pretty much all the time (when the screen is off for now, but that's a memory controller issue more than anything else). I'm pretty sure the ARM guys will not be far behind.

#153 lore raw
In reply to Paul E. McKenney
Quoted 17 lines · On Sun, 1 Aug 2010 12:12:28 -0700 "Paul E. McKenney"…

I agree that much progress has been made over the past four years. My laptop's battery life has increased substantially, with roughly half of the increase due to software changes. Taken over all the laptops and PCs out there, this indeed adds up to substantial and valuable savings.

So, yes, you have done quite well.

However, your reliance on application-by-application fixes, while good up to a point, is worrisome longer term. The reason for my concern is that computing history has not been kind to those who fail to vigorously automate. The Android guys have offered up one way of automating power efficiency. There might be better ways, but their approach does at the very least deserve a fair hearing -- and no one who read the recent LKML discussion of their approach could possibly mistake it for anything resembling a fair hearing.

Quoted 8 lines

And yes, I do understand and appreciate your contributions in the form of things like timer aggregation, which does automate the otherwise-tricky task of coordinating power usage across unrelated applications, at least in some important cases. But power efficiency will likely require multiple approaches, especially if the Linux stack is to approach the power efficiencies provided by dedicated devices.

power indeed needs multiple approaches. For example the timer work you mention. What the timer work allows is controlling the behavior of applications that are not well behaved. This is an important way of driving progress, one the android guys sort of swept under the table.

Is the flash plugin (which seems to be the most popular and also worst behaving software in these type of discussions) waking up 100 times per second? <small adjustment by a policy manager> ... now it's only waking up once every 10 seconds, or when something else causes system activity anyway.

That capability is there in Linux today, and has been there for a long time now. It's highly underused unfortunately... at least outside the MeeGo world of Linux distributions.

Another one: freezing whole cgroups..... we have that today. it actually works quite well.... of course the hard part is the decision what to put in which cgroup, and at what frequency and duration you let cgroups run.

on the suspend blockers for drivers; the linux device runtime PM is effectively doing the same things; it allows drivers to suspend/resume individually (with a very nice API/programming model I should say) based on usage. And it works on a tree level, so that it's relatively easy to do things like "I want to go to <this magic deep idle state>, but only if <this set of devices is suspended already>". This is obviously an important functionality for all low power devices, ARM or x86. Suspend blockers had this functionality as part of what it did (they do more obviously) but I'd wager that the current Linux infrastructure is outright nicer.

It's what I want to be using for the Intel phone silicon (which isn't all that different in power behavior/requirements than ARM based silicon), and I need to thank Qualcomm here for providing some very good patches to the kernel to allow this model to work for this scenario.

As for the aware-versus-good-behaving point; applications can be aware, and yet bad behaving, and can be unaware but good behaving. You don't like me saying this, but the reality is that the behavior matters in the end. *AND WE OBSERVE THIS BEHAVIOR*. It's not hard to move a program/task/whatever from a "behaves well, let run unrestricted" to a "doesn't behave well, needs its behavior adjusted" list and back, just from its behavior. PowerTOP observes such apps. Android has an equivalent thing that observes app behavior. It's not all that hard to detect such things.... and the result is much better than some static "aware" flag one can tag an application with. The "aware" flag indicates that there is a "before" and an "after", and that that's it. Reality isn't so black and white as you stated, but that goes for both sides. Observing *current* behavior is much more powerful. Is the part of the app you use fine, even though some function you don't use behave badly? No problem, you get it categorized with the good guys. Is an app 98% working clean, but you on your phone like using the 2% all the time? it's moved to the "must get its attitude adjusted" list.

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
#154 lore raw
In reply to Paul E. McKenney
Quoted 17 lines · On Sun, 1 Aug 2010 12:12:28 -0700 "Paul E. McKenney"…

I agree that much progress has been made over the past four years. My laptop's battery life has increased substantially, with roughly half of the increase due to software changes. Taken over all the laptops and PCs out there, this indeed adds up to substantial and valuable savings.

So, yes, you have done quite well.

However, your reliance on application-by-application fixes, while good up to a point, is worrisome longer term. The reason for my concern is that computing history has not been kind to those who fail to vigorously automate. The Android guys have offered up one way of automating power efficiency. There might be better ways, but their approach does at the very least deserve a fair hearing -- and no one who read the recent LKML discussion of their approach could possibly mistake it for anything resembling a fair hearing.

Quoted 8 lines

And yes, I do understand and appreciate your contributions in the form of things like timer aggregation, which does automate the otherwise-tricky task of coordinating power usage across unrelated applications, at least in some important cases. But power efficiency will likely require multiple approaches, especially if the Linux stack is to approach the power efficiencies provided by dedicated devices.

power indeed needs multiple approaches. For example the timer work you mention. What the timer work allows is controlling the behavior of applications that are not well behaved. This is an important way of driving progress, one the android guys sort of swept under the table.

Is the flash plugin (which seems to be the most popular and also worst behaving software in these type of discussions) waking up 100 times per second? <small adjustment by a policy manager> ... now it's only waking up once every 10 seconds, or when something else causes system activity anyway.

That capability is there in Linux today, and has been there for a long time now. It's highly underused unfortunately... at least outside the MeeGo world of Linux distributions.

Another one: freezing whole cgroups..... we have that today. it actually works quite well.... of course the hard part is the decision what to put in which cgroup, and at what frequency and duration you let cgroups run.

on the suspend blockers for drivers; the linux device runtime PM is effectively doing the same things; it allows drivers to suspend/resume individually (with a very nice API/programming model I should say) based on usage. And it works on a tree level, so that it's relatively easy to do things like "I want to go to <this magic deep idle state>, but only if <this set of devices is suspended already>". This is obviously an important functionality for all low power devices, ARM or x86. Suspend blockers had this functionality as part of what it did (they do more obviously) but I'd wager that the current Linux infrastructure is outright nicer.

It's what I want to be using for the Intel phone silicon (which isn't all that different in power behavior/requirements than ARM based silicon), and I need to thank Qualcomm here for providing some very good patches to the kernel to allow this model to work for this scenario.

As for the aware-versus-good-behaving point; applications can be aware, and yet bad behaving, and can be unaware but good behaving. You don't like me saying this, but the reality is that the behavior matters in the end. *AND WE OBSERVE THIS BEHAVIOR*. It's not hard to move a program/task/whatever from a "behaves well, let run unrestricted" to a "doesn't behave well, needs its behavior adjusted" list and back, just from its behavior. PowerTOP observes such apps. Android has an equivalent thing that observes app behavior. It's not all that hard to detect such things.... and the result is much better than some static "aware" flag one can tag an application with. The "aware" flag indicates that there is a "before" and an "after", and that that's it. Reality isn't so black and white as you stated, but that goes for both sides. Observing *current* behavior is much more powerful. Is the part of the app you use fine, even though some function you don't use behave badly? No problem, you get it categorized with the good guys. Is an app 98% working clean, but you on your phone like using the 2% all the time? it's moved to the "must get its attitude adjusted" list.

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
#155 lore raw
Quoted 39 lines · Arjan van de Ven
Quoted 17 lines · On Sun, 1 Aug 2010 12:12:28 -0700 "Paul E. McKenney"…

I agree that much progress has been made over the past four years. My laptop's battery life has increased substantially, with roughly half of the increase due to software changes. Taken over all the laptops and PCs out there, this indeed adds up to substantial and valuable savings.

So, yes, you have done quite well.

However, your reliance on application-by-application fixes, while good up to a point, is worrisome longer term. The reason for my concern is that computing history has not been kind to those who fail to vigorously automate. The Android guys have offered up one way of automating power efficiency. There might be better ways, but their approach does at the very least deserve a fair hearing -- and no one who read the recent LKML discussion of their approach could possibly mistake it for anything resembling a fair hearing.

Quoted 7 lines

And yes, I do understand and appreciate your contributions in the form of things like timer aggregation, which does automate the otherwise-tricky task of coordinating power usage across unrelated applications, at least in some important cases. But power efficiency will likely require multiple approaches, especially if the Linux stack is to approach the power efficiencies provided by dedicated devices.

power indeed needs multiple approaches. For example the timer work you mention. What the timer work allows is controlling the behavior of applications that are not well behaved. This is an important way of driving progress, one the android guys sort of swept under the table.

Is the flash plugin (which seems to be the most popular and also worst behaving software in these type of discussions) waking up 100 times per second? <small adjustment by a policy manager> ... now it's only waking up once every 10 seconds, or when something else causes system activity anyway.

Quoted 3 lines

That capability is there in Linux today, and has been there for a long time now. It's highly underused unfortunately... at least outside the MeeGo world of Linux distributions.

I agree that timer control is important and will continue to be. It doesn't seem to me to be in conflict with the Android guys' approach, in fact, it should help reduce power consumption while the device is active. I might well be missing something, though.

Quoted 4 lines

Another one: freezing whole cgroups..... we have that today. it actually works quite well.... of course the hard part is the decision what to put in which cgroup, and at what frequency and duration you let cgroups run.

Indeed, the Android guys seemed to be quite excited by cgroup freezing until they thought about the application-classification problem. Seems like it should be easy for some types of applications, but I do admit that apps can have non-trivial and non-obvious dependencies.

Quoted 10 lines

on the suspend blockers for drivers; the linux device runtime PM is effectively doing the same things; it allows drivers to suspend/resume individually (with a very nice API/programming model I should say) based on usage. And it works on a tree level, so that it's relatively easy to do things like "I want to go to <this magic deep idle state>, but only if <this set of devices is suspended already>". This is obviously an important functionality for all low power devices, ARM or x86. Suspend blockers had this functionality as part of what it did (they do more obviously) but I'd wager that the current Linux infrastructure is outright nicer.

This is what Rafael has been working on?

Of course, the Android guys also want to pay attention to which apps are running as well as to the state of devices on the system.

Quoted 5 lines

It's what I want to be using for the Intel phone silicon (which isn't all that different in power behavior/requirements than ARM based silicon), and I need to thank Qualcomm here for providing some very good patches to the kernel to allow this model to work for this scenario.

I must have missed those, and I am not seeing any obvious commits in v2.6.35-rc6. Would you be willing to send a pointer?

Quoted 10 lines

As for the aware-versus-good-behaving point; applications can be aware, and yet bad behaving, and can be unaware but good behaving. You don't like me saying this, but the reality is that the behavior matters in the end. *AND WE OBSERVE THIS BEHAVIOR*. It's not hard to move a program/task/whatever from a "behaves well, let run unrestricted" to a "doesn't behave well, needs its behavior adjusted" list and back, just from its behavior. PowerTOP observes such apps. Android has an equivalent thing that observes app behavior. It's not all that hard to detect such things.... and the result is much better than some static "aware" flag one can tag an application with. The "aware" flag

Quoted 8 lines

indicates that there is a "before" and an "after", and that that's it. Reality isn't so black and white as you stated, but that goes for both sides. Observing *current* behavior is much more powerful. Is the part of the app you use fine, even though some function you don't use behave badly? No problem, you get it categorized with the good guys. Is an app 98% working clean, but you on your phone like using the 2% all the time? it's moved to the "must get its attitude adjusted" list.

If I understand you correctly, a key point of agreement between you and the Android guys is that both the system and the user have some say over how applications are treated by the system in terms of how seriously the system takes a given application's requests.

The Android guys also want the user to have some say about what applications are permitted to have some control over "I want to go to <this magic deep idle state>" requests. Does that seem reasonable to you?

Thanx, Paul

#156 lore raw
In reply to Arjan van de Ven
Quoted 39 lines · Arjan van de Ven
Quoted 17 lines · On Sun, 1 Aug 2010 12:12:28 -0700 "Paul E. McKenney"…

I agree that much progress has been made over the past four years. My laptop's battery life has increased substantially, with roughly half of the increase due to software changes. Taken over all the laptops and PCs out there, this indeed adds up to substantial and valuable savings.

So, yes, you have done quite well.

However, your reliance on application-by-application fixes, while good up to a point, is worrisome longer term. The reason for my concern is that computing history has not been kind to those who fail to vigorously automate. The Android guys have offered up one way of automating power efficiency. There might be better ways, but their approach does at the very least deserve a fair hearing -- and no one who read the recent LKML discussion of their approach could possibly mistake it for anything resembling a fair hearing.

Quoted 7 lines

And yes, I do understand and appreciate your contributions in the form of things like timer aggregation, which does automate the otherwise-tricky task of coordinating power usage across unrelated applications, at least in some important cases. But power efficiency will likely require multiple approaches, especially if the Linux stack is to approach the power efficiencies provided by dedicated devices.

power indeed needs multiple approaches. For example the timer work you mention. What the timer work allows is controlling the behavior of applications that are not well behaved. This is an important way of driving progress, one the android guys sort of swept under the table.

Is the flash plugin (which seems to be the most popular and also worst behaving software in these type of discussions) waking up 100 times per second? <small adjustment by a policy manager> ... now it's only waking up once every 10 seconds, or when something else causes system activity anyway.

Quoted 3 lines

That capability is there in Linux today, and has been there for a long time now. It's highly underused unfortunately... at least outside the MeeGo world of Linux distributions.

I agree that timer control is important and will continue to be. It doesn't seem to me to be in conflict with the Android guys' approach, in fact, it should help reduce power consumption while the device is active. I might well be missing something, though.

Quoted 4 lines

Another one: freezing whole cgroups..... we have that today. it actually works quite well.... of course the hard part is the decision what to put in which cgroup, and at what frequency and duration you let cgroups run.

Indeed, the Android guys seemed to be quite excited by cgroup freezing until they thought about the application-classification problem. Seems like it should be easy for some types of applications, but I do admit that apps can have non-trivial and non-obvious dependencies.

Quoted 10 lines

on the suspend blockers for drivers; the linux device runtime PM is effectively doing the same things; it allows drivers to suspend/resume individually (with a very nice API/programming model I should say) based on usage. And it works on a tree level, so that it's relatively easy to do things like "I want to go to <this magic deep idle state>, but only if <this set of devices is suspended already>". This is obviously an important functionality for all low power devices, ARM or x86. Suspend blockers had this functionality as part of what it did (they do more obviously) but I'd wager that the current Linux infrastructure is outright nicer.

This is what Rafael has been working on?

Of course, the Android guys also want to pay attention to which apps are running as well as to the state of devices on the system.

Quoted 5 lines

It's what I want to be using for the Intel phone silicon (which isn't all that different in power behavior/requirements than ARM based silicon), and I need to thank Qualcomm here for providing some very good patches to the kernel to allow this model to work for this scenario.

I must have missed those, and I am not seeing any obvious commits in v2.6.35-rc6. Would you be willing to send a pointer?

Quoted 10 lines

As for the aware-versus-good-behaving point; applications can be aware, and yet bad behaving, and can be unaware but good behaving. You don't like me saying this, but the reality is that the behavior matters in the end. *AND WE OBSERVE THIS BEHAVIOR*. It's not hard to move a program/task/whatever from a "behaves well, let run unrestricted" to a "doesn't behave well, needs its behavior adjusted" list and back, just from its behavior. PowerTOP observes such apps. Android has an equivalent thing that observes app behavior. It's not all that hard to detect such things.... and the result is much better than some static "aware" flag one can tag an application with. The "aware" flag

Quoted 8 lines

indicates that there is a "before" and an "after", and that that's it. Reality isn't so black and white as you stated, but that goes for both sides. Observing *current* behavior is much more powerful. Is the part of the app you use fine, even though some function you don't use behave badly? No problem, you get it categorized with the good guys. Is an app 98% working clean, but you on your phone like using the 2% all the time? it's moved to the "must get its attitude adjusted" list.

If I understand you correctly, a key point of agreement between you and the Android guys is that both the system and the user have some say over how applications are treated by the system in terms of how seriously the system takes a given application's requests.

The Android guys also want the user to have some say about what applications are permitted to have some control over "I want to go to <this magic deep idle state>" requests. Does that seem reasonable to you?

Thanx, Paul

#157 lore raw
Quoted 9 lines · On Sun, 1 Aug 2010 18:10:06 -0700 "Paul E. McKenney"…

If I understand you correctly, a key point of agreement between you and the Android guys is that both the system and the user have some say over how applications are treated by the system in terms of how seriously the system takes a given application's requests.

The Android guys also want the user to have some say about what applications are permitted to have some control over "I want to go to <this magic deep idle state>" requests. Does that seem reasonable to you?

I personally think it's one of those things where... well we can get a LONG way automatically (by just observing things); asking the users is very very often just caving in rather than solving the problem.

Asking the user should only be done for things the user
1) Can give an intelligent answer to
and
2) Are something the user WANTS to be involved in. (rather than 'stupid thing, why don't just do the right thing'.. think the Windows Vista security questions)

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
#158 lore raw
Quoted 17 lines · Arjan van de Ven
Quoted 9 lines · On Sun, 1 Aug 2010 18:10:06 -0700 "Paul E. McKenney"…

If I understand you correctly, a key point of agreement between you and the Android guys is that both the system and the user have some say over how applications are treated by the system in terms of how seriously the system takes a given application's requests.

The Android guys also want the user to have some say about what applications are permitted to have some control over "I want to go to <this magic deep idle state>" requests. Does that seem reasonable to you?

I personally think it's one of those things where... well we can get a LONG way automatically (by just observing things); asking the users is very very often just caving in rather than solving the problem.

Quoted 6 lines

Asking the user should only be done for things the user
1) Can give an intelligent answer to
and
2) Are something the user WANTS to be involved in. (rather than 'stupid thing, why don't just do the right thing'.. think the Windows Vista security questions)

Combining this with your previous email, I believe that you are saying that it is necessary for the user to be able to exert some control, but that the UI design had better be sufficiently intelligent with sufficiently good defaults that the user almost never actually -needs- to exert such control.

If this is indeed what you are saying, I certainly agree.

Thanx, Paul

#159 lore raw
In reply to Arjan van de Ven
Quoted 17 lines · Arjan van de Ven
Quoted 9 lines · On Sun, 1 Aug 2010 18:10:06 -0700 "Paul E. McKenney"…

If I understand you correctly, a key point of agreement between you and the Android guys is that both the system and the user have some say over how applications are treated by the system in terms of how seriously the system takes a given application's requests.

The Android guys also want the user to have some say about what applications are permitted to have some control over "I want to go to <this magic deep idle state>" requests. Does that seem reasonable to you?

I personally think it's one of those things where... well we can get a LONG way automatically (by just observing things); asking the users is very very often just caving in rather than solving the problem.

Quoted 6 lines

Asking the user should only be done for things the user
1) Can give an intelligent answer to
and
2) Are something the user WANTS to be involved in. (rather than 'stupid thing, why don't just do the right thing'.. think the Windows Vista security questions)

Combining this with your previous email, I believe that you are saying that it is necessary for the user to be able to exert some control, but that the UI design had better be sufficiently intelligent with sufficiently good defaults that the user almost never actually -needs- to exert such control.

If this is indeed what you are saying, I certainly agree.

Thanx, Paul

#160 lore raw
In reply to Paul E. McKenney
Quoted 9 lines · On Sun, 1 Aug 2010 18:10:06 -0700 "Paul E. McKenney"…

If I understand you correctly, a key point of agreement between you and the Android guys is that both the system and the user have some say over how applications are treated by the system in terms of how seriously the system takes a given application's requests.

The Android guys also want the user to have some say about what applications are permitted to have some control over "I want to go to <this magic deep idle state>" requests. Does that seem reasonable to you?

I personally think it's one of those things where... well we can get a LONG way automatically (by just observing things); asking the users is very very often just caving in rather than solving the problem.

Asking the user should only be done for things the user
1) Can give an intelligent answer to
and
2) Are something the user WANTS to be involved in. (rather than 'stupid thing, why don't just do the right thing'.. think the Windows Vista security questions)

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
#161 lore raw
In reply to Paul E. McKenney
Quoted 3 lines · Paul E. McKenney
Quoted 2 lines · Arjan van de Ven

On Sun, 1 Aug 2010 12:12:28 -0700
"Paul E. McKenney" <[email protected]> wrote:

...

Quoted 9 lines
Quoted 4 lines

Another one: freezing whole cgroups..... we have that today. it actually works quite well.... of course the hard part is the decision what to put in which cgroup, and at what frequency and duration you let cgroups run.

Indeed, the Android guys seemed to be quite excited by cgroup freezing until they thought about the application-classification problem. Seems like it should be easy for some types of applications, but I do admit that apps can have non-trivial and non-obvious dependencies.

This isn't more difficult than deciding which applications will be allowed to use wakelocks (in the wakelocks world). It actually seems to be pretty much equivalent to me. :-)

Quoted 11 lines
Quoted 10 lines

on the suspend blockers for drivers; the linux device runtime PM is effectively doing the same things; it allows drivers to suspend/resume individually (with a very nice API/programming model I should say) based on usage. And it works on a tree level, so that it's relatively easy to do things like "I want to go to <this magic deep idle state>, but only if <this set of devices is suspended already>". This is obviously an important functionality for all low power devices, ARM or x86. Suspend blockers had this functionality as part of what it did (they do more obviously) but I'd wager that the current Linux infrastructure is outright nicer.

Quoted 1 line

This is what Rafael has been working on?

If you mean the runtime PM framework, then yes, I've been working on it.

Quoted 2 lines

Of course, the Android guys also want to pay attention to which apps are running as well as to the state of devices on the system.

In fact the runtime PM framework is also important to Android, because it can be used in there, for example, to implement the "early suspend" thing I referred to in one of my previous messages in this thread.

Thanks,
Rafael

#162 lore raw
In reply to Paul E. McKenney
Quoted 3 lines · Paul E. McKenney
Quoted 2 lines · Arjan van de Ven

On Sun, 1 Aug 2010 12:12:28 -0700
"Paul E. McKenney" <[email protected]> wrote:

...

Quoted 9 lines
Quoted 4 lines

Another one: freezing whole cgroups..... we have that today. it actually works quite well.... of course the hard part is the decision what to put in which cgroup, and at what frequency and duration you let cgroups run.

Indeed, the Android guys seemed to be quite excited by cgroup freezing until they thought about the application-classification problem. Seems like it should be easy for some types of applications, but I do admit that apps can have non-trivial and non-obvious dependencies.

This isn't more difficult than deciding which applications will be allowed to use wakelocks (in the wakelocks world). It actually seems to be pretty much equivalent to me. :-)

Quoted 11 lines
Quoted 10 lines

on the suspend blockers for drivers; the linux device runtime PM is effectively doing the same things; it allows drivers to suspend/resume individually (with a very nice API/programming model I should say) based on usage. And it works on a tree level, so that it's relatively easy to do things like "I want to go to <this magic deep idle state>, but only if <this set of devices is suspended already>". This is obviously an important functionality for all low power devices, ARM or x86. Suspend blockers had this functionality as part of what it did (they do more obviously) but I'd wager that the current Linux infrastructure is outright nicer.

Quoted 1 line

This is what Rafael has been working on?

If you mean the runtime PM framework, then yes, I've been working on it.

Quoted 2 lines

Of course, the Android guys also want to pay attention to which apps are running as well as to the state of devices on the system.

In fact the runtime PM framework is also important to Android, because it can be used in there, for example, to implement the "early suspend" thing I referred to in one of my previous messages in this thread.

Thanks,
Rafael

#163 lore raw
Quoted 10 lines · Rafael J. Wysocki
Quoted 3 lines · Paul E. McKenney
Quoted 2 lines · Arjan van de Ven

On Sun, 1 Aug 2010 12:12:28 -0700
"Paul E. McKenney" <[email protected]> wrote:

...

Quoted 5 lines
Quoted 4 lines

Another one: freezing whole cgroups..... we have that today. it actually works quite well.... of course the hard part is the decision what to put in which cgroup, and at what frequency and duration you let cgroups run.

Quoted 8 lines
Quoted 4 lines

Indeed, the Android guys seemed to be quite excited by cgroup freezing until they thought about the application-classification problem. Seems like it should be easy for some types of applications, but I do admit that apps can have non-trivial and non-obvious dependencies.

This isn't more difficult than deciding which applications will be allowed to use wakelocks (in the wakelocks world). It actually seems to be pretty much equivalent to me. :-)

If I understand correctly, the problem they were concerned about was instead "given that a certain set of apps are permitted to use wakelocks, which of the other apps can safely be frozen when the display blanks itself."

Quoted 13 lines
Quoted 11 lines
Quoted 10 lines

on the suspend blockers for drivers; the linux device runtime PM is effectively doing the same things; it allows drivers to suspend/resume individually (with a very nice API/programming model I should say) based on usage. And it works on a tree level, so that it's relatively easy to do things like "I want to go to <this magic deep idle state>, but only if <this set of devices is suspended already>". This is obviously an important functionality for all low power devices, ARM or x86. Suspend blockers had this functionality as part of what it did (they do more obviously) but I'd wager that the current Linux infrastructure is outright nicer.

Quoted 1 line

This is what Rafael has been working on?

Quoted 8 lines

If you mean the runtime PM framework, then yes, I've been working on it.

Quoted 2 lines

Of course, the Android guys also want to pay attention to which apps are running as well as to the state of devices on the system.

In fact the runtime PM framework is also important to Android, because it can be used in there, for example, to implement the "early suspend" thing I referred to in one of my previous messages in this thread.

Now we just need to convince the Android guys of that. ;-)

Thanx, Paul

#164 lore raw
In reply to Rafael J. Wysocki
Quoted 10 lines · Rafael J. Wysocki
Quoted 3 lines · Paul E. McKenney
Quoted 2 lines · Arjan van de Ven

On Sun, 1 Aug 2010 12:12:28 -0700
"Paul E. McKenney" <[email protected]> wrote:

...

Quoted 5 lines
Quoted 4 lines

Another one: freezing whole cgroups..... we have that today. it actually works quite well.... of course the hard part is the decision what to put in which cgroup, and at what frequency and duration you let cgroups run.

Quoted 8 lines
Quoted 4 lines

Indeed, the Android guys seemed to be quite excited by cgroup freezing until they thought about the application-classification problem. Seems like it should be easy for some types of applications, but I do admit that apps can have non-trivial and non-obvious dependencies.

This isn't more difficult than deciding which applications will be allowed to use wakelocks (in the wakelocks world). It actually seems to be pretty much equivalent to me. :-)

If I understand correctly, the problem they were concerned about was instead "given that a certain set of apps are permitted to use wakelocks, which of the other apps can safely be frozen when the display blanks itself."

Quoted 13 lines
Quoted 11 lines
Quoted 10 lines

on the suspend blockers for drivers; the linux device runtime PM is effectively doing the same things; it allows drivers to suspend/resume individually (with a very nice API/programming model I should say) based on usage. And it works on a tree level, so that it's relatively easy to do things like "I want to go to <this magic deep idle state>, but only if <this set of devices is suspended already>". This is obviously an important functionality for all low power devices, ARM or x86. Suspend blockers had this functionality as part of what it did (they do more obviously) but I'd wager that the current Linux infrastructure is outright nicer.

Quoted 1 line

This is what Rafael has been working on?

Quoted 8 lines

If you mean the runtime PM framework, then yes, I've been working on it.

Quoted 2 lines

Of course, the Android guys also want to pay attention to which apps are running as well as to the state of devices on the system.

In fact the runtime PM framework is also important to Android, because it can be used in there, for example, to implement the "early suspend" thing I referred to in one of my previous messages in this thread.

Now we just need to convince the Android guys of that. ;-)

Thanx, Paul

#165 lore raw
Quoted 16 lines · Paul E. McKenney
Quoted 15 lines · Rafael J. Wysocki
Quoted 3 lines · Paul E. McKenney
Quoted 2 lines · Arjan van de Ven

On Sun, 1 Aug 2010 12:12:28 -0700
"Paul E. McKenney" <[email protected]> wrote:

...

Quoted 9 lines
Quoted 4 lines

Another one: freezing whole cgroups..... we have that today. it actually works quite well.... of course the hard part is the decision what to put in which cgroup, and at what frequency and duration you let cgroups run.

Indeed, the Android guys seemed to be quite excited by cgroup freezing until they thought about the application-classification problem. Seems like it should be easy for some types of applications, but I do admit that apps can have non-trivial and non-obvious dependencies.

Quoted 8 lines
Quoted 3 lines

This isn't more difficult than deciding which applications will be allowed to use wakelocks (in the wakelocks world). It actually seems to be pretty much equivalent to me. :-)

If I understand correctly, the problem they were concerned about was instead "given that a certain set of apps are permitted to use wakelocks, which of the other apps can safely be frozen when the display blanks itself."

I _think_ the problem should be reformulated as "which of the other apps can be safely frozen without causing the wakelocks-using ones to have problems" instead (the particular scenario is that one of the wakelocks-using apps may need one of the other apps to process something and therefore the other app cannot be frozen; however, that may be resolved by thawing all of the other apps in such situations IMO).

Quoted 15 lines
Quoted 15 lines
Quoted 11 lines
Quoted 10 lines

on the suspend blockers for drivers; the linux device runtime PM is effectively doing the same things; it allows drivers to suspend/resume individually (with a very nice API/programming model I should say) based on usage. And it works on a tree level, so that it's relatively easy to do things like "I want to go to <this magic deep idle state>, but only if <this set of devices is suspended already>". This is obviously an important functionality for all low power devices, ARM or x86. Suspend blockers had this functionality as part of what it did (they do more obviously) but I'd wager that the current Linux infrastructure is outright nicer.

Quoted 1 line

This is what Rafael has been working on?

If you mean the runtime PM framework, then yes, I've been working on it.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Of course, the Android guys also want to pay attention to which apps are running as well as to the state of devices on the system.

In fact the runtime PM framework is also important to Android, because it can be used in there, for example, to implement the "early suspend" thing I referred to in one of my previous messages in this thread.

Now we just need to convince the Android guys of that. ;-)

I believe there's no need for that, as we were talking about that a few months ago.

Thanks,
Rafael

#166 lore raw
In reply to Paul E. McKenney
Quoted 16 lines · Paul E. McKenney
Quoted 15 lines · Rafael J. Wysocki
Quoted 3 lines · Paul E. McKenney
Quoted 2 lines · Arjan van de Ven

On Sun, 1 Aug 2010 12:12:28 -0700
"Paul E. McKenney" <[email protected]> wrote:

...

Quoted 9 lines
Quoted 4 lines

Another one: freezing whole cgroups..... we have that today. it actually works quite well.... of course the hard part is the decision what to put in which cgroup, and at what frequency and duration you let cgroups run.

Indeed, the Android guys seemed to be quite excited by cgroup freezing until they thought about the application-classification problem. Seems like it should be easy for some types of applications, but I do admit that apps can have non-trivial and non-obvious dependencies.

Quoted 8 lines
Quoted 3 lines

This isn't more difficult than deciding which applications will be allowed to use wakelocks (in the wakelocks world). It actually seems to be pretty much equivalent to me. :-)

If I understand correctly, the problem they were concerned about was instead "given that a certain set of apps are permitted to use wakelocks, which of the other apps can safely be frozen when the display blanks itself."

I _think_ the problem should be reformulated as "which of the other apps can be safely frozen without causing the wakelocks-using ones to have problems" instead (the particular scenario is that one of the wakelocks-using apps may need one of the other apps to process something and therefore the other app cannot be frozen; however, that may be resolved by thawing all of the other apps in such situations IMO).

Quoted 15 lines
Quoted 15 lines
Quoted 11 lines
Quoted 10 lines

on the suspend blockers for drivers; the linux device runtime PM is effectively doing the same things; it allows drivers to suspend/resume individually (with a very nice API/programming model I should say) based on usage. And it works on a tree level, so that it's relatively easy to do things like "I want to go to <this magic deep idle state>, but only if <this set of devices is suspended already>". This is obviously an important functionality for all low power devices, ARM or x86. Suspend blockers had this functionality as part of what it did (they do more obviously) but I'd wager that the current Linux infrastructure is outright nicer.

Quoted 1 line

This is what Rafael has been working on?

If you mean the runtime PM framework, then yes, I've been working on it.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Of course, the Android guys also want to pay attention to which apps are running as well as to the state of devices on the system.

In fact the runtime PM framework is also important to Android, because it can be used in there, for example, to implement the "early suspend" thing I referred to in one of my previous messages in this thread.

Now we just need to convince the Android guys of that. ;-)

I believe there's no need for that, as we were talking about that a few months ago.

Thanks,
Rafael

#167 lore raw
Quoted 26 lines · Rafael J. Wysocki
Quoted 16 lines · Paul E. McKenney
Quoted 15 lines · Rafael J. Wysocki
Quoted 3 lines · Paul E. McKenney
Quoted 2 lines · Arjan van de Ven

On Sun, 1 Aug 2010 12:12:28 -0700
"Paul E. McKenney" <[email protected]> wrote:

...

Quoted 9 lines
Quoted 4 lines

Another one: freezing whole cgroups..... we have that today. it actually works quite well.... of course the hard part is the decision what to put in which cgroup, and at what frequency and duration you let cgroups run.

Indeed, the Android guys seemed to be quite excited by cgroup freezing until they thought about the application-classification problem. Seems like it should be easy for some types of applications, but I do admit that apps can have non-trivial and non-obvious dependencies.

Quoted 8 lines
Quoted 3 lines

This isn't more difficult than deciding which applications will be allowed to use wakelocks (in the wakelocks world). It actually seems to be pretty much equivalent to me. :-)

If I understand correctly, the problem they were concerned about was instead "given that a certain set of apps are permitted to use wakelocks, which of the other apps can safely be frozen when the display blanks itself."

Quoted 6 lines

I _think_ the problem should be reformulated as "which of the other apps can be safely frozen without causing the wakelocks-using ones to have problems" instead (the particular scenario is that one of the wakelocks-using apps may need one of the other apps to process something and therefore the other app cannot be frozen; however, that may be resolved by thawing all of the other apps in such situations IMO).

I agree that your statement is equivalent to mine. From what I can see, the current Android code resolves this by not freezing any app while a wakelock is held.

Just out of curiosity, how are you detecting the situation in order to decide when to thaw the apps in the cgroup?

Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 11 lines
Quoted 10 lines

on the suspend blockers for drivers; the linux device runtime PM is effectively doing the same things; it allows drivers to suspend/resume individually (with a very nice API/programming model I should say) based on usage. And it works on a tree level, so that it's relatively easy to do things like "I want to go to <this magic deep idle state>, but only if <this set of devices is suspended already>". This is obviously an important functionality for all low power devices, ARM or x86. Suspend blockers had this functionality as part of what it did (they do more obviously) but I'd wager that the current Linux infrastructure is outright nicer.

Quoted 1 line

This is what Rafael has been working on?

If you mean the runtime PM framework, then yes, I've been working on it.

Quoted 2 lines

Of course, the Android guys also want to pay attention to which apps are running as well as to the state of devices on the system.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

In fact the runtime PM framework is also important to Android, because it can be used in there, for example, to implement the "early suspend" thing I referred to in one of my previous messages in this thread.

Now we just need to convince the Android guys of that. ;-)

I believe there's no need for that, as we were talking about that a few months ago.

Here is hoping...

Thanx, Paul

#168 lore raw
In reply to Rafael J. Wysocki
Quoted 26 lines · Rafael J. Wysocki
Quoted 16 lines · Paul E. McKenney
Quoted 15 lines · Rafael J. Wysocki
Quoted 3 lines · Paul E. McKenney
Quoted 2 lines · Arjan van de Ven

On Sun, 1 Aug 2010 12:12:28 -0700
"Paul E. McKenney" <[email protected]> wrote:

...

Quoted 9 lines
Quoted 4 lines

Another one: freezing whole cgroups..... we have that today. it actually works quite well.... of course the hard part is the decision what to put in which cgroup, and at what frequency and duration you let cgroups run.

Indeed, the Android guys seemed to be quite excited by cgroup freezing until they thought about the application-classification problem. Seems like it should be easy for some types of applications, but I do admit that apps can have non-trivial and non-obvious dependencies.

Quoted 8 lines
Quoted 3 lines

This isn't more difficult than deciding which applications will be allowed to use wakelocks (in the wakelocks world). It actually seems to be pretty much equivalent to me. :-)

If I understand correctly, the problem they were concerned about was instead "given that a certain set of apps are permitted to use wakelocks, which of the other apps can safely be frozen when the display blanks itself."

Quoted 6 lines

I _think_ the problem should be reformulated as "which of the other apps can be safely frozen without causing the wakelocks-using ones to have problems" instead (the particular scenario is that one of the wakelocks-using apps may need one of the other apps to process something and therefore the other app cannot be frozen; however, that may be resolved by thawing all of the other apps in such situations IMO).

I agree that your statement is equivalent to mine. From what I can see, the current Android code resolves this by not freezing any app while a wakelock is held.

Just out of curiosity, how are you detecting the situation in order to decide when to thaw the apps in the cgroup?

Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 11 lines
Quoted 10 lines

on the suspend blockers for drivers; the linux device runtime PM is effectively doing the same things; it allows drivers to suspend/resume individually (with a very nice API/programming model I should say) based on usage. And it works on a tree level, so that it's relatively easy to do things like "I want to go to <this magic deep idle state>, but only if <this set of devices is suspended already>". This is obviously an important functionality for all low power devices, ARM or x86. Suspend blockers had this functionality as part of what it did (they do more obviously) but I'd wager that the current Linux infrastructure is outright nicer.

Quoted 1 line

This is what Rafael has been working on?

If you mean the runtime PM framework, then yes, I've been working on it.

Quoted 2 lines

Of course, the Android guys also want to pay attention to which apps are running as well as to the state of devices on the system.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

In fact the runtime PM framework is also important to Android, because it can be used in there, for example, to implement the "early suspend" thing I referred to in one of my previous messages in this thread.

Now we just need to convince the Android guys of that. ;-)

I believe there's no need for that, as we were talking about that a few months ago.

Here is hoping...

Thanx, Paul

#169 lore raw
Quoted 34 lines · Paul E. McKenney
Quoted 26 lines · Rafael J. Wysocki
Quoted 16 lines · Paul E. McKenney
Quoted 15 lines · Rafael J. Wysocki
Quoted 3 lines · Paul E. McKenney
Quoted 2 lines · Arjan van de Ven

On Sun, 1 Aug 2010 12:12:28 -0700
"Paul E. McKenney" <[email protected]> wrote:

...

Quoted 9 lines
Quoted 4 lines

Another one: freezing whole cgroups..... we have that today. it actually works quite well.... of course the hard part is the decision what to put in which cgroup, and at what frequency and duration you let cgroups run.

Indeed, the Android guys seemed to be quite excited by cgroup freezing until they thought about the application-classification problem. Seems like it should be easy for some types of applications, but I do admit that apps can have non-trivial and non-obvious dependencies.

Quoted 8 lines
Quoted 3 lines

This isn't more difficult than deciding which applications will be allowed to use wakelocks (in the wakelocks world). It actually seems to be pretty much equivalent to me. :-)

If I understand correctly, the problem they were concerned about was instead "given that a certain set of apps are permitted to use wakelocks, which of the other apps can safely be frozen when the display blanks itself."

Quoted 6 lines

I _think_ the problem should be reformulated as "which of the other apps can be safely frozen without causing the wakelocks-using ones to have problems" instead (the particular scenario is that one of the wakelocks-using apps may need one of the other apps to process something and therefore the other app cannot be frozen; however, that may be resolved by thawing all of the other apps in such situations IMO).

Quoted 6 lines

I agree that your statement is equivalent to mine. From what I can see, the current Android code resolves this by not freezing any app while a wakelock is held.

Just out of curiosity, how are you detecting the situation in order to decide when to thaw the apps in the cgroup?

Well, in fact I would only be able to talk about that theoretically, as I'm currently not involved in any project using cgroups for power management. I have considered that, but I haven't tried to implement it.

Thanks,
Rafael

#170 lore raw
In reply to Paul E. McKenney
Quoted 1 line · Paul E. McKenney

On Sun, Aug 01, 2010 at 03:47:08PM -0700, Arjan van de Ven wrote:

...

Quoted 10 lines
Quoted 4 lines

Another one: freezing whole cgroups..... we have that today. it actually works quite well.... of course the hard part is the decision what to put in which cgroup, and at what frequency and duration you let cgroups run.

Indeed, the Android guys seemed to be quite excited by cgroup freezing until they thought about the application-classification problem. Seems like it should be easy for some types of applications, but I do admit that apps can have non-trivial and non-obvious dependencies.

The dependencies is what made this solution uninteresting to us. For instance, we currently use cgroup scheduling to reduce the impact of some background tasks, but we occasionally saw a watchdog restart of the system process were critical services were waiting on a kernel mutex owned by a background task for more than 20 seconds. If we froze a cgroup instead, we would not hit this particular problem since tasks cannot be frozen while executing kernel code the same way they can be preempted, but nothing prevents a task from being frozen while holding a user-space resource.

Signature · 1 line
Arve Hjønnevåg
#171 lore raw
In reply to Paul E. McKenney
Quoted 1 line · Paul E. McKenney

On Sun, Aug 01, 2010 at 03:47:08PM -0700, Arjan van de Ven wrote:

...

Quoted 10 lines
Quoted 4 lines

Another one: freezing whole cgroups..... we have that today. it actually works quite well.... of course the hard part is the decision what to put in which cgroup, and at what frequency and duration you let cgroups run.

Indeed, the Android guys seemed to be quite excited by cgroup freezing until they thought about the application-classification problem. Seems like it should be easy for some types of applications, but I do admit that apps can have non-trivial and non-obvious dependencies.

The dependencies is what made this solution uninteresting to us. For instance, we currently use cgroup scheduling to reduce the impact of some background tasks, but we occasionally saw a watchdog restart of the system process were critical services were waiting on a kernel mutex owned by a background task for more than 20 seconds. If we froze a cgroup instead, we would not hit this particular problem since tasks cannot be frozen while executing kernel code the same way they can be preempted, but nothing prevents a task from being frozen while holding a user-space resource.

Signature · 1 line
Arve Hjønnevåg
#172 lore raw

Hi Arve and Alan,

I have some questions regarding the Android early suspend and ACPI that are as follows:

1) If i see the early suspend features which is for android, it is if the user presses power off

the button and on button for late resumes. The question is if there is mobile platform,

then when user presses power off button, will the early suspend handlers will be called

at that time?

what usecase android early suspend handles?

2) Regarding ACPI which is more bios centric, will the drivers need to implement suspend/resume

as for normal OS use case scenarios?

Regards

Raj

Quoted 38 lines

Date: Mon, 2 Aug 2010 21:56:10 -0700
Subject: Re: Attempted summary of suspend-blockers LKML thread
From: [email protected]
To: [email protected]
CC: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]

Quoted 1 line · Paul E. McKenney

On Sun, Aug 01, 2010 at 03:47:08PM -0700, Arjan van de Ven wrote:

...

Quoted 10 lines
Quoted 4 lines

Another one: freezing whole cgroups..... we have that today. it actually works quite well.... of course the hard part is the decision what to put in which cgroup, and at what frequency and duration you let cgroups run.

Indeed, the Android guys seemed to be quite excited by cgroup freezing until they thought about the application-classification problem. Seems like it should be easy for some types of applications, but I do admit that apps can have non-trivial and non-obvious dependencies.

The dependencies is what made this solution uninteresting to us. For instance, we currently use cgroup scheduling to reduce the impact of some background tasks, but we occasionally saw a watchdog restart of the system process were critical services were waiting on a kernel mutex owned by a background task for more than 20 seconds. If we froze a cgroup instead, we would not hit this particular problem since tasks cannot be frozen while executing kernel code the same way they can be preempted, but nothing prevents a task from being frozen while holding a user-space resource.

Signature · 6 lines
Arve Hjønnevåg
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
#173 lore raw
Quoted 6 lines · Raj Kumar

Hi Arve and Alan,

I have some questions regarding the Android early suspend and ACPI that are as follows:

Quoted 9 lines

1) If i see the early suspend features which is for android, it is if the user presses power off
the button and on button for late resumes. The question is if there is mobile platform,
then when user presses power off button, will the early suspend handlers will be called
at that time?
what usecase android early suspend handles?

Early suspend is called on android when user-space turns the screen off. It provides a central switch for user-space to turn off devices that are not needed when the screen is off. The goal is to use runtime-pm for this instead so the drivers don't have to be android specific.

Quoted 8 lines

2) Regarding ACPI which is more bios centric, will the drivers need to implement suspend/resume
as for normal OS use case scenarios?

Regards
Raj

Signature · 1 line
Arve Hjønnevåg
#174 lore raw
In reply to Arve Hjønnevåg
Quoted 14 lines · Arve Hjønnevåg
Quoted 1 line · Paul E. McKenney

On Sun, Aug 01, 2010 at 03:47:08PM -0700, Arjan van de Ven wrote:

...

Quoted 9 lines
Quoted 4 lines

Another one: freezing whole cgroups..... we have that today. it actually works quite well.... of course the hard part is the decision what to put in which cgroup, and at what frequency and duration you let cgroups run.

Indeed, the Android guys seemed to be quite excited by cgroup freezing until they thought about the application-classification problem. Seems like it should be easy for some types of applications, but I do admit that apps can have non-trivial and non-obvious dependencies.

Quoted 9 lines

The dependencies is what made this solution uninteresting to us. For instance, we currently use cgroup scheduling to reduce the impact of some background tasks, but we occasionally saw a watchdog restart of the system process were critical services were waiting on a kernel mutex owned by a background task for more than 20 seconds. If we froze a cgroup instead, we would not hit this particular problem since tasks cannot be frozen while executing kernel code the same way they can be preempted, but nothing prevents a task from being frozen while holding a user-space resource.

Excellent point -- I had completely missed this failure mode!!!

Thanx, Paul

#175 lore raw
In reply to Arve Hjønnevåg
Quoted 14 lines · Arve Hjønnevåg
Quoted 1 line · Paul E. McKenney

On Sun, Aug 01, 2010 at 03:47:08PM -0700, Arjan van de Ven wrote:

...

Quoted 9 lines
Quoted 4 lines

Another one: freezing whole cgroups..... we have that today. it actually works quite well.... of course the hard part is the decision what to put in which cgroup, and at what frequency and duration you let cgroups run.

Indeed, the Android guys seemed to be quite excited by cgroup freezing until they thought about the application-classification problem. Seems like it should be easy for some types of applications, but I do admit that apps can have non-trivial and non-obvious dependencies.

Quoted 9 lines

The dependencies is what made this solution uninteresting to us. For instance, we currently use cgroup scheduling to reduce the impact of some background tasks, but we occasionally saw a watchdog restart of the system process were critical services were waiting on a kernel mutex owned by a background task for more than 20 seconds. If we froze a cgroup instead, we would not hit this particular problem since tasks cannot be frozen while executing kernel code the same way they can be preempted, but nothing prevents a task from being frozen while holding a user-space resource.

Excellent point -- I had completely missed this failure mode!!!

Thanx, Paul

#176 lore raw
In reply to Arve Hjønnevåg
Quoted 13 lines · On Mon, 2 Aug 2010 21:56:10 -0700 Arve Hjønnevåg <[email protected]> wrote:
Quoted 2 lines

non-obvious dependencies.

The dependencies is what made this solution uninteresting to us. For instance, we currently use cgroup scheduling to reduce the impact of some background tasks, but we occasionally saw a watchdog restart of the system process were critical services were waiting on a kernel mutex owned by a background task for more than 20 seconds. If we froze a cgroup instead, we would not hit this particular problem since tasks cannot be frozen while executing kernel code the same way they can be preempted, but nothing prevents a task from being frozen while holding a user-space resource.

one of the solutions we're looking at to solve this is to unfreeze the cgroup on a regular basis (say, every 15 to 30 seconds) briefly to avoid this kind of deadlock...

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
#177 lore raw
Quoted 16 lines · Arjan van de Ven
Quoted 12 lines · On Mon, 2 Aug 2010 21:56:10 -0700 Arve Hjønnevåg <[email protected]> wrote:
Quoted 2 lines

non-obvious dependencies.

The dependencies is what made this solution uninteresting to us. For instance, we currently use cgroup scheduling to reduce the impact of some background tasks, but we occasionally saw a watchdog restart of the system process were critical services were waiting on a kernel mutex owned by a background task for more than 20 seconds. If we froze a cgroup instead, we would not hit this particular problem since tasks cannot be frozen while executing kernel code the same way they can be preempted, but nothing prevents a task from being frozen while holding a user-space resource.

Quoted 3 lines

one of the solutions we're looking at to solve this is to unfreeze the cgroup on a regular basis (say, every 15 to 30 seconds) briefly to avoid this kind of deadlock...

Cute!!! ;-)

If this doesn't work for the Android folks for whatever reason, another approach would be to do the freeze in user code, which could track whether any user-level resources (pthread mutexes, SysV semas, whatever) where held, and do the freeze on a thread-by-thread basis within each "victim" application as the threads reach safe points.

I must of course defer to the Android folks as to whether or not this would actually work for Android. But if your approach works for them, why worry?

Thanx, Paul

#178 lore raw
In reply to Arjan van de Ven
Quoted 16 lines · Arjan van de Ven
Quoted 12 lines · On Mon, 2 Aug 2010 21:56:10 -0700 Arve Hjønnevåg <[email protected]> wrote:
Quoted 2 lines

non-obvious dependencies.

The dependencies is what made this solution uninteresting to us. For instance, we currently use cgroup scheduling to reduce the impact of some background tasks, but we occasionally saw a watchdog restart of the system process were critical services were waiting on a kernel mutex owned by a background task for more than 20 seconds. If we froze a cgroup instead, we would not hit this particular problem since tasks cannot be frozen while executing kernel code the same way they can be preempted, but nothing prevents a task from being frozen while holding a user-space resource.

Quoted 3 lines

one of the solutions we're looking at to solve this is to unfreeze the cgroup on a regular basis (say, every 15 to 30 seconds) briefly to avoid this kind of deadlock...

Cute!!! ;-)

If this doesn't work for the Android folks for whatever reason, another approach would be to do the freeze in user code, which could track whether any user-level resources (pthread mutexes, SysV semas, whatever) where held, and do the freeze on a thread-by-thread basis within each "victim" application as the threads reach safe points.

I must of course defer to the Android folks as to whether or not this would actually work for Android. But if your approach works for them, why worry?

Thanx, Paul

#179 lore raw
Quoted 5 lines · Paul E. McKenney

If this doesn't work for the Android folks for whatever reason, another approach would be to do the freeze in user code, which could track whether any user-level resources (pthread mutexes, SysV semas, whatever) where held, and do the freeze on a thread-by-thread basis within each "victim" application as the threads reach safe points.

The main problem I see with the cgroups solution is that it doesn't seem to do anything to handle avoiding loss of wakeup events.

Signature · 1 line
Matthew Garrett | [email protected]
#180 lore raw
In reply to Paul E. McKenney
Quoted 5 lines · Paul E. McKenney

If this doesn't work for the Android folks for whatever reason, another approach would be to do the freeze in user code, which could track whether any user-level resources (pthread mutexes, SysV semas, whatever) where held, and do the freeze on a thread-by-thread basis within each "victim" application as the threads reach safe points.

The main problem I see with the cgroups solution is that it doesn't seem to do anything to handle avoiding loss of wakeup events.

Signature · 1 line
Matthew Garrett | [email protected]
#181 lore raw
Quoted 10 lines · Matthew Garrett
Quoted 5 lines · Paul E. McKenney

If this doesn't work for the Android folks for whatever reason, another approach would be to do the freeze in user code, which could track whether any user-level resources (pthread mutexes, SysV semas, whatever) where held, and do the freeze on a thread-by-thread basis within each "victim" application as the threads reach safe points.

The main problem I see with the cgroups solution is that it doesn't seem to do anything to handle avoiding loss of wakeup events.

there are two cgroup solutions in discussion at this point.

weeks ago there was the suggestion to put non-privilaged tasks in a cgroup so that they could be frozen as a group. I thought the problem there was that there can be user-space dpendancies that would prevent privilaged tasks from working.

a couple days ago I made the suggestion to put non-privilaged tasks in a cgroup so that the idle/suspend decision code could ignore acitivity caused by this cgroup.

in the second version wakeup events would be 'activity' that would be counted and therefor the system would not be idle. As for the race with suspending and new things happening, wouldn't that be handled the same way that it is in a normal linux box?

David Lang

#182 lore raw
In reply to Matthew Garrett
Quoted 10 lines · Matthew Garrett
Quoted 5 lines · Paul E. McKenney

If this doesn't work for the Android folks for whatever reason, another approach would be to do the freeze in user code, which could track whether any user-level resources (pthread mutexes, SysV semas, whatever) where held, and do the freeze on a thread-by-thread basis within each "victim" application as the threads reach safe points.

The main problem I see with the cgroups solution is that it doesn't seem to do anything to handle avoiding loss of wakeup events.

there are two cgroup solutions in discussion at this point.

weeks ago there was the suggestion to put non-privilaged tasks in a cgroup so that they could be frozen as a group. I thought the problem there was that there can be user-space dpendancies that would prevent privilaged tasks from working.

a couple days ago I made the suggestion to put non-privilaged tasks in a cgroup so that the idle/suspend decision code could ignore acitivity caused by this cgroup.

in the second version wakeup events would be 'activity' that would be counted and therefor the system would not be idle. As for the race with suspending and new things happening, wouldn't that be handled the same way that it is in a normal linux box?

David Lang

#183 lore raw
Quoted 8 lines · On Wed, Aug 04, 2010 at 11:30:44AM -0700, [email protected] wrote:

a couple days ago I made the suggestion to put non-privilaged tasks in a cgroup so that the idle/suspend decision code could ignore acitivity caused by this cgroup.

in the second version wakeup events would be 'activity' that would be counted and therefor the system would not be idle. As for the race with suspending and new things happening, wouldn't that be handled the same way that it is in a normal linux box?

No! And that's precisely the issue. Android's existing behaviour could be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

Signature · 1 line
Matthew Garrett | [email protected]
#184 lore raw
In reply to [email protected]
Quoted 8 lines · On Wed, Aug 04, 2010 at 11:30:44AM -0700, [email protected] wrote:

a couple days ago I made the suggestion to put non-privilaged tasks in a cgroup so that the idle/suspend decision code could ignore acitivity caused by this cgroup.

in the second version wakeup events would be 'activity' that would be counted and therefor the system would not be idle. As for the race with suspending and new things happening, wouldn't that be handled the same way that it is in a normal linux box?

No! And that's precisely the issue. Android's existing behaviour could be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

Signature · 1 line
Matthew Garrett | [email protected]
#185 lore raw
Quoted 22 lines · Matthew Garrett
Quoted 8 lines · On Wed, Aug 04, 2010 at 11:30:44AM -0700, [email protected] wrote:

a couple days ago I made the suggestion to put non-privilaged tasks in a cgroup so that the idle/suspend decision code could ignore acitivity caused by this cgroup.

in the second version wakeup events would be 'activity' that would be counted and therefor the system would not be idle. As for the race with suspending and new things happening, wouldn't that be handled the same way that it is in a normal linux box?

No! And that's precisely the issue. Android's existing behaviour could be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

Quoted 3 lines

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

Even in the current implementation (wakelocks), Since the VOIP application isn't allowed to take a wakelock, wouldn't the system go to sleep immediatly anyway, even if the application gets the packet and starts the call? What would ever raise the wakelock to keep the phone from sleeping in the middle of the call?

as I said last night in an e-mail to Arve

Quoted 14 lines

it's possible that I'm making false assumptions about how quickly you want to go into full suspend mode.

if a user is doing nothing that would warrent wakelocks, but has an unprivilaged application running (a dancing cows game), and is doing nothing other than occasionally hitting a button, how short is the timeout that you would set that would have the system go into suspend? (i.e. how frequently must the user do something to keep the system awake)

or let's use a better example, the user has an unprivilaged book-reader application, how quickly must they change pages to prevent the system from suspending?

Quoted 6 lines

I'm figuring that these times are in the 1-5 minute range.

therefor the timeout period I am mentioning above could easily be one wakeup every 40-50 seconds. that is not going to kill your idle power.

is my assumption about the length of the timeout incorrect?

David Lang

#186 lore raw
In reply to Matthew Garrett
Quoted 22 lines · Matthew Garrett
Quoted 8 lines · On Wed, Aug 04, 2010 at 11:30:44AM -0700, [email protected] wrote:

a couple days ago I made the suggestion to put non-privilaged tasks in a cgroup so that the idle/suspend decision code could ignore acitivity caused by this cgroup.

in the second version wakeup events would be 'activity' that would be counted and therefor the system would not be idle. As for the race with suspending and new things happening, wouldn't that be handled the same way that it is in a normal linux box?

No! And that's precisely the issue. Android's existing behaviour could be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

Quoted 3 lines

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

Even in the current implementation (wakelocks), Since the VOIP application isn't allowed to take a wakelock, wouldn't the system go to sleep immediatly anyway, even if the application gets the packet and starts the call? What would ever raise the wakelock to keep the phone from sleeping in the middle of the call?

as I said last night in an e-mail to Arve

Quoted 11 lines

it's possible that I'm making false assumptions about how quickly you want to go into full suspend mode.

if a user is doing nothing that would warrent wakelocks, but has an unprivilaged application running (a dancing cows game), and is doing nothing other than occasionally hitting a button, how short is the timeout that you would set that would have the system go into suspend? (i.e. how frequently must the user do something to keep the system awake)

or let's use a better example, the user has an unprivilaged book-reader application, how quickly must they change pages to prevent the system from suspending?

I'm figuring that these times are in the 1-5 minute range.

therefor the timeout period I am mentioning above could easily be one wakeup every 40-50 seconds. that is not going to kill your idle power.

is my assumption about the length of the timeout incorrect?

David Lang

#187 lore raw
Quoted 17 lines · On Wed, Aug 04, 2010 at 12:15:59PM -0700, [email protected] wrote:
Quoted 12 lines · Matthew Garrett

No! And that's precisely the issue. Android's existing behaviour could be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

Quoted 3 lines

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

Quoted 5 lines

Even in the current implementation (wakelocks), Since the VOIP application isn't allowed to take a wakelock, wouldn't the system go to sleep immediatly anyway, even if the application gets the packet and starts the call? What would ever raise the wakelock to keep the phone from sleeping in the middle of the call?

There's two parts of that. The first is that the voip application is allowed to take a wakelock - but that doesn't mean that you trust it the rest of the time.The second is that the incoming network packet causes the kernel to take a wakelock that will be released once userspace has processed the network packet. This ensures that at least one wakelock is held for the entire relevant period of time.

Signature · 1 line
Matthew Garrett | [email protected]
#188 lore raw
In reply to [email protected]
Quoted 17 lines · On Wed, Aug 04, 2010 at 12:15:59PM -0700, [email protected] wrote:
Quoted 12 lines · Matthew Garrett

No! And that's precisely the issue. Android's existing behaviour could be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

Quoted 3 lines

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

Quoted 5 lines

Even in the current implementation (wakelocks), Since the VOIP application isn't allowed to take a wakelock, wouldn't the system go to sleep immediatly anyway, even if the application gets the packet and starts the call? What would ever raise the wakelock to keep the phone from sleeping in the middle of the call?

There's two parts of that. The first is that the voip application is allowed to take a wakelock - but that doesn't mean that you trust it the rest of the time.The second is that the incoming network packet causes the kernel to take a wakelock that will be released once userspace has processed the network packet. This ensures that at least one wakelock is held for the entire relevant period of time.

Signature · 1 line
Matthew Garrett | [email protected]
#189 lore raw
Quoted 24 lines · Matthew Garrett
Quoted 17 lines · On Wed, Aug 04, 2010 at 12:15:59PM -0700, [email protected] wrote:
Quoted 12 lines · Matthew Garrett

No! And that's precisely the issue. Android's existing behaviour could be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

Quoted 3 lines

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

Quoted 5 lines

Even in the current implementation (wakelocks), Since the VOIP application isn't allowed to take a wakelock, wouldn't the system go to sleep immediatly anyway, even if the application gets the packet and starts the call? What would ever raise the wakelock to keep the phone from sleeping in the middle of the call?

Quoted 3 lines

There's two parts of that. The first is that the voip application is allowed to take a wakelock - but that doesn't mean that you trust it the rest of the time.

why would you trust it to take a wakelock, but not trust it the rest of the time?

in my proposal I'm saying that if you would trust the application to take a wakelock, you instead trust it to be sane in the rest of it's power activity (avoiding polling, etc) and so you consider it for sleep decisions.

Quoted 4 lines

The second is that the incoming network packet causes
the kernel to take a wakelock that will be released once userspace has processed the network packet. This ensures that at least one wakelock is held for the entire relevant period of time.

how do you determine that userspace has processed the network packet so that the kernel can release the wakelock (or is this one of the cases where there is a timer related to the wakelock)

two things here,

on the dirty networks that I see as common, refusing to sleep if network packets are arriving will mean that you never go to sleep.

secondly, nothing stops the code doing the idle/suspend decision from considering network activity. I would be surprised if there weren't already options to support this today.

David Lang

#190 lore raw
In reply to Matthew Garrett
Quoted 24 lines · Matthew Garrett
Quoted 17 lines · On Wed, Aug 04, 2010 at 12:15:59PM -0700, [email protected] wrote:
Quoted 12 lines · Matthew Garrett

No! And that's precisely the issue. Android's existing behaviour could be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

Quoted 3 lines

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

Quoted 5 lines

Even in the current implementation (wakelocks), Since the VOIP application isn't allowed to take a wakelock, wouldn't the system go to sleep immediatly anyway, even if the application gets the packet and starts the call? What would ever raise the wakelock to keep the phone from sleeping in the middle of the call?

Quoted 3 lines

There's two parts of that. The first is that the voip application is allowed to take a wakelock - but that doesn't mean that you trust it the rest of the time.

why would you trust it to take a wakelock, but not trust it the rest of the time?

in my proposal I'm saying that if you would trust the application to take a wakelock, you instead trust it to be sane in the rest of it's power activity (avoiding polling, etc) and so you consider it for sleep decisions.

Quoted 4 lines

The second is that the incoming network packet causes
the kernel to take a wakelock that will be released once userspace has processed the network packet. This ensures that at least one wakelock is held for the entire relevant period of time.

how do you determine that userspace has processed the network packet so that the kernel can release the wakelock (or is this one of the cases where there is a timer related to the wakelock)

two things here,

on the dirty networks that I see as common, refusing to sleep if network packets are arriving will mean that you never go to sleep.

secondly, nothing stops the code doing the idle/suspend decision from considering network activity. I would be surprised if there weren't already options to support this today.

David Lang

#191 lore raw
Quoted 2 lines · On Wed, Aug 04, 2010 at 12:29:36PM -0700, [email protected] wrote:

why would you trust it to take a wakelock, but not trust it the rest of the time?

Because I trust that when the application author says "I explicitly need the machine to stay awake" that they mean it, whereas I don't trust the application author to write an application that avoids consuming background CPU. The distinction is pretty important.

Quoted 4 lines

in my proposal I'm saying that if you would trust the application to take a wakelock, you instead trust it to be sane in the rest of it's power activity (avoiding polling, etc) and so you consider it for sleep decisions.

When we say "trust", we're not using the same meaning as we do with security. Yes, it's possible that an application that can block suspend will do so at inopportune times. But given that blocking suspend is an explicit act it's much more likely that the developer will only use it in reasonable ways, while it's still entirely plausible that the application will generate unnecessary wakeups. Pretending otherwise is unrealistic. I recently had to fix the fact that the kernel IPMI layer would generate a constant 1000 wakeups a second even if it had an interrupt-driven controller or was entirely idle.

Quoted 8 lines
Quoted 4 lines

The second is that the incoming network packet causes
the kernel to take a wakelock that will be released once userspace has processed the network packet. This ensures that at least one wakelock is held for the entire relevant period of time.

how do you determine that userspace has processed the network packet so that the kernel can release the wakelock (or is this one of the cases where there is a timer related to the wakelock)

The current implementation uses a timer, but Rafael's implementation should allow userspace to explicitly acknowledge it.

Quoted 4 lines

two things here,

on the dirty networks that I see as common, refusing to sleep if network packets are arriving will mean that you never go to sleep.

Cell networks typically have no background traffic, for obvious reasons.

Quoted 3 lines

secondly, nothing stops the code doing the idle/suspend decision from considering network activity. I would be surprised if there weren't already options to support this today.

If you proxy every potential wakeup event through some central server then this becomes much easier, but it's also a performance hit. The alternative is that you poll for network activity, but that's a power hit.

Signature · 1 line
Matthew Garrett | [email protected]
#192 lore raw
In reply to [email protected]
Quoted 2 lines · On Wed, Aug 04, 2010 at 12:29:36PM -0700, [email protected] wrote:

why would you trust it to take a wakelock, but not trust it the rest of the time?

Because I trust that when the application author says "I explicitly need the machine to stay awake" that they mean it, whereas I don't trust the application author to write an application that avoids consuming background CPU. The distinction is pretty important.

Quoted 4 lines

in my proposal I'm saying that if you would trust the application to take a wakelock, you instead trust it to be sane in the rest of it's power activity (avoiding polling, etc) and so you consider it for sleep decisions.

When we say "trust", we're not using the same meaning as we do with security. Yes, it's possible that an application that can block suspend will do so at inopportune times. But given that blocking suspend is an explicit act it's much more likely that the developer will only use it in reasonable ways, while it's still entirely plausible that the application will generate unnecessary wakeups. Pretending otherwise is unrealistic. I recently had to fix the fact that the kernel IPMI layer would generate a constant 1000 wakeups a second even if it had an interrupt-driven controller or was entirely idle.

Quoted 8 lines
Quoted 4 lines

The second is that the incoming network packet causes
the kernel to take a wakelock that will be released once userspace has processed the network packet. This ensures that at least one wakelock is held for the entire relevant period of time.

how do you determine that userspace has processed the network packet so that the kernel can release the wakelock (or is this one of the cases where there is a timer related to the wakelock)

The current implementation uses a timer, but Rafael's implementation should allow userspace to explicitly acknowledge it.

Quoted 4 lines

two things here,

on the dirty networks that I see as common, refusing to sleep if network packets are arriving will mean that you never go to sleep.

Cell networks typically have no background traffic, for obvious reasons.

Quoted 3 lines

secondly, nothing stops the code doing the idle/suspend decision from considering network activity. I would be surprised if there weren't already options to support this today.

If you proxy every potential wakeup event through some central server then this becomes much easier, but it's also a performance hit. The alternative is that you poll for network activity, but that's a power hit.

Signature · 1 line
Matthew Garrett | [email protected]
#193 lore raw
Quoted 9 lines · Matthew Garrett
Quoted 2 lines · On Wed, Aug 04, 2010 at 12:29:36PM -0700, [email protected] wrote:

why would you trust it to take a wakelock, but not trust it the rest of the time?

Because I trust that when the application author says "I explicitly need the machine to stay awake" that they mean it, whereas I don't trust the application author to write an application that avoids consuming background CPU. The distinction is pretty important.

on the other hand, making an application avoid consuming inappropriate background resources helps everywhere. an explicit "don't let the machine sleep" only works if you are trusted by a system that implements this flag.

yes, it is painful to make the change, but the end result is better (and there are more tools out there to figure things out)

Quoted 5 lines
Quoted 4 lines

in my proposal I'm saying that if you would trust the application to take a wakelock, you instead trust it to be sane in the rest of it's power activity (avoiding polling, etc) and so you consider it for sleep decisions.

Quoted 9 lines

When we say "trust", we're not using the same meaning as we do with security. Yes, it's possible that an application that can block suspend will do so at inopportune times. But given that blocking suspend is an explicit act it's much more likely that the developer will only use it in reasonable ways, while it's still entirely plausible that the application will generate unnecessary wakeups. Pretending otherwise is unrealistic. I recently had to fix the fact that the kernel IPMI layer would generate a constant 1000 wakeups a second even if it had an interrupt-driven controller or was entirely idle.

I'm not sure I buy the distinction, but I'm not a maintainer so it's others you have to convince.

it's better to have one type of problem with one set of tools that document why the machine isn't sleeping, than to have orthoginal ways of influencing power management.

but if you have an application in the mid-level trust situation, go ahead and have it talk to a 'keepalive' daemon that is in the 'trusted' set and let the rest of the app run untrusted. As I noted elsewhere, the keepalive daemon would need very little in the way of resources and can implement much more complex policies than anyone is going to be willing to put in the kernel.

Quoted 11 lines
Quoted 8 lines
Quoted 4 lines

The second is that the incoming network packet causes
the kernel to take a wakelock that will be released once userspace has processed the network packet. This ensures that at least one wakelock is held for the entire relevant period of time.

how do you determine that userspace has processed the network packet so that the kernel can release the wakelock (or is this one of the cases where there is a timer related to the wakelock)

The current implementation uses a timer, but Rafael's implementation should allow userspace to explicitly acknowledge it.

similar to the current implementation, the arrival of a packet could be counted as activity that keeps the system awake for a bit (your timeout)

Quoted 6 lines
Quoted 4 lines

two things here,

on the dirty networks that I see as common, refusing to sleep if network packets are arriving will mean that you never go to sleep.

Cell networks typically have no background traffic, for obvious reasons.

but don't most new smartphones also connect up to wifi networks? those are FAR from quiet.

Quoted 8 lines
Quoted 3 lines

secondly, nothing stops the code doing the idle/suspend decision from considering network activity. I would be surprised if there weren't already options to support this today.

If you proxy every potential wakeup event through some central server then this becomes much easier, but it's also a performance hit. The alternative is that you poll for network activity, but that's a power hit.

I'm not suggesting running all events through some central server (unless you count the kernel as that server), I'm saying that the decision that the system is idle and therefor can be stopped should be able to take this infomation into account, and if there's a race here, it should be a race that exists everywhere else, so there should be a general solution, not something specific to one use-case. (and definantly not something that requires all software to be modified and trusted to implement)

David Lang

#194 lore raw
In reply to Matthew Garrett
Quoted 9 lines · Matthew Garrett
Quoted 2 lines · On Wed, Aug 04, 2010 at 12:29:36PM -0700, [email protected] wrote:

why would you trust it to take a wakelock, but not trust it the rest of the time?

Because I trust that when the application author says "I explicitly need the machine to stay awake" that they mean it, whereas I don't trust the application author to write an application that avoids consuming background CPU. The distinction is pretty important.

on the other hand, making an application avoid consuming inappropriate background resources helps everywhere. an explicit "don't let the machine sleep" only works if you are trusted by a system that implements this flag.

yes, it is painful to make the change, but the end result is better (and there are more tools out there to figure things out)

Quoted 5 lines
Quoted 4 lines

in my proposal I'm saying that if you would trust the application to take a wakelock, you instead trust it to be sane in the rest of it's power activity (avoiding polling, etc) and so you consider it for sleep decisions.

Quoted 9 lines

When we say "trust", we're not using the same meaning as we do with security. Yes, it's possible that an application that can block suspend will do so at inopportune times. But given that blocking suspend is an explicit act it's much more likely that the developer will only use it in reasonable ways, while it's still entirely plausible that the application will generate unnecessary wakeups. Pretending otherwise is unrealistic. I recently had to fix the fact that the kernel IPMI layer would generate a constant 1000 wakeups a second even if it had an interrupt-driven controller or was entirely idle.

I'm not sure I buy the distinction, but I'm not a maintainer so it's others you have to convince.

it's better to have one type of problem with one set of tools that document why the machine isn't sleeping, than to have orthoginal ways of influencing power management.

but if you have an application in the mid-level trust situation, go ahead and have it talk to a 'keepalive' daemon that is in the 'trusted' set and let the rest of the app run untrusted. As I noted elsewhere, the keepalive daemon would need very little in the way of resources and can implement much more complex policies than anyone is going to be willing to put in the kernel.

Quoted 11 lines
Quoted 8 lines
Quoted 4 lines

The second is that the incoming network packet causes
the kernel to take a wakelock that will be released once userspace has processed the network packet. This ensures that at least one wakelock is held for the entire relevant period of time.

how do you determine that userspace has processed the network packet so that the kernel can release the wakelock (or is this one of the cases where there is a timer related to the wakelock)

The current implementation uses a timer, but Rafael's implementation should allow userspace to explicitly acknowledge it.

similar to the current implementation, the arrival of a packet could be counted as activity that keeps the system awake for a bit (your timeout)

Quoted 6 lines
Quoted 4 lines

two things here,

on the dirty networks that I see as common, refusing to sleep if network packets are arriving will mean that you never go to sleep.

Cell networks typically have no background traffic, for obvious reasons.

but don't most new smartphones also connect up to wifi networks? those are FAR from quiet.

Quoted 8 lines
Quoted 3 lines

secondly, nothing stops the code doing the idle/suspend decision from considering network activity. I would be surprised if there weren't already options to support this today.

If you proxy every potential wakeup event through some central server then this becomes much easier, but it's also a performance hit. The alternative is that you poll for network activity, but that's a power hit.

I'm not suggesting running all events through some central server (unless you count the kernel as that server), I'm saying that the decision that the system is idle and therefor can be stopped should be able to take this infomation into account, and if there's a race here, it should be a race that exists everywhere else, so there should be a general solution, not something specific to one use-case. (and definantly not something that requires all software to be modified and trusted to implement)

David Lang

#195 lore raw
Quoted 7 lines · On Wed, Aug 04, 2010 at 03:20:04PM -0700, [email protected] wrote:

on the other hand, making an application avoid consuming inappropriate background resources helps everywhere. an explicit "don't let the machine sleep" only works if you are trusted by a system that implements this flag.

yes, it is painful to make the change, but the end result is better (and there are more tools out there to figure things out)

Nobody's denying that it's better, but people are saying they want to design a platform that's capable of handling the software we have rather than the software we'd like to have.

Quoted 6 lines

but if you have an application in the mid-level trust situation, go ahead and have it talk to a 'keepalive' daemon that is in the 'trusted' set and let the rest of the app run untrusted. As I noted elsewhere, the keepalive daemon would need very little in the way of resources and can implement much more complex policies than anyone is going to be willing to put in the kernel.

That doesn't work. You'll race with wakeup events.

Quoted 2 lines

similar to the current implementation, the arrival of a packet could be counted as activity that keeps the system awake for a bit (your timeout)

How? You're either polling in order to know whether there's network activity, or you're having every network packet wake up the policy daemon, or you've got something that looks like the kernel side of wakelocks.

Quoted 4 lines
Quoted 1 line

Cell networks typically have no background traffic, for obvious reasons.

but don't most new smartphones also connect up to wifi networks? those are FAR from quiet.

Wifi radio typically dwarfs your other power consumption anyway. The typical situation is one where you're not attached to a wifi network.

Quoted 7 lines

I'm not suggesting running all events through some central server (unless you count the kernel as that server), I'm saying that the decision that the system is idle and therefor can be stopped should be able to take this infomation into account, and if there's a race here, it should be a race that exists everywhere else, so there should be a general solution, not something specific to one use-case. (and definantly not something that requires all software to be modified and trusted to implement)

You're right. It's a race that exists everywhere else, and it's inherent unless you have some handshaking between userspace and the kernel when entering suspend. Which is what wakelocks provide. Nobody has proposed a solution that works without modifying existing code.

Signature · 1 line
Matthew Garrett | [email protected]
#196 lore raw
In reply to [email protected]
Quoted 7 lines · On Wed, Aug 04, 2010 at 03:20:04PM -0700, [email protected] wrote:

on the other hand, making an application avoid consuming inappropriate background resources helps everywhere. an explicit "don't let the machine sleep" only works if you are trusted by a system that implements this flag.

yes, it is painful to make the change, but the end result is better (and there are more tools out there to figure things out)

Nobody's denying that it's better, but people are saying they want to design a platform that's capable of handling the software we have rather than the software we'd like to have.

Quoted 6 lines

but if you have an application in the mid-level trust situation, go ahead and have it talk to a 'keepalive' daemon that is in the 'trusted' set and let the rest of the app run untrusted. As I noted elsewhere, the keepalive daemon would need very little in the way of resources and can implement much more complex policies than anyone is going to be willing to put in the kernel.

That doesn't work. You'll race with wakeup events.

Quoted 2 lines

similar to the current implementation, the arrival of a packet could be counted as activity that keeps the system awake for a bit (your timeout)

How? You're either polling in order to know whether there's network activity, or you're having every network packet wake up the policy daemon, or you've got something that looks like the kernel side of wakelocks.

Quoted 4 lines
Quoted 1 line

Cell networks typically have no background traffic, for obvious reasons.

but don't most new smartphones also connect up to wifi networks? those are FAR from quiet.

Wifi radio typically dwarfs your other power consumption anyway. The typical situation is one where you're not attached to a wifi network.

Quoted 7 lines

I'm not suggesting running all events through some central server (unless you count the kernel as that server), I'm saying that the decision that the system is idle and therefor can be stopped should be able to take this infomation into account, and if there's a race here, it should be a race that exists everywhere else, so there should be a general solution, not something specific to one use-case. (and definantly not something that requires all software to be modified and trusted to implement)

You're right. It's a race that exists everywhere else, and it's inherent unless you have some handshaking between userspace and the kernel when entering suspend. Which is what wakelocks provide. Nobody has proposed a solution that works without modifying existing code.

Signature · 1 line
Matthew Garrett | [email protected]
#197 lore raw
Quoted 9 lines · Matthew Garrett
Quoted 2 lines · On Wed, Aug 04, 2010 at 03:20:04PM -0700, [email protected] wrote:

similar to the current implementation, the arrival of a packet could be counted as activity that keeps the system awake for a bit (your timeout)

How? You're either polling in order to know whether there's network activity, or you're having every network packet wake up the policy daemon, or you've got something that looks like the kernel side of wakelocks.

infrequent polling (on the order of seconds or 10s of seconds) is not a very significant impact on your power

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Cell networks typically have no background traffic, for obvious reasons.

but don't most new smartphones also connect up to wifi networks? those are FAR from quiet.

Wifi radio typically dwarfs your other power consumption anyway. The typical situation is one where you're not attached to a wifi network.

on some devices (my kindle for example) the cell network dwarfs my other power consumption today.

Quoted 8 lines
Quoted 7 lines

I'm not suggesting running all events through some central server (unless you count the kernel as that server), I'm saying that the decision that the system is idle and therefor can be stopped should be able to take this infomation into account, and if there's a race here, it should be a race that exists everywhere else, so there should be a general solution, not something specific to one use-case. (and definantly not something that requires all software to be modified and trusted to implement)

Quoted 4 lines

You're right. It's a race that exists everywhere else, and it's inherent unless you have some handshaking between userspace and the kernel when entering suspend. Which is what wakelocks provide. Nobody has proposed a solution that works without modifying existing code.

I think the issue is confusion between the different purposes of the wakelock.

as you say, I don't think anyone is opposed to the kernel being modified to eliminate this race. The disagreement is far more about the interface to userspace and userspace use of wakelocks.

the kernel implementation of this doesn't have to set a single flag, and it doesn't have to notify userspace directly. The kernel already produces many stats today and it may be appropriate for the kernel to produce some more.

for example, if you want to abort the suspend because there is network activity, you can check the packet count of your network interface, decide to go to sleep, setup the network interface to raise a 'wake me up' interrupt (because you have decided in a userspace policy that you want this), and then check to see if the packet count has changed. If it has, abort the suspend, if not continue the suspend and once you are suspended if the 'wake me up' interrupt is set you will wake back up.

there are probably cleaner/better ways of doing this than the simple logic that I'm listing, but why wouldn't the simple logic provide the correct result?

David Lang

#198 lore raw
In reply to Matthew Garrett
Quoted 9 lines · Matthew Garrett
Quoted 2 lines · On Wed, Aug 04, 2010 at 03:20:04PM -0700, [email protected] wrote:

similar to the current implementation, the arrival of a packet could be counted as activity that keeps the system awake for a bit (your timeout)

How? You're either polling in order to know whether there's network activity, or you're having every network packet wake up the policy daemon, or you've got something that looks like the kernel side of wakelocks.

infrequent polling (on the order of seconds or 10s of seconds) is not a very significant impact on your power

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Cell networks typically have no background traffic, for obvious reasons.

but don't most new smartphones also connect up to wifi networks? those are FAR from quiet.

Wifi radio typically dwarfs your other power consumption anyway. The typical situation is one where you're not attached to a wifi network.

on some devices (my kindle for example) the cell network dwarfs my other power consumption today.

Quoted 8 lines
Quoted 7 lines

I'm not suggesting running all events through some central server (unless you count the kernel as that server), I'm saying that the decision that the system is idle and therefor can be stopped should be able to take this infomation into account, and if there's a race here, it should be a race that exists everywhere else, so there should be a general solution, not something specific to one use-case. (and definantly not something that requires all software to be modified and trusted to implement)

Quoted 4 lines

You're right. It's a race that exists everywhere else, and it's inherent unless you have some handshaking between userspace and the kernel when entering suspend. Which is what wakelocks provide. Nobody has proposed a solution that works without modifying existing code.

I think the issue is confusion between the different purposes of the wakelock.

as you say, I don't think anyone is opposed to the kernel being modified to eliminate this race. The disagreement is far more about the interface to userspace and userspace use of wakelocks.

the kernel implementation of this doesn't have to set a single flag, and it doesn't have to notify userspace directly. The kernel already produces many stats today and it may be appropriate for the kernel to produce some more.

for example, if you want to abort the suspend because there is network activity, you can check the packet count of your network interface, decide to go to sleep, setup the network interface to raise a 'wake me up' interrupt (because you have decided in a userspace policy that you want this), and then check to see if the packet count has changed. If it has, abort the suspend, if not continue the suspend and once you are suspended if the 'wake me up' interrupt is set you will wake back up.

there are probably cleaner/better ways of doing this than the simple logic that I'm listing, but why wouldn't the simple logic provide the correct result?

David Lang

#199 lore raw
Quoted 9 lines · On Thu, Aug 5, 2010 at 7:34 AM, <[email protected]> wrote:

for example, if you want to abort the suspend because there is network activity, you can check the packet count of your network interface, decide to go to sleep, setup the network interface to raise a 'wake me up' interrupt (because you have decided in a userspace policy that you want this), and then check to see if the packet count has changed. If it has, abort the suspend, if not continue the suspend and once you are suspended if the 'wake me up' interrupt is set you will wake back up.

Quoted 3 lines

there are probably cleaner/better ways of doing this than the simple logic that I'm listing, but why wouldn't the simple logic provide the correct result?

If your network interrupt happens before the network driver's suspend() hook is called this works -- the check in the suspend hook observes the change and returns an abort status.

If your network interrupt happens after the suspend() hook is called this does not work -- the event comes after your opportunity to abort suspend has happened, your interrupt handler processed it, set the flag, but the system proceeds to suspend anyway, missing the event.

The wakelock/suspendblock mechanism avoids races like the above.

Brian

#200 lore raw
In reply to [email protected]
Quoted 9 lines · On Thu, Aug 5, 2010 at 7:34 AM, <[email protected]> wrote:

for example, if you want to abort the suspend because there is network activity, you can check the packet count of your network interface, decide to go to sleep, setup the network interface to raise a 'wake me up' interrupt (because you have decided in a userspace policy that you want this), and then check to see if the packet count has changed. If it has, abort the suspend, if not continue the suspend and once you are suspended if the 'wake me up' interrupt is set you will wake back up.

Quoted 3 lines

there are probably cleaner/better ways of doing this than the simple logic that I'm listing, but why wouldn't the simple logic provide the correct result?

If your network interrupt happens before the network driver's suspend() hook is called this works -- the check in the suspend hook observes the change and returns an abort status.

If your network interrupt happens after the suspend() hook is called this does not work -- the event comes after your opportunity to abort suspend has happened, your interrupt handler processed it, set the flag, but the system proceeds to suspend anyway, missing the event.

The wakelock/suspendblock mechanism avoids races like the above.

Brian

#201 lore raw
In reply to [email protected]
Quoted 30 lines · On Wed, Aug 04, 2010 at 12:29:36PM -0700, [email protected] wrote:
Quoted 24 lines · Matthew Garrett
Quoted 17 lines · On Wed, Aug 04, 2010 at 12:15:59PM -0700, [email protected] wrote:
Quoted 12 lines · Matthew Garrett

No! And that's precisely the issue. Android's existing behaviour could be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

Quoted 3 lines

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

Quoted 5 lines

Even in the current implementation (wakelocks), Since the VOIP application isn't allowed to take a wakelock, wouldn't the system go to sleep immediatly anyway, even if the application gets the packet and starts the call? What would ever raise the wakelock to keep the phone from sleeping in the middle of the call?

Quoted 3 lines

There's two parts of that. The first is that the voip application is allowed to take a wakelock - but that doesn't mean that you trust it the rest of the time.

Quoted 7 lines

why would you trust it to take a wakelock, but not trust it the rest of the time?

in my proposal I'm saying that if you would trust the application to take a wakelock, you instead trust it to be sane in the rest of it's power activity (avoiding polling, etc) and so you consider it for sleep decisions.

The word "trust" does not appear to be helping here. ;-)

The VOIP application acquires a suspend blocker when it needs to prevent the system from suspending, and releases that suspend blocker when it can tolerate the system suspending. It is important to note that while the VOIP application holds the suspend blocker, the system won't suspend even if it is completely idle (for example, if the VOIP application uses blocking system calls, during the time that the VOIP application is waiting for its next event).

Quoted 8 lines
Quoted 4 lines

The second is that the incoming network packet causes
the kernel to take a wakelock that will be released once userspace has processed the network packet. This ensures that at least one wakelock is held for the entire relevant period of time.

how do you determine that userspace has processed the network packet so that the kernel can release the wakelock (or is this one of the cases where there is a timer related to the wakelock)

There are two cases:

1. The application is permitted to acquire suspend blockers.
In this case, the application would acquire a suspend blocker before reading the input. It would then read the input (at which point the kernel releases its suspend blocker), do any needed processing, and finally release the suspend blocker.

So in this case, the system knows that the application is done processing the input when that application releases its suspend blocker.

2. The application is prohibited from acquiring suspend blockers.
In this case, the system might well be suspended before the application has a chance to do more than read the input.

But the application will get a chance to process the input when the next input event is directed to it.

Quoted 8 lines

two things here,

on the dirty networks that I see as common, refusing to sleep if network packets are arriving will mean that you never go to sleep.

secondly, nothing stops the code doing the idle/suspend decision from considering network activity. I would be surprised if there weren't already options to support this today.

I don't know about the general networking case for Android, but the example of downloading was discussed some time back. The application doing the download acquires a suspend blocker, which it releases once the download is complete (or once a timeout expires, if I remember correctly). In this particular case, the network packets were not bringing the device out of suspend.

There might well be other cases where networking packets -do- bring the system out of suspend, but I must leave this to someone who knows more about Android than do I.

Thanx, Paul

#202 lore raw
In reply to [email protected]
Quoted 30 lines · On Wed, Aug 04, 2010 at 12:29:36PM -0700, [email protected] wrote:
Quoted 24 lines · Matthew Garrett
Quoted 17 lines · On Wed, Aug 04, 2010 at 12:15:59PM -0700, [email protected] wrote:
Quoted 12 lines · Matthew Garrett

No! And that's precisely the issue. Android's existing behaviour could be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

Quoted 3 lines

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

Quoted 5 lines

Even in the current implementation (wakelocks), Since the VOIP application isn't allowed to take a wakelock, wouldn't the system go to sleep immediatly anyway, even if the application gets the packet and starts the call? What would ever raise the wakelock to keep the phone from sleeping in the middle of the call?

Quoted 3 lines

There's two parts of that. The first is that the voip application is allowed to take a wakelock - but that doesn't mean that you trust it the rest of the time.

Quoted 7 lines

why would you trust it to take a wakelock, but not trust it the rest of the time?

in my proposal I'm saying that if you would trust the application to take a wakelock, you instead trust it to be sane in the rest of it's power activity (avoiding polling, etc) and so you consider it for sleep decisions.

The word "trust" does not appear to be helping here. ;-)

The VOIP application acquires a suspend blocker when it needs to prevent the system from suspending, and releases that suspend blocker when it can tolerate the system suspending. It is important to note that while the VOIP application holds the suspend blocker, the system won't suspend even if it is completely idle (for example, if the VOIP application uses blocking system calls, during the time that the VOIP application is waiting for its next event).

Quoted 8 lines
Quoted 4 lines

The second is that the incoming network packet causes
the kernel to take a wakelock that will be released once userspace has processed the network packet. This ensures that at least one wakelock is held for the entire relevant period of time.

how do you determine that userspace has processed the network packet so that the kernel can release the wakelock (or is this one of the cases where there is a timer related to the wakelock)

There are two cases:

1. The application is permitted to acquire suspend blockers.
In this case, the application would acquire a suspend blocker before reading the input. It would then read the input (at which point the kernel releases its suspend blocker), do any needed processing, and finally release the suspend blocker.

So in this case, the system knows that the application is done processing the input when that application releases its suspend blocker.

2. The application is prohibited from acquiring suspend blockers.
In this case, the system might well be suspended before the application has a chance to do more than read the input.

But the application will get a chance to process the input when the next input event is directed to it.

Quoted 8 lines

two things here,

on the dirty networks that I see as common, refusing to sleep if network packets are arriving will mean that you never go to sleep.

secondly, nothing stops the code doing the idle/suspend decision from considering network activity. I would be surprised if there weren't already options to support this today.

I don't know about the general networking case for Android, but the example of downloading was discussed some time back. The application doing the download acquires a suspend blocker, which it releases once the download is complete (or once a timeout expires, if I remember correctly). In this particular case, the network packets were not bringing the device out of suspend.

There might well be other cases where networking packets -do- bring the system out of suspend, but I must leave this to someone who knows more about Android than do I.

Thanx, Paul

#203 lore raw
Quoted 41 lines · Paul E. McKenney
Quoted 30 lines · On Wed, Aug 04, 2010 at 12:29:36PM -0700, [email protected] wrote:
Quoted 24 lines · Matthew Garrett
Quoted 17 lines · On Wed, Aug 04, 2010 at 12:15:59PM -0700, [email protected] wrote:
Quoted 12 lines · Matthew Garrett

No! And that's precisely the issue. Android's existing behaviour could be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

Quoted 3 lines

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

Quoted 5 lines

Even in the current implementation (wakelocks), Since the VOIP application isn't allowed to take a wakelock, wouldn't the system go to sleep immediatly anyway, even if the application gets the packet and starts the call? What would ever raise the wakelock to keep the phone from sleeping in the middle of the call?

Quoted 3 lines

There's two parts of that. The first is that the voip application is allowed to take a wakelock - but that doesn't mean that you trust it the rest of the time.

Quoted 7 lines

why would you trust it to take a wakelock, but not trust it the rest of the time?

in my proposal I'm saying that if you would trust the application to take a wakelock, you instead trust it to be sane in the rest of it's power activity (avoiding polling, etc) and so you consider it for sleep decisions.

The word "trust" does not appear to be helping here. ;-)

Quoted 7 lines

The VOIP application acquires a suspend blocker when it needs to prevent the system from suspending, and releases that suspend blocker when it can tolerate the system suspending. It is important to note that while the VOIP application holds the suspend blocker, the system won't suspend even if it is completely idle (for example, if the VOIP application uses blocking system calls, during the time that the VOIP application is waiting for its next event).

In the terminology I have been using, the VOIP sofware is then trusted to take the wakelock appropriately, and I'm then saying it would be in the trusted cgroup

Quoted 17 lines
Quoted 8 lines
Quoted 4 lines

The second is that the incoming network packet causes
the kernel to take a wakelock that will be released once userspace has processed the network packet. This ensures that at least one wakelock is held for the entire relevant period of time.

how do you determine that userspace has processed the network packet so that the kernel can release the wakelock (or is this one of the cases where there is a timer related to the wakelock)

There are two cases:

1. The application is permitted to acquire suspend blockers.
In this case, the application would acquire a suspend blocker before reading the input. It would then read the input (at which point the kernel releases its suspend blocker), do any needed processing, and finally release the suspend blocker.

Quoted 3 lines

So in this case, the system knows that the application is done processing the input when that application releases its suspend blocker.

in my proposal, the application is trusted to take the wakelock, so it would be trusted to not use the CPU wildly inappropriatly and so it running would make the system active and so it would not sleep.

Quoted 6 lines

2. The application is prohibited from acquiring suspend blockers.
In this case, the system might well be suspended before the application has a chance to do more than read the input.

But the application will get a chance to process the input when the next input event is directed to it.

In this case the system would go ahead and suspend, but the next time the sustem wakes up for any reason, this application would continue to run and process the input

Quoted 9 lines
Quoted 8 lines

two things here,

on the dirty networks that I see as common, refusing to sleep if network packets are arriving will mean that you never go to sleep.

secondly, nothing stops the code doing the idle/suspend decision from considering network activity. I would be surprised if there weren't already options to support this today.

Quoted 6 lines

I don't know about the general networking case for Android, but the example of downloading was discussed some time back. The application doing the download acquires a suspend blocker, which it releases once the download is complete (or once a timeout expires, if I remember correctly). In this particular case, the network packets were not bringing the device out of suspend.

it would seem reasonable to say that if a packet arrives for an existing connection (which the kernel does know) it is considered activity for purposes of sleeping.

I don't know if you would care enough to try and say that packets for untrusted apps network connections don't keep the system awake, or just allow them to (after all, keypresses going to untrusted apps do keep the system awake)

Quoted 3 lines

There might well be other cases where networking packets -do- bring the system out of suspend, but I must leave this to someone who knows more about Android than do I.

this would be the normal wake-on-lan type of functionality that exists without Android.

The primary thing that I was getting at was the other things above.

David Lang

#204 lore raw
Quoted 49 lines · On Wed, Aug 04, 2010 at 03:29:25PM -0700, [email protected] wrote:
Quoted 40 lines · Paul E. McKenney
Quoted 29 lines · On Wed, Aug 04, 2010 at 12:29:36PM -0700, [email protected] wrote:
Quoted 24 lines · Matthew Garrett
Quoted 17 lines · On Wed, Aug 04, 2010 at 12:15:59PM -0700, [email protected] wrote:
Quoted 12 lines · Matthew Garrett

No! And that's precisely the issue. Android's existing behaviour could be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

Quoted 3 lines

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

Quoted 5 lines

Even in the current implementation (wakelocks), Since the VOIP application isn't allowed to take a wakelock, wouldn't the system go to sleep immediatly anyway, even if the application gets the packet and starts the call? What would ever raise the wakelock to keep the phone from sleeping in the middle of the call?

Quoted 3 lines

There's two parts of that. The first is that the voip application is allowed to take a wakelock - but that doesn't mean that you trust it the rest of the time.

Quoted 7 lines

why would you trust it to take a wakelock, but not trust it the rest of the time?

in my proposal I'm saying that if you would trust the application to take a wakelock, you instead trust it to be sane in the rest of it's power activity (avoiding polling, etc) and so you consider it for sleep decisions.

The word "trust" does not appear to be helping here. ;-)

Quoted 7 lines

The VOIP application acquires a suspend blocker when it needs to prevent the system from suspending, and releases that suspend blocker when it can tolerate the system suspending. It is important to note that while the VOIP application holds the suspend blocker, the system won't suspend even if it is completely idle (for example, if the VOIP application uses blocking system calls, during the time that the VOIP application is waiting for its next event).

Quoted 3 lines

In the terminology I have been using, the VOIP sofware is then trusted to take the wakelock appropriately, and I'm then saying it would be in the trusted cgroup

Understood, but...

Quoted 17 lines
Quoted 17 lines
Quoted 8 lines
Quoted 4 lines

The second is that the incoming network packet causes
the kernel to take a wakelock that will be released once userspace has processed the network packet. This ensures that at least one wakelock is held for the entire relevant period of time.

how do you determine that userspace has processed the network packet so that the kernel can release the wakelock (or is this one of the cases where there is a timer related to the wakelock)

There are two cases:

1. The application is permitted to acquire suspend blockers.
In this case, the application would acquire a suspend blocker before reading the input. It would then read the input (at which point the kernel releases its suspend blocker), do any needed processing, and finally release the suspend blocker.

Quoted 7 lines
Quoted 3 lines

So in this case, the system knows that the application is done processing the input when that application releases its suspend blocker.

in my proposal, the application is trusted to take the wakelock, so it would be trusted to not use the CPU wildly inappropriatly and so it running would make the system active and so it would not sleep.

... here you seem to be assuming that "trusted to properly use a wakelock" implies "coded to optimize power usage when not holding a wakelock." But this does not necessarily follow.

Quoted 10 lines
Quoted 6 lines

2. The application is prohibited from acquiring suspend blockers.
In this case, the system might well be suspended before the application has a chance to do more than read the input.

But the application will get a chance to process the input when the next input event is directed to it.

In this case the system would go ahead and suspend, but the next time the sustem wakes up for any reason, this application would continue to run and process the input

Yep, that is in fact what I said. ;-)

Quoted 16 lines
Quoted 9 lines
Quoted 8 lines

two things here,

on the dirty networks that I see as common, refusing to sleep if network packets are arriving will mean that you never go to sleep.

secondly, nothing stops the code doing the idle/suspend decision from considering network activity. I would be surprised if there weren't already options to support this today.

Quoted 6 lines

I don't know about the general networking case for Android, but the example of downloading was discussed some time back. The application doing the download acquires a suspend blocker, which it releases once the download is complete (or once a timeout expires, if I remember correctly). In this particular case, the network packets were not bringing the device out of suspend.

Quoted 3 lines

it would seem reasonable to say that if a packet arrives for an existing connection (which the kernel does know) it is considered activity for purposes of sleeping.

That would be up to the people creating the system in question. In some cases, they might (as you say) want every packet arriving to wake up the system, in other cases they might not. We should not be taking that design decision away from them.

Quoted 4 lines

I don't know if you would care enough to try and say that packets for untrusted apps network connections don't keep the system awake, or just allow them to (after all, keypresses going to untrusted apps do keep the system awake)

Again, this is up to the people creating the system in question. On some Android systems, there is a particular button you have to press to wake the system up after it has suspended itself.

Quoted 6 lines
Quoted 3 lines

There might well be other cases where networking packets -do- bring the system out of suspend, but I must leave this to someone who knows more about Android than do I.

this would be the normal wake-on-lan type of functionality that exists without Android.

Although this wake-on-LAN functionality applies only to special wake-up packets, not to normal packets, right?

Thanx, Paul

Quoted 3 lines

The primary thing that I was getting at was the other things above.

David Lang

#205 lore raw
In reply to [email protected]
Quoted 49 lines · On Wed, Aug 04, 2010 at 03:29:25PM -0700, [email protected] wrote:
Quoted 40 lines · Paul E. McKenney
Quoted 29 lines · On Wed, Aug 04, 2010 at 12:29:36PM -0700, [email protected] wrote:
Quoted 24 lines · Matthew Garrett
Quoted 17 lines · On Wed, Aug 04, 2010 at 12:15:59PM -0700, [email protected] wrote:
Quoted 12 lines · Matthew Garrett

No! And that's precisely the issue. Android's existing behaviour could be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

Quoted 3 lines

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

Quoted 5 lines

Even in the current implementation (wakelocks), Since the VOIP application isn't allowed to take a wakelock, wouldn't the system go to sleep immediatly anyway, even if the application gets the packet and starts the call? What would ever raise the wakelock to keep the phone from sleeping in the middle of the call?

Quoted 3 lines

There's two parts of that. The first is that the voip application is allowed to take a wakelock - but that doesn't mean that you trust it the rest of the time.

Quoted 7 lines

why would you trust it to take a wakelock, but not trust it the rest of the time?

in my proposal I'm saying that if you would trust the application to take a wakelock, you instead trust it to be sane in the rest of it's power activity (avoiding polling, etc) and so you consider it for sleep decisions.

The word "trust" does not appear to be helping here. ;-)

Quoted 7 lines

The VOIP application acquires a suspend blocker when it needs to prevent the system from suspending, and releases that suspend blocker when it can tolerate the system suspending. It is important to note that while the VOIP application holds the suspend blocker, the system won't suspend even if it is completely idle (for example, if the VOIP application uses blocking system calls, during the time that the VOIP application is waiting for its next event).

Quoted 3 lines

In the terminology I have been using, the VOIP sofware is then trusted to take the wakelock appropriately, and I'm then saying it would be in the trusted cgroup

Understood, but...

Quoted 17 lines
Quoted 17 lines
Quoted 8 lines
Quoted 4 lines

The second is that the incoming network packet causes
the kernel to take a wakelock that will be released once userspace has processed the network packet. This ensures that at least one wakelock is held for the entire relevant period of time.

how do you determine that userspace has processed the network packet so that the kernel can release the wakelock (or is this one of the cases where there is a timer related to the wakelock)

There are two cases:

1. The application is permitted to acquire suspend blockers.
In this case, the application would acquire a suspend blocker before reading the input. It would then read the input (at which point the kernel releases its suspend blocker), do any needed processing, and finally release the suspend blocker.

Quoted 7 lines
Quoted 3 lines

So in this case, the system knows that the application is done processing the input when that application releases its suspend blocker.

in my proposal, the application is trusted to take the wakelock, so it would be trusted to not use the CPU wildly inappropriatly and so it running would make the system active and so it would not sleep.

... here you seem to be assuming that "trusted to properly use a wakelock" implies "coded to optimize power usage when not holding a wakelock." But this does not necessarily follow.

Quoted 10 lines
Quoted 6 lines

2. The application is prohibited from acquiring suspend blockers.
In this case, the system might well be suspended before the application has a chance to do more than read the input.

But the application will get a chance to process the input when the next input event is directed to it.

In this case the system would go ahead and suspend, but the next time the sustem wakes up for any reason, this application would continue to run and process the input

Yep, that is in fact what I said. ;-)

Quoted 16 lines
Quoted 9 lines
Quoted 8 lines

two things here,

on the dirty networks that I see as common, refusing to sleep if network packets are arriving will mean that you never go to sleep.

secondly, nothing stops the code doing the idle/suspend decision from considering network activity. I would be surprised if there weren't already options to support this today.

Quoted 6 lines

I don't know about the general networking case for Android, but the example of downloading was discussed some time back. The application doing the download acquires a suspend blocker, which it releases once the download is complete (or once a timeout expires, if I remember correctly). In this particular case, the network packets were not bringing the device out of suspend.

Quoted 3 lines

it would seem reasonable to say that if a packet arrives for an existing connection (which the kernel does know) it is considered activity for purposes of sleeping.

That would be up to the people creating the system in question. In some cases, they might (as you say) want every packet arriving to wake up the system, in other cases they might not. We should not be taking that design decision away from them.

Quoted 4 lines

I don't know if you would care enough to try and say that packets for untrusted apps network connections don't keep the system awake, or just allow them to (after all, keypresses going to untrusted apps do keep the system awake)

Again, this is up to the people creating the system in question. On some Android systems, there is a particular button you have to press to wake the system up after it has suspended itself.

Quoted 6 lines
Quoted 3 lines

There might well be other cases where networking packets -do- bring the system out of suspend, but I must leave this to someone who knows more about Android than do I.

this would be the normal wake-on-lan type of functionality that exists without Android.

Although this wake-on-LAN functionality applies only to special wake-up packets, not to normal packets, right?

Thanx, Paul

Quoted 3 lines

The primary thing that I was getting at was the other things above.

David Lang

#206 lore raw
Quoted 31 lines · Paul E. McKenney
Quoted 26 lines · On Wed, Aug 04, 2010 at 03:29:25PM -0700, [email protected] wrote:
Quoted 17 lines · Paul E. McKenney
Quoted 6 lines · On Wed, Aug 04, 2010 at 12:29:36PM -0700, [email protected] wrote:
Quoted 4 lines · Matthew Garrett

There's two parts of that. The first is that the voip application is allowed to take a wakelock - but that doesn't mean that you trust it the rest of the time.

Quoted 7 lines

why would you trust it to take a wakelock, but not trust it the rest of the time?

in my proposal I'm saying that if you would trust the application to take a wakelock, you instead trust it to be sane in the rest of it's power activity (avoiding polling, etc) and so you consider it for sleep decisions.

The word "trust" does not appear to be helping here. ;-)

Quoted 7 lines

The VOIP application acquires a suspend blocker when it needs to prevent the system from suspending, and releases that suspend blocker when it can tolerate the system suspending. It is important to note that while the VOIP application holds the suspend blocker, the system won't suspend even if it is completely idle (for example, if the VOIP application uses blocking system calls, during the time that the VOIP application is waiting for its next event).

Quoted 3 lines

In the terminology I have been using, the VOIP sofware is then trusted to take the wakelock appropriately, and I'm then saying it would be in the trusted cgroup

Quoted 8 lines

Understood, but...

Quoted 2 lines

it would be trusted to not use the CPU wildly inappropriatly and so it running would make the system active and so it would not sleep.

... here you seem to be assuming that "trusted to properly use a wakelock" implies "coded to optimize power usage when not holding a wakelock." But this does not necessarily follow.

I am saying that 'trusted to use a wakelock' does imply 'trusted to not waste power'

I am sure that there are apps that do not manage power effectivly, but I don't expect that giving those same developers wakelock power will make them do much better. I expect that any time they discover the system going to sleep on them, they will just add another wakelock to keep it awake. If they were the type to carefully consider what was really important and what wasn't, I would expect them to write fairly power efficiant code in the first place.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

2. The application is prohibited from acquiring suspend blockers.
In this case, the system might well be suspended before the application has a chance to do more than read the input.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

But the application will get a chance to process the input when the next input event is directed to it.

In this case the system would go ahead and suspend, but the next time the sustem wakes up for any reason, this application would continue to run and process the input

Yep, that is in fact what I said. ;-)

so the systems are pretty much equivalent from this point of view.

Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 8 lines

two things here,

on the dirty networks that I see as common, refusing to sleep if network packets are arriving will mean that you never go to sleep.

secondly, nothing stops the code doing the idle/suspend decision from considering network activity. I would be surprised if there weren't already options to support this today.

I don't know about the general networking case for Android, but the example of downloading was discussed some time back. The application doing the download acquires a suspend blocker, which it releases once the download is complete (or once a timeout expires, if I remember correctly). In this particular case, the network packets were not bringing the device out of suspend.

Quoted 8 lines
Quoted 3 lines

it would seem reasonable to say that if a packet arrives for an existing connection (which the kernel does know) it is considered activity for purposes of sleeping.

That would be up to the people creating the system in question. In some cases, they might (as you say) want every packet arriving to wake up the system, in other cases they might not. We should not be taking that design decision away from them.

well, if you have the kernel take a wakelock when the packet arrives, you are doing the equivalent thing.

Quoted 8 lines
Quoted 4 lines

I don't know if you would care enough to try and say that packets for untrusted apps network connections don't keep the system awake, or just allow them to (after all, keypresses going to untrusted apps do keep the system awake)

Again, this is up to the people creating the system in question. On some Android systems, there is a particular button you have to press to wake the system up after it has suspended itself.

note that here I am talking about thigns that will keep the system awake, not wake it up after it suspends.

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

There might well be other cases where networking packets -do- bring the system out of suspend, but I must leave this to someone who knows more about Android than do I.

this would be the normal wake-on-lan type of functionality that exists without Android.

Although this wake-on-LAN functionality applies only to special wake-up packets, not to normal packets, right?

that's not my understanding. my understanding (which could be flawed) is that wake-on-lan programs your IP into the NIC and if the NIC sees traffic for you it will wake you up. I've never had a reason to use it, so I could easily be mistaken.

David Lang

#207 lore raw
In reply to Paul E. McKenney
Quoted 31 lines · Paul E. McKenney
Quoted 26 lines · On Wed, Aug 04, 2010 at 03:29:25PM -0700, [email protected] wrote:
Quoted 17 lines · Paul E. McKenney
Quoted 6 lines · On Wed, Aug 04, 2010 at 12:29:36PM -0700, [email protected] wrote:
Quoted 4 lines · Matthew Garrett

There's two parts of that. The first is that the voip application is allowed to take a wakelock - but that doesn't mean that you trust it the rest of the time.

Quoted 7 lines

why would you trust it to take a wakelock, but not trust it the rest of the time?

in my proposal I'm saying that if you would trust the application to take a wakelock, you instead trust it to be sane in the rest of it's power activity (avoiding polling, etc) and so you consider it for sleep decisions.

The word "trust" does not appear to be helping here. ;-)

Quoted 7 lines

The VOIP application acquires a suspend blocker when it needs to prevent the system from suspending, and releases that suspend blocker when it can tolerate the system suspending. It is important to note that while the VOIP application holds the suspend blocker, the system won't suspend even if it is completely idle (for example, if the VOIP application uses blocking system calls, during the time that the VOIP application is waiting for its next event).

Quoted 3 lines

In the terminology I have been using, the VOIP sofware is then trusted to take the wakelock appropriately, and I'm then saying it would be in the trusted cgroup

Quoted 8 lines

Understood, but...

Quoted 2 lines

it would be trusted to not use the CPU wildly inappropriatly and so it running would make the system active and so it would not sleep.

... here you seem to be assuming that "trusted to properly use a wakelock" implies "coded to optimize power usage when not holding a wakelock." But this does not necessarily follow.

I am saying that 'trusted to use a wakelock' does imply 'trusted to not waste power'

I am sure that there are apps that do not manage power effectivly, but I don't expect that giving those same developers wakelock power will make them do much better. I expect that any time they discover the system going to sleep on them, they will just add another wakelock to keep it awake. If they were the type to carefully consider what was really important and what wasn't, I would expect them to write fairly power efficiant code in the first place.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

2. The application is prohibited from acquiring suspend blockers.
In this case, the system might well be suspended before the application has a chance to do more than read the input.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

But the application will get a chance to process the input when the next input event is directed to it.

In this case the system would go ahead and suspend, but the next time the sustem wakes up for any reason, this application would continue to run and process the input

Yep, that is in fact what I said. ;-)

so the systems are pretty much equivalent from this point of view.

Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 8 lines

two things here,

on the dirty networks that I see as common, refusing to sleep if network packets are arriving will mean that you never go to sleep.

secondly, nothing stops the code doing the idle/suspend decision from considering network activity. I would be surprised if there weren't already options to support this today.

I don't know about the general networking case for Android, but the example of downloading was discussed some time back. The application doing the download acquires a suspend blocker, which it releases once the download is complete (or once a timeout expires, if I remember correctly). In this particular case, the network packets were not bringing the device out of suspend.

Quoted 8 lines
Quoted 3 lines

it would seem reasonable to say that if a packet arrives for an existing connection (which the kernel does know) it is considered activity for purposes of sleeping.

That would be up to the people creating the system in question. In some cases, they might (as you say) want every packet arriving to wake up the system, in other cases they might not. We should not be taking that design decision away from them.

well, if you have the kernel take a wakelock when the packet arrives, you are doing the equivalent thing.

Quoted 8 lines
Quoted 4 lines

I don't know if you would care enough to try and say that packets for untrusted apps network connections don't keep the system awake, or just allow them to (after all, keypresses going to untrusted apps do keep the system awake)

Again, this is up to the people creating the system in question. On some Android systems, there is a particular button you have to press to wake the system up after it has suspended itself.

note that here I am talking about thigns that will keep the system awake, not wake it up after it suspends.

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

There might well be other cases where networking packets -do- bring the system out of suspend, but I must leave this to someone who knows more about Android than do I.

this would be the normal wake-on-lan type of functionality that exists without Android.

Although this wake-on-LAN functionality applies only to special wake-up packets, not to normal packets, right?

that's not my understanding. my understanding (which could be flawed) is that wake-on-lan programs your IP into the NIC and if the NIC sees traffic for you it will wake you up. I've never had a reason to use it, so I could easily be mistaken.

David Lang

#208 lore raw
In reply to Matthew Garrett
Quoted 22 lines · Matthew Garrett
Quoted 8 lines · On Wed, Aug 04, 2010 at 11:30:44AM -0700, [email protected] wrote:

a couple days ago I made the suggestion to put non-privilaged tasks in a cgroup so that the idle/suspend decision code could ignore acitivity caused by this cgroup.

in the second version wakeup events would be 'activity' that would be counted and therefor the system would not be idle. As for the race with suspending and new things happening, wouldn't that be handled the same way that it is in a normal linux box?

No! And that's precisely the issue. Android's existing behaviour could be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

Quoted 3 lines

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to avoid the race (if pm_wakeup_event() is called at 2)).

Thanks,
Rafael

#209 lore raw
In reply to Matthew Garrett
Quoted 22 lines · Matthew Garrett
Quoted 8 lines · On Wed, Aug 04, 2010 at 11:30:44AM -0700, [email protected] wrote:

a couple days ago I made the suggestion to put non-privilaged tasks in a cgroup so that the idle/suspend decision code could ignore acitivity caused by this cgroup.

in the second version wakeup events would be 'activity' that would be counted and therefor the system would not be idle. As for the race with suspending and new things happening, wouldn't that be handled the same way that it is in a normal linux box?

No! And that's precisely the issue. Android's existing behaviour could be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

Quoted 3 lines

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to avoid the race (if pm_wakeup_event() is called at 2)).

Thanks,
Rafael

#210 lore raw
In reply to Matthew Garrett
Quoted 22 lines · Matthew Garrett
Quoted 8 lines · On Wed, Aug 04, 2010 at 11:30:44AM -0700, [email protected] wrote:

a couple days ago I made the suggestion to put non-privilaged tasks in a cgroup so that the idle/suspend decision code could ignore acitivity caused by this cgroup.

in the second version wakeup events would be 'activity' that would be counted and therefor the system would not be idle. As for the race with suspending and new things happening, wouldn't that be handled the same way that it is in a normal linux box?

No! And that's precisely the issue. Android's existing behaviour could be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

Quoted 3 lines

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to avoid the race (if pm_wakeup_event() is called at 2)).

Thanks,
Rafael

#211 lore raw
Quoted 13 lines · Rafael J. Wysocki
Quoted 12 lines · Matthew Garrett

No! And that's precisely the issue. Android's existing behaviour could be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

Quoted 6 lines
Quoted 3 lines

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to avoid the race (if pm_wakeup_event() is called at 2)).

Yes, I think that solves the problem. The only question then is whether it's preferable to use cgroups or suspend fully, which is pretty much up to the implementation. In other words, is there a reason we're still having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

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

No! And that's precisely the issue. Android's existing behaviour could be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

Quoted 6 lines
Quoted 3 lines

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to avoid the race (if pm_wakeup_event() is called at 2)).

Yes, I think that solves the problem. The only question then is whether it's preferable to use cgroups or suspend fully, which is pretty much up to the implementation. In other words, is there a reason we're still having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

Signature · 1 line
Matthew Garrett | [email protected]
#213 lore raw
Quoted 18 lines · Matthew Garrett
Quoted 17 lines · Rafael J. Wysocki
Quoted 15 lines · Matthew Garrett

No! And that's precisely the issue. Android's existing behaviour could be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

Quoted 8 lines
Quoted 2 lines

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to avoid the race (if pm_wakeup_event() is called at 2)).

Yes, I think that solves the problem. The only question then is whether it's preferable to use cgroups or suspend fully, which is pretty much up to the implementation. In other words, is there a reason we're still having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

The issue with cgroup freezer as currently defined is that it can freeze processes that hold user-level resources (pthread mutexes, SysV semas, ...). If some non-frozen process attempts to acquire that resource, you get a hang. There might be some ways to work around this, for example, Arjan suggests momentarily unfreezing periodically, and I suggested doing the freeze in user-space code, but we don't know if either of these will really do what is required.

Also, I believe that Android's use of cgroups would be in addition to suspending fully rather than instead of. Freezing a subset of the applications allows cutting power drain from output-only apps when the screen blanks but where some app such as a download needs to keep the system active. They still would need to suspend once the download completes.

But we do need to hear from the Android guys on these points.

Thanx, Paul

#214 lore raw
In reply to Matthew Garrett
Quoted 18 lines · Matthew Garrett
Quoted 17 lines · Rafael J. Wysocki
Quoted 15 lines · Matthew Garrett

No! And that's precisely the issue. Android's existing behaviour could be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

Quoted 8 lines
Quoted 2 lines

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to avoid the race (if pm_wakeup_event() is called at 2)).

Yes, I think that solves the problem. The only question then is whether it's preferable to use cgroups or suspend fully, which is pretty much up to the implementation. In other words, is there a reason we're still having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

The issue with cgroup freezer as currently defined is that it can freeze processes that hold user-level resources (pthread mutexes, SysV semas, ...). If some non-frozen process attempts to acquire that resource, you get a hang. There might be some ways to work around this, for example, Arjan suggests momentarily unfreezing periodically, and I suggested doing the freeze in user-space code, but we don't know if either of these will really do what is required.

Also, I believe that Android's use of cgroups would be in addition to suspending fully rather than instead of. Freezing a subset of the applications allows cutting power drain from output-only apps when the screen blanks but where some app such as a download needs to keep the system active. They still would need to suspend once the download completes.

But we do need to hear from the Android guys on these points.

Thanx, Paul

#215 lore raw
Quoted 36 lines · Paul E. McKenney
Quoted 18 lines · Matthew Garrett
Quoted 17 lines · Rafael J. Wysocki
Quoted 15 lines · Matthew Garrett

No! And that's precisely the issue. Android's existing behaviour could be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

Quoted 8 lines
Quoted 2 lines

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to avoid the race (if pm_wakeup_event() is called at 2)).

Yes, I think that solves the problem. The only question then is whether it's preferable to use cgroups or suspend fully, which is pretty much up to the implementation. In other words, is there a reason we're still having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

The issue with cgroup freezer as currently defined is that it can freeze processes that hold user-level resources (pthread mutexes, SysV semas, ...). If some non-frozen process attempts to acquire that resource, you get a hang. There might be some ways to work around this, for example, Arjan suggests momentarily unfreezing periodically, and I suggested doing the freeze in user-space code, but we don't know if either of these will really do what is required.

Quoted 6 lines

Also, I believe that Android's use of cgroups would be in addition to suspending fully rather than instead of. Freezing a subset of the applications allows cutting power drain from output-only apps when the screen blanks but where some app such as a download needs to keep the system active. They still would need to suspend once the download completes.

One can argue that once the download has been completed, the cpuidle framework should make the system reduce its energy consumption to the level achievable by using suspend.

However, the problem is the cpuidle framework only deals with CPUs right now (at least generally) and there's a problem of the interrupt sources that allow the monotonic clock to advance and are deactivated during suspend (which allows more energy to be saved, because periodic timers are then effectively disabled).

So, it seems, system suspend is necessary to maximize energy savings as long as the cpuidle framework cannot take care of I/O devices and interrupt sources in general.

Thanks,
Rafael

#216 lore raw
In reply to Paul E. McKenney
Quoted 36 lines · Paul E. McKenney
Quoted 18 lines · Matthew Garrett
Quoted 17 lines · Rafael J. Wysocki
Quoted 15 lines · Matthew Garrett

No! And that's precisely the issue. Android's existing behaviour could be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

Quoted 8 lines
Quoted 2 lines

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to avoid the race (if pm_wakeup_event() is called at 2)).

Yes, I think that solves the problem. The only question then is whether it's preferable to use cgroups or suspend fully, which is pretty much up to the implementation. In other words, is there a reason we're still having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

The issue with cgroup freezer as currently defined is that it can freeze processes that hold user-level resources (pthread mutexes, SysV semas, ...). If some non-frozen process attempts to acquire that resource, you get a hang. There might be some ways to work around this, for example, Arjan suggests momentarily unfreezing periodically, and I suggested doing the freeze in user-space code, but we don't know if either of these will really do what is required.

Quoted 6 lines

Also, I believe that Android's use of cgroups would be in addition to suspending fully rather than instead of. Freezing a subset of the applications allows cutting power drain from output-only apps when the screen blanks but where some app such as a download needs to keep the system active. They still would need to suspend once the download completes.

One can argue that once the download has been completed, the cpuidle framework should make the system reduce its energy consumption to the level achievable by using suspend.

However, the problem is the cpuidle framework only deals with CPUs right now (at least generally) and there's a problem of the interrupt sources that allow the monotonic clock to advance and are deactivated during suspend (which allows more energy to be saved, because periodic timers are then effectively disabled).

So, it seems, system suspend is necessary to maximize energy savings as long as the cpuidle framework cannot take care of I/O devices and interrupt sources in general.

Thanks,
Rafael

#217 lore raw
In reply to Matthew Garrett
Quoted 14 lines · Matthew Garrett
Quoted 13 lines · Rafael J. Wysocki
Quoted 12 lines · Matthew Garrett

No! And that's precisely the issue. Android's existing behaviour could be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to avoid the race (if pm_wakeup_event() is called at 2)).

Yes, I think that solves the problem. The only question then is whether

How? By passing a timeout to pm_wakeup_event when the network driver gets the packet or by passing 0. If you pass a timeout it is the same as using a wakelock with a timeout and should work (assuming the timeout you picked is long enough). If you don't pass a timeout it does not work, since the packet may not be visible to user-space yet.

Quoted 2 lines

it's preferable to use cgroups or suspend fully, which is pretty much up to the implementation. In other words, is there a reason we're still

I have seen no proposed way to use cgroups that will work. If you leave some processes running while other processes are frozen you run into problems when a frozen process holds a resource that a running process needs.

Quoted 3 lines

having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

That is "this"? The merged code? If so, no it does not satisfy our requirements. The in kernel api, while offering similar functionality to the wakelock interface, does not use any handles which makes it impossible to get reasonable stats (You don't know which pm_stay_awake request pm_relax is reverting). The proposed in user-space interface of calling into every process that receives wakeup events before every suspend call is also not compatible with existing apps.

Signature · 1 line
Arve Hjønnevåg
#218 lore raw
In reply to Matthew Garrett
Quoted 14 lines · Matthew Garrett
Quoted 13 lines · Rafael J. Wysocki
Quoted 12 lines · Matthew Garrett

No! And that's precisely the issue. Android's existing behaviour could be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to avoid the race (if pm_wakeup_event() is called at 2)).

Yes, I think that solves the problem. The only question then is whether

How? By passing a timeout to pm_wakeup_event when the network driver gets the packet or by passing 0. If you pass a timeout it is the same as using a wakelock with a timeout and should work (assuming the timeout you picked is long enough). If you don't pass a timeout it does not work, since the packet may not be visible to user-space yet.

Quoted 2 lines

it's preferable to use cgroups or suspend fully, which is pretty much up to the implementation. In other words, is there a reason we're still

I have seen no proposed way to use cgroups that will work. If you leave some processes running while other processes are frozen you run into problems when a frozen process holds a resource that a running process needs.

Quoted 3 lines

having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

That is "this"? The merged code? If so, no it does not satisfy our requirements. The in kernel api, while offering similar functionality to the wakelock interface, does not use any handles which makes it impossible to get reasonable stats (You don't know which pm_stay_awake request pm_relax is reverting). The proposed in user-space interface of calling into every process that receives wakeup events before every suspend call is also not compatible with existing apps.

Signature · 1 line
Arve Hjønnevåg
#219 lore raw
Quoted 22 lines · Arve Hjønnevåg
Quoted 21 lines · Matthew Garrett
Quoted 19 lines · Rafael J. Wysocki
Quoted 12 lines · Matthew Garrett

No! And that's precisely the issue. Android's existing behaviour could be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

Quoted 3 lines

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to avoid the race (if pm_wakeup_event() is called at 2)).

Quoted 7 lines
Quoted 1 line

Yes, I think that solves the problem. The only question then is whether

How? By passing a timeout to pm_wakeup_event when the network driver gets the packet or by passing 0. If you pass a timeout it is the same as using a wakelock with a timeout and should work (assuming the timeout you picked is long enough). If you don't pass a timeout it does not work, since the packet may not be visible to user-space yet.

Alternatively, pm_stay_awake() / pm_relax() can be used.

Quoted 13 lines
Quoted 2 lines

it's preferable to use cgroups or suspend fully, which is pretty much up to the implementation. In other words, is there a reason we're still

I have seen no proposed way to use cgroups that will work. If you leave some processes running while other processes are frozen you run into problems when a frozen process holds a resource that a running process needs.

Quoted 3 lines

having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

Quoted 5 lines

That is "this"? The merged code? If so, no it does not satisfy our requirements. The in kernel api, while offering similar functionality to the wakelock interface, does not use any handles which makes it impossible to get reasonable stats (You don't know which pm_stay_awake request pm_relax is reverting).

Why is that a problem (out of curiosity)?

Quoted 3 lines

The proposed in user-space interface
of calling into every process that receives wakeup events before every suspend call

Well, you don't really need to do that.

Quoted 1 line

is also not compatible with existing apps.

Thanks,
Rafael

#220 lore raw
In reply to Arve Hjønnevåg
Quoted 22 lines · Arve Hjønnevåg
Quoted 21 lines · Matthew Garrett
Quoted 19 lines · Rafael J. Wysocki
Quoted 12 lines · Matthew Garrett

No! And that's precisely the issue. Android's existing behaviour could be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

Quoted 3 lines

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to avoid the race (if pm_wakeup_event() is called at 2)).

Quoted 7 lines
Quoted 1 line

Yes, I think that solves the problem. The only question then is whether

How? By passing a timeout to pm_wakeup_event when the network driver gets the packet or by passing 0. If you pass a timeout it is the same as using a wakelock with a timeout and should work (assuming the timeout you picked is long enough). If you don't pass a timeout it does not work, since the packet may not be visible to user-space yet.

Alternatively, pm_stay_awake() / pm_relax() can be used.

Quoted 13 lines
Quoted 2 lines

it's preferable to use cgroups or suspend fully, which is pretty much up to the implementation. In other words, is there a reason we're still

I have seen no proposed way to use cgroups that will work. If you leave some processes running while other processes are frozen you run into problems when a frozen process holds a resource that a running process needs.

Quoted 3 lines

having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

Quoted 5 lines

That is "this"? The merged code? If so, no it does not satisfy our requirements. The in kernel api, while offering similar functionality to the wakelock interface, does not use any handles which makes it impossible to get reasonable stats (You don't know which pm_stay_awake request pm_relax is reverting).

Why is that a problem (out of curiosity)?

Quoted 3 lines

The proposed in user-space interface
of calling into every process that receives wakeup events before every suspend call

Well, you don't really need to do that.

Quoted 1 line

is also not compatible with existing apps.

Thanks,
Rafael

#221 lore raw

2010/8/4 Rafael J. Wysocki <[email protected]>:

Quoted 25 lines · Arve Hjønnevåg
Quoted 24 lines · Matthew Garrett
Quoted 22 lines · Rafael J. Wysocki
Quoted 13 lines · Matthew Garrett
Quoted 12 lines

No! And that's precisely the issue. Android's existing behaviour could be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

Quoted 6 lines
Quoted 3 lines

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to avoid the race (if pm_wakeup_event() is called at 2)).

Yes, I think that solves the problem. The only question then is whether

Quoted 8 lines
Quoted 5 lines

How? By passing a timeout to pm_wakeup_event when the network driver gets the packet or by passing 0. If you pass a timeout it is the same as using a wakelock with a timeout and should work (assuming the timeout you picked is long enough). If you don't pass a timeout it does not work, since the packet may not be visible to user-space yet.

Alternatively, pm_stay_awake() / pm_relax() can be used.

Which makes the driver and/or network stack changes identical to using wakelocks, right?

Quoted 13 lines
Quoted 13 lines
Quoted 2 lines

it's preferable to use cgroups or suspend fully, which is pretty much up to the implementation. In other words, is there a reason we're still

I have seen no proposed way to use cgroups that will work. If you leave some processes running while other processes are frozen you run into problems when a frozen process holds a resource that a running process needs.

Quoted 3 lines

having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

Quoted 8 lines
Quoted 5 lines

That is "this"? The merged code? If so, no it does not satisfy our requirements. The in kernel api, while offering similar functionality to the wakelock interface, does not use any handles which makes it impossible to get reasonable stats (You don't know which pm_stay_awake request pm_relax is reverting).

Why is that a problem (out of curiosity)?

Not having stats or not knowing what pm_relax is undoing? We need stats to be able to debug the system. If the system does not suspend at all or is awake for too long, the wakelock stats tells us which component is at fault. Since pm_stay_awake and pm_relax does not operate on a handle, you cannot determine how long it prevented suspend for.

Quoted 6 lines
Quoted 3 lines

The proposed in user-space interface
of calling into every process that receives wakeup events before every suspend call

Well,  you don't really need to do that.

Only if the driver blocks suspend until user-space has read the event. This means that for android to work we need to block suspend when input events are not processed, but a system using your scheme needs a pm_wakeup_event call when the input event is queued. How to you switch between them? Do we add separate ioctls in the input device to enable each scheme? If someone has a single threaded user space power manager that also reads input event it will deadlock if you block suspend until it reads the input events since you block when reading the wake count.

Quoted 10 lines
Quoted 1 line

is also not compatible with existing apps.

Thanks,
Rafael
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Signature · 1 line
Arve Hjønnevåg
#222 lore raw
In reply to Rafael J. Wysocki

2010/8/4 Rafael J. Wysocki <[email protected]>:

Quoted 25 lines · Arve Hjønnevåg
Quoted 24 lines · Matthew Garrett
Quoted 22 lines · Rafael J. Wysocki
Quoted 13 lines · Matthew Garrett
Quoted 12 lines

No! And that's precisely the issue. Android's existing behaviour could be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

Quoted 6 lines
Quoted 3 lines

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to avoid the race (if pm_wakeup_event() is called at 2)).

Yes, I think that solves the problem. The only question then is whether

Quoted 8 lines
Quoted 5 lines

How? By passing a timeout to pm_wakeup_event when the network driver gets the packet or by passing 0. If you pass a timeout it is the same as using a wakelock with a timeout and should work (assuming the timeout you picked is long enough). If you don't pass a timeout it does not work, since the packet may not be visible to user-space yet.

Alternatively, pm_stay_awake() / pm_relax() can be used.

Which makes the driver and/or network stack changes identical to using wakelocks, right?

Quoted 13 lines
Quoted 13 lines
Quoted 2 lines

it's preferable to use cgroups or suspend fully, which is pretty much up to the implementation. In other words, is there a reason we're still

I have seen no proposed way to use cgroups that will work. If you leave some processes running while other processes are frozen you run into problems when a frozen process holds a resource that a running process needs.

Quoted 3 lines

having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

Quoted 8 lines
Quoted 5 lines

That is "this"? The merged code? If so, no it does not satisfy our requirements. The in kernel api, while offering similar functionality to the wakelock interface, does not use any handles which makes it impossible to get reasonable stats (You don't know which pm_stay_awake request pm_relax is reverting).

Why is that a problem (out of curiosity)?

Not having stats or not knowing what pm_relax is undoing? We need stats to be able to debug the system. If the system does not suspend at all or is awake for too long, the wakelock stats tells us which component is at fault. Since pm_stay_awake and pm_relax does not operate on a handle, you cannot determine how long it prevented suspend for.

Quoted 6 lines
Quoted 3 lines

The proposed in user-space interface
of calling into every process that receives wakeup events before every suspend call

Well,  you don't really need to do that.

Only if the driver blocks suspend until user-space has read the event. This means that for android to work we need to block suspend when input events are not processed, but a system using your scheme needs a pm_wakeup_event call when the input event is queued. How to you switch between them? Do we add separate ioctls in the input device to enable each scheme? If someone has a single threaded user space power manager that also reads input event it will deadlock if you block suspend until it reads the input events since you block when reading the wake count.

Quoted 10 lines
Quoted 1 line

is also not compatible with existing apps.

Thanks,
Rafael
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Signature · 1 line
Arve Hjønnevåg
#223 lore raw
Quoted 32 lines · Arve Hjønnevåg

2010/8/4 Rafael J. Wysocki <[email protected]>:

Quoted 31 lines · Arve Hjønnevåg
Quoted 29 lines · Matthew Garrett
Quoted 14 lines · Rafael J. Wysocki
Quoted 13 lines · Matthew Garrett
Quoted 12 lines

No! And that's precisely the issue. Android's existing behaviour could be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to avoid the race (if pm_wakeup_event() is called at 2)).

Yes, I think that solves the problem. The only question then is whether

How? By passing a timeout to pm_wakeup_event when the network driver gets the packet or by passing 0. If you pass a timeout it is the same as using a wakelock with a timeout and should work (assuming the timeout you picked is long enough). If you don't pass a timeout it does not work, since the packet may not be visible to user-space yet.

Quoted 4 lines
Quoted 1 line

Alternatively, pm_stay_awake() / pm_relax() can be used.

Which makes the driver and/or network stack changes identical to using wakelocks, right?

Arve, you say that like it is a bad thing. ;-)

Seriously, the hope is that Rafael's implementation is useful to other projects in addition to Android. And, all else being equal, the more people who need a given facility, the more likely that facility is to make it to mainline, right?

And yes, I see you call out some additional things that Android needs, but hopefully this gap can be closed one way or another.

Thanx, Paul

Quoted 61 lines
Quoted 13 lines
Quoted 13 lines
Quoted 2 lines

it's preferable to use cgroups or suspend fully, which is pretty much up to the implementation. In other words, is there a reason we're still

I have seen no proposed way to use cgroups that will work. If you leave some processes running while other processes are frozen you run into problems when a frozen process holds a resource that a running process needs.

Quoted 3 lines

having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

Quoted 8 lines
Quoted 5 lines

That is "this"? The merged code? If so, no it does not satisfy our requirements. The in kernel api, while offering similar functionality to the wakelock interface, does not use any handles which makes it impossible to get reasonable stats (You don't know which pm_stay_awake request pm_relax is reverting).

Why is that a problem (out of curiosity)?

Not having stats or not knowing what pm_relax is undoing? We need stats to be able to debug the system. If the system does not suspend at all or is awake for too long, the wakelock stats tells us which component is at fault. Since pm_stay_awake and pm_relax does not operate on a handle, you cannot determine how long it prevented suspend for.

Quoted 6 lines
Quoted 3 lines

The proposed in user-space interface
of calling into every process that receives wakeup events before every suspend call

Well,  you don't really need to do that.

Only if the driver blocks suspend until user-space has read the event. This means that for android to work we need to block suspend when input events are not processed, but a system using your scheme needs a pm_wakeup_event call when the input event is queued. How to you switch between them? Do we add separate ioctls in the input device to enable each scheme? If someone has a single threaded user space power manager that also reads input event it will deadlock if you block suspend until it reads the input events since you block when reading the wake count.

Quoted 10 lines
Quoted 1 line

is also not compatible with existing apps.

Thanks,
Rafael
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Signature · 1 line
Arve Hjønnevåg
#224 lore raw
In reply to Arve Hjønnevåg
Quoted 32 lines · Arve Hjønnevåg

2010/8/4 Rafael J. Wysocki <[email protected]>:

Quoted 31 lines · Arve Hjønnevåg
Quoted 29 lines · Matthew Garrett
Quoted 14 lines · Rafael J. Wysocki
Quoted 13 lines · Matthew Garrett
Quoted 12 lines

No! And that's precisely the issue. Android's existing behaviour could be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to avoid the race (if pm_wakeup_event() is called at 2)).

Yes, I think that solves the problem. The only question then is whether

How? By passing a timeout to pm_wakeup_event when the network driver gets the packet or by passing 0. If you pass a timeout it is the same as using a wakelock with a timeout and should work (assuming the timeout you picked is long enough). If you don't pass a timeout it does not work, since the packet may not be visible to user-space yet.

Quoted 4 lines
Quoted 1 line

Alternatively, pm_stay_awake() / pm_relax() can be used.

Which makes the driver and/or network stack changes identical to using wakelocks, right?

Arve, you say that like it is a bad thing. ;-)

Seriously, the hope is that Rafael's implementation is useful to other projects in addition to Android. And, all else being equal, the more people who need a given facility, the more likely that facility is to make it to mainline, right?

And yes, I see you call out some additional things that Android needs, but hopefully this gap can be closed one way or another.

Thanx, Paul

Quoted 61 lines
Quoted 13 lines
Quoted 13 lines
Quoted 2 lines

it's preferable to use cgroups or suspend fully, which is pretty much up to the implementation. In other words, is there a reason we're still

I have seen no proposed way to use cgroups that will work. If you leave some processes running while other processes are frozen you run into problems when a frozen process holds a resource that a running process needs.

Quoted 3 lines

having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

Quoted 8 lines
Quoted 5 lines

That is "this"? The merged code? If so, no it does not satisfy our requirements. The in kernel api, while offering similar functionality to the wakelock interface, does not use any handles which makes it impossible to get reasonable stats (You don't know which pm_stay_awake request pm_relax is reverting).

Why is that a problem (out of curiosity)?

Not having stats or not knowing what pm_relax is undoing? We need stats to be able to debug the system. If the system does not suspend at all or is awake for too long, the wakelock stats tells us which component is at fault. Since pm_stay_awake and pm_relax does not operate on a handle, you cannot determine how long it prevented suspend for.

Quoted 6 lines
Quoted 3 lines

The proposed in user-space interface
of calling into every process that receives wakeup events before every suspend call

Well,  you don't really need to do that.

Only if the driver blocks suspend until user-space has read the event. This means that for android to work we need to block suspend when input events are not processed, but a system using your scheme needs a pm_wakeup_event call when the input event is queued. How to you switch between them? Do we add separate ioctls in the input device to enable each scheme? If someone has a single threaded user space power manager that also reads input event it will deadlock if you block suspend until it reads the input events since you block when reading the wake count.

Quoted 10 lines
Quoted 1 line

is also not compatible with existing apps.

Thanks,
Rafael
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Signature · 1 line
Arve Hjønnevåg
#225 lore raw
In reply to Arve Hjønnevåg
Quoted 2 lines · Arve Hjønnevåg

Which makes the driver and/or network stack changes identical to using wakelocks, right?

I think we're resigned to the fact that we need to indicate wakeup events in a manner that's pretty equivalent to wakelocks. The only real issue is what the API looks like. Anyone who's still talking about cgroups seems to be trying to solve a different problem.

Signature · 1 line
Matthew Garrett | [email protected]
#226 lore raw
In reply to Arve Hjønnevåg
Quoted 2 lines · Arve Hjønnevåg

Which makes the driver and/or network stack changes identical to using wakelocks, right?

I think we're resigned to the fact that we need to indicate wakeup events in a manner that's pretty equivalent to wakelocks. The only real issue is what the API looks like. Anyone who's still talking about cgroups seems to be trying to solve a different problem.

Signature · 1 line
Matthew Garrett | [email protected]
#227 lore raw
In reply to Arve Hjønnevåg
Quoted 2 lines · Arve Hjønnevåg

Which makes the driver and/or network stack changes identical to using wakelocks, right?

I think we're resigned to the fact that we need to indicate wakeup events in a manner that's pretty equivalent to wakelocks. The only real issue is what the API looks like. Anyone who's still talking about cgroups seems to be trying to solve a different problem.

Signature · 1 line
Matthew Garrett | [email protected]
#228 lore raw
Quoted 9 lines · Matthew Garrett
Quoted 2 lines · Arve Hj?nnev?g

Which makes the driver and/or network stack changes identical to using wakelocks, right?

I think we're resigned to the fact that we need to indicate wakeup events in a manner that's pretty equivalent to wakelocks. The only real issue is what the API looks like. Anyone who's still talking about cgroups seems to be trying to solve a different problem.

Ok, it is now sounding to me like there are two different (but somewhat related) purposes that wakelocks are being used for

1. deciding if the system should go to sleep now or not (what most of the discussion has been about)

2. narrowing the race between going to sleep and wakeup events.

I'm not sure it's possible to completely eliminate the race, even with wakelocks there is some time between the time you last check if the wakelock is set and when the hardware finishes responding to your commands to go to sleep (Unless you can set a level-based interrupt that will wake you up as soon as you finish going to sleep)

David Lang

#229 lore raw
In reply to Matthew Garrett
Quoted 9 lines · Matthew Garrett
Quoted 2 lines · Arve Hj?nnev?g

Which makes the driver and/or network stack changes identical to using wakelocks, right?

I think we're resigned to the fact that we need to indicate wakeup events in a manner that's pretty equivalent to wakelocks. The only real issue is what the API looks like. Anyone who's still talking about cgroups seems to be trying to solve a different problem.

Ok, it is now sounding to me like there are two different (but somewhat related) purposes that wakelocks are being used for

1. deciding if the system should go to sleep now or not (what most of the discussion has been about)

2. narrowing the race between going to sleep and wakeup events.

I'm not sure it's possible to completely eliminate the race, even with wakelocks there is some time between the time you last check if the wakelock is set and when the hardware finishes responding to your commands to go to sleep (Unless you can set a level-based interrupt that will wake you up as soon as you finish going to sleep)

David Lang

#230 lore raw
Quoted 7 lines · On Thu, Aug 5, 2010 at 7:22 AM, <[email protected]> wrote:

Ok, it is now sounding to me like there are two different (but somewhat related) purposes that wakelocks are being used for

1. deciding if the system should go to sleep now or not (what most of the discussion has been about)

Quoted 7 lines

2. narrowing the race between going to sleep and wakeup events.

I'm not sure it's possible to completely eliminate the race, even with wakelocks there is some time between the time you last check if the wakelock is set and when the hardware finishes responding to your commands to go to sleep (Unless you can set a level-based interrupt that will wake you up as soon as you finish going to sleep)

The transition into sleep is race-free in the wakelock model -- either the wakeup event happens during the kernel suspend (and grabs a wakelock), in which case suspend is aborted (and not attempted again until there are once again no more wakelocks held), or the system fully suspends to its lowest power mode until a wakeup event brings it back out again. Entry to lowest power mode must abort if a wakeup event/interrupt occurs while it's in process -- exactly how the handoff happens here is hardware dependent but in practice this is doable on just about any modern system.

Brian

#231 lore raw
In reply to [email protected]
Quoted 7 lines · On Thu, Aug 5, 2010 at 7:22 AM, <[email protected]> wrote:

Ok, it is now sounding to me like there are two different (but somewhat related) purposes that wakelocks are being used for

1. deciding if the system should go to sleep now or not (what most of the discussion has been about)

Quoted 7 lines

2. narrowing the race between going to sleep and wakeup events.

I'm not sure it's possible to completely eliminate the race, even with wakelocks there is some time between the time you last check if the wakelock is set and when the hardware finishes responding to your commands to go to sleep (Unless you can set a level-based interrupt that will wake you up as soon as you finish going to sleep)

The transition into sleep is race-free in the wakelock model -- either the wakeup event happens during the kernel suspend (and grabs a wakelock), in which case suspend is aborted (and not attempted again until there are once again no more wakelocks held), or the system fully suspends to its lowest power mode until a wakeup event brings it back out again. Entry to lowest power mode must abort if a wakeup event/interrupt occurs while it's in process -- exactly how the handoff happens here is hardware dependent but in practice this is doable on just about any modern system.

Brian

#232 lore raw
In reply to [email protected]
Quoted 5 lines · On Thu, Aug 05, 2010 at 07:22:53AM -0700, [email protected] wrote:

I'm not sure it's possible to completely eliminate the race, even with wakelocks there is some time between the time you last check if the wakelock is set and when the hardware finishes responding to your commands to go to sleep (Unless you can set a level-based interrupt that will wake you up as soon as you finish going to sleep)

It's typically the case that you can - we've even seen that on x86 with ACPI GPEs.

Signature · 1 line
Matthew Garrett | [email protected]
#233 lore raw
In reply to [email protected]
Quoted 5 lines · On Thu, Aug 05, 2010 at 07:22:53AM -0700, [email protected] wrote:

I'm not sure it's possible to completely eliminate the race, even with wakelocks there is some time between the time you last check if the wakelock is set and when the hardware finishes responding to your commands to go to sleep (Unless you can set a level-based interrupt that will wake you up as soon as you finish going to sleep)

It's typically the case that you can - we've even seen that on x86 with ACPI GPEs.

Signature · 1 line
Matthew Garrett | [email protected]
#234 lore raw
In reply to Arve Hjønnevåg
Quoted 32 lines · Arve Hjønnevåg

2010/8/4 Rafael J. Wysocki <[email protected]>:

Quoted 31 lines · Arve Hjønnevåg
Quoted 29 lines · Matthew Garrett
Quoted 14 lines · Rafael J. Wysocki
Quoted 13 lines · Matthew Garrett
Quoted 12 lines

No! And that's precisely the issue. Android's existing behaviour could be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to avoid the race (if pm_wakeup_event() is called at 2)).

Yes, I think that solves the problem. The only question then is whether

How? By passing a timeout to pm_wakeup_event when the network driver gets the packet or by passing 0. If you pass a timeout it is the same as using a wakelock with a timeout and should work (assuming the timeout you picked is long enough). If you don't pass a timeout it does not work, since the packet may not be visible to user-space yet.

Quoted 5 lines
Quoted 2 lines

Alternatively, pm_stay_awake() / pm_relax() can be used.

Which makes the driver and/or network stack changes identical to using wakelocks, right?

Please refer to the Matthew's response.

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 2 lines

it's preferable to use cgroups or suspend fully, which is pretty much up to the implementation. In other words, is there a reason we're still

I have seen no proposed way to use cgroups that will work. If you leave some processes running while other processes are frozen you run into problems when a frozen process holds a resource that a running process needs.

Quoted 3 lines

having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

That is "this"? The merged code? If so, no it does not satisfy our requirements. The in kernel api, while offering similar functionality to the wakelock interface, does not use any handles which makes it impossible to get reasonable stats (You don't know which pm_stay_awake request pm_relax is reverting).

Quoted 5 lines
Quoted 2 lines

Why is that a problem (out of curiosity)?

Not having stats or not knowing what pm_relax is undoing? We need stats to be able to debug the system.

You have the stats in struct device and they are available via sysfs. I suppose they are insufficient, but I'd like to know why exactly.

Quoted 5 lines

If the system does not suspend
at all or is awake for too long, the wakelock stats tells us which component is at fault. Since pm_stay_awake and pm_relax does not operate on a handle, you cannot determine how long it prevented suspend for.

Well, if you need that, you can add a counter of "completed events" into struct dev_pm_info and a function similar to pm_relax() that will update that counter. I don't think anyone will object to that change.

Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

The proposed in user-space interface
of calling into every process that receives wakeup events before every suspend call

Well, you don't really need to do that.

Quoted 9 lines

Only if the driver blocks suspend until user-space has read the event. This means that for android to work we need to block suspend when input events are not processed, but a system using your scheme needs a pm_wakeup_event call when the input event is queued. How to you switch between them? Do we add separate ioctls in the input device to enable each scheme? If someone has a single threaded user space power manager that also reads input event it will deadlock if you block suspend until it reads the input events since you block when reading the wake count.

Well, until someone actually tries to implement a power manager in user space it's a bit vague.

Thanks,
Rafael

#235 lore raw
In reply to Arve Hjønnevåg
Quoted 32 lines · Arve Hjønnevåg

2010/8/4 Rafael J. Wysocki <[email protected]>:

Quoted 31 lines · Arve Hjønnevåg
Quoted 29 lines · Matthew Garrett
Quoted 14 lines · Rafael J. Wysocki
Quoted 13 lines · Matthew Garrett
Quoted 12 lines

No! And that's precisely the issue. Android's existing behaviour could be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to avoid the race (if pm_wakeup_event() is called at 2)).

Yes, I think that solves the problem. The only question then is whether

How? By passing a timeout to pm_wakeup_event when the network driver gets the packet or by passing 0. If you pass a timeout it is the same as using a wakelock with a timeout and should work (assuming the timeout you picked is long enough). If you don't pass a timeout it does not work, since the packet may not be visible to user-space yet.

Quoted 5 lines
Quoted 2 lines

Alternatively, pm_stay_awake() / pm_relax() can be used.

Which makes the driver and/or network stack changes identical to using wakelocks, right?

Please refer to the Matthew's response.

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 2 lines

it's preferable to use cgroups or suspend fully, which is pretty much up to the implementation. In other words, is there a reason we're still

I have seen no proposed way to use cgroups that will work. If you leave some processes running while other processes are frozen you run into problems when a frozen process holds a resource that a running process needs.

Quoted 3 lines

having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

That is "this"? The merged code? If so, no it does not satisfy our requirements. The in kernel api, while offering similar functionality to the wakelock interface, does not use any handles which makes it impossible to get reasonable stats (You don't know which pm_stay_awake request pm_relax is reverting).

Quoted 5 lines
Quoted 2 lines

Why is that a problem (out of curiosity)?

Not having stats or not knowing what pm_relax is undoing? We need stats to be able to debug the system.

You have the stats in struct device and they are available via sysfs. I suppose they are insufficient, but I'd like to know why exactly.

Quoted 5 lines

If the system does not suspend
at all or is awake for too long, the wakelock stats tells us which component is at fault. Since pm_stay_awake and pm_relax does not operate on a handle, you cannot determine how long it prevented suspend for.

Well, if you need that, you can add a counter of "completed events" into struct dev_pm_info and a function similar to pm_relax() that will update that counter. I don't think anyone will object to that change.

Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

The proposed in user-space interface
of calling into every process that receives wakeup events before every suspend call

Well, you don't really need to do that.

Quoted 9 lines

Only if the driver blocks suspend until user-space has read the event. This means that for android to work we need to block suspend when input events are not processed, but a system using your scheme needs a pm_wakeup_event call when the input event is queued. How to you switch between them? Do we add separate ioctls in the input device to enable each scheme? If someone has a single threaded user space power manager that also reads input event it will deadlock if you block suspend until it reads the input events since you block when reading the wake count.

Well, until someone actually tries to implement a power manager in user space it's a bit vague.

Thanks,
Rafael

#236 lore raw

2010/8/5 Rafael J. Wysocki <[email protected]>:

Quoted 60 lines · Arve Hjønnevåg
Quoted 32 lines

2010/8/4 Rafael J. Wysocki <[email protected]>:

Quoted 31 lines · Arve Hjønnevåg
Quoted 29 lines · Matthew Garrett
Quoted 14 lines · Rafael J. Wysocki
Quoted 13 lines · Matthew Garrett
Quoted 12 lines

No! And that's precisely the issue. Android's existing behaviour could be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to avoid the race (if pm_wakeup_event() is called at 2)).

Yes, I think that solves the problem. The only question then is whether

How? By passing a timeout to pm_wakeup_event when the network driver gets the packet or by passing 0. If you pass a timeout it is the same as using a wakelock with a timeout and should work (assuming the timeout you picked is long enough). If you don't pass a timeout it does not work, since the packet may not be visible to user-space yet.

Quoted 5 lines
Quoted 2 lines

Alternatively, pm_stay_awake() / pm_relax() can be used.

Which makes the driver and/or network stack changes identical to using wakelocks, right?

Please refer to the Matthew's response.

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 2 lines

it's preferable to use cgroups or suspend fully, which is pretty much up to the implementation. In other words, is there a reason we're still

I have seen no proposed way to use cgroups that will work. If you leave some processes running while other processes are frozen you run into problems when a frozen process holds a resource that a running process needs.

Quoted 3 lines

having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

That is "this"? The merged code? If so, no it does not satisfy our requirements. The in kernel api, while offering similar functionality to the wakelock interface, does not use any handles which makes it impossible to get reasonable stats (You don't know which pm_stay_awake request pm_relax is reverting).

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

Why is that a problem (out of curiosity)?

Not having stats or not knowing what pm_relax is undoing? We need stats to be able to debug the system.

You have the stats in struct device and they are available via sysfs. I suppose they are insufficient, but I'd like to know why exactly.

Our wakelock stats currently have (name,)count,expire_count,wake_count,active_since,total_time,sleep_time,max_time and last_change. Not all of these are equally important (total_time is most important followed by active_since), but you only have count. Also as discussed before, many wakelocks/suspendblockers are not associated with a struct device.

Quoted 7 lines
Quoted 5 lines

If the system does not suspend
at all or is awake for too long, the wakelock stats tells us which component is at fault. Since pm_stay_awake and pm_relax does not operate on a handle, you cannot determine how long it prevented suspend for.

Well, if you need that, you can add a counter of "completed events" into

We need more than that (see above).

Quoted 3 lines

struct dev_pm_info and a function similar to pm_relax() that will update that counter.  I don't think anyone will object to that change.

What about adding a handle that is passed to all three functions?

Quoted 17 lines
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

The proposed in user-space interface
of calling into every process that receives wakeup events before every suspend call

Well,  you don't really need to do that.

Quoted 9 lines

Only if the driver blocks suspend until user-space has read the event. This means that for android to work we need to block suspend when input events are not processed, but a system using your scheme needs a pm_wakeup_event call when the input event is queued. How to you switch between them? Do we add separate ioctls in the input device to enable each scheme? If someone has a single threaded user space power manager that also reads input event it will deadlock if you block suspend until it reads the input events since you block when reading the wake count.

Quoted 3 lines

Well, until someone actually tries to implement a power manager in user space it's a bit vague.

Not having clear rules for what the drivers should do is a problem. The comments in your code seem to advocate using timeouts instead of overlapping pm_stay_awake/pm_relax sections. I find this recommendation strange given all the opposition to wakelock/suspendblocker timeouts. But more importantly, calling pm_wakeup_event with a timeout of 0 is incompatible with the android user space code, and I would prefer that the kernel interfaces would encourage drivers to block suspend until user space has consumed the event, which works for the android user space, instead of just long enough to work with a hypothetical user space power manager.

Signature · 1 line
Arve Hjønnevåg
#237 lore raw
In reply to Rafael J. Wysocki

2010/8/5 Rafael J. Wysocki <[email protected]>:

Quoted 60 lines · Arve Hjønnevåg
Quoted 32 lines

2010/8/4 Rafael J. Wysocki <[email protected]>:

Quoted 31 lines · Arve Hjønnevåg
Quoted 29 lines · Matthew Garrett
Quoted 14 lines · Rafael J. Wysocki
Quoted 13 lines · Matthew Garrett
Quoted 12 lines

No! And that's precisely the issue. Android's existing behaviour could be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to avoid the race (if pm_wakeup_event() is called at 2)).

Yes, I think that solves the problem. The only question then is whether

How? By passing a timeout to pm_wakeup_event when the network driver gets the packet or by passing 0. If you pass a timeout it is the same as using a wakelock with a timeout and should work (assuming the timeout you picked is long enough). If you don't pass a timeout it does not work, since the packet may not be visible to user-space yet.

Quoted 5 lines
Quoted 2 lines

Alternatively, pm_stay_awake() / pm_relax() can be used.

Which makes the driver and/or network stack changes identical to using wakelocks, right?

Please refer to the Matthew's response.

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 2 lines

it's preferable to use cgroups or suspend fully, which is pretty much up to the implementation. In other words, is there a reason we're still

I have seen no proposed way to use cgroups that will work. If you leave some processes running while other processes are frozen you run into problems when a frozen process holds a resource that a running process needs.

Quoted 3 lines

having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

That is "this"? The merged code? If so, no it does not satisfy our requirements. The in kernel api, while offering similar functionality to the wakelock interface, does not use any handles which makes it impossible to get reasonable stats (You don't know which pm_stay_awake request pm_relax is reverting).

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

Why is that a problem (out of curiosity)?

Not having stats or not knowing what pm_relax is undoing? We need stats to be able to debug the system.

You have the stats in struct device and they are available via sysfs. I suppose they are insufficient, but I'd like to know why exactly.

Our wakelock stats currently have (name,)count,expire_count,wake_count,active_since,total_time,sleep_time,max_time and last_change. Not all of these are equally important (total_time is most important followed by active_since), but you only have count. Also as discussed before, many wakelocks/suspendblockers are not associated with a struct device.

Quoted 7 lines
Quoted 5 lines

If the system does not suspend
at all or is awake for too long, the wakelock stats tells us which component is at fault. Since pm_stay_awake and pm_relax does not operate on a handle, you cannot determine how long it prevented suspend for.

Well, if you need that, you can add a counter of "completed events" into

We need more than that (see above).

Quoted 3 lines

struct dev_pm_info and a function similar to pm_relax() that will update that counter.  I don't think anyone will object to that change.

What about adding a handle that is passed to all three functions?

Quoted 17 lines
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

The proposed in user-space interface
of calling into every process that receives wakeup events before every suspend call

Well,  you don't really need to do that.

Quoted 9 lines

Only if the driver blocks suspend until user-space has read the event. This means that for android to work we need to block suspend when input events are not processed, but a system using your scheme needs a pm_wakeup_event call when the input event is queued. How to you switch between them? Do we add separate ioctls in the input device to enable each scheme? If someone has a single threaded user space power manager that also reads input event it will deadlock if you block suspend until it reads the input events since you block when reading the wake count.

Quoted 3 lines

Well, until someone actually tries to implement a power manager in user space it's a bit vague.

Not having clear rules for what the drivers should do is a problem. The comments in your code seem to advocate using timeouts instead of overlapping pm_stay_awake/pm_relax sections. I find this recommendation strange given all the opposition to wakelock/suspendblocker timeouts. But more importantly, calling pm_wakeup_event with a timeout of 0 is incompatible with the android user space code, and I would prefer that the kernel interfaces would encourage drivers to block suspend until user space has consumed the event, which works for the android user space, instead of just long enough to work with a hypothetical user space power manager.

Signature · 1 line
Arve Hjønnevåg
#238 lore raw
Quoted 71 lines · Arve Hjønnevåg

2010/8/5 Rafael J. Wysocki <[email protected]>:

Quoted 60 lines · Arve Hjønnevåg
Quoted 32 lines

2010/8/4 Rafael J. Wysocki <[email protected]>:

Quoted 31 lines · Arve Hjønnevåg
Quoted 29 lines · Matthew Garrett
Quoted 14 lines · Rafael J. Wysocki
Quoted 13 lines · Matthew Garrett
Quoted 12 lines

No! And that's precisely the issue. Android's existing behaviour could be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to avoid the race (if pm_wakeup_event() is called at 2)).

Yes, I think that solves the problem. The only question then is whether

How? By passing a timeout to pm_wakeup_event when the network driver gets the packet or by passing 0. If you pass a timeout it is the same as using a wakelock with a timeout and should work (assuming the timeout you picked is long enough). If you don't pass a timeout it does not work, since the packet may not be visible to user-space yet.

Quoted 5 lines
Quoted 2 lines

Alternatively, pm_stay_awake() / pm_relax() can be used.

Which makes the driver and/or network stack changes identical to using wakelocks, right?

Please refer to the Matthew's response.

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 2 lines

it's preferable to use cgroups or suspend fully, which is pretty much up to the implementation. In other words, is there a reason we're still

I have seen no proposed way to use cgroups that will work. If you leave some processes running while other processes are frozen you run into problems when a frozen process holds a resource that a running process needs.

Quoted 3 lines

having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

That is "this"? The merged code? If so, no it does not satisfy our requirements. The in kernel api, while offering similar functionality to the wakelock interface, does not use any handles which makes it impossible to get reasonable stats (You don't know which pm_stay_awake request pm_relax is reverting).

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

Why is that a problem (out of curiosity)?

Not having stats or not knowing what pm_relax is undoing? We need stats to be able to debug the system.

You have the stats in struct device and they are available via sysfs. I suppose they are insufficient, but I'd like to know why exactly.

Quoted 6 lines

Our wakelock stats currently have (name,)count,expire_count,wake_count,active_since,total_time,sleep_time,max_time and last_change. Not all of these are equally important (total_time is most important followed by active_since), but you only have count. Also as discussed before, many wakelocks/suspendblockers are not associated with a struct device.

OK

How much of that is used in practice and what for exactly?

Do you _really_ have to debug the wakelocks in drivers that much?

Quoted 8 lines
Quoted 7 lines
Quoted 5 lines

If the system does not suspend
at all or is awake for too long, the wakelock stats tells us which component is at fault. Since pm_stay_awake and pm_relax does not operate on a handle, you cannot determine how long it prevented suspend for.

Well, if you need that, you can add a counter of "completed events" into

Quoted 7 lines

We need more than that (see above).

Quoted 3 lines

struct dev_pm_info and a function similar to pm_relax() that will update that counter. I don't think anyone will object to that change.

What about adding a handle that is passed to all three functions?

I don't think that will fly at this point.

Quoted 21 lines
Quoted 17 lines
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

The proposed in user-space interface
of calling into every process that receives wakeup events before every suspend call

Well, you don't really need to do that.

Quoted 9 lines

Only if the driver blocks suspend until user-space has read the event. This means that for android to work we need to block suspend when input events are not processed, but a system using your scheme needs a pm_wakeup_event call when the input event is queued. How to you switch between them? Do we add separate ioctls in the input device to enable each scheme? If someone has a single threaded user space power manager that also reads input event it will deadlock if you block suspend until it reads the input events since you block when reading the wake count.

Quoted 3 lines

Well, until someone actually tries to implement a power manager in user space it's a bit vague.

Quoted 5 lines

Not having clear rules for what the drivers should do is a problem. The comments in your code seem to advocate using timeouts instead of overlapping pm_stay_awake/pm_relax sections. I find this recommendation strange given all the opposition to wakelock/suspendblocker timeouts.

There's no recommendation either way.

Quoted 3 lines

But more importantly, calling
pm_wakeup_event with a timeout of 0 is incompatible with the android user space code,

Which I don't find really relevant, sorry.

Quoted 4 lines

and I would prefer that the kernel interfaces would encourage drivers to block suspend until user space has consumed the event, which works for the android user space, instead of just long enough to work with a hypothetical user space power manager.

Well, that are your personal preferences, which I respect. I also have some personal preferences that are not necessarily followed by the kernel code.

Thanks,
Rafael

#239 lore raw
In reply to Arve Hjønnevåg
Quoted 71 lines · Arve Hjønnevåg

2010/8/5 Rafael J. Wysocki <[email protected]>:

Quoted 60 lines · Arve Hjønnevåg
Quoted 32 lines

2010/8/4 Rafael J. Wysocki <[email protected]>:

Quoted 31 lines · Arve Hjønnevåg
Quoted 29 lines · Matthew Garrett
Quoted 14 lines · Rafael J. Wysocki
Quoted 13 lines · Matthew Garrett
Quoted 12 lines

No! And that's precisely the issue. Android's existing behaviour could be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to avoid the race (if pm_wakeup_event() is called at 2)).

Yes, I think that solves the problem. The only question then is whether

How? By passing a timeout to pm_wakeup_event when the network driver gets the packet or by passing 0. If you pass a timeout it is the same as using a wakelock with a timeout and should work (assuming the timeout you picked is long enough). If you don't pass a timeout it does not work, since the packet may not be visible to user-space yet.

Quoted 5 lines
Quoted 2 lines

Alternatively, pm_stay_awake() / pm_relax() can be used.

Which makes the driver and/or network stack changes identical to using wakelocks, right?

Please refer to the Matthew's response.

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 2 lines

it's preferable to use cgroups or suspend fully, which is pretty much up to the implementation. In other words, is there a reason we're still

I have seen no proposed way to use cgroups that will work. If you leave some processes running while other processes are frozen you run into problems when a frozen process holds a resource that a running process needs.

Quoted 3 lines

having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

That is "this"? The merged code? If so, no it does not satisfy our requirements. The in kernel api, while offering similar functionality to the wakelock interface, does not use any handles which makes it impossible to get reasonable stats (You don't know which pm_stay_awake request pm_relax is reverting).

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

Why is that a problem (out of curiosity)?

Not having stats or not knowing what pm_relax is undoing? We need stats to be able to debug the system.

You have the stats in struct device and they are available via sysfs. I suppose they are insufficient, but I'd like to know why exactly.

Quoted 6 lines

Our wakelock stats currently have (name,)count,expire_count,wake_count,active_since,total_time,sleep_time,max_time and last_change. Not all of these are equally important (total_time is most important followed by active_since), but you only have count. Also as discussed before, many wakelocks/suspendblockers are not associated with a struct device.

OK

How much of that is used in practice and what for exactly?

Do you _really_ have to debug the wakelocks in drivers that much?

Quoted 8 lines
Quoted 7 lines
Quoted 5 lines

If the system does not suspend
at all or is awake for too long, the wakelock stats tells us which component is at fault. Since pm_stay_awake and pm_relax does not operate on a handle, you cannot determine how long it prevented suspend for.

Well, if you need that, you can add a counter of "completed events" into

Quoted 7 lines

We need more than that (see above).

Quoted 3 lines

struct dev_pm_info and a function similar to pm_relax() that will update that counter. I don't think anyone will object to that change.

What about adding a handle that is passed to all three functions?

I don't think that will fly at this point.

Quoted 21 lines
Quoted 17 lines
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

The proposed in user-space interface
of calling into every process that receives wakeup events before every suspend call

Well, you don't really need to do that.

Quoted 9 lines

Only if the driver blocks suspend until user-space has read the event. This means that for android to work we need to block suspend when input events are not processed, but a system using your scheme needs a pm_wakeup_event call when the input event is queued. How to you switch between them? Do we add separate ioctls in the input device to enable each scheme? If someone has a single threaded user space power manager that also reads input event it will deadlock if you block suspend until it reads the input events since you block when reading the wake count.

Quoted 3 lines

Well, until someone actually tries to implement a power manager in user space it's a bit vague.

Quoted 5 lines

Not having clear rules for what the drivers should do is a problem. The comments in your code seem to advocate using timeouts instead of overlapping pm_stay_awake/pm_relax sections. I find this recommendation strange given all the opposition to wakelock/suspendblocker timeouts.

There's no recommendation either way.

Quoted 3 lines

But more importantly, calling
pm_wakeup_event with a timeout of 0 is incompatible with the android user space code,

Which I don't find really relevant, sorry.

Quoted 4 lines

and I would prefer that the kernel interfaces would encourage drivers to block suspend until user space has consumed the event, which works for the android user space, instead of just long enough to work with a hypothetical user space power manager.

Well, that are your personal preferences, which I respect. I also have some personal preferences that are not necessarily followed by the kernel code.

Thanks,
Rafael

#240 lore raw

2010/8/5 Rafael J. Wysocki <[email protected]>:

Quoted 8 lines
Quoted 7 lines

Our wakelock stats currently have (name,)count,expire_count,wake_count,active_since,total_time,sleep_time,max_time and last_change. Not all of these are equally important (total_time is most important followed by active_since), but you only have count. Also as discussed before, many wakelocks/suspendblockers are not associated with a struct device.

Quoted 5 lines

OK

How much of that is used in practice and what for exactly?

Do you _really_ have to debug the wakelocks in drivers that much?

Debugging power related issues is pretty critical to building competitive mobile devices.

Throughout the several months of this discussion I have been continually scratching my head at this "debugability considered harmful" attitude that I see in reaction to our interest in having the ability (gated behind a config option even -- really, that'd be fine, not everyone need enable it) to gather useful stats and examine the state of the system.

At this point it sounds like there's no interest in the solution we have, which works and has worked for a few years, and has been revised 10+ times based on feedback here, and no interest in providing a solution that accomplishes similar functionality, so perhaps it's time for us to cut our losses and just go back to maintaining our patches instead of having the same arguments over and over again.

Brian

#241 lore raw
In reply to Rafael J. Wysocki

2010/8/5 Rafael J. Wysocki <[email protected]>:

Quoted 8 lines
Quoted 7 lines

Our wakelock stats currently have (name,)count,expire_count,wake_count,active_since,total_time,sleep_time,max_time and last_change. Not all of these are equally important (total_time is most important followed by active_since), but you only have count. Also as discussed before, many wakelocks/suspendblockers are not associated with a struct device.

Quoted 5 lines

OK

How much of that is used in practice and what for exactly?

Do you _really_ have to debug the wakelocks in drivers that much?

Debugging power related issues is pretty critical to building competitive mobile devices.

Throughout the several months of this discussion I have been continually scratching my head at this "debugability considered harmful" attitude that I see in reaction to our interest in having the ability (gated behind a config option even -- really, that'd be fine, not everyone need enable it) to gather useful stats and examine the state of the system.

At this point it sounds like there's no interest in the solution we have, which works and has worked for a few years, and has been revised 10+ times based on feedback here, and no interest in providing a solution that accomplishes similar functionality, so perhaps it's time for us to cut our losses and just go back to maintaining our patches instead of having the same arguments over and over again.

Brian

#242 lore raw
Quoted 9 lines · Brian Swetland

2010/8/5 Rafael J. Wysocki <[email protected]>:

Quoted 8 lines
Quoted 7 lines

Our wakelock stats currently have (name,)count,expire_count,wake_count,active_since,total_time,sleep_time,max_time and last_change. Not all of these are equally important (total_time is most important followed by active_since), but you only have count. Also as discussed before, many wakelocks/suspendblockers are not associated with a struct device.

Quoted 8 lines
Quoted 5 lines

OK

How much of that is used in practice and what for exactly?

Do you _really_ have to debug the wakelocks in drivers that much?

Debugging power related issues is pretty critical to building competitive mobile devices.

Well, I don't think anyone will disagree with that.

Quoted 6 lines

Throughout the several months of this discussion I have been continually scratching my head at this "debugability considered harmful" attitude that I see in reaction to our interest in having the ability (gated behind a config option even -- really, that'd be fine, not everyone need enable it) to gather useful stats and examine the state of the system.

The problem is what kind of stats would be actually sufficient and we haven't seriously discussed that. You said you'd need statistics and we took that for granted, but we didn't really go into details here.

Quoted 6 lines

At this point it sounds like there's no interest in the solution we have, which works and has worked for a few years, and has been revised 10+ times based on feedback here, and no interest in providing a solution that accomplishes similar functionality, so perhaps it's time for us to cut our losses and just go back to maintaining our patches instead of having the same arguments over and over again.

Please remember that I also have spent considerable amount of time trying to push your solution upstream and defending it. I might have spent that time on other things instead, so please don't tell me about "losses".

If you want to stay in your ivory tower, that's perfectly fine by me, but I guess that won't really benefit anyone in the long run.

Thanks,
Rafael

#243 lore raw
In reply to Brian Swetland
Quoted 9 lines · Brian Swetland

2010/8/5 Rafael J. Wysocki <[email protected]>:

Quoted 8 lines
Quoted 7 lines

Our wakelock stats currently have (name,)count,expire_count,wake_count,active_since,total_time,sleep_time,max_time and last_change. Not all of these are equally important (total_time is most important followed by active_since), but you only have count. Also as discussed before, many wakelocks/suspendblockers are not associated with a struct device.

Quoted 8 lines
Quoted 5 lines

OK

How much of that is used in practice and what for exactly?

Do you _really_ have to debug the wakelocks in drivers that much?

Debugging power related issues is pretty critical to building competitive mobile devices.

Well, I don't think anyone will disagree with that.

Quoted 6 lines

Throughout the several months of this discussion I have been continually scratching my head at this "debugability considered harmful" attitude that I see in reaction to our interest in having the ability (gated behind a config option even -- really, that'd be fine, not everyone need enable it) to gather useful stats and examine the state of the system.

The problem is what kind of stats would be actually sufficient and we haven't seriously discussed that. You said you'd need statistics and we took that for granted, but we didn't really go into details here.

Quoted 6 lines

At this point it sounds like there's no interest in the solution we have, which works and has worked for a few years, and has been revised 10+ times based on feedback here, and no interest in providing a solution that accomplishes similar functionality, so perhaps it's time for us to cut our losses and just go back to maintaining our patches instead of having the same arguments over and over again.

Please remember that I also have spent considerable amount of time trying to push your solution upstream and defending it. I might have spent that time on other things instead, so please don't tell me about "losses".

If you want to stay in your ivory tower, that's perfectly fine by me, but I guess that won't really benefit anyone in the long run.

Thanks,
Rafael

#244 lore raw
In reply to Brian Swetland
Quoted 18 lines · Brian Swetland

2010/8/5 Rafael J. Wysocki <[email protected]>:

Quoted 8 lines
Quoted 7 lines

Our wakelock stats currently have (name,)count,expire_count,wake_count,active_since,total_time,sleep_time,max_time and last_change. Not all of these are equally important (total_time is most important followed by active_since), but you only have count. Also as discussed before, many wakelocks/suspendblockers are not associated with a struct device.

Quoted 5 lines

OK

How much of that is used in practice and what for exactly?

Do you _really_ have to debug the wakelocks in drivers that much?

Debugging power related issues is pretty critical to building competitive mobile devices.

Quoted 6 lines

Throughout the several months of this discussion I have been continually scratching my head at this "debugability considered harmful" attitude that I see in reaction to our interest in having the ability (gated behind a config option even -- really, that'd be fine, not everyone need enable it) to gather useful stats and examine the state of the system.

In my case, it has not been "debuggability considered harmful", but rather my lack of understanding of the kinds of bugs that can arise and what information is most helpful in tracking them down. Arve's post listing the meanings of the stats helped me quite a bit, although I am sure that my understanding is still quite rudimentary.

Quoted 6 lines

At this point it sounds like there's no interest in the solution we have, which works and has worked for a few years, and has been revised 10+ times based on feedback here, and no interest in providing a solution that accomplishes similar functionality, so perhaps it's time for us to cut our losses and just go back to maintaining our patches instead of having the same arguments over and over again.

And this brings up another aspect of Android requirements. Mainlining Android features is not necessarily an all-or-nothing proposition. Here is a prototype list of degrees of mainlining, along with at least a few of the benefits and difficulties of each level:

o Mainline that provides exactly what Android needs.

This is of course the best case, but, as you may have noticed, might not be easy to achieve. The plain fact is that Linux must support a wide variety of workloads, so some give-and-take is usually required.

o Mainline that exactly matches the ideal API, but which fails
to implement some feature or another.

This is still not bad. You have to carry a specific patch to provide the feature(s), but all the calling sites are carried upstream in mainline.

o Mainline provides something that is close to the ideal API, but
some additional constant arguments are required.

This is not so good, but at least the drivers can be upstreamed and the changes required to get to an Android-ready kernel are fairly simple.

o Mainline provides something, but Android requires changes to the
supplied API which require additional data to be passed from call site to call site.

Again, at least drivers can be upstreamed, but the changes required to get to an Android-ready kernel are a bit more involved.

o Mainline provides a stubbed-out API.

Once again, the drivers can at least be upstreamed, but Android is the only project validating the placement of calls to the
API. This means that changes to the drivers are likely to
mess up the placement of the call sites. Therefore, getting to an Android-ready kernel requires careful inspection of the drivers to adjust for bugs introduced by others.

o Mainline provides nothing.

Status quo. This means that some other group will likely introduce the required functionality in an incremental fashion. This process will likely fail to take Android's needs into account, probably leading to...

o Mainline provides functionality that is similar to what
Android needs, but in a completely incompatible manner that cannot be used easily (or perhaps at all) by Android.

My guess is that there is value to Android in a number of the non-perfect cases.

Thanx, Paul

#245 lore raw
In reply to Brian Swetland
Quoted 18 lines · Brian Swetland

2010/8/5 Rafael J. Wysocki <[email protected]>:

Quoted 8 lines
Quoted 7 lines

Our wakelock stats currently have (name,)count,expire_count,wake_count,active_since,total_time,sleep_time,max_time and last_change. Not all of these are equally important (total_time is most important followed by active_since), but you only have count. Also as discussed before, many wakelocks/suspendblockers are not associated with a struct device.

Quoted 5 lines

OK

How much of that is used in practice and what for exactly?

Do you _really_ have to debug the wakelocks in drivers that much?

Debugging power related issues is pretty critical to building competitive mobile devices.

Quoted 6 lines

Throughout the several months of this discussion I have been continually scratching my head at this "debugability considered harmful" attitude that I see in reaction to our interest in having the ability (gated behind a config option even -- really, that'd be fine, not everyone need enable it) to gather useful stats and examine the state of the system.

In my case, it has not been "debuggability considered harmful", but rather my lack of understanding of the kinds of bugs that can arise and what information is most helpful in tracking them down. Arve's post listing the meanings of the stats helped me quite a bit, although I am sure that my understanding is still quite rudimentary.

Quoted 6 lines

At this point it sounds like there's no interest in the solution we have, which works and has worked for a few years, and has been revised 10+ times based on feedback here, and no interest in providing a solution that accomplishes similar functionality, so perhaps it's time for us to cut our losses and just go back to maintaining our patches instead of having the same arguments over and over again.

And this brings up another aspect of Android requirements. Mainlining Android features is not necessarily an all-or-nothing proposition. Here is a prototype list of degrees of mainlining, along with at least a few of the benefits and difficulties of each level:

o Mainline that provides exactly what Android needs.

This is of course the best case, but, as you may have noticed, might not be easy to achieve. The plain fact is that Linux must support a wide variety of workloads, so some give-and-take is usually required.

o Mainline that exactly matches the ideal API, but which fails
to implement some feature or another.

This is still not bad. You have to carry a specific patch to provide the feature(s), but all the calling sites are carried upstream in mainline.

o Mainline provides something that is close to the ideal API, but
some additional constant arguments are required.

This is not so good, but at least the drivers can be upstreamed and the changes required to get to an Android-ready kernel are fairly simple.

o Mainline provides something, but Android requires changes to the
supplied API which require additional data to be passed from call site to call site.

Again, at least drivers can be upstreamed, but the changes required to get to an Android-ready kernel are a bit more involved.

o Mainline provides a stubbed-out API.

Once again, the drivers can at least be upstreamed, but Android is the only project validating the placement of calls to the
API. This means that changes to the drivers are likely to
mess up the placement of the call sites. Therefore, getting to an Android-ready kernel requires careful inspection of the drivers to adjust for bugs introduced by others.

o Mainline provides nothing.

Status quo. This means that some other group will likely introduce the required functionality in an incremental fashion. This process will likely fail to take Android's needs into account, probably leading to...

o Mainline provides functionality that is similar to what
Android needs, but in a completely incompatible manner that cannot be used easily (or perhaps at all) by Android.

My guess is that there is value to Android in a number of the non-perfect cases.

Thanx, Paul

#246 lore raw
In reply to Rafael J. Wysocki

2010/8/5 Rafael J. Wysocki <[email protected]>:

Quoted 79 lines · Arve Hjønnevåg
Quoted 71 lines

2010/8/5 Rafael J. Wysocki <[email protected]>:

Quoted 60 lines · Arve Hjønnevåg
Quoted 32 lines

2010/8/4 Rafael J. Wysocki <[email protected]>:

Quoted 31 lines · Arve Hjønnevåg
Quoted 29 lines · Matthew Garrett
Quoted 14 lines · Rafael J. Wysocki
Quoted 13 lines · Matthew Garrett
Quoted 12 lines

No! And that's precisely the issue. Android's existing behaviour could be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to avoid the race (if pm_wakeup_event() is called at 2)).

Yes, I think that solves the problem. The only question then is whether

How? By passing a timeout to pm_wakeup_event when the network driver gets the packet or by passing 0. If you pass a timeout it is the same as using a wakelock with a timeout and should work (assuming the timeout you picked is long enough). If you don't pass a timeout it does not work, since the packet may not be visible to user-space yet.

Quoted 5 lines
Quoted 2 lines

Alternatively, pm_stay_awake() / pm_relax() can be used.

Which makes the driver and/or network stack changes identical to using wakelocks, right?

Please refer to the Matthew's response.

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 2 lines

it's preferable to use cgroups or suspend fully, which is pretty much up to the implementation. In other words, is there a reason we're still

I have seen no proposed way to use cgroups that will work. If you leave some processes running while other processes are frozen you run into problems when a frozen process holds a resource that a running process needs.

Quoted 3 lines

having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

That is "this"? The merged code? If so, no it does not satisfy our requirements. The in kernel api, while offering similar functionality to the wakelock interface, does not use any handles which makes it impossible to get reasonable stats (You don't know which pm_stay_awake request pm_relax is reverting).

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

Why is that a problem (out of curiosity)?

Not having stats or not knowing what pm_relax is undoing? We need stats to be able to debug the system.

You have the stats in struct device and they are available via sysfs. I suppose they are insufficient, but I'd like to know why exactly.

Quoted 6 lines

Our wakelock stats currently have (name,)count,expire_count,wake_count,active_since,total_time,sleep_time,max_time and last_change. Not all of these are equally important (total_time is most important followed by active_since), but you only have count. Also as discussed before, many wakelocks/suspendblockers are not associated with a struct device.

Quoted 3 lines

OK

How much of that is used in practice and what for exactly?

count, tells you how many times the wakelock was activated. If a wakelock prevented suspend for a long time a large count tells you it handled a lot of events while a small count tells you it took a long time to process the events, or the wakelock was not released properly.

expire_count, tells you how many times the timeout expired. For the input event wakelock in the android kernel (which has a timeout) an expire count that matches the count tells you that someone opened an input device but is not reading from it (this has happened several times).

wake_count, tells you that this is the first wakelock that was acquired in the resume path. This is currently less useful than I would like on the Nexus One since it is usually "SMD_RPCCALL" which does not tell me a lot.

active_since, tells you how long a a still active wakelock has been active. If someone activated a wakelock and never released it, it will be obvious here.

total_time, total time the wake lock has been active. This one should be obvious.

sleep_time, total time the wake lock has been active when the screen was off.

max_time, longest time the wakelock was active uninterrupted. This used less often, but the battery on a device was draining fast, but the problem went away before looking at the stats this will show if a wakelock was active for a long time.

Quoted 3 lines

Do you _really_ have to debug the wakelocks in drivers that much?

Wake locks in drivers sometimes need to be debugged. If the api has no accountability, then these problems would take forever to fix.

Quoted 10 lines
Quoted 10 lines
Quoted 7 lines
Quoted 5 lines

If the system does not suspend
at all or is awake for too long, the wakelock stats tells us which component is at fault. Since pm_stay_awake and pm_relax does not operate on a handle, you cannot determine how long it prevented suspend for.

Well, if you need that, you can add a counter of "completed events" into

We need more than that (see above).

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

struct dev_pm_info and a function similar to pm_relax() that will update that counter.  I don't think anyone will object to that change.

What about adding a handle that is passed to all three functions?

I don't think that will fly at this point.

Why not? I think allowing drivers to modify a global reference count with no accountability is a terrible idea.

Quoted 21 lines
Quoted 21 lines
Quoted 20 lines
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

The proposed in user-space interface
of calling into every process that receives wakeup events before every suspend call

Well,  you don't really need to do that.

Quoted 9 lines

Only if the driver blocks suspend until user-space has read the event. This means that for android to work we need to block suspend when input events are not processed, but a system using your scheme needs a pm_wakeup_event call when the input event is queued. How to you switch between them? Do we add separate ioctls in the input device to enable each scheme? If someone has a single threaded user space power manager that also reads input event it will deadlock if you block suspend until it reads the input events since you block when reading the wake count.

Well, until someone actually tries to implement a power manager in user space it's a bit vague.

Quoted 7 lines
Quoted 5 lines

Not having clear rules for what the drivers should do is a problem. The comments in your code seem to advocate using timeouts instead of overlapping pm_stay_awake/pm_relax sections. I find this recommendation strange given all the opposition to wakelock/suspendblocker timeouts.

There's no recommendation either way.

I'm referring to this paragraph:

* Second, a wakeup event may be detected by one functional unit and processed
* by another one. In that case the unit that has detected it cannot really
* "close" the "no suspend" period associated with it, unless it knows in
* advance what's going to happen to the event during processing. This
* knowledge, however, may not be available to it, so it can simply
specify time
* to wait before the system can be suspended and pass it as the second
* argument of pm_wakeup_event().

Quoted 23 lines
Quoted 4 lines

But more importantly, calling
pm_wakeup_event with a timeout of 0 is incompatible with the android user space code,

Which I don't find really relevant, sorry.

Quoted 4 lines

and I would prefer that the kernel interfaces would encourage drivers to block suspend until user space has consumed the event, which works for the android user space, instead of just long enough to work with a hypothetical user space power manager.

Well, that are your personal preferences, which I respect.  I also have some personal preferences that are not necessarily followed by the kernel code.

Thanks,
Rafael
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Signature · 1 line
Arve Hjønnevåg
#247 lore raw
In reply to Rafael J. Wysocki

2010/8/5 Rafael J. Wysocki <[email protected]>:

Quoted 79 lines · Arve Hjønnevåg
Quoted 71 lines

2010/8/5 Rafael J. Wysocki <[email protected]>:

Quoted 60 lines · Arve Hjønnevåg
Quoted 32 lines

2010/8/4 Rafael J. Wysocki <[email protected]>:

Quoted 31 lines · Arve Hjønnevåg
Quoted 29 lines · Matthew Garrett
Quoted 14 lines · Rafael J. Wysocki
Quoted 13 lines · Matthew Garrett
Quoted 12 lines

No! And that's precisely the issue. Android's existing behaviour could be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to avoid the race (if pm_wakeup_event() is called at 2)).

Yes, I think that solves the problem. The only question then is whether

How? By passing a timeout to pm_wakeup_event when the network driver gets the packet or by passing 0. If you pass a timeout it is the same as using a wakelock with a timeout and should work (assuming the timeout you picked is long enough). If you don't pass a timeout it does not work, since the packet may not be visible to user-space yet.

Quoted 5 lines
Quoted 2 lines

Alternatively, pm_stay_awake() / pm_relax() can be used.

Which makes the driver and/or network stack changes identical to using wakelocks, right?

Please refer to the Matthew's response.

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 2 lines

it's preferable to use cgroups or suspend fully, which is pretty much up to the implementation. In other words, is there a reason we're still

I have seen no proposed way to use cgroups that will work. If you leave some processes running while other processes are frozen you run into problems when a frozen process holds a resource that a running process needs.

Quoted 3 lines

having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

That is "this"? The merged code? If so, no it does not satisfy our requirements. The in kernel api, while offering similar functionality to the wakelock interface, does not use any handles which makes it impossible to get reasonable stats (You don't know which pm_stay_awake request pm_relax is reverting).

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

Why is that a problem (out of curiosity)?

Not having stats or not knowing what pm_relax is undoing? We need stats to be able to debug the system.

You have the stats in struct device and they are available via sysfs. I suppose they are insufficient, but I'd like to know why exactly.

Quoted 6 lines

Our wakelock stats currently have (name,)count,expire_count,wake_count,active_since,total_time,sleep_time,max_time and last_change. Not all of these are equally important (total_time is most important followed by active_since), but you only have count. Also as discussed before, many wakelocks/suspendblockers are not associated with a struct device.

Quoted 3 lines

OK

How much of that is used in practice and what for exactly?

count, tells you how many times the wakelock was activated. If a wakelock prevented suspend for a long time a large count tells you it handled a lot of events while a small count tells you it took a long time to process the events, or the wakelock was not released properly.

expire_count, tells you how many times the timeout expired. For the input event wakelock in the android kernel (which has a timeout) an expire count that matches the count tells you that someone opened an input device but is not reading from it (this has happened several times).

wake_count, tells you that this is the first wakelock that was acquired in the resume path. This is currently less useful than I would like on the Nexus One since it is usually "SMD_RPCCALL" which does not tell me a lot.

active_since, tells you how long a a still active wakelock has been active. If someone activated a wakelock and never released it, it will be obvious here.

total_time, total time the wake lock has been active. This one should be obvious.

sleep_time, total time the wake lock has been active when the screen was off.

max_time, longest time the wakelock was active uninterrupted. This used less often, but the battery on a device was draining fast, but the problem went away before looking at the stats this will show if a wakelock was active for a long time.

Quoted 3 lines

Do you _really_ have to debug the wakelocks in drivers that much?

Wake locks in drivers sometimes need to be debugged. If the api has no accountability, then these problems would take forever to fix.

Quoted 10 lines
Quoted 10 lines
Quoted 7 lines
Quoted 5 lines

If the system does not suspend
at all or is awake for too long, the wakelock stats tells us which component is at fault. Since pm_stay_awake and pm_relax does not operate on a handle, you cannot determine how long it prevented suspend for.

Well, if you need that, you can add a counter of "completed events" into

We need more than that (see above).

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

struct dev_pm_info and a function similar to pm_relax() that will update that counter.  I don't think anyone will object to that change.

What about adding a handle that is passed to all three functions?

I don't think that will fly at this point.

Why not? I think allowing drivers to modify a global reference count with no accountability is a terrible idea.

Quoted 21 lines
Quoted 21 lines
Quoted 20 lines
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

The proposed in user-space interface
of calling into every process that receives wakeup events before every suspend call

Well,  you don't really need to do that.

Quoted 9 lines

Only if the driver blocks suspend until user-space has read the event. This means that for android to work we need to block suspend when input events are not processed, but a system using your scheme needs a pm_wakeup_event call when the input event is queued. How to you switch between them? Do we add separate ioctls in the input device to enable each scheme? If someone has a single threaded user space power manager that also reads input event it will deadlock if you block suspend until it reads the input events since you block when reading the wake count.

Well, until someone actually tries to implement a power manager in user space it's a bit vague.

Quoted 7 lines
Quoted 5 lines

Not having clear rules for what the drivers should do is a problem. The comments in your code seem to advocate using timeouts instead of overlapping pm_stay_awake/pm_relax sections. I find this recommendation strange given all the opposition to wakelock/suspendblocker timeouts.

There's no recommendation either way.

I'm referring to this paragraph:

* Second, a wakeup event may be detected by one functional unit and processed
* by another one. In that case the unit that has detected it cannot really
* "close" the "no suspend" period associated with it, unless it knows in
* advance what's going to happen to the event during processing. This
* knowledge, however, may not be available to it, so it can simply
specify time
* to wait before the system can be suspended and pass it as the second
* argument of pm_wakeup_event().

Quoted 23 lines
Quoted 4 lines

But more importantly, calling
pm_wakeup_event with a timeout of 0 is incompatible with the android user space code,

Which I don't find really relevant, sorry.

Quoted 4 lines

and I would prefer that the kernel interfaces would encourage drivers to block suspend until user space has consumed the event, which works for the android user space, instead of just long enough to work with a hypothetical user space power manager.

Well, that are your personal preferences, which I respect.  I also have some personal preferences that are not necessarily followed by the kernel code.

Thanks,
Rafael
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Signature · 1 line
Arve Hjønnevåg
#248 lore raw
Quoted 1 line · Arve Hj?nnev?g

sleep_time, total time the wake lock has been active when the screen was off.

This one seems a little odd, and won't make sense on some devices like those with E Ink displays or those which don't have screens at all. I guess it's really focused on metering when the user is not actively interacting with the device?

#249 lore raw
In reply to Arve Hjønnevåg
Quoted 1 line · Arve Hj?nnev?g

sleep_time, total time the wake lock has been active when the screen was off.

This one seems a little odd, and won't make sense on some devices like those with E Ink displays or those which don't have screens at all. I guess it's really focused on metering when the user is not actively interacting with the device?

#250 lore raw
In reply to Arve Hjønnevåg
Quoted 80 lines · Arve Hjønnevåg

2010/8/5 Rafael J. Wysocki <[email protected]>:

Quoted 79 lines · Arve Hjønnevåg
Quoted 77 lines

2010/8/5 Rafael J. Wysocki <[email protected]>:

Quoted 60 lines · Arve Hjønnevåg
Quoted 32 lines

2010/8/4 Rafael J. Wysocki <[email protected]>:

Quoted 31 lines · Arve Hjønnevåg
Quoted 29 lines · Matthew Garrett
Quoted 14 lines · Rafael J. Wysocki
Quoted 13 lines · Matthew Garrett
Quoted 12 lines

No! And that's precisely the issue. Android's existing behaviour could be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to avoid the race (if pm_wakeup_event() is called at 2)).

Yes, I think that solves the problem. The only question then is whether

How? By passing a timeout to pm_wakeup_event when the network driver gets the packet or by passing 0. If you pass a timeout it is the same as using a wakelock with a timeout and should work (assuming the timeout you picked is long enough). If you don't pass a timeout it does not work, since the packet may not be visible to user-space yet.

Quoted 5 lines
Quoted 2 lines

Alternatively, pm_stay_awake() / pm_relax() can be used.

Which makes the driver and/or network stack changes identical to using wakelocks, right?

Please refer to the Matthew's response.

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 2 lines

it's preferable to use cgroups or suspend fully, which is pretty much up to the implementation. In other words, is there a reason we're still

I have seen no proposed way to use cgroups that will work. If you leave some processes running while other processes are frozen you run into problems when a frozen process holds a resource that a running process needs.

Quoted 3 lines

having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

That is "this"? The merged code? If so, no it does not satisfy our requirements. The in kernel api, while offering similar functionality to the wakelock interface, does not use any handles which makes it impossible to get reasonable stats (You don't know which pm_stay_awake request pm_relax is reverting).

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

Why is that a problem (out of curiosity)?

Not having stats or not knowing what pm_relax is undoing? We need stats to be able to debug the system.

You have the stats in struct device and they are available via sysfs. I suppose they are insufficient, but I'd like to know why exactly.

Our wakelock stats currently have (name,)count,expire_count,wake_count,active_since,total_time,sleep_time,max_time and last_change. Not all of these are equally important (total_time is most important followed by active_since), but you only have count. Also as discussed before, many wakelocks/suspendblockers are not associated with a struct device.

Quoted 8 lines
Quoted 3 lines

OK

How much of that is used in practice and what for exactly?

count, tells you how many times the wakelock was activated. If a wakelock prevented suspend for a long time a large count tells you it handled a lot of events while a small count tells you it took a long time to process the events, or the wakelock was not released properly.

Got it!

Quoted 5 lines

expire_count, tells you how many times the timeout expired. For the input event wakelock in the android kernel (which has a timeout) an expire count that matches the count tells you that someone opened an input device but is not reading from it (this has happened several times).

Ah, I hadn't considered that an power-oblivious application could take this approach to waste power. I now better understand the purpose of the timeouts, and have added the corresponding requirement. ;-)

Quoted 4 lines

wake_count, tells you that this is the first wakelock that was acquired in the resume path. This is currently less useful than I would like on the Nexus One since it is usually "SMD_RPCCALL" which does not tell me a lot.

Got it!

Quoted 3 lines

active_since, tells you how long a a still active wakelock has been active. If someone activated a wakelock and never released it, it will be obvious here.

This one is zero if the wakelock is not currently held, correct?

Quoted 2 lines

total_time, total time the wake lock has been active. This one should be obvious.

Got it!

Quoted 1 line

sleep_time, total time the wake lock has been active when the screen was off.

Hmmm... The statistics for apps are collected in userspace, correct? If so, this would be collecting the total time that suspend blockers that were acquired by some driver have been held while the screen was powered off. So if things were working properly, sleep_time should be quite small -- with the exception of the suspend blocker that the userspace daemon was using as a proxy for all of the userspace suspend blockers.

Or am I confused about this?

Quoted 4 lines

max_time, longest time the wakelock was active uninterrupted. This used less often, but the battery on a device was draining fast, but the problem went away before looking at the stats this will show if a wakelock was active for a long time.

Got it!

Thank you for this additional info, it really shines some light on what you are trying to do.

One question: are these statistics enabled in production devices, are is this a debug-only facility?

Quoted 5 lines
Quoted 2 lines

Do you _really_ have to debug the wakelocks in drivers that much?

Wake locks in drivers sometimes need to be debugged. If the api has no accountability, then these problems would take forever to fix.

So there is a separate set of suspend-blocker statistics collected in userspace, correct? (The kernel probably doesn't need to care about this, and I don't believe that I need anything more than a "yes" or "no" answer, but just want to make sure I understand how these statistics are used.)

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 5 lines

If the system does not suspend
at all or is awake for too long, the wakelock stats tells us which component is at fault. Since pm_stay_awake and pm_relax does not operate on a handle, you cannot determine how long it prevented suspend for.

Well, if you need that, you can add a counter of "completed events" into

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

We need more than that (see above).

Quoted 3 lines

struct dev_pm_info and a function similar to pm_relax() that will update that counter.  I don't think anyone will object to that change.

What about adding a handle that is passed to all three functions?

The reason you want the handle is to allow the calling code to indicate which calling points are dealing with the same suspend-blocker entity?

Thaxn, Paul

Quoted 74 lines
Quoted 2 lines

I don't think that will fly at this point.

Why not? I think allowing drivers to modify a global reference count with no accountability is a terrible idea.

Quoted 21 lines
Quoted 21 lines
Quoted 20 lines
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

The proposed in user-space interface
of calling into every process that receives wakeup events before every suspend call

Well,  you don't really need to do that.

Quoted 9 lines

Only if the driver blocks suspend until user-space has read the event. This means that for android to work we need to block suspend when input events are not processed, but a system using your scheme needs a pm_wakeup_event call when the input event is queued. How to you switch between them? Do we add separate ioctls in the input device to enable each scheme? If someone has a single threaded user space power manager that also reads input event it will deadlock if you block suspend until it reads the input events since you block when reading the wake count.

Well, until someone actually tries to implement a power manager in user space it's a bit vague.

Quoted 7 lines
Quoted 5 lines

Not having clear rules for what the drivers should do is a problem. The comments in your code seem to advocate using timeouts instead of overlapping pm_stay_awake/pm_relax sections. I find this recommendation strange given all the opposition to wakelock/suspendblocker timeouts.

There's no recommendation either way.

I'm referring to this paragraph:

* Second, a wakeup event may be detected by one functional unit and processed
* by another one. In that case the unit that has detected it cannot really
* "close" the "no suspend" period associated with it, unless it knows in
* advance what's going to happen to the event during processing. This
* knowledge, however, may not be available to it, so it can simply
specify time
* to wait before the system can be suspended and pass it as the second
* argument of pm_wakeup_event().

Quoted 23 lines
Quoted 4 lines

But more importantly, calling
pm_wakeup_event with a timeout of 0 is incompatible with the android user space code,

Which I don't find really relevant, sorry.

Quoted 4 lines

and I would prefer that the kernel interfaces would encourage drivers to block suspend until user space has consumed the event, which works for the android user space, instead of just long enough to work with a hypothetical user space power manager.

Well, that are your personal preferences, which I respect.  I also have some personal preferences that are not necessarily followed by the kernel code.

Thanks,
Rafael
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Signature · 1 line
Arve Hjønnevåg
#251 lore raw
In reply to Arve Hjønnevåg
Quoted 80 lines · Arve Hjønnevåg

2010/8/5 Rafael J. Wysocki <[email protected]>:

Quoted 79 lines · Arve Hjønnevåg
Quoted 77 lines

2010/8/5 Rafael J. Wysocki <[email protected]>:

Quoted 60 lines · Arve Hjønnevåg
Quoted 32 lines

2010/8/4 Rafael J. Wysocki <[email protected]>:

Quoted 31 lines · Arve Hjønnevåg
Quoted 29 lines · Matthew Garrett
Quoted 14 lines · Rafael J. Wysocki
Quoted 13 lines · Matthew Garrett
Quoted 12 lines

No! And that's precisely the issue. Android's existing behaviour could be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to avoid the race (if pm_wakeup_event() is called at 2)).

Yes, I think that solves the problem. The only question then is whether

How? By passing a timeout to pm_wakeup_event when the network driver gets the packet or by passing 0. If you pass a timeout it is the same as using a wakelock with a timeout and should work (assuming the timeout you picked is long enough). If you don't pass a timeout it does not work, since the packet may not be visible to user-space yet.

Quoted 5 lines
Quoted 2 lines

Alternatively, pm_stay_awake() / pm_relax() can be used.

Which makes the driver and/or network stack changes identical to using wakelocks, right?

Please refer to the Matthew's response.

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 2 lines

it's preferable to use cgroups or suspend fully, which is pretty much up to the implementation. In other words, is there a reason we're still

I have seen no proposed way to use cgroups that will work. If you leave some processes running while other processes are frozen you run into problems when a frozen process holds a resource that a running process needs.

Quoted 3 lines

having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

That is "this"? The merged code? If so, no it does not satisfy our requirements. The in kernel api, while offering similar functionality to the wakelock interface, does not use any handles which makes it impossible to get reasonable stats (You don't know which pm_stay_awake request pm_relax is reverting).

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

Why is that a problem (out of curiosity)?

Not having stats or not knowing what pm_relax is undoing? We need stats to be able to debug the system.

You have the stats in struct device and they are available via sysfs. I suppose they are insufficient, but I'd like to know why exactly.

Our wakelock stats currently have (name,)count,expire_count,wake_count,active_since,total_time,sleep_time,max_time and last_change. Not all of these are equally important (total_time is most important followed by active_since), but you only have count. Also as discussed before, many wakelocks/suspendblockers are not associated with a struct device.

Quoted 8 lines
Quoted 3 lines

OK

How much of that is used in practice and what for exactly?

count, tells you how many times the wakelock was activated. If a wakelock prevented suspend for a long time a large count tells you it handled a lot of events while a small count tells you it took a long time to process the events, or the wakelock was not released properly.

Got it!

Quoted 5 lines

expire_count, tells you how many times the timeout expired. For the input event wakelock in the android kernel (which has a timeout) an expire count that matches the count tells you that someone opened an input device but is not reading from it (this has happened several times).

Ah, I hadn't considered that an power-oblivious application could take this approach to waste power. I now better understand the purpose of the timeouts, and have added the corresponding requirement. ;-)

Quoted 4 lines

wake_count, tells you that this is the first wakelock that was acquired in the resume path. This is currently less useful than I would like on the Nexus One since it is usually "SMD_RPCCALL" which does not tell me a lot.

Got it!

Quoted 3 lines

active_since, tells you how long a a still active wakelock has been active. If someone activated a wakelock and never released it, it will be obvious here.

This one is zero if the wakelock is not currently held, correct?

Quoted 2 lines

total_time, total time the wake lock has been active. This one should be obvious.

Got it!

Quoted 1 line

sleep_time, total time the wake lock has been active when the screen was off.

Hmmm... The statistics for apps are collected in userspace, correct? If so, this would be collecting the total time that suspend blockers that were acquired by some driver have been held while the screen was powered off. So if things were working properly, sleep_time should be quite small -- with the exception of the suspend blocker that the userspace daemon was using as a proxy for all of the userspace suspend blockers.

Or am I confused about this?

Quoted 4 lines

max_time, longest time the wakelock was active uninterrupted. This used less often, but the battery on a device was draining fast, but the problem went away before looking at the stats this will show if a wakelock was active for a long time.

Got it!

Thank you for this additional info, it really shines some light on what you are trying to do.

One question: are these statistics enabled in production devices, are is this a debug-only facility?

Quoted 5 lines
Quoted 2 lines

Do you _really_ have to debug the wakelocks in drivers that much?

Wake locks in drivers sometimes need to be debugged. If the api has no accountability, then these problems would take forever to fix.

So there is a separate set of suspend-blocker statistics collected in userspace, correct? (The kernel probably doesn't need to care about this, and I don't believe that I need anything more than a "yes" or "no" answer, but just want to make sure I understand how these statistics are used.)

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 5 lines

If the system does not suspend
at all or is awake for too long, the wakelock stats tells us which component is at fault. Since pm_stay_awake and pm_relax does not operate on a handle, you cannot determine how long it prevented suspend for.

Well, if you need that, you can add a counter of "completed events" into

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

We need more than that (see above).

Quoted 3 lines

struct dev_pm_info and a function similar to pm_relax() that will update that counter.  I don't think anyone will object to that change.

What about adding a handle that is passed to all three functions?

The reason you want the handle is to allow the calling code to indicate which calling points are dealing with the same suspend-blocker entity?

Thaxn, Paul

Quoted 74 lines
Quoted 2 lines

I don't think that will fly at this point.

Why not? I think allowing drivers to modify a global reference count with no accountability is a terrible idea.

Quoted 21 lines
Quoted 21 lines
Quoted 20 lines
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

The proposed in user-space interface
of calling into every process that receives wakeup events before every suspend call

Well,  you don't really need to do that.

Quoted 9 lines

Only if the driver blocks suspend until user-space has read the event. This means that for android to work we need to block suspend when input events are not processed, but a system using your scheme needs a pm_wakeup_event call when the input event is queued. How to you switch between them? Do we add separate ioctls in the input device to enable each scheme? If someone has a single threaded user space power manager that also reads input event it will deadlock if you block suspend until it reads the input events since you block when reading the wake count.

Well, until someone actually tries to implement a power manager in user space it's a bit vague.

Quoted 7 lines
Quoted 5 lines

Not having clear rules for what the drivers should do is a problem. The comments in your code seem to advocate using timeouts instead of overlapping pm_stay_awake/pm_relax sections. I find this recommendation strange given all the opposition to wakelock/suspendblocker timeouts.

There's no recommendation either way.

I'm referring to this paragraph:

* Second, a wakeup event may be detected by one functional unit and processed
* by another one. In that case the unit that has detected it cannot really
* "close" the "no suspend" period associated with it, unless it knows in
* advance what's going to happen to the event during processing. This
* knowledge, however, may not be available to it, so it can simply
specify time
* to wait before the system can be suspended and pass it as the second
* argument of pm_wakeup_event().

Quoted 23 lines
Quoted 4 lines

But more importantly, calling
pm_wakeup_event with a timeout of 0 is incompatible with the android user space code,

Which I don't find really relevant, sorry.

Quoted 4 lines

and I would prefer that the kernel interfaces would encourage drivers to block suspend until user space has consumed the event, which works for the android user space, instead of just long enough to work with a hypothetical user space power manager.

Well, that are your personal preferences, which I respect.  I also have some personal preferences that are not necessarily followed by the kernel code.

Thanks,
Rafael
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Signature · 1 line
Arve Hjønnevåg
#252 lore raw
In reply to Arve Hjønnevåg
Quoted 4 lines · Arve Hjønnevåg

count, tells you how many times the wakelock was activated. If a wakelock prevented suspend for a long time a large count tells you it handled a lot of events while a small count tells you it took a long time to process the events, or the wakelock was not released properly.

As noted, we already have this.

Quoted 5 lines

expire_count, tells you how many times the timeout expired. For the input event wakelock in the android kernel (which has a timeout) an expire count that matches the count tells you that someone opened an input device but is not reading from it (this has happened several times).

This is a little tricky. Rafael's model currently does not allow wakeup events started by pm_wakeup_event() to be cancelled any way other than by having their timer expire. This essentially means that for some devices, expire_count will always be the same as count and for others it will always be 0. To change this would require adding an extra timer struct, which could be done (in fact, an earlier version of the code included it). It would be nice if we could avoid the need.

Does Android use any kernel-internal wakelocks both with a timer and with active cancellation?

Quoted 4 lines

wake_count, tells you that this is the first wakelock that was acquired in the resume path. This is currently less useful than I would like on the Nexus One since it is usually "SMD_RPCCALL" which does not tell me a lot.

This could be done easily enough, but if it's not very useful then there's no point.

Quoted 3 lines

active_since, tells you how long a a still active wakelock has been active. If someone activated a wakelock and never released it, it will be obvious here.

Easily added. But you didn't mention any field saying whether the wakelock is currently active. That could be added too (although it would be racy -- but for detecting unreleased wakelocks you wouldn't care).

Quoted 2 lines

total_time, total time the wake lock has been active. This one should be obvious.

Also easily added.

Quoted 1 line

sleep_time, total time the wake lock has been active when the screen was off.

Not applicable to general systems. Is there anything like it that _would_ apply in general?

Quoted 4 lines

max_time, longest time the wakelock was active uninterrupted. This used less often, but the battery on a device was draining fast, but the problem went away before looking at the stats this will show if a wakelock was active for a long time.

Again, easily added. The only drawback is that all these additions will bloat the size of struct device. Of course, that's why you used separately-allocated structures for your wakelocks. Maybe we can change to do the same; it seems likely that the majority of device structures won't ever be used for wakeup events.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

and I would prefer that the kernel interfaces would encourage drivers to block suspend until user space has consumed the event, which works for the android user space, instead of just long enough to work with a hypothetical user space power manager.

Rafael doesn't _discourage_ drivers from doing this. However you have to keep in mind that many kernel developers are accustomed to working on systems (mostly PCs) with a different range of hardware devices from embedded systems like your phones. With PCI devices(*), for example, there's no clear point where a wakeup event gets handed off to userspace.

On the other hand, there's no reason the input layer shouldn't use pm_stay_awake and pm_relax. It simply hasn't been implemented yet.

Alan Stern

(*) Speaking of PCI devices, I'm not convinced that the way Rafael is using the pm_wakeup_event interface in the PCI core is entirely correct. The idea is to resolve the race between wakeup events and suspend. The code assumes that a wakeup event will be consumed in 100 ms or less, which is a reasonable assumption.

But what sorts of things qualify as wakeup events? Right now, the code handles only events coming by way of the PME# signal (or its platform equivalent). But that signal usually gets activated only when a PCI device is in a low-power mode; if the device is at full power then it simply generates an IRQ. It's the same event, but reported to the kernel in a different way. So consider...

Case 1: The system is suspending and the PCI device has already been
placed in D3hot when an event occurs. PME# is activated, the wakeup event is reported, the suspend is aborted, and the system won't try to suspend again for at least 100 ms. Good.

Case 2: The system is running normally and the PCI device is at full
power when an event occurs. PME# isn't activated and pm_wakeup_event doesn't get called. Then when the system tries to suspend 25 ms later, there's nothing to prevent it even though the event is still being processed. Bad.

In case 2 the race has not been resolved. It seems to me that the only proper solution is to call pm_wakeup_event for _every_ PCI interrupt. This may be too much to add to a hot path, but what's the alternative?

#253 lore raw
In reply to Arve Hjønnevåg
Quoted 4 lines · Arve Hjønnevåg

count, tells you how many times the wakelock was activated. If a wakelock prevented suspend for a long time a large count tells you it handled a lot of events while a small count tells you it took a long time to process the events, or the wakelock was not released properly.

As noted, we already have this.

Quoted 5 lines

expire_count, tells you how many times the timeout expired. For the input event wakelock in the android kernel (which has a timeout) an expire count that matches the count tells you that someone opened an input device but is not reading from it (this has happened several times).

This is a little tricky. Rafael's model currently does not allow wakeup events started by pm_wakeup_event() to be cancelled any way other than by having their timer expire. This essentially means that for some devices, expire_count will always be the same as count and for others it will always be 0. To change this would require adding an extra timer struct, which could be done (in fact, an earlier version of the code included it). It would be nice if we could avoid the need.

Does Android use any kernel-internal wakelocks both with a timer and with active cancellation?

Quoted 4 lines

wake_count, tells you that this is the first wakelock that was acquired in the resume path. This is currently less useful than I would like on the Nexus One since it is usually "SMD_RPCCALL" which does not tell me a lot.

This could be done easily enough, but if it's not very useful then there's no point.

Quoted 3 lines

active_since, tells you how long a a still active wakelock has been active. If someone activated a wakelock and never released it, it will be obvious here.

Easily added. But you didn't mention any field saying whether the wakelock is currently active. That could be added too (although it would be racy -- but for detecting unreleased wakelocks you wouldn't care).

Quoted 2 lines

total_time, total time the wake lock has been active. This one should be obvious.

Also easily added.

Quoted 1 line

sleep_time, total time the wake lock has been active when the screen was off.

Not applicable to general systems. Is there anything like it that _would_ apply in general?

Quoted 4 lines

max_time, longest time the wakelock was active uninterrupted. This used less often, but the battery on a device was draining fast, but the problem went away before looking at the stats this will show if a wakelock was active for a long time.

Again, easily added. The only drawback is that all these additions will bloat the size of struct device. Of course, that's why you used separately-allocated structures for your wakelocks. Maybe we can change to do the same; it seems likely that the majority of device structures won't ever be used for wakeup events.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

and I would prefer that the kernel interfaces would encourage drivers to block suspend until user space has consumed the event, which works for the android user space, instead of just long enough to work with a hypothetical user space power manager.

Rafael doesn't _discourage_ drivers from doing this. However you have to keep in mind that many kernel developers are accustomed to working on systems (mostly PCs) with a different range of hardware devices from embedded systems like your phones. With PCI devices(*), for example, there's no clear point where a wakeup event gets handed off to userspace.

On the other hand, there's no reason the input layer shouldn't use pm_stay_awake and pm_relax. It simply hasn't been implemented yet.

Alan Stern

(*) Speaking of PCI devices, I'm not convinced that the way Rafael is using the pm_wakeup_event interface in the PCI core is entirely correct. The idea is to resolve the race between wakeup events and suspend. The code assumes that a wakeup event will be consumed in 100 ms or less, which is a reasonable assumption.

But what sorts of things qualify as wakeup events? Right now, the code handles only events coming by way of the PME# signal (or its platform equivalent). But that signal usually gets activated only when a PCI device is in a low-power mode; if the device is at full power then it simply generates an IRQ. It's the same event, but reported to the kernel in a different way. So consider...

Case 1: The system is suspending and the PCI device has already been
placed in D3hot when an event occurs. PME# is activated, the wakeup event is reported, the suspend is aborted, and the system won't try to suspend again for at least 100 ms. Good.

Case 2: The system is running normally and the PCI device is at full
power when an event occurs. PME# isn't activated and pm_wakeup_event doesn't get called. Then when the system tries to suspend 25 ms later, there's nothing to prevent it even though the event is still being processed. Bad.

In case 2 the race has not been resolved. It seems to me that the only proper solution is to call pm_wakeup_event for _every_ PCI interrupt. This may be too much to add to a hot path, but what's the alternative?

#254 lore raw
Quoted 1 line · Alan Stern

On Thu, 5 Aug 2010, Arve Hjønnevåg wrote:

...

Quoted 18 lines

But what sorts of things qualify as wakeup events? Right now, the code handles only events coming by way of the PME# signal (or its platform equivalent). But that signal usually gets activated only when a PCI device is in a low-power mode; if the device is at full power then it simply generates an IRQ. It's the same event, but reported to the kernel in a different way. So consider...

Case 1: The system is suspending and the PCI device has already been
placed in D3hot when an event occurs. PME# is activated, the wakeup event is reported, the suspend is aborted, and the system won't try to suspend again for at least 100 ms. Good.

Case 2: The system is running normally and the PCI device is at full
power when an event occurs. PME# isn't activated and pm_wakeup_event doesn't get called. Then when the system tries to suspend 25 ms later, there's nothing to prevent it even though the event is still being processed. Bad.

Quoted 4 lines

In case 2 the race has not been resolved. It seems to me that the only proper solution is to call pm_wakeup_event for _every_ PCI interrupt. This may be too much to add to a hot path, but what's the alternative?

Arguably not every PCI interrupt should be regarded as a wakeup event, so I think we can simply say in the cases when that's necessary the driver should be responsible for using pm_wakeup_event() or pm_stay_awake() / pm_relax() as appropriate.

My patch only added it to the bus-level code which covered the PME-based wakeup events that _cannot_ be handled by device drivers.

Thanks,
Rafael

#255 lore raw
In reply to Alan Stern
Quoted 1 line · Alan Stern

On Thu, 5 Aug 2010, Arve Hjønnevåg wrote:

...

Quoted 18 lines

But what sorts of things qualify as wakeup events? Right now, the code handles only events coming by way of the PME# signal (or its platform equivalent). But that signal usually gets activated only when a PCI device is in a low-power mode; if the device is at full power then it simply generates an IRQ. It's the same event, but reported to the kernel in a different way. So consider...

Case 1: The system is suspending and the PCI device has already been
placed in D3hot when an event occurs. PME# is activated, the wakeup event is reported, the suspend is aborted, and the system won't try to suspend again for at least 100 ms. Good.

Case 2: The system is running normally and the PCI device is at full
power when an event occurs. PME# isn't activated and pm_wakeup_event doesn't get called. Then when the system tries to suspend 25 ms later, there's nothing to prevent it even though the event is still being processed. Bad.

Quoted 4 lines

In case 2 the race has not been resolved. It seems to me that the only proper solution is to call pm_wakeup_event for _every_ PCI interrupt. This may be too much to add to a hot path, but what's the alternative?

Arguably not every PCI interrupt should be regarded as a wakeup event, so I think we can simply say in the cases when that's necessary the driver should be responsible for using pm_wakeup_event() or pm_stay_awake() / pm_relax() as appropriate.

My patch only added it to the bus-level code which covered the PME-based wakeup events that _cannot_ be handled by device drivers.

Thanks,
Rafael

#256 lore raw
Quoted 26 lines · Rafael J. Wysocki
Quoted 1 line · Alan Stern

On Thu, 5 Aug 2010, Arve Hjønnevåg wrote:

...

Quoted 18 lines

But what sorts of things qualify as wakeup events? Right now, the code handles only events coming by way of the PME# signal (or its platform equivalent). But that signal usually gets activated only when a PCI device is in a low-power mode; if the device is at full power then it simply generates an IRQ. It's the same event, but reported to the kernel in a different way. So consider...

Case 1: The system is suspending and the PCI device has already been
placed in D3hot when an event occurs. PME# is activated, the wakeup event is reported, the suspend is aborted, and the system won't try to suspend again for at least 100 ms. Good.

Case 2: The system is running normally and the PCI device is at full
power when an event occurs. PME# isn't activated and pm_wakeup_event doesn't get called. Then when the system tries to suspend 25 ms later, there's nothing to prevent it even though the event is still being processed. Bad.

Quoted 4 lines

In case 2 the race has not been resolved. It seems to me that the only proper solution is to call pm_wakeup_event for _every_ PCI interrupt. This may be too much to add to a hot path, but what's the alternative?

Quoted 7 lines

Arguably not every PCI interrupt should be regarded as a wakeup event, so I think we can simply say in the cases when that's necessary the driver should be responsible for using pm_wakeup_event() or pm_stay_awake() / pm_relax() as appropriate.

My patch only added it to the bus-level code which covered the PME-based wakeup events that _cannot_ be handled by device drivers.

Also please note that it depends a good deal on the definition of a "wakeup event". Under the definition used when my patch was being developed, ie. that wakeup events are the events that would wake up the system from a sleep state, PCI interrupts cannot be wakeup events, unless the given device remains in the full power state although the system has been suspended (standard PCI devices are not allowed to generate signals except for PME from low-power states).

Thanks,
Rafael

#257 lore raw
In reply to Rafael J. Wysocki
Quoted 26 lines · Rafael J. Wysocki
Quoted 1 line · Alan Stern

On Thu, 5 Aug 2010, Arve Hjønnevåg wrote:

...

Quoted 18 lines

But what sorts of things qualify as wakeup events? Right now, the code handles only events coming by way of the PME# signal (or its platform equivalent). But that signal usually gets activated only when a PCI device is in a low-power mode; if the device is at full power then it simply generates an IRQ. It's the same event, but reported to the kernel in a different way. So consider...

Case 1: The system is suspending and the PCI device has already been
placed in D3hot when an event occurs. PME# is activated, the wakeup event is reported, the suspend is aborted, and the system won't try to suspend again for at least 100 ms. Good.

Case 2: The system is running normally and the PCI device is at full
power when an event occurs. PME# isn't activated and pm_wakeup_event doesn't get called. Then when the system tries to suspend 25 ms later, there's nothing to prevent it even though the event is still being processed. Bad.

Quoted 4 lines

In case 2 the race has not been resolved. It seems to me that the only proper solution is to call pm_wakeup_event for _every_ PCI interrupt. This may be too much to add to a hot path, but what's the alternative?

Quoted 7 lines

Arguably not every PCI interrupt should be regarded as a wakeup event, so I think we can simply say in the cases when that's necessary the driver should be responsible for using pm_wakeup_event() or pm_stay_awake() / pm_relax() as appropriate.

My patch only added it to the bus-level code which covered the PME-based wakeup events that _cannot_ be handled by device drivers.

Also please note that it depends a good deal on the definition of a "wakeup event". Under the definition used when my patch was being developed, ie. that wakeup events are the events that would wake up the system from a sleep state, PCI interrupts cannot be wakeup events, unless the given device remains in the full power state although the system has been suspended (standard PCI devices are not allowed to generate signals except for PME from low-power states).

Thanks,
Rafael

#258 lore raw
Quoted 7 lines · Rafael J. Wysocki
Quoted 7 lines

Arguably not every PCI interrupt should be regarded as a wakeup event, so I think we can simply say in the cases when that's necessary the driver should be responsible for using pm_wakeup_event() or pm_stay_awake() / pm_relax() as appropriate.

My patch only added it to the bus-level code which covered the PME-based wakeup events that _cannot_ be handled by device drivers.

In other words, your bus-level changes were a necessary but not sufficient start. I can buy that.

Quoted 6 lines

Also please note that it depends a good deal on the definition of a "wakeup event". Under the definition used when my patch was being developed, ie. that wakeup events are the events that would wake up the system from a sleep state, PCI interrupts cannot be wakeup events, unless the given device remains in the full power state although the system has been suspended (standard PCI devices are not allowed to generate signals except for PME from low-power states).

Um, what do you mean by "event"? Let's take a concrete example. Suppose you have a system where you want USB plug or unplug events to cause a wakeup. This is relevant to the discussion at hand if your USB host controller is a PCI device.

By your reckoning, a plug or unplug event that occurs while the system is asleep would be a wakeup event by definition. And yet you say that the same plug or unplug event occurring while the controller was at full power would not count as a wakeup event? And in particular, it should not prevent the system from suspending before the event can be fully processed? That doesn't make sense. The same event is the same event, regardless of the context in which it occurs. If it is treated as a wakeup event in context then it should be treated as a wakeup event in other contexts too.

Alan Stern

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

Arguably not every PCI interrupt should be regarded as a wakeup event, so I think we can simply say in the cases when that's necessary the driver should be responsible for using pm_wakeup_event() or pm_stay_awake() / pm_relax() as appropriate.

My patch only added it to the bus-level code which covered the PME-based wakeup events that _cannot_ be handled by device drivers.

In other words, your bus-level changes were a necessary but not sufficient start. I can buy that.

Quoted 6 lines

Also please note that it depends a good deal on the definition of a "wakeup event". Under the definition used when my patch was being developed, ie. that wakeup events are the events that would wake up the system from a sleep state, PCI interrupts cannot be wakeup events, unless the given device remains in the full power state although the system has been suspended (standard PCI devices are not allowed to generate signals except for PME from low-power states).

Um, what do you mean by "event"? Let's take a concrete example. Suppose you have a system where you want USB plug or unplug events to cause a wakeup. This is relevant to the discussion at hand if your USB host controller is a PCI device.

By your reckoning, a plug or unplug event that occurs while the system is asleep would be a wakeup event by definition. And yet you say that the same plug or unplug event occurring while the controller was at full power would not count as a wakeup event? And in particular, it should not prevent the system from suspending before the event can be fully processed? That doesn't make sense. The same event is the same event, regardless of the context in which it occurs. If it is treated as a wakeup event in context then it should be treated as a wakeup event in other contexts too.

Alan Stern

#260 lore raw
Quoted 25 lines · Alan Stern
Quoted 7 lines · Rafael J. Wysocki
Quoted 7 lines

Arguably not every PCI interrupt should be regarded as a wakeup event, so I think we can simply say in the cases when that's necessary the driver should be responsible for using pm_wakeup_event() or pm_stay_awake() / pm_relax() as appropriate.

My patch only added it to the bus-level code which covered the PME-based wakeup events that _cannot_ be handled by device drivers.

In other words, your bus-level changes were a necessary but not sufficient start. I can buy that.

Quoted 6 lines

Also please note that it depends a good deal on the definition of a "wakeup event". Under the definition used when my patch was being developed, ie. that wakeup events are the events that would wake up the system from a sleep state, PCI interrupts cannot be wakeup events, unless the given device remains in the full power state although the system has been suspended (standard PCI devices are not allowed to generate signals except for PME from low-power states).

Um, what do you mean by "event"? Let's take a concrete example. Suppose you have a system where you want USB plug or unplug events to cause a wakeup. This is relevant to the discussion at hand if your USB host controller is a PCI device.

Quoted 9 lines

By your reckoning, a plug or unplug event that occurs while the system is asleep would be a wakeup event by definition. And yet you say that the same plug or unplug event occurring while the controller was at full power would not count as a wakeup event? And in particular, it should not prevent the system from suspending before the event can be fully processed? That doesn't make sense. The same event is the same event, regardless of the context in which it occurs. If it is treated as a wakeup event in context then it should be treated as a wakeup event in other contexts too.

In this example the event is not a PCI interrupt itself, which is a consqeuence of the event, but the USB plug-unplug. So, whoever detects the plug-unplug should use pm_stay_awake() or pm_wakeup_event(). That may be an interrupt handler of a PCI USB controller, so if that is the case, the controller driver probably should use one of these functions in its interrupt handler. Still, that by no measn implies that _every_ PCI interrupt should in principle be regarded as a wakeup event.

Thanks,
Rafael

#261 lore raw
In reply to Alan Stern
Quoted 25 lines · Alan Stern
Quoted 7 lines · Rafael J. Wysocki
Quoted 7 lines

Arguably not every PCI interrupt should be regarded as a wakeup event, so I think we can simply say in the cases when that's necessary the driver should be responsible for using pm_wakeup_event() or pm_stay_awake() / pm_relax() as appropriate.

My patch only added it to the bus-level code which covered the PME-based wakeup events that _cannot_ be handled by device drivers.

In other words, your bus-level changes were a necessary but not sufficient start. I can buy that.

Quoted 6 lines

Also please note that it depends a good deal on the definition of a "wakeup event". Under the definition used when my patch was being developed, ie. that wakeup events are the events that would wake up the system from a sleep state, PCI interrupts cannot be wakeup events, unless the given device remains in the full power state although the system has been suspended (standard PCI devices are not allowed to generate signals except for PME from low-power states).

Um, what do you mean by "event"? Let's take a concrete example. Suppose you have a system where you want USB plug or unplug events to cause a wakeup. This is relevant to the discussion at hand if your USB host controller is a PCI device.

Quoted 9 lines

By your reckoning, a plug or unplug event that occurs while the system is asleep would be a wakeup event by definition. And yet you say that the same plug or unplug event occurring while the controller was at full power would not count as a wakeup event? And in particular, it should not prevent the system from suspending before the event can be fully processed? That doesn't make sense. The same event is the same event, regardless of the context in which it occurs. If it is treated as a wakeup event in context then it should be treated as a wakeup event in other contexts too.

In this example the event is not a PCI interrupt itself, which is a consqeuence of the event, but the USB plug-unplug. So, whoever detects the plug-unplug should use pm_stay_awake() or pm_wakeup_event(). That may be an interrupt handler of a PCI USB controller, so if that is the case, the controller driver probably should use one of these functions in its interrupt handler. Still, that by no measn implies that _every_ PCI interrupt should in principle be regarded as a wakeup event.

Thanks,
Rafael

#262 lore raw
Quoted 22 lines · Rafael J. Wysocki
Quoted 12 lines
Quoted 6 lines

Also please note that it depends a good deal on the definition of a "wakeup event". Under the definition used when my patch was being developed, ie. that wakeup events are the events that would wake up the system from a sleep state, PCI interrupts cannot be wakeup events, unless the given device remains in the full power state although the system has been suspended (standard PCI devices are not allowed to generate signals except for PME from low-power states).

Um, what do you mean by "event"? Let's take a concrete example. Suppose you have a system where you want USB plug or unplug events to cause a wakeup. This is relevant to the discussion at hand if your USB host controller is a PCI device.

Quoted 9 lines

By your reckoning, a plug or unplug event that occurs while the system is asleep would be a wakeup event by definition. And yet you say that the same plug or unplug event occurring while the controller was at full power would not count as a wakeup event? And in particular, it should not prevent the system from suspending before the event can be fully processed? That doesn't make sense. The same event is the same event, regardless of the context in which it occurs. If it is treated as a wakeup event in context then it should be treated as a wakeup event in other contexts too.

Quoted 7 lines

In this example the event is not a PCI interrupt itself, which is a consqeuence of the event, but the USB plug-unplug. So, whoever detects the plug-unplug should use pm_stay_awake() or pm_wakeup_event(). That may be an interrupt handler of a PCI USB controller, so if that is the case, the controller driver probably should use one of these functions in its interrupt handler. Still, that by no measn implies that _every_ PCI interrupt should in principle be regarded as a wakeup event.

Okay, agreed. I just wanted you to grant that some PCI interrupts should be treated like wakeup events even if they don't actually wake the system up from a sleep state. The "PCI interrupts cannot be wakeup events" statement is a little strong.

Alan Stern

#263 lore raw
In reply to Rafael J. Wysocki
Quoted 22 lines · Rafael J. Wysocki
Quoted 12 lines
Quoted 6 lines

Also please note that it depends a good deal on the definition of a "wakeup event". Under the definition used when my patch was being developed, ie. that wakeup events are the events that would wake up the system from a sleep state, PCI interrupts cannot be wakeup events, unless the given device remains in the full power state although the system has been suspended (standard PCI devices are not allowed to generate signals except for PME from low-power states).

Um, what do you mean by "event"? Let's take a concrete example. Suppose you have a system where you want USB plug or unplug events to cause a wakeup. This is relevant to the discussion at hand if your USB host controller is a PCI device.

Quoted 9 lines

By your reckoning, a plug or unplug event that occurs while the system is asleep would be a wakeup event by definition. And yet you say that the same plug or unplug event occurring while the controller was at full power would not count as a wakeup event? And in particular, it should not prevent the system from suspending before the event can be fully processed? That doesn't make sense. The same event is the same event, regardless of the context in which it occurs. If it is treated as a wakeup event in context then it should be treated as a wakeup event in other contexts too.

Quoted 7 lines

In this example the event is not a PCI interrupt itself, which is a consqeuence of the event, but the USB plug-unplug. So, whoever detects the plug-unplug should use pm_stay_awake() or pm_wakeup_event(). That may be an interrupt handler of a PCI USB controller, so if that is the case, the controller driver probably should use one of these functions in its interrupt handler. Still, that by no measn implies that _every_ PCI interrupt should in principle be regarded as a wakeup event.

Okay, agreed. I just wanted you to grant that some PCI interrupts should be treated like wakeup events even if they don't actually wake the system up from a sleep state. The "PCI interrupts cannot be wakeup events" statement is a little strong.

Alan Stern

#264 lore raw
In reply to Alan Stern

2010/8/6 Alan Stern <[email protected]>:

Quoted 9 lines · Arve Hjønnevåg
Quoted 5 lines

count, tells you how many times the wakelock was activated. If a wakelock prevented suspend for a long time a large count tells you it handled a lot of events while a small count tells you it took a long time to process the events, or the wakelock was not released properly.

As noted, we already have this.

Almost. We have it when a device is passed in.

Quoted 14 lines
Quoted 5 lines

expire_count, tells you how many times the timeout expired. For the input event wakelock in the android kernel (which has a timeout) an expire count that matches the count tells you that someone opened an input device but is not reading from it (this has happened several times).

This is a little tricky.  Rafael's model currently does not allow wakeup events started by pm_wakeup_event() to be cancelled any way other than by having their timer expire.  This essentially means that for some devices, expire_count will always be the same as count and for others it will always be 0.  To change this would require adding an extra timer struct, which could be done (in fact, an earlier version of the code included it).  It would be nice if we could avoid the need.

Quoted 3 lines

Does Android use any kernel-internal wakelocks both with a timer and with active cancellation?

I don't know if they are all kernel-internal but these drivers appear to use timeouts and active cancellation on the same wakelock:
wifi driver, mmc core, alarm driver, evdev (suspend blocker version removes the timeout).

Quoted 8 lines
Quoted 4 lines

wake_count, tells you that this is the first wakelock that was acquired in the resume path. This is currently less useful than I would like on the Nexus One since it is usually "SMD_RPCCALL" which does not tell me a lot.

This could be done easily enough, but if it's not very useful then there's no point.

It is useful there is no other way to tell what triggered a wakeup, but it would probably be better to just track wakeup interrupts/events elsewhere.

Quoted 9 lines
Quoted 3 lines

active_since, tells you how long a a still active wakelock has been active. If someone activated a wakelock and never released it, it will be obvious here.

Easily added.  But you didn't mention any field saying whether the wakelock is currently active.  That could be added too (although it would be racy -- but for detecting unreleased wakelocks you wouldn't care).

These are the reported stats, not the fields in the stats structure. The wakelock code has an active flag. If we want to keep the pm_stay_wake nesting (which I would argue against), we would need an active count. It would also require a handle, which is a change Rafael said would not fly.

Quoted 5 lines
Quoted 2 lines

total_time, total time the wake lock has been active. This one should be obvious.

Also easily added.

Only with a handle passed to all the calls.

Quoted 5 lines
Quoted 1 line

sleep_time, total time the wake lock has been active when the screen was off.

Not applicable to general systems.  Is there anything like it that _would_ apply in general?

The screen off is how it is used on android, the stats is keyed of what user space wrote to /sys/power/state. If "on" was written the sleep time is not updated.

Quoted 11 lines
Quoted 4 lines

max_time, longest time the wakelock was active uninterrupted. This used less often, but the battery on a device was draining fast, but the problem went away before looking at the stats this will show if a wakelock was active for a long time.

Again, easily added.  The only drawback is that all these additions will bloat the size of struct device.  Of course, that's why you used separately-allocated structures for your wakelocks.  Maybe we can change to do the same; it seems likely that the majority of device structures won't ever be used for wakeup events.

Since many wakelocks are not associated with s struct device we need a separate object for this anyway.

Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

and I would prefer that the kernel interfaces would encourage drivers to block suspend until user space has consumed the event, which works for the android user space, instead of just long enough to work with a hypothetical user space power manager.

Rafael doesn't _discourage_ drivers from doing this.  However you have to keep in mind that many kernel developers are accustomed to working on systems (mostly PCs) with a different range of hardware devices from embedded systems like your phones.  With PCI devices(*), for example, there's no clear point where a wakeup event gets handed off to userspace.

Quoted 2 lines

On the other hand, there's no reason the input layer shouldn't use pm_stay_awake and pm_relax.  It simply hasn't been implemented yet.

...

The merged user space interface makes this unclear to me. When I first used suspend on android I had a power manager process that opened all the input devices and reset a screen off timeout every time there was an input event. If the input layer uses pm_stay_awake to block suspend when the queue is not empty, this will deadlock with the current interface since reading the wake count will block forever if an input event occurred right after the power manager decides to suspend.

Signature · 1 line
Arve Hjønnevåg
#265 lore raw
In reply to Alan Stern

2010/8/6 Alan Stern <[email protected]>:

Quoted 9 lines · Arve Hjønnevåg
Quoted 5 lines

count, tells you how many times the wakelock was activated. If a wakelock prevented suspend for a long time a large count tells you it handled a lot of events while a small count tells you it took a long time to process the events, or the wakelock was not released properly.

As noted, we already have this.

Almost. We have it when a device is passed in.

Quoted 14 lines
Quoted 5 lines

expire_count, tells you how many times the timeout expired. For the input event wakelock in the android kernel (which has a timeout) an expire count that matches the count tells you that someone opened an input device but is not reading from it (this has happened several times).

This is a little tricky.  Rafael's model currently does not allow wakeup events started by pm_wakeup_event() to be cancelled any way other than by having their timer expire.  This essentially means that for some devices, expire_count will always be the same as count and for others it will always be 0.  To change this would require adding an extra timer struct, which could be done (in fact, an earlier version of the code included it).  It would be nice if we could avoid the need.

Quoted 3 lines

Does Android use any kernel-internal wakelocks both with a timer and with active cancellation?

I don't know if they are all kernel-internal but these drivers appear to use timeouts and active cancellation on the same wakelock:
wifi driver, mmc core, alarm driver, evdev (suspend blocker version removes the timeout).

Quoted 8 lines
Quoted 4 lines

wake_count, tells you that this is the first wakelock that was acquired in the resume path. This is currently less useful than I would like on the Nexus One since it is usually "SMD_RPCCALL" which does not tell me a lot.

This could be done easily enough, but if it's not very useful then there's no point.

It is useful there is no other way to tell what triggered a wakeup, but it would probably be better to just track wakeup interrupts/events elsewhere.

Quoted 9 lines
Quoted 3 lines

active_since, tells you how long a a still active wakelock has been active. If someone activated a wakelock and never released it, it will be obvious here.

Easily added.  But you didn't mention any field saying whether the wakelock is currently active.  That could be added too (although it would be racy -- but for detecting unreleased wakelocks you wouldn't care).

These are the reported stats, not the fields in the stats structure. The wakelock code has an active flag. If we want to keep the pm_stay_wake nesting (which I would argue against), we would need an active count. It would also require a handle, which is a change Rafael said would not fly.

Quoted 5 lines
Quoted 2 lines

total_time, total time the wake lock has been active. This one should be obvious.

Also easily added.

Only with a handle passed to all the calls.

Quoted 5 lines
Quoted 1 line

sleep_time, total time the wake lock has been active when the screen was off.

Not applicable to general systems.  Is there anything like it that _would_ apply in general?

The screen off is how it is used on android, the stats is keyed of what user space wrote to /sys/power/state. If "on" was written the sleep time is not updated.

Quoted 11 lines
Quoted 4 lines

max_time, longest time the wakelock was active uninterrupted. This used less often, but the battery on a device was draining fast, but the problem went away before looking at the stats this will show if a wakelock was active for a long time.

Again, easily added.  The only drawback is that all these additions will bloat the size of struct device.  Of course, that's why you used separately-allocated structures for your wakelocks.  Maybe we can change to do the same; it seems likely that the majority of device structures won't ever be used for wakeup events.

Since many wakelocks are not associated with s struct device we need a separate object for this anyway.

Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

and I would prefer that the kernel interfaces would encourage drivers to block suspend until user space has consumed the event, which works for the android user space, instead of just long enough to work with a hypothetical user space power manager.

Rafael doesn't _discourage_ drivers from doing this.  However you have to keep in mind that many kernel developers are accustomed to working on systems (mostly PCs) with a different range of hardware devices from embedded systems like your phones.  With PCI devices(*), for example, there's no clear point where a wakeup event gets handed off to userspace.

Quoted 2 lines

On the other hand, there's no reason the input layer shouldn't use pm_stay_awake and pm_relax.  It simply hasn't been implemented yet.

...

The merged user space interface makes this unclear to me. When I first used suspend on android I had a power manager process that opened all the input devices and reset a screen off timeout every time there was an input event. If the input layer uses pm_stay_awake to block suspend when the queue is not empty, this will deadlock with the current interface since reading the wake count will block forever if an input event occurred right after the power manager decides to suspend.

Signature · 1 line
Arve Hjønnevåg
#266 lore raw
Quoted 8 lines · Arve Hjønnevåg

2010/8/6 Alan Stern <[email protected]>:

Quoted 7 lines · Arve Hjønnevåg
Quoted 5 lines

count, tells you how many times the wakelock was activated. If a wakelock prevented suspend for a long time a large count tells you it handled a lot of events while a small count tells you it took a long time to process the events, or the wakelock was not released properly.

Quoted 4 lines
Quoted 2 lines

As noted, we already have this.

Almost. We have it when a device is passed in.

Sure. And what are the other cases (details, please)?

Quoted 14 lines
Quoted 14 lines
Quoted 5 lines

expire_count, tells you how many times the timeout expired. For the input event wakelock in the android kernel (which has a timeout) an expire count that matches the count tells you that someone opened an input device but is not reading from it (this has happened several times).

This is a little tricky. Rafael's model currently does not allow wakeup events started by pm_wakeup_event() to be cancelled any way other than by having their timer expire. This essentially means that for some devices, expire_count will always be the same as count and for others it will always be 0. To change this would require adding an extra timer struct, which could be done (in fact, an earlier version of the code included it). It would be nice if we could avoid the need.

Quoted 8 lines
Quoted 3 lines

Does Android use any kernel-internal wakelocks both with a timer and with active cancellation?

I don't know if they are all kernel-internal but these drivers appear to use timeouts and active cancellation on the same wakelock:
wifi driver, mmc core, alarm driver, evdev (suspend blocker version removes the timeout).

You previously said you didn't need timeouted wakelocks in the kernel, so I guess that was incorrect.

Quoted 28 lines
Quoted 8 lines
Quoted 4 lines

wake_count, tells you that this is the first wakelock that was acquired in the resume path. This is currently less useful than I would like on the Nexus One since it is usually "SMD_RPCCALL" which does not tell me a lot.

This could be done easily enough, but if it's not very useful then there's no point.

It is useful there is no other way to tell what triggered a wakeup, but it would probably be better to just track wakeup interrupts/events elsewhere.

Quoted 9 lines
Quoted 3 lines

active_since, tells you how long a a still active wakelock has been active. If someone activated a wakelock and never released it, it will be obvious here.

Easily added. But you didn't mention any field saying whether the wakelock is currently active. That could be added too (although it would be racy -- but for detecting unreleased wakelocks you wouldn't care).

These are the reported stats, not the fields in the stats structure. The wakelock code has an active flag. If we want to keep the pm_stay_wake nesting (which I would argue against), we would need an active count. It would also require a handle, which is a change Rafael said would not fly.

Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

total_time, total time the wake lock has been active. This one should be obvious.

Also easily added.

Only with a handle passed to all the calls.

Well, I'm kind of tired of this "my solution is the only acceptable one" mindset. IMHO, it's totally counter productive.

Quoted 41 lines
Quoted 5 lines
Quoted 1 line

sleep_time, total time the wake lock has been active when the screen was off.

Not applicable to general systems. Is there anything like it that _would_ apply in general?

The screen off is how it is used on android, the stats is keyed of what user space wrote to /sys/power/state. If "on" was written the sleep time is not updated.

Quoted 11 lines
Quoted 4 lines

max_time, longest time the wakelock was active uninterrupted. This used less often, but the battery on a device was draining fast, but the problem went away before looking at the stats this will show if a wakelock was active for a long time.

Again, easily added. The only drawback is that all these additions will bloat the size of struct device. Of course, that's why you used separately-allocated structures for your wakelocks. Maybe we can change to do the same; it seems likely that the majority of device structures won't ever be used for wakeup events.

Since many wakelocks are not associated with s struct device we need a separate object for this anyway.

Quoted 14 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

and I would prefer that the kernel interfaces would encourage drivers to block suspend until user space has consumed the event, which works for the android user space, instead of just long enough to work with a hypothetical user space power manager.

Rafael doesn't _discourage_ drivers from doing this. However you have to keep in mind that many kernel developers are accustomed to working on systems (mostly PCs) with a different range of hardware devices from embedded systems like your phones. With PCI devices(*), for example, there's no clear point where a wakeup event gets handed off to userspace.

On the other hand, there's no reason the input layer shouldn't use pm_stay_awake and pm_relax. It simply hasn't been implemented yet.

...

Quoted 7 lines

The merged user space interface makes this unclear to me. When I first used suspend on android I had a power manager process that opened all the input devices and reset a screen off timeout every time there was an input event. If the input layer uses pm_stay_awake to block suspend when the queue is not empty, this will deadlock with the current interface since reading the wake count will block forever if an input event occurred right after the power manager decides to suspend.

No, in that case suspend will be aborted, IIUC.

Thanks,
Rafael

#267 lore raw
In reply to Arve Hjønnevåg
Quoted 8 lines · Arve Hjønnevåg

2010/8/6 Alan Stern <[email protected]>:

Quoted 7 lines · Arve Hjønnevåg
Quoted 5 lines

count, tells you how many times the wakelock was activated. If a wakelock prevented suspend for a long time a large count tells you it handled a lot of events while a small count tells you it took a long time to process the events, or the wakelock was not released properly.

Quoted 4 lines
Quoted 2 lines

As noted, we already have this.

Almost. We have it when a device is passed in.

Sure. And what are the other cases (details, please)?

Quoted 14 lines
Quoted 14 lines
Quoted 5 lines

expire_count, tells you how many times the timeout expired. For the input event wakelock in the android kernel (which has a timeout) an expire count that matches the count tells you that someone opened an input device but is not reading from it (this has happened several times).

This is a little tricky. Rafael's model currently does not allow wakeup events started by pm_wakeup_event() to be cancelled any way other than by having their timer expire. This essentially means that for some devices, expire_count will always be the same as count and for others it will always be 0. To change this would require adding an extra timer struct, which could be done (in fact, an earlier version of the code included it). It would be nice if we could avoid the need.

Quoted 8 lines
Quoted 3 lines

Does Android use any kernel-internal wakelocks both with a timer and with active cancellation?

I don't know if they are all kernel-internal but these drivers appear to use timeouts and active cancellation on the same wakelock:
wifi driver, mmc core, alarm driver, evdev (suspend blocker version removes the timeout).

You previously said you didn't need timeouted wakelocks in the kernel, so I guess that was incorrect.

Quoted 28 lines
Quoted 8 lines
Quoted 4 lines

wake_count, tells you that this is the first wakelock that was acquired in the resume path. This is currently less useful than I would like on the Nexus One since it is usually "SMD_RPCCALL" which does not tell me a lot.

This could be done easily enough, but if it's not very useful then there's no point.

It is useful there is no other way to tell what triggered a wakeup, but it would probably be better to just track wakeup interrupts/events elsewhere.

Quoted 9 lines
Quoted 3 lines

active_since, tells you how long a a still active wakelock has been active. If someone activated a wakelock and never released it, it will be obvious here.

Easily added. But you didn't mention any field saying whether the wakelock is currently active. That could be added too (although it would be racy -- but for detecting unreleased wakelocks you wouldn't care).

These are the reported stats, not the fields in the stats structure. The wakelock code has an active flag. If we want to keep the pm_stay_wake nesting (which I would argue against), we would need an active count. It would also require a handle, which is a change Rafael said would not fly.

Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

total_time, total time the wake lock has been active. This one should be obvious.

Also easily added.

Only with a handle passed to all the calls.

Well, I'm kind of tired of this "my solution is the only acceptable one" mindset. IMHO, it's totally counter productive.

Quoted 41 lines
Quoted 5 lines
Quoted 1 line

sleep_time, total time the wake lock has been active when the screen was off.

Not applicable to general systems. Is there anything like it that _would_ apply in general?

The screen off is how it is used on android, the stats is keyed of what user space wrote to /sys/power/state. If "on" was written the sleep time is not updated.

Quoted 11 lines
Quoted 4 lines

max_time, longest time the wakelock was active uninterrupted. This used less often, but the battery on a device was draining fast, but the problem went away before looking at the stats this will show if a wakelock was active for a long time.

Again, easily added. The only drawback is that all these additions will bloat the size of struct device. Of course, that's why you used separately-allocated structures for your wakelocks. Maybe we can change to do the same; it seems likely that the majority of device structures won't ever be used for wakeup events.

Since many wakelocks are not associated with s struct device we need a separate object for this anyway.

Quoted 14 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

and I would prefer that the kernel interfaces would encourage drivers to block suspend until user space has consumed the event, which works for the android user space, instead of just long enough to work with a hypothetical user space power manager.

Rafael doesn't _discourage_ drivers from doing this. However you have to keep in mind that many kernel developers are accustomed to working on systems (mostly PCs) with a different range of hardware devices from embedded systems like your phones. With PCI devices(*), for example, there's no clear point where a wakeup event gets handed off to userspace.

On the other hand, there's no reason the input layer shouldn't use pm_stay_awake and pm_relax. It simply hasn't been implemented yet.

...

Quoted 7 lines

The merged user space interface makes this unclear to me. When I first used suspend on android I had a power manager process that opened all the input devices and reset a screen off timeout every time there was an input event. If the input layer uses pm_stay_awake to block suspend when the queue is not empty, this will deadlock with the current interface since reading the wake count will block forever if an input event occurred right after the power manager decides to suspend.

No, in that case suspend will be aborted, IIUC.

Thanks,
Rafael

#268 lore raw

2010/8/7 Rafael J. Wysocki <[email protected]>:

Quoted 9 lines · Arve Hjønnevåg
Quoted 8 lines

2010/8/6 Alan Stern <[email protected]>:

Quoted 7 lines · Arve Hjønnevåg
Quoted 5 lines

count, tells you how many times the wakelock was activated. If a wakelock prevented suspend for a long time a large count tells you it handled a lot of events while a small count tells you it took a long time to process the events, or the wakelock was not released properly.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

As noted, we already have this.

Almost. We have it when a device is passed in.

Sure.  And what are the other cases (details, please)?

The suspend blockers I added I my suspend blocker patchset were not directly associated with a device. The evdev changes could be modified to share a device, but it would give less detail since a separate queue is created for each client that opens the device. The suspend blocking work api would have to change so the caller to passes a device in, which I think would make that api less flexible. Mostly the problem is that we need separate stats for wakelocks created by a single driver. For instance we will still need a user-space interface to block suspend on android devices (lower level services than the power manager need to block suspend), with the stats in the device struct we have to create a new device for every wakelock user space creates in the kernel.

There is also the issue of reading the stats. It is a lot easier to read a single stats file, than looping though every device on the system (when most of the devices never block suspend).

Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
Quoted 5 lines

expire_count, tells you how many times the timeout expired. For the input event wakelock in the android kernel (which has a timeout) an expire count that matches the count tells you that someone opened an input device but is not reading from it (this has happened several times).

This is a little tricky.  Rafael's model currently does not allow wakeup events started by pm_wakeup_event() to be cancelled any way other than by having their timer expire.  This essentially means that for some devices, expire_count will always be the same as count and for others it will always be 0.  To change this would require adding an extra timer struct, which could be done (in fact, an earlier version of the code included it).  It would be nice if we could avoid the need.

Does Android use any kernel-internal wakelocks both with a timer and with active cancellation?

Quoted 8 lines
Quoted 4 lines

I don't know if they are all kernel-internal but these drivers appear to use timeouts and active cancellation on the same wakelock:
wifi driver, mmc core, alarm driver, evdev (suspend blocker version removes the timeout).

You previously said you didn't need timeouted wakelocks in the kernel, so I guess that was incorrect.

I don't know what you are reffering to. We have always stated that we need timeouts in the kernel to pass events through other kernel layers that do not use wakelocks (that list is much longer than the list above which mixes timeouts and unlock on the same wakelock). The only feature we do not use is the timeout feature in the user space interface to kernel wakelocks.

Quoted 31 lines
Quoted 31 lines
Quoted 8 lines
Quoted 4 lines

wake_count, tells you that this is the first wakelock that was acquired in the resume path. This is currently less useful than I would like on the Nexus One since it is usually "SMD_RPCCALL" which does not tell me a lot.

This could be done easily enough, but if it's not very useful then there's no point.

It is useful there is no other way to tell what triggered a wakeup, but it would probably be better to just track wakeup interrupts/events elsewhere.

Quoted 9 lines
Quoted 3 lines

active_since, tells you how long a a still active wakelock has been active. If someone activated a wakelock and never released it, it will be obvious here.

Easily added.  But you didn't mention any field saying whether the wakelock is currently active.  That could be added too (although it would be racy -- but for detecting unreleased wakelocks you wouldn't care).

These are the reported stats, not the fields in the stats structure. The wakelock code has an active flag. If we want to keep the pm_stay_wake nesting (which I would argue against), we would need an active count. It would also require a handle, which is a change Rafael said would not fly.

Quoted 3 lines
Quoted 2 lines

total_time, total time the wake lock has been active. This one should be obvious.

Quoted 7 lines
Quoted 3 lines
Quoted 2 lines

Also easily added.

Only with a handle passed to all the calls.

Well, I'm kind of tired of this "my solution is the only acceptable one" mindset.  IMHO, it's totally counter productive.

How do you propose to track how long a driver has blocked suspend when you have an unblock call that takes no arguments.

Quoted 49 lines
Quoted 41 lines
Quoted 5 lines
Quoted 1 line

sleep_time, total time the wake lock has been active when the screen was off.

Not applicable to general systems.  Is there anything like it that _would_ apply in general?

The screen off is how it is used on android, the stats is keyed of what user space wrote to /sys/power/state. If "on" was written the sleep time is not updated.

Quoted 11 lines
Quoted 4 lines

max_time, longest time the wakelock was active uninterrupted. This used less often, but the battery on a device was draining fast, but the problem went away before looking at the stats this will show if a wakelock was active for a long time.

Again, easily added.  The only drawback is that all these additions will bloat the size of struct device.  Of course, that's why you used separately-allocated structures for your wakelocks.  Maybe we can change to do the same; it seems likely that the majority of device structures won't ever be used for wakeup events.

Since many wakelocks are not associated with s struct device we need a separate object for this anyway.

Quoted 14 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

and I would prefer that the kernel interfaces would encourage drivers to block suspend until user space has consumed the event, which works for the android user space, instead of just long enough to work with a hypothetical user space power manager.

Rafael doesn't _discourage_ drivers from doing this.  However you have to keep in mind that many kernel developers are accustomed to working on systems (mostly PCs) with a different range of hardware devices from embedded systems like your phones.  With PCI devices(*), for example, there's no clear point where a wakeup event gets handed off to userspace.

On the other hand, there's no reason the input layer shouldn't use pm_stay_awake and pm_relax.  It simply hasn't been implemented yet.

...

Quoted 7 lines

The merged user space interface makes this unclear to me. When I first used suspend on android I had a power manager process that opened all the input devices and reset a screen off timeout every time there was an input event. If the input layer uses pm_stay_awake to block suspend when the queue is not empty, this will deadlock with the current interface since reading the wake count will block forever if an input event occurred right after the power manager decides to suspend.

Quoted 2 lines

No, in that case suspend will be aborted, IIUC.

How? Your pm_get_wakeup_count function loops until events_in_progress becomes 0.

Signature · 1 line
Arve Hjønnevåg
#269 lore raw
In reply to Rafael J. Wysocki

2010/8/7 Rafael J. Wysocki <[email protected]>:

Quoted 9 lines · Arve Hjønnevåg
Quoted 8 lines

2010/8/6 Alan Stern <[email protected]>:

Quoted 7 lines · Arve Hjønnevåg
Quoted 5 lines

count, tells you how many times the wakelock was activated. If a wakelock prevented suspend for a long time a large count tells you it handled a lot of events while a small count tells you it took a long time to process the events, or the wakelock was not released properly.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

As noted, we already have this.

Almost. We have it when a device is passed in.

Sure.  And what are the other cases (details, please)?

The suspend blockers I added I my suspend blocker patchset were not directly associated with a device. The evdev changes could be modified to share a device, but it would give less detail since a separate queue is created for each client that opens the device. The suspend blocking work api would have to change so the caller to passes a device in, which I think would make that api less flexible. Mostly the problem is that we need separate stats for wakelocks created by a single driver. For instance we will still need a user-space interface to block suspend on android devices (lower level services than the power manager need to block suspend), with the stats in the device struct we have to create a new device for every wakelock user space creates in the kernel.

There is also the issue of reading the stats. It is a lot easier to read a single stats file, than looping though every device on the system (when most of the devices never block suspend).

Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
Quoted 5 lines

expire_count, tells you how many times the timeout expired. For the input event wakelock in the android kernel (which has a timeout) an expire count that matches the count tells you that someone opened an input device but is not reading from it (this has happened several times).

This is a little tricky.  Rafael's model currently does not allow wakeup events started by pm_wakeup_event() to be cancelled any way other than by having their timer expire.  This essentially means that for some devices, expire_count will always be the same as count and for others it will always be 0.  To change this would require adding an extra timer struct, which could be done (in fact, an earlier version of the code included it).  It would be nice if we could avoid the need.

Does Android use any kernel-internal wakelocks both with a timer and with active cancellation?

Quoted 8 lines
Quoted 4 lines

I don't know if they are all kernel-internal but these drivers appear to use timeouts and active cancellation on the same wakelock:
wifi driver, mmc core, alarm driver, evdev (suspend blocker version removes the timeout).

You previously said you didn't need timeouted wakelocks in the kernel, so I guess that was incorrect.

I don't know what you are reffering to. We have always stated that we need timeouts in the kernel to pass events through other kernel layers that do not use wakelocks (that list is much longer than the list above which mixes timeouts and unlock on the same wakelock). The only feature we do not use is the timeout feature in the user space interface to kernel wakelocks.

Quoted 31 lines
Quoted 31 lines
Quoted 8 lines
Quoted 4 lines

wake_count, tells you that this is the first wakelock that was acquired in the resume path. This is currently less useful than I would like on the Nexus One since it is usually "SMD_RPCCALL" which does not tell me a lot.

This could be done easily enough, but if it's not very useful then there's no point.

It is useful there is no other way to tell what triggered a wakeup, but it would probably be better to just track wakeup interrupts/events elsewhere.

Quoted 9 lines
Quoted 3 lines

active_since, tells you how long a a still active wakelock has been active. If someone activated a wakelock and never released it, it will be obvious here.

Easily added.  But you didn't mention any field saying whether the wakelock is currently active.  That could be added too (although it would be racy -- but for detecting unreleased wakelocks you wouldn't care).

These are the reported stats, not the fields in the stats structure. The wakelock code has an active flag. If we want to keep the pm_stay_wake nesting (which I would argue against), we would need an active count. It would also require a handle, which is a change Rafael said would not fly.

Quoted 3 lines
Quoted 2 lines

total_time, total time the wake lock has been active. This one should be obvious.

Quoted 7 lines
Quoted 3 lines
Quoted 2 lines

Also easily added.

Only with a handle passed to all the calls.

Well, I'm kind of tired of this "my solution is the only acceptable one" mindset.  IMHO, it's totally counter productive.

How do you propose to track how long a driver has blocked suspend when you have an unblock call that takes no arguments.

Quoted 49 lines
Quoted 41 lines
Quoted 5 lines
Quoted 1 line

sleep_time, total time the wake lock has been active when the screen was off.

Not applicable to general systems.  Is there anything like it that _would_ apply in general?

The screen off is how it is used on android, the stats is keyed of what user space wrote to /sys/power/state. If "on" was written the sleep time is not updated.

Quoted 11 lines
Quoted 4 lines

max_time, longest time the wakelock was active uninterrupted. This used less often, but the battery on a device was draining fast, but the problem went away before looking at the stats this will show if a wakelock was active for a long time.

Again, easily added.  The only drawback is that all these additions will bloat the size of struct device.  Of course, that's why you used separately-allocated structures for your wakelocks.  Maybe we can change to do the same; it seems likely that the majority of device structures won't ever be used for wakeup events.

Since many wakelocks are not associated with s struct device we need a separate object for this anyway.

Quoted 14 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

and I would prefer that the kernel interfaces would encourage drivers to block suspend until user space has consumed the event, which works for the android user space, instead of just long enough to work with a hypothetical user space power manager.

Rafael doesn't _discourage_ drivers from doing this.  However you have to keep in mind that many kernel developers are accustomed to working on systems (mostly PCs) with a different range of hardware devices from embedded systems like your phones.  With PCI devices(*), for example, there's no clear point where a wakeup event gets handed off to userspace.

On the other hand, there's no reason the input layer shouldn't use pm_stay_awake and pm_relax.  It simply hasn't been implemented yet.

...

Quoted 7 lines

The merged user space interface makes this unclear to me. When I first used suspend on android I had a power manager process that opened all the input devices and reset a screen off timeout every time there was an input event. If the input layer uses pm_stay_awake to block suspend when the queue is not empty, this will deadlock with the current interface since reading the wake count will block forever if an input event occurred right after the power manager decides to suspend.

Quoted 2 lines

No, in that case suspend will be aborted, IIUC.

How? Your pm_get_wakeup_count function loops until events_in_progress becomes 0.

Signature · 1 line
Arve Hjønnevåg
#270 lore raw

2010/8/7 Arve Hjønnevåg <[email protected]>:

Quoted 4 lines

2010/8/7 Rafael J. Wysocki <[email protected]>:

Quoted 3 lines · Arve Hjønnevåg
Quoted 2 lines

2010/8/6 Alan Stern <[email protected]>:

Quoted 1 line · Arve Hjønnevåg

...

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

total_time, total time the wake lock has been active. This one should be obvious.

Also easily added.

Quoted 9 lines
Quoted 5 lines
Quoted 1 line

Only with a handle passed to all the calls.

Well, I'm kind of tired of this "my solution is the only acceptable one" mindset.  IMHO, it's totally counter productive.

How do you propose to track how long a driver has blocked suspend when you have an unblock call that takes no arguments.

Also, I did not not see a response to my question about why you don't want to pass a handle.

Signature · 1 line
Arve Hjønnevåg
#271 lore raw
In reply to Arve Hjønnevåg

2010/8/7 Arve Hjønnevåg <[email protected]>:

Quoted 4 lines

2010/8/7 Rafael J. Wysocki <[email protected]>:

Quoted 3 lines · Arve Hjønnevåg
Quoted 2 lines

2010/8/6 Alan Stern <[email protected]>:

Quoted 1 line · Arve Hjønnevåg

...

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

total_time, total time the wake lock has been active. This one should be obvious.

Also easily added.

Quoted 9 lines
Quoted 5 lines
Quoted 1 line

Only with a handle passed to all the calls.

Well, I'm kind of tired of this "my solution is the only acceptable one" mindset.  IMHO, it's totally counter productive.

How do you propose to track how long a driver has blocked suspend when you have an unblock call that takes no arguments.

Also, I did not not see a response to my question about why you don't want to pass a handle.

Signature · 1 line
Arve Hjønnevåg
#272 lore raw
Quoted 17 lines · Arve Hjønnevåg

2010/8/7 Arve Hjønnevåg <[email protected]>:

Quoted 4 lines

2010/8/7 Rafael J. Wysocki <[email protected]>:

Quoted 3 lines · Arve Hjønnevåg
Quoted 2 lines

2010/8/6 Alan Stern <[email protected]>:

Quoted 1 line · Arve Hjønnevåg

...

Quoted 11 lines
Quoted 10 lines
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

total_time, total time the wake lock has been active. This one should be obvious.

Also easily added.

Only with a handle passed to all the calls.

Well, I'm kind of tired of this "my solution is the only acceptable one" mindset. IMHO, it's totally counter productive.

Quoted 6 lines
Quoted 3 lines

How do you propose to track how long a driver has blocked suspend when you have an unblock call that takes no arguments.

Also, I did not not see a response to my question about why you don't want to pass a handle.

It doesn't really matter what I personally want. In fact, I'm not totally opposed to that idea, although there are disadvantages (eg. a "handle" would really mean a pointer to an object with certain life cycle that needs to be managed by the caller and it's not that clear to me who should manage the objects that the PCI wakeup code would pass to pm_wakeup_event(), for one example). I sent a pull request for your original patchset to Linus after all. :-)

I said I didn't think "it would fly", meaning that I was afraid the other kernel developers wouldn't like that change.

The reason why I think so is that you'd like to add a whole new infrastructure whose only purpose would be debugging that would only be useful to systems using opportunistic suspend. That, however, is only Android right now and it cannot use the mainline kernel for other reasons, so basically we would add infrastructure that's useful to no one.

Thanks,
Rafael

#273 lore raw
In reply to Arve Hjønnevåg
Quoted 17 lines · Arve Hjønnevåg

2010/8/7 Arve Hjønnevåg <[email protected]>:

Quoted 4 lines

2010/8/7 Rafael J. Wysocki <[email protected]>:

Quoted 3 lines · Arve Hjønnevåg
Quoted 2 lines

2010/8/6 Alan Stern <[email protected]>:

Quoted 1 line · Arve Hjønnevåg

...

Quoted 11 lines
Quoted 10 lines
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

total_time, total time the wake lock has been active. This one should be obvious.

Also easily added.

Only with a handle passed to all the calls.

Well, I'm kind of tired of this "my solution is the only acceptable one" mindset. IMHO, it's totally counter productive.

Quoted 6 lines
Quoted 3 lines

How do you propose to track how long a driver has blocked suspend when you have an unblock call that takes no arguments.

Also, I did not not see a response to my question about why you don't want to pass a handle.

It doesn't really matter what I personally want. In fact, I'm not totally opposed to that idea, although there are disadvantages (eg. a "handle" would really mean a pointer to an object with certain life cycle that needs to be managed by the caller and it's not that clear to me who should manage the objects that the PCI wakeup code would pass to pm_wakeup_event(), for one example). I sent a pull request for your original patchset to Linus after all. :-)

I said I didn't think "it would fly", meaning that I was afraid the other kernel developers wouldn't like that change.

The reason why I think so is that you'd like to add a whole new infrastructure whose only purpose would be debugging that would only be useful to systems using opportunistic suspend. That, however, is only Android right now and it cannot use the mainline kernel for other reasons, so basically we would add infrastructure that's useful to no one.

Thanks,
Rafael

#274 lore raw

2010/8/8 Rafael J. Wysocki <[email protected]>:

Quoted 22 lines · Arve Hjønnevåg
Quoted 21 lines

2010/8/7 Arve Hjønnevåg <[email protected]>:

Quoted 4 lines

2010/8/7 Rafael J. Wysocki <[email protected]>:

Quoted 3 lines · Arve Hjønnevåg
Quoted 2 lines

2010/8/6 Alan Stern <[email protected]>:

Quoted 1 line · Arve Hjønnevåg

...

Quoted 14 lines
Quoted 10 lines
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

total_time, total time the wake lock has been active. This one should be obvious.

Also easily added.

Only with a handle passed to all the calls.

Well, I'm kind of tired of this "my solution is the only acceptable one" mindset.  IMHO, it's totally counter productive.

How do you propose to track how long a driver has blocked suspend when you have an unblock call that takes no arguments.

Quoted 8 lines
Quoted 2 lines

Also, I did not not see a response to my question about why you don't want to pass a handle.

It doesn't really matter what I personally want.  In fact, I'm not totally opposed to that idea, although there are disadvantages (eg. a "handle" would really mean a pointer to an object with certain life cycle that needs to be managed by the caller and it's not that clear to me who should manage the objects that the PCI wakeup code would pass to pm_wakeup_event(), for one

Wouldn't a single global handle work for the way you are handling pci wakeup events? It looked like you just reset a global timeout every time a pci wakeup event occurs.

Quoted 11 lines

example).  I sent a pull request for your original patchset to Linus after all. :-)

I said I didn't think "it would fly", meaning that I was afraid the other kernel developers wouldn't like that change.

The reason why I think so is that you'd like to add a whole new infrastructure whose only purpose would be debugging that would only be useful to systems using opportunistic suspend.  That, however, is only Android right now and it cannot use the mainline kernel for other reasons, so basically we would add infrastructure that's useful to no one.

I'm not sure what you mean by this. The debugging is useful for anyone using the api, not just Android, and a handle is also needed to mix timeouts and pm_relax. The handle can be the device, but some drivers need several handles per device.

Signature · 1 line
Arve Hjønnevåg
#275 lore raw
In reply to Rafael J. Wysocki

2010/8/8 Rafael J. Wysocki <[email protected]>:

Quoted 22 lines · Arve Hjønnevåg
Quoted 21 lines

2010/8/7 Arve Hjønnevåg <[email protected]>:

Quoted 4 lines

2010/8/7 Rafael J. Wysocki <[email protected]>:

Quoted 3 lines · Arve Hjønnevåg
Quoted 2 lines

2010/8/6 Alan Stern <[email protected]>:

Quoted 1 line · Arve Hjønnevåg

...

Quoted 14 lines
Quoted 10 lines
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

total_time, total time the wake lock has been active. This one should be obvious.

Also easily added.

Only with a handle passed to all the calls.

Well, I'm kind of tired of this "my solution is the only acceptable one" mindset.  IMHO, it's totally counter productive.

How do you propose to track how long a driver has blocked suspend when you have an unblock call that takes no arguments.

Quoted 8 lines
Quoted 2 lines

Also, I did not not see a response to my question about why you don't want to pass a handle.

It doesn't really matter what I personally want.  In fact, I'm not totally opposed to that idea, although there are disadvantages (eg. a "handle" would really mean a pointer to an object with certain life cycle that needs to be managed by the caller and it's not that clear to me who should manage the objects that the PCI wakeup code would pass to pm_wakeup_event(), for one

Wouldn't a single global handle work for the way you are handling pci wakeup events? It looked like you just reset a global timeout every time a pci wakeup event occurs.

Quoted 11 lines

example).  I sent a pull request for your original patchset to Linus after all. :-)

I said I didn't think "it would fly", meaning that I was afraid the other kernel developers wouldn't like that change.

The reason why I think so is that you'd like to add a whole new infrastructure whose only purpose would be debugging that would only be useful to systems using opportunistic suspend.  That, however, is only Android right now and it cannot use the mainline kernel for other reasons, so basically we would add infrastructure that's useful to no one.

I'm not sure what you mean by this. The debugging is useful for anyone using the api, not just Android, and a handle is also needed to mix timeouts and pm_relax. The handle can be the device, but some drivers need several handles per device.

Signature · 1 line
Arve Hjønnevåg
#276 lore raw
Quoted 26 lines · Arve Hjønnevåg

2010/8/8 Rafael J. Wysocki <[email protected]>:

Quoted 25 lines · Arve Hjønnevåg
Quoted 23 lines

2010/8/7 Arve Hjønnevåg <[email protected]>:

Quoted 4 lines

2010/8/7 Rafael J. Wysocki <[email protected]>:

Quoted 3 lines · Arve Hjønnevåg
Quoted 2 lines

2010/8/6 Alan Stern <[email protected]>:

Quoted 1 line · Arve Hjønnevåg

...

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

total_time, total time the wake lock has been active. This one should be obvious.

Also easily added.

Quoted 9 lines
Quoted 5 lines
Quoted 1 line

Only with a handle passed to all the calls.

Well, I'm kind of tired of this "my solution is the only acceptable one" mindset. IMHO, it's totally counter productive.

How do you propose to track how long a driver has blocked suspend when you have an unblock call that takes no arguments.

Also, I did not not see a response to my question about why you don't want to pass a handle.

Quoted 8 lines
Quoted 5 lines

It doesn't really matter what I personally want. In fact, I'm not totally opposed to that idea, although there are disadvantages (eg. a "handle" would really mean a pointer to an object with certain life cycle that needs to be managed by the caller and it's not that clear to me who should manage the objects that the PCI wakeup code would pass to pm_wakeup_event(), for one

Wouldn't a single global handle work for the way you are handling pci wakeup events?

Not really, because I'd like to know the number of wakeups associated with the given device.

Quoted 2 lines

It looked like you just reset a global timeout every time a pci wakeup event occurs.

We bump up the per-device counter of wakeup events in addition to that.

Quoted 12 lines
Quoted 11 lines

example). I sent a pull request for your original patchset to Linus after all. :-)

I said I didn't think "it would fly", meaning that I was afraid the other kernel developers wouldn't like that change.

The reason why I think so is that you'd like to add a whole new infrastructure whose only purpose would be debugging that would only be useful to systems using opportunistic suspend. That, however, is only Android right now and it cannot use the mainline kernel for other reasons, so basically we would add infrastructure that's useful to no one.

Quoted 3 lines

I'm not sure what you mean by this. The debugging is useful for anyone using the api, not just Android, and a handle is also needed to mix timeouts and pm_relax.

The purpose of the debugging would be to be able to figure out why the system is staying in the working state, which is only relevant for systems that use opportunistic suspend.

If opportunistic suspend isn't used, it makes sense to ask which device caused suspend (initiated by the user) to be aborted and for this purpose it is sufficient to count wakeup events associated with each device (you need to preserve the pre-suspend values of these counters, but that can be done by a user space power manager just fine).

Quoted 2 lines

The handle can be the device, but some drivers need several handles per device.

That depends on how precise the collected debug information should be and that, in turn, depends on what it's going to be used for.

Anyway, as I said I'm not opposed to the idea of using a special type of objects for collecting debug information on wakeup events, so please free to submit patches modifying the current mainline kernel code in that direction.

Thanks,
Rafael

#277 lore raw
In reply to Arve Hjønnevåg
Quoted 26 lines · Arve Hjønnevåg

2010/8/8 Rafael J. Wysocki <[email protected]>:

Quoted 25 lines · Arve Hjønnevåg
Quoted 23 lines

2010/8/7 Arve Hjønnevåg <[email protected]>:

Quoted 4 lines

2010/8/7 Rafael J. Wysocki <[email protected]>:

Quoted 3 lines · Arve Hjønnevåg
Quoted 2 lines

2010/8/6 Alan Stern <[email protected]>:

Quoted 1 line · Arve Hjønnevåg

...

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

total_time, total time the wake lock has been active. This one should be obvious.

Also easily added.

Quoted 9 lines
Quoted 5 lines
Quoted 1 line

Only with a handle passed to all the calls.

Well, I'm kind of tired of this "my solution is the only acceptable one" mindset. IMHO, it's totally counter productive.

How do you propose to track how long a driver has blocked suspend when you have an unblock call that takes no arguments.

Also, I did not not see a response to my question about why you don't want to pass a handle.

Quoted 8 lines
Quoted 5 lines

It doesn't really matter what I personally want. In fact, I'm not totally opposed to that idea, although there are disadvantages (eg. a "handle" would really mean a pointer to an object with certain life cycle that needs to be managed by the caller and it's not that clear to me who should manage the objects that the PCI wakeup code would pass to pm_wakeup_event(), for one

Wouldn't a single global handle work for the way you are handling pci wakeup events?

Not really, because I'd like to know the number of wakeups associated with the given device.

Quoted 2 lines

It looked like you just reset a global timeout every time a pci wakeup event occurs.

We bump up the per-device counter of wakeup events in addition to that.

Quoted 12 lines
Quoted 11 lines

example). I sent a pull request for your original patchset to Linus after all. :-)

I said I didn't think "it would fly", meaning that I was afraid the other kernel developers wouldn't like that change.

The reason why I think so is that you'd like to add a whole new infrastructure whose only purpose would be debugging that would only be useful to systems using opportunistic suspend. That, however, is only Android right now and it cannot use the mainline kernel for other reasons, so basically we would add infrastructure that's useful to no one.

Quoted 3 lines

I'm not sure what you mean by this. The debugging is useful for anyone using the api, not just Android, and a handle is also needed to mix timeouts and pm_relax.

The purpose of the debugging would be to be able to figure out why the system is staying in the working state, which is only relevant for systems that use opportunistic suspend.

If opportunistic suspend isn't used, it makes sense to ask which device caused suspend (initiated by the user) to be aborted and for this purpose it is sufficient to count wakeup events associated with each device (you need to preserve the pre-suspend values of these counters, but that can be done by a user space power manager just fine).

Quoted 2 lines

The handle can be the device, but some drivers need several handles per device.

That depends on how precise the collected debug information should be and that, in turn, depends on what it's going to be used for.

Anyway, as I said I'm not opposed to the idea of using a special type of objects for collecting debug information on wakeup events, so please free to submit patches modifying the current mainline kernel code in that direction.

Thanks,
Rafael

#278 lore raw

2010/8/9 Rafael J. Wysocki <[email protected]>:

Quoted 33 lines · Arve Hjønnevåg
Quoted 32 lines

2010/8/8 Rafael J. Wysocki <[email protected]>:

Quoted 30 lines · Arve Hjønnevåg
Quoted 17 lines

2010/8/7 Arve Hjønnevåg <[email protected]>:

Quoted 4 lines

2010/8/7 Rafael J. Wysocki <[email protected]>:

Quoted 3 lines · Arve Hjønnevåg
Quoted 2 lines

2010/8/6 Alan Stern <[email protected]>:

Quoted 1 line · Arve Hjønnevåg

...

Quoted 11 lines
Quoted 10 lines
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

total_time, total time the wake lock has been active. This one should be obvious.

Also easily added.

Only with a handle passed to all the calls.

Well, I'm kind of tired of this "my solution is the only acceptable one" mindset.  IMHO, it's totally counter productive.

Quoted 6 lines
Quoted 3 lines

How do you propose to track how long a driver has blocked suspend when you have an unblock call that takes no arguments.

Also, I did not not see a response to my question about why you don't want to pass a handle.

It doesn't really matter what I personally want.  In fact, I'm not totally opposed to that idea, although there are disadvantages (eg. a "handle" would really mean a pointer to an object with certain life cycle that needs to be managed by the caller and it's not that clear to me who should manage the objects that the PCI wakeup code would pass to pm_wakeup_event(), for one

Quoted 6 lines
Quoted 2 lines

Wouldn't a single global handle work for the way you are handling pci wakeup events?

Not really, because I'd like to know the number of wakeups associated with the given device.

For debugging purposes right? I'm not sure automatically counting wakeup events from pm_stay_awake and pm_wakeup_event is the best way to do this. To avoid race conditions these calls have to be made for every event that could also be a wakeup event, which means the actual wakeup event easily gets lost in the noise. This is why I had a separate wakeup count that only increments on the fist call to wake_lock after each suspend, but this did not work that well either.

Quoted 17 lines
Quoted 2 lines

It looked like you just reset a global timeout every time a pci wakeup event occurs.

We bump up the per-device counter of wakeup events in addition to that.

Quoted 12 lines
Quoted 11 lines

example).  I sent a pull request for your original patchset to Linus after all. :-)

I said I didn't think "it would fly", meaning that I was afraid the other kernel developers wouldn't like that change.

The reason why I think so is that you'd like to add a whole new infrastructure whose only purpose would be debugging that would only be useful to systems using opportunistic suspend.  That, however, is only Android right now and it cannot use the mainline kernel for other reasons, so basically we would add infrastructure that's useful to no one.

Quoted 8 lines
Quoted 3 lines

I'm not sure what you mean by this. The debugging is useful for anyone using the api, not just Android, and a handle is also needed to mix timeouts and pm_relax.

The purpose of the debugging would be to be able to figure out why the system is staying in the working state, which is only relevant for systems that use opportunistic suspend.

Only if the drivers do not have bugs. A driver calling pm_say_awake without a matching pm_relax call will prevent any race free suspend from succeeding.

Quoted 6 lines

If opportunistic suspend isn't used, it makes sense to ask which device caused suspend (initiated by the user) to be aborted and for this purpose it is sufficient to count wakeup events associated with each device (you need to preserve the pre-suspend values of these counters, but that can be done by a user space power manager just fine).

Quoted 6 lines
Quoted 2 lines

The handle can be the device, but some drivers need several handles per device.

That depends on how precise the collected debug information should be and that, in turn, depends on what it's going to be used for.

It is not just debug information. Drivers that mix wake_lock_timeout and wake_unlock do not map to the current api.

Quoted 4 lines

Anyway, as I said I'm not opposed to the idea of using a special type of objects for collecting debug information on wakeup events, so please free to submit patches modifying the current mainline kernel code in that direction.

How do you prefer to handle your pci wakeup events? Add a handle to every device or pci device? Or use a global handle to avoid the race and report wakeup events for debugging separately?

Signature · 1 line
Arve Hjønnevåg
#279 lore raw
In reply to Rafael J. Wysocki

2010/8/9 Rafael J. Wysocki <[email protected]>:

Quoted 33 lines · Arve Hjønnevåg
Quoted 32 lines

2010/8/8 Rafael J. Wysocki <[email protected]>:

Quoted 30 lines · Arve Hjønnevåg
Quoted 17 lines

2010/8/7 Arve Hjønnevåg <[email protected]>:

Quoted 4 lines

2010/8/7 Rafael J. Wysocki <[email protected]>:

Quoted 3 lines · Arve Hjønnevåg
Quoted 2 lines

2010/8/6 Alan Stern <[email protected]>:

Quoted 1 line · Arve Hjønnevåg

...

Quoted 11 lines
Quoted 10 lines
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

total_time, total time the wake lock has been active. This one should be obvious.

Also easily added.

Only with a handle passed to all the calls.

Well, I'm kind of tired of this "my solution is the only acceptable one" mindset.  IMHO, it's totally counter productive.

Quoted 6 lines
Quoted 3 lines

How do you propose to track how long a driver has blocked suspend when you have an unblock call that takes no arguments.

Also, I did not not see a response to my question about why you don't want to pass a handle.

It doesn't really matter what I personally want.  In fact, I'm not totally opposed to that idea, although there are disadvantages (eg. a "handle" would really mean a pointer to an object with certain life cycle that needs to be managed by the caller and it's not that clear to me who should manage the objects that the PCI wakeup code would pass to pm_wakeup_event(), for one

Quoted 6 lines
Quoted 2 lines

Wouldn't a single global handle work for the way you are handling pci wakeup events?

Not really, because I'd like to know the number of wakeups associated with the given device.

For debugging purposes right? I'm not sure automatically counting wakeup events from pm_stay_awake and pm_wakeup_event is the best way to do this. To avoid race conditions these calls have to be made for every event that could also be a wakeup event, which means the actual wakeup event easily gets lost in the noise. This is why I had a separate wakeup count that only increments on the fist call to wake_lock after each suspend, but this did not work that well either.

Quoted 17 lines
Quoted 2 lines

It looked like you just reset a global timeout every time a pci wakeup event occurs.

We bump up the per-device counter of wakeup events in addition to that.

Quoted 12 lines
Quoted 11 lines

example).  I sent a pull request for your original patchset to Linus after all. :-)

I said I didn't think "it would fly", meaning that I was afraid the other kernel developers wouldn't like that change.

The reason why I think so is that you'd like to add a whole new infrastructure whose only purpose would be debugging that would only be useful to systems using opportunistic suspend.  That, however, is only Android right now and it cannot use the mainline kernel for other reasons, so basically we would add infrastructure that's useful to no one.

Quoted 8 lines
Quoted 3 lines

I'm not sure what you mean by this. The debugging is useful for anyone using the api, not just Android, and a handle is also needed to mix timeouts and pm_relax.

The purpose of the debugging would be to be able to figure out why the system is staying in the working state, which is only relevant for systems that use opportunistic suspend.

Only if the drivers do not have bugs. A driver calling pm_say_awake without a matching pm_relax call will prevent any race free suspend from succeeding.

Quoted 6 lines

If opportunistic suspend isn't used, it makes sense to ask which device caused suspend (initiated by the user) to be aborted and for this purpose it is sufficient to count wakeup events associated with each device (you need to preserve the pre-suspend values of these counters, but that can be done by a user space power manager just fine).

Quoted 6 lines
Quoted 2 lines

The handle can be the device, but some drivers need several handles per device.

That depends on how precise the collected debug information should be and that, in turn, depends on what it's going to be used for.

It is not just debug information. Drivers that mix wake_lock_timeout and wake_unlock do not map to the current api.

Quoted 4 lines

Anyway, as I said I'm not opposed to the idea of using a special type of objects for collecting debug information on wakeup events, so please free to submit patches modifying the current mainline kernel code in that direction.

How do you prefer to handle your pci wakeup events? Add a handle to every device or pci device? Or use a global handle to avoid the race and report wakeup events for debugging separately?

Signature · 1 line
Arve Hjønnevåg
#280 lore raw
Quoted 2 lines · Arve Hjønnevåg

2010/8/9 Rafael J. Wysocki <[email protected]>:

Quoted 1 line · Arve Hjønnevåg

...

Quoted 9 lines
Quoted 5 lines

Anyway, as I said I'm not opposed to the idea of using a special type of objects for collecting debug information on wakeup events, so please free to submit patches modifying the current mainline kernel code in that direction.

How do you prefer to handle your pci wakeup events? Add a handle to every device or pci device? Or use a global handle to avoid the race and report wakeup events for debugging separately?

The latter, maybe?

Thanks,
Rafael

#281 lore raw
In reply to Arve Hjønnevåg
Quoted 2 lines · Arve Hjønnevåg

2010/8/9 Rafael J. Wysocki <[email protected]>:

Quoted 1 line · Arve Hjønnevåg

...

Quoted 9 lines
Quoted 5 lines

Anyway, as I said I'm not opposed to the idea of using a special type of objects for collecting debug information on wakeup events, so please free to submit patches modifying the current mainline kernel code in that direction.

How do you prefer to handle your pci wakeup events? Add a handle to every device or pci device? Or use a global handle to avoid the race and report wakeup events for debugging separately?

The latter, maybe?

Thanks,
Rafael

#282 lore raw
In reply to Arve Hjønnevåg
Quoted 2 lines · Arve Hjønnevåg

The suspend blockers I added I my suspend blocker patchset were not directly associated with a device.

For the benefit of those who don't remember the details of that patchset, can you list again the suspend blockers/wakelocks that aren't directly associated with a device? (No need to mention things coming from userspace -- those are obviously unrelated to any device.)

Quoted 3 lines

The evdev changes could be modified
to share a device, but it would give less detail since a separate queue is created for each client that opens the device.

I don't understand enough about how the input layer works. Does it create a new queue each time an input device file is opened? And each input event gets added to all of the queues? And each queue gets a corresponding wakelock?

If these surmises are right then I can see how relying on devices alone wouldn't give enough information. There could be two separate programs both reading input events, and you wouldn't know which one was responsible for failing to drain its queue.

Quoted 3 lines

The suspend
blocking work api would have to change so the caller to passes a device in, which I think would make that api less flexible.

Maybe. There aren't enough examples coded up yet to be sure. At this point we could easily make the device argument required instead of optional, and we could add a device argument to pm_relax.

Quoted 7 lines

Mostly the
problem is that we need separate stats for wakelocks created by a single driver. For instance we will still need a user-space interface to block suspend on android devices (lower level services than the power manager need to block suspend), with the stats in the device struct we have to create a new device for every wakelock user space creates in the kernel.

In the scheme we're talking about, the suspend-blocking interface for uesrspace would be located entirely in the power manager. Hence it could maintain all the necessary statistics, without involving the kernel. During early stages of system startup, before the power manager is running, lower-level services would not be able to block suspend. This wouldn't matter because at those times the system simply would not ever suspend -- because suspends have to be initiated by the power manager.

Quoted 3 lines

There is also the issue of reading the stats. It is a lot easier to read a single stats file, than looping though every device on the system (when most of the devices never block suspend).

I agree, it should be possible to simplify this and perhaps at the same time avoid adding all the wakeup-related fields to every device structure.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

Does Android use any kernel-internal wakelocks both with a timer and with active cancellation?

I don't know if they are all kernel-internal but these drivers appear to use timeouts and active cancellation on the same wakelock:
wifi driver, mmc core, alarm driver, evdev (suspend blocker version removes the timeout).

Roughly speaking, what do the timings work out to be? That is, how long are the timeouts for these wakelocks, how long does it usually take for one of them to be actively cancelled, and what percentage of them end up timing out?

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

The wakelock code has an active flag. If we want to keep the pm_stay_wake nesting (which I would argue against), we would need an active count. It would also require a handle, which is a change Rafael said would not fly.

Never mind the handles for now. As for the nesting, we effectively don't have it when the pm_wakeup_event interface is used. The pm_stay_awake/pm_relax interface _is_ nested, but since that interface isn't used anywhere yet, we can't say whether it really should be nested or not. Maybe we'll find out in the end that it shouldn't be.

Consider an input event queue as a typical case. You would call pm_stay_awake when an item is added to an empty queue, and you would call pm_relax when the last item is removed from a queue. The nesting count would never be > 1, so it wouldn't make any difference either way.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 5 lines
Quoted 1 line

sleep_time, total time the wake lock has been active when the screen was off.

Not applicable to general systems.  Is there anything like it that _would_ apply in general?

The screen off is how it is used on android, the stats is keyed of what user space wrote to /sys/power/state. If "on" was written the sleep time is not updated.

I guess we could keep track of pm_stay_awake or pm_wakeup_event calls made between a read and write of /sys/power/wakeup_count (i.e., while events_check_enabled is set). Would that be roughly equivalent?

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

The merged user space interface makes this unclear to me. When I first used suspend on android I had a power manager process that opened all the input devices and reset a screen off timeout every time there was an input event. If the input layer uses pm_stay_awake to block suspend when the queue is not empty, this will deadlock with the current interface since reading the wake count will block forever if an input event occurred right after the power manager decides to suspend.

Quoted 4 lines
Quoted 2 lines

No, in that case suspend will be aborted, IIUC.

How? Your pm_get_wakeup_count function loops until events_in_progress becomes 0.

The problem is that the same task is reading /sys/power/wakeup_count (thus waiting for an input event queue to drain) and also reading an input event queue. Clearly this will result in deadlock, but there must be a reasonably simple way around it. For example, carry out those two activities in separate threads.

Alan Stern

#283 lore raw
In reply to Arve Hjønnevåg
Quoted 2 lines · Arve Hjønnevåg

The suspend blockers I added I my suspend blocker patchset were not directly associated with a device.

For the benefit of those who don't remember the details of that patchset, can you list again the suspend blockers/wakelocks that aren't directly associated with a device? (No need to mention things coming from userspace -- those are obviously unrelated to any device.)

Quoted 3 lines

The evdev changes could be modified
to share a device, but it would give less detail since a separate queue is created for each client that opens the device.

I don't understand enough about how the input layer works. Does it create a new queue each time an input device file is opened? And each input event gets added to all of the queues? And each queue gets a corresponding wakelock?

If these surmises are right then I can see how relying on devices alone wouldn't give enough information. There could be two separate programs both reading input events, and you wouldn't know which one was responsible for failing to drain its queue.

Quoted 3 lines

The suspend
blocking work api would have to change so the caller to passes a device in, which I think would make that api less flexible.

Maybe. There aren't enough examples coded up yet to be sure. At this point we could easily make the device argument required instead of optional, and we could add a device argument to pm_relax.

Quoted 7 lines

Mostly the
problem is that we need separate stats for wakelocks created by a single driver. For instance we will still need a user-space interface to block suspend on android devices (lower level services than the power manager need to block suspend), with the stats in the device struct we have to create a new device for every wakelock user space creates in the kernel.

In the scheme we're talking about, the suspend-blocking interface for uesrspace would be located entirely in the power manager. Hence it could maintain all the necessary statistics, without involving the kernel. During early stages of system startup, before the power manager is running, lower-level services would not be able to block suspend. This wouldn't matter because at those times the system simply would not ever suspend -- because suspends have to be initiated by the power manager.

Quoted 3 lines

There is also the issue of reading the stats. It is a lot easier to read a single stats file, than looping though every device on the system (when most of the devices never block suspend).

I agree, it should be possible to simplify this and perhaps at the same time avoid adding all the wakeup-related fields to every device structure.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

Does Android use any kernel-internal wakelocks both with a timer and with active cancellation?

I don't know if they are all kernel-internal but these drivers appear to use timeouts and active cancellation on the same wakelock:
wifi driver, mmc core, alarm driver, evdev (suspend blocker version removes the timeout).

Roughly speaking, what do the timings work out to be? That is, how long are the timeouts for these wakelocks, how long does it usually take for one of them to be actively cancelled, and what percentage of them end up timing out?

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

The wakelock code has an active flag. If we want to keep the pm_stay_wake nesting (which I would argue against), we would need an active count. It would also require a handle, which is a change Rafael said would not fly.

Never mind the handles for now. As for the nesting, we effectively don't have it when the pm_wakeup_event interface is used. The pm_stay_awake/pm_relax interface _is_ nested, but since that interface isn't used anywhere yet, we can't say whether it really should be nested or not. Maybe we'll find out in the end that it shouldn't be.

Consider an input event queue as a typical case. You would call pm_stay_awake when an item is added to an empty queue, and you would call pm_relax when the last item is removed from a queue. The nesting count would never be > 1, so it wouldn't make any difference either way.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 5 lines
Quoted 1 line

sleep_time, total time the wake lock has been active when the screen was off.

Not applicable to general systems.  Is there anything like it that _would_ apply in general?

The screen off is how it is used on android, the stats is keyed of what user space wrote to /sys/power/state. If "on" was written the sleep time is not updated.

I guess we could keep track of pm_stay_awake or pm_wakeup_event calls made between a read and write of /sys/power/wakeup_count (i.e., while events_check_enabled is set). Would that be roughly equivalent?

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

The merged user space interface makes this unclear to me. When I first used suspend on android I had a power manager process that opened all the input devices and reset a screen off timeout every time there was an input event. If the input layer uses pm_stay_awake to block suspend when the queue is not empty, this will deadlock with the current interface since reading the wake count will block forever if an input event occurred right after the power manager decides to suspend.

Quoted 4 lines
Quoted 2 lines

No, in that case suspend will be aborted, IIUC.

How? Your pm_get_wakeup_count function loops until events_in_progress becomes 0.

The problem is that the same task is reading /sys/power/wakeup_count (thus waiting for an input event queue to drain) and also reading an input event queue. Clearly this will result in deadlock, but there must be a reasonably simple way around it. For example, carry out those two activities in separate threads.

Alan Stern

#284 lore raw

2010/8/8 Alan Stern <[email protected]>:

Quoted 9 lines · Arve Hjønnevåg
Quoted 3 lines

The suspend blockers I added I my suspend blocker patchset were not directly associated with a device.

For the benefit of those who don't remember the details of that patchset, can you list again the suspend blockers/wakelocks that aren't directly associated with a device?  (No need to mention things coming from userspace -- those are obviously unrelated to any device.)

Other than the user space interface and the internal main suspend blocker that patchset modified evdev, and added suspend blocking work.

Quoted 10 lines
Quoted 4 lines

The evdev changes could be modified
to share a device, but it would give less detail since a separate queue is created for each client that opens the device.

I don't understand enough about how the input layer works.  Does it create a new queue each time an input device file is opened?  And each input event gets added to all of the queues?  And each queue gets a corresponding wakelock?

Yes, yes and yes.

Quoted 5 lines

If these surmises are right then I can see how relying on devices alone wouldn't give enough information.  There could be two separate programs both reading input events, and you wouldn't know which one was responsible for failing to drain its queue.

We don't know which one now either since we don't give them unique names, but we know that one of them is not reading (and it is usually not the normal input path).

Quoted 8 lines
Quoted 3 lines

The suspend
blocking work api would have to change so the caller to passes a device in, which I think would make that api less flexible.

Maybe.  There aren't enough examples coded up yet to be sure.  At this point we could easily make the device argument required instead of optional, and we could add a device argument to pm_relax.

I think that would be a good start. I can create dummy devices for now where I don't already have a device.

Quoted 8 lines
Quoted 7 lines

Mostly the
problem is that we need separate stats for wakelocks created by a single driver. For instance we will still need a user-space interface to block suspend on android devices (lower level services than the power manager need to block suspend), with the stats in the device struct we have to create a new device for every wakelock user space creates in the kernel.

Quoted 8 lines

In the scheme we're talking about, the suspend-blocking interface for uesrspace would be located entirely in the power manager.  Hence it could maintain all the necessary statistics, without involving the kernel.  During early stages of system startup, before the power manager is running, lower-level services would not be able to block suspend.  This wouldn't matter because at those times the system simply would not ever suspend -- because suspends have to be initiated by the power manager.

If we do that, a low level process could try to block suspend while the power manager is not running. Then the power manager could start and decide to suspend not knowing that a low level process wanted to block suspend.

Quoted 18 lines
Quoted 4 lines

There is also the issue of reading the stats. It is a lot easier to read a single stats file, than looping though every device on the system (when most of the devices never block suspend).

I agree, it should be possible to simplify this and perhaps at the same time avoid adding all the wakeup-related fields to every device structure.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

Does Android use any kernel-internal wakelocks both with a timer and with active cancellation?

I don't know if they are all kernel-internal but these drivers appear to use timeouts and active cancellation on the same wakelock:
wifi driver, mmc core, alarm driver, evdev (suspend blocker version removes the timeout).

Quoted 5 lines

Roughly speaking, what do the timings work out to be?  That is, how long are the timeouts for these wakelocks, how long does it usually take for one of them to be actively cancelled, and what percentage of them end up timing out?

The evdev timeout is a few seconds, and never timeout unless user space is misbehaving. I don't know how the wifi and mmc wakelocks are used. The alarm driver uses a 1 or 2 second timeout to abort suspend when an alarm is set to close to program an rtc alarm. I think this one is cancelled when the alarm triggers, and the timeout only handles the case where the client cancelled the alarm before it trigger, but I don't remember for sure.

Quoted 11 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

The wakelock code has an active flag. If we want to keep the pm_stay_wake nesting (which I would argue against), we would need an active count. It would also require a handle, which is a change Rafael said would not fly.

Never mind the handles for now.  As for the nesting, we effectively don't have it when the pm_wakeup_event interface is used.  The pm_stay_awake/pm_relax interface _is_ nested, but since that interface isn't used anywhere yet, we can't say whether it really should be nested or not.  Maybe we'll find out in the end that it shouldn't be.

You cannot easily mix timeouts, cancellations and nesting. Wakelocks/suspend blockers allow you to mix timeouts and cancellations.

Quoted 6 lines

Consider an input event queue as a typical case.  You would call pm_stay_awake when an item is added to an empty queue, and you would call pm_relax when the last item is removed from a queue.  The nesting count would never be > 1, so it wouldn't make any difference either way.

The cleanup is a little simpler when you don't nest and there is less chance that a missed edge case prevents suspend forever (we had a few of those bugs in our userspace code that used nested wakelocks). If the above is all you do, then you block suspend forever if someone closes an non-empty input device.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 1 line

sleep_time, total time the wake lock has been active when the screen was off.

Not applicable to general systems.  Is there anything like it that _would_ apply in general?

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

The screen off is how it is used on android, the stats is keyed of what user space wrote to /sys/power/state. If "on" was written the sleep time is not updated.

I guess we could keep track of pm_stay_awake or pm_wakeup_event calls made between a read and write of /sys/power/wakeup_count (i.e., while events_check_enabled is set).  Would that be roughly equivalent?

Roughly, yes. (or even just while blocking the read from /sys/power/wakeup_count).

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 7 lines

The merged user space interface makes this unclear to me. When I first used suspend on android I had a power manager process that opened all the input devices and reset a screen off timeout every time there was an input event. If the input layer uses pm_stay_awake to block suspend when the queue is not empty, this will deadlock with the current interface since reading the wake count will block forever if an input event occurred right after the power manager decides to suspend.

No, in that case suspend will be aborted, IIUC.

Quoted 8 lines
Quoted 1 line

How? Your pm_get_wakeup_count function loops until events_in_progress becomes 0.

The problem is that the same task is reading /sys/power/wakeup_count (thus waiting for an input event queue to drain) and also reading an input event queue.  Clearly this will result in deadlock, but there must be a reasonably simple way around it.  For example, carry out those two activities in separate threads.

Yes, but my point is that user-space code that is safe if the driver does not block suspend until the queue is empty becomes unsafe if it does. Also note that it is not enough to just use two separate threads for this, the thread that reads /sys/power/wakeup_count cannot hold a lock while reading, or directly provide the user space wakelock api.

I do think it is possible to use this api and provide a user space wakelock api (by having a dedicated thread that suspends), but it is more complicated than using the asynchronous wakelock/suspend blocker api.

Signature · 1 line
Arve Hjønnevåg
#285 lore raw
In reply to Alan Stern

2010/8/8 Alan Stern <[email protected]>:

Quoted 9 lines · Arve Hjønnevåg
Quoted 3 lines

The suspend blockers I added I my suspend blocker patchset were not directly associated with a device.

For the benefit of those who don't remember the details of that patchset, can you list again the suspend blockers/wakelocks that aren't directly associated with a device?  (No need to mention things coming from userspace -- those are obviously unrelated to any device.)

Other than the user space interface and the internal main suspend blocker that patchset modified evdev, and added suspend blocking work.

Quoted 10 lines
Quoted 4 lines

The evdev changes could be modified
to share a device, but it would give less detail since a separate queue is created for each client that opens the device.

I don't understand enough about how the input layer works.  Does it create a new queue each time an input device file is opened?  And each input event gets added to all of the queues?  And each queue gets a corresponding wakelock?

Yes, yes and yes.

Quoted 5 lines

If these surmises are right then I can see how relying on devices alone wouldn't give enough information.  There could be two separate programs both reading input events, and you wouldn't know which one was responsible for failing to drain its queue.

We don't know which one now either since we don't give them unique names, but we know that one of them is not reading (and it is usually not the normal input path).

Quoted 8 lines
Quoted 3 lines

The suspend
blocking work api would have to change so the caller to passes a device in, which I think would make that api less flexible.

Maybe.  There aren't enough examples coded up yet to be sure.  At this point we could easily make the device argument required instead of optional, and we could add a device argument to pm_relax.

I think that would be a good start. I can create dummy devices for now where I don't already have a device.

Quoted 8 lines
Quoted 7 lines

Mostly the
problem is that we need separate stats for wakelocks created by a single driver. For instance we will still need a user-space interface to block suspend on android devices (lower level services than the power manager need to block suspend), with the stats in the device struct we have to create a new device for every wakelock user space creates in the kernel.

Quoted 8 lines

In the scheme we're talking about, the suspend-blocking interface for uesrspace would be located entirely in the power manager.  Hence it could maintain all the necessary statistics, without involving the kernel.  During early stages of system startup, before the power manager is running, lower-level services would not be able to block suspend.  This wouldn't matter because at those times the system simply would not ever suspend -- because suspends have to be initiated by the power manager.

If we do that, a low level process could try to block suspend while the power manager is not running. Then the power manager could start and decide to suspend not knowing that a low level process wanted to block suspend.

Quoted 18 lines
Quoted 4 lines

There is also the issue of reading the stats. It is a lot easier to read a single stats file, than looping though every device on the system (when most of the devices never block suspend).

I agree, it should be possible to simplify this and perhaps at the same time avoid adding all the wakeup-related fields to every device structure.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

Does Android use any kernel-internal wakelocks both with a timer and with active cancellation?

I don't know if they are all kernel-internal but these drivers appear to use timeouts and active cancellation on the same wakelock:
wifi driver, mmc core, alarm driver, evdev (suspend blocker version removes the timeout).

Quoted 5 lines

Roughly speaking, what do the timings work out to be?  That is, how long are the timeouts for these wakelocks, how long does it usually take for one of them to be actively cancelled, and what percentage of them end up timing out?

The evdev timeout is a few seconds, and never timeout unless user space is misbehaving. I don't know how the wifi and mmc wakelocks are used. The alarm driver uses a 1 or 2 second timeout to abort suspend when an alarm is set to close to program an rtc alarm. I think this one is cancelled when the alarm triggers, and the timeout only handles the case where the client cancelled the alarm before it trigger, but I don't remember for sure.

Quoted 11 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

The wakelock code has an active flag. If we want to keep the pm_stay_wake nesting (which I would argue against), we would need an active count. It would also require a handle, which is a change Rafael said would not fly.

Never mind the handles for now.  As for the nesting, we effectively don't have it when the pm_wakeup_event interface is used.  The pm_stay_awake/pm_relax interface _is_ nested, but since that interface isn't used anywhere yet, we can't say whether it really should be nested or not.  Maybe we'll find out in the end that it shouldn't be.

You cannot easily mix timeouts, cancellations and nesting. Wakelocks/suspend blockers allow you to mix timeouts and cancellations.

Quoted 6 lines

Consider an input event queue as a typical case.  You would call pm_stay_awake when an item is added to an empty queue, and you would call pm_relax when the last item is removed from a queue.  The nesting count would never be > 1, so it wouldn't make any difference either way.

The cleanup is a little simpler when you don't nest and there is less chance that a missed edge case prevents suspend forever (we had a few of those bugs in our userspace code that used nested wakelocks). If the above is all you do, then you block suspend forever if someone closes an non-empty input device.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 1 line

sleep_time, total time the wake lock has been active when the screen was off.

Not applicable to general systems.  Is there anything like it that _would_ apply in general?

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

The screen off is how it is used on android, the stats is keyed of what user space wrote to /sys/power/state. If "on" was written the sleep time is not updated.

I guess we could keep track of pm_stay_awake or pm_wakeup_event calls made between a read and write of /sys/power/wakeup_count (i.e., while events_check_enabled is set).  Would that be roughly equivalent?

Roughly, yes. (or even just while blocking the read from /sys/power/wakeup_count).

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 7 lines

The merged user space interface makes this unclear to me. When I first used suspend on android I had a power manager process that opened all the input devices and reset a screen off timeout every time there was an input event. If the input layer uses pm_stay_awake to block suspend when the queue is not empty, this will deadlock with the current interface since reading the wake count will block forever if an input event occurred right after the power manager decides to suspend.

No, in that case suspend will be aborted, IIUC.

Quoted 8 lines
Quoted 1 line

How? Your pm_get_wakeup_count function loops until events_in_progress becomes 0.

The problem is that the same task is reading /sys/power/wakeup_count (thus waiting for an input event queue to drain) and also reading an input event queue.  Clearly this will result in deadlock, but there must be a reasonably simple way around it.  For example, carry out those two activities in separate threads.

Yes, but my point is that user-space code that is safe if the driver does not block suspend until the queue is empty becomes unsafe if it does. Also note that it is not enough to just use two separate threads for this, the thread that reads /sys/power/wakeup_count cannot hold a lock while reading, or directly provide the user space wakelock api.

I do think it is possible to use this api and provide a user space wakelock api (by having a dedicated thread that suspends), but it is more complicated than using the asynchronous wakelock/suspend blocker api.

Signature · 1 line
Arve Hjønnevåg
#286 lore raw

Wakeup-events implementation

Since this area of the discussion has strayed away from the path of Paul McKenney's original summary, I'm starting a new email thread and drastically cutting the CC list.

Quoted 6 lines · Arve Hjønnevåg
Quoted 4 lines

Maybe.  There aren't enough examples coded up yet to be sure.  At this point we could easily make the device argument required instead of optional, and we could add a device argument to pm_relax.

I think that would be a good start. I can create dummy devices for now where I don't already have a device.

Rafael and I spent some time discussing all this during LinuxCon. Combining what he thought with my own ideas led us to decide that the wakeup information should be stored in a separate structure, not in dev_pm_info. These structures will be allocated dynamically when a device is enabled for remote wakeup (and presumably deallocated if a device is disabled for remote wakeup). A pointer to the new structure will be stored in dev_pm_info. We expect that most devices won't need a wakeup structure, because most devices aren't wakeup sources.

This new structure (as yet unnamed) will be a lot like your suspend_blocker structure, but with some differences. It won't need a name, since the device already has a name. It won't have a timer, if we can get away with leaving one out. But it will optionally contain various counters that can be used for statistics reporting and debugging. The API for exporting these fields to userspace has not yet been decided upon.

The device argument will become mandatory for pm_stay_awake, pm_relax, and pm_wakeup_event, so that the counter fields can be updated properly.

Quoted 9 lines
Quoted 8 lines

In the scheme we're talking about, the suspend-blocking interface for uesrspace would be located entirely in the power manager.  Hence it could maintain all the necessary statistics, without involving the kernel.  During early stages of system startup, before the power manager is running, lower-level services would not be able to block suspend.  This wouldn't matter because at those times the system simply would not ever suspend -- because suspends have to be initiated by the power manager.

Quoted 4 lines

If we do that, a low level process could try to block suspend while the power manager is not running. Then the power manager could start and decide to suspend not knowing that a low level process wanted to block suspend.

There's a simple solution: Put all this in a _new_, low-level power manager program that can be started very early during boot-up (before any of the other low-level services that need to block suspend). Then all the other programs would communicate their suspend-blocker requirements to this program instead of to the kernel.

You expressed concern about the new power manager deadlocking. This can be avoided by designing the program properly. It should run in two threads. Thread 1 will handle IPC, keeping track of userspace suspend-blocker requests, their statistics, and so on. Thread 2 will manage the PM interface to the kernel, and it will execute the following simple loop:

	for (;;) {
		read /sys/power/wakeup_count	/* blocking read */
		if (there are any active userspace suspend blockers) {
			wait until they are all deactivated
		} else {
			if (write to /sys/power/wakeup_count succeeds)
				write "mem" to /sys/power/state
		}
	}

I think this will resolve the problem you were worried about.

Quoted 10 lines
Quoted 10 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

I don't know if they are all kernel-internal but these drivers appear to use timeouts and active cancellation on the same wakelock:
wifi driver, mmc core, alarm driver, evdev (suspend blocker version removes the timeout).

Roughly speaking, what do the timings work out to be?  That is, how long are the timeouts for these wakelocks, how long does it usually take for one of them to be actively cancelled, and what percentage of them end up timing out?

Quoted 7 lines

The evdev timeout is a few seconds, and never timeout unless user space is misbehaving. I don't know how the wifi and mmc wakelocks are used. The alarm driver uses a 1 or 2 second timeout to abort suspend when an alarm is set to close to program an rtc alarm. I think this one is cancelled when the alarm triggers, and the timeout only handles the case where the client cancelled the alarm before it trigger, but I don't remember for sure.

Evdev turns out to be tricky for a couple of reasons. One is this business of combining active cancellation with timeouts (we might end up needing a special-purpose timer for this). Another is the way all input events funnel into a single event queue.

For example, suppose you want the keyboard to be a wakeup device but not the mouse. Once events get into the input queue, there's no way to tell where they came from. Hence mouse motion events would prevent the system from suspending, even though they weren't supposed to.

Quoted 3 lines

You cannot easily mix timeouts, cancellations and nesting. Wakelocks/suspend blockers allow you to mix timeouts and cancellations.

That's true. And it turns out that we do need to mix cancellations with nesting. For example, it may well happen that pm_request_resume gets called several times before the pm workqueue thread gets around to resuming the device. If each of those calls has a corresponding call to pm_stay_awake then we would like to cancel all of them with a single pm_relax after the driver's runtime_resume callback is finished.

On the other hand, the driver's runtime_resume routine might need to carry out some work in a different kernel thread. It would call pm_stay_awake, and we wouldn't want _this_ call to be cancelled until the other thread has run.

In the end, the best answer may be to keep a count of pending wakeup events in the new wakeup structure (as well as a global count of the number of devices whose pending count is > 0). Then pm_stay_awake would increment the count, pm_relax would decrement it, and there could be a variant of pm_stay_awake that would increment the count only if it was currently equal to 0.

Quoted 3 lines

The cleanup is a little simpler when you don't nest and there is less chance that a missed edge case prevents suspend forever (we had a few of those bugs in our userspace code that used nested wakelocks).

Bugs in the kernel can be tracked down and fixed.

Quoted 3 lines

If
the above is all you do, then you block suspend forever if someone closes an non-empty input device.

That sounds like a fixable bug. :-)

Alan Stern

#287 lore raw

Re: Wakeup-events implementation

2010/8/13 Alan Stern <[email protected]>:

Quoted 22 lines

Since this area of the discussion has strayed away from the path of Paul McKenney's original summary, I'm starting a new email thread and drastically cutting the CC list.

Quoted 6 lines · Arve Hjønnevåg
Quoted 4 lines

Maybe.  There aren't enough examples coded up yet to be sure.  At this point we could easily make the device argument required instead of optional, and we could add a device argument to pm_relax.

I think that would be a good start. I can create dummy devices for now where I don't already have a device.

Rafael and I spent some time discussing all this during LinuxCon. Combining what he thought with my own ideas led us to decide that the wakeup information should be stored in a separate structure, not in dev_pm_info.  These structures will be allocated dynamically when a device is enabled for remote wakeup (and presumably deallocated if a device is disabled for remote wakeup).  A pointer to the new structure will be stored in dev_pm_info.  We expect that most devices won't need a wakeup structure, because most devices aren't wakeup sources.

Quoted 3 lines

This new structure (as yet unnamed) will be a lot like your suspend_blocker structure, but with some differences.  It won't need a name, since the device already has a name.

A name is still useful if we allocate multiple handles per device (see below for why one handle per device is not enough).

Quoted 2 lines

 It won't have a timer, if
we can get away with leaving one out.

The suspend_blocker structure does not have a timer, it has a timeout. This was intentional, since it avoids unnecessary timers from firing but it also means it takes a lot less space than the stats. We do need the timeout in the structure to support some of our drivers since they mix wake_lock_timeout and wake_unlock.

Quoted 9 lines

 But it will optionally contain
various counters that can be used for statistics reporting and debugging.  The API for exporting these fields to userspace has not yet been decided upon.

The device argument will become mandatory for pm_stay_awake, pm_relax, and pm_wakeup_event, so that the counter fields can be updated properly.

I think this is a step in the right direction, but it is not enough to support mixing timeouts and pm_relax in all the drivers.

Quoted 14 lines
Quoted 9 lines
Quoted 8 lines

In the scheme we're talking about, the suspend-blocking interface for uesrspace would be located entirely in the power manager.  Hence it could maintain all the necessary statistics, without involving the kernel.  During early stages of system startup, before the power manager is running, lower-level services would not be able to block suspend.  This wouldn't matter because at those times the system simply would not ever suspend -- because suspends have to be initiated by the power manager.

Quoted 4 lines

If we do that, a low level process could try to block suspend while the power manager is not running. Then the power manager could start and decide to suspend not knowing that a low level process wanted to block suspend.

Quoted 6 lines

There's a simple solution: Put all this in a _new_, low-level power manager program that can be started very early during boot-up (before any of the other low-level services that need to block suspend).  Then all the other programs would communicate their suspend-blocker requirements to this program instead of to the kernel.

Maintaining an out of mainline driver to export allow user space to block suspend seems like a more appealing solution than adding another process for everyone to depend on. Having a user space interface to block suspend in the mainline kernel would still be valuable, though. Like I mentioned in another message, this would allow some low level services, like the user-space battery monitor some devices have, to not be android specific.

Quoted 17 lines

You expressed concern about the new power manager deadlocking.  This can be avoided by designing the program properly.  It should run in two threads.  Thread 1 will handle IPC, keeping track of userspace suspend-blocker requests, their statistics, and so on.  Thread 2 will manage the PM interface to the kernel, and it will execute the following simple loop:

       for (;;) {
               read /sys/power/wakeup_count    /* blocking read */ if (there are any active userspace suspend blockers) { wait until they are all deactivated } else {
                       if (write to /sys/power/wakeup_count succeeds) write "mem" to /sys/power/state }
       }

Quoted 2 lines

I think this will resolve the problem you were worried about.

I know how to avoid the deadlock. My point was that adding the code in the drivers to support the overlapping wakelock model of handling wakeup events, means that a single threaded power manager that did not deadlock before now could deadlock.

Quoted 18 lines
Quoted 10 lines
Quoted 10 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

I don't know if they are all kernel-internal but these drivers appear to use timeouts and active cancellation on the same wakelock:
wifi driver, mmc core, alarm driver, evdev (suspend blocker version removes the timeout).

Roughly speaking, what do the timings work out to be?  That is, how long are the timeouts for these wakelocks, how long does it usually take for one of them to be actively cancelled, and what percentage of them end up timing out?

Quoted 7 lines

The evdev timeout is a few seconds, and never timeout unless user space is misbehaving. I don't know how the wifi and mmc wakelocks are used. The alarm driver uses a 1 or 2 second timeout to abort suspend when an alarm is set to close to program an rtc alarm. I think this one is cancelled when the alarm triggers, and the timeout only handles the case where the client cancelled the alarm before it trigger, but I don't remember for sure.

Quoted 5 lines

Evdev turns out to be tricky for a couple of reasons.  One is this business of combining active cancellation with timeouts (we might end up needing a special-purpose timer for this).  Another is the way all input events funnel into a single event queue.

Input events do not funnel to a single event queue in the kernel (at least not with the interface I have used). There are separate queues for each client of every device.

Quoted 21 lines

For example, suppose you want the keyboard to be a wakeup device but not the mouse.  Once events get into the input queue, there's no way to tell where they came from.  Hence mouse motion events would prevent the system from suspending, even though they weren't supposed to.

Quoted 3 lines

You cannot easily mix timeouts, cancellations and nesting. Wakelocks/suspend blockers allow you to mix timeouts and cancellations.

That's true.  And it turns out that we do need to mix cancellations with nesting.  For example, it may well happen that pm_request_resume gets called several times before the pm workqueue thread gets around to resuming the device.  If each of those calls has a corresponding call to pm_stay_awake then we would like to cancel all of them with a single pm_relax after the driver's runtime_resume callback is finished.

On the other hand, the driver's runtime_resume routine might need to carry out some work in a different kernel thread.  It would call pm_stay_awake, and we wouldn't want _this_ call to be cancelled until the other thread has run.

Quoted 7 lines

In the end, the best answer may be to keep a count of pending wakeup events in the new wakeup structure (as well as a global count of the number of devices whose pending count is > 0).  Then pm_stay_awake would increment the count, pm_relax would decrement it, and there could be a variant of pm_stay_awake that would increment the count only if it was currently equal to 0.

If I correctly understand what you are suggesting, that does not work. If two subsystems use the same device an one of them expects the pm_stay_awake call to be nested and the other one does not, then the subsystem that uses the non-nested api is not preventing suspend if the other subsystem was preventing suspend when it called pm_stay_awake_if_not_zero (the non-nested pm_relax variant would cause similar problems). Also, to support all our existing drivers we need multiple handles per device. For each input device we have a wakelock with a timeout per client. We only allow suspend when all the clients have emptied their queue or had their wakelock timeout.

Quoted 6 lines
Quoted 3 lines

The cleanup is a little simpler when you don't nest and there is less chance that a missed edge case prevents suspend forever (we had a few of those bugs in our userspace code that used nested wakelocks).

Bugs in the kernel can be tracked down and fixed.

Yes, bugs can be fixed, but not all bugs are discovered quickly and products ship before some bugs are fixed. For instance, when applying our patch that holds a wakelock when the input queue is not empty to this weeks kernel, I noticed that someone had fixed a bug where a queue overflow could leave the queue empty. If you hit this bug with the wakelock with timeout implementation that we currently use, then it would cause suspend to be blocked for 5 seconds (less if another event occurred or the file descriptor was closed). With the patch that uses a suspend blocker without a timeout, it would block suspend until another event from the same device occurred or user space closes the device. With a nesting api like the current pm_stay_awake/pm_relax, it will prevent suspend forever (unless another driver has the opposite bug).

Do we need the nested api for something? We need a non-nested api to mix timeouts and pm_relax, and unless we need the nested variants, it is easier to just make all the calls non-nesting.

Quoted 9 lines
Quoted 3 lines

If
the above is all you do, then you block suspend forever if someone closes an non-empty input device.

That sounds like a fixable bug.  :-)

Alan Stern

Signature · 1 line
Arve Hjønnevåg
#288 lore raw

Re: Wakeup-events implementation

Quoted 9 lines · Arve Hjønnevåg
Quoted 9 lines

Rafael and I spent some time discussing all this during LinuxCon. Combining what he thought with my own ideas led us to decide that the wakeup information should be stored in a separate structure, not in dev_pm_info.  These structures will be allocated dynamically when a device is enabled for remote wakeup (and presumably deallocated if a device is disabled for remote wakeup).  A pointer to the new structure will be stored in dev_pm_info.  We expect that most devices won't need a wakeup structure, because most devices aren't wakeup sources.

Quoted 6 lines
Quoted 3 lines

This new structure (as yet unnamed) will be a lot like your suspend_blocker structure, but with some differences.  It won't need a name, since the device already has a name.

A name is still useful if we allocate multiple handles per device (see below for why one handle per device is not enough).

Are the input queues are the only place where this is needed?

And BTW, I'm puzzled with regard to something you wrote earlier:

Quoted 8 lines
Quoted 5 lines

... I can see how relying on devices alone
wouldn't give enough information. There could be two separate programs both reading input events, and you wouldn't know which one was responsible for failing to drain its queue.

We don't know which one now either since we don't give them unique names, but we know that one of them is not reading (and it is usually not the normal input path).

If you don't keep track of the input queues by name, why do you need a separate wakeup structure for each queue?

Quoted 8 lines
Quoted 2 lines

 It won't have a timer, if
we can get away with leaving one out.

The suspend_blocker structure does not have a timer, it has a timeout. This was intentional, since it avoids unnecessary timers from firing but it also means it takes a lot less space than the stats. We do need the timeout in the structure to support some of our drivers since they mix wake_lock_timeout and wake_unlock.

A timeout is okay.

Quoted 6 lines
Quoted 4 lines

The device argument will become mandatory for pm_stay_awake, pm_relax, and pm_wakeup_event, so that the counter fields can be updated properly.

I think this is a step in the right direction, but it is not enough to support mixing timeouts and pm_relax in all the drivers.

We'll figure out the best approach. You mentioned that when the timeouts and pm_relax do get mixed, the timeout value is around 1 or 2 seconds. For these cases, would it be so terrible just to use the timeout alone and forget about pm_relax?

Quoted 7 lines

Maintaining an out of mainline driver to export allow user space to block suspend seems like a more appealing solution than adding another process for everyone to depend on. Having a user space interface to block suspend in the mainline kernel would still be valuable, though. Like I mentioned in another message, this would allow some low level services, like the user-space battery monitor some devices have, to not be android specific.

Adding out-of-mainline drivers is of course always possible. As for your second point, I guess it's a matter of perspective. You see the kernel as always trying to suspend, with userspace needing to do something special to keep it awake. Rafael and I see it as userspace occasionally asking the kernel to suspend, and the kernel delaying or aborting if a wakeup event occurs. This is because we believe that suspends should be initiated by userspace, not by the kernel. From our point of view there doesn't have to be a user interface to block suspends; you only need a way for one part of userspace to tell another to stop requesting a suspend.

This could become non-Android-specific as well, if people decide on some standard way for system management programs to decide when the system should go to sleep.

Quoted 8 lines
Quoted 7 lines

In the end, the best answer may be to keep a count of pending wakeup events in the new wakeup structure (as well as a global count of the number of devices whose pending count is > 0).  Then pm_stay_awake would increment the count, pm_relax would decrement it, and there could be a variant of pm_stay_awake that would increment the count only if it was currently equal to 0.

Quoted 7 lines

If I correctly understand what you are suggesting, that does not work. If two subsystems use the same device an one of them expects the pm_stay_awake call to be nested and the other one does not, then the subsystem that uses the non-nested api is not preventing suspend if the other subsystem was preventing suspend when it called pm_stay_awake_if_not_zero (the non-nested pm_relax variant would cause similar problems).

Do you have any examples where two subsystems use the same device but with differing expectations? In the examples I can think of, the non-nesting call is used only when a wakeup request is received (which happens only when the device is at low power), so the nesting calls can't interfere.

Quoted 4 lines

Also, to support all our existing drivers we need
multiple handles per device. For each input device we have a wakelock with a timeout per client. We only allow suspend when all the clients have emptied their queue or had their wakelock timeout.

We may end up attaching these wakeup structures not just to devices but also to input queues (or other kernel->userspace communication channels).

Quoted 17 lines
Quoted 2 lines

Bugs in the kernel can be tracked down and fixed.

Yes, bugs can be fixed, but not all bugs are discovered quickly and products ship before some bugs are fixed. For instance, when applying our patch that holds a wakelock when the input queue is not empty to this weeks kernel, I noticed that someone had fixed a bug where a queue overflow could leave the queue empty. If you hit this bug with the wakelock with timeout implementation that we currently use, then it would cause suspend to be blocked for 5 seconds (less if another event occurred or the file descriptor was closed). With the patch that uses a suspend blocker without a timeout, it would block suspend until another event from the same device occurred or user space closes the device. With a nesting api like the current pm_stay_awake/pm_relax, it will prevent suspend forever (unless another driver has the opposite bug).

Quoted 3 lines

Do we need the nested api for something? We need a non-nested api to mix timeouts and pm_relax, and unless we need the nested variants, it is easier to just make all the calls non-nesting.

Here's an example where nested pm_stay_awake calls are needed. Suppose a USB root hub is enabled for wakeup (in other words, plugging or unplugging a USB device into the computer should wake the system up). Suppose the root hub is at low power (autosuspended) when a wakeup event occurs. The interrupt handler calls pm_stay_awake and indirectly invokes the USB runtime-resume routine. This routine brings the root hub back to full power, informs the hub driver, and then calls pm_relax.

But the hub driver carries out its main work in a separate kernel thread (i.e., khubd). So the hub_resume routine has to call pm_stay_awake, and then khubd calls pm_relax when it is finished processing the root hub's event. Thus we end up with:

usb_runtime_resume: call pm_stay_awake (1)
call hub_resume
hub_resume: call pm_stay_awake (2)
usb_runtime_resume: call pm_relax (balances 1)
khubd: call pm_relax (balances 2)

As you can see, this won't work right if the pm wakeup calls aren't cumulative. ("Nested" isn't quite the right word.) The system would be allowed to sleep before khubd could process the root hub's wakeup event.

Alan Stern

#289 lore raw

Re: Wakeup-events implementation

2010/8/16 Alan Stern <[email protected]>:

Quoted 11 lines · Arve Hjønnevåg
Quoted 10 lines
Quoted 10 lines

Rafael and I spent some time discussing all this during LinuxCon. Combining what he thought with my own ideas led us to decide that the wakeup information should be stored in a separate structure, not in dev_pm_info.  These structures will be allocated dynamically when a device is enabled for remote wakeup (and presumably deallocated if a device is disabled for remote wakeup).  A pointer to the new structure will be stored in dev_pm_info.  We expect that most devices won't need a wakeup structure, because most devices aren't wakeup sources.

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

This new structure (as yet unnamed) will be a lot like your suspend_blocker structure, but with some differences.  It won't need a name, since the device already has a name.

A name is still useful if we allocate multiple handles per device (see below for why one handle per device is not enough).

Are the input queues are the only place where this is needed?

I don't know if it is the only place that is using more than one wakelock with a timeout per device. There are other drivers that use more than one wakelock, but it is possible they could use a single nested lock instead (with some detail loss in the the stats). I'm not sure every wakelock can be associated with a device though. For instance the mmc core wakelock does not have a corresponding device.

Quoted 7 lines

And BTW, I'm puzzled with regard to something you wrote earlier:

Quoted 5 lines
Quoted 5 lines

... I can see how relying on devices alone
wouldn't give enough information.  There could be two separate programs both reading input events, and you wouldn't know which one was responsible for failing to drain its queue.

Quoted 7 lines
Quoted 3 lines

We don't know which one now either since we don't give them unique names, but we know that one of them is not reading (and it is usually not the normal input path).

If you don't keep track of the input queues by name, why do you need a separate wakeup structure for each queue?

Primarily for the timeouts, but the individual stats are still useful even if they don't name the client.

Quoted 15 lines
Quoted 8 lines
Quoted 2 lines

 It won't have a timer, if
we can get away with leaving one out.

The suspend_blocker structure does not have a timer, it has a timeout. This was intentional, since it avoids unnecessary timers from firing but it also means it takes a lot less space than the stats. We do need the timeout in the structure to support some of our drivers since they mix wake_lock_timeout and wake_unlock.

A timeout is okay.

Quoted 4 lines
Quoted 4 lines

The device argument will become mandatory for pm_stay_awake, pm_relax, and pm_wakeup_event, so that the counter fields can be updated properly.

Quoted 8 lines
Quoted 2 lines

I think this is a step in the right direction, but it is not enough to support mixing timeouts and pm_relax in all the drivers.

We'll figure out the best approach.  You mentioned that when the timeouts and pm_relax do get mixed, the timeout value is around 1 or 2 seconds.  For these cases, would it be so terrible just to use the timeout alone and forget about pm_relax?

The timeout used when mixing timeouts and wake_unlock are generally longer than when only using only timeouts since the timeouts are used to cover edge cases were wake_unlock did not get called. Allowing timeouts and pm_relax to be mixed may allow a gradual path from using timeouts to block suspend only when needed (timeouts only -> timeouts for edge cases -> no timeouts).

We have also had bugs, where sensors generate input events whenever the system is not suspended. The 5 second timeout we have on input events is not short enough to allow the system to suspend at all in this case.

Quoted 8 lines
Quoted 7 lines

Maintaining an out of mainline driver to export allow user space to block suspend seems like a more appealing solution than adding another process for everyone to depend on. Having a user space interface to block suspend in the mainline kernel would still be valuable, though. Like I mentioned in another message, this would allow some low level services, like the user-space battery monitor some devices have, to not be android specific.

Quoted 4 lines

Adding out-of-mainline drivers is of course always possible.  As for your second point, I guess it's a matter of perspective.  You see the kernel as always trying to suspend, with userspace needing to do something special to keep it awake.

I see the kernel as trying to suspend if user space asked it to suspend (until it user space asks the kernel to stop suspending). Wakeup events that don't reach user space should not need user space support to reenter suspend.

Quoted 4 lines

 Rafael and I see it as userspace
occasionally asking the kernel to suspend, and the kernel delaying or aborting if a wakeup event occurs.  This is because we believe that suspends should be initiated by userspace, not by the kernel.

You want each suspend attempt to be initiated by user space. Suspend is initiated from user space in both cases, the difference is that you want the suspend request to be one-shot, which means that the kernel may cancel the user space suspend request, where I want user space to explicitly cancel the request.

Quoted 5 lines

 From our
point of view there doesn't have to be a user interface to block suspends; you only need a way for one part of userspace to tell another to stop requesting a suspend.

The user space interface to block suspend is not all that relevant here. Both suspend interfaces can be used with or without a user space interface to block suspend.

Quoted 20 lines

This could become non-Android-specific as well, if people decide on some standard way for system management programs to decide when the system should go to sleep.

Quoted 8 lines
Quoted 7 lines

In the end, the best answer may be to keep a count of pending wakeup events in the new wakeup structure (as well as a global count of the number of devices whose pending count is > 0).  Then pm_stay_awake would increment the count, pm_relax would decrement it, and there could be a variant of pm_stay_awake that would increment the count only if it was currently equal to 0.

Quoted 7 lines

If I correctly understand what you are suggesting, that does not work. If two subsystems use the same device an one of them expects the pm_stay_awake call to be nested and the other one does not, then the subsystem that uses the non-nested api is not preventing suspend if the other subsystem was preventing suspend when it called pm_stay_awake_if_not_zero (the non-nested pm_relax variant would cause similar problems).

Quoted 6 lines

Do you have any examples where two subsystems use the same device but with differing expectations?  In the examples I can think of, the non-nesting call is used only when a wakeup request is received (which happens only when the device is at low power), so the nesting calls can't interfere.

The wakeup request need to block suspend until the driver has seen the event. If the driver and the wakeup code uses the same handle how can you avoid interference?

Quoted 9 lines
Quoted 4 lines

Also, to support all our existing drivers we need
multiple handles per device. For each input device we have a wakelock with a timeout per client. We only allow suspend when all the clients have emptied their queue or had their wakelock timeout.

We may end up attaching these wakeup structures not just to devices but also to input queues (or other kernel->userspace communication channels).

That is we do now (with wakelocks), but I think we need to pass this handle to the pm_stay_wake... calls, and not the device, for this to work.

Quoted 41 lines
Quoted 17 lines
Quoted 2 lines

Bugs in the kernel can be tracked down and fixed.

Yes, bugs can be fixed, but not all bugs are discovered quickly and products ship before some bugs are fixed. For instance, when applying our patch that holds a wakelock when the input queue is not empty to this weeks kernel, I noticed that someone had fixed a bug where a queue overflow could leave the queue empty. If you hit this bug with the wakelock with timeout implementation that we currently use, then it would cause suspend to be blocked for 5 seconds (less if another event occurred or the file descriptor was closed). With the patch that uses a suspend blocker without a timeout, it would block suspend until another event from the same device occurred or user space closes the device. With a nesting api like the current pm_stay_awake/pm_relax, it will prevent suspend forever (unless another driver has the opposite bug).

Quoted 3 lines

Do we need the nested api for something? We need a non-nested api to mix timeouts and pm_relax, and unless we need the nested variants, it is easier to just make all the calls non-nesting.

Here's an example where nested pm_stay_awake calls are needed. Suppose a USB root hub is enabled for wakeup (in other words, plugging or unplugging a USB device into the computer should wake the system up).  Suppose the root hub is at low power (autosuspended) when a wakeup event occurs.  The interrupt handler calls pm_stay_awake and indirectly invokes the USB runtime-resume routine.  This routine brings the root hub back to full power, informs the hub driver, and then calls pm_relax.

But the hub driver carries out its main work in a separate kernel thread (i.e., khubd).  So the hub_resume routine has to call pm_stay_awake, and then khubd calls pm_relax when it is finished processing the root hub's event.  Thus we end up with:

       usb_runtime_resume:     call pm_stay_awake (1) call hub_resume
               hub_resume:             call pm_stay_awake (2)
       usb_runtime_resume:     call pm_relax (balances 1)
       khubd:                  call pm_relax (balances 2)

Quoted 5 lines

As you can see, this won't work right if the pm wakeup calls aren't cumulative.  ("Nested" isn't quite the right word.)  The system would be allowed to sleep before khubd could process the root hub's wakeup event.

Too me this is an example of where two handles are needed, not where nesting is needed. Yes, you can use a single nested handle here, but the stats will not tell you which driver blocked suspend if there is a problem.

Signature · 1 line
Arve Hjønnevåg
#290 lore raw

Re: Wakeup-events implementation

Quoted 6 lines · Arve Hjønnevåg
Quoted 5 lines
Quoted 2 lines

A name is still useful if we allocate multiple handles per device (see below for why one handle per device is not enough).

Are the input queues are the only place where this is needed?

Quoted 6 lines

I don't know if it is the only place that is using more than one wakelock with a timeout per device. There are other drivers that use more than one wakelock, but it is possible they could use a single nested lock instead (with some detail loss in the the stats). I'm not sure every wakelock can be associated with a device though. For instance the mmc core wakelock does not have a corresponding device.

What other drivers need more than one wakelock per device?

For that matter, why does the MMC core need wakelocks at all? I wasn't aware that memory cards could generate wakeup events.

Quoted 6 lines
Quoted 5 lines

We'll figure out the best approach.  You mentioned that when the timeouts and pm_relax do get mixed, the timeout value is around 1 or 2 seconds.  For these cases, would it be so terrible just to use the timeout alone and forget about pm_relax?

Quoted 6 lines

The timeout used when mixing timeouts and wake_unlock are generally longer than when only using only timeouts since the timeouts are used to cover edge cases were wake_unlock did not get called. Allowing timeouts and pm_relax to be mixed may allow a gradual path from using timeouts to block suspend only when needed (timeouts only -> timeouts for edge cases -> no timeouts).

In fact, I rather expected you would say that the combined cancellations/timeouts were useful for pinpointing applications that don't read their input events quickly enough. If the wakelocks were always allowed to time out instead of being cancelled when the data was read, you wouldn't be able to tell whether the data was read in a timely manner or not.

Quoted 4 lines

We have also had bugs, where sensors generate input events whenever the system is not suspended. The 5 second timeout we have on input events is not short enough to allow the system to suspend at all in this case.

This sounds like the sort of bug that would be found very quickly and easily if you didn't have active cancellation. It would be pretty obvious when the system didn't suspend at all.

Quoted 4 lines

I see the kernel as trying to suspend if user space asked it to suspend (until it user space asks the kernel to stop suspending). Wakeup events that don't reach user space should not need user space support to reenter suspend.

That's debatable. For example, consider a Wake-On-LAN magic packet. It generally doesn't go anywhere -- it gets dropped once the system is awake.

Quoted 5 lines

You want each suspend attempt to be initiated by user space. Suspend is initiated from user space in both cases, the difference is that you want the suspend request to be one-shot, which means that the kernel may cancel the user space suspend request, where I want user space to explicitly cancel the request.

Yes, that's a fair way to describe the situation.

Quoted 10 lines
Quoted 6 lines

Do you have any examples where two subsystems use the same device but with differing expectations?  In the examples I can think of, the non-nesting call is used only when a wakeup request is received (which happens only when the device is at low power), so the nesting calls can't interfere.

The wakeup request need to block suspend until the driver has seen the event. If the driver and the wakeup code uses the same handle how can you avoid interference?

Let's say the interrupt handlers responsible for invoking pm_request_resume use non-nesting calls. This may happen several times, depending on the wakeup and interrupt delivery mechanism, but the end result is that the counter is incremented only once. When the pm_runtime_resume call ends, pm_relax does a single decrement.

Meanwhile, the driver uses nesting calls. It can increment the counter as much as it wants, and it has to perform an equal number of decrements. The key point is that pm_request_resume never gets called while the driver has any outstanding pm_stay_awake requests. Hence the non-nesting calls never got "lost", since the first one is always made while the counter is 0.

Quoted 8 lines
Quoted 4 lines

We may end up attaching these wakeup structures not just to devices but also to input queues (or other kernel->userspace communication channels).

That is we do now (with wakelocks), but I think we need to pass this handle to the pm_stay_wake... calls, and not the device, for this to work.

You may be right. Or we may need additional calls taking the handle as an argument rather than the device. The design requirements are still simmering in my mind, and I'm waiting to hear what Rafael thinks.

Quoted 26 lines
Quoted 20 lines

Here's an example where nested pm_stay_awake calls are needed. Suppose a USB root hub is enabled for wakeup (in other words, plugging or unplugging a USB device into the computer should wake the system up).  Suppose the root hub is at low power (autosuspended) when a wakeup event occurs.  The interrupt handler calls pm_stay_awake and indirectly invokes the USB runtime-resume routine.  This routine brings the root hub back to full power, informs the hub driver, and then calls pm_relax.

But the hub driver carries out its main work in a separate kernel thread (i.e., khubd).  So the hub_resume routine has to call pm_stay_awake, and then khubd calls pm_relax when it is finished processing the root hub's event.  Thus we end up with:

       usb_runtime_resume:     call pm_stay_awake (1) call hub_resume
               hub_resume:             call pm_stay_awake (2)
       usb_runtime_resume:     call pm_relax (balances 1)
       khubd:                  call pm_relax (balances 2)

Quoted 5 lines

As you can see, this won't work right if the pm wakeup calls aren't cumulative.  ("Nested" isn't quite the right word.)  The system would be allowed to sleep before khubd could process the root hub's wakeup event.

Quoted 4 lines

Too me this is an example of where two handles are needed, not where nesting is needed. Yes, you can use a single nested handle here, but the stats will not tell you which driver blocked suspend if there is a problem.

It sounds like you're suggesting that handles should be allocated per-driver rather than per-device. That would tell you which driver blocked suspend, but not which device.

This raises a few other questions.

With Android-based handsets, you're in a setting where you have a pretty good idea of what all the wakeup sources are and how they might get used. On a general system this isn't so. Many devices are potential wakeup sources, even though only a few of them end up getting enabled. In the example above, I said "Suppose a USB root hub is enabled for wakeup". But usually people won't want to do this; they don't want their suspended laptops to wake up when a USB mouse is unplugged or plugged in.

Allocating these wakeup structures for all possible wakeup sources would be a big waste. On the other hand, a driver generally doesn't know until a suspend starts whether or not its devices should be enabled for wakeup. That makes things difficult, especially if you contemplate having multiple structures for each device. Have you really sat down and thought about what wakelocks would be needed on a general system such as a desktop or laptop machine?

Also, I frankly have to wonder why you demand such a large amount of detailed debugging about the kernel's wakeup/wakelock subsystem (as opposed to userspace wakelocks). Yes, it's clear that if something goes wrong then you will drain your phone's battery in a few hours rather than a few days. But what if something goes wrong with the VM subsystem, or the RF subsystem, or the keypad driver? The device would crash immediately or at best become almost totally unusable. These are much worse scenarios than losing some battery life -- have you added comparable quantities of debugging to those other parts of the kernel?

In addition, you retain all these debugging facilities in your production builds, not just in the debug kernels. Doesn't this seem excessive?

Alan Stern

#291 lore raw

Re: Wakeup-events implementation

--- On Tue, 8/17/10, Alan Stern <[email protected]> wrote:

I wasn't

Quoted 1 line

aware that memory cards could generate wakeup events.

Almost all MMC/SD hardware can generate reliable insert/remove events, in my experience. So MMC/SD drivers I've modified tend to treat them as wake events ... userspace can respond without polling constantly "did it change yet, huh, did it???"

Unfortunately Pierre spent a lot of time hard-wiring UNSAFE_RESUME assumptions into the MMC core, so lots of that stuff is currently (and needlessly) broken.

And of more experimental interest, something I don't recall being discussed here: I/O completions as wake events. Start an I/O, enter low power state, and wake when it completes. Easily done on lots of embedded hardware..

#292 lore raw

Re: Wakeup-events implementation

Quoted 10 lines · David Brownell

--- On Tue, 8/17/10, Alan Stern <[email protected]> wrote:

I wasn't

Quoted 1 line

aware that memory cards could generate wakeup events.

Almost all MMC/SD hardware can generate reliable insert/remove events, in my experience. So MMC/SD drivers I've modified tend to treat them as wake events ... userspace can respond without polling constantly "did it change yet, huh, did it???"

This is interesting in light of the fact that testing has shown many USB card readers don't track insert/remove events while in low-power mode. When they return to full power, if a card is present they always report a media change -- even if the card had been there all along. This makes autosuspend less useful than it might be.

Quoted 3 lines

Unfortunately Pierre spent a lot of time hard-wiring UNSAFE_RESUME assumptions into the MMC core, so lots of that stuff is currently (and needlessly) broken.

There's a difference between generating wakeup events for insert/remove and keeping track of media-change events. I wouldn't want my sleeping laptop to wake up when I insert or remove a memory card, but I would like it to recognize when a card has been changed. If the hardware can do one but not the other then Pierre's choice is understandable (although not in accord with Linus's preference).

Alan Stern

#293 lore raw

Re: Wakeup-events implementation

In reply to Alan Stern
Quoted 15 lines · Alan Stern
Quoted 6 lines · Arve Hjønnevåg
Quoted 5 lines
Quoted 2 lines

A name is still useful if we allocate multiple handles per device (see below for why one handle per device is not enough).

Are the input queues are the only place where this is needed?

Quoted 6 lines

I don't know if it is the only place that is using more than one wakelock with a timeout per device. There are other drivers that use more than one wakelock, but it is possible they could use a single nested lock instead (with some detail loss in the the stats). I'm not sure every wakelock can be associated with a device though. For instance the mmc core wakelock does not have a corresponding device.

Quoted 4 lines

What other drivers need more than one wakelock per device?

For that matter, why does the MMC core need wakelocks at all? I wasn't aware that memory cards could generate wakeup events.

Yes, that's interesting, although I _guess_ this is related to the events generated by inserting/removing a card.

Quoted 29 lines
Quoted 6 lines
Quoted 5 lines

We'll figure out the best approach. You mentioned that when the timeouts and pm_relax do get mixed, the timeout value is around 1 or 2 seconds. For these cases, would it be so terrible just to use the timeout alone and forget about pm_relax?

Quoted 6 lines

The timeout used when mixing timeouts and wake_unlock are generally longer than when only using only timeouts since the timeouts are used to cover edge cases were wake_unlock did not get called. Allowing timeouts and pm_relax to be mixed may allow a gradual path from using timeouts to block suspend only when needed (timeouts only -> timeouts for edge cases -> no timeouts).

In fact, I rather expected you would say that the combined cancellations/timeouts were useful for pinpointing applications that don't read their input events quickly enough. If the wakelocks were always allowed to time out instead of being cancelled when the data was read, you wouldn't be able to tell whether the data was read in a timely manner or not.

Quoted 4 lines

We have also had bugs, where sensors generate input events whenever the system is not suspended. The 5 second timeout we have on input events is not short enough to allow the system to suspend at all in this case.

This sounds like the sort of bug that would be found very quickly and easily if you didn't have active cancellation. It would be pretty obvious when the system didn't suspend at all.

Quoted 8 lines
Quoted 4 lines

I see the kernel as trying to suspend if user space asked it to suspend (until it user space asks the kernel to stop suspending). Wakeup events that don't reach user space should not need user space support to reenter suspend.

That's debatable. For example, consider a Wake-On-LAN magic packet. It generally doesn't go anywhere -- it gets dropped once the system is awake.

Yes. I think every event that would wake up a sleeping system should result in unfreezing user space.

Quoted 2 lines
Quoted 2 lines

You want each suspend attempt to be initiated by user space. Suspend is initiated from user space in both cases,

Not really. With wakelocks suspend may be initiated as a result of a driver dropping its wakelock, which doesn't qualify as "from user space" to me.

Quoted 5 lines
Quoted 3 lines

the difference is that you want the suspend request to be one-shot, which means that the kernel may cancel the user space suspend request, where I want user space to explicitly cancel the request.

Yes, that's a fair way to describe the situation.

I somewhat agree.

Quoted 29 lines
Quoted 10 lines
Quoted 6 lines

Do you have any examples where two subsystems use the same device but with differing expectations? In the examples I can think of, the non-nesting call is used only when a wakeup request is received (which happens only when the device is at low power), so the nesting calls can't interfere.

The wakeup request need to block suspend until the driver has seen the event. If the driver and the wakeup code uses the same handle how can you avoid interference?

Let's say the interrupt handlers responsible for invoking pm_request_resume use non-nesting calls. This may happen several times, depending on the wakeup and interrupt delivery mechanism, but the end result is that the counter is incremented only once. When the pm_runtime_resume call ends, pm_relax does a single decrement.

Meanwhile, the driver uses nesting calls. It can increment the counter as much as it wants, and it has to perform an equal number of decrements. The key point is that pm_request_resume never gets called while the driver has any outstanding pm_stay_awake requests. Hence the non-nesting calls never got "lost", since the first one is always made while the counter is 0.

Quoted 5 lines
Quoted 4 lines

We may end up attaching these wakeup structures not just to devices but also to input queues (or other kernel->userspace communication channels).

Quoted 7 lines
Quoted 3 lines

That is we do now (with wakelocks), but I think we need to pass this handle to the pm_stay_wake... calls, and not the device, for this to work.

You may be right. Or we may need additional calls taking the handle as an argument rather than the device. The design requirements are still simmering in my mind, and I'm waiting to hear what Rafael thinks.

I actually like the idea of having two levels of calls, ie. pm_stay_awake(dev) calling something like __pm_stay_awake(handle), where the handle is read from struct dev_pm_info. And analogously for pm_relax().

Then, the object associated with the handle might be created when the device is enabled to wake up and destroyed when it's disabled to do that.

OTOH, if it's really necessary to use a "raw" handle (ie. without struct device), the caller of __pm_stay_awake() will allocate and free the "wakelock" object by itself as necessary.

As far as the names are concerned, I'd like to avoid allocating space for them whenever it is not necessary (like when the "wakelock" is pointed to by struct dev_pm_info, in which case it is simply sufficient to use the device name to refer to it).

Quoted 46 lines
Quoted 26 lines
Quoted 20 lines

Here's an example where nested pm_stay_awake calls are needed. Suppose a USB root hub is enabled for wakeup (in other words, plugging or unplugging a USB device into the computer should wake the system up). Suppose the root hub is at low power (autosuspended) when a wakeup event occurs. The interrupt handler calls pm_stay_awake and indirectly invokes the USB runtime-resume routine. This routine brings the root hub back to full power, informs the hub driver, and then calls pm_relax.

But the hub driver carries out its main work in a separate kernel thread (i.e., khubd). So the hub_resume routine has to call pm_stay_awake, and then khubd calls pm_relax when it is finished processing the root hub's event. Thus we end up with:

usb_runtime_resume: call pm_stay_awake (1)
call hub_resume
hub_resume: call pm_stay_awake (2)
usb_runtime_resume: call pm_relax (balances 1)
khubd: call pm_relax (balances 2)

Quoted 5 lines

As you can see, this won't work right if the pm wakeup calls aren't cumulative. ("Nested" isn't quite the right word.) The system would be allowed to sleep before khubd could process the root hub's wakeup event.

Quoted 4 lines

Too me this is an example of where two handles are needed, not where nesting is needed. Yes, you can use a single nested handle here, but the stats will not tell you which driver blocked suspend if there is a problem.

It sounds like you're suggesting that handles should be allocated per-driver rather than per-device. That would tell you which driver blocked suspend, but not which device.

This raises a few other questions.

With Android-based handsets, you're in a setting where you have a pretty good idea of what all the wakeup sources are and how they might get used. On a general system this isn't so. Many devices are potential wakeup sources, even though only a few of them end up getting enabled. In the example above, I said "Suppose a USB root hub is enabled for wakeup". But usually people won't want to do this; they don't want their suspended laptops to wake up when a USB mouse is unplugged or plugged in.

Quoted 2 lines

Allocating these wakeup structures for all possible wakeup sources would be a big waste.

Indeed.

Quoted 10 lines

On the other hand, a driver generally doesn't
know until a suspend starts whether or not its devices should be enabled for wakeup. That makes things difficult, especially if you contemplate having multiple structures for each device. Have you really sat down and thought about what wakelocks would be needed on a general system such as a desktop or laptop machine?

Also, I frankly have to wonder why you demand such a large amount of detailed debugging about the kernel's wakeup/wakelock subsystem (as opposed to userspace wakelocks).

That also is my question.

Quoted 11 lines

Yes, it's clear that if something
goes wrong then you will drain your phone's battery in a few hours rather than a few days. But what if something goes wrong with the VM subsystem, or the RF subsystem, or the keypad driver? The device would crash immediately or at best become almost totally unusable. These are much worse scenarios than losing some battery life -- have you added comparable quantities of debugging to those other parts of the kernel?

In addition, you retain all these debugging facilities in your production builds, not just in the debug kernels. Doesn't this seem excessive?

It definitely seems so.

Thanks,
Rafael

#294 lore raw

Re: Wakeup-events implementation

2010/8/17 Rafael J. Wysocki <[email protected]>:

Quoted 16 lines · Alan Stern
Quoted 15 lines · Arve Hjønnevåg
Quoted 13 lines
Quoted 6 lines
Quoted 3 lines

A name is still useful if we allocate multiple handles per device (see below for why one handle per device is not enough).

Are the input queues are the only place where this is needed?

I don't know if it is the only place that is using more than one wakelock with a timeout per device. There are other drivers that use more than one wakelock, but it is possible they could use a single nested lock instead (with some detail loss in the the stats). I'm not sure every wakelock can be associated with a device though. For instance the mmc core wakelock does not have a corresponding device.

Quoted 8 lines
Quoted 4 lines

What other drivers need more than one wakelock per device?

For that matter, why does the MMC core need wakelocks at all?  I wasn't aware that memory cards could generate wakeup events.

Yes, that's interesting, although I _guess_ this is related to the events generated by inserting/removing a card.

That is my guess too, but it is also possible sdio wakeup events could also hit this code path.

Quoted 25 lines
Quoted 25 lines
Quoted 6 lines
Quoted 5 lines

We'll figure out the best approach.  You mentioned that when the timeouts and pm_relax do get mixed, the timeout value is around 1 or 2 seconds.  For these cases, would it be so terrible just to use the timeout alone and forget about pm_relax?

Quoted 6 lines

The timeout used when mixing timeouts and wake_unlock are generally longer than when only using only timeouts since the timeouts are used to cover edge cases were wake_unlock did not get called. Allowing timeouts and pm_relax to be mixed may allow a gradual path from using timeouts to block suspend only when needed (timeouts only -> timeouts for edge cases -> no timeouts).

In fact, I rather expected you would say that the combined cancellations/timeouts were useful for pinpointing applications that don't read their input events quickly enough.  If the wakelocks were always allowed to time out instead of being cancelled when the data was read, you wouldn't be able to tell whether the data was read in a timely manner or not.

Quoted 4 lines

We have also had bugs, where sensors generate input events whenever the system is not suspended. The 5 second timeout we have on input events is not short enough to allow the system to suspend at all in this case.

Quoted 4 lines
Quoted 4 lines

This sounds like the sort of bug that would be found very quickly and easily if you didn't have active cancellation.  It would be pretty obvious when the system didn't suspend at all.

We don't uncover all bugs during testing before we ship. For instance the bug could be triggered by a 3db party app, and there is value in making the system as robust as possible to both driver and user space bugs.

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

I see the kernel as trying to suspend if user space asked it to suspend (until it user space asks the kernel to stop suspending). Wakeup events that don't reach user space should not need user space support to reenter suspend.

Quoted 7 lines
Quoted 3 lines

That's debatable.  For example, consider a Wake-On-LAN magic packet. It generally doesn't go anywhere -- it gets dropped once the system is awake.

Yes.  I think every event that would wake up a sleeping system should result in unfreezing user space.

Returning all the way to user space for every wakeup event is a poor substitute for delivering the actual event to user space. If user space want to stay awake for 60 seconds after every wake-on-lan packet, how can it accomplish this if it does not get the event. If user space delays suspend for 60 seconds after every failed suspend attempt, a wake-on-lan packet that arrives just before it decided to suspend will be ignored.

Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

You want each suspend attempt to be initiated by user space. Suspend is initiated from user space in both cases,

Not really.  With wakelocks suspend may be initiated as a result of a driver dropping its wakelock, which doesn't qualify as "from user space" to me.

Sure, but only if user-space had already requested suspend.

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

the difference is that you want the suspend request to be one-shot, which means that the kernel may cancel the user space suspend request, where I want user space to explicitly cancel the request.

Quoted 28 lines
Quoted 1 line

Yes, that's a fair way to describe the situation.

I somewhat agree.

Quoted 24 lines
Quoted 10 lines
Quoted 6 lines

Do you have any examples where two subsystems use the same device but with differing expectations?  In the examples I can think of, the non-nesting call is used only when a wakeup request is received (which happens only when the device is at low power), so the nesting calls can't interfere.

The wakeup request need to block suspend until the driver has seen the event. If the driver and the wakeup code uses the same handle how can you avoid interference?

Let's say the interrupt handlers responsible for invoking pm_request_resume use non-nesting calls.  This may happen several times, depending on the wakeup and interrupt delivery mechanism, but the end result is that the counter is incremented only once.  When the pm_runtime_resume call ends, pm_relax does a single decrement.

Meanwhile, the driver uses nesting calls.  It can increment the counter as much as it wants, and it has to perform an equal number of decrements.  The key point is that pm_request_resume never gets called while the driver has any outstanding pm_stay_awake requests.  Hence the non-nesting calls never got "lost", since the first one is always made while the counter is 0.

It sounds as if you are saying that the two drivers don't interfere because one of them always gets there first. In your example if another interrupt occurs before the second driver still has released all its references on the counter, the interrupt will (incorrectly) not increment the count.

Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

We may end up attaching these wakeup structures not just to devices but also to input queues (or other kernel->userspace communication channels).

Quoted 7 lines
Quoted 3 lines

That is we do now (with wakelocks), but I think we need to pass this handle to the pm_stay_wake... calls, and not the device, for this to work.

You may be right.  Or we may need additional calls taking the handle as an argument rather than the device.  The design requirements are still simmering in my mind, and I'm waiting to hear what Rafael thinks.

Quoted 7 lines

I actually like the idea of having two levels of calls, ie. pm_stay_awake(dev) calling something like __pm_stay_awake(handle), where the handle is read from struct dev_pm_info.  And analogously for pm_relax().

Then, the object associated with the handle might be created when the device is enabled to wake up and destroyed when it's disabled to do that.

When multiple drivers use the same device, who creates and destroys the handle?

Quoted 4 lines

OTOH, if it's really necessary to use a "raw" handle (ie. without struct device), the caller of __pm_stay_awake() will allocate and free the "wakelock" object by itself as necessary.

Quoted 40 lines

As far as the names are concerned, I'd like to avoid allocating space for them whenever it is not necessary (like when the "wakelock" is pointed to by struct dev_pm_info, in which case it is simply sufficient to use the device name to refer to it).

Quoted 35 lines
Quoted 26 lines
Quoted 20 lines

Here's an example where nested pm_stay_awake calls are needed. Suppose a USB root hub is enabled for wakeup (in other words, plugging or unplugging a USB device into the computer should wake the system up).  Suppose the root hub is at low power (autosuspended) when a wakeup event occurs.  The interrupt handler calls pm_stay_awake and indirectly invokes the USB runtime-resume routine.  This routine brings the root hub back to full power, informs the hub driver, and then calls pm_relax.

But the hub driver carries out its main work in a separate kernel thread (i.e., khubd).  So the hub_resume routine has to call pm_stay_awake, and then khubd calls pm_relax when it is finished processing the root hub's event.  Thus we end up with:

       usb_runtime_resume:     call pm_stay_awake (1) call hub_resume
               hub_resume:             call pm_stay_awake (2)
       usb_runtime_resume:     call pm_relax (balances 1)
       khubd:                  call pm_relax (balances 2)

Quoted 5 lines

As you can see, this won't work right if the pm wakeup calls aren't cumulative.  ("Nested" isn't quite the right word.)  The system would be allowed to sleep before khubd could process the root hub's wakeup event.

Quoted 4 lines

Too me this is an example of where two handles are needed, not where nesting is needed. Yes, you can use a single nested handle here, but the stats will not tell you which driver blocked suspend if there is a problem.

It sounds like you're suggesting that handles should be allocated per-driver rather than per-device.  That would tell you which driver blocked suspend, but not which device.

Typically a driver puts a wakelock in the state that it already allocates for each device, so you have a handle for each device/driver combo that needs to block suspend.

Quoted 11 lines
Quoted 11 lines

This raises a few other questions.

With Android-based handsets, you're in a setting where you have a pretty good idea of what all the wakeup sources are and how they might get used.  On a general system this isn't so.  Many devices are potential wakeup sources, even though only a few of them end up getting enabled.  In the example above, I said "Suppose a USB root hub is enabled for wakeup".  But usually people won't want to do this; they don't want their suspended laptops to wake up when a USB mouse is unplugged or plugged in.

Quoted 8 lines
Quoted 2 lines

Allocating these wakeup structures for all possible wakeup sources would be a big waste.

Indeed.

Quoted 3 lines

On the other hand, a driver generally doesn't
know until a suspend starts whether or not its devices should be enabled for wakeup.

Why? How is the driver notified on suspend that it needs to be enabled for wakeup.

Quoted 4 lines
Quoted 4 lines

 That makes things difficult, especially if you contemplate having multiple structures for each device.  Have you really sat down and thought about what wakelocks would be needed on a general system such as a desktop or laptop machine?

No, I don't know what wakelocks are needed on a general system, but you need code to turn the wakeup events on and off events anyway, so I assume allocating a handle for the wakeup event is possible.

Quoted 7 lines
Quoted 4 lines

Also, I frankly have to wonder why you demand such a large amount of detailed debugging about the kernel's wakeup/wakelock subsystem (as opposed to userspace wakelocks).

That also is my question.

It is not that different from what you get from /proc/timer_list, /proc/meminfo etc. When the system does not suspend I want to know why.

Quoted 8 lines
Quoted 8 lines

Yes, it's clear that if something
goes wrong then you will drain your phone's battery in a few hours rather than a few days.  But what if something goes wrong with the VM subsystem, or the RF subsystem, or the keypad driver?  The device would crash immediately or at best become almost totally unusable.  These are much worse scenarios than losing some battery life -- have you added comparable quantities of debugging to those other parts of the kernel?

We do track crashes and the kernel already dumps detailed debug information in that case. Also, I don't agree that a kernel crash is always worse than draining the battery. If you are away from a power source and the kernel crashes, the device reboots and you have a usable device again. If the battery drained, you cannot use the device again until you get to a power source.

Quoted 6 lines
Quoted 3 lines

In addition, you retain all these debugging facilities in your production builds, not just in the debug kernels.  Doesn't this seem excessive?

It definitely seems so.

There are two reasons for keeping the debugging facilities in production builds.
1. The debugging information is useful for debugging problems in the field.
2. We want to test with the same code we ship.

Signature · 1 line
Arve Hjønnevåg
#295 lore raw

Re: Wakeup-events implementation

Quoted 8 lines · Arve Hj?nnev?g

2010/8/17 Rafael J. Wysocki <[email protected]>:

Quoted 3 lines
Quoted 3 lines

On the other hand, a driver generally doesn't
know until a suspend starts whether or not its devices should be enabled for wakeup.

Why? How is the driver notified on suspend that it needs to be enabled for wakeup.

There's the wakeup API in pm_wakeup.h, plus subsystem specific knowledge about what sensible defaults for the hardware in much the same way as we handle what to do when we suspend.

Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

In addition, you retain all these debugging facilities in your production builds, not just in the debug kernels. ?Doesn't this seem excessive?

It definitely seems so.

There are two reasons for keeping the debugging facilities in production builds.
1. The debugging information is useful for debugging problems in the field.
2. We want to test with the same code we ship.

Plus the fact that power usage tends to be very dynamic often with strong dependencies on usage patterns. Power usage is something that end users will want to debug as well as developers, though most likely not in the same detail.

#296 lore raw

Re: Wakeup-events implementation

In reply to Arve Hjønnevåg
Quoted 4 lines · Arve Hjønnevåg

We don't uncover all bugs during testing before we ship. For instance the bug could be triggered by a 3db party app, and there is value in making the system as robust as possible to both driver and user space bugs.

By that argument, all in-kernel wakelocks should always have a timeout.

What happens if somebody puts down their phone and then puts something on top of it, in such a way that one of the keypad buttons is depressed? If the keypad driver's wakelock doesn't have a timeout then the battery would drain quickly.

Quoted 9 lines
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines

Wakeup events that don't reach user space should not need user space support to reenter suspend.

That's debatable.  For example, consider a Wake-On-LAN magic packet. It generally doesn't go anywhere -- it gets dropped once the system is awake.

Yes.  I think every event that would wake up a sleeping system should result in unfreezing user space.

In fact they do -- there's almost no way to avoid it. However, unfreezing userspace is different from sending a wakeup event to userspace.

The question is whether the kernel should automatically try to re-suspend following a wakeup for which no information was sent to userspace (e.g., WOL). The alternative, of course, is that the kernel does not try to re-suspend until a power-manager program tells it to. To me this seems more flexible and general (the PM program can always start a new suspend, whereas there's no way to prevent an automatic in-kernel re-suspend).

Quoted 14 lines
Quoted 6 lines
Quoted 6 lines

Let's say the interrupt handlers responsible for invoking pm_request_resume use non-nesting calls.  This may happen several times, depending on the wakeup and interrupt delivery mechanism, but the end result is that the counter is incremented only once.  When the pm_runtime_resume call ends, pm_relax does a single decrement.

Quoted 7 lines
Quoted 7 lines

Meanwhile, the driver uses nesting calls.  It can increment the counter as much as it wants, and it has to perform an equal number of decrements.  The key point is that pm_request_resume never gets called while the driver has any outstanding pm_stay_awake requests.  Hence the non-nesting calls never got "lost", since the first one is always made while the counter is 0.

Quoted 5 lines

It sounds as if you are saying that the two drivers don't interfere because one of them always gets there first. In your example if another interrupt occurs before the second driver still has released all its references on the counter, the interrupt will (incorrectly) not increment the count.

That's right -- one of them always gets there first. You're also right to suspect that this is an unusual situation. It arises with USB root hubs because a root hub is the only child of its parent controller device, and the only reason a controller would generate a wakeup request is because the root hub needs to wake up.

This means that a root-hub wakeup can be signalled in two different ways:

If the controller is in low-power then the controller sends its wakeup request. The controller's driver sets the controller back to full power, sees that the root hub has needs attention, and calls pm_request_resume for the root hub.

If the controller isn't in low-power then the root hub simply generates an IRQ. The interrupt handler calls pm_request_resume for the root hub.

Depending on how the timing works out, both can occur: The controller gets set to full power and then the IRQ line is signalled before the PM workqueue gets around to resuming the root hub. I have seen this happen while testing my computer.

With a little care, I could avoid calling pm_stay_awake twice. The code already sets a bitflag before queuing the resume request, and I could use test_and_set_bit instead. If I did then the non-nesting calls wouldn't be needed at all. And that was the only case I could think of where the two types of calls might need to be mixed.

Quoted 9 lines
Quoted 7 lines

I actually like the idea of having two levels of calls, ie. pm_stay_awake(dev) calling something like __pm_stay_awake(handle), where the handle is read from struct dev_pm_info.  And analogously for pm_relax().

Then, the object associated with the handle might be created when the device is enabled to wake up and destroyed when it's disabled to do that.

When multiple drivers use the same device, who creates and destroys the handle?

The primary driver (i.e., the one bound to the device) would use the device's handle. Other drivers would create and use their own separate wakeup structures.

But if all the calls are of the "nesting" sort then there's not really any need for multiple structures, other than to help identify which driver is misbehaving when a problem occurs.

Quoted 3 lines

Typically a driver puts a wakelock in the state that it already allocates for each device, so you have a handle for each device/driver combo that needs to block suspend.

You didn't answer my question about which devices have more than one associated wakelock in Android. Those would be the only cases where the device/driver combo matters.

Also, why does Android's MMC core have its own wakelock instead of using a per-device wakelock?

Quoted 11 lines
Quoted 8 lines
Quoted 2 lines

Allocating these wakeup structures for all possible wakeup sources would be a big waste.

Indeed.

Quoted 3 lines

On the other hand, a driver generally doesn't
know until a suspend starts whether or not its devices should be enabled for wakeup.

Why? How is the driver notified on suspend that it needs to be enabled for wakeup.

The driver's (or bus subsystem's) suspend routine calls device_may_wakeup(dev) to see whether it should enable dev's wakeup mechanism. The value returned by device_may_wakeup can change at almost any time, since it is set by userspace.

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines

 That makes things difficult, especially if you contemplate having multiple structures for each device.  Have you really sat down and thought about what wakelocks would be needed on a general system such as a desktop or laptop machine?

No, I don't know what wakelocks are needed on a general system, but you need code to turn the wakeup events on and off events anyway, so I assume allocating a handle for the wakeup event is possible.

Yes. However system suspend is generally not a good time to go around allocating new structures; memory tends to be tight then. I suppose it might be acceptable to do this during the "prepare" phase of system suspend.

Alan Stern