Attempted summary of suspend-blockers LKML thread
Subsystems (4)
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Paul E. McKenneyone other nice-to-have (or conflicting requirement, depending on your point of view), and I think one of the big things causing people to dislike wavelocks, is the desire to not have to modify applications to have them work with the infrastructure.
you sort of touch on this when you say that power oblivious applications need to be able to be intergrated, but it goes beyond what that statement implies.
with wavelocka, even power optimized applications need to be modified, or the system may halt them at any time.
one thing that has been very clear over the years is that if an API only exists on Linux, no matter how good it is, most application developers won't use it.
In this case we are in an even worse situation, it's not only specific to Linux, it's specific to a subset of Linux systems, and not using it will cause no problems most of the time.
now, android is betting that the apps are all developed specifically for the android from scratch, so having a different API is acceptable, even if it cuts them off from the rest of the *nix applications. For a phone this is not neccessarily an unreasonable stance, but as Android moves into the spaces where normal applications are in use (netbooks and tablets), this becomes a much shakier stance to take.
David Lang
Quoted 672 lines · Paul E. McKenney
Date: Fri, 6 Aug 2010 15:54:53 -0700
From: Paul E. McKenney <[email protected]>
To: [email protected], [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], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
Subject: Attempted summary of suspend-blockers LKML thread, take threeFinal report from this particular angel-free zone for the time being...
This is the third and final version of my Android requirements list (last version available at http://lkml.org/lkml/2010/8/4/409). Again, this email is an attempt to present the Android guys' requirements, based on my interpretation of LKML discussions. This past week's discussion was quite productive, and I thank everyone who took part.
Please note that I am not proposing a solution that meets these requirements, nor am I attempting to judge the various proposed solutions. In fact, I am not even trying to judge whether the requirements are optimal, or even whether or not they make sense at all. My only goal at the moment is to improve our collective understanding of what the Android folks' requirements are. That said, I do discuss example mechanisms where needed to clarify the meaning of the requirements. This should not be interpreted as a preference for any given example mechanism.
Thanx, Paul
------------------------------------------------------------------------
CONTENTS
o DEFINITIONS
o CATEGORIES OF APPLICATION BEHAVIOR
o REQUIREMENTS
o NICE-TO-HAVES
o APPARENT NON-REQUIREMENTS
o SUGGESTED USAGE
o POWER-OPTIMIZED APPLICATIONS
o OTHER EXAMPLE APPLICATIONS
o ACKNOWLEDGMENTSDEFINITIONS
These have been updated based on LKML and linux-pm discussions. The names are probably still sub-optimal, but incremental progress is nevertheless a very good thing.
o "Ill-behaved application" AKA "untrusted application" AKA
"crappy application". The Android guys seem to be thinking in terms of applications that are well-designed and well-implemented in general, but which do not take power consumption or battery life into account. Examples include applications designed for externally powered PCs. Many other people seemed to instead be thinking in terms of an ill-conceived or useless application, perhaps exemplified by "bouncing cows".This document uses "power-oblivious applications" to mean applications that are well-designed and well-implemented in in general, but which do not take power consumption or battery life into account.
o "PM-driving application" are applications that are permitted
to acquire suspend blockers on Android. Verion 8 of the suspend-blocker patch seems to use group permissions to determine
which processes are classified as power aware. Android uses a
user-level daemon to classify app-store apps as PM-driving or not. More generally, PM-driving applications are those that have permission to exert some control over the system's sleep state.Note that an application might be power-oblivious on one Android device and PM-driving on another, depending on whether the user allows that application to acquire suspend blockers. The classification might even change over time. For example, a user might give an application PM-driving status initially, but change his or her mind after some experience with that application.
o Oddly enough, "power-optimized applications" were not discussed.
See "POWER-OPTIMIZED APPLICATIONS" below for a brief introduction. The short version is that power-optimized applications are those PM-driving applications that have been aggressively tuned to reduce power consumption.o Individual devices in an embedded system can enter "device
low-power states" when not in use.o The system as a whole can enter a "system sleep state" when
the system as a whole is not in use. Suspend blockers are about system sleep states rather than device low-power states.o There was much discussion of "idle" (AKA "deep idle") and
"suspend" (as in current Linux-kernel suspend operations). The following characteristics distinguish "idle" from "suspend":1. Idle states are entered by a given CPU only there are no
runnable tasks for that CPU. In contrast, opportunistic suspend can halt the entire system even when there are tasks that are ready, willing, and able to run. (But please note that this might not apply to real-time tasks.)Freezing of subsets of applications is somewhat related to the idle/suspend discussion, but is covered in a later section of this document.
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 idle. Exactly which events are in this set depends both on hardware capabilities and on the platform/application policy. For example, on one of the Android-based smartphones, touchscreen input is ignored when the system is suspended, but is handled when idle.3. The system comes out of idle when a timer expires. In
contrast, timers might or might not bring the system out of suspend, depending on both hardware capabilities and platform/application policy.CATEGORIES OF APPLICATION BEHAVIOR
There are a number of categories of application behavior with respect to power management and energy efficiency. These can be classified via the following questions: (1) What degree of control is an application permitted over its own behavior? (2) What degree of control is an application permitted over the power state of individual devices within the system? (3) What degree of control is an application permitted over the system sleep state? (4) To what degree has the application been tuned to reduce its power consumption, either in isolation or in conjunction with other applications that might be running concurrently?
These categories are discussed below.
o What degree of control is an application permitted over its
own behavior?The Linux kernel already has many controls over application behavior:
o the
CAP_capabilities frominclude/linux/capability.h.o Processes can be assigned to multiple groups, allowing
them privileged access to portions of the filesystem.o The
chroot()system call limits a process's access to the
specified subtree of the filesystem.o The ulimit facility can limit CPU consumption, number
of processes, memory, etc. on a per-user basis. The rlimit facility has similar effects on a per-process basis.o The
mlockall()system call provides privileged access
to memory, avoiding page-fault overhead.But more relevant to this discussion, real-time processes are permitted a much higher degree of control over the timing of their execution than are non-real-time processes. However, suspending the system destroys any pretense of offering real-time guarantees, which might explain much of the annoyance towards suspend blockers from the real-time and scheduler folks. For but one example, Peter Zijlstra suggested that he would merge a patch that acquired a suspend blocker any time that the runqueues were non-empty. My first reaction was amusement at this vintage Peter Zijlstra response, and my second reaction was that it was a futile gesture, as the Android guys would simply back out any such change.
After more thought, however, a variation of Peter's approach might well be the key to resolving this tension between real-time response on the one hand and Android's desire to conserve power at any cost on the other. Given that suspending destroys real-time response, why not acquire a suspend blocker any time there is a user-created real-time task in the system, whether runnable or not? Of course, a simpler approach would be to make Android's
OPPORTUNISTIC_SUSPENDdepend on !PREEMPT_RT.o What degree of control is an application permitted over the power
state of individual devices within the system?Is the application in question permitted to power down the CPU or peripheral devices? As more of the power control is automated based on usage, it is possible that this question will become less relevant. The longer the latency and the greater the energy consumption of a power-up/power-down sequence for a given device, the less suitable that device is for automatic power-up/power-down decisions. Cache SRAMs and main-memory DRAM tend to be less suitable for automation for this reason.
o What degree of control is an application permitted over the
system sleep state?Is the application permitted to suspend the device? Or in the case of Android, is the application permitted to acquire a suspend blocker, which prevents the device from being suspended?
o To what degree has the application been tuned to reduce its
power consumption, either in isolation or in conjunction with other applications that might be running concurrently?See the "POWER-OPTIMIZED APPLICATIONS" section below for more detail on the lengths that embedded developers go to in order to conserve power -- or, more accurately, to extend battery life.
REQUIREMENTS
o Reduce the system's power consumption in order to (1) extend
battery life and (2) preserve state until external power can be obtained.o It is necessary to be able to use power-oblivious applications.
Many of these applications were designed for use in PC platforms where power consumption has historically not been of great concern, due to either (1) the availability of external power or
(2) relatively undemanding laptop battery-lifetime expectations. The system must be capable of running these power-oblivious applications without requiring that these applications be modified, and must be capable of reasonable power efficiency even when power-oblivious applications are in use.In other words, it must be possible to automate the incorporation of a power-oblivious application into the Android environment, but without significantly degrading battery lifetime.
o If the display is powered off, there is no need to run any
application whose only effect is to update the display.Although one could simply block such an application when it next tries to access the display, it it is highly desirable that the application also be prevented from consuming power computing something that will not be displayed. Furthermore, whatever mechanism is used must operate on power-oblivious applications that do not use blocking system calls.
There might well be similar requirements for other output-only devices, as noted by Alan Stern.
o In order to avoid overrunning hardware and/or kernel buffers,
and to minimize response latencies, designated input events must be delivered to the corresponding application in a timely fashion. The application might or might not be required to actually process the events in a timely fashion, depending on the specific application.In particular, if user input that would prevent the system from entering a sleep state is received while the system is transitioning into a sleep state, the system must transition back out of the sleep state so that it can hand the user input off to the corresponding application.
Other input events do not force a wakeup, and such input events -can- be lost due to buffer overflow in hardware or the kernel. The response latency to such input events can of course be unbounded.
o Because Android acquires a suspend blocker as soon as an
input event is noticed and holds it until some application reads that input event, there must be a way to cause the suspend blocker to timeout. If there was no such timeout facility, a power-oblivious application could block suspend by opening an input device and then refusing to ever read from it. (Yes, this can be considered to be a energy-efficiency bug in the power-oblivious application. Please see the statistics requirement below.)o The API must provide a way for PM-driving applications that
receive events to keep themselves running until they have been able to process those events.o Statistics of the power-control actions taken by PM-driving
applications must be provided. Statistics are aggregated by name,
which is passed by the application in through the suspend-blocker interface. The following specific statistics are collected in the kernel, in roughly decreasing order of importance:o
total_time, which accumulates the total amount of time
that the corresponding suspend blocker has been held.o
active_since, which tracks how long a suspend blocker has
been held since it was last acquired, or (presumably) zero if it is not currently held.o count, which is the number of times that the suspend
blocker has been acquired. This is useful in combination withtotal_time, as it allows you to calculate the average hold time for the suspend blocker.o
expire_count, which is the number of times that the
suspend blocker has timed out. This indicates that some application has an input device open, but is not reading from it, which is a bug, as noted earlier.o
max_time, which is the longest hold time for the suspend
blocker. This allows finding cases where suspend blockers are held for too long, but are eventually released. (In contrast,active_sinceis more useful in the held-forever case.)o
sleep_time, which is the total time that the suspend
blocker was held while the display was powered off. (This might have interesting implications should E-ink displays every become capable of full-motion color video, but it is easy to imagine that the definition of "powered off" would then include only those times during which the display wasn't actively being updated.)o
wake_count, which is the number of times that the
suspend blocker was the first to be acquired in the resume path. This is less than useful on some Android platforms; Arve is dissatisfied with it on Nexus One.Presumably, the userspace code collects similar statistics on application suspend-blocker activity, but that is out of the scope of this document, which focuses instead on kernel requirements. Given that the overhead of maintaining these statistics is quite low, it seems that it would be worthwhile to have them enabled in production systems, for example, in order to flag power-buggy applications that the user has naively downloaded.
o Some PM-driving applications use power-oblivious infrastructure
code. This means that a PM-driving application must have some way, whether explicit or implicit, to ensure that any power-oblivious infrastructure code is permitted to run when a PM-driving application needs it to run.o If no PM-driving or power-optimized application are indicating
a need for the system to remain operating, the system is permitted (even encouraged!) to suspend all execution, regardless of the
state of power-oblivious applications. (This requirement did
appear to be somewhat controversial, both in terms of what is meant by "runnable" and in terms of what constitutes "execution".)In Android, this is implemented by suspending even while PM-driving or power-optimized applications are active, -unless- a suspend blocker is held.
o Transition to system sleep state must be power-efficient.
In particular, methods based on repeated attempts to suspend are considered to be too inefficient to be useful.o Transition to system sleep state must occur very soon after
all PM-driving and power-optimized applications have indicated that they have no need for the system to remain operating. Quick transition is expecially important in cases where the wakeup was momentary, for example, when processing sporadic network input or processing widely spaced batches of audio output. For an example of the latter, MP3 playback allows 1-4 minute spacing between bursts of CPU activity).o Individual peripherals and CPUs must still use standard
power-conservation measures, for example, transitioning CPUs into low-power states on idle and powering down peripheral devices and hardware accelerators that have not been recently used.o The API that controls the system sleep state must be accessible
both from Android's Java replacement, from userland C code, and from kernel C code (both process level and irq code, but not NMI handlers).o The API that controls the system sleep state must operate
correctly on SMP systems of modest size. (My guess is that "modest" means up to four CPUs, maybe up to eight CPUs.)o Any QoS-based solution must take display and user-input
state into account. In other words, the QoS must be expressed as a function of the display and the user-input states.o Transitioning to extremely low-power sleep states requires saving
and restoring DRAM and/or cache SRAM state, which in itself consumes significant energy. The power savings must therefore be balanced against the energy consumed in the state transitions.o The current Android userspace API must be supported in order
to support existing device software. According to Brian Swetland:For Java/Dalvik apps, the wakelock API is pertty high level -- it talks to a service via RPC (Binder) that actually interacts with the kernel. Changing the basic kernel<->userspace interface (within reason) is not unthinkable. For example, Arve's
suspend_blockerpatch provides a device interface rather than the proc interface the older wakelock patches use. We'd have to make some userspace changes to support that but they're pretty low level and minor.In the current model, only a few processes need to specifically interact with the kernel (the power management service in the
system_server, possibly themedia_serverand the radio interface glue). A model where every process needs to have a bunch of instrumentation is not very desirable from our point of view. We definitely do need reasonable statistics in order to enable debugging and to enable reporting to endusers (through the Battery Usage UI) what's keeping the device awake.o Any mechanism that freezes some subset of the applications must
ensure that none of the frozen applications hold any user-level resources, such as pthread mutexes. The reason for this is that freezing an application that holds a shared pthread mutex will result in an application-level hang should some unfrozen process attempt to acquire that same pthread mutex. Note that although the current cgroup freezer ensures that frozen applications do not hold any kernel-level mutexes (at least assuming these mutexes are not wrongly held when returning to user-level execution), it currently does nothing to prevent freezing processes holding pthread mutexes. (There are some proposals to address this issue.)NICE-TO-HAVES
o It would be nice to be able to identify power-oblivious
applications that never were depended on by PM-driving applications. This particular class of power-oblivious applications could be shut down when the screen blanks even if some PM-driving application was preventing the system from powering down.There are two obstacles to meeting this requirement:
1. There must be a reliable way to identify such
applications. This should be doable, for example, the application might be tagged by its developer.2. There must be a reliable way to freeze them such
that no frozen application holds a resource that might be contended by a non-frozen application.Although the cgroup freezer does ensure that frozen tasks hold no kernel-level resources, it currently does nothing to ensure that no user-level resources are held. There are some alternative proposals, which might or might not be more successful:
a. Unfreeze this group periodically to ensure
that any such resource is eventually released, while keeping power consumption down to a dull roar.b. Perform the freeze at application level, where
it is possible to determine whether an application-level resource is held.o Any initialization of the API that controls the system power
state should be unconditional, so as to be free from failure. Such unconditional initialization reduces the intrusiveness of the Android patchset.APPARENT NON-REQUIREMENTS
o Transitioning to system sleep states need not be highly scalable,
as evidenced by the global locks. (If you believe that high scalability will in fact be required, please provide a use case. But please understand that I do know something about scalability trends, but also about uses for transistors beyond more cores.)That said, it should not be hard to provide a highly scalable implementation of suspend blockers, especially if large systems are allowed to take their time suspending themselves.
o Conserving power in the WiFi and cellular telephony networks.
At the moment, the focus is on increased battery life in the handheld device, perhaps even at the expense of additional power consumed by the externally powered WiFi and cell-telephony equipment.o Synchronizing wakeups of unrelated applications. This is of
course an important requirement for power savings overall, but seems to be left to other mechanisms (e.g., timer aggregation) by the Android folks. Although one could implement suspend blockers so as to aggregate timers after a sufficiently long suspension, there are problems with this approach:o There would be a "thundering herd" problem just after
resume completed as almost every timer in the system would expire simultaneously.o The applications would not necessarily stay aggregated
without some other mechanism helping out.SUGGESTED USAGE
These are constraints that the developer is expected to abide by, "for best results" and all that.
o When a PM-driving application is preventing the system from
shutting down, and is also waiting on a power-oblivious application, the PM-driving application should set a timeout to handle the possibility that the power-oblivious application might halt or otherwise fail.POWER-OPTIMIZED APPLICATIONS
A typical power-optimized application manually controls the power state of many separately controlled hardware subsystems to minimize power consumption. Such optimization normally requires an understanding of the hardware and of the full system's workload: strangely enough, concurrently running two separately power-optimized applications often does -not- result in a power-optimized system. Such optimization also requires knowledge of what the application will be doing in the future, so that needed hardware subsystems can be proactively powered up just when the application will need them. This is especially important when powering down cache SRAMS or banks of main memory, because such components take significant time (and consume significant energy) when preparing them to be powered off and when restoring their state after powering them on.
Consider an MP3 player as an example. Such a player will periodically read MP3-encoded data from flash memory, decode it (possibly using hardware acceleration), and place the resulting audio data into main memory. Different systems have different ways of getting the data from main memory to the audio output device, but let's assume that the audio output device consumes data at a predictable rate such that the software can use timers to schedule refilling of the device's output buffer. The timer duration will of course need to allow for the time required to power up the CPU and L2 cache. The timer can be allowed to happen too soon, albeit with a battery-lifetime penalty, but cannot be permitted to happen too late, as this will cause "skips" in the playback.
If MP3 playback is the only application running in the system, things are quite easy. We calculate when the audio output device will empty its buffer, allow a few milliseconds to power up the needed hardware, and set a timer accordingly. Because modern audio output devices have buffers that can handle roughly a second's worth of output, it is well worthwhile to spend the few milliseconds required to flush the cache SRAMS in order to put the system into an extremely low-power sleep state over the several hundred milliseconds of playback.
Now suppose that this device is also recording audio -- perhaps the device is being used to monitor an area for noise pollution, and the user is also using the device to play music via earphones. The audio input process will be the inverse of the audio output process: the microphone data will fill a data buffer, which must be collected into DRAM, then encoded (perhaps again via MP3) and stored into flash. It would be easy to create an optimal application for audio input, but running this optimal audio input program concurrently with the optimal audio playback program would not necessarily result in a power-optimized combination. This lack of optimality is due to the fact that the input and output programs would each burn power separately powering down and up. In contrast, an optimal solution would align the input and output programs' timers so that a single power-down/power-up event would cover both programs' processing. This would trade off optimal processing of each (for example, by draining the input buffer before it was full) in order to attain global optimality (by sharing power-down/power-up overhead).
There are a number of ways to achieve this:
1. Making the kernel group timers that occur at roughly the same
time, as has been discussed on this list many times. This can work in many cases, but can be problematic in the audio example, due to the presence of hard deadlines.2. Write the programs to be aware of each other, so that each
adjusts its behavior when the other is present. This seems to be current practice in the battery-powered embedded arena, but is quite complex, sensitive to both hardware configuration and software behavior, and requires that all combinations of programs be anticipated by the designer -- which can be a serious disadvantage given today's app stores.3. Use new features such as range timers, so that each program
can indicate both its preference and the degree of flexibility that it can tolerate. This also works in some cases, but as far as I know, current proposals do not allow the kernel to take power-consumption penalties into account.4. Provide "heartbeat" services that allow applications to
synchronize with each other. This seems most applicable for applications that run infrequently, such as email-checking and location-service applications.5. Use of hardware facilities that allow DMA to be scheduled across
time. This would allow the CPU to be turned on only for decode/encode operations. I am under the impression that this sort of time-based DMA hardware does exist in the embedded space and that it is actually used for this purpose.6. Your favorite solution here.
Whatever solution is chosen, the key point to keep in mind is that running power-optimized applications in combination does -not- result in optimal system behavior.
OTHER EXAMPLE APPLICATIONS
GPS application that silently displays position.
There is no point in this application consuming CPU cycles or in powering up the GPS hardware unless the display is active. Such an application could be handled by the Android suspend-blocker proposal. Of course, such an application could also periodically poll the display, shutting itself down if the display is inactive. In this case, it would also need to have some way to be reactivated when the display comes back on.
GPS application that alerts the user when a given location is reached.
This application should presumably run even when the display is powered down due to input timeout. The question of whether or not it should continue running when the device is powered off is an interesting one that would be likely to spark much spirited discussion. Regardless of the answer to this question, the GPS application would hopefully run very intermittently, adjusting the delay interval based on the device's velocity and distance from the location in question.
I don't know enough about GPS hardware to say under what circumstances the GPS hardware itself should be powered off. However, my experience indicates that it takes significant time for the GPS hardware to get a position fix after being powered on, so presumably this decision would also be based on device velocity and distance from the location in question.
Assuming that the application can run only intermittently, suspend blockers would work reasonably well for this use case. If the application needed to run continuously, battery life would be quite short regardless of the approach used.
MP3 playback.
This requires a PM-driving (and preferably a power-optimized) application. Because the CPU need only run intermittently, suspend blockers can handle this use case. Presumably switching the device off would halt playback.
Bouncing cows.
This can work with a power-oblivious application that is shut down whenever the display is powered off or the device is switched off, similar to the GPS application that silently displays position.
ACKNOWLEDGMENTS
Of course, just because I acknowledge their contributions does not necessarily mean that I think they agree with my assessment of the requirements behind suspend blockers. ;-)
Nevertheless, I am grateful for any and all feedback, whatever the form of that feedback might be. I am new to this area, and have much to learn.
Alan Stern
Anca Emanuel
Arjan van de Ven
Arve Hj?nnev?g
Brian Swetland
David Brownell
David Lang
Florian Mickler
James Bottomley
Kevin Granade
Mark Brown
Matt Helsley
Matthew Garrett
Mikael Abrahamsson
Olivier Galibert
Paul Menage
Pavel Machek
Rafael J. Wysocki
Richard Woodruff
Ted Ts'o
Quoted 1 line · On Fri, Aug 06, 2010 at 04:35:59PM -0700, [email protected] wrote:
On Fri, 6 Aug 2010, Paul E. McKenney wrote:
Guys, please try to cut unneeded text from the quotes - it makes it much easier to find the new text.
Quoted 11 lines
Quoted 11 lines
Quoted 3 lines
Well, not really from the Linux point of view. It's not massively different to something like keeping an ethernet controller sufficiently alive to allow it to provide wake on LAN functionality while the system
The wake-on-LAN and the lights-out management systems are indeed interesting examples, and actually pretty good ones. The reason I excluded them is that they don't do any application processing -- their only purpose is the care and feeding of the system itself. In contrast, the embedded processors are able to do significant applications processing (e.g., play back music) while any CPUs are completely shut down and most of the memory is powered down as well.
This isn't a particularly meaningful distinction, things like the LoM systems on servers are generally at least as capable as things like the DSPs doing tasks like offloaded MP3 decode and often provide useful services in themselves (like system monitoring). It's really just semantics to treat them differently to something like a cellular modem - at a high level they're both just independant processors ticking away without the application processor.
Quoted 5 lines
one other significant issue is that on the PC, things like wake-on-LAN, lights out management cards, etc require nothing from the main system other than power. If they do something, they are sending the signal to the chipset, which then wakes the system up. they don't interact with the main processor/memory/etc at all.
I don't see that it makes much difference what gets kept alive - at the end of the day the point is that we're making a decision to keep bits of the system alive over suspend.
Quoted 4 lines
So as I see it, we need to do one of two things.
1. change the suspend definition to allow for some things to not be suspended
This is essentially what's already happening.
Quoted 4 lines
2. change the sleep/low-power mode definition to have a more standardized way of turning things off, and extend it to allow clocks to be turned off as well (today we have things able to be turned off, drive spin-down for example, but per comments in this thread it's all one-off methods)
Currently things like clock trees are frequently managed orthogonaly to the system power state to at least some extent anyway - for example, perfectly normal wake events like button presses will often require clocks for things like debouncing.
Quoted 1 line · On Fri, Aug 06, 2010 at 04:35:59PM -0700, [email protected] wrote:
On Fri, 6 Aug 2010, Paul E. McKenney wrote:
Guys, please try to cut unneeded text from the quotes - it makes it much easier to find the new text.
Quoted 11 lines
Quoted 11 lines
Quoted 3 lines
Well, not really from the Linux point of view. It's not massively different to something like keeping an ethernet controller sufficiently alive to allow it to provide wake on LAN functionality while the system
The wake-on-LAN and the lights-out management systems are indeed interesting examples, and actually pretty good ones. The reason I excluded them is that they don't do any application processing -- their only purpose is the care and feeding of the system itself. In contrast, the embedded processors are able to do significant applications processing (e.g., play back music) while any CPUs are completely shut down and most of the memory is powered down as well.
This isn't a particularly meaningful distinction, things like the LoM systems on servers are generally at least as capable as things like the DSPs doing tasks like offloaded MP3 decode and often provide useful services in themselves (like system monitoring). It's really just semantics to treat them differently to something like a cellular modem - at a high level they're both just independant processors ticking away without the application processor.
Quoted 5 lines
one other significant issue is that on the PC, things like wake-on-LAN, lights out management cards, etc require nothing from the main system other than power. If they do something, they are sending the signal to the chipset, which then wakes the system up. they don't interact with the main processor/memory/etc at all.
I don't see that it makes much difference what gets kept alive - at the end of the day the point is that we're making a decision to keep bits of the system alive over suspend.
Quoted 4 lines
So as I see it, we need to do one of two things.
1. change the suspend definition to allow for some things to not be suspended
This is essentially what's already happening.
Quoted 4 lines
2. change the sleep/low-power mode definition to have a more standardized way of turning things off, and extend it to allow clocks to be turned off as well (today we have things able to be turned off, drive spin-down for example, but per comments in this thread it's all one-off methods)
Currently things like clock trees are frequently managed orthogonaly to the system power state to at least some extent anyway - for example, perfectly normal wake events like button presses will often require clocks for things like debouncing.
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to [email protected]Quoted 11 lines · On Fri, Aug 06, 2010 at 04:59:54PM -0700, [email protected] wrote:
one other nice-to-have (or conflicting requirement, depending on your point of view), and I think one of the big things causing people to dislike wavelocks, is the desire to not have to modify applications to have them work with the infrastructure.
you sort of touch on this when you say that power oblivious applications need to be able to be intergrated, but it goes beyond what that statement implies.
with wavelocka, even power optimized applications need to be modified, or the system may halt them at any time.
Yes, I believe that Android would require most power-optimized application be modified to use wakelocks. But power-optimized applications require so much tweaking that the addition of suspend blockers (or whatever other power-control mechanism) is pretty much a non-issue by comparison.
And the number of power-optimized applications should be small, which, as you noted earlier, greatly eases the overall pain of modifying them.
Quoted 3 lines
one thing that has been very clear over the years is that if an API only exists on Linux, no matter how good it is, most application developers won't use it.
Many application developers do indeed value portability. But this in turn means that most application developers will not be writing power-optimized applications, because the process of power-optimization significantly degrades portability. Just as does the process of performance tuning, beyond a certain point.
Of course, the reason that application developers value portability is that this is one way to gain large unit volumes. Another way to gain large unit volumes is to code for a very popular platform, which explains the large number of apps that run only on iPhone, Android, and Windows.
And in my experience, developers who have decided to commit to a single platform are usually not at all shy about exploiting special facilities of that platform to the fullest.
Quoted 3 lines
In this case we are in an even worse situation, it's not only specific to Linux, it's specific to a subset of Linux systems, and not using it will cause no problems most of the time.
It seems to me that PM-driving and power-optimized applications are going to be highly platform specific, whether that platform be Linux or some other OS.
Quoted 7 lines
now, android is betting that the apps are all developed specifically for the android from scratch, so having a different API is acceptable, even if it cuts them off from the rest of the *nix applications. For a phone this is not neccessarily an unreasonable stance, but as Android moves into the spaces where normal applications are in use (netbooks and tablets), this becomes a much shakier stance to take.
There certainly does seem to be a large and growing number of Android apps, so I might be reluctant to bet against them. And the Android guys appear to be making another bet as well -- that almost all applications will be power-oblivious. Their design handles this rather well, given that such applications need not worry about special power-control features.
Thanx, Paul
Quoted 676 lines
David Lang
Quoted 672 lines · Paul E. McKenney
Date: Fri, 6 Aug 2010 15:54:53 -0700
From: Paul E. McKenney <[email protected]>
To: [email protected], [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], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
Subject: Attempted summary of suspend-blockers LKML thread, take threeFinal report from this particular angel-free zone for the time being...
This is the third and final version of my Android requirements list (last version available at http://lkml.org/lkml/2010/8/4/409). Again, this email is an attempt to present the Android guys' requirements, based on my interpretation of LKML discussions. This past week's discussion was quite productive, and I thank everyone who took part.
Please note that I am not proposing a solution that meets these requirements, nor am I attempting to judge the various proposed solutions. In fact, I am not even trying to judge whether the requirements are optimal, or even whether or not they make sense at all. My only goal at the moment is to improve our collective understanding of what the Android folks' requirements are. That said, I do discuss example mechanisms where needed to clarify the meaning of the requirements. This should not be interpreted as a preference for any given example mechanism.
Thanx, Paul
------------------------------------------------------------------------
CONTENTS
o DEFINITIONS
o CATEGORIES OF APPLICATION BEHAVIOR
o REQUIREMENTS
o NICE-TO-HAVES
o APPARENT NON-REQUIREMENTS
o SUGGESTED USAGE
o POWER-OPTIMIZED APPLICATIONS
o OTHER EXAMPLE APPLICATIONS
o ACKNOWLEDGMENTSDEFINITIONS
These have been updated based on LKML and linux-pm discussions. The names are probably still sub-optimal, but incremental progress is nevertheless a very good thing.
o "Ill-behaved application" AKA "untrusted application" AKA
"crappy application". The Android guys seem to be thinking in terms of applications that are well-designed and well-implemented in general, but which do not take power consumption or battery life into account. Examples include applications designed for externally powered PCs. Many other people seemed to instead be thinking in terms of an ill-conceived or useless application, perhaps exemplified by "bouncing cows".This document uses "power-oblivious applications" to mean applications that are well-designed and well-implemented in in general, but which do not take power consumption or battery life into account.
o "PM-driving application" are applications that are permitted
to acquire suspend blockers on Android. Verion 8 of the suspend-blocker patch seems to use group permissions to determine
which processes are classified as power aware. Android uses a
user-level daemon to classify app-store apps as PM-driving or not. More generally, PM-driving applications are those that have permission to exert some control over the system's sleep state.Note that an application might be power-oblivious on one Android device and PM-driving on another, depending on whether the user allows that application to acquire suspend blockers. The classification might even change over time. For example, a user might give an application PM-driving status initially, but change his or her mind after some experience with that application.
o Oddly enough, "power-optimized applications" were not discussed.
See "POWER-OPTIMIZED APPLICATIONS" below for a brief introduction. The short version is that power-optimized applications are those PM-driving applications that have been aggressively tuned to reduce power consumption.o Individual devices in an embedded system can enter "device
low-power states" when not in use.o The system as a whole can enter a "system sleep state" when
the system as a whole is not in use. Suspend blockers are about system sleep states rather than device low-power states.o There was much discussion of "idle" (AKA "deep idle") and
"suspend" (as in current Linux-kernel suspend operations). The following characteristics distinguish "idle" from "suspend":1. Idle states are entered by a given CPU only there are no
runnable tasks for that CPU. In contrast, opportunistic suspend can halt the entire system even when there are tasks that are ready, willing, and able to run. (But please note that this might not apply to real-time tasks.)Freezing of subsets of applications is somewhat related to the idle/suspend discussion, but is covered in a later section of this document.
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 idle. Exactly which events are in this set depends both on hardware capabilities and on the platform/application policy. For example, on one of the Android-based smartphones, touchscreen input is ignored when the system is suspended, but is handled when idle.3. The system comes out of idle when a timer expires. In
contrast, timers might or might not bring the system out of suspend, depending on both hardware capabilities and platform/application policy.CATEGORIES OF APPLICATION BEHAVIOR
There are a number of categories of application behavior with respect to power management and energy efficiency. These can be classified via the following questions: (1) What degree of control is an application permitted over its own behavior? (2) What degree of control is an application permitted over the power state of individual devices within the system? (3) What degree of control is an application permitted over the system sleep state? (4) To what degree has the application been tuned to reduce its power consumption, either in isolation or in conjunction with other applications that might be running concurrently?
These categories are discussed below.
o What degree of control is an application permitted over its
own behavior?The Linux kernel already has many controls over application behavior:
o the
CAP_capabilities frominclude/linux/capability.h.o Processes can be assigned to multiple groups, allowing
them privileged access to portions of the filesystem.o The
chroot()system call limits a process's access to the
specified subtree of the filesystem.o The ulimit facility can limit CPU consumption, number
of processes, memory, etc. on a per-user basis. The rlimit facility has similar effects on a per-process basis.o The
mlockall()system call provides privileged access
to memory, avoiding page-fault overhead.But more relevant to this discussion, real-time processes are permitted a much higher degree of control over the timing of their execution than are non-real-time processes. However, suspending the system destroys any pretense of offering real-time guarantees, which might explain much of the annoyance towards suspend blockers from the real-time and scheduler folks. For but one example, Peter Zijlstra suggested that he would merge a patch that acquired a suspend blocker any time that the runqueues were non-empty. My first reaction was amusement at this vintage Peter Zijlstra response, and my second reaction was that it was a futile gesture, as the Android guys would simply back out any such change.
After more thought, however, a variation of Peter's approach might well be the key to resolving this tension between real-time response on the one hand and Android's desire to conserve power at any cost on the other. Given that suspending destroys real-time response, why not acquire a suspend blocker any time there is a user-created real-time task in the system, whether runnable or not? Of course, a simpler approach would be to make Android's
OPPORTUNISTIC_SUSPENDdepend on !PREEMPT_RT.o What degree of control is an application permitted over the power
state of individual devices within the system?Is the application in question permitted to power down the CPU or peripheral devices? As more of the power control is automated based on usage, it is possible that this question will become less relevant. The longer the latency and the greater the energy consumption of a power-up/power-down sequence for a given device, the less suitable that device is for automatic power-up/power-down decisions. Cache SRAMs and main-memory DRAM tend to be less suitable for automation for this reason.
o What degree of control is an application permitted over the
system sleep state?Is the application permitted to suspend the device? Or in the case of Android, is the application permitted to acquire a suspend blocker, which prevents the device from being suspended?
o To what degree has the application been tuned to reduce its
power consumption, either in isolation or in conjunction with other applications that might be running concurrently?See the "POWER-OPTIMIZED APPLICATIONS" section below for more detail on the lengths that embedded developers go to in order to conserve power -- or, more accurately, to extend battery life.
REQUIREMENTS
o Reduce the system's power consumption in order to (1) extend
battery life and (2) preserve state until external power can be obtained.o It is necessary to be able to use power-oblivious applications.
Many of these applications were designed for use in PC platforms where power consumption has historically not been of great concern, due to either (1) the availability of external power or
(2) relatively undemanding laptop battery-lifetime expectations. The system must be capable of running these power-oblivious applications without requiring that these applications be modified, and must be capable of reasonable power efficiency even when power-oblivious applications are in use.In other words, it must be possible to automate the incorporation of a power-oblivious application into the Android environment, but without significantly degrading battery lifetime.
o If the display is powered off, there is no need to run any
application whose only effect is to update the display.Although one could simply block such an application when it next tries to access the display, it it is highly desirable that the application also be prevented from consuming power computing something that will not be displayed. Furthermore, whatever mechanism is used must operate on power-oblivious applications that do not use blocking system calls.
There might well be similar requirements for other output-only devices, as noted by Alan Stern.
o In order to avoid overrunning hardware and/or kernel buffers,
and to minimize response latencies, designated input events must be delivered to the corresponding application in a timely fashion. The application might or might not be required to actually process the events in a timely fashion, depending on the specific application.In particular, if user input that would prevent the system from entering a sleep state is received while the system is transitioning into a sleep state, the system must transition back out of the sleep state so that it can hand the user input off to the corresponding application.
Other input events do not force a wakeup, and such input events -can- be lost due to buffer overflow in hardware or the kernel. The response latency to such input events can of course be unbounded.
o Because Android acquires a suspend blocker as soon as an
input event is noticed and holds it until some application reads that input event, there must be a way to cause the suspend blocker to timeout. If there was no such timeout facility, a power-oblivious application could block suspend by opening an input device and then refusing to ever read from it. (Yes, this can be considered to be a energy-efficiency bug in the power-oblivious application. Please see the statistics requirement below.)o The API must provide a way for PM-driving applications that
receive events to keep themselves running until they have been able to process those events.o Statistics of the power-control actions taken by PM-driving
applications must be provided. Statistics are aggregated by name,
which is passed by the application in through the suspend-blocker interface. The following specific statistics are collected in the kernel, in roughly decreasing order of importance:o
total_time, which accumulates the total amount of time
that the corresponding suspend blocker has been held.o
active_since, which tracks how long a suspend blocker has
been held since it was last acquired, or (presumably) zero if it is not currently held.o count, which is the number of times that the suspend
blocker has been acquired. This is useful in combination withtotal_time, as it allows you to calculate the average hold time for the suspend blocker.o
expire_count, which is the number of times that the
suspend blocker has timed out. This indicates that some application has an input device open, but is not reading from it, which is a bug, as noted earlier.o
max_time, which is the longest hold time for the suspend
blocker. This allows finding cases where suspend blockers are held for too long, but are eventually released. (In contrast,active_sinceis more useful in the held-forever case.)o
sleep_time, which is the total time that the suspend
blocker was held while the display was powered off. (This might have interesting implications should E-ink displays every become capable of full-motion color video, but it is easy to imagine that the definition of "powered off" would then include only those times during which the display wasn't actively being updated.)o
wake_count, which is the number of times that the
suspend blocker was the first to be acquired in the resume path. This is less than useful on some Android platforms; Arve is dissatisfied with it on Nexus One.Presumably, the userspace code collects similar statistics on application suspend-blocker activity, but that is out of the scope of this document, which focuses instead on kernel requirements. Given that the overhead of maintaining these statistics is quite low, it seems that it would be worthwhile to have them enabled in production systems, for example, in order to flag power-buggy applications that the user has naively downloaded.
o Some PM-driving applications use power-oblivious infrastructure
code. This means that a PM-driving application must have some way, whether explicit or implicit, to ensure that any power-oblivious infrastructure code is permitted to run when a PM-driving application needs it to run.o If no PM-driving or power-optimized application are indicating
a need for the system to remain operating, the system is permitted (even encouraged!) to suspend all execution, regardless of the
state of power-oblivious applications. (This requirement did
appear to be somewhat controversial, both in terms of what is meant by "runnable" and in terms of what constitutes "execution".)In Android, this is implemented by suspending even while PM-driving or power-optimized applications are active, -unless- a suspend blocker is held.
o Transition to system sleep state must be power-efficient.
In particular, methods based on repeated attempts to suspend are considered to be too inefficient to be useful.o Transition to system sleep state must occur very soon after
all PM-driving and power-optimized applications have indicated that they have no need for the system to remain operating. Quick transition is expecially important in cases where the wakeup was momentary, for example, when processing sporadic network input or processing widely spaced batches of audio output. For an example of the latter, MP3 playback allows 1-4 minute spacing between bursts of CPU activity).o Individual peripherals and CPUs must still use standard
power-conservation measures, for example, transitioning CPUs into low-power states on idle and powering down peripheral devices and hardware accelerators that have not been recently used.o The API that controls the system sleep state must be accessible
both from Android's Java replacement, from userland C code, and from kernel C code (both process level and irq code, but not NMI handlers).o The API that controls the system sleep state must operate
correctly on SMP systems of modest size. (My guess is that "modest" means up to four CPUs, maybe up to eight CPUs.)o Any QoS-based solution must take display and user-input
state into account. In other words, the QoS must be expressed as a function of the display and the user-input states.o Transitioning to extremely low-power sleep states requires saving
and restoring DRAM and/or cache SRAM state, which in itself consumes significant energy. The power savings must therefore be balanced against the energy consumed in the state transitions.o The current Android userspace API must be supported in order
to support existing device software. According to Brian Swetland:For Java/Dalvik apps, the wakelock API is pertty high level -- it talks to a service via RPC (Binder) that actually interacts with the kernel. Changing the basic kernel<->userspace interface (within reason) is not unthinkable. For example, Arve's
suspend_blockerpatch provides a device interface rather than the proc interface the older wakelock patches use. We'd have to make some userspace changes to support that but they're pretty low level and minor.In the current model, only a few processes need to specifically interact with the kernel (the power management service in the
system_server, possibly themedia_serverand the radio interface glue). A model where every process needs to have a bunch of instrumentation is not very desirable from our point of view. We definitely do need reasonable statistics in order to enable debugging and to enable reporting to endusers (through the Battery Usage UI) what's keeping the device awake.o Any mechanism that freezes some subset of the applications must
ensure that none of the frozen applications hold any user-level resources, such as pthread mutexes. The reason for this is that freezing an application that holds a shared pthread mutex will result in an application-level hang should some unfrozen process attempt to acquire that same pthread mutex. Note that although the current cgroup freezer ensures that frozen applications do not hold any kernel-level mutexes (at least assuming these mutexes are not wrongly held when returning to user-level execution), it currently does nothing to prevent freezing processes holding pthread mutexes. (There are some proposals to address this issue.)NICE-TO-HAVES
o It would be nice to be able to identify power-oblivious
applications that never were depended on by PM-driving applications. This particular class of power-oblivious applications could be shut down when the screen blanks even if some PM-driving application was preventing the system from powering down.There are two obstacles to meeting this requirement:
1. There must be a reliable way to identify such
applications. This should be doable, for example, the application might be tagged by its developer.2. There must be a reliable way to freeze them such
that no frozen application holds a resource that might be contended by a non-frozen application.Although the cgroup freezer does ensure that frozen tasks hold no kernel-level resources, it currently does nothing to ensure that no user-level resources are held. There are some alternative proposals, which might or might not be more successful:
a. Unfreeze this group periodically to ensure
that any such resource is eventually released, while keeping power consumption down to a dull roar.b. Perform the freeze at application level, where
it is possible to determine whether an application-level resource is held.o Any initialization of the API that controls the system power
state should be unconditional, so as to be free from failure. Such unconditional initialization reduces the intrusiveness of the Android patchset.APPARENT NON-REQUIREMENTS
o Transitioning to system sleep states need not be highly scalable,
as evidenced by the global locks. (If you believe that high scalability will in fact be required, please provide a use case. But please understand that I do know something about scalability trends, but also about uses for transistors beyond more cores.)That said, it should not be hard to provide a highly scalable implementation of suspend blockers, especially if large systems are allowed to take their time suspending themselves.
o Conserving power in the WiFi and cellular telephony networks.
At the moment, the focus is on increased battery life in the handheld device, perhaps even at the expense of additional power consumed by the externally powered WiFi and cell-telephony equipment.o Synchronizing wakeups of unrelated applications. This is of
course an important requirement for power savings overall, but seems to be left to other mechanisms (e.g., timer aggregation) by the Android folks. Although one could implement suspend blockers so as to aggregate timers after a sufficiently long suspension, there are problems with this approach:o There would be a "thundering herd" problem just after
resume completed as almost every timer in the system would expire simultaneously.o The applications would not necessarily stay aggregated
without some other mechanism helping out.SUGGESTED USAGE
These are constraints that the developer is expected to abide by, "for best results" and all that.
o When a PM-driving application is preventing the system from
shutting down, and is also waiting on a power-oblivious application, the PM-driving application should set a timeout to handle the possibility that the power-oblivious application might halt or otherwise fail.POWER-OPTIMIZED APPLICATIONS
A typical power-optimized application manually controls the power state of many separately controlled hardware subsystems to minimize power consumption. Such optimization normally requires an understanding of the hardware and of the full system's workload: strangely enough, concurrently running two separately power-optimized applications often does -not- result in a power-optimized system. Such optimization also requires knowledge of what the application will be doing in the future, so that needed hardware subsystems can be proactively powered up just when the application will need them. This is especially important when powering down cache SRAMS or banks of main memory, because such components take significant time (and consume significant energy) when preparing them to be powered off and when restoring their state after powering them on.
Consider an MP3 player as an example. Such a player will periodically read MP3-encoded data from flash memory, decode it (possibly using hardware acceleration), and place the resulting audio data into main memory. Different systems have different ways of getting the data from main memory to the audio output device, but let's assume that the audio output device consumes data at a predictable rate such that the software can use timers to schedule refilling of the device's output buffer. The timer duration will of course need to allow for the time required to power up the CPU and L2 cache. The timer can be allowed to happen too soon, albeit with a battery-lifetime penalty, but cannot be permitted to happen too late, as this will cause "skips" in the playback.
If MP3 playback is the only application running in the system, things are quite easy. We calculate when the audio output device will empty its buffer, allow a few milliseconds to power up the needed hardware, and set a timer accordingly. Because modern audio output devices have buffers that can handle roughly a second's worth of output, it is well worthwhile to spend the few milliseconds required to flush the cache SRAMS in order to put the system into an extremely low-power sleep state over the several hundred milliseconds of playback.
Now suppose that this device is also recording audio -- perhaps the device is being used to monitor an area for noise pollution, and the user is also using the device to play music via earphones. The audio input process will be the inverse of the audio output process: the microphone data will fill a data buffer, which must be collected into DRAM, then encoded (perhaps again via MP3) and stored into flash. It would be easy to create an optimal application for audio input, but running this optimal audio input program concurrently with the optimal audio playback program would not necessarily result in a power-optimized combination. This lack of optimality is due to the fact that the input and output programs would each burn power separately powering down and up. In contrast, an optimal solution would align the input and output programs' timers so that a single power-down/power-up event would cover both programs' processing. This would trade off optimal processing of each (for example, by draining the input buffer before it was full) in order to attain global optimality (by sharing power-down/power-up overhead).
There are a number of ways to achieve this:
1. Making the kernel group timers that occur at roughly the same
time, as has been discussed on this list many times. This can work in many cases, but can be problematic in the audio example, due to the presence of hard deadlines.2. Write the programs to be aware of each other, so that each
adjusts its behavior when the other is present. This seems to be current practice in the battery-powered embedded arena, but is quite complex, sensitive to both hardware configuration and software behavior, and requires that all combinations of programs be anticipated by the designer -- which can be a serious disadvantage given today's app stores.3. Use new features such as range timers, so that each program
can indicate both its preference and the degree of flexibility that it can tolerate. This also works in some cases, but as far as I know, current proposals do not allow the kernel to take power-consumption penalties into account.4. Provide "heartbeat" services that allow applications to
synchronize with each other. This seems most applicable for applications that run infrequently, such as email-checking and location-service applications.5. Use of hardware facilities that allow DMA to be scheduled across
time. This would allow the CPU to be turned on only for decode/encode operations. I am under the impression that this sort of time-based DMA hardware does exist in the embedded space and that it is actually used for this purpose.6. Your favorite solution here.
Whatever solution is chosen, the key point to keep in mind is that running power-optimized applications in combination does -not- result in optimal system behavior.
OTHER EXAMPLE APPLICATIONS
GPS application that silently displays position.
There is no point in this application consuming CPU cycles or in powering up the GPS hardware unless the display is active. Such an application could be handled by the Android suspend-blocker proposal. Of course, such an application could also periodically poll the display, shutting itself down if the display is inactive. In this case, it would also need to have some way to be reactivated when the display comes back on.
GPS application that alerts the user when a given location is reached.
This application should presumably run even when the display is powered down due to input timeout. The question of whether or not it should continue running when the device is powered off is an interesting one that would be likely to spark much spirited discussion. Regardless of the answer to this question, the GPS application would hopefully run very intermittently, adjusting the delay interval based on the device's velocity and distance from the location in question.
I don't know enough about GPS hardware to say under what circumstances the GPS hardware itself should be powered off. However, my experience indicates that it takes significant time for the GPS hardware to get a position fix after being powered on, so presumably this decision would also be based on device velocity and distance from the location in question.
Assuming that the application can run only intermittently, suspend blockers would work reasonably well for this use case. If the application needed to run continuously, battery life would be quite short regardless of the approach used.
MP3 playback.
This requires a PM-driving (and preferably a power-optimized) application. Because the CPU need only run intermittently, suspend blockers can handle this use case. Presumably switching the device off would halt playback.
Bouncing cows.
This can work with a power-oblivious application that is shut down whenever the display is powered off or the device is switched off, similar to the GPS application that silently displays position.
ACKNOWLEDGMENTS
Of course, just because I acknowledge their contributions does not necessarily mean that I think they agree with my assessment of the requirements behind suspend blockers. ;-)
Nevertheless, I am grateful for any and all feedback, whatever the form of that feedback might be. I am new to this area, and have much to learn.
Alan Stern
Anca Emanuel
Arjan van de Ven
Arve Hj?nnev?g
Brian Swetland
David Brownell
David Lang
Florian Mickler
James Bottomley
Kevin Granade
Mark Brown
Matt Helsley
Matthew Garrett
Mikael Abrahamsson
Olivier Galibert
Paul Menage
Pavel Machek
Rafael J. Wysocki
Richard Woodruff
Ted Ts'o
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to [email protected]Quoted 11 lines · On Fri, Aug 06, 2010 at 04:59:54PM -0700, [email protected] wrote:
one other nice-to-have (or conflicting requirement, depending on your point of view), and I think one of the big things causing people to dislike wavelocks, is the desire to not have to modify applications to have them work with the infrastructure.
you sort of touch on this when you say that power oblivious applications need to be able to be intergrated, but it goes beyond what that statement implies.
with wavelocka, even power optimized applications need to be modified, or the system may halt them at any time.
Yes, I believe that Android would require most power-optimized application be modified to use wakelocks. But power-optimized applications require so much tweaking that the addition of suspend blockers (or whatever other power-control mechanism) is pretty much a non-issue by comparison.
And the number of power-optimized applications should be small, which, as you noted earlier, greatly eases the overall pain of modifying them.
Quoted 3 lines
one thing that has been very clear over the years is that if an API only exists on Linux, no matter how good it is, most application developers won't use it.
Many application developers do indeed value portability. But this in turn means that most application developers will not be writing power-optimized applications, because the process of power-optimization significantly degrades portability. Just as does the process of performance tuning, beyond a certain point.
Of course, the reason that application developers value portability is that this is one way to gain large unit volumes. Another way to gain large unit volumes is to code for a very popular platform, which explains the large number of apps that run only on iPhone, Android, and Windows.
And in my experience, developers who have decided to commit to a single platform are usually not at all shy about exploiting special facilities of that platform to the fullest.
Quoted 3 lines
In this case we are in an even worse situation, it's not only specific to Linux, it's specific to a subset of Linux systems, and not using it will cause no problems most of the time.
It seems to me that PM-driving and power-optimized applications are going to be highly platform specific, whether that platform be Linux or some other OS.
Quoted 7 lines
now, android is betting that the apps are all developed specifically for the android from scratch, so having a different API is acceptable, even if it cuts them off from the rest of the *nix applications. For a phone this is not neccessarily an unreasonable stance, but as Android moves into the spaces where normal applications are in use (netbooks and tablets), this becomes a much shakier stance to take.
There certainly does seem to be a large and growing number of Android apps, so I might be reluctant to bet against them. And the Android guys appear to be making another bet as well -- that almost all applications will be power-oblivious. Their design handles this rather well, given that such applications need not worry about special power-control features.
Thanx, Paul
Quoted 676 lines
David Lang
Quoted 672 lines · Paul E. McKenney
Date: Fri, 6 Aug 2010 15:54:53 -0700
From: Paul E. McKenney <[email protected]>
To: [email protected], [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], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
Subject: Attempted summary of suspend-blockers LKML thread, take threeFinal report from this particular angel-free zone for the time being...
This is the third and final version of my Android requirements list (last version available at http://lkml.org/lkml/2010/8/4/409). Again, this email is an attempt to present the Android guys' requirements, based on my interpretation of LKML discussions. This past week's discussion was quite productive, and I thank everyone who took part.
Please note that I am not proposing a solution that meets these requirements, nor am I attempting to judge the various proposed solutions. In fact, I am not even trying to judge whether the requirements are optimal, or even whether or not they make sense at all. My only goal at the moment is to improve our collective understanding of what the Android folks' requirements are. That said, I do discuss example mechanisms where needed to clarify the meaning of the requirements. This should not be interpreted as a preference for any given example mechanism.
Thanx, Paul
------------------------------------------------------------------------
CONTENTS
o DEFINITIONS
o CATEGORIES OF APPLICATION BEHAVIOR
o REQUIREMENTS
o NICE-TO-HAVES
o APPARENT NON-REQUIREMENTS
o SUGGESTED USAGE
o POWER-OPTIMIZED APPLICATIONS
o OTHER EXAMPLE APPLICATIONS
o ACKNOWLEDGMENTSDEFINITIONS
These have been updated based on LKML and linux-pm discussions. The names are probably still sub-optimal, but incremental progress is nevertheless a very good thing.
o "Ill-behaved application" AKA "untrusted application" AKA
"crappy application". The Android guys seem to be thinking in terms of applications that are well-designed and well-implemented in general, but which do not take power consumption or battery life into account. Examples include applications designed for externally powered PCs. Many other people seemed to instead be thinking in terms of an ill-conceived or useless application, perhaps exemplified by "bouncing cows".This document uses "power-oblivious applications" to mean applications that are well-designed and well-implemented in in general, but which do not take power consumption or battery life into account.
o "PM-driving application" are applications that are permitted
to acquire suspend blockers on Android. Verion 8 of the suspend-blocker patch seems to use group permissions to determine
which processes are classified as power aware. Android uses a
user-level daemon to classify app-store apps as PM-driving or not. More generally, PM-driving applications are those that have permission to exert some control over the system's sleep state.Note that an application might be power-oblivious on one Android device and PM-driving on another, depending on whether the user allows that application to acquire suspend blockers. The classification might even change over time. For example, a user might give an application PM-driving status initially, but change his or her mind after some experience with that application.
o Oddly enough, "power-optimized applications" were not discussed.
See "POWER-OPTIMIZED APPLICATIONS" below for a brief introduction. The short version is that power-optimized applications are those PM-driving applications that have been aggressively tuned to reduce power consumption.o Individual devices in an embedded system can enter "device
low-power states" when not in use.o The system as a whole can enter a "system sleep state" when
the system as a whole is not in use. Suspend blockers are about system sleep states rather than device low-power states.o There was much discussion of "idle" (AKA "deep idle") and
"suspend" (as in current Linux-kernel suspend operations). The following characteristics distinguish "idle" from "suspend":1. Idle states are entered by a given CPU only there are no
runnable tasks for that CPU. In contrast, opportunistic suspend can halt the entire system even when there are tasks that are ready, willing, and able to run. (But please note that this might not apply to real-time tasks.)Freezing of subsets of applications is somewhat related to the idle/suspend discussion, but is covered in a later section of this document.
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 idle. Exactly which events are in this set depends both on hardware capabilities and on the platform/application policy. For example, on one of the Android-based smartphones, touchscreen input is ignored when the system is suspended, but is handled when idle.3. The system comes out of idle when a timer expires. In
contrast, timers might or might not bring the system out of suspend, depending on both hardware capabilities and platform/application policy.CATEGORIES OF APPLICATION BEHAVIOR
There are a number of categories of application behavior with respect to power management and energy efficiency. These can be classified via the following questions: (1) What degree of control is an application permitted over its own behavior? (2) What degree of control is an application permitted over the power state of individual devices within the system? (3) What degree of control is an application permitted over the system sleep state? (4) To what degree has the application been tuned to reduce its power consumption, either in isolation or in conjunction with other applications that might be running concurrently?
These categories are discussed below.
o What degree of control is an application permitted over its
own behavior?The Linux kernel already has many controls over application behavior:
o the
CAP_capabilities frominclude/linux/capability.h.o Processes can be assigned to multiple groups, allowing
them privileged access to portions of the filesystem.o The
chroot()system call limits a process's access to the
specified subtree of the filesystem.o The ulimit facility can limit CPU consumption, number
of processes, memory, etc. on a per-user basis. The rlimit facility has similar effects on a per-process basis.o The
mlockall()system call provides privileged access
to memory, avoiding page-fault overhead.But more relevant to this discussion, real-time processes are permitted a much higher degree of control over the timing of their execution than are non-real-time processes. However, suspending the system destroys any pretense of offering real-time guarantees, which might explain much of the annoyance towards suspend blockers from the real-time and scheduler folks. For but one example, Peter Zijlstra suggested that he would merge a patch that acquired a suspend blocker any time that the runqueues were non-empty. My first reaction was amusement at this vintage Peter Zijlstra response, and my second reaction was that it was a futile gesture, as the Android guys would simply back out any such change.
After more thought, however, a variation of Peter's approach might well be the key to resolving this tension between real-time response on the one hand and Android's desire to conserve power at any cost on the other. Given that suspending destroys real-time response, why not acquire a suspend blocker any time there is a user-created real-time task in the system, whether runnable or not? Of course, a simpler approach would be to make Android's
OPPORTUNISTIC_SUSPENDdepend on !PREEMPT_RT.o What degree of control is an application permitted over the power
state of individual devices within the system?Is the application in question permitted to power down the CPU or peripheral devices? As more of the power control is automated based on usage, it is possible that this question will become less relevant. The longer the latency and the greater the energy consumption of a power-up/power-down sequence for a given device, the less suitable that device is for automatic power-up/power-down decisions. Cache SRAMs and main-memory DRAM tend to be less suitable for automation for this reason.
o What degree of control is an application permitted over the
system sleep state?Is the application permitted to suspend the device? Or in the case of Android, is the application permitted to acquire a suspend blocker, which prevents the device from being suspended?
o To what degree has the application been tuned to reduce its
power consumption, either in isolation or in conjunction with other applications that might be running concurrently?See the "POWER-OPTIMIZED APPLICATIONS" section below for more detail on the lengths that embedded developers go to in order to conserve power -- or, more accurately, to extend battery life.
REQUIREMENTS
o Reduce the system's power consumption in order to (1) extend
battery life and (2) preserve state until external power can be obtained.o It is necessary to be able to use power-oblivious applications.
Many of these applications were designed for use in PC platforms where power consumption has historically not been of great concern, due to either (1) the availability of external power or
(2) relatively undemanding laptop battery-lifetime expectations. The system must be capable of running these power-oblivious applications without requiring that these applications be modified, and must be capable of reasonable power efficiency even when power-oblivious applications are in use.In other words, it must be possible to automate the incorporation of a power-oblivious application into the Android environment, but without significantly degrading battery lifetime.
o If the display is powered off, there is no need to run any
application whose only effect is to update the display.Although one could simply block such an application when it next tries to access the display, it it is highly desirable that the application also be prevented from consuming power computing something that will not be displayed. Furthermore, whatever mechanism is used must operate on power-oblivious applications that do not use blocking system calls.
There might well be similar requirements for other output-only devices, as noted by Alan Stern.
o In order to avoid overrunning hardware and/or kernel buffers,
and to minimize response latencies, designated input events must be delivered to the corresponding application in a timely fashion. The application might or might not be required to actually process the events in a timely fashion, depending on the specific application.In particular, if user input that would prevent the system from entering a sleep state is received while the system is transitioning into a sleep state, the system must transition back out of the sleep state so that it can hand the user input off to the corresponding application.
Other input events do not force a wakeup, and such input events -can- be lost due to buffer overflow in hardware or the kernel. The response latency to such input events can of course be unbounded.
o Because Android acquires a suspend blocker as soon as an
input event is noticed and holds it until some application reads that input event, there must be a way to cause the suspend blocker to timeout. If there was no such timeout facility, a power-oblivious application could block suspend by opening an input device and then refusing to ever read from it. (Yes, this can be considered to be a energy-efficiency bug in the power-oblivious application. Please see the statistics requirement below.)o The API must provide a way for PM-driving applications that
receive events to keep themselves running until they have been able to process those events.o Statistics of the power-control actions taken by PM-driving
applications must be provided. Statistics are aggregated by name,
which is passed by the application in through the suspend-blocker interface. The following specific statistics are collected in the kernel, in roughly decreasing order of importance:o
total_time, which accumulates the total amount of time
that the corresponding suspend blocker has been held.o
active_since, which tracks how long a suspend blocker has
been held since it was last acquired, or (presumably) zero if it is not currently held.o count, which is the number of times that the suspend
blocker has been acquired. This is useful in combination withtotal_time, as it allows you to calculate the average hold time for the suspend blocker.o
expire_count, which is the number of times that the
suspend blocker has timed out. This indicates that some application has an input device open, but is not reading from it, which is a bug, as noted earlier.o
max_time, which is the longest hold time for the suspend
blocker. This allows finding cases where suspend blockers are held for too long, but are eventually released. (In contrast,active_sinceis more useful in the held-forever case.)o
sleep_time, which is the total time that the suspend
blocker was held while the display was powered off. (This might have interesting implications should E-ink displays every become capable of full-motion color video, but it is easy to imagine that the definition of "powered off" would then include only those times during which the display wasn't actively being updated.)o
wake_count, which is the number of times that the
suspend blocker was the first to be acquired in the resume path. This is less than useful on some Android platforms; Arve is dissatisfied with it on Nexus One.Presumably, the userspace code collects similar statistics on application suspend-blocker activity, but that is out of the scope of this document, which focuses instead on kernel requirements. Given that the overhead of maintaining these statistics is quite low, it seems that it would be worthwhile to have them enabled in production systems, for example, in order to flag power-buggy applications that the user has naively downloaded.
o Some PM-driving applications use power-oblivious infrastructure
code. This means that a PM-driving application must have some way, whether explicit or implicit, to ensure that any power-oblivious infrastructure code is permitted to run when a PM-driving application needs it to run.o If no PM-driving or power-optimized application are indicating
a need for the system to remain operating, the system is permitted (even encouraged!) to suspend all execution, regardless of the
state of power-oblivious applications. (This requirement did
appear to be somewhat controversial, both in terms of what is meant by "runnable" and in terms of what constitutes "execution".)In Android, this is implemented by suspending even while PM-driving or power-optimized applications are active, -unless- a suspend blocker is held.
o Transition to system sleep state must be power-efficient.
In particular, methods based on repeated attempts to suspend are considered to be too inefficient to be useful.o Transition to system sleep state must occur very soon after
all PM-driving and power-optimized applications have indicated that they have no need for the system to remain operating. Quick transition is expecially important in cases where the wakeup was momentary, for example, when processing sporadic network input or processing widely spaced batches of audio output. For an example of the latter, MP3 playback allows 1-4 minute spacing between bursts of CPU activity).o Individual peripherals and CPUs must still use standard
power-conservation measures, for example, transitioning CPUs into low-power states on idle and powering down peripheral devices and hardware accelerators that have not been recently used.o The API that controls the system sleep state must be accessible
both from Android's Java replacement, from userland C code, and from kernel C code (both process level and irq code, but not NMI handlers).o The API that controls the system sleep state must operate
correctly on SMP systems of modest size. (My guess is that "modest" means up to four CPUs, maybe up to eight CPUs.)o Any QoS-based solution must take display and user-input
state into account. In other words, the QoS must be expressed as a function of the display and the user-input states.o Transitioning to extremely low-power sleep states requires saving
and restoring DRAM and/or cache SRAM state, which in itself consumes significant energy. The power savings must therefore be balanced against the energy consumed in the state transitions.o The current Android userspace API must be supported in order
to support existing device software. According to Brian Swetland:For Java/Dalvik apps, the wakelock API is pertty high level -- it talks to a service via RPC (Binder) that actually interacts with the kernel. Changing the basic kernel<->userspace interface (within reason) is not unthinkable. For example, Arve's
suspend_blockerpatch provides a device interface rather than the proc interface the older wakelock patches use. We'd have to make some userspace changes to support that but they're pretty low level and minor.In the current model, only a few processes need to specifically interact with the kernel (the power management service in the
system_server, possibly themedia_serverand the radio interface glue). A model where every process needs to have a bunch of instrumentation is not very desirable from our point of view. We definitely do need reasonable statistics in order to enable debugging and to enable reporting to endusers (through the Battery Usage UI) what's keeping the device awake.o Any mechanism that freezes some subset of the applications must
ensure that none of the frozen applications hold any user-level resources, such as pthread mutexes. The reason for this is that freezing an application that holds a shared pthread mutex will result in an application-level hang should some unfrozen process attempt to acquire that same pthread mutex. Note that although the current cgroup freezer ensures that frozen applications do not hold any kernel-level mutexes (at least assuming these mutexes are not wrongly held when returning to user-level execution), it currently does nothing to prevent freezing processes holding pthread mutexes. (There are some proposals to address this issue.)NICE-TO-HAVES
o It would be nice to be able to identify power-oblivious
applications that never were depended on by PM-driving applications. This particular class of power-oblivious applications could be shut down when the screen blanks even if some PM-driving application was preventing the system from powering down.There are two obstacles to meeting this requirement:
1. There must be a reliable way to identify such
applications. This should be doable, for example, the application might be tagged by its developer.2. There must be a reliable way to freeze them such
that no frozen application holds a resource that might be contended by a non-frozen application.Although the cgroup freezer does ensure that frozen tasks hold no kernel-level resources, it currently does nothing to ensure that no user-level resources are held. There are some alternative proposals, which might or might not be more successful:
a. Unfreeze this group periodically to ensure
that any such resource is eventually released, while keeping power consumption down to a dull roar.b. Perform the freeze at application level, where
it is possible to determine whether an application-level resource is held.o Any initialization of the API that controls the system power
state should be unconditional, so as to be free from failure. Such unconditional initialization reduces the intrusiveness of the Android patchset.APPARENT NON-REQUIREMENTS
o Transitioning to system sleep states need not be highly scalable,
as evidenced by the global locks. (If you believe that high scalability will in fact be required, please provide a use case. But please understand that I do know something about scalability trends, but also about uses for transistors beyond more cores.)That said, it should not be hard to provide a highly scalable implementation of suspend blockers, especially if large systems are allowed to take their time suspending themselves.
o Conserving power in the WiFi and cellular telephony networks.
At the moment, the focus is on increased battery life in the handheld device, perhaps even at the expense of additional power consumed by the externally powered WiFi and cell-telephony equipment.o Synchronizing wakeups of unrelated applications. This is of
course an important requirement for power savings overall, but seems to be left to other mechanisms (e.g., timer aggregation) by the Android folks. Although one could implement suspend blockers so as to aggregate timers after a sufficiently long suspension, there are problems with this approach:o There would be a "thundering herd" problem just after
resume completed as almost every timer in the system would expire simultaneously.o The applications would not necessarily stay aggregated
without some other mechanism helping out.SUGGESTED USAGE
These are constraints that the developer is expected to abide by, "for best results" and all that.
o When a PM-driving application is preventing the system from
shutting down, and is also waiting on a power-oblivious application, the PM-driving application should set a timeout to handle the possibility that the power-oblivious application might halt or otherwise fail.POWER-OPTIMIZED APPLICATIONS
A typical power-optimized application manually controls the power state of many separately controlled hardware subsystems to minimize power consumption. Such optimization normally requires an understanding of the hardware and of the full system's workload: strangely enough, concurrently running two separately power-optimized applications often does -not- result in a power-optimized system. Such optimization also requires knowledge of what the application will be doing in the future, so that needed hardware subsystems can be proactively powered up just when the application will need them. This is especially important when powering down cache SRAMS or banks of main memory, because such components take significant time (and consume significant energy) when preparing them to be powered off and when restoring their state after powering them on.
Consider an MP3 player as an example. Such a player will periodically read MP3-encoded data from flash memory, decode it (possibly using hardware acceleration), and place the resulting audio data into main memory. Different systems have different ways of getting the data from main memory to the audio output device, but let's assume that the audio output device consumes data at a predictable rate such that the software can use timers to schedule refilling of the device's output buffer. The timer duration will of course need to allow for the time required to power up the CPU and L2 cache. The timer can be allowed to happen too soon, albeit with a battery-lifetime penalty, but cannot be permitted to happen too late, as this will cause "skips" in the playback.
If MP3 playback is the only application running in the system, things are quite easy. We calculate when the audio output device will empty its buffer, allow a few milliseconds to power up the needed hardware, and set a timer accordingly. Because modern audio output devices have buffers that can handle roughly a second's worth of output, it is well worthwhile to spend the few milliseconds required to flush the cache SRAMS in order to put the system into an extremely low-power sleep state over the several hundred milliseconds of playback.
Now suppose that this device is also recording audio -- perhaps the device is being used to monitor an area for noise pollution, and the user is also using the device to play music via earphones. The audio input process will be the inverse of the audio output process: the microphone data will fill a data buffer, which must be collected into DRAM, then encoded (perhaps again via MP3) and stored into flash. It would be easy to create an optimal application for audio input, but running this optimal audio input program concurrently with the optimal audio playback program would not necessarily result in a power-optimized combination. This lack of optimality is due to the fact that the input and output programs would each burn power separately powering down and up. In contrast, an optimal solution would align the input and output programs' timers so that a single power-down/power-up event would cover both programs' processing. This would trade off optimal processing of each (for example, by draining the input buffer before it was full) in order to attain global optimality (by sharing power-down/power-up overhead).
There are a number of ways to achieve this:
1. Making the kernel group timers that occur at roughly the same
time, as has been discussed on this list many times. This can work in many cases, but can be problematic in the audio example, due to the presence of hard deadlines.2. Write the programs to be aware of each other, so that each
adjusts its behavior when the other is present. This seems to be current practice in the battery-powered embedded arena, but is quite complex, sensitive to both hardware configuration and software behavior, and requires that all combinations of programs be anticipated by the designer -- which can be a serious disadvantage given today's app stores.3. Use new features such as range timers, so that each program
can indicate both its preference and the degree of flexibility that it can tolerate. This also works in some cases, but as far as I know, current proposals do not allow the kernel to take power-consumption penalties into account.4. Provide "heartbeat" services that allow applications to
synchronize with each other. This seems most applicable for applications that run infrequently, such as email-checking and location-service applications.5. Use of hardware facilities that allow DMA to be scheduled across
time. This would allow the CPU to be turned on only for decode/encode operations. I am under the impression that this sort of time-based DMA hardware does exist in the embedded space and that it is actually used for this purpose.6. Your favorite solution here.
Whatever solution is chosen, the key point to keep in mind is that running power-optimized applications in combination does -not- result in optimal system behavior.
OTHER EXAMPLE APPLICATIONS
GPS application that silently displays position.
There is no point in this application consuming CPU cycles or in powering up the GPS hardware unless the display is active. Such an application could be handled by the Android suspend-blocker proposal. Of course, such an application could also periodically poll the display, shutting itself down if the display is inactive. In this case, it would also need to have some way to be reactivated when the display comes back on.
GPS application that alerts the user when a given location is reached.
This application should presumably run even when the display is powered down due to input timeout. The question of whether or not it should continue running when the device is powered off is an interesting one that would be likely to spark much spirited discussion. Regardless of the answer to this question, the GPS application would hopefully run very intermittently, adjusting the delay interval based on the device's velocity and distance from the location in question.
I don't know enough about GPS hardware to say under what circumstances the GPS hardware itself should be powered off. However, my experience indicates that it takes significant time for the GPS hardware to get a position fix after being powered on, so presumably this decision would also be based on device velocity and distance from the location in question.
Assuming that the application can run only intermittently, suspend blockers would work reasonably well for this use case. If the application needed to run continuously, battery life would be quite short regardless of the approach used.
MP3 playback.
This requires a PM-driving (and preferably a power-optimized) application. Because the CPU need only run intermittently, suspend blockers can handle this use case. Presumably switching the device off would halt playback.
Bouncing cows.
This can work with a power-oblivious application that is shut down whenever the display is powered off or the device is switched off, similar to the GPS application that silently displays position.
ACKNOWLEDGMENTS
Of course, just because I acknowledge their contributions does not necessarily mean that I think they agree with my assessment of the requirements behind suspend blockers. ;-)
Nevertheless, I am grateful for any and all feedback, whatever the form of that feedback might be. I am new to this area, and have much to learn.
Alan Stern
Anca Emanuel
Arjan van de Ven
Arve Hj?nnev?g
Brian Swetland
David Brownell
David Lang
Florian Mickler
James Bottomley
Kevin Granade
Mark Brown
Matt Helsley
Matthew Garrett
Mikael Abrahamsson
Olivier Galibert
Paul Menage
Pavel Machek
Rafael J. Wysocki
Richard Woodruff
Ted Ts'o
Quoted 18 lines · Mark Brown
Quoted 1 line · On Fri, Aug 06, 2010 at 04:35:59PM -0700, [email protected] wrote:
On Fri, 6 Aug 2010, Paul E. McKenney wrote:
Guys, please try to cut unneeded text from the quotes - it makes it much easier to find the new text.
Quoted 11 lines
Quoted 11 lines
Quoted 3 lines
Well, not really from the Linux point of view. It's not massively different to something like keeping an ethernet controller sufficiently alive to allow it to provide wake on LAN functionality while the system
The wake-on-LAN and the lights-out management systems are indeed interesting examples, and actually pretty good ones. The reason I excluded them is that they don't do any application processing -- their only purpose is the care and feeding of the system itself. In contrast, the embedded processors are able to do significant applications processing (e.g., play back music) while any CPUs are completely shut down and most of the memory is powered down as well.
Quoted 7 lines
This isn't a particularly meaningful distinction, things like the LoM systems on servers are generally at least as capable as things like the DSPs doing tasks like offloaded MP3 decode and often provide useful services in themselves (like system monitoring). It's really just semantics to treat them differently to something like a cellular modem - at a high level they're both just independant processors ticking away without the application processor.
I agree that a smartphone's cellular modem can be argued to be very similar to wake-on-LAN. The smartphone applications that seem to me to be very different from wake-on-LAN are things like audio playback, where the system is providing service to the user during the time that it is suspended.
Quoted 9 lines
Quoted 5 lines
one other significant issue is that on the PC, things like wake-on-LAN, lights out management cards, etc require nothing from the main system other than power. If they do something, they are sending the signal to the chipset, which then wakes the system up. they don't interact with the main processor/memory/etc at all.
I don't see that it makes much difference what gets kept alive - at the end of the day the point is that we're making a decision to keep bits of the system alive over suspend.
The distinction is whether or not the system is perceived to be actively doing something useful while it is suspended. Yes, this is subjective, but the distinction is still important.
Quoted 6 lines
Quoted 4 lines
So as I see it, we need to do one of two things.
1. change the suspend definition to allow for some things to not be suspended
This is essentially what's already happening.
The time-of-day clock is certainly a case in point here. ;-)
Thanx, Paul
Quoted 9 lines
Quoted 4 lines
2. change the sleep/low-power mode definition to have a more standardized way of turning things off, and extend it to allow clocks to be turned off as well (today we have things able to be turned off, drive spin-down for example, but per comments in this thread it's all one-off methods)
Currently things like clock trees are frequently managed orthogonaly to the system power state to at least some extent anyway - for example, perfectly normal wake events like button presses will often require clocks for things like debouncing.
Quoted 18 lines · Mark Brown
Quoted 1 line · On Fri, Aug 06, 2010 at 04:35:59PM -0700, [email protected] wrote:
On Fri, 6 Aug 2010, Paul E. McKenney wrote:
Guys, please try to cut unneeded text from the quotes - it makes it much easier to find the new text.
Quoted 11 lines
Quoted 11 lines
Quoted 3 lines
Well, not really from the Linux point of view. It's not massively different to something like keeping an ethernet controller sufficiently alive to allow it to provide wake on LAN functionality while the system
The wake-on-LAN and the lights-out management systems are indeed interesting examples, and actually pretty good ones. The reason I excluded them is that they don't do any application processing -- their only purpose is the care and feeding of the system itself. In contrast, the embedded processors are able to do significant applications processing (e.g., play back music) while any CPUs are completely shut down and most of the memory is powered down as well.
Quoted 7 lines
This isn't a particularly meaningful distinction, things like the LoM systems on servers are generally at least as capable as things like the DSPs doing tasks like offloaded MP3 decode and often provide useful services in themselves (like system monitoring). It's really just semantics to treat them differently to something like a cellular modem - at a high level they're both just independant processors ticking away without the application processor.
I agree that a smartphone's cellular modem can be argued to be very similar to wake-on-LAN. The smartphone applications that seem to me to be very different from wake-on-LAN are things like audio playback, where the system is providing service to the user during the time that it is suspended.
Quoted 9 lines
Quoted 5 lines
one other significant issue is that on the PC, things like wake-on-LAN, lights out management cards, etc require nothing from the main system other than power. If they do something, they are sending the signal to the chipset, which then wakes the system up. they don't interact with the main processor/memory/etc at all.
I don't see that it makes much difference what gets kept alive - at the end of the day the point is that we're making a decision to keep bits of the system alive over suspend.
The distinction is whether or not the system is perceived to be actively doing something useful while it is suspended. Yes, this is subjective, but the distinction is still important.
Quoted 6 lines
Quoted 4 lines
So as I see it, we need to do one of two things.
1. change the suspend definition to allow for some things to not be suspended
This is essentially what's already happening.
The time-of-day clock is certainly a case in point here. ;-)
Thanx, Paul
Quoted 9 lines
Quoted 4 lines
2. change the sleep/low-power mode definition to have a more standardized way of turning things off, and extend it to allow clocks to be turned off as well (today we have things able to be turned off, drive spin-down for example, but per comments in this thread it's all one-off methods)
Currently things like clock trees are frequently managed orthogonaly to the system power state to at least some extent anyway - for example, perfectly normal wake events like button presses will often require clocks for things like debouncing.
Quoted 15 lines · Mark Brown
Quoted 6 lines · On Fri, Aug 06, 2010 at 04:35:59PM -0700, [email protected] wrote:
On Fri, 6 Aug 2010, Paul E. McKenney wrote:
So as I see it, we need to do one of two things.
1. change the suspend definition to allow for some things to not be suspended
This is essentially what's already happening.
Quoted 4 lines
2. change the sleep/low-power mode definition to have a more standardized way of turning things off, and extend it to allow clocks to be turned off as well (today we have things able to be turned off, drive spin-down for example, but per comments in this thread it's all one-off methods)
Quoted 4 lines
Currently things like clock trees are frequently managed orthogonaly to the system power state to at least some extent anyway - for example, perfectly normal wake events like button presses will often require clocks for things like debouncing.
I recognise that #1 is essentially what Android is already doing.
I'm asking the question, "Is this what Linux should be doing?
Personally, I think that suspend should be treated much more like a low-power state and much less like hibernation than it currently is (I believe that Linus has also voiced this opinion). And I think that the situation with Android suspending while audio is playing between busts of CPU activity is a perfect example.
for the moment, forget the problem of other apps that may be running, and consider a system that's just running a media player.
the media player needs bursts of CPU to decode the media so that the output device can access it (via DMA or something like that)
the media player needs bursts of I/O to read the encoded program source from storage.
What we want to have happen in an ideal world is
when the storage isn't needed (between reads) the storage should shutdown to as low a power state as possible.
when the CPU isn't needed (between decoding bursts) the CPU and as much of the system as possible (potentially including some banks of RAM) should shutdown to as low a power state as possible.
today there are two ways of this happening, via the idle approach (on everything except Android), or via suspend (on Android)
Given that many platforms cannot go to into suspend while still playing audio, the idle approach is not going to be able to be eliminated (and in fact will be the most common approach to be used/deugged in terms of the types of platforms), it seems to me that there may be a significant amount of value in seeing if there is a way to change Android to use this approach as well instead of having two different systems competing to do the same job.
David Lang
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Paul E. McKenneyQuoted 13 lines · Paul E. McKenney
Quoted 11 lines · On Fri, Aug 06, 2010 at 04:59:54PM -0700, [email protected] wrote:
one other nice-to-have (or conflicting requirement, depending on your point of view), and I think one of the big things causing people to dislike wavelocks, is the desire to not have to modify applications to have them work with the infrastructure.
you sort of touch on this when you say that power oblivious applications need to be able to be intergrated, but it goes beyond what that statement implies.
with wavelocka, even power optimized applications need to be modified, or the system may halt them at any time.
Quoted 7 lines
Yes, I believe that Android would require most power-optimized application be modified to use wakelocks. But power-optimized applications require so much tweaking that the addition of suspend blockers (or whatever other power-control mechanism) is pretty much a non-issue by comparison.
And the number of power-optimized applications should be small, which, as you noted earlier, greatly eases the overall pain of modifying them.
except, power optimized applications aren't just written for android, they are also written for many other battery powered devices, many of which don't use wavelocks (and in fact, have no real reason to as they don't also have the untrusted apps running)
As such the pool of power optmized software will grow faster than the pool of wakelock enabled software.
Quoted 9 lines
Quoted 3 lines
one thing that has been very clear over the years is that if an API only exists on Linux, no matter how good it is, most application developers won't use it.
Many application developers do indeed value portability. But this in turn means that most application developers will not be writing power-optimized applications, because the process of power-optimization significantly degrades portability. Just as does the process of performance tuning, beyond a certain point.
just like performance tuning, power optimization only degrades portability beyond a certin point. A lot of power optimization is like a lot of performance tuning, find algorithms that you are using (usually frequent polling in the case of power optimizations) and change them. These changes are very frequently very portable.
In this case we are talking about changes that not only aren't portable across different Operating systems, they would not even be portable across Linux itself.
Quoted 8 lines
Of course, the reason that application developers value portability is that this is one way to gain large unit volumes. Another way to gain large unit volumes is to code for a very popular platform, which explains the large number of apps that run only on iPhone, Android, and Windows.
And in my experience, developers who have decided to commit to a single platform are usually not at all shy about exploiting special facilities of that platform to the fullest.
and they are not shy about ignoring other variations of a platform either (for example, Adobe has flash for i386 linux, but not amd64 linux, arm linux, powerpc linux, etc)
I see this as a bad thing to be discouraged.
Quoted 7 lines
Quoted 3 lines
In this case we are in an even worse situation, it's not only specific to Linux, it's specific to a subset of Linux systems, and not using it will cause no problems most of the time.
It seems to me that PM-driving and power-optimized applications are going to be highly platform specific, whether that platform be Linux or some other OS.
The thing is, they don't need to be.
Quoted 8 lines
Quoted 7 lines
now, android is betting that the apps are all developed specifically for the android from scratch, so having a different API is acceptable, even if it cuts them off from the rest of the *nix applications. For a phone this is not neccessarily an unreasonable stance, but as Android moves into the spaces where normal applications are in use (netbooks and tablets), this becomes a much shakier stance to take.
Quoted 6 lines
There certainly does seem to be a large and growing number of Android apps, so I might be reluctant to bet against them. And the Android guys appear to be making another bet as well -- that almost all applications will be power-oblivious. Their design handles this rather well, given that such applications need not worry about special power-control features.
there is also a growing population of nook applications, kindle applications (ok, in this category there are only two released, both in the last week, but the SDK has not hit public release yet ;-), maemo applications, OLPC applications, tom-tom applications, .....
unless all of these platforms are going to start using wavelocks there are going to be power optimized applications out there that don't use wavelocks.
Quoted 1 line
From this discussion, it looks to me like Android wants two key features
that they don't see a way to get today
1. the ability to decide to suspend while there are still some 'unimportant' apps running.
2. changes to idle/suspend so that they can get into a state of lower power consumption thatn any existing idle state (by being able to disable clocks), but still have some parts of the system powered (so that they are more awake than suspend)
If these two features were available, I think that the rest of what they are looking for could be built up without requireing other changes.
In addition to these key features, the fact that they use suspend much more frequently means that the race condition between deciding to freeze and wake events happening is far more likely to cause them problems, so improvements in this area are needed. I don't think that there is any fundamental opposition to these improvements, just questions on how best to do it without causing performance problems.
Today Android uses wakelocks to indicate that there is something 'important' running and trigger a suspend when nothing 'important' is running.
they have cusomized suspend to sometimes not shut everythng down.
My straw-man to address these is the following
1. create the ability to tag cgroups with power management values track their timers separatly
be able to set idle time before sleep per-group instead of system-wide other things in the future
eventually this could be things like preventing processes in
different cgroups from sharing userspace mutexes (or at least detecting when this is the case) to support being able to freeze one cgroup without affectng others.
2. modify the schedular/idle thread to be able to decide to go to a low-power state based on the cgroup information
In addition to checking this in the idle thread, optionally check
this at other times so that you can trigger low-power states even if not completely idle (possibly during the scheduler rebalancing check??)
3. modify the move to low-power modes to include disabling more components in the system (including clocks), in the extreme case this would be a full suspend.
This may include doing work to standardize power management for
devices more than it is to more readily be able to power down components.
this may include making an idle mode of 'stop all clocks except for
one alarm, until the alarm goes off, then advance the clocks to reflect the time passed'
This probably does require the conceptual change from the fairly
monolithic 'you are in this C state' approach to a more fine grained 'the CPU is in this C state, the video card is in that power management state, the audio is in this other state.....'
David Lang
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to [email protected]Quoted 7 lines · On Fri, Aug 6, 2010 at 4:59 PM, <[email protected]> wrote:
now, android is betting that the apps are all developed specifically for the android from scratch, so having a different API is acceptable, even if it cuts them off from the rest of the *nix applications. For a phone this is not neccessarily an unreasonable stance, but as Android moves into the spaces where normal applications are in use (netbooks and tablets), this becomes a much shakier stance to take.
"Normal" apps work reasonably well -- they get halted when the screen turns off, just like they do when my laptop suspends.
Wakelocks are useful for mobile-centric apps that you want to keep running in the background, wake up and do work when the device is "asleep", etc.
Brian
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to [email protected]Quoted 7 lines · On Fri, Aug 6, 2010 at 4:59 PM, <[email protected]> wrote:
now, android is betting that the apps are all developed specifically for the android from scratch, so having a different API is acceptable, even if it cuts them off from the rest of the *nix applications. For a phone this is not neccessarily an unreasonable stance, but as Android moves into the spaces where normal applications are in use (netbooks and tablets), this becomes a much shakier stance to take.
"Normal" apps work reasonably well -- they get halted when the screen turns off, just like they do when my laptop suspends.
Wakelocks are useful for mobile-centric apps that you want to keep running in the background, wake up and do work when the device is "asleep", etc.
Brian
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to [email protected]Quoted 2 lines · On Fri, 6 Aug 2010 [email protected] wrote:
From this discussion, it looks to me like Android wants two key features that they don't see a way to get today
I have largely kept out of this discussion, but this was so outrageous I had to say something.
Quoted 2 lines
1. the ability to decide to suspend while there are still some 'unimportant' apps running.
While this may be true in some literal sense, it certainly is not the best way to view the situation. Linux already has the ability to suspend (or to decide to suspend) whenever you want. What Android has added is the ability to suspend conditionally, based on whether or not some applications or drivers want to keep the system running.
Furthermore, this statement leaves out the primary purpose of
wakelocks: to avoid races between suspending and wakeup events. And it also ignores a very important distinction: the difference between drivers and applications. Wakelocks are used by both, but it has been shown that only the wakelocks used by drivers need to be implemented in the kernel -- the others can be implemented entirely in userspace.
All of these issues are addressed by Raphael's new wakeup_events code.
Quoted 4 lines
2. changes to idle/suspend so that they can get into a state of lower power consumption thatn any existing idle state (by being able to disable clocks), but still have some parts of the system powered (so that they are more awake than suspend)
This is nonsense. Nothing was changed. Instead, Android implemented system suspend on their platform in a way that would leave some devices running while the rest of the system powered down. There's nothing out of the ordinary about this. Platforms are free to implement system suspend in whatever way they deem most appropriate. On modern PCs, the most appropriate technique is to go into ACPI's S3 or S4 state. On embedded systems, the technique will vary from one platform to another.
Quoted 2 lines
If these two features were available, I think that the rest of what they are looking for could be built up without requireing other changes.
They already _are_ available. Admittedly, only since quite recently. (Rafael's new code was accepted during the 2.6.36 merge window.)
Quoted 6 lines
In addition to these key features, the fact that they use suspend much more frequently means that the race condition between deciding to freeze and wake events happening is far more likely to cause them problems, so improvements in this area are needed. I don't think that there is any fundamental opposition to these improvements, just questions on how best to do it without causing performance problems.
By now, I think most of these questions have been answered.
On a slightly different tack, I have noticed that email discussions concerning Android's wakelocks tend to evolve (I almost wrote "devolve") along one of two paths: Either they start talking about ways to integrate Android's goals into the mainline kernel, or else they start complaining about the fact that Android uses system suspend so aggressively and try to find ways to use deep-idle to achieve equivalent results. Although the second path generally ends up being much less productive than the first, it is the one that most discussions seem to end up taking. Large portions of _this_ thread have tended in that direction.
Alan Stern
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to [email protected]Quoted 2 lines · On Fri, 6 Aug 2010 [email protected] wrote:
From this discussion, it looks to me like Android wants two key features that they don't see a way to get today
I have largely kept out of this discussion, but this was so outrageous I had to say something.
Quoted 2 lines
1. the ability to decide to suspend while there are still some 'unimportant' apps running.
While this may be true in some literal sense, it certainly is not the best way to view the situation. Linux already has the ability to suspend (or to decide to suspend) whenever you want. What Android has added is the ability to suspend conditionally, based on whether or not some applications or drivers want to keep the system running.
Furthermore, this statement leaves out the primary purpose of
wakelocks: to avoid races between suspending and wakeup events. And it also ignores a very important distinction: the difference between drivers and applications. Wakelocks are used by both, but it has been shown that only the wakelocks used by drivers need to be implemented in the kernel -- the others can be implemented entirely in userspace.
All of these issues are addressed by Raphael's new wakeup_events code.
Quoted 4 lines
2. changes to idle/suspend so that they can get into a state of lower power consumption thatn any existing idle state (by being able to disable clocks), but still have some parts of the system powered (so that they are more awake than suspend)
This is nonsense. Nothing was changed. Instead, Android implemented system suspend on their platform in a way that would leave some devices running while the rest of the system powered down. There's nothing out of the ordinary about this. Platforms are free to implement system suspend in whatever way they deem most appropriate. On modern PCs, the most appropriate technique is to go into ACPI's S3 or S4 state. On embedded systems, the technique will vary from one platform to another.
Quoted 2 lines
If these two features were available, I think that the rest of what they are looking for could be built up without requireing other changes.
They already _are_ available. Admittedly, only since quite recently. (Rafael's new code was accepted during the 2.6.36 merge window.)
Quoted 6 lines
In addition to these key features, the fact that they use suspend much more frequently means that the race condition between deciding to freeze and wake events happening is far more likely to cause them problems, so improvements in this area are needed. I don't think that there is any fundamental opposition to these improvements, just questions on how best to do it without causing performance problems.
By now, I think most of these questions have been answered.
On a slightly different tack, I have noticed that email discussions concerning Android's wakelocks tend to evolve (I almost wrote "devolve") along one of two paths: Either they start talking about ways to integrate Android's goals into the mainline kernel, or else they start complaining about the fact that Android uses system suspend so aggressively and try to find ways to use deep-idle to achieve equivalent results. Although the second path generally ends up being much less productive than the first, it is the one that most discussions seem to end up taking. Large portions of _this_ thread have tended in that direction.
Alan Stern
Re: Attempted summary of suspend-blockers LKML thread, take three
Quoted 7 lines · Alan Stern
Quoted 2 lines · On Fri, 6 Aug 2010 [email protected] wrote:
From this discussion, it looks to me like Android wants two key features that they don't see a way to get today
I have largely kept out of this discussion, but this was so outrageous I had to say something.
sorry for misunderstanding things, thank you for speaking up to correct the misunderstanding.
Quoted 8 lines
Quoted 2 lines
1. the ability to decide to suspend while there are still some 'unimportant' apps running.
While this may be true in some literal sense, it certainly is not the best way to view the situation. Linux already has the ability to suspend (or to decide to suspend) whenever you want. What Android has added is the ability to suspend conditionally, based on whether or not some applications or drivers want to keep the system running.
Ok, aside from possibly drivers, what' stopping this from being done on a valilla system today?
Quoted 6 lines
Furthermore, this statement leaves out the primary purpose of
wakelocks: to avoid races between suspending and wakeup events. And it also ignores a very important distinction: the difference between drivers and applications. Wakelocks are used by both, but it has been shown that only the wakelocks used by drivers need to be implemented in the kernel -- the others can be implemented entirely in userspace.
Ok, this is the first I've heard in this discussion that wakelocks would not be available to userspace. In fact it was explicitly stated that userspace applications called IOCTLs to get/release the wakelock.
many of my objections (voiced in another thread) about Android specific features are not relavent if the wakelock in userspace is just part of that application framework and not tied into the kernel.
Quoted 1 line
All of these issues are addressed by Raphael's new
wakeup_eventscode.
Ok, then why is there still discussion about wakelocks at all if Raphael has implemnetd the needed kernel functionality and userspace is Android SDK specific? the heated replys from some people about what Android needs (from people who I assumed were Android maintainers due to the way they were answering questions) sure didn't sound like this was a solved problem.
Quoted 5 lines
Quoted 4 lines
2. changes to idle/suspend so that they can get into a state of lower power consumption thatn any existing idle state (by being able to disable clocks), but still have some parts of the system powered (so that they are more awake than suspend)
Quoted 7 lines
This is nonsense. Nothing was changed. Instead, Android implemented system suspend on their platform in a way that would leave some devices running while the rest of the system powered down. There's nothing out of the ordinary about this. Platforms are free to implement system suspend in whatever way they deem most appropriate. On modern PCs, the most appropriate technique is to go into ACPI's S3 or S4 state. On embedded systems, the technique will vary from one platform to another.
the difference is that not all suspends on Android are the same, sometimes when you suspend you power down the audio components, sometimes you don't.
As far as I am aware (and please correct meif I am mistaken), this is significantly different from suspend elsewhere where suspend always takes you to the same state.
Quoted 5 lines
Quoted 2 lines
If these two features were available, I think that the rest of what they are looking for could be built up without requireing other changes.
They already _are_ available. Admittedly, only since quite recently. (Rafael's new code was accepted during the 2.6.36 merge window.)
Do Brian and Arve agree that this solves their problem?
Quoted 9 lines
Quoted 6 lines
In addition to these key features, the fact that they use suspend much more frequently means that the race condition between deciding to freeze and wake events happening is far more likely to cause them problems, so improvements in this area are needed. I don't think that there is any fundamental opposition to these improvements, just questions on how best to do it without causing performance problems.
By now, I think most of these questions have been answered.
Quoted 10 lines
On a slightly different tack, I have noticed that email discussions concerning Android's wakelocks tend to evolve (I almost wrote "devolve") along one of two paths: Either they start talking about ways to integrate Android's goals into the mainline kernel, or else they start complaining about the fact that Android uses system suspend so aggressively and try to find ways to use deep-idle to achieve equivalent results. Although the second path generally ends up being much less productive than the first, it is the one that most discussions seem to end up taking. Large portions of _this_ thread have tended in that direction.
to be fair, there have been numerous complaints about suspend being separate from deep sleep long before Android. Linus' blow-up that resulted in Hibernation and Suspend being separated from each other is a case in point. He was making the point that there shouldn't be a difference between the deepest sleep and suspend.
As deep sleep gains the ability to use even less power and as suspend gains the ability to leave things on sometimes, the difference between them is dissapearing. I wouldn't be at all surprised to see them start overlaping soon. So it's not that I think Android should use deep sleeps instead of suspend, but rather that suspend should just be the deepest sleep, one mechanism instead of two.
David Lang
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Brian SwetlandQuoted 9 lines · Brian Swetland
Quoted 7 lines · On Fri, Aug 6, 2010 at 4:59 PM, <[email protected]> wrote:
now, android is betting that the apps are all developed specifically for the android from scratch, so having a different API is acceptable, even if it cuts them off from the rest of the *nix applications. For a phone this is not neccessarily an unreasonable stance, but as Android moves into the spaces where normal applications are in use (netbooks and tablets), this becomes a much shakier stance to take.
Quoted 6 lines
"Normal" apps work reasonably well -- they get halted when the screen turns off, just like they do when my laptop suspends.
Wakelocks are useful for mobile-centric apps that you want to keep running in the background, wake up and do work when the device is "asleep", etc.
that description sounds far more like normal sleep power management that suspending. especially since they want to set timers to wake the system up and the defining characteristic of suspend (according to this thread) is that timers don't fire while suspended.
as I am seeing it, there are two reasons why this don't "just work"
1. sleeping can't currently save as much power as suspending
2. the current logic for deciding to sleep can't ignore the other apps on the system.
David Lang
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_countwill 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_awakeandpm_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
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_countwill 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_awakeandpm_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
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to [email protected]Quoted 9 lines · On Fri, Aug 06, 2010 at 08:14:09PM -0700, [email protected] wrote:
that description sounds far more like normal sleep power management that suspending. especially since they want to set timers to wake the system up and the defining characteristic of suspend (according to this thread) is that timers don't fire while suspended.
as I am seeing it, there are two reasons why this don't "just work"
1. sleeping can't currently save as much power as suspending
No, I don't think that's the case at all. The key thing here is that *most* applications don't need to be modified to use suspend locks, because even though they might be in an event loop, when the user user turns off the display, the user generally doesn't want it doing things on their behalf.
Again, take for example the Mac Book, since Apple has gotten this right for most users' use cases. When you close the lid, you even if the application is under the misguided belief that it should be checking every five seconds to see whether or not the web page has reloaded --- actually, that's not what you want. You probably want the application to be forcibly put to sleep. So the whole point of the suspend blocker design is that you don't have to modify most applications; they just simply get put to sleep when you close the MacBook lid, or, in the case of the Android device, you push the button that turns off the screen.
So the reason why this doesn't work is that power management for small mobile devices *is* different from power management for laptops and data center servers, and if you want a rich application ecosystem, it's best if you don't require them to be specially tuned to use the absolute minimum power. (And that means waking up every 30 seconds might be too much; as Brian and Arve have pointed out, with the G1 in airplane mode, the CPU might be waking up once every half hour or more --- and at that rate, powertop will be waking up the CPU more than Android system would be doing so.)
So the real key here is to take most applications, which may be written using techniques that might be considered well written from a laptop point of view, but not for a cell phone, and not require modifications. Even though the application writer might think it's doing well by waking up every 15 seconds, if the laptop lid is down, or if the screen is off, for **most** applications, it should be forcibly put to sleep.
It's only the rare applications that should really be allowed to run while screen is off. And it's only those applications that need modifications to use suspend blocker. From your earlier comments, it seems that this is the key point which you are missing. (No doubt, some of these applications that do need to know about suspend blockers are important ones; ones that make sure the battery isn't about to blow up, or ones which silently wake up every 10-15 minutes to pull down fresh mail for you from your mail server. But those applications are the exception, not the rule.)
Best regards,
- Ted
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to [email protected]Quoted 9 lines · On Fri, Aug 06, 2010 at 08:14:09PM -0700, [email protected] wrote:
that description sounds far more like normal sleep power management that suspending. especially since they want to set timers to wake the system up and the defining characteristic of suspend (according to this thread) is that timers don't fire while suspended.
as I am seeing it, there are two reasons why this don't "just work"
1. sleeping can't currently save as much power as suspending
No, I don't think that's the case at all. The key thing here is that *most* applications don't need to be modified to use suspend locks, because even though they might be in an event loop, when the user user turns off the display, the user generally doesn't want it doing things on their behalf.
Again, take for example the Mac Book, since Apple has gotten this right for most users' use cases. When you close the lid, you even if the application is under the misguided belief that it should be checking every five seconds to see whether or not the web page has reloaded --- actually, that's not what you want. You probably want the application to be forcibly put to sleep. So the whole point of the suspend blocker design is that you don't have to modify most applications; they just simply get put to sleep when you close the MacBook lid, or, in the case of the Android device, you push the button that turns off the screen.
So the reason why this doesn't work is that power management for small mobile devices *is* different from power management for laptops and data center servers, and if you want a rich application ecosystem, it's best if you don't require them to be specially tuned to use the absolute minimum power. (And that means waking up every 30 seconds might be too much; as Brian and Arve have pointed out, with the G1 in airplane mode, the CPU might be waking up once every half hour or more --- and at that rate, powertop will be waking up the CPU more than Android system would be doing so.)
So the real key here is to take most applications, which may be written using techniques that might be considered well written from a laptop point of view, but not for a cell phone, and not require modifications. Even though the application writer might think it's doing well by waking up every 15 seconds, if the laptop lid is down, or if the screen is off, for **most** applications, it should be forcibly put to sleep.
It's only the rare applications that should really be allowed to run while screen is off. And it's only those applications that need modifications to use suspend blocker. From your earlier comments, it seems that this is the key point which you are missing. (No doubt, some of these applications that do need to know about suspend blockers are important ones; ones that make sure the battery isn't about to blow up, or ones which silently wake up every 10-15 minutes to pull down fresh mail for you from your mail server. But those applications are the exception, not the rule.)
Best regards,
- Ted
Quoted 4 lines · On Fri, Aug 06, 2010 at 06:00:34PM -0700, [email protected] wrote:
today there are two ways of this happening, via the idle approach (on everything except Android), or via suspend (on Android)
Most other devices use a lot more power at idle; in some cases it's because the hardware just isn't as power optimized (why bother, when you have 94,000 mWh of power at your disposal with a 6 cell laptop battery, as opposed to the 800-1000 mWh that you might have on a cell phone battery). In other cases, it's because the kernel and the low-level software stack (never mind the applications) are waking up the CPU too darned often --- in other words, idle simply isn't idle enough.
So you may want to consider whether part of the problem is that general purpose Linux systems need a radical redesign to get power utilization down to those sorts of levels --- where the CPU might only be waking up once every half-hour or so, and then only do actual useful work.
Can you get there by assuming that every single application is competently written? In an idle approach, you have to. That way lies Maemo, where installing just one bad application will cut your battery life time by a factor of 2-3. You could try stopping processes by using kill -STOP, but this at that point, you've moved into Android strategy of "suspend". And the only question is what is the most efficient way to allow the system to run when there is true work that needs to be done, and how to avoid deadlocks by stopping processes that might be holding user space locks --- and to administer when and how to suspend the processes.
Sure, you could do someting amazing complicated using cgroups, and user space processes that have to wake up the CPU every 30 seconds to see if it's safe to suspend the system --- but why not just use the system which is being used by 200,000 new phones every day? It's simple and it works. And unlike Maemo, untrustworthy applications don't end up chewing up your battery lifetime.
- Ted
Quoted 4 lines · On Fri, Aug 06, 2010 at 06:00:34PM -0700, [email protected] wrote:
today there are two ways of this happening, via the idle approach (on everything except Android), or via suspend (on Android)
Most other devices use a lot more power at idle; in some cases it's because the hardware just isn't as power optimized (why bother, when you have 94,000 mWh of power at your disposal with a 6 cell laptop battery, as opposed to the 800-1000 mWh that you might have on a cell phone battery). In other cases, it's because the kernel and the low-level software stack (never mind the applications) are waking up the CPU too darned often --- in other words, idle simply isn't idle enough.
So you may want to consider whether part of the problem is that general purpose Linux systems need a radical redesign to get power utilization down to those sorts of levels --- where the CPU might only be waking up once every half-hour or so, and then only do actual useful work.
Can you get there by assuming that every single application is competently written? In an idle approach, you have to. That way lies Maemo, where installing just one bad application will cut your battery life time by a factor of 2-3. You could try stopping processes by using kill -STOP, but this at that point, you've moved into Android strategy of "suspend". And the only question is what is the most efficient way to allow the system to run when there is true work that needs to be done, and how to avoid deadlocks by stopping processes that might be holding user space locks --- and to administer when and how to suspend the processes.
Sure, you could do someting amazing complicated using cgroups, and user space processes that have to wake up the CPU every 30 seconds to see if it's safe to suspend the system --- but why not just use the system which is being used by 200,000 new phones every day? It's simple and it works. And unlike Maemo, untrustworthy applications don't end up chewing up your battery lifetime.
- Ted
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_countwill 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_wakenesting (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_awakeandpm_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_awaketo 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
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_countwill 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_wakenesting (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_awakeandpm_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_awaketo 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
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 andpm_wakeup_eventdoesn'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_eventfor _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()orpm_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
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 andpm_wakeup_eventdoesn'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_eventfor _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()orpm_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
Quoted 4 lines · On Saturday, August 07, 2010, [email protected] wrote:
Quoted 2 lines · Mark Brown
Quoted 1 line · On Fri, Aug 06, 2010 at 04:35:59PM -0700, [email protected] wrote:
On Fri, 6 Aug 2010, Paul E. McKenney wrote:
...
Quoted 8 lines
What we want to have happen in an ideal world is
when the storage isn't needed (between reads) the storage should shutdown to as low a power state as possible.
when the CPU isn't needed (between decoding bursts) the CPU and as much of the system as possible (potentially including some banks of RAM) should shutdown to as low a power state as possible.
Unfortunately, the criteria for "not being needed" are not really straightforward and one of the wakelocks' roles is to work around this issue.
Quoted 10 lines
today there are two ways of this happening, via the idle approach (on everything except Android), or via suspend (on Android)
Given that many platforms cannot go to into suspend while still playing audio, the idle approach is not going to be able to be eliminated (and in fact will be the most common approach to be used/deugged in terms of the types of platforms), it seems to me that there may be a significant amount of value in seeing if there is a way to change Android to use this approach as well instead of having two different systems competing to do the same job.
There is a fundamental obstacle to that, though. Namely, the Android developers say that the idle-based approach doesn't lead to sufficient energy savings due to periodic timers and "polling applications". Technically that boils down to the interrupt sources that remain active in the idle-based case and that are shut down during suspend. If you found a way to deactivate all of them from the idle context in a non-racy fashion, that would probably satisfy the Android's needs too.
Thanks,
Rafael
Quoted 4 lines · On Saturday, August 07, 2010, [email protected] wrote:
Quoted 2 lines · Mark Brown
Quoted 1 line · On Fri, Aug 06, 2010 at 04:35:59PM -0700, [email protected] wrote:
On Fri, 6 Aug 2010, Paul E. McKenney wrote:
...
Quoted 8 lines
What we want to have happen in an ideal world is
when the storage isn't needed (between reads) the storage should shutdown to as low a power state as possible.
when the CPU isn't needed (between decoding bursts) the CPU and as much of the system as possible (potentially including some banks of RAM) should shutdown to as low a power state as possible.
Unfortunately, the criteria for "not being needed" are not really straightforward and one of the wakelocks' roles is to work around this issue.
Quoted 10 lines
today there are two ways of this happening, via the idle approach (on everything except Android), or via suspend (on Android)
Given that many platforms cannot go to into suspend while still playing audio, the idle approach is not going to be able to be eliminated (and in fact will be the most common approach to be used/deugged in terms of the types of platforms), it seems to me that there may be a significant amount of value in seeing if there is a way to change Android to use this approach as well instead of having two different systems competing to do the same job.
There is a fundamental obstacle to that, though. Namely, the Android developers say that the idle-based approach doesn't lead to sufficient energy savings due to periodic timers and "polling applications". Technically that boils down to the interrupt sources that remain active in the idle-based case and that are shut down during suspend. If you found a way to deactivate all of them from the idle context in a non-racy fashion, that would probably satisfy the Android's needs too.
Thanks,
Rafael
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Ted Ts'oQuoted 17 lines · Ted Ts'o
Quoted 9 lines · On Fri, Aug 06, 2010 at 08:14:09PM -0700, [email protected] wrote:
that description sounds far more like normal sleep power management that suspending. especially since they want to set timers to wake the system up and the defining characteristic of suspend (according to this thread) is that timers don't fire while suspended.
as I am seeing it, there are two reasons why this don't "just work"
1. sleeping can't currently save as much power as suspending
No, I don't think that's the case at all. The key thing here is that *most* applications don't need to be modified to use suspend locks, because even though they might be in an event loop, when the user user turns off the display, the user generally doesn't want it doing things on their behalf.
Quoted 10 lines
Again, take for example the Mac Book, since Apple has gotten this right for most users' use cases. When you close the lid, you even if the application is under the misguided belief that it should be checking every five seconds to see whether or not the web page has reloaded --- actually, that's not what you want. You probably want the application to be forcibly put to sleep. So the whole point of the suspend blocker design is that you don't have to modify most applications; they just simply get put to sleep when you close the MacBook lid, or, in the case of the Android device, you push the button that turns off the screen.
But in principle that need not mean suspending the entire system. To get applications out of the way, you need to freeze user space. However, that's not sufficient, because in addition to that you need to prevent deactivate the majority of interrupt sources to avoid waking up the CPU (from C-states) too often.
Thanks,
Rafael
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Ted Ts'oQuoted 17 lines · Ted Ts'o
Quoted 9 lines · On Fri, Aug 06, 2010 at 08:14:09PM -0700, [email protected] wrote:
that description sounds far more like normal sleep power management that suspending. especially since they want to set timers to wake the system up and the defining characteristic of suspend (according to this thread) is that timers don't fire while suspended.
as I am seeing it, there are two reasons why this don't "just work"
1. sleeping can't currently save as much power as suspending
No, I don't think that's the case at all. The key thing here is that *most* applications don't need to be modified to use suspend locks, because even though they might be in an event loop, when the user user turns off the display, the user generally doesn't want it doing things on their behalf.
Quoted 10 lines
Again, take for example the Mac Book, since Apple has gotten this right for most users' use cases. When you close the lid, you even if the application is under the misguided belief that it should be checking every five seconds to see whether or not the web page has reloaded --- actually, that's not what you want. You probably want the application to be forcibly put to sleep. So the whole point of the suspend blocker design is that you don't have to modify most applications; they just simply get put to sleep when you close the MacBook lid, or, in the case of the Android device, you push the button that turns off the screen.
But in principle that need not mean suspending the entire system. To get applications out of the way, you need to freeze user space. However, that's not sufficient, because in addition to that you need to prevent deactivate the majority of interrupt sources to avoid waking up the CPU (from C-states) too often.
Thanks,
Rafael
Re: Attempted summary of suspend-blockers LKML thread, take three
Quoted 29 lines · Rafael J. Wysocki
Quoted 17 lines · Ted Ts'o
Quoted 9 lines · On Fri, Aug 06, 2010 at 08:14:09PM -0700, [email protected] wrote:
that description sounds far more like normal sleep power management that suspending. especially since they want to set timers to wake the system up and the defining characteristic of suspend (according to this thread) is that timers don't fire while suspended.
as I am seeing it, there are two reasons why this don't "just work"
1. sleeping can't currently save as much power as suspending
No, I don't think that's the case at all. The key thing here is that *most* applications don't need to be modified to use suspend locks, because even though they might be in an event loop, when the user user turns off the display, the user generally doesn't want it doing things on their behalf.
Quoted 10 lines
Again, take for example the Mac Book, since Apple has gotten this right for most users' use cases. When you close the lid, you even if the application is under the misguided belief that it should be checking every five seconds to see whether or not the web page has reloaded --- actually, that's not what you want. You probably want the application to be forcibly put to sleep. So the whole point of the suspend blocker design is that you don't have to modify most applications; they just simply get put to sleep when you close the MacBook lid, or, in the case of the Android device, you push the button that turns off the screen.
Quoted 5 lines
But in principle that need not mean suspending the entire system. To get applications out of the way, you need to freeze user space. However, that's not sufficient, because in addition to that you need to prevent deactivate the majority of interrupt sources to avoid waking up the CPU (from C-states) too often.
s/prevent deactivate/deactivate/
Rafael
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Rafael J. WysockiQuoted 29 lines · Rafael J. Wysocki
Quoted 17 lines · Ted Ts'o
Quoted 9 lines · On Fri, Aug 06, 2010 at 08:14:09PM -0700, [email protected] wrote:
that description sounds far more like normal sleep power management that suspending. especially since they want to set timers to wake the system up and the defining characteristic of suspend (according to this thread) is that timers don't fire while suspended.
as I am seeing it, there are two reasons why this don't "just work"
1. sleeping can't currently save as much power as suspending
No, I don't think that's the case at all. The key thing here is that *most* applications don't need to be modified to use suspend locks, because even though they might be in an event loop, when the user user turns off the display, the user generally doesn't want it doing things on their behalf.
Quoted 10 lines
Again, take for example the Mac Book, since Apple has gotten this right for most users' use cases. When you close the lid, you even if the application is under the misguided belief that it should be checking every five seconds to see whether or not the web page has reloaded --- actually, that's not what you want. You probably want the application to be forcibly put to sleep. So the whole point of the suspend blocker design is that you don't have to modify most applications; they just simply get put to sleep when you close the MacBook lid, or, in the case of the Android device, you push the button that turns off the screen.
Quoted 5 lines
But in principle that need not mean suspending the entire system. To get applications out of the way, you need to freeze user space. However, that's not sufficient, because in addition to that you need to prevent deactivate the majority of interrupt sources to avoid waking up the CPU (from C-states) too often.
s/prevent deactivate/deactivate/
Rafael
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Ted Ts'oQuoted 17 lines · Ted Ts'o
Quoted 9 lines · On Fri, Aug 06, 2010 at 08:14:09PM -0700, [email protected] wrote:
that description sounds far more like normal sleep power management that suspending. especially since they want to set timers to wake the system up and the defining characteristic of suspend (according to this thread) is that timers don't fire while suspended.
as I am seeing it, there are two reasons why this don't "just work"
1. sleeping can't currently save as much power as suspending
No, I don't think that's the case at all. The key thing here is that *most* applications don't need to be modified to use suspend locks, because even though they might be in an event loop, when the user user turns off the display, the user generally doesn't want it doing things on their behalf.
Quoted 10 lines
Again, take for example the Mac Book, since Apple has gotten this right for most users' use cases. When you close the lid, you even if the application is under the misguided belief that it should be checking every five seconds to see whether or not the web page has reloaded --- actually, that's not what you want. You probably want the application to be forcibly put to sleep. So the whole point of the suspend blocker design is that you don't have to modify most applications; they just simply get put to sleep when you close the MacBook lid, or, in the case of the Android device, you push the button that turns off the screen.
this doesn't require wakelocks or anything else new. all it takes is setting the policy that you don't want anything to run when the lid is closed and a switch to detect the lid being closed. Laptops have been doing this for years.
Quoted 9 lines
So the reason why this doesn't work is that power management for small mobile devices *is* different from power management for laptops and data center servers, and if you want a rich application ecosystem, it's best if you don't require them to be specially tuned to use the absolute minimum power. (And that means waking up every 30 seconds might be too much; as Brian and Arve have pointed out, with the G1 in airplane mode, the CPU might be waking up once every half hour or more --- and at that rate, powertop will be waking up the CPU more than Android system would be doing so.)
note that nothing that I have proposed would wake up a sleeping system. the 'every several seconds' thing that I proposed was that on a system that's fully awake, busy and doesn't want to sleep, there would be a context switch periodically by a privilaged process so that the system would not end up deciding it was idle and halt everything. Now that I think about this more, it's not needed if you want to override this to keep everything running for a significant amount of time, just change the power saving mode from "sleep if a privilaged task isn't running" to "disable suspend". This can be done today by changing the right sysfs value. normal privilaged processes would never need to do this, only gatekeeper daemons that want to let unprivilaged processes run even if no privilaged processes want to run would need to do this (i.e. in the current system, whatever process controls the screen would probably be right)
Quoted 8 lines
So the real key here is to take most applications, which may be written using techniques that might be considered well written from a laptop point of view, but not for a cell phone, and not require modifications. Even though the application writer might think it's doing well by waking up every 15 seconds, if the laptop lid is down, or if the screen is off, for **most** applications, it should be forcibly put to sleep.
Quoted 9 lines
It's only the rare applications that should really be allowed to run while screen is off. And it's only those applications that need modifications to use suspend blocker. From your earlier comments, it seems that this is the key point which you are missing. (No doubt, some of these applications that do need to know about suspend blockers are important ones; ones that make sure the battery isn't about to blow up, or ones which silently wake up every 10-15 minutes to pull down fresh mail for you from your mail server. But those applications are the exception, not the rule.)
the question is what it takes to make an application privilaged like this.
what I proposed was to make it possible for the user/admin to select what applications are allowed to keep the system awake.
wakelocks require that the application developer decide that they want to keep the system awake as well as the user/admin
take your example of a mail client waking up every 15 min.
with Android it needs to be privilaged to grab the wakelock while fetching the mail, it also needs to use a privilaged API to set the wakeups to wake it up at those times.
with what I proposed all you need to do is to tag the application as power privilaged and then if the application sleeps for 15 min between doing thing the system will wake up every 15 min, work for a short time, then go back to sleep.
if you want to put everything to sleep when the screen blanks, that's trivial to do.
the fun starts when you want to say that there are some things you don't want to put to sleep.
do you let some processes run while halting others?
in which case how do you prevent deadlocks?
on the other hand, sleeping again is simple, you sleep when there
is nothing more to run
or do you let wasteful processes run while you are awake?
this avoids deadlocks, but how do you decide when to sleep again?
Android approaches this by requiring that any program that a user may want to keep running must be modified to use wakelocks.
My suggestion was that the system ignore other processes when deciding if the system is idle enough to put to sleep.
Yes the Android approach works reasonably well on the phones where everything must currently be custom developed anyway (due to screen and UI constraints), but as Android starts getting used on laptops and other larger devices is that really still the right approach? or would it be better to have something that could use standard software in the privilaged mode?
to use your example of a mail client, why should someone not be able to use fetchmail to get their mail instead of requiring that fetchmail be modified to use wavelocks (or a substatute written)?
the theoretical best approach would probably look nothing like either of these. Instead it would probably either
forbid privilaged processes from having blocking dependancies on unprivilaged processes (you can then just halt the unprivilaged processes when you blank the screen and let idle sleep deal with the privilged processes)
or
use something like priority inheritance through userspace so that if a privilaged process blocks on something where it's waiting for an unprivilaged process, that unprivilaged process gets woken up and allowed to run until it unblocks the privilaged process.
both of these have been deemed too hard
David Lang
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Ted Ts'oQuoted 17 lines · Ted Ts'o
Quoted 9 lines · On Fri, Aug 06, 2010 at 08:14:09PM -0700, [email protected] wrote:
that description sounds far more like normal sleep power management that suspending. especially since they want to set timers to wake the system up and the defining characteristic of suspend (according to this thread) is that timers don't fire while suspended.
as I am seeing it, there are two reasons why this don't "just work"
1. sleeping can't currently save as much power as suspending
No, I don't think that's the case at all. The key thing here is that *most* applications don't need to be modified to use suspend locks, because even though they might be in an event loop, when the user user turns off the display, the user generally doesn't want it doing things on their behalf.
Quoted 10 lines
Again, take for example the Mac Book, since Apple has gotten this right for most users' use cases. When you close the lid, you even if the application is under the misguided belief that it should be checking every five seconds to see whether or not the web page has reloaded --- actually, that's not what you want. You probably want the application to be forcibly put to sleep. So the whole point of the suspend blocker design is that you don't have to modify most applications; they just simply get put to sleep when you close the MacBook lid, or, in the case of the Android device, you push the button that turns off the screen.
this doesn't require wakelocks or anything else new. all it takes is setting the policy that you don't want anything to run when the lid is closed and a switch to detect the lid being closed. Laptops have been doing this for years.
Quoted 9 lines
So the reason why this doesn't work is that power management for small mobile devices *is* different from power management for laptops and data center servers, and if you want a rich application ecosystem, it's best if you don't require them to be specially tuned to use the absolute minimum power. (And that means waking up every 30 seconds might be too much; as Brian and Arve have pointed out, with the G1 in airplane mode, the CPU might be waking up once every half hour or more --- and at that rate, powertop will be waking up the CPU more than Android system would be doing so.)
note that nothing that I have proposed would wake up a sleeping system. the 'every several seconds' thing that I proposed was that on a system that's fully awake, busy and doesn't want to sleep, there would be a context switch periodically by a privilaged process so that the system would not end up deciding it was idle and halt everything. Now that I think about this more, it's not needed if you want to override this to keep everything running for a significant amount of time, just change the power saving mode from "sleep if a privilaged task isn't running" to "disable suspend". This can be done today by changing the right sysfs value. normal privilaged processes would never need to do this, only gatekeeper daemons that want to let unprivilaged processes run even if no privilaged processes want to run would need to do this (i.e. in the current system, whatever process controls the screen would probably be right)
Quoted 8 lines
So the real key here is to take most applications, which may be written using techniques that might be considered well written from a laptop point of view, but not for a cell phone, and not require modifications. Even though the application writer might think it's doing well by waking up every 15 seconds, if the laptop lid is down, or if the screen is off, for **most** applications, it should be forcibly put to sleep.
Quoted 9 lines
It's only the rare applications that should really be allowed to run while screen is off. And it's only those applications that need modifications to use suspend blocker. From your earlier comments, it seems that this is the key point which you are missing. (No doubt, some of these applications that do need to know about suspend blockers are important ones; ones that make sure the battery isn't about to blow up, or ones which silently wake up every 10-15 minutes to pull down fresh mail for you from your mail server. But those applications are the exception, not the rule.)
the question is what it takes to make an application privilaged like this.
what I proposed was to make it possible for the user/admin to select what applications are allowed to keep the system awake.
wakelocks require that the application developer decide that they want to keep the system awake as well as the user/admin
take your example of a mail client waking up every 15 min.
with Android it needs to be privilaged to grab the wakelock while fetching the mail, it also needs to use a privilaged API to set the wakeups to wake it up at those times.
with what I proposed all you need to do is to tag the application as power privilaged and then if the application sleeps for 15 min between doing thing the system will wake up every 15 min, work for a short time, then go back to sleep.
if you want to put everything to sleep when the screen blanks, that's trivial to do.
the fun starts when you want to say that there are some things you don't want to put to sleep.
do you let some processes run while halting others?
in which case how do you prevent deadlocks?
on the other hand, sleeping again is simple, you sleep when there
is nothing more to run
or do you let wasteful processes run while you are awake?
this avoids deadlocks, but how do you decide when to sleep again?
Android approaches this by requiring that any program that a user may want to keep running must be modified to use wakelocks.
My suggestion was that the system ignore other processes when deciding if the system is idle enough to put to sleep.
Yes the Android approach works reasonably well on the phones where everything must currently be custom developed anyway (due to screen and UI constraints), but as Android starts getting used on laptops and other larger devices is that really still the right approach? or would it be better to have something that could use standard software in the privilaged mode?
to use your example of a mail client, why should someone not be able to use fetchmail to get their mail instead of requiring that fetchmail be modified to use wavelocks (or a substatute written)?
the theoretical best approach would probably look nothing like either of these. Instead it would probably either
forbid privilaged processes from having blocking dependancies on unprivilaged processes (you can then just halt the unprivilaged processes when you blank the screen and let idle sleep deal with the privilged processes)
or
use something like priority inheritance through userspace so that if a privilaged process blocks on something where it's waiting for an unprivilaged process, that unprivilaged process gets woken up and allowed to run until it unblocks the privilaged process.
both of these have been deemed too hard
David Lang
Quoted 11 lines · Rafael J. Wysocki
Quoted 4 lines · On Saturday, August 07, 2010, [email protected] wrote:
Quoted 2 lines · Mark Brown
Quoted 1 line · On Fri, Aug 06, 2010 at 04:35:59PM -0700, [email protected] wrote:
On Fri, 6 Aug 2010, Paul E. McKenney wrote:
...
Quoted 5 lines
What we want to have happen in an ideal world is
when the storage isn't needed (between reads) the storage should shutdown to as low a power state as possible.
Quoted 6 lines
Quoted 3 lines
when the CPU isn't needed (between decoding bursts) the CPU and as much of the system as possible (potentially including some banks of RAM) should shutdown to as low a power state as possible.
Unfortunately, the criteria for "not being needed" are not really straightforward and one of the wakelocks' roles is to work around this issue.
if you can ignore the activity caused by the other "unimportant" processes in the system, why is this much different then just the one process running, in which case standard power management sleeps work pretty well.
Quoted 11 lines
Quoted 10 lines
today there are two ways of this happening, via the idle approach (on everything except Android), or via suspend (on Android)
Given that many platforms cannot go to into suspend while still playing audio, the idle approach is not going to be able to be eliminated (and in fact will be the most common approach to be used/deugged in terms of the types of platforms), it seems to me that there may be a significant amount of value in seeing if there is a way to change Android to use this approach as well instead of having two different systems competing to do the same job.
Quoted 3 lines
There is a fundamental obstacle to that, though. Namely, the Android developers say that the idle-based approach doesn't lead to sufficient energy savings due to periodic timers and "polling applications".
polling applications can be solved by deciding that they aren't going to be allowed to affect the power management decision (don't consider their CPU useage when deciding to go to sleep, don't consider their timers when deciding when to wake back up)
Quoted 5 lines
Technically that
boils down to the interrupt sources that remain active in the idle-based case and that are shut down during suspend. If you found a way to deactivate all of them from the idle context in a non-racy fashion, that would probably satisfy the Android's needs too.
well, we already have similar capibility for other peripherals (I keep pointing to drive spin down as an example), the key to avoiding the races seems to be in the drivers supporting this.
the fact that Android is making it possible for suspend to selectivly avoid disabling them makes me think that a lot of the work needed to make this happen has probably been done. look at what would happen in a suspend if it decided to leave everything else on and just disable the one thing, that should e the same thing that happens if you are just disabling that one thing for idle sleep.
David Lang
Quoted 11 lines · Rafael J. Wysocki
Quoted 4 lines · On Saturday, August 07, 2010, [email protected] wrote:
Quoted 2 lines · Mark Brown
Quoted 1 line · On Fri, Aug 06, 2010 at 04:35:59PM -0700, [email protected] wrote:
On Fri, 6 Aug 2010, Paul E. McKenney wrote:
...
Quoted 5 lines
What we want to have happen in an ideal world is
when the storage isn't needed (between reads) the storage should shutdown to as low a power state as possible.
Quoted 6 lines
Quoted 3 lines
when the CPU isn't needed (between decoding bursts) the CPU and as much of the system as possible (potentially including some banks of RAM) should shutdown to as low a power state as possible.
Unfortunately, the criteria for "not being needed" are not really straightforward and one of the wakelocks' roles is to work around this issue.
if you can ignore the activity caused by the other "unimportant" processes in the system, why is this much different then just the one process running, in which case standard power management sleeps work pretty well.
Quoted 11 lines
Quoted 10 lines
today there are two ways of this happening, via the idle approach (on everything except Android), or via suspend (on Android)
Given that many platforms cannot go to into suspend while still playing audio, the idle approach is not going to be able to be eliminated (and in fact will be the most common approach to be used/deugged in terms of the types of platforms), it seems to me that there may be a significant amount of value in seeing if there is a way to change Android to use this approach as well instead of having two different systems competing to do the same job.
Quoted 3 lines
There is a fundamental obstacle to that, though. Namely, the Android developers say that the idle-based approach doesn't lead to sufficient energy savings due to periodic timers and "polling applications".
polling applications can be solved by deciding that they aren't going to be allowed to affect the power management decision (don't consider their CPU useage when deciding to go to sleep, don't consider their timers when deciding when to wake back up)
Quoted 5 lines
Technically that
boils down to the interrupt sources that remain active in the idle-based case and that are shut down during suspend. If you found a way to deactivate all of them from the idle context in a non-racy fashion, that would probably satisfy the Android's needs too.
well, we already have similar capibility for other peripherals (I keep pointing to drive spin down as an example), the key to avoiding the races seems to be in the drivers supporting this.
the fact that Android is making it possible for suspend to selectivly avoid disabling them makes me think that a lot of the work needed to make this happen has probably been done. look at what would happen in a suspend if it decided to leave everything else on and just disable the one thing, that should e the same thing that happens if you are just disabling that one thing for idle sleep.
David Lang
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_countwill 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_wakenesting (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_awakeandpm_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_awaketo 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
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_countwill 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_wakenesting (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_awakeandpm_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_awaketo 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
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
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
Quoted 7 lines · Paul E. McKenney
Quoted 4 lines · Mark Brown
services in themselves (like system monitoring). It's really just semantics to treat them differently to something like a cellular modem - at a high level they're both just independant processors ticking away without the application processor.
Quoted 5 lines
I agree that a smartphone's cellular modem can be argued to be very similar to wake-on-LAN. The smartphone applications that seem to me to be very different from wake-on-LAN are things like audio playback, where the system is providing service to the user during the time that it is suspended.
The cellular modem case includes not just hanging off the network but also being on a call - the voice path for a phone call doesn't need the CPU to do anything. It's probably best to view a phone as a bunch of interconnected systems that happen to sit in the same box, and there's various design decisions that can be taken about which systems own the shared components.
Quoted 7 lines · Paul E. McKenney
Quoted 4 lines · Mark Brown
services in themselves (like system monitoring). It's really just semantics to treat them differently to something like a cellular modem - at a high level they're both just independant processors ticking away without the application processor.
Quoted 5 lines
I agree that a smartphone's cellular modem can be argued to be very similar to wake-on-LAN. The smartphone applications that seem to me to be very different from wake-on-LAN are things like audio playback, where the system is providing service to the user during the time that it is suspended.
The cellular modem case includes not just hanging off the network but also being on a call - the voice path for a phone call doesn't need the CPU to do anything. It's probably best to view a phone as a bunch of interconnected systems that happen to sit in the same box, and there's various design decisions that can be taken about which systems own the shared components.
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to [email protected]Quoted 11 lines · On Fri, 6 Aug 2010 [email protected] wrote:
Quoted 8 lines
Quoted 2 lines
1. the ability to decide to suspend while there are still some 'unimportant' apps running.
While this may be true in some literal sense, it certainly is not the best way to view the situation. Linux already has the ability to suspend (or to decide to suspend) whenever you want. What Android has added is the ability to suspend conditionally, based on whether or not some applications or drivers want to keep the system running.
Ok, aside from possibly drivers, what' stopping this from being done on a valilla system today?
Nothing much. Mainly just the fact that Rafael's code is so new. It hasn't yet been integrated into the drivers that should use it.
Quoted 10 lines
Quoted 6 lines
Furthermore, this statement leaves out the primary purpose of
wakelocks: to avoid races between suspending and wakeup events. And it also ignores a very important distinction: the difference between drivers and applications. Wakelocks are used by both, but it has been shown that only the wakelocks used by drivers need to be implemented in the kernel -- the others can be implemented entirely in userspace.Ok, this is the first I've heard in this discussion that wakelocks would not be available to userspace. In fact it was explicitly stated that userspace applications called IOCTLs to get/release the wakelock.
Android's wakelock implementation does make wakelocks available to userspace. In Rafael's approach there is nothing comparable. Instead "userspace wakelock"-equivalents have to be handled by a power manager program.
Quoted 9 lines
many of my objections (voiced in another thread) about Android specific features are not relavent if the wakelock in userspace is just part of that application framework and not tied into the kernel.
Quoted 1 line
All of these issues are addressed by Raphael's new
wakeup_eventscode.Ok, then why is there still discussion about wakelocks at all if Raphael has implemnetd the needed kernel functionality and userspace is Android SDK specific?
This thread started when Paul posted his list of requirements for Android power management (or power management in general). It wasn't really specific to wakelocks, but people brought them up when discussing how those requirements are currently being met.
In fact, it seems to me that _you_ are the person most responsible for prolonging this discussion.
Quoted 4 lines
the heated replys from some people about what Android needs (from people who I assumed were Android maintainers due to the way they were answering questions) sure didn't sound like this was a solved problem.
The solution is still in its early stages, and it hasn't yet been accepted into Android. Things will improve over time. (Or they won't, and Android will continue to go its separate way...)
Quoted 11 lines
Quoted 7 lines
This is nonsense. Nothing was changed. Instead, Android implemented system suspend on their platform in a way that would leave some devices running while the rest of the system powered down. There's nothing out of the ordinary about this. Platforms are free to implement system suspend in whatever way they deem most appropriate. On modern PCs, the most appropriate technique is to go into ACPI's S3 or S4 state. On embedded systems, the technique will vary from one platform to another.
the difference is that not all suspends on Android are the same, sometimes when you suspend you power down the audio components, sometimes you don't.
That's not a difference; it is their decision. For all you or I know, other platforms have been doing the same thing for years.
Quoted 3 lines
As far as I am aware (and please correct meif I am mistaken), this is significantly different from suspend elsewhere where suspend always takes you to the same state.
You are mistaken. Or at best, you are overgeneralizing. It may be true now that all other suspend implementations always go to the same state, but there is no requirement that they do so.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
If these two features were available, I think that the rest of what they are looking for could be built up without requireing other changes.
They already _are_ available. Admittedly, only since quite recently. (Rafael's new code was accepted during the 2.6.36 merge window.)
Do Brian and Arve agree that this solves their problem?
I think you should ask them instead of asking me.
Quoted 5 lines
to be fair, there have been numerous complaints about suspend being separate from deep sleep long before Android. Linus' blow-up that resulted in Hibernation and Suspend being separated from each other is a case in point. He was making the point that there shouldn't be a difference between the deepest sleep and suspend.
This may be controversial, but I think Rafael will agree when I say that (in this one respect) Linus was wrong. Separating hibernation from suspend makes sense, and I agree that the differences between deepest idle and suspend should be minimized. But to get rid of them altogether would be wrong (and probably not possible anyway).
Quoted 6 lines
As deep sleep gains the ability to use even less power and as suspend gains the ability to leave things on sometimes, the difference between them is dissapearing. I wouldn't be at all surprised to see them start overlaping soon. So it's not that I think Android should use deep sleeps instead of suspend, but rather that suspend should just be the deepest sleep, one mechanism instead of two.
I disagree. There are critical differences between them:
Suspend uses the freezer and idle doesn't.
Suspend generally forces devices to go into their low-power states immediately, whereas idle tends to leave unused devices at full power for some time before going to low power (to minimize average latency).
Overall, suspend generally has longer latency than idle. (This varies among platforms.)
The set of wakeup sources (including timers) is different.
On some systems, suspend uses platform-specific mechanisms to go into lower power states than are available to idle.
There may be others I have left out.
Alan Stern
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to [email protected]Quoted 11 lines · On Fri, 6 Aug 2010 [email protected] wrote:
Quoted 8 lines
Quoted 2 lines
1. the ability to decide to suspend while there are still some 'unimportant' apps running.
While this may be true in some literal sense, it certainly is not the best way to view the situation. Linux already has the ability to suspend (or to decide to suspend) whenever you want. What Android has added is the ability to suspend conditionally, based on whether or not some applications or drivers want to keep the system running.
Ok, aside from possibly drivers, what' stopping this from being done on a valilla system today?
Nothing much. Mainly just the fact that Rafael's code is so new. It hasn't yet been integrated into the drivers that should use it.
Quoted 10 lines
Quoted 6 lines
Furthermore, this statement leaves out the primary purpose of
wakelocks: to avoid races between suspending and wakeup events. And it also ignores a very important distinction: the difference between drivers and applications. Wakelocks are used by both, but it has been shown that only the wakelocks used by drivers need to be implemented in the kernel -- the others can be implemented entirely in userspace.Ok, this is the first I've heard in this discussion that wakelocks would not be available to userspace. In fact it was explicitly stated that userspace applications called IOCTLs to get/release the wakelock.
Android's wakelock implementation does make wakelocks available to userspace. In Rafael's approach there is nothing comparable. Instead "userspace wakelock"-equivalents have to be handled by a power manager program.
Quoted 9 lines
many of my objections (voiced in another thread) about Android specific features are not relavent if the wakelock in userspace is just part of that application framework and not tied into the kernel.
Quoted 1 line
All of these issues are addressed by Raphael's new
wakeup_eventscode.Ok, then why is there still discussion about wakelocks at all if Raphael has implemnetd the needed kernel functionality and userspace is Android SDK specific?
This thread started when Paul posted his list of requirements for Android power management (or power management in general). It wasn't really specific to wakelocks, but people brought them up when discussing how those requirements are currently being met.
In fact, it seems to me that _you_ are the person most responsible for prolonging this discussion.
Quoted 4 lines
the heated replys from some people about what Android needs (from people who I assumed were Android maintainers due to the way they were answering questions) sure didn't sound like this was a solved problem.
The solution is still in its early stages, and it hasn't yet been accepted into Android. Things will improve over time. (Or they won't, and Android will continue to go its separate way...)
Quoted 11 lines
Quoted 7 lines
This is nonsense. Nothing was changed. Instead, Android implemented system suspend on their platform in a way that would leave some devices running while the rest of the system powered down. There's nothing out of the ordinary about this. Platforms are free to implement system suspend in whatever way they deem most appropriate. On modern PCs, the most appropriate technique is to go into ACPI's S3 or S4 state. On embedded systems, the technique will vary from one platform to another.
the difference is that not all suspends on Android are the same, sometimes when you suspend you power down the audio components, sometimes you don't.
That's not a difference; it is their decision. For all you or I know, other platforms have been doing the same thing for years.
Quoted 3 lines
As far as I am aware (and please correct meif I am mistaken), this is significantly different from suspend elsewhere where suspend always takes you to the same state.
You are mistaken. Or at best, you are overgeneralizing. It may be true now that all other suspend implementations always go to the same state, but there is no requirement that they do so.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
If these two features were available, I think that the rest of what they are looking for could be built up without requireing other changes.
They already _are_ available. Admittedly, only since quite recently. (Rafael's new code was accepted during the 2.6.36 merge window.)
Do Brian and Arve agree that this solves their problem?
I think you should ask them instead of asking me.
Quoted 5 lines
to be fair, there have been numerous complaints about suspend being separate from deep sleep long before Android. Linus' blow-up that resulted in Hibernation and Suspend being separated from each other is a case in point. He was making the point that there shouldn't be a difference between the deepest sleep and suspend.
This may be controversial, but I think Rafael will agree when I say that (in this one respect) Linus was wrong. Separating hibernation from suspend makes sense, and I agree that the differences between deepest idle and suspend should be minimized. But to get rid of them altogether would be wrong (and probably not possible anyway).
Quoted 6 lines
As deep sleep gains the ability to use even less power and as suspend gains the ability to leave things on sometimes, the difference between them is dissapearing. I wouldn't be at all surprised to see them start overlaping soon. So it's not that I think Android should use deep sleeps instead of suspend, but rather that suspend should just be the deepest sleep, one mechanism instead of two.
I disagree. There are critical differences between them:
Suspend uses the freezer and idle doesn't.
Suspend generally forces devices to go into their low-power states immediately, whereas idle tends to leave unused devices at full power for some time before going to low power (to minimize average latency).
Overall, suspend generally has longer latency than idle. (This varies among platforms.)
The set of wakeup sources (including timers) is different.
On some systems, suspend uses platform-specific mechanisms to go into lower power states than are available to idle.
There may be others I have left out.
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()orpm_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
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()orpm_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
Quoted 14 lines · Mark Brown
Quoted 7 lines · Paul E. McKenney
Quoted 4 lines · Mark Brown
services in themselves (like system monitoring). It's really just semantics to treat them differently to something like a cellular modem - at a high level they're both just independant processors ticking away without the application processor.
Quoted 5 lines
I agree that a smartphone's cellular modem can be argued to be very similar to wake-on-LAN. The smartphone applications that seem to me to be very different from wake-on-LAN are things like audio playback, where the system is providing service to the user during the time that it is suspended.
Quoted 6 lines
The cellular modem case includes not just hanging off the network but also being on a call - the voice path for a phone call doesn't need the CPU to do anything. It's probably best to view a phone as a bunch of interconnected systems that happen to sit in the same box, and there's various design decisions that can be taken about which systems own the shared components.
OK, apologies, I thought you were talking about the wait-for-a-call case. If there actually is a call ongoing, then the user perceives the system as doing something, so this is similar to audio playback and quite different from wake-on-LAN or system monitoring.
Thanx, Paul
Quoted 14 lines · Mark Brown
Quoted 7 lines · Paul E. McKenney
Quoted 4 lines · Mark Brown
services in themselves (like system monitoring). It's really just semantics to treat them differently to something like a cellular modem - at a high level they're both just independant processors ticking away without the application processor.
Quoted 5 lines
I agree that a smartphone's cellular modem can be argued to be very similar to wake-on-LAN. The smartphone applications that seem to me to be very different from wake-on-LAN are things like audio playback, where the system is providing service to the user during the time that it is suspended.
Quoted 6 lines
The cellular modem case includes not just hanging off the network but also being on a call - the voice path for a phone call doesn't need the CPU to do anything. It's probably best to view a phone as a bunch of interconnected systems that happen to sit in the same box, and there's various design decisions that can be taken about which systems own the shared components.
OK, apologies, I thought you were talking about the wait-for-a-call case. If there actually is a call ongoing, then the user perceives the system as doing something, so this is similar to audio playback and quite different from wake-on-LAN or system monitoring.
Thanx, Paul
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Rafael J. WysockiQuoted 5 lines · Rafael J. Wysocki
But in principle that need not mean suspending the entire system. To get applications out of the way, you need to freeze user space. However, that's not sufficient, because in addition to that you need to prevent deactivate the majority of interrupt sources to avoid waking up the CPU (from C-states) too often.
True, but again, consider the MacBook. If you plug in an iPod, the machine will wake up for *just* long enough to let the iTunes sync the iPod, but once its done, the machine goes back to sleep again immediately. I doubt MacOS has something called a "suspend blocker" which prevents the machine from sleeping until iTunes finished, which when released, allows the machine to suspend again immediately. But neither did I see any evidence that it took 30 seconds for some kludgy polling process to decide that iTunes was done, and to allow the MacBook to go back to sleep. Clearly, the MacBook allows some interrupts through, and some USB insert events through, but clearly not all. (Inserting a USB drive doesn't wake up the laptop; at least, not for long.)
Can we do something as smooth with a Linux desktop? And if not, why not? (Oh yeah, and wasn't this supposed to be the year of the Linux Desktop? :-)
-- Ted
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Rafael J. WysockiQuoted 5 lines · Rafael J. Wysocki
But in principle that need not mean suspending the entire system. To get applications out of the way, you need to freeze user space. However, that's not sufficient, because in addition to that you need to prevent deactivate the majority of interrupt sources to avoid waking up the CPU (from C-states) too often.
True, but again, consider the MacBook. If you plug in an iPod, the machine will wake up for *just* long enough to let the iTunes sync the iPod, but once its done, the machine goes back to sleep again immediately. I doubt MacOS has something called a "suspend blocker" which prevents the machine from sleeping until iTunes finished, which when released, allows the machine to suspend again immediately. But neither did I see any evidence that it took 30 seconds for some kludgy polling process to decide that iTunes was done, and to allow the MacBook to go back to sleep. Clearly, the MacBook allows some interrupts through, and some USB insert events through, but clearly not all. (Inserting a USB drive doesn't wake up the laptop; at least, not for long.)
Can we do something as smooth with a Linux desktop? And if not, why not? (Oh yeah, and wasn't this supposed to be the year of the Linux Desktop? :-)
-- Ted
Quoted 17 lines · On Sat, Aug 07, 2010 at 03:00:48AM -0700, [email protected] wrote:
Quoted 15 lines · Rafael J. Wysocki
Quoted 4 lines · On Saturday, August 07, 2010, [email protected] wrote:
Quoted 2 lines · Mark Brown
Quoted 1 line · On Fri, Aug 06, 2010 at 04:35:59PM -0700, [email protected] wrote:
On Fri, 6 Aug 2010, Paul E. McKenney wrote:
...
Quoted 8 lines
What we want to have happen in an ideal world is
when the storage isn't needed (between reads) the storage should shutdown to as low a power state as possible.
when the CPU isn't needed (between decoding bursts) the CPU and as much of the system as possible (potentially including some banks of RAM) should shutdown to as low a power state as possible.
Quoted 7 lines
Quoted 2 lines
Unfortunately, the criteria for "not being needed" are not really straightforward and one of the wakelocks' roles is to work around this issue.
if you can ignore the activity caused by the other "unimportant" processes in the system, why is this much different then just the one process running, in which case standard power management sleeps work pretty well.
But isn't the whole point of wakelocks to permit developers to easily and efficiently identify which processes are "unimportant" at a given point in time, thereby allowing them to be ignored?
I understand your position -- you believe that PM-driving applications should be written to remain idle any time that they aren't doing something "important". This is a reasonable position to take, but it is also reasonable to justify your position. Exactly -why- is this better? Here is my evaluation:
o You might not need suspend blockers. This is not totally clear,
and won't be until you actually build a system based on your design.
o You will be requiring that developers of PM-driving applications
deal with more code that must be very carefully coded and validated. This requirement forces the expenditure of lots of people time to save a very small amount of very inexpensive memory (that occupied by the suspend-blocker code).
Keep in mind that there was a similar decision in the -rt kernel. One choice was similar to your proposal: all code paths must call schedule() sufficiently frequently. The other choice was to allow almost all code paths to be preempted, which resembles suspend blockers (preempt_disable() being analogous to acquiring a suspend blocker, and preempt_enable() being analogous to releasing a suspend blocker).
Then as now, there was much debate. The choice then was preemption. One big reason was that the choice of preemption reduced the amount of real-time-aware code from the entire kernel to only that part of the kernel that disabled preemption, which turned out to greatly simplify the job of meeting aggressive scheduling-latency goals. This experience does add some serious precedent against your position. So, what do you believe is different in the energy-efficiency case?
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
today there are two ways of this happening, via the idle approach (on everything except Android), or via suspend (on Android)
Given that many platforms cannot go to into suspend while still playing audio, the idle approach is not going to be able to be eliminated (and in fact will be the most common approach to be used/deugged in terms of the types of platforms), it seems to me that there may be a significant amount of value in seeing if there is a way to change Android to use this approach as well instead of having two different systems competing to do the same job.
Quoted 8 lines
Quoted 3 lines
There is a fundamental obstacle to that, though. Namely, the Android developers say that the idle-based approach doesn't lead to sufficient energy savings due to periodic timers and "polling applications".
polling applications can be solved by deciding that they aren't going to be allowed to affect the power management decision (don't consider their CPU useage when deciding to go to sleep, don't consider their timers when deciding when to wake back up)
Agreed, and the focus is on how one decides which applications need to be considered. After all, the activity of a highly optimized audio-playback application looks exactly like that of a stupid polling application -- they both periodically consume some CPU. But this is something that you and the Android guys are actually agreeing about. You are only arguing about exactly what mechanism should be used to make this determination. The Android guys want suspend blockers, and you want to extend cgroups.
So I believe that the next step for you is to implement your approach so that it can be compared in terms of energy efficiency, code size, intrusiveness, performance, and compatibility with existing code.
Quoted 9 lines
Quoted 5 lines
Technically that
boils down to the interrupt sources that remain active in the idle-based case and that are shut down during suspend. If you found a way to deactivate all of them from the idle context in a non-racy fashion, that would probably satisfy the Android's needs too.well, we already have similar capibility for other peripherals (I keep pointing to drive spin down as an example), the key to avoiding the races seems to be in the drivers supporting this.
The difference is that the CPU stays active in the drive spin down case -- if the drive turns out to be needed, the CPU can spin it up. The added complication in the suspend case is that the CPU goes away, so that you must more carefully plan for all of the power-up cases.
Quoted 6 lines
the fact that Android is making it possible for suspend to selectivly avoid disabling them makes me think that a lot of the work needed to make this happen has probably been done. look at what would happen in a suspend if it decided to leave everything else on and just disable the one thing, that should e the same thing that happens if you are just disabling that one thing for idle sleep.
We already covered the differences between suspend and idle, now didn't we? ;-)
Thanx, Paul
Quoted 17 lines · On Sat, Aug 07, 2010 at 03:00:48AM -0700, [email protected] wrote:
Quoted 15 lines · Rafael J. Wysocki
Quoted 4 lines · On Saturday, August 07, 2010, [email protected] wrote:
Quoted 2 lines · Mark Brown
Quoted 1 line · On Fri, Aug 06, 2010 at 04:35:59PM -0700, [email protected] wrote:
On Fri, 6 Aug 2010, Paul E. McKenney wrote:
...
Quoted 8 lines
What we want to have happen in an ideal world is
when the storage isn't needed (between reads) the storage should shutdown to as low a power state as possible.
when the CPU isn't needed (between decoding bursts) the CPU and as much of the system as possible (potentially including some banks of RAM) should shutdown to as low a power state as possible.
Quoted 7 lines
Quoted 2 lines
Unfortunately, the criteria for "not being needed" are not really straightforward and one of the wakelocks' roles is to work around this issue.
if you can ignore the activity caused by the other "unimportant" processes in the system, why is this much different then just the one process running, in which case standard power management sleeps work pretty well.
But isn't the whole point of wakelocks to permit developers to easily and efficiently identify which processes are "unimportant" at a given point in time, thereby allowing them to be ignored?
I understand your position -- you believe that PM-driving applications should be written to remain idle any time that they aren't doing something "important". This is a reasonable position to take, but it is also reasonable to justify your position. Exactly -why- is this better? Here is my evaluation:
o You might not need suspend blockers. This is not totally clear,
and won't be until you actually build a system based on your design.
o You will be requiring that developers of PM-driving applications
deal with more code that must be very carefully coded and validated. This requirement forces the expenditure of lots of people time to save a very small amount of very inexpensive memory (that occupied by the suspend-blocker code).
Keep in mind that there was a similar decision in the -rt kernel. One choice was similar to your proposal: all code paths must call schedule() sufficiently frequently. The other choice was to allow almost all code paths to be preempted, which resembles suspend blockers (preempt_disable() being analogous to acquiring a suspend blocker, and preempt_enable() being analogous to releasing a suspend blocker).
Then as now, there was much debate. The choice then was preemption. One big reason was that the choice of preemption reduced the amount of real-time-aware code from the entire kernel to only that part of the kernel that disabled preemption, which turned out to greatly simplify the job of meeting aggressive scheduling-latency goals. This experience does add some serious precedent against your position. So, what do you believe is different in the energy-efficiency case?
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
today there are two ways of this happening, via the idle approach (on everything except Android), or via suspend (on Android)
Given that many platforms cannot go to into suspend while still playing audio, the idle approach is not going to be able to be eliminated (and in fact will be the most common approach to be used/deugged in terms of the types of platforms), it seems to me that there may be a significant amount of value in seeing if there is a way to change Android to use this approach as well instead of having two different systems competing to do the same job.
Quoted 8 lines
Quoted 3 lines
There is a fundamental obstacle to that, though. Namely, the Android developers say that the idle-based approach doesn't lead to sufficient energy savings due to periodic timers and "polling applications".
polling applications can be solved by deciding that they aren't going to be allowed to affect the power management decision (don't consider their CPU useage when deciding to go to sleep, don't consider their timers when deciding when to wake back up)
Agreed, and the focus is on how one decides which applications need to be considered. After all, the activity of a highly optimized audio-playback application looks exactly like that of a stupid polling application -- they both periodically consume some CPU. But this is something that you and the Android guys are actually agreeing about. You are only arguing about exactly what mechanism should be used to make this determination. The Android guys want suspend blockers, and you want to extend cgroups.
So I believe that the next step for you is to implement your approach so that it can be compared in terms of energy efficiency, code size, intrusiveness, performance, and compatibility with existing code.
Quoted 9 lines
Quoted 5 lines
Technically that
boils down to the interrupt sources that remain active in the idle-based case and that are shut down during suspend. If you found a way to deactivate all of them from the idle context in a non-racy fashion, that would probably satisfy the Android's needs too.well, we already have similar capibility for other peripherals (I keep pointing to drive spin down as an example), the key to avoiding the races seems to be in the drivers supporting this.
The difference is that the CPU stays active in the drive spin down case -- if the drive turns out to be needed, the CPU can spin it up. The added complication in the suspend case is that the CPU goes away, so that you must more carefully plan for all of the power-up cases.
Quoted 6 lines
the fact that Android is making it possible for suspend to selectivly avoid disabling them makes me think that a lot of the work needed to make this happen has probably been done. look at what would happen in a suspend if it decided to leave everything else on and just disable the one thing, that should e the same thing that happens if you are just disabling that one thing for idle sleep.
We already covered the differences between suspend and idle, now didn't we? ;-)
Thanx, Paul
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to [email protected]Quoted 30 lines · On Sat, Aug 07, 2010 at 02:38:35AM -0700, [email protected] wrote:
Quoted 17 lines · Ted Ts'o
Quoted 9 lines · On Fri, Aug 06, 2010 at 08:14:09PM -0700, [email protected] wrote:
that description sounds far more like normal sleep power management that suspending. especially since they want to set timers to wake the system up and the defining characteristic of suspend (according to this thread) is that timers don't fire while suspended.
as I am seeing it, there are two reasons why this don't "just work"
1. sleeping can't currently save as much power as suspending
No, I don't think that's the case at all. The key thing here is that *most* applications don't need to be modified to use suspend locks, because even though they might be in an event loop, when the user user turns off the display, the user generally doesn't want it doing things on their behalf.
Quoted 10 lines
Again, take for example the Mac Book, since Apple has gotten this right for most users' use cases. When you close the lid, you even if the application is under the misguided belief that it should be checking every five seconds to see whether or not the web page has reloaded --- actually, that's not what you want. You probably want the application to be forcibly put to sleep. So the whole point of the suspend blocker design is that you don't have to modify most applications; they just simply get put to sleep when you close the MacBook lid, or, in the case of the Android device, you push the button that turns off the screen.
Quoted 4 lines
this doesn't require wakelocks or anything else new. all it takes is setting the policy that you don't want anything to run when the lid is closed and a switch to detect the lid being closed. Laptops have been doing this for years.
Please re-read Ted's paragraph above, but carefully this time. You will then see that the desired policy is -not- "you don't want anything to run when the lid is closed."
Quoted 44 lines
Quoted 9 lines
So the reason why this doesn't work is that power management for small mobile devices *is* different from power management for laptops and data center servers, and if you want a rich application ecosystem, it's best if you don't require them to be specially tuned to use the absolute minimum power. (And that means waking up every 30 seconds might be too much; as Brian and Arve have pointed out, with the G1 in airplane mode, the CPU might be waking up once every half hour or more --- and at that rate, powertop will be waking up the CPU more than Android system would be doing so.)
note that nothing that I have proposed would wake up a sleeping system. the 'every several seconds' thing that I proposed was that on a system that's fully awake, busy and doesn't want to sleep, there would be a context switch periodically by a privilaged process so that the system would not end up deciding it was idle and halt everything. Now that I think about this more, it's not needed if you want to override this to keep everything running for a significant amount of time, just change the power saving mode from "sleep if a privilaged task isn't running" to "disable suspend". This can be done today by changing the right sysfs value. normal privilaged processes would never need to do this, only gatekeeper daemons that want to let unprivilaged processes run even if no privilaged processes want to run would need to do this (i.e. in the current system, whatever process controls the screen would probably be right)
Quoted 8 lines
So the real key here is to take most applications, which may be written using techniques that might be considered well written from a laptop point of view, but not for a cell phone, and not require modifications. Even though the application writer might think it's doing well by waking up every 15 seconds, if the laptop lid is down, or if the screen is off, for **most** applications, it should be forcibly put to sleep.
Quoted 9 lines
It's only the rare applications that should really be allowed to run while screen is off. And it's only those applications that need modifications to use suspend blocker. From your earlier comments, it seems that this is the key point which you are missing. (No doubt, some of these applications that do need to know about suspend blockers are important ones; ones that make sure the battery isn't about to blow up, or ones which silently wake up every 10-15 minutes to pull down fresh mail for you from your mail server. But those applications are the exception, not the rule.)
Quoted 4 lines
the question is what it takes to make an application privilaged like this.
what I proposed was to make it possible for the user/admin to select what applications are allowed to keep the system awake.
The Android guys do the same.
Quoted 2 lines
wakelocks require that the application developer decide that they want to keep the system awake as well as the user/admin
Whereas you require that the application developer redesign/rewrite applications to decide when to keep the system awake, e.g., by carefully determining when to idle themselves. The difference is that the Android developer need only release a suspend blocker. In contrast, you are requiring that the developer rewrite all the code that follows the point where the Android developer would release a suspend blocker.
Your way seems to require that the developer do more work for the same result. Why?
Now, I do agree that a safe way to freeze the power-oblivious applications could be valuable, as it might reduce power consumption while the screen was blanked but while a PM-driving application was holding a suspend blocker. However, as we have discussed, you have to be very careful not to freeze any app holding a user-level resource.
Quoted 12 lines
take your example of a mail client waking up every 15 min.
with Android it needs to be privilaged to grab the wakelock while fetching the mail, it also needs to use a privilaged API to set the wakeups to wake it up at those times.
with what I proposed all you need to do is to tag the application as power privilaged and then if the application sleeps for 15 min between doing thing the system will wake up every 15 min, work for a short time, then go back to sleep.
Quoted 5 lines
if you want to put everything to sleep when the screen blanks, that's trivial to do.
the fun starts when you want to say that there are some things you don't want to put to sleep.
Which is in fact a critical requirement that you appear to have been ignoring in your words above.
Quoted 8 lines
do you let some processes run while halting others?
in which case how do you prevent deadlocks?
on the other hand, sleeping again is simple, you sleep when
there is nothing more to run
or do you let wasteful processes run while you are awake?
this avoids deadlocks, but how do you decide when to sleep again?
Quoted 5 lines
Android approaches this by requiring that any program that a user may want to keep running must be modified to use wakelocks.
My suggestion was that the system ignore other processes when deciding if the system is idle enough to put to sleep.
But your suggestion seems to require quite a bit more coding effort for little gain. The Android developer can just release a suspend blocker, and in contrast, a developer using your proposal needs to rewrite all the code following the point at which the Android developer released the suspend blocker. So why are you saying that your is approach better? ;-)
Quoted 21 lines
Yes the Android approach works reasonably well on the phones where everything must currently be custom developed anyway (due to screen and UI constraints), but as Android starts getting used on laptops and other larger devices is that really still the right approach? or would it be better to have something that could use standard software in the privilaged mode?
to use your example of a mail client, why should someone not be able to use fetchmail to get their mail instead of requiring that fetchmail be modified to use wavelocks (or a substatute written)?
the theoretical best approach would probably look nothing like either of these. Instead it would probably either
forbid privilaged processes from having blocking dependancies on unprivilaged processes (you can then just halt the unprivilaged processes when you blank the screen and let idle sleep deal with the privilged processes)
Quoted 8 lines
or
use something like priority inheritance through userspace so that if a privilaged process blocks on something where it's waiting for an unprivilaged process, that unprivilaged process gets woken up and allowed to run until it unblocks the privilaged process.
both of these have been deemed too hard
And for good reason.
Thanx, Paul
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to [email protected]Quoted 30 lines · On Sat, Aug 07, 2010 at 02:38:35AM -0700, [email protected] wrote:
Quoted 17 lines · Ted Ts'o
Quoted 9 lines · On Fri, Aug 06, 2010 at 08:14:09PM -0700, [email protected] wrote:
that description sounds far more like normal sleep power management that suspending. especially since they want to set timers to wake the system up and the defining characteristic of suspend (according to this thread) is that timers don't fire while suspended.
as I am seeing it, there are two reasons why this don't "just work"
1. sleeping can't currently save as much power as suspending
No, I don't think that's the case at all. The key thing here is that *most* applications don't need to be modified to use suspend locks, because even though they might be in an event loop, when the user user turns off the display, the user generally doesn't want it doing things on their behalf.
Quoted 10 lines
Again, take for example the Mac Book, since Apple has gotten this right for most users' use cases. When you close the lid, you even if the application is under the misguided belief that it should be checking every five seconds to see whether or not the web page has reloaded --- actually, that's not what you want. You probably want the application to be forcibly put to sleep. So the whole point of the suspend blocker design is that you don't have to modify most applications; they just simply get put to sleep when you close the MacBook lid, or, in the case of the Android device, you push the button that turns off the screen.
Quoted 4 lines
this doesn't require wakelocks or anything else new. all it takes is setting the policy that you don't want anything to run when the lid is closed and a switch to detect the lid being closed. Laptops have been doing this for years.
Please re-read Ted's paragraph above, but carefully this time. You will then see that the desired policy is -not- "you don't want anything to run when the lid is closed."
Quoted 44 lines
Quoted 9 lines
So the reason why this doesn't work is that power management for small mobile devices *is* different from power management for laptops and data center servers, and if you want a rich application ecosystem, it's best if you don't require them to be specially tuned to use the absolute minimum power. (And that means waking up every 30 seconds might be too much; as Brian and Arve have pointed out, with the G1 in airplane mode, the CPU might be waking up once every half hour or more --- and at that rate, powertop will be waking up the CPU more than Android system would be doing so.)
note that nothing that I have proposed would wake up a sleeping system. the 'every several seconds' thing that I proposed was that on a system that's fully awake, busy and doesn't want to sleep, there would be a context switch periodically by a privilaged process so that the system would not end up deciding it was idle and halt everything. Now that I think about this more, it's not needed if you want to override this to keep everything running for a significant amount of time, just change the power saving mode from "sleep if a privilaged task isn't running" to "disable suspend". This can be done today by changing the right sysfs value. normal privilaged processes would never need to do this, only gatekeeper daemons that want to let unprivilaged processes run even if no privilaged processes want to run would need to do this (i.e. in the current system, whatever process controls the screen would probably be right)
Quoted 8 lines
So the real key here is to take most applications, which may be written using techniques that might be considered well written from a laptop point of view, but not for a cell phone, and not require modifications. Even though the application writer might think it's doing well by waking up every 15 seconds, if the laptop lid is down, or if the screen is off, for **most** applications, it should be forcibly put to sleep.
Quoted 9 lines
It's only the rare applications that should really be allowed to run while screen is off. And it's only those applications that need modifications to use suspend blocker. From your earlier comments, it seems that this is the key point which you are missing. (No doubt, some of these applications that do need to know about suspend blockers are important ones; ones that make sure the battery isn't about to blow up, or ones which silently wake up every 10-15 minutes to pull down fresh mail for you from your mail server. But those applications are the exception, not the rule.)
Quoted 4 lines
the question is what it takes to make an application privilaged like this.
what I proposed was to make it possible for the user/admin to select what applications are allowed to keep the system awake.
The Android guys do the same.
Quoted 2 lines
wakelocks require that the application developer decide that they want to keep the system awake as well as the user/admin
Whereas you require that the application developer redesign/rewrite applications to decide when to keep the system awake, e.g., by carefully determining when to idle themselves. The difference is that the Android developer need only release a suspend blocker. In contrast, you are requiring that the developer rewrite all the code that follows the point where the Android developer would release a suspend blocker.
Your way seems to require that the developer do more work for the same result. Why?
Now, I do agree that a safe way to freeze the power-oblivious applications could be valuable, as it might reduce power consumption while the screen was blanked but while a PM-driving application was holding a suspend blocker. However, as we have discussed, you have to be very careful not to freeze any app holding a user-level resource.
Quoted 12 lines
take your example of a mail client waking up every 15 min.
with Android it needs to be privilaged to grab the wakelock while fetching the mail, it also needs to use a privilaged API to set the wakeups to wake it up at those times.
with what I proposed all you need to do is to tag the application as power privilaged and then if the application sleeps for 15 min between doing thing the system will wake up every 15 min, work for a short time, then go back to sleep.
Quoted 5 lines
if you want to put everything to sleep when the screen blanks, that's trivial to do.
the fun starts when you want to say that there are some things you don't want to put to sleep.
Which is in fact a critical requirement that you appear to have been ignoring in your words above.
Quoted 8 lines
do you let some processes run while halting others?
in which case how do you prevent deadlocks?
on the other hand, sleeping again is simple, you sleep when
there is nothing more to run
or do you let wasteful processes run while you are awake?
this avoids deadlocks, but how do you decide when to sleep again?
Quoted 5 lines
Android approaches this by requiring that any program that a user may want to keep running must be modified to use wakelocks.
My suggestion was that the system ignore other processes when deciding if the system is idle enough to put to sleep.
But your suggestion seems to require quite a bit more coding effort for little gain. The Android developer can just release a suspend blocker, and in contrast, a developer using your proposal needs to rewrite all the code following the point at which the Android developer released the suspend blocker. So why are you saying that your is approach better? ;-)
Quoted 21 lines
Yes the Android approach works reasonably well on the phones where everything must currently be custom developed anyway (due to screen and UI constraints), but as Android starts getting used on laptops and other larger devices is that really still the right approach? or would it be better to have something that could use standard software in the privilaged mode?
to use your example of a mail client, why should someone not be able to use fetchmail to get their mail instead of requiring that fetchmail be modified to use wavelocks (or a substatute written)?
the theoretical best approach would probably look nothing like either of these. Instead it would probably either
forbid privilaged processes from having blocking dependancies on unprivilaged processes (you can then just halt the unprivilaged processes when you blank the screen and let idle sleep deal with the privilged processes)
Quoted 8 lines
or
use something like priority inheritance through userspace so that if a privilaged process blocks on something where it's waiting for an unprivilaged process, that unprivilaged process gets woken up and allowed to run until it unblocks the privilaged process.
both of these have been deemed too hard
And for good reason.
Thanx, Paul
Quoted 40 lines · Paul E. McKenney
Quoted 17 lines · On Sat, Aug 07, 2010 at 03:00:48AM -0700, [email protected] wrote:
Quoted 15 lines · Rafael J. Wysocki
Quoted 4 lines · On Saturday, August 07, 2010, [email protected] wrote:
Quoted 2 lines · Mark Brown
Quoted 1 line · On Fri, Aug 06, 2010 at 04:35:59PM -0700, [email protected] wrote:
On Fri, 6 Aug 2010, Paul E. McKenney wrote:
...
Quoted 8 lines
What we want to have happen in an ideal world is
when the storage isn't needed (between reads) the storage should shutdown to as low a power state as possible.
when the CPU isn't needed (between decoding bursts) the CPU and as much of the system as possible (potentially including some banks of RAM) should shutdown to as low a power state as possible.
Quoted 7 lines
Quoted 2 lines
Unfortunately, the criteria for "not being needed" are not really straightforward and one of the wakelocks' roles is to work around this issue.
if you can ignore the activity caused by the other "unimportant" processes in the system, why is this much different then just the one process running, in which case standard power management sleeps work pretty well.
But isn't the whole point of wakelocks to permit developers to easily and efficiently identify which processes are "unimportant" at a given point in time, thereby allowing them to be ignored?
I understand your position -- you believe that PM-driving applications should be written to remain idle any time that they aren't doing something "important". This is a reasonable position to take, but it is also reasonable to justify your position. Exactly -why- is this better? Here is my evaluation:
o You might not need suspend blockers. This is not totally clear,
and won't be until you actually build a system based on your design.
Quoted 5 lines
o You will be requiring that developers of PM-driving applications
deal with more code that must be very carefully coded and validated. This requirement forces the expenditure of lots of people time to save a very small amount of very inexpensive memory (that occupied by the suspend-blocker code).
the issue isn't avoiding the memory useage, the issue is avoiding the special API requirement that make the userspace code no longer be portable.
note that there are a lot of battery powered embedded devices out there that work just fine without wakelocks. They are able to use the existing idle/sleep and suspend options to get good battery life.
The key difference is that Android allows other programs to be loaded on the system, and the current idle/sleep/suspend triggers can't tell the difference between the important software and the other software.
Quoted 7 lines
Keep in mind that there was a similar decision in the -rt kernel. One choice was similar to your proposal: all code paths must call
schedule()sufficiently frequently. The other choice was to allow almost all code paths to be preempted, which resembles suspend blockers (preempt_disable()being analogous to acquiring a suspend blocker, andpreempt_enable()being analogous to releasing a suspend blocker).
Quoted 7 lines
Then as now, there was much debate. The choice then was preemption. One big reason was that the choice of preemption reduced the amount of real-time-aware code from the entire kernel to only that part of the kernel that disabled preemption, which turned out to greatly simplify the job of meeting aggressive scheduling-latency goals. This experience does add some serious precedent against your position. So, what do you believe is different in the energy-efficiency case?
for one thing, there was never any thought that any code that would have to have preempt written would ever run anywhere else other than inside the linux kernel.
If you had proposed that userspace be allowed to do preempt_enable/disable calls, it would have been a very different discussion.
In the case of real-time applications, we require that things that are given real-time priority be carefully coded to behave well, and that if they depend on things that are not given real-time priority they may not behave as expected. Priority Inheritance is a way to avoid complete system lockup in many cases, but it would still be possible for a badly written real-time app to kill the system if it does something like go into a busy-loop waiting for a file to be created by a non-real-time process.
wakelocks are like implementing real-time by allowing userspace to issue preempt_disable() calls to tell the scheduler not to take the CPU away from them until they make a preempt_enable() call.
In addition wakelocks cannot replace the need to write efficient code. all that wakelocks do is to prevent the system from doing a suspend, you still want to have the code written to not do unneccessary wakeups that would prevent you from using the low-power modes other than suspend. On the other hand, it _is_ possible for the idle/sleep states to be extended to also cover suspend.
Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
today there are two ways of this happening, via the idle approach (on everything except Android), or via suspend (on Android)
Given that many platforms cannot go to into suspend while still playing audio, the idle approach is not going to be able to be eliminated (and in fact will be the most common approach to be used/deugged in terms of the types of platforms), it seems to me that there may be a significant amount of value in seeing if there is a way to change Android to use this approach as well instead of having two different systems competing to do the same job.
Quoted 8 lines
Quoted 3 lines
There is a fundamental obstacle to that, though. Namely, the Android developers say that the idle-based approach doesn't lead to sufficient energy savings due to periodic timers and "polling applications".
polling applications can be solved by deciding that they aren't going to be allowed to affect the power management decision (don't consider their CPU useage when deciding to go to sleep, don't consider their timers when deciding when to wake back up)
Quoted 8 lines
Agreed, and the focus is on how one decides which applications need to be considered. After all, the activity of a highly optimized audio-playback application looks exactly like that of a stupid polling application -- they both periodically consume some CPU. But this is something that you and the Android guys are actually agreeing about. You are only arguing about exactly what mechanism should be used to make this determination. The Android guys want suspend blockers, and you want to extend cgroups.
I want the kernel to be explicitly told that this application is important (or alternativly that these other applications are not). I suggested cgroups as a possible way to do this, but anything that could tell the kernel what processes to care about and what ones to not care about would work. My initial thought had actually been to do something like echo the pid of important processes into a /proc or /sys file, but I was under the impression that there were a lot of processes that would get this state and therefore a more general tool like cgroups (which as I understand it automatically puts children of a process into the same cgroup as the parent) seemed moreuseful
Quoted 10 lines
So I believe that the next step for you is to implement your approach so that it can be compared in terms of energy efficiency, code size, intrusiveness, performance, and compatibility with existing code.
Quoted 6 lines
Quoted 5 lines
Technically that
boils down to the interrupt sources that remain active in the idle-based case and that are shut down during suspend. If you found a way to deactivate all of them from the idle context in a non-racy fashion, that would probably satisfy the Android's needs too.
Quoted 8 lines
Quoted 3 lines
well, we already have similar capibility for other peripherals (I keep pointing to drive spin down as an example), the key to avoiding the races seems to be in the drivers supporting this.
The difference is that the CPU stays active in the drive spin down case -- if the drive turns out to be needed, the CPU can spin it up. The added complication in the suspend case is that the CPU goes away, so that you must more carefully plan for all of the power-up cases.
I agree tha the power down and restart needs to be planned, but it's not like you are going to wake up the drive (or the audio hardware0 without waking up the CPU first.
even with idle sleep modes and drive spin-down there is no provision for the drive to be restarted if the CPU is asleep, you first have something happen that wakes up the CPU and it then wakes up the drive. This same approach should work for other things.
Quoted 9 lines
Quoted 6 lines
the fact that Android is making it possible for suspend to selectivly avoid disabling them makes me think that a lot of the work needed to make this happen has probably been done. look at what would happen in a suspend if it decided to leave everything else on and just disable the one thing, that should e the same thing that happens if you are just disabling that one thing for idle sleep.
We already covered the differences between suspend and idle, now didn't we? ;-)
we did, however at the time suspend was to stop everything, now we are finding that Android has multiple flavors of suspend, one of which stops everything, the others leave some things running.
David Lang
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Theodore TsoQuoted 8 lines · Theodore Tso
Quoted 5 lines · Rafael J. Wysocki
But in principle that need not mean suspending the entire system. To get applications out of the way, you need to freeze user space. However, that's not sufficient, because in addition to that you need to prevent deactivate the majority of interrupt sources to avoid waking up the CPU (from C-states) too often.
Quoted 9 lines
True, but again, consider the MacBook. If you plug in an iPod, the machine will wake up for *just* long enough to let the iTunes sync the iPod, but once its done, the machine goes back to sleep again immediately. I doubt MacOS has something called a "suspend blocker" which prevents the machine from sleeping until iTunes finished, which when released, allows the machine to suspend again immediately. But neither did I see any evidence that it took 30 seconds for some kludgy polling process to decide that iTunes was done, and to allow the MacBook to go back to sleep.
nobody has proposed a polling process to decide the system can suspend, what I proposed was to have idle detection decide the system can suspend, which would mean that if you don't want the system to suspend you have to do something to keep it from being idle.
At the time I didn't know that Android always disabled suspend for the entire time the display was on, so I made the assumption that timouts had to be long enough for input events to keep the system awake, which would put them on the order of 30 seconds or longer.
If all that is wanted is to disable the suspend for the entire time the backlight is on you don't need wakelocks, and you don't need a privilaged thread waking up, all you need is to tell the power management system not to suspend through the existing mechanism. you could create a new mechanism (wakelock) to pass the same information, but what is the advantage of doing so?
David Lang
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Alan SternQuoted 11 lines · Alan Stern
Quoted 9 lines · On Fri, 6 Aug 2010 [email protected] wrote:
Quoted 8 lines
Quoted 2 lines
1. the ability to decide to suspend while there are still some 'unimportant' apps running.
While this may be true in some literal sense, it certainly is not the best way to view the situation. Linux already has the ability to suspend (or to decide to suspend) whenever you want. What Android has added is the ability to suspend conditionally, based on whether or not some applications or drivers want to keep the system running.
Quoted 5 lines
Quoted 2 lines
Ok, aside from possibly drivers, what' stopping this from being done on a valilla system today?
Nothing much. Mainly just the fact that Rafael's code is so new. It hasn't yet been integrated into the drivers that should use it.
makes sense.
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Furthermore, this statement leaves out the primary purpose of
wakelocks: to avoid races between suspending and wakeup events. And it also ignores a very important distinction: the difference between drivers and applications. Wakelocks are used by both, but it has been shown that only the wakelocks used by drivers need to be implemented in the kernel -- the others can be implemented entirely in userspace.
Quoted 8 lines
Quoted 3 lines
Ok, this is the first I've heard in this discussion that wakelocks would not be available to userspace. In fact it was explicitly stated that userspace applications called IOCTLs to get/release the wakelock.
Android's wakelock implementation does make wakelocks available to userspace. In Rafael's approach there is nothing comparable. Instead "userspace wakelock"-equivalents have to be handled by a power manager program.
And the question to the Android people is if they consider this acceptable or think that this means that the vanilla can't support them.
Quoted 10 lines
Quoted 9 lines
many of my objections (voiced in another thread) about Android specific features are not relavent if the wakelock in userspace is just part of that application framework and not tied into the kernel.
Quoted 1 line
All of these issues are addressed by Raphael's new
wakeup_eventscode.Ok, then why is there still discussion about wakelocks at all if Raphael has implemnetd the needed kernel functionality and userspace is Android SDK specific?
Quoted 7 lines
This thread started when Paul posted his list of requirements for Android power management (or power management in general). It wasn't really specific to wakelocks, but people brought them up when discussing how those requirements are currently being met.
In fact, it seems to me that _you_ are the person most responsible for prolonging this discussion.
I'll admit to that, but it seems like there is still new information comeing up about the requirements, as well as the current implementation.
Quoted 9 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
If these two features were available, I think that the rest of what they are looking for could be built up without requireing other changes.
They already _are_ available. Admittedly, only since quite recently. (Rafael's new code was accepted during the 2.6.36 merge window.)
Do Brian and Arve agree that this solves their problem?
I think you should ask them instead of asking me.
Since they are following this thread, this was intended to be asking them torespond.
Quoted 11 lines
Quoted 5 lines
to be fair, there have been numerous complaints about suspend being separate from deep sleep long before Android. Linus' blow-up that resulted in Hibernation and Suspend being separated from each other is a case in point. He was making the point that there shouldn't be a difference between the deepest sleep and suspend.
This may be controversial, but I think Rafael will agree when I say that (in this one respect) Linus was wrong. Separating hibernation from suspend makes sense, and I agree that the differences between deepest idle and suspend should be minimized. But to get rid of them altogether would be wrong (and probably not possible anyway).
if you thing the differences should be minimized, why do you think that getting rid of them would be wrong?
I know that Rafael disagrees with Linus, because he has not implemented what Linus suggested.
Quoted 7 lines
Quoted 6 lines
As deep sleep gains the ability to use even less power and as suspend gains the ability to leave things on sometimes, the difference between them is dissapearing. I wouldn't be at all surprised to see them start overlaping soon. So it's not that I think Android should use deep sleeps instead of suspend, but rather that suspend should just be the deepest sleep, one mechanism instead of two.
Quoted 8 lines
I disagree. There are critical differences between them:
Suspend uses the freezer and idle doesn't.
Suspend generally forces devices to go into their low-power states immediately, whereas idle tends to leave unused devices at full power for some time before going to low power (to minimize average latency).
this sounds like policy, not capability.
Quoted 2 lines
Overall, suspend generally has longer latency than idle. (This varies among platforms.)
even different idle modes have different latency
Quoted 1 line
The set of wakeup sources (including timers) is different.
I agree that they are different, but don't they also vary within sleep or suspend as well?
Quoted 2 lines
On some systems, suspend uses platform-specific mechanisms to go into lower power states than are available to idle.
the exact mechanism to go into low-power states is platform specific to start with (there are some very popular platforms admittedly, like the PC ACPI modes)
as I see it
Sleep
a policy engine to decide when to sleep, how deeply to sleep, what to disable, what will wake you up (this includes taking into account desired latency, and the amount of power/time needed to get in and out of the various modes)
platform specific mechanisms for transitioning in and out of the modes.
Suspend
a policy engine to decide when to suspend, what to leave enabled when you supend, what will wake you i[
platform specific mechanisms for transition in and out of suspend. I view use of the freezer to be one of these mechansims.
Somewhere amoung this mess are things like spinning down drives, disabling inactive network interfaces, etc. I don't knwo if those are run from the sleep policy engine, or if there is a third policy engine to decide these things.
why should there be multiple different policy engines making power management decisions? it seems to me like these policy engines can and should be merged, with the resulting engine able to trigger all the existing mechanisms for transitioning between modes.
David Lang
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Alan SternQuoted 11 lines · Alan Stern
Quoted 9 lines · On Fri, 6 Aug 2010 [email protected] wrote:
Quoted 8 lines
Quoted 2 lines
1. the ability to decide to suspend while there are still some 'unimportant' apps running.
While this may be true in some literal sense, it certainly is not the best way to view the situation. Linux already has the ability to suspend (or to decide to suspend) whenever you want. What Android has added is the ability to suspend conditionally, based on whether or not some applications or drivers want to keep the system running.
Quoted 5 lines
Quoted 2 lines
Ok, aside from possibly drivers, what' stopping this from being done on a valilla system today?
Nothing much. Mainly just the fact that Rafael's code is so new. It hasn't yet been integrated into the drivers that should use it.
makes sense.
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Furthermore, this statement leaves out the primary purpose of
wakelocks: to avoid races between suspending and wakeup events. And it also ignores a very important distinction: the difference between drivers and applications. Wakelocks are used by both, but it has been shown that only the wakelocks used by drivers need to be implemented in the kernel -- the others can be implemented entirely in userspace.
Quoted 8 lines
Quoted 3 lines
Ok, this is the first I've heard in this discussion that wakelocks would not be available to userspace. In fact it was explicitly stated that userspace applications called IOCTLs to get/release the wakelock.
Android's wakelock implementation does make wakelocks available to userspace. In Rafael's approach there is nothing comparable. Instead "userspace wakelock"-equivalents have to be handled by a power manager program.
And the question to the Android people is if they consider this acceptable or think that this means that the vanilla can't support them.
Quoted 10 lines
Quoted 9 lines
many of my objections (voiced in another thread) about Android specific features are not relavent if the wakelock in userspace is just part of that application framework and not tied into the kernel.
Quoted 1 line
All of these issues are addressed by Raphael's new
wakeup_eventscode.Ok, then why is there still discussion about wakelocks at all if Raphael has implemnetd the needed kernel functionality and userspace is Android SDK specific?
Quoted 7 lines
This thread started when Paul posted his list of requirements for Android power management (or power management in general). It wasn't really specific to wakelocks, but people brought them up when discussing how those requirements are currently being met.
In fact, it seems to me that _you_ are the person most responsible for prolonging this discussion.
I'll admit to that, but it seems like there is still new information comeing up about the requirements, as well as the current implementation.
Quoted 9 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
If these two features were available, I think that the rest of what they are looking for could be built up without requireing other changes.
They already _are_ available. Admittedly, only since quite recently. (Rafael's new code was accepted during the 2.6.36 merge window.)
Do Brian and Arve agree that this solves their problem?
I think you should ask them instead of asking me.
Since they are following this thread, this was intended to be asking them torespond.
Quoted 11 lines
Quoted 5 lines
to be fair, there have been numerous complaints about suspend being separate from deep sleep long before Android. Linus' blow-up that resulted in Hibernation and Suspend being separated from each other is a case in point. He was making the point that there shouldn't be a difference between the deepest sleep and suspend.
This may be controversial, but I think Rafael will agree when I say that (in this one respect) Linus was wrong. Separating hibernation from suspend makes sense, and I agree that the differences between deepest idle and suspend should be minimized. But to get rid of them altogether would be wrong (and probably not possible anyway).
if you thing the differences should be minimized, why do you think that getting rid of them would be wrong?
I know that Rafael disagrees with Linus, because he has not implemented what Linus suggested.
Quoted 7 lines
Quoted 6 lines
As deep sleep gains the ability to use even less power and as suspend gains the ability to leave things on sometimes, the difference between them is dissapearing. I wouldn't be at all surprised to see them start overlaping soon. So it's not that I think Android should use deep sleeps instead of suspend, but rather that suspend should just be the deepest sleep, one mechanism instead of two.
Quoted 8 lines
I disagree. There are critical differences between them:
Suspend uses the freezer and idle doesn't.
Suspend generally forces devices to go into their low-power states immediately, whereas idle tends to leave unused devices at full power for some time before going to low power (to minimize average latency).
this sounds like policy, not capability.
Quoted 2 lines
Overall, suspend generally has longer latency than idle. (This varies among platforms.)
even different idle modes have different latency
Quoted 1 line
The set of wakeup sources (including timers) is different.
I agree that they are different, but don't they also vary within sleep or suspend as well?
Quoted 2 lines
On some systems, suspend uses platform-specific mechanisms to go into lower power states than are available to idle.
the exact mechanism to go into low-power states is platform specific to start with (there are some very popular platforms admittedly, like the PC ACPI modes)
as I see it
Sleep
a policy engine to decide when to sleep, how deeply to sleep, what to disable, what will wake you up (this includes taking into account desired latency, and the amount of power/time needed to get in and out of the various modes)
platform specific mechanisms for transitioning in and out of the modes.
Suspend
a policy engine to decide when to suspend, what to leave enabled when you supend, what will wake you i[
platform specific mechanisms for transition in and out of suspend. I view use of the freezer to be one of these mechansims.
Somewhere amoung this mess are things like spinning down drives, disabling inactive network interfaces, etc. I don't knwo if those are run from the sleep policy engine, or if there is a third policy engine to decide these things.
why should there be multiple different policy engines making power management decisions? it seems to me like these policy engines can and should be merged, with the resulting engine able to trigger all the existing mechanisms for transitioning between modes.
David Lang
Quoted 48 lines · On Sat, Aug 07, 2010 at 01:17:48PM -0700, [email protected] wrote:
Quoted 40 lines · Paul E. McKenney
Quoted 17 lines · On Sat, Aug 07, 2010 at 03:00:48AM -0700, [email protected] wrote:
Quoted 15 lines · Rafael J. Wysocki
Quoted 4 lines · On Saturday, August 07, 2010, [email protected] wrote:
Quoted 2 lines · Mark Brown
Quoted 1 line · On Fri, Aug 06, 2010 at 04:35:59PM -0700, [email protected] wrote:
On Fri, 6 Aug 2010, Paul E. McKenney wrote:
...
Quoted 8 lines
What we want to have happen in an ideal world is
when the storage isn't needed (between reads) the storage should shutdown to as low a power state as possible.
when the CPU isn't needed (between decoding bursts) the CPU and as much of the system as possible (potentially including some banks of RAM) should shutdown to as low a power state as possible.
Quoted 7 lines
Quoted 2 lines
Unfortunately, the criteria for "not being needed" are not really straightforward and one of the wakelocks' roles is to work around this issue.
if you can ignore the activity caused by the other "unimportant" processes in the system, why is this much different then just the one process running, in which case standard power management sleeps work pretty well.
But isn't the whole point of wakelocks to permit developers to easily and efficiently identify which processes are "unimportant" at a given point in time, thereby allowing them to be ignored?
I understand your position -- you believe that PM-driving applications should be written to remain idle any time that they aren't doing something "important". This is a reasonable position to take, but it is also reasonable to justify your position. Exactly -why- is this better? Here is my evaluation:
o You might not need suspend blockers. This is not totally clear,
and won't be until you actually build a system based on your design.Quoted 5 lines
o You will be requiring that developers of PM-driving applications
deal with more code that must be very carefully coded and validated. This requirement forces the expenditure of lots of people time to save a very small amount of very inexpensive memory (that occupied by the suspend-blocker code).
Quoted 8 lines
the issue isn't avoiding the memory useage, the issue is avoiding the special API requirement that make the userspace code no longer be portable.
note that there are a lot of battery powered embedded devices out there that work just fine without wakelocks. They are able to use the existing idle/sleep and suspend options to get good battery life.
There certainly are such devices, but their power-optimized software is highly non-portable, so I fail to see how this example can possibly support your position. In addition, there are quite a few non-portable Linux extensions to the user-mode API, so your point would not carry in any case.
Quoted 4 lines
The key difference is that Android allows other programs to be loaded on the system, and the current idle/sleep/suspend triggers can't tell the difference between the important software and the other software.
But the suspend blockers can, to the Android guys' point. And something needs to tell the difference. It is not helpful for you to try to hide from this issue.
Quoted 15 lines
Quoted 7 lines
Keep in mind that there was a similar decision in the -rt kernel. One choice was similar to your proposal: all code paths must call
schedule()sufficiently frequently. The other choice was to allow almost all code paths to be preempted, which resembles suspend blockers (preempt_disable()being analogous to acquiring a suspend blocker, andpreempt_enable()being analogous to releasing a suspend blocker).Quoted 7 lines
Then as now, there was much debate. The choice then was preemption. One big reason was that the choice of preemption reduced the amount of real-time-aware code from the entire kernel to only that part of the kernel that disabled preemption, which turned out to greatly simplify the job of meeting aggressive scheduling-latency goals. This experience does add some serious precedent against your position. So, what do you believe is different in the energy-efficiency case?
Quoted 3 lines
for one thing, there was never any thought that any code that would have to have preempt written would ever run anywhere else other than inside the linux kernel.
Portability is for the common-case power-oblivious applications. Even on Android, the power-oblivious applications do not need to use suspend blockers. Suspend blockers are instead used by PM-driving and power-optimized applications. And as you yourself pointed out in an earlier email, the PM-driving and power-optimized applications are in the minority. Furthermore, the suspend-blocker approach allows the bulk of the code in a PM-driving application to be written in a power-oblivious manner, greatly easing its implementation while still providing power-efficient operation.
So again, your point does not carry.
Quoted 3 lines
If you had proposed that userspace be allowed to do preempt_enable/disable calls, it would have been a very different discussion.
There have been proposals that userspace be allowed to disable preemption, and the proposals indeed did not get far. However, the Linux user-kernel API -was- extended to accommodate the underlying need, namely with futexes. And futexes provide an excellent example of a non-portable extension to the Linux user-kernel API.
So, sorry, but again, your point does not carry.
Quoted 4 lines
In the case of real-time applications, we require that things that are given real-time priority be carefully coded to behave well, and that if they depend on things that are not given real-time priority they may not behave as expected.
And therefore real-world applications often are designed to minimize the amount of code that needs real-time privileges, exactly because real-time code is harder to develop than is non-realtime code. In addition, a number of Linux-specific facilities have been used to mitigate the effects of bad behavior by real-time applications.
A similar effect is making itself felt in the power-efficiency arena -- apps minimize the amount of code that must obey the PM-driving rules. Android suspend blockers are one mechanism to carry this minimization further.
Easing development of code is something you would do well to take more seriously.
Quoted 5 lines
Priority Inheritance is a way to
avoid complete system lockup in many cases, but it would still be possible for a badly written real-time app to kill the system if it does something like go into a busy-loop waiting for a file to be created by a non-real-time process.
Just as it is possible for a badly-designed PM-driving app to kill the battery. And this is exactly why most apps are power-oblivious, and further why Android allows PM-driving apps that are not currently holding suspend blockers to be written in a power-oblivious manner. Doing this reduces the opportunity for even PM-driving apps to kill the battery.
Quoted 3 lines
wakelocks are like implementing real-time by allowing userspace to issue
preempt_disable()calls to tell the scheduler not to take the CPU away from them until they make apreempt_enable()call.
Not so. Suspend blockers are actually less dangerous than a thread raising its priority to a real-time level, let alone than the ability to disable preemption at user level.
Quoted 5 lines
In addition wakelocks cannot replace the need to write efficient code. all that wakelocks do is to prevent the system from doing a suspend, you still want to have the code written to not do unneccessary wakeups that would prevent you from using the low-power modes other than suspend.
If you had said "wakelocks cannot -completely- replace the need to write efficient code", I might agree with you. Just as I would agree that a compiler cannot -completely- replace the need to write assembly from time to time. This is no more an argument against suspend blockers (or something like them) than the occasional need to write assembly is an argument against compilers.
Quoted 2 lines
On the other hand, it _is_ possible for
the idle/sleep states to be extended to also cover suspend.
Nice try, but please take a look at any of the prior discussion of how idle and suspend differ, and then feel free to try again.
Quoted 29 lines
Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
today there are two ways of this happening, via the idle approach (on everything except Android), or via suspend (on Android)
Given that many platforms cannot go to into suspend while still playing audio, the idle approach is not going to be able to be eliminated (and in fact will be the most common approach to be used/deugged in terms of the types of platforms), it seems to me that there may be a significant amount of value in seeing if there is a way to change Android to use this approach as well instead of having two different systems competing to do the same job.
Quoted 8 lines
Quoted 3 lines
There is a fundamental obstacle to that, though. Namely, the Android developers say that the idle-based approach doesn't lead to sufficient energy savings due to periodic timers and "polling applications".
polling applications can be solved by deciding that they aren't going to be allowed to affect the power management decision (don't consider their CPU useage when deciding to go to sleep, don't consider their timers when deciding when to wake back up)
Quoted 8 lines
Agreed, and the focus is on how one decides which applications need to be considered. After all, the activity of a highly optimized audio-playback application looks exactly like that of a stupid polling application -- they both periodically consume some CPU. But this is something that you and the Android guys are actually agreeing about. You are only arguing about exactly what mechanism should be used to make this determination. The Android guys want suspend blockers, and you want to extend cgroups.
Quoted 11 lines
I want the kernel to be explicitly told that this application is important (or alternativly that these other applications are not). I suggested cgroups as a possible way to do this, but anything that could tell the kernel what processes to care about and what ones to not care about would work. My initial thought had actually been to do something like echo the pid of important processes into a /proc or /sys file, but I was under the impression that there were a lot of processes that would get this state and therefore a more general tool like cgroups (which as I understand it automatically puts children of a process into the same cgroup as the parent) seemed moreuseful
Again, the Android guys just use a different mechanism. So, as I said in my earlier email, that the next step for you is to implement your approach so that it can be compared in terms of energy efficiency, code size, intrusiveness, performance, and compatibility with existing code.
Please keep in mind that the Android guys really do have code that works in production, which, despite real and perceived imperfections, carries serious weight. Rafael and Alan have some code that meets some but apparently not all of the Android guys' requirements. You have some serious work to do if you want to catch up to them.
I am sorry, but until you actually have something credible running, I have to place much more weight on Arve's, Brian's, Rafael's, and Alan's opinions than on yours.
Quoted 14 lines
Quoted 14 lines
So I believe that the next step for you is to implement your approach so that it can be compared in terms of energy efficiency, code size, intrusiveness, performance, and compatibility with existing code.
Quoted 9 lines
Quoted 5 lines
Technically that
boils down to the interrupt sources that remain active in the idle-based case and that are shut down during suspend. If you found a way to deactivate all of them from the idle context in a non-racy fashion, that would probably satisfy the Android's needs too.well, we already have similar capibility for other peripherals (I keep pointing to drive spin down as an example), the key to avoiding the races seems to be in the drivers supporting this.
Quoted 8 lines
Quoted 4 lines
The difference is that the CPU stays active in the drive spin down case -- if the drive turns out to be needed, the CPU can spin it up. The added complication in the suspend case is that the CPU goes away, so that you must more carefully plan for all of the power-up cases.
I agree tha the power down and restart needs to be planned, but it's not like you are going to wake up the drive (or the audio hardware0 without waking up the CPU first.
On servers, desktops, and laptops, agreed. In contrast, the embedded guys have facilities that allows hardware to activate without the CPU being active at the time. So there is a difference.
Quoted 4 lines
even with idle sleep modes and drive spin-down there is no provision for the drive to be restarted if the CPU is asleep, you first have something happen that wakes up the CPU and it then wakes up the drive. This same approach should work for other things.
It will indeed work, but it can be quite energy inefficient, given the capabilities of embedded hardware.
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
the fact that Android is making it possible for suspend to selectivly avoid disabling them makes me think that a lot of the work needed to make this happen has probably been done. look at what would happen in a suspend if it decided to leave everything else on and just disable the one thing, that should e the same thing that happens if you are just disabling that one thing for idle sleep.
Quoted 6 lines
Quoted 2 lines
We already covered the differences between suspend and idle, now didn't we? ;-)
we did, however at the time suspend was to stop everything, now we are finding that Android has multiple flavors of suspend, one of which stops everything, the others leave some things running.
Suspend never has stopped the time-of-day clock, so Android's approach is nothing new. Besides, in the embedded world, the ability to leave other types of hardware running during a suspend long predates Android. It might well be new to you, but it is not at all new.
Thanx, Paul
Quoted 48 lines · On Sat, Aug 07, 2010 at 01:17:48PM -0700, [email protected] wrote:
Quoted 40 lines · Paul E. McKenney
Quoted 17 lines · On Sat, Aug 07, 2010 at 03:00:48AM -0700, [email protected] wrote:
Quoted 15 lines · Rafael J. Wysocki
Quoted 4 lines · On Saturday, August 07, 2010, [email protected] wrote:
Quoted 2 lines · Mark Brown
Quoted 1 line · On Fri, Aug 06, 2010 at 04:35:59PM -0700, [email protected] wrote:
On Fri, 6 Aug 2010, Paul E. McKenney wrote:
...
Quoted 8 lines
What we want to have happen in an ideal world is
when the storage isn't needed (between reads) the storage should shutdown to as low a power state as possible.
when the CPU isn't needed (between decoding bursts) the CPU and as much of the system as possible (potentially including some banks of RAM) should shutdown to as low a power state as possible.
Quoted 7 lines
Quoted 2 lines
Unfortunately, the criteria for "not being needed" are not really straightforward and one of the wakelocks' roles is to work around this issue.
if you can ignore the activity caused by the other "unimportant" processes in the system, why is this much different then just the one process running, in which case standard power management sleeps work pretty well.
But isn't the whole point of wakelocks to permit developers to easily and efficiently identify which processes are "unimportant" at a given point in time, thereby allowing them to be ignored?
I understand your position -- you believe that PM-driving applications should be written to remain idle any time that they aren't doing something "important". This is a reasonable position to take, but it is also reasonable to justify your position. Exactly -why- is this better? Here is my evaluation:
o You might not need suspend blockers. This is not totally clear,
and won't be until you actually build a system based on your design.Quoted 5 lines
o You will be requiring that developers of PM-driving applications
deal with more code that must be very carefully coded and validated. This requirement forces the expenditure of lots of people time to save a very small amount of very inexpensive memory (that occupied by the suspend-blocker code).
Quoted 8 lines
the issue isn't avoiding the memory useage, the issue is avoiding the special API requirement that make the userspace code no longer be portable.
note that there are a lot of battery powered embedded devices out there that work just fine without wakelocks. They are able to use the existing idle/sleep and suspend options to get good battery life.
There certainly are such devices, but their power-optimized software is highly non-portable, so I fail to see how this example can possibly support your position. In addition, there are quite a few non-portable Linux extensions to the user-mode API, so your point would not carry in any case.
Quoted 4 lines
The key difference is that Android allows other programs to be loaded on the system, and the current idle/sleep/suspend triggers can't tell the difference between the important software and the other software.
But the suspend blockers can, to the Android guys' point. And something needs to tell the difference. It is not helpful for you to try to hide from this issue.
Quoted 15 lines
Quoted 7 lines
Keep in mind that there was a similar decision in the -rt kernel. One choice was similar to your proposal: all code paths must call
schedule()sufficiently frequently. The other choice was to allow almost all code paths to be preempted, which resembles suspend blockers (preempt_disable()being analogous to acquiring a suspend blocker, andpreempt_enable()being analogous to releasing a suspend blocker).Quoted 7 lines
Then as now, there was much debate. The choice then was preemption. One big reason was that the choice of preemption reduced the amount of real-time-aware code from the entire kernel to only that part of the kernel that disabled preemption, which turned out to greatly simplify the job of meeting aggressive scheduling-latency goals. This experience does add some serious precedent against your position. So, what do you believe is different in the energy-efficiency case?
Quoted 3 lines
for one thing, there was never any thought that any code that would have to have preempt written would ever run anywhere else other than inside the linux kernel.
Portability is for the common-case power-oblivious applications. Even on Android, the power-oblivious applications do not need to use suspend blockers. Suspend blockers are instead used by PM-driving and power-optimized applications. And as you yourself pointed out in an earlier email, the PM-driving and power-optimized applications are in the minority. Furthermore, the suspend-blocker approach allows the bulk of the code in a PM-driving application to be written in a power-oblivious manner, greatly easing its implementation while still providing power-efficient operation.
So again, your point does not carry.
Quoted 3 lines
If you had proposed that userspace be allowed to do preempt_enable/disable calls, it would have been a very different discussion.
There have been proposals that userspace be allowed to disable preemption, and the proposals indeed did not get far. However, the Linux user-kernel API -was- extended to accommodate the underlying need, namely with futexes. And futexes provide an excellent example of a non-portable extension to the Linux user-kernel API.
So, sorry, but again, your point does not carry.
Quoted 4 lines
In the case of real-time applications, we require that things that are given real-time priority be carefully coded to behave well, and that if they depend on things that are not given real-time priority they may not behave as expected.
And therefore real-world applications often are designed to minimize the amount of code that needs real-time privileges, exactly because real-time code is harder to develop than is non-realtime code. In addition, a number of Linux-specific facilities have been used to mitigate the effects of bad behavior by real-time applications.
A similar effect is making itself felt in the power-efficiency arena -- apps minimize the amount of code that must obey the PM-driving rules. Android suspend blockers are one mechanism to carry this minimization further.
Easing development of code is something you would do well to take more seriously.
Quoted 5 lines
Priority Inheritance is a way to
avoid complete system lockup in many cases, but it would still be possible for a badly written real-time app to kill the system if it does something like go into a busy-loop waiting for a file to be created by a non-real-time process.
Just as it is possible for a badly-designed PM-driving app to kill the battery. And this is exactly why most apps are power-oblivious, and further why Android allows PM-driving apps that are not currently holding suspend blockers to be written in a power-oblivious manner. Doing this reduces the opportunity for even PM-driving apps to kill the battery.
Quoted 3 lines
wakelocks are like implementing real-time by allowing userspace to issue
preempt_disable()calls to tell the scheduler not to take the CPU away from them until they make apreempt_enable()call.
Not so. Suspend blockers are actually less dangerous than a thread raising its priority to a real-time level, let alone than the ability to disable preemption at user level.
Quoted 5 lines
In addition wakelocks cannot replace the need to write efficient code. all that wakelocks do is to prevent the system from doing a suspend, you still want to have the code written to not do unneccessary wakeups that would prevent you from using the low-power modes other than suspend.
If you had said "wakelocks cannot -completely- replace the need to write efficient code", I might agree with you. Just as I would agree that a compiler cannot -completely- replace the need to write assembly from time to time. This is no more an argument against suspend blockers (or something like them) than the occasional need to write assembly is an argument against compilers.
Quoted 2 lines
On the other hand, it _is_ possible for
the idle/sleep states to be extended to also cover suspend.
Nice try, but please take a look at any of the prior discussion of how idle and suspend differ, and then feel free to try again.
Quoted 29 lines
Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
today there are two ways of this happening, via the idle approach (on everything except Android), or via suspend (on Android)
Given that many platforms cannot go to into suspend while still playing audio, the idle approach is not going to be able to be eliminated (and in fact will be the most common approach to be used/deugged in terms of the types of platforms), it seems to me that there may be a significant amount of value in seeing if there is a way to change Android to use this approach as well instead of having two different systems competing to do the same job.
Quoted 8 lines
Quoted 3 lines
There is a fundamental obstacle to that, though. Namely, the Android developers say that the idle-based approach doesn't lead to sufficient energy savings due to periodic timers and "polling applications".
polling applications can be solved by deciding that they aren't going to be allowed to affect the power management decision (don't consider their CPU useage when deciding to go to sleep, don't consider their timers when deciding when to wake back up)
Quoted 8 lines
Agreed, and the focus is on how one decides which applications need to be considered. After all, the activity of a highly optimized audio-playback application looks exactly like that of a stupid polling application -- they both periodically consume some CPU. But this is something that you and the Android guys are actually agreeing about. You are only arguing about exactly what mechanism should be used to make this determination. The Android guys want suspend blockers, and you want to extend cgroups.
Quoted 11 lines
I want the kernel to be explicitly told that this application is important (or alternativly that these other applications are not). I suggested cgroups as a possible way to do this, but anything that could tell the kernel what processes to care about and what ones to not care about would work. My initial thought had actually been to do something like echo the pid of important processes into a /proc or /sys file, but I was under the impression that there were a lot of processes that would get this state and therefore a more general tool like cgroups (which as I understand it automatically puts children of a process into the same cgroup as the parent) seemed moreuseful
Again, the Android guys just use a different mechanism. So, as I said in my earlier email, that the next step for you is to implement your approach so that it can be compared in terms of energy efficiency, code size, intrusiveness, performance, and compatibility with existing code.
Please keep in mind that the Android guys really do have code that works in production, which, despite real and perceived imperfections, carries serious weight. Rafael and Alan have some code that meets some but apparently not all of the Android guys' requirements. You have some serious work to do if you want to catch up to them.
I am sorry, but until you actually have something credible running, I have to place much more weight on Arve's, Brian's, Rafael's, and Alan's opinions than on yours.
Quoted 14 lines
Quoted 14 lines
So I believe that the next step for you is to implement your approach so that it can be compared in terms of energy efficiency, code size, intrusiveness, performance, and compatibility with existing code.
Quoted 9 lines
Quoted 5 lines
Technically that
boils down to the interrupt sources that remain active in the idle-based case and that are shut down during suspend. If you found a way to deactivate all of them from the idle context in a non-racy fashion, that would probably satisfy the Android's needs too.well, we already have similar capibility for other peripherals (I keep pointing to drive spin down as an example), the key to avoiding the races seems to be in the drivers supporting this.
Quoted 8 lines
Quoted 4 lines
The difference is that the CPU stays active in the drive spin down case -- if the drive turns out to be needed, the CPU can spin it up. The added complication in the suspend case is that the CPU goes away, so that you must more carefully plan for all of the power-up cases.
I agree tha the power down and restart needs to be planned, but it's not like you are going to wake up the drive (or the audio hardware0 without waking up the CPU first.
On servers, desktops, and laptops, agreed. In contrast, the embedded guys have facilities that allows hardware to activate without the CPU being active at the time. So there is a difference.
Quoted 4 lines
even with idle sleep modes and drive spin-down there is no provision for the drive to be restarted if the CPU is asleep, you first have something happen that wakes up the CPU and it then wakes up the drive. This same approach should work for other things.
It will indeed work, but it can be quite energy inefficient, given the capabilities of embedded hardware.
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
the fact that Android is making it possible for suspend to selectivly avoid disabling them makes me think that a lot of the work needed to make this happen has probably been done. look at what would happen in a suspend if it decided to leave everything else on and just disable the one thing, that should e the same thing that happens if you are just disabling that one thing for idle sleep.
Quoted 6 lines
Quoted 2 lines
We already covered the differences between suspend and idle, now didn't we? ;-)
we did, however at the time suspend was to stop everything, now we are finding that Android has multiple flavors of suspend, one of which stops everything, the others leave some things running.
Suspend never has stopped the time-of-day clock, so Android's approach is nothing new. Besides, in the embedded world, the ability to leave other types of hardware running during a suspend long predates Android. It might well be new to you, but it is not at all new.
Thanx, Paul
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Paul E. McKenneyQuoted 40 lines · Paul E. McKenney
Quoted 22 lines · On Sat, Aug 07, 2010 at 02:38:35AM -0700, [email protected] wrote:
Quoted 10 lines · Ted Ts'o
On Fri, Aug 06, 2010 at 08:14:09PM -0700, [email protected] wrote:
So the real key here is to take most applications, which may be written using techniques that might be considered well written from a laptop point of view, but not for a cell phone, and not require modifications. Even though the application writer might think it's doing well by waking up every 15 seconds, if the laptop lid is down, or if the screen is off, for **most** applications, it should be forcibly put to sleep.
Quoted 9 lines
It's only the rare applications that should really be allowed to run while screen is off. And it's only those applications that need modifications to use suspend blocker. From your earlier comments, it seems that this is the key point which you are missing. (No doubt, some of these applications that do need to know about suspend blockers are important ones; ones that make sure the battery isn't about to blow up, or ones which silently wake up every 10-15 minutes to pull down fresh mail for you from your mail server. But those applications are the exception, not the rule.)
Quoted 4 lines
the question is what it takes to make an application privilaged like this.
what I proposed was to make it possible for the user/admin to select what applications are allowed to keep the system awake.
The Android guys do the same.
Quoted 2 lines
wakelocks require that the application developer decide that they want to keep the system awake as well as the user/admin
Whereas you require that the application developer redesign/rewrite applications to decide when to keep the system awake, e.g., by carefully determining when to idle themselves. The difference is that the Android developer need only release a suspend blocker. In contrast, you are requiring that the developer rewrite all the code that follows the point where the Android developer would release a suspend blocker.
Quoted 2 lines
Your way seems to require that the developer do more work for the same result. Why?
portability, and the fact that it will save more power even when the system is prevented from suspending.
Quoted 12 lines
Quoted 12 lines
take your example of a mail client waking up every 15 min.
with Android it needs to be privilaged to grab the wakelock while fetching the mail, it also needs to use a privilaged API to set the wakeups to wake it up at those times.
with what I proposed all you need to do is to tag the application as power privilaged and then if the application sleeps for 15 min between doing thing the system will wake up every 15 min, work for a short time, then go back to sleep.
Quoted 8 lines
Quoted 5 lines
if you want to put everything to sleep when the screen blanks, that's trivial to do.
the fun starts when you want to say that there are some things you don't want to put to sleep.
Which is in fact a critical requirement that you appear to have been ignoring in your words above.
I admit that the way I wrote this is confusing, but I don't think I am ignoring this requirement. the example above was how an application that the system is not wanting to put to sleep would run with the two mechansims.
Quoted 11 lines
Quoted 11 lines
do you let some processes run while halting others?
in which case how do you prevent deadlocks?
on the other hand, sleeping again is simple, you sleep when
there is nothing more to run
or do you let wasteful processes run while you are awake?
this avoids deadlocks, but how do you decide when to sleep again?Android approaches this by requiring that any program that a user may want to keep running must be modified to use wakelocks.
Quoted 8 lines
Quoted 2 lines
My suggestion was that the system ignore other processes when deciding if the system is idle enough to put to sleep.
But your suggestion seems to require quite a bit more coding effort for little gain. The Android developer can just release a suspend blocker, and in contrast, a developer using your proposal needs to rewrite all the code following the point at which the Android developer released the suspend blocker. So why are you saying that your is approach better? ;-)
no, the coder needs to make his code not do unnessasary things. Even with a wakelock this is needed for the system to be able to use lower power modes while the system is not going to do a suspend anyway.
I am say that if the coder does that, the coder should not also have to code in wakelocks.
I want it to be as easy as possible to port applications between mobile platforms. On most platforms wakelocks are not needed because standard idle/sleep/suspend mechanisms are good enough. Android allows other applications to run that confuse the idle/sleep/suspend mechanisms, so something needs to be done to cut through the confusion. Android does this by creating a new API to control this, I'm suggesting that there should be a way to tell the system to ignore the other applications so that the existing mechanisms can make good decisions again.
David Lang
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Paul E. McKenneyQuoted 5 lines · Paul E. McKenney
o "Ill-behaved application" AKA "untrusted application" AKA "crappy application".
o "PM-driving application" are applications that are permitted to acquire suspend blockers on Android.
These definitions are wrong.
1) There are trusted applications that misbehave (the user clicks Yes when asked about PM permissions)
2) There are untrusted applications that are power optimized (The user clicks No)
The proponents of suspend blockers in user-space have tried to ignore this fact, but the truth is that PM permissions and power optimization are orthogonal to each other.
Signature · 5 lines
Felipe Contreras _______________________________________________ linux-pm mailing list [email protected] https://lists.linux-foundation.org/mailman/listinfo/linux-pm
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Paul E. McKenneyQuoted 5 lines · Paul E. McKenney
o "Ill-behaved application" AKA "untrusted application" AKA "crappy application".
o "PM-driving application" are applications that are permitted to acquire suspend blockers on Android.
These definitions are wrong.
1) There are trusted applications that misbehave (the user clicks Yes when asked about PM permissions)
2) There are untrusted applications that are power optimized (The user clicks No)
The proponents of suspend blockers in user-space have tried to ignore this fact, but the truth is that PM permissions and power optimization are orthogonal to each other.
Signature · 1 line
Felipe Contreras
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Ted Ts'oQuoted 8 lines · Ted Ts'o
Quoted 1 line · On Fri, Aug 06, 2010 at 08:14:09PM -0700, [email protected] wrote:
1. sleeping can't currently save as much power as suspending
No, I don't think that's the case at all. The key thing here is that *most* applications don't need to be modified to use suspend locks, because even though they might be in an event loop, when the user user turns off the display, the user generally doesn't want it doing things on their behalf.
You are overgeneralizing; there are many applications that run in the background, and you want to keep them running even when the display is off.
You seen to be concentrating on UI-only applications, for those it's worth noting that Android provides separate mechanisms for power saving. Since Android doesn't have true multi-tasking, the applications must serialize their states so that the next time they are opened they seem to have not been closed. So, the current active UI application can be closed while turning off the display, and re-opened later.
User-space suspend blockers are relevant for background services, and as it has been discussed before; suspend blockers (not activating them) might actually degrade power usage.
Signature · 5 lines
Felipe Contreras _______________________________________________ linux-pm mailing list [email protected] https://lists.linux-foundation.org/mailman/listinfo/linux-pm
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Ted Ts'oQuoted 8 lines · Ted Ts'o
Quoted 1 line · On Fri, Aug 06, 2010 at 08:14:09PM -0700, [email protected] wrote:
1. sleeping can't currently save as much power as suspending
No, I don't think that's the case at all. The key thing here is that *most* applications don't need to be modified to use suspend locks, because even though they might be in an event loop, when the user user turns off the display, the user generally doesn't want it doing things on their behalf.
You are overgeneralizing; there are many applications that run in the background, and you want to keep them running even when the display is off.
You seen to be concentrating on UI-only applications, for those it's worth noting that Android provides separate mechanisms for power saving. Since Android doesn't have true multi-tasking, the applications must serialize their states so that the next time they are opened they seem to have not been closed. So, the current active UI application can be closed while turning off the display, and re-opened later.
User-space suspend blockers are relevant for background services, and as it has been discussed before; suspend blockers (not activating them) might actually degrade power usage.
Signature · 1 line
Felipe Contreras
Quoted 20 lines · Ted Ts'o
Quoted 3 lines · On Fri, Aug 06, 2010 at 06:00:34PM -0700, [email protected] wrote:
today there are two ways of this happening, via the idle approach (on everything except Android), or via suspend (on Android)
Most other devices use a lot more power at idle; in some cases it's because the hardware just isn't as power optimized (why bother, when you have 94,000 mWh of power at your disposal with a 6 cell laptop battery, as opposed to the 800-1000 mWh that you might have on a cell phone battery). In other cases, it's because the kernel and the low-level software stack (never mind the applications) are waking up the CPU too darned often --- in other words, idle simply isn't idle enough.
So you may want to consider whether part of the problem is that general purpose Linux systems need a radical redesign to get power utilization down to those sorts of levels --- where the CPU might only be waking up once every half-hour or so, and then only do actual useful work.
Quoted 4 lines
Can you get there by assuming that every single application is competently written? In an idle approach, you have to. That way lies Maemo, where installing just one bad application will cut your battery life time by a factor of 2-3.
Exactly the same happens on Android.
Install one bad application, a request for PM permissions is made, you click Yes. There's no difference at all.
Quoted 7 lines
You could try stopping processes by
using kill -STOP, but this at that point, you've moved into Android strategy of "suspend". And the only question is what is the most efficient way to allow the system to run when there is true work that needs to be done, and how to avoid deadlocks by stopping processes that might be holding user space locks --- and to administer when and how to suspend the processes.
No. You are assuming that PM permissions will be magically set appropriately; that's not the case.
1) Install a bad application that requests PM permissions and is granted those
In this case you've gained nothing with user-space suspend blockers.
2) Install a good application that is not requesting PM permissions (or is denied them)
Imagine this application requires expensive initialization, but afterwards it only needs to send a small packet each minute to a server. If this application forgets to request PM permission (or is denied them), then it might miss the 1 minute mark, and would have to re-initialize when a trusted app starts some work.
In this case suspend blockers cause more battery drain (and the application to behave poorly).
There's only one case when suspend blockers might actually help:
a) The application is badly written (most probably a UI app drawing when it shouldn't, which incidentally is not a problem in Android since it's not multi-tasking)
b) The application is either not requesting, or denied PM permissions
c) The application is not affected too badly if it's not running all the time (piggy-backing on trusted apps is ok)
For that it's much better to have a different strategy: all applications are trusted, bad applications must be manually tagged. Also, instead of having each and every user figure out which are the bad apps, such information is more pertinent in the app store, where users could vote when an app is bad PM-use or not; crowd-sourcing the problem.
But guess what; once you have an app store system that can detect when an application is badly written, why would you expose the users to such bad apps?
In Maemo, 3rd party applications have to go trough a community review (maemo.org extras testing) before they go into the main repository, and this way bad applications (functionality or PM-wise) don't make it to the general public.
Also, on mobile phones in general there are 3 kinds of applications.
1) desktop widgets: by far the ones with the most danger of drawing the battery
2) foreground UI apps: also have some danger, but only on multi-tasking systems (not Android)
3) background services: usually don't do unnecessary work
Suspend blockers are mostly useful for 1), but desktop widgets are platform-specific, so they are written for embedded anyway, and if you are writing for embedded, there's no point in relying on suspend-blockers; just write it PM optimized.
Signature · 5 lines
Felipe Contreras _______________________________________________ linux-pm mailing list [email protected] https://lists.linux-foundation.org/mailman/listinfo/linux-pm
Quoted 20 lines · Ted Ts'o
Quoted 3 lines · On Fri, Aug 06, 2010 at 06:00:34PM -0700, [email protected] wrote:
today there are two ways of this happening, via the idle approach (on everything except Android), or via suspend (on Android)
Most other devices use a lot more power at idle; in some cases it's because the hardware just isn't as power optimized (why bother, when you have 94,000 mWh of power at your disposal with a 6 cell laptop battery, as opposed to the 800-1000 mWh that you might have on a cell phone battery). In other cases, it's because the kernel and the low-level software stack (never mind the applications) are waking up the CPU too darned often --- in other words, idle simply isn't idle enough.
So you may want to consider whether part of the problem is that general purpose Linux systems need a radical redesign to get power utilization down to those sorts of levels --- where the CPU might only be waking up once every half-hour or so, and then only do actual useful work.
Quoted 4 lines
Can you get there by assuming that every single application is competently written? In an idle approach, you have to. That way lies Maemo, where installing just one bad application will cut your battery life time by a factor of 2-3.
Exactly the same happens on Android.
Install one bad application, a request for PM permissions is made, you click Yes. There's no difference at all.
Quoted 7 lines
You could try stopping processes by
using kill -STOP, but this at that point, you've moved into Android strategy of "suspend". And the only question is what is the most efficient way to allow the system to run when there is true work that needs to be done, and how to avoid deadlocks by stopping processes that might be holding user space locks --- and to administer when and how to suspend the processes.
No. You are assuming that PM permissions will be magically set appropriately; that's not the case.
1) Install a bad application that requests PM permissions and is granted those
In this case you've gained nothing with user-space suspend blockers.
2) Install a good application that is not requesting PM permissions (or is denied them)
Imagine this application requires expensive initialization, but afterwards it only needs to send a small packet each minute to a server. If this application forgets to request PM permission (or is denied them), then it might miss the 1 minute mark, and would have to re-initialize when a trusted app starts some work.
In this case suspend blockers cause more battery drain (and the application to behave poorly).
There's only one case when suspend blockers might actually help:
a) The application is badly written (most probably a UI app drawing when it shouldn't, which incidentally is not a problem in Android since it's not multi-tasking)
b) The application is either not requesting, or denied PM permissions
c) The application is not affected too badly if it's not running all the time (piggy-backing on trusted apps is ok)
For that it's much better to have a different strategy: all applications are trusted, bad applications must be manually tagged. Also, instead of having each and every user figure out which are the bad apps, such information is more pertinent in the app store, where users could vote when an app is bad PM-use or not; crowd-sourcing the problem.
But guess what; once you have an app store system that can detect when an application is badly written, why would you expose the users to such bad apps?
In Maemo, 3rd party applications have to go trough a community review (maemo.org extras testing) before they go into the main repository, and this way bad applications (functionality or PM-wise) don't make it to the general public.
Also, on mobile phones in general there are 3 kinds of applications.
1) desktop widgets: by far the ones with the most danger of drawing the battery
2) foreground UI apps: also have some danger, but only on multi-tasking systems (not Android)
3) background services: usually don't do unnecessary work
Suspend blockers are mostly useful for 1), but desktop widgets are platform-specific, so they are written for embedded anyway, and if you are writing for embedded, there's no point in relying on suspend-blockers; just write it PM optimized.
Signature · 1 line
Felipe Contreras
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to [email protected]Quoted 8 lines · On Sat, 7 Aug 2010 [email protected] wrote:
Quoted 5 lines
This may be controversial, but I think Rafael will agree when I say that (in this one respect) Linus was wrong. Separating hibernation from suspend makes sense, and I agree that the differences between deepest idle and suspend should be minimized. But to get rid of them altogether would be wrong (and probably not possible anyway).
if you thing the differences should be minimized, why do you think that getting rid of them would be wrong?
Actually I meant that _attempting_ to get rid of them would be wrong, because it would be a futile attempt to carry out an impossible task.
Quoted 9 lines
Quoted 9 lines
Quoted 6 lines
As deep sleep gains the ability to use even less power and as suspend gains the ability to leave things on sometimes, the difference between them is dissapearing. I wouldn't be at all surprised to see them start overlaping soon. So it's not that I think Android should use deep sleeps instead of suspend, but rather that suspend should just be the deepest sleep, one mechanism instead of two.
I disagree. There are critical differences between them:
Quoted 8 lines
Quoted 6 lines
Suspend uses the freezer and idle doesn't.
Suspend generally forces devices to go into their low-power states immediately, whereas idle tends to leave unused devices at full power for some time before going to low power (to minimize average latency).
this sounds like policy, not capability.
It isn't. Suspend does not have the capability to leave a device at full power for 100 ms and then switch it to low power if it hasn't been used in that time. (Or, it requires special hardware support to be able to do this.) Idle does have this capability.
Quoted 4 lines
Quoted 2 lines
Overall, suspend generally has longer latency than idle. (This varies among platforms.)
even different idle modes have different latency
But the difference between idle and suspend can be orders of magnitude larger. That makes it qualitatively different, not just quantitatively different.
Quoted 4 lines
Quoted 1 line
The set of wakeup sources (including timers) is different.
I agree that they are different, but don't they also vary within sleep or suspend as well?
Suspend _is_ a form of sleep. (The other form is hibernation.) It's true that the set of wakeup sources can be customized to some extent. But in the usual implementations, timers are never a wakeup source for suspend whereas they always are for idle.
Quoted 6 lines
Quoted 2 lines
On some systems, suspend uses platform-specific mechanisms to go into lower power states than are available to idle.
the exact mechanism to go into low-power states is platform specific to start with (there are some very popular platforms admittedly, like the PC ACPI modes)
Sure, the mechanism is platform-specific. That doesn't change the fact that ACPI systems can achieve lower power usage with suspend than they can with idle.
Quoted 3 lines
as I see it
Sleep
Do you mean "idle" or "deep-idle" rather than "sleep"?
Quoted 5 lines
a policy engine to decide when to sleep, how deeply to sleep, what to disable, what will wake you up (this includes taking into account desired latency, and the amount of power/time needed to get in and out of the various modes)
Quoted 7 lines
platform specific mechanisms for transitioning in and out of the modes.
Suspend
a policy engine to decide when to suspend, what to leave enabled when you supend, what will wake you i[
Suspend is initiated entirely by userspace, not by the kernel. Wakelocks provide a means for the kernel to delay or cancel a suspend request, not to initiate one.
Quoted 2 lines
platform specific mechanisms for transition in and out of suspend. I view use of the freezer to be one of these mechansims.
The freezer is not platform specific.
Quoted 10 lines
Somewhere amoung this mess are things like spinning down drives, disabling inactive network interfaces, etc. I don't knwo if those are run from the sleep policy engine, or if there is a third policy engine to decide these things.
why should there be multiple different policy engines making power management decisions? it seems to me like these policy engines can and should be merged, with the resulting engine able to trigger all the existing mechanisms for transitioning between modes.
There are multiple policy engines because one of them is in the kernel and the other is in userspace. I don't see how you can merge the two.
Alan Stern
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to [email protected]Quoted 8 lines · On Sat, 7 Aug 2010 [email protected] wrote:
Quoted 5 lines
This may be controversial, but I think Rafael will agree when I say that (in this one respect) Linus was wrong. Separating hibernation from suspend makes sense, and I agree that the differences between deepest idle and suspend should be minimized. But to get rid of them altogether would be wrong (and probably not possible anyway).
if you thing the differences should be minimized, why do you think that getting rid of them would be wrong?
Actually I meant that _attempting_ to get rid of them would be wrong, because it would be a futile attempt to carry out an impossible task.
Quoted 9 lines
Quoted 9 lines
Quoted 6 lines
As deep sleep gains the ability to use even less power and as suspend gains the ability to leave things on sometimes, the difference between them is dissapearing. I wouldn't be at all surprised to see them start overlaping soon. So it's not that I think Android should use deep sleeps instead of suspend, but rather that suspend should just be the deepest sleep, one mechanism instead of two.
I disagree. There are critical differences between them:
Quoted 8 lines
Quoted 6 lines
Suspend uses the freezer and idle doesn't.
Suspend generally forces devices to go into their low-power states immediately, whereas idle tends to leave unused devices at full power for some time before going to low power (to minimize average latency).
this sounds like policy, not capability.
It isn't. Suspend does not have the capability to leave a device at full power for 100 ms and then switch it to low power if it hasn't been used in that time. (Or, it requires special hardware support to be able to do this.) Idle does have this capability.
Quoted 4 lines
Quoted 2 lines
Overall, suspend generally has longer latency than idle. (This varies among platforms.)
even different idle modes have different latency
But the difference between idle and suspend can be orders of magnitude larger. That makes it qualitatively different, not just quantitatively different.
Quoted 4 lines
Quoted 1 line
The set of wakeup sources (including timers) is different.
I agree that they are different, but don't they also vary within sleep or suspend as well?
Suspend _is_ a form of sleep. (The other form is hibernation.) It's true that the set of wakeup sources can be customized to some extent. But in the usual implementations, timers are never a wakeup source for suspend whereas they always are for idle.
Quoted 6 lines
Quoted 2 lines
On some systems, suspend uses platform-specific mechanisms to go into lower power states than are available to idle.
the exact mechanism to go into low-power states is platform specific to start with (there are some very popular platforms admittedly, like the PC ACPI modes)
Sure, the mechanism is platform-specific. That doesn't change the fact that ACPI systems can achieve lower power usage with suspend than they can with idle.
Quoted 3 lines
as I see it
Sleep
Do you mean "idle" or "deep-idle" rather than "sleep"?
Quoted 5 lines
a policy engine to decide when to sleep, how deeply to sleep, what to disable, what will wake you up (this includes taking into account desired latency, and the amount of power/time needed to get in and out of the various modes)
Quoted 7 lines
platform specific mechanisms for transitioning in and out of the modes.
Suspend
a policy engine to decide when to suspend, what to leave enabled when you supend, what will wake you i[
Suspend is initiated entirely by userspace, not by the kernel. Wakelocks provide a means for the kernel to delay or cancel a suspend request, not to initiate one.
Quoted 2 lines
platform specific mechanisms for transition in and out of suspend. I view use of the freezer to be one of these mechansims.
The freezer is not platform specific.
Quoted 10 lines
Somewhere amoung this mess are things like spinning down drives, disabling inactive network interfaces, etc. I don't knwo if those are run from the sleep policy engine, or if there is a third policy engine to decide these things.
why should there be multiple different policy engines making power management decisions? it seems to me like these policy engines can and should be merged, with the resulting engine able to trigger all the existing mechanisms for transitioning between modes.
There are multiple policy engines because one of them is in the kernel and the other is in userspace. I don't see how you can merge the two.
Alan Stern
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Felipe ContrerasQuoted 4 lines · Felipe Contreras
You are overgeneralizing; there are many applications that run in the background, and you want to keep them running even when the display is off.
Really? How many do you really expect will be running at the same time on a mobile platform with a 800-1000 mWh battery? And what percentage of the applications that might be in a Android or Moblin or Maemo app store will have things running in the background? 10%? 20%? 50%? 80%?
Quoted 7 lines
You seen to be concentrating on UI-only applications, for those it's worth noting that Android provides separate mechanisms for power saving. Since Android doesn't have true multi-tasking, the applications must serialize their states so that the next time they are opened they seem to have not been closed. So, the current active UI application can be closed while turning off the display, and re-opened later.
Actually in practice, the process or processes which comprise current active UI application generally won't actually be killed when you turn off the display. It *might* happen, if one of the rare backround applications needs more memory than is available without closing some of the more recently open applications. In practice, the last 2-3 most recently used applications are still loaded in memory so you can switch back and forth between them simply and easily. It is true they have to be ready to be killed at any time in case their memory is needed for the currently active application, but that generally does't happen right away. The design is to keep this transparent to the user so the user does't have to keep track of how many apps currently running on the system.
In any case, the key thing to keep in mind is that when you deal with extreme power savings, very often you end up making compromises that probably make sense for other reasons anyway (such as the small screen size). It's not at all clear that supporting generalized multi-tasking applications makes sense just from a screen real-estate issue and user experience POV, never mind battery lifetime.
Quoted 3 lines
User-space suspend blockers are relevant for background services, and as it has been discussed before; suspend blockers (not activating them) might actually degrade power usage.
Yes, absolutely. Note though that with the iPhone, Apple has decided that the only background services that will be allowed is audio, VOIP, location/navigation, and push notifications. iOS developers don't get access to anything else, and the argument is that nothing else is really *needed*. Android is more flexible in that it allows for non-Apple developers to create new background services, but it's not clear how many you really *need*.
This goes back to your first assertion that there are *many* applications that need to run in the background. I just don't think that's true. There will be a few, and probably more than just the restricted set allowed (and programmed) by Apple. But not *many*.
- Ted
P.S. Although you won't see Apple admitting it, their "fast app switching" is basically what Android has had all along, and most mobile developers are quite happy to call this multi-tasking. Yes, it's not the same as trying to compile the kernel using "make -j 16" in the background. But are you really going to do that on a cell phone battery? I think not.
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Felipe ContrerasQuoted 4 lines · Felipe Contreras
You are overgeneralizing; there are many applications that run in the background, and you want to keep them running even when the display is off.
Really? How many do you really expect will be running at the same time on a mobile platform with a 800-1000 mWh battery? And what percentage of the applications that might be in a Android or Moblin or Maemo app store will have things running in the background? 10%? 20%? 50%? 80%?
Quoted 7 lines
You seen to be concentrating on UI-only applications, for those it's worth noting that Android provides separate mechanisms for power saving. Since Android doesn't have true multi-tasking, the applications must serialize their states so that the next time they are opened they seem to have not been closed. So, the current active UI application can be closed while turning off the display, and re-opened later.
Actually in practice, the process or processes which comprise current active UI application generally won't actually be killed when you turn off the display. It *might* happen, if one of the rare backround applications needs more memory than is available without closing some of the more recently open applications. In practice, the last 2-3 most recently used applications are still loaded in memory so you can switch back and forth between them simply and easily. It is true they have to be ready to be killed at any time in case their memory is needed for the currently active application, but that generally does't happen right away. The design is to keep this transparent to the user so the user does't have to keep track of how many apps currently running on the system.
In any case, the key thing to keep in mind is that when you deal with extreme power savings, very often you end up making compromises that probably make sense for other reasons anyway (such as the small screen size). It's not at all clear that supporting generalized multi-tasking applications makes sense just from a screen real-estate issue and user experience POV, never mind battery lifetime.
Quoted 3 lines
User-space suspend blockers are relevant for background services, and as it has been discussed before; suspend blockers (not activating them) might actually degrade power usage.
Yes, absolutely. Note though that with the iPhone, Apple has decided that the only background services that will be allowed is audio, VOIP, location/navigation, and push notifications. iOS developers don't get access to anything else, and the argument is that nothing else is really *needed*. Android is more flexible in that it allows for non-Apple developers to create new background services, but it's not clear how many you really *need*.
This goes back to your first assertion that there are *many* applications that need to run in the background. I just don't think that's true. There will be a few, and probably more than just the restricted set allowed (and programmed) by Apple. But not *many*.
- Ted
P.S. Although you won't see Apple admitting it, their "fast app switching" is basically what Android has had all along, and most mobile developers are quite happy to call this multi-tasking. Yes, it's not the same as trying to compile the kernel using "make -j 16" in the background. But are you really going to do that on a cell phone battery? I think not.
Quoted 5 lines · Felipe Contreras
appropriately; that's not the case.
1) Install a bad application that requests PM permissions and is granted those
In this case you've gained nothing with user-space suspend blockers.
It's clearly possible for a pathological Android application to destroy the power management policy. But to do that, the author would have to explicitly take a wakelock. That's difficult to do by accident. The various failure modes that exist in a non-wakelock world can be triggered in a wide variety of ways by accident. A sufficiently reductionist viewpoint will equate the two situations, but in the real world they're clearly different.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 5 lines · Felipe Contreras
appropriately; that's not the case.
1) Install a bad application that requests PM permissions and is granted those
In this case you've gained nothing with user-space suspend blockers.
It's clearly possible for a pathological Android application to destroy the power management policy. But to do that, the author would have to explicitly take a wakelock. That's difficult to do by accident. The various failure modes that exist in a non-wakelock world can be triggered in a wide variety of ways by accident. A sufficiently reductionist viewpoint will equate the two situations, but in the real world they're clearly different.
Signature · 1 line
Matthew Garrett | [email protected]
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Theodore TsoQuoted 4 lines · Theodore Tso
True, but again, consider the MacBook. If you plug in an iPod, the machine will wake up for *just* long enough to let the iTunes sync the iPod, but once its done, the machine goes back to sleep again immediately. I doubt MacOS has something called a "suspend blocker"
Quoted 8 lines
which prevents the machine from sleeping until iTunes finished, which when released, allows the machine to suspend again immediately. But neither did I see any evidence that it took 30 seconds for some kludgy polling process to decide that iTunes was done, and to allow the MacBook to go back to sleep. Clearly, the MacBook allows some interrupts through, and some USB insert events through, but clearly not all. (Inserting a USB drive doesn't wake up the laptop; at least, not for long.)
On the contrary, I suspect that it's precisely equivalent to userspace suspend blockers. There's no way to conditionalise USB wakeups - the system comes up when you plug or unplug any USB device. The system is then fully awake and I'd *guess* that ipods are magically exempted in some way, with itunes sending a signal when it's complete in order to allow the suspend policy daemon to trigger a suspend again.
Quoted 3 lines
Can we do something as smooth with a Linux desktop? And if not, why not? (Oh yeah, and wasn't this supposed to be the year of the Linux Desktop? :-)
gnome-power-manager supports applications inhibiting suspend, but right now I suspect that it'll never deal with the case where you resume with the lid closed. It's a simple matter of coding, though.
Signature · 1 line
Matthew Garrett | [email protected]
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Theodore TsoQuoted 4 lines · Theodore Tso
True, but again, consider the MacBook. If you plug in an iPod, the machine will wake up for *just* long enough to let the iTunes sync the iPod, but once its done, the machine goes back to sleep again immediately. I doubt MacOS has something called a "suspend blocker"
Quoted 8 lines
which prevents the machine from sleeping until iTunes finished, which when released, allows the machine to suspend again immediately. But neither did I see any evidence that it took 30 seconds for some kludgy polling process to decide that iTunes was done, and to allow the MacBook to go back to sleep. Clearly, the MacBook allows some interrupts through, and some USB insert events through, but clearly not all. (Inserting a USB drive doesn't wake up the laptop; at least, not for long.)
On the contrary, I suspect that it's precisely equivalent to userspace suspend blockers. There's no way to conditionalise USB wakeups - the system comes up when you plug or unplug any USB device. The system is then fully awake and I'd *guess* that ipods are magically exempted in some way, with itunes sending a signal when it's complete in order to allow the suspend policy daemon to trigger a suspend again.
Quoted 3 lines
Can we do something as smooth with a Linux desktop? And if not, why not? (Oh yeah, and wasn't this supposed to be the year of the Linux Desktop? :-)
gnome-power-manager supports applications inhibiting suspend, but right now I suspect that it'll never deal with the case where you resume with the lid closed. It's a simple matter of coding, though.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 11 lines · Matthew Garrett
Quoted 5 lines · Felipe Contreras
appropriately; that's not the case.
1) Install a bad application that requests PM permissions and is granted those
In this case you've gained nothing with user-space suspend blockers.
It's clearly possible for a pathological Android application to destroy the power management policy. But to do that, the author would have to explicitly take a wakelock. That's difficult to do by accident.
The writer can take a wakelock the whole time the application is running (isn't that the typical case?), because perhaps the author realizes that way the application works correctly, or he copy-pasted it from somewhere else.
Signature · 1 line
Felipe Contreras
Quoted 11 lines · Matthew Garrett
Quoted 5 lines · Felipe Contreras
appropriately; that's not the case.
1) Install a bad application that requests PM permissions and is granted those
In this case you've gained nothing with user-space suspend blockers.
It's clearly possible for a pathological Android application to destroy the power management policy. But to do that, the author would have to explicitly take a wakelock. That's difficult to do by accident.
The writer can take a wakelock the whole time the application is running (isn't that the typical case?), because perhaps the author realizes that way the application works correctly, or he copy-pasted it from somewhere else.
Signature · 1 line
Felipe Contreras
Quoted 9 lines · Felipe Contreras
Quoted 3 lines · Matthew Garrett
It's clearly possible for a pathological Android application to destroy the power management policy. But to do that, the author would have to explicitly take a wakelock. That's difficult to do by accident.
The writer can take a wakelock the whole time the application is running (isn't that the typical case?), because perhaps the author realizes that way the application works correctly, or he copy-pasted it from somewhere else.
No, that's not the typical case.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 9 lines · Felipe Contreras
Quoted 3 lines · Matthew Garrett
It's clearly possible for a pathological Android application to destroy the power management policy. But to do that, the author would have to explicitly take a wakelock. That's difficult to do by accident.
The writer can take a wakelock the whole time the application is running (isn't that the typical case?), because perhaps the author realizes that way the application works correctly, or he copy-pasted it from somewhere else.
No, that's not the typical case.
Signature · 1 line
Matthew Garrett | [email protected]
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()orpm_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
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()orpm_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
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Ted Ts'oQuoted 11 lines · Ted Ts'o
Quoted 4 lines · Felipe Contreras
You are overgeneralizing; there are many applications that run in the background, and you want to keep them running even when the display is off.
Really? How many do you really expect will be running at the same time on a mobile platform with a 800-1000 mWh battery? And what percentage of the applications that might be in a Android or Moblin or Maemo app store will have things running in the background? 10%? 20%? 50%? 80%?
At any given time most of the applications are running on the background, how much exactly depends on the platform. In my N900 I can see that at least 90% of the process are running on the background right now.
Quoted 8 lines
Quoted 7 lines
You seen to be concentrating on UI-only applications, for those it's worth noting that Android provides separate mechanisms for power saving. Since Android doesn't have true multi-tasking, the applications must serialize their states so that the next time they are opened they seem to have not been closed. So, the current active UI application can be closed while turning off the display, and re-opened later.
Quoted 12 lines
Actually in practice, the process or processes which comprise current active UI application generally won't actually be killed when you turn off the display. It *might* happen, if one of the rare backround applications needs more memory than is available without closing some of the more recently open applications. In practice, the last 2-3 most recently used applications are still loaded in memory so you can switch back and forth between them simply and easily. It is true they have to be ready to be killed at any time in case their memory is needed for the currently active application, but that generally does't happen right away. The design is to keep this transparent to the user so the user does't have to keep track of how many apps currently running on the system.
My last experience using an Android system was that switching applications wasn't done "simply and easily".
But supposing it is, Android's UI is completely different to anything else; you cannot take a GNOME/KDE app and expect it to run on Android. Since UI applications are written for Android anyway, then they should be written with PM in mind, and should not rely on suspend blockers.
Quoted 6 lines
In any case, the key thing to keep in mind is that when you deal with extreme power savings, very often you end up making compromises that probably make sense for other reasons anyway (such as the small screen size). It's not at all clear that supporting generalized multi-tasking applications makes sense just from a screen real-estate issue and user experience POV, never mind battery lifetime.
My guess is you haven't used a truly multi-tasking device like the N900; now that I've got used to it, I consider that functionality *essential*.
Multi-tasking and good PM is possible, and the N900 is a good example. Rather than giving up multi-tasking to see how much longer the battery can last, I would rather like to see how to improve batter life for the multi-tasking case.
Quoted 12 lines
Quoted 3 lines
User-space suspend blockers are relevant for background services, and as it has been discussed before; suspend blockers (not activating them) might actually degrade power usage.
Yes, absolutely. Note though that with the iPhone, Apple has decided that the only background services that will be allowed is audio, VOIP, location/navigation, and push notifications. iOS developers don't get access to anything else, and the argument is that nothing else is really *needed*. Android is more flexible in that it allows for non-Apple developers to create new background services, but it's not clear how many you really *need*.
Quoted 4 lines
This goes back to your first assertion that there are *many* applications that need to run in the background. I just don't think that's true. There will be a few, and probably more than just the restricted set allowed (and programmed) by Apple. But not *many*.
The argument in favor of suspend blockers is that you could take applications that are not designed for embedded, and make them run on an embedded device without draining excessive battery life; those applications would have to be background services not conflicting with Android's design.
I agree there probably would not be that many background apps, and probably even less ported background apps, but that is actually an argument against suspend blockers.
The rest of the apps (UI apps), cannot be ported, but have to be written specifically for Android, and therefore should have PM in mind, and not require suspend blockers to have good power usage.
Signature · 5 lines
Felipe Contreras _______________________________________________ linux-pm mailing list [email protected] https://lists.linux-foundation.org/mailman/listinfo/linux-pm
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Ted Ts'oQuoted 11 lines · Ted Ts'o
Quoted 4 lines · Felipe Contreras
You are overgeneralizing; there are many applications that run in the background, and you want to keep them running even when the display is off.
Really? How many do you really expect will be running at the same time on a mobile platform with a 800-1000 mWh battery? And what percentage of the applications that might be in a Android or Moblin or Maemo app store will have things running in the background? 10%? 20%? 50%? 80%?
At any given time most of the applications are running on the background, how much exactly depends on the platform. In my N900 I can see that at least 90% of the process are running on the background right now.
Quoted 8 lines
Quoted 7 lines
You seen to be concentrating on UI-only applications, for those it's worth noting that Android provides separate mechanisms for power saving. Since Android doesn't have true multi-tasking, the applications must serialize their states so that the next time they are opened they seem to have not been closed. So, the current active UI application can be closed while turning off the display, and re-opened later.
Quoted 12 lines
Actually in practice, the process or processes which comprise current active UI application generally won't actually be killed when you turn off the display. It *might* happen, if one of the rare backround applications needs more memory than is available without closing some of the more recently open applications. In practice, the last 2-3 most recently used applications are still loaded in memory so you can switch back and forth between them simply and easily. It is true they have to be ready to be killed at any time in case their memory is needed for the currently active application, but that generally does't happen right away. The design is to keep this transparent to the user so the user does't have to keep track of how many apps currently running on the system.
My last experience using an Android system was that switching applications wasn't done "simply and easily".
But supposing it is, Android's UI is completely different to anything else; you cannot take a GNOME/KDE app and expect it to run on Android. Since UI applications are written for Android anyway, then they should be written with PM in mind, and should not rely on suspend blockers.
Quoted 6 lines
In any case, the key thing to keep in mind is that when you deal with extreme power savings, very often you end up making compromises that probably make sense for other reasons anyway (such as the small screen size). It's not at all clear that supporting generalized multi-tasking applications makes sense just from a screen real-estate issue and user experience POV, never mind battery lifetime.
My guess is you haven't used a truly multi-tasking device like the N900; now that I've got used to it, I consider that functionality *essential*.
Multi-tasking and good PM is possible, and the N900 is a good example. Rather than giving up multi-tasking to see how much longer the battery can last, I would rather like to see how to improve batter life for the multi-tasking case.
Quoted 12 lines
Quoted 3 lines
User-space suspend blockers are relevant for background services, and as it has been discussed before; suspend blockers (not activating them) might actually degrade power usage.
Yes, absolutely. Note though that with the iPhone, Apple has decided that the only background services that will be allowed is audio, VOIP, location/navigation, and push notifications. iOS developers don't get access to anything else, and the argument is that nothing else is really *needed*. Android is more flexible in that it allows for non-Apple developers to create new background services, but it's not clear how many you really *need*.
Quoted 4 lines
This goes back to your first assertion that there are *many* applications that need to run in the background. I just don't think that's true. There will be a few, and probably more than just the restricted set allowed (and programmed) by Apple. But not *many*.
The argument in favor of suspend blockers is that you could take applications that are not designed for embedded, and make them run on an embedded device without draining excessive battery life; those applications would have to be background services not conflicting with Android's design.
I agree there probably would not be that many background apps, and probably even less ported background apps, but that is actually an argument against suspend blockers.
The rest of the apps (UI apps), cannot be ported, but have to be written specifically for Android, and therefore should have PM in mind, and not require suspend blockers to have good power usage.
Signature · 1 line
Felipe Contreras
Re: Attempted summary of suspend-blockers LKML thread, take three
Quoted 11 lines · Felipe Contreras
Quoted 4 lines
This goes back to your first assertion that there are *many* applications that need to run in the background. I just don't think that's true. There will be a few, and probably more than just the restricted set allowed (and programmed) by Apple. But not *many*.
The argument in favor of suspend blockers is that you could take applications that are not designed for embedded, and make them run on an embedded device without draining excessive battery life; those applications would have to be background services not conflicting with Android's design.
Quoted 7 lines
I agree there probably would not be that many background apps, and probably even less ported background apps, but that is actually an argument against suspend blockers.
The rest of the apps (UI apps), cannot be ported, but have to be written specifically for Android, and therefore should have PM in mind, and not require suspend blockers to have good power usage.
I think there's some confusion here.
The default operating mode for Android is to aggressively reach the lowest possible power state (typically full suspend). suspend blockers are used by applications to inform the system that they are currently doing work which requires immediate processing, so the system will avoid fully suspending until that work is done. You could think of it as setting your laptop power management settings to be "blank screen after 60 seconds, power down 5 seconds after blanking", except that there's also a mechanism for apps to hold off on that power down if they're doing important work, and a lot more ways to wakeup beyond opening the lid or pushing the power button.
Straight-forward UI apps don't actually require much special handling -- it's preferable that they do busy-wait on things, but even when power is not an issue, wasting cpu spinning needlessly is frowned upon, so this isn't a special request. There's nothing stopping somebody from writing an Android app that acts as a bridge to X11 apps (embedding an X server, etc) and making it possible for native X11 apps to coexist with the Android composition model. I'm a little surprised nobody has done so, actually. I figured *somebody* would decide that they like their phone but absolutely need to run xclock or something locally as a first class app.
The Android app model does say that if you're not in the foreground (from a UI standpoint) you should save your state, as you may be terminated if the system runs low on resources. The system only does this when it has to -- generally when we bottom out on memory. On devices with sufficient memory, it's quite common for many apps to remain resident for days-weeks -- I've seen as many as 45-50 apps running on my nexus one.
I am a little puzzled by the assertion that Android lasks "true multitasking", but that's another discussion entirely. We certainly don't lack for many concurrent processes and threads...
Brian
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Felipe ContrerasQuoted 11 lines · Felipe Contreras
Quoted 4 lines
This goes back to your first assertion that there are *many* applications that need to run in the background. I just don't think that's true. There will be a few, and probably more than just the restricted set allowed (and programmed) by Apple. But not *many*.
The argument in favor of suspend blockers is that you could take applications that are not designed for embedded, and make them run on an embedded device without draining excessive battery life; those applications would have to be background services not conflicting with Android's design.
Quoted 7 lines
I agree there probably would not be that many background apps, and probably even less ported background apps, but that is actually an argument against suspend blockers.
The rest of the apps (UI apps), cannot be ported, but have to be written specifically for Android, and therefore should have PM in mind, and not require suspend blockers to have good power usage.
I think there's some confusion here.
The default operating mode for Android is to aggressively reach the lowest possible power state (typically full suspend). suspend blockers are used by applications to inform the system that they are currently doing work which requires immediate processing, so the system will avoid fully suspending until that work is done. You could think of it as setting your laptop power management settings to be "blank screen after 60 seconds, power down 5 seconds after blanking", except that there's also a mechanism for apps to hold off on that power down if they're doing important work, and a lot more ways to wakeup beyond opening the lid or pushing the power button.
Straight-forward UI apps don't actually require much special handling -- it's preferable that they do busy-wait on things, but even when power is not an issue, wasting cpu spinning needlessly is frowned upon, so this isn't a special request. There's nothing stopping somebody from writing an Android app that acts as a bridge to X11 apps (embedding an X server, etc) and making it possible for native X11 apps to coexist with the Android composition model. I'm a little surprised nobody has done so, actually. I figured *somebody* would decide that they like their phone but absolutely need to run xclock or something locally as a first class app.
The Android app model does say that if you're not in the foreground (from a UI standpoint) you should save your state, as you may be terminated if the system runs low on resources. The system only does this when it has to -- generally when we bottom out on memory. On devices with sufficient memory, it's quite common for many apps to remain resident for days-weeks -- I've seen as many as 45-50 apps running on my nexus one.
I am a little puzzled by the assertion that Android lasks "true multitasking", but that's another discussion entirely. We certainly don't lack for many concurrent processes and threads...
Brian
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Felipe ContrerasQuoted 9 lines · Felipe Contreras
Quoted 5 lines · Paul E. McKenney
o "Ill-behaved application" AKA "untrusted application" AKA "crappy application".
o "PM-driving application" are applications that are permitted to acquire suspend blockers on Android.
These definitions are wrong.
Indeed they are, given the way you quoted small portions of them. ;-)
Quoted 2 lines
1) There are trusted applications that misbehave (the user clicks Yes when asked about PM permissions)
These would be buggy PM-driving applications. Of course, any type of application might have bugs, including PM-driving applications.
Quoted 2 lines
2) There are untrusted applications that are power optimized (The user clicks No)
I did indeed exclude this category by saying "power-optimized applications are those PM-driving applications that have been aggressively tuned to reduce power consumption." The reason I excluded this case is that that there are a number of cases where removing the PM-driving attribute could destroy the power optimization.
If you have an example power-optimized application that retains its power-optimized property despite lacking PM-driving privileges, please put it forward. In doing so, please keep two things in mind:
1. The definition of power-optimized is more aggressive than many
people are used to -- look at http://lkml.org/lkml/2010/8/4/409 and search for "POWER-OPTIMIZED APPLICATIONS".
2. In a number of the implementations that do not use suspend blockers,
-all- applications are in effect PM-driving applications. So it is quite possible that different people are using subtly different flavors of the "PM-driving applications" definition.
For example, an Android person might consider a application to be PM-driving only if it is permitted to use suspend blockers, while a Maemo person might consider an application to be PM-driving if it had permission to invoke pm_qos functions. If these two hypothetical people each try to apply their definition of PM-driving to each others' platforms, they will likely have severe problems communicating with each other, right? ;-)
But if you do have a good example, perhaps I will need to change my definition of power-optimized application.
Quoted 3 lines
The proponents of suspend blockers in user-space have tried to ignore this fact, but the truth is that PM permissions and power optimization are orthogonal to each other.
In fact, you might have noticed that the proponents of each platform have been quite persistent in shouting past each other from the warmth and security of their own particular viewpoints. ;-)
Thanx, Paul
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Felipe ContrerasQuoted 9 lines · Felipe Contreras
Quoted 5 lines · Paul E. McKenney
o "Ill-behaved application" AKA "untrusted application" AKA "crappy application".
o "PM-driving application" are applications that are permitted to acquire suspend blockers on Android.
These definitions are wrong.
Indeed they are, given the way you quoted small portions of them. ;-)
Quoted 2 lines
1) There are trusted applications that misbehave (the user clicks Yes when asked about PM permissions)
These would be buggy PM-driving applications. Of course, any type of application might have bugs, including PM-driving applications.
Quoted 2 lines
2) There are untrusted applications that are power optimized (The user clicks No)
I did indeed exclude this category by saying "power-optimized applications are those PM-driving applications that have been aggressively tuned to reduce power consumption." The reason I excluded this case is that that there are a number of cases where removing the PM-driving attribute could destroy the power optimization.
If you have an example power-optimized application that retains its power-optimized property despite lacking PM-driving privileges, please put it forward. In doing so, please keep two things in mind:
1. The definition of power-optimized is more aggressive than many
people are used to -- look at http://lkml.org/lkml/2010/8/4/409 and search for "POWER-OPTIMIZED APPLICATIONS".
2. In a number of the implementations that do not use suspend blockers,
-all- applications are in effect PM-driving applications. So it is quite possible that different people are using subtly different flavors of the "PM-driving applications" definition.
For example, an Android person might consider a application to be PM-driving only if it is permitted to use suspend blockers, while a Maemo person might consider an application to be PM-driving if it had permission to invoke pm_qos functions. If these two hypothetical people each try to apply their definition of PM-driving to each others' platforms, they will likely have severe problems communicating with each other, right? ;-)
But if you do have a good example, perhaps I will need to change my definition of power-optimized application.
Quoted 3 lines
The proponents of suspend blockers in user-space have tried to ignore this fact, but the truth is that PM permissions and power optimization are orthogonal to each other.
In fact, you might have noticed that the proponents of each platform have been quite persistent in shouting past each other from the warmth and security of their own particular viewpoints. ;-)
Thanx, Paul
Quoted 9 lines · Felipe Contreras
Quoted 3 lines · Matthew Garrett
It's clearly possible for a pathological Android application to destroy the power management policy. But to do that, the author would have to explicitly take a wakelock. That's difficult to do by accident.
The writer can take a wakelock the whole time the application is running (isn't that the typical case?), because perhaps the author realizes that way the application works correctly, or he copy-pasted it from somewhere else.
That would be exceptionally unusual. A more common case is that the application will take a wakelock while performing some specific long running task which needs no user intervention such as downloading a file or displaying constantly update status that the user is not expected to respond to. There's no need for applications to take wakelocks while the user is directly interacting with them since the system will be kept awake as a result of the user interaction, the wakelocks are used to override the default suspend that occurs when the user is not interacting with the device.
Quoted 9 lines · Felipe Contreras
Quoted 3 lines · Matthew Garrett
It's clearly possible for a pathological Android application to destroy the power management policy. But to do that, the author would have to explicitly take a wakelock. That's difficult to do by accident.
The writer can take a wakelock the whole time the application is running (isn't that the typical case?), because perhaps the author realizes that way the application works correctly, or he copy-pasted it from somewhere else.
That would be exceptionally unusual. A more common case is that the application will take a wakelock while performing some specific long running task which needs no user intervention such as downloading a file or displaying constantly update status that the user is not expected to respond to. There's no need for applications to take wakelocks while the user is directly interacting with them since the system will be kept awake as a result of the user interaction, the wakelocks are used to override the default suspend that occurs when the user is not interacting with the device.
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()orpm_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
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()orpm_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
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
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
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_wakenesting (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_awaketo 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_countfunction loops untilevents_in_progressbecomes 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
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_wakenesting (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_awaketo 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_countfunction loops untilevents_in_progressbecomes 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
Quoted 15 lines · Arve Hjønnevåg
2010/8/7 Rafael J. Wysocki <[email protected]>:
Quoted 14 lines · Arve Hjønnevåg
Quoted 12 lines
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 7 lines
Quoted 2 lines
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.
OK, that's a good argument.
Quoted 8 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. 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.
Well, what about managing these stats in user space?
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).
It seems you can have a list of the "interesting" ones.
Quoted 27 lines
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_countwill 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.
Quoted 6 lines
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.
Now that's more clear, thanks.
Quoted 33 lines
Quoted 33 lines
Quoted 33 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_wakenesting (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.
Quoted 8 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.
You can extend pm_relax() to take a dev argument and measure the time between pm_stay_awake() and pm_relax() called for the same device.
Quoted 49 lines
Quoted 49 lines
Quoted 48 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 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_awakeandpm_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_awaketo 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_countfunction loops untilevents_in_progressbecomes 0.
So, to deadlock with it you'd have to call pm_stay_awake() and wait for it to complete. However, right now there are no means by which user space can call pm_stay_awake(), so this can't happen.
Of course, if you add pm_stay_awake() to an ioctl() code path, you should make sure that whoever uses that ioctl() won't be waiting for the power manager to read from /sys/power/wakeup_count. I guess your point is that this isn't possible to achieve?
Thanks,
Rafael
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Felipe ContrerasQuoted 4 lines · Felipe Contreras
My guess is you haven't used a truly multi-tasking device like the N900; now that I've got used to it, I consider that functionality *essential*.
I've used an N800, and I wasn't impressed; if anything, the fact that I have to worry about manually killing off applications when memory gets low, I actually thought it was incredibly sucky. It was a miniature, badly done laptop.
Maybe the N900 is different, but the bigger question is what do you mean by "multi-tasking"? Definitions are critical here, which is why Paul was so careful in his definitions section of his document.
Do you mean:
* allowing multiple processes running at the same time?
* allowing some applications to be able to update mail, play audio, upload location information so your friends know where you are?
* allowing arbitrary applications that users can interact with simultaneously (which implies a window manager, the need to have the concept of window focus for keyboard input), etc?
or something else?
Quoted 6 lines
The argument in favor of suspend blockers is that you could take applications that are not designed for embedded, and make them run on an embedded device without draining excessive battery life; those applications would have to be background services not conflicting with Android's design.
Quoted 7 lines
I agree there probably would not be that many background apps, and probably even less ported background apps, but that is actually an argument against suspend blockers.
The rest of the apps (UI apps), cannot be ported, but have to be written specifically for Android, and therefore should have PM in mind, and not require suspend blockers to have good power usage.
If you are using a GUI framework which is optimized for a single- application-focus-at-a-time UI that isn't GNOME or KDE, then that will require the applications to be written. However, that's not because of suspend-blockers.
If you assume a GUI framework which is flexible enough --- maybe Qt falls into this category, maybe not --- for the rest of the applications, they don't need to *know* about suspend blockers, and they certainly do't have to be rewritten or modified specifically for suspend blockers. So if your argument is that applications that don't need bacground services (which you've admitted comprises majority of applicatios) need to be modified or written specifically to support suspend blockers, that's simply not true. They don't need to be modified at all.
As far as whether they *should* require suspend blockers to be in the kernel to get power usage that is suitable for cell phone batteries, I would agree that in the ideal world, it would be nice if you could have applications that make the correct performance/battery utilization tradeoff for devices running on 800 mWh batteries, 94,000 mWh batteries, and while running on the AC mains. But I don't believe that it's likely to be true, and if you want to try to beat up on application writers one at a time to be power optimized --- as far as I'm concerned, that's an argument *for* suspend blockers, since I'm not big believer in plans that begin, "First, you command the tides of the sea to go back", King Canute style. :-)
- Ted
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Felipe ContrerasQuoted 4 lines · Felipe Contreras
My guess is you haven't used a truly multi-tasking device like the N900; now that I've got used to it, I consider that functionality *essential*.
I've used an N800, and I wasn't impressed; if anything, the fact that I have to worry about manually killing off applications when memory gets low, I actually thought it was incredibly sucky. It was a miniature, badly done laptop.
Maybe the N900 is different, but the bigger question is what do you mean by "multi-tasking"? Definitions are critical here, which is why Paul was so careful in his definitions section of his document.
Do you mean:
* allowing multiple processes running at the same time?
* allowing some applications to be able to update mail, play audio, upload location information so your friends know where you are?
* allowing arbitrary applications that users can interact with simultaneously (which implies a window manager, the need to have the concept of window focus for keyboard input), etc?
or something else?
Quoted 6 lines
The argument in favor of suspend blockers is that you could take applications that are not designed for embedded, and make them run on an embedded device without draining excessive battery life; those applications would have to be background services not conflicting with Android's design.
Quoted 7 lines
I agree there probably would not be that many background apps, and probably even less ported background apps, but that is actually an argument against suspend blockers.
The rest of the apps (UI apps), cannot be ported, but have to be written specifically for Android, and therefore should have PM in mind, and not require suspend blockers to have good power usage.
If you are using a GUI framework which is optimized for a single- application-focus-at-a-time UI that isn't GNOME or KDE, then that will require the applications to be written. However, that's not because of suspend-blockers.
If you assume a GUI framework which is flexible enough --- maybe Qt falls into this category, maybe not --- for the rest of the applications, they don't need to *know* about suspend blockers, and they certainly do't have to be rewritten or modified specifically for suspend blockers. So if your argument is that applications that don't need bacground services (which you've admitted comprises majority of applicatios) need to be modified or written specifically to support suspend blockers, that's simply not true. They don't need to be modified at all.
As far as whether they *should* require suspend blockers to be in the kernel to get power usage that is suitable for cell phone batteries, I would agree that in the ideal world, it would be nice if you could have applications that make the correct performance/battery utilization tradeoff for devices running on 800 mWh batteries, 94,000 mWh batteries, and while running on the AC mains. But I don't believe that it's likely to be true, and if you want to try to beat up on application writers one at a time to be power optimized --- as far as I'm concerned, that's an argument *for* suspend blockers, since I'm not big believer in plans that begin, "First, you command the tides of the sea to go back", King Canute style. :-)
- Ted
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_wakenesting (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_eventinterface 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_awakewhen an item is added to an empty queue, and you would callpm_relaxwhen 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_awakeorpm_wakeup_eventcalls made between a read and write of/sys/power/wakeup_count(i.e., whileevents_check_enabledis 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_awaketo 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_countfunction loops untilevents_in_progressbecomes 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
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_wakenesting (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_eventinterface 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_awakewhen an item is added to an empty queue, and you would callpm_relaxwhen 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_awakeorpm_wakeup_eventcalls made between a read and write of/sys/power/wakeup_count(i.e., whileevents_check_enabledis 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_awaketo 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_countfunction loops untilevents_in_progressbecomes 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
2010/8/8 Rafael J. Wysocki <[email protected]>:
Quoted 1 line · Arve Hjønnevåg
...
Quoted 11 lines
Quoted 8 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. 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.
Well, what about managing these stats in user space?
The java wakelocks have stats in user space, but the lower level services that use the kernel api do not show up there.
Quoted 6 lines
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).
It seems you can have a list of the "interesting" ones.
I'm not sure what you mean. If you mean add a procfs or debugfs api that lists the stats for devices that have used the api, then yes that should work. If I have a devices where the battery drained too quickly, I run cat /proc/wakelocks which has all the reasons why it was not suspended.
...
Quoted 11 lines
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 2 lines
How do you propose to track how long a driver has blocked suspend when you have an unblock call that takes no arguments.
You can extend
pm_relax()to take a dev argument and measure the time betweenpm_stay_awake()andpm_relax()called for the same device.
As long as it is not optional.
Quoted 49 lines
Quoted 49 lines
Quoted 49 lines
Quoted 48 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 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_awakeandpm_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_awaketo 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 9 lines
Quoted 4 lines
Quoted 2 lines
No, in that case suspend will be aborted, IIUC.
How? Your
pm_get_wakeup_countfunction loops untilevents_in_progressbecomes 0.So, to deadlock with it you'd have to call
pm_stay_awake()and wait for it to complete. However, right now there are no means by which user space can callpm_stay_awake(), so this can't happen.
No that is not how it deadlocks. The input driver calls pm_stay_awake which blocks the thread that reads from /sys/power/wakeup_count. If that threads needs to run before the user-space reads from the input device (either because it is the same thread, or because it provides a user-space wakelock api) you have a deadlock.
Quoted 5 lines
Of course, if you add
pm_stay_awake()to anioctl()code path, you should make sure that whoever uses thatioctl()won't be waiting for the power manager to read from/sys/power/wakeup_count. I guess your point is that this isn't possible to achieve?
My main point is that blocking suspend while the input event queue is not empty changes what else is safe for the user-space process reading /sys/power/wakeup_count.
Signature · 1 line
Arve Hjønnevåg
2010/8/8 Rafael J. Wysocki <[email protected]>:
Quoted 1 line · Arve Hjønnevåg
...
Quoted 11 lines
Quoted 8 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. 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.
Well, what about managing these stats in user space?
The java wakelocks have stats in user space, but the lower level services that use the kernel api do not show up there.
Quoted 6 lines
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).
It seems you can have a list of the "interesting" ones.
I'm not sure what you mean. If you mean add a procfs or debugfs api that lists the stats for devices that have used the api, then yes that should work. If I have a devices where the battery drained too quickly, I run cat /proc/wakelocks which has all the reasons why it was not suspended.
...
Quoted 11 lines
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 2 lines
How do you propose to track how long a driver has blocked suspend when you have an unblock call that takes no arguments.
You can extend
pm_relax()to take a dev argument and measure the time betweenpm_stay_awake()andpm_relax()called for the same device.
As long as it is not optional.
Quoted 49 lines
Quoted 49 lines
Quoted 49 lines
Quoted 48 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 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_awakeandpm_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_awaketo 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 9 lines
Quoted 4 lines
Quoted 2 lines
No, in that case suspend will be aborted, IIUC.
How? Your
pm_get_wakeup_countfunction loops untilevents_in_progressbecomes 0.So, to deadlock with it you'd have to call
pm_stay_awake()and wait for it to complete. However, right now there are no means by which user space can callpm_stay_awake(), so this can't happen.
No that is not how it deadlocks. The input driver calls pm_stay_awake which blocks the thread that reads from /sys/power/wakeup_count. If that threads needs to run before the user-space reads from the input device (either because it is the same thread, or because it provides a user-space wakelock api) you have a deadlock.
Quoted 5 lines
Of course, if you add
pm_stay_awake()to anioctl()code path, you should make sure that whoever uses thatioctl()won't be waiting for the power manager to read from/sys/power/wakeup_count. I guess your point is that this isn't possible to achieve?
My main point is that blocking suspend while the input event queue is not empty changes what else is safe for the user-space process reading /sys/power/wakeup_count.
Signature · 1 line
Arve Hjønnevåg
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
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
Re: Attempted summary of suspend-blockers LKML thread, take two
In reply to [email protected]Hi!
Quoted 8 lines
Quoted 4 lines
I should have asked this earlier... What exactly are the apps' compatibility constraints? Source-level APIs? Byte-code class-library invocations? C/C++ dynamic linking? C/C++ static linking (in other words, syscall)?
For Java/Dalvik apps, the wakelock API is pertty high level -- it talks to a service via RPC (Binder) that actually interacts with the kernel. Changing the basic kernel<->userspace interface (within
Strange. Arve claimed that open/close is too slow, and few microseconds faster ioctl is needed, and now we learn it actually uses RPC.
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: Attempted summary of suspend-blockers LKML thread, take two
In reply to [email protected]Hi!
Quoted 8 lines
Quoted 4 lines
I should have asked this earlier... What exactly are the apps' compatibility constraints? Source-level APIs? Byte-code class-library invocations? C/C++ dynamic linking? C/C++ static linking (in other words, syscall)?
For Java/Dalvik apps, the wakelock API is pertty high level -- it talks to a service via RPC (Binder) that actually interacts with the kernel. Changing the basic kernel<->userspace interface (within
Strange. Arve claimed that open/close is too slow, and few microseconds faster ioctl is needed, and now we learn it actually uses RPC.
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: Attempted summary of suspend-blockers LKML thread, take two
Quoted 7 lines · Pavel Machek
Hi!
Quoted 5 lines
Quoted 4 lines
I should have asked this earlier... What exactly are the apps' compatibility constraints? Source-level APIs? Byte-code class-library invocations? C/C++ dynamic linking? C/C++ static linking (in other words, syscall)?
Quoted 7 lines
Quoted 3 lines
For Java/Dalvik apps, the wakelock API is pertty high level -- it talks to a service via RPC (Binder) that actually interacts with the kernel. Changing the basic kernel<->userspace interface (within
Strange. Arve claimed that open/close is too slow, and few microseconds faster ioctl is needed, and now we learn it actually uses RPC.
For the high level Java API, yes. For lower level userspace code, like the code that processes keypresses, the kernel interface is used directly. I think an open/close per keypress would be a bit excessive, for example. In any case, that ignores the fact that it's useful to have statistics, which are tricky to maintain meaningfully if you destroy the handle after use every time (by closing the fd).
Brian
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm
Re: Attempted summary of suspend-blockers LKML thread, take two
In reply to Pavel MachekQuoted 7 lines · Pavel Machek
Hi!
Quoted 5 lines
Quoted 4 lines
I should have asked this earlier... What exactly are the apps' compatibility constraints? Source-level APIs? Byte-code class-library invocations? C/C++ dynamic linking? C/C++ static linking (in other words, syscall)?
Quoted 7 lines
Quoted 3 lines
For Java/Dalvik apps, the wakelock API is pertty high level -- it talks to a service via RPC (Binder) that actually interacts with the kernel. Changing the basic kernel<->userspace interface (within
Strange. Arve claimed that open/close is too slow, and few microseconds faster ioctl is needed, and now we learn it actually uses RPC.
For the high level Java API, yes. For lower level userspace code, like the code that processes keypresses, the kernel interface is used directly. I think an open/close per keypress would be a bit excessive, for example. In any case, that ignores the fact that it's useful to have statistics, which are tricky to maintain meaningfully if you destroy the handle after use every time (by closing the fd).
Brian
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Ted Ts'oQuoted 3 lines
I have to worry about manually killing off applications when memory gets low, I actually thought it was incredibly sucky. It was a miniature, badly done laptop.
Likewise I thought the lack of proper multi-tasking apps in Android was comically bad. Nice device completely wrecked by the inability to flip between running apps each with their own screen - something that was old tech in 1990.
It's no use looking at this from an "In my opinion" angle. A proper solution works for most if not all opinions except maybe around corner cases.
Quoted 3 lines
* allowing arbitrary applications that users can interact with simultaneously (which implies a window manager, the need to have the concept of window focus for keyboard input), etc?
That's also untrue as anyone who has worked in industrial control or entertainment systems will tell you. You may well have fourteen apps driving fourteen display/input devices and no window manager.
Quoted 9 lines
would agree that in the ideal world, it would be nice if you could have applications that make the correct performance/battery utilization tradeoff for devices running on 800 mWh batteries, 94,000 mWh batteries, and while running on the AC mains. But I don't believe that it's likely to be true, and if you want to try to beat up on application writers one at a time to be power optimized --- as far as I'm concerned, that's an argument *for* suspend blockers, since I'm not big believer in plans that begin, "First, you command the tides of the sea to go back", King Canute style. :-)
Suspend blockers drive the system policy part way into the apps, that in turn makes the apps very vulnerable to change in their environment because you've specialised them. I am sure that in the Android world it's considered fine, and that the marketing and business people even like this binding together - but it doesn't generalise and will blow up in people's faces in the future.
To consider your tide analogy - suspend blockers is like trying to program the waves individually. Show me a suspend blocker aware open office patch 8)
Re: Attempted summary of suspend-blockers LKML thread, take three
On Mon, Aug 09, 2010 at 11:24:53AM +0100, Alan Cox wrote:
[ . . . ]
Quoted 17 lines
Quoted 9 lines
would agree that in the ideal world, it would be nice if you could have applications that make the correct performance/battery utilization tradeoff for devices running on 800 mWh batteries, 94,000 mWh batteries, and while running on the AC mains. But I don't believe that it's likely to be true, and if you want to try to beat up on application writers one at a time to be power optimized --- as far as I'm concerned, that's an argument *for* suspend blockers, since I'm not big believer in plans that begin, "First, you command the tides of the sea to go back", King Canute style. :-)
Suspend blockers drive the system policy part way into the apps, that in turn makes the apps very vulnerable to change in their environment because you've specialised them. I am sure that in the Android world it's considered fine, and that the marketing and business people even like this binding together - but it doesn't generalise and will blow up in people's faces in the future.
Quoted 3 lines
To consider your tide analogy - suspend blockers is like trying to program the waves individually. Show me a suspend blocker aware open office patch 8)
But wouldn't an office suite run as a power-oblivious application on an Android device? After all, office applications do not need to run when the screen is turned off, so these the applications do not need to use suspend blockers. That said, I could easily imagine that significant work would be required to make OpenOffice run on Android, not due to suspend blockers, but rather due to Android's unusual user space.
On devices that do not have suspend blockers, a normal application runs in a manner similar to a hypothetical Android application that acquires a suspend blocker when it starts and holds that suspend blocker until it exits. In contrast with Android, this situation requires that each and every application be carefully written to avoid battery drain, which I suspect is what Ted is getting at with his King Canute analogy.
Thanx, Paul
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Alan CoxOn Mon, Aug 09, 2010 at 11:24:53AM +0100, Alan Cox wrote:
[ . . . ]
Quoted 17 lines
Quoted 9 lines
would agree that in the ideal world, it would be nice if you could have applications that make the correct performance/battery utilization tradeoff for devices running on 800 mWh batteries, 94,000 mWh batteries, and while running on the AC mains. But I don't believe that it's likely to be true, and if you want to try to beat up on application writers one at a time to be power optimized --- as far as I'm concerned, that's an argument *for* suspend blockers, since I'm not big believer in plans that begin, "First, you command the tides of the sea to go back", King Canute style. :-)
Suspend blockers drive the system policy part way into the apps, that in turn makes the apps very vulnerable to change in their environment because you've specialised them. I am sure that in the Android world it's considered fine, and that the marketing and business people even like this binding together - but it doesn't generalise and will blow up in people's faces in the future.
Quoted 3 lines
To consider your tide analogy - suspend blockers is like trying to program the waves individually. Show me a suspend blocker aware open office patch 8)
But wouldn't an office suite run as a power-oblivious application on an Android device? After all, office applications do not need to run when the screen is turned off, so these the applications do not need to use suspend blockers. That said, I could easily imagine that significant work would be required to make OpenOffice run on Android, not due to suspend blockers, but rather due to Android's unusual user space.
On devices that do not have suspend blockers, a normal application runs in a manner similar to a hypothetical Android application that acquires a suspend blocker when it starts and holds that suspend blocker until it exits. In contrast with Android, this situation requires that each and every application be carefully written to avoid battery drain, which I suspect is what Ted is getting at with his King Canute analogy.
Thanx, Paul
Re: Attempted summary of suspend-blockers LKML thread, take three
Quoted 25 lines · Paul E. McKenney
On Mon, Aug 09, 2010 at 11:24:53AM +0100, Alan Cox wrote:
[ . . . ]
Quoted 17 lines
Quoted 9 lines
would agree that in the ideal world, it would be nice if you could have applications that make the correct performance/battery utilization tradeoff for devices running on 800 mWh batteries, 94,000 mWh batteries, and while running on the AC mains. But I don't believe that it's likely to be true, and if you want to try to beat up on application writers one at a time to be power optimized --- as far as I'm concerned, that's an argument *for* suspend blockers, since I'm not big believer in plans that begin, "First, you command the tides of the sea to go back", King Canute style. :-)
Suspend blockers drive the system policy part way into the apps, that in turn makes the apps very vulnerable to change in their environment because you've specialised them. I am sure that in the Android world it's considered fine, and that the marketing and business people even like this binding together - but it doesn't generalise and will blow up in people's faces in the future.
Quoted 3 lines
To consider your tide analogy - suspend blockers is like trying to program the waves individually. Show me a suspend blocker aware open office patch 8)
Quoted 6 lines
But wouldn't an office suite run as a power-oblivious application on an Android device? After all, office applications do not need to run when the screen is turned off, so these the applications do not need to use suspend blockers. That said, I could easily imagine that significant work would be required to make OpenOffice run on Android, not due to suspend blockers, but rather due to Android's unusual user space.
pick your application if you don't like the example.
but also, which android system should the applicaton be written for? the phone with a 800maH battery or a larger device with a 94,000maH battery?
well bahaved applications (not doing unnecessary wakeups, etc) are well bahaved, no matter what system they are on (explicitly setting allowable timer fuzz is linux specific, but will again help on any system)
David Lang
Re: Attempted summary of suspend-blockers LKML thread, take three
Quoted 27 lines · On Mon, Aug 09, 2010 at 11:28:02AM -0700, [email protected] wrote:
Quoted 25 lines · Paul E. McKenney
On Mon, Aug 09, 2010 at 11:24:53AM +0100, Alan Cox wrote:
[ . . . ]
Quoted 20 lines
Quoted 9 lines
would agree that in the ideal world, it would be nice if you could have applications that make the correct performance/battery utilization tradeoff for devices running on 800 mWh batteries, 94,000 mWh batteries, and while running on the AC mains. But I don't believe that it's likely to be true, and if you want to try to beat up on application writers one at a time to be power optimized --- as far as I'm concerned, that's an argument *for* suspend blockers, since I'm not big believer in plans that begin, "First, you command the tides of the sea to go back", King Canute style. :-)
Suspend blockers drive the system policy part way into the apps, that in turn makes the apps very vulnerable to change in their environment because you've specialised them. I am sure that in the Android world it's considered fine, and that the marketing and business people even like this binding together - but it doesn't generalise and will blow up in people's faces in the future.
To consider your tide analogy - suspend blockers is like trying to program the waves individually. Show me a suspend blocker aware open office patch 8)
Quoted 8 lines
Quoted 6 lines
But wouldn't an office suite run as a power-oblivious application on an Android device? After all, office applications do not need to run when the screen is turned off, so these the applications do not need to use suspend blockers. That said, I could easily imagine that significant work would be required to make OpenOffice run on Android, not due to suspend blockers, but rather due to Android's unusual user space.
pick your application if you don't like the example.
I like the office-suite example just fine.
Quoted 3 lines
but also, which android system should the applicaton be written for? the phone with a 800maH battery or a larger device with a 94,000maH battery?
Does battery size make a difference in this particular case?
Quoted 2 lines
well bahaved applications (not doing unnecessary wakeups, etc) are well bahaved, no matter what system they are on
Yep. Your point being what exactly? That all applications should be required to be power-optimized, and that any technology that automates energy efficiency should be rejected out of hand? If so, please justify your position.
Quoted 3 lines
(explicitly setting
allowable timer fuzz is linux specific, but will again help on any system)
Setting aside the question of how timer fuzz will help on non-Linux systems if timer fuzz is specific to Linux...
Thanx, Paul
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Paul E. McKenneyQuoted 2 lines
But wouldn't an office suite run as a power-oblivious application on an Android device? After all, office applications do not need to run when
I was waiting for soemone to leap down the pit I dug Office suites have some quite important background activities. Consider the case of a power oblivious Open Office. You type a critical document, you suspend, your phone battery dies a bit later, you lost your document. Office suites do timed backing up as one simple obvious example. That could become a power aware behaviour but the truely power oblivious office suite is a myth.
Quoted 4 lines
the screen is turned off, so these the applications do not need to use suspend blockers. That said, I could easily imagine that significant work would be required to make OpenOffice run on Android, not due to suspend blockers, but rather due to Android's unusual user space.
You are tightly linking suspend blockers with Android. If they were a sensible general solution they would be generic not tied closely to Android
Some of the other bad assumptions being made in this discussion:
- That the phone is special. Todays Android phones are up with the PC's of some years back (but with better graphics and more faster storage), in a few more generations of the technology what will they look like ? I'm sure that within a few years there will be people playing Warcraft or similar on their phone in the train.
- That Android will continue to tbe offering the same services in future as today. If it does it'll go the way of PalmOS and Symbian. Equally you can't just bust all the apps as it changes
As devices get more complex and varied you cannot afford to put the detailed awareness of platform behaviour in the applications. It doesn't scale. Android developers are haivng enough fun coping with all the OS variants, customisations and new phones - and thats far less variety than PC hardware. Generally the PC app folks are not having the same level of problem - so ask why ?
Quoted 6 lines
On devices that do not have suspend blockers, a normal application runs in a manner similar to a hypothetical Android application that acquires a suspend blocker when it starts and holds that suspend blocker until it exits. In contrast with Android, this situation requires that each and every application be carefully written to avoid battery drain, which I suspect is what Ted is getting at with his King Canute analogy.
Which is flawed and not the case. The same argument could be made for multi-tasking
DOS "Each application implements its own internal
multitasking/polling if needed"
Windows 3.x "Each application has an event loop and is built
in a certain way" (the 'suspend blocker' mentality)
Real OS "The scheduler operates in a manner which prevents
CPU hogs breaking the system or abusing it sufficiently to threaten its functionality"
The same applies to power. Only the OS has the big picture and can hide the hardware and general policy variety from the application.
OpenOffice runs on netbooks, laptops, servers, even big non x86 boxes. It runs on virtual machines, it runs in power sensitive environments, it runs in thermally constrained environments, it runs in I/O constrained environments, it runs in latency constrained environments etc etc
All the same code, true some work has been done to make it behave politely but the rest is down to the OS doing its job - deploying the resources available while considering and obeying the constraints present, in a manner which makes best use of the resources to achieve the policy goals of the system.
And not unsurprisingly that all starts to look like Stafford Beer's good old viable systems model.
Alan
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Paul E. McKenneyQuoted 2 lines
But wouldn't an office suite run as a power-oblivious application on an Android device? After all, office applications do not need to run when
I was waiting for soemone to leap down the pit I dug Office suites have some quite important background activities. Consider the case of a power oblivious Open Office. You type a critical document, you suspend, your phone battery dies a bit later, you lost your document. Office suites do timed backing up as one simple obvious example. That could become a power aware behaviour but the truely power oblivious office suite is a myth.
Quoted 4 lines
the screen is turned off, so these the applications do not need to use suspend blockers. That said, I could easily imagine that significant work would be required to make OpenOffice run on Android, not due to suspend blockers, but rather due to Android's unusual user space.
You are tightly linking suspend blockers with Android. If they were a sensible general solution they would be generic not tied closely to Android
Some of the other bad assumptions being made in this discussion:
- That the phone is special. Todays Android phones are up with the PC's of some years back (but with better graphics and more faster storage), in a few more generations of the technology what will they look like ? I'm sure that within a few years there will be people playing Warcraft or similar on their phone in the train.
- That Android will continue to tbe offering the same services in future as today. If it does it'll go the way of PalmOS and Symbian. Equally you can't just bust all the apps as it changes
As devices get more complex and varied you cannot afford to put the detailed awareness of platform behaviour in the applications. It doesn't scale. Android developers are haivng enough fun coping with all the OS variants, customisations and new phones - and thats far less variety than PC hardware. Generally the PC app folks are not having the same level of problem - so ask why ?
Quoted 6 lines
On devices that do not have suspend blockers, a normal application runs in a manner similar to a hypothetical Android application that acquires a suspend blocker when it starts and holds that suspend blocker until it exits. In contrast with Android, this situation requires that each and every application be carefully written to avoid battery drain, which I suspect is what Ted is getting at with his King Canute analogy.
Which is flawed and not the case. The same argument could be made for multi-tasking
DOS "Each application implements its own internal
multitasking/polling if needed"
Windows 3.x "Each application has an event loop and is built
in a certain way" (the 'suspend blocker' mentality)
Real OS "The scheduler operates in a manner which prevents
CPU hogs breaking the system or abusing it sufficiently to threaten its functionality"
The same applies to power. Only the OS has the big picture and can hide the hardware and general policy variety from the application.
OpenOffice runs on netbooks, laptops, servers, even big non x86 boxes. It runs on virtual machines, it runs in power sensitive environments, it runs in thermally constrained environments, it runs in I/O constrained environments, it runs in latency constrained environments etc etc
All the same code, true some work has been done to make it behave politely but the rest is down to the OS doing its job - deploying the resources available while considering and obeying the constraints present, in a manner which makes best use of the resources to achieve the policy goals of the system.
And not unsurprisingly that all starts to look like Stafford Beer's good old viable systems model.
Alan
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Alan CoxQuoted 10 lines · Alan Cox
Quoted 2 lines
But wouldn't an office suite run as a power-oblivious application on an Android device? After all, office applications do not need to run when
I was waiting for soemone to leap down the pit I dug Office suites have some quite important background activities. Consider the case of a power oblivious Open Office. You type a critical document, you suspend, your phone battery dies a bit later, you lost your document. Office suites do timed backing up as one simple obvious example. That could become a power aware behaviour but the truely power oblivious office suite is a myth.
Quoted 8 lines
Quoted 4 lines
the screen is turned off, so these the applications do not need to use suspend blockers. That said, I could easily imagine that significant work would be required to make OpenOffice run on Android, not due to suspend blockers, but rather due to Android's unusual user space.
You are tightly linking suspend blockers with Android. If they were a sensible general solution they would be generic not tied closely to Android
Doesn't the same problem exist on my linux laptop? I write out my manifesto in open office, close the lid of my laptop, the system suspends before my huge document finishes writing out, later my battery dies or I foolishly remove it or whatnot... the main difference seems to be that laptops, with their big 'ol batteries, are less aggressive about power management and the result is wider windows before and less frequent wakeups from suspend and thus better odds at missing the race condition.
As Arve has pointed out previously, there are a number of uses for suspend blockers, even on plugged-into-the-wall systems -- take his example of wanting his mythtv backend to power down when not busy, but never power down when he happens to be using it on console, or issues with multiple services that want to wake up and keep the device awake while working.
Brian
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Alan CoxQuoted 10 lines · Alan Cox
Quoted 2 lines
But wouldn't an office suite run as a power-oblivious application on an Android device? After all, office applications do not need to run when
I was waiting for soemone to leap down the pit I dug Office suites have some quite important background activities. Consider the case of a power oblivious Open Office. You type a critical document, you suspend, your phone battery dies a bit later, you lost your document. Office suites do timed backing up as one simple obvious example. That could become a power aware behaviour but the truely power oblivious office suite is a myth.
Quoted 8 lines
Quoted 4 lines
the screen is turned off, so these the applications do not need to use suspend blockers. That said, I could easily imagine that significant work would be required to make OpenOffice run on Android, not due to suspend blockers, but rather due to Android's unusual user space.
You are tightly linking suspend blockers with Android. If they were a sensible general solution they would be generic not tied closely to Android
Doesn't the same problem exist on my linux laptop? I write out my manifesto in open office, close the lid of my laptop, the system suspends before my huge document finishes writing out, later my battery dies or I foolishly remove it or whatnot... the main difference seems to be that laptops, with their big 'ol batteries, are less aggressive about power management and the result is wider windows before and less frequent wakeups from suspend and thus better odds at missing the race condition.
As Arve has pointed out previously, there are a number of uses for suspend blockers, even on plugged-into-the-wall systems -- take his example of wanting his mythtv backend to power down when not busy, but never power down when he happens to be using it on console, or issues with multiple services that want to wake up and keep the device awake while working.
Brian
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Alan CoxQuoted 9 lines · Alan Cox
Quoted 2 lines
But wouldn't an office suite run as a power-oblivious application on an Android device? After all, office applications do not need to run when
I was waiting for soemone to leap down the pit I dug Office suites have some quite important background activities. Consider the case of a power oblivious Open Office. You type a critical document, you suspend, your phone battery dies a bit later, you lost your document. Office suites do timed backing up as one simple obvious example. That could become a power aware behaviour but the truely power oblivious office suite is a myth.
this is a good example of why the office suite should be a privilaged application. If the system were to consider it privilaged, it could wake up when the timer is scheduled to fire to save the document.
the office suite probably has a periodic timer that would fire every 10 min no matter what, but if there was a reason to change it, it could be modified to only setup the timer when the document is changed. If no changes can take place because the system is asleep, the timer never gets setup.
David Lang
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Alan CoxQuoted 9 lines · Alan Cox
Quoted 2 lines
But wouldn't an office suite run as a power-oblivious application on an Android device? After all, office applications do not need to run when
I was waiting for soemone to leap down the pit I dug Office suites have some quite important background activities. Consider the case of a power oblivious Open Office. You type a critical document, you suspend, your phone battery dies a bit later, you lost your document. Office suites do timed backing up as one simple obvious example. That could become a power aware behaviour but the truely power oblivious office suite is a myth.
this is a good example of why the office suite should be a privilaged application. If the system were to consider it privilaged, it could wake up when the timer is scheduled to fire to save the document.
the office suite probably has a periodic timer that would fire every 10 min no matter what, but if there was a reason to change it, it could be modified to only setup the timer when the document is changed. If no changes can take place because the system is asleep, the timer never gets setup.
David Lang
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 oneWouldn'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
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 oneWouldn'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
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
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
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Alan CoxQuoted 9 lines · Alan Cox
Quoted 2 lines
But wouldn't an office suite run as a power-oblivious application on an Android device? After all, office applications do not need to run when
I was waiting for soemone to leap down the pit I dug Office suites have some quite important background activities. Consider the case of a power oblivious Open Office. You type a critical document, you suspend, your phone battery dies a bit later, you lost your document. Office suites do timed backing up as one simple obvious example. That could become a power aware behaviour but the truely power oblivious office suite is a myth.
It is a sad day on LKML when we are busy digging pits for each other. On the other hand, I have seen far sadder days, and the pit you dug happens to lead somewhere useful. As Brian noted in his reply, the situation you call out can occur with manual suspend-to-RAM already:
the fact is that this is a design choice. You could indeed make a PM-driving office application if you wished, or run the same application as a power-oblivious application. There is a slight difference in the contract with the user. Of course, it is quite clear which one -you- prefer, but preferences can vary.
Quoted 8 lines
Quoted 4 lines
the screen is turned off, so these the applications do not need to use suspend blockers. That said, I could easily imagine that significant work would be required to make OpenOffice run on Android, not due to suspend blockers, but rather due to Android's unusual user space.
You are tightly linking suspend blockers with Android. If they were a sensible general solution they would be generic not tied closely to Android
Android is certainly where suspend blockers originated, and is to the best of my knowledge is still the only platform that uses them. But there is a first user of every new mechanism, and for some time that first user will by definition be the only user of that mechanism. So the fact that Android is most probably the only user of suspend blockers does not prove anything about whether or not suspend blockers are sensible.
Quoted 7 lines
Some of the other bad assumptions being made in this discussion:
- That the phone is special. Todays Android phones are up with the PC's of some years back (but with better graphics and more faster storage), in a few more generations of the technology what will they look like ? I'm sure that within a few years there will be people playing Warcraft or similar on their phone in the train.
Indeed, people have played games on their cellphones for some years. Not sure whether any of the games resembles World of Warcraft, but they probably soon will. If so, perhaps they will make use of significant hardware acceleration -- most other embedded systems do so.
But that doesn't guarantee that solutions developed for PCs and laptops will be optimal (or even usable) on cellphones. Sufficient difference in scale can easily change the form of the optimal solution, so you have not yet made your case. (For that matter, you also haven't proven that adoption of suspend blockers or something like them depends on the assumption that cellphones are special.)
Quoted 3 lines
- That Android will continue to tbe offering the same services in future as today. If it does it'll go the way of PalmOS and Symbian. Equally you can't just bust all the apps as it changes
I hope that no one is arguing that Android will remain unchanged, just as I hope no one would argue that Linux will remain unchanged. In fact, I am quite confident that both Linux and Android will continue to change. So exactly what point were you attempting to make here?
As to busting all apps, lthough there have been situations where busting all the apps turned out to be the right thing to do, I agree that these situations are extremely rare. Such situations are usually associated with the emergence of a new high-volume platform.
Quoted 8 lines
As devices get more complex and varied you cannot afford to put the detailed awareness of platform behaviour in the applications. It doesn't scale. Android developers are haivng enough fun coping with all the OS variants, customisations and new phones - and thats far less variety than PC hardware. Generally the PC app folks are not having the same level of problem - so ask why ?
From what I can see, the Android developers are suffering less than
the PC developers were suffering when the PC was the same age that Android is now. For that matter, suspend blockers don't put detailed awareness of platform behavior into apps. You must look to the heavily power-optimized apps to find that kind of awareness.
Quoted 8 lines
Quoted 6 lines
On devices that do not have suspend blockers, a normal application runs in a manner similar to a hypothetical Android application that acquires a suspend blocker when it starts and holds that suspend blocker until it exits. In contrast with Android, this situation requires that each and every application be carefully written to avoid battery drain, which I suspect is what Ted is getting at with his King Canute analogy.
Which is flawed and not the case.
Hmmm... Exactly which part do you consider flawed? Let's take it one sentence at a time. The devices that I know of that lack suspend blockers also lack opportunistic suspend. Therefore, all applications on such devices run as would an application that acquired a suspend blocker when it started and did not release that suspend blocker until it exited. Pretty straightforward.
As for the first part of the second sentence, you yourself have argued that each and every application should be carefully written to avoid battery drain (or, equivalently, to promote energy efficiency), so presumably the flaw does not reside there. That leaves the second half of that sentence, for which we both must defer to Ted. But Ted's intended meaning of his King Canute analogy does not affect the argument as to whether or not suspend blockers (or, again, something like them) are useful.
Quoted 6 lines
The same argument could be made for
multi-taskingDOS "Each application implements its own internal
multitasking/polling if needed"
Quoted 6 lines
Windows 3.x "Each application has an event loop and is built
in a certain way" (the 'suspend blocker' mentality)Real OS "The scheduler operates in a manner which prevents
CPU hogs breaking the system or abusing it sufficiently to threaten its functionality"
I really do like this progression. I will return to it further down.
Quoted 2 lines
The same applies to power. Only the OS has the big picture and can hide the hardware and general policy variety from the application.
The OS can be said to possess the full picture only if the applications communicate their portion of the picture to the OS. Linux has quite a few APIs devoted to this sort of communication, many of them mandated by POSIX. Some people are proposing suspend blockers (or something like them) as another member of this set of APIs.
Quoted 4 lines
OpenOffice runs on netbooks, laptops, servers, even big non x86 boxes. It runs on virtual machines, it runs in power sensitive environments, it runs in thermally constrained environments, it runs in I/O constrained environments, it runs in latency constrained environments etc etc
And there are numerous environments in which it will not run. So what?
Quoted 5 lines
All the same code, true some work has been done to make it behave politely but the rest is down to the OS doing its job - deploying the resources available while considering and obeying the constraints present, in a manner which makes best use of the resources to achieve the policy goals of the system.
And if the work has not been done on the application, and if there is nothing like suspend blockers, the OS cannot do its job. So how exactly does this support your position?
Which brings us to the progression from DOS to Windows 3.x to Real OS. Why can the Real OS's scheduler can operate "in a manner which prevents CPU hogs from breaking the system or abusing it sufficiently to threaten its functionality" while still allowing applications with special requirements to operate correctly? One reason is the advent of any number of APIs that communicate special properties of specific applications to the OS, including the old nice() system call, POSIX realtime, numerous facilities to communicate application properties to the VM system, and so on.
Given this context, are you sure that suspend blockers are not the next step in the Real OS progression? Or some QoS mechanism that subsumes suspend blockers? However, there is a lot of negative experience around general-purpose QoS mechanisms -- you have to be quite careful in order to avoid spending more energy computing QoS than you would otherwise spend on the application's computations. The usual way out of this trap is to abandon generality in favor of exploiting the commonly occurring special cases. For all I know, raw suspend blockers might be the appropriate special case.
Quoted 2 lines
And not unsurprisingly that all starts to look like Stafford Beer's good old viable systems model.
Hmmm... I do like "Absolutum Obsoletum", especially if it really does translate to "If it works it's out of date." However, I am not at all convinced that it supports your position! ;-)
Thanx, Paul
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Alan CoxQuoted 9 lines · Alan Cox
Quoted 2 lines
But wouldn't an office suite run as a power-oblivious application on an Android device? After all, office applications do not need to run when
I was waiting for soemone to leap down the pit I dug Office suites have some quite important background activities. Consider the case of a power oblivious Open Office. You type a critical document, you suspend, your phone battery dies a bit later, you lost your document. Office suites do timed backing up as one simple obvious example. That could become a power aware behaviour but the truely power oblivious office suite is a myth.
It is a sad day on LKML when we are busy digging pits for each other. On the other hand, I have seen far sadder days, and the pit you dug happens to lead somewhere useful. As Brian noted in his reply, the situation you call out can occur with manual suspend-to-RAM already:
the fact is that this is a design choice. You could indeed make a PM-driving office application if you wished, or run the same application as a power-oblivious application. There is a slight difference in the contract with the user. Of course, it is quite clear which one -you- prefer, but preferences can vary.
Quoted 8 lines
Quoted 4 lines
the screen is turned off, so these the applications do not need to use suspend blockers. That said, I could easily imagine that significant work would be required to make OpenOffice run on Android, not due to suspend blockers, but rather due to Android's unusual user space.
You are tightly linking suspend blockers with Android. If they were a sensible general solution they would be generic not tied closely to Android
Android is certainly where suspend blockers originated, and is to the best of my knowledge is still the only platform that uses them. But there is a first user of every new mechanism, and for some time that first user will by definition be the only user of that mechanism. So the fact that Android is most probably the only user of suspend blockers does not prove anything about whether or not suspend blockers are sensible.
Quoted 7 lines
Some of the other bad assumptions being made in this discussion:
- That the phone is special. Todays Android phones are up with the PC's of some years back (but with better graphics and more faster storage), in a few more generations of the technology what will they look like ? I'm sure that within a few years there will be people playing Warcraft or similar on their phone in the train.
Indeed, people have played games on their cellphones for some years. Not sure whether any of the games resembles World of Warcraft, but they probably soon will. If so, perhaps they will make use of significant hardware acceleration -- most other embedded systems do so.
But that doesn't guarantee that solutions developed for PCs and laptops will be optimal (or even usable) on cellphones. Sufficient difference in scale can easily change the form of the optimal solution, so you have not yet made your case. (For that matter, you also haven't proven that adoption of suspend blockers or something like them depends on the assumption that cellphones are special.)
Quoted 3 lines
- That Android will continue to tbe offering the same services in future as today. If it does it'll go the way of PalmOS and Symbian. Equally you can't just bust all the apps as it changes
I hope that no one is arguing that Android will remain unchanged, just as I hope no one would argue that Linux will remain unchanged. In fact, I am quite confident that both Linux and Android will continue to change. So exactly what point were you attempting to make here?
As to busting all apps, lthough there have been situations where busting all the apps turned out to be the right thing to do, I agree that these situations are extremely rare. Such situations are usually associated with the emergence of a new high-volume platform.
Quoted 8 lines
As devices get more complex and varied you cannot afford to put the detailed awareness of platform behaviour in the applications. It doesn't scale. Android developers are haivng enough fun coping with all the OS variants, customisations and new phones - and thats far less variety than PC hardware. Generally the PC app folks are not having the same level of problem - so ask why ?
From what I can see, the Android developers are suffering less than
the PC developers were suffering when the PC was the same age that Android is now. For that matter, suspend blockers don't put detailed awareness of platform behavior into apps. You must look to the heavily power-optimized apps to find that kind of awareness.
Quoted 8 lines
Quoted 6 lines
On devices that do not have suspend blockers, a normal application runs in a manner similar to a hypothetical Android application that acquires a suspend blocker when it starts and holds that suspend blocker until it exits. In contrast with Android, this situation requires that each and every application be carefully written to avoid battery drain, which I suspect is what Ted is getting at with his King Canute analogy.
Which is flawed and not the case.
Hmmm... Exactly which part do you consider flawed? Let's take it one sentence at a time. The devices that I know of that lack suspend blockers also lack opportunistic suspend. Therefore, all applications on such devices run as would an application that acquired a suspend blocker when it started and did not release that suspend blocker until it exited. Pretty straightforward.
As for the first part of the second sentence, you yourself have argued that each and every application should be carefully written to avoid battery drain (or, equivalently, to promote energy efficiency), so presumably the flaw does not reside there. That leaves the second half of that sentence, for which we both must defer to Ted. But Ted's intended meaning of his King Canute analogy does not affect the argument as to whether or not suspend blockers (or, again, something like them) are useful.
Quoted 6 lines
The same argument could be made for
multi-taskingDOS "Each application implements its own internal
multitasking/polling if needed"
Quoted 6 lines
Windows 3.x "Each application has an event loop and is built
in a certain way" (the 'suspend blocker' mentality)Real OS "The scheduler operates in a manner which prevents
CPU hogs breaking the system or abusing it sufficiently to threaten its functionality"
I really do like this progression. I will return to it further down.
Quoted 2 lines
The same applies to power. Only the OS has the big picture and can hide the hardware and general policy variety from the application.
The OS can be said to possess the full picture only if the applications communicate their portion of the picture to the OS. Linux has quite a few APIs devoted to this sort of communication, many of them mandated by POSIX. Some people are proposing suspend blockers (or something like them) as another member of this set of APIs.
Quoted 4 lines
OpenOffice runs on netbooks, laptops, servers, even big non x86 boxes. It runs on virtual machines, it runs in power sensitive environments, it runs in thermally constrained environments, it runs in I/O constrained environments, it runs in latency constrained environments etc etc
And there are numerous environments in which it will not run. So what?
Quoted 5 lines
All the same code, true some work has been done to make it behave politely but the rest is down to the OS doing its job - deploying the resources available while considering and obeying the constraints present, in a manner which makes best use of the resources to achieve the policy goals of the system.
And if the work has not been done on the application, and if there is nothing like suspend blockers, the OS cannot do its job. So how exactly does this support your position?
Which brings us to the progression from DOS to Windows 3.x to Real OS. Why can the Real OS's scheduler can operate "in a manner which prevents CPU hogs from breaking the system or abusing it sufficiently to threaten its functionality" while still allowing applications with special requirements to operate correctly? One reason is the advent of any number of APIs that communicate special properties of specific applications to the OS, including the old nice() system call, POSIX realtime, numerous facilities to communicate application properties to the VM system, and so on.
Given this context, are you sure that suspend blockers are not the next step in the Real OS progression? Or some QoS mechanism that subsumes suspend blockers? However, there is a lot of negative experience around general-purpose QoS mechanisms -- you have to be quite careful in order to avoid spending more energy computing QoS than you would otherwise spend on the application's computations. The usual way out of this trap is to abandon generality in favor of exploiting the commonly occurring special cases. For all I know, raw suspend blockers might be the appropriate special case.
Quoted 2 lines
And not unsurprisingly that all starts to look like Stafford Beer's good old viable systems model.
Hmmm... I do like "Absolutum Obsoletum", especially if it really does translate to "If it works it's out of date." However, I am not at all convinced that it supports your position! ;-)
Thanx, Paul
Re: Attempted summary of suspend-blockers LKML thread, take three
Quoted 2 lines
situation you call out can occur with manual suspend-to-RAM already:
the fact is that this is a design choice. You could indeed make a
Losing data is a design choice ? The application set a timer, the OS shouldn't be ignoring it in that situation. It might want to delay it, it might want to warn the user its hogging things it shouldnt (powertop, battery usage monitors in Android etc)
Quoted 3 lines
will by definition be the only user of that mechanism. So the fact that Android is most probably the only user of suspend blockers does not prove anything about whether or not suspend blockers are sensible.
They don't appear to solve the constraints on power management that you have in other environments, nor do they happen to be conveniently backward compatible or available on other platforms - which makes code hard to port.
Quoted 2 lines
But that doesn't guarantee that solutions developed for PCs and laptops will be optimal (or even usable) on cellphones. Sufficient difference
Your cellphone is to all intents a laptop from ten years ago, it even has a similar display resolution and internet availability. The underlying difference between the two is solely form factor - the laptop had a better keyboard.
Quoted 4 lines
I hope that no one is arguing that Android will remain unchanged, just as I hope no one would argue that Linux will remain unchanged. In fact, I am quite confident that both Linux and Android will continue to change. So exactly what point were you attempting to make here?
That anything which ties to a particular style of behaviour and set of current usage assumptions is broken. If you rewrite all the apps to Android 2.1 and design in a single tasking model then you'll have to unrewrite half of it again when Android grows up. Ditto suspend blockers
- encode too much policy in your apps and you lose the ability to change the environment under them. See the mess Microsoft got into with Win16 on Win32. Compare with Linux 32bit on Linux 64bit.
Quoted 4 lines
As to busting all apps, lthough there have been situations where busting all the apps turned out to be the right thing to do, I agree that these situations are extremely rare. Such situations are usually associated with the emergence of a new high-volume platform.
Like Microsoft Windows 16bit co-operative multi-tasking ? It's rarely right. It's merely that in certain cases the value in the market is large enough that it can be used as a big stick to beat people into doing lots of usually wasted work.
Quoted 6 lines
Hmmm... Exactly which part do you consider flawed? Let's take it one sentence at a time. The devices that I know of that lack suspend blockers also lack opportunistic suspend. Therefore, all applications on such devices run as would an application that acquired a suspend blocker when it started and did not release that suspend blocker until it exited. Pretty straightforward.
What do you mean by "opportunistic suspend", lots of systems drop into lowest power states whenever they can. "Suspend is different" is a bit of Android religion that I am dubious has any basis in reality as seen from the application end of the universe.
You may also wish to review the earlier parts of the discussion where it was explicitly stated by several developers that they were using "suspend" type modes as power states already and not using suspend blockers. So it's being done, today on ARM and your statement is directly contradicting the code. Modern ARM processors and x86 MID devices can suspend and resume extremely fast (fast enough that the fact Linux x86 rewriting all the SMP alternatives on suspend/resume is a measurable problem). If this same property doesn't end up on big PC boxes in time then I'd be very surprised. At that point the openoffice with suspend blockers or oracle with suspend blockers question becomes rather relevant.
Quoted 3 lines
As for the first part of the second sentence, you yourself have argued that each and every application should be carefully written to avoid battery drain (or, equivalently, to promote energy efficiency), so
No. I've argued that applications need to be generally well behaved, not keep waking up, not burn cpu - which is a generic property applicable on all environments not a specialisation.
Quoted 6 lines
Quoted 4 lines
OpenOffice runs on netbooks, laptops, servers, even big non x86 boxes. It runs on virtual machines, it runs in power sensitive environments, it runs in thermally constrained environments, it runs in I/O constrained environments, it runs in latency constrained environments etc etc
And there are numerous environments in which it will not run. So what?
It's one codebase for all of them and furthermore almost all of that was done by modifying only the OS. Linux learned to do power throttling without the app being involved, it learned to do virtualisation without the app being changed, it is learning (with -rt) to handle to do real time this way.
Quoted 8 lines
Quoted 5 lines
All the same code, true some work has been done to make it behave politely but the rest is down to the OS doing its job - deploying the resources available while considering and obeying the constraints present, in a manner which makes best use of the resources to achieve the policy goals of the system.
And if the work has not been done on the application, and if there is nothing like suspend blockers, the OS cannot do its job.
I don't see any evidence to support that claim. I see evidence that there are cases where apps wish to communicate their intentions around power more clearly but a suspend blocker is a crude single case hammer. Today most applications communicate their sleep/wake requirements fairly well by sleeping, by executing code and by setting timers/alarms.
Quoted 9 lines
Given this context, are you sure that suspend blockers are not the next step in the Real OS progression? Or some QoS mechanism that subsumes suspend blockers? However, there is a lot of negative experience around general-purpose QoS mechanisms -- you have to be quite careful in order to avoid spending more energy computing QoS than you would otherwise spend on the application's computations. The usual way out of this trap is to abandon generality in favor of exploiting the commonly occurring special cases. For all I know, raw suspend blockers might be the appropriate special case.
For Android possibly and I've never had any objection to Android keeping suspend blockers in private patches. The claim is only a small number are needed in their kernel so its a tiddly patch and the patch context will no doubt keep it applying between releases and easy for them to maintain.
For the rest of us - I see no evidence it's generally useful. A QoS API does appear to be generally useful but as you say you need to get the performance right. However you can also tackle that the way we tackle several other examples of one interface/many needs - such as schedulers, security models and the like.
One interface to applications and one interface to drivers so that its easy to maintain and you don't end up with hooks all over the place for different things, then if it proves neccessary different implementations. So yes maybe Android would use a "qos_basic" which returns -EOPNOTSUPP to anything but a suspend blocker behaviour. The important thing about that is that my device drivers, my applications and my other platforms don't have to care that Android made this choice - they can still be generic code.
That is why I used the Win16 example. The Win16 model encapsulated an implementation into the API. Had they followed a more conventional interface based around yielding then like MacOS they'd have had a far smoother move to pre-emptive MT.
Alan
Re: Attempted summary of suspend-blockers LKML thread, take three
Quoted 7 lines · Alan Cox
Quoted 2 lines
situation you call out can occur with manual suspend-to-RAM already:
the fact is that this is a design choice. You could indeed make aLosing data is a design choice ? The application set a timer, the OS shouldn't be ignoring it in that situation. It might want to delay it, it might want to warn the user its hogging things it shouldnt (powertop, battery usage monitors in Android etc)
So we should remove explicit system suspend from the kernel?
Quoted 12 lines
Quoted 6 lines
Hmmm... Exactly which part do you consider flawed? Let's take it one sentence at a time. The devices that I know of that lack suspend blockers also lack opportunistic suspend. Therefore, all applications on such devices run as would an application that acquired a suspend blocker when it started and did not release that suspend blocker until it exited. Pretty straightforward.
What do you mean by "opportunistic suspend", lots of systems drop into lowest power states whenever they can. "Suspend is different" is a bit of Android religion that I am dubious has any basis in reality as seen from the application end of the universe.
Quoted 10 lines
You may also wish to review the earlier parts of the discussion where it was explicitly stated by several developers that they were using "suspend" type modes as power states already and not using suspend blockers. So it's being done, today on ARM and your statement is directly contradicting the code. Modern ARM processors and x86 MID devices can suspend and resume extremely fast (fast enough that the fact Linux x86 rewriting all the SMP alternatives on suspend/resume is a measurable problem). If this same property doesn't end up on big PC boxes in time then I'd be very surprised. At that point the openoffice with suspend blockers or oracle with suspend blockers question becomes rather relevant.
There's a clear and absolute difference between system suspend and entering the same hardware state from the idle loop. That difference is that processes aren't scheduled until an explicit wakeup event occurs. Android is entirely capable of entering the same low power state at idle (it's done with a hardcoded idle loop on Qualcomm, cpuidle on omap), but if you have more than 0 scheduling wakeups a second then your power draw is going to be greater.
I agree that we should be targetting 0 wakeups per second. I don't agree that it's realistic to insist that a use model that assumes imperfect software is an invalid use model.
Signature · 1 line
Matthew Garrett | [email protected]
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Alan CoxQuoted 7 lines · Alan Cox
Quoted 2 lines
situation you call out can occur with manual suspend-to-RAM already:
the fact is that this is a design choice. You could indeed make aLosing data is a design choice ? The application set a timer, the OS shouldn't be ignoring it in that situation. It might want to delay it, it might want to warn the user its hogging things it shouldnt (powertop, battery usage monitors in Android etc)
So we should remove explicit system suspend from the kernel?
Quoted 12 lines
Quoted 6 lines
Hmmm... Exactly which part do you consider flawed? Let's take it one sentence at a time. The devices that I know of that lack suspend blockers also lack opportunistic suspend. Therefore, all applications on such devices run as would an application that acquired a suspend blocker when it started and did not release that suspend blocker until it exited. Pretty straightforward.
What do you mean by "opportunistic suspend", lots of systems drop into lowest power states whenever they can. "Suspend is different" is a bit of Android religion that I am dubious has any basis in reality as seen from the application end of the universe.
Quoted 10 lines
You may also wish to review the earlier parts of the discussion where it was explicitly stated by several developers that they were using "suspend" type modes as power states already and not using suspend blockers. So it's being done, today on ARM and your statement is directly contradicting the code. Modern ARM processors and x86 MID devices can suspend and resume extremely fast (fast enough that the fact Linux x86 rewriting all the SMP alternatives on suspend/resume is a measurable problem). If this same property doesn't end up on big PC boxes in time then I'd be very surprised. At that point the openoffice with suspend blockers or oracle with suspend blockers question becomes rather relevant.
There's a clear and absolute difference between system suspend and entering the same hardware state from the idle loop. That difference is that processes aren't scheduled until an explicit wakeup event occurs. Android is entirely capable of entering the same low power state at idle (it's done with a hardcoded idle loop on Qualcomm, cpuidle on omap), but if you have more than 0 scheduling wakeups a second then your power draw is going to be greater.
I agree that we should be targetting 0 wakeups per second. I don't agree that it's realistic to insist that a use model that assumes imperfect software is an invalid use model.
Signature · 1 line
Matthew Garrett | [email protected]
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Alan CoxQuoted 8 lines · Alan Cox
Quoted 3 lines
I have to worry about manually killing off applications when memory gets low, I actually thought it was incredibly sucky. It was a miniature, badly done laptop.
Likewise I thought the lack of proper multi-tasking apps in Android was comically bad. Nice device completely wrecked by the inability to flip between running apps each with their own screen - something that was old tech in 1990.
Rather beside the point for this thread and it's perhaps not so intuitive as it ought to be but holding down the home button should do what you're looking for here.
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Alan CoxQuoted 8 lines · Alan Cox
Quoted 3 lines
I have to worry about manually killing off applications when memory gets low, I actually thought it was incredibly sucky. It was a miniature, badly done laptop.
Likewise I thought the lack of proper multi-tasking apps in Android was comically bad. Nice device completely wrecked by the inability to flip between running apps each with their own screen - something that was old tech in 1990.
Rather beside the point for this thread and it's perhaps not so intuitive as it ought to be but holding down the home button should do what you're looking for here.
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Matthew GarrettQuoted 6 lines
Quoted 4 lines
Losing data is a design choice ? The application set a timer, the OS shouldn't be ignoring it in that situation. It might want to delay it, it might want to warn the user its hogging things it shouldnt (powertop, battery usage monitors in Android etc)
So we should remove explicit system suspend from the kernel?
Explicit suspend is user triggered - in the laptop case its a bit different. I don't btw like the fact that a laptop explicit suspend doesn't end up as a dbus "save data" and openoffice save (or it didn't last time I looked which is a while ago).
Quoted 7 lines
There's a clear and absolute difference between system suspend and entering the same hardware state from the idle loop. That difference is that processes aren't scheduled until an explicit wakeup event occurs. Android is entirely capable of entering the same low power state at idle (it's done with a hardcoded idle loop on Qualcomm, cpuidle on omap), but if you have more than 0 scheduling wakeups a second then your power draw is going to be greater.
And nothing stops you also implementing a 'forced' suspend, although you can do that nicely by simply stopping the process group that contains the stuff you don't want to stop suspend and dropping into suspend when you idle.
Quoted 3 lines
I agree that we should be targetting 0 wakeups per second. I don't agree that it's realistic to insist that a use model that assumes imperfect software is an invalid use model.
No argument.
The question is what applications should be expressing to the kernel which is not tied to assumptions like 'suspend mode' and which is generic.
We don't have xfs stuff for example splattered all over userspace and in lots of drivers - we have generic interfaces. That way user community A doesn't have to care about user community B's choices, and JFFS flash fs people don't offend big data centre people and vice versa.
Alan
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Matthew GarrettWhich reminds me. I forgot a very important way that user space signals the kernel as to its intents.
The kernel can see whether code is sleeping by choice or sleeping because someone blocked it (eg a page fault). The kernel also knows a lot about the event being waited for (much more so in -rt than base).
We don't capture all of that info but it seems it would advance progress in the right direction to do so better.
Alan
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Matthew GarrettWhich reminds me. I forgot a very important way that user space signals the kernel as to its intents.
The kernel can see whether code is sleeping by choice or sleeping because someone blocked it (eg a page fault). The kernel also knows a lot about the event being waited for (much more so in -rt than base).
We don't capture all of that info but it seems it would advance progress in the right direction to do so better.
Alan
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Alan CoxQuoted 11 lines · Alan Cox
Quoted 6 lines
Quoted 4 lines
Losing data is a design choice ? The application set a timer, the OS shouldn't be ignoring it in that situation. It might want to delay it, it might want to warn the user its hogging things it shouldnt (powertop, battery usage monitors in Android etc)
So we should remove explicit system suspend from the kernel?
Explicit suspend is user triggered - in the laptop case its a bit different. I don't btw like the fact that a laptop explicit suspend doesn't end up as a dbus "save data" and openoffice save (or it didn't last time I looked which is a while ago).
It's not inherently user triggered. Machines typically have an idle timeout that triggers suspend. This differs from the Android opportunistic suspend approach only in that the timeout is significantly larger, primarily due to the greater latency involved.
Quoted 8 lines
Quoted 7 lines
There's a clear and absolute difference between system suspend and entering the same hardware state from the idle loop. That difference is that processes aren't scheduled until an explicit wakeup event occurs. Android is entirely capable of entering the same low power state at idle (it's done with a hardcoded idle loop on Qualcomm, cpuidle on omap), but if you have more than 0 scheduling wakeups a second then your power draw is going to be greater.
Quoted 4 lines
And nothing stops you also implementing a 'forced' suspend, although you can do that nicely by simply stopping the process group that contains the stuff you don't want to stop suspend and dropping into suspend when you idle.
We've already had the discussion about this resulting in potential deadlocks if there's any intercommunication between the trusted and untrusted apps, and if untrusted apps can be the consumers of wakeup events then you still end up with the wake event race condition. If we want to avoid the case where system suspend can cause wakeup events to be lost, we're pretty much required to implement something like suspend blocks (and, in fact, Rafael's implementation of this is already mainline).
Quoted 6 lines
Quoted 3 lines
I agree that we should be targetting 0 wakeups per second. I don't agree that it's realistic to insist that a use model that assumes imperfect software is an invalid use model.
No argument.
Quoted 7 lines
The question is what applications should be expressing to the kernel which is not tied to assumptions like 'suspend mode' and which is generic.
We don't have xfs stuff for example splattered all over userspace and in lots of drivers - we have generic interfaces. That way user community A doesn't have to care about user community B's choices, and JFFS flash fs people don't offend big data centre people and vice versa.
I wholeheartedly agree. But nobody has yet provided a generic approach to avoiding the loss of wakeup events, and that's an issue you can hit whenever you use full-system suspend - it's not a problem that's unique to Android.
Signature · 1 line
Matthew Garrett | [email protected]
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Alan CoxQuoted 11 lines · Alan Cox
Quoted 6 lines
Quoted 4 lines
Losing data is a design choice ? The application set a timer, the OS shouldn't be ignoring it in that situation. It might want to delay it, it might want to warn the user its hogging things it shouldnt (powertop, battery usage monitors in Android etc)
So we should remove explicit system suspend from the kernel?
Explicit suspend is user triggered - in the laptop case its a bit different. I don't btw like the fact that a laptop explicit suspend doesn't end up as a dbus "save data" and openoffice save (or it didn't last time I looked which is a while ago).
It's not inherently user triggered. Machines typically have an idle timeout that triggers suspend. This differs from the Android opportunistic suspend approach only in that the timeout is significantly larger, primarily due to the greater latency involved.
Quoted 8 lines
Quoted 7 lines
There's a clear and absolute difference between system suspend and entering the same hardware state from the idle loop. That difference is that processes aren't scheduled until an explicit wakeup event occurs. Android is entirely capable of entering the same low power state at idle (it's done with a hardcoded idle loop on Qualcomm, cpuidle on omap), but if you have more than 0 scheduling wakeups a second then your power draw is going to be greater.
Quoted 4 lines
And nothing stops you also implementing a 'forced' suspend, although you can do that nicely by simply stopping the process group that contains the stuff you don't want to stop suspend and dropping into suspend when you idle.
We've already had the discussion about this resulting in potential deadlocks if there's any intercommunication between the trusted and untrusted apps, and if untrusted apps can be the consumers of wakeup events then you still end up with the wake event race condition. If we want to avoid the case where system suspend can cause wakeup events to be lost, we're pretty much required to implement something like suspend blocks (and, in fact, Rafael's implementation of this is already mainline).
Quoted 6 lines
Quoted 3 lines
I agree that we should be targetting 0 wakeups per second. I don't agree that it's realistic to insist that a use model that assumes imperfect software is an invalid use model.
No argument.
Quoted 7 lines
The question is what applications should be expressing to the kernel which is not tied to assumptions like 'suspend mode' and which is generic.
We don't have xfs stuff for example splattered all over userspace and in lots of drivers - we have generic interfaces. That way user community A doesn't have to care about user community B's choices, and JFFS flash fs people don't offend big data centre people and vice versa.
I wholeheartedly agree. But nobody has yet provided a generic approach to avoiding the loss of wakeup events, and that's an issue you can hit whenever you use full-system suspend - it's not a problem that's unique to Android.
Signature · 1 line
Matthew Garrett | [email protected]
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Matthew GarrettQuoted 32 lines · Matthew Garrett
Quoted 12 lines · Alan Cox
Quoted 6 lines
Hmmm... Exactly which part do you consider flawed? Let's take it one sentence at a time. The devices that I know of that lack suspend blockers also lack opportunistic suspend. Therefore, all applications on such devices run as would an application that acquired a suspend blocker when it started and did not release that suspend blocker until it exited. Pretty straightforward.
What do you mean by "opportunistic suspend", lots of systems drop into lowest power states whenever they can. "Suspend is different" is a bit of Android religion that I am dubious has any basis in reality as seen from the application end of the universe.
Quoted 10 lines
You may also wish to review the earlier parts of the discussion where it was explicitly stated by several developers that they were using "suspend" type modes as power states already and not using suspend blockers. So it's being done, today on ARM and your statement is directly contradicting the code. Modern ARM processors and x86 MID devices can suspend and resume extremely fast (fast enough that the fact Linux x86 rewriting all the SMP alternatives on suspend/resume is a measurable problem). If this same property doesn't end up on big PC boxes in time then I'd be very surprised. At that point the openoffice with suspend blockers or oracle with suspend blockers question becomes rather relevant.
There's a clear and absolute difference between system suspend and entering the same hardware state from the idle loop. That difference is that processes aren't scheduled until an explicit wakeup event occurs. Android is entirely capable of entering the same low power state at idle (it's done with a hardcoded idle loop on Qualcomm, cpuidle on omap), but if you have more than 0 scheduling wakeups a second then your power draw is going to be greater.
Quoted 3 lines
I agree that we should be targetting 0 wakeups per second. I don't agree that it's realistic to insist that a use model that assumes imperfect software is an invalid use model.
If the primary difference between sleep and suspend is not scheduling processes, instead of messing with oppurtinistic suspend/suspend blockers/wakelocks/etc, why not just 'temporarily' change the timer fuzz value to a very large value (say an hour). That would still let things like openoffice saves ahve a fair chance to trigger before the battery died completely, but would wake the system so infrequently that it will be effectivly the same as a full suspend.
David Lang
Re: Attempted summary of suspend-blockers LKML thread, take three
Quoted 7 lines · On Tue, Aug 10, 2010 at 11:07:20AM -0700, [email protected] wrote:
If the primary difference between sleep and suspend is not scheduling processes, instead of messing with oppurtinistic suspend/suspend blockers/wakelocks/etc, why not just 'temporarily' change the timer fuzz value to a very large value (say an hour). That would still let things like openoffice saves ahve a fair chance to trigger before the battery died completely, but would wake the system so infrequently that it will be effectivly the same as a full suspend.
Because it only affects processes that sleep. It's a question of how much pathology you want to be able to tolerate.
Signature · 1 line
Matthew Garrett | [email protected]
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to [email protected]Quoted 7 lines · On Tue, Aug 10, 2010 at 11:07:20AM -0700, [email protected] wrote:
If the primary difference between sleep and suspend is not scheduling processes, instead of messing with oppurtinistic suspend/suspend blockers/wakelocks/etc, why not just 'temporarily' change the timer fuzz value to a very large value (say an hour). That would still let things like openoffice saves ahve a fair chance to trigger before the battery died completely, but would wake the system so infrequently that it will be effectivly the same as a full suspend.
Because it only affects processes that sleep. It's a question of how much pathology you want to be able to tolerate.
Signature · 1 line
Matthew Garrett | [email protected]
Re: Attempted summary of suspend-blockers LKML thread, take three
Quoted 10 lines · Matthew Garrett
Quoted 7 lines · On Tue, Aug 10, 2010 at 11:07:20AM -0700, [email protected] wrote:
If the primary difference between sleep and suspend is not scheduling processes, instead of messing with oppurtinistic suspend/suspend blockers/wakelocks/etc, why not just 'temporarily' change the timer fuzz value to a very large value (say an hour). That would still let things like openoffice saves ahve a fair chance to trigger before the battery died completely, but would wake the system so infrequently that it will be effectivly the same as a full suspend.
Quoted 2 lines
Because it only affects processes that sleep. It's a question of how much pathology you want to be able to tolerate.
Standard system stats will show you hogs like this. The Android people claim that wakelock stats will let the user identify processes that prevent the system from suspending properly and then remove them. If this is the case, a process that never sleeps will be even easier to identify and even more obvious an offender.
If that isn't enough, then you can go back to the other idea I advanced, having some way to tell the system not to consider some processes when trying to decide if the system should sleep or not.
David Lang
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Matthew GarrettQuoted 10 lines · Matthew Garrett
Quoted 7 lines · On Tue, Aug 10, 2010 at 11:07:20AM -0700, [email protected] wrote:
If the primary difference between sleep and suspend is not scheduling processes, instead of messing with oppurtinistic suspend/suspend blockers/wakelocks/etc, why not just 'temporarily' change the timer fuzz value to a very large value (say an hour). That would still let things like openoffice saves ahve a fair chance to trigger before the battery died completely, but would wake the system so infrequently that it will be effectivly the same as a full suspend.
Quoted 2 lines
Because it only affects processes that sleep. It's a question of how much pathology you want to be able to tolerate.
Standard system stats will show you hogs like this. The Android people claim that wakelock stats will let the user identify processes that prevent the system from suspending properly and then remove them. If this is the case, a process that never sleeps will be even easier to identify and even more obvious an offender.
If that isn't enough, then you can go back to the other idea I advanced, having some way to tell the system not to consider some processes when trying to decide if the system should sleep or not.
David Lang
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Alan CoxQuoted 7 lines · Alan Cox
Quoted 2 lines
situation you call out can occur with manual suspend-to-RAM already:
the fact is that this is a design choice. You could indeed make aLosing data is a design choice ? The application set a timer, the OS shouldn't be ignoring it in that situation. It might want to delay it, it might want to warn the user its hogging things it shouldnt (powertop, battery usage monitors in Android etc)
Hmmm... Let's put the two approaches side by side so that we can compare them more easily:
Opportunistic Suspend Idle + Timer Jitter
Set timer Set timer
Suspend OS delays timer
Resume OS continues delaying timer
Timer fires Timer fires
These two cases look quite similar to me.
But as you say, the battery can run out. So let's add that to the comparison:
Opportunistic Suspend Idle + Timer Jitter
Set timer Set timer
Suspend OS delays timer
Battery runs out Battery runs out
Data loss Data loss
The two cases still look quite similar. You might note, quite correctly, that the time between suspend and resume might be quite a bit longer than the typical time that the OS delays a timer. But the power consumption on some platforms is quite a bit lower in the suspend case than it is in the delayed-timer case.
Quoted 8 lines
Quoted 3 lines
will by definition be the only user of that mechanism. So the fact that Android is most probably the only user of suspend blockers does not prove anything about whether or not suspend blockers are sensible.
They don't appear to solve the constraints on power management that you have in other environments, nor do they happen to be conveniently backward compatible or available on other platforms - which makes code hard to port.
There does seem to be some debate (if you can call it that) over whether suspend blockers (or something like them) apply to non-Android environments, though I do understand that you believe that suspend blockers are relevant only to Android. And indeed, adding features to a particular platform can degrade portability, but the same is true of any number of pre-existing Linux-specific features.
Quoted 7 lines
Quoted 2 lines
But that doesn't guarantee that solutions developed for PCs and laptops will be optimal (or even usable) on cellphones. Sufficient difference
Your cellphone is to all intents a laptop from ten years ago, it even has a similar display resolution and internet availability. The underlying difference between the two is solely form factor - the laptop had a better keyboard.
There are similarities and differences. You have called out some of the similarities. Differences include the more-aggressive hardware power management on cellphones, the greater number and variety of hardware accelerators on cellphones, battery capacity, and, as you say, physical size. People currently use cellphones differently than they do laptops or desktops. The usage might converge, but we will see. There is as much reason to expect increasing specialization as there is to expect increasing convergence.
Quoted 5 lines
Quoted 4 lines
I hope that no one is arguing that Android will remain unchanged, just as I hope no one would argue that Linux will remain unchanged. In fact, I am quite confident that both Linux and Android will continue to change. So exactly what point were you attempting to make here?
Quoted 7 lines
That anything which ties to a particular style of behaviour and set of current usage assumptions is broken. If you rewrite all the apps to Android 2.1 and design in a single tasking model then you'll have to unrewrite half of it again when Android grows up. Ditto suspend blockers
- encode too much policy in your apps and you lose the ability to change the environment under them. See the mess Microsoft got into with Win16 on Win32. Compare with Linux 32bit on Linux 64bit.
Yes, sooner or later, changes in environment and usage will break our assumptions. This includes your assumptions, my assumptions, the Android folks' assumptions, and everyone else's assumptions. We nevertheless build things anyway.
A better comparison for Win16->Win32 would be UNIX's move from 16-bit PDP-11 to 32-bit VAX. There was plenty of screaming over that one.
Quoted 9 lines
Quoted 4 lines
As to busting all apps, lthough there have been situations where busting all the apps turned out to be the right thing to do, I agree that these situations are extremely rare. Such situations are usually associated with the emergence of a new high-volume platform.
Like Microsoft Windows 16bit co-operative multi-tasking ? It's rarely right. It's merely that in certain cases the value in the market is large enough that it can be used as a big stick to beat people into doing lots of usually wasted work.
Interesting choice of example. I do well remember the Sequent hardware guys' frustration when the old printer driver would monopolize the desktop while printing their large documents. The fact was that Microsoft's co-operative multi-tasking required all applications to be well behaved, just as does your approach to power efficiency.
Quoted 11 lines
Quoted 6 lines
Hmmm... Exactly which part do you consider flawed? Let's take it one sentence at a time. The devices that I know of that lack suspend blockers also lack opportunistic suspend. Therefore, all applications on such devices run as would an application that acquired a suspend blocker when it started and did not release that suspend blocker until it exited. Pretty straightforward.
What do you mean by "opportunistic suspend", lots of systems drop into lowest power states whenever they can. "Suspend is different" is a bit of Android religion that I am dubious has any basis in reality as seen from the application end of the universe.
Opportunistic suspend has been well defined in this discussion. I do understand that you don't like opportunistic suspend, but your distaste for it does not undefine it.
Quoted 10 lines
You may also wish to review the earlier parts of the discussion where it was explicitly stated by several developers that they were using "suspend" type modes as power states already and not using suspend blockers. So it's being done, today on ARM and your statement is directly contradicting the code. Modern ARM processors and x86 MID devices can suspend and resume extremely fast (fast enough that the fact Linux x86 rewriting all the SMP alternatives on suspend/resume is a measurable problem). If this same property doesn't end up on big PC boxes in time then I'd be very surprised. At that point the openoffice with suspend blockers or oracle with suspend blockers question becomes rather relevant.
Here is the list of properties distinguishing idle from suspend:
1. Idle states are entered by a given CPU only there are no runnable
tasks for that CPU. In contrast, opportunistic suspend can halt the entire system even when there are tasks that are ready, willing, and able to run. (But please note that this might not apply to real-time tasks.)
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 idle. Exactly which events are in this set depends both on hardware capabilities and on the platform/application policy. For example, on one of the Android-based smartphones, touchscreen input is ignored when the system is suspended, but is handled when idle.
3. The system comes out of idle when a timer expires. In contrast,
timers might or might not bring the system out of suspend, depending on both hardware capabilities and platform/application policy.
4. Suspend generally forces devices to go into their low-power
states immediately. In contrast, idle generally leaves unused devices at full power, relying on timers to shut down these devices. Idle thus has shorter average wakeup latencies, but worse energy efficiency.
5. Suspend usually has longer wakeup latency than does idle.
This list was compiled from this thread.
It is the above semantics rather than the particular C-state that makes the difference between idle and suspend. Yes, you have claimed that idle will render suspend obsolete, but you have not yet convinced me.
Quoted 7 lines
Quoted 3 lines
As for the first part of the second sentence, you yourself have argued that each and every application should be carefully written to avoid battery drain (or, equivalently, to promote energy efficiency), so
No. I've argued that applications need to be generally well behaved, not keep waking up, not burn cpu - which is a generic property applicable on all environments not a specialisation.
Either way you prefer to word it is fine by me -- I am fine with either "carefully written" or "generally well behaved". Alternatively, if you were trying to say something different than what I said, I failed to spot the difference.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
OpenOffice runs on netbooks, laptops, servers, even big non x86 boxes. It runs on virtual machines, it runs in power sensitive environments, it runs in thermally constrained environments, it runs in I/O constrained environments, it runs in latency constrained environments etc etc
And there are numerous environments in which it will not run. So what?
It's one codebase for all of them
Yes, and there are still numerous environments where it does not run.
Quoted 5 lines
and furthermore almost all of that was
done by modifying only the OS. Linux learned to do power throttling without the app being involved, it learned to do virtualisation without the app being changed, it is learning (with -rt) to handle to do real time this way.
Except that you do modify the app to more effectively throttle power. Which is fine; I have no problem with that. I also have no problem with things that reduce the need to modify the apps to more effectively throttle power.
Real time indeed allows unmodified non-real-time apps to stay out of the way of very carefully written real-time apps, so I do like that example.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
All the same code, true some work has been done to make it behave politely but the rest is down to the OS doing its job - deploying the resources available while considering and obeying the constraints present, in a manner which makes best use of the resources to achieve the policy goals of the system.
Quoted 8 lines
Quoted 2 lines
And if the work has not been done on the application, and if there is nothing like suspend blockers, the OS cannot do its job.
I don't see any evidence to support that claim. I see evidence that there are cases where apps wish to communicate their intentions around power more clearly but a suspend blocker is a crude single case hammer. Today most applications communicate their sleep/wake requirements fairly well by sleeping, by executing code and by setting timers/alarms.
I will take your "there are cases where apps wish to communicate their intentions around power more clearly", thank you very much. And yes, there is much debate over exactly what form that communication might take.
Quoted 15 lines
Quoted 9 lines
Given this context, are you sure that suspend blockers are not the next step in the Real OS progression? Or some QoS mechanism that subsumes suspend blockers? However, there is a lot of negative experience around general-purpose QoS mechanisms -- you have to be quite careful in order to avoid spending more energy computing QoS than you would otherwise spend on the application's computations. The usual way out of this trap is to abandon generality in favor of exploiting the commonly occurring special cases. For all I know, raw suspend blockers might be the appropriate special case.
For Android possibly and I've never had any objection to Android keeping suspend blockers in private patches. The claim is only a small number are needed in their kernel so its a tiddly patch and the patch context will no doubt keep it applying between releases and easy for them to maintain.
Quoted 5 lines
For the rest of us - I see no evidence it's generally useful. A QoS API does appear to be generally useful but as you say you need to get the performance right. However you can also tackle that the way we tackle several other examples of one interface/many needs - such as schedulers, security models and the like.
No one will know whether or not suspend blockers are generally useful until they are willing to try them.
Quoted 8 lines
One interface to applications and one interface to drivers so that its easy to maintain and you don't end up with hooks all over the place for different things, then if it proves neccessary different implementations. So yes maybe Android would use a "
qos_basic" which returns-EOPNOTSUPPto anything but a suspend blocker behaviour. The important thing about that is that my device drivers, my applications and my other platforms don't have to care that Android made this choice - they can still be generic code.
If this can actually happen, I would consider it a good thing.
Of course, we might well find out some years down the road that the qos_basic piece is the only part that was actually in common use. Then again, it would not be the first time. System-V semaphores, anyone? ;-)
Quoted 4 lines
That is why I used the Win16 example. The Win16 model encapsulated an implementation into the API. Had they followed a more conventional interface based around yielding then like MacOS they'd have had a far smoother move to pre-emptive MT.
I am certainly no fan of Win16. That said, if there is a qos_basic that maps nicely to suspend blockers, the risk of adding suspend blockers in their current form seems to me to be rather low.
Thanx, Paul