Animation/Python/PyGames vs battery charge

John Gilmore gnu at toad.com
Wed Jan 30 01:21:51 EST 2008


> I am trying to preserve as much battery energy as I can.
> 
> So I am setting a specific frame rate and sleeping beyond what it takes to 
> maintain that frame rate.
> 
> Do you think this will actually reduce the drain on the XO battery?

Sleeping for a small fraction of a second (e.g. 1/20th of a second or
less) will reduce the CPU's power drain slightly, when the Linux
scheduler executes a "Halt" instruction.  But it won't allow the XO's
very aggressive powering down of the whole CPU chip.  That's because
it currently takes the OLPC OS almost a whole second to power down or
power up the CPU chip.  (This, in turn, is partly caused by the
hardware being designed to do that for Windows "when the user hits the
manual Suspend button", and partly by inefficiencies in the kernel
drivers that will soon be addressed.)  The system's design goal is to
do this in a tenth or a second or so.  Thus any frame rate above about
8 Hz is going to make suspending impossible while your game is
running, even with the best possible auto-suspend software running in
today's hardware.

I suspect that the best thing you can do to reduce power is to make
sure that your game doesn't do anything when it isn't the frontmost
thing on the screen.  I.e. if the window that you're drawing in is
totally obscured, then don't run ANYTHING -- no game animations, but
also no background world-simulating stuff, and little or no network
activity.  Resume activity once the user brings your game to the front
again.  Don't wake up periodically and do anything; be sure to do
NOTHING.

Ensuring this background-idle behavior will not only allow the
activity that's frontmost to get 100% of the CPU cycles.  It will also
allow the XO to suspend and power down if that frontmost activity goes
idle.  (If you're chewing up CPU in the background, the system won't
auto-suspend.)

(To test this, log in to your XO via ssh from another machine, and run
"strace -p NNNNN" to watch your game do system calls.  This will
verify for you that no system calls are happening while the game is
not visible.  If strace shows system calls happening, you can get out
of strace with Ctrl-C and run gdb to see why those calls are
happening.  To login via ssh you'll need to set a password for root or
olpc first.)

	John



More information about the Devel mailing list