Saving the world one uW at a time
I'm here at UDS and joined a session between the kernel and desktop teams talking about power. Like all of such sessions the kernel team thinks that the desktop should fix all the problems and vice versa. At their suggestion, I took an action item.
One of the features of GTK+ is that it provides two timeout functions: gtk_timeout_add and gtk_timeout_add_seconds. The difference is much more important than not having to add a "* 1000" in one and not the other. The important thing that the second function does is that it tried to group wake-ups to ensure that the program wakes up as little as possible. This is never perfect, but it's a small thing that can help to save some power and reduce the number of wake-ups.
So I looked through the Ubuntu main archive to figure out how many applications use the more precise function, but just pass in several seconds as the parameter. I figured this would be a few apps, and I'd submit a couple patches, then I could go back to blaming the kernel team for all our problems. There are more than a couple packages. There are a lot of packages. The results of the grep and a cleaned up list of packages that are likely to have easy fixes.
I realize now that I can't do this by myself, the only hope is to document how to fix it.
So if you'd like to help save a little power on your machine, follow these instructions.
- Take one of the packages in the list above and find it in the package repository (instructions).
-
Branch it:
$ bzr branch http://package-import.ubuntu.com/x/xproject/jaunty localfix -
Find the instances that might be causing the problem.
$ rgrep timeout_add * -
Commit and build a package:
$ bzr commit -m "Saving the world"
$ dch -i
$ debuild - Test it on your system, make sure things still work reasonably.
-
Generate a patch:
$ bzr diff -r ancestor: - Submit it upstream!
posted on Wed, 10 Dec 2008 at 15:28 | permanent link | 14 Comments
hahah do you literally want that to be the commit message?
Wow, I had never really understood how useful branches for packages could be! Fixing all of this could really make a difference.
After reading this post I imagined a bunch of people rushing off to tackle the list provided, all starting with the first package, and not realizing that someone already did it untill the went and filed an upstream bug report. So I made a wiki page to keep it organized:
https://wiki.ubuntu.com/SavingTheWorld
Hope this is useful. Feel free to improve it...
Just noticed in a package I was interested in that the grep actually was finding the function: g_timeout_add
Does the same thing apply here? Or is the issue only with gtk_timeout_add?
@mackenzie, not required, but I'd love that to be the comments for everyone :)
@andrewsomething, thanks for setting up the wiki page! I hope that people can really tackle these, and get a good consciousness of this everywhere.
@andrewsomething, Yes, g_timeout_add and gtk_timeout_add are roughly the same thing. As the GTK mainloop was moved from GTK to GLib the name was changed. gtk_timeout_add is older, but still valid.
Does anyone know what the equivalent would be with Qt? Does QTimer have some sort of grouping power saving features like this? Does it do it automagically?
Well, you would know better, but I have this lingering on my mind. Is it not possible that some apps might actually need to use the precise version of that call?
This is a cool post ...but is there some reason gtk_timeout_add could not perhaps just recognize when the timeout is zero mod 1000 and do the right thing?
@nucco, yes it is possible. I just think that many of them haven't thought about it, I'm willing to bet that if 10 are patched for 8 of them it's a good patch.
@Jason, The reason is that some apps really do need a precise timeout of a second, or several seconds. In that way the API allows app developers to make the choice, even if they don't make a good choice ;)
Wow. Since so many people are not doing it the most efficient way, perhaps it would be a good idea for gtk+ to do this optimization instead of having to go through the manual process of patching and sending upstream.
Perhaps a compiler warning should be emitted when the "wrong" way is used unless it is explicitly suppressed :)
Added new page for this task in Gnome wiki:
http://live.gnome.org/GnomeGoals/UseTimeoutAddSeconds