Skip to content

Commit d004e02

Browse files
hpalaciojohnstultz-work
authored andcommitted
timekeeping: add arch_offset hook to ktime_get functions
ktime_get and ktime_get_ts were calling timekeeping_get_ns() but later they were not calling arch_gettimeoffset() so architectures using this mechanism returned 0 ns when calling these functions. This happened for example when running Busybox's ping which calls syscall(__NR_clock_gettime, CLOCK_MONOTONIC, ts) which eventually calls ktime_get. As a result the returned ping travel time was zero. CC: stable@kernel.org Signed-off-by: Hector Palacios <hector.palacios@digi.com> Signed-off-by: John Stultz <john.stultz@linaro.org>
1 parent 367177e commit d004e02

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

‎kernel/time/timekeeping.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ ktime_t ktime_get(void)
249249
secs = xtime.tv_sec + wall_to_monotonic.tv_sec;
250250
nsecs = xtime.tv_nsec + wall_to_monotonic.tv_nsec;
251251
nsecs += timekeeping_get_ns();
252+
/* If arch requires, add in gettimeoffset() */
253+
nsecs += arch_gettimeoffset();
252254

253255
} while (read_seqretry(&xtime_lock, seq));
254256
/*
@@ -280,6 +282,8 @@ void ktime_get_ts(struct timespec *ts)
280282
*ts = xtime;
281283
tomono = wall_to_monotonic;
282284
nsecs = timekeeping_get_ns();
285+
/* If arch requires, add in gettimeoffset() */
286+
nsecs += arch_gettimeoffset();
283287

284288
} while (read_seqretry(&xtime_lock, seq));
285289

0 commit comments

Comments
 (0)