- Stephen Rothwell: APM updates
[davej-history.git] / include / linux / time.h
blob8d641efd8ec35f7dacd86ed566d05a289362659d
1 #ifndef _LINUX_TIME_H
2 #define _LINUX_TIME_H
4 #include <asm/param.h>
5 #include <linux/types.h>
7 #ifndef _STRUCT_TIMESPEC
8 #define _STRUCT_TIMESPEC
9 struct timespec {
10 time_t tv_sec; /* seconds */
11 long tv_nsec; /* nanoseconds */
13 #endif /* _STRUCT_TIMESPEC */
15 #ifdef __KERNEL__
18 * Change timeval to jiffies, trying to avoid the
19 * most obvious overflows..
21 * And some not so obvious.
23 * Note that we don't want to return MAX_LONG, because
24 * for various timeout reasons we often end up having
25 * to wait "jiffies+1" in order to guarantee that we wait
26 * at _least_ "jiffies" - so "jiffies+1" had better still
27 * be positive.
29 #define MAX_JIFFY_OFFSET ((~0UL >> 1)-1)
31 static __inline__ unsigned long
32 timespec_to_jiffies(struct timespec *value)
34 unsigned long sec = value->tv_sec;
35 long nsec = value->tv_nsec;
37 if (sec >= (MAX_JIFFY_OFFSET / HZ))
38 return MAX_JIFFY_OFFSET;
39 nsec += 1000000000L / HZ - 1;
40 nsec /= 1000000000L / HZ;
41 return HZ * sec + nsec;
44 static __inline__ void
45 jiffies_to_timespec(unsigned long jiffies, struct timespec *value)
47 value->tv_nsec = (jiffies % HZ) * (1000000000L / HZ);
48 value->tv_sec = jiffies / HZ;
52 /* Converts Gregorian date to seconds since 1970-01-01 00:00:00.
53 * Assumes input in normal date format, i.e. 1980-12-31 23:59:59
54 * => year=1980, mon=12, day=31, hour=23, min=59, sec=59.
56 * [For the Julian calendar (which was used in Russia before 1917,
57 * Britain & colonies before 1752, anywhere else before 1582,
58 * and is still in use by some communities) leave out the
59 * -year/100+year/400 terms, and add 10.]
61 * This algorithm was first published by Gauss (I think).
63 * WARNING: this function will overflow on 2106-02-07 06:28:16 on
64 * machines were long is 32-bit! (However, as time_t is signed, we
65 * will already get problems at other places on 2038-01-19 03:14:08)
67 static inline unsigned long
68 mktime (unsigned int year, unsigned int mon,
69 unsigned int day, unsigned int hour,
70 unsigned int min, unsigned int sec)
72 if (0 >= (int) (mon -= 2)) { /* 1..12 -> 11,12,1..10 */
73 mon += 12; /* Puts Feb last since it has leap day */
74 year -= 1;
77 return (((
78 (unsigned long) (year/4 - year/100 + year/400 + 367*mon/12 + day) +
79 year*365 - 719499
80 )*24 + hour /* now have hours */
81 )*60 + min /* now have minutes */
82 )*60 + sec; /* finally seconds */
85 #endif /* __KERNEL__ */
88 struct timeval {
89 time_t tv_sec; /* seconds */
90 suseconds_t tv_usec; /* microseconds */
93 struct timezone {
94 int tz_minuteswest; /* minutes west of Greenwich */
95 int tz_dsttime; /* type of dst correction */
98 #define NFDBITS __NFDBITS
100 #ifdef __KERNEL__
101 extern void do_gettimeofday(struct timeval *tv);
102 extern void do_settimeofday(struct timeval *tv);
103 extern void get_fast_time(struct timeval *tv);
104 extern void (*do_get_fast_time)(struct timeval *);
105 #endif
107 #define FD_SETSIZE __FD_SETSIZE
108 #define FD_SET(fd,fdsetp) __FD_SET(fd,fdsetp)
109 #define FD_CLR(fd,fdsetp) __FD_CLR(fd,fdsetp)
110 #define FD_ISSET(fd,fdsetp) __FD_ISSET(fd,fdsetp)
111 #define FD_ZERO(fdsetp) __FD_ZERO(fdsetp)
114 * Names of the interval timers, and structure
115 * defining a timer setting.
117 #define ITIMER_REAL 0
118 #define ITIMER_VIRTUAL 1
119 #define ITIMER_PROF 2
121 struct itimerspec {
122 struct timespec it_interval; /* timer period */
123 struct timespec it_value; /* timer expiration */
126 struct itimerval {
127 struct timeval it_interval; /* timer interval */
128 struct timeval it_value; /* current value */
131 #endif