Thursday, November 17, 2011

Linux gettimeofday error on Power PC

So I've come across a gnarly issue with gettimeofday() on Linux. I'm posting this blog hoping that if someone else comes across it and Google's it, you'll contact me and we can compare notes.

Ive got a daemon running that aggregates ZigBee Wireless Sensors. It pretty much spends most of its time checking to see how long its been since a node has sent it a packet. The call to gettimeofday occurs many times a second in the main loop. Ive got this running on a few systems and every couple of days gettimeofday returns a negative value and I write these messages to the syslog.


2011-11-14 12:36:22 Daemon.Error  Time then invalid tv_sec = [-1] <= 0 (time now tv_sec = [1321292182])

and

2011-11-16 09:28:34 Daemon.Error Time now invalid tv_sec = [-524288] <= 0, (time then tv_sec = [1321453659]) timeDelta 1848



I'm doing a little reading into how the clock and time functions work on my kernel. I'm using a custom port of version 2.6.12 on a Freescale PowerPC.Im using gcc 3.4.2, with uClibC