Received: from eggs.gnu.org ([2001:4830:134:3::10]:52818) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bSPq8-0000kW-93 for qemu-devel@nongnu.org; Wed, 27 Jul 2016 10:29:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bSPq5-0005Ns-3Z for qemu-devel@nongnu.org; Wed, 27 Jul 2016 10:29:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35294) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bSPq4-0005Nf-U4 for qemu-devel@nongnu.org; Wed, 27 Jul 2016 10:29:37 -0400 From: Eduardo Habkost Date: Wed, 27 Jul 2016 11:29:17 -0300 Message-Id: <1469629761-23274-6-git-send-email-ehabkost@redhat.com> In-Reply-To: <1469629761-23274-1-git-send-email-ehabkost@redhat.com> References: <1469629761-23274-1-git-send-email-ehabkost@redhat.com> Subject: [Qemu-devel] [PULL 5/9] pc: Init CPUState->cpu_index with index in possible_cpus[] List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: Paolo Bonzini , Richard Henderson , Marcel Apfelbaum , qemu-devel@nongnu.org, Igor Mammedov From: Igor Mammedov It will enshure that cpu_index for a given cpu stays the same regardless of the order cpus has been created/deleted. No compat code is needed as for initial cpus index in possible_cpus[] matches cpu_index that's been auto-allocated in cpu_exec_init(). Tha same applies for hotplug with cpu-add command if cpus are added sequentially in increasing order as 'id' matches cpu_index. If cpu-add had been used for creating out-of-order cpus, that created unmigratable instance since it were not possible to start target with the same cpu_index using old way of migrating instance with hotplugged cpus: * source QEMU with CLI (-smp 1,maxcpus=3 and cpu-add id=2) following set of cpu_index is allocated [0, 1] with apics set [0, 2] respectivelly * target QEMU is started with CLI -smp 2,maxcpus=3 resulting in set of cpu_index [0, 1] but with set of apics [0, 1] wich doesn't match source. So we don't need compat code in this case as it's never worked and newelly added device_add support would use stable cpu_index set by machine to begin with, so it won't have above limitation and source QEMU could be migrated to destination regardless of the order cpus were created. Signed-off-by: Igor Mammedov Reviewed-by: David Gibson Reviewed-by: Michael S. Tsirkin Signed-off-by: Eduardo Habkost --- hw/i386/pc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 9e3c70f..d6f0347 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1875,6 +1875,7 @@ static void pc_cpu_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { int idx; + CPUState *cs; CPUArchId *cpu_slot; X86CPUTopoInfo topo; X86CPU *cpu = X86_CPU(dev); @@ -1975,6 +1976,9 @@ static void pc_cpu_pre_plug(HotplugHandler *hotplug_dev, return; } cpu->thread_id = topo.smt_id; + + cs = CPU(cpu); + cs->cpu_index = idx; } static void pc_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev, -- 2.5.5