kern_tc.c (209216) | kern_tc.c (209390) |
---|---|
1/*- 2 * ---------------------------------------------------------------------------- 3 * "THE BEER-WARE LICENSE" (Revision 42): 4 * <phk@FreeBSD.ORG> wrote this file. As long as you retain this notice you 5 * can do whatever you want with this stuff. If we meet some day, and you think 6 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp 7 * ---------------------------------------------------------------------------- 8 */ 9 10#include <sys/cdefs.h> | 1/*- 2 * ---------------------------------------------------------------------------- 3 * "THE BEER-WARE LICENSE" (Revision 42): 4 * <phk@FreeBSD.ORG> wrote this file. As long as you retain this notice you 5 * can do whatever you want with this stuff. If we meet some day, and you think 6 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp 7 * ---------------------------------------------------------------------------- 8 */ 9 10#include <sys/cdefs.h> |
11__FBSDID("$FreeBSD: head/sys/kern/kern_tc.c 209216 2010-06-15 19:28:44Z jkim $"); | 11__FBSDID("$FreeBSD: head/sys/kern/kern_tc.c 209390 2010-06-21 09:55:56Z ed $"); |
12 13#include "opt_ntp.h" 14 15#include <sys/param.h> 16#include <sys/kernel.h> 17#include <sys/sysctl.h> 18#include <sys/syslog.h> 19#include <sys/systm.h> --- 26 unchanged lines hidden (view full) --- 46static struct timecounter dummy_timecounter = { 47 dummy_get_timecount, 0, ~0u, 1000000, "dummy", -1000000 48}; 49 50struct timehands { 51 /* These fields must be initialized by the driver. */ 52 struct timecounter *th_counter; 53 int64_t th_adjustment; | 12 13#include "opt_ntp.h" 14 15#include <sys/param.h> 16#include <sys/kernel.h> 17#include <sys/sysctl.h> 18#include <sys/syslog.h> 19#include <sys/systm.h> --- 26 unchanged lines hidden (view full) --- 46static struct timecounter dummy_timecounter = { 47 dummy_get_timecount, 0, ~0u, 1000000, "dummy", -1000000 48}; 49 50struct timehands { 51 /* These fields must be initialized by the driver. */ 52 struct timecounter *th_counter; 53 int64_t th_adjustment; |
54 u_int64_t th_scale; | 54 uint64_t th_scale; |
55 u_int th_offset_count; 56 struct bintime th_offset; 57 struct timeval th_microtime; 58 struct timespec th_nanotime; 59 /* Fields not to be copied in tc_windup start with th_generation. */ 60 volatile u_int th_generation; 61 struct timehands *th_next; 62}; --- 66 unchanged lines hidden (view full) --- 129 130 ncount = tc->tc_get_timecount(tc); 131 return sysctl_handle_int(oidp, &ncount, 0, req); 132} 133 134static int 135sysctl_kern_timecounter_freq(SYSCTL_HANDLER_ARGS) 136{ | 55 u_int th_offset_count; 56 struct bintime th_offset; 57 struct timeval th_microtime; 58 struct timespec th_nanotime; 59 /* Fields not to be copied in tc_windup start with th_generation. */ 60 volatile u_int th_generation; 61 struct timehands *th_next; 62}; --- 66 unchanged lines hidden (view full) --- 129 130 ncount = tc->tc_get_timecount(tc); 131 return sysctl_handle_int(oidp, &ncount, 0, req); 132} 133 134static int 135sysctl_kern_timecounter_freq(SYSCTL_HANDLER_ARGS) 136{ |
137 u_int64_t freq; | 137 uint64_t freq; |
138 struct timecounter *tc = arg1; 139 140 freq = tc->tc_frequency; 141 return sysctl_handle_quad(oidp, &freq, 0, req); 142} 143 144/* 145 * Return the difference between the timehands' counter value now and what --- 211 unchanged lines hidden (view full) --- 357 tc->tc_frequency < timecounter->tc_frequency) 358 return; 359 (void)tc->tc_get_timecount(tc); 360 (void)tc->tc_get_timecount(tc); 361 timecounter = tc; 362} 363 364/* Report the frequency of the current timecounter. */ | 138 struct timecounter *tc = arg1; 139 140 freq = tc->tc_frequency; 141 return sysctl_handle_quad(oidp, &freq, 0, req); 142} 143 144/* 145 * Return the difference between the timehands' counter value now and what --- 211 unchanged lines hidden (view full) --- 357 tc->tc_frequency < timecounter->tc_frequency) 358 return; 359 (void)tc->tc_get_timecount(tc); 360 (void)tc->tc_get_timecount(tc); 361 timecounter = tc; 362} 363 364/* Report the frequency of the current timecounter. */ |
365u_int64_t | 365uint64_t |
366tc_getfrequency(void) 367{ 368 369 return (timehands->th_counter->tc_frequency); 370} 371 372/* 373 * Step our concept of UTC. This is done by modifying our estimate of --- 33 unchanged lines hidden (view full) --- 407 * it the active timehands. Along the way we might switch to a different 408 * timecounter and/or do seconds processing in NTP. Slightly magic. 409 */ 410static void 411tc_windup(void) 412{ 413 struct bintime bt; 414 struct timehands *th, *tho; | 366tc_getfrequency(void) 367{ 368 369 return (timehands->th_counter->tc_frequency); 370} 371 372/* 373 * Step our concept of UTC. This is done by modifying our estimate of --- 33 unchanged lines hidden (view full) --- 407 * it the active timehands. Along the way we might switch to a different 408 * timecounter and/or do seconds processing in NTP. Slightly magic. 409 */ 410static void 411tc_windup(void) 412{ 413 struct bintime bt; 414 struct timehands *th, *tho; |
415 u_int64_t scale; | 415 uint64_t scale; |
416 u_int delta, ncount, ogen; 417 int i; 418 time_t t; 419 420 /* 421 * Make the next timehands a copy of the current one, but do not 422 * overwrite the generation or next pointer. While we update 423 * the contents, the generation must be zero. --- 78 unchanged lines hidden (view full) --- 502 * Divide before multiply with a fraction of 2199/512 results in a 503 * systematic undercompensation of 10PPM of th_adjustment. On a 504 * 5000PPM adjustment this is a 0.05PPM error. This is acceptable. 505 * 506 * We happily sacrifice the lowest of the 64 bits of our result 507 * to the goddess of code clarity. 508 * 509 */ | 416 u_int delta, ncount, ogen; 417 int i; 418 time_t t; 419 420 /* 421 * Make the next timehands a copy of the current one, but do not 422 * overwrite the generation or next pointer. While we update 423 * the contents, the generation must be zero. --- 78 unchanged lines hidden (view full) --- 502 * Divide before multiply with a fraction of 2199/512 results in a 503 * systematic undercompensation of 10PPM of th_adjustment. On a 504 * 5000PPM adjustment this is a 0.05PPM error. This is acceptable. 505 * 506 * We happily sacrifice the lowest of the 64 bits of our result 507 * to the goddess of code clarity. 508 * 509 */ |
510 scale = (u_int64_t)1 << 63; | 510 scale = (uint64_t)1 << 63; |
511 scale += (th->th_adjustment / 1024) * 2199; 512 scale /= th->th_counter->tc_frequency; 513 th->th_scale = scale * 2; 514 515 /* 516 * Now that the struct timehands is again consistent, set the new 517 * generation number, making sure to not make it zero. 518 */ --- 210 unchanged lines hidden (view full) --- 729 timespecadd(tsp, osp); 730 if (tsp->tv_nsec < 0) { 731 tsp->tv_nsec += 1000000000; 732 tsp->tv_sec -= 1; 733 } 734 } 735#ifdef PPS_SYNC 736 if (fhard) { | 511 scale += (th->th_adjustment / 1024) * 2199; 512 scale /= th->th_counter->tc_frequency; 513 th->th_scale = scale * 2; 514 515 /* 516 * Now that the struct timehands is again consistent, set the new 517 * generation number, making sure to not make it zero. 518 */ --- 210 unchanged lines hidden (view full) --- 729 timespecadd(tsp, osp); 730 if (tsp->tv_nsec < 0) { 731 tsp->tv_nsec += 1000000000; 732 tsp->tv_sec -= 1; 733 } 734 } 735#ifdef PPS_SYNC 736 if (fhard) { |
737 u_int64_t scale; | 737 uint64_t scale; |
738 739 /* 740 * Feed the NTP PLL/FLL. 741 * The FLL wants to know how many (hardware) nanoseconds 742 * elapsed since the previous event. 743 */ 744 tcount = pps->capcount - pps->ppscount[2]; 745 pps->ppscount[2] = pps->capcount; 746 tcount &= pps->capth->th_counter->tc_counter_mask; | 738 739 /* 740 * Feed the NTP PLL/FLL. 741 * The FLL wants to know how many (hardware) nanoseconds 742 * elapsed since the previous event. 743 */ 744 tcount = pps->capcount - pps->ppscount[2]; 745 pps->ppscount[2] = pps->capcount; 746 tcount &= pps->capth->th_counter->tc_counter_mask; |
747 scale = (u_int64_t)1 << 63; | 747 scale = (uint64_t)1 << 63; |
748 scale /= pps->capth->th_counter->tc_frequency; 749 scale *= 2; 750 bt.sec = 0; 751 bt.frac = 0; 752 bintime_addx(&bt, scale * tcount); 753 bintime2timespec(&bt, &ts); 754 hardpps(tsp, ts.tv_nsec + 1000000000 * ts.tv_sec); 755 } --- 199 unchanged lines hidden --- | 748 scale /= pps->capth->th_counter->tc_frequency; 749 scale *= 2; 750 bt.sec = 0; 751 bt.frac = 0; 752 bintime_addx(&bt, scale * tcount); 753 bintime2timespec(&bt, &ts); 754 hardpps(tsp, ts.tv_nsec + 1000000000 * ts.tv_sec); 755 } --- 199 unchanged lines hidden --- |