Linux kernel & device driver programming

Cross-Referenced Linux and Device Driver Code

[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ]
Version: [ 2.6.11.8 ] [ 2.6.25 ] [ 2.6.25.8 ] [ 2.6.31.13 ] Architecture: [ i386 ]
  1 #ifndef _LINUX_TIME_H
  2 #define _LINUX_TIME_H
  3 
  4 #include <linux/types.h>
  5 
  6 #ifdef __KERNEL__
  7 #include <linux/seqlock.h>
  8 #endif
  9 
 10 #ifndef _STRUCT_TIMESPEC
 11 #define _STRUCT_TIMESPEC
 12 struct timespec {
 13         time_t  tv_sec;         /* seconds */
 14         long    tv_nsec;        /* nanoseconds */
 15 };
 16 #endif /* _STRUCT_TIMESPEC */
 17 
 18 struct timeval {
 19         time_t          tv_sec;         /* seconds */
 20         suseconds_t     tv_usec;        /* microseconds */
 21 };
 22 
 23 struct timezone {
 24         int     tz_minuteswest; /* minutes west of Greenwich */
 25         int     tz_dsttime;     /* type of dst correction */
 26 };
 27 
 28 #ifdef __KERNEL__
 29 
 30 /* Parameters used to convert the timespec values */
 31 #ifndef USEC_PER_SEC
 32 #define USEC_PER_SEC (1000000L)
 33 #endif
 34 
 35 #ifndef NSEC_PER_SEC
 36 #define NSEC_PER_SEC (1000000000L)
 37 #endif
 38 
 39 #ifndef NSEC_PER_USEC
 40 #define NSEC_PER_USEC (1000L)
 41 #endif
 42 
 43 static __inline__ int timespec_equal(struct timespec *a, struct timespec *b) 
 44 { 
 45         return (a->tv_sec == b->tv_sec) && (a->tv_nsec == b->tv_nsec);
 46 } 
 47 
 48 /* Converts Gregorian date to seconds since 1970-01-01 00:00:00.
 49  * Assumes input in normal date format, i.e. 1980-12-31 23:59:59
 50  * => year=1980, mon=12, day=31, hour=23, min=59, sec=59.
 51  *
 52  * [For the Julian calendar (which was used in Russia before 1917,
 53  * Britain & colonies before 1752, anywhere else before 1582,
 54  * and is still in use by some communities) leave out the
 55  * -year/100+year/400 terms, and add 10.]
 56  *
 57  * This algorithm was first published by Gauss (I think).
 58  *
 59  * WARNING: this function will overflow on 2106-02-07 06:28:16 on
 60  * machines were long is 32-bit! (However, as time_t is signed, we
 61  * will already get problems at other places on 2038-01-19 03:14:08)
 62  */
 63 static inline unsigned long
 64 mktime (unsigned int year, unsigned int mon,
 65         unsigned int day, unsigned int hour,
 66         unsigned int min, unsigned int sec)
 67 {
 68         if (0 >= (int) (mon -= 2)) {    /* 1..12 -> 11,12,1..10 */
 69                 mon += 12;              /* Puts Feb last since it has leap day */
 70                 year -= 1;
 71         }
 72 
 73         return (((
 74                 (unsigned long) (year/4 - year/100 + year/400 + 367*mon/12 + day) +
 75                         year*365 - 719499
 76             )*24 + hour /* now have hours */
 77           )*60 + min /* now have minutes */
 78         )*60 + sec; /* finally seconds */
 79 }
 80 
 81 extern struct timespec xtime;
 82 extern struct timespec wall_to_monotonic;
 83 extern seqlock_t xtime_lock;
 84 
 85 static inline unsigned long get_seconds(void)
 86 { 
 87         return xtime.tv_sec;
 88 }
 89 
 90 struct timespec current_kernel_time(void);
 91 
 92 #define CURRENT_TIME (current_kernel_time())
 93 #define CURRENT_TIME_SEC ((struct timespec) { xtime.tv_sec, 0 })
 94 
 95 extern void do_gettimeofday(struct timeval *tv);
 96 extern int do_settimeofday(struct timespec *tv);
 97 extern int do_sys_settimeofday(struct timespec *tv, struct timezone *tz);
 98 extern void clock_was_set(void); // call when ever the clock is set
 99 extern int do_posix_clock_monotonic_gettime(struct timespec *tp);
100 extern long do_nanosleep(struct timespec *t);
101 extern long do_utimes(char __user * filename, struct timeval * times);
102 struct itimerval;
103 extern int do_setitimer(int which, struct itimerval *value, struct itimerval *ovalue);
104 extern int do_getitimer(int which, struct itimerval *value);
105 extern void getnstimeofday (struct timespec *tv);
106 
107 extern struct timespec timespec_trunc(struct timespec t, unsigned gran);
108 
109 static inline void
110 set_normalized_timespec (struct timespec *ts, time_t sec, long nsec)
111 {
112         while (nsec > NSEC_PER_SEC) {
113                 nsec -= NSEC_PER_SEC;
114                 ++sec;
115         }
116         while (nsec < 0) {
117                 nsec += NSEC_PER_SEC;
118                 --sec;
119         }
120         ts->tv_sec = sec;
121         ts->tv_nsec = nsec;
122 }
123 
124 #endif /* __KERNEL__ */
125 
126 #define NFDBITS                 __NFDBITS
127 
128 #define FD_SETSIZE              __FD_SETSIZE
129 #define FD_SET(fd,fdsetp)       __FD_SET(fd,fdsetp)
130 #define FD_CLR(fd,fdsetp)       __FD_CLR(fd,fdsetp)
131 #define FD_ISSET(fd,fdsetp)     __FD_ISSET(fd,fdsetp)
132 #define FD_ZERO(fdsetp)         __FD_ZERO(fdsetp)
133 
134 /*
135  * Names of the interval timers, and structure
136  * defining a timer setting.
137  */
138 #define ITIMER_REAL     0
139 #define ITIMER_VIRTUAL  1
140 #define ITIMER_PROF     2
141 
142 struct  itimerspec {
143         struct  timespec it_interval;    /* timer period */
144         struct  timespec it_value;       /* timer expiration */
145 };
146 
147 struct  itimerval {
148         struct  timeval it_interval;    /* timer interval */
149         struct  timeval it_value;       /* current value */
150 };
151 
152 
153 /*
154  * The IDs of the various system clocks (for POSIX.1b interval timers).
155  */
156 #define CLOCK_REALTIME            0
157 #define CLOCK_MONOTONIC   1
158 #define CLOCK_PROCESS_CPUTIME_ID 2
159 #define CLOCK_THREAD_CPUTIME_ID  3
160 #define CLOCK_REALTIME_HR        4
161 #define CLOCK_MONOTONIC_HR        5
162 
163 /*
164  * The IDs of various hardware clocks
165  */
166 
167 
168 #define CLOCK_SGI_CYCLE 10
169 #define MAX_CLOCKS 16
170 #define CLOCKS_MASK  (CLOCK_REALTIME | CLOCK_MONOTONIC | \
171                      CLOCK_REALTIME_HR | CLOCK_MONOTONIC_HR)
172 #define CLOCKS_MONO (CLOCK_MONOTONIC & CLOCK_MONOTONIC_HR)
173 
174 /*
175  * The various flags for setting POSIX.1b interval timers.
176  */
177 
178 #define TIMER_ABSTIME 0x01
179 
180 
181 #endif
182 
  This page was automatically generated by the LXR engine.