diff options
Diffstat (limited to 'include/linux/time.h')
| -rw-r--r-- | include/linux/time.h | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/include/linux/time.h b/include/linux/time.h index 0cd696cee998..a5b739967b74 100644 --- a/include/linux/time.h +++ b/include/linux/time.h | |||
| @@ -28,10 +28,13 @@ struct timezone { | |||
| 28 | #ifdef __KERNEL__ | 28 | #ifdef __KERNEL__ |
| 29 | 29 | ||
| 30 | /* Parameters used to convert the timespec values: */ | 30 | /* Parameters used to convert the timespec values: */ |
| 31 | #define MSEC_PER_SEC 1000L | 31 | #define MSEC_PER_SEC 1000L |
| 32 | #define USEC_PER_SEC 1000000L | 32 | #define USEC_PER_MSEC 1000L |
| 33 | #define NSEC_PER_SEC 1000000000L | 33 | #define NSEC_PER_USEC 1000L |
| 34 | #define NSEC_PER_USEC 1000L | 34 | #define NSEC_PER_MSEC 1000000L |
| 35 | #define USEC_PER_SEC 1000000L | ||
| 36 | #define NSEC_PER_SEC 1000000000L | ||
| 37 | #define FSEC_PER_SEC 1000000000000000L | ||
| 35 | 38 | ||
| 36 | static inline int timespec_equal(struct timespec *a, struct timespec *b) | 39 | static inline int timespec_equal(struct timespec *a, struct timespec *b) |
| 37 | { | 40 | { |
| @@ -68,6 +71,18 @@ extern unsigned long mktime(const unsigned int year, const unsigned int mon, | |||
| 68 | extern void set_normalized_timespec(struct timespec *ts, time_t sec, long nsec); | 71 | extern void set_normalized_timespec(struct timespec *ts, time_t sec, long nsec); |
| 69 | 72 | ||
| 70 | /* | 73 | /* |
| 74 | * sub = lhs - rhs, in normalized form | ||
| 75 | */ | ||
| 76 | static inline struct timespec timespec_sub(struct timespec lhs, | ||
| 77 | struct timespec rhs) | ||
| 78 | { | ||
| 79 | struct timespec ts_delta; | ||
| 80 | set_normalized_timespec(&ts_delta, lhs.tv_sec - rhs.tv_sec, | ||
| 81 | lhs.tv_nsec - rhs.tv_nsec); | ||
| 82 | return ts_delta; | ||
| 83 | } | ||
| 84 | |||
| 85 | /* | ||
| 71 | * Returns true if the timespec is norm, false if denorm: | 86 | * Returns true if the timespec is norm, false if denorm: |
| 72 | */ | 87 | */ |
| 73 | #define timespec_valid(ts) \ | 88 | #define timespec_valid(ts) \ |
| @@ -77,6 +92,8 @@ extern struct timespec xtime; | |||
| 77 | extern struct timespec wall_to_monotonic; | 92 | extern struct timespec wall_to_monotonic; |
| 78 | extern seqlock_t xtime_lock; | 93 | extern seqlock_t xtime_lock; |
| 79 | 94 | ||
| 95 | void timekeeping_init(void); | ||
| 96 | |||
| 80 | static inline unsigned long get_seconds(void) | 97 | static inline unsigned long get_seconds(void) |
| 81 | { | 98 | { |
| 82 | return xtime.tv_sec; | 99 | return xtime.tv_sec; |
| @@ -100,6 +117,7 @@ extern int do_getitimer(int which, struct itimerval *value); | |||
| 100 | extern void getnstimeofday(struct timespec *tv); | 117 | extern void getnstimeofday(struct timespec *tv); |
| 101 | 118 | ||
| 102 | extern struct timespec timespec_trunc(struct timespec t, unsigned gran); | 119 | extern struct timespec timespec_trunc(struct timespec t, unsigned gran); |
| 120 | extern int timekeeping_is_continuous(void); | ||
| 103 | 121 | ||
| 104 | /** | 122 | /** |
| 105 | * timespec_to_ns - Convert timespec to nanoseconds | 123 | * timespec_to_ns - Convert timespec to nanoseconds |
| @@ -142,6 +160,20 @@ extern struct timespec ns_to_timespec(const s64 nsec); | |||
| 142 | */ | 160 | */ |
| 143 | extern struct timeval ns_to_timeval(const s64 nsec); | 161 | extern struct timeval ns_to_timeval(const s64 nsec); |
| 144 | 162 | ||
| 163 | /** | ||
| 164 | * timespec_add_ns - Adds nanoseconds to a timespec | ||
| 165 | * @a: pointer to timespec to be incremented | ||
| 166 | * @ns: unsigned nanoseconds value to be added | ||
| 167 | */ | ||
| 168 | static inline void timespec_add_ns(struct timespec *a, u64 ns) | ||
| 169 | { | ||
| 170 | ns += a->tv_nsec; | ||
| 171 | while(unlikely(ns >= NSEC_PER_SEC)) { | ||
| 172 | ns -= NSEC_PER_SEC; | ||
| 173 | a->tv_sec++; | ||
| 174 | } | ||
| 175 | a->tv_nsec = ns; | ||
| 176 | } | ||
| 145 | #endif /* __KERNEL__ */ | 177 | #endif /* __KERNEL__ */ |
| 146 | 178 | ||
| 147 | #define NFDBITS __NFDBITS | 179 | #define NFDBITS __NFDBITS |
