source: GPL/trunk/include/linux/time.h

Last change on this file was 679, checked in by David Azarewicz, 4 years ago

Merge changes from Paul's uniaud32next branch.

File size: 3.9 KB
RevLine 
[32]1#ifndef _LINUX_TIME_H
2#define _LINUX_TIME_H
3
4#include <asm/param.h>
5#include <linux/types.h>
[679]6#include <linux/ktime.h>
7#include <linux/time64.h>
8#include <linux/math64.h>
[32]9
[679]10#define NSEC_PER_SEC 1000000000L
11
12
[32]13#ifndef _STRUCT_TIMESPEC
14#define _STRUCT_TIMESPEC
15struct timespec {
16 time_t tv_sec; /* seconds */
17 long tv_nsec; /* nanoseconds */
18};
19#endif /* _STRUCT_TIMESPEC */
20
[679]21static inline int timespec_equal(const struct timespec *a,
22 const struct timespec *b)
23{
24 return (a->tv_sec == b->tv_sec) && (a->tv_nsec == b->tv_nsec);
25}
26
[32]27/*
28 * Change timeval to jiffies, trying to avoid the
29 * most obvious overflows..
30 *
31 * And some not so obvious.
32 *
33 * Note that we don't want to return MAX_LONG, because
34 * for various timeout reasons we often end up having
35 * to wait "jiffies+1" in order to guarantee that we wait
36 * at _least_ "jiffies" - so "jiffies+1" had better still
37 * be positive.
38 */
39#define MAX_JIFFY_OFFSET ((~0UL >> 1)-1)
40
41static __inline__ unsigned long
42timespec_to_jiffies(struct timespec *value)
43{
44 unsigned long sec = value->tv_sec;
45 long nsec = value->tv_nsec;
46
47 if (sec >= (MAX_JIFFY_OFFSET / HZ))
48 return MAX_JIFFY_OFFSET;
49 nsec += 1000000000L / HZ - 1;
50 nsec /= 1000000000L / HZ;
51 return HZ * sec + nsec;
52}
53
54static __inline__ void
55jiffies_to_timespec(unsigned long jiffies, struct timespec *value)
56{
57 value->tv_nsec = (jiffies % HZ) * (1000000000L / HZ);
58 value->tv_sec = jiffies / HZ;
59}
[479]60
[32]61struct timeval {
62 time_t tv_sec; /* seconds */
63 suseconds_t tv_usec; /* microseconds */
64};
65
66struct timezone {
67 int tz_minuteswest; /* minutes west of Greenwich */
68 int tz_dsttime; /* type of dst correction */
69};
70
71#define NFDBITS __NFDBITS
72
73#ifdef __KERNEL__
74extern void do_gettimeofday(struct timeval *tv);
75extern void do_settimeofday(struct timeval *tv);
76extern void get_fast_time(struct timeval *tv);
77extern void (*do_get_fast_time)(struct timeval *);
78#endif
79
80#define FD_SETSIZE __FD_SETSIZE
81#define FD_SET(fd,fdsetp) __FD_SET(fd,fdsetp)
82#define FD_CLR(fd,fdsetp) __FD_CLR(fd,fdsetp)
83#define FD_ISSET(fd,fdsetp) __FD_ISSET(fd,fdsetp)
84#define FD_ZERO(fdsetp) __FD_ZERO(fdsetp)
85
86/*
87 * Names of the interval timers, and structure
88 * defining a timer setting.
89 */
90#define ITIMER_REAL 0
91#define ITIMER_VIRTUAL 1
92#define ITIMER_PROF 2
93
94struct itimerspec {
95 struct timespec it_interval; /* timer period */
96 struct timespec it_value; /* timer expiration */
97};
98
99struct itimerval {
100 struct timeval it_interval; /* timer interval */
101 struct timeval it_value; /* current value */
102};
103
104/* msecs_to_jiffies */
105#ifndef CONFIG_HAVE_MSECS_TO_JIFFIES
106static __inline__ unsigned int jiffies_to_msecs(const unsigned long j)
107{
[479]108#if (HZ <= 1000 && !(1000 % HZ))
[32]109 return (1000 / HZ) * j;
[479]110#elif (HZ > 1000 && !(HZ % 1000))
[32]111 return (j + (HZ / 1000) - 1)/(HZ / 1000);
[479]112#else
[32]113 return (j * 1000) / HZ;
[479]114#endif
[32]115}
116static __inline__ unsigned long msecs_to_jiffies(const unsigned int m)
117{
118 if (m > jiffies_to_msecs(MAX_JIFFY_OFFSET))
119 return MAX_JIFFY_OFFSET;
[479]120#if (HZ <= 1000 && !(1000 % HZ))
[32]121 return (m + (1000 / HZ) - 1) / (1000 / HZ);
[479]122#elif (HZ > 1000 && !(HZ % 1000))
[32]123 return m * (HZ / 1000);
[479]124#else
[32]125 return (m * HZ + 999) / 1000;
[479]126#endif
[32]127}
128#endif
129
[441]130/* wrapper for getnstimeofday()
131 * it's needed for recent 2.6 kernels, too, due to lack of EXPORT_SYMBOL
132 */
133#define getnstimeofday(x) do { \
134 struct timeval __x; \
135 do_gettimeofday(&__x); \
136 (x)->tv_sec = __x.tv_sec; \
137 (x)->tv_nsec = __x.tv_usec * 1000; \
138} while (0)
139
140#define do_posix_clock_monotonic_gettime getnstimeofday
141
[442]142void msleep(unsigned int msecs);
143
[679]144/**
145 * ns_to_timespec - Convert nanoseconds to timespec
146 * @nsec: the nanoseconds value to be converted
147 *
148 * Returns the timespec representation of the nsec parameter.
149 */
150extern struct timespec ns_to_timespec(const s64 nsec);
151#define getrawmonotonic(ts) do_posix_clock_monotonic_gettime(ts)
[32]152#endif
Note: See TracBrowser for help on using the repository browser.