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

Cache object: 11f7c18b7b373e8a9ba0d16d6a365a97


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