OSDN Git Service

cpu/hotplug: Cache number of online CPUs
authorThomas Gleixner <tglx@linutronix.de>
Tue, 9 Jul 2019 14:23:40 +0000 (16:23 +0200)
committerThomas Gleixner <tglx@linutronix.de>
Thu, 25 Jul 2019 13:48:01 +0000 (15:48 +0200)
commit0c09ab96fc820109d63097a2adcbbd20836b655f
tree813c75e34ed913bf7dbe7b8e7dfbda997ac27071
parentb9fa6442f7043e2cdd247905d4f3b80f2e9605cb
cpu/hotplug: Cache number of online CPUs

Re-evaluating the bitmap wheight of the online cpus bitmap in every
invocation of num_online_cpus() over and over is a pretty useless
exercise. Especially when num_online_cpus() is used in code paths
like the IPI delivery of x86 or the membarrier code.

Cache the number of online CPUs in the core and just return the cached
variable. The accessor function provides only a snapshot when used without
protection against concurrent CPU hotplug.

The storage needs to use an atomic_t because the kexec and reboot code
(ab)use set_cpu_online() in their 'shutdown' handlers without any form of
serialization as pointed out by Mathieu. Regular CPU hotplug usage is
properly serialized.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Link: https://lkml.kernel.org/r/alpine.DEB.2.21.1907091622590.1634@nanos.tec.linutronix.de
include/linux/cpumask.h
kernel/cpu.c