Skip to content

Commit 4f0fad9

Browse files
arndbKAGA-KOKO
authored andcommitted
timekeeping: Remove timespec64 hack
At this point, we have converted most of the kernel to use timespec64 consistently in place of timespec, so it seems it's time to make timespec64 the native structure and define timespec in terms of that one on 64-bit architectures. Starting with gcc-5, the compiler can completely optimize away the timespec_to_timespec64 and timespec64_to_timespec functions on 64-bit architectures. With older compilers, we introduce a couple of extra copies of local variables, but those are easily avoided by using the timespec64 based interfaces consistently, as we do in most of the important code paths already. The main upside of removing the hack is that printing the tv_sec field of a timespec64 structure can now use the %lld format string on all architectures without a cast to time64_t. Without this patch, the field is a 'long' type and would have to be printed using %ld on 64-bit architectures. Signed-off-by: Arnd Bergmann <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Cc: Stephen Boyd <[email protected]> Cc: [email protected] Cc: John Stultz <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent b563ea6 commit 4f0fad9

File tree

4 files changed

+3
-69
lines changed

4 files changed

+3
-69
lines changed

include/linux/time32.h

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,14 @@
1818
/* timespec64 is defined as timespec here */
1919
static inline struct timespec timespec64_to_timespec(const struct timespec64 ts64)
2020
{
21-
return ts64;
21+
return *(const struct timespec *)&ts64;
2222
}
2323

2424
static inline struct timespec64 timespec_to_timespec64(const struct timespec ts)
2525
{
26-
return ts;
26+
return *(const struct timespec64 *)&ts;
2727
}
2828

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-
4029
#else
4130
static inline struct timespec timespec64_to_timespec(const struct timespec64 ts64)
4231
{
@@ -55,6 +44,7 @@ static inline struct timespec64 timespec_to_timespec64(const struct timespec ts)
5544
ret.tv_nsec = ts.tv_nsec;
5645
return ret;
5746
}
47+
#endif
5848

5949
static inline int timespec_equal(const struct timespec *a,
6050
const struct timespec *b)
@@ -159,8 +149,6 @@ static __always_inline void timespec_add_ns(struct timespec *a, u64 ns)
159149
a->tv_nsec = ns;
160150
}
161151

162-
#endif
163-
164152
/**
165153
* time_to_tm - converts the calendar time to local broken-down time
166154
*

include/linux/time64.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ typedef __u64 timeu64_t;
1616

1717
#include <uapi/linux/time.h>
1818

19-
#if __BITS_PER_LONG == 64
20-
/* this trick allows us to optimize out timespec64_to_timespec */
21-
# define timespec64 timespec
22-
#define itimerspec64 itimerspec
23-
#else
2419
struct timespec64 {
2520
time64_t tv_sec; /* seconds */
2621
long tv_nsec; /* nanoseconds */
@@ -31,8 +26,6 @@ struct itimerspec64 {
3126
struct timespec64 it_value;
3227
};
3328

34-
#endif
35-
3629
/* Parameters used to convert the timespec values: */
3730
#define MSEC_PER_SEC 1000L
3831
#define USEC_PER_MSEC 1000L

include/linux/timekeeping32.h

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -16,50 +16,6 @@ static inline struct timespec current_kernel_time(void)
1616
return timespec64_to_timespec(now);
1717
}
1818

19-
#if BITS_PER_LONG == 64
20-
/**
21-
* Deprecated. Use do_settimeofday64().
22-
*/
23-
static inline int do_settimeofday(const struct timespec *ts)
24-
{
25-
return do_settimeofday64(ts);
26-
}
27-
28-
static inline int __getnstimeofday(struct timespec *ts)
29-
{
30-
return __getnstimeofday64(ts);
31-
}
32-
33-
static inline void getnstimeofday(struct timespec *ts)
34-
{
35-
getnstimeofday64(ts);
36-
}
37-
38-
static inline void ktime_get_ts(struct timespec *ts)
39-
{
40-
ktime_get_ts64(ts);
41-
}
42-
43-
static inline void ktime_get_real_ts(struct timespec *ts)
44-
{
45-
getnstimeofday64(ts);
46-
}
47-
48-
static inline void getrawmonotonic(struct timespec *ts)
49-
{
50-
getrawmonotonic64(ts);
51-
}
52-
53-
static inline struct timespec get_monotonic_coarse(void)
54-
{
55-
return get_monotonic_coarse64();
56-
}
57-
58-
static inline void getboottime(struct timespec *ts)
59-
{
60-
return getboottime64(ts);
61-
}
62-
#else
6319
/**
6420
* Deprecated. Use do_settimeofday64().
6521
*/
@@ -124,7 +80,6 @@ static inline void getboottime(struct timespec *ts)
12480
getboottime64(&ts64);
12581
*ts = timespec64_to_timespec(ts64);
12682
}
127-
#endif
12883

12984
/*
13085
* Timespec interfaces utilizing the ktime based ones

kernel/time/time.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,6 @@ time64_t mktime64(const unsigned int year0, const unsigned int mon0,
407407
}
408408
EXPORT_SYMBOL(mktime64);
409409

410-
#if __BITS_PER_LONG == 32
411410
/**
412411
* set_normalized_timespec - set timespec sec and nsec parts and normalize
413412
*
@@ -468,7 +467,6 @@ struct timespec ns_to_timespec(const s64 nsec)
468467
return ts;
469468
}
470469
EXPORT_SYMBOL(ns_to_timespec);
471-
#endif
472470

473471
/**
474472
* ns_to_timeval - Convert nanoseconds to timeval

0 commit comments

Comments
 (0)