Skip to content

Commit 8758a24

Browse files
wangbaolin719johnstultz-work
authored andcommitted
time: Introduce current_kernel_time64()
The current_kernel_time() is not year 2038 safe on 32bit systems since it returns a timespec value. Introduce current_kernel_time64() which returns a timespec64 value. Cc: Prarit Bhargava <[email protected]> Cc: Richard Cochran <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Thomas Gleixner <[email protected]> Signed-off-by: Baolin Wang <[email protected]> Signed-off-by: John Stultz <[email protected]>
1 parent 19a46fe commit 8758a24

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

include/linux/timekeeping.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,17 @@ extern int do_sys_settimeofday(const struct timespec *tv,
1818
* Kernel time accessors
1919
*/
2020
unsigned long get_seconds(void);
21-
struct timespec current_kernel_time(void);
21+
struct timespec64 current_kernel_time64(void);
2222
/* does not take xtime_lock */
2323
struct timespec __current_kernel_time(void);
2424

25+
static inline struct timespec current_kernel_time(void)
26+
{
27+
struct timespec64 now = current_kernel_time64();
28+
29+
return timespec64_to_timespec(now);
30+
}
31+
2532
/*
2633
* timespec based interfaces
2734
*/

kernel/time/timekeeping.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,7 +1881,7 @@ struct timespec __current_kernel_time(void)
18811881
return timespec64_to_timespec(tk_xtime(tk));
18821882
}
18831883

1884-
struct timespec current_kernel_time(void)
1884+
struct timespec64 current_kernel_time64(void)
18851885
{
18861886
struct timekeeper *tk = &tk_core.timekeeper;
18871887
struct timespec64 now;
@@ -1893,9 +1893,9 @@ struct timespec current_kernel_time(void)
18931893
now = tk_xtime(tk);
18941894
} while (read_seqcount_retry(&tk_core.seq, seq));
18951895

1896-
return timespec64_to_timespec(now);
1896+
return now;
18971897
}
1898-
EXPORT_SYMBOL(current_kernel_time);
1898+
EXPORT_SYMBOL(current_kernel_time64);
18991899

19001900
struct timespec64 get_monotonic_coarse64(void)
19011901
{

0 commit comments

Comments
 (0)