Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Arnd Bergmann and committed by
John Stultz
abc8f96e 5dbf2012

+49 -51
+45
include/linux/time32.h
··· 13 13 14 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 */ 19 + static inline struct timespec timespec64_to_timespec(const struct timespec64 ts64) 20 + { 21 + return ts64; 22 + } 23 + 24 + static 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 41 + static 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 + 50 + static 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 + 16 59 static inline int timespec_equal(const struct timespec *a, 17 60 const struct timespec *b) 18 61 { ··· 158 115 a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns); 159 116 a->tv_nsec = ns; 160 117 } 118 + 119 + #endif 161 120 162 121 /** 163 122 * time_to_tm - converts the calendar time to local broken-down time
+1 -49
include/linux/time64.h
··· 7 7 typedef __s64 time64_t; 8 8 typedef __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 10 #if __BITS_PER_LONG == 64 11 + /* this trick allows us to optimize out timespec64_to_timespec */ 15 12 # define timespec64 timespec 16 13 #define itimerspec64 itimerspec 17 14 #else ··· 37 40 #define TIME64_MAX ((s64)~((u64)1 << 63)) 38 41 #define KTIME_MAX ((s64)~((u64)1 << 63)) 39 42 #define KTIME_SEC_MAX (KTIME_MAX / NSEC_PER_SEC) 40 - 41 - #if __BITS_PER_LONG == 64 42 - 43 - static inline struct timespec timespec64_to_timespec(const struct timespec64 ts64) 44 - { 45 - return ts64; 46 - } 47 - 48 - static inline struct timespec64 timespec_to_timespec64(const struct timespec ts) 49 - { 50 - return ts; 51 - } 52 - 53 - # define timespec64_equal timespec_equal 54 - # define timespec64_compare timespec_compare 55 - # define set_normalized_timespec64 set_normalized_timespec 56 - # define timespec64_add timespec_add 57 - # define timespec64_sub timespec_sub 58 - # define timespec64_valid timespec_valid 59 - # define timespec64_valid_strict timespec_valid_strict 60 - # define timespec64_to_ns timespec_to_ns 61 - # define ns_to_timespec64 ns_to_timespec 62 - # define timespec64_add_ns timespec_add_ns 63 - 64 - #else 65 - 66 - static inline struct timespec timespec64_to_timespec(const struct timespec64 ts64) 67 - { 68 - struct timespec ret; 69 - 70 - ret.tv_sec = (time_t)ts64.tv_sec; 71 - ret.tv_nsec = ts64.tv_nsec; 72 - return ret; 73 - } 74 - 75 - static inline struct timespec64 timespec_to_timespec64(const struct timespec ts) 76 - { 77 - struct timespec64 ret; 78 - 79 - ret.tv_sec = ts.tv_sec; 80 - ret.tv_nsec = ts.tv_nsec; 81 - return ret; 82 - } 83 43 84 44 static inline int timespec64_equal(const struct timespec64 *a, 85 45 const struct timespec64 *b) ··· 138 184 a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns); 139 185 a->tv_nsec = ns; 140 186 } 141 - 142 - #endif 143 187 144 188 /* 145 189 * timespec64_add_safe assumes both values are positive and checks for
+3 -2
kernel/time/time.c
··· 407 407 } 408 408 EXPORT_SYMBOL(mktime64); 409 409 410 + #if __BITS_PER_LONG == 32 410 411 /** 411 412 * set_normalized_timespec - set timespec sec and nsec parts and normalize 412 413 * ··· 468 467 return ts; 469 468 } 470 469 EXPORT_SYMBOL(ns_to_timespec); 470 + #endif 471 471 472 472 /** 473 473 * ns_to_timeval - Convert nanoseconds to timeval ··· 488 486 } 489 487 EXPORT_SYMBOL(ns_to_timeval); 490 488 491 - #if BITS_PER_LONG == 32 492 489 /** 493 490 * set_normalized_timespec - set timespec sec and nsec parts and normalize 494 491 * ··· 548 547 return ts; 549 548 } 550 549 EXPORT_SYMBOL(ns_to_timespec64); 551 - #endif 550 + 552 551 /** 553 552 * msecs_to_jiffies: - convert milliseconds to jiffies 554 553 * @m: time in milliseconds