Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 24 Jul 2006 17:18:50 -0400
From:      Michael Scheidell <scheidell@secnap.net>
To:        freebsd-hackers@freebsd.org
Subject:   Re: FBSD 5.5 and software timers
Message-ID:  <44C5393A.6010203@secnap.net>
In-Reply-To: <44C4EB9D.1060106@secnap.net>
References:  <44C4EB9D.1060106@secnap.net>

next in thread | previous in thread | raw e-mail | index | archive | help
Michael Scheidell wrote:
> I had a 200ms software timer running in FBSD 5.4 that isn't working in 
> 5.5 now.
> This software timer was resetting a 1 second hardware watchdog timer.
> Every 200ms, I sent a reset to the hardware WDT.
> Everything worked on 5.4, but I am getting failures on 5.5
> It appears that something changed in ntpd, clock_gettime, or nanosleep.
> I can 'fix' it by specifying -x in ntpd (slew even if large change), 
> but after a day, time is off by more than 5 mins.
>
> I think all I did was upgrade from 5.4 to 5.5

I suspect, but have not found it, that on 5.4 when ntp sets time back 
using adjtime, it triggers any nanosleep() that would be affected.

It looks like FREEBSD 5.4 doesn't do this.

Reason I ask:

simple program:
#define MS_SLEEP(x) nanosleep(x*1000);

main() {
 
   enable_our_hardware_wdt(1);     // Set our hardware watchdog timer to 
die if not patted in 1 second.
   while(1) {
      MS_SLEEP(200);            // sleep for 200ms
      pat_our_dog();
    }

}

if I set clock back 2 seconds using ntpdate, or if ntpd sets clock back 
2 seconds, the nanosleep sleeps for more than 1 second.
Reason I know: the hardware timer goes off.
I have tried starting process with nice -19, rtprio 31, doesn't matter.

(ntpdate -qd us.pool.ntp.org shows offset of -2 seconds or more)

Again, worked fine in 5.4.
   
my current workaround is to run ntpd with -x to slew changes to 128ms, 
but after 10 hours, one of the computers is off by  10 seconds.   
('date' vs ntpdate -qd us.pool.ntp.org)

then every 24 hours, I have to slay ntpd, run ntpdate -b to fix the 
time, start ntpd and our_dog.
>
> It fails within 1 second of getting these types of log entries:
> Jul 23 15:03:42 audit18 ntpd[473]: time reset -2.497234 s
> Jul 23 16:03:56 audit18 ntpd[473]: time reset +1.532401 s
>
> if -2.49, and we were inside of the nanosleep() and I was expecting a 
> 200ms sleep, I get 2600ms.
> (yes, I think I do.  the 1 second hardware timer on the WDT triggers 
> if not reset every 1000ms (1 second))
>
> if +1.53, I have to do some hard thinking since my nanosleep() APPEARS 
> to have happened in -1330 ms.
>
> Oh, did I mention, this worked on 5.4? and if a prevent the 'time 
> reset' log entries by adding the -x switch to ntpd I don't get 
> failures? (except that the clock drifts about 2 seconds per hour!)
> Also, 5.4 also showed alternating -2 and +2 second time resets, about 
> once an hour, but it didn't seem to affect nanosleep().
>
> ntpd using strata 2 ntp server, with 2 other backups.
> ntpdc -c peers shows drift when using -x option. (no different then 
> 5.4 did)
>


-- 
Michael Scheidell, CTO
SECNAP Network Security / www.secnap.com
scheidell@secnap.net  / 1+561-999-5000, x 1131




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?44C5393A.6010203>