User: Password:
|
|
Subscribe / Log in / New account

Blocking suspend blockers

Blocking suspend blockers

Posted May 20, 2010 4:22 UTC (Thu) by brendan_wright (guest, #7376)
Parent article: Blocking suspend blockers

The argument that suspend blockers aren't needed because "applications shouldn't waste power" is like saying that the kernel doesn't need to enforce security policies because "applications shouldn't modify system files".

Landing at an airport in a foreign country and finding you can't access your emails/maps/whatever because the last app you installed on your Android device had a bug in it causing it to flatten your battery would be a Big Problem for many people. It seems that suspend blockers are the only reasonable solution proposed so far. Merging some form of them would make Linux a much more reliable solution for "open" portable devices.


(Log in to post comments)

Blocking suspend blockers

Posted May 20, 2010 4:36 UTC (Thu) by dlang (subscriber, #313) [Link]

umm, I think you may be misunderstanding this.

suspend blockers will let an application tell the system that it is not allowed to suspend. This makes it far _more_ likely that you will have a buggy (or just plain poorly written) app that causes your device to run out of battery.

Blocking suspend blockers

Posted May 20, 2010 4:44 UTC (Thu) by wblew (subscriber, #39088) [Link]

The point is this: without suspend blockers, the portable device's userland cannot aggressively suspend itself. After all, how is it to know that device driver X is preventing suspension?

Hence suspend blocker leads to aggressive userland initiated suspend, right?

Or, maybe _I_ am missing something... which is certainly possible.

Blocking suspend blockers

Posted May 20, 2010 5:18 UTC (Thu) by dlang (subscriber, #313) [Link]

no, all that suspend blockers do is to tell the system that while suspend is blocked, don't run your normal heuristics.

When suspend is not blocked, the system can run the heuristics to decide if it should suspend or not.

suspend blockers may allow yo to set the system heuristics to be more aggressive, but if you have any apps on the system that do not invoke suspend blockers, you run the risk of suspending too aggressively when those apps are running.

And if an app claims that you should not suspend (by setting a suspend block), then the system will never go to sleep.

this is very similar to cooperative multitasking, when all apps are well written it can work _very_ well (and can be far more efficient than premptive multitasking), but it only takes one badly written app to cripple the system.

There's a reason that there are basically no commonly used cooperative multitasking systems, in the real world they just aren't reliable enough. The only place you can really use them is in embedded situations where you control everything that's running on the system. That no longer includes phones as people can download apps to run on them.

Blocking suspend blockers

Posted May 20, 2010 7:02 UTC (Thu) by neilbrown (subscriber, #359) [Link]

If what you say is true (and I'm afraid I haven't been able to follow the discussion at all closely) then it would seem to make sense to only allow selected applications to block suspend, with only the device distributer and the device owner allowed to make that selection.

What I don't quite see is why device drivers want to impose suspend blocks. Does anyone know an example of a device driver that needs to do this? I would have thought that the decision of whether to suspend would be entirely up to user-space. Obviously a device can say "just a moment, I need to tidy up a bit first", but otherwise it should just do what it is told.

Blocking suspend blockers

Posted May 20, 2010 7:15 UTC (Thu) by dlang (subscriber, #313) [Link]

I may be misreading things as well, so it will be interesting to see others comments on this.

As for why drivers need to block suspend, if you set the system to be hyper eager to suspend, then you can't count on getting anything finished unless you block suspend.

if for example, your driver needs to send a string of bytes to your GPS chip to initialize it, having the system sleep in the middle can leave you with a uninitialized device that won't work when you wake up and pick up where you left off, so you need to block suspend while you do this 'critical, uninterruptible' work

the problem that I see is that I haven't seen anything that would prevent an application from claiming that everything that it's doing is critical. It's definitely easier for joe random game developer to just tell the system to not suspend while the game is running than it is to properly handle being suspended.

sometimes an app blocking suspend is the right thing to do (think a 'flashlight' app that just displays an all-white screen and prevents the system from sleeping until you do something to turn it off), but without any way for the system to prevent abuse, it's only going to be a short time before apps start abusing it.

Blocking suspend blockers

Posted May 20, 2010 9:39 UTC (Thu) by farnz (subscriber, #17727) [Link]

The trick, in Android world, is that only a limited set of known processes can actually set suspend blockers (just as in POSIXy Linux world, only a limited set of processes can write to /dev/sd*). Everyone else who wants to block suspend has to ask one of the privileged processes to set a block for them, using Android's RPC mechanism. An Android app comes with a manifest file, and in that manifest file, you must declare if you wish to take out a suspend blocker. This translates in UI terms to a warning when the application is installed, telling you that the application can "prevent phone from sleeping", and to Android's "where's my battery gone" UI and APIs blaming applications that hold a suspend blocker for the resulting power consumption.

Thus, on a phone, if you take out a suspend blocker via the RPC mechanism, you get blamed whenever the user asks the phone "why's my battery life poor?", even if it's another app hammering the CPU and keeping you out of idle. The hope is that this will be enough to stop application writers from using suspend blockers when they're not needed.

Blocking suspend blockers

Posted May 20, 2010 18:33 UTC (Thu) by felipebalbi (guest, #56613) [Link]

That's not what some android developers said on the discussion, they said anyone can take a suspend blocker and like I replied to them, if you only want suspend blockers to pretty print on UI, there are other less invasive and transparent to apps mechanisms to do so. You don't need opportunistic suspend and suspend blockers.

Blocking suspend blockers

Posted May 20, 2010 20:12 UTC (Thu) by broonie (subscriber, #7078) [Link]

For all practical purposes any app can take a suspend blocker - there's no opportunity for users to tweak the set of permissions an application has, it's fixed by the app developer. However, the UI does warn the user during installation that the app might do this and does provide the accounting that's been discussed.

Blocking suspend blockers

Posted May 20, 2010 18:30 UTC (Thu) by felipebalbi (guest, #56613) [Link]

Imagine what would happen if you suspend while usb cable is attached. You don't really know whether pc has mounted the file system (considering you're using mass storage) and if the pc is transferring files to device, since with mass storage we need a 2 second poll for media change and there's no way to differentiate those IRQs from actual _data_ coming to device. They're all endpoint IRQs.

If you forcefully suspend at that point, you're risking corrupting user's Data.

Also, we can get pretty much the same power consumption with cpufreq + cpuidle + runtime pm since idle consumption is HW characteristic, not SW. If we don't reach that level, it only mean device isn't idle enough and there's some cripple app waking up the processor.

Blocking suspend blockers

Posted May 20, 2010 19:40 UTC (Thu) by sfeam (subscriber, #2841) [Link]

That seems to be an argument in favor of suspend blockers, rather than against them. That "actual _data_" operation can be protected by a suspend block, while the period poll for media change is not. What level the suspend blocker is invoked from to bracket a data transfer is a separate question.

I may be missing your point about suspending while a usb file system is mounted. If you can suspend your laptop while the hard drive is mounted, isn't it equally desirable to be able to suspend it while a memory stick is mounted? I imagine that a forceful suspend would necessarily trigger a sync operation, but isn't that true anyhow?

Blocking suspend blockers

Posted May 21, 2010 1:30 UTC (Fri) by dlang (subscriber, #313) [Link]

a problem with suspending while a USB device is connected is that it's highly likely that the USB device will no longer be connected when the system tries to come back up from being suspended.

Blocking suspend blockers

Posted May 22, 2010 8:19 UTC (Sat) by quintesse (guest, #14569) [Link]

But that's a problem the system has to deal with anyway, the user can yank out the cable at any time.

Blocking suspend blockers

Posted May 22, 2010 18:48 UTC (Sat) by giraffedata (subscriber, #1954) [Link]

But that's a problem the system has to deal with anyway, the user can yank out the cable at any time.

The system more options to deal with the user yanking out the cable, because the user expects yanking the cable to interrupt use of the device, and the user can arrange not to yank the cable if it is a problem. In contrast, suspend happens all by itself at largely arbitrary times, so the user won't expect interruption and can't practically avoid it.

Blocking suspend blockers

Posted May 22, 2010 22:00 UTC (Sat) by sfeam (subscriber, #2841) [Link]

The system has more options to deal with the user yanking out the cable, because the user expects yanking the cable to interrupt use of the device, and the user can arrange not to yank the cable if it is a problem. In contrast, suspend happens all by itself at largely arbitrary times, so the user won't expect interruption and can't practically avoid it.

Huh? The point is that suspend/resume should be harmless with respect to a device that is still plugged in.

If the device is still plugged in when the system resumes, open files should still be open, etc. This already works with the hard drive; is it really so hard to re-establish communication with a usb device?
If the device is gone when the system resumes, that's a problem, yes. But it's the same problem as just yanking the cable while the system is active. Or hold on, it's actually a less serious problem, because we should have been smart enough to sync during the suspend process, whereas there was no opportunity to do so during the cable yanking.

Blocking suspend blockers

Posted May 22, 2010 22:32 UTC (Sat) by giraffedata (subscriber, #1954) [Link]

Oh, I misunderstood "connected" as in the device may not be connected when the system wakes up. "Connected" is a logical state to me, but I can see it was supposed to mean plugged in.

I agree. There's no issue with a cable being yanked while the system is asleep that doesn't also exist for the cable being yanked while it's awake.

Well, except that since going to sleep correlates with a lull in user activity, there's a higher chance of that yank happening while the system is asleep. But since preventing the sleep won't prevent the lull in user activity, I don't suppose that's relevant to the question of whether suspension should be blocked.

Blocking suspend blockers

Posted May 20, 2010 7:49 UTC (Thu) by MisterIO (guest, #36192) [Link]

No, you missed a part of it. The article explained that the Android system aggressively suspends whenever it can(for example it could suspend even when a userspace app is doing some work) and thus it needs suspend blockers to force the system to not suspend. Thus suspend blockers are what makes possible the aggressive suspend capability of the Android system. Even a buggy app won't stop the system from suspending if, at the time, the suspend blocker won't block the suspend.

Blocking suspend blockers

Posted May 20, 2010 7:52 UTC (Thu) by MisterIO (guest, #36192) [Link]

Clear example of a comment I'd like to cancel.

Blocking suspend blockers

Posted May 20, 2010 17:56 UTC (Thu) by dlang (subscriber, #313) [Link]

which part of the post did you wish to cancel?

Blocking suspend blockers

Posted May 20, 2010 18:34 UTC (Thu) by felipebalbi (guest, #56613) [Link]

If you have an application that holds a suspend blocker forever, device will never "aggressively suspend" whatever that means.

Blocking suspend blockers

Posted May 20, 2010 10:41 UTC (Thu) by brendan_wright (guest, #7376) [Link]

Android's implementation of suspend blockers allows it to suspend the system aggressively without worrying about interrupting anything important (such as a download). And for many apps it achieves this without any risk that the app will block suspend no matter how buggy it is, because only some apps have access to the suspend blocker API.

Before an app is installed the user is shown a list of access rights the app is requesting. One access right an app can require is to "prevent the phone from sleeping". As many apps don't need this functionality they don't ask for access to the suspend blocker API, and so can't flatten your battery no matter how buggy they are.

Apps that do require access to the suspend blocker API would need to to exhibit buggy behavior *while holding a lock* in order to drain your battery. Android can also show you which apps are using the most power if you are concerned about your battery life.

Desktop distros could presumably not compile the functionality in, or restrict userspace access to the API, if they were concerned about buggy userspace code blocking suspend?

Blocking suspend blockers

Posted May 20, 2010 15:57 UTC (Thu) by intgr (subscriber, #39733) [Link]

> Desktop distros could [...] restrict userspace access to the API, if they
> were concerned about buggy userspace code blocking suspend?

No, desktop distros only support user-initiated suspend, which should never be blocked by user space applications anyway. A desktop computer cannot use opportunistic suspend as it stands, because:
* The hardware is not designed that way; suspending (spinning down) your hard drive every few seconds is a great way to kill it
* Current software does not acquire suspend blockers where they would be expected by the user
* Current drivers do not use suspend blockers, so the system as a whole doesn't know when it *can* suspend. If it tries, chances are that the suspend will be blocked half-way until the driver can finish its work -- time during which the system is still running, but the user cannot do anything meaningful.

This is an Android-specific feature that cannot be reliabily used in other configurations, possibly even other handsets.

Blocking suspend blockers

Posted May 20, 2010 17:59 UTC (Thu) by dlang (subscriber, #313) [Link]

I don't know what desktop distros you have been using, but every one that I have seen that does suspend does not require the user to explicitly take action to initiate the suspend, they all are setup to suspend after some defined period of 'inactivity'

Blocking suspend blockers

Posted May 22, 2010 20:24 UTC (Sat) by rvfh (subscriber, #31018) [Link]

But you do expect your movie player to block the screen saver and DPMS off, don't you? Isn't this some kind of user-space suspend blocker?

Blocking suspend blockers

Posted May 20, 2010 23:44 UTC (Thu) by brendan_wright (guest, #7376) [Link]

> No, desktop distros only support user-initiated suspend, which should never be blocked by user space applications anyway.

By desktop distros I mean Ubuntu, Fedora etc that are used on both desktops and laptops. As dlang has pointed out, laptops are often set to suspend after a certain period of inactivity by the user. This non-user-initiated-suspend can and does sometimes interrupt important activities (such as watching a movie, downloading a file etc).

> A desktop computer cannot use opportunistic suspend as it stands, because:
> * The hardware is not designed that way; suspending (spinning down) your hard drive every few seconds is a great way to kill it

Desktops/laptops are certainly different beasts in terms of hardware than mobile devices. A laptop with a solid-state drive (that isn't damaged by a suspend/resume "every few seconds") could potentially handle frequent suspend/resumes whereas a machine with a hard drive couldn't.

Currently we rely on the user or the disto to set reasonable policies in terms of how soon to suspend when running on battery power, but ideally the driver itself would inform the system of it's limitations. A correctly implemented suspend blocker API might be a way to achieve this.

Also Android's userspace API for suspend blockers (which they call wakelocks) supports multiple suspend states:
http://developer.android.com/reference/android/os/PowerMa...

Possibly a suspend blocker implementation would allow devices that are happy to suspend frequently to do so while others are kept active. A user may wish for their dual 24" monitors and 12-core CPU to suspend after 3 minutes of inactivity but not their hard drive (which would suffer too much wear). A well implemented suspend blocker API could allow the drivers to indicate when they are willing to suspend.

> * Current software does not acquire suspend blockers where they would be expected by the user

Of course nobody is using an API that doesn't exist yet. But I think you're assuming that by implementing suspend blockers distros would be forced to suspend very frequently like Android devices do, thereby causing problems for software. There's no reason why they would need to be configured this way.

But by providing the API a browser that's downloading a 600MB ISO from a server that doesn't support resuming could indicate it doesn't want the network & storage systems to be suspended till it's finished. Perhaps this might be sufficient to block a timeout-triggered suspend but a user might still be allowed to force a suspend if required?

> * Current drivers do not use suspend blockers, so the system as a whole doesn't know when it *can* suspend. If it tries, chances are that the suspend will be blocked half-way until the driver can finish its work -- time during which the system is still running, but the user cannot do anything meaningful.

Most laptops running desktop distros are suspended after a period of inactivity when running on the battery. As you point out, they do so without the system really knowing that it can. The system is forced to *assume* that it can because drivers can't tell it otherwise because they have no API with which to do so. Providing this API rectifies this problem.

> This is an Android-specific feature that cannot be reliabily used in other configurations, possibly even other handsets.

I think it's a potentially useful feature for any Linux system that runs off a battery or uses a lot of power.

Blocking suspend blockers

Posted May 21, 2010 9:41 UTC (Fri) by intgr (subscriber, #39733) [Link]

Thanks for this post! You have convinced me.

> A user may wish for their dual 24" monitors and 12-core CPU to suspend
> after 3 minutes of inactivity but not their hard drive (which would suffer
> too much wear).

Is that possible with current PC hardware? To suspend the rest of the system except hard drives?

I always thought that when you suspend the CPU, the rest of the system has to come down too. (Except on Android where hardware was specifically designed to allow this)

Blocking suspend blockers

Posted May 22, 2010 20:29 UTC (Sat) by rvfh (subscriber, #31018) [Link]

> But by providing the API a browser that's downloading a 600MB ISO from a server that doesn't support resuming could indicate it doesn't want the network & storage systems to be suspended till it's finished. Perhaps this might be sufficient to block a timeout-triggered suspend but a user might still be allowed to force a suspend if required?

This reminds of the way KDE (and I suppose the others too) will stop you from logging off when you have unsaved changes. Indeed, you'd like to have a way to back off when the app tells you 'ongoing download: do you really want to stand-by?'

Blocking suspend blockers

Posted May 20, 2010 18:01 UTC (Thu) by dlang (subscriber, #313) [Link]

the buggy behavior I expect is to raise the blocker for excessive periods of time (there has to be a way for multiple apps to raise the blocker at the same time, or the concept will fall apart in a multiprocess envrionment)

Blocking suspend blockers

Posted May 20, 2010 23:54 UTC (Thu) by brendan_wright (guest, #7376) [Link]

> the buggy behavior I expect is to raise the blocker for excessive periods of time (there has to be a way for multiple apps to raise the blocker at the same time, or the concept will fall apart in a multiprocess environment)

This is a potential problem. One advantage Android has is that most apps are installed through a market where user comments can indicate to others that software has these kinds of bugs (which should be pretty rare as most code shouldn't need to operate with a suspend block taken).

A user who notices that the problem is occurring could manually kill the app. However they won't always be paying attention to the device.

A battery operated device will eventually die through lack of power anyway, so perhaps devices should choose to ignore an apps suspend-blocking request after a certain amount of battery is consumed. This sort of functionality might seem unnecessarily complex in the desktop world but could be a life-saver in the world of battery operated devices.

Blocking suspend blockers

Posted May 21, 2010 11:03 UTC (Fri) by tialaramex (subscriber, #21167) [Link]

My understanding is that in the Android phone world what happens is this:

• User A downloads "cow bouncer" and is impressed that now their phone constantly has bouncing cows. However an hour later their phone bleeps to warn the battery is low. The "low battery" screen shows a "Why so soon?" button or link, which implicates "cow bouncer" as the reason. User A chooses to uninstall the "cow bouncer" app because it's a waste of battery life.

• User B downloads "John the ripper Android edition" and sets it to work cracking password hashes. An hour later the phone bleeps due to exhausted battery. User B plugs it into the wall, he doesn't ask why because hey, he was running a password cracker on his phone, stands to reason it will exhaust the battery.

By obligating ordinary developers to ask for this functionality if they need it and then auditing how it is used, Android make them responsible to their users - if you need to block suspend for long periods, you will need to educate your users about why that is, and persuade them that the app functionality is worth the reduced battery life, otherwise they're going to throw your app away and probably warn off other potential customers.

Blocking suspend blockers

Posted May 21, 2010 12:57 UTC (Fri) by farnz (subscriber, #17727) [Link]

Close, but not quite for the HTC Hero running Android 1.5. When you download "cow bouncer" or "JTR Android", you get warned that the application can "Prevent the phone from sleeping", and have to say OK or Cancel to the "install anyway" prompt.

There's no in-built UI for catching bad apps, but there are third party applications in the Market that use the existing API to tell you which applications are using power - they're spotted not because they're CPU hogs, but because they're holding a wakelock preventing the phone from sleeping.

Blocking suspend blockers

Posted May 21, 2010 15:58 UTC (Fri) by Aissen (guest, #59976) [Link]

HTC Hero running Android 1.5

Although it was released just over a year ago, Android 1.5 is a pretty old in the Android timeline.
Wonderful things have happened, and three releases later Android 2.2 have been announced officially yesterday.
HTC promised to update the Hero to Android 2.1, and hopefully you'll get it sooner rather than later, and see the UI everyone's talking about in the default OS.

The most important is that susupend blockers are merged so that the future of Android is one where upstream matters, and Android kernel is no longer a fork.

Blocking suspend blockers

Posted May 21, 2010 16:00 UTC (Fri) by farnz (subscriber, #17727) [Link]

Android 1.5 is the latest version available for my device; I cannot in fairness tell you how Android behaves without qualifying it with the version number, because I can't tell you if it's been improved in later versions.

However, I'd hope that in this respect, Android isn't regressing in new versions. Power management is kinda critical on a phone.

Blocking suspend blockers

Posted May 21, 2010 23:17 UTC (Fri) by vonbrand (guest, #4458) [Link]

Ever heard of dancing pigs? Fat chance that the end user will ever make an informed decision on installing an application calling for this then...

Blocking suspend blockers

Posted May 22, 2010 1:53 UTC (Sat) by swetland (guest, #63414) [Link]

It is true that users are well-trained to keep clicking until they get whatever it is that they're after, but the way we use suspend blockers in Android includes more than just warning users that the app may "prevent the device from sleeping":

- Applications that don't specifically need to prevent suspend don't request the permission, and the vast majority of apps fall into that category. The user obtains benefit here in that if non-suspend-blocking apps perform poorly, they only do so while the device is awake, which we attempt to minimize.

- Applications that keep the device awake must use suspend blockers and the statistics from their use allows us to answer the "Why is my battery running low?" question by pointing out apps that are contributing to poor battery life. The "battery low, please plug in the charger" notification has had a "Why?" button since Android 2.0, to help users discover the "what apps are using up my battery" panel.

So yes, users will certainly get their dancing pigs (or bouncing cows), especially on a platform that has no restrictions on app installation, but we can certainly help the user still have a positive experience, or at the least, understand what the cause of their negative experience is.

Blocking suspend blockers

Posted May 22, 2010 2:30 UTC (Sat) by dlang (subscriber, #313) [Link]

do the statistics tell you how long an app has blocked suspend? how many times it's done so? what percentage of the time?

a long running app that uses suspend blockers only where needed could still show up as a top item for total time blocked or how many times it's blocked.

Blocking suspend blockers

Posted May 22, 2010 3:15 UTC (Sat) by swetland (guest, #63414) [Link]

The battery statistics service tracks number of times acquired, total realtime (aka walltime) held, etc. Here's a sample from a typical bugreport. The user facing UI is, of course, friendlier looking: http://frotz.net/misc/battery-stats-unplugged.txt

It starts with an overview then provides a UID-by-UID and process-by-process breakdown of wakelocks, cpu time, sensor usage, etc.

Blocking suspend blockers

Posted Jun 1, 2010 20:11 UTC (Tue) by Duncan (guest, #6647) [Link]

Thanks for the link to a real log. That's one thing I'd not seen in all this discussion.


Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds