FreeBSD/sys/kern/kern_tc.c
/*
 * Take a snapshot of sysclock data which can be used to compare system clocks
 * and generate timestamps after the fact.
 */
Take a snapshot of sysclock data which can be used to compare system clocks
and generate timestamps after the fact.
Take a snapshot of sysclock data which can be used to compare system clocks and generate timestamps after the fact .
void
sysclock_getsnapshot(struct sysclock_snap *clock_snap, int fast)
{
	struct fbclock_info *fbi;
	struct timehands *th;
	struct bintime bt;
	unsigned int delta, gen;
#ifdef FFCLOCK
	ffcounter ffcount;
	struct fftimehands *ffth;
	struct ffclock_info *ffi;
	struct ffclock_estimate cest;
	ffi = &clock_snap->ff_info;
#endif
	fbi = &clock_snap->fb_info;
	delta = 0;
	do {
		th = timehands;
		gen = atomic_load_acq_int(&th->th_generation);
		fbi->th_scale = th->th_scale;
		fbi->tick_time = th->th_offset;
#ifdef FFCLOCK
		ffth = fftimehands;
		ffi->tick_time = ffth->tick_time_lerp;
		ffi->tick_time_lerp = ffth->tick_time_lerp;
		ffi->period = ffth->cest.period;
		ffi->period_lerp = ffth->period_lerp;
		clock_snap->ffcount = ffth->tick_ffcount;
		cest = ffth->cest;
#endif
		if (!fast)
			delta = tc_delta(th);
		atomic_thread_fence_acq();
	} while (gen == 0 || gen != th->th_generation);
	clock_snap->delta = delta;
	clock_snap->sysclock_active = sysclock_active;
	clock_snap->fb_info.status = time_status;
	bt.sec = time_esterror / 1000000;
	bt.frac = ((time_esterror - bt.sec) * 1000000) *
	    (uint64_t)18446744073709ULL;
	clock_snap->fb_info.error = bt;
#ifdef FFCLOCK
	if (!fast)
		clock_snap->ffcount += delta;
	ffi->leapsec_adjustment = cest.leapsec_total;
	if (clock_snap->ffcount > cest.leapsec_next)
		ffi->leapsec_adjustment -= cest.leapsec;
	clock_snap->ff_info.status = cest.status;
	ffcount = clock_snap->ffcount - cest.update_ffcount;
	ffclock_convert_delta(ffcount, cest.period, &bt);
	bintime_mul(&bt, cest.errb_rate * (uint64_t)18446744073709ULL);
	bintime_addx(&bt, cest.errb_abs * (uint64_t)18446744073ULL);
	clock_snap->ff_info.error = bt;
#endif
}
void sysclock_getsnapshot ( struct sysclock_snap * clock_snap , int fast ) { struct fbclock_info * fbi ; struct timehands * th ; struct bintime bt ; unsigned int delta , gen ; #ifdef FFCLOCK ffcounter ffcount ; struct fftimehands * ffth ; struct ffclock_info * ffi ; struct ffclock_estimate cest ; ffi = & clock_snap -> ff_info ; #endif fbi = & clock_snap -> fb_info ; delta = 0 ; do { th = timehands ; gen = atomic_load_acq_int ( & th -> th_generation ) ; fbi -> th_scale = th -> th_scale ; fbi -> tick_time = th -> th_offset ; #ifdef FFCLOCK ffth = fftimehands ; ffi -> tick_time = ffth -> tick_time_lerp ; ffi -> tick_time_lerp = ffth -> tick_time_lerp ; ffi -> period = ffth -> cest . period ; ffi -> period_lerp = ffth -> period_lerp ; clock_snap -> ffcount = ffth -> tick_ffcount ; cest = ffth -> cest ; #endif if ( ! fast ) delta = tc_delta ( th ) ; atomic_thread_fence_acq ( ) ; } while ( gen == 0 || gen != th -> th_generation ) ; clock_snap -> delta = delta ; clock_snap -> sysclock_active = sysclock_active ; clock_snap -> fb_info . status = time_status ; bt . sec = time_esterror / 1000000 ; bt . frac = ( ( time_esterror - bt . sec ) * 1000000 ) * ( uint64_t ) 18446744073709ULL ; clock_snap -> fb_info . error = bt ; #ifdef FFCLOCK if ( ! fast ) clock_snap -> ffcount += delta ; ffi -> leapsec_adjustment = cest . leapsec_total ; if ( clock_snap -> ffcount > cest . leapsec_next ) ffi -> leapsec_adjustment -= cest . leapsec ; clock_snap -> ff_info . status = cest . status ; ffcount = clock_snap -> ffcount - cest . update_ffcount ; ffclock_convert_delta ( ffcount , cest . period , & bt ) ; bintime_mul ( & bt , cest . errb_rate * ( uint64_t ) 18446744073709ULL ) ; bintime_addx ( & bt , cest . errb_abs * ( uint64_t ) 18446744073ULL ) ; clock_snap -> ff_info . error = bt ; #endif }
Take a snapshot of sysclock data which can be used to compare system clocks
 and generate timestamps after the fact.
Take a snapshot of sysclock data which can be used to compare system clocks and generate timestamps after the fact .
/* Record feedback clock status and error. */ /* XXX: Very crude estimate of feedback clock error. */ /* Record feed-forward clock leap second adjustment. */ /* Record feed-forward clock status and error. */ /* 18446744073709 = int(2^64/1e12), err_bound_rate in [ps/s]. */ /* 18446744073 = int(2^64 / 1e9), since err_abs in [ns]. */