ubuntu-phone team mailing list archive
Mailing list archive
Catching CPU run-aways on Touch
In another discussion, James Hunt raised the possibility of
periodically checking for runaway processes on Touch, killing those
consuming 100% CPU while creating a report to be sent to
I've summarised the key points of that discussion here into a
proposal. The hope of this is that it gives everyone a chance to
== Examples ==
There are a few examples of this problem biting us already.
The original bug James ran into was:
Martin Pitt also raised one where two rogue system service processes
constantly used 150% CPU (i. e. 1.5 cores):
A few weeks ago there was a nasty timing bug which caused ueventd to
use 100% CPU:
Whoopsie also had a memory corruption bug which caused 100% CPU usage
around the same time as the ueventd bug:
Note that this is not really about power consumption. Colin King has
done analysis of power consumption on Touch devices and the biggest
bang for the buck is ensuring that sensors are turned off when they
are not needed, not minimising CPU usage. Instead, please consider
this proposal an attempt to better ensure the stability and
performance of Touch systems out in the wild.
== Implementation ==
We will enable the sampling and reporting of high CPU usage in
background processes on Touch devices when the device is not in
Foreground processes will be ignored by this check. They will instead
be handled by an "application not responding" (ANR) implementation in
Mir. They will be allowed to use 100% CPU unless they block the UI
thread for an unreasonable amount of time.
With the application lifecycle work, background applications will be
suspended and get no CPU time at all, so this check will only apply to
Each background process will be periodically sampled for its CPU
usage. If the process is using a large amount of CPU consistently
across several of these samplings, it will be killed and an apport
report will be created.
An outstanding question is what the threshold should be for high CPU usage.
== Where will this check live? ==
It has been suggested that the task of periodically checking for
runaway processes live inside a long-running and lightweight C
process. Whoopsie was suggested as a potential candidate.
libprocps was raised as potentially helpful, but James pointed out
that CPU percentage needed to be calculated by the caller, so another
approach may prove easier.
== How will we group reports of the same underlying problem? ==
https://errors.ubuntu.com will need to receive a string that
represents the problem (a signature) to which this instance of a
runaway process belongs. This lets the website group together the
instances of a problem onto a single page and increment the count for
the problem on the front page leaderboard.
Whoopsie, or whatever process holds this check, will use the ptrace
system call to generate a stack trace of the runaway process which
apport can then use to generate a crash signature:
Martin suggested we could do three stack traces each 1 s ± <random
interval> apart, and then chop away the differing part at the top, so
that we only keep the common bit.
Since we would be generating multiple stack traces, we cannot just
build the report and stack trace through the traditional means of
triggering apport kernel core pipe handler by sending SIGABRT.
== Bringing the check to the Ubuntu desktop ==
It was suggested that we could also have this check on the Ubuntu
desktop, but it was quickly pointed out that great care would need to
be taken to prevent reporting when gcc or Firefox uses 100% CPU.
This would be particularly annoying since the desktop currently
presents a dialog whenever an error occurs. There are plans underway
to group errors that do not need your immediate attention
(non-application crashes, e.g. package installation failures) into a
single dialog with the next error that does require your attention
(Firefox crashing); however, a quicker solution would be to only
report these desktop runaway processes on systems that have automatic
error reporting enabled.
We could then create a blacklist of processes that are known to be
intensive but safe using the data gathered from Touch and automatic
reporting systems and eventually bring reporting of runaway processes
to all Ubuntu systems (save servers).
A whitelist was considered, but determined to not save us from
problems like the ueventd bug.