s390/idle: fix cpu idle time calculation
authorHeiko Carstens <heiko.carstens@de.ibm.com>
Mon, 28 Oct 2019 10:03:27 +0000 (11:03 +0100)
committerVasily Gorbik <gor@linux.ibm.com>
Thu, 31 Oct 2019 16:26:48 +0000 (17:26 +0100)
commit3d7efa4edd07be5c5c3ffa95ba63e97e070e1f3f
tree7b086d413d56374438633850d74f14bf82846581
parenta1d863ac3e1085e1fea9caafd87252d08731de2e
s390/idle: fix cpu idle time calculation

The idle time reported in /proc/stat sometimes incorrectly contains
huge values on s390. This is caused by a bug in arch_cpu_idle_time().

The kernel tries to figure out when a different cpu entered idle by
accessing its per-cpu data structure. There is an ordering problem: if
the remote cpu has an idle_enter value which is not zero, and an
idle_exit value which is zero, it is assumed it is idle since
"now". The "now" timestamp however is taken before the idle_enter
value is read.

Which in turn means that "now" can be smaller than idle_enter of the
remote cpu. Unconditionally subtracting idle_enter from "now" can thus
lead to a negative value (aka large unsigned value).

Fix this by moving the get_tod_clock() invocation out of the
loop. While at it also make the code a bit more readable.

A similar bug also exists for show_idle_time(). Fix this is as well.

Cc: <stable@vger.kernel.org>
Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
arch/s390/kernel/idle.c