Animation/Python/PyGames vs battery charge

Mike C. Fletcher mcfletch at vrplumber.com
Mon Jan 28 17:36:18 EST 2008


Noah Kantrowitz wrote:
> Kent Loobey wrote:
>> I have set up some test animation code.
>>
>> Normally games try to take all the cycles they can get.
>>
>> 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?
>>
>> In other words "What does the XO do when apps sleep?"
>>
>>   
>
> If SDL is actually using a real timed sleep, it would help, but I
> don't think it does. This is often too inaccurate for games, so we may
> need to look at that ourselves. Because pygame is polling driven
> (instead of using async callbacks like GTK) it is unlikely that it
> will ever get as nice a battery life as GTK-based activities.
There are two types of "sleep" in Pygame, one is:

    pygame.time.wait( milliseconds )

which does a process sleep.  The other is:

    pygame.time.delay( milliseconds )

which does a busy-loop to provide accurate time-keeping.  OLPCGames also
now has a function which combines wait with a time-based "sleep" state
where the program is completely suspended if there are no events for a
given period.  The same is true of Pippy's (independent) wrapper.

That said, lots of games, particularly ones which are "simulation"
based, may need to run all the time.  The XO is also *not* currently
(AFAIK) doing aggressive suspend.  That is, while we would like to get
to the point where the machine can suspend and resume in 10ms range, it
currently takes too long to shut down between frames of a game.  That
is, while eventually micro-sleep may show up, AFAIK we don't yet have
support for it on the laptop, so the processor is likely running at 100%
power (even if in a busy loop in the kernel) (AFAIK there is no
frequency scaling available in the processor).  We might get some
minimal benefit from having less load, but if we're waking up 10 or 15
times a second we're not going to see the kind of power benefits we'd
see with multi-second or multi-minute suspending.

We still want to have the games waiting when they are not needed. 
Eventually we hope to get aggressive suspend such that between frames we
can go to sleep, but until then the power benefits are in allowing other
processes to run, and in shutting down the game entirely after a period
of inactivity.

HTH,
Mike

-- 
________________________________________________
  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://www.vrplumber.com
  http://blog.vrplumber.com




More information about the Devel mailing list