From: david on
On Wed, 4 Aug 2010, Rafael J. Wysocki wrote:

> On Wednesday, August 04, 2010, david(a)lang.hm wrote:
>> On Wed, 4 Aug 2010, Arve Hj?nnev?g wrote:
>>
>>> 2010/8/3 <david(a)lang.hm>:
>>>> On Tue, 3 Aug 2010, Arve Hj?nnev?g wrote:
>>>>
>>>>> 2010/8/3 <david(a)lang.hm>:
>>>>>>
>>>>>> On Tue, 3 Aug 2010, Arve Hj?nnev?g wrote:
> ...
>>>>>>> The hardware specific idle hook can (and does) decide to go into any
>>>>>>> power state from idle that does not disrupt any active devices.
>>>>>>
>>>>>> This I know is an Andoid specific thing. On other platforms power states
>>>>>> very definantly can make user visible changes.
>
> It would be much better if you gave specific examples. Because, for instance,
> I'm not sure what platforms you have in mind.

I gave examples in other messages that included dimming/turning off the
screen and spinning down the disk among others.

the definition of 'transparently' was then clarified to not mean
transparent to the user, but transparent (except for possibly delays) to
the applications (they may have to wait for the disk to spin up for
example)

>>>>> How is this Android specific?
>>>>
>>>> you are stating that this must be suspend because low-power idle must be
>>>> transparent to the user.
>>>
>>> It must be transparent to the rest of the system.
>>>
>>>>
>>>> I am saying that on Linux, low-power idle commonly is not transparent to the
>>>> user, so the requirement for it to be transparent (therefor putting the
>>>> suspend into a different category) is an Android only requirement.
>>>>
>>>
>>> I'm am not talking about minor latencies. If you have a platform that
>>> for instance turns off you screen dma when entering idle, it is broken
>>> whether is running Android or not. If it does the same in suspend it
>>> is not a problem.
>>
>> This isn't sounding quite right to me. I've seen too many discussions
>> about things like idle and USB devices/hubs/drives/etc getting powered
>> down for power savings modes to make me readily accept that everything
>> must be as transparent as you imply. Just the case of drive spin-down
>> shows that it's possible to do things that would be considered
>> destructive, but you have to have a flag and wake-up path to recover
>> within a 'reasonable' amount of time (I guess that this could be
>> 'transparent' if that only implies that things must work eventually, which
>> isn't what I read into the statement)
>
> Well, consider a single character device and suppose there is an application
> talking to the driver using read(), write(), ioctl(), whatever. Now suppose
> you want to put the device into a low-power state such that the device can't
> do the I/O in that state. You need to ensure that the app won't be able to
> reach the device while in that state and you can (1) arrange things so that
> the device is put into the full-power state whenever the app tries to access
> it and (2) "freeze" the app so that it won't try to access the device being in
> the low-power state.
>
> Generally speaking (1) is what idle (and any other form of runtime PM) does and
> (2) is what suspend does with respect to the whole system.

makes sense

> In the suspend case, when you have frozen all applications, you can
> sequentially disable all interrupts except for a few selected ("wakeup") ones
> in a safe way. By disabling them, you ensure that the CPU will only be
> "revived" by a limited set of events and that allows the system to stay
> low-power for extended time intervals.

the benifit of this will depend on what wakeups you are able to avoid by
putting the hardware to sleep. Depending on the hardware, this may be not
matter that much.

In addition, there are input devices like a touchscreen that could be
disabled even short of a full suspend, as long as there is some way to get
them reactivated.

> To achieve the same result in the "idle" case, you'll need to have a mechanism
> to disable interrupts (except for the "wakeup" ones) avoiding synchronization
> problems (eg. situations in which task A, blocked on a "suspended" device
> access, holds a mutex waited for by task B that needs to run so that we can
> "suspend" another device). That, however, is a difficult problem.

I would say that the difficulty of the problem depends on the hardware and
how much userspace interaction is needed. If the kernel can disable the
hardware in the driver (so that it can wake it up again when accessed by
an application) it would seem that this isn't a problem.

David Lang
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Matthew Garrett on
On Wed, Aug 04, 2010 at 11:30:44AM -0700, david(a)lang.hm 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.

--
Matthew Garrett | mjg59(a)srcf.ucam.org
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: david on
On Wed, 4 Aug 2010, Matthew Garrett wrote:

> On Wed, Aug 04, 2010 at 11:30:44AM -0700, david(a)lang.hm 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.

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

> 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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Matthew Garrett on
On Wed, Aug 04, 2010 at 12:15:59PM -0700, david(a)lang.hm wrote:
> On Wed, 4 Aug 2010, Matthew Garrett wrote:
>> 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.
>
> 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.

--
Matthew Garrett | mjg59(a)srcf.ucam.org
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: david on
On Wed, 4 Aug 2010, Matthew Garrett wrote:

> On Wed, Aug 04, 2010 at 12:15:59PM -0700, david(a)lang.hm wrote:
>> On Wed, 4 Aug 2010, Matthew Garrett wrote:
>>> 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.
>>
>> 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.

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 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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/