aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnd Bergmann <arnd@arndb.de>2017-10-19 07:14:48 -0400
committerJohn Stultz <john.stultz@linaro.org>2017-10-30 18:17:19 -0400
commitabc8f96e3eb846fcf6333395ee1f6ed4a734576c (patch)
treeff43ddc35d3a039dcc683018ff5b0c4e1f746b37
parent5dbf20127f8cca8588ad0b0e3e8ded587ac7afa0 (diff)
time: Move time_t conversion helpers to time32.h
On 64-bit architectures, the timespec64 based helpers in linux/time.h are defined as macros pointing to their timespec based counterparts. This made sense when they were first introduced, but as we are migrating away from timespec in general, it's much less intuitive now. This changes the macros to work in the exact opposite way: we always provide the timespec64 based helpers and define the old interfaces as macros for them. Now we can move those macros into linux/time32.h, which already contains the respective helpers for 32-bit architectures. Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Ingo Molnar <mingo@kernel.org> Cc: Miroslav Lichvar <mlichvar@redhat.com> Cc: Richard Cochran <richardcochran@gmail.com> Cc: Prarit Bhargava <prarit@redhat.com> Cc: Stephen Boyd <stephen.boyd@linaro.org> Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: John Stultz <john.stultz@linaro.org>
-rw-r--r--include/linux/time32.h45
-rw-r--r--include/linux/time64.h50
-rw-r--r--kernel/time/time.c5
3 files changed, 49 insertions, 51 deletions
diff --git a/include/linux/time32.h b/include/linux/time32.h
index 9b9c43f0d39b..65b1de25198d 100644
--- a/include/linux/time32.h
+++ b/include/linux/time32.h
@@ -13,6 +13,49 @@
13 13
14#define TIME_T_MAX (time_t)((1UL << ((sizeof(time_t) << 3) - 1)) - 1) 14#define TIME_T_MAX (time_t)((1UL << ((sizeof(time_t) << 3) - 1)) - 1)
15 15
16#if __BITS_PER_LONG == 64
17
18/* timespec64 is defined as timespec here */
19static inline struct timespec timespec64_to_timespec(const struct timespec64 ts64)
20{
21 return ts64;
22}
23
24static inline struct timespec64 timespec_to_timespec64(const struct timespec ts)
25{
26 return ts;
27}
28
29# define timespec_equal timespec64_equal
30# define timespec_compare timespec64_compare
31# define set_normalized_timespec set_normalized_timespec64
32# define timespec_add timespec64_add
33# define timespec_sub timespec64_sub
34# define timespec_valid timespec64_valid
35# define timespec_valid_strict timespec64_valid_strict
36# define timespec_to_ns timespec64_to_ns
37# define ns_to_timespec ns_to_timespec64
38# define timespec_add_ns timespec64_add_ns
39
40#else
41static inline struct timespec timespec64_to_timespec(const struct timespec64 ts64)
42{
43 struct timespec ret;
44
45 ret.tv_sec = (time_t)ts64.tv_sec;
46 ret.tv_nsec = ts64.tv_nsec;
47 return ret;
48}
49
50static inline struct timespec64 timespec_to_timespec64(const struct timespec ts)
51{
52 struct timespec64 ret;
53
54 ret.tv_sec = ts.tv_sec;
55 ret.tv_nsec = ts.tv_nsec;
56 return ret;
57}
58
16static inline int timespec_equal(const struct timespec *a, 59static inline int timespec_equal(const struct timespec *a,
17 const struct timespec *b) 60 const struct timespec *b)
18{ 61{
@@ -116,6 +159,8 @@ static __always_inline void timespec_add_ns(struct timespec *a, u64 ns)
116 a->tv_nsec = ns; 159 a->tv_nsec = ns;
117} 160}
118 161
162#endif
163
119/** 164/**
120 * time_to_tm - converts the calendar time to local broken-down time 165 * time_to_tm - converts the calendar time to local broken-down time
121 * 166 *
diff --git a/include/linux/time64.h b/include/linux/time64.h
index 402b595c76d2..ec1888cf5378 100644
--- a/include/linux/time64.h
+++ b/include/linux/time64.h
@@ -7,11 +7,8 @@
7typedef __s64 time64_t; 7typedef __s64 time64_t;
8typedef __u64 timeu64_t; 8typedef __u64 timeu64_t;
9 9
10/*
11 * This wants to go into uapi/linux/time.h once we agreed about the
12 * userspace interfaces.
13 */
14#if __BITS_PER_LONG == 64 10#if __BITS_PER_LONG == 64
11/* this trick allows us to optimize out timespec64_to_timespec */
15# define timespec64 timespec 12# define timespec64 timespec
16#define itimerspec64 itimerspec 13#define itimerspec64 itimerspec
17#else 14#else
@@ -41,49 +38,6 @@ struct itimerspec64 {
41#define KTIME_MAX ((s64)~((u64)1 << 63)) 38#define KTIME_MAX ((s64)~((u64)1 << 63))
42#define KTIME_SEC_MAX (KTIME_MAX / NSEC_PER_SEC) 39#define KTIME_SEC_MAX (KTIME_MAX / NSEC_PER_SEC)
43 40
44#if __BITS_PER_LONG == 64
45
46static inline struct timespec timespec64_to_timespec(const struct timespec64 ts64)
47{
48 return ts64;
49}
50
51static inline struct timespec64 timespec_to_timespec64(const struct timespec ts)
52{
53 return ts;
54}
55
56# define timespec64_equal timespec_equal
57# define timespec64_compare timespec_compare
58# define set_normalized_timespec64 set_normalized_timespec
59# define timespec64_add timespec_add
60# define timespec64_sub timespec_sub
61# define timespec64_valid timespec_valid
62# define timespec64_valid_strict timespec_valid_strict
63# define timespec64_to_ns timespec_to_ns
64# define ns_to_timespec64 ns_to_timespec
65# define timespec64_add_ns timespec_add_ns
66
67#else
68
69static inline struct timespec timespec64_to_timespec(const struct timespec64 ts64)
70{
71 struct timespec ret;
72
73 ret.tv_sec = (time_t)ts64.tv_sec;
74 ret.tv_nsec = ts64.tv_nsec;
75 return ret;
76}
77
78static inline struct timespec64 timespec_to_timespec64(const struct timespec ts)
79{
80 struct timespec64 ret;
81
82 ret.tv_sec = ts.tv_sec;
83 ret.tv_nsec = ts.tv_nsec;
84 return ret;
85}
86
87static inline int timespec64_equal(const struct timespec64 *a, 41static inline int timespec64_equal(const struct timespec64 *a,
88 const struct timespec64 *b) 42 const struct timespec64 *b)
89{ 43{
@@ -185,8 +139,6 @@ static __always_inline void timespec64_add_ns(struct timespec64 *a, u64 ns)
185 a->tv_nsec = ns; 139 a->tv_nsec = ns;
186} 140}
187 141
188#endif
189
190/* 142/*
191 * timespec64_add_safe assumes both values are positive and checks for 143 * timespec64_add_safe assumes both values are positive and checks for
192 * overflow. It will return TIME64_MAX in case of overflow. 144 * overflow. It will return TIME64_MAX in case of overflow.
diff --git a/kernel/time/time.c b/kernel/time/time.c
index 947fb614c78f..fe60ebd301cf 100644
--- a/kernel/time/time.c
+++ b/kernel/time/time.c
@@ -407,6 +407,7 @@ time64_t mktime64(const unsigned int year0, const unsigned int mon0,
407} 407}
408EXPORT_SYMBOL(mktime64); 408EXPORT_SYMBOL(mktime64);
409 409
410#if __BITS_PER_LONG == 32
410/** 411/**
411 * set_normalized_timespec - set timespec sec and nsec parts and normalize 412 * set_normalized_timespec - set timespec sec and nsec parts and normalize
412 * 413 *
@@ -467,6 +468,7 @@ struct timespec ns_to_timespec(const s64 nsec)
467 return ts; 468 return ts;
468} 469}
469EXPORT_SYMBOL(ns_to_timespec); 470EXPORT_SYMBOL(ns_to_timespec);
471#endif
470 472
471/** 473/**
472 * ns_to_timeval - Convert nanoseconds to timeval 474 * ns_to_timeval - Convert nanoseconds to timeval
@@ -486,7 +488,6 @@ struct timeval ns_to_timeval(const s64 nsec)
486} 488}
487EXPORT_SYMBOL(ns_to_timeval); 489EXPORT_SYMBOL(ns_to_timeval);
488 490
489#if BITS_PER_LONG == 32
490/** 491/**
491 * set_normalized_timespec - set timespec sec and nsec parts and normalize 492 * set_normalized_timespec - set timespec sec and nsec parts and normalize
492 * 493 *
@@ -547,7 +548,7 @@ struct timespec64 ns_to_timespec64(const s64 nsec)
547 return ts; 548 return ts;
548} 549}
549EXPORT_SYMBOL(ns_to_timespec64); 550EXPORT_SYMBOL(ns_to_timespec64);
550#endif 551
551/** 552/**
552 * msecs_to_jiffies: - convert milliseconds to jiffies 553 * msecs_to_jiffies: - convert milliseconds to jiffies
553 * @m: time in milliseconds 554 * @m: time in milliseconds