[LinuxPPS] OK, I found an error, please fix.

clemens at dwf.com clemens at dwf.com
Mon Oct 22 02:00:24 CEST 2007


OK, I found the error.
In kapi.c/pps_event, you call pps_add_offset to add any offset that has been
provided.

The arguments to pps_add_offset are of type pps_ktime, defined as

struct pps_ktime {
       __u64 sec;
       __u32 nsec;
       __u32 flags;
};

in pps.h .

(1) FIRST PROBLEM: Offset can be negative so it cant be of type pps_ktime.
If negative, its value has been screwed up by the time you get here.

In pps_add_offset, you add the offset to the time, putting the result back
in ts->nsec. You then normalize the result if the number of ns has gone
above NSEC_PER_SEC (this works) or if it goes below ZERO (this doesnt work)
since ts->nsec is unsigned and the result will never be below ZERO.

(2) SECOND PROBLEM: ts->nsec is UNSIGNED, so the test

        } else if (ts->nsec < 0) {

always fails.

In fact, my offset is negative, and Im sure that this is what is biting
me in the ass.  Im not sure how I seem to get several seconds off but Ill worry
about that when the above is fixed.

Seems you need EITHER to NOT make ktime up out of unsigned's or you need
a parallel structure with signed variables in it.

Ill wait to see what your solution is.

AND, I seem to remember some old NTP code where the the IF and ELSE in the
pps_add_offset normalization  were in fact while loops, with the thought that they
should only be gone thru once,   ... but just in case ... they would get the right answer.

--
                                        Reg.Clemens
                                        reg at dwf.com





More information about the LinuxPPS mailing list