Lines Matching +full:period +full:- +full:scale
1 /*-
2 * SPDX-License-Identifier: Beerware
4 * ----------------------------------------------------------------------------
5 * "THE BEER-WARE LICENSE" (Revision 42):
8 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
9 * ----------------------------------------------------------------------------
65 dummy_get_timecount, 0, ~0u, 1000000, "dummy", -1000000
88 .th_scale = (uint64_t)-1 / 1000000,
111 * is set to new_time - uptime.
150 static int tc_chosen; /* Non-zero if a specific tc was chosen via sysctl. */
171 if (req->flags & SCTL_MASK32) { in sysctl_kern_boottime()
187 ncount = tc->tc_get_timecount(tc); in sysctl_kern_timecounter_get()
197 freq = tc->tc_frequency; in sysctl_kern_timecounter_freq()
210 tc = th->th_counter; in tc_delta()
211 return ((tc->tc_get_timecount(tc) - th->th_offset_count) & in tc_delta()
212 tc->tc_counter_mask); in tc_delta()
216 bintime_add_tc_delta(struct bintime *bt, uint64_t scale, in bintime_add_tc_delta() argument
222 /* Avoid overflow for scale * delta. */ in bintime_add_tc_delta()
223 x = (scale >> 32) * delta; in bintime_add_tc_delta()
224 bt->sec += x >> 32; in bintime_add_tc_delta()
226 bintime_addx(bt, (scale & 0xffffffff) * delta); in bintime_add_tc_delta()
228 bintime_addx(bt, scale * delta); in bintime_add_tc_delta()
243 uint64_t scale; in bintime_off() local
248 gen = atomic_load_acq_int(&th->th_generation); in bintime_off()
251 scale = th->th_scale; in bintime_off()
253 large_delta = th->th_large_delta; in bintime_off()
255 } while (gen == 0 || gen != th->th_generation); in bintime_off()
257 bintime_add_tc_delta(bt, scale, large_delta, delta); in bintime_off()
261 _Static_assert(_Generic(((struct timehands *)NULL)->member, \
275 gen = atomic_load_acq_int(&th->th_generation); in getthmember()
278 } while (gen == 0 || gen != th->th_generation); in getthmember()
283 __typeof(((struct timehands *)NULL)->member): 1, \
503 * Support for feed-forward synchronization algorithms. This is heavily inspired
509 /* Feed-forward clock estimates kept updated by the synchronization daemon. */
511 struct bintime ffclock_boottime; /* Feed-forward boot time estimate. */
512 uint32_t ffclock_status; /* Feed-forward clock status. */
539 last = ffth + NUM_ELEMENTS(ffth) - 1; in ffclock_init()
541 cur->next = cur + 1; in ffclock_init()
542 last->next = ffth; in ffclock_init()
550 * Reset the feed-forward clock estimates. Called from inittodr() to get things
551 * kick started and uses the timecounter nominal frequency as a first period
554 * monotonic (i.e. uptime) version of the feed-forward clock.
562 tc = timehands->th_counter; in ffclock_reset_clock()
569 cest.period = ((1ULL << 63) / tc->tc_frequency) << 1; in ffclock_reset_clock()
581 printf("ffclock reset: %s (%llu Hz), time = %ld.%09lu\n", tc->tc_name, in ffclock_reset_clock()
582 (unsigned long long)tc->tc_frequency, (long)ts->tv_sec, in ffclock_reset_clock()
583 (unsigned long)ts->tv_nsec); in ffclock_reset_clock()
587 * Sub-routine to convert a time interval measured in RAW counter units to time
594 ffclock_convert_delta(ffcounter ffdelta, uint64_t period, struct bintime *bt) in ffclock_convert_delta() argument
599 delta_max = (1ULL << (8 * sizeof(unsigned int))) - 1; in ffclock_convert_delta()
607 bt2.frac = period; in ffclock_convert_delta()
610 ffdelta -= delta; in ffclock_convert_delta()
638 ffth = fftimehands->next; in ffclock_windup()
639 ogen = ffth->gen; in ffclock_windup()
640 ffth->gen = 0; in ffclock_windup()
641 cest = &ffth->cest; in ffclock_windup()
642 bcopy(&fftimehands->cest, cest, sizeof(struct ffclock_estimate)); in ffclock_windup()
644 ffth->period_lerp = fftimehands->period_lerp; in ffclock_windup()
646 ffth->tick_time = fftimehands->tick_time; in ffclock_windup()
647 ffclock_convert_delta(ffdelta, cest->period, &bt); in ffclock_windup()
648 bintime_add(&ffth->tick_time, &bt); in ffclock_windup()
650 ffth->tick_time_lerp = fftimehands->tick_time_lerp; in ffclock_windup()
651 ffclock_convert_delta(ffdelta, ffth->period_lerp, &bt); in ffclock_windup()
652 bintime_add(&ffth->tick_time_lerp, &bt); in ffclock_windup()
654 ffth->tick_ffcount = fftimehands->tick_ffcount + ffdelta; in ffclock_windup()
662 ffdelta = ffth->tick_ffcount - cest->update_ffcount; in ffclock_windup()
663 ffclock_convert_delta(ffdelta, cest->period, &bt); in ffclock_windup()
671 * estimates passed the feed-forward synchronisation daemon may result in ffclock_windup()
674 * synchronisation algo polling period that ensures monotonicity for the in ffclock_windup()
679 ffdelta = ffth->tick_ffcount - cest->update_ffcount; in ffclock_windup()
680 ffth->tick_time = cest->update_time; in ffclock_windup()
681 ffclock_convert_delta(ffdelta, cest->period, &bt); in ffclock_windup()
682 bintime_add(&ffth->tick_time, &bt); in ffclock_windup()
686 ffth->tick_time_lerp = ffth->tick_time; in ffclock_windup()
688 if (bintime_cmp(&ffth->tick_time, &ffth->tick_time_lerp, >)) in ffclock_windup()
695 gap_lerp = ffth->tick_time; in ffclock_windup()
696 bintime_sub(&gap_lerp, &ffth->tick_time_lerp); in ffclock_windup()
698 gap_lerp = ffth->tick_time_lerp; in ffclock_windup()
699 bintime_sub(&gap_lerp, &ffth->tick_time); in ffclock_windup()
713 ((cest->status & FFCLOCK_STA_UNSYNC) == 0) && in ffclock_windup()
714 ((cest->status & FFCLOCK_STA_WARMUP) == FFCLOCK_STA_WARMUP)) { in ffclock_windup()
719 ffth->tick_time_lerp = ffth->tick_time; in ffclock_windup()
723 ffclock_status = cest->status; in ffclock_windup()
724 ffth->period_lerp = cest->period; in ffclock_windup()
727 * Compute corrected period used for the linear interpolation of in ffclock_windup()
732 ffdelta = cest->update_ffcount; in ffclock_windup()
733 ffdelta -= fftimehands->cest.update_ffcount; in ffclock_windup()
734 ffclock_convert_delta(ffdelta, cest->period, &bt); in ffclock_windup()
742 /* Approximate 1 sec by 1-(1/2^64) to ease arithmetic */ in ffclock_windup()
745 frac -= 1; in ffclock_windup()
751 ffth->period_lerp += frac; in ffclock_windup()
753 ffth->period_lerp -= frac; in ffclock_windup()
760 ffth->gen = ogen; in ffclock_windup()
769 * operation for a feed-forward synchronization daemon, and it is its job to not
782 tc = th->th_counter; in ffclock_change_tc()
783 ffth = fftimehands->next; in ffclock_change_tc()
784 ogen = ffth->gen; in ffclock_change_tc()
785 ffth->gen = 0; in ffclock_change_tc()
787 cest = &ffth->cest; in ffclock_change_tc()
788 bcopy(&(fftimehands->cest), cest, sizeof(struct ffclock_estimate)); in ffclock_change_tc()
789 cest->period = ((1ULL << 63) / tc->tc_frequency ) << 1; in ffclock_change_tc()
790 cest->errb_abs = 0; in ffclock_change_tc()
791 cest->errb_rate = 0; in ffclock_change_tc()
792 cest->status |= FFCLOCK_STA_UNSYNC; in ffclock_change_tc()
794 ffth->tick_ffcount = fftimehands->tick_ffcount; in ffclock_change_tc()
795 ffth->tick_time_lerp = fftimehands->tick_time_lerp; in ffclock_change_tc()
796 ffth->tick_time = fftimehands->tick_time; in ffclock_change_tc()
797 ffth->period_lerp = cest->period; in ffclock_change_tc()
800 ffclock_updated--; in ffclock_change_tc()
804 ffth->gen = ogen; in ffclock_change_tc()
809 * Retrieve feed-forward counter and time of last kernel tick.
823 gen = ffth->gen; in ffclock_last_tick()
825 *bt = ffth->tick_time_lerp; in ffclock_last_tick()
827 *bt = ffth->tick_time; in ffclock_last_tick()
828 *ffcount = ffth->tick_ffcount; in ffclock_last_tick()
829 } while (gen == 0 || gen != ffth->gen); in ffclock_last_tick()
834 * bintime. The ffcounter is converted using the current ffclock period estimate
835 * or the "interpolated period" to ensure monotonicity.
853 gen = ffth->gen; in ffclock_convert_abs()
854 if (ffcount > ffth->tick_ffcount) in ffclock_convert_abs()
855 ffdelta = ffcount - ffth->tick_ffcount; in ffclock_convert_abs()
857 ffdelta = ffth->tick_ffcount - ffcount; in ffclock_convert_abs()
860 *bt = ffth->tick_time_lerp; in ffclock_convert_abs()
861 ffclock_convert_delta(ffdelta, ffth->period_lerp, &bt2); in ffclock_convert_abs()
863 *bt = ffth->tick_time; in ffclock_convert_abs()
864 ffclock_convert_delta(ffdelta, ffth->cest.period, &bt2); in ffclock_convert_abs()
867 if (ffcount > ffth->tick_ffcount) in ffclock_convert_abs()
871 } while (gen == 0 || gen != ffth->gen); in ffclock_convert_abs()
889 gen = ffth->gen; in ffclock_convert_diff()
890 ffclock_convert_delta(ffdelta, ffth->cest.period, bt); in ffclock_convert_diff()
891 } while (gen == 0 || gen != ffth->gen); in ffclock_convert_diff()
906 * th->th_generation only, for correct delta and ffcounter. in ffclock_read_counter()
910 gen = atomic_load_acq_int(&th->th_generation); in ffclock_read_counter()
913 *ffcount = ffth->tick_ffcount; in ffclock_read_counter()
915 } while (gen == 0 || gen != th->th_generation); in ffclock_read_counter()
1059 ffi = &clock_snap->ff_info; in sysclock_getsnapshot()
1062 fbi = &clock_snap->fb_info; in sysclock_getsnapshot()
1067 gen = atomic_load_acq_int(&th->th_generation); in sysclock_getsnapshot()
1068 fbi->th_scale = th->th_scale; in sysclock_getsnapshot()
1069 fbi->tick_time = th->th_offset; in sysclock_getsnapshot()
1072 ffi->tick_time = ffth->tick_time_lerp; in sysclock_getsnapshot()
1073 ffi->tick_time_lerp = ffth->tick_time_lerp; in sysclock_getsnapshot()
1074 ffi->period = ffth->cest.period; in sysclock_getsnapshot()
1075 ffi->period_lerp = ffth->period_lerp; in sysclock_getsnapshot()
1076 clock_snap->ffcount = ffth->tick_ffcount; in sysclock_getsnapshot()
1077 cest = ffth->cest; in sysclock_getsnapshot()
1082 } while (gen == 0 || gen != th->th_generation); in sysclock_getsnapshot()
1084 clock_snap->delta = delta; in sysclock_getsnapshot()
1085 clock_snap->sysclock_active = sysclock_active; in sysclock_getsnapshot()
1088 clock_snap->fb_info.status = time_status; in sysclock_getsnapshot()
1091 bt.frac = ((time_esterror - bt.sec) * 1000000) * in sysclock_getsnapshot()
1093 clock_snap->fb_info.error = bt; in sysclock_getsnapshot()
1097 clock_snap->ffcount += delta; in sysclock_getsnapshot()
1099 /* Record feed-forward clock leap second adjustment. */ in sysclock_getsnapshot()
1100 ffi->leapsec_adjustment = cest.leapsec_total; in sysclock_getsnapshot()
1101 if (clock_snap->ffcount > cest.leapsec_next) in sysclock_getsnapshot()
1102 ffi->leapsec_adjustment -= cest.leapsec; in sysclock_getsnapshot()
1104 /* Record feed-forward clock status and error. */ in sysclock_getsnapshot()
1105 clock_snap->ff_info.status = cest.status; in sysclock_getsnapshot()
1106 ffcount = clock_snap->ffcount - cest.update_ffcount; in sysclock_getsnapshot()
1107 ffclock_convert_delta(ffcount, cest.period, &bt); in sysclock_getsnapshot()
1112 clock_snap->ff_info.error = bt; in sysclock_getsnapshot()
1127 uint64_t period; in sysclock_snap2bintime() local
1132 *bt = cs->fb_info.tick_time; in sysclock_snap2bintime()
1135 if (cs->delta > 0) in sysclock_snap2bintime()
1136 bintime_addx(bt, cs->fb_info.th_scale * cs->delta); in sysclock_snap2bintime()
1146 *bt = cs->ff_info.tick_time_lerp; in sysclock_snap2bintime()
1147 period = cs->ff_info.period_lerp; in sysclock_snap2bintime()
1149 *bt = cs->ff_info.tick_time; in sysclock_snap2bintime()
1150 period = cs->ff_info.period; in sysclock_snap2bintime()
1154 if (cs->delta > 0) { in sysclock_snap2bintime()
1155 ffclock_convert_delta(cs->delta, period, &bt2); in sysclock_snap2bintime()
1161 bt->sec -= cs->ff_info.leapsec_adjustment; in sysclock_snap2bintime()
1185 u = tc->tc_frequency / tc->tc_counter_mask; in tc_init()
1189 if (u > hz && tc->tc_quality >= 0) { in tc_init()
1190 tc->tc_quality = -2000; in tc_init()
1193 tc->tc_name, (uintmax_t)tc->tc_frequency); in tc_init()
1194 printf(" -- Insufficient hz, needs at least %u\n", u); in tc_init()
1196 } else if (tc->tc_quality >= 0 || bootverbose) { in tc_init()
1198 tc->tc_name, (uintmax_t)tc->tc_frequency, in tc_init()
1199 tc->tc_quality); in tc_init()
1206 SYSCTL_STATIC_CHILDREN(_kern_timecounter_tc), OID_AUTO, tc->tc_name, in tc_init()
1210 "mask", CTLFLAG_RD, &(tc->tc_counter_mask), 0, in tc_init()
1221 "quality", CTLFLAG_RD, &(tc->tc_quality), 0, in tc_init()
1225 tc->tc_next = timecounters; in tc_init()
1236 if (tc->tc_quality < 0) in tc_init()
1239 strcmp(tc->tc_name, tc_from_tunable) == 0) { in tc_init()
1243 if (tc->tc_quality < timecounter->tc_quality) in tc_init()
1245 if (tc->tc_quality == timecounter->tc_quality && in tc_init()
1246 tc->tc_frequency < timecounter->tc_frequency) in tc_init()
1249 (void)tc->tc_get_timecount(tc); in tc_init()
1260 return (timehands->th_counter->tc_frequency); in tc_getfrequency()
1273 * the thread that it was woken due to a real-time clock adjustment. in sleeping_on_old_rtc()
1276 if (td->td_rtcgen != 0 && td->td_rtcgen != rtc_generation) { in sleeping_on_old_rtc()
1277 td->td_rtcgen = 0; in sleeping_on_old_rtc()
1317 (intmax_t)ts->tv_sec, ts->tv_nsec); in tc_setclock()
1323 * fractions of a second per period of the hardware counter, taking
1332 * The range of th_adjustment is +/- 5000PPM so inside a 64bit int
1346 uint64_t scale; in recalculate_scaling_factor_and_large_delta() local
1348 scale = (uint64_t)1 << 63; in recalculate_scaling_factor_and_large_delta()
1349 scale += (th->th_adjustment / 1024) * 2199; in recalculate_scaling_factor_and_large_delta()
1350 scale /= th->th_counter->tc_frequency; in recalculate_scaling_factor_and_large_delta()
1351 th->th_scale = scale * 2; in recalculate_scaling_factor_and_large_delta()
1352 th->th_large_delta = MIN(((uint64_t)1 << 63) / scale, UINT_MAX); in recalculate_scaling_factor_and_large_delta()
1376 * For similar reasons, re-reading of the generation after the in tc_windup()
1380 th = tho->th_next; in tc_windup()
1381 ogen = th->th_generation; in tc_windup()
1382 th->th_generation = 0; in tc_windup()
1386 th->th_boottime = *new_boottimebin; in tc_windup()
1395 if (th->th_counter != tc) in tc_windup()
1396 ncount = tc->tc_get_timecount(tc); in tc_windup()
1402 th->th_offset_count += delta; in tc_windup()
1403 th->th_offset_count &= th->th_counter->tc_counter_mask; in tc_windup()
1404 bintime_add_tc_delta(&th->th_offset, th->th_scale, in tc_windup()
1405 th->th_large_delta, delta); in tc_windup()
1415 if (tho->th_counter->tc_poll_pps) in tc_windup()
1416 tho->th_counter->tc_poll_pps(tho->th_counter); in tc_windup()
1427 bt = th->th_offset; in tc_windup()
1428 bintime_add(&bt, &th->th_boottime); in tc_windup()
1429 i = bt.sec - tho->th_microtime.tv_sec; in tc_windup()
1436 ntp_update_second(&th->th_adjustment, &bt.sec); in tc_windup()
1438 th->th_boottime.sec += bt.sec - t; in tc_windup()
1439 --i; in tc_windup()
1446 th->th_bintime = bt; in tc_windup()
1447 bintime2timeval(&bt, &th->th_microtime); in tc_windup()
1448 bintime2timespec(&bt, &th->th_nanotime); in tc_windup()
1451 if (th->th_counter != tc) { in tc_windup()
1453 if ((tc->tc_flags & TC_FLAGS_C2STOP) != 0) in tc_windup()
1455 if ((th->th_counter->tc_flags & TC_FLAGS_C2STOP) != 0) in tc_windup()
1456 cpu_disable_c2_sleep--; in tc_windup()
1458 th->th_counter = tc; in tc_windup()
1459 th->th_offset_count = ncount; in tc_windup()
1460 tc_min_ticktock_freq = max(1, tc->tc_frequency / in tc_windup()
1461 (((uint64_t)tc->tc_counter_mask + 1) / 3)); in tc_windup()
1474 atomic_store_rel_int(&th->th_generation, ogen); in tc_windup()
1481 time_second = th->th_microtime.tv_sec; in tc_windup()
1482 time_uptime = th->th_offset.sec; in tc_windup()
1486 time_second = fftimehands->tick_time_lerp.sec; in tc_windup()
1487 time_uptime = fftimehands->tick_time_lerp.sec - ffclock_boottime.sec; in tc_windup()
1506 strlcpy(newname, tc->tc_name, sizeof(newname)); in sysctl_kern_timecounter_hardware()
1510 if (error != 0 || req->newptr == NULL) in sysctl_kern_timecounter_hardware()
1516 if (strcmp(newname, tc->tc_name) == 0) { in sysctl_kern_timecounter_hardware()
1520 for (newtc = timecounters; newtc != NULL; newtc = newtc->tc_next) { in sysctl_kern_timecounter_hardware()
1521 if (strcmp(newname, newtc->tc_name) != 0) in sysctl_kern_timecounter_hardware()
1525 (void)newtc->tc_get_timecount(newtc); in sysctl_kern_timecounter_hardware()
1560 for (tc = timecounters; tc != NULL; tc = tc->tc_next) { in sysctl_kern_timecounter_choice()
1563 sbuf_printf(&sb, "%s(%d)", tc->tc_name, tc->tc_quality); in sysctl_kern_timecounter_choice()
1577 * RFC 2783 PPS-API implementation.
1588 return ((pps->kcmode & KCMODE_ABIFLAG) && pps->driver_abi >= vers); in abi_aware()
1598 if (fapi->tsformat && fapi->tsformat != PPS_TSFMT_TSPEC) in pps_fetch()
1603 * most recently captured. If timeout seconds is -1, that's a request in pps_fetch()
1608 if (fapi->timeout.tv_sec || fapi->timeout.tv_nsec) { in pps_fetch()
1609 if (fapi->timeout.tv_sec == -1) in pps_fetch()
1612 tv.tv_sec = fapi->timeout.tv_sec; in pps_fetch()
1613 tv.tv_usec = fapi->timeout.tv_nsec / 1000; in pps_fetch()
1616 aseq = atomic_load_int(&pps->ppsinfo.assert_sequence); in pps_fetch()
1617 cseq = atomic_load_int(&pps->ppsinfo.clear_sequence); in pps_fetch()
1618 while (aseq == atomic_load_int(&pps->ppsinfo.assert_sequence) && in pps_fetch()
1619 cseq == atomic_load_int(&pps->ppsinfo.clear_sequence)) { in pps_fetch()
1620 if (abi_aware(pps, 1) && pps->driver_mtx != NULL) { in pps_fetch()
1621 if (pps->flags & PPSFLAG_MTX_SPIN) { in pps_fetch()
1622 err = msleep_spin(pps, pps->driver_mtx, in pps_fetch()
1625 err = msleep(pps, pps->driver_mtx, PCATCH, in pps_fetch()
1632 if (fapi->timeout.tv_sec == -1) { in pps_fetch()
1643 pps->ppsinfo.current_mode = pps->ppsparam.mode; in pps_fetch()
1644 fapi->pps_info_buf = pps->ppsinfo; in pps_fetch()
1669 if (app->mode & ~pps->ppscap) in pps_ioctl()
1673 if ((app->mode & PPS_TSCLK_MASK) == PPS_TSCLK_MASK) in pps_ioctl()
1676 pps->ppsparam = *app; in pps_ioctl()
1680 *app = pps->ppsparam; in pps_ioctl()
1681 app->api_version = PPS_API_VERS_1; in pps_ioctl()
1684 *(int*)data = pps->ppscap; in pps_ioctl()
1692 if (fapi_ffc->tsformat && fapi_ffc->tsformat != in pps_ioctl()
1695 if (fapi_ffc->timeout.tv_sec || fapi_ffc->timeout.tv_nsec) in pps_ioctl()
1697 pps->ppsinfo_ffc.current_mode = pps->ppsparam.mode; in pps_ioctl()
1698 fapi_ffc->pps_info_buf_ffc = pps->ppsinfo_ffc; in pps_ioctl()
1700 switch (pps->ppsparam.mode & PPS_TSCLK_MASK) { in pps_ioctl()
1702 fapi_ffc->pps_info_buf_ffc.assert_timestamp = in pps_ioctl()
1703 pps->ppsinfo.assert_timestamp; in pps_ioctl()
1704 fapi_ffc->pps_info_buf_ffc.clear_timestamp = in pps_ioctl()
1705 pps->ppsinfo.clear_timestamp; in pps_ioctl()
1718 if (kapi->tsformat && kapi->tsformat != PPS_TSFMT_TSPEC) in pps_ioctl()
1720 if (kapi->kernel_consumer != PPS_KC_HARDPPS) in pps_ioctl()
1722 if (kapi->edge & ~pps->ppscap) in pps_ioctl()
1724 pps->kcmode = (kapi->edge & KCMODE_EDGEMASK) | in pps_ioctl()
1725 (pps->kcmode & KCMODE_ABIFLAG); in pps_ioctl()
1738 pps->ppscap |= PPS_TSFMT_TSPEC | PPS_CANWAIT; in pps_init()
1739 if (pps->ppscap & PPS_CAPTUREASSERT) in pps_init()
1740 pps->ppscap |= PPS_OFFSETASSERT; in pps_init()
1741 if (pps->ppscap & PPS_CAPTURECLEAR) in pps_init()
1742 pps->ppscap |= PPS_OFFSETCLEAR; in pps_init()
1744 pps->ppscap |= PPS_TSCLK_MASK; in pps_init()
1746 pps->kcmode &= ~KCMODE_ABIFLAG; in pps_init()
1754 if (pps->driver_abi > 0) { in pps_init_abi()
1755 pps->kcmode |= KCMODE_ABIFLAG; in pps_init_abi()
1756 pps->kernel_abi = PPS_ABI_VERSION; in pps_init_abi()
1768 pps->capgen = atomic_load_acq_int(&th->th_generation); in pps_capture()
1769 pps->capth = th; in pps_capture()
1771 pps->capffth = fftimehands; in pps_capture()
1773 tc = th->th_counter; in pps_capture()
1774 pps->capcount = tc->tc_get_timecount(tc); in pps_capture()
1799 if ((event & pps->ppsparam.mode) == 0) in pps_event()
1803 capth = pps->capth; in pps_event()
1804 captc = capth->th_counter; in pps_event()
1805 capth_scale = capth->th_scale; in pps_event()
1806 tcount = capth->th_offset_count; in pps_event()
1807 bt = capth->th_bintime; in pps_event()
1811 if (pps->capgen == 0 || pps->capgen != capth->th_generation) in pps_event()
1816 tsp = &pps->ppsinfo.assert_timestamp; in pps_event()
1817 osp = &pps->ppsparam.assert_offset; in pps_event()
1818 foff = pps->ppsparam.mode & PPS_OFFSETASSERT; in pps_event()
1820 fhard = pps->kcmode & PPS_CAPTUREASSERT; in pps_event()
1822 pcount = &pps->ppscount[0]; in pps_event()
1823 pseq = &pps->ppsinfo.assert_sequence; in pps_event()
1825 ffcount = &pps->ppsinfo_ffc.assert_ffcount; in pps_event()
1826 tsp_ffc = &pps->ppsinfo_ffc.assert_timestamp; in pps_event()
1827 pseq_ffc = &pps->ppsinfo_ffc.assert_sequence; in pps_event()
1830 tsp = &pps->ppsinfo.clear_timestamp; in pps_event()
1831 osp = &pps->ppsparam.clear_offset; in pps_event()
1832 foff = pps->ppsparam.mode & PPS_OFFSETCLEAR; in pps_event()
1834 fhard = pps->kcmode & PPS_CAPTURECLEAR; in pps_event()
1836 pcount = &pps->ppscount[1]; in pps_event()
1837 pseq = &pps->ppsinfo.clear_sequence; in pps_event()
1839 ffcount = &pps->ppsinfo_ffc.clear_ffcount; in pps_event()
1840 tsp_ffc = &pps->ppsinfo_ffc.clear_timestamp; in pps_event()
1841 pseq_ffc = &pps->ppsinfo_ffc.clear_sequence; in pps_event()
1845 *pcount = pps->capcount; in pps_event()
1849 * we have to drop the rest of the PPS-stuff until the next event. in pps_event()
1851 if (__predict_false(pps->ppstc != captc)) { in pps_event()
1852 pps->ppstc = captc; in pps_event()
1853 pps->ppscount[2] = pps->capcount; in pps_event()
1860 tcount = pps->capcount - tcount; in pps_event()
1861 tcount &= captc->tc_counter_mask; in pps_event()
1867 if (tsp->tv_nsec < 0) { in pps_event()
1868 tsp->tv_nsec += 1000000000; in pps_event()
1869 tsp->tv_sec -= 1; in pps_event()
1874 *ffcount = pps->capffth->tick_ffcount + tcount; in pps_event()
1875 bt = pps->capffth->tick_time; in pps_event()
1876 ffclock_convert_delta(tcount, pps->capffth->cest.period, &bt); in pps_event()
1877 bintime_add(&bt, &pps->capffth->tick_time); in pps_event()
1892 tcount = pps->capcount - pps->ppscount[2]; in pps_event()
1893 pps->ppscount[2] = pps->capcount; in pps_event()
1894 tcount &= captc->tc_counter_mask; in pps_event()
1897 freq = captc->tc_frequency; in pps_event()
1940 tc_precexp = fls(t + (t >> 1)) - 1; in tc_adjprecision()
1962 if (error != 0 || req->newptr == NULL) in sysctl_kern_timecounter_adjprecision()
1986 thp->th_next = &ths[i]; in inittimehands()
1987 thp->th_next = &ths[0]; in inittimehands()
2008 * should use the non-"get"* functions. in inittimecounter()
2028 (void)timecounter->tc_get_timecount(timecounter); in inittimecounter()
2036 /* Cpu tick handling -------------------------------------------------*/
2054 tc = timehands->th_counter; in tc_cpu_ticks()
2055 u = tc->tc_get_timecount(tc) & tc->tc_counter_mask; in tc_cpu_ticks()
2057 *base += (uint64_t)tc->tc_counter_mask + 1; in tc_cpu_ticks()
2105 c_delta = c_this - c_last; in cpu_tick_calibrate()
2110 * 2^(64-20) / 16[s] = in cpu_tick_calibrate()
2116 divi |= t_delta.frac >> (64 - 20); in cpu_tick_calibrate()
2194 vdso_th->th_scale = th->th_scale; in tc_fill_vdso_timehands()
2195 vdso_th->th_offset_count = th->th_offset_count; in tc_fill_vdso_timehands()
2196 vdso_th->th_counter_mask = th->th_counter->tc_counter_mask; in tc_fill_vdso_timehands()
2197 vdso_th->th_offset = th->th_offset; in tc_fill_vdso_timehands()
2198 vdso_th->th_boottime = th->th_boottime; in tc_fill_vdso_timehands()
2199 if (th->th_counter->tc_fill_vdso_timehands != NULL) { in tc_fill_vdso_timehands()
2200 enabled = th->th_counter->tc_fill_vdso_timehands(vdso_th, in tc_fill_vdso_timehands()
2201 th->th_counter); in tc_fill_vdso_timehands()
2217 *(uint64_t *)&vdso_th32->th_scale[0] = th->th_scale; in tc_fill_vdso_timehands32()
2218 vdso_th32->th_offset_count = th->th_offset_count; in tc_fill_vdso_timehands32()
2219 vdso_th32->th_counter_mask = th->th_counter->tc_counter_mask; in tc_fill_vdso_timehands32()
2220 vdso_th32->th_offset.sec = th->th_offset.sec; in tc_fill_vdso_timehands32()
2221 *(uint64_t *)&vdso_th32->th_offset.frac[0] = th->th_offset.frac; in tc_fill_vdso_timehands32()
2222 vdso_th32->th_boottime.sec = th->th_boottime.sec; in tc_fill_vdso_timehands32()
2223 *(uint64_t *)&vdso_th32->th_boottime.frac[0] = th->th_boottime.frac; in tc_fill_vdso_timehands32()
2224 if (th->th_counter->tc_fill_vdso_timehands32 != NULL) { in tc_fill_vdso_timehands32()
2225 enabled = th->th_counter->tc_fill_vdso_timehands32(vdso_th32, in tc_fill_vdso_timehands32()
2226 th->th_counter); in tc_fill_vdso_timehands32()
2246 tc = th->th_counter; in DB_SHOW_COMMAND()
2247 val1 = tc->tc_get_timecount(tc); in DB_SHOW_COMMAND()
2249 val2 = tc->tc_get_timecount(tc); in DB_SHOW_COMMAND()
2251 db_printf("timecounter %p %s\n", tc, tc->tc_name); in DB_SHOW_COMMAND()
2253 tc->tc_counter_mask, (uintmax_t)tc->tc_frequency, tc->tc_quality, in DB_SHOW_COMMAND()
2254 tc->tc_flags, tc->tc_priv); in DB_SHOW_COMMAND()
2256 db_printf("timehands adj %#jx scale %#jx ldelta %d off_cnt %d gen %d\n", in DB_SHOW_COMMAND()
2257 (uintmax_t)th->th_adjustment, (uintmax_t)th->th_scale, in DB_SHOW_COMMAND()
2258 th->th_large_delta, th->th_offset_count, th->th_generation); in DB_SHOW_COMMAND()
2260 (intmax_t)th->th_offset.sec, (uintmax_t)th->th_offset.frac, in DB_SHOW_COMMAND()
2261 (intmax_t)th->th_boottime.sec, (uintmax_t)th->th_boottime.frac); in DB_SHOW_COMMAND()