History log of /freebsd-current/sys/sys/time.h
Revision Date Author Comments
# 29363fb4 23-Nov-2023 Warner Losh <imp@FreeBSD.org>

sys: Remove ancient SCCS tags.

Remove ancient SCCS tags from the tree, automated scripting, with two
minor fixup to keep things compiling. All the common forms in the tree
were removed with a perl script.

Sponsored by: Netflix


# 2ff63af9 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

sys: Remove $FreeBSD$: one-line .h pattern

Remove /^\s*\*+\s*\$FreeBSD\$.*$\n/


# 83158c68 22-Feb-2023 Mateusz Guzik <mjg@FreeBSD.org>

time: s/ppsratecheck/eventratecheck

The routine is used as a general event-limiting routine in places which
have nothing to do with packets.

Provide a define to keep everything happy.

Reviewed by: rew
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D38746


# 35a33d14 20-Oct-2022 Hans Petter Selasky <hselasky@FreeBSD.org>

time(3): Optimize tvtohz() function.

List of changes:
- Use integer multiplication instead of long multiplication, because the result is an integer.
- Remove multiple if-statements and predict new if-statements.
- Rename local variable name, "ticks" into "retval" to avoid shadowing
the system "ticks" global variable.

Reviewed by: kib@ and imp@
MFC after: 1 week
Sponsored by: NVIDIA Networking
Differential Revision: https://reviews.freebsd.org/D36859


# ee29897f 03-Oct-2022 Hans Petter Selasky <hselasky@FreeBSD.org>

time(3): Declare the minimum and maximum hz values supported.

Reviewed by: kib@ and imp@
MFC after: 1 week
Sponsored by: NVIDIA Networking
Differential Revision: https://reviews.freebsd.org/D37072


# d97ecf71 02-Oct-2022 Hans Petter Selasky <hselasky@FreeBSD.org>

time(3): Increase precision of time conversion functions by using gcd.

When converting times to and from units which have many leading zeros,
it pays off to compute the greatest common divisor first, and then do the
scaling product. This way all time unit conversion comes down to scaling a
signed or unsigned 64-bit value by a fraction represented by two signed
or unsigned 32-bit integers.

SBT_1S is defined as 2^32 . When scaling using powers of 10 above 1,
the gcd of SBT_1S and 10^N is always greater than or equal to 4,
when N is greater or equal to 2.

Scaling a sbt value to milliseconds is then done by multiplying by
(1000 / 8) and dividing by (2^32 / 8).

This trick allows for higher precision at very little additional CPU cost.

It shall also be noted that the Xtosbt() functions prior to this patch,
sometimes were off-by-one:

For example when converting 1 / 8 of a second to sbt as 125ms the old sbt
conversion function would compute 0x20000001 while the new function computes
0x20000000 which multiplied by 8 becomes SBT_1S, which is the correct value.

Reviewed by: kib@
Differential Revision: https://reviews.freebsd.org/D36857
MFC after: 1 week
Sponsored by: NVIDIA Networking


# 10f44229 06-Apr-2022 Alan Somers <asomers@FreeBSD.org>

Fix overflow errors in sbttous and sbttoms

Both of these functions would overflow for very large inputs. Add tests
for them. Also, add tests for the inverse functions, *stosbt, whose
overflow errors were fixed by 4c30b9ecd47.

PR: 263073
MFC after: 1 week
Sponsored by: Axcient
Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D34809


# 91e7bdcd 25-Apr-2022 Dmitry Chagin <dchagin@FreeBSD.org>

Add timespecvalid_interval macro and use it.

Reviewed by: jhb, imp (early rev)
Differential revision: https://reviews.freebsd.org/D34848
MFC after: 2 weeks


# 4c30b9ec 05-Apr-2022 Warner Losh <imp@FreeBSD.org>

fix integer overflow bugs in *stosbt

68f57679d660 Fixed another class of integer overflows, but introduced a
boundary condition for 2-4s in ns conversion, 2-~4000s in us conversions
and 2-~4,000,000s in ms conversions. This was because we bogusly used
SBT_1S for the notion of 1 second, instead of the appropriate power of
10. To fix, just use the appropriate power of 10, which avoids these
overflows.

This caused some sleeps in ZFS to be on the order of an hour.

MFC: 1 day
PR: 263073
Sponsored by: Netflix
Reviewed by: asomers
Differential Revision: https://reviews.freebsd.org/D34790


# 7b797ba2 30-Jul-2021 Warner Losh <imp@FreeBSD.org>

time.h: reduce CLOCK_ namespace pollution, move to _clock_id.h

Attempt to comply with the strict namespace pollution requirements of
_POSIX_C_SOURCE. Add guards to limit visitbility of CLOCK_ and TIMER_
defines as appropriate. Only define the CLOCK_ variables relevant to the
specific standards. Move all the sharing to sys/_clock_id.h and make
time.h and sys/time.h both include that rather than copy due to the
now large number of clocks and compat defines.

Please note: The old time.h previously used these newer dates:
CLOCK_REALTIME 199506
CLOCK_MONOTONIC 200112
CLOCK_THREAD_CPUTIME_ID 200112
CLOCK_PROCESS_CPUTIME_ID 200112

but glibc defines all of these for 199309. glibc uses this date for all
these values, however, only CLOCK_REALTIME was in IEEE 1003.1b. Add a
comment about this to document it. A large number of programs and
libraries assume that these will be defined for _POSIX_C_SOURCE =
199309.

In addition, leak CLOCK_UPTIME_FAST for the pocl package until it can be
updated to use a simple CLOCK_MONOTONIC.

Reviewed by: kib
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D31056


# b45daaea 09-Jun-2021 Randall Stewart <rrs@FreeBSD.org>

tcp: LRO timestamps have lost their previous precision

Recently we had a rewrite to tcp_lro.c that was tested but one subtle change
was the move to a less precise timestamp. This causes all kinds of chaos
in tcp's that do pacing and needs to be fixed to use the more precise
time that was there before.

Reviewed by: mtuexen, gallatin, hselasky
Sponsored by: Netflix Inc
Differential Revision: https://reviews.freebsd.org/D30695


# 62693fe8 28-Aug-2020 Warner Losh <imp@FreeBSD.org>

Treat the boot loader as the same as the kernel for what's visible

The boot loader will be growing some (limited) support for some kernel
interfaces for some of the timekeeping routines to support zstd code.
Allow the declarations for them to be visible when compiling for the
boot loader, rather than treating it like a user-space environment
(which stand.h already provides to a limited degree).


# aeafed21 14-Jul-2020 Konstantin Belousov <kib@FreeBSD.org>

Make CLOCK_REALTIME and TIMER_ABSTIME available for XOPEN_SOURCE >= 500.

Reported by: jbeich
PR: 247701
Reviewed by: jilles
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D25554


# 67580964 12-Apr-2019 Warner Losh <imp@FreeBSD.org>

Fix sbttons for values > 2s

Add test against negative times. Add code to cope with larger values
properly.

Discussed with: bde@ (quite some time ago, for an earlier version)


# 68f57679 20-Nov-2018 Warner Losh <imp@FreeBSD.org>

Ensure that all values of ns, us and ms work for {n,u,m}stosbt

Integer overflows and wrong constants limited the accuracy of these
functions and created situatiosn where sbttoXs(Xstosbt(Y)) != Y. This
was especailly true in the ns case where we had millions of values
that were wrong.

Instead, used fixed constants because there's no way to say ceil(X)
for integer math. Document what these crazy constants are.

Also, use a shift one fewer left to avoid integer overflow causing
incorrect results, and adjust the equasion accordingly. Document this.

Allow times >= 1s to be well defined for these conversion functions
(at least the Xstosbt). There's too many users in the tree that they
work for >= 1s.

This fixes a failure on boot to program firmware on the mlx4
NIC. There was a msleep(1000) in the code. Prior to my recent rounding
changes, msleep(1000) worked, but msleep(1001) did not because the old
code rounded to just below 2^64 and the new code rounds to just above
it (overflowing, causing the msleep(1000) to really sleep 1ms).

A test program to test all cases will be committed shortly. The test
exaustively tries every value (thanks to bde for the test).

Sponsored by: Netflix, Inc
Differential Revision: https://reviews.freebsd.org/D18051


# 023b87bf 15-Nov-2018 Warner Losh <imp@FreeBSD.org>

When converting ns,us,ms to sbt, return the ceil() of the result
rather than the floor(). Returning the floor means that
sbttoX(Xtosbt(y)) != y for almost all values of y. In practice, this
results in a difference of at most 1 in the lsb of the sbintime_t.
This difference is meaningless for all current users of these
functions, but is important for the newly introduced sysctl conversion
routines which implicitly rely on the transformation being idempotent.

Sponsored by: Netflix, Inc


# 6040822c 30-Jul-2018 Alan Somers <asomers@FreeBSD.org>

Make timespecadd(3) and friends public

The timespecadd(3) family of macros were imported from NetBSD back in
r35029. However, they were initially guarded by #ifdef _KERNEL. In the
meantime, we have grown at least 28 syscalls that use timespecs in some
way, leading many programs both inside and outside of the base system to
redefine those macros. It's better just to make the definitions public.

Our kernel currently defines two-argument versions of timespecadd and
timespecsub. NetBSD, OpenBSD, and FreeDesktop.org's libbsd, however, define
three-argument versions. Solaris also defines a three-argument version, but
only in its kernel. This revision changes our definition to match the
common three-argument version.

Bump _FreeBSD_version due to the breaking KPI change.

Discussed with: cem, jilles, ian, bde
Differential Revision: https://reviews.freebsd.org/D14725


# 89e560f4 07-Jun-2018 Randall Stewart <rrs@FreeBSD.org>

This commit brings in a new refactored TCP stack called Rack.
Rack includes the following features:
- A different SACK processing scheme (the old sack structures are not used).
- RACK (Recent acknowledgment) where counting dup-acks is no longer done
instead time is used to knwo when to retransmit. (see the I-D)
- TLP (Tail Loss Probe) where we will probe for tail-losses to attempt
to try not to take a retransmit time-out. (see the I-D)
- Burst mitigation using TCPHTPS
- PRR (partial rate reduction) see the RFC.

Once built into your kernel, you can select this stack by either
socket option with the name of the stack is "rack" or by setting
the global sysctl so the default is rack.

Note that any connection that does not support SACK will be kicked
back to the "default" base FreeBSD stack (currently known as "default").

To build this into your kernel you will need to enable in your
kernel:
makeoptions WITH_EXTRA_TCP_STACKS=1
options TCPHPTS

Sponsored by: Netflix Inc.
Differential Revision: https://reviews.freebsd.org/D15525


# b43a0401 03-Mar-2018 Ian Lepore <ian@FreeBSD.org>

Correct a misplaced closing paren. Does not affect the result, but does
clarify (at least for me) that the multiplication happens before the shift.


# 51369649 20-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

sys: further adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 3-Clause license.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.


# d35f6548 29-Jul-2017 Ian Lepore <ian@FreeBSD.org>

Add inline functions to convert between sbintime_t and decimal time units.
Use them in some existing code that is vulnerable to roundoff errors.

The existing constant SBT_1NS is a honeypot, luring unsuspecting folks into
writing code such as long_timeout_ns*SBT_1NS to generate the argument for a
sleep call. The actual value of 1ns in sbt units is ~4.3, leading to a
large roundoff error giving a shorter sleep than expected when multiplying
by the trucated value of 4 in SBT_1NS. (The evil honeypot aspect becomes
clear after you waste a whole day figuring out why your sleeps return early.)


# 9dbdf2a1 14-Mar-2017 Eric van Gyzen <vangyzen@FreeBSD.org>

When the RTC is adjusted, reevaluate absolute sleep times based on the RTC

POSIX 2008 says this about clock_settime(2):

If the value of the CLOCK_REALTIME clock is set via clock_settime(),
the new value of the clock shall be used to determine the time
of expiration for absolute time services based upon the
CLOCK_REALTIME clock. This applies to the time at which armed
absolute timers expire. If the absolute time requested at the
invocation of such a time service is before the new value of
the clock, the time service shall expire immediately as if the
clock had reached the requested time normally.

Setting the value of the CLOCK_REALTIME clock via clock_settime()
shall have no effect on threads that are blocked waiting for
a relative time service based upon this clock, including the
nanosleep() function; nor on the expiration of relative timers
based upon this clock. Consequently, these time services shall
expire when the requested relative interval elapses, independently
of the new or old value of the clock.

When the real-time clock is adjusted, such as by clock_settime(3),
wake any threads sleeping until an absolute real-clock time.
Such a sleep is indicated by a non-zero td_rtcgen. The sleep functions
will set that field to zero and return zero to tell the caller
to reevaluate its sleep duration based on the new value of the clock.

At present, this affects the following functions:

pthread_cond_timedwait(3)
pthread_mutex_timedlock(3)
pthread_rwlock_timedrdlock(3)
pthread_rwlock_timedwrlock(3)
sem_timedwait(3)
sem_clockwait_np(3)

I'm working on adding clock_nanosleep(2), which will also be affected.

Reported by: Sebastian Huber <sebastian.huber@embedded-brains.de>
Reviewed by: jhb, kib
MFC after: 2 weeks
Relnotes: yes
Sponsored by: Dell EMC
Differential Revision: https://reviews.freebsd.org/D9791


# fbbd9655 28-Feb-2017 Warner Losh <imp@FreeBSD.org>

Renumber copyright clause 4

Renumber cluase 4 to 3, per what everybody else did when BSD granted
them permission to remove clause 3. My insistance on keeping the same
numbering for legal reasons is too pedantic, so give up on that point.

Submitted by: Jan Schaumann <jschauma@stevens.edu>
Pull Request: https://github.com/freebsd/freebsd/pull/96


# 584b675e 27-Jul-2016 Konstantin Belousov <kib@FreeBSD.org>

Hide the boottime and bootimebin globals, provide the getboottime(9)
and getboottimebin(9) KPI. Change consumers of boottime to use the
KPI. The variables were renamed to avoid shadowing issues with local
variables of the same name.

Issue is that boottime* should be adjusted from tc_windup(), which
requires them to be members of the timehands structure. As a
preparation, this commit only introduces the interface.

Some uses of boottime were found doubtful, e.g. NLM uses boottime to
identify the system boot instance. Arguably the identity should not
change on the leap second adjustment, but the commit is about the
timekeeping code and the consumers were kept bug-to-bug compatible.

Tested by: pho (as part of the bigger patch)
Reviewed by: jhb (same)
Discussed with: bde
Sponsored by: The FreeBSD Foundation
MFC after: 1 month
X-Differential revision: https://reviews.freebsd.org/D7302


# 61f26cae 20-Dec-2014 Warner Losh <imp@FreeBSD.org>

Where appropriate, use the modern terms for the one true time base
(UTC) rather than the archaic (GMT) in comments. Except where the
comments are making fun of people doing this (and pedants who insist
on the new terms).


# e9577457 21-Aug-2014 Davide Italiano <davide@FreeBSD.org>

Revert r270227. GCC doesn't like the lack of LL suffix,
so this makes powerpc build failing.


# d0091d66 20-Aug-2014 Davide Italiano <davide@FreeBSD.org>

Make Bruce happy removing the "LL abomination" from time.h
It's not necessary in all the three instances because
they already have the correct type on all the supported
arches.

Requested by: bde


# 3a8106f5 25-Jun-2014 Davide Italiano <davide@FreeBSD.org>

Improve r264388 removing namespace pollution previously introduced in
<sys/time.h>. INT64_MAX actually requires __INT64_C() hack to get the
type right on exotic architectures (e.g. on ones with 63-bit ints or long
0x7fffffffffffffff is unsigned int or long). The hardcoded LL suffix is
good enough to avoid these problems for SBT_MAX (it makes the type always
signed long long, without overflow since long long has at least 64 bits).
Many thanks to Bruce Evans for the time spent me to explain this.

Reported by: bde
Reviewed by: bde


# 4bc38a5a 12-Apr-2014 Davide Italiano <davide@FreeBSD.org>

Hide internal details of sbintime_t implementation wrapping INT64_MAX into
SBT_MAX, to make it more robust in case internal type representation will
change in the future. All the consumers were migrated to SBT_MAX and
every new consumer (if any) should from now use this interface.

Requested by: bapt, jmg, Ryan Lortie (implictly)
Reviewed by: mav, bde


# efd01e37 23-Oct-2013 Brooks Davis <brooks@FreeBSD.org>

Revert addition of sbintime and getsbintime that crept into r256963.

Pointyhat: brooks


# 0e902f8a 23-Oct-2013 Brooks Davis <brooks@FreeBSD.org>

Revert r256934, it needs work to build on mips32.


# 17df25c4 01-Sep-2013 Davide Italiano <davide@FreeBSD.org>

Use single underscore for all parameters name and local variables in
bintime_* related functions. This commit completes what was already done
by theraven@ for bintime_shift, and just uses a single underscore instead
of two (which is a style bug according to Bruce). See r251855 for reference.

Reported by: theraven
Discussed with: bde
Reviewed by: bde


# 0f78a367 17-Jun-2013 David Chisnall <theraven@FreeBSD.org>

Rename a parameter in sys/time.h so that you don't get warnings for things
like libdialog that include both this header and math.h.


# 5b999a6b 04-Mar-2013 Davide Italiano <davide@FreeBSD.org>

- Make callout(9) tickless, relying on eventtimers(4) as backend for
precise time event generation. This greatly improves granularity of
callouts which are not anymore constrained to wait next tick to be
scheduled.
- Extend the callout KPI introducing a set of callout_reset_sbt* functions,
which take a sbintime_t as timeout argument. The new KPI also offers a
way for consumers to specify precision tolerance they allow, so that
callout can coalesce events and reduce number of interrupts as well as
potentially avoid scheduling a SWI thread.
- Introduce support for dispatching callouts directly from hardware
interrupt context, specifying an additional flag. This feature should be
used carefully, as long as interrupt context has some limitations
(e.g. no sleeping locks can be held).
- Enhance mechanisms to gather informations about callwheel, introducing
a new sysctl to obtain stats.

This change breaks the KBI. struct callout fields has been changed, in
particular 'int ticks' (4 bytes) has been replaced with 'sbintime_t'
(8 bytes) and another 'sbintime_t' field was added for precision.

Together with: mav
Reviewed by: attilio, bde, luigi, phk
Sponsored by: Google Summer of Code 2012, iXsystems inc.
Tested by: flo (amd64, sparc64), marius (sparc64), ian (arm),
markj (amd64), mav, Fabian Keil


# 25e533d3 02-Mar-2013 Alexander Motin <mav@FreeBSD.org>

Polish few spaces/tabs.


# aa97685d 28-Feb-2013 Davide Italiano <davide@FreeBSD.org>

Move the definition of sbintime_t type from <sys/time.h> to <sys/types.h>.
With this change we prevent gross namespace pollution.

Reported by: bde
Suggested by: attilio


# 0f4fc79e 28-Feb-2013 Alexander Motin <mav@FreeBSD.org>

Introduce sbintime_t type -- the simplified version of struct bintime,
using 32.32 fixed point in form of single int64_t. It is much easier to
use in cases where additional precision and range of struct bintime is
not required.

Reviewed by: bde (previous version), davide


# d9dcc463 26-Feb-2013 Xin LI <delphij@FreeBSD.org>

Revert r247300 for now. I'll post a new changeset for review.


# 285a4c7c 25-Feb-2013 Xin LI <delphij@FreeBSD.org>

Expose timespec and timeval macros when __BSD_VISIBLE is defined. This
allows userland application to use the following macros:

timespecclear, timespecisset, timespeccmp, timespecadd,
timespecsub;

timevalclear, timevalisset, timevalcmp.

MFC after: 1 month


# a8df530d 28-Jan-2013 John Baldwin <jhb@FreeBSD.org>

Mark 'ticks', 'time_second', and 'time_uptime' as volatile to prevent the
compiler from caching their values in tight loops.

Reviewed by: bde
MFC after: 1 week


# 4a8914c6 01-Sep-2012 Ed Schouten <ed@FreeBSD.org>

While there, remove an unneeded blank line.

MFC after: 1 month


# ef424581 01-Sep-2012 Ed Schouten <ed@FreeBSD.org>

Fix whitespace.

MFC after: 1 month


# d65f1abc 16-Aug-2012 David Xu <davidxu@FreeBSD.org>

Implement syscall clock_getcpuclockid2, so we can get a clock id
for process, thread or others we want to support.
Use the syscall to implement POSIX API clock_getcpuclock and
pthread_getcpuclockid.

PR: 168417


# d14e812b 23-Feb-2012 Gleb Smirnoff <glebius@FreeBSD.org>

Use correct API for timeval subtraction.

Noticed by: bde


# 95037eb1 23-Feb-2012 Gleb Smirnoff <glebius@FreeBSD.org>

Expose NetBSD/OpenBSD compat defines to kernel code, too.


# 3797b1fc 09-Aug-2011 Jonathan Anderson <jonathan@FreeBSD.org>

Remove timeval2timespec and its converse, since we already have
TIMEVAL_TO_TIMESPEC() in <sys/timespec.h>.

Spotted by: bde
Approved by: re (kib), mentor (rwatson)


# ef5502c5 08-Aug-2011 Jonathan Anderson <jonathan@FreeBSD.org>

Create timeval2timespec() and timespec2timeval().

These functions will be used by process descriptors to convert process
creation time into process descriptor [acm]time.

Approved by: re (kib), mentor (rwatson)
Suggested by: jhb
Sponsored by: Google Inc


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# 47a9ec41 04-Oct-2010 Poul-Henning Kamp <phk@FreeBSD.org>

Certain static code analysis tools (FlexeLint being one) are very
suspicious about 'l' and '1' being confused in numeric constants.
The fear being that some old fart programmer might still think that
he is using a Remmington Noiseless as input terminal device.

An easy way to placate this fear is to use capital 'L' or to put
the 'u' in unsigned constants in front of the 'l'.


# 170a7705 08-Sep-2010 Alexander Motin <mav@FreeBSD.org>

Add few more bintime math macros.


# 1a996ed1 18-Jul-2010 Edward Tomasz Napierala <trasz@FreeBSD.org>

Revert r210225 - turns out I was wrong; the "/*-" is not license-only
thing; it's also used to indicate that the comment should not be automatically
rewrapped.

Explained by: cperciva@


# 805cc58a 18-Jul-2010 Edward Tomasz Napierala <trasz@FreeBSD.org>

The "/*-" comment marker is supposed to denote copyrights. Remove non-copyright
occurences from sys/sys/ and sys/kern/.


# 547d94bd 15-Jun-2010 Jung-uk Kim <jkim@FreeBSD.org>

Implement flexible BPF timestamping framework.

- Allow setting format, resolution and accuracy of BPF time stamps per
listener. Previously, we were only able to use microtime(9). Now we can
set various resolutions and accuracies with ioctl(2) BIOCSTSTAMP command.
Similarly, we can get the current resolution and accuracy with BIOCGTSTAMP
command. Document all supported options in bpf(4) and their uses.

- Introduce new time stamp 'struct bpf_ts' and header 'struct bpf_xhdr'.
The new time stamp has both 64-bit second and fractional parts. bpf_xhdr
has this time stamp instead of 'struct timeval' for bh_tstamp. The new
structures let us use bh_tstamp of same size on both 32-bit and 64-bit
platforms without adding additional shims for 32-bit binaries. On 64-bit
platforms, size of BPF header does not change compared to bpf_hdr as its
members are already all 64-bit long. On 32-bit platforms, the size may
increase by 8 bytes. For backward compatibility, struct bpf_hdr with
struct timeval is still the default header unless new time stamp format is
explicitly requested. However, the behaviour may change in the future and
all relevant code is wrapped around "#ifdef BURN_BRIDGES" for now.

- Add experimental support for tagging mbufs with time stamps from a lower
layer, e.g., device driver. Currently, mbuf_tags(9) is used to tag mbufs.
The time stamps must be uptime in 'struct bintime' format as binuptime(9)
and getbinuptime(9) do.

Reviewed by: net@


# 052e971d 29-Oct-2009 Ruslan Ermilov <ru@FreeBSD.org>

HZ is now 1000 on most platforms, update a comment.

Reviewed by: phk, markm


# df41066d 14-Mar-2009 David Schultz <das@FreeBSD.org>

Namespace: adjtime(), futimes(), futimesat(), lutimes(), and settimeofday()
are BSD extensions.

Also include <sys/select.h> in user code, since this header is
also supposed to define most of the symbols there.


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# 8a2dd5b9 18-May-2008 John Birrell <jb@FreeBSD.org>

Remove some DTrace hook definitions that are now in dtrace_bsd.h
which contains all the hook definitions rather than splattering
them all over the header files.

The definitions are only valid when the KDTRACE_HOOKS kernel
option is defined, so other kernel sources have no need to
see them.


# 9b4a8ab7 22-Apr-2008 Poul-Henning Kamp <phk@FreeBSD.org>

Now that all platforms use genclock, shuffle things around slightly
for better structure.

Much of this is related to <sys/clock.h>, which should really have
been called <sys/calendar.h>, but unless and until we need the name,
the repocopy can wait.

In general the kernel does not know about minutes, hours, days,
timezones, daylight savings time, leap-years and such. All that
is theoretically a matter for userland only.

Parts of kernel code does however care: badly designed filesystems
store timestamps in local time and RTC chips almost universally
track time in a YY-MM-DD HH:MM:SS format, and sometimes in local
timezone instead of UTC. For this we have <sys/clock.h>

<sys/time.h> on the other hand, deals with time_t, timeval, timespec
and so on. These know only seconds and fractions thereof.

Move inittodr() and resettodr() prototypes to <sys/time.h>.
Retain the names as it is one of the few surviving PDP/VAX references.

Move startrtclock() to <machine/clock.h> on relevant platforms, it
is a MD call between machdep.c/clock.c. Remove references to it
elsewhere.

Remove a lot of unnecessary <sys/clock.h> includes.

Move the machdep.disable_rtc_set sysctl to subr_rtc.c where it belongs.
XXX: should be kern.disable_rtc_set really, it's not MD.


# ba2983e5 30-Mar-2008 Konstantin Belousov <kib@FreeBSD.org>

Add the libc glue and headers definitions for the *at() syscalls.

Based on the submission by rdivacky,
sponsored by Google Summer of Code 2007
Reviewed by: rwatson, rdivacky
Tested by: pho


# 00d6ac63 18-Jan-2008 David Xu <davidxu@FreeBSD.org>

Add POSIX clock id CLOCK_THREAD_CPUTIME_ID, this can be used to measure
per-thread runtime in user code.


# e3709a56 28-Nov-2007 John Birrell <jb@FreeBSD.org>

Remove _SOLARIS_C_SOURCE compatibility definitions. Unfortunately the
ZFS porting style didn't extend this, instead using a heap of additional
header files that don't get installed.

My intention had been to allow OpenSolaris external code to build on
FreeBSD out of the box (i.e. without a src tree).


# 678faae2 02-Oct-2006 John Birrell <jb@FreeBSD.org>

Solaris compatibility only: Be specific about the fact that
the inline function takes no arguments.


# 3632bc0a 04-Aug-2006 John Birrell <jb@FreeBSD.org>

Add some OpenSolaris compatibility definitions which are only visible
if _SOLARIS_C_SOURCE is defined.

Add two function prototypes which are required to feed high-resolution
times to DTrace. DTrace requires it's own functions with the dtrace_
prefix so that it knows not to try and trace them. This is a rule that
code executed from the DTrace probe context must obey.

The two functions are only be compiled if the KDTRACE option is defined
to compile in kernel support for loading the DTrace modules.


# 5e758b95 26-Nov-2005 Robert Watson <rwatson@FreeBSD.org>

Add several aliases for existing clockid_t names to indicate that the
application wishes to request high precision time stamps be returned:

Alias Existing

CLOCK_REALTIME_PRECISE CLOCK_REALTIME
CLOCK_MONOTONIC_PRECISE CLOCK_MONOTONIC
CLOCK_UPTIME_PRECISE CLOCK_UPTIME

Add experimental low-precision clockid_t names corresponding to these
clocks, but implemented using cached timestamps in kernel rather than
a full time counter query. This offers a minimum update rate of 1/HZ,
but in practice will often be more frequent due to the frequency of
time stamping in the kernel:

New clockid_t name Approximates existing clockid_t

CLOCK_REALTIME_FAST CLOCK_REALTIME
CLOCK_MONOTONIC_FAST CLOCK_MONOTONIC
CLOCK_UPTIME_FAST CLOCK_UPTIME

Add one additional new clockid_t, CLOCK_SECOND, which returns the
current second without performing a full time counter query or cache
lookup overhead to make sure the cached timestamp is stable. This is
intended to support very low granularity consumers, such as time(3).

The names, visibility, and implementation of the above are subject
to change, and will not be MFC'd any time soon. The goal is to
expose lower quality time measurement to applications willing to
sacrifice accuracy in performance critical paths, such as when taking
time stamps for the purpose of rescheduling select() and poll()
timeouts. Future changes might include retrofitting the time counter
infrastructure to allow the "fast" time query mechanisms to use a
different time counter, rather than a cached time counter (i.e.,
TSC).

NOTE: With different underlying time mechanisms exposed, using
different time query mechanisms in the same application may result in
relative non-monoticity or the appearance of clock stalling for a
single clockid_t, as a cached time stamp queried after a precision
time stamp lookup may be "before" the time returned by the earlier
live time counter query.


# 5eefd889 18-Nov-2005 Andre Oppermann <andre@FreeBSD.org>

Add CLOCK_UPTIME to clock_gettime(2) reporting the current
uptime measured in SI seconds.

Sponsored by: TCP/IP Optimization Fundraise 2005


# 6d2f64c1 01-Apr-2005 David Schultz <das@FreeBSD.org>

Define CLOCK_* and TIMER_* in time.h, where they are supposed to be.


# efa42cbc 19-Jan-2005 Paul Saab <ps@FreeBSD.org>

move kern_nanosleep to sys/syscallsubr.h

Requested by: jhb


# 7fdf2c85 19-Jan-2005 Paul Saab <ps@FreeBSD.org>

- rename nanosleep1 to kern_nanosleep
- Add a 32bit syscall entry for nanosleep

Reviewed by: peter
Obtained from: Yahoo!


# 60727d8b 06-Jan-2005 Warner Losh <imp@FreeBSD.org>

/* -> /*- for license, minor formatting changes


# 82c6e879 06-Apr-2004 Warner Losh <imp@FreeBSD.org>

Remove advertising clause from University of California Regent's license,
per letter dated July 22, 1999.

Approved by: core


# 7314dafb 29-Feb-2004 Poul-Henning Kamp <phk@FreeBSD.org>

Move boottime from <sys/kernel.h> to <sys/time.h> where it belongs.


# 6229d841 25-Oct-2003 Alfred Perlstein <alfred@FreeBSD.org>

constify bintime_add, bintime_sub, bintime2timespec, timespec2bintime,
bintime2timeval and timeval2bintime.


# 6ff7636e 25-Oct-2003 Alfred Perlstein <alfred@FreeBSD.org>

constify the second args to timevaladd() and timevalsub().


# 8f5ef1a9 23-Feb-2003 Poul-Henning Kamp <phk@FreeBSD.org>

Implement CLOCK_MONOTONIC.


# d9755695 30-Dec-2002 Mike Barcroft <mike@FreeBSD.org>

Move struct timeval to its own header so that it can be shared between
multiple headers.


# 91974ce1 20-Dec-2002 Sam Leffler <sam@FreeBSD.org>

add generic rate limiting support from netbsd; ratelimit is purely time based,
ppsratecheck is for controlling packets/second

Obtained from: netbsd


# 38b0884c 01-Nov-2002 Poul-Henning Kamp <phk@FreeBSD.org>

Introduce a "time_uptime" global variable which holds the time since boot
in seconds.


# 58db51b2 15-Jun-2002 Garrett Wollman <wollman@FreeBSD.org>

Fix visibility issues; use <sys/timespec.h>.


# a9a0f15a 04-May-2002 Bruce Evans <bde@FreeBSD.org>

Fixed breakage of binary compatibility of the kern.clockrate sysctl in
sys/time.h rev.1.53, etc. Zero out the entire struct clkinfo and not
just the new spare part of it so that there is no possibility of leaking
kernel stack context to userland.


# 9c30ce57 30-Apr-2002 Poul-Henning Kamp <phk@FreeBSD.org>

Brucifixion ? Yes, out that door, row on the left, one patch each.


# 056abcab 26-Apr-2002 Poul-Henning Kamp <phk@FreeBSD.org>

Various cleanup and sorting of clock reading functions. Add the two
functions missing in the complete 12 function complement.


# b35c8f28 14-Apr-2002 Poul-Henning Kamp <phk@FreeBSD.org>

Take the "tickadj" element out of struct clockinfo. Our adjtime(2)
implementation is being changed and the very concept of tickadj will
no longer be meaningful.


# c7ec79b0 20-Mar-2002 Poul-Henning Kamp <phk@FreeBSD.org>

Various style issues from a recent brucification:
use uint_%dt not u_int%dt
Avoid LL suffixed intergers where we can by using explicit casts.
(The last two I don't know how to avoid.)
Add an explanation why truncation rather than rounding is used.

Inspired by: bde


# 789f12fe 19-Mar-2002 Alfred Perlstein <alfred@FreeBSD.org>

Remove __P


# a060acb1 07-Feb-2002 Peter Wemm <peter@FreeBSD.org>

Fix world breakage (compiling libstdc++):
sys/time.h:137: integer constant out of range
sys/time.h:137: warning: decimal integer constant is so large that it is unsigned
sys/time.h:153: integer constant out of range
sys/time.h:153: warning: decimal integer constant is so large that it is unsigned


# d627beda 07-Feb-2002 Poul-Henning Kamp <phk@FreeBSD.org>

Remove the inline assembly optimized versins of bintime_*() functions,
they have no measurable effect and they don't belong in an MI header
even if they did.


# 2028c0cd 07-Feb-2002 Poul-Henning Kamp <phk@FreeBSD.org>

Revise timercounters to use binary fixed point format internally.

The binary format "bintime" is a 32.64 format, it will go to 64.64
when time_t does.

The bintime format is available to consumers of time in the kernel,
and is preferable where timeintervals needs to be accumulated.

This change simplifies much of the magic math inside the timecounters
and improves the frequency and time precision by a couple of bits.

I have not been able to measure a performance difference which was not
a tiny fraction of the standard deviation on the measurements.


# 5752bffd 04-Sep-2001 David E. O'Brien <obrien@FreeBSD.org>

style(9) the structure definitions.


# 4638cadd 23-May-2001 Poul-Henning Kamp <phk@FreeBSD.org>

Polish getnano{up}*time() prototypes.

PR: 15908
Submitted by: Kelly Yancey kbyanc@posi.net


# 9b399f7e 21-Mar-2001 Mark Murray <markm@FreeBSD.org>

Paranthesise macros. This fixes an unlikely bug and silences lint.


# 2fa72ea7 05-Feb-2001 Jeroen Ruigrok van der Werven <asmodai@FreeBSD.org>

Fix typo: compatability -> compatibility.

Compatability is not an existing english word.


# 91266b96 20-Mar-2000 Poul-Henning Kamp <phk@FreeBSD.org>

Isolate the Timecounter internals in their own two files.

Make the public interface more systematically named.

Remove the alternate method, it doesn't do any good, only ruins performance.

Add counters to profile the usage of the 8 access functions.

Apply the beer-ware to my code.

The weird +/- counts are caused by two repocopies behind the scenes:
kern/kern_clock.c -> kern/kern_tc.c
sys/time.h -> sys/timetc.h
(thanks peter!)


# 664a31e4 28-Dec-1999 Peter Wemm <peter@FreeBSD.org>

Change #ifdef KERNEL to #ifdef _KERNEL in the public headers. "KERNEL"
is an application space macro and the applications are supposed to be free
to use it as they please (but cannot). This is consistant with the other
BSD's who made this change quite some time ago. More commits to come.


# e7678c1e 23-Dec-1999 Bruce Evans <bde@FreeBSD.org>

Fixed missing declarations of futimes(2) and lutimes(2).


# c3aac50f 27-Aug-1999 Peter Wemm <peter@FreeBSD.org>

$Id$ -> $FreeBSD$


# 6b6ef746 18-Jul-1999 Bruce Evans <bde@FreeBSD.org>

Added a sysctl "kern.timecounter.hardware" for selecting the hardware
used for timecounting. The possible values are the names of the
physically present harware timecounters ("i8254" and "TSC" on i386's).

Fixed some nearby bitrot in comments in <sys/time.h>.

Reviewed by: phk


# 0bb2226a 25-Apr-1999 Poul-Henning Kamp <phk@FreeBSD.org>

Make the machdep.i8254_freq and machdep.tsc_freq sysctls modify the
timecounter as well

Asked for by: bde, jhay


# 32c20357 11-Mar-1999 Poul-Henning Kamp <phk@FreeBSD.org>

Make even more of the PPSAPI implementations generic.

FLL support in hardpps()

Various magic shuffles and improved comments

Style fixes from Bruce.


# c68996e2 07-Mar-1999 Poul-Henning Kamp <phk@FreeBSD.org>

Integrate the new "nanokernel" PLL from Dave Mills.

This code is backwards compatible with the older "microkernel" PLL, but
allows ntpd v4 to use nanosecond resolution. Many other improvements.

PPS_SYNC and hardpps() are NOT supported yet.


# e3b3ba2d 15-Dec-1998 Dag-Erling Smørgrav <des@FreeBSD.org>

Wrap two macros into do { ... } while (0), and fix the way they're used
in the kernel.

Reviewed by: bde


# e49994fe 23-Oct-1998 Poul-Henning Kamp <phk@FreeBSD.org>

Remove the tc_cost field from timecounters.


# a58f0f8e 09-Jun-1998 Poul-Henning Kamp <phk@FreeBSD.org>

Add a tc_ prefix to struct timecounter members.

Urged by: bde


# 48115288 07-Jun-1998 Poul-Henning Kamp <phk@FreeBSD.org>

Add a member function more to the timecounters, this one is for use
with latch based PPS implementations. The client that uses it will
be committed after more testing.


# 85a2cb8e 07-Jun-1998 Poul-Henning Kamp <phk@FreeBSD.org>

Sigh, all good words are reserved words these days...
s/private/priv/

Noticed by: sos


# dbb34755 07-Jun-1998 Poul-Henning Kamp <phk@FreeBSD.org>

Add a "this" style argument and a "void *private" so timecounters can
figure out which instance to wount with.


# e796e00d 28-May-1998 Poul-Henning Kamp <phk@FreeBSD.org>

Some cleanups related to timecounters and weird ifdefs in <sys/time.h>.

Clean up (or if antipodic: down) some of the msgbuf stuff.

Use an inline function rather than a macro for timecounter delta.

Maintain process "on-cpu" time as 64 bits of microseconds to avoid
needless second rollover overhead.

Avoid calling microuptime the second time in mi_switch() if we do
not pass through _idle in cpu_switch()

This should reduce our context-switch overhead a bit, in particular
on pre-P5 and SMP systems.

WARNING: Programs which muck about with struct proc in userland
will have to be fixed.

Reviewed, but found imperfect by: bde


# 579f4456 19-May-1998 Poul-Henning Kamp <phk@FreeBSD.org>

Change a data type internal to the timecounters, and remove the "delta"
function.

Reviewed, but not entirely approved by: bde


# c21410e1 17-May-1998 Poul-Henning Kamp <phk@FreeBSD.org>

s/nanoruntime/nanouptime/g
s/microruntime/microuptime/g

Reviewed by: bde


# 01404206 23-Apr-1998 Eivind Eklund <eivind@FreeBSD.org>

Convert timespecclear() back to an expression (this time without
sideeffects).


# e89652d0 22-Apr-1998 Eivind Eklund <eivind@FreeBSD.org>

Wrap timerclear in do { ... } while(0)


# 4cf41af3 06-Apr-1998 Poul-Henning Kamp <phk@FreeBSD.org>

Make a kernel version of the timer* functions called timerval* to be
more consistent.

OK'ed by: bde


# 00af9731 04-Apr-1998 Poul-Henning Kamp <phk@FreeBSD.org>

Time changes mark 2:

* Figure out UTC relative to boottime. Four new functions provide
time relative to boottime.

* move "runtime" into struct proc. This helps fix the calcru()
problem in SMP.

* kill mono_time.

* add timespec{add|sub|cmp} macros to time.h. (XXX: These may change!)

* nanosleep, select & poll takes long sleeps one day at a time

Reviewed by: bde
Tested by: ache and others


# 227ee8a1 30-Mar-1998 Poul-Henning Kamp <phk@FreeBSD.org>

Eradicate the variable "time" from the kernel, using various measures.
"time" wasn't a atomic variable, so splfoo() protection were needed
around any access to it, unless you just wanted the seconds part.

Most uses of time.tv_sec now uses the new variable time_second instead.

gettime() changed to getmicrotime(0.

Remove a couple of unneeded splfoo() protections, the new getmicrotime()
is atomic, (until Bruce sets a breakpoint in it).

A couple of places needed random data, so use read_random() instead
of mucking about with time which isn't random.

Add a new nfs_curusec() function.

Mark a couple of bogosities involving the now disappeard time variable.

Update ffs_update() to avoid the weird "== &time" checks, by fixing the
one remaining call that passwd &time as args.

Change profiling in ncr.c to use ticks instead of time. Resolution is
the same.

Add new function "tvtohz()" to avoid the bogus "splfoo(), add time, call
hzto() which subtracts time" sequences.

Reviewed by: bde


# a0502b19 26-Mar-1998 Poul-Henning Kamp <phk@FreeBSD.org>

Add two new functions, get{micro|nano}time.

They are atomic, but return in essence what is in the "time" variable.
gettime() is now a macro front for getmicrotime().

Various patches to use the two new functions instead of the various
hacks used in their absence.

Some puntuation and grammer patches from Bruce.

A couple of XXX comments.


# 917e476d 04-Mar-1998 Peter Dufault <dufault@FreeBSD.org>

Reviewed by: msmith, bde long ago
POSIX.4 headers and sysctl variables. Nothing should change
unless POSIX4 is defined or _POSIX_VERSION is set to 199309.


# fb156c95 24-Feb-1998 Bruce Evans <bde@FreeBSD.org>

Removed _POSIX_SOURCE ifdefs. This is not a POSIX.1 header, so POSIX
sources can't include it. However, until recently it was included
by <sys/stat.h>, so it should have been (almost) entirely inside
_POSIX_SOURCE ifdefs for <sys/stat.h> to be (almost) POSIX.1 conformant,
but it was only about half inside _POSIX_SOURCE ifdefs.


# a0a9bf2e 20-Feb-1998 John Birrell <jb@FreeBSD.org>

Add #ifndef _POSIX_SOURCE around the timecounter definitions
which rely on u_int being defined in sys/types.h, but isn't
if _POSIX_SOURCE is defined.

This fixes the gnu/lib/libstdc++ breakage. I've successfully completed
a make world after this and a kernel (without many devices).


# 7ec73f64 20-Feb-1998 Poul-Henning Kamp <phk@FreeBSD.org>

Replace TOD clock code with more systematic approach.

Highlights:
* Simple model for underlying hardware.
* Hardware basis for timekeeping can be changed on the fly.
* Only one hardware clock responsible for TOD keeping.
* Provides a real nanotime() function.
* Time granularity: .232E-18 seconds.
* Frequency granularity: .238E-12 s/s
* Frequency adjustment is continuous in time.
* Less overhead for frequency adjustment.
* Improves xntpd performance.

Reviewed by: bde, bde, bde


# d46e059f 28-Dec-1997 Poul-Henning Kamp <phk@FreeBSD.org>

wash, sort and put in order various nits from the i586_ctr -> tsc
commit.

Pointed out by: bde


# 5faa3121 24-Jun-1997 John Hay <jhay@FreeBSD.org>

Add tickadj to struct clockinfo, like NetBSD and OpenBSD.
NOTE: libc, time, kgmon and rpc.rstatd will have to be recompiled.


# 7fb149d5 13-May-1997 Peter Wemm <peter@FreeBSD.org>

struct timespec needs to be useable with just <time.h>, but needs to not
conflict with the kernel visible one. Make the new stuff not visible if
_ANSI_SOURCE or _POSIX_SOURCE is defined (!) because the new things are
not part of the base 1003.1-1990 standard or ansi (says Bruce).

Reviewed by: bde


# 0f5ed9f4 08-May-1997 Peter Wemm <peter@FreeBSD.org>

Add posix clock and timer definitions

Obtained from: NetBSD


# 3c816944 21-Mar-1997 Bruce Evans <bde@FreeBSD.org>

Fixed some invalid (non-atomic) accesses to `time', mostly ones of the
form `tv = time'. Use a new function gettime(). The current version
just forces atomicicity without fixing precision or efficiency bugs.
Simplified some related valid accesses by using the central function.


# 6875d254 22-Feb-1997 Peter Wemm <peter@FreeBSD.org>

Back out part 1 of the MCFH that changed $Id$ to $FreeBSD$. We are not
ready for it yet.


# 1130b656 14-Jan-1997 Jordan K. Hubbard <jkh@FreeBSD.org>

Make the long-awaited change from $Id$ to $FreeBSD$

This will make a number of things easier in the future, as well as (finally!)
avoiding the Id-smashing problem which has plagued developers for so long.

Boy, I'm glad we're not using sup anymore. This update would have been
insane otherwise.


# c3f47ca9 30-Dec-1996 Peter Wemm <peter@FreeBSD.org>

Add NetBSD/OpenBSD compatable timeradd()/timersub() user-space macros.

These are deliberately not visible to the kernel since we have timevaladd()
and timevalsub() functions there.

Obtained from: NetBSD/OpenBSD


# 030e2e9e 19-Sep-1996 Nate Williams <nate@FreeBSD.org>

In sys/time.h, struct timespec is defined as:

/*
* Structure defined by POSIX.4 to be like a timeval.
*/
struct timespec {
time_t ts_sec; /* seconds */
long ts_nsec; /* and nanoseconds */
};

The correct names of the fields are tv_sec and tv_nsec.

Reminded by: James Drobina <jdrobina@infinet.com>


# 02e2c406 11-Mar-1996 Peter Wemm <peter@FreeBSD.org>

Import 4.4BSD-Lite2 onto the vendor branch, note that in the kernel, all
files are off the vendor branch, so this should not change anything.

A "U" marker generally means that the file was not changed in between
the 4.4Lite and Lite-2 releases, and does not need a merge. "C" generally
means that there was a change.
[new sys/syscallargs.h file, to be "cvs rm"ed]


# 886556be 10-Mar-1996 Jeffrey Hsu <hsu@FreeBSD.org>

Merge in Lite2: make timespec struct POSIX.4 compliant
stylistic changes to function prototypes
Reviewed by: davidg & bde


# 80c07b66 25-Dec-1995 Bruce Evans <bde@FreeBSD.org>

Finished staticizing of timevalfix().


# 3d05297c 09-Oct-1994 Poul-Henning Kamp <phk@FreeBSD.org>

Cosmetics. (sort of) Added 19 prototypes.


# f86eaaca 02-Oct-1994 Poul-Henning Kamp <phk@FreeBSD.org>

Prototypes, prototypes and even more prototypes. Not quite done yet, but
getting closer all the time.


# f23b4c91 18-Aug-1994 Garrett Wollman <wollman@FreeBSD.org>

Fix up some sloppy coding practices:

- Delete redundant declarations.
- Add -Wredundant-declarations to Makefile.i386 so they don't come back.
- Delete sloppy COMMON-style declarations of uninitialized data in
header files.
- Add a few prototypes.
- Clean up warnings resulting from the above.

NB: ioconf.c will still generate a redundant-declaration warning, which
is unavoidable unless somebody volunteers to make `config' smarter.


# 3c4dd356 02-Aug-1994 David Greenman <dg@FreeBSD.org>

Added $Id$


# df8bae1d 24-May-1994 Rodney W. Grimes <rgrimes@FreeBSD.org>

BSD 4.4 Lite Kernel Sources