GNOME Bugzilla – Bug 348749
clock wakes up too frequently
Last modified: 2007-02-21 21:19:11 UTC
the clock does a syscall per second, even when seconds are disabled. this is bad for battery life on portables. it shouldn't be too hard to do the following: if we are in don't-display-seconds mode: - take the current time of day and figure out how far until the next minute boundry. - schedule our next wakeup for that long -- not in 1 second from now.
Created attachment 69742 [details] [review] fix. while fixing this bug i found another bug related to internet time. we do something like printf("%3.0f", time) for internet time without second. printf rounds up. this means that @345.67 would show as @346 with seconds disabled which is a bit odd. this wrongness is componded by the fact that the old "check if the time shown on the clock has changed" rounds down meaning that the change would actually occur only on integer boundries and therefore the clock would appear to be functioning normally (except if changing the format/orientation/etc of the clock while in the 0.5..1.0 period). i fixed this by flooring the value before giving it to printf. otherwise the patch should fix the problem as described. please give it a go.
IIRC this used to work correctly. I think this regression was caused by the patch from bug #156796.
One thing to note: the entire idea of sleeping for the interval of an 'internet time second' is cracked (at least with the current code). The time() syscall is used to get the current time. This only has second-level accuracy so even if you sleep for 800ms you will not get more than one-second accuracy. Note also that nobody even noticed the bug about the improper rounding in internet time. This makes me question how many people use internet time at all.
Internet time should most probably be killed, or at least hidden. Bug #156796 is indeed when we reintroduce the bug, but it clearly fixed a bug too. I don't know what we can do here...
"If seconds are not showed the time is updated only every minute" i don't understand why this is a problem. if seconds are not shown then the correct behaviour is that the displayed time will change once per minute. maybe i'm being terribly obtuse here. if so, please explain to me slowly and with a baseball bat what the problem is :)
Created attachment 70049 [details] [review] A fix for the continuous wake up of the clock, and the no regular update of Internet Time. Hi all: I fixed both bugs (wake up and internet time) with this patch. It calculates the time so far for the next minute and reprograms the timer for that time, unless the time is 60 seconds; in that case it will put the timer to 60 seconds and don't touch it again unless the user changes the configuration. Normally only two sets of the timer are needed. For the second bug (the jumps in the internet time) I used the microsecond resolution (thanks, gettimeofday() :). Now it counts fine.
I'll accept a patch which does nothing but monitors /etc/timezone to know that the clock should be updated.
I've actually thought about a different problem. If you actually change the date/time on your computer (not just the timezone), then the clock will take as long as a minute to update. This is probably a more common case than changing your timezone. Not sure if there is anything we can do about this, really. In an ideal world, anything that changes the time would have a way of alerting all interested programs on the system. Alternatively, the kernel could alert any interested parties when the time is stepped by more than a few seconds. We need some more love from upstream for this to happen properly :(
(In reply to comment #7) > I'll accept a patch which does nothing but monitors /etc/timezone to know that > the clock should be updated. I think you'll find that it is a little more difficult than that - especially if you want something robust and reasonable cross-platform.
Created attachment 70438 [details] an example of how to get and set timezone Here is an example from one of my ancient and slightly wrong-headed attempts to solve the timezone problems (from bug #154085). So, you'd have to look at more than /etc/timezone.
Created attachment 72035 [details] [review] alternative patch that is more minimally invasive Alternative patch attached; what it does is just the change to wait until the next redisplay, everything else already works as expected yes this means that if you change timezones you may need to wait upto one minute for the clock to update. All other OSes have similar things as well and nobody seems to care about it..
Created attachment 72039 [details] [review] another patch For reference, here is the patch that I've put in the Fedora rpm
(In reply to comment #11) > yes this means that if you change timezones you may need to wait upto one > minute for the clock to update. All other OSes have similar things as well and > nobody seems to care about it.. Well, actually I care, and at some point reported it in bugzilla. This gives the feeling that the time change did not go through. It is confusing, but probably not enough to reject patches in this bug. :-)
Think about, also, a laptop returning from sleep.
I committed a patch based on the latest ones. I didn't fix the internet time issue, since the two patches fixing this are mixed with the patch for this bug. Ryan, raster: could you update your patches and add them to bug 410542? Thanks.