4 #include <linux/types.h>
7 #include <linux/seqlock.h>
10 #ifndef _STRUCT_TIMESPEC
11 #define _STRUCT_TIMESPEC
13 time_t tv_sec; /* seconds */
14 long tv_nsec; /* nanoseconds */
16 #endif /* _STRUCT_TIMESPEC */
19 time_t tv_sec; /* seconds */
20 suseconds_t tv_usec; /* microseconds */
24 int tz_minuteswest; /* minutes west of Greenwich */
25 int tz_dsttime; /* type of dst correction */
30 /* Parameters used to convert the timespec values */
31 #define MSEC_PER_SEC (1000L)
34 #define USEC_PER_SEC (1000000L)
38 #define NSEC_PER_SEC (1000000000L)
42 #define NSEC_PER_USEC (1000L)
45 static __inline__ int timespec_equal(struct timespec *a, struct timespec *b)
47 return (a->tv_sec == b->tv_sec) && (a->tv_nsec == b->tv_nsec);
50 /* Converts Gregorian date to seconds since 1970-01-01 00:00:00.
51 * Assumes input in normal date format, i.e. 1980-12-31 23:59:59
52 * => year=1980, mon=12, day=31, hour=23, min=59, sec=59.
54 * [For the Julian calendar (which was used in Russia before 1917,
55 * Britain & colonies before 1752, anywhere else before 1582,
56 * and is still in use by some communities) leave out the
57 * -year/100+year/400 terms, and add 10.]
59 * This algorithm was first published by Gauss (I think).
61 * WARNING: this function will overflow on 2106-02-07 06:28:16 on
62 * machines were long is 32-bit! (However, as time_t is signed, we
63 * will already get problems at other places on 2038-01-19 03:14:08)
65 static inline unsigned long
66 mktime (unsigned int year, unsigned int mon,
67 unsigned int day, unsigned int hour,
68 unsigned int min, unsigned int sec)
70 if (0 >= (int) (mon -= 2)) { /* 1..12 -> 11,12,1..10 */
71 mon += 12; /* Puts Feb last since it has leap day */
76 (unsigned long) (year/4 - year/100 + year/400 + 367*mon/12 + day) +
78 )*24 + hour /* now have hours */
79 )*60 + min /* now have minutes */
80 )*60 + sec; /* finally seconds */
83 extern struct timespec xtime;
84 extern struct timespec wall_to_monotonic;
85 extern seqlock_t xtime_lock;
87 static inline unsigned long get_seconds(void)
92 struct timespec current_kernel_time(void);
94 #define CURRENT_TIME (current_kernel_time())
95 #define CURRENT_TIME_SEC ((struct timespec) { xtime.tv_sec, 0 })
97 extern void do_gettimeofday(struct timeval *tv);
98 extern int do_settimeofday(struct timespec *tv);
99 extern int do_sys_settimeofday(struct timespec *tv, struct timezone *tz);
100 extern void clock_was_set(void); // call when ever the clock is set
101 extern int do_posix_clock_monotonic_gettime(struct timespec *tp);
102 extern long do_utimes(char __user * filename, struct timeval * times);
104 extern int do_setitimer(int which, struct itimerval *value, struct itimerval *ovalue);
105 extern int do_getitimer(int which, struct itimerval *value);
106 extern void getnstimeofday (struct timespec *tv);
108 extern struct timespec timespec_trunc(struct timespec t, unsigned gran);
111 set_normalized_timespec (struct timespec *ts, time_t sec, long nsec)
113 while (nsec > NSEC_PER_SEC) {
114 nsec -= NSEC_PER_SEC;
118 nsec += NSEC_PER_SEC;
125 #endif /* __KERNEL__ */
127 #define NFDBITS __NFDBITS
129 #define FD_SETSIZE __FD_SETSIZE
130 #define FD_SET(fd,fdsetp) __FD_SET(fd,fdsetp)
131 #define FD_CLR(fd,fdsetp) __FD_CLR(fd,fdsetp)
132 #define FD_ISSET(fd,fdsetp) __FD_ISSET(fd,fdsetp)
133 #define FD_ZERO(fdsetp) __FD_ZERO(fdsetp)
136 * Names of the interval timers, and structure
137 * defining a timer setting.
139 #define ITIMER_REAL 0
140 #define ITIMER_VIRTUAL 1
141 #define ITIMER_PROF 2
144 struct timespec it_interval; /* timer period */
145 struct timespec it_value; /* timer expiration */
149 struct timeval it_interval; /* timer interval */
150 struct timeval it_value; /* current value */
155 * The IDs of the various system clocks (for POSIX.1b interval timers).
157 #define CLOCK_REALTIME 0
158 #define CLOCK_MONOTONIC 1
159 #define CLOCK_PROCESS_CPUTIME_ID 2
160 #define CLOCK_THREAD_CPUTIME_ID 3
161 #define CLOCK_REALTIME_HR 4
162 #define CLOCK_MONOTONIC_HR 5
165 * The IDs of various hardware clocks
169 #define CLOCK_SGI_CYCLE 10
170 #define MAX_CLOCKS 16
171 #define CLOCKS_MASK (CLOCK_REALTIME | CLOCK_MONOTONIC | \
172 CLOCK_REALTIME_HR | CLOCK_MONOTONIC_HR)
173 #define CLOCKS_MONO (CLOCK_MONOTONIC & CLOCK_MONOTONIC_HR)
176 * The various flags for setting POSIX.1b interval timers.
179 #define TIMER_ABSTIME 0x01