xref: /freebsd/lib/libsys/ffclock.2 (revision 8269e767)
18269e767SBrooks Davis.\" Copyright (c) 2011 The University of Melbourne
28269e767SBrooks Davis.\" All rights reserved.
38269e767SBrooks Davis.\"
48269e767SBrooks Davis.\" This documentation was written by Julien Ridoux at the University of
58269e767SBrooks Davis.\" Melbourne under sponsorship from the FreeBSD Foundation.
68269e767SBrooks Davis.\"
78269e767SBrooks Davis.\" Redistribution and use in source and binary forms, with or without
88269e767SBrooks Davis.\" modification, are permitted provided that the following conditions
98269e767SBrooks Davis.\" are met:
108269e767SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright
118269e767SBrooks Davis.\"    notice, this list of conditions and the following disclaimer.
128269e767SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright
138269e767SBrooks Davis.\"    notice, this list of conditions and the following disclaimer in the
148269e767SBrooks Davis.\"    documentation and/or other materials provided with the distribution.
158269e767SBrooks Davis.\"
168269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
178269e767SBrooks Davis.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
188269e767SBrooks Davis.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
198269e767SBrooks Davis.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
208269e767SBrooks Davis.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
218269e767SBrooks Davis.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
228269e767SBrooks Davis.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
238269e767SBrooks Davis.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
248269e767SBrooks Davis.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
258269e767SBrooks Davis.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
268269e767SBrooks Davis.\" SUCH DAMAGE.
278269e767SBrooks Davis.\"
288269e767SBrooks Davis.Dd November 21, 2011
298269e767SBrooks Davis.Dt FFCLOCK 2
308269e767SBrooks Davis.Os
318269e767SBrooks Davis.Sh NAME
328269e767SBrooks Davis.Nm ffclock_getcounter ,
338269e767SBrooks Davis.Nm ffclock_getestimate ,
348269e767SBrooks Davis.Nm ffclock_setestimate
358269e767SBrooks Davis.Nd Retrieve feed-forward counter, get and set feed-forward clock estimates
368269e767SBrooks Davis.Sh LIBRARY
378269e767SBrooks Davis.Lb libc
388269e767SBrooks Davis.Sh SYNOPSIS
398269e767SBrooks Davis.In sys/timeffc.h
408269e767SBrooks Davis.Ft int
418269e767SBrooks Davis.Fn ffclock_getcounter "ffcounter *ffcount"
428269e767SBrooks Davis.Ft int
438269e767SBrooks Davis.Fn ffclock_getestimate "struct ffclock_estimate *cest"
448269e767SBrooks Davis.Ft int
458269e767SBrooks Davis.Fn ffclock_setestimate "struct ffclock_estimate *cest"
468269e767SBrooks Davis.Sh DESCRIPTION
478269e767SBrooks DavisThe ffclock is an alternative method to synchronise the system clock.
488269e767SBrooks DavisThe ffclock implements a feed-forward paradigm and decouples the timestamping
498269e767SBrooks Davisand timekeeping kernel functions.
508269e767SBrooks DavisThis ensures that past clock errors do not affect current timekeeping, an
518269e767SBrooks Davisapproach radically different from the feedback alternative implemented by the
528269e767SBrooks Davisntpd daemon when adjusting the system clock.
538269e767SBrooks DavisThe feed-forward approach has demonstrated better performance and higher
548269e767SBrooks Davisrobustness than a feedback approach when synchronising over the network.
558269e767SBrooks Davis.Pp
568269e767SBrooks DavisIn the feed-forward context, a
578269e767SBrooks Davis.Em timestamp
588269e767SBrooks Davisis a cumulative value of the ticks of the timecounter, which can be converted
598269e767SBrooks Davisinto seconds by using the feed-forward
608269e767SBrooks Davis.Em clock estimates .
618269e767SBrooks Davis.Pp
628269e767SBrooks DavisThe
638269e767SBrooks Davis.Fn ffclock_getcounter
648269e767SBrooks Davissystem call allows the calling process to retrieve the current value of the
658269e767SBrooks Davisfeed-forward counter maintained by the kernel.
668269e767SBrooks Davis.Pp
678269e767SBrooks DavisThe
688269e767SBrooks Davis.Fn ffclock_getestimate
698269e767SBrooks Davisand
708269e767SBrooks Davis.Fn ffclock_setestimate
718269e767SBrooks Davissystem calls allow the caller to get and set the kernel's feed-forward clock
728269e767SBrooks Davisparameter estimates respectively.
738269e767SBrooks DavisThe
748269e767SBrooks Davis.Fn ffclock_setestimate
758269e767SBrooks Davissystem call should be invoked by a single instance of a feed-forward
768269e767SBrooks Davissynchronisation daemon.
778269e767SBrooks DavisThe
788269e767SBrooks Davis.Fn ffclock_getestimate
798269e767SBrooks Davissystem call can be called by any process to retrieve the feed-forward clock
808269e767SBrooks Davisestimates.
818269e767SBrooks Davis.Pp
828269e767SBrooks DavisThe feed-forward approach does not require that the clock estimates be retrieved
838269e767SBrooks Davisevery time a timestamp is to be converted into seconds.
848269e767SBrooks DavisThe number of system calls can therefore be greatly reduced if the calling
858269e767SBrooks Davisprocess retrieves the clock estimates from the clock synchronisation daemon
868269e767SBrooks Davisinstead.
878269e767SBrooks DavisThe
888269e767SBrooks Davis.Fn ffclock_getestimate
898269e767SBrooks Davismust be used when the feed-forward synchronisation daemon is not running
908269e767SBrooks Davis.Po see
918269e767SBrooks Davis.Sx USAGE
928269e767SBrooks Davisbelow
938269e767SBrooks Davis.Pc .
948269e767SBrooks Davis.Pp
958269e767SBrooks DavisThe clock parameter estimates structure pointed to by
968269e767SBrooks Davis.Fa cest
978269e767SBrooks Davisis defined in
988269e767SBrooks Davis.In sys/timeffc.h
998269e767SBrooks Davisas:
1008269e767SBrooks Davis.Bd -literal
1018269e767SBrooks Davisstruct ffclock_estimate {
1028269e767SBrooks Davis	struct bintime update_time;    /* Time of last estimates update. */
1038269e767SBrooks Davis	ffcounter      update_ffcount; /* Counter value at last update. */
1048269e767SBrooks Davis	ffcounter      leapsec_next;   /* Counter value of next leap second. */
1058269e767SBrooks Davis	uint64_t       period;         /* Estimate of counter period. */
1068269e767SBrooks Davis	uint32_t       errb_abs;       /* Bound on absolute clock error [ns]. */
1078269e767SBrooks Davis	uint32_t       errb_rate;      /* Bound on counter rate error [ps/s]. */
1088269e767SBrooks Davis	uint32_t       status;         /* Clock status. */
1098269e767SBrooks Davis	int16_t        leapsec_total;  /* All leap seconds seen so far. */
1108269e767SBrooks Davis	int8_t         leapsec;        /* Next leap second (in {-1,0,1}). */
1118269e767SBrooks Davis};
1128269e767SBrooks Davis.Ed
1138269e767SBrooks Davis.Pp
1148269e767SBrooks DavisOnly the super-user may set the feed-forward clock estimates.
1158269e767SBrooks Davis.Sh RETURN VALUES
1168269e767SBrooks Davis.Rv -std
1178269e767SBrooks Davis.Sh ERRORS
1188269e767SBrooks DavisThe following error codes may be set in
1198269e767SBrooks Davis.Va errno :
1208269e767SBrooks Davis.Bl -tag -width Er
1218269e767SBrooks Davis.It Bq Er EFAULT
1228269e767SBrooks DavisThe
1238269e767SBrooks Davis.Fa ffcount
1248269e767SBrooks Davisor
1258269e767SBrooks Davis.Fa cest
1268269e767SBrooks Davispointer referenced invalid memory.
1278269e767SBrooks Davis.It Bq Er EPERM
1288269e767SBrooks DavisA user other than the super-user attempted to set the feed-forward clock
1298269e767SBrooks Davisparameter estimates.
1308269e767SBrooks Davis.El
1318269e767SBrooks Davis.Sh USAGE
1328269e767SBrooks DavisThe feed-forward paradigm enables the definition of specialised clock functions.
1338269e767SBrooks Davis.Pp
1348269e767SBrooks DavisIn its simplest form,
1358269e767SBrooks Davis.Fn ffclock_getcounter
1368269e767SBrooks Daviscan be used to establish strict order between events or to measure small time
1378269e767SBrooks Davisintervals very accurately with a minimum performance cost.
1388269e767SBrooks Davis.Pp
1398269e767SBrooks DavisDifferent methods exist to access absolute time
1408269e767SBrooks Davis.Po or
1418269e767SBrooks Davis.Qq wall-clock time
1428269e767SBrooks Davis.Pc tracked by the ffclock.
1438269e767SBrooks DavisThe simplest method uses the ffclock sysctl interface
1448269e767SBrooks Davis.Va kern.ffclock
1458269e767SBrooks Davisto make the system clock return the ffclock time.
1468269e767SBrooks DavisThe
1478269e767SBrooks Davis.Xr clock_gettime 2
1488269e767SBrooks Davissystem call can then be used to retrieve the current time seen by the
1498269e767SBrooks Davisfeed-forward clock.
1508269e767SBrooks DavisNote that this setting affects the entire system and that a feed-forward
1518269e767SBrooks Davissynchronisation daemon should be running.
1528269e767SBrooks Davis.Pp
1538269e767SBrooks DavisA less automated method consists of retrieving the feed-forward counter
1548269e767SBrooks Davistimestamp from the kernel and using the feed-forward clock parameter estimates
1558269e767SBrooks Davisto convert the timestamp into seconds.
1568269e767SBrooks DavisThe feed-forward clock parameter estimates can be retrieved from the kernel or
1578269e767SBrooks Davisfrom the synchronisation daemon directly (preferred).
1588269e767SBrooks DavisThis method allows converting timestamps using different clock models as needed
1598269e767SBrooks Davisby the application, while collecting meaningful upper bounds on current clock
1608269e767SBrooks Daviserror.
1618269e767SBrooks Davis.Sh SEE ALSO
1628269e767SBrooks Davis.Xr date 1 ,
1638269e767SBrooks Davis.Xr adjtime 2 ,
1648269e767SBrooks Davis.Xr clock_gettime 2 ,
1658269e767SBrooks Davis.Xr ctime 3
1668269e767SBrooks Davis.Sh HISTORY
1678269e767SBrooks DavisFeed-forward clock support first appeared in
1688269e767SBrooks Davis.Fx 10.0 .
1698269e767SBrooks Davis.Sh AUTHORS
1708269e767SBrooks Davis.An -nosplit
1718269e767SBrooks DavisThe feed-forward clock support was written by
1728269e767SBrooks Davis.An Julien Ridoux Aq Mt jridoux@unimelb.edu.au
1738269e767SBrooks Davisin collaboration with
1748269e767SBrooks Davis.An Darryl Veitch Aq Mt dveitch@unimelb.edu.au
1758269e767SBrooks Davisat the University of Melbourne under sponsorship from the FreeBSD Foundation.
176