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