fs/proc/uptime.c: Fix idle time reporting in /proc/uptime
authorJosh Don <joshdon@google.com>
Fri, 27 Aug 2021 16:54:38 +0000 (09:54 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 18 Nov 2021 13:03:56 +0000 (14:03 +0100)
commitf09e1a2d2c74ff5bdeb6b0ad63435ee0eb9c4263
treedfdeda087b18ef1eb1ad3423a42455280b01d853
parent6e242c557ad5d827dacba8ad9b03e90ebeb78581
fs/proc/uptime.c: Fix idle time reporting in /proc/uptime

[ Upstream commit a130e8fbc7de796eb6e680724d87f4737a26d0ac ]

/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@google.com>
Signed-off-by: Josh Don <joshdon@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Link: https://lkml.kernel.org/r/20210827165438.3280779-1-joshdon@google.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/proc/stat.c
fs/proc/uptime.c
include/linux/kernel_stat.h