Re: [PATCH] compat: Avoid double rounding in times()
From: Andrew Morton
Date: Tue Oct 20 2026 - 17:36:00 EST
On Tue, 20 Oct 2026 21:01:57 +0000 Hungyu Lin <dennylin0707@xxxxxxxxx> wrote:
> do_sys_times() already converts CPU time to USER_HZ ticks. The compat
> path converts each value back to jiffies before converting it to
> COMPAT_USER_HZ. This round trip can lose precision even when the two
> userspace rates match.
>
> With HZ=250 and USER_HZ=COMPAT_USER_HZ=100, one user tick becomes two
> jiffies and then zero compat ticks. Every odd tick count loses one
> tick, so any of the four tms fields can underreport CPU time by an
> additional 10 ms.
>
> Return the value directly when the native and compat units match. Keep
> the existing conversion for differing rates.
The fix looks correct. The compat times() path unnecessarily converts
CPU time from USER_HZ ticks to jiffies and back, losing precision.
I had $LLM model the userspace-visible results for tick counts 0 through
10,000. With HZ=250 and USER_HZ=COMPAT_USER_HZ=100, 5,000 values
underreport CPU time by 10 ms. The patch eliminates these errors
without changing the differing-rate case.
Thanks.