diff options
author | phk <phk@FreeBSD.org> | 2002-04-26 20:24:28 +0000 |
---|---|---|
committer | phk <phk@FreeBSD.org> | 2002-04-26 20:24:28 +0000 |
commit | 0054f0f74b4415097c17e647b18be568e088debd (patch) | |
tree | 61c1590387f116655d9c80b8e7b3ced6030e81c9 /sys/kern | |
parent | 8fb7b3e1de2f4a190bd736f36efaace478312ffe (diff) | |
download | FreeBSD-src-0054f0f74b4415097c17e647b18be568e088debd.zip FreeBSD-src-0054f0f74b4415097c17e647b18be568e088debd.tar.gz |
Simplify the RFC2783 and PPS_SYNC timestamp collection API.
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/kern_tc.c | 53 |
1 files changed, 37 insertions, 16 deletions
diff --git a/sys/kern/kern_tc.c b/sys/kern/kern_tc.c index aee3eaa..fe07aec 100644 --- a/sys/kern/kern_tc.c +++ b/sys/kern/kern_tc.c @@ -478,7 +478,18 @@ pps_init(struct pps_state *pps) } void -pps_event(struct pps_state *pps, struct timecounter *tc, unsigned count, int event) +pps_capture(struct pps_state *pps) +{ + struct timecounter *tc; + + tc = timecounter; + pps->captc = tc; + pps->capgen = tc->tc_generation; + pps->capcount = tc->tc_get_timecount(tc); +} + +void +pps_event(struct pps_state *pps, int event) { struct timespec ts, *tsp, *osp; unsigned tcount, *pcount; @@ -486,6 +497,10 @@ pps_event(struct pps_state *pps, struct timecounter *tc, unsigned count, int eve int foff, fhard; pps_seq_t *pseq; + /* If the timecounter were wound up, bail. */ + if (pps->capgen != pps->capgen) + return; + /* Things would be easier with arrays... */ if (event == PPS_CAPTUREASSERT) { tsp = &pps->ppsinfo.assert_timestamp; @@ -505,26 +520,32 @@ pps_event(struct pps_state *pps, struct timecounter *tc, unsigned count, int eve /* The timecounter changed: bail */ if (!pps->ppstc || - pps->ppstc->tc_name != tc->tc_name || - tc->tc_name != timecounter->tc_name) { - pps->ppstc = tc; - *pcount = count; + pps->ppstc->tc_name != pps->captc->tc_name || + pps->captc->tc_name != timecounter->tc_name) { + pps->ppstc = pps->captc; + *pcount = pps->capcount; +#ifdef PPS_SYNC + pps->ppscount[2] = pps->capcount; +#endif return; } /* Nothing really happened */ - if (*pcount == count) + if (*pcount == pps->capcount) return; - *pcount = count; - /* Convert the count to timespec */ - tcount = count - tc->tc_offset_count; - tcount &= tc->tc_counter_mask; - bt = tc->tc_offset; - bintime_addx(&bt, tc->tc_scale * tcount); + tcount = pps->capcount - pps->captc->tc_offset_count; + tcount &= pps->captc->tc_counter_mask; + bt = pps->captc->tc_offset; + bintime_addx(&bt, pps->captc->tc_scale * tcount); bintime2timespec(&bt, &ts); + /* If the timecounter were wound up, bail. */ + if (pps->capgen != pps->capgen) + return; + + *pcount = pps->capcount; (*pseq)++; *tsp = ts; @@ -538,12 +559,12 @@ pps_event(struct pps_state *pps, struct timecounter *tc, unsigned count, int eve #ifdef PPS_SYNC if (fhard) { /* magic, at its best... */ - tcount = count - pps->ppscount[2]; - pps->ppscount[2] = count; - tcount &= tc->tc_counter_mask; + tcount = pps->capcount - pps->ppscount[2]; + pps->ppscount[2] = pps->capcount; + tcount &= pps->captc->tc_counter_mask; bt.sec = 0; bt.frac = 0; - bintime_addx(&bt, tc->tc_scale * tcount); + bintime_addx(&bt, pps->captc->tc_scale * tcount); bintime2timespec(&bt, &ts); hardpps(tsp, ts.tv_nsec + 1000000000 * ts.tv_sec); } |