LWN: Comments on "Blocking suspend blockers" http://lwn.net/Articles/388131/ This is a special feed containing comments posted to the individual LWN article titled "Blocking suspend blockers". hourly 2 Blocking suspend blockers http://lwn.net/Articles/390390/rss 2010-06-01T20:11:13+00:00 Duncan <div class="FormattedComment"> Thanks for the link to a real log. That's one thing I'd not seen in all this discussion.<br> </div> Blocking suspend blockers http://lwn.net/Articles/388819/rss 2010-05-22T22:32:17+00:00 giraffedata <p>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. <p> 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. <p> 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 http://lwn.net/Articles/388815/rss 2010-05-22T22:00:41+00:00 sfeam <i>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.</i> <p> Huh? The point is that suspend/resume should be harmless with respect to a device that is still plugged in. <p> 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? <br> If the device is gone when the system resumes, that's a problem, yes. But it's the <i>same</i> 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 http://lwn.net/Articles/388811/rss 2010-05-22T20:29:03+00:00 rvfh <div class="FormattedComment"> <font class="QuotedText">&gt; 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 &amp; 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?</font><br> <p> 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?'<br> </div> Blocking suspend blockers http://lwn.net/Articles/388810/rss 2010-05-22T20:24:08+00:00 rvfh <div class="FormattedComment"> 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?<br> </div> Blocking suspend blockers http://lwn.net/Articles/388806/rss 2010-05-22T18:48:56+00:00 giraffedata <blockquote> But that's a problem the system has to deal with anyway, the user can yank out the cable at any time. </blockquote> <p> 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 http://lwn.net/Articles/388786/rss 2010-05-22T08:19:04+00:00 quintesse <div class="FormattedComment"> But that's a problem the system has to deal with anyway, the user can yank out the cable at any time.<br> </div> Blocking suspend blockers http://lwn.net/Articles/388772/rss 2010-05-22T03:15:38+00:00 swetland <div class="FormattedComment"> 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: <a href="http://frotz.net/misc/battery-stats-unplugged.txt">http://frotz.net/misc/battery-stats-unplugged.txt</a><br> <p> It starts with an overview then provides a UID-by-UID and process-by-process breakdown of wakelocks, cpu time, sensor usage, etc.<br> <p> </div> Blocking suspend blockers http://lwn.net/Articles/388771/rss 2010-05-22T02:30:33+00:00 dlang <div class="FormattedComment"> do the statistics tell you how long an app has blocked suspend? how many times it's done so? what percentage of the time?<br> <p> 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.<br> </div> Blocking suspend blockers http://lwn.net/Articles/388770/rss 2010-05-22T01:53:00+00:00 swetland <div class="FormattedComment"> 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":<br> <p> - 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.<br> <p> - 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.<br> <p> 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.<br> </div> Blocking suspend blockers http://lwn.net/Articles/388768/rss 2010-05-21T23:17:51+00:00 vonbrand <p> Ever heard of <a href="http://en.wikipedia.org/wiki/Dancing_pigs">dancing pigs</a>? Fat chance that the end user will ever make an informed decision on installing an application calling for this then... Blocking suspend blockers http://lwn.net/Articles/388724/rss 2010-05-21T16:00:57+00:00 farnz <p>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. <p>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 http://lwn.net/Articles/388721/rss 2010-05-21T15:58:04+00:00 Aissen <cite>HTC Hero running Android 1.5</cite> <p> Although it was released just over a year ago, Android 1.5 is a pretty old in the Android timeline.<br/> Wonderful things have happened, and three releases later Android 2.2 have been announced officially yesterday.<br/> 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. </p><p> 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. </p> Blocking suspend blockers http://lwn.net/Articles/388703/rss 2010-05-21T12:57:19+00:00 farnz <p>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. <p>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 http://lwn.net/Articles/388695/rss 2010-05-21T11:03:31+00:00 tialaramex <div class="FormattedComment"> My understanding is that in the Android phone world what happens is this:<br> <p> • 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.<br> <p> • 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.<br> <p> 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.<br> </div> Blocking suspend blockers http://lwn.net/Articles/388688/rss 2010-05-21T09:41:14+00:00 intgr <div class="FormattedComment"> Thanks for this post! You have convinced me.<br> <p> <font class="QuotedText">&gt; A user may wish for their dual 24" monitors and 12-core CPU to suspend</font><br> <font class="QuotedText">&gt; after 3 minutes of inactivity but not their hard drive (which would suffer</font><br> <font class="QuotedText">&gt; too much wear).</font><br> <p> Is that possible with current PC hardware? To suspend the rest of the system except hard drives?<br> <p> 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)<br> <p> </div> Blocking suspend blockers http://lwn.net/Articles/388648/rss 2010-05-21T01:30:05+00:00 dlang <div class="FormattedComment"> 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.<br> </div> Android looks good in that aera http://lwn.net/Articles/388647/rss 2010-05-21T00:48:38+00:00 brendan_wright <div class="FormattedComment"> I've used a couple of Android devices as my main phone over the last two years. While their early JVM's were very inefficient and chewed through the power when you were actually using them (which has since been improved greatly), their ability to not suspend on you when you're playing music or using the nav software, but also not be "mysteriously dead" when you need to use them, is awesome! <br> <p> I wish I could say the same about my Ubuntu powered laptops - they're either suspending on you 10 minutes into your movie because you left the power management switched on, or are unexpectedly dead when you need them because you switched it off. I'm hoping the merge of suspend blockers will improve this situation, as enable all the money that's being thrown at building Android powered phones, in-car devices, tablets etc to broaden the range of drivers compatible with the mainline Linux kernel.<br> </div> Blocking suspend blockers http://lwn.net/Articles/388646/rss 2010-05-20T23:54:45+00:00 brendan_wright <div class="FormattedComment"> <font class="QuotedText">&gt; 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)</font><br> <p> 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).<br> <p> 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. <br> <p> 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.<br> </div> Blocking suspend blockers http://lwn.net/Articles/388641/rss 2010-05-20T23:44:32+00:00 brendan_wright <div class="FormattedComment"> <font class="QuotedText">&gt; No, desktop distros only support user-initiated suspend, which should never be blocked by user space applications anyway. </font><br> <p> 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).<br> <p> <p> <font class="QuotedText">&gt; A desktop computer cannot use opportunistic suspend as it stands, because:</font><br> <font class="QuotedText">&gt; * The hardware is not designed that way; suspending (spinning down) your hard drive every few seconds is a great way to kill it</font><br> <p> 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. <br> <p> 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. <br> <p> Also Android's userspace API for suspend blockers (which they call wakelocks) supports multiple suspend states:<br> <a href="http://developer.android.com/reference/android/os/PowerManager.html">http://developer.android.com/reference/android/os/PowerMa...</a><br> <p> 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. <br> <p> <p> <font class="QuotedText">&gt; * Current software does not acquire suspend blockers where they would be expected by the user</font><br> <p> 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. <br> <p> 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 &amp; 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?<br> <p> <p> <font class="QuotedText">&gt; * 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.</font><br> <p> 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.<br> <p> <p> <font class="QuotedText">&gt; This is an Android-specific feature that cannot be reliabily used in other configurations, possibly even other handsets.</font><br> <p> I think it's a potentially useful feature for any Linux system that runs off a battery or uses a lot of power.<br> </div> Android looks good in that aera http://lwn.net/Articles/388636/rss 2010-05-20T22:26:06+00:00 iabervon <div class="FormattedComment"> IM applications never consider the possibility that the system could suspend. They are poor citizens because they don't think about the issues, not because they consider the issues and decide to be bad. This would mean that they wouldn't even consider the possibility that they could need or want a suspend blocker. And, on a system that uses suspend blockers, their naive design is fine: they check for updates every 5 seconds if the system is awake, but don't keep the system awake if there's nothing else keeping it awake. <br> <p> In fact, the current situation doesn't really give IM applications the ability to behave well; they need to update is a reasonable amount of time without any user interaction if the user is watching the window out of the corner of their eye, but don't need to do anything if the user is actually not paying attention. There's no current easy way for an application to say "sleep for 5 seconds, but don't bother waking me if the user doesn't care", and applications just don't consider this situation anyway, so they don't tend to try to set up a negotiation with the screensaver or something.<br> </div> Blocking suspend blockers http://lwn.net/Articles/388612/rss 2010-05-20T20:12:49+00:00 broonie <div class="FormattedComment"> 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.<br> </div> Blocking suspend blockers http://lwn.net/Articles/388602/rss 2010-05-20T19:40:41+00:00 sfeam 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. <p> 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? Android looks good in that aera http://lwn.net/Articles/388600/rss 2010-05-20T19:01:54+00:00 zlynx <div class="FormattedComment"> Another point.<br> <p> With suspend blockers the developer must take action in order to keep the system awake by setting a suspend block on purpose.<br> <p> Without suspend blockers the developer will keep the system awake by default just by writing normal software. The developer must take action, often quite a lot of code redesign, in order to *not* keep the system awake.<br> </div> Android looks good in that aera http://lwn.net/Articles/388594/rss 2010-05-20T18:41:40+00:00 felipebalbi <div class="FormattedComment"> You don't need suspend blockers to shout that an app is preventing sleep or waking up too much, take a look at powertop <a href="http://www.lesswatts.org/projects/powertop/">http://www.lesswatts.org/projects/powertop/</a><br> </div> Android looks good in that aera http://lwn.net/Articles/388590/rss 2010-05-20T18:40:10+00:00 felipebalbi <div class="FormattedComment"> Badly written apps aren't the only problems in N900, due to a HW problem smartreflex (which is a technology to automatically adjust the regulators in the PMIC to save battery) can't be used.<br> </div> Blocking suspend blockers http://lwn.net/Articles/388585/rss 2010-05-20T18:34:23+00:00 felipebalbi <div class="FormattedComment"> If you have an application that holds a suspend blocker forever, device will never "aggressively suspend" whatever that means.<br> </div> Blocking suspend blockers http://lwn.net/Articles/388584/rss 2010-05-20T18:33:15+00:00 felipebalbi <div class="FormattedComment"> 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.<br> </div> Blocking suspend blockers http://lwn.net/Articles/388581/rss 2010-05-20T18:30:46+00:00 felipebalbi <div class="FormattedComment"> 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.<br> <p> If you forcefully suspend at that point, you're risking corrupting user's Data.<br> <p> 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.<br> </div> Android looks good in that aera http://lwn.net/Articles/388575/rss 2010-05-20T18:25:25+00:00 farnz <p>Suspend blockers would help in one or possibly two ways: <ol> <li>You can log whenever a suspend blocker is taken out or released, so it's then obvious that the IM app is causing the power draw; when it just wakes up briefly once a second to poll things, it vanishes in system noise. Even an in-memory log is enough to let you spot apps that are claiming a suspend blocker once a second. <li>Assuming you have appropriate system capabilities, you can prohibit the application from taking out the block in the first place. For example, you could set permissions that prevent the app from taking out a suspend block, or use a library to lie to the application and tell it that it has a block taken out when it doesn't. </ol> Android looks good in that aera http://lwn.net/Articles/388576/rss 2010-05-20T18:13:03+00:00 zlynx <div class="FormattedComment"> Because suspend blocks are noisily pointed out to both the developer and the user. <br> <p> While in the IM example, a desktop software developer might find it perfectly reasonable to wake every 5 seconds and not think anything of it.<br> </div> Android looks good in that aera http://lwn.net/Articles/388574/rss 2010-05-20T18:03:28+00:00 dlang <div class="FormattedComment"> and if that IM app raises the blocker flag to prevent the system from going to sleep so that it can do it's checks, how are you any better off?<br> </div> Blocking suspend blockers http://lwn.net/Articles/388573/rss 2010-05-20T18:01:46+00:00 dlang <div class="FormattedComment"> 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)<br> </div> Blocking suspend blockers http://lwn.net/Articles/388572/rss 2010-05-20T17:59:51+00:00 dlang <div class="FormattedComment"> 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'<br> </div> Blocking suspend blockers http://lwn.net/Articles/388571/rss 2010-05-20T17:56:42+00:00 dlang <div class="FormattedComment"> which part of the post did you wish to cancel?<br> </div> Blocking suspend blockers http://lwn.net/Articles/388552/rss 2010-05-20T15:57:29+00:00 intgr <div class="FormattedComment"> <font class="QuotedText">&gt; Desktop distros could [...] restrict userspace access to the API, if they</font><br> <font class="QuotedText">&gt; were concerned about buggy userspace code blocking suspend?</font><br> <p> 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:<br> * The hardware is not designed that way; suspending (spinning down) your hard drive every few seconds is a great way to kill it<br> * Current software does not acquire suspend blockers where they would be expected by the user<br> * 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.<br> <p> This is an Android-specific feature that cannot be reliabily used in other configurations, possibly even other handsets.<br> <p> </div> Android looks good in that aera http://lwn.net/Articles/388527/rss 2010-05-20T13:24:46+00:00 xav <div class="FormattedComment"> I have a N900 which, unlike Android, uses a more desktop-like system. It's a "normal" kernel where applications have to be careful not to drain the battery.<br> And believe me, even if it seems it's a good idea, it sucks for a phone. I often find my phone dead because some IM app just wakes up once every few seconds, which is nearly undetectable with top but is sufficient to avoid deep sleep and drains the battery like mad.<br> <p> So, even if at first I found the concept of a desktop-like linux on a phone better, the more I learn about Android the more I think the latter made the right design decision.<br> </div> Blocking suspend blockers http://lwn.net/Articles/388496/rss 2010-05-20T12:17:22+00:00 iq-0 <div class="FormattedComment"> I'm probably missing some things, but in my view these "suspend blockers" are nothing more than a simple semaphore lock around the "deep suspend" resource. And as such it is nothing more than a very basic synchronization mechanism between a lot of concurrently running processes.<br> <p> To put it differently: I don't think "suspend blockers" actually add something new, they just move the "device not ready for suspending" synchronized flag out of the driver and into the generic kernel. The "userspace can inhibit suspend" is nothing more than a N-th party acquiring the "lock".<br> <p> This "lock" would logically be something very close to the device structure used for other stuff (thus the "system" cannot suspend, because a "bus" cannot suspend, because a "device" has the "suspend lock" but the rest can be suspended). So this would effectively be a hierarchical locking scheme where releasing the lock would switch that part of the hierarchy to the default idle state.<br> <p> This default idle state would for normal (classic PM) probably be simply to let the device be turned on (or put in a shallow power state in laptop mode) and in the aggressive power-save state it would immediately put all resources in that subtree in a deeper power state.<br> <p> Userspace could simply control this "wanted powerstate" attribute given external observation (how it's done now) and the "locking" would prevent the system from powering down devices that are in a critical region until they're done.<br> <p> The tricky bits in suspend are normally the interdependencies between devices that are powered down and devices that want to power down. But the "aggressive power-save" state should still inhibit devices (or even wake them) when others really need them (a simple write to disk would probably have to wait, but a read is blocking someone).<br> <p> There ofcourse always subtle behaviours to take care of, but the general idea of locking could possibly apply to simple suspend as well. And one doesn't really have to write code to put devices in as deep a sleep as possible but the rather easier: don't power down during this critical region.<br> </div> Blocking suspend blockers http://lwn.net/Articles/388469/rss 2010-05-20T10:41:22+00:00 brendan_wright <div class="FormattedComment"> 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.<br> <p> 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.<br> <p> 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. <br> <p> 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?<br> </div> Blocking suspend blockers http://lwn.net/Articles/388471/rss 2010-05-20T09:39:55+00:00 farnz <p>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 <a href="http://developer.android.com/guide/topics/manifest/manifest-intro.html">manifest file</a>, 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. <p>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.