Skip to content

Commit aa06a9b

Browse files
trofiakpm00
authored andcommitted
ia64: fix clock_getres(CLOCK_MONOTONIC) to report ITC frequency
clock_gettime(CLOCK_MONOTONIC, &tp) is very precise on ia64 as it uses ITC (similar to rdtsc on x86). It's not quite a hrtimer as it is a few times slower than 1ns. Usually 2-3ns. clock_getres(CLOCK_MONOTONIC, &res) never reflected that fact and reported 0.04s precision (1/HZ value). In https://bugs.gentoo.org/596382 gstreamer's test suite failed loudly when it noticed precision discrepancy. Before the change: clock_getres(CLOCK_MONOTONIC, &res) reported 250Hz precision. After the change: clock_getres(CLOCK_MONOTONIC, &res) reports ITC (400Mhz) precision. The patch is based on matoro's fix. I added a bit of explanation why we need to special-case arch-specific clock_getres(). [[email protected]: coding-style cleanups] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Sergei Trofimovich <[email protected]> Cc: matoro <[email protected]> Cc: Émeric Maschino <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent cba7543 commit aa06a9b

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

arch/ia64/kernel/sys_ia64.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,29 @@ ia64_mremap (unsigned long addr, unsigned long old_len, unsigned long new_len, u
166166
force_successful_syscall_return();
167167
return addr;
168168
}
169+
170+
asmlinkage long
171+
ia64_clock_getres(const clockid_t which_clock, struct __kernel_timespec __user *tp)
172+
{
173+
/*
174+
* ia64's clock_gettime() syscall is implemented as a vdso call
175+
* fsys_clock_gettime(). Currently it handles only
176+
* CLOCK_REALTIME and CLOCK_MONOTONIC. Both are based on
177+
* 'ar.itc' counter which gets incremented at a constant
178+
* frequency. It's usually 400MHz, ~2.5x times slower than CPU
179+
* clock frequency. Which is almost a 1ns hrtimer, but not quite.
180+
*
181+
* Let's special-case these timers to report correct precision
182+
* based on ITC frequency and not HZ frequency for supported
183+
* clocks.
184+
*/
185+
switch (which_clock) {
186+
case CLOCK_REALTIME:
187+
case CLOCK_MONOTONIC:
188+
s64 tick_ns = DIV_ROUND_UP(NSEC_PER_SEC, local_cpu_data->itc_freq);
189+
struct timespec64 rtn_tp = ns_to_timespec64(tick_ns);
190+
return put_timespec64(&rtn_tp, tp);
191+
}
192+
193+
return sys_clock_getres(which_clock, tp);
194+
}

arch/ia64/kernel/syscalls/syscall.tbl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@
240240
228 common timer_delete sys_timer_delete
241241
229 common clock_settime sys_clock_settime
242242
230 common clock_gettime sys_clock_gettime
243-
231 common clock_getres sys_clock_getres
243+
231 common clock_getres ia64_clock_getres
244244
232 common clock_nanosleep sys_clock_nanosleep
245245
233 common fstatfs64 sys_fstatfs64
246246
234 common statfs64 sys_statfs64

0 commit comments

Comments
 (0)