The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/sys/time.h

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * SPDX-License-Identifier: BSD-3-Clause
    3  *
    4  * Copyright (c) 1982, 1986, 1993
    5  *      The Regents of the University of California.  All rights reserved.
    6  *
    7  * Redistribution and use in source and binary forms, with or without
    8  * modification, are permitted provided that the following conditions
    9  * are met:
   10  * 1. Redistributions of source code must retain the above copyright
   11  *    notice, this list of conditions and the following disclaimer.
   12  * 2. Redistributions in binary form must reproduce the above copyright
   13  *    notice, this list of conditions and the following disclaimer in the
   14  *    documentation and/or other materials provided with the distribution.
   15  * 3. Neither the name of the University nor the names of its contributors
   16  *    may be used to endorse or promote products derived from this software
   17  *    without specific prior written permission.
   18  *
   19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   29  * SUCH DAMAGE.
   30  *
   31  *      @(#)time.h      8.5 (Berkeley) 5/4/95
   32  * $FreeBSD: head/sys/sys/time.h 346176 2019-04-13 04:46:35Z imp $
   33  */
   34 
   35 #ifndef _SYS_TIME_H_
   36 #define _SYS_TIME_H_
   37 
   38 #include <sys/_timeval.h>
   39 #include <sys/types.h>
   40 #include <sys/timespec.h>
   41 
   42 struct timezone {
   43         int     tz_minuteswest; /* minutes west of Greenwich */
   44         int     tz_dsttime;     /* type of dst correction */
   45 };
   46 #define DST_NONE        0       /* not on dst */
   47 #define DST_USA         1       /* USA style dst */
   48 #define DST_AUST        2       /* Australian style dst */
   49 #define DST_WET         3       /* Western European dst */
   50 #define DST_MET         4       /* Middle European dst */
   51 #define DST_EET         5       /* Eastern European dst */
   52 #define DST_CAN         6       /* Canada */
   53 
   54 #if __BSD_VISIBLE
   55 struct bintime {
   56         time_t  sec;
   57         uint64_t frac;
   58 };
   59 
   60 static __inline void
   61 bintime_addx(struct bintime *_bt, uint64_t _x)
   62 {
   63         uint64_t _u;
   64 
   65         _u = _bt->frac;
   66         _bt->frac += _x;
   67         if (_u > _bt->frac)
   68                 _bt->sec++;
   69 }
   70 
   71 static __inline void
   72 bintime_add(struct bintime *_bt, const struct bintime *_bt2)
   73 {
   74         uint64_t _u;
   75 
   76         _u = _bt->frac;
   77         _bt->frac += _bt2->frac;
   78         if (_u > _bt->frac)
   79                 _bt->sec++;
   80         _bt->sec += _bt2->sec;
   81 }
   82 
   83 static __inline void
   84 bintime_sub(struct bintime *_bt, const struct bintime *_bt2)
   85 {
   86         uint64_t _u;
   87 
   88         _u = _bt->frac;
   89         _bt->frac -= _bt2->frac;
   90         if (_u < _bt->frac)
   91                 _bt->sec--;
   92         _bt->sec -= _bt2->sec;
   93 }
   94 
   95 static __inline void
   96 bintime_mul(struct bintime *_bt, u_int _x)
   97 {
   98         uint64_t _p1, _p2;
   99 
  100         _p1 = (_bt->frac & 0xffffffffull) * _x;
  101         _p2 = (_bt->frac >> 32) * _x + (_p1 >> 32);
  102         _bt->sec *= _x;
  103         _bt->sec += (_p2 >> 32);
  104         _bt->frac = (_p2 << 32) | (_p1 & 0xffffffffull);
  105 }
  106 
  107 static __inline void
  108 bintime_shift(struct bintime *_bt, int _exp)
  109 {
  110 
  111         if (_exp > 0) {
  112                 _bt->sec <<= _exp;
  113                 _bt->sec |= _bt->frac >> (64 - _exp);
  114                 _bt->frac <<= _exp;
  115         } else if (_exp < 0) {
  116                 _bt->frac >>= -_exp;
  117                 _bt->frac |= (uint64_t)_bt->sec << (64 + _exp);
  118                 _bt->sec >>= -_exp;
  119         }
  120 }
  121 
  122 #define bintime_clear(a)        ((a)->sec = (a)->frac = 0)
  123 #define bintime_isset(a)        ((a)->sec || (a)->frac)
  124 #define bintime_cmp(a, b, cmp)                                          \
  125         (((a)->sec == (b)->sec) ?                                       \
  126             ((a)->frac cmp (b)->frac) :                                 \
  127             ((a)->sec cmp (b)->sec))
  128 
  129 #define SBT_1S  ((sbintime_t)1 << 32)
  130 #define SBT_1M  (SBT_1S * 60)
  131 #define SBT_1MS (SBT_1S / 1000)
  132 #define SBT_1US (SBT_1S / 1000000)
  133 #define SBT_1NS (SBT_1S / 1000000000) /* beware rounding, see nstosbt() */
  134 #define SBT_MAX 0x7fffffffffffffffLL
  135 
  136 static __inline int
  137 sbintime_getsec(sbintime_t _sbt)
  138 {
  139 
  140         return (_sbt >> 32);
  141 }
  142 
  143 static __inline sbintime_t
  144 bttosbt(const struct bintime _bt)
  145 {
  146 
  147         return (((sbintime_t)_bt.sec << 32) + (_bt.frac >> 32));
  148 }
  149 
  150 static __inline struct bintime
  151 sbttobt(sbintime_t _sbt)
  152 {
  153         struct bintime _bt;
  154 
  155         _bt.sec = _sbt >> 32;
  156         _bt.frac = _sbt << 32;
  157         return (_bt);
  158 }
  159 
  160 /*
  161  * Decimal<->sbt conversions.  Multiplying or dividing by SBT_1NS results in
  162  * large roundoff errors which sbttons() and nstosbt() avoid.  Millisecond and
  163  * microsecond functions are also provided for completeness.
  164  *
  165  * These functions return the smallest sbt larger or equal to the
  166  * number of seconds requested so that sbttoX(Xtosbt(y)) == y.  Unlike
  167  * top of second computations below, which require that we tick at the
  168  * top of second, these need to be rounded up so we do whatever for at
  169  * least as long as requested.
  170  *
  171  * The naive computation we'd do is this
  172  *      ((unit * 2^64 / SIFACTOR) + 2^32-1) >> 32
  173  * However, that overflows. Instead, we compute
  174  *      ((unit * 2^63 / SIFACTOR) + 2^31-1) >> 32
  175  * and use pre-computed constants that are the ceil of the 2^63 / SIFACTOR
  176  * term to ensure we are using exactly the right constant. We use the lesser
  177  * evil of ull rather than a uint64_t cast to ensure we have well defined
  178  * right shift semantics. With these changes, we get all the ns, us and ms
  179  * conversions back and forth right.
  180  * Note: This file is used for both kernel and userland includes, so we can't
  181  * rely on KASSERT being defined, nor can we pollute the namespace by including
  182  * assert.h.
  183  */
  184 static __inline int64_t
  185 sbttons(sbintime_t _sbt)
  186 {
  187         uint64_t ns;
  188 
  189 #ifdef KASSERT
  190         KASSERT(_sbt >= 0, ("Negative values illegal for sbttons: %jx", _sbt));
  191 #endif
  192         ns = _sbt;
  193         if (ns >= SBT_1S)
  194                 ns = (ns >> 32) * 1000000000;
  195         else
  196                 ns = 0;
  197 
  198         return (ns + (1000000000 * (_sbt & 0xffffffffu) >> 32));
  199 }
  200 
  201 static __inline sbintime_t
  202 nstosbt(int64_t _ns)
  203 {
  204         sbintime_t sb = 0;
  205 
  206 #ifdef KASSERT
  207         KASSERT(_ns >= 0, ("Negative values illegal for nstosbt: %jd", _ns));
  208 #endif
  209         if (_ns >= SBT_1S) {
  210                 sb = (_ns / 1000000000) * SBT_1S;
  211                 _ns = _ns % 1000000000;
  212         }
  213         /* 9223372037 = ceil(2^63 / 1000000000) */
  214         sb += ((_ns * 9223372037ull) + 0x7fffffff) >> 31;
  215         return (sb);
  216 }
  217 
  218 static __inline int64_t
  219 sbttous(sbintime_t _sbt)
  220 {
  221 
  222         return ((1000000 * _sbt) >> 32);
  223 }
  224 
  225 static __inline sbintime_t
  226 ustosbt(int64_t _us)
  227 {
  228         sbintime_t sb = 0;
  229 
  230 #ifdef KASSERT
  231         KASSERT(_us >= 0, ("Negative values illegal for ustosbt: %jd", _us));
  232 #endif
  233         if (_us >= SBT_1S) {
  234                 sb = (_us / 1000000) * SBT_1S;
  235                 _us = _us % 1000000;
  236         }
  237         /* 9223372036855 = ceil(2^63 / 1000000) */
  238         sb += ((_us * 9223372036855ull) + 0x7fffffff) >> 31;
  239         return (sb);
  240 }
  241 
  242 static __inline int64_t
  243 sbttoms(sbintime_t _sbt)
  244 {
  245 
  246         return ((1000 * _sbt) >> 32);
  247 }
  248 
  249 static __inline sbintime_t
  250 mstosbt(int64_t _ms)
  251 {
  252         sbintime_t sb = 0;
  253 
  254 #ifdef KASSERT
  255         KASSERT(_ms >= 0, ("Negative values illegal for mstosbt: %jd", _ms));
  256 #endif
  257         if (_ms >= SBT_1S) {
  258                 sb = (_ms / 1000) * SBT_1S;
  259                 _ms = _ms % 1000;
  260         }
  261         /* 9223372036854776 = ceil(2^63 / 1000) */
  262         sb += ((_ms * 9223372036854776ull) + 0x7fffffff) >> 31;
  263         return (sb);
  264 }
  265 
  266 /*-
  267  * Background information:
  268  *
  269  * When converting between timestamps on parallel timescales of differing
  270  * resolutions it is historical and scientific practice to round down rather
  271  * than doing 4/5 rounding.
  272  *
  273  *   The date changes at midnight, not at noon.
  274  *
  275  *   Even at 15:59:59.999999999 it's not four'o'clock.
  276  *
  277  *   time_second ticks after N.999999999 not after N.4999999999
  278  */
  279 
  280 static __inline void
  281 bintime2timespec(const struct bintime *_bt, struct timespec *_ts)
  282 {
  283 
  284         _ts->tv_sec = _bt->sec;
  285         _ts->tv_nsec = ((uint64_t)1000000000 *
  286             (uint32_t)(_bt->frac >> 32)) >> 32;
  287 }
  288 
  289 static __inline void
  290 timespec2bintime(const struct timespec *_ts, struct bintime *_bt)
  291 {
  292 
  293         _bt->sec = _ts->tv_sec;
  294         /* 18446744073 = int(2^64 / 1000000000) */
  295         _bt->frac = _ts->tv_nsec * (uint64_t)18446744073LL;
  296 }
  297 
  298 static __inline void
  299 bintime2timeval(const struct bintime *_bt, struct timeval *_tv)
  300 {
  301 
  302         _tv->tv_sec = _bt->sec;
  303         _tv->tv_usec = ((uint64_t)1000000 * (uint32_t)(_bt->frac >> 32)) >> 32;
  304 }
  305 
  306 static __inline void
  307 timeval2bintime(const struct timeval *_tv, struct bintime *_bt)
  308 {
  309 
  310         _bt->sec = _tv->tv_sec;
  311         /* 18446744073709 = int(2^64 / 1000000) */
  312         _bt->frac = _tv->tv_usec * (uint64_t)18446744073709LL;
  313 }
  314 
  315 static __inline struct timespec
  316 sbttots(sbintime_t _sbt)
  317 {
  318         struct timespec _ts;
  319 
  320         _ts.tv_sec = _sbt >> 32;
  321         _ts.tv_nsec = sbttons((uint32_t)_sbt);
  322         return (_ts);
  323 }
  324 
  325 static __inline sbintime_t
  326 tstosbt(struct timespec _ts)
  327 {
  328 
  329         return (((sbintime_t)_ts.tv_sec << 32) + nstosbt(_ts.tv_nsec));
  330 }
  331 
  332 static __inline struct timeval
  333 sbttotv(sbintime_t _sbt)
  334 {
  335         struct timeval _tv;
  336 
  337         _tv.tv_sec = _sbt >> 32;
  338         _tv.tv_usec = sbttous((uint32_t)_sbt);
  339         return (_tv);
  340 }
  341 
  342 static __inline sbintime_t
  343 tvtosbt(struct timeval _tv)
  344 {
  345 
  346         return (((sbintime_t)_tv.tv_sec << 32) + ustosbt(_tv.tv_usec));
  347 }
  348 #endif /* __BSD_VISIBLE */
  349 
  350 #ifdef _KERNEL
  351 /*
  352  * Simple macros to convert ticks to milliseconds
  353  * or microseconds and vice-versa. The answer
  354  * will always be at least 1. Note the return
  355  * value is a uint32_t however we step up the
  356  * operations to 64 bit to avoid any overflow/underflow
  357  * problems.
  358  */
  359 #define TICKS_2_MSEC(t) max(1, (uint32_t)(hz == 1000) ? \
  360           (t) : (((uint64_t)(t) * (uint64_t)1000)/(uint64_t)hz))
  361 #define TICKS_2_USEC(t) max(1, (uint32_t)(hz == 1000) ? \
  362           ((t) * 1000) : (((uint64_t)(t) * (uint64_t)1000000)/(uint64_t)hz))
  363 #define MSEC_2_TICKS(m) max(1, (uint32_t)((hz == 1000) ? \
  364           (m) : ((uint64_t)(m) * (uint64_t)hz)/(uint64_t)1000))
  365 #define USEC_2_TICKS(u) max(1, (uint32_t)((hz == 1000) ? \
  366          ((u) / 1000) : ((uint64_t)(u) * (uint64_t)hz)/(uint64_t)1000000))
  367 
  368 #endif
  369 /* Operations on timespecs */
  370 #define timespecclear(tvp)      ((tvp)->tv_sec = (tvp)->tv_nsec = 0)
  371 #define timespecisset(tvp)      ((tvp)->tv_sec || (tvp)->tv_nsec)
  372 #define timespeccmp(tvp, uvp, cmp)                                      \
  373         (((tvp)->tv_sec == (uvp)->tv_sec) ?                             \
  374             ((tvp)->tv_nsec cmp (uvp)->tv_nsec) :                       \
  375             ((tvp)->tv_sec cmp (uvp)->tv_sec))
  376 
  377 #define timespecadd(tsp, usp, vsp)                                      \
  378         do {                                                            \
  379                 (vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec;          \
  380                 (vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec;       \
  381                 if ((vsp)->tv_nsec >= 1000000000L) {                    \
  382                         (vsp)->tv_sec++;                                \
  383                         (vsp)->tv_nsec -= 1000000000L;                  \
  384                 }                                                       \
  385         } while (0)
  386 #define timespecsub(tsp, usp, vsp)                                      \
  387         do {                                                            \
  388                 (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec;          \
  389                 (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec;       \
  390                 if ((vsp)->tv_nsec < 0) {                               \
  391                         (vsp)->tv_sec--;                                \
  392                         (vsp)->tv_nsec += 1000000000L;                  \
  393                 }                                                       \
  394         } while (0)
  395 
  396 #ifdef _KERNEL
  397 
  398 /* Operations on timevals. */
  399 
  400 #define timevalclear(tvp)               ((tvp)->tv_sec = (tvp)->tv_usec = 0)
  401 #define timevalisset(tvp)               ((tvp)->tv_sec || (tvp)->tv_usec)
  402 #define timevalcmp(tvp, uvp, cmp)                                       \
  403         (((tvp)->tv_sec == (uvp)->tv_sec) ?                             \
  404             ((tvp)->tv_usec cmp (uvp)->tv_usec) :                       \
  405             ((tvp)->tv_sec cmp (uvp)->tv_sec))
  406 
  407 /* timevaladd and timevalsub are not inlined */
  408 
  409 #endif /* _KERNEL */
  410 
  411 #ifndef _KERNEL                 /* NetBSD/OpenBSD compatible interfaces */
  412 
  413 #define timerclear(tvp)         ((tvp)->tv_sec = (tvp)->tv_usec = 0)
  414 #define timerisset(tvp)         ((tvp)->tv_sec || (tvp)->tv_usec)
  415 #define timercmp(tvp, uvp, cmp)                                 \
  416         (((tvp)->tv_sec == (uvp)->tv_sec) ?                             \
  417             ((tvp)->tv_usec cmp (uvp)->tv_usec) :                       \
  418             ((tvp)->tv_sec cmp (uvp)->tv_sec))
  419 #define timeradd(tvp, uvp, vvp)                                         \
  420         do {                                                            \
  421                 (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec;          \
  422                 (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec;       \
  423                 if ((vvp)->tv_usec >= 1000000) {                        \
  424                         (vvp)->tv_sec++;                                \
  425                         (vvp)->tv_usec -= 1000000;                      \
  426                 }                                                       \
  427         } while (0)
  428 #define timersub(tvp, uvp, vvp)                                         \
  429         do {                                                            \
  430                 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec;          \
  431                 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec;       \
  432                 if ((vvp)->tv_usec < 0) {                               \
  433                         (vvp)->tv_sec--;                                \
  434                         (vvp)->tv_usec += 1000000;                      \
  435                 }                                                       \
  436         } while (0)
  437 #endif
  438 
  439 /*
  440  * Names of the interval timers, and structure
  441  * defining a timer setting.
  442  */
  443 #define ITIMER_REAL     0
  444 #define ITIMER_VIRTUAL  1
  445 #define ITIMER_PROF     2
  446 
  447 struct itimerval {
  448         struct  timeval it_interval;    /* timer interval */
  449         struct  timeval it_value;       /* current value */
  450 };
  451 
  452 /*
  453  * Getkerninfo clock information structure
  454  */
  455 struct clockinfo {
  456         int     hz;             /* clock frequency */
  457         int     tick;           /* micro-seconds per hz tick */
  458         int     spare;
  459         int     stathz;         /* statistics clock frequency */
  460         int     profhz;         /* profiling clock frequency */
  461 };
  462 
  463 /* These macros are also in time.h. */
  464 #ifndef CLOCK_REALTIME
  465 #define CLOCK_REALTIME  0
  466 #define CLOCK_VIRTUAL   1
  467 #define CLOCK_PROF      2
  468 #define CLOCK_MONOTONIC 4
  469 #define CLOCK_UPTIME    5               /* FreeBSD-specific. */
  470 #define CLOCK_UPTIME_PRECISE    7       /* FreeBSD-specific. */
  471 #define CLOCK_UPTIME_FAST       8       /* FreeBSD-specific. */
  472 #define CLOCK_REALTIME_PRECISE  9       /* FreeBSD-specific. */
  473 #define CLOCK_REALTIME_FAST     10      /* FreeBSD-specific. */
  474 #define CLOCK_MONOTONIC_PRECISE 11      /* FreeBSD-specific. */
  475 #define CLOCK_MONOTONIC_FAST    12      /* FreeBSD-specific. */
  476 #define CLOCK_SECOND    13              /* FreeBSD-specific. */
  477 #define CLOCK_THREAD_CPUTIME_ID 14
  478 #define CLOCK_PROCESS_CPUTIME_ID        15
  479 #endif
  480 
  481 #ifndef TIMER_ABSTIME
  482 #define TIMER_RELTIME   0x0     /* relative timer */
  483 #define TIMER_ABSTIME   0x1     /* absolute timer */
  484 #endif
  485 
  486 #if __BSD_VISIBLE
  487 #define CPUCLOCK_WHICH_PID      0
  488 #define CPUCLOCK_WHICH_TID      1
  489 #endif
  490 
  491 #ifdef _KERNEL
  492 
  493 /*
  494  * Kernel to clock driver interface.
  495  */
  496 void    inittodr(time_t base);
  497 void    resettodr(void);
  498 
  499 extern volatile time_t  time_second;
  500 extern volatile time_t  time_uptime;
  501 extern struct bintime tc_tick_bt;
  502 extern sbintime_t tc_tick_sbt;
  503 extern struct bintime tick_bt;
  504 extern sbintime_t tick_sbt;
  505 extern int tc_precexp;
  506 extern int tc_timepercentage;
  507 extern struct bintime bt_timethreshold;
  508 extern struct bintime bt_tickthreshold;
  509 extern sbintime_t sbt_timethreshold;
  510 extern sbintime_t sbt_tickthreshold;
  511 
  512 extern volatile int rtc_generation;
  513 
  514 /*
  515  * Functions for looking at our clock: [get]{bin,nano,micro}[up]time()
  516  *
  517  * Functions without the "get" prefix returns the best timestamp
  518  * we can produce in the given format.
  519  *
  520  * "bin"   == struct bintime  == seconds + 64 bit fraction of seconds.
  521  * "nano"  == struct timespec == seconds + nanoseconds.
  522  * "micro" == struct timeval  == seconds + microseconds.
  523  *
  524  * Functions containing "up" returns time relative to boot and
  525  * should be used for calculating time intervals.
  526  *
  527  * Functions without "up" returns UTC time.
  528  *
  529  * Functions with the "get" prefix returns a less precise result
  530  * much faster than the functions without "get" prefix and should
  531  * be used where a precision of 1/hz seconds is acceptable or where
  532  * performance is priority. (NB: "precision", _not_ "resolution" !)
  533  */
  534 
  535 void    binuptime(struct bintime *bt);
  536 void    nanouptime(struct timespec *tsp);
  537 void    microuptime(struct timeval *tvp);
  538 
  539 static __inline sbintime_t
  540 sbinuptime(void)
  541 {
  542         struct bintime _bt;
  543 
  544         binuptime(&_bt);
  545         return (bttosbt(_bt));
  546 }
  547 
  548 void    bintime(struct bintime *bt);
  549 void    nanotime(struct timespec *tsp);
  550 void    microtime(struct timeval *tvp);
  551 
  552 void    getbinuptime(struct bintime *bt);
  553 void    getnanouptime(struct timespec *tsp);
  554 void    getmicrouptime(struct timeval *tvp);
  555 
  556 static __inline sbintime_t
  557 getsbinuptime(void)
  558 {
  559         struct bintime _bt;
  560 
  561         getbinuptime(&_bt);
  562         return (bttosbt(_bt));
  563 }
  564 
  565 void    getbintime(struct bintime *bt);
  566 void    getnanotime(struct timespec *tsp);
  567 void    getmicrotime(struct timeval *tvp);
  568 
  569 void    getboottime(struct timeval *boottime);
  570 void    getboottimebin(struct bintime *boottimebin);
  571 
  572 /* Other functions */
  573 int     itimerdecr(struct itimerval *itp, int usec);
  574 int     itimerfix(struct timeval *tv);
  575 int     ppsratecheck(struct timeval *, int *, int);
  576 int     ratecheck(struct timeval *, const struct timeval *);
  577 void    timevaladd(struct timeval *t1, const struct timeval *t2);
  578 void    timevalsub(struct timeval *t1, const struct timeval *t2);
  579 int     tvtohz(struct timeval *tv);
  580 
  581 #define TC_DEFAULTPERC          5
  582 
  583 #define BT2FREQ(bt)                                                     \
  584         (((uint64_t)0x8000000000000000 + ((bt)->frac >> 2)) /           \
  585             ((bt)->frac >> 1))
  586 
  587 #define SBT2FREQ(sbt)   ((SBT_1S + ((sbt) >> 1)) / (sbt))
  588 
  589 #define FREQ2BT(freq, bt)                                               \
  590 {                                                                       \
  591         (bt)->sec = 0;                                                  \
  592         (bt)->frac = ((uint64_t)0x8000000000000000  / (freq)) << 1;     \
  593 }
  594 
  595 #define TIMESEL(sbt, sbt2)                                              \
  596         (((sbt2) >= sbt_timethreshold) ?                                \
  597             ((*(sbt) = getsbinuptime()), 1) : ((*(sbt) = sbinuptime()), 0))
  598 
  599 #else /* !_KERNEL */
  600 #include <time.h>
  601 
  602 #include <sys/cdefs.h>
  603 #include <sys/select.h>
  604 
  605 __BEGIN_DECLS
  606 int     setitimer(int, const struct itimerval *, struct itimerval *);
  607 int     utimes(const char *, const struct timeval *);
  608 
  609 #if __BSD_VISIBLE
  610 int     adjtime(const struct timeval *, struct timeval *);
  611 int     clock_getcpuclockid2(id_t, int, clockid_t *);
  612 int     futimes(int, const struct timeval *);
  613 int     futimesat(int, const char *, const struct timeval [2]);
  614 int     lutimes(const char *, const struct timeval *);
  615 int     settimeofday(const struct timeval *, const struct timezone *);
  616 #endif
  617 
  618 #if __XSI_VISIBLE
  619 int     getitimer(int, struct itimerval *);
  620 int     gettimeofday(struct timeval *, struct timezone *);
  621 #endif
  622 
  623 __END_DECLS
  624 
  625 #endif /* !_KERNEL */
  626 
  627 #endif /* !_SYS_TIME_H_ */

Cache object: 53f2427634476d15f5f57a1b7afec00b


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.