Re: [PATCH v2] fs/proc/uptime.c: fix idle time reporting in /proc/uptime

From: Eric Dumazet
Date: Fri Aug 27 2021 - 17:41:14 EST


On Fri, Aug 27, 2021 at 9:55 AM Josh Don <joshdon@xxxxxxxxxx> wrote:
>
> /proc/uptime reports idle time by reading the CPUTIME_IDLE field from
> the per-cpu kcpustats. However, on NO_HZ systems, idle time is not
> continually updated on idle cpus, leading this value to appear
> incorrectly small.
>
> /proc/stat performs an accounting update when reading idle time; we can
> use the same approach for uptime.
>
> With this patch, /proc/stat and /proc/uptime now agree on idle time.
> Additionally, the following shows idle time tick up consistently on an
> idle machine:
> (while true; do cat /proc/uptime; sleep 1; done) | awk '{print $2-prev; prev=$2}'
>
> Reported-by: Luigi Rizzo <lrizzo@xxxxxxxxxx>
> Signed-off-by: Josh Don <joshdon@xxxxxxxxxx>
> ---
>

SGTM thanks !

Reviewed-by: Eric Dumazet <edumazet@xxxxxxxxxx>