source: GPL/trunk/include/linux/time64.h@ 703

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

Merge changes from Paul's uniaud32next branch.

File size: 2.6 KB
Line 
1#ifndef _LINUX_TIME64_H
2#define _LINUX_TIME64_H
3
4#include <linux/math64.h>
5
6typedef __s64 time64_t;
7typedef __u64 timeu64_t;
8
9struct timespec64 {
10 time64_t tv_sec; /* seconds */
11 long tv_nsec; /* nanoseconds */
12};
13
14struct itimerspec64 {
15 struct timespec64 it_interval;
16 struct timespec64 it_value;
17};
18
19/* Parameters used to convert the timespec values: */
20#define MSEC_PER_SEC 1000L
21#define USEC_PER_MSEC 1000L
22#define NSEC_PER_USEC 1000L
23#define NSEC_PER_MSEC 1000000L
24#define USEC_PER_SEC 1000000L
25#define NSEC_PER_SEC 1000000000L
26#define FSEC_PER_SEC 1000000000000000LL
27
28/* Located here for timespec[64]_valid_strict */
29#define TIME64_MAX ((s64)~((u64)1 << 63))
30#define KTIME_MAX ((s64)~((u64)1 << 63))
31#define KTIME_SEC_MAX (KTIME_MAX / NSEC_PER_SEC)
32
33extern void set_normalized_timespec64(struct timespec64 *ts, time64_t sec, s64 nsec);
34
35static inline struct timespec64 timespec64_add(struct timespec64 lhs,
36 struct timespec64 rhs)
37{
38 struct timespec64 ts_delta;
39 set_normalized_timespec64(&ts_delta, lhs.tv_sec + rhs.tv_sec,
40 lhs.tv_nsec + rhs.tv_nsec);
41 return ts_delta;
42}
43
44/*
45 * sub = lhs - rhs, in normalized form
46 */
47static inline struct timespec64 timespec64_sub(struct timespec64 lhs,
48 struct timespec64 rhs)
49{
50 struct timespec64 ts_delta;
51 set_normalized_timespec64(&ts_delta, lhs.tv_sec - rhs.tv_sec,
52 lhs.tv_nsec - rhs.tv_nsec);
53 return ts_delta;
54}
55
56/*
57 * Returns true if the timespec64 is norm, false if denorm:
58 */
59static inline bool timespec64_valid(const struct timespec64 *ts)
60{
61 /* Dates before 1970 are bogus */
62 if (ts->tv_sec < 0)
63 return false;
64 /* Can't have more nanoseconds then a second */
65 if ((unsigned long)ts->tv_nsec >= NSEC_PER_SEC)
66 return false;
67 return true;
68}
69
70static inline bool timespec64_valid_strict(const struct timespec64 *ts)
71{
72 if (!timespec64_valid(ts))
73 return false;
74 /* Disallow values that could overflow ktime_t */
75 if ((unsigned long long)ts->tv_sec >= KTIME_SEC_MAX)
76 return false;
77 return true;
78}
79
80/**
81 * timespec64_to_ns - Convert timespec64 to nanoseconds
82 * @ts: pointer to the timespec64 variable to be converted
83 *
84 * Returns the scalar nanosecond representation of the timespec64
85 * parameter.
86 */
87static inline s64 timespec64_to_ns(const struct timespec64 *ts)
88{
89 return ((s64) ts->tv_sec * NSEC_PER_SEC) + ts->tv_nsec;
90}
91
92/**
93 * ns_to_timespec64 - Convert nanoseconds to timespec64
94 * @nsec: the nanoseconds value to be converted
95 *
96 * Returns the timespec64 representation of the nsec parameter.
97 */
98extern struct timespec64 ns_to_timespec64(const s64 nsec);
99
100#endif
Note: See TracBrowser for help on using the repository browser.