Attempted summary of suspend-blockers LKML thread
Subsystems (4)
Re: Wakeup-events implementation
In reply to Arve HjønnevågQuoted 6 lines · Arve Hjønnevåg
Quoted 5 lines
Quoted 2 lines
A name is still useful if we allocate multiple handles per device (see below for why one handle per device is not enough).
Are the input queues are the only place where this is needed?
Quoted 6 lines
I don't know if it is the only place that is using more than one wakelock with a timeout per device. There are other drivers that use more than one wakelock, but it is possible they could use a single nested lock instead (with some detail loss in the the stats). I'm not sure every wakelock can be associated with a device though. For instance the mmc core wakelock does not have a corresponding device.
What other drivers need more than one wakelock per device?
For that matter, why does the MMC core need wakelocks at all? I wasn't aware that memory cards could generate wakeup events.
Quoted 6 lines
Quoted 5 lines
We'll figure out the best approach. You mentioned that when the timeouts and
pm_relaxdo get mixed, the timeout value is around 1 or 2 seconds. For these cases, would it be so terrible just to use the timeout alone and forget aboutpm_relax?
Quoted 6 lines
The timeout used when mixing timeouts and
wake_unlockare generally longer than when only using only timeouts since the timeouts are used to cover edge cases werewake_unlockdid not get called. Allowing timeouts andpm_relaxto be mixed may allow a gradual path from using timeouts to block suspend only when needed (timeouts only -> timeouts for edge cases -> no timeouts).
In fact, I rather expected you would say that the combined cancellations/timeouts were useful for pinpointing applications that don't read their input events quickly enough. If the wakelocks were always allowed to time out instead of being cancelled when the data was read, you wouldn't be able to tell whether the data was read in a timely manner or not.
Quoted 4 lines
We have also had bugs, where sensors generate input events whenever the system is not suspended. The 5 second timeout we have on input events is not short enough to allow the system to suspend at all in this case.
This sounds like the sort of bug that would be found very quickly and easily if you didn't have active cancellation. It would be pretty obvious when the system didn't suspend at all.
Quoted 4 lines
I see the kernel as trying to suspend if user space asked it to suspend (until it user space asks the kernel to stop suspending). Wakeup events that don't reach user space should not need user space support to reenter suspend.
That's debatable. For example, consider a Wake-On-LAN magic packet. It generally doesn't go anywhere -- it gets dropped once the system is awake.
Quoted 5 lines
You want each suspend attempt to be initiated by user space. Suspend is initiated from user space in both cases, the difference is that you want the suspend request to be one-shot, which means that the kernel may cancel the user space suspend request, where I want user space to explicitly cancel the request.
Yes, that's a fair way to describe the situation.
Quoted 10 lines
Quoted 6 lines
Do you have any examples where two subsystems use the same device but with differing expectations? In the examples I can think of, the non-nesting call is used only when a wakeup request is received (which happens only when the device is at low power), so the nesting calls can't interfere.
The wakeup request need to block suspend until the driver has seen the event. If the driver and the wakeup code uses the same handle how can you avoid interference?
Let's say the interrupt handlers responsible for invoking pm_request_resume use non-nesting calls. This may happen several times, depending on the wakeup and interrupt delivery mechanism, but the end result is that the counter is incremented only once. When the pm_runtime_resume call ends, pm_relax does a single decrement.
Meanwhile, the driver uses nesting calls. It can increment the counter as much as it wants, and it has to perform an equal number of decrements. The key point is that pm_request_resume never gets called while the driver has any outstanding pm_stay_awake requests. Hence the non-nesting calls never got "lost", since the first one is always made while the counter is 0.
Quoted 8 lines
Quoted 4 lines
We may end up attaching these wakeup structures not just to devices but also to input queues (or other
kernel->userspacecommunication channels).That is we do now (with wakelocks), but I think we need to pass this handle to the
pm_stay_wake... calls, and not the device, for this to work.
You may be right. Or we may need additional calls taking the handle as an argument rather than the device. The design requirements are still simmering in my mind, and I'm waiting to hear what Rafael thinks.
Quoted 26 lines
Quoted 20 lines
Here's an example where nested
pm_stay_awakecalls are needed. Suppose a USB root hub is enabled for wakeup (in other words, plugging or unplugging a USB device into the computer should wake the system up). Suppose the root hub is at low power (autosuspended) when a wakeup event occurs. The interrupt handler callspm_stay_awakeand indirectly invokes the USB runtime-resume routine. This routine brings the root hub back to full power, informs the hub driver, and then callspm_relax.But the hub driver carries out its main work in a separate kernel thread (i.e., khubd). So the
hub_resumeroutine has to callpm_stay_awake, and then khubd callspm_relaxwhen it is finished processing the root hub's event. Thus we end up with:usb_runtime_resume: call
pm_stay_awake(1) callhub_resume
hub_resume: callpm_stay_awake(2)
usb_runtime_resume: callpm_relax(balances 1)
khubd: callpm_relax(balances 2)Quoted 5 lines
As you can see, this won't work right if the pm wakeup calls aren't cumulative. ("Nested" isn't quite the right word.) The system would be allowed to sleep before khubd could process the root hub's wakeup event.
Quoted 4 lines
Too me this is an example of where two handles are needed, not where nesting is needed. Yes, you can use a single nested handle here, but the stats will not tell you which driver blocked suspend if there is a problem.
It sounds like you're suggesting that handles should be allocated per-driver rather than per-device. That would tell you which driver blocked suspend, but not which device.
This raises a few other questions.
With Android-based handsets, you're in a setting where you have a pretty good idea of what all the wakeup sources are and how they might get used. On a general system this isn't so. Many devices are potential wakeup sources, even though only a few of them end up getting enabled. In the example above, I said "Suppose a USB root hub is enabled for wakeup". But usually people won't want to do this; they don't want their suspended laptops to wake up when a USB mouse is unplugged or plugged in.
Allocating these wakeup structures for all possible wakeup sources would be a big waste. On the other hand, a driver generally doesn't know until a suspend starts whether or not its devices should be enabled for wakeup. That makes things difficult, especially if you contemplate having multiple structures for each device. Have you really sat down and thought about what wakelocks would be needed on a general system such as a desktop or laptop machine?
Also, I frankly have to wonder why you demand such a large amount of detailed debugging about the kernel's wakeup/wakelock subsystem (as opposed to userspace wakelocks). Yes, it's clear that if something goes wrong then you will drain your phone's battery in a few hours rather than a few days. But what if something goes wrong with the VM subsystem, or the RF subsystem, or the keypad driver? The device would crash immediately or at best become almost totally unusable. These are much worse scenarios than losing some battery life -- have you added comparable quantities of debugging to those other parts of the kernel?
In addition, you retain all these debugging facilities in your production builds, not just in the debug kernels. Doesn't this seem excessive?
Alan Stern
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Neil BrownQuoted 42 lines · Neil Brown
Quoted 16 lines · On Mon, 16 Aug 2010 20:20:32 -0400 Ted Ts'o <[email protected]> wrote:
Quoted 8 lines · Jesse Barnes
Fortunately in this case the problem doesn't seem to be fatal. We've already established that the userland API portion of suspend blockers could be implemented in userspace with a bit more work, given that the kernel problems with suspend/resume and events are addressed. Hopefully Google is already developing a prototype userspace implementation to make sure it's workable; being able to build stock upstream kernels for my Droid and its Android userspace sure would be nice.
You know, you don't have to wait for the Android engineers to do this work. You (or others who want to be able to use stock upstream kernel with Android devices) could just as easily try to do the "bit more work" yourselves --- that is, do the open souce thing and scratch one's own itch.
Quoted 8 lines
After all, Rafael is saying he's refusing to accept patches (or implement) in-kernel oppunsitic suspend for upstream unless it's proven to him that a userspace implementation isn't sufficient. It might be just as fair for the Android userspace upstream to refuse to accept (or engineer) userspace changes unless it is proven that the userspace version of opporunistic suspend is just as good as the in-kernel version which is successfully been deployed in millions and millions of shipping units today...
Reminds me of the one of the first questions asked in a murder investigation (or so they say on TV)
Cui Bono??Who benefits? Does Android benefit more by being able to use a standard kernel, or does Linux benefit more by being able to run Android without modification.
Currently it seems that only the lawyers^Wpeople who like arguing on lkml are gaining anything.
Maybe this is the first real fork of Linux - google might be rich enough to persist with it.
Quoted 8 lines
Quoted 5 lines
Speaking personally, it's not clear to me how waking up a userspace suspend daemon and waiting for it to get scheduled will result in better power savings than simply handling it in the kernel, but as soon as someone is willing to do the work, we can find out for sure who is right.
I'm surprised at this comment Ted!
Power saving is not the single supreme goal, yet you make it sound like it is.
My initial impression was also that power savings was Android's single supreme goal, but a careful reading of this thread and the ones preceding it taught me otherwise. Please see below for my current understanding of what they are trying to accomplish. As always, feedback is welcome!
Thanx, Paul
------------------------------------------------------------------------
Subject: Attempted summary of suspend-blockers LKML thread, epilogue 1
Final report from this particular angel-free zone for the time being...
This is the third^Wfourth and final version of my Android requirements list (last version available at http://lkml.org/lkml/2010/8/6/581).
Again, this email is an attempt to present the Android guys' requirements, based on my interpretation of LKML discussions. Thank you to 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 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 ACKNOWLEDGMENTS
DEFINITIONS
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.
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 often has shorter average wakeup latencies, but on systems where suspend can use deeper sleep states than can idle, idle might have worse energy efficiency.
5. Suspend shuts down timekeeping, but deep idle currently
does not. Timekeeping requires periodic interrupts to correctly compute time. If these interrupts are spaced too far apart (for example, by minutes or hours), timekeeping can become inaccurate. The degree of inaccuracy and the permissible spacing intervals depends on the time-source hardware and the kernel configuration. (It might be possible to reduce the timekeeping system's dependency on periodic interrupts, but this is currently speculation rather than reality.)
6. Suspend usually has longer wakeup latency than does
idle.
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 from include/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_SUSPEND depend 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 It must be possible to apply power-oblivious coding techniques
to those code sequences in PM-driving applications where suspend blockers are not held.
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 with total_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_since is 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_blocker patch 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 the media_server and 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 Neil BrownQuoted 42 lines · Neil Brown
Quoted 16 lines · On Mon, 16 Aug 2010 20:20:32 -0400 Ted Ts'o <[email protected]> wrote:
Quoted 8 lines · Jesse Barnes
Fortunately in this case the problem doesn't seem to be fatal. We've already established that the userland API portion of suspend blockers could be implemented in userspace with a bit more work, given that the kernel problems with suspend/resume and events are addressed. Hopefully Google is already developing a prototype userspace implementation to make sure it's workable; being able to build stock upstream kernels for my Droid and its Android userspace sure would be nice.
You know, you don't have to wait for the Android engineers to do this work. You (or others who want to be able to use stock upstream kernel with Android devices) could just as easily try to do the "bit more work" yourselves --- that is, do the open souce thing and scratch one's own itch.
Quoted 8 lines
After all, Rafael is saying he's refusing to accept patches (or implement) in-kernel oppunsitic suspend for upstream unless it's proven to him that a userspace implementation isn't sufficient. It might be just as fair for the Android userspace upstream to refuse to accept (or engineer) userspace changes unless it is proven that the userspace version of opporunistic suspend is just as good as the in-kernel version which is successfully been deployed in millions and millions of shipping units today...
Reminds me of the one of the first questions asked in a murder investigation (or so they say on TV)
Cui Bono??Who benefits? Does Android benefit more by being able to use a standard kernel, or does Linux benefit more by being able to run Android without modification.
Currently it seems that only the lawyers^Wpeople who like arguing on lkml are gaining anything.
Maybe this is the first real fork of Linux - google might be rich enough to persist with it.
Quoted 8 lines
Quoted 5 lines
Speaking personally, it's not clear to me how waking up a userspace suspend daemon and waiting for it to get scheduled will result in better power savings than simply handling it in the kernel, but as soon as someone is willing to do the work, we can find out for sure who is right.
I'm surprised at this comment Ted!
Power saving is not the single supreme goal, yet you make it sound like it is.
My initial impression was also that power savings was Android's single supreme goal, but a careful reading of this thread and the ones preceding it taught me otherwise. Please see below for my current understanding of what they are trying to accomplish. As always, feedback is welcome!
Thanx, Paul
------------------------------------------------------------------------
Subject: Attempted summary of suspend-blockers LKML thread, epilogue 1
Final report from this particular angel-free zone for the time being...
This is the third^Wfourth and final version of my Android requirements list (last version available at http://lkml.org/lkml/2010/8/6/581).
Again, this email is an attempt to present the Android guys' requirements, based on my interpretation of LKML discussions. Thank you to 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 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 ACKNOWLEDGMENTS
DEFINITIONS
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.
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 often has shorter average wakeup latencies, but on systems where suspend can use deeper sleep states than can idle, idle might have worse energy efficiency.
5. Suspend shuts down timekeeping, but deep idle currently
does not. Timekeeping requires periodic interrupts to correctly compute time. If these interrupts are spaced too far apart (for example, by minutes or hours), timekeeping can become inaccurate. The degree of inaccuracy and the permissible spacing intervals depends on the time-source hardware and the kernel configuration. (It might be possible to reduce the timekeeping system's dependency on periodic interrupts, but this is currently speculation rather than reality.)
6. Suspend usually has longer wakeup latency than does
idle.
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 from include/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_SUSPEND depend 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 It must be possible to apply power-oblivious coding techniques
to those code sequences in PM-driving applications where suspend blockers are not held.
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 with total_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_since is 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_blocker patch 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 the media_server and 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: Wakeup-events implementation
In reply to Alan Stern--- On Tue, 8/17/10, Alan Stern <[email protected]> wrote:
I wasn't
Quoted 1 line
aware that memory cards could generate wakeup events.
Almost all MMC/SD hardware can generate reliable insert/remove events, in my experience. So MMC/SD drivers I've modified tend to treat them as wake events ... userspace can respond without polling constantly "did it change yet, huh, did it???"
Unfortunately Pierre spent a lot of time hard-wiring UNSAFE_RESUME assumptions into the MMC core, so lots of that stuff is currently (and needlessly) broken.
And of more experimental interest, something I don't recall being discussed here: I/O completions as wake events. Start an I/O, enter low power state, and wake when it completes. Easily done on lots of embedded hardware..
Re: Wakeup-events implementation
Quoted 10 lines · David Brownell
--- On Tue, 8/17/10, Alan Stern <[email protected]> wrote:
I wasn't
Quoted 1 line
aware that memory cards could generate wakeup events.
Almost all MMC/SD hardware can generate reliable insert/remove events, in my experience. So MMC/SD drivers I've modified tend to treat them as wake events ... userspace can respond without polling constantly "did it change yet, huh, did it???"
This is interesting in light of the fact that testing has shown many USB card readers don't track insert/remove events while in low-power mode. When they return to full power, if a card is present they always report a media change -- even if the card had been there all along. This makes autosuspend less useful than it might be.
Quoted 3 lines
Unfortunately Pierre spent a lot of time hard-wiring
UNSAFE_RESUMEassumptions into the MMC core, so lots of that stuff is currently (and needlessly) broken.
There's a difference between generating wakeup events for insert/remove and keeping track of media-change events. I wouldn't want my sleeping laptop to wake up when I insert or remove a memory card, but I would like it to recognize when a card has been changed. If the hardware can do one but not the other then Pierre's choice is understandable (although not in accord with Linus's preference).
Alan Stern
Re: Wakeup-events implementation
In reply to Alan SternQuoted 15 lines · Alan Stern
Quoted 6 lines · Arve Hjønnevåg
Quoted 5 lines
Quoted 2 lines
A name is still useful if we allocate multiple handles per device (see below for why one handle per device is not enough).
Are the input queues are the only place where this is needed?
Quoted 6 lines
I don't know if it is the only place that is using more than one wakelock with a timeout per device. There are other drivers that use more than one wakelock, but it is possible they could use a single nested lock instead (with some detail loss in the the stats). I'm not sure every wakelock can be associated with a device though. For instance the mmc core wakelock does not have a corresponding device.
Quoted 4 lines
What other drivers need more than one wakelock per device?
For that matter, why does the MMC core need wakelocks at all? I wasn't aware that memory cards could generate wakeup events.
Yes, that's interesting, although I _guess_ this is related to the events generated by inserting/removing a card.
Quoted 29 lines
Quoted 6 lines
Quoted 5 lines
We'll figure out the best approach. You mentioned that when the timeouts and
pm_relaxdo get mixed, the timeout value is around 1 or 2 seconds. For these cases, would it be so terrible just to use the timeout alone and forget aboutpm_relax?Quoted 6 lines
The timeout used when mixing timeouts and
wake_unlockare generally longer than when only using only timeouts since the timeouts are used to cover edge cases werewake_unlockdid not get called. Allowing timeouts andpm_relaxto be mixed may allow a gradual path from using timeouts to block suspend only when needed (timeouts only -> timeouts for edge cases -> no timeouts).In fact, I rather expected you would say that the combined cancellations/timeouts were useful for pinpointing applications that don't read their input events quickly enough. If the wakelocks were always allowed to time out instead of being cancelled when the data was read, you wouldn't be able to tell whether the data was read in a timely manner or not.
Quoted 4 lines
We have also had bugs, where sensors generate input events whenever the system is not suspended. The 5 second timeout we have on input events is not short enough to allow the system to suspend at all in this case.
This sounds like the sort of bug that would be found very quickly and easily if you didn't have active cancellation. It would be pretty obvious when the system didn't suspend at all.
Quoted 8 lines
Quoted 4 lines
I see the kernel as trying to suspend if user space asked it to suspend (until it user space asks the kernel to stop suspending). Wakeup events that don't reach user space should not need user space support to reenter suspend.
That's debatable. For example, consider a Wake-On-LAN magic packet. It generally doesn't go anywhere -- it gets dropped once the system is awake.
Yes. I think every event that would wake up a sleeping system should result in unfreezing user space.
Quoted 2 lines
Quoted 2 lines
You want each suspend attempt to be initiated by user space. Suspend is initiated from user space in both cases,
Not really. With wakelocks suspend may be initiated as a result of a driver dropping its wakelock, which doesn't qualify as "from user space" to me.
Quoted 5 lines
Quoted 3 lines
the difference is that you want the suspend request to be one-shot, which means that the kernel may cancel the user space suspend request, where I want user space to explicitly cancel the request.
Yes, that's a fair way to describe the situation.
I somewhat agree.
Quoted 29 lines
Quoted 10 lines
Quoted 6 lines
Do you have any examples where two subsystems use the same device but with differing expectations? In the examples I can think of, the non-nesting call is used only when a wakeup request is received (which happens only when the device is at low power), so the nesting calls can't interfere.
The wakeup request need to block suspend until the driver has seen the event. If the driver and the wakeup code uses the same handle how can you avoid interference?
Let's say the interrupt handlers responsible for invoking
pm_request_resumeuse non-nesting calls. This may happen several times, depending on the wakeup and interrupt delivery mechanism, but the end result is that the counter is incremented only once. When thepm_runtime_resumecall ends,pm_relaxdoes a single decrement.Meanwhile, the driver uses nesting calls. It can increment the counter as much as it wants, and it has to perform an equal number of decrements. The key point is that
pm_request_resumenever gets called while the driver has any outstandingpm_stay_awakerequests. Hence the non-nesting calls never got "lost", since the first one is always made while the counter is 0.Quoted 5 lines
Quoted 4 lines
We may end up attaching these wakeup structures not just to devices but also to input queues (or other
kernel->userspacecommunication channels).
Quoted 7 lines
Quoted 3 lines
That is we do now (with wakelocks), but I think we need to pass this handle to the
pm_stay_wake... calls, and not the device, for this to work.You may be right. Or we may need additional calls taking the handle as an argument rather than the device. The design requirements are still simmering in my mind, and I'm waiting to hear what Rafael thinks.
I actually like the idea of having two levels of calls, ie. pm_stay_awake(dev) calling something like __pm_stay_awake(handle), where the handle is read from struct dev_pm_info. And analogously for pm_relax().
Then, the object associated with the handle might be created when the device is enabled to wake up and destroyed when it's disabled to do that.
OTOH, if it's really necessary to use a "raw" handle (ie. without struct device), the caller of __pm_stay_awake() will allocate and free the "wakelock" object by itself as necessary.
As far as the names are concerned, I'd like to avoid allocating space for them whenever it is not necessary (like when the "wakelock" is pointed to by struct dev_pm_info, in which case it is simply sufficient to use the device name to refer to it).
Quoted 46 lines
Quoted 26 lines
Quoted 20 lines
Here's an example where nested
pm_stay_awakecalls are needed. Suppose a USB root hub is enabled for wakeup (in other words, plugging or unplugging a USB device into the computer should wake the system up). Suppose the root hub is at low power (autosuspended) when a wakeup event occurs. The interrupt handler callspm_stay_awakeand indirectly invokes the USB runtime-resume routine. This routine brings the root hub back to full power, informs the hub driver, and then callspm_relax.But the hub driver carries out its main work in a separate kernel thread (i.e., khubd). So the
hub_resumeroutine has to callpm_stay_awake, and then khubd callspm_relaxwhen it is finished processing the root hub's event. Thus we end up with:
usb_runtime_resume: callpm_stay_awake(1)
callhub_resume
hub_resume: callpm_stay_awake(2)
usb_runtime_resume: callpm_relax(balances 1)
khubd: callpm_relax(balances 2)Quoted 5 lines
As you can see, this won't work right if the pm wakeup calls aren't cumulative. ("Nested" isn't quite the right word.) The system would be allowed to sleep before khubd could process the root hub's wakeup event.
Quoted 4 lines
Too me this is an example of where two handles are needed, not where nesting is needed. Yes, you can use a single nested handle here, but the stats will not tell you which driver blocked suspend if there is a problem.
It sounds like you're suggesting that handles should be allocated per-driver rather than per-device. That would tell you which driver blocked suspend, but not which device.
This raises a few other questions.
With Android-based handsets, you're in a setting where you have a pretty good idea of what all the wakeup sources are and how they might get used. On a general system this isn't so. Many devices are potential wakeup sources, even though only a few of them end up getting enabled. In the example above, I said "Suppose a USB root hub is enabled for wakeup". But usually people won't want to do this; they don't want their suspended laptops to wake up when a USB mouse is unplugged or plugged in.
Quoted 2 lines
Allocating these wakeup structures for all possible wakeup sources would be a big waste.
Indeed.
Quoted 10 lines
On the other hand, a driver generally doesn't
know until a suspend starts whether or not its devices should be enabled for wakeup. That makes things difficult, especially if you contemplate having multiple structures for each device. Have you really sat down and thought about what wakelocks would be needed on a general system such as a desktop or laptop machine?Also, I frankly have to wonder why you demand such a large amount of detailed debugging about the kernel's wakeup/wakelock subsystem (as opposed to userspace wakelocks).
That also is my question.
Quoted 11 lines
Yes, it's clear that if something
goes wrong then you will drain your phone's battery in a few hours rather than a few days. But what if something goes wrong with the VM subsystem, or the RF subsystem, or the keypad driver? The device would crash immediately or at best become almost totally unusable. These are much worse scenarios than losing some battery life -- have you added comparable quantities of debugging to those other parts of the kernel?In addition, you retain all these debugging facilities in your production builds, not just in the debug kernels. Doesn't this seem excessive?
It definitely seems so.
Thanks,
Rafael
Re: Wakeup-events implementation
2010/8/17 Rafael J. Wysocki <[email protected]>:
Quoted 16 lines · Alan Stern
Quoted 15 lines · Arve Hjønnevåg
Quoted 13 lines
Quoted 6 lines
Quoted 3 lines
A name is still useful if we allocate multiple handles per device (see below for why one handle per device is not enough).
Are the input queues are the only place where this is needed?
I don't know if it is the only place that is using more than one wakelock with a timeout per device. There are other drivers that use more than one wakelock, but it is possible they could use a single nested lock instead (with some detail loss in the the stats). I'm not sure every wakelock can be associated with a device though. For instance the mmc core wakelock does not have a corresponding device.
Quoted 8 lines
Quoted 4 lines
What other drivers need more than one wakelock per device?
For that matter, why does the MMC core need wakelocks at all? I wasn't aware that memory cards could generate wakeup events.
Yes, that's interesting, although I _guess_ this is related to the events generated by inserting/removing a card.
That is my guess too, but it is also possible sdio wakeup events could also hit this code path.
Quoted 25 lines
Quoted 25 lines
Quoted 6 lines
Quoted 5 lines
We'll figure out the best approach. You mentioned that when the timeouts and
pm_relaxdo get mixed, the timeout value is around 1 or 2 seconds. For these cases, would it be so terrible just to use the timeout alone and forget aboutpm_relax?Quoted 6 lines
The timeout used when mixing timeouts and
wake_unlockare generally longer than when only using only timeouts since the timeouts are used to cover edge cases werewake_unlockdid not get called. Allowing timeouts andpm_relaxto be mixed may allow a gradual path from using timeouts to block suspend only when needed (timeouts only -> timeouts for edge cases -> no timeouts).In fact, I rather expected you would say that the combined cancellations/timeouts were useful for pinpointing applications that don't read their input events quickly enough. If the wakelocks were always allowed to time out instead of being cancelled when the data was read, you wouldn't be able to tell whether the data was read in a timely manner or not.
Quoted 4 lines
We have also had bugs, where sensors generate input events whenever the system is not suspended. The 5 second timeout we have on input events is not short enough to allow the system to suspend at all in this case.
Quoted 4 lines
Quoted 4 lines
This sounds like the sort of bug that would be found very quickly and easily if you didn't have active cancellation. It would be pretty obvious when the system didn't suspend at all.
We don't uncover all bugs during testing before we ship. For instance the bug could be triggered by a 3db party app, and there is value in making the system as robust as possible to both driver and user space bugs.
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
I see the kernel as trying to suspend if user space asked it to suspend (until it user space asks the kernel to stop suspending). Wakeup events that don't reach user space should not need user space support to reenter suspend.
Quoted 7 lines
Quoted 3 lines
That's debatable. For example, consider a Wake-On-LAN magic packet. It generally doesn't go anywhere -- it gets dropped once the system is awake.
Yes. I think every event that would wake up a sleeping system should result in unfreezing user space.
Returning all the way to user space for every wakeup event is a poor substitute for delivering the actual event to user space. If user space want to stay awake for 60 seconds after every wake-on-lan packet, how can it accomplish this if it does not get the event. If user space delays suspend for 60 seconds after every failed suspend attempt, a wake-on-lan packet that arrives just before it decided to suspend will be ignored.
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
You want each suspend attempt to be initiated by user space. Suspend is initiated from user space in both cases,
Not really. With wakelocks suspend may be initiated as a result of a driver dropping its wakelock, which doesn't qualify as "from user space" to me.
Sure, but only if user-space had already requested suspend.
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
the difference is that you want the suspend request to be one-shot, which means that the kernel may cancel the user space suspend request, where I want user space to explicitly cancel the request.
Quoted 28 lines
Quoted 1 line
Yes, that's a fair way to describe the situation.
I somewhat agree.
Quoted 24 lines
Quoted 10 lines
Quoted 6 lines
Do you have any examples where two subsystems use the same device but with differing expectations? In the examples I can think of, the non-nesting call is used only when a wakeup request is received (which happens only when the device is at low power), so the nesting calls can't interfere.
The wakeup request need to block suspend until the driver has seen the event. If the driver and the wakeup code uses the same handle how can you avoid interference?
Let's say the interrupt handlers responsible for invoking
pm_request_resumeuse non-nesting calls. This may happen several times, depending on the wakeup and interrupt delivery mechanism, but the end result is that the counter is incremented only once. When thepm_runtime_resumecall ends,pm_relaxdoes a single decrement.Meanwhile, the driver uses nesting calls. It can increment the counter as much as it wants, and it has to perform an equal number of decrements. The key point is that
pm_request_resumenever gets called while the driver has any outstandingpm_stay_awakerequests. Hence the non-nesting calls never got "lost", since the first one is always made while the counter is 0.
It sounds as if you are saying that the two drivers don't interfere because one of them always gets there first. In your example if another interrupt occurs before the second driver still has released all its references on the counter, the interrupt will (incorrectly) not increment the count.
Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
We may end up attaching these wakeup structures not just to devices but also to input queues (or other
kernel->userspacecommunication channels).Quoted 7 lines
Quoted 3 lines
That is we do now (with wakelocks), but I think we need to pass this handle to the
pm_stay_wake... calls, and not the device, for this to work.You may be right. Or we may need additional calls taking the handle as an argument rather than the device. The design requirements are still simmering in my mind, and I'm waiting to hear what Rafael thinks.
Quoted 7 lines
I actually like the idea of having two levels of calls, ie.
pm_stay_awake(dev)calling something like__pm_stay_awake(handle), where the handle is read from structdev_pm_info. And analogously forpm_relax().Then, the object associated with the handle might be created when the device is enabled to wake up and destroyed when it's disabled to do that.
When multiple drivers use the same device, who creates and destroys the handle?
Quoted 4 lines
OTOH, if it's really necessary to use a "raw" handle (ie. without struct device), the caller of
__pm_stay_awake()will allocate and free the "wakelock" object by itself as necessary.
Quoted 40 lines
As far as the names are concerned, I'd like to avoid allocating space for them whenever it is not necessary (like when the "wakelock" is pointed to by struct
dev_pm_info, in which case it is simply sufficient to use the device name to refer to it).Quoted 35 lines
Quoted 26 lines
Quoted 20 lines
Here's an example where nested
pm_stay_awakecalls are needed. Suppose a USB root hub is enabled for wakeup (in other words, plugging or unplugging a USB device into the computer should wake the system up). Suppose the root hub is at low power (autosuspended) when a wakeup event occurs. The interrupt handler callspm_stay_awakeand indirectly invokes the USB runtime-resume routine. This routine brings the root hub back to full power, informs the hub driver, and then callspm_relax.But the hub driver carries out its main work in a separate kernel thread (i.e., khubd). So the
hub_resumeroutine has to callpm_stay_awake, and then khubd callspm_relaxwhen it is finished processing the root hub's event. Thus we end up with:usb_runtime_resume: call
pm_stay_awake(1) callhub_resume
hub_resume: callpm_stay_awake(2)
usb_runtime_resume: callpm_relax(balances 1)
khubd: callpm_relax(balances 2)Quoted 5 lines
As you can see, this won't work right if the pm wakeup calls aren't cumulative. ("Nested" isn't quite the right word.) The system would be allowed to sleep before khubd could process the root hub's wakeup event.
Quoted 4 lines
Too me this is an example of where two handles are needed, not where nesting is needed. Yes, you can use a single nested handle here, but the stats will not tell you which driver blocked suspend if there is a problem.
It sounds like you're suggesting that handles should be allocated per-driver rather than per-device. That would tell you which driver blocked suspend, but not which device.
Typically a driver puts a wakelock in the state that it already allocates for each device, so you have a handle for each device/driver combo that needs to block suspend.
Quoted 11 lines
Quoted 11 lines
This raises a few other questions.
With Android-based handsets, you're in a setting where you have a pretty good idea of what all the wakeup sources are and how they might get used. On a general system this isn't so. Many devices are potential wakeup sources, even though only a few of them end up getting enabled. In the example above, I said "Suppose a USB root hub is enabled for wakeup". But usually people won't want to do this; they don't want their suspended laptops to wake up when a USB mouse is unplugged or plugged in.
Quoted 8 lines
Quoted 2 lines
Allocating these wakeup structures for all possible wakeup sources would be a big waste.
Indeed.
Quoted 3 lines
On the other hand, a driver generally doesn't
know until a suspend starts whether or not its devices should be enabled for wakeup.
Why? How is the driver notified on suspend that it needs to be enabled for wakeup.
Quoted 4 lines
Quoted 4 lines
That makes things difficult, especially if you contemplate having multiple structures for each device. Have you really sat down and thought about what wakelocks would be needed on a general system such as a desktop or laptop machine?
No, I don't know what wakelocks are needed on a general system, but you need code to turn the wakeup events on and off events anyway, so I assume allocating a handle for the wakeup event is possible.
Quoted 7 lines
Quoted 4 lines
Also, I frankly have to wonder why you demand such a large amount of detailed debugging about the kernel's wakeup/wakelock subsystem (as opposed to userspace wakelocks).
That also is my question.
It is not that different from what you get from /proc/timer_list, /proc/meminfo etc. When the system does not suspend I want to know why.
Quoted 8 lines
Quoted 8 lines
Yes, it's clear that if something
goes wrong then you will drain your phone's battery in a few hours rather than a few days. But what if something goes wrong with the VM subsystem, or the RF subsystem, or the keypad driver? The device would crash immediately or at best become almost totally unusable. These are much worse scenarios than losing some battery life -- have you added comparable quantities of debugging to those other parts of the kernel?
We do track crashes and the kernel already dumps detailed debug information in that case. Also, I don't agree that a kernel crash is always worse than draining the battery. If you are away from a power source and the kernel crashes, the device reboots and you have a usable device again. If the battery drained, you cannot use the device again until you get to a power source.
Quoted 6 lines
Quoted 3 lines
In addition, you retain all these debugging facilities in your production builds, not just in the debug kernels. Doesn't this seem excessive?
It definitely seems so.
There are two reasons for keeping the debugging facilities in production builds.
1. The debugging information is useful for debugging problems in the field.
2. We want to test with the same code we ship.
Signature · 1 line
Arve Hjønnevåg
Re: Wakeup-events implementation
In reply to Alan SternQuoted 10 lines · On Tue, 17 Aug 2010 11:53:53 -0400 (EDT) Alan Stern…
Also, I frankly have to wonder why you demand such a large amount of detailed debugging about the kernel's wakeup/wakelock subsystem (as opposed to userspace wakelocks). Yes, it's clear that if something goes wrong then you will drain your phone's battery in a few hours rather than a few days. But what if something goes wrong with the VM subsystem, or the RF subsystem, or the keypad driver? The device would crash immediately or at best become almost totally unusable. These are much worse scenarios than losing some battery life -- have you added comparable quantities of debugging to those other parts of the kernel?
Quoted 4 lines
In addition, you retain all these debugging facilities in your production builds, not just in the debug kernels. Doesn't this seem excessive?
There is a theory about risk analysis and follow-up costs... i don't have anything concrete at hand but the main idea is that if you develop for example some monitoring for a production line of a pharmaceutical product, you have to take into consideration all possible failure-modes, the associated risk (likelihood * impact)
and the likelihood of detecting these failures before shipping.
A failure mode that is fatal (->high risk), and is not detectable before shipping is bad and a sign that you probably shouldn't produce at all.
A failure mode that is fatal (->high risk) but is detectable in all cases before shipping is not such a big problem.
With battery powered devices, you have failure-modes (run-time not optimal) that is not easily detectable before shipping. This is the worst kind of failure-mode because you don't know if it will happen or not.
The risk of this failure mode (non-optimal runtime) is bad also, because for mobile devices the runtime is critical and the fact that we talk about millions of devices will turn this up with a non-negligible probability.
So I totally understand that the android people want all the debugging they can get to make non-optimal runtime as visible as a broken vm or a not functioning keypad. After all, runtime is critical for mobile devices.
Cheers,
Flo
Re: Wakeup-events implementation
In reply to Arve HjønnevågQuoted 8 lines · Arve Hj?nnev?g
2010/8/17 Rafael J. Wysocki <[email protected]>:
Quoted 3 lines
Quoted 3 lines
On the other hand, a driver generally doesn't
know until a suspend starts whether or not its devices should be enabled for wakeup.Why? How is the driver notified on suspend that it needs to be enabled for wakeup.
There's the wakeup API in pm_wakeup.h, plus subsystem specific knowledge about what sensible defaults for the hardware in much the same way as we handle what to do when we suspend.
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
In addition, you retain all these debugging facilities in your production builds, not just in the debug kernels. ?Doesn't this seem excessive?
It definitely seems so.
There are two reasons for keeping the debugging facilities in production builds.
1. The debugging information is useful for debugging problems in the field.
2. We want to test with the same code we ship.
Plus the fact that power usage tends to be very dynamic often with strong dependencies on usage patterns. Power usage is something that end users will want to debug as well as developers, though most likely not in the same detail.
Re: Wakeup-events implementation
In reply to Arve HjønnevågQuoted 4 lines · Arve Hjønnevåg
We don't uncover all bugs during testing before we ship. For instance the bug could be triggered by a 3db party app, and there is value in making the system as robust as possible to both driver and user space bugs.
By that argument, all in-kernel wakelocks should always have a timeout.
What happens if somebody puts down their phone and then puts something on top of it, in such a way that one of the keypad buttons is depressed? If the keypad driver's wakelock doesn't have a timeout then the battery would drain quickly.
Quoted 9 lines
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
Wakeup events that don't reach user space should not need user space support to reenter suspend.
That's debatable. For example, consider a Wake-On-LAN magic packet. It generally doesn't go anywhere -- it gets dropped once the system is awake.
Yes. I think every event that would wake up a sleeping system should result in unfreezing user space.
In fact they do -- there's almost no way to avoid it. However, unfreezing userspace is different from sending a wakeup event to userspace.
The question is whether the kernel should automatically try to re-suspend following a wakeup for which no information was sent to userspace (e.g., WOL). The alternative, of course, is that the kernel does not try to re-suspend until a power-manager program tells it to. To me this seems more flexible and general (the PM program can always start a new suspend, whereas there's no way to prevent an automatic in-kernel re-suspend).
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
Let's say the interrupt handlers responsible for invoking
pm_request_resumeuse non-nesting calls. This may happen several times, depending on the wakeup and interrupt delivery mechanism, but the end result is that the counter is incremented only once. When thepm_runtime_resumecall ends,pm_relaxdoes a single decrement.Quoted 7 lines
Quoted 7 lines
Meanwhile, the driver uses nesting calls. It can increment the counter as much as it wants, and it has to perform an equal number of decrements. The key point is that
pm_request_resumenever gets called while the driver has any outstandingpm_stay_awakerequests. Hence the non-nesting calls never got "lost", since the first one is always made while the counter is 0.
Quoted 5 lines
It sounds as if you are saying that the two drivers don't interfere because one of them always gets there first. In your example if another interrupt occurs before the second driver still has released all its references on the counter, the interrupt will (incorrectly) not increment the count.
That's right -- one of them always gets there first. You're also right to suspect that this is an unusual situation. It arises with USB root hubs because a root hub is the only child of its parent controller device, and the only reason a controller would generate a wakeup request is because the root hub needs to wake up.
This means that a root-hub wakeup can be signalled in two different ways:
If the controller is in low-power then the controller sends its wakeup request. The controller's driver sets the controller back to full power, sees that the root hub has needs attention, and calls pm_request_resume for the root hub.
If the controller isn't in low-power then the root hub simply generates an IRQ. The interrupt handler calls pm_request_resume for the root hub.
Depending on how the timing works out, both can occur: The controller gets set to full power and then the IRQ line is signalled before the PM workqueue gets around to resuming the root hub. I have seen this happen while testing my computer.
With a little care, I could avoid calling pm_stay_awake twice. The code already sets a bitflag before queuing the resume request, and I could use test_and_set_bit instead. If I did then the non-nesting calls wouldn't be needed at all. And that was the only case I could think of where the two types of calls might need to be mixed.
Quoted 9 lines
Quoted 7 lines
I actually like the idea of having two levels of calls, ie.
pm_stay_awake(dev)calling something like__pm_stay_awake(handle), where the handle is read from structdev_pm_info. And analogously forpm_relax().Then, the object associated with the handle might be created when the device is enabled to wake up and destroyed when it's disabled to do that.
When multiple drivers use the same device, who creates and destroys the handle?
The primary driver (i.e., the one bound to the device) would use the device's handle. Other drivers would create and use their own separate wakeup structures.
But if all the calls are of the "nesting" sort then there's not really any need for multiple structures, other than to help identify which driver is misbehaving when a problem occurs.
Quoted 3 lines
Typically a driver puts a wakelock in the state that it already allocates for each device, so you have a handle for each device/driver combo that needs to block suspend.
You didn't answer my question about which devices have more than one associated wakelock in Android. Those would be the only cases where the device/driver combo matters.
Also, why does Android's MMC core have its own wakelock instead of using a per-device wakelock?
Quoted 11 lines
Quoted 8 lines
Quoted 2 lines
Allocating these wakeup structures for all possible wakeup sources would be a big waste.
Indeed.
Quoted 3 lines
On the other hand, a driver generally doesn't
know until a suspend starts whether or not its devices should be enabled for wakeup.Why? How is the driver notified on suspend that it needs to be enabled for wakeup.
The driver's (or bus subsystem's) suspend routine calls device_may_wakeup(dev) to see whether it should enable dev's wakeup mechanism. The value returned by device_may_wakeup can change at almost any time, since it is set by userspace.
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
That makes things difficult, especially if you contemplate having multiple structures for each device. Have you really sat down and thought about what wakelocks would be needed on a general system such as a desktop or laptop machine?
No, I don't know what wakelocks are needed on a general system, but you need code to turn the wakeup events on and off events anyway, so I assume allocating a handle for the wakeup event is possible.
Yes. However system suspend is generally not a good time to go around allocating new structures; memory tends to be tight then. I suppose it might be acceptable to do this during the "prepare" phase of system suspend.
Alan Stern
Re: Wakeup-events implementation
Quoted 28 lines · Alan Stern
Quoted 4 lines · Arve Hjønnevåg
We don't uncover all bugs during testing before we ship. For instance the bug could be triggered by a 3db party app, and there is value in making the system as robust as possible to both driver and user space bugs.
By that argument, all in-kernel wakelocks should always have a timeout.
What happens if somebody puts down their phone and then puts something on top of it, in such a way that one of the keypad buttons is depressed? If the keypad driver's wakelock doesn't have a timeout then the battery would drain quickly.
Quoted 9 lines
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
Wakeup events that don't reach user space should not need user space support to reenter suspend.
That's debatable. For example, consider a Wake-On-LAN magic packet. It generally doesn't go anywhere -- it gets dropped once the system is awake.
Yes. I think every event that would wake up a sleeping system should result in unfreezing user space.
In fact they do -- there's almost no way to avoid it. However, unfreezing userspace is different from sending a wakeup event to userspace.
Quoted 7 lines
The question is whether the kernel should automatically try to re-suspend following a wakeup for which no information was sent to userspace (e.g., WOL). The alternative, of course, is that the kernel does not try to re-suspend until a power-manager program tells it to. To me this seems more flexible and general (the PM program can always start a new suspend, whereas there's no way to prevent an automatic in-kernel re-suspend).
I agree.
Quoted 43 lines
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
Let's say the interrupt handlers responsible for invoking
pm_request_resumeuse non-nesting calls. This may happen several times, depending on the wakeup and interrupt delivery mechanism, but the end result is that the counter is incremented only once. When thepm_runtime_resumecall ends,pm_relaxdoes a single decrement.Quoted 7 lines
Quoted 7 lines
Meanwhile, the driver uses nesting calls. It can increment the counter as much as it wants, and it has to perform an equal number of decrements. The key point is that
pm_request_resumenever gets called while the driver has any outstandingpm_stay_awakerequests. Hence the non-nesting calls never got "lost", since the first one is always made while the counter is 0.Quoted 5 lines
It sounds as if you are saying that the two drivers don't interfere because one of them always gets there first. In your example if another interrupt occurs before the second driver still has released all its references on the counter, the interrupt will (incorrectly) not increment the count.
That's right -- one of them always gets there first. You're also right to suspect that this is an unusual situation. It arises with USB root hubs because a root hub is the only child of its parent controller device, and the only reason a controller would generate a wakeup request is because the root hub needs to wake up.
This means that a root-hub wakeup can be signalled in two different ways:
If the controller is in low-power then the controller sends its wakeup request. The controller's driver sets the controller back to full power, sees that the root hub has needs attention, and calls
pm_request_resumefor the root hub.If the controller isn't in low-power then the root hub simply generates an IRQ. The interrupt handler calls
pm_request_resumefor the root hub.Depending on how the timing works out, both can occur: The controller gets set to full power and then the IRQ line is signalled before the PM workqueue gets around to resuming the root hub. I have seen this happen while testing my computer.
Quoted 5 lines
With a little care, I could avoid calling
pm_stay_awaketwice. The code already sets a bitflag before queuing the resume request, and I could usetest_and_set_bitinstead. If I did then the non-nesting calls wouldn't be needed at all. And that was the only case I could think of where the two types of calls might need to be mixed.
That means one corner case less to worry about, good. :-)
Quoted 10 lines
Quoted 9 lines
Quoted 7 lines
I actually like the idea of having two levels of calls, ie.
pm_stay_awake(dev)calling something like__pm_stay_awake(handle), where the handle is read from structdev_pm_info. And analogously forpm_relax().Then, the object associated with the handle might be created when the device is enabled to wake up and destroyed when it's disabled to do that.
When multiple drivers use the same device, who creates and destroys the handle?
Quoted 7 lines
The primary driver (i.e., the one bound to the device) would use the device's handle. Other drivers would create and use their own separate wakeup structures.
But if all the calls are of the "nesting" sort then there's not really any need for multiple structures, other than to help identify which driver is misbehaving when a problem occurs.
Still, IMO we can do that if it would help to narrow the gap between the Android kernel and the mainline.
Quoted 33 lines
Quoted 3 lines
Typically a driver puts a wakelock in the state that it already allocates for each device, so you have a handle for each device/driver combo that needs to block suspend.
You didn't answer my question about which devices have more than one associated wakelock in Android. Those would be the only cases where the device/driver combo matters.
Also, why does Android's MMC core have its own wakelock instead of using a per-device wakelock?
Quoted 11 lines
Quoted 8 lines
Quoted 2 lines
Allocating these wakeup structures for all possible wakeup sources would be a big waste.
Indeed.
Quoted 3 lines
On the other hand, a driver generally doesn't
know until a suspend starts whether or not its devices should be enabled for wakeup.Why? How is the driver notified on suspend that it needs to be enabled for wakeup.
The driver's (or bus subsystem's) suspend routine calls
device_may_wakeup(dev)to see whether it should enable dev's wakeup mechanism. The value returned bydevice_may_wakeupcan change at almost any time, since it is set by userspace.Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
That makes things difficult, especially if you
contemplate having multiple structures for each device. Have you really sat down and thought about what wakelocks would be needed on a general system such as a desktop or laptop machine?
Quoted 6 lines
Quoted 3 lines
No, I don't know what wakelocks are needed on a general system, but you need code to turn the wakeup events on and off events anyway, so I assume allocating a handle for the wakeup event is possible.
Yes. However system suspend is generally not a good time to go around allocating new structures; memory tends to be tight then.
Well, that's what I wanted to do originally in pm_stay_awake(), but you convinced me it was avoidable. :-)
Quoted 2 lines
I suppose it might be acceptable to do this during the "prepare" phase of system suspend.
I generally think it would make sense to allocate a structure, call it struct wakeup_source for now, for each device or whatever part of the system that we want to treat as a wakeup source and put all of the statistics in there.
For devices it would be pretty straightforward, the structure is allocated as soon as the device is enabled to wakeup and freed when it is disabled. In the other cases it would have to depend on the usage scenario, I guess.
Rafael
Re: Wakeup-events implementation
2010/8/18 Rafael J. Wysocki <[email protected]>:
Quoted 10 lines · Alan Stern
Quoted 9 lines · Arve Hjønnevåg
Quoted 5 lines
We don't uncover all bugs during testing before we ship. For instance the bug could be triggered by a 3db party app, and there is value in making the system as robust as possible to both driver and user space bugs.
By that argument, all in-kernel wakelocks should always have a timeout.
I don't think that is the only conclusion.
Quoted 4 lines
Quoted 4 lines
What happens if somebody puts down their phone and then puts something on top of it, in such a way that one of the keypad buttons is depressed? If the keypad driver's wakelock doesn't have a timeout then the battery would drain quickly.
This is a real problem that might be worth solving, but just adding a wakelock timeout does not solve it since the keyboard driver would either renew the timeout after every scan, or it would leave the keyboard in a state where you could not use it to wake up the device anymore.
Quoted 23 lines
Quoted 15 lines
Quoted 10 lines
Quoted 10 lines
Quoted 7 lines
Quoted 3 lines
Wakeup events that don't reach user space should not need user space support to reenter suspend.
That's debatable. For example, consider a Wake-On-LAN magic packet. It generally doesn't go anywhere -- it gets dropped once the system is awake.
Yes. I think every event that would wake up a sleeping system should result in unfreezing user space.
In fact they do -- there's almost no way to avoid it. However, unfreezing userspace is different from sending a wakeup event to userspace.
Quoted 7 lines
The question is whether the kernel should automatically try to re-suspend following a wakeup for which no information was sent to userspace (e.g., WOL). The alternative, of course, is that the kernel does not try to re-suspend until a power-manager program tells it to. To me this seems more flexible and general (the PM program can always start a new suspend, whereas there's no way to prevent an automatic in-kernel re-suspend).
Quoted 2 lines
I agree.
Having user space initiate every suspend operation is more flexible out of the box, but you can get the same flexibility with the other approach by adding an interface to report all wakeup events and failed suspend attempts. However, I have not seen a use case for this flexibility other than as a partial workaround for wakeup events that user space needs to know about but are not reported to user space any other way (it is only a partial workaround since it still has the same race condition we are fixing for other wakeup events).
Quoted 65 lines
Quoted 43 lines
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
Let's say the interrupt handlers responsible for invoking
pm_request_resumeuse non-nesting calls. This may happen several times, depending on the wakeup and interrupt delivery mechanism, but the end result is that the counter is incremented only once. When thepm_runtime_resumecall ends,pm_relaxdoes a single decrement.Quoted 7 lines
Quoted 7 lines
Meanwhile, the driver uses nesting calls. It can increment the counter as much as it wants, and it has to perform an equal number of decrements. The key point is that
pm_request_resumenever gets called while the driver has any outstandingpm_stay_awakerequests. Hence the non-nesting calls never got "lost", since the first one is always made while the counter is 0.Quoted 5 lines
It sounds as if you are saying that the two drivers don't interfere because one of them always gets there first. In your example if another interrupt occurs before the second driver still has released all its references on the counter, the interrupt will (incorrectly) not increment the count.
That's right -- one of them always gets there first. You're also right to suspect that this is an unusual situation. It arises with USB root hubs because a root hub is the only child of its parent controller device, and the only reason a controller would generate a wakeup request is because the root hub needs to wake up.
This means that a root-hub wakeup can be signalled in two different ways:
If the controller is in low-power then the controller sends its wakeup request. The controller's driver sets the controller back to full power, sees that the root hub has needs attention, and calls
pm_request_resumefor the root hub.If the controller isn't in low-power then the root hub simply generates an IRQ. The interrupt handler calls
pm_request_resumefor the root hub.Depending on how the timing works out, both can occur: The controller gets set to full power and then the IRQ line is signalled before the PM workqueue gets around to resuming the root hub. I have seen this happen while testing my computer.
Quoted 5 lines
With a little care, I could avoid calling
pm_stay_awaketwice. The code already sets a bitflag before queuing the resume request, and I could usetest_and_set_bitinstead. If I did then the non-nesting calls wouldn't be needed at all. And that was the only case I could think of where the two types of calls might need to be mixed.That means one corner case less to worry about, good. :-)
Quoted 14 lines
Quoted 9 lines
Quoted 7 lines
I actually like the idea of having two levels of calls, ie.
pm_stay_awake(dev)calling something like__pm_stay_awake(handle), where the handle is read from structdev_pm_info. And analogously forpm_relax().Then, the object associated with the handle might be created when the device is enabled to wake up and destroyed when it's disabled to do that.
When multiple drivers use the same device, who creates and destroys the handle?
The primary driver (i.e., the one bound to the device) would use the device's handle. Other drivers would create and use their own separate wakeup structures.
Quoted 7 lines
Quoted 3 lines
But if all the calls are of the "nesting" sort then there's not really any need for multiple structures, other than to help identify which driver is misbehaving when a problem occurs.
Still, IMO we can do that if it would help to narrow the gap between the Android kernel and the mainline.
Some android drivers currently need the calls to be not nested so that they can mix timeouts and pm_relax. With only nesting apis we cannot get the same functionality.
Other drivers rely on the non nesting property of the existing wakelock api but do not use timeouts. I expect these drivers can be converted have the same behavior with a nested api, but there could be difficult edge cases.
Non-android driver may need a nested api so they can use a handle that they did not allocate. It is not clear to me if this is really needed. If it is not needed we can make all the calls non nested and require that the driver allocates a handle (or more commonly put the handle in the private data it already allocates). If we do need to keep the nested behavior, we a way to select which variant to use. We can have separate calls that nest and require drivers that use the non-nested variant have their own handle, or we could set a flag when creating a handle that makes calls on that handle not nest.
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Typically a driver puts a wakelock in the state that it already allocates for each device, so you have a handle for each device/driver combo that needs to block suspend.
You didn't answer my question about which devices have more than one associated wakelock in Android. Those would be the only cases where the device/driver combo matters.
Wakelocks are not associated with devices at all right now, so I don't have a list for you. However, the input queues need more than one wakelock per device if they use timeouts. In this case there is only one driver though, but the driver allocates a separate queue for each client that opens a device. Our keypad/gpio-keys driver may also end up using multiple wakelocks. Many phones use different keys types in the same logical keyboard, so you could end up with one wakelock for the matrix scan and another one for debouncing keys connected directly to a gpio. The driver could be changed to share a nested handle, but I prefer to keep them separate.
Quoted 3 lines
Quoted 3 lines
Also, why does Android's MMC core have its own wakelock instead of using a per-device wakelock?
There is a global work queue.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 2 lines
Allocating these wakeup structures for all possible wakeup sources would be a big waste.
Indeed.
Quoted 3 lines
On the other hand, a driver generally doesn't
know until a suspend starts whether or not its devices should be enabled for wakeup.
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
Why? How is the driver notified on suspend that it needs to be enabled for wakeup.
The driver's (or bus subsystem's) suspend routine calls
device_may_wakeup(dev)to see whether it should enable dev's wakeup mechanism. The value returned bydevice_may_wakeupcan change at almost any time, since it is set by userspace.
It would be better to allocate the structure when user space changes the setting. If you wait until suspend before blocking suspend you may have passed the event on already.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
That makes things difficult, especially if you
contemplate having multiple structures for each device. Have you really sat down and thought about what wakelocks would be needed on a general system such as a desktop or laptop machine?
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
No, I don't know what wakelocks are needed on a general system, but you need code to turn the wakeup events on and off events anyway, so I assume allocating a handle for the wakeup event is possible.
Yes. However system suspend is generally not a good time to go around allocating new structures; memory tends to be tight then.
I mean the code that lets user space turn wakeup events on and off, not the driver transferring a wakeup source from an interrupt to a wakeup controller.
Quoted 16 lines
Well, that's what I wanted to do originally in
pm_stay_awake(), but you convinced me it was avoidable. :-)Quoted 2 lines
I suppose it might be acceptable to do this during the "prepare" phase of system suspend.
I generally think it would make sense to allocate a structure, call it struct
wakeup_sourcefor now, for each device or whatever part of the system that we want to treat as a wakeup source and put all of the statistics in there.For devices it would be pretty straightforward, the structure is allocated as soon as the device is enabled to wakeup and freed when it is disabled. In the other cases it would have to depend on the usage scenario, I guess.
Rafael
Signature · 1 line
Arve Hjønnevåg
Re: Wakeup-events implementation
Quoted 9 lines · Arve Hjønnevåg
Quoted 2 lines
Quoted 2 lines
By that argument, all in-kernel wakelocks should always have a timeout.
I don't think that is the only conclusion.
Quoted 4 lines
Quoted 4 lines
What happens if somebody puts down their phone and then puts something on top of it, in such a way that one of the keypad buttons is depressed? If the keypad driver's wakelock doesn't have a timeout then the battery would drain quickly.
Quoted 5 lines
This is a real problem that might be worth solving, but just adding a wakelock timeout does not solve it since the keyboard driver would either renew the timeout after every scan, or it would leave the keyboard in a state where you could not use it to wake up the device anymore.
Okay. Nevertheless, you maintain debugging info in case a driver bug causes a wakelock not to be released. If the wakelocks all had timeouts then a bug of that sort wouldn't be able to affect battery life very much. So why not add the timeouts?
Or conversely, if you think the likelihood of such bugs is too low to worry about, then why have the debugging info?
Quoted 11 lines
Quoted 10 lines
Quoted 7 lines
The question is whether the kernel should automatically try to re-suspend following a wakeup for which no information was sent to userspace (e.g., WOL). The alternative, of course, is that the kernel does not try to re-suspend until a power-manager program tells it to. To me this seems more flexible and general (the PM program can always start a new suspend, whereas there's no way to prevent an automatic in-kernel re-suspend).
I agree.
Quoted 8 lines
Having user space initiate every suspend operation is more flexible out of the box, but you can get the same flexibility with the other approach by adding an interface to report all wakeup events and failed suspend attempts. However, I have not seen a use case for this flexibility other than as a partial workaround for wakeup events that user space needs to know about but are not reported to user space any other way (it is only a partial workaround since it still has the same race condition we are fixing for other wakeup events).
In any case, this is something that could easily be changed with a small Android-specific kernel patch. At the moment it doesn't seem to be a major issue.
Quoted 23 lines
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
When multiple drivers use the same device, who creates and destroys the handle?
The primary driver (i.e., the one bound to the device) would use the device's handle. Other drivers would create and use their own separate wakeup structures.
Quoted 7 lines
Quoted 3 lines
But if all the calls are of the "nesting" sort then there's not really any need for multiple structures, other than to help identify which driver is misbehaving when a problem occurs.
Still, IMO we can do that if it would help to narrow the gap between the Android kernel and the mainline.
Some android drivers currently need the calls to be not nested so that they can mix timeouts and
pm_relax. With only nesting apis we cannot get the same functionality.Other drivers rely on the non nesting property of the existing wakelock api but do not use timeouts. I expect these drivers can be converted have the same behavior with a nested api, but there could be difficult edge cases.
Quoted 9 lines
Non-android driver may need a nested api so they can use a handle that they did not allocate. It is not clear to me if this is really needed. If it is not needed we can make all the calls non nested and require that the driver allocates a handle (or more commonly put the handle in the private data it already allocates). If we do need to keep the nested behavior, we a way to select which variant to use. We can have separate calls that nest and require drivers that use the non-nested variant have their own handle, or we could set a flag when creating a handle that makes calls on that handle not nest.
I agree, there are several possible designs. It's hard to tell which will be best without more experience.
How much degradation do you think you would observe if in-kernel wakelocks _always_ used timeouts alone and _never_ were cancelled?
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
You didn't answer my question about which devices have more than one associated wakelock in Android. Those would be the only cases where the device/driver combo matters.
Quoted 10 lines
Wakelocks are not associated with devices at all right now, so I don't have a list for you. However, the input queues need more than one wakelock per device if they use timeouts. In this case there is only one driver though, but the driver allocates a separate queue for each client that opens a device. Our keypad/gpio-keys driver may also end up using multiple wakelocks. Many phones use different keys types in the same logical keyboard, so you could end up with one wakelock for the matrix scan and another one for debouncing keys connected directly to a gpio. The driver could be changed to share a nested handle, but I prefer to keep them separate.
Okay. In addition, we've already seen that devices for which you haven't yet implemented any wakelocks may end up needing more than one.
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
Also, why does Android's MMC core have its own wakelock instead of using a per-device wakelock?
There is a global work queue.
So you want to be able to cancel the wakelock whenever the queue is empty, right? And not have to keep track of whether each MMC device has any work items in the queue.
In theory this is insufficient -- it doesn't handle the case where one MMC device is enabled for wakeup and another isn't. I assume you don't really care about this (especially since Android phones aren't likely to have more than one MMC device capable of generating wakeup events).
Quoted 9 lines
Quoted 5 lines
Quoted 5 lines
The driver's (or bus subsystem's) suspend routine calls
device_may_wakeup(dev)to see whether it should enable dev's wakeup mechanism. The value returned bydevice_may_wakeupcan change at almost any time, since it is set by userspace.It would be better to allocate the structure when user space changes the setting. If you wait until suspend before blocking suspend you may have passed the event on already.
That will work for the structure directly associated with the device. Additional structures allocated by the drivers have to be handled differently, because the drivers aren't notified when the wakeup-enable setting is changed.
Alan Stern
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Paul E. McKenneyQuoted 25 lines · Paul E. McKenney
Quoted 16 lines · Felipe Contreras
Quoted 7 lines · Paul E. McKenney
Quoted 5 lines · Felipe Contreras
Quoted 2 lines
It seems to me that the same social-engineering approaches work in both cases.
Yes, but if dynamic PM works as advertised, you don't need opportunistic suspend.
Quoted 6 lines
For dynamic power management to totally eliminate the need for something like suspend blockers, you are having to make some brave assumptions. Yes, dynamic power management is quite useful, but there is a big difference between something being useful and something doing everything for everyone. You have not yet convinced me that dynamic power management will make it to the "doing everything for everyone" stage.
Quoted 7 lines
As it has been explained before, there's a sweet-spot of idleness:
http://article.gmane.org/gmane.linux.kernel/995525
http://article.gmane.org/gmane.linux.ports.arm.omap/37982Do you agree that there's such a thing, and if so, do you agree that the benefits of opportunistic suspend are much less once that point is reached?
Quoted 5 lines
I agree that there will be a sweet spot of idleness (though I would call it a "point of diminishing returns"), but only if all the applications are power-optimized. The advantage of opportunistic suspend is instead its tolerance of power-oblivious applications with minimal degradation of battery life.
sorry for the late response, the last week has been very hectic.
I just wanted to note that there is already a tool in the kernel to deal with this, the timer jitter/fuzz control. This can be set by an application for itself, or it can be set by some other process for an application (I don't remember the details of all the ways this can be set)
This could be used in a way similar to how userspace wakelocks are set today, if the power management process (that holds the wakelock and keep sthe screen lit today) thinks the system should be awake, let the jitter/fuzz be small, if that process thinks the system should probably be asleep, set the jitter/fuzz to a larger value. If other things are running anyway, the timers can fire and be serviced normally, otherwise the kernel is free to delay the timer going off even for badly written processes.
David Lang
Re: Wakeup-events implementation
In reply to Alan Stern2010/8/19 Alan Stern <[email protected]>:
Quoted 17 lines · Arve Hjønnevåg
Quoted 10 lines
Quoted 3 lines
Quoted 3 lines
By that argument, all in-kernel wakelocks should always have a timeout.
I don't think that is the only conclusion.
Quoted 4 lines
Quoted 4 lines
What happens if somebody puts down their phone and then puts something on top of it, in such a way that one of the keypad buttons is depressed? If the keypad driver's wakelock doesn't have a timeout then the battery would drain quickly.
Quoted 5 lines
This is a real problem that might be worth solving, but just adding a wakelock timeout does not solve it since the keyboard driver would either renew the timeout after every scan, or it would leave the keyboard in a state where you could not use it to wake up the device anymore.
Quoted 5 lines
Okay. Nevertheless, you maintain debugging info in case a driver bug causes a wakelock not to be released. If the wakelocks all had timeouts then a bug of that sort wouldn't be able to affect battery life very much. So why not add the timeouts?
Because we can't. I just described how the keypad driver would break we just add a timeout to its wakelock. Other drivers, like the usb gadget driver may need to block suspend for an extended time period.
Quoted 3 lines
Or conversely, if you think the likelihood of such bugs is too low to worry about, then why have the debugging info?
That statement assumes all the bugs can be fixed by adding timeouts, which I don't think is true. Also, you don't need to have bugs for the stats to be useful. The gps could for instance prevent suspend for a long time because the user ran a gps tracking app.
Quoted 20 lines
Quoted 11 lines
Quoted 10 lines
Quoted 7 lines
The question is whether the kernel should automatically try to re-suspend following a wakeup for which no information was sent to userspace (e.g., WOL). The alternative, of course, is that the kernel does not try to re-suspend until a power-manager program tells it to. To me this seems more flexible and general (the PM program can always start a new suspend, whereas there's no way to prevent an automatic in-kernel re-suspend).
I agree.
Quoted 8 lines
Having user space initiate every suspend operation is more flexible out of the box, but you can get the same flexibility with the other approach by adding an interface to report all wakeup events and failed suspend attempts. However, I have not seen a use case for this flexibility other than as a partial workaround for wakeup events that user space needs to know about but are not reported to user space any other way (it is only a partial workaround since it still has the same race condition we are fixing for other wakeup events).
Quoted 4 lines
In any case, this is something that could easily be changed with a small Android-specific kernel patch. At the moment it doesn't seem to be a major issue.
Yes, that seems to be a likely outcome.
Quoted 33 lines
Quoted 23 lines
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
When multiple drivers use the same device, who creates and destroys the handle?
The primary driver (i.e., the one bound to the device) would use the device's handle. Other drivers would create and use their own separate wakeup structures.
Quoted 7 lines
Quoted 3 lines
But if all the calls are of the "nesting" sort then there's not really any need for multiple structures, other than to help identify which driver is misbehaving when a problem occurs.
Still, IMO we can do that if it would help to narrow the gap between the Android kernel and the mainline.
Some android drivers currently need the calls to be not nested so that they can mix timeouts and
pm_relax. With only nesting apis we cannot get the same functionality.Other drivers rely on the non nesting property of the existing wakelock api but do not use timeouts. I expect these drivers can be converted have the same behavior with a nested api, but there could be difficult edge cases.
Quoted 9 lines
Non-android driver may need a nested api so they can use a handle that they did not allocate. It is not clear to me if this is really needed. If it is not needed we can make all the calls non nested and require that the driver allocates a handle (or more commonly put the handle in the private data it already allocates). If we do need to keep the nested behavior, we a way to select which variant to use. We can have separate calls that nest and require drivers that use the non-nested variant have their own handle, or we could set a flag when creating a handle that makes calls on that handle not nest.
Quoted 6 lines
I agree, there are several possible designs. It's hard to tell which will be best without more experience.
How much degradation do you think you would observe if in-kernel wakelocks _always_ used timeouts alone and _never_ were cancelled?
I don't think that is an option. We have kernel wakelocks that need to be held while the device is in a specific state.
Quoted 23 lines
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
You didn't answer my question about which devices have more than one associated wakelock in Android. Those would be the only cases where the device/driver combo matters.
Quoted 10 lines
Wakelocks are not associated with devices at all right now, so I don't have a list for you. However, the input queues need more than one wakelock per device if they use timeouts. In this case there is only one driver though, but the driver allocates a separate queue for each client that opens a device. Our keypad/gpio-keys driver may also end up using multiple wakelocks. Many phones use different keys types in the same logical keyboard, so you could end up with one wakelock for the matrix scan and another one for debouncing keys connected directly to a gpio. The driver could be changed to share a nested handle, but I prefer to keep them separate.
Okay. In addition, we've already seen that devices for which you haven't yet implemented any wakelocks may end up needing more than one.
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
Also, why does Android's MMC core have its own wakelock instead of using a per-device wakelock?
Quoted 6 lines
Quoted 1 line
There is a global work queue.
So you want to be able to cancel the wakelock whenever the queue is empty, right? And not have to keep track of whether each MMC device has any work items in the queue.
I have not reviewed that code, so I don't know the details of how it works or even if it is correct, but I see that it uses both timeouts and wake_unlock calls on the same wakelock.
Quoted 5 lines
In theory this is insufficient -- it doesn't handle the case where one MMC device is enabled for wakeup and another isn't. I assume you don't really care about this (especially since Android phones aren't likely to have more than one MMC device capable of generating wakeup events).
I'm not sure what you mean by insufficient here. If it not optimal if you also have work that does not need to prevent suspend, but it should still work correctly.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 5 lines
The driver's (or bus subsystem's) suspend routine calls
device_may_wakeup(dev)to see whether it should enable dev's wakeup mechanism. The value returned bydevice_may_wakeupcan change at almost any time, since it is set by userspace.
Quoted 9 lines
Quoted 3 lines
It would be better to allocate the structure when user space changes the setting. If you wait until suspend before blocking suspend you may have passed the event on already.
That will work for the structure directly associated with the device. Additional structures allocated by the drivers have to be handled differently, because the drivers aren't notified when the wakeup-enable setting is changed.
I'm not convinced that is it sufficient to detect that a device is wakeup-enabled on suspend. However it is not a problem I have tried to solve since we have only used static wakeup sources.
Signature · 1 line
Arve Hjønnevåg
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to [email protected]Quoted 41 lines · On Thu, Aug 19, 2010 at 04:10:10PM -0700, [email protected] wrote:
Quoted 25 lines · Paul E. McKenney
Quoted 16 lines · Felipe Contreras
Quoted 7 lines · Paul E. McKenney
Quoted 5 lines · Felipe Contreras
Quoted 2 lines
It seems to me that the same social-engineering approaches work in both cases.
Yes, but if dynamic PM works as advertised, you don't need opportunistic suspend.
Quoted 6 lines
For dynamic power management to totally eliminate the need for something like suspend blockers, you are having to make some brave assumptions. Yes, dynamic power management is quite useful, but there is a big difference between something being useful and something doing everything for everyone. You have not yet convinced me that dynamic power management will make it to the "doing everything for everyone" stage.
Quoted 7 lines
As it has been explained before, there's a sweet-spot of idleness:
http://article.gmane.org/gmane.linux.kernel/995525
http://article.gmane.org/gmane.linux.ports.arm.omap/37982Do you agree that there's such a thing, and if so, do you agree that the benefits of opportunistic suspend are much less once that point is reached?
Quoted 5 lines
I agree that there will be a sweet spot of idleness (though I would call it a "point of diminishing returns"), but only if all the applications are power-optimized. The advantage of opportunistic suspend is instead its tolerance of power-oblivious applications with minimal degradation of battery life.
sorry for the late response, the last week has been very hectic.
I just wanted to note that there is already a tool in the kernel to deal with this, the timer jitter/fuzz control. This can be set by an application for itself, or it can be set by some other process for an application (I don't remember the details of all the ways this can be set)
Quoted 8 lines
This could be used in a way similar to how userspace wakelocks are set today, if the power management process (that holds the wakelock and keep sthe screen lit today) thinks the system should be awake, let the jitter/fuzz be small, if that process thinks the system should probably be asleep, set the jitter/fuzz to a larger value. If other things are running anyway, the timers can fire and be serviced normally, otherwise the kernel is free to delay the timer going off even for badly written processes.
Indeed, Rafael and Alan Stern are working to make pm_qos do what the Android guys need, which could (very roughly) be thought of as extending the jitter/fuzz such that it meets Android's requirements.
Thanx, Paul
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to [email protected]Quoted 41 lines · On Thu, Aug 19, 2010 at 04:10:10PM -0700, [email protected] wrote:
Quoted 25 lines · Paul E. McKenney
Quoted 16 lines · Felipe Contreras
Quoted 7 lines · Paul E. McKenney
Quoted 5 lines · Felipe Contreras
Quoted 2 lines
It seems to me that the same social-engineering approaches work in both cases.
Yes, but if dynamic PM works as advertised, you don't need opportunistic suspend.
Quoted 6 lines
For dynamic power management to totally eliminate the need for something like suspend blockers, you are having to make some brave assumptions. Yes, dynamic power management is quite useful, but there is a big difference between something being useful and something doing everything for everyone. You have not yet convinced me that dynamic power management will make it to the "doing everything for everyone" stage.
Quoted 7 lines
As it has been explained before, there's a sweet-spot of idleness:
http://article.gmane.org/gmane.linux.kernel/995525
http://article.gmane.org/gmane.linux.ports.arm.omap/37982Do you agree that there's such a thing, and if so, do you agree that the benefits of opportunistic suspend are much less once that point is reached?
Quoted 5 lines
I agree that there will be a sweet spot of idleness (though I would call it a "point of diminishing returns"), but only if all the applications are power-optimized. The advantage of opportunistic suspend is instead its tolerance of power-oblivious applications with minimal degradation of battery life.
sorry for the late response, the last week has been very hectic.
I just wanted to note that there is already a tool in the kernel to deal with this, the timer jitter/fuzz control. This can be set by an application for itself, or it can be set by some other process for an application (I don't remember the details of all the ways this can be set)
Quoted 8 lines
This could be used in a way similar to how userspace wakelocks are set today, if the power management process (that holds the wakelock and keep sthe screen lit today) thinks the system should be awake, let the jitter/fuzz be small, if that process thinks the system should probably be asleep, set the jitter/fuzz to a larger value. If other things are running anyway, the timers can fire and be serviced normally, otherwise the kernel is free to delay the timer going off even for badly written processes.
Indeed, Rafael and Alan Stern are working to make pm_qos do what the Android guys need, which could (very roughly) be thought of as extending the jitter/fuzz such that it meets Android's requirements.
Thanx, Paul
Re: Wakeup-events implementation
In reply to Arve HjønnevågQuoted 9 lines · Arve Hjønnevåg
Quoted 5 lines
Okay. Nevertheless, you maintain debugging info in case a driver bug causes a wakelock not to be released. If the wakelocks all had timeouts then a bug of that sort wouldn't be able to affect battery life very much. So why not add the timeouts?
Because we can't. I just described how the keypad driver would break we just add a timeout to its wakelock. Other drivers, like the usb gadget driver may need to block suspend for an extended time period.
Some wakelocks can't use timeouts because they may have to be held for extended periods. But the others could have timeouts.
Quoted 6 lines
Quoted 3 lines
How much degradation do you think you would observe if in-kernel wakelocks _always_ used timeouts alone and _never_ were cancelled?
I don't think that is an option. We have kernel wakelocks that need to be held while the device is in a specific state.
Yes, but what about all the others? What I'm getting at is whether it's feasible for each wakelock to be exclusively used either with timeouts or cancellations, but never both.
Quoted 9 lines
Quoted 5 lines
In theory this is insufficient -- it doesn't handle the case where one MMC device is enabled for wakeup and another isn't. I assume you don't really care about this (especially since Android phones aren't likely to have more than one MMC device capable of generating wakeup events).
I'm not sure what you mean by insufficient here. If it not optimal if you also have work that does not need to prevent suspend, but it should still work correctly.
Yeah, that's what I meant. You would end up blocking suspends unnecessarily. It's okay if it doesn't happen very often.
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
It would be better to allocate the structure when user space changes the setting. If you wait until suspend before blocking suspend you may have passed the event on already.
Quoted 8 lines
Quoted 5 lines
That will work for the structure directly associated with the device. Additional structures allocated by the drivers have to be handled differently, because the drivers aren't notified when the wakeup-enable setting is changed.
I'm not convinced that is it sufficient to detect that a device is wakeup-enabled on suspend.
It isn't.
Quoted 2 lines
However it is not a problem I have tried to
solve since we have only used static wakeup sources.
Well, we may need to solve it eventually. One possible solution is to imitate what you're doing with MMC: Use a single per-driver wakelock instead of separate wakelocks for each driver/device combination. I don't know if that would work for all the cases, though.
Alan Stern
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Paul E. McKenneyHi!
Quoted 10 lines
Quoted 9 lines
You are *one* user of the kernel. Let's suppose Android wasn't using suspend-blockers, and there was another equally successful linux mobile platform, Foobingo, and they were using them, and they were the only ones interested on implementing them.
What does that change? Nothing. They still need to convince the community that what they are proposing to be merged is actually useful, and somebody will use it. If not, they can just keep the patch for themselves until they do. I don't see the big deal.
Quoted 7 lines
So the current users of the Linux kernel are the following?
o GNU/Linux
o AndroidDo any other distributions or devices with unusual user-space layouts qualify?
QTembedded distros are somehow similar to android (one big binary).
Then there's minor stuff, like webOS and Motorola A1200...
Pavel
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 three
In reply to Paul E. McKenneyHi!
Quoted 10 lines
Quoted 9 lines
You are *one* user of the kernel. Let's suppose Android wasn't using suspend-blockers, and there was another equally successful linux mobile platform, Foobingo, and they were using them, and they were the only ones interested on implementing them.
What does that change? Nothing. They still need to convince the community that what they are proposing to be merged is actually useful, and somebody will use it. If not, they can just keep the patch for themselves until they do. I don't see the big deal.
Quoted 7 lines
So the current users of the Linux kernel are the following?
o GNU/Linux
o AndroidDo any other distributions or devices with unusual user-space layouts qualify?
QTembedded distros are somehow similar to android (one big binary).
Then there's minor stuff, like webOS and Motorola A1200...
Pavel
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 three
Quoted 17 lines · Pavel Machek
Hi!
Quoted 15 lines
Quoted 9 lines
You are *one* user of the kernel. Let's suppose Android wasn't using suspend-blockers, and there was another equally successful linux mobile platform, Foobingo, and they were using them, and they were the only ones interested on implementing them.
What does that change? Nothing. They still need to convince the community that what they are proposing to be merged is actually useful, and somebody will use it. If not, they can just keep the patch for themselves until they do. I don't see the big deal.
So the current users of the Linux kernel are the following?
o GNU/Linux
o Android
Quoted 6 lines
Quoted 2 lines
Do any other distributions or devices with unusual user-space layouts qualify?
QTembedded distros are somehow similar to android (one big binary).
Then there's minor stuff, like webOS and Motorola A1200...
It does sounds like there is some variety, then. Thank you for the info!
Thanx, Paul
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Pavel MachekQuoted 17 lines · Pavel Machek
Hi!
Quoted 15 lines
Quoted 9 lines
You are *one* user of the kernel. Let's suppose Android wasn't using suspend-blockers, and there was another equally successful linux mobile platform, Foobingo, and they were using them, and they were the only ones interested on implementing them.
What does that change? Nothing. They still need to convince the community that what they are proposing to be merged is actually useful, and somebody will use it. If not, they can just keep the patch for themselves until they do. I don't see the big deal.
So the current users of the Linux kernel are the following?
o GNU/Linux
o Android
Quoted 6 lines
Quoted 2 lines
Do any other distributions or devices with unusual user-space layouts qualify?
QTembedded distros are somehow similar to android (one big binary).
Then there's minor stuff, like webOS and Motorola A1200...
It does sounds like there is some variety, then. Thank you for the info!
Thanx, Paul
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Jesse BarnesHi!
Quoted 25 lines
Quoted 25 lines
Quoted 11 lines
Quoted 8 lines
The question is why are we adding a user-space API that:
1) no user-space beside Android has expresses interest in implementing
2) is dubious whether the benefits are worth the pain for non-Android
user-space
3) will become less and less attractive as dynamic PM gets closer to
the sweet-spot, and then surpass it
4) Android can keep in a separate tree until it's clear in the linux
community that it's useful (if it ever happens)So, Felipe,
Quoted 8 lines
Do you believe you speak for all of LKML?
Are you willing to tell ZDNet and the Slashdot fanboys that it's OK for Suspend blockers to live in a separate tree, and it's not a case of OMG! Google is forking the kernel?
If you could speak out a passionately on those forums as you have here, that would be great.
Ted, what is going on here? Are you suggesting people disagreeing with Google patches suddenly have to do advocacy for Google?
And yes, for the record Felipe speaks for me pretty well.
Quoted 7 lines
Quoted 4 lines
Normal path of merging stuff to the kernel is
"Google develops it, then modifies it to address the review comments, then it is merged, then it is deployed".
Pavel, you should know better than this. You've been working on Linux long enough to know that development doesn't happen this way.
Well, I know that world is not always ideal, but it still surprised me how far from "ideal" Google got....
Quoted 4 lines
Although it would have been nice for Google to work more directly with upstream on their suspend blockers for Android, I don't think they could have made their product development cycle a slave to the politics of upstream development.
"Slave of upstream politics" would be going all the way; seeing the patches before there were million devices out there would also help a lot...
Quoted 4 lines
Fortunately in this case the problem doesn't seem to be fatal. We've already established that the userland API portion of suspend blockers could be implemented in userspace with a bit more work, given that the kernel problems with suspend/resume and events are addressed.
You are an optimist. Yes, I also hope it will work out fine, but...
Pavel
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 three
In reply to Jesse BarnesHi!
Quoted 25 lines
Quoted 25 lines
Quoted 11 lines
Quoted 8 lines
The question is why are we adding a user-space API that:
1) no user-space beside Android has expresses interest in implementing
2) is dubious whether the benefits are worth the pain for non-Android
user-space
3) will become less and less attractive as dynamic PM gets closer to
the sweet-spot, and then surpass it
4) Android can keep in a separate tree until it's clear in the linux
community that it's useful (if it ever happens)So, Felipe,
Quoted 8 lines
Do you believe you speak for all of LKML?
Are you willing to tell ZDNet and the Slashdot fanboys that it's OK for Suspend blockers to live in a separate tree, and it's not a case of OMG! Google is forking the kernel?
If you could speak out a passionately on those forums as you have here, that would be great.
Ted, what is going on here? Are you suggesting people disagreeing with Google patches suddenly have to do advocacy for Google?
And yes, for the record Felipe speaks for me pretty well.
Quoted 7 lines
Quoted 4 lines
Normal path of merging stuff to the kernel is
"Google develops it, then modifies it to address the review comments, then it is merged, then it is deployed".
Pavel, you should know better than this. You've been working on Linux long enough to know that development doesn't happen this way.
Well, I know that world is not always ideal, but it still surprised me how far from "ideal" Google got....
Quoted 4 lines
Although it would have been nice for Google to work more directly with upstream on their suspend blockers for Android, I don't think they could have made their product development cycle a slave to the politics of upstream development.
"Slave of upstream politics" would be going all the way; seeing the patches before there were million devices out there would also help a lot...
Quoted 4 lines
Fortunately in this case the problem doesn't seem to be fatal. We've already established that the userland API portion of suspend blockers could be implemented in userspace with a bit more work, given that the kernel problems with suspend/resume and events are addressed.
You are an optimist. Yes, I also hope it will work out fine, but...
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
RFC PATCH 1/1 PM / Wakeup: Introduce wakeup source objects and event statistics (was: Re: Wakeup-events implementation)
In reply to Alan SternHi,
Below is a patch that adds some statistics to the previously merged pm_wakeup_event()/pm_stay_awake()/pm_relax() code. It also makes it possible to use wakeup sources that are not directly associated with devices.
It adds functions for manipulating wakeup source objects and reworks the device wakeup enabling/disabling to use the new functions. The list of wakeup sources is only used for updating the "hit count" statistics for now (this is the number of times the wakeup source was active when the PM core checked), but I'm planning to add a /proc file listing all wakeup sources, including the ones that are not attached to device objects.
It appears to work with the PCI wakeup code added previously, but that's only one case. I'm also not sure if it builds withoug CONFIG_PM_SLEEP. [BTW, I'm not sure it atomic_inc() and atomic_dec() imply a memory barrier in general. That seems to be the case on x86, but I don't know about other architectures.]
Please have a look and let me know what you think.
Thanks,
Rafael
--- drivers/base/power/main.c | 3 drivers/base/power/power.h | 1 drivers/base/power/runtime.c | 2 drivers/base/power/sysfs.c | 121 +++++++++ drivers/base/power/wakeup.c | 532 ++++++++++++++++++++++++++++++++++++------- include/linux/pm.h | 16 - include/linux/pm_wakeup.h | 114 +++++++-- include/linux/suspend.h | 4 kernel/power/main.c | 8 9 files changed, 673 insertions(+), 128 deletions(-)
include/linux/pm_wakeup.h +89 -25
@@ -2,6 +2,7 @@* pm_wakeup.h - Power management wakeup interface * * Copyright (C) 2008 Alan Stern +* Copyright (C) 2010 Rafael J. Wysocki, Novell Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
@@ -27,18 +28,27 @@#include <linux/types.h> -#ifdef CONFIG_PM +struct wakeup_source { +char *name; +struct list_head entry; +spinlock_t lock; +struct timer_list timer; +unsigned long timer_expires; +ktime_t total_time; +ktime_t max_time; +ktime_t last_time; +unsigned long event_count; +unsigned long active_count; +unsigned long relax_count; +unsigned long hit_count; +unsigned int active:1 ; +}; -/* Changes to device_may_wakeup take effect on the next pm state change. -* -* By default, most devices should leave wakeup disabled. The exceptions -* are devices that everyone expects to be wakeup sources: keyboards, -* power buttons, possibly network interfaces, etc. +#ifdef CONFIG_PM_SLEEP + +/* +* Changes to device_may_wakeup take effect on the next pm state change. */ -static inline void device_init_wakeup (struct device *dev,bool val) -{ - dev->power.can_wakeup = dev->power.should_wakeup = val; -}static inline void device_set_wakeup_capable (struct device *dev,bool capable) {
@@ -50,23 +60,32 @@ static inline bool device_can_wakeup(strreturn dev->power.can_wakeup; } -static inline void device_set_wakeup_enable (struct device *dev,bool enable) -{ - dev->power.should_wakeup = enable; -} +static inline bool device_may_wakeup (struct device *dev) { -return dev->power.can_wakeup && dev->power.should_wakeup; +return dev->power.can_wakeup && !!dev->power.wakeup; } -#else /* !CONFIG_PM */ +/* drivers/base/power/wakeup.c */ +extern struct wakeup_source *wakeup_source_create (const char *name); +extern void wakeup_source_destroy (struct wakeup_source *ws); +extern void wakeup_source_register (struct wakeup_source *ws); +extern void wakeup_source_unregister (struct wakeup_source *ws); +extern struct wakeup_source *wakeup_source_add (const char *name); +extern void wakeup_source_remove (struct wakeup_source *ws); +extern int device_wakeup_enable (struct device *dev); +extern int device_wakeup_disable (struct device *dev); +extern int device_init_wakeup (struct device *dev,bool val); +extern int device_set_wakeup_enable (struct device *dev,bool enable); +extern void __pm_stay_awake (struct wakeup_source *ws); +extern void pm_stay_awake (struct device *dev); +extern void __pm_relax (struct wakeup_source *ws); +extern void pm_relax (struct device *dev); +extern void __pm_wakeup_event (struct wakeup_source *ws,unsigned int msec); +extern void pm_wakeup_event (struct device *dev,unsigned int msec); -/* For some reason the following routines work even without CONFIG_PM */ -static inline void device_init_wakeup (struct device *dev,bool val) -{ - dev->power.can_wakeup = val; -} +#else /* !CONFIG_PM_SLEEP */ static inline void device_set_wakeup_capable (struct device *dev,bool capable) {
@@ -78,15 +97,60 @@ static inline bool device_can_wakeup(strreturn dev->power.can_wakeup; } -static inline void device_set_wakeup_enable (struct device *dev,bool enable) +static inline bool device_may_wakeup (struct device *dev) { +return false; } -static inline bool device_may_wakeup (struct device *dev) +static inline struct wakeup_source *wakeup_source_create (char *name) { -return false; +return NULL ; +} + +static inline void wakeup_source_destroy (struct wakeup_source *ws) {} + +static inline void wakeup_source_register (struct wakeup_source *ws) {} + +static inline void wakeup_source_unregister (struct wakeup_source *ws) {} + +static inline struct wakeup_source *wakeup_source_add (char *name) +{ +return NULL ; } -#endif /* !CONFIG_PM */ +static inline void wakeup_source_remove (struct wakeup_source *ws) {} + +static inline int device_wakeup_enable (struct device *dev) +{ +return -EINVAL ; +} + +static inline int device_wakeup_disable (struct device *dev) {} + +static inline int device_init_wakeup (struct device *dev,bool val) +{ + dev->power.can_wakeup = val; +return val ? -EINVAL :0 ; +} + + +static inline int device_set_wakeup_enable (struct device *dev,bool enable) +{ +return -EINVAL ; +} + +static inline void __pm_stay_awake (struct wakeup_source *ws) {} + +static inline void pm_stay_awake (struct device *dev) {} + +static inline void __pm_relax (struct wakeup_source *ws) {} + +static inline void pm_relax (struct device *dev) {} + +static inline void __pm_wakeup_event (struct wakeup_source *ws,unsigned int msec) {} + +static inline void pm_wakeup_event (struct device *dev,unsigned int msec) {} + +#endif /* !CONFIG_PM_SLEEP */ #endif /* _LINUX_PM_WAKEUP_H */
include/linux/pm.h +4 -12
@@ -448,23 +448,24 @@ enum rpm_request { RPM_REQ_RESUME, }; +struct wakeup_source ; +struct dev_pm_info {pm_message_t power_state;unsigned int can_wakeup:1 ; -unsigned int should_wakeup:1 ;unsigned async_suspend:1 ;enum dpm_state status;/* Owned by the PM core */ +spinlock_t lock;#ifdef CONFIG_PM_SLEEP struct list_head entry;struct completion completion; -unsigned long wakeup_count; +struct wakeup_source *wakeup;#endif #ifdef CONFIG_PM_RUNTIME struct timer_list suspend_timer;unsigned long timer_expires;struct work_struct work;wait_queue_head_t wait_queue; -spinlock_t lock;atomic_t usage_count;atomic_t child_count;unsigned int disable_depth:3 ;
@@ -559,11 +560,6 @@ extern void __suspend_report_result(cons } while (0) extern void device_pm_wait_for_dev(struct device *sub, struct device *dev); - -/* drivers/base/power/wakeup.c */ -extern void pm_wakeup_event (struct device *dev,unsigned int msec); -extern void pm_stay_awake (struct device *dev); -extern void pm_relax (void );#else /* !CONFIG_PM_SLEEP */ #define device_pm_lock () do {} while (0)
@@ -577,10 +573,6 @@ static inline int dpm_suspend_start(pm_m#define suspend_report_result (fn, ret) do {} while (0)static inline void device_pm_wait_for_dev (struct device *a,struct device *b) {} - -static inline void pm_wakeup_event (struct device *dev,unsigned int msec) {} -static inline void pm_stay_awake (struct device *dev) {} -static inline void pm_relax (void ) {}#endif /* !CONFIG_PM_SLEEP */ /* How to reorder dpm_list after device_move() */
drivers/base/power/wakeup.c +452 -80
645 lines not on this page · raw message
drivers/base/power/main.c +2 -1
@@ -60,7 +60,8 @@ void device_pm_init(struct device *dev) dev->power.status =DPM_ON ;init_completion (&dev->power.completion);complete_all (&dev->power.completion); - dev->power.wakeup_count =0 ; + dev->power.wakeup =NULL ; +spin_lock_init (&dev->power.lock);pm_runtime_init (dev); }
drivers/base/power/power.h +1 -0
@@ -34,6 +34,7 @@ extern void device_pm_move_last(struct dstatic inline void device_pm_init (struct device *dev) { +spin_lock_init (&dev->power.lock);pm_runtime_init (dev); }
drivers/base/power/runtime.c +0 -2
@@ -1099,8 +1099,6 @@ EXPORT_SYMBOL_GPL(pm_runtime_allow);*/ void pm_runtime_init (struct device *dev) { -spin_lock_init (&dev->power.lock); - dev->power.runtime_status =RPM_SUSPENDED ; dev->power.idle_notification = false;
include/linux/suspend.h +2 -2
@@ -302,8 +302,8 @@ extern int unregister_pm_notifier(structextern bool events_check_enabled;extern bool pm_check_wakeup_events (void ); -extern bool pm_get_wakeup_count (unsigned long *count); -extern bool pm_save_wakeup_count (unsigned long count); +extern bool pm_get_wakeup_count (unsigned int *count); +extern bool pm_save_wakeup_count (unsigned int count);#else /* !CONFIG_PM_SLEEP */ static inline int register_pm_notifier (struct notifier_block *nb)
kernel/power/main.c +4 -4
@@ -237,18 +237,18 @@ static ssize_t wakeup_count_show(structstruct kobj_attribute *attr, char *buf) { - unsigned long val; + unsigned int val; -return pm_get_wakeup_count (&val) ?sprintf (buf,"%lu\n" , val) : -EINTR ; +return pm_get_wakeup_count (&val) ?sprintf (buf,"%u\n" , val) : -EINTR ; }static ssize_t wakeup_count_store (struct kobject *kobj,struct kobj_attribute *attr,const char *buf,size_t n) { -unsigned long val; +unsigned int val; -if (sscanf (buf,"%lu" , &val) ==1 ) { +if (sscanf (buf,"%u" , &val) ==1 ) {if (pm_save_wakeup_count (val))return n; }
drivers/base/power/sysfs.c +119 -2
136 lines not on this page · raw message
RFC PATCH 1/1 PM / Wakeup: Introduce wakeup source objects and event statistics (was: Re: Wakeup-events implementation)
In reply to Alan SternHi,
Below is a patch that adds some statistics to the previously merged pm_wakeup_event()/pm_stay_awake()/pm_relax() code. It also makes it possible to use wakeup sources that are not directly associated with devices.
It adds functions for manipulating wakeup source objects and reworks the device wakeup enabling/disabling to use the new functions. The list of wakeup sources is only used for updating the "hit count" statistics for now (this is the number of times the wakeup source was active when the PM core checked), but I'm planning to add a /proc file listing all wakeup sources, including the ones that are not attached to device objects.
It appears to work with the PCI wakeup code added previously, but that's only one case. I'm also not sure if it builds withoug CONFIG_PM_SLEEP. [BTW, I'm not sure it atomic_inc() and atomic_dec() imply a memory barrier in general. That seems to be the case on x86, but I don't know about other architectures.]
Please have a look and let me know what you think.
Thanks,
Rafael
--- drivers/base/power/main.c | 3 drivers/base/power/power.h | 1 drivers/base/power/runtime.c | 2 drivers/base/power/sysfs.c | 121 +++++++++ drivers/base/power/wakeup.c | 532 ++++++++++++++++++++++++++++++++++++------- include/linux/pm.h | 16 - include/linux/pm_wakeup.h | 114 +++++++-- include/linux/suspend.h | 4 kernel/power/main.c | 8 9 files changed, 673 insertions(+), 128 deletions(-)
include/linux/pm_wakeup.h +89 -25
@@ -2,6 +2,7 @@* pm_wakeup.h - Power management wakeup interface * * Copyright (C) 2008 Alan Stern +* Copyright (C) 2010 Rafael J. Wysocki, Novell Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
@@ -27,18 +28,27 @@#include <linux/types.h> -#ifdef CONFIG_PM +struct wakeup_source { +char *name; +struct list_head entry; +spinlock_t lock; +struct timer_list timer; +unsigned long timer_expires; +ktime_t total_time; +ktime_t max_time; +ktime_t last_time; +unsigned long event_count; +unsigned long active_count; +unsigned long relax_count; +unsigned long hit_count; +unsigned int active:1 ; +}; -/* Changes to device_may_wakeup take effect on the next pm state change. -* -* By default, most devices should leave wakeup disabled. The exceptions -* are devices that everyone expects to be wakeup sources: keyboards, -* power buttons, possibly network interfaces, etc. +#ifdef CONFIG_PM_SLEEP + +/* +* Changes to device_may_wakeup take effect on the next pm state change. */ -static inline void device_init_wakeup (struct device *dev,bool val) -{ - dev->power.can_wakeup = dev->power.should_wakeup = val; -}static inline void device_set_wakeup_capable (struct device *dev,bool capable) {
@@ -50,23 +60,32 @@ static inline bool device_can_wakeup(strreturn dev->power.can_wakeup; } -static inline void device_set_wakeup_enable (struct device *dev,bool enable) -{ - dev->power.should_wakeup = enable; -} +static inline bool device_may_wakeup (struct device *dev) { -return dev->power.can_wakeup && dev->power.should_wakeup; +return dev->power.can_wakeup && !!dev->power.wakeup; } -#else /* !CONFIG_PM */ +/* drivers/base/power/wakeup.c */ +extern struct wakeup_source *wakeup_source_create (const char *name); +extern void wakeup_source_destroy (struct wakeup_source *ws); +extern void wakeup_source_register (struct wakeup_source *ws); +extern void wakeup_source_unregister (struct wakeup_source *ws); +extern struct wakeup_source *wakeup_source_add (const char *name); +extern void wakeup_source_remove (struct wakeup_source *ws); +extern int device_wakeup_enable (struct device *dev); +extern int device_wakeup_disable (struct device *dev); +extern int device_init_wakeup (struct device *dev,bool val); +extern int device_set_wakeup_enable (struct device *dev,bool enable); +extern void __pm_stay_awake (struct wakeup_source *ws); +extern void pm_stay_awake (struct device *dev); +extern void __pm_relax (struct wakeup_source *ws); +extern void pm_relax (struct device *dev); +extern void __pm_wakeup_event (struct wakeup_source *ws,unsigned int msec); +extern void pm_wakeup_event (struct device *dev,unsigned int msec); -/* For some reason the following routines work even without CONFIG_PM */ -static inline void device_init_wakeup (struct device *dev,bool val) -{ - dev->power.can_wakeup = val; -} +#else /* !CONFIG_PM_SLEEP */ static inline void device_set_wakeup_capable (struct device *dev,bool capable) {
@@ -78,15 +97,60 @@ static inline bool device_can_wakeup(strreturn dev->power.can_wakeup; } -static inline void device_set_wakeup_enable (struct device *dev,bool enable) +static inline bool device_may_wakeup (struct device *dev) { +return false; } -static inline bool device_may_wakeup (struct device *dev) +static inline struct wakeup_source *wakeup_source_create (char *name) { -return false; +return NULL ; +} + +static inline void wakeup_source_destroy (struct wakeup_source *ws) {} + +static inline void wakeup_source_register (struct wakeup_source *ws) {} + +static inline void wakeup_source_unregister (struct wakeup_source *ws) {} + +static inline struct wakeup_source *wakeup_source_add (char *name) +{ +return NULL ; } -#endif /* !CONFIG_PM */ +static inline void wakeup_source_remove (struct wakeup_source *ws) {} + +static inline int device_wakeup_enable (struct device *dev) +{ +return -EINVAL ; +} + +static inline int device_wakeup_disable (struct device *dev) {} + +static inline int device_init_wakeup (struct device *dev,bool val) +{ + dev->power.can_wakeup = val; +return val ? -EINVAL :0 ; +} + + +static inline int device_set_wakeup_enable (struct device *dev,bool enable) +{ +return -EINVAL ; +} + +static inline void __pm_stay_awake (struct wakeup_source *ws) {} + +static inline void pm_stay_awake (struct device *dev) {} + +static inline void __pm_relax (struct wakeup_source *ws) {} + +static inline void pm_relax (struct device *dev) {} + +static inline void __pm_wakeup_event (struct wakeup_source *ws,unsigned int msec) {} + +static inline void pm_wakeup_event (struct device *dev,unsigned int msec) {} + +#endif /* !CONFIG_PM_SLEEP */ #endif /* _LINUX_PM_WAKEUP_H */
include/linux/pm.h +4 -12
@@ -448,23 +448,24 @@ enum rpm_request { RPM_REQ_RESUME, }; +struct wakeup_source ; +struct dev_pm_info {pm_message_t power_state;unsigned int can_wakeup:1 ; -unsigned int should_wakeup:1 ;unsigned async_suspend:1 ;enum dpm_state status;/* Owned by the PM core */ +spinlock_t lock;#ifdef CONFIG_PM_SLEEP struct list_head entry;struct completion completion; -unsigned long wakeup_count; +struct wakeup_source *wakeup;#endif #ifdef CONFIG_PM_RUNTIME struct timer_list suspend_timer;unsigned long timer_expires;struct work_struct work;wait_queue_head_t wait_queue; -spinlock_t lock;atomic_t usage_count;atomic_t child_count;unsigned int disable_depth:3 ;
@@ -559,11 +560,6 @@ extern void __suspend_report_result(cons } while (0) extern void device_pm_wait_for_dev(struct device *sub, struct device *dev); - -/* drivers/base/power/wakeup.c */ -extern void pm_wakeup_event (struct device *dev,unsigned int msec); -extern void pm_stay_awake (struct device *dev); -extern void pm_relax (void );#else /* !CONFIG_PM_SLEEP */ #define device_pm_lock () do {} while (0)
@@ -577,10 +573,6 @@ static inline int dpm_suspend_start(pm_m#define suspend_report_result (fn, ret) do {} while (0)static inline void device_pm_wait_for_dev (struct device *a,struct device *b) {} - -static inline void pm_wakeup_event (struct device *dev,unsigned int msec) {} -static inline void pm_stay_awake (struct device *dev) {} -static inline void pm_relax (void ) {}#endif /* !CONFIG_PM_SLEEP */ /* How to reorder dpm_list after device_move() */
drivers/base/power/wakeup.c +452 -80
645 lines not on this page · raw message
drivers/base/power/main.c +2 -1
@@ -60,7 +60,8 @@ void device_pm_init(struct device *dev) dev->power.status =DPM_ON ;init_completion (&dev->power.completion);complete_all (&dev->power.completion); - dev->power.wakeup_count =0 ; + dev->power.wakeup =NULL ; +spin_lock_init (&dev->power.lock);pm_runtime_init (dev); }
drivers/base/power/power.h +1 -0
@@ -34,6 +34,7 @@ extern void device_pm_move_last(struct dstatic inline void device_pm_init (struct device *dev) { +spin_lock_init (&dev->power.lock);pm_runtime_init (dev); }
drivers/base/power/runtime.c +0 -2
@@ -1099,8 +1099,6 @@ EXPORT_SYMBOL_GPL(pm_runtime_allow);*/ void pm_runtime_init (struct device *dev) { -spin_lock_init (&dev->power.lock); - dev->power.runtime_status =RPM_SUSPENDED ; dev->power.idle_notification = false;
include/linux/suspend.h +2 -2
@@ -302,8 +302,8 @@ extern int unregister_pm_notifier(structextern bool events_check_enabled;extern bool pm_check_wakeup_events (void ); -extern bool pm_get_wakeup_count (unsigned long *count); -extern bool pm_save_wakeup_count (unsigned long count); +extern bool pm_get_wakeup_count (unsigned int *count); +extern bool pm_save_wakeup_count (unsigned int count);#else /* !CONFIG_PM_SLEEP */ static inline int register_pm_notifier (struct notifier_block *nb)
kernel/power/main.c +4 -4
@@ -237,18 +237,18 @@ static ssize_t wakeup_count_show(structstruct kobj_attribute *attr, char *buf) { - unsigned long val; + unsigned int val; -return pm_get_wakeup_count (&val) ?sprintf (buf,"%lu\n" , val) : -EINTR ; +return pm_get_wakeup_count (&val) ?sprintf (buf,"%u\n" , val) : -EINTR ; }static ssize_t wakeup_count_store (struct kobject *kobj,struct kobj_attribute *attr,const char *buf,size_t n) { -unsigned long val; +unsigned int val; -if (sscanf (buf,"%lu" , &val) ==1 ) { +if (sscanf (buf,"%u" , &val) ==1 ) {if (pm_save_wakeup_count (val))return n; }
drivers/base/power/sysfs.c +119 -2
136 lines not on this page · raw message
Re: [RFC][PATCH] PM / Wakeup: Introduce wakeup source objects and event statistics (was: Re: Wakeup-events implementation)
Quoted 5 lines · Rafael J. Wysocki
Hi,
Below is a patch that adds some statistics to the previously merged pm_wakeup_event()/pm_stay_awake()/pm_relax() code. It also makes it possible to use wakeup sources that are not directly associated with devices.
I noted only a few things during a quick read-through. See below.
Quoted 6 lines
It adds functions for manipulating wakeup source objects and reworks the device wakeup enabling/disabling to use the new functions. The list of wakeup sources is only used for updating the "hit count" statistics for now (this is the number of times the wakeup source was active when the PM core checked), but I'm planning to add a /proc file listing all wakeup sources, including the ones that are not attached to device objects.
It must be obvious that this is starting to look more and more like the suspend_blockers patch. What that means or will lead to, I don't know...
Quoted 4 lines
It appears to work with the PCI wakeup code added previously, but that's only one case. I'm also not sure if it builds withoug
CONFIG_PM_SLEEP. [BTW, I'm not sure itatomic_inc()andatomic_dec()imply a memory barrier in general. That seems to be the case on x86, but I don't know about other architectures.]
They do not imply memory barriers. See the section on atomic operations in Documentation/memory-barriers.txt.
Quoted 7 lines
drivers/base/power/wakeup.c +7
-0+/** +* wakeup_source_create - Create a struct wakeup_source object. +* @name: Name of the new wakeup source. +*/ +struct wakeup_source *wakeup_source_create (const char *name) +{ +struct wakeup_source *ws;
drivers/base/power/wakeup.c line 54
Quoted 10 lines
drivers/base/power/wakeup.c +10
-0+ + ws =kzalloc (sizeof (*ws),GFP_KERNEL ); +if (!ws) +return NULL ; + +if (name) { +int len =strlen (name); +char *s =kzalloc (len +1 ,GFP_KERNEL ); +if (s) { +strncpy (s, name, len);
Would it be better to use kmalloc instead of kzalloc, call memcpy instead of strncpy, and write the terminating NUL character manually?
Quoted 8 lines
drivers/base/power/wakeup.c +8
-0+ ws->name = s; + } + } + +return ws; +} +EXPORT_SYMBOL_GPL (wakeup_source_create); +
drivers/base/power/wakeup.c line 72
Quoted 10 lines
drivers/base/power/wakeup.c +10
-0+/** +* wakeup_source_destroy - Destroy a struct wakeup_source object. +* @ws: Wakeup source to destroy. +*/ +void wakeup_source_destroy (struct wakeup_source *ws) +{ +if (!ws) +return ; + +spin_lock_irq (&ws->lock);
Since you use the spinlock here, it needs to be initialized in wakeup_source_create rather than wakeup_source_register.
drivers/base/power/wakeup.c line 83
Quoted 11 lines
drivers/base/power/wakeup.c +11
-0+while (ws->active) { +spin_unlock_irq (&ws->lock); + +schedule_timeout_interruptible (msecs_to_jiffies (TIMEOUT )); + +spin_lock_irq (&ws->lock); + } +spin_unlock_irq (&ws->lock); + +if (ws->name) +kfree (ws->name);
No need for the "if".
Quoted 23 lines
drivers/base/power/wakeup.c +23
-0+kfree (ws); +} +EXPORT_SYMBOL_GPL (wakeup_source_destroy); + +/** +* wakeup_source_register - Add given object to the list of wakeup sources. +* @ws: Wakeup source object to register. +*/ +void wakeup_source_register (struct wakeup_source *ws) +{ +if (WARN_ON (!ws)) +return ; + +spin_lock_init (&ws->lock); +setup_timer (&ws->timer, pm_wakeup_timer_fn, (unsigned long )ws); + ws->active = false; + +spin_lock_irq (&events_lock); +list_add_rcu (&ws->entry, &wakeup_sources); +spin_unlock_irq (&events_lock); +synchronize_rcu (); +} +EXPORT_SYMBOL_GPL (wakeup_source_register);
...
Quoted 5 lines
drivers/base/power/wakeup.c +5
-0+/** +* wakeup_source_add - Create and register a wakeup source object. +* @name: Name of the wakeup source to create. +*/ +struct wakeup_source *wakeup_source_add (const char *name)
drivers/base/power/wakeup.c line 138
Quoted 10 lines
drivers/base/power/wakeup.c +10
-0+{ +struct wakeup_source *ws; + + ws =wakeup_source_create (name); +if (ws) +wakeup_source_register (ws); + +return ws; +} +EXPORT_SYMBOL_GPL (wakeup_source_add);
Your use of names is backward. Normally the *_register routine does *_init followed by *_add.
I haven't looked through the rest in enough detail yet to make any meaningful comments.
Alan Stern
Re: [RFC][PATCH] PM / Wakeup: Introduce wakeup source objects and event statistics (was: Re: Wakeup-events implementation)
In reply to Rafael J. WysockiQuoted 5 lines · Rafael J. Wysocki
Hi,
Below is a patch that adds some statistics to the previously merged pm_wakeup_event()/pm_stay_awake()/pm_relax() code. It also makes it possible to use wakeup sources that are not directly associated with devices.
I noted only a few things during a quick read-through. See below.
Quoted 6 lines
It adds functions for manipulating wakeup source objects and reworks the device wakeup enabling/disabling to use the new functions. The list of wakeup sources is only used for updating the "hit count" statistics for now (this is the number of times the wakeup source was active when the PM core checked), but I'm planning to add a /proc file listing all wakeup sources, including the ones that are not attached to device objects.
It must be obvious that this is starting to look more and more like the suspend_blockers patch. What that means or will lead to, I don't know...
Quoted 4 lines
It appears to work with the PCI wakeup code added previously, but that's only one case. I'm also not sure if it builds withoug
CONFIG_PM_SLEEP. [BTW, I'm not sure itatomic_inc()andatomic_dec()imply a memory barrier in general. That seems to be the case on x86, but I don't know about other architectures.]
They do not imply memory barriers. See the section on atomic operations in Documentation/memory-barriers.txt.
Quoted 7 lines
drivers/base/power/wakeup.c +7
-0+/** +* wakeup_source_create - Create a struct wakeup_source object. +* @name: Name of the new wakeup source. +*/ +struct wakeup_source *wakeup_source_create (const char *name) +{ +struct wakeup_source *ws;
drivers/base/power/wakeup.c line 54
Quoted 10 lines
drivers/base/power/wakeup.c +10
-0+ + ws =kzalloc (sizeof (*ws),GFP_KERNEL ); +if (!ws) +return NULL ; + +if (name) { +int len =strlen (name); +char *s =kzalloc (len +1 ,GFP_KERNEL ); +if (s) { +strncpy (s, name, len);
Would it be better to use kmalloc instead of kzalloc, call memcpy instead of strncpy, and write the terminating NUL character manually?
Quoted 8 lines
drivers/base/power/wakeup.c +8
-0+ ws->name = s; + } + } + +return ws; +} +EXPORT_SYMBOL_GPL (wakeup_source_create); +
drivers/base/power/wakeup.c line 72
Quoted 10 lines
drivers/base/power/wakeup.c +10
-0+/** +* wakeup_source_destroy - Destroy a struct wakeup_source object. +* @ws: Wakeup source to destroy. +*/ +void wakeup_source_destroy (struct wakeup_source *ws) +{ +if (!ws) +return ; + +spin_lock_irq (&ws->lock);
Since you use the spinlock here, it needs to be initialized in wakeup_source_create rather than wakeup_source_register.
drivers/base/power/wakeup.c line 83
Quoted 11 lines
drivers/base/power/wakeup.c +11
-0+while (ws->active) { +spin_unlock_irq (&ws->lock); + +schedule_timeout_interruptible (msecs_to_jiffies (TIMEOUT )); + +spin_lock_irq (&ws->lock); + } +spin_unlock_irq (&ws->lock); + +if (ws->name) +kfree (ws->name);
No need for the "if".
Quoted 23 lines
drivers/base/power/wakeup.c +23
-0+kfree (ws); +} +EXPORT_SYMBOL_GPL (wakeup_source_destroy); + +/** +* wakeup_source_register - Add given object to the list of wakeup sources. +* @ws: Wakeup source object to register. +*/ +void wakeup_source_register (struct wakeup_source *ws) +{ +if (WARN_ON (!ws)) +return ; + +spin_lock_init (&ws->lock); +setup_timer (&ws->timer, pm_wakeup_timer_fn, (unsigned long )ws); + ws->active = false; + +spin_lock_irq (&events_lock); +list_add_rcu (&ws->entry, &wakeup_sources); +spin_unlock_irq (&events_lock); +synchronize_rcu (); +} +EXPORT_SYMBOL_GPL (wakeup_source_register);
...
Quoted 5 lines
drivers/base/power/wakeup.c +5
-0+/** +* wakeup_source_add - Create and register a wakeup source object. +* @name: Name of the wakeup source to create. +*/ +struct wakeup_source *wakeup_source_add (const char *name)
drivers/base/power/wakeup.c line 138
Quoted 10 lines
drivers/base/power/wakeup.c +10
-0+{ +struct wakeup_source *ws; + + ws =wakeup_source_create (name); +if (ws) +wakeup_source_register (ws); + +return ws; +} +EXPORT_SYMBOL_GPL (wakeup_source_add);
Your use of names is backward. Normally the *_register routine does *_init followed by *_add.
I haven't looked through the rest in enough detail yet to make any meaningful comments.
Alan Stern
Re: [RFC][PATCH] PM / Wakeup: Introduce wakeup source objects and event statistics (was: Re: Wakeup-events implementation)
Quoted 9 lines · Alan Stern
Quoted 5 lines · Rafael J. Wysocki
Hi,
Below is a patch that adds some statistics to the previously merged pm_wakeup_event()/pm_stay_awake()/pm_relax() code. It also makes it possible to use wakeup sources that are not directly associated with devices.
I noted only a few things during a quick read-through.
Great. :-)
Quoted 9 lines
See below.
Quoted 6 lines
It adds functions for manipulating wakeup source objects and reworks the device wakeup enabling/disabling to use the new functions. The list of wakeup sources is only used for updating the "hit count" statistics for now (this is the number of times the wakeup source was active when the PM core checked), but I'm planning to add a /proc file listing all wakeup sources, including the ones that are not attached to device objects.
Quoted 3 lines
It must be obvious that this is starting to look more and more like the
suspend_blockerspatch. What that means or will lead to, I don't know...
This actually is intentional, because I want to make it easier for the Android people to move their stuff towards the mainline, if they want to.
Quoted 7 lines
Quoted 4 lines
It appears to work with the PCI wakeup code added previously, but that's only one case. I'm also not sure if it builds withoug
CONFIG_PM_SLEEP. [BTW, I'm not sure itatomic_inc()andatomic_dec()imply a memory barrier in general. That seems to be the case on x86, but I don't know about other architectures.]They do not imply memory barriers. See the section on atomic operations in
Documentation/memory-barriers.txt.
Ah. Thanks for the pointer.
Quoted 12 lines
Quoted 12 lines
drivers/base/power/wakeup.c +12
-0+/** +* wakeup_source_create - Create a struct wakeup_source object. +* @name: Name of the new wakeup source. +*/ +struct wakeup_source *wakeup_source_create (const char *name) +{ +struct wakeup_source *ws; + + ws =kzalloc (sizeof (*ws),GFP_KERNEL ); +if (!ws) +return NULL ; +
Quoted 8 lines
drivers/base/power/wakeup.c line 54
Quoted 5 lines
drivers/base/power/wakeup.c +5
-0+if (name) { +int len =strlen (name); +char *s =kzalloc (len +1 ,GFP_KERNEL ); +if (s) { +strncpy (s, name, len);Would it be better to use kmalloc instead of kzalloc, call memcpy instead of strncpy, and write the terminating NUL character manually?
Yeah, thanks.
Quoted 13 lines
Quoted 13 lines
drivers/base/power/wakeup.c +13
-0+ ws->name = s; + } + } + +return ws; +} +EXPORT_SYMBOL_GPL (wakeup_source_create); + +/** +* wakeup_source_destroy - Destroy a struct wakeup_source object. +* @ws: Wakeup source to destroy. +*/ +void wakeup_source_destroy (struct wakeup_source *ws)
Quoted 8 lines
drivers/base/power/wakeup.c line 72
Quoted 5 lines
drivers/base/power/wakeup.c +5
-0+{ +if (!ws) +return ; + +spin_lock_irq (&ws->lock);Since you use the spinlock here, it needs to be initialized in
wakeup_source_createrather thanwakeup_source_register.
Yes, thanks.
Quoted 5 lines
Quoted 5 lines
drivers/base/power/wakeup.c +5
-0+while (ws->active) { +spin_unlock_irq (&ws->lock); + +schedule_timeout_interruptible (msecs_to_jiffies (TIMEOUT )); +
Quoted 8 lines
drivers/base/power/wakeup.c line 83
Quoted 6 lines
drivers/base/power/wakeup.c +6
-0+spin_lock_irq (&ws->lock); + } +spin_unlock_irq (&ws->lock); + +if (ws->name) +kfree (ws->name);No need for the "if".
OK
Quoted 36 lines
Quoted 23 lines
drivers/base/power/wakeup.c +23
-0+kfree (ws); +} +EXPORT_SYMBOL_GPL (wakeup_source_destroy); + +/** +* wakeup_source_register - Add given object to the list of wakeup sources. +* @ws: Wakeup source object to register. +*/ +void wakeup_source_register (struct wakeup_source *ws) +{ +if (WARN_ON (!ws)) +return ; + +spin_lock_init (&ws->lock); +setup_timer (&ws->timer, pm_wakeup_timer_fn, (unsigned long )ws); + ws->active = false; + +spin_lock_irq (&events_lock); +list_add_rcu (&ws->entry, &wakeup_sources); +spin_unlock_irq (&events_lock); +synchronize_rcu (); +} +EXPORT_SYMBOL_GPL (wakeup_source_register);...
Quoted 10 lines
drivers/base/power/wakeup.c +10
-0+/** +* wakeup_source_add - Create and register a wakeup source object. +* @name: Name of the wakeup source to create. +*/ +struct wakeup_source *wakeup_source_add (const char *name) +{ +struct wakeup_source *ws; + + ws =wakeup_source_create (name); +if (ws)
Quoted 8 lines
drivers/base/power/wakeup.c line 138
Quoted 5 lines
drivers/base/power/wakeup.c +5
-0+wakeup_source_register (ws); + +return ws; +} +EXPORT_SYMBOL_GPL (wakeup_source_add);Your use of names is backward. Normally the
*_registerroutine does*_initfollowed by*_add.
Hmm, I haven't noticed that. Thanks for the heads up. :-)
Quoted 2 lines
I haven't looked through the rest in enough detail yet to make any meaningful comments.
Sure. Thanks a lot for your comments so far!
Rafael
Re: [RFC][PATCH] PM / Wakeup: Introduce wakeup source objects and event statistics (was: Re: Wakeup-events implementation)
In reply to Rafael J. WysockiQuoted 9 lines · Rafael J. Wysocki
drivers/base/power/wakeup.c +9
-0+struct wakeup_source *wakeup_source_create (const char *name) +{ +struct wakeup_source *ws; + + ws =kzalloc (sizeof (*ws),GFP_KERNEL ); +if (!ws) +return NULL ; + +if (name) {
drivers/base/power/wakeup.c line 60
Quoted 10 lines
drivers/base/power/wakeup.c +10
-0+int len =strlen (name); +char *s =kzalloc (len +1 ,GFP_KERNEL ); +if (s) { +strncpy (s, name, len); + ws->name = s; + } + } + +return ws; +}
Forget what I wrote earlier; it was stupid. Just use kstrdup.
Alan Stern
Re: [RFC][PATCH] PM / Wakeup: Introduce wakeup source objects and event statistics (was: Re: Wakeup-events implementation)
In reply to Rafael J. WysockiQuoted 9 lines · Rafael J. Wysocki
drivers/base/power/wakeup.c +9
-0+struct wakeup_source *wakeup_source_create (const char *name) +{ +struct wakeup_source *ws; + + ws =kzalloc (sizeof (*ws),GFP_KERNEL ); +if (!ws) +return NULL ; + +if (name) {
drivers/base/power/wakeup.c line 60
Quoted 10 lines
drivers/base/power/wakeup.c +10
-0+int len =strlen (name); +char *s =kzalloc (len +1 ,GFP_KERNEL ); +if (s) { +strncpy (s, name, len); + ws->name = s; + } + } + +return ws; +}
Forget what I wrote earlier; it was stupid. Just use kstrdup.
Alan Stern
Re: [RFC][PATCH] PM / Wakeup: Introduce wakeup source objects and event statistics (was: Re: Wakeup-events implementation)
Quoted 16 lines · Rafael J. Wysocki
Quoted 15 lines · Alan Stern
Quoted 13 lines · Rafael J. Wysocki
drivers/base/power/wakeup.c +13
-0+struct wakeup_source *wakeup_source_create (const char *name) +{ +struct wakeup_source *ws; + + ws =kzalloc (sizeof (*ws),GFP_KERNEL ); +if (!ws) +return NULL ; + +if (name) { +int len =strlen (name); +char *s =kzalloc (len +1 ,GFP_KERNEL ); +if (s) { +strncpy (s, name, len);
Quoted 8 lines
Quoted 8 lines
drivers/base/power/wakeup.c line 60
Quoted 6 lines
drivers/base/power/wakeup.c +6
-0+ ws->name = s; + } + } + +return ws; +}Forget what I wrote earlier; it was stupid. Just use kstrdup.
Right, I didn't know it existed. :-)
Thanks,
Rafael
Re: [RFC][PATCH] PM / Wakeup: Introduce wakeup source objects and event statistics (was: Re: Wakeup-events implementation)
In reply to Alan SternQuoted 16 lines · Rafael J. Wysocki
Quoted 15 lines · Alan Stern
Quoted 13 lines · Rafael J. Wysocki
drivers/base/power/wakeup.c +13
-0+struct wakeup_source *wakeup_source_create (const char *name) +{ +struct wakeup_source *ws; + + ws =kzalloc (sizeof (*ws),GFP_KERNEL ); +if (!ws) +return NULL ; + +if (name) { +int len =strlen (name); +char *s =kzalloc (len +1 ,GFP_KERNEL ); +if (s) { +strncpy (s, name, len);
Quoted 8 lines
Quoted 8 lines
drivers/base/power/wakeup.c line 60
Quoted 6 lines
drivers/base/power/wakeup.c +6
-0+ ws->name = s; + } + } + +return ws; +}Forget what I wrote earlier; it was stupid. Just use kstrdup.
Right, I didn't know it existed. :-)
Thanks,
Rafael
PM / Wakeup: Introduce wakeup source objects and event statistics (v2)
Quoted 26 lines · Rafael J. Wysocki
Quoted 16 lines · Rafael J. Wysocki
Quoted 15 lines · Alan Stern
Quoted 13 lines · Rafael J. Wysocki
(quoted diff) +13
-0+struct wakeup_source *wakeup_source_create(const char *name) +{ + struct wakeup_source *ws; + + ws = kzalloc(sizeof(*ws), GFP_KERNEL); + if (!ws) + return NULL; + + if (name) { + int len = strlen(name); + char *s = kzalloc(len + 1, GFP_KERNEL); + if (s) { + strncpy(s, name, len);Quoted 8 lines
Quoted 8 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+ ws->name = s; + } + } + + return ws; +}Forget what I wrote earlier; it was stupid. Just use kstrdup.
Quoted 1 line
Right, I didn't know it existed. :-)
Below is a new version of the patch with your comments addressed (hopefully) and a few unrelated fixes, and some documentation.
Thanks,
Rafael
---
From: Rafael J. Wysocki <[email protected]>
Subject: PM / Wakeup: Introduce wakeup source objects and event statistics (v2)
Introduce struct wakeup_source for representing system wakeup sources within the kernel and for collecting statistics related to them. Make the recently introduced helper functions pm_wakeup_event(), pm_stay_awake() and pm_relax() use struct wakeup_source objects internally, so that wakeup statistics associated with wakeup devices can be collected and reported in a consistent way (the definition of pm_relax() is changed, which is harmless, because this function is not called directly by anyone yet). Introduce new wakeup-related sysfs device attributes in /sys/devices/.../power for reporting the device wakeup statistics.
Change the global wakeup events counters event_count and events_in_progress into atomic variables, so that it is not necessary to acquire a global spinlock in pm_wakeup_event(), pm_stay_awake() and pm_relax(), which should allow us to avoid lock contention in these functions on SMP systems with many wakeup devices.
--- Documentation/ABI/testing/sysfs-devices-power | 70 +++ drivers/base/power/main.c | 4 drivers/base/power/power.h | 1 drivers/base/power/runtime.c | 2 drivers/base/power/sysfs.c | 121 +++++ drivers/base/power/wakeup.c | 534 ++++++++++++++++++++++---- include/linux/pm.h | 16 include/linux/pm_wakeup.h | 126 ++++-- include/linux/suspend.h | 4 kernel/power/main.c | 8 10 files changed, 757 insertions(+), 129 deletions(-)
include/linux/pm_wakeup.h +101 -25
@@ -2,6 +2,7 @@* pm_wakeup.h - Power management wakeup interface * * Copyright (C) 2008 Alan Stern +* Copyright (C) 2010 Rafael J. Wysocki, Novell Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
@@ -27,18 +28,39 @@#include <linux/types.h> -#ifdef CONFIG_PM - -/* Changes to device_may_wakeup take effect on the next pm state change. +/** +* struct wakeup_source - Representation of wakeup sources * -* By default, most devices should leave wakeup disabled. The exceptions -* are devices that everyone expects to be wakeup sources: keyboards, -* power buttons, possibly network interfaces, etc. +* @total_time: Total time this wakeup source has been active. +* @max_time: Maximum time this wakeup source has been continuously active. +* @last_time: Monotonic clock when the wakeup source's was activated last time. +* @event_count: Number of signaled wakeup events. +* @active_count: Number of times the wakeup sorce was activated. +* @relax_count: Number of times the wakeup sorce was deactivated. +* @hit_count: Number of times the wakeup sorce might abort system suspend. +* @active: Status of the wakeup source. +*/ +struct wakeup_source { +char *name; +struct list_head entry; +spinlock_t lock; +struct timer_list timer; +unsigned long timer_expires; +ktime_t total_time; +ktime_t max_time; +ktime_t last_time; +unsigned long event_count; +unsigned long active_count; +unsigned long relax_count; +unsigned long hit_count; +unsigned int active:1 ; +}; + +#ifdef CONFIG_PM_SLEEP + +/* +* Changes to device_may_wakeup take effect on the next pm state change. */ -static inline void device_init_wakeup (struct device *dev,bool val) -{ - dev->power.can_wakeup = dev->power.should_wakeup = val; -}static inline void device_set_wakeup_capable (struct device *dev,bool capable) {
@@ -50,23 +72,32 @@ static inline bool device_can_wakeup(strreturn dev->power.can_wakeup; } -static inline void device_set_wakeup_enable (struct device *dev,bool enable) -{ - dev->power.should_wakeup = enable; -} +static inline bool device_may_wakeup (struct device *dev) { -return dev->power.can_wakeup && dev->power.should_wakeup; +return dev->power.can_wakeup && !!dev->power.wakeup; } -#else /* !CONFIG_PM */ +/* drivers/base/power/wakeup.c */ +extern struct wakeup_source *wakeup_source_create (const char *name); +extern void wakeup_source_destroy (struct wakeup_source *ws); +extern void wakeup_source_add (struct wakeup_source *ws); +extern void wakeup_source_remove (struct wakeup_source *ws); +extern struct wakeup_source *wakeup_source_register (const char *name); +extern void wakeup_source_unregister (struct wakeup_source *ws); +extern int device_wakeup_enable (struct device *dev); +extern int device_wakeup_disable (struct device *dev); +extern int device_init_wakeup (struct device *dev,bool val); +extern int device_set_wakeup_enable (struct device *dev,bool enable); +extern void __pm_stay_awake (struct wakeup_source *ws); +extern void pm_stay_awake (struct device *dev); +extern void __pm_relax (struct wakeup_source *ws); +extern void pm_relax (struct device *dev); +extern void __pm_wakeup_event (struct wakeup_source *ws,unsigned int msec); +extern void pm_wakeup_event (struct device *dev,unsigned int msec); -/* For some reason the following routines work even without CONFIG_PM */ -static inline void device_init_wakeup (struct device *dev,bool val) -{ - dev->power.can_wakeup = val; -} +#else /* !CONFIG_PM_SLEEP */ static inline void device_set_wakeup_capable (struct device *dev,bool capable) {
@@ -78,15 +109,60 @@ static inline bool device_can_wakeup(strreturn dev->power.can_wakeup; } -static inline void device_set_wakeup_enable (struct device *dev,bool enable) +static inline bool device_may_wakeup (struct device *dev) { +return false; } -static inline bool device_may_wakeup (struct device *dev) +static inline struct wakeup_source *wakeup_source_create (const char *name) { -return false; +return NULL ; } -#endif /* !CONFIG_PM */ +static inline void wakeup_source_destroy (struct wakeup_source *ws) {} + +static inline void wakeup_source_add (struct wakeup_source *ws) {} + +static inline void wakeup_source_remove (struct wakeup_source *ws) {} + +static inline struct wakeup_source *wakeup_source_register (const char *name) +{ +return NULL ; +} + +static inline void wakeup_source_unregister (struct wakeup_source *ws) {} + +static inline int device_wakeup_enable (struct device *dev) +{ +return -EINVAL ; +} + +static inline int device_wakeup_disable (struct device *dev) {} + +static inline int device_init_wakeup (struct device *dev,bool val) +{ + dev->power.can_wakeup = val; +return val ? -EINVAL :0 ; +} + + +static inline int device_set_wakeup_enable (struct device *dev,bool enable) +{ +return -EINVAL ; +} + +static inline void __pm_stay_awake (struct wakeup_source *ws) {} + +static inline void pm_stay_awake (struct device *dev) {} + +static inline void __pm_relax (struct wakeup_source *ws) {} + +static inline void pm_relax (struct device *dev) {} + +static inline void __pm_wakeup_event (struct wakeup_source *ws,unsigned int msec) {} + +static inline void pm_wakeup_event (struct device *dev,unsigned int msec) {} + +#endif /* !CONFIG_PM_SLEEP */ #endif /* _LINUX_PM_WAKEUP_H */
include/linux/pm.h +4 -12
@@ -448,23 +448,24 @@ enum rpm_request { RPM_REQ_RESUME, }; +struct wakeup_source ; +struct dev_pm_info {pm_message_t power_state;unsigned int can_wakeup:1 ; -unsigned int should_wakeup:1 ;unsigned async_suspend:1 ;enum dpm_state status;/* Owned by the PM core */ +spinlock_t lock;#ifdef CONFIG_PM_SLEEP struct list_head entry;struct completion completion; -unsigned long wakeup_count; +struct wakeup_source *wakeup;#endif #ifdef CONFIG_PM_RUNTIME struct timer_list suspend_timer;unsigned long timer_expires;struct work_struct work;wait_queue_head_t wait_queue; -spinlock_t lock;atomic_t usage_count;atomic_t child_count;unsigned int disable_depth:3 ;
@@ -559,11 +560,6 @@ extern void __suspend_report_result(cons } while (0) extern void device_pm_wait_for_dev(struct device *sub, struct device *dev); - -/* drivers/base/power/wakeup.c */ -extern void pm_wakeup_event (struct device *dev,unsigned int msec); -extern void pm_stay_awake (struct device *dev); -extern void pm_relax (void );#else /* !CONFIG_PM_SLEEP */ #define device_pm_lock () do {} while (0)
@@ -577,10 +573,6 @@ static inline int dpm_suspend_start(pm_m#define suspend_report_result (fn, ret) do {} while (0)static inline void device_pm_wait_for_dev (struct device *a,struct device *b) {} - -static inline void pm_wakeup_event (struct device *dev,unsigned int msec) {} -static inline void pm_stay_awake (struct device *dev) {} -static inline void pm_relax (void ) {}#endif /* !CONFIG_PM_SLEEP */ /* How to reorder dpm_list after device_move() */
drivers/base/power/wakeup.c +453 -81
646 lines not on this page · raw message
drivers/base/power/main.c +3 -1
@@ -60,7 +60,8 @@ void device_pm_init(struct device *dev) dev->power.status =DPM_ON ;init_completion (&dev->power.completion);complete_all (&dev->power.completion); - dev->power.wakeup_count =0 ; + dev->power.wakeup =NULL ; +spin_lock_init (&dev->power.lock);pm_runtime_init (dev); }
@@ -120,6 +121,7 @@ void device_pm_remove(struct device *devmutex_lock (&dpm_list_mtx);list_del_init (&dev->power.entry);mutex_unlock (&dpm_list_mtx); +device_wakeup_disable (dev);pm_runtime_remove (dev); }
drivers/base/power/power.h +1 -0
@@ -34,6 +34,7 @@ extern void device_pm_move_last(struct dstatic inline void device_pm_init (struct device *dev) { +spin_lock_init (&dev->power.lock);pm_runtime_init (dev); }
drivers/base/power/runtime.c +0 -2
@@ -1099,8 +1099,6 @@ EXPORT_SYMBOL_GPL(pm_runtime_allow);*/ void pm_runtime_init (struct device *dev) { -spin_lock_init (&dev->power.lock); - dev->power.runtime_status =RPM_SUSPENDED ; dev->power.idle_notification = false;
include/linux/suspend.h +2 -2
@@ -302,8 +302,8 @@ extern int unregister_pm_notifier(structextern bool events_check_enabled;extern bool pm_check_wakeup_events (void ); -extern bool pm_get_wakeup_count (unsigned long *count); -extern bool pm_save_wakeup_count (unsigned long count); +extern bool pm_get_wakeup_count (unsigned int *count); +extern bool pm_save_wakeup_count (unsigned int count);#else /* !CONFIG_PM_SLEEP */ static inline int register_pm_notifier (struct notifier_block *nb)
kernel/power/main.c +4 -4
@@ -237,18 +237,18 @@ static ssize_t wakeup_count_show(structstruct kobj_attribute *attr, char *buf) { - unsigned long val; + unsigned int val; -return pm_get_wakeup_count (&val) ?sprintf (buf,"%lu\n" , val) : -EINTR ; +return pm_get_wakeup_count (&val) ?sprintf (buf,"%u\n" , val) : -EINTR ; }static ssize_t wakeup_count_store (struct kobject *kobj,struct kobj_attribute *attr,const char *buf,size_t n) { -unsigned long val; +unsigned int val; -if (sscanf (buf,"%lu" , &val) ==1 ) { +if (sscanf (buf,"%u" , &val) ==1 ) {if (pm_save_wakeup_count (val))return n; }
drivers/base/power/sysfs.c +119 -2
136 lines not on this page · raw message
Documentation/ABI/testing/sysfs-devices-power +70 -0
73 lines not on this page · raw message
PM / Wakeup: Introduce wakeup source objects and event statistics (v2)
In reply to Rafael J. WysockiQuoted 26 lines · Rafael J. Wysocki
Quoted 16 lines · Rafael J. Wysocki
Quoted 15 lines · Alan Stern
Quoted 13 lines · Rafael J. Wysocki
(quoted diff) +13
-0+struct wakeup_source *wakeup_source_create(const char *name) +{ + struct wakeup_source *ws; + + ws = kzalloc(sizeof(*ws), GFP_KERNEL); + if (!ws) + return NULL; + + if (name) { + int len = strlen(name); + char *s = kzalloc(len + 1, GFP_KERNEL); + if (s) { + strncpy(s, name, len);Quoted 8 lines
Quoted 8 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+ ws->name = s; + } + } + + return ws; +}Forget what I wrote earlier; it was stupid. Just use kstrdup.
Quoted 1 line
Right, I didn't know it existed. :-)
Below is a new version of the patch with your comments addressed (hopefully) and a few unrelated fixes, and some documentation.
Thanks,
Rafael
---
From: Rafael J. Wysocki <[email protected]>
Subject: PM / Wakeup: Introduce wakeup source objects and event statistics (v2)
Introduce struct wakeup_source for representing system wakeup sources within the kernel and for collecting statistics related to them. Make the recently introduced helper functions pm_wakeup_event(), pm_stay_awake() and pm_relax() use struct wakeup_source objects internally, so that wakeup statistics associated with wakeup devices can be collected and reported in a consistent way (the definition of pm_relax() is changed, which is harmless, because this function is not called directly by anyone yet). Introduce new wakeup-related sysfs device attributes in /sys/devices/.../power for reporting the device wakeup statistics.
Change the global wakeup events counters event_count and events_in_progress into atomic variables, so that it is not necessary to acquire a global spinlock in pm_wakeup_event(), pm_stay_awake() and pm_relax(), which should allow us to avoid lock contention in these functions on SMP systems with many wakeup devices.
--- Documentation/ABI/testing/sysfs-devices-power | 70 +++ drivers/base/power/main.c | 4 drivers/base/power/power.h | 1 drivers/base/power/runtime.c | 2 drivers/base/power/sysfs.c | 121 +++++ drivers/base/power/wakeup.c | 534 ++++++++++++++++++++++---- include/linux/pm.h | 16 include/linux/pm_wakeup.h | 126 ++++-- include/linux/suspend.h | 4 kernel/power/main.c | 8 10 files changed, 757 insertions(+), 129 deletions(-)
include/linux/pm_wakeup.h +101 -25
@@ -2,6 +2,7 @@* pm_wakeup.h - Power management wakeup interface * * Copyright (C) 2008 Alan Stern +* Copyright (C) 2010 Rafael J. Wysocki, Novell Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
@@ -27,18 +28,39 @@#include <linux/types.h> -#ifdef CONFIG_PM - -/* Changes to device_may_wakeup take effect on the next pm state change. +/** +* struct wakeup_source - Representation of wakeup sources * -* By default, most devices should leave wakeup disabled. The exceptions -* are devices that everyone expects to be wakeup sources: keyboards, -* power buttons, possibly network interfaces, etc. +* @total_time: Total time this wakeup source has been active. +* @max_time: Maximum time this wakeup source has been continuously active. +* @last_time: Monotonic clock when the wakeup source's was activated last time. +* @event_count: Number of signaled wakeup events. +* @active_count: Number of times the wakeup sorce was activated. +* @relax_count: Number of times the wakeup sorce was deactivated. +* @hit_count: Number of times the wakeup sorce might abort system suspend. +* @active: Status of the wakeup source. +*/ +struct wakeup_source { +char *name; +struct list_head entry; +spinlock_t lock; +struct timer_list timer; +unsigned long timer_expires; +ktime_t total_time; +ktime_t max_time; +ktime_t last_time; +unsigned long event_count; +unsigned long active_count; +unsigned long relax_count; +unsigned long hit_count; +unsigned int active:1 ; +}; + +#ifdef CONFIG_PM_SLEEP + +/* +* Changes to device_may_wakeup take effect on the next pm state change. */ -static inline void device_init_wakeup (struct device *dev,bool val) -{ - dev->power.can_wakeup = dev->power.should_wakeup = val; -}static inline void device_set_wakeup_capable (struct device *dev,bool capable) {
@@ -50,23 +72,32 @@ static inline bool device_can_wakeup(strreturn dev->power.can_wakeup; } -static inline void device_set_wakeup_enable (struct device *dev,bool enable) -{ - dev->power.should_wakeup = enable; -} +static inline bool device_may_wakeup (struct device *dev) { -return dev->power.can_wakeup && dev->power.should_wakeup; +return dev->power.can_wakeup && !!dev->power.wakeup; } -#else /* !CONFIG_PM */ +/* drivers/base/power/wakeup.c */ +extern struct wakeup_source *wakeup_source_create (const char *name); +extern void wakeup_source_destroy (struct wakeup_source *ws); +extern void wakeup_source_add (struct wakeup_source *ws); +extern void wakeup_source_remove (struct wakeup_source *ws); +extern struct wakeup_source *wakeup_source_register (const char *name); +extern void wakeup_source_unregister (struct wakeup_source *ws); +extern int device_wakeup_enable (struct device *dev); +extern int device_wakeup_disable (struct device *dev); +extern int device_init_wakeup (struct device *dev,bool val); +extern int device_set_wakeup_enable (struct device *dev,bool enable); +extern void __pm_stay_awake (struct wakeup_source *ws); +extern void pm_stay_awake (struct device *dev); +extern void __pm_relax (struct wakeup_source *ws); +extern void pm_relax (struct device *dev); +extern void __pm_wakeup_event (struct wakeup_source *ws,unsigned int msec); +extern void pm_wakeup_event (struct device *dev,unsigned int msec); -/* For some reason the following routines work even without CONFIG_PM */ -static inline void device_init_wakeup (struct device *dev,bool val) -{ - dev->power.can_wakeup = val; -} +#else /* !CONFIG_PM_SLEEP */ static inline void device_set_wakeup_capable (struct device *dev,bool capable) {
@@ -78,15 +109,60 @@ static inline bool device_can_wakeup(strreturn dev->power.can_wakeup; } -static inline void device_set_wakeup_enable (struct device *dev,bool enable) +static inline bool device_may_wakeup (struct device *dev) { +return false; } -static inline bool device_may_wakeup (struct device *dev) +static inline struct wakeup_source *wakeup_source_create (const char *name) { -return false; +return NULL ; } -#endif /* !CONFIG_PM */ +static inline void wakeup_source_destroy (struct wakeup_source *ws) {} + +static inline void wakeup_source_add (struct wakeup_source *ws) {} + +static inline void wakeup_source_remove (struct wakeup_source *ws) {} + +static inline struct wakeup_source *wakeup_source_register (const char *name) +{ +return NULL ; +} + +static inline void wakeup_source_unregister (struct wakeup_source *ws) {} + +static inline int device_wakeup_enable (struct device *dev) +{ +return -EINVAL ; +} + +static inline int device_wakeup_disable (struct device *dev) {} + +static inline int device_init_wakeup (struct device *dev,bool val) +{ + dev->power.can_wakeup = val; +return val ? -EINVAL :0 ; +} + + +static inline int device_set_wakeup_enable (struct device *dev,bool enable) +{ +return -EINVAL ; +} + +static inline void __pm_stay_awake (struct wakeup_source *ws) {} + +static inline void pm_stay_awake (struct device *dev) {} + +static inline void __pm_relax (struct wakeup_source *ws) {} + +static inline void pm_relax (struct device *dev) {} + +static inline void __pm_wakeup_event (struct wakeup_source *ws,unsigned int msec) {} + +static inline void pm_wakeup_event (struct device *dev,unsigned int msec) {} + +#endif /* !CONFIG_PM_SLEEP */ #endif /* _LINUX_PM_WAKEUP_H */
include/linux/pm.h +4 -12
@@ -448,23 +448,24 @@ enum rpm_request { RPM_REQ_RESUME, }; +struct wakeup_source ; +struct dev_pm_info {pm_message_t power_state;unsigned int can_wakeup:1 ; -unsigned int should_wakeup:1 ;unsigned async_suspend:1 ;enum dpm_state status;/* Owned by the PM core */ +spinlock_t lock;#ifdef CONFIG_PM_SLEEP struct list_head entry;struct completion completion; -unsigned long wakeup_count; +struct wakeup_source *wakeup;#endif #ifdef CONFIG_PM_RUNTIME struct timer_list suspend_timer;unsigned long timer_expires;struct work_struct work;wait_queue_head_t wait_queue; -spinlock_t lock;atomic_t usage_count;atomic_t child_count;unsigned int disable_depth:3 ;
@@ -559,11 +560,6 @@ extern void __suspend_report_result(cons } while (0) extern void device_pm_wait_for_dev(struct device *sub, struct device *dev); - -/* drivers/base/power/wakeup.c */ -extern void pm_wakeup_event (struct device *dev,unsigned int msec); -extern void pm_stay_awake (struct device *dev); -extern void pm_relax (void );#else /* !CONFIG_PM_SLEEP */ #define device_pm_lock () do {} while (0)
@@ -577,10 +573,6 @@ static inline int dpm_suspend_start(pm_m#define suspend_report_result (fn, ret) do {} while (0)static inline void device_pm_wait_for_dev (struct device *a,struct device *b) {} - -static inline void pm_wakeup_event (struct device *dev,unsigned int msec) {} -static inline void pm_stay_awake (struct device *dev) {} -static inline void pm_relax (void ) {}#endif /* !CONFIG_PM_SLEEP */ /* How to reorder dpm_list after device_move() */
drivers/base/power/wakeup.c +453 -81
646 lines not on this page · raw message
drivers/base/power/main.c +3 -1
@@ -60,7 +60,8 @@ void device_pm_init(struct device *dev) dev->power.status =DPM_ON ;init_completion (&dev->power.completion);complete_all (&dev->power.completion); - dev->power.wakeup_count =0 ; + dev->power.wakeup =NULL ; +spin_lock_init (&dev->power.lock);pm_runtime_init (dev); }
@@ -120,6 +121,7 @@ void device_pm_remove(struct device *devmutex_lock (&dpm_list_mtx);list_del_init (&dev->power.entry);mutex_unlock (&dpm_list_mtx); +device_wakeup_disable (dev);pm_runtime_remove (dev); }
drivers/base/power/power.h +1 -0
@@ -34,6 +34,7 @@ extern void device_pm_move_last(struct dstatic inline void device_pm_init (struct device *dev) { +spin_lock_init (&dev->power.lock);pm_runtime_init (dev); }
drivers/base/power/runtime.c +0 -2
@@ -1099,8 +1099,6 @@ EXPORT_SYMBOL_GPL(pm_runtime_allow);*/ void pm_runtime_init (struct device *dev) { -spin_lock_init (&dev->power.lock); - dev->power.runtime_status =RPM_SUSPENDED ; dev->power.idle_notification = false;
include/linux/suspend.h +2 -2
@@ -302,8 +302,8 @@ extern int unregister_pm_notifier(structextern bool events_check_enabled;extern bool pm_check_wakeup_events (void ); -extern bool pm_get_wakeup_count (unsigned long *count); -extern bool pm_save_wakeup_count (unsigned long count); +extern bool pm_get_wakeup_count (unsigned int *count); +extern bool pm_save_wakeup_count (unsigned int count);#else /* !CONFIG_PM_SLEEP */ static inline int register_pm_notifier (struct notifier_block *nb)
kernel/power/main.c +4 -4
@@ -237,18 +237,18 @@ static ssize_t wakeup_count_show(structstruct kobj_attribute *attr, char *buf) { - unsigned long val; + unsigned int val; -return pm_get_wakeup_count (&val) ?sprintf (buf,"%lu\n" , val) : -EINTR ; +return pm_get_wakeup_count (&val) ?sprintf (buf,"%u\n" , val) : -EINTR ; }static ssize_t wakeup_count_store (struct kobject *kobj,struct kobj_attribute *attr,const char *buf,size_t n) { -unsigned long val; +unsigned int val; -if (sscanf (buf,"%lu" , &val) ==1 ) { +if (sscanf (buf,"%u" , &val) ==1 ) {if (pm_save_wakeup_count (val))return n; }
drivers/base/power/sysfs.c +119 -2
136 lines not on this page · raw message
Documentation/ABI/testing/sysfs-devices-power +70 -0
73 lines not on this page · raw message
Re: PM / Wakeup: Introduce wakeup source objects and event statistics (v2)
Quoted 14 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Subject: PM / Wakeup: Introduce wakeup source objects and event statistics (v2)Introduce struct
wakeup_sourcefor representing system wakeup sources within the kernel and for collecting statistics related to them. Make the recently introduced helper functionspm_wakeup_event(),pm_stay_awake()andpm_relax()use structwakeup_sourceobjects internally, so that wakeup statistics associated with wakeup devices can be collected and reported in a consistent way (the definition ofpm_relax()is changed, which is harmless, because this function is not called directly by anyone yet). Introduce new wakeup-related sysfs device attributes in/sys/devices/.../powerfor reporting the device wakeup statistics.
Quoted 7 lines
Change the global wakeup events counters
event_countandevents_in_progressinto atomic variables, so that it is not necessary to acquire a global spinlock inpm_wakeup_event(),pm_stay_awake()andpm_relax(), which should allow us to avoid lock contention in these functions on SMP systems with many wakeup devices.Signed-off-by Rafael J. Wysocki <[email protected]>
Hi Rafael,
This looks like a really useful feature. Was doing some experiments with this on OMAP, and found a minor cut-and-paste bug in the Documentation file:
[...]
Documentation/ABI/testing/sysfs-devices-power Description: · line 140
Quoted 11 lines
Documentation/ABI/testing/sysfs-devices-power +11
-0+What: /sys/devices/.../power/wakeup_max_time_ms +Date: September 2010 +Contact: Rafael J. Wysocki <[email protected]> +Description: + The /sys/devices/.../wakeup_max_time_ms attribute contains + the maximum time of processing a single wakeup event associated + with the device, in milliseconds. This attribute is read-only. + If the device is not enabled to wake up the system from sleep + states, this attribute is empty. + +What: /sys/devices/.../power/wakeup_max_time_ms
^^^
s/max/last/ for this one.
Documentation/ABI/testing/sysfs-devices-power Description: · line 149
Quoted 9 lines
Documentation/ABI/testing/sysfs-devices-power +9
-0+Date: September 2010 +Contact: Rafael J. Wysocki <[email protected]> +Description: + The /sys/devices/.../wakeup_last_time_ms attribute contains + the value of the monotonic clock corresponding to the time of + signaling the last wakeup event associated with the device, in + milliseconds. This attribute is read-only. If the device is + not enabled to wake up the system from sleep states, this + attribute is empty.
Kevin
Re: PM / Wakeup: Introduce wakeup source objects and event statistics (v2)
In reply to Rafael J. WysockiQuoted 14 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Subject: PM / Wakeup: Introduce wakeup source objects and event statistics (v2)Introduce struct
wakeup_sourcefor representing system wakeup sources within the kernel and for collecting statistics related to them. Make the recently introduced helper functionspm_wakeup_event(),pm_stay_awake()andpm_relax()use structwakeup_sourceobjects internally, so that wakeup statistics associated with wakeup devices can be collected and reported in a consistent way (the definition ofpm_relax()is changed, which is harmless, because this function is not called directly by anyone yet). Introduce new wakeup-related sysfs device attributes in/sys/devices/.../powerfor reporting the device wakeup statistics.
Quoted 7 lines
Change the global wakeup events counters
event_countandevents_in_progressinto atomic variables, so that it is not necessary to acquire a global spinlock inpm_wakeup_event(),pm_stay_awake()andpm_relax(), which should allow us to avoid lock contention in these functions on SMP systems with many wakeup devices.Signed-off-by Rafael J. Wysocki <[email protected]>
Hi Rafael,
This looks like a really useful feature. Was doing some experiments with this on OMAP, and found a minor cut-and-paste bug in the Documentation file:
[...]
Documentation/ABI/testing/sysfs-devices-power Description: · line 140
Quoted 11 lines
Documentation/ABI/testing/sysfs-devices-power +11
-0+What: /sys/devices/.../power/wakeup_max_time_ms +Date: September 2010 +Contact: Rafael J. Wysocki <[email protected]> +Description: + The /sys/devices/.../wakeup_max_time_ms attribute contains + the maximum time of processing a single wakeup event associated + with the device, in milliseconds. This attribute is read-only. + If the device is not enabled to wake up the system from sleep + states, this attribute is empty. + +What: /sys/devices/.../power/wakeup_max_time_ms
^^^
s/max/last/ for this one.
Documentation/ABI/testing/sysfs-devices-power Description: · line 149
Quoted 9 lines
Documentation/ABI/testing/sysfs-devices-power +9
-0+Date: September 2010 +Contact: Rafael J. Wysocki <[email protected]> +Description: + The /sys/devices/.../wakeup_last_time_ms attribute contains + the value of the monotonic clock corresponding to the time of + signaling the last wakeup event associated with the device, in + milliseconds. This attribute is read-only. If the device is + not enabled to wake up the system from sleep states, this + attribute is empty.
Kevin
Re: PM / Wakeup: Introduce wakeup source objects and event statistics (v2)
Quoted 22 lines · Kevin Hilman
Quoted 20 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Subject: PM / Wakeup: Introduce wakeup source objects and event statistics (v2)Introduce struct
wakeup_sourcefor representing system wakeup sources within the kernel and for collecting statistics related to them. Make the recently introduced helper functionspm_wakeup_event(),pm_stay_awake()andpm_relax()use structwakeup_sourceobjects internally, so that wakeup statistics associated with wakeup devices can be collected and reported in a consistent way (the definition ofpm_relax()is changed, which is harmless, because this function is not called directly by anyone yet). Introduce new wakeup-related sysfs device attributes in/sys/devices/.../powerfor reporting the device wakeup statistics.Change the global wakeup events counters
event_countandevents_in_progressinto atomic variables, so that it is not necessary to acquire a global spinlock inpm_wakeup_event(),pm_stay_awake()andpm_relax(), which should allow us to avoid lock contention in these functions on SMP systems with many wakeup devices.
Quoted 5 lines
Quoted 1 line
Signed-off-by Rafael J. Wysocki <[email protected]>Hi Rafael,
This looks like a really useful feature.
Great!
Quoted 17 lines
Was doing some experiments with this on OMAP, and found a minor cut-and-paste bug in the Documentation file:
[...]
Documentation/ABI/testing/sysfs-devices-power Description: · line 140
Quoted 11 lines
Documentation/ABI/testing/sysfs-devices-power +11
-0+What: /sys/devices/.../power/wakeup_max_time_ms +Date: September 2010 +Contact: Rafael J. Wysocki <[email protected]> +Description: + The /sys/devices/.../wakeup_max_time_ms attribute contains + the maximum time of processing a single wakeup event associated + with the device, in milliseconds. This attribute is read-only. + If the device is not enabled to wake up the system from sleep + states, this attribute is empty. + +What: /sys/devices/.../power/wakeup_max_time_ms^^^
Quoted 1 line
s/max/last/ for this one.
Ah, thanks a lot.
Quoted 9 lines
Documentation/ABI/testing/sysfs-devices-power Description: · line 149
Quoted 9 lines
Documentation/ABI/testing/sysfs-devices-power +9
-0+Date: September 2010 +Contact: Rafael J. Wysocki <[email protected]> +Description: + The /sys/devices/.../wakeup_last_time_ms attribute contains + the value of the monotonic clock corresponding to the time of + signaling the last wakeup event associated with the device, in + milliseconds. This attribute is read-only. If the device is + not enabled to wake up the system from sleep states, this + attribute is empty.
Rafael
Re: PM / Wakeup: Introduce wakeup source objects and event statistics (v2)
In reply to Kevin HilmanQuoted 22 lines · Kevin Hilman
Quoted 20 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Subject: PM / Wakeup: Introduce wakeup source objects and event statistics (v2)Introduce struct
wakeup_sourcefor representing system wakeup sources within the kernel and for collecting statistics related to them. Make the recently introduced helper functionspm_wakeup_event(),pm_stay_awake()andpm_relax()use structwakeup_sourceobjects internally, so that wakeup statistics associated with wakeup devices can be collected and reported in a consistent way (the definition ofpm_relax()is changed, which is harmless, because this function is not called directly by anyone yet). Introduce new wakeup-related sysfs device attributes in/sys/devices/.../powerfor reporting the device wakeup statistics.Change the global wakeup events counters
event_countandevents_in_progressinto atomic variables, so that it is not necessary to acquire a global spinlock inpm_wakeup_event(),pm_stay_awake()andpm_relax(), which should allow us to avoid lock contention in these functions on SMP systems with many wakeup devices.
Quoted 5 lines
Quoted 1 line
Signed-off-by Rafael J. Wysocki <[email protected]>Hi Rafael,
This looks like a really useful feature.
Great!
Quoted 17 lines
Was doing some experiments with this on OMAP, and found a minor cut-and-paste bug in the Documentation file:
[...]
Documentation/ABI/testing/sysfs-devices-power Description: · line 140
Quoted 11 lines
Documentation/ABI/testing/sysfs-devices-power +11
-0+What: /sys/devices/.../power/wakeup_max_time_ms +Date: September 2010 +Contact: Rafael J. Wysocki <[email protected]> +Description: + The /sys/devices/.../wakeup_max_time_ms attribute contains + the maximum time of processing a single wakeup event associated + with the device, in milliseconds. This attribute is read-only. + If the device is not enabled to wake up the system from sleep + states, this attribute is empty. + +What: /sys/devices/.../power/wakeup_max_time_ms^^^
Quoted 1 line
s/max/last/ for this one.
Ah, thanks a lot.
Quoted 9 lines
Documentation/ABI/testing/sysfs-devices-power Description: · line 149
Quoted 9 lines
Documentation/ABI/testing/sysfs-devices-power +9
-0+Date: September 2010 +Contact: Rafael J. Wysocki <[email protected]> +Description: + The /sys/devices/.../wakeup_last_time_ms attribute contains + the value of the monotonic clock corresponding to the time of + signaling the last wakeup event associated with the device, in + milliseconds. This attribute is read-only. If the device is + not enabled to wake up the system from sleep states, this + attribute is empty.
Rafael
Re: PM / Wakeup: Introduce wakeup source objects and event statistics (v2)
Quoted 19 lines · Rafael J. Wysocki
Quoted 17 lines
Was doing some experiments with this on OMAP, and found a minor cut-and-paste bug in the Documentation file:
[...]
Documentation/ABI/testing/sysfs-devices-power Description: · line 140
Quoted 11 lines
Documentation/ABI/testing/sysfs-devices-power +11
-0+What: /sys/devices/.../power/wakeup_max_time_ms +Date: September 2010 +Contact: Rafael J. Wysocki <[email protected]> +Description: + The /sys/devices/.../wakeup_max_time_ms attribute contains + the maximum time of processing a single wakeup event associated + with the device, in milliseconds. This attribute is read-only. + If the device is not enabled to wake up the system from sleep + states, this attribute is empty. + +What: /sys/devices/.../power/wakeup_max_time_ms^^^Quoted 1 line
s/max/last/ for this one.
Quoted 1 line
Ah, thanks a lot.
There was another copy & paste errors in that file, a "wakeup_active_count" that should be "wakeup_hit_count".
Alan Stern
Re: PM / Wakeup: Introduce wakeup source objects and event statistics (v2)
In reply to Rafael J. WysockiQuoted 19 lines · Rafael J. Wysocki
Quoted 17 lines
Was doing some experiments with this on OMAP, and found a minor cut-and-paste bug in the Documentation file:
[...]
Documentation/ABI/testing/sysfs-devices-power Description: · line 140
Quoted 11 lines
Documentation/ABI/testing/sysfs-devices-power +11
-0+What: /sys/devices/.../power/wakeup_max_time_ms +Date: September 2010 +Contact: Rafael J. Wysocki <[email protected]> +Description: + The /sys/devices/.../wakeup_max_time_ms attribute contains + the maximum time of processing a single wakeup event associated + with the device, in milliseconds. This attribute is read-only. + If the device is not enabled to wake up the system from sleep + states, this attribute is empty. + +What: /sys/devices/.../power/wakeup_max_time_ms^^^Quoted 1 line
s/max/last/ for this one.
Quoted 1 line
Ah, thanks a lot.
There was another copy & paste errors in that file, a "wakeup_active_count" that should be "wakeup_hit_count".
Alan Stern
Re: PM / Wakeup: Introduce wakeup source objects and event statistics (v2)
Quoted 21 lines · Alan Stern
Quoted 19 lines · Rafael J. Wysocki
Quoted 18 lines
Was doing some experiments with this on OMAP, and found a minor cut-and-paste bug in the Documentation file:
[...]
Documentation/ABI/testing/sysfs-devices-power Description: · line 140
Quoted 11 lines
Documentation/ABI/testing/sysfs-devices-power +11
-0+What: /sys/devices/.../power/wakeup_max_time_ms +Date: September 2010 +Contact: Rafael J. Wysocki <[email protected]> +Description: + The /sys/devices/.../wakeup_max_time_ms attribute contains + the maximum time of processing a single wakeup event associated + with the device, in milliseconds. This attribute is read-only. + If the device is not enabled to wake up the system from sleep + states, this attribute is empty. + +What: /sys/devices/.../power/wakeup_max_time_ms^^^s/max/last/ for this one.
Quoted 4 lines
Quoted 1 line
Ah, thanks a lot.
There was another copy & paste errors in that file, a "
wakeup_active_count" that should be "wakeup_hit_count".
Indeed, fixed now.
Thanks,
Rafael
Re: PM / Wakeup: Introduce wakeup source objects and event statistics (v2)
In reply to Alan SternQuoted 21 lines · Alan Stern
Quoted 19 lines · Rafael J. Wysocki
Quoted 18 lines
Was doing some experiments with this on OMAP, and found a minor cut-and-paste bug in the Documentation file:
[...]
Documentation/ABI/testing/sysfs-devices-power Description: · line 140
Quoted 11 lines
Documentation/ABI/testing/sysfs-devices-power +11
-0+What: /sys/devices/.../power/wakeup_max_time_ms +Date: September 2010 +Contact: Rafael J. Wysocki <[email protected]> +Description: + The /sys/devices/.../wakeup_max_time_ms attribute contains + the maximum time of processing a single wakeup event associated + with the device, in milliseconds. This attribute is read-only. + If the device is not enabled to wake up the system from sleep + states, this attribute is empty. + +What: /sys/devices/.../power/wakeup_max_time_ms^^^s/max/last/ for this one.
Quoted 4 lines
Quoted 1 line
Ah, thanks a lot.
There was another copy & paste errors in that file, a "
wakeup_active_count" that should be "wakeup_hit_count".
Indeed, fixed now.
Thanks,
Rafael