source: GPL/include/linux/time.h@ 18

Last change on this file since 18 was 18, checked in by vladest, 20 years ago

initial import

File size: 2.9 KB
Line 
1#ifndef _LINUX_TIME_H
2#define _LINUX_TIME_H
3
4#include <asm/param.h>
5#include <linux/types.h>
6
7#ifndef _STRUCT_TIMESPEC
8#define _STRUCT_TIMESPEC
9struct timespec {
10 time_t tv_sec; /* seconds */
11 long tv_nsec; /* nanoseconds */
12};
13#endif /* _STRUCT_TIMESPEC */
14
15/*
16 * Change timeval to jiffies, trying to avoid the
17 * most obvious overflows..
18 *
19 * And some not so obvious.
20 *
21 * Note that we don't want to return MAX_LONG, because
22 * for various timeout reasons we often end up having
23 * to wait "jiffies+1" in order to guarantee that we wait
24 * at _least_ "jiffies" - so "jiffies+1" had better still
25 * be positive.
26 */
27#define MAX_JIFFY_OFFSET ((~0UL >> 1)-1)
28
29static __inline__ unsigned long
30timespec_to_jiffies(struct timespec *value)
31{
32 unsigned long sec = value->tv_sec;
33 long nsec = value->tv_nsec;
34
35 if (sec >= (MAX_JIFFY_OFFSET / HZ))
36 return MAX_JIFFY_OFFSET;
37 nsec += 1000000000L / HZ - 1;
38 nsec /= 1000000000L / HZ;
39 return HZ * sec + nsec;
40}
41
42static __inline__ void
43jiffies_to_timespec(unsigned long jiffies, struct timespec *value)
44{
45 value->tv_nsec = (jiffies % HZ) * (1000000000L / HZ);
46 value->tv_sec = jiffies / HZ;
47}
48
49struct timeval {
50 time_t tv_sec; /* seconds */
51 suseconds_t tv_usec; /* microseconds */
52};
53
54struct timezone {
55 int tz_minuteswest; /* minutes west of Greenwich */
56 int tz_dsttime; /* type of dst correction */
57};
58
59#define NFDBITS __NFDBITS
60
61#ifdef __KERNEL__
62extern void do_gettimeofday(struct timeval *tv);
63extern void do_settimeofday(struct timeval *tv);
64extern void get_fast_time(struct timeval *tv);
65extern void (*do_get_fast_time)(struct timeval *);
66#endif
67
68#define FD_SETSIZE __FD_SETSIZE
69#define FD_SET(fd,fdsetp) __FD_SET(fd,fdsetp)
70#define FD_CLR(fd,fdsetp) __FD_CLR(fd,fdsetp)
71#define FD_ISSET(fd,fdsetp) __FD_ISSET(fd,fdsetp)
72#define FD_ZERO(fdsetp) __FD_ZERO(fdsetp)
73
74/*
75 * Names of the interval timers, and structure
76 * defining a timer setting.
77 */
78#define ITIMER_REAL 0
79#define ITIMER_VIRTUAL 1
80#define ITIMER_PROF 2
81
82struct itimerspec {
83 struct timespec it_interval; /* timer period */
84 struct timespec it_value; /* timer expiration */
85};
86
87struct itimerval {
88 struct timeval it_interval; /* timer interval */
89 struct timeval it_value; /* current value */
90};
91
92/* msecs_to_jiffies */
93#ifndef CONFIG_HAVE_MSECS_TO_JIFFIES
94static __inline__ unsigned int jiffies_to_msecs(const unsigned long j)
95{
96 if (HZ <= 1000 && !(1000 % HZ))
97 return (1000 / HZ) * j;
98 else if (HZ > 1000 && !(HZ % 1000))
99 return (j + (HZ / 1000) - 1)/(HZ / 1000);
100 else
101 return (j * 1000) / HZ;
102}
103static __inline__ unsigned long msecs_to_jiffies(const unsigned int m)
104{
105 if (m > jiffies_to_msecs(MAX_JIFFY_OFFSET))
106 return MAX_JIFFY_OFFSET;
107 if (HZ <= 1000 && !(1000 % HZ))
108 return (m + (1000 / HZ) - 1) / (1000 / HZ);
109 else if (HZ > 1000 && !(HZ % 1000))
110 return m * (HZ / 1000);
111 else
112 return (m * HZ + 999) / 1000;
113}
114#endif
115
116#endif
Note: See TracBrowser for help on using the repository browser.