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-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
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$
   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 #include <sys/_clock_id.h>
   42 
   43 struct timezone {
   44         int     tz_minuteswest; /* minutes west of Greenwich */
   45         int     tz_dsttime;     /* type of dst correction */
   46 };
   47 #define DST_NONE        0       /* not on dst */
   48 #define DST_USA         1       /* USA style dst */
   49 #define DST_AUST        2       /* Australian style dst */
   50 #define DST_WET         3       /* Western European dst */
   51 #define DST_MET         4       /* Middle European dst */
   52 #define DST_EET         5       /* Eastern European dst */
   53 #define DST_CAN         6       /* Canada */
   54 
   55 #if __BSD_VISIBLE
   56 struct bintime {
   57         time_t  sec;
   58         uint64_t frac;
   59 };
   60 
   61 static __inline void
   62 bintime_addx(struct bintime *_bt, uint64_t _x)
   63 {
   64         uint64_t _u;
   65 
   66         _u = _bt->frac;
   67         _bt->frac += _x;
   68         if (_u > _bt->frac)
   69                 _bt->sec++;
   70 }
   71 
   72 static __inline void
   73 bintime_add(struct bintime *_bt, const struct bintime *_bt2)
   74 {
   75         uint64_t _u;
   76 
   77         _u = _bt->frac;
   78         _bt->frac += _bt2->frac;
   79         if (_u > _bt->frac)
   80                 _bt->sec++;
   81         _bt->sec += _bt2->sec;
   82 }
   83 
   84 static __inline void
   85 bintime_sub(struct bintime *_bt, const struct bintime *_bt2)
   86 {
   87         uint64_t _u;
   88 
   89         _u = _bt->frac;
   90         _bt->frac -= _bt2->frac;
   91         if (_u < _bt->frac)
   92                 _bt->sec--;
   93         _bt->sec -= _bt2->sec;
   94 }
   95 
   96 static __inline void
   97 bintime_mul(struct bintime *_bt, u_int _x)
   98 {
   99         uint64_t _p1, _p2;
  100 
  101         _p1 = (_bt->frac & 0xffffffffull) * _x;
  102         _p2 = (_bt->frac >> 32) * _x + (_p1 >> 32);
  103         _bt->sec *= _x;
  104         _bt->sec += (_p2 >> 32);
  105         _bt->frac = (_p2 << 32) | (_p1 & 0xffffffffull);
  106 }
  107 
  108 static __inline void
  109 bintime_shift(struct bintime *_bt, int _exp)
  110 {
  111 
  112         if (_exp > 0) {
  113                 _bt->sec <<= _exp;
  114                 _bt->sec |= _bt->frac >> (64 - _exp);
  115                 _bt->frac <<= _exp;
  116         } else if (_exp < 0) {
  117                 _bt->frac >>= -_exp;
  118                 _bt->frac |= (uint64_t)_bt->sec << (64 + _exp);
  119                 _bt->sec >>= -_exp;
  120         }
  121 }
  122 
  123 #define bintime_clear(a)        ((a)->sec = (a)->frac = 0)
  124 #define bintime_isset(a)        ((a)->sec || (a)->frac)
  125 #define bintime_cmp(a, b, cmp)                                          \
  126         (((a)->sec == (b)->sec) ?                                       \
  127             ((a)->frac cmp (b)->frac) :                                 \
  128             ((a)->sec cmp (b)->sec))
  129 
  130 #define SBT_1S  ((sbintime_t)1 << 32)
  131 #define SBT_1M  (SBT_1S * 60)
  132 #define SBT_1MS (SBT_1S / 1000)
  133 #define SBT_1US (SBT_1S / 1000000)
  134 #define SBT_1NS (SBT_1S / 1000000000) /* beware rounding, see nstosbt() */
  135 #define SBT_MAX 0x7fffffffffffffffLL
  136 
  137 static __inline int
  138 sbintime_getsec(sbintime_t _sbt)
  139 {
  140 
  141         return (_sbt >> 32);
  142 }
  143 
  144 static __inline sbintime_t
  145 bttosbt(const struct bintime _bt)
  146 {
  147 
  148         return (((sbintime_t)_bt.sec << 32) + (_bt.frac >> 32));
  149 }
  150 
  151 static __inline struct bintime
  152 sbttobt(sbintime_t _sbt)
  153 {
  154         struct bintime _bt;
  155 
  156         _bt.sec = _sbt >> 32;
  157         _bt.frac = _sbt << 32;
  158         return (_bt);
  159 }
  160 
  161 /*
  162  * Scaling functions for signed and unsigned 64-bit time using any
  163  * 32-bit fraction:
  164  */
  165 
  166 static __inline int64_t
  167 __stime64_scale32_ceil(int64_t x, int32_t factor, int32_t divisor)
  168 {
  169         const int64_t rem = x % divisor;
  170 
  171         return (x / divisor * factor + (rem * factor + divisor - 1) / divisor);
  172 }
  173 
  174 static __inline int64_t
  175 __stime64_scale32_floor(int64_t x, int32_t factor, int32_t divisor)
  176 {
  177         const int64_t rem = x % divisor;
  178 
  179         return (x / divisor * factor + (rem * factor) / divisor);
  180 }
  181 
  182 static __inline uint64_t
  183 __utime64_scale32_ceil(uint64_t x, uint32_t factor, uint32_t divisor)
  184 {
  185         const uint64_t rem = x % divisor;
  186 
  187         return (x / divisor * factor + (rem * factor + divisor - 1) / divisor);
  188 }
  189 
  190 static __inline uint64_t
  191 __utime64_scale32_floor(uint64_t x, uint32_t factor, uint32_t divisor)
  192 {
  193         const uint64_t rem = x % divisor;
  194 
  195         return (x / divisor * factor + (rem * factor) / divisor);
  196 }
  197 
  198 /*
  199  * This function finds the common divisor between the two arguments,
  200  * in powers of two. Use a macro, so the compiler will output a
  201  * warning if the value overflows!
  202  *
  203  * Detailed description:
  204  *
  205  * Create a variable with 1's at the positions of the leading 0's
  206  * starting at the least significant bit, producing 0 if none (e.g.,
  207  * 01011000 -> 0000 0111). Then these two variables are bitwise AND'ed
  208  * together, to produce the greatest common power of two minus one. In
  209  * the end add one to flip the value to the actual power of two (e.g.,
  210  * 0000 0111 + 1 -> 0000 1000).
  211  */
  212 #define __common_powers_of_two(a, b) \
  213         ((~(a) & ((a) - 1) & ~(b) & ((b) - 1)) + 1)
  214 
  215 /*
  216  * Scaling functions for signed and unsigned 64-bit time assuming
  217  * reducable 64-bit fractions to 32-bit fractions:
  218  */
  219 
  220 static __inline int64_t
  221 __stime64_scale64_ceil(int64_t x, int64_t factor, int64_t divisor)
  222 {
  223         const int64_t gcd = __common_powers_of_two(factor, divisor);
  224 
  225         return (__stime64_scale32_ceil(x, factor / gcd, divisor / gcd));
  226 }
  227 
  228 static __inline int64_t
  229 __stime64_scale64_floor(int64_t x, int64_t factor, int64_t divisor)
  230 {
  231         const int64_t gcd = __common_powers_of_two(factor, divisor);
  232 
  233         return (__stime64_scale32_floor(x, factor / gcd, divisor / gcd));
  234 }
  235 
  236 static __inline uint64_t
  237 __utime64_scale64_ceil(uint64_t x, uint64_t factor, uint64_t divisor)
  238 {
  239         const uint64_t gcd = __common_powers_of_two(factor, divisor);
  240 
  241         return (__utime64_scale32_ceil(x, factor / gcd, divisor / gcd));
  242 }
  243 
  244 static __inline uint64_t
  245 __utime64_scale64_floor(uint64_t x, uint64_t factor, uint64_t divisor)
  246 {
  247         const uint64_t gcd = __common_powers_of_two(factor, divisor);
  248 
  249         return (__utime64_scale32_floor(x, factor / gcd, divisor / gcd));
  250 }
  251 
  252 /*
  253  * Decimal<->sbt conversions. Multiplying or dividing by SBT_1NS
  254  * results in large roundoff errors which sbttons() and nstosbt()
  255  * avoid. Millisecond and microsecond functions are also provided for
  256  * completeness.
  257  *
  258  * When converting from sbt to another unit, the result is always
  259  * rounded down. When converting back to sbt the result is always
  260  * rounded up. This gives the property that sbttoX(Xtosbt(y)) == y .
  261  *
  262  * The conversion functions can also handle negative values.
  263  */
  264 #define SBT_DECLARE_CONVERSION_PAIR(name, units_per_second)     \
  265 static __inline int64_t \
  266 sbtto##name(sbintime_t sbt) \
  267 { \
  268         return (__stime64_scale64_floor(sbt, units_per_second, SBT_1S)); \
  269 } \
  270 static __inline sbintime_t \
  271 name##tosbt(int64_t name) \
  272 { \
  273         return (__stime64_scale64_ceil(name, SBT_1S, units_per_second)); \
  274 }
  275 
  276 SBT_DECLARE_CONVERSION_PAIR(ns, 1000000000)
  277 SBT_DECLARE_CONVERSION_PAIR(us, 1000000)
  278 SBT_DECLARE_CONVERSION_PAIR(ms, 1000)
  279 
  280 /*-
  281  * Background information:
  282  *
  283  * When converting between timestamps on parallel timescales of differing
  284  * resolutions it is historical and scientific practice to round down rather
  285  * than doing 4/5 rounding.
  286  *
  287  *   The date changes at midnight, not at noon.
  288  *
  289  *   Even at 15:59:59.999999999 it's not four'o'clock.
  290  *
  291  *   time_second ticks after N.999999999 not after N.4999999999
  292  */
  293 
  294 static __inline void
  295 bintime2timespec(const struct bintime *_bt, struct timespec *_ts)
  296 {
  297 
  298         _ts->tv_sec = _bt->sec;
  299         _ts->tv_nsec = __utime64_scale64_floor(
  300             _bt->frac, 1000000000, 1ULL << 32) >> 32;
  301 }
  302 
  303 static __inline uint64_t
  304 bintime2ns(const struct bintime *_bt)
  305 {
  306         uint64_t ret;
  307 
  308         ret = (uint64_t)(_bt->sec) * (uint64_t)1000000000;
  309         ret += __utime64_scale64_floor(
  310             _bt->frac, 1000000000, 1ULL << 32) >> 32;
  311         return (ret);
  312 }
  313 
  314 static __inline void
  315 timespec2bintime(const struct timespec *_ts, struct bintime *_bt)
  316 {
  317 
  318         _bt->sec = _ts->tv_sec;
  319         _bt->frac = __utime64_scale64_floor(
  320             (uint64_t)_ts->tv_nsec << 32, 1ULL << 32, 1000000000);
  321 }
  322 
  323 static __inline void
  324 bintime2timeval(const struct bintime *_bt, struct timeval *_tv)
  325 {
  326 
  327         _tv->tv_sec = _bt->sec;
  328         _tv->tv_usec = __utime64_scale64_floor(
  329             _bt->frac, 1000000, 1ULL << 32) >> 32;
  330 }
  331 
  332 static __inline void
  333 timeval2bintime(const struct timeval *_tv, struct bintime *_bt)
  334 {
  335 
  336         _bt->sec = _tv->tv_sec;
  337         _bt->frac = __utime64_scale64_floor(
  338             (uint64_t)_tv->tv_usec << 32, 1ULL << 32, 1000000);
  339 }
  340 
  341 static __inline struct timespec
  342 sbttots(sbintime_t _sbt)
  343 {
  344         struct timespec _ts;
  345 
  346         _ts.tv_sec = _sbt >> 32;
  347         _ts.tv_nsec = sbttons((uint32_t)_sbt);
  348         return (_ts);
  349 }
  350 
  351 static __inline sbintime_t
  352 tstosbt(struct timespec _ts)
  353 {
  354 
  355         return (((sbintime_t)_ts.tv_sec << 32) + nstosbt(_ts.tv_nsec));
  356 }
  357 
  358 static __inline struct timeval
  359 sbttotv(sbintime_t _sbt)
  360 {
  361         struct timeval _tv;
  362 
  363         _tv.tv_sec = _sbt >> 32;
  364         _tv.tv_usec = sbttous((uint32_t)_sbt);
  365         return (_tv);
  366 }
  367 
  368 static __inline sbintime_t
  369 tvtosbt(struct timeval _tv)
  370 {
  371 
  372         return (((sbintime_t)_tv.tv_sec << 32) + ustosbt(_tv.tv_usec));
  373 }
  374 #endif /* __BSD_VISIBLE */
  375 
  376 #ifdef _KERNEL
  377 /*
  378  * Simple macros to convert ticks to milliseconds
  379  * or microseconds and vice-versa. The answer
  380  * will always be at least 1. Note the return
  381  * value is a uint32_t however we step up the
  382  * operations to 64 bit to avoid any overflow/underflow
  383  * problems.
  384  */
  385 #define TICKS_2_MSEC(t) max(1, (uint32_t)(hz == 1000) ? \
  386           (t) : (((uint64_t)(t) * (uint64_t)1000)/(uint64_t)hz))
  387 #define TICKS_2_USEC(t) max(1, (uint32_t)(hz == 1000) ? \
  388           ((t) * 1000) : (((uint64_t)(t) * (uint64_t)1000000)/(uint64_t)hz))
  389 #define MSEC_2_TICKS(m) max(1, (uint32_t)((hz == 1000) ? \
  390           (m) : ((uint64_t)(m) * (uint64_t)hz)/(uint64_t)1000))
  391 #define USEC_2_TICKS(u) max(1, (uint32_t)((hz == 1000) ? \
  392          ((u) / 1000) : ((uint64_t)(u) * (uint64_t)hz)/(uint64_t)1000000))
  393 
  394 #endif
  395 /* Operations on timespecs */
  396 #define timespecclear(tvp)      ((tvp)->tv_sec = (tvp)->tv_nsec = 0)
  397 #define timespecisset(tvp)      ((tvp)->tv_sec || (tvp)->tv_nsec)
  398 #define timespeccmp(tvp, uvp, cmp)                                      \
  399         (((tvp)->tv_sec == (uvp)->tv_sec) ?                             \
  400             ((tvp)->tv_nsec cmp (uvp)->tv_nsec) :                       \
  401             ((tvp)->tv_sec cmp (uvp)->tv_sec))
  402 
  403 #define timespecadd(tsp, usp, vsp)                                      \
  404         do {                                                            \
  405                 (vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec;          \
  406                 (vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec;       \
  407                 if ((vsp)->tv_nsec >= 1000000000L) {                    \
  408                         (vsp)->tv_sec++;                                \
  409                         (vsp)->tv_nsec -= 1000000000L;                  \
  410                 }                                                       \
  411         } while (0)
  412 #define timespecsub(tsp, usp, vsp)                                      \
  413         do {                                                            \
  414                 (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec;          \
  415                 (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec;       \
  416                 if ((vsp)->tv_nsec < 0) {                               \
  417                         (vsp)->tv_sec--;                                \
  418                         (vsp)->tv_nsec += 1000000000L;                  \
  419                 }                                                       \
  420         } while (0)
  421 #define timespecvalid_interval(tsp)     ((tsp)->tv_sec >= 0 &&          \
  422             (tsp)->tv_nsec >= 0 && (tsp)->tv_nsec < 1000000000L)
  423 
  424 #ifdef _KERNEL
  425 
  426 /* Operations on timevals. */
  427 
  428 #define timevalclear(tvp)               ((tvp)->tv_sec = (tvp)->tv_usec = 0)
  429 #define timevalisset(tvp)               ((tvp)->tv_sec || (tvp)->tv_usec)
  430 #define timevalcmp(tvp, uvp, cmp)                                       \
  431         (((tvp)->tv_sec == (uvp)->tv_sec) ?                             \
  432             ((tvp)->tv_usec cmp (uvp)->tv_usec) :                       \
  433             ((tvp)->tv_sec cmp (uvp)->tv_sec))
  434 
  435 /* timevaladd and timevalsub are not inlined */
  436 
  437 #endif /* _KERNEL */
  438 
  439 #ifndef _KERNEL                 /* NetBSD/OpenBSD compatible interfaces */
  440 
  441 #define timerclear(tvp)         ((tvp)->tv_sec = (tvp)->tv_usec = 0)
  442 #define timerisset(tvp)         ((tvp)->tv_sec || (tvp)->tv_usec)
  443 #define timercmp(tvp, uvp, cmp)                                 \
  444         (((tvp)->tv_sec == (uvp)->tv_sec) ?                             \
  445             ((tvp)->tv_usec cmp (uvp)->tv_usec) :                       \
  446             ((tvp)->tv_sec cmp (uvp)->tv_sec))
  447 #define timeradd(tvp, uvp, vvp)                                         \
  448         do {                                                            \
  449                 (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec;          \
  450                 (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec;       \
  451                 if ((vvp)->tv_usec >= 1000000) {                        \
  452                         (vvp)->tv_sec++;                                \
  453                         (vvp)->tv_usec -= 1000000;                      \
  454                 }                                                       \
  455         } while (0)
  456 #define timersub(tvp, uvp, vvp)                                         \
  457         do {                                                            \
  458                 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec;          \
  459                 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec;       \
  460                 if ((vvp)->tv_usec < 0) {                               \
  461                         (vvp)->tv_sec--;                                \
  462                         (vvp)->tv_usec += 1000000;                      \
  463                 }                                                       \
  464         } while (0)
  465 #endif
  466 
  467 /*
  468  * Names of the interval timers, and structure
  469  * defining a timer setting.
  470  */
  471 #define ITIMER_REAL     0
  472 #define ITIMER_VIRTUAL  1
  473 #define ITIMER_PROF     2
  474 
  475 struct itimerval {
  476         struct  timeval it_interval;    /* timer interval */
  477         struct  timeval it_value;       /* current value */
  478 };
  479 
  480 /*
  481  * Getkerninfo clock information structure
  482  */
  483 struct clockinfo {
  484         int     hz;             /* clock frequency */
  485         int     tick;           /* micro-seconds per hz tick */
  486         int     spare;
  487         int     stathz;         /* statistics clock frequency */
  488         int     profhz;         /* profiling clock frequency */
  489 };
  490 
  491 #if __BSD_VISIBLE
  492 #define CPUCLOCK_WHICH_PID      0
  493 #define CPUCLOCK_WHICH_TID      1
  494 #endif
  495 
  496 #if defined(_KERNEL) || defined(_STANDALONE)
  497 
  498 /*
  499  * Kernel to clock driver interface.
  500  */
  501 void    inittodr(time_t base);
  502 void    resettodr(void);
  503 
  504 extern volatile time_t  time_second;
  505 extern volatile time_t  time_uptime;
  506 extern struct bintime tc_tick_bt;
  507 extern sbintime_t tc_tick_sbt;
  508 extern time_t tick_seconds_max;
  509 extern struct bintime tick_bt;
  510 extern sbintime_t tick_sbt;
  511 extern int tc_precexp;
  512 extern int tc_timepercentage;
  513 extern struct bintime bt_timethreshold;
  514 extern struct bintime bt_tickthreshold;
  515 extern sbintime_t sbt_timethreshold;
  516 extern sbintime_t sbt_tickthreshold;
  517 
  518 extern volatile int rtc_generation;
  519 
  520 /*
  521  * Functions for looking at our clock: [get]{bin,nano,micro}[up]time()
  522  *
  523  * Functions without the "get" prefix returns the best timestamp
  524  * we can produce in the given format.
  525  *
  526  * "bin"   == struct bintime  == seconds + 64 bit fraction of seconds.
  527  * "nano"  == struct timespec == seconds + nanoseconds.
  528  * "micro" == struct timeval  == seconds + microseconds.
  529  *
  530  * Functions containing "up" returns time relative to boot and
  531  * should be used for calculating time intervals.
  532  *
  533  * Functions without "up" returns UTC time.
  534  *
  535  * Functions with the "get" prefix returns a less precise result
  536  * much faster than the functions without "get" prefix and should
  537  * be used where a precision of 1/hz seconds is acceptable or where
  538  * performance is priority. (NB: "precision", _not_ "resolution" !)
  539  */
  540 
  541 void    binuptime(struct bintime *bt);
  542 void    nanouptime(struct timespec *tsp);
  543 void    microuptime(struct timeval *tvp);
  544 
  545 static __inline sbintime_t
  546 sbinuptime(void)
  547 {
  548         struct bintime _bt;
  549 
  550         binuptime(&_bt);
  551         return (bttosbt(_bt));
  552 }
  553 
  554 void    bintime(struct bintime *bt);
  555 void    nanotime(struct timespec *tsp);
  556 void    microtime(struct timeval *tvp);
  557 
  558 void    getbinuptime(struct bintime *bt);
  559 void    getnanouptime(struct timespec *tsp);
  560 void    getmicrouptime(struct timeval *tvp);
  561 
  562 static __inline sbintime_t
  563 getsbinuptime(void)
  564 {
  565         struct bintime _bt;
  566 
  567         getbinuptime(&_bt);
  568         return (bttosbt(_bt));
  569 }
  570 
  571 void    getbintime(struct bintime *bt);
  572 void    getnanotime(struct timespec *tsp);
  573 void    getmicrotime(struct timeval *tvp);
  574 
  575 void    getboottime(struct timeval *boottime);
  576 void    getboottimebin(struct bintime *boottimebin);
  577 
  578 /* Other functions */
  579 int     itimerdecr(struct itimerval *itp, int usec);
  580 int     itimerfix(struct timeval *tv);
  581 int     ppsratecheck(struct timeval *, int *, int);
  582 int     ratecheck(struct timeval *, const struct timeval *);
  583 void    timevaladd(struct timeval *t1, const struct timeval *t2);
  584 void    timevalsub(struct timeval *t1, const struct timeval *t2);
  585 int     tvtohz(struct timeval *tv);
  586 
  587 /*
  588  * The following HZ limits allow the tvtohz() function
  589  * to only use integer computations.
  590  */
  591 #define HZ_MAXIMUM (INT_MAX / (1000000 >> 6)) /* 137kHz */
  592 #define HZ_MINIMUM 8 /* hz */
  593 
  594 #define TC_DEFAULTPERC          5
  595 
  596 #define BT2FREQ(bt)                                                     \
  597         (((uint64_t)0x8000000000000000 + ((bt)->frac >> 2)) /           \
  598             ((bt)->frac >> 1))
  599 
  600 #define SBT2FREQ(sbt)   ((SBT_1S + ((sbt) >> 1)) / (sbt))
  601 
  602 #define FREQ2BT(freq, bt)                                               \
  603 {                                                                       \
  604         (bt)->sec = 0;                                                  \
  605         (bt)->frac = ((uint64_t)0x8000000000000000  / (freq)) << 1;     \
  606 }
  607 
  608 #define TIMESEL(sbt, sbt2)                                              \
  609         (((sbt2) >= sbt_timethreshold) ?                                \
  610             ((*(sbt) = getsbinuptime()), 1) : ((*(sbt) = sbinuptime()), 0))
  611 
  612 #else /* !_KERNEL && !_STANDALONE */
  613 #include <time.h>
  614 
  615 #include <sys/cdefs.h>
  616 #include <sys/select.h>
  617 
  618 __BEGIN_DECLS
  619 int     setitimer(int, const struct itimerval *, struct itimerval *);
  620 int     utimes(const char *, const struct timeval *);
  621 
  622 #if __BSD_VISIBLE
  623 int     adjtime(const struct timeval *, struct timeval *);
  624 int     clock_getcpuclockid2(id_t, int, clockid_t *);
  625 int     futimes(int, const struct timeval *);
  626 int     futimesat(int, const char *, const struct timeval [2]);
  627 int     lutimes(const char *, const struct timeval *);
  628 int     settimeofday(const struct timeval *, const struct timezone *);
  629 #endif
  630 
  631 #if __XSI_VISIBLE
  632 int     getitimer(int, struct itimerval *);
  633 int     gettimeofday(struct timeval *, struct timezone *);
  634 #endif
  635 
  636 __END_DECLS
  637 
  638 #endif /* !_KERNEL */
  639 
  640 #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.