1*8269e767SBrooks Davis.\" Copyright (c) 2011 The University of Melbourne 2*8269e767SBrooks Davis.\" All rights reserved. 3*8269e767SBrooks Davis.\" 4*8269e767SBrooks Davis.\" This documentation was written by Julien Ridoux at the University of 5*8269e767SBrooks Davis.\" Melbourne under sponsorship from the FreeBSD Foundation. 6*8269e767SBrooks Davis.\" 7*8269e767SBrooks Davis.\" Redistribution and use in source and binary forms, with or without 8*8269e767SBrooks Davis.\" modification, are permitted provided that the following conditions 9*8269e767SBrooks Davis.\" are met: 10*8269e767SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright 11*8269e767SBrooks Davis.\" notice, this list of conditions and the following disclaimer. 12*8269e767SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright 13*8269e767SBrooks Davis.\" notice, this list of conditions and the following disclaimer in the 14*8269e767SBrooks Davis.\" documentation and/or other materials provided with the distribution. 15*8269e767SBrooks Davis.\" 16*8269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17*8269e767SBrooks Davis.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18*8269e767SBrooks Davis.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19*8269e767SBrooks Davis.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20*8269e767SBrooks Davis.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21*8269e767SBrooks Davis.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22*8269e767SBrooks Davis.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23*8269e767SBrooks Davis.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24*8269e767SBrooks Davis.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25*8269e767SBrooks Davis.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26*8269e767SBrooks Davis.\" SUCH DAMAGE. 27*8269e767SBrooks Davis.\" 28*8269e767SBrooks Davis.Dd November 21, 2011 29*8269e767SBrooks Davis.Dt FFCLOCK 2 30*8269e767SBrooks Davis.Os 31*8269e767SBrooks Davis.Sh NAME 32*8269e767SBrooks Davis.Nm ffclock_getcounter , 33*8269e767SBrooks Davis.Nm ffclock_getestimate , 34*8269e767SBrooks Davis.Nm ffclock_setestimate 35*8269e767SBrooks Davis.Nd Retrieve feed-forward counter, get and set feed-forward clock estimates 36*8269e767SBrooks Davis.Sh LIBRARY 37*8269e767SBrooks Davis.Lb libc 38*8269e767SBrooks Davis.Sh SYNOPSIS 39*8269e767SBrooks Davis.In sys/timeffc.h 40*8269e767SBrooks Davis.Ft int 41*8269e767SBrooks Davis.Fn ffclock_getcounter "ffcounter *ffcount" 42*8269e767SBrooks Davis.Ft int 43*8269e767SBrooks Davis.Fn ffclock_getestimate "struct ffclock_estimate *cest" 44*8269e767SBrooks Davis.Ft int 45*8269e767SBrooks Davis.Fn ffclock_setestimate "struct ffclock_estimate *cest" 46*8269e767SBrooks Davis.Sh DESCRIPTION 47*8269e767SBrooks DavisThe ffclock is an alternative method to synchronise the system clock. 48*8269e767SBrooks DavisThe ffclock implements a feed-forward paradigm and decouples the timestamping 49*8269e767SBrooks Davisand timekeeping kernel functions. 50*8269e767SBrooks DavisThis ensures that past clock errors do not affect current timekeeping, an 51*8269e767SBrooks Davisapproach radically different from the feedback alternative implemented by the 52*8269e767SBrooks Davisntpd daemon when adjusting the system clock. 53*8269e767SBrooks DavisThe feed-forward approach has demonstrated better performance and higher 54*8269e767SBrooks Davisrobustness than a feedback approach when synchronising over the network. 55*8269e767SBrooks Davis.Pp 56*8269e767SBrooks DavisIn the feed-forward context, a 57*8269e767SBrooks Davis.Em timestamp 58*8269e767SBrooks Davisis a cumulative value of the ticks of the timecounter, which can be converted 59*8269e767SBrooks Davisinto seconds by using the feed-forward 60*8269e767SBrooks Davis.Em clock estimates . 61*8269e767SBrooks Davis.Pp 62*8269e767SBrooks DavisThe 63*8269e767SBrooks Davis.Fn ffclock_getcounter 64*8269e767SBrooks Davissystem call allows the calling process to retrieve the current value of the 65*8269e767SBrooks Davisfeed-forward counter maintained by the kernel. 66*8269e767SBrooks Davis.Pp 67*8269e767SBrooks DavisThe 68*8269e767SBrooks Davis.Fn ffclock_getestimate 69*8269e767SBrooks Davisand 70*8269e767SBrooks Davis.Fn ffclock_setestimate 71*8269e767SBrooks Davissystem calls allow the caller to get and set the kernel's feed-forward clock 72*8269e767SBrooks Davisparameter estimates respectively. 73*8269e767SBrooks DavisThe 74*8269e767SBrooks Davis.Fn ffclock_setestimate 75*8269e767SBrooks Davissystem call should be invoked by a single instance of a feed-forward 76*8269e767SBrooks Davissynchronisation daemon. 77*8269e767SBrooks DavisThe 78*8269e767SBrooks Davis.Fn ffclock_getestimate 79*8269e767SBrooks Davissystem call can be called by any process to retrieve the feed-forward clock 80*8269e767SBrooks Davisestimates. 81*8269e767SBrooks Davis.Pp 82*8269e767SBrooks DavisThe feed-forward approach does not require that the clock estimates be retrieved 83*8269e767SBrooks Davisevery time a timestamp is to be converted into seconds. 84*8269e767SBrooks DavisThe number of system calls can therefore be greatly reduced if the calling 85*8269e767SBrooks Davisprocess retrieves the clock estimates from the clock synchronisation daemon 86*8269e767SBrooks Davisinstead. 87*8269e767SBrooks DavisThe 88*8269e767SBrooks Davis.Fn ffclock_getestimate 89*8269e767SBrooks Davismust be used when the feed-forward synchronisation daemon is not running 90*8269e767SBrooks Davis.Po see 91*8269e767SBrooks Davis.Sx USAGE 92*8269e767SBrooks Davisbelow 93*8269e767SBrooks Davis.Pc . 94*8269e767SBrooks Davis.Pp 95*8269e767SBrooks DavisThe clock parameter estimates structure pointed to by 96*8269e767SBrooks Davis.Fa cest 97*8269e767SBrooks Davisis defined in 98*8269e767SBrooks Davis.In sys/timeffc.h 99*8269e767SBrooks Davisas: 100*8269e767SBrooks Davis.Bd -literal 101*8269e767SBrooks Davisstruct ffclock_estimate { 102*8269e767SBrooks Davis struct bintime update_time; /* Time of last estimates update. */ 103*8269e767SBrooks Davis ffcounter update_ffcount; /* Counter value at last update. */ 104*8269e767SBrooks Davis ffcounter leapsec_next; /* Counter value of next leap second. */ 105*8269e767SBrooks Davis uint64_t period; /* Estimate of counter period. */ 106*8269e767SBrooks Davis uint32_t errb_abs; /* Bound on absolute clock error [ns]. */ 107*8269e767SBrooks Davis uint32_t errb_rate; /* Bound on counter rate error [ps/s]. */ 108*8269e767SBrooks Davis uint32_t status; /* Clock status. */ 109*8269e767SBrooks Davis int16_t leapsec_total; /* All leap seconds seen so far. */ 110*8269e767SBrooks Davis int8_t leapsec; /* Next leap second (in {-1,0,1}). */ 111*8269e767SBrooks Davis}; 112*8269e767SBrooks Davis.Ed 113*8269e767SBrooks Davis.Pp 114*8269e767SBrooks DavisOnly the super-user may set the feed-forward clock estimates. 115*8269e767SBrooks Davis.Sh RETURN VALUES 116*8269e767SBrooks Davis.Rv -std 117*8269e767SBrooks Davis.Sh ERRORS 118*8269e767SBrooks DavisThe following error codes may be set in 119*8269e767SBrooks Davis.Va errno : 120*8269e767SBrooks Davis.Bl -tag -width Er 121*8269e767SBrooks Davis.It Bq Er EFAULT 122*8269e767SBrooks DavisThe 123*8269e767SBrooks Davis.Fa ffcount 124*8269e767SBrooks Davisor 125*8269e767SBrooks Davis.Fa cest 126*8269e767SBrooks Davispointer referenced invalid memory. 127*8269e767SBrooks Davis.It Bq Er EPERM 128*8269e767SBrooks DavisA user other than the super-user attempted to set the feed-forward clock 129*8269e767SBrooks Davisparameter estimates. 130*8269e767SBrooks Davis.El 131*8269e767SBrooks Davis.Sh USAGE 132*8269e767SBrooks DavisThe feed-forward paradigm enables the definition of specialised clock functions. 133*8269e767SBrooks Davis.Pp 134*8269e767SBrooks DavisIn its simplest form, 135*8269e767SBrooks Davis.Fn ffclock_getcounter 136*8269e767SBrooks Daviscan be used to establish strict order between events or to measure small time 137*8269e767SBrooks Davisintervals very accurately with a minimum performance cost. 138*8269e767SBrooks Davis.Pp 139*8269e767SBrooks DavisDifferent methods exist to access absolute time 140*8269e767SBrooks Davis.Po or 141*8269e767SBrooks Davis.Qq wall-clock time 142*8269e767SBrooks Davis.Pc tracked by the ffclock. 143*8269e767SBrooks DavisThe simplest method uses the ffclock sysctl interface 144*8269e767SBrooks Davis.Va kern.ffclock 145*8269e767SBrooks Davisto make the system clock return the ffclock time. 146*8269e767SBrooks DavisThe 147*8269e767SBrooks Davis.Xr clock_gettime 2 148*8269e767SBrooks Davissystem call can then be used to retrieve the current time seen by the 149*8269e767SBrooks Davisfeed-forward clock. 150*8269e767SBrooks DavisNote that this setting affects the entire system and that a feed-forward 151*8269e767SBrooks Davissynchronisation daemon should be running. 152*8269e767SBrooks Davis.Pp 153*8269e767SBrooks DavisA less automated method consists of retrieving the feed-forward counter 154*8269e767SBrooks Davistimestamp from the kernel and using the feed-forward clock parameter estimates 155*8269e767SBrooks Davisto convert the timestamp into seconds. 156*8269e767SBrooks DavisThe feed-forward clock parameter estimates can be retrieved from the kernel or 157*8269e767SBrooks Davisfrom the synchronisation daemon directly (preferred). 158*8269e767SBrooks DavisThis method allows converting timestamps using different clock models as needed 159*8269e767SBrooks Davisby the application, while collecting meaningful upper bounds on current clock 160*8269e767SBrooks Daviserror. 161*8269e767SBrooks Davis.Sh SEE ALSO 162*8269e767SBrooks Davis.Xr date 1 , 163*8269e767SBrooks Davis.Xr adjtime 2 , 164*8269e767SBrooks Davis.Xr clock_gettime 2 , 165*8269e767SBrooks Davis.Xr ctime 3 166*8269e767SBrooks Davis.Sh HISTORY 167*8269e767SBrooks DavisFeed-forward clock support first appeared in 168*8269e767SBrooks Davis.Fx 10.0 . 169*8269e767SBrooks Davis.Sh AUTHORS 170*8269e767SBrooks Davis.An -nosplit 171*8269e767SBrooks DavisThe feed-forward clock support was written by 172*8269e767SBrooks Davis.An Julien Ridoux Aq Mt jridoux@unimelb.edu.au 173*8269e767SBrooks Davisin collaboration with 174*8269e767SBrooks Davis.An Darryl Veitch Aq Mt dveitch@unimelb.edu.au 175*8269e767SBrooks Davisat the University of Melbourne under sponsorship from the FreeBSD Foundation. 176