This patch changes the way cpu_index is handed out to newly created CPUs by tracking the allocted CPUs in a bitmap. More information and the need for this patch is described in patch 2/3 of this series. These generic changes are needed to support CPU hot plug/unplug on PowerPC.
cpu_index is allocated in cpu_exec_init() and freed (during CPU unplug) in the newly added API cpu_exec_exit(). Currently all architectures call cpu_exec_init() from instance_init and hence cpu_exec_exit() is called from instance_finalize for all archs in this series. Instead of adding instance_finalize to all archs, we could call cpu_exec_exit() from the parent class (CPUClass.instance_finalize). However archs like x86 and PowerPC want cpu_exec_init() to be moved to realizefn from instance_init. Such movement will become easy with the current approach. Eudardo's suggested alternative of making cpu_exec_exit() idempotent (http://lists.nongnu.org/archive/html/qemu-devel/2015-05/msg01241.html) will also simplify this movement, but I think that would compilicate the deallocation logic. Another open question is about handling of holes correctly in the allocated bitmap to support VM migration after CPU unplug. This was briefly discussed here: https://lists.gnu.org/archive/html/qemu-devel/2015-04/msg00560.html Should cpu_exec_init() API support specifying of a particular cpu_index in addition to returning the next available cpu_index by default ? I know that QEMU cmdline semantics for CPU device add/delele haven't been defined yet, but should we now make provision in cpu_exec_init() to allocate the required cpu_index ? Changes in v1 ------------- - Added Error argument to cpu_exec_init() so that it callers calling it from realizefn can collect errors. v0: https://lists.gnu.org/archive/html/qemu-devel/2015-03/msg02950.html Bharata B Rao (3): cpus: Add Error argument to cpu_exec_init() cpus: Convert cpu_index into a bitmap ppc: Move cpu_exec_init() call to realize function exec.c | 39 +++++++++++++++++++++++++++++++++++---- include/exec/exec-all.h | 2 +- include/qom/cpu.h | 8 ++++++++ target-alpha/cpu.c | 8 +++++++- target-arm/cpu.c | 3 ++- target-cris/cpu.c | 8 +++++++- target-i386/cpu.c | 8 +++++++- target-lm32/cpu.c | 8 +++++++- target-m68k/cpu.c | 8 +++++++- target-microblaze/cpu.c | 8 +++++++- target-mips/cpu.c | 8 +++++++- target-moxie/cpu.c | 8 +++++++- target-openrisc/cpu.c | 8 +++++++- target-ppc/translate_init.c | 15 +++++++++++++-- target-s390x/cpu.c | 3 ++- target-sh4/cpu.c | 8 +++++++- target-sparc/cpu.c | 3 ++- target-tricore/cpu.c | 7 ++++++- target-unicore32/cpu.c | 8 +++++++- target-xtensa/cpu.c | 8 +++++++- 20 files changed, 153 insertions(+), 23 deletions(-) -- 2.1.0