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  * Copyright (c) 1982, 1986, 1993
    3  *      The Regents of the University of California.  All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  * 1. Redistributions of source code must retain the above copyright
    9  *    notice, this list of conditions and the following disclaimer.
   10  * 2. Redistributions in binary form must reproduce the above copyright
   11  *    notice, this list of conditions and the following disclaimer in the
   12  *    documentation and/or other materials provided with the distribution.
   13  * 3. All advertising materials mentioning features or use of this software
   14  *    must display the following acknowledgement:
   15  *      This product includes software developed by the University of
   16  *      California, Berkeley and its contributors.
   17  * 4. Neither the name of the University nor the names of its contributors
   18  *    may be used to endorse or promote products derived from this software
   19  *    without specific prior written permission.
   20  *
   21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   31  * SUCH DAMAGE.
   32  *
   33  *      @(#)time.h      8.5 (Berkeley) 5/4/95
   34  * $FreeBSD: releng/5.2/sys/sys/time.h 121524 2003-10-26 02:38:34Z alfred $
   35  */
   36 
   37 #ifndef _SYS_TIME_H_
   38 #define _SYS_TIME_H_
   39 
   40 #include <sys/_timeval.h>
   41 #include <sys/types.h>
   42 #include <sys/timespec.h>
   43 
   44 struct timezone {
   45         int     tz_minuteswest; /* minutes west of Greenwich */
   46         int     tz_dsttime;     /* type of dst correction */
   47 };
   48 #define DST_NONE        0       /* not on dst */
   49 #define DST_USA         1       /* USA style dst */
   50 #define DST_AUST        2       /* Australian style dst */
   51 #define DST_WET         3       /* Western European dst */
   52 #define DST_MET         4       /* Middle European dst */
   53 #define DST_EET         5       /* Eastern European dst */
   54 #define DST_CAN         6       /* Canada */
   55 
   56 #if __BSD_VISIBLE
   57 struct bintime {
   58         time_t  sec;
   59         uint64_t frac;
   60 };
   61 
   62 static __inline void
   63 bintime_addx(struct bintime *bt, uint64_t x)
   64 {
   65         uint64_t u;
   66 
   67         u = bt->frac;
   68         bt->frac += x;
   69         if (u > bt->frac)
   70                 bt->sec++;
   71 }
   72 
   73 static __inline void
   74 bintime_add(struct bintime *bt, const struct bintime *bt2)
   75 {
   76         uint64_t u;
   77 
   78         u = bt->frac;
   79         bt->frac += bt2->frac;
   80         if (u > bt->frac)
   81                 bt->sec++;
   82         bt->sec += bt2->sec;
   83 }
   84 
   85 static __inline void
   86 bintime_sub(struct bintime *bt, const struct bintime *bt2)
   87 {
   88         uint64_t u;
   89 
   90         u = bt->frac;
   91         bt->frac -= bt2->frac;
   92         if (u < bt->frac)
   93                 bt->sec--;
   94         bt->sec -= bt2->sec;
   95 }
   96 
   97 /*-
   98  * Background information:
   99  *
  100  * When converting between timestamps on parallel timescales of differing
  101  * resolutions it is historical and scientific practice to round down rather
  102  * than doing 4/5 rounding.
  103  *
  104  *   The date changes at midnight, not at noon.
  105  *
  106  *   Even at 15:59:59.999999999 it's not four'o'clock.
  107  *
  108  *   time_second ticks after N.999999999 not after N.4999999999
  109  */
  110 
  111 static __inline void
  112 bintime2timespec(const struct bintime *bt, struct timespec *ts)
  113 {
  114 
  115         ts->tv_sec = bt->sec;
  116         ts->tv_nsec = ((uint64_t)1000000000 * (uint32_t)(bt->frac >> 32)) >> 32;
  117 }
  118 
  119 static __inline void
  120 timespec2bintime(const struct timespec *ts, struct bintime *bt)
  121 {
  122 
  123         bt->sec = ts->tv_sec;
  124         /* 18446744073 = int(2^64 / 1000000000) */
  125         bt->frac = ts->tv_nsec * (uint64_t)18446744073LL; 
  126 }
  127 
  128 static __inline void
  129 bintime2timeval(const struct bintime *bt, struct timeval *tv)
  130 {
  131 
  132         tv->tv_sec = bt->sec;
  133         tv->tv_usec = ((uint64_t)1000000 * (uint32_t)(bt->frac >> 32)) >> 32;
  134 }
  135 
  136 static __inline void
  137 timeval2bintime(const struct timeval *tv, struct bintime *bt)
  138 {
  139 
  140         bt->sec = tv->tv_sec;
  141         /* 18446744073709 = int(2^64 / 1000000) */
  142         bt->frac = tv->tv_usec * (uint64_t)18446744073709LL;
  143 }
  144 #endif /* __BSD_VISIBLE */
  145 
  146 #ifdef _KERNEL
  147 
  148 /* Operations on timespecs */
  149 #define timespecclear(tvp)      ((tvp)->tv_sec = (tvp)->tv_nsec = 0)
  150 #define timespecisset(tvp)      ((tvp)->tv_sec || (tvp)->tv_nsec)
  151 #define timespeccmp(tvp, uvp, cmp)                                      \
  152         (((tvp)->tv_sec == (uvp)->tv_sec) ?                             \
  153             ((tvp)->tv_nsec cmp (uvp)->tv_nsec) :                       \
  154             ((tvp)->tv_sec cmp (uvp)->tv_sec))
  155 #define timespecadd(vvp, uvp)                                           \
  156         do {                                                            \
  157                 (vvp)->tv_sec += (uvp)->tv_sec;                         \
  158                 (vvp)->tv_nsec += (uvp)->tv_nsec;                       \
  159                 if ((vvp)->tv_nsec >= 1000000000) {                     \
  160                         (vvp)->tv_sec++;                                \
  161                         (vvp)->tv_nsec -= 1000000000;                   \
  162                 }                                                       \
  163         } while (0)
  164 #define timespecsub(vvp, uvp)                                           \
  165         do {                                                            \
  166                 (vvp)->tv_sec -= (uvp)->tv_sec;                         \
  167                 (vvp)->tv_nsec -= (uvp)->tv_nsec;                       \
  168                 if ((vvp)->tv_nsec < 0) {                               \
  169                         (vvp)->tv_sec--;                                \
  170                         (vvp)->tv_nsec += 1000000000;                   \
  171                 }                                                       \
  172         } while (0)
  173 
  174 /* Operations on timevals. */
  175 
  176 #define timevalclear(tvp)               ((tvp)->tv_sec = (tvp)->tv_usec = 0)
  177 #define timevalisset(tvp)               ((tvp)->tv_sec || (tvp)->tv_usec)
  178 #define timevalcmp(tvp, uvp, cmp)                                       \
  179         (((tvp)->tv_sec == (uvp)->tv_sec) ?                             \
  180             ((tvp)->tv_usec cmp (uvp)->tv_usec) :                       \
  181             ((tvp)->tv_sec cmp (uvp)->tv_sec))
  182 
  183 /* timevaladd and timevalsub are not inlined */
  184 
  185 #endif /* _KERNEL */
  186 
  187 #ifndef _KERNEL                 /* NetBSD/OpenBSD compatible interfaces */
  188 
  189 #define timerclear(tvp)         ((tvp)->tv_sec = (tvp)->tv_usec = 0)
  190 #define timerisset(tvp)         ((tvp)->tv_sec || (tvp)->tv_usec)
  191 #define timercmp(tvp, uvp, cmp)                                 \
  192         (((tvp)->tv_sec == (uvp)->tv_sec) ?                             \
  193             ((tvp)->tv_usec cmp (uvp)->tv_usec) :                       \
  194             ((tvp)->tv_sec cmp (uvp)->tv_sec))
  195 #define timeradd(tvp, uvp, vvp)                                         \
  196         do {                                                            \
  197                 (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec;          \
  198                 (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec;       \
  199                 if ((vvp)->tv_usec >= 1000000) {                        \
  200                         (vvp)->tv_sec++;                                \
  201                         (vvp)->tv_usec -= 1000000;                      \
  202                 }                                                       \
  203         } while (0)
  204 #define timersub(tvp, uvp, vvp)                                         \
  205         do {                                                            \
  206                 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec;          \
  207                 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec;       \
  208                 if ((vvp)->tv_usec < 0) {                               \
  209                         (vvp)->tv_sec--;                                \
  210                         (vvp)->tv_usec += 1000000;                      \
  211                 }                                                       \
  212         } while (0)
  213 #endif
  214 
  215 /*
  216  * Names of the interval timers, and structure
  217  * defining a timer setting.
  218  */
  219 #define ITIMER_REAL     0
  220 #define ITIMER_VIRTUAL  1
  221 #define ITIMER_PROF     2
  222 
  223 struct itimerval {
  224         struct  timeval it_interval;    /* timer interval */
  225         struct  timeval it_value;       /* current value */
  226 };
  227 
  228 /*
  229  * Getkerninfo clock information structure
  230  */
  231 struct clockinfo {
  232         int     hz;             /* clock frequency */
  233         int     tick;           /* micro-seconds per hz tick */
  234         int     spare;
  235         int     stathz;         /* statistics clock frequency */
  236         int     profhz;         /* profiling clock frequency */
  237 };
  238 
  239 /* CLOCK_REALTIME and TIMER_ABSTIME are supposed to be in time.h */
  240 
  241 #ifndef CLOCK_REALTIME
  242 #define CLOCK_REALTIME  0
  243 #endif
  244 #define CLOCK_VIRTUAL   1
  245 #define CLOCK_PROF      2
  246 #define CLOCK_MONOTONIC 4
  247 
  248 #define TIMER_RELTIME   0x0     /* relative timer */
  249 #ifndef TIMER_ABSTIME
  250 #define TIMER_ABSTIME   0x1     /* absolute timer */
  251 #endif
  252 
  253 #ifdef _KERNEL
  254 extern time_t   time_second;
  255 extern time_t   time_uptime;
  256 
  257 /*
  258  * Functions for looking at our clock: [get]{bin,nano,micro}[up]time()
  259  *
  260  * Functions without the "get" prefix returns the best timestamp
  261  * we can produce in the given format.
  262  *
  263  * "bin"   == struct bintime  == seconds + 64 bit fraction of seconds.
  264  * "nano"  == struct timespec == seconds + nanoseconds.
  265  * "micro" == struct timeval  == seconds + microseconds.
  266  *              
  267  * Functions containing "up" returns time relative to boot and
  268  * should be used for calculating time intervals.
  269  *
  270  * Functions without "up" returns GMT time.
  271  *
  272  * Functions with the "get" prefix returns a less precise result
  273  * much faster than the functions without "get" prefix and should
  274  * be used where a precision of 10 msec is acceptable or where
  275  * performance is priority. (NB: "precision", _not_ "resolution" !) 
  276  * 
  277  */
  278 
  279 void    binuptime(struct bintime *bt);
  280 void    nanouptime(struct timespec *tsp);
  281 void    microuptime(struct timeval *tvp);
  282 
  283 void    bintime(struct bintime *bt);
  284 void    nanotime(struct timespec *tsp);
  285 void    microtime(struct timeval *tvp);
  286 
  287 void    getbinuptime(struct bintime *bt);
  288 void    getnanouptime(struct timespec *tsp);
  289 void    getmicrouptime(struct timeval *tvp);
  290 
  291 void    getbintime(struct bintime *bt);
  292 void    getnanotime(struct timespec *tsp);
  293 void    getmicrotime(struct timeval *tvp);
  294 
  295 /* Other functions */
  296 int     itimerdecr(struct itimerval *itp, int usec);
  297 int     itimerfix(struct timeval *tv);
  298 int     ppsratecheck(struct timeval *, int *, int);
  299 int     ratecheck(struct timeval *, const struct timeval *);
  300 void    timevaladd(struct timeval *t1, const struct timeval *t2);
  301 void    timevalsub(struct timeval *t1, const struct timeval *t2);
  302 int     tvtohz(struct timeval *tv);
  303 #else /* !_KERNEL */
  304 #include <time.h>
  305 
  306 #include <sys/cdefs.h>
  307 
  308 __BEGIN_DECLS
  309 int     adjtime(const struct timeval *, struct timeval *);
  310 int     futimes(int, const struct timeval *);
  311 int     getitimer(int, struct itimerval *);
  312 int     gettimeofday(struct timeval *, struct timezone *);
  313 int     lutimes(const char *, const struct timeval *);
  314 int     setitimer(int, const struct itimerval *, struct itimerval *);
  315 int     settimeofday(const struct timeval *, const struct timezone *);
  316 int     utimes(const char *, const struct timeval *);
  317 __END_DECLS
  318 
  319 #endif /* !_KERNEL */
  320 
  321 #endif /* !_SYS_TIME_H_ */

Cache object: 5fe8859c0655f2c3cdc65edcbe6db062


[ 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.