Re: Synchronising an app with the system clock



On Wed, 2007-02-14 at 19:28 +0000, Alex Jones wrote: 
> This involves a glib timeout of 1000ms, which I understand is not 100%
> guaranteed to work because it might skip from...

One of the things we're working on is an application that displays
timezones. So, surprise, we needed not just hourly updates but per
minute UI updates.

There were all kinds of horrible cases: Suspend and resume the machine
of course - waiting up to a minute for the clock to correct itself is
not good, so had to cover that one off. Pausing the application - for
example debugging it - same story. Then there was changing timezone as
you fly from one city to another. Ouch.

We ended up with the same 1000ms Timer you did, but then asked the OS
for the time rather than assuming that 1 second has occurred. Converting
that answer to seconds we do (tick % 60 == 0)? to see if the minute has
rolled over and if it has, we do the UI update.

We then store that as "last tick" in a local variable. When the next
wake up happens, if it is not (last + 1). If it isn't, we force a UI
update on the assumption that things are probably wrong due to one of
the above reasons.

Works pretty well, and although we have the 1000ms timer (yes, bad), at
least we're not slavishly updating the UI every second for no reason.

This is all somewhat excessive, of course, but at least the time
displayed is always correct, which is kinda the point.

> Any other ideas/comments?

The usual thing that happens in these conversations is that someone says
"if you need realistic time response you should be using a real time
operating system!" (Oh, gee, really? Thanks dude). The work that has
been done to reduce context switches and wakeups is cool, though, and I
get the notion that we should be trying to eliminate the timers to save
power.

But for those of us who need to display a clock, what's the right thing
to do? Isn't a DBus notification still a wakeup? The "clock changed a
lot" notification woudln't help for an individual app that is gets
itself out of sync for whatever reason, would it?

clock-applet is one always of the highest CPU time  programs on my box.
So perhaps being expensive is just the way that doing time based UI
updates is gonna be.

AfC
Sydney


-- 
Andrew Frederick Cowie
Operational Dynamics

Website: http://www.operationaldynamics.com/
Blog: http://research.operationaldynamics.com/blogs/andrew/
GPG key: 0945 9282 449C 0058 1FF5  2852 2D51 130C 57F6 E7BD

Sydney    +61 2 9977 6866
New York  +1 646 472 5054
Toronto   +1 416 848 6072
London    +44 207 1019201

Attachment: signature.asc
Description: This is a digitally signed message part



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]