Skip to content

Commit 18f135c

Browse files
kerneltoastcyberknight777
authored andcommitted
printk: Add sleep time to timestamps
cpu_clock() uses monotonic time, which skews when the system suspends, making it difficult to interpret kmsg timestamps. Add the sleep time offset to cpu_clock() in order to make kmsg timestamps reflect the actual boot time. Signed-off-by: Sultanxda <sultanxda@gmail.com> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com> Signed-off-by: Danny Lin <danny@kdrag0n.dev> Signed-off-by: Fiqri Ardyansyah <fiqri15072019@gmail.com> Signed-off-by: Forenche <prahul2003@gmail.com> Signed-off-by: Cyber Knight <cyberknight755@gmail.com>
1 parent 64e357e commit 18f135c

3 files changed

Lines changed: 12 additions & 0 deletions

File tree

include/linux/timekeeping.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,5 +347,6 @@ extern void read_boot_clock64(struct timespec64 *ts);
347347
extern int update_persistent_clock(struct timespec now);
348348
extern int update_persistent_clock64(struct timespec64 now);
349349

350+
s64 get_total_sleep_time_nsec(void);
350351

351352
#endif

kernel/printk/printk.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,7 @@ static size_t print_time(u64 ts, char *buf)
12321232
if (!printk_time)
12331233
return 0;
12341234

1235+
ts += get_total_sleep_time_nsec();
12351236
rem_nsec = do_div(ts, 1000000000);
12361237

12371238
if (!buf)

kernel/time/timekeeping.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2332,3 +2332,13 @@ void xtime_update(unsigned long ticks)
23322332
write_sequnlock(&jiffies_lock);
23332333
update_wall_time();
23342334
}
2335+
2336+
/**
2337+
* get_total_sleep_time_nsec() - returns total sleep time in nanoseconds
2338+
*/
2339+
s64 get_total_sleep_time_nsec(void)
2340+
{
2341+
struct timekeeper *tk = &tk_core.timekeeper;
2342+
2343+
return ktime_to_ns(tk->offs_boot);
2344+
}

0 commit comments

Comments
 (0)