s390/idle: fix sequence handling vs cpu hotplug
authorHeiko Carstens <heiko.carstens@de.ibm.com>
Fri, 13 Jul 2012 13:45:33 +0000 (15:45 +0200)
committerBen Hutchings <ben@decadent.org.uk>
Thu, 2 Aug 2012 13:37:50 +0000 (14:37 +0100)
commit88981d86ee7c3d3bcfe75f359363658478667fa5
tree37910f907813d3b39c06fafb1810fb58a913073d
parent3e51f8abdd9f7c7a70f1f77295c46a88a46766a6
s390/idle: fix sequence handling vs cpu hotplug

commit 0008204ffe85d23382d6fd0f971f3f0fbe70bae2 upstream.

The s390 idle accounting code uses a sequence counter which gets used
when the per cpu idle statistics get updated and read.

One assumption on read access is that only when the sequence counter is
even and did not change while reading all values the result is valid.
On cpu hotplug however the per cpu data structure gets initialized via
a cpu hotplug notifier on CPU_ONLINE.
CPU_ONLINE however is too late, since the onlined cpu is already running
and might access the per cpu data. Worst case is that the data structure
gets initialized while an idle thread is updating its idle statistics.
This will result in an uneven sequence counter after an update.

As a result user space tools like top, which access /proc/stat in order
to get idle stats, will busy loop waiting for the sequence counter to
become even again, which will never happen until the queried cpu will
update its idle statistics again. And even then the sequence counter
will only have an even value for a couple of cpu cycles.

Fix this by moving the initialization of the per cpu idle statistics
to cpu_init(). I prefer that solution in favor of changing the
notifier to CPU_UP_PREPARE, which would be a different solution to
the problem.

Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
[bwh: Backported to 3.2: adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
arch/s390/kernel/processor.c
arch/s390/kernel/smp.c